From 3d7ebc4ac95de2dc6df708c38be5882eacf8e250 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 28 Mar 2012 20:08:26 -0600 Subject: [PATCH 0001/1191] update gemspec to remove versions and add ffi-rzmq --- Gemfile.lock | 39 +++++++++++++++++++++------------------ protobuf.gemspec | 11 ++++++----- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 15ab5a69..4eaa03f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,34 +2,37 @@ PATH remote: . specs: protobuf (1.1.3) - eventmachine (~> 0.12.10) - eventually (~> 0.1.0) - json_pure (~> 1.6.4) + eventmachine + eventually + ffi-rzmq + json_pure GEM remote: http://rubygems.org/ specs: diff-lcs (1.1.3) eventmachine (0.12.10) - eventmachine (0.12.10-java) - eventually (0.1.0) - json_pure (1.6.5) + eventually (0.1.1) + ffi (1.0.11) + ffi-rzmq (0.9.3) + ffi + json_pure (1.6.6) multi_json (1.0.4) - rake (0.8.7) + rake (0.9.2.2) redcarpet (1.17.2) - rspec (2.8.0) - rspec-core (~> 2.8.0) - rspec-expectations (~> 2.8.0) - rspec-mocks (~> 2.8.0) - rspec-core (2.8.0) - rspec-expectations (2.8.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.8.0) + rspec (2.9.0) + rspec-core (~> 2.9.0) + rspec-expectations (~> 2.9.0) + rspec-mocks (~> 2.9.0) + rspec-core (2.9.0) + rspec-expectations (2.9.0) + diff-lcs (~> 1.1.3) + rspec-mocks (2.9.0) simplecov (0.5.4) multi_json (~> 1.0.3) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) - yard (0.7.4) + yard (0.7.5) PLATFORMS java @@ -37,8 +40,8 @@ PLATFORMS DEPENDENCIES protobuf! - rake (~> 0.8.7) + rake redcarpet (~> 1.17.2) - rspec (~> 2.8.0) + rspec simplecov (~> 0.5.4) yard (~> 0.7.4) diff --git a/protobuf.gemspec b/protobuf.gemspec index 3528c0b5..7517a70c 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -18,12 +18,13 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'eventmachine', '~> 0.12.10' - s.add_dependency 'eventually', '~> 0.1.0' - s.add_dependency 'json_pure', '~> 1.6.4' + s.add_dependency 'eventmachine' + s.add_dependency 'eventually' + s.add_dependency 'json_pure' + s.add_dependency 'ffi-rzmq' - s.add_development_dependency 'rake', '~> 0.8.7' - s.add_development_dependency 'rspec', '~> 2.8.0' + s.add_development_dependency 'rake' + s.add_development_dependency 'rspec' s.add_development_dependency 'yard', '~> 0.7.4' s.add_development_dependency 'redcarpet', '~> 1.17.2' s.add_development_dependency 'simplecov', '~> 0.5.4' From 20259361971c2d018b9261055578a939d15ece35 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 29 Mar 2012 12:11:30 -0600 Subject: [PATCH 0002/1191] add prototypal zmq server/client --- .gitignore | 1 + Gemfile.lock | 30 +++++++++--- bin/rpc_server | 6 +++ lib/protobuf.rb | 21 ++++++-- lib/protobuf/rpc/connector.rb | 2 + lib/protobuf/rpc/connectors/zmq.rb | 63 ++++++++++++++++++++++++ lib/protobuf/rpc/servers/zmq_runner.rb | 28 +++++++++++ lib/protobuf/rpc/servers/zmq_server.rb | 65 +++++++++++++++++++++++++ protobuf.gemspec | 7 +-- spec/helper/server.rb | 17 ++++++- spec/unit/rpc/connectors/socket_spec.rb | 1 - 11 files changed, 223 insertions(+), 18 deletions(-) create mode 100644 lib/protobuf/rpc/connectors/zmq.rb create mode 100644 lib/protobuf/rpc/servers/zmq_runner.rb create mode 100644 lib/protobuf/rpc/servers/zmq_server.rb diff --git a/.gitignore b/.gitignore index 1c987c7e..09b9ff9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.gem +*.swp pkg/* .bundle .rvmrc diff --git a/Gemfile.lock b/Gemfile.lock index 4eaa03f2..870b69ca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,16 +10,29 @@ PATH GEM remote: http://rubygems.org/ specs: + coderay (1.0.5) diff-lcs (1.1.3) eventmachine (0.12.10) + eventmachine (0.12.10-java) eventually (0.1.1) ffi (1.0.11) + ffi (1.0.11-java) ffi-rzmq (0.9.3) ffi json_pure (1.6.6) - multi_json (1.0.4) + method_source (0.7.1) + multi_json (1.2.0) + pry (0.9.8.4) + coderay (~> 1.0.5) + method_source (~> 0.7.1) + slop (>= 2.4.4, < 3) + pry (0.9.8.4-java) + coderay (~> 1.0.5) + method_source (~> 0.7.1) + slop (>= 2.4.4, < 3) + spoon (~> 0.0) rake (0.9.2.2) - redcarpet (1.17.2) + redcarpet (2.1.1) rspec (2.9.0) rspec-core (~> 2.9.0) rspec-expectations (~> 2.9.0) @@ -28,10 +41,12 @@ GEM rspec-expectations (2.9.0) diff-lcs (~> 1.1.3) rspec-mocks (2.9.0) - simplecov (0.5.4) - multi_json (~> 1.0.3) + simplecov (0.6.1) + multi_json (~> 1.0) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) + slop (2.4.4) + spoon (0.0.1) yard (0.7.5) PLATFORMS @@ -40,8 +55,9 @@ PLATFORMS DEPENDENCIES protobuf! + pry rake - redcarpet (~> 1.17.2) + redcarpet rspec - simplecov (~> 0.5.4) - yard (~> 0.7.4) + simplecov + yard diff --git a/bin/rpc_server b/bin/rpc_server index 1accf8ba..79f78e3c 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -60,6 +60,12 @@ parser = OptionParser.new do |opts| Protobuf::ServerType = "SocketServer" server.runner = Protobuf::Rpc::SocketRunner end + + opts.on("-z", "--zmq", "ZeroMQ Socket Mode for client and server connections (they must be used together)") do |v| + Protobuf::ConnectorType = "Zmq" + Protobuf::ServerType = "ZmqServer" + server.running = Protobuf::Rpc::ZmqRunner + end opts.on("-d", "--[no-]debug", "Debug Mode. Override log level to DEBUG.") do |v| server.debug = v diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 81598f9f..fa1c0db0 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -6,12 +6,16 @@ module Protobuf end - Protobuf::ClientType = ENV['PB_CLIENT_TYPE'] if ENV['PB_CLIENT_TYPE'] Protobuf::ServerType = ENV['PB_SERVER_TYPE'] if ENV['PB_SERVER_TYPE'] # When setting up a client -unless defined?(Protobuf::ClientType) && Protobuf::ClientType == "Socket" +case +when defined?(Protobuf::ClientType) && Protobuf::ClientType == "Zmq" then + require 'ffi-rzmq' + require 'protobuf/rpc/client' + require 'protobuf/rpc/connectors/zmq' +else Protobuf::ClientType = "EventMachine" require 'eventmachine' require 'protobuf/ext/eventmachine' @@ -19,14 +23,21 @@ module Protobuf end # For running the rpc_server -unless defined?(Protobuf::ServerType) && Protobuf::ServerType == "SocketServer" +case +when defined?(Protobuf::ServerType) && Protobuf::ServerType == "ZmqServer" then + require 'ffi-rzmq' + require 'protobuf/rpc/service' + require 'protobuf/rpc/servers/zmq_server' +else Protobuf::ServerType = "EventedServer" require 'eventmachine' require 'protobuf/ext/eventmachine' require 'protobuf/rpc/servers/evented_server' end +# Socket Client/Server loaded by default as it has no impact on cross-platform issues +require 'protobuf/rpc/service' +require 'protobuf/rpc/servers/socket_server' + require 'protobuf/rpc/client' require 'protobuf/rpc/connectors/socket' -require 'protobuf/rpc/service' -require 'protobuf/rpc/servers/socket_server' diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb index d7fd06cc..5752c2a4 100644 --- a/lib/protobuf/rpc/connector.rb +++ b/lib/protobuf/rpc/connector.rb @@ -7,6 +7,8 @@ def self.connector_for_client case Protobuf::ClientType when "Socket" then ::Protobuf::Rpc::Connectors::Socket + when "Zmq" then + ::Protobuf::Rpc::Connectors::Zmq else ::Protobuf::Rpc::Connectors::EventMachine end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb new file mode 100644 index 00000000..b1f35b86 --- /dev/null +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -0,0 +1,63 @@ +require 'protobuf/rpc/connectors/base' + +module Protobuf + module Rpc + module Connectors + class Zmq < Base + include Protobuf::Rpc::Connectors::Common + include Protobuf::Logger::LogMethods + + def send_request + check_async + initialize_stats + connect_to_rpc_server + post_init # calls _send_request + read_response + end + + private + + def assert(return_code) + raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + end + + def check_async + if async? + log_error "[client-#{self.class}] Cannot run in async mode" + raise "Cannot use Zmq client in async mode" + else + log_debug "[client-#{self.class}] Async check passed" + end + end + + def close_connection + @socket.close + log_debug "[client-#{self.class}] Connector closed" + end + + def connect_to_rpc_server + zmq_context = ZMQ::Context.new + @socket = zmq_context.socket(ZMQ::REQ) + assert(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) + log_debug "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" + end + + # Method to determine error state, must be used with Connector api + def error? + false + end + + def read_response + assert(@socket.recv_string(@buffer.data)) + @buffer.size = @buffer.data.size + end + + def send_data(data) + assert(@socket.send_string(data.split("-")[1])) + log_debug "[client-#{self.class}] write closed" + end + + end + end + end +end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb new file mode 100644 index 00000000..8857dc73 --- /dev/null +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -0,0 +1,28 @@ +module Protobuf + module Rpc + class ZmqRunner + + def self.stop + Protobuf::Rpc::ZmqServer.stop + Protobuf::Logger.info 'Shutdown complete' + end + + def self.run(server) + Protobuf::Logger.info "ZmqServer Running" + server_config = case + when server.is_a?(OpenStruct) then + server.marshal_dump + when server.is_a?(Hash) then + server + when server.respond_to?(:to_hash) then + server.to_hash + else + raise "Cannot parser Zmq Server - server options" + end + + Protobuf::Rpc::ZmqServer.run(server_config) + end + end + + end +end diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb new file mode 100644 index 00000000..5aadf603 --- /dev/null +++ b/lib/protobuf/rpc/servers/zmq_server.rb @@ -0,0 +1,65 @@ +require 'protobuf/rpc/server' + +module Protobuf + module Rpc + class ZmqServer + include Protobuf::Rpc::Server + include Protobuf::Logger::LogMethods + + def self.run(opts = {}) + @running = true + host = opts.fetch(:host, "127.0.0.1") + port = opts.fetch(:port, 9399) + + context = ZMQ::Context.new + @socket = context.socket(ZMQ::REP) + @socket.bind("tcp://#{host}:#{port}") + + while running? + + end + end + + def self.running? + @running + end + + def self.stop + @running = false + end + + end + + class Worker + include Protobuf::Rpc::Server + include Protobuf::Logger::LogMethods + + def initialize(sock, &complete_cb) + @did_response = false + @socket = sock + @request = Protobuf::Socketrpc::Request.new + @response = Protobuf::Socketrpc::Response.new + @buffer = Protobuf::Rpc::Buffer.new(:read) + @stats = Protobuf::Rpc::Stat.new(:SERVER, true) + @complete_cb = complete_cb + log_debug "[#{log_signature}] Post init, new read buffer created" + + @socket.recv_string(@buffer.data) + @buffer.size = @buffer.data.size + + log_debug "[#{log_signature}] handling request" + handle_client + end + + def log_signature + @log_signature ||= "server-#{self.class}-#{object_id}" + end + + def send_data(data) + log_debug "[#{log_signature}] sending data : %s" % data + @socket.send_string(data.split("-")[1]) + @complete_cb.call(@socket) + end + end + end +end diff --git a/protobuf.gemspec b/protobuf.gemspec index 7517a70c..6f9db5bb 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -24,8 +24,9 @@ Gem::Specification.new do |s| s.add_dependency 'ffi-rzmq' s.add_development_dependency 'rake' + s.add_development_dependency 'pry' s.add_development_dependency 'rspec' - s.add_development_dependency 'yard', '~> 0.7.4' - s.add_development_dependency 'redcarpet', '~> 1.17.2' - s.add_development_dependency 'simplecov', '~> 0.5.4' + s.add_development_dependency 'yard' + s.add_development_dependency 'redcarpet' + s.add_development_dependency 'simplecov' end diff --git a/spec/helper/server.rb b/spec/helper/server.rb index aea334d7..7e712fc6 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -48,8 +48,11 @@ def initialize(opts = {}) end def start - if @options.server == Protobuf::Rpc::EventedServer + case + when @options.server == Protobuf::Rpc::EventedServer then start_em_server + when @options.server == Protobuf::Rpc::ZmqServer then + start_zmq_server else @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } @sock_server.abort_on_exception = true # Set for testing purposes @@ -63,17 +66,27 @@ def start end end + def start_zmq_server + @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } + Thread.pass until Protobuf::Rpc::ZmqServer.running? + end + def start_em_server @server_handle = EventMachine::start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) end def stop - if @options.server == Protobuf::Rpc::EventedServer + case + when @options.server == Protobuf::Rpc::EventedServer then EventMachine.stop_server(@server_handle) if @server_handle + when @options.server == Protobuf::Rpc::ZmqServer then + Protobuf::Rpc::ZmqRunner.stop + Thread.kill(@zmq_server) if @zmq_server else Protobuf::Rpc::SocketRunner.stop Thread.kill(@sock_server) if @sock_server end + @running = false end end diff --git a/spec/unit/rpc/connectors/socket_spec.rb b/spec/unit/rpc/connectors/socket_spec.rb index 4e7bd335..6753f343 100644 --- a/spec/unit/rpc/connectors/socket_spec.rb +++ b/spec/unit/rpc/connectors/socket_spec.rb @@ -45,5 +45,4 @@ expect{ conn.__send__(:check_async) }.to_not raise_error end end - end From ca55a95843ac9d2825e53791ad68e05b2bf375ce Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 2 Apr 2012 22:51:30 -0600 Subject: [PATCH 0003/1191] Add spec for rpc_failed --- .gitignore | 1 + Gemfile.lock | 1 + spec/unit/rpc/service_spec.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/.gitignore b/.gitignore index 1c987c7e..c6ebb233 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ pkg/* coverage doc .yardoc +.DS_Store diff --git a/Gemfile.lock b/Gemfile.lock index 818cc599..7f552243 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,7 @@ GEM specs: diff-lcs (1.1.3) eventmachine (0.12.10) + eventmachine (0.12.10-java) eventually (0.1.0) json_pure (1.6.4) multi_json (1.0.4) diff --git a/spec/unit/rpc/service_spec.rb b/spec/unit/rpc/service_spec.rb index 4b200f74..2c46e5cb 100644 --- a/spec/unit/rpc/service_spec.rb +++ b/spec/unit/rpc/service_spec.rb @@ -72,4 +72,17 @@ def bad_var end + context 'when using rpc_failed mechanism' do + it 'provides callback registration and invokes block on rpc_failed call' do + expected_error = nil + service = Protobuf::Rpc::Service.new + service.on_rpc_failed do |error| + expected_error = error + end + service.rpc_failed('an error happened') + expected_error.should be_an(Protobuf::Rpc::RpcFailed) + expected_error.message.should eq 'an error happened' + end + end + end \ No newline at end of file From 1c1928e18996493661fe58dc733b2da7c86d0d8c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 2 Apr 2012 23:07:45 -0600 Subject: [PATCH 0004/1191] Update rspec dep. Add rake test and rake spec (default) tasks --- .gitignore | 1 + Gemfile.lock | 18 +++++++++--------- Rakefile | 15 +++++++++++++++ protobuf.gemspec | 6 +++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index c6ebb233..693f0f87 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ coverage doc .yardoc .DS_Store +*.bin diff --git a/Gemfile.lock b/Gemfile.lock index 15ab5a69..88566232 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,14 +17,14 @@ GEM multi_json (1.0.4) rake (0.8.7) redcarpet (1.17.2) - rspec (2.8.0) - rspec-core (~> 2.8.0) - rspec-expectations (~> 2.8.0) - rspec-mocks (~> 2.8.0) - rspec-core (2.8.0) - rspec-expectations (2.8.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.8.0) + rspec (2.9.0) + rspec-core (~> 2.9.0) + rspec-expectations (~> 2.9.0) + rspec-mocks (~> 2.9.0) + rspec-core (2.9.0) + rspec-expectations (2.9.0) + diff-lcs (~> 1.1.3) + rspec-mocks (2.9.0) simplecov (0.5.4) multi_json (~> 1.0.3) simplecov-html (~> 0.5.3) @@ -39,6 +39,6 @@ DEPENDENCIES protobuf! rake (~> 0.8.7) redcarpet (~> 1.17.2) - rspec (~> 2.8.0) + rspec (>= 2.8.0) simplecov (~> 0.5.4) yard (~> 0.7.4) diff --git a/Rakefile b/Rakefile index 97f1c2d5..b4b50bb7 100644 --- a/Rakefile +++ b/Rakefile @@ -3,3 +3,18 @@ $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "bundler/gem_tasks" require "benchmark/tasks" + +require 'rake/testtask' +Rake::TestTask.new(:test) do |test| + test.libs << 'test:.' + test.pattern = 'test/**/test_*.rb' + test.verbose = true +end + +require 'rspec/core/rake_task' + +desc 'Default: run specs.' +task :default => :spec + +desc "Run specs" +RSpec::Core::RakeTask.new(:spec) diff --git a/protobuf.gemspec b/protobuf.gemspec index 3528c0b5..ade07922 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -12,18 +12,18 @@ Gem::Specification.new do |s| s.homepage = %q{https://github.com/localshred/protobuf} s.summary = 'Ruby implementation for Protocol Buffers. Works with other protobuf rpc implementations (e.g. Java, Python, C++).' s.description = s.summary + "\n\nThis gem has diverged from https://github.com/macks/ruby-protobuf. All credit for serialization and rprotoc work most certainly goes to the original authors. All RPC implementation code (client/server/service) was written and is maintained by this author. Attempts to reconcile the original codebase with the current RPC implementation went unsuccessful." - + s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - + s.add_dependency 'eventmachine', '~> 0.12.10' s.add_dependency 'eventually', '~> 0.1.0' s.add_dependency 'json_pure', '~> 1.6.4' s.add_development_dependency 'rake', '~> 0.8.7' - s.add_development_dependency 'rspec', '~> 2.8.0' + s.add_development_dependency 'rspec', '>= 2.8.0' s.add_development_dependency 'yard', '~> 0.7.4' s.add_development_dependency 'redcarpet', '~> 1.17.2' s.add_development_dependency 'simplecov', '~> 0.5.4' From c6cb48cdfefb5607630a9222304f49c3adf39aef Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 6 Apr 2012 02:11:49 -0600 Subject: [PATCH 0005/1191] starting buffer clean up --- Gemfile.lock | 2 + bin/rpc_server | 3 +- lib/protobuf.rb | 4 ++ lib/protobuf/common/logger.rb | 50 +++++++------- lib/protobuf/descriptor/file_descriptor.rb | 2 +- lib/protobuf/rpc/buffer.rb | 17 +++-- lib/protobuf/rpc/connectors/common.rb | 33 +++++---- lib/protobuf/rpc/connectors/zmq.rb | 27 +++++--- lib/protobuf/rpc/server.rb | 19 ++---- lib/protobuf/rpc/servers/zmq_server.rb | 78 ++++++++++++---------- protobuf.gemspec | 1 + spec/benchmark/tasks.rb | 29 +++++++- spec/helper/server.rb | 3 + 13 files changed, 162 insertions(+), 106 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 870b69ca..72090854 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM rspec-expectations (2.9.0) diff-lcs (~> 1.1.3) rspec-mocks (2.9.0) + ruby-prof (0.10.8) simplecov (0.6.1) multi_json (~> 1.0) simplecov-html (~> 0.5.3) @@ -59,5 +60,6 @@ DEPENDENCIES rake redcarpet rspec + ruby-prof simplecov yard diff --git a/bin/rpc_server b/bin/rpc_server index 79f78e3c..e7fa5141 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -6,6 +6,7 @@ require 'logger' require 'protobuf/version' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/rpc/servers/socket_runner' +require 'protobuf/rpc/servers/zmq_runner' # Default options server = OpenStruct.new({ @@ -64,7 +65,7 @@ parser = OptionParser.new do |opts| opts.on("-z", "--zmq", "ZeroMQ Socket Mode for client and server connections (they must be used together)") do |v| Protobuf::ConnectorType = "Zmq" Protobuf::ServerType = "ZmqServer" - server.running = Protobuf::Rpc::ZmqRunner + server.runner = Protobuf::Rpc::ZmqRunner end opts.on("-d", "--[no-]debug", "Debug Mode. Override log level to DEBUG.") do |v| diff --git a/lib/protobuf.rb b/lib/protobuf.rb index fa1c0db0..a60b4f49 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -39,5 +39,9 @@ module Protobuf require 'protobuf/rpc/service' require 'protobuf/rpc/servers/socket_server' + require 'ffi-rzmq' + require 'protobuf/rpc/client' + require 'protobuf/rpc/connectors/zmq' + require 'protobuf/rpc/client' require 'protobuf/rpc/connectors/socket' diff --git a/lib/protobuf/common/logger.rb b/lib/protobuf/common/logger.rb index bb9b0d17..29a6eac3 100644 --- a/lib/protobuf/common/logger.rb +++ b/lib/protobuf/common/logger.rb @@ -5,30 +5,7 @@ class Logger < ::Logger class << self attr_accessor :file, :level - - # One-line file/level configuration - def configure(options) - self.file = options[:file] if options[:file] - self.level = options[:level] if options[:level] - end - - # Use to reset the instance - def reset_device! - self.file = self.level = @__instance = nil - end - - # Singleton instance - def instance - @__instance ||= begin - log = nil - if @file and @level - log = new(self.file) - log.level = self.level - end - log - end - end - + # Stub out the log methods for Protobuf::Logger as singleton methods [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| define_method(m) do |*params, &block| @@ -36,7 +13,31 @@ def instance end end end + + # One-line file/level configuration + def self.configure(options) + self.file = options[:file] if options[:file] + self.level = options[:level] if options[:level] + end + + # Use to reset the instance + def self.reset_device! + self.file = self.level = @__instance = nil + end + + # Singleton instance + def self.instance + @__instance ||= begin + log = nil + if @file and @level + log = new(self.file) + log.level = self.level + end + log + end + end + # # LogMethods module for log method including, e.g.: # @@ -51,6 +52,7 @@ def instance module LogMethods [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| define_method("log_#{m}") do |*params, &block| + return Protobuf::Logger.__send__(m, *params, &block) end end diff --git a/lib/protobuf/descriptor/file_descriptor.rb b/lib/protobuf/descriptor/file_descriptor.rb index b933eb0d..f0d2f17e 100644 --- a/lib/protobuf/descriptor/file_descriptor.rb +++ b/lib/protobuf/descriptor/file_descriptor.rb @@ -1,7 +1,7 @@ module Protobuf module Descriptor class FileDescriptor - class <= 0 end @@ -31,14 +35,15 @@ def check_async end def close_connection - @socket.close + zmq_error_check(@socket.close) + zmq_error_check(@zmq_context.terminate) log_debug "[client-#{self.class}] Connector closed" end def connect_to_rpc_server - zmq_context = ZMQ::Context.new - @socket = zmq_context.socket(ZMQ::REQ) - assert(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) + @zmq_context = ZMQ::Context.new + @socket = @zmq_context.socket(ZMQ::REQ) + zmq_error_check(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) log_debug "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" end @@ -48,15 +53,15 @@ def error? end def read_response - assert(@socket.recv_string(@buffer.data)) - @buffer.size = @buffer.data.size + zmq_error_check(@socket.recv_string(@response_buffer.data)) + @response_buffer.size = @response_buffer.data.size + parse_response end - def send_data(data) - assert(@socket.send_string(data.split("-")[1])) + def send_data + zmq_error_check(@socket.send_string(@request_buffer.data)) log_debug "[client-#{self.class}] write closed" end - end end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 4fba9ef5..3f22f7e7 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -1,4 +1,3 @@ -# require 'protobuf' require 'protobuf/common/logger' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' @@ -11,12 +10,8 @@ module Server # Invoke the service method dictated by the proto wrapper request object def handle_client - @stats.request_size = @buffer.size - - # Setup the initial request and response - @request = Protobuf::Socketrpc::Request.new - @response = Protobuf::Socketrpc::Response.new - + @stats.request_size = @request_buffer.size + # Parse the protobuf request from the socket log_debug "[#{log_signature}] Parsing request from client" parse_request_from_buffer @@ -84,8 +79,8 @@ def log_signature # Parse the incoming request object into our expected request object def parse_request_from_buffer - log_debug "[#{log_signature}] parsing request from buffer: %s" % @buffer.data.inspect - @request.parse_from_string(@buffer.data) + log_debug "[#{log_signature}] parsing request from buffer: %s" % @request_buffer.data.inspect + @request.parse_from_string(@request_buffer.data) rescue => error exc = BadRequestData.new 'Unable to parse request: %s' % error.message log_error exc.message @@ -135,9 +130,9 @@ def parse_service_info def send_response raise 'Response already sent to client' if @did_respond log_debug "[#{log_signature}] Sending response to client: %s" % @response.inspect - response_buffer = Protobuf::Rpc::Buffer.new(:write, @response) - send_data(response_buffer.write) - @stats.response_size = response_buffer.size + @response_buffer.set_data(@response) + send_data + @stats.response_size = @response_buffer.size @stats.end @stats.log_stats @did_respond = true diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb index 5aadf603..b702db00 100644 --- a/lib/protobuf/rpc/servers/zmq_server.rb +++ b/lib/protobuf/rpc/servers/zmq_server.rb @@ -1,4 +1,5 @@ require 'protobuf/rpc/server' +require 'pry' module Protobuf module Rpc @@ -6,59 +7,62 @@ class ZmqServer include Protobuf::Rpc::Server include Protobuf::Logger::LogMethods - def self.run(opts = {}) - @running = true - host = opts.fetch(:host, "127.0.0.1") - port = opts.fetch(:port, 9399) - - context = ZMQ::Context.new - @socket = context.socket(ZMQ::REP) - @socket.bind("tcp://#{host}:#{port}") + def initialize(sock) + @request = Protobuf::Socketrpc::Request.new + @response = Protobuf::Socketrpc::Response.new + @request_buffer = Protobuf::Rpc::Buffer.new(:read) + @response_buffer = Protobuf::Rpc::Buffer.new(:write) + @stats = Protobuf::Rpc::Stat.new(:SERVER, true) + @socket = sock + log_debug "[#{log_signature}] Post init, new read buffer created" - while running? + zmq_error_check(sock.recv_string(@request_buffer.data)) + @request_buffer.size = @request_buffer.data.size - end + log_debug "[#{log_signature}] handling request" + handle_client end - def self.running? - @running + def send_data(data_buffer) + zmq_error_check(@socket.send_string(data_buffer.data)) end - def self.stop - @running = false + def zmq_error_check(return_code) + self.class.zmq_error_check(return_code) end - end - - class Worker - include Protobuf::Rpc::Server - include Protobuf::Logger::LogMethods + def self.zmq_error_check(return_code) + raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + end - def initialize(sock, &complete_cb) - @did_response = false - @socket = sock - @request = Protobuf::Socketrpc::Request.new - @response = Protobuf::Socketrpc::Response.new - @buffer = Protobuf::Rpc::Buffer.new(:read) - @stats = Protobuf::Rpc::Stat.new(:SERVER, true) - @complete_cb = complete_cb - log_debug "[#{log_signature}] Post init, new read buffer created" + def self.run(opts = {}) + host = opts.fetch(:host, "127.0.0.1") + port = opts.fetch(:port, 9399) - @socket.recv_string(@buffer.data) - @buffer.size = @buffer.data.size + @zmq_context ||= ZMQ::Context.new(8) + @socket = @zmq_context.socket(ZMQ::REP) + zmq_error_check(@socket.setsockopt(ZMQ::SNDHWM, 1000)) + zmq_error_check(@socket.setsockopt(ZMQ::RCVHWM, 1000)) + zmq_error_check(@socket.bind("tcp://#{host}:#{port}")) + @running = true - log_debug "[#{log_signature}] handling request" - handle_client + loop do + new(@socket) + end end - def log_signature + def self.log_signature @log_signature ||= "server-#{self.class}-#{object_id}" end - def send_data(data) - log_debug "[#{log_signature}] sending data : %s" % data - @socket.send_string(data.split("-")[1]) - @complete_cb.call(@socket) + def self.running? + @running + end + + def self.stop + @socket.close + @zmq_context.terminate + @running = false end end end diff --git a/protobuf.gemspec b/protobuf.gemspec index 6f9db5bb..dd9a93eb 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |s| s.add_dependency 'json_pure' s.add_dependency 'ffi-rzmq' + s.add_development_dependency 'ruby-prof' s.add_development_dependency 'rake' s.add_development_dependency 'pry' s.add_development_dependency 'rspec' diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 4c50c0e9..bac824fa 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,3 +1,5 @@ +require 'pry' +require 'ruby-prof' require 'benchmark' require 'helper/all' require 'proto/test_service_impl' @@ -88,6 +90,26 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) Thread.kill(em_thread) if em_thread end + def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) + StubServer.new(:port => 9399, :server => Protobuf::Rpc::ZmqServer) do |server| + with_constants "Protobuf::ClientType" => "Zmq" do + client = Spec::Proto::TestService.client(:async => false, :port => 9399) + + benchmark_wrapper(global_bench) do |bench| + bench.report("ZS / ZC") do + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + end + end + end + end + end + + desc "benchmark ZMQ client with ZMQ server" + task :zmq_client_zmq_server, [:number, :length] do |t, args| + args.with_defaults(:number => 1000, :length => 100) + zmq_client_zmq_server(args[:number], args[:length]) + end + desc "benchmark EventMachine client with EventMachine server" task :em_client_em_server, [:number, :length] do |t, args| args.with_defaults(:number => 1000, :length => 100) @@ -117,10 +139,11 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :length => 100) Benchmark.bm(10) do |bench| - em_client_em_server(args[:number], args[:length], bench) - em_client_sock_server(args[:number], args[:length], bench) + zmq_client_zmq_server(args[:number], args[:length], bench) + # em_client_em_server(args[:number], args[:length], bench) + # em_client_sock_server(args[:number], args[:length], bench) sock_client_sock_server(args[:number], args[:length], bench) - sock_client_em_server(args[:number], args[:length], bench) + # sock_client_em_server(args[:number], args[:length], bench) end end end diff --git a/spec/helper/server.rb b/spec/helper/server.rb index 7e712fc6..d8bf98f9 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -1,8 +1,11 @@ +require 'pry' require 'ostruct' require 'protobuf/common/logger' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket_server' require 'protobuf/rpc/servers/socket_runner' +require 'protobuf/rpc/servers/zmq_server' +require 'protobuf/rpc/servers/zmq_runner' require 'spec/proto/test_service_impl' module StubProtobufServerFactory From 0afe029181312bc05cf0cd690050044b959dca0c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 8 Apr 2012 19:38:09 -0600 Subject: [PATCH 0006/1191] working zmq and socket servers with buffers moved to instances --- lib/protobuf.rb | 4 ++ lib/protobuf/rpc/buffer.rb | 17 +++----- lib/protobuf/rpc/connectors/base.rb | 1 - lib/protobuf/rpc/connectors/common.rb | 46 ++++++++------------- lib/protobuf/rpc/connectors/em_client.rb | 13 ++---- lib/protobuf/rpc/connectors/eventmachine.rb | 25 +++++------ lib/protobuf/rpc/connectors/socket.rb | 18 ++++---- lib/protobuf/rpc/connectors/zmq.rb | 16 +++---- lib/protobuf/rpc/server.rb | 6 +-- lib/protobuf/rpc/servers/socket_server.rb | 16 +++---- lib/protobuf/rpc/servers/zmq_server.rb | 24 ++++++++--- spec/helper/server.rb | 4 +- 12 files changed, 88 insertions(+), 102 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index a60b4f49..4b5af4bf 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -45,3 +45,7 @@ module Protobuf require 'protobuf/rpc/client' require 'protobuf/rpc/connectors/socket' + +# set_trace_func proc { |event, file, line, id, binding, classname| +# printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname +# } diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 588fa202..9c6ff33a 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -8,6 +8,8 @@ class Buffer def initialize(mode=:read) @flush = false + @data = "" + @size = 0 self.mode = mode end @@ -38,7 +40,7 @@ def write(force_mode=true) def <<(data) @data << data if reading? - get_data_size + @size = @data.size check_for_flush end end @@ -61,18 +63,9 @@ def flushed? end private - - def get_data_size - if @size.nil? - sliced_size = @data.slice! /^\d+-/ - unless sliced_size.nil? - @size = sliced_size.gsub(/-/, '').to_i - end - end - end - + def check_for_flush - if not @size.nil? and @data.length == @size + if !@size.nil? && @data.length == @size @flush = true end end diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index cb5786d6..79b3660a 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -37,7 +37,6 @@ def send_request def async? !!@options[:async] end - end end end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 007728d9..a6a6d5a9 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -47,8 +47,7 @@ def initialize_stats @stats = Protobuf::Rpc::Stat.new(:CLIENT, true) @stats.server = [@options[:port], @options[:host]] @stats.service = @options[:service].name - @stats.method = @options[:method] - self + @stats.method = @options[:method].to_s rescue => ex fail(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") end @@ -92,45 +91,27 @@ def parse_response end end - # Setup the read buffer for data coming back def post_init - # Setup an object for reponses without callbacks - @data = nil - _send_request unless error? - log_debug "[#{log_signature}] Post init, new read buffer created just sent" + send_data unless error? rescue fail(:RPC_ERROR, 'Connection error: %s' % $!.message) end - # Sends the request to the server, invoked by the connection_completed event - def _send_request - log_debug "[#{log_signature}] Sending Request: %s" % request_wrapper.inspect - @stats.request_size = @request_buffer.size - send_data - end - def request_wrapper - wrapper = Protobuf::Socketrpc::Request.new - wrapper.service_name = @options[:service].name - wrapper.method_name = @options[:method].to_s - - if @options[:request].class == @options[:request_type] - wrapper.request_proto = @options[:request].serialize_to_string - else - expected = @options[:request_type].name - actual = @options[:request].class.name - fail :INVALID_REQUEST_PROTO, 'Expected request type to be type of %s, got %s instead' % [expected, actual] - end + validate_request_type - return wrapper + return Protobuf::Socketrpc::Request.new( + :service_name => @options[:service].name, + :method_name => @options[:method].to_s, + :request_proto => @options[:request].serialize_to_string + ) end def setup_connection initialize_stats - wrapper = request_wrapper @response_buffer = Protobuf::Rpc::Buffer.new(:read) @request_buffer = Protobuf::Rpc::Buffer.new(:write) - @request_buffer.set_data(wrapper) + @request_buffer.set_data(request_wrapper) end def succeed(response) @@ -144,6 +125,14 @@ def succeed(response) complete end + def validate_request_type + unless @options[:request].class == @options[:request_type] + expected = @options[:request_type].name + actual = @options[:request].class.name + fail :INVALID_REQUEST_PROTO, 'Expected request type to be type of %s, got %s instead' % [expected, actual] + end + end + def verify_callbacks if !any_callbacks? log_debug "[#{log_signature}] No callbacks set, using data_callback" @@ -157,7 +146,6 @@ def verify_options fail(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? end end - end end end diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index eb7c5cfe..54956ce9 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -10,14 +10,10 @@ class EMClient < EM::Connection attr_reader :options, :request, :response attr_reader :error, :error_reason, :error_message - class << self - - def connect(options={}) - options = DEFAULT_OPTIONS.merge(options) - log_debug "[client-#{self}] Connecting to server: %s" % options.inspect - EM.connect(options[:host], options[:port], self, options) - end - + def self.connect(options={}) + options = DEFAULT_OPTIONS.merge(options) + log_debug "[client-#{self}] Connecting to server: %s" % options.inspect + EM.connect(options[:host], options[:port], self, options) end def initialize(options={}, &failure_cb) @@ -51,7 +47,6 @@ def receive_data(data) @buffer << data parse_response if @buffer.flushed? end - end end end diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index 99f61df8..11d1c088 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -41,10 +41,10 @@ def log_signature def ensure_em_running(&blk) if EM.reactor_running? - @global_reactor = true + @using_global_reactor = true yield else - @global_reactor = false + @using_global_reactor = false EM.fiber_run do blk.call EM.stop @@ -56,32 +56,27 @@ def resume_fiber(fib) EM::cancel_timer(@timeout_timer) fib.resume(true) rescue => ex - log_error "[#{log_signature}] An exception occurred while waiting for server response:" - log_error ex.message - log_error ex.backtrace.join("\n") - message = 'Synchronous client failed: %s' % ex.message - err = Protobuf::Rpc::ClientError.new(Protobuf::Socketrpc::ErrorReason::RPC_ERROR, message) - ensure_cb.call(err) - EM.stop if !@global_reactor + error_stop_reactor(message) end def set_timeout_and_validate_fiber @timeout_timer = EM::add_timer(@options[:timeout]) do message = 'Client timeout of %d seconds expired' % @options[:timeout] - err = Protobuf::Rpc::ClientError.new(Protobuf::Socketrpc::ErrorReason::RPC_ERROR, message) - ensure_cb.call(err) - EM.stop if !@global_reactor + error_stop_reactor(message) end Fiber.yield rescue FiberError message = "Synchronous calls must be in 'EM.fiber_run' block" + error_stop_reactor(message) + end + + def error_stop_reactor(message) err = Protobuf::Rpc::ClientError.new(Protobuf::Socketrpc::ErrorReason::RPC_ERROR, message) ensure_cb.call(err) - EM.stop if !@global_reactor - end - + EM.stop unless @using_global_reactor + end end end end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 3346384a..a8038467 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -9,9 +9,9 @@ class Socket < Base def send_request check_async - initialize_stats + setup_connection connect_to_rpc_server - post_init # calls _send_request + post_init read_response end @@ -21,9 +21,7 @@ def check_async if async? log_error "[client-#{self.class}] Cannot run in async mode" raise "Cannot use Socket client in async mode" - else - log_debug "[client-#{self.class}] Async check passed" - end + end end def close_connection @@ -50,16 +48,16 @@ def read_data end str_size_io = size_io.string - "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" + "#{@socket.read(str_size_io.to_i)}" end def read_response - @buffer << read_data - parse_response if @buffer.flushed? + @response_buffer << read_data + parse_response if @response_buffer.flushed? end - def send_data(data) - @socket.write(data) + def send_data + @socket.write(@request_buffer.size_prefixed_data) @socket.flush log_debug "[client-#{self.class}] write closed" end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 120c858f..d9ac0983 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -6,12 +6,12 @@ module Connectors class Zmq < Base include Protobuf::Rpc::Connectors::Common include Protobuf::Logger::LogMethods - + def send_request check_async setup_connection connect_to_rpc_server - post_init # calls _send_request + post_init read_response ensure @socket.close if @socket @@ -21,16 +21,10 @@ def send_request private - def zmq_error_check(return_code) - raise "Last API call failed at #{caller(1)}" unless return_code >= 0 - end - def check_async if async? log_error "[client-#{self.class}] Cannot run in async mode" raise "Cannot use Zmq client in async mode" - else - log_debug "[client-#{self.class}] Async check passed" end end @@ -59,9 +53,15 @@ def read_response end def send_data + log_debug "[#{log_signature}] Sending Request: %s" % @request_buffer.data + @stats.request_size = @request_buffer.size zmq_error_check(@socket.send_string(@request_buffer.data)) log_debug "[client-#{self.class}] write closed" end + + def zmq_error_check(return_code) + raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + end end end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 3f22f7e7..f47548e4 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -9,7 +9,7 @@ module Rpc module Server # Invoke the service method dictated by the proto wrapper request object - def handle_client + def handle_client(check=false) @stats.request_size = @request_buffer.size # Parse the protobuf request from the socket @@ -25,6 +25,7 @@ def handle_client invoke_rpc_method rescue => error # Ensure we're handling any errors that try to slip out the back door + binding.pry if check log_error error.message log_error error.backtrace.join("\n") handle_error(error) @@ -144,9 +145,6 @@ def serialize_response(response) rescue raise BadResponseProto, $!.message end - end - end - end diff --git a/lib/protobuf/rpc/servers/socket_server.rb b/lib/protobuf/rpc/servers/socket_server.rb index d7b5ea60..d8d3c2f2 100644 --- a/lib/protobuf/rpc/servers/socket_server.rb +++ b/lib/protobuf/rpc/servers/socket_server.rb @@ -6,7 +6,6 @@ class SocketServer include Protobuf::Rpc::Server include Protobuf::Logger::LogMethods - def self.cleanup? # every 10 connections run a cleanup routine after closing the response @threads.size > (@thread_threshold - 1) && (@threads.size % @thread_threshold) == 0 @@ -108,15 +107,16 @@ def initialize(sock, &complete_cb) @socket = sock @request = Protobuf::Socketrpc::Request.new @response = Protobuf::Socketrpc::Response.new - @buffer = Protobuf::Rpc::Buffer.new(:read) + @response_buffer = Protobuf::Rpc::Buffer.new(:write) + @request_buffer = Protobuf::Rpc::Buffer.new(:read) @stats = Protobuf::Rpc::Stat.new(:SERVER, true) @complete_cb = complete_cb log_debug "[#{log_signature}] Post init, new read buffer created" @stats.client = Socket.unpack_sockaddr_in(@socket.getpeername) - @buffer << read_data + @request_buffer << read_data log_debug "[#{log_signature}] handling request" - handle_client if @buffer.flushed? + handle_client(true) if @request_buffer.flushed? end def log_signature @@ -131,12 +131,12 @@ def read_data end str_size_io = size_io.string - "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" + "#{@socket.read(str_size_io.to_i)}" end - def send_data(data) - log_debug "[#{log_signature}] sending data : %s" % data - @socket.write(data) + def send_data + log_debug "[#{log_signature}] sending data : %s" % @response_buffer.size_prefixed_data + @socket.write(@response_buffer.size_prefixed_data) @socket.flush @complete_cb.call(@socket) end diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb index b702db00..f07c441b 100644 --- a/lib/protobuf/rpc/servers/zmq_server.rb +++ b/lib/protobuf/rpc/servers/zmq_server.rb @@ -1,5 +1,4 @@ require 'protobuf/rpc/server' -require 'pry' module Protobuf module Rpc @@ -16,15 +15,15 @@ def initialize(sock) @socket = sock log_debug "[#{log_signature}] Post init, new read buffer created" - zmq_error_check(sock.recv_string(@request_buffer.data)) + zmq_error_check(@socket.recv_string(@request_buffer.data)) @request_buffer.size = @request_buffer.data.size log_debug "[#{log_signature}] handling request" handle_client end - def send_data(data_buffer) - zmq_error_check(@socket.send_string(data_buffer.data)) + def send_data + zmq_error_check(@socket.send_string(@response_buffer.data)) end def zmq_error_check(return_code) @@ -39,11 +38,26 @@ def self.run(opts = {}) host = opts.fetch(:host, "127.0.0.1") port = opts.fetch(:port, 9399) - @zmq_context ||= ZMQ::Context.new(8) + @zmq_context ||= ZMQ::Context.new @socket = @zmq_context.socket(ZMQ::REP) zmq_error_check(@socket.setsockopt(ZMQ::SNDHWM, 1000)) zmq_error_check(@socket.setsockopt(ZMQ::RCVHWM, 1000)) zmq_error_check(@socket.bind("tcp://#{host}:#{port}")) + +# @frontend = @zmq_context.socket(ZMQ::ROUTER) +# zmq_error_check(@frontend.setsockopt(ZMQ::SNDHWM, 1000)) +# zmq_error_check(@frontend.setsockopt(ZMQ::RCVHWM, 1000)) +# zmq_error_check(@frontend.bind("tcp://#{host}:#{port}")) +# +# @backend = @zmq_context.socket(ZMQ::DEALER) +# zmq_error_check(@backend.setsockopt(ZMQ::SNDHWM, 1000)) +# zmq_error_check(@backend.setsockopt(ZMQ::RCVHWM, 1000)) +# zmq_error_check(@backend.bind("tcp://#{host}:#{port + 1}")) +# +# @frontend.identity = "frontend" +# @backend.identity = "backend" +# +# @poller = ZMQ::Poller.new @running = true loop do diff --git a/spec/helper/server.rb b/spec/helper/server.rb index d8bf98f9..dda70c78 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -1,4 +1,3 @@ -require 'pry' require 'ostruct' require 'protobuf/common/logger' require 'protobuf/rpc/server' @@ -8,6 +7,9 @@ require 'protobuf/rpc/servers/zmq_runner' require 'spec/proto/test_service_impl' +# Want to abort if server dies? +# Thread.abort_on_exception = true + module StubProtobufServerFactory def self.build(delay) new_server = Class.new(Protobuf::Rpc::EventedServer) do From 873094c3d30a8bdcbd9212d83fcee3d36021ffc9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 16 May 2012 11:24:38 -0600 Subject: [PATCH 0007/1191] clean up the socket protobuf server/client for new buffer design --- bin/rpc_server | 28 ++-- lib/protobuf.rb | 8 +- lib/protobuf/common/logger.rb | 11 +- lib/protobuf/rpc/error.rb | 3 +- lib/protobuf/rpc/error/client_error.rb | 8 +- lib/protobuf/rpc/server.rb | 37 +++--- lib/protobuf/rpc/servers/evented_server.rb | 11 +- lib/protobuf/rpc/servers/socket_server.rb | 28 ++-- lib/protobuf/rpc/servers/zmq_server.rb | 145 ++++++++++++++------- spec/benchmark/tasks.rb | 4 +- spec/helper/server.rb | 26 ++-- 11 files changed, 178 insertions(+), 131 deletions(-) diff --git a/bin/rpc_server b/bin/rpc_server index e7fa5141..e4b6f10f 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -18,7 +18,7 @@ server = OpenStruct.new({ :threshold => 100, :log => File.expand_path('./protobuf.log'), :level => ::Logger::INFO, - :runner => Protobuf::Rpc::EventedRunner, + :runner => ::Protobuf::Rpc::EventedRunner, :debug => false }) @@ -54,18 +54,18 @@ parser = OptionParser.new do |opts| end opts.on("-c", "--client_socket", "Socket Mode for client connections (No EventMachine)") do |v| - Protobuf::ConnectorType = "Socket" + ::Protobuf::ClientType = "Socket" end opts.on("-s", "--socket", "Socket Server Mode (No EventMachine)") do |v| - Protobuf::ServerType = "SocketServer" - server.runner = Protobuf::Rpc::SocketRunner + ::Protobuf::ServerType = "Socket" + server.runner = ::Protobuf::Rpc::SocketRunner end opts.on("-z", "--zmq", "ZeroMQ Socket Mode for client and server connections (they must be used together)") do |v| - Protobuf::ConnectorType = "Zmq" - Protobuf::ServerType = "ZmqServer" - server.runner = Protobuf::Rpc::ZmqRunner + ::Protobuf::ClientType = "Zmq" + ::Protobuf::ServerType = "Zmq" + server.runner = ::Protobuf::Rpc::ZmqRunner end opts.on("-d", "--[no-]debug", "Debug Mode. Override log level to DEBUG.") do |v| @@ -82,7 +82,7 @@ parser = OptionParser.new do |opts| end opts.on_tail("--version", "Show version") do - puts Protobuf::VERSION + puts ::Protobuf::VERSION exit end end @@ -106,12 +106,12 @@ begin raise 'Invalid app file specified (%s).' % server.app unless File.exists?(server.app) end - # Configure the Protobuf::Logger - Protobuf::Logger.configure :file => server.log, :level => server.debug ? ::Logger::DEBUG : server.level + # Configure the ::Protobuf::Logger + ::Protobuf::Logger.configure :file => server.log, :level => server.debug ? ::Logger::DEBUG : server.level # Output the server opts - Protobuf::Logger.debug 'Debugging options:' - Protobuf::Logger.debug server.inspect + ::Protobuf::Logger.debug 'Debugging options:' + ::Protobuf::Logger.debug server.inspect # Set the name of the process $0 = 'rpc_server %s:%d %s' % [server.host, server.port, server.app] @@ -123,7 +123,7 @@ begin rescue msg = 'ERROR: RPC Server failed to start. %s' % $!.inspect $stderr.puts msg, *($!.backtrace) - Protobuf::Logger.error msg - Protobuf::Logger.error $!.backtrace.join("\n") + ::Protobuf::Logger.error msg + ::Protobuf::Logger.error $!.backtrace.join("\n") exit 1 end diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 4b5af4bf..df225b10 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -11,7 +11,9 @@ module Protobuf # When setting up a client case -when defined?(Protobuf::ClientType) && Protobuf::ClientType == "Zmq" then +when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Asocket\Z/i then + #no-op +when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Azmq\Z/i then require 'ffi-rzmq' require 'protobuf/rpc/client' require 'protobuf/rpc/connectors/zmq' @@ -24,7 +26,9 @@ module Protobuf # For running the rpc_server case -when defined?(Protobuf::ServerType) && Protobuf::ServerType == "ZmqServer" then +when defined?(Protobuf::ServerType) && Protobuf::ServerType =~ /\Asocket\Z/i then + #no-op +when defined?(Protobuf::ServerType) && Protobuf::ServerType =~ /\Azmq\Z/i then require 'ffi-rzmq' require 'protobuf/rpc/service' require 'protobuf/rpc/servers/zmq_server' diff --git a/lib/protobuf/common/logger.rb b/lib/protobuf/common/logger.rb index 29a6eac3..b53e7746 100644 --- a/lib/protobuf/common/logger.rb +++ b/lib/protobuf/common/logger.rb @@ -16,8 +16,8 @@ class << self # One-line file/level configuration def self.configure(options) - self.file = options[:file] if options[:file] - self.level = options[:level] if options[:level] + self.file = options.fetch(:file, false) + self.level = options.fetch(:level, false) end # Use to reset the instance @@ -29,15 +29,16 @@ def self.reset_device! def self.instance @__instance ||= begin log = nil - if @file and @level + + if @file && @level log = new(self.file) log.level = self.level end + log end end - # # LogMethods module for log method including, e.g.: # @@ -52,7 +53,6 @@ def self.instance module LogMethods [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| define_method("log_#{m}") do |*params, &block| - return Protobuf::Logger.__send__(m, *params, &block) end end @@ -61,6 +61,5 @@ def self.included(base) base.extend(LogMethods) end end - end end diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index c8c6b235..bf4a490d 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -9,7 +9,7 @@ class PbError < StandardError attr_reader :error_type def initialize message='An unknown RpcError occurred', error_type='RPC_ERROR' - @error_type = error_type.is_a?(String) ? Protobuf::Socketrpc::ErrorReason.const_get(error_type) : error_type + @error_type = error_type.is_a?(String) ? ::Protobuf::Socketrpc::ErrorReason.const_get(error_type) : error_type super message end @@ -18,7 +18,6 @@ def to_response response response.error_reason = @error_type end end - end end diff --git a/lib/protobuf/rpc/error/client_error.rb b/lib/protobuf/rpc/error/client_error.rb index 15a41aba..5b65ed3b 100644 --- a/lib/protobuf/rpc/error/client_error.rb +++ b/lib/protobuf/rpc/error/client_error.rb @@ -4,25 +4,25 @@ module Protobuf module Rpc class InvalidRequestProto < PbError - def initialize message='Invalid request type given' + def initialize(message='Invalid request type given') super message, 'INVALID_REQUEST_PROTO' end end class BadResponseProto < PbError - def initialize message='Bad response type from server' + def initialize(message='Bad response type from server') super message, 'BAD_RESPONSE_PROTO' end end class UnkownHost < PbError - def initialize message='Unknown host or port' + def initialize(message='Unknown host or port') super message, 'UNKNOWN_HOST' end end class IOError < PbError - def initialize message='IO Error occurred' + def initialize(message='IO Error occurred') super message, 'IO_ERROR' end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index f47548e4..c20b1163 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -9,38 +9,37 @@ module Rpc module Server # Invoke the service method dictated by the proto wrapper request object - def handle_client(check=false) + def handle_client @stats.request_size = @request_buffer.size # Parse the protobuf request from the socket - log_debug "[#{log_signature}] Parsing request from client" + log_debug { "[#{log_signature}] Parsing request from client" } parse_request_from_buffer # Determine the service class and method name from the request - log_debug "[#{log_signature}] Extracting procedure call info from request" + log_debug { "[#{log_signature}] Extracting procedure call info from request" } parse_service_info # Call the service method - log_debug "[#{log_signature}] Dispatching client request to service" + log_debug { "[#{log_signature}] Dispatching client request to service" } invoke_rpc_method rescue => error # Ensure we're handling any errors that try to slip out the back door - binding.pry if check - log_error error.message - log_error error.backtrace.join("\n") + log_error(error.message) + log_error(error.backtrace.join("\n")) handle_error(error) send_response end # Client error handler. Receives an exception object and writes it into the @response def handle_error(error) - log_debug "[#{log_signature}] handle_error: %s" % error.inspect + log_debug { "[#{log_signature}] handle_error: %s" % error.inspect } if error.respond_to?(:to_response) error.to_response(@response) else message = error.respond_to?(:message) ? error.message : error.to_s code = error.respond_to?(:code) ? error.code.to_s : "RPC_ERROR" - PbError.new(message, code).to_response(@response) + ::Protobuf::Rpc::PbError.new(message, code).to_response(@response) end end @@ -70,7 +69,7 @@ def invoke_rpc_method end # Call the service method - log_debug "[#{log_signature}] Invoking %s#%s with request %s" % [@klass.name, @method, @request.inspect] + log_debug { "[#{log_signature}] Invoking %s#%s with request %s" % [@klass.name, @method, @request.inspect] } @service.__send__(@method, @request) end @@ -80,11 +79,11 @@ def log_signature # Parse the incoming request object into our expected request object def parse_request_from_buffer - log_debug "[#{log_signature}] parsing request from buffer: %s" % @request_buffer.data.inspect + log_debug { "[#{log_signature}] parsing request from buffer: %s" % @request_buffer.data.inspect } @request.parse_from_string(@request_buffer.data) rescue => error - exc = BadRequestData.new 'Unable to parse request: %s' % error.message - log_error exc.message + exc = ::Protobuf::Rpc::BadRequestData.new 'Unable to parse request: %s' % error.message + log_error { exc.message } raise exc end @@ -97,14 +96,14 @@ def parse_response_from_service(response) # Cannibalize the response if it's a Hash response = expected.new(response) if response.is_a?(Hash) actual = response.class - log_debug "[#{log_signature}] response (should/actual): %s/%s" % [expected.name, actual.name] + log_debug { "[#{log_signature}] response (should/actual): %s/%s" % [expected.name, actual.name] } # Determine if the service tried to change response types on us if expected == actual serialize_response(response) else # response types do not match, throw the appropriate error - raise BadResponseProto, 'Response proto changed from %s to %s' % [expected.name, actual.name] + raise ::Protobuf::Rpc::BadResponseProto, 'Response proto changed from %s to %s' % [expected.name, actual.name] end rescue => error log_error error.message @@ -114,8 +113,8 @@ def parse_response_from_service(response) # Parses and returns the service and method name from the request wrapper proto def parse_service_info - @klass = Util.constantize(@request.service_name) - @method = Util.underscore(@request.method_name).to_sym + @klass = ::Protobuf::Util.constantize(@request.service_name) + @method = ::Protobuf::Util.underscore(@request.method_name).to_sym unless @klass.instance_methods.include?(@method) raise MethodNotFound, "Service method #{@request.method_name} is not defined by the service" @@ -130,7 +129,7 @@ def parse_service_info # Write the response wrapper to the client def send_response raise 'Response already sent to client' if @did_respond - log_debug "[#{log_signature}] Sending response to client: %s" % @response.inspect + log_debug { "[#{log_signature}] Sending response to client: %s" % @response.inspect } @response_buffer.set_data(@response) send_data @stats.response_size = @response_buffer.size @@ -140,7 +139,7 @@ def send_response end def serialize_response(response) - log_debug "[#{log_signature}] serializing response: %s" % response.inspect + log_debug { "[#{log_signature}] serializing response: %s" % response.inspect } @response.response_proto = response.serialize_to_string rescue raise BadResponseProto, $!.message diff --git a/lib/protobuf/rpc/servers/evented_server.rb b/lib/protobuf/rpc/servers/evented_server.rb index d34c8108..4fa41af3 100644 --- a/lib/protobuf/rpc/servers/evented_server.rb +++ b/lib/protobuf/rpc/servers/evented_server.rb @@ -2,13 +2,13 @@ module Protobuf module Rpc - class EventedServer < EventMachine::Connection - include Protobuf::Rpc::Server - include Protobuf::Logger::LogMethods + class EventedServer < ::EventMachine::Connection + include ::Protobuf::Rpc::Server + include ::Protobuf::Logger::LogMethods # Initialize a new read buffer for storing client request info def post_init - log_debug '[server] Post init, new read buffer created' + log_debug { '[server] Post init, new read buffer created' } @stats = Protobuf::Rpc::Stat.new(:SERVER, true) @stats.client = Socket.unpack_sockaddr_in(get_peername) @@ -18,11 +18,10 @@ def post_init # Receive a chunk of data, potentially flushed to handle_client def receive_data(data) - log_debug '[server] receive_data: %s' % data + log_debug { '[server] receive_data: %s' % data } @buffer << data handle_client if @buffer.flushed? end - end end end diff --git a/lib/protobuf/rpc/servers/socket_server.rb b/lib/protobuf/rpc/servers/socket_server.rb index d8d3c2f2..97eaedfa 100644 --- a/lib/protobuf/rpc/servers/socket_server.rb +++ b/lib/protobuf/rpc/servers/socket_server.rb @@ -3,8 +3,8 @@ module Protobuf module Rpc class SocketServer - include Protobuf::Rpc::Server - include Protobuf::Logger::LogMethods + include ::Protobuf::Rpc::Server + include ::Protobuf::Logger::LogMethods def self.cleanup? # every 10 connections run a cleanup routine after closing the response @@ -12,7 +12,7 @@ def self.cleanup? end def self.cleanup_threads - log_debug "[#{log_signature}] Thread cleanup - #{@threads.size} - start" + log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - start" } @threads = @threads.select do |t| if t[:thread].alive? @@ -24,7 +24,7 @@ def self.cleanup_threads end end - log_debug "[#{log_signature}] Thread cleanup - #{@threads.size} - complete" + log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - complete" } end def self.log_signature @@ -33,7 +33,7 @@ def self.log_signature def self.new_worker(socket) Thread.new(socket) do |sock| - Protobuf::Rpc::SocketServer::Worker.new(sock) do |s| + ::Protobuf::Rpc::SocketServer::Worker.new(sock) do |s| s.close end end @@ -47,16 +47,16 @@ def self.run(opts = {}) thread_threshold = opts.fetch(:thread_threshold, 100) auto_collect_timeout = opts.fetch(:auto_collect_timeout, 20) - @running = true @threads = [] @thread_threshold = thread_threshold - @server = TCPServer.new(host, port) + @server = ::TCPServer.new(host, port) @server.listen(backlog) @working = [] @listen_fds = [@server] + @running = true while running? - log_debug "[#{log_signature}] Waiting for connections" + log_debug { "[#{log_signature}] Waiting for connections" } if ready_cnxns = IO.select(@listen_fds, [], [], auto_collect_timeout) cnxns = ready_cnxns.first @@ -99,8 +99,8 @@ def self.stop end class Worker - include Protobuf::Rpc::Server - include Protobuf::Logger::LogMethods + include ::Protobuf::Rpc::Server + include ::Protobuf::Logger::LogMethods def initialize(sock, &complete_cb) @did_response = false @@ -111,12 +111,12 @@ def initialize(sock, &complete_cb) @request_buffer = Protobuf::Rpc::Buffer.new(:read) @stats = Protobuf::Rpc::Stat.new(:SERVER, true) @complete_cb = complete_cb - log_debug "[#{log_signature}] Post init, new read buffer created" + log_debug { "[#{log_signature}] Post init, new read buffer created" } @stats.client = Socket.unpack_sockaddr_in(@socket.getpeername) @request_buffer << read_data - log_debug "[#{log_signature}] handling request" - handle_client(true) if @request_buffer.flushed? + log_debug { "[#{log_signature}] handling request" } + handle_client if @request_buffer.flushed? end def log_signature @@ -135,7 +135,7 @@ def read_data end def send_data - log_debug "[#{log_signature}] sending data : %s" % @response_buffer.size_prefixed_data + log_debug { "[#{log_signature}] sending data : %s" % @response_buffer.size_prefixed_data } @socket.write(@response_buffer.size_prefixed_data) @socket.flush @complete_cb.call(@socket) diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb index f07c441b..e427f640 100644 --- a/lib/protobuf/rpc/servers/zmq_server.rb +++ b/lib/protobuf/rpc/servers/zmq_server.rb @@ -3,32 +3,7 @@ module Protobuf module Rpc class ZmqServer - include Protobuf::Rpc::Server - include Protobuf::Logger::LogMethods - - def initialize(sock) - @request = Protobuf::Socketrpc::Request.new - @response = Protobuf::Socketrpc::Response.new - @request_buffer = Protobuf::Rpc::Buffer.new(:read) - @response_buffer = Protobuf::Rpc::Buffer.new(:write) - @stats = Protobuf::Rpc::Stat.new(:SERVER, true) - @socket = sock - log_debug "[#{log_signature}] Post init, new read buffer created" - - zmq_error_check(@socket.recv_string(@request_buffer.data)) - @request_buffer.size = @request_buffer.data.size - - log_debug "[#{log_signature}] handling request" - handle_client - end - - def send_data - zmq_error_check(@socket.send_string(@response_buffer.data)) - end - - def zmq_error_check(return_code) - self.class.zmq_error_check(return_code) - end + include ::Protobuf::Logger::LogMethods def self.zmq_error_check(return_code) raise "Last API call failed at #{caller(1)}" unless return_code >= 0 @@ -37,31 +12,50 @@ def self.zmq_error_check(return_code) def self.run(opts = {}) host = opts.fetch(:host, "127.0.0.1") port = opts.fetch(:port, 9399) + protocol = opts.fetch(:protocol, "tcp") + local_worker_threads = opts.fetch(:threads, 10) + + @zmq_context = ::ZMQ::Context.new + @frontend = @zmq_context.socket(::ZMQ::ROUTER) + zmq_error_check(@frontend.bind("#{protocol}://#{host}:#{port}")) + + dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) + dealer_host = dealer_options.fetch(:host, "127.0.0.1") + dealer_port = dealer_options.fetch(:port, 9400) + dealer_protocol = dealer_options.fetch(:protocol, "tcp") + @backend = @zmq_context.socket(::ZMQ::DEALER) + zmq_error_check(@backend.bind("#{dealer_protocol}://#{dealer_host}:#{dealer_port}")) - @zmq_context ||= ZMQ::Context.new - @socket = @zmq_context.socket(ZMQ::REP) - zmq_error_check(@socket.setsockopt(ZMQ::SNDHWM, 1000)) - zmq_error_check(@socket.setsockopt(ZMQ::RCVHWM, 1000)) - zmq_error_check(@socket.bind("tcp://#{host}:#{port}")) - -# @frontend = @zmq_context.socket(ZMQ::ROUTER) -# zmq_error_check(@frontend.setsockopt(ZMQ::SNDHWM, 1000)) -# zmq_error_check(@frontend.setsockopt(ZMQ::RCVHWM, 1000)) -# zmq_error_check(@frontend.bind("tcp://#{host}:#{port}")) -# -# @backend = @zmq_context.socket(ZMQ::DEALER) -# zmq_error_check(@backend.setsockopt(ZMQ::SNDHWM, 1000)) -# zmq_error_check(@backend.setsockopt(ZMQ::RCVHWM, 1000)) -# zmq_error_check(@backend.bind("tcp://#{host}:#{port + 1}")) -# -# @frontend.identity = "frontend" -# @backend.identity = "backend" -# -# @poller = ZMQ::Poller.new + @poller = ::ZMQ::Poller.new + @poller.register(@frontend, ::ZMQ::POLLIN) + @poller.register(@backend, ::ZMQ::POLLIN) + + @threads = [] + local_worker_threads.times do + @threads << Thread.new(dealer_options) { |options| ZmqWorker.new(options).run } + end @running = true - loop do - new(@socket) + while @running do + @poller.poll(:blocking) + @poller.readables.each do |socket| + more = true + + case socket + when @frontend then + while more do + socket.recv_string(message = '') + more = socket.more_parts? + @backend.send_string(message, more ? ::ZMQ::SNDMORE : 0) + end + when @backend then + while more do + socket.recv_string(message = '') + more = socket.more_parts? + @frontend.send_string(message, more ? ::ZMQ::SNDMORE : 0) + end + end + end end end @@ -74,9 +68,62 @@ def self.running? end def self.stop + @threads.map{ |t| t.join } + @running = false + end + end + + class ZmqWorker + include ::Protobuf::Rpc::Server + include ::Protobuf::Logger::LogMethods + + def initialize(options) + @options = options + host = @options.fetch(:host, "127.0.0.1") + port = @options.fetch(:port, 9400) + protocol = @options.fetch(:protocol, "tcp") + @zmq_context = ::ZMQ::Context.new + @socket = @zmq_context.socket(::ZMQ::REP) + zmq_error_check(@socket.connect("#{protocol}://#{host}:#{port}")) + end + + def self.zmq_error_check(return_code) + raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + end + + def run + loop do + initialize_buffers + handle_request + handle_client + end + ensure @socket.close @zmq_context.terminate - @running = false + end + + def handle_request + zmq_error_check(@socket.recv_string(@request_buffer.data)) + @request_buffer.size = @request_buffer.data.size + log_debug { "[#{log_signature}] handling request" } + end + + def initialize_buffers + @did_respond = false + @request = ::Protobuf::Socketrpc::Request.new + @response = ::Protobuf::Socketrpc::Response.new + @request_buffer = ::Protobuf::Rpc::Buffer.new(:read) + @response_buffer = ::Protobuf::Rpc::Buffer.new(:write) + @stats = ::Protobuf::Rpc::Stat.new(:SERVER, true) + log_debug { "[#{log_signature}] Post init, new read buffer created" } + end + + def send_data + zmq_error_check(@socket.send_string(@response_buffer.data)) + end + + def zmq_error_check(return_code) + self.class.zmq_error_check(return_code) end end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index bac824fa..7d8f901b 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,5 +1,3 @@ -require 'pry' -require 'ruby-prof' require 'benchmark' require 'helper/all' require 'proto/test_service_impl' @@ -139,7 +137,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :length => 100) Benchmark.bm(10) do |bench| - zmq_client_zmq_server(args[:number], args[:length], bench) + # zmq_client_zmq_server(args[:number], args[:length], bench) # em_client_em_server(args[:number], args[:length], bench) # em_client_sock_server(args[:number], args[:length], bench) sock_client_sock_server(args[:number], args[:length], bench) diff --git a/spec/helper/server.rb b/spec/helper/server.rb index dda70c78..48c19080 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -8,7 +8,7 @@ require 'spec/proto/test_service_impl' # Want to abort if server dies? -# Thread.abort_on_exception = true +Thread.abort_on_exception = true module StubProtobufServerFactory def self.build(delay) @@ -54,14 +54,10 @@ def initialize(opts = {}) def start case - when @options.server == Protobuf::Rpc::EventedServer then - start_em_server - when @options.server == Protobuf::Rpc::ZmqServer then - start_zmq_server + when @options.server == Protobuf::Rpc::EventedServer then start_em_server + when @options.server == Protobuf::Rpc::ZmqServer then start_zmq_server else - @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } - @sock_server.abort_on_exception = true # Set for testing purposes - Thread.pass until Protobuf::Rpc::SocketServer.running? + start_socket_server end log_debug "[stub-server] Server started #{@options.host}:#{@options.port}" rescue => ex @@ -71,15 +67,21 @@ def start end end + def start_em_server + @server_handle = EventMachine::start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) + end + + def start_socket_server + @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } + @sock_server.abort_on_exception = true # Set for testing purposes + Thread.pass until Protobuf::Rpc::SocketServer.running? + end + def start_zmq_server @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } Thread.pass until Protobuf::Rpc::ZmqServer.running? end - def start_em_server - @server_handle = EventMachine::start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) - end - def stop case when @options.server == Protobuf::Rpc::EventedServer then From d083a0973230fe82e154885537418d82eca11aeb Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 16 May 2012 14:06:30 -0600 Subject: [PATCH 0008/1191] log messages as blocks instead of strings --- lib/protobuf/rpc/connectors/common.rb | 28 +++++++++++++-------------- lib/protobuf/rpc/connectors/zmq.rb | 10 +++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index a6a6d5a9..bef89003 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -14,16 +14,16 @@ def any_callbacks? def complete @stats.end @stats.log_stats - log_debug "[#{log_signature}] Response proceessing complete" + log_debug { "[#{log_signature}] Response proceessing complete" } @complete_cb.call(self) unless @complete_cb.nil? rescue - log_error "[#{log_signature}] Complete callback error encountered: %s" % $!.message - log_error "[#{log_signature}] %s" % $!.backtrace.join("\n") + log_error { "[#{log_signature}] Complete callback error encountered: %s" % $!.message } + log_error { "[#{log_signature}] %s" % $!.backtrace.join("\n") } raise end def data_callback(data) - log_debug "[#{log_signature}] Using data_callback" + log_debug { "[#{log_signature}] Using data_callback" } @used_data_callback = true @data = data end @@ -32,12 +32,12 @@ def fail(code, message) @error = ClientError.new @error.code = code.is_a?(Symbol) ? Protobuf::Socketrpc::ErrorReason.values[code] : code @error.message = message - log_debug "[#{log_signature}] Server failed request (invoking on_failure): %s" % @error.inspect + log_debug { "[#{log_signature}] Server failed request (invoking on_failure): %s" % @error.inspect } @failure_cb.call(@error) unless @failure_cb.nil? rescue - log_error "[#{log_signature}] Failure callback error encountered: %s" % $!.message - log_error "[#{log_signature}] %s" % $!.backtrace.join("\n") + log_error { "[#{log_signature}] Failure callback error encountered: %s" % $!.message } + log_error { "[#{log_signature}] %s" % $!.backtrace.join("\n") } raise ensure complete @@ -60,7 +60,7 @@ def parse_response # Close up the connection as we no longer need it close_connection - log_debug "[#{log_signature}] Parsing response from server (connection closed)" + log_debug { "[#{log_signature}] Parsing response from server (connection closed)" } @stats.response_size = @response_buffer.size # Parse out the raw response @@ -69,13 +69,13 @@ def parse_response # Determine success or failure based on parsed data if response_wrapper.has_field?(:error_reason) - log_debug "[#{log_signature}] Error response parsed" + log_debug { "[#{log_signature}] Error response parsed" } # fail the call if we already know the client is failed # (don't try to parse out the response payload) fail(response_wrapper.error_reason, response_wrapper.error) else - log_debug "[#{log_signature}] Successful response parsed" + log_debug { "[#{log_signature}] Successful response parsed" } # Ensure client_response is an instance response_type = @options[:response_type].new @@ -115,11 +115,11 @@ def setup_connection end def succeed(response) - log_debug "[#{log_signature}] Server succeeded request (invoking on_success)" + log_debug { "[#{log_signature}] Server succeeded request (invoking on_success)" } @success_cb.call(response) unless @success_cb.nil? rescue - log_error "[#{log_signature}] Success callback error encountered: %s" % $!.message - log_error "[#{log_signature}] %s" % $!.backtrace.join("\n") + log_error { "[#{log_signature}] Success callback error encountered: %s" % $!.message } + log_error { "[#{log_signature}] %s" % $!.backtrace.join("\n") } fail :RPC_ERROR, 'An exception occurred while calling on_success: %s' % $!.message ensure complete @@ -135,7 +135,7 @@ def validate_request_type def verify_callbacks if !any_callbacks? - log_debug "[#{log_signature}] No callbacks set, using data_callback" + log_debug { "[#{log_signature}] No callbacks set, using data_callback" } @success_cb = @failure_cb = self.method(:data_callback) end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index d9ac0983..1d147c85 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -23,7 +23,7 @@ def send_request def check_async if async? - log_error "[client-#{self.class}] Cannot run in async mode" + log_error { "[client-#{self.class}] Cannot run in async mode" } raise "Cannot use Zmq client in async mode" end end @@ -31,14 +31,14 @@ def check_async def close_connection zmq_error_check(@socket.close) zmq_error_check(@zmq_context.terminate) - log_debug "[client-#{self.class}] Connector closed" + log_debug { "[client-#{self.class}] Connector closed" } end def connect_to_rpc_server @zmq_context = ZMQ::Context.new @socket = @zmq_context.socket(ZMQ::REQ) zmq_error_check(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) - log_debug "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" + log_debug { "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" } end # Method to determine error state, must be used with Connector api @@ -53,10 +53,10 @@ def read_response end def send_data - log_debug "[#{log_signature}] Sending Request: %s" % @request_buffer.data + log_debug { "[#{log_signature}] Sending Request: %s" % @request_buffer.data } @stats.request_size = @request_buffer.size zmq_error_check(@socket.send_string(@request_buffer.data)) - log_debug "[client-#{self.class}] write closed" + log_debug { "[client-#{self.class}] write closed" } end def zmq_error_check(return_code) From 012edf5b1db1b5d7c2c6946129e855eb035768f7 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 16 May 2012 15:55:55 -0600 Subject: [PATCH 0009/1191] fixed two specs --- spec/unit/rpc/connectors/common_spec.rb | 1 - spec/unit/rpc/connectors/socket_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/unit/rpc/connectors/common_spec.rb b/spec/unit/rpc/connectors/common_spec.rb index 72d9c6d6..afd08bfd 100644 --- a/spec/unit/rpc/connectors/common_spec.rb +++ b/spec/unit/rpc/connectors/common_spec.rb @@ -19,7 +19,6 @@ specify{ subject.respond_to?(:fail).should be_true } specify{ subject.respond_to?(:complete).should be_true } specify{ subject.respond_to?(:parse_response).should be_true } - specify{ subject.respond_to?(:_send_request).should be_true } specify{ subject.respond_to?(:verify_options).should be_true } specify{ subject.respond_to?(:verify_callbacks).should be_true } end diff --git a/spec/unit/rpc/connectors/socket_spec.rb b/spec/unit/rpc/connectors/socket_spec.rb index 6753f343..93ffae34 100644 --- a/spec/unit/rpc/connectors/socket_spec.rb +++ b/spec/unit/rpc/connectors/socket_spec.rb @@ -24,13 +24,13 @@ it "fills the buffer with data from the socket" do socket = StringIO.new("#{data.bytesize}-#{data}") - subject.instance_variable_set(:@buffer, Protobuf::Rpc::Buffer.new(:read)) + subject.instance_variable_set(:@response_buffer, Protobuf::Rpc::Buffer.new(:read)) subject.instance_variable_set(:@socket, socket) subject.should_receive(:parse_response).and_return(true) subject.__send__(:read_response) - subject.instance_variable_get(:@buffer).flushed?.should be_true - subject.instance_variable_get(:@buffer).data.should eq(data) + subject.instance_variable_get(:@response_buffer).flushed?.should be_true + subject.instance_variable_get(:@responsebuffer).data.should eq(data) end end From 863560c5234e6d48ea70e0410d635be8a5609309 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Thu, 17 May 2012 14:31:39 -0600 Subject: [PATCH 0010/1191] started fixing message sending/receiving for EM client/server --- lib/protobuf/rpc/connectors/em_client.rb | 9 +++++++-- lib/protobuf/rpc/servers/evented_server.rb | 9 ++++++--- spec/helper/server.rb | 2 +- spec/spec_helper.rb | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 54956ce9..63183307 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -21,6 +21,7 @@ def initialize(options={}, &failure_cb) @options = DEFAULT_OPTIONS.merge(options) verify_options initialize_stats + setup_connection log_debug "[#{log_signature}] Client Initialized: %s" % options.inspect rescue @@ -41,11 +42,15 @@ def on_failure(&failure_cb) def on_complete(&complete_cb) @complete_cb = complete_cb end + + def send_data + super(@request_buffer.write) + end def receive_data(data) log_debug "[#{log_signature}] receive_data: %s" % data - @buffer << data - parse_response if @buffer.flushed? + @response_buffer << data + parse_response if @response_buffer.flushed? end end end diff --git a/lib/protobuf/rpc/servers/evented_server.rb b/lib/protobuf/rpc/servers/evented_server.rb index 4fa41af3..fd9b4c91 100644 --- a/lib/protobuf/rpc/servers/evented_server.rb +++ b/lib/protobuf/rpc/servers/evented_server.rb @@ -12,15 +12,18 @@ def post_init @stats = Protobuf::Rpc::Stat.new(:SERVER, true) @stats.client = Socket.unpack_sockaddr_in(get_peername) - @buffer = Protobuf::Rpc::Buffer.new(:read) + @response_buffer = Protobuf::Rpc::Buffer.new(:write) + @request_buffer = Protobuf::Rpc::Buffer.new(:read) @did_respond = false end # Receive a chunk of data, potentially flushed to handle_client def receive_data(data) log_debug { '[server] receive_data: %s' % data } - @buffer << data - handle_client if @buffer.flushed? + @request_buffer << data + @request = ::Protobuf::Socketrpc::Request.new + @response = ::Protobuf::Socketrpc::Response.new + handle_client if @request_buffer.flushed? end end end diff --git a/spec/helper/server.rb b/spec/helper/server.rb index 48c19080..5fd77a48 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -68,7 +68,7 @@ def start end def start_em_server - @server_handle = EventMachine::start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) + @server_handle = EventMachine.start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) end def start_socket_server diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8037d400..d9e647d9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,6 +11,7 @@ require 'protobuf' require 'protobuf/rpc/client' require File.dirname(__FILE__) + '/helper/all' +require 'pry' # Including a way to turn on debug logger for spec runs if ENV["DEBUG"] From beaad1898723930d2f099aa9c9e4d37bec86411e Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Thu, 17 May 2012 15:04:35 -0600 Subject: [PATCH 0011/1191] fixed send_data bug (from eventmachine client/server). fixed socket spec --- lib/protobuf/rpc/connectors/em_client.rb | 2 +- lib/protobuf/rpc/servers/evented_server.rb | 4 ++++ spec/unit/rpc/connectors/socket_spec.rb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 63183307..a3f5745d 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -44,7 +44,7 @@ def on_complete(&complete_cb) end def send_data - super(@request_buffer.write) + super(@request_buffer.data) end def receive_data(data) diff --git a/lib/protobuf/rpc/servers/evented_server.rb b/lib/protobuf/rpc/servers/evented_server.rb index fd9b4c91..4e16bc35 100644 --- a/lib/protobuf/rpc/servers/evented_server.rb +++ b/lib/protobuf/rpc/servers/evented_server.rb @@ -25,6 +25,10 @@ def receive_data(data) @response = ::Protobuf::Socketrpc::Response.new handle_client if @request_buffer.flushed? end + + def send_data + super(@response_buffer.data) + end end end end diff --git a/spec/unit/rpc/connectors/socket_spec.rb b/spec/unit/rpc/connectors/socket_spec.rb index 93ffae34..1e4ecc95 100644 --- a/spec/unit/rpc/connectors/socket_spec.rb +++ b/spec/unit/rpc/connectors/socket_spec.rb @@ -30,7 +30,7 @@ subject.__send__(:read_response) subject.instance_variable_get(:@response_buffer).flushed?.should be_true - subject.instance_variable_get(:@responsebuffer).data.should eq(data) + subject.instance_variable_get(:@response_buffer).data.should eq(data) end end From 7ab05e5cd3cdd88132ca423152e723b77e9287dd Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Thu, 17 May 2012 15:28:01 -0600 Subject: [PATCH 0012/1191] fixed order dependant tests in client_spec --- spec/unit/rpc/client_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/unit/rpc/client_spec.rb b/spec/unit/rpc/client_spec.rb index 211265b6..1647980e 100644 --- a/spec/unit/rpc/client_spec.rb +++ b/spec/unit/rpc/client_spec.rb @@ -2,6 +2,9 @@ require 'spec/proto/test_service_impl' describe Protobuf::Rpc::Client do + before(:each) do + ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION) + end context "when using fiber based calls" do it "waits for response when running synchronously" do From f5854acab8e4ef0676ec7162c2bcc0049c8a5130 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 18 May 2012 10:26:06 -0600 Subject: [PATCH 0013/1191] reverted buffer changes in preparation of zmq compatibility --- lib/protobuf/rpc/buffer.rb | 38 ++++++++++++---------- lib/protobuf/rpc/connectors/em_client.rb | 2 +- lib/protobuf/rpc/connectors/socket.rb | 4 +-- lib/protobuf/rpc/servers/evented_server.rb | 2 +- lib/protobuf/rpc/servers/socket_server.rb | 6 ++-- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 9c6ff33a..5a40ae81 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -1,18 +1,21 @@ module Protobuf module Rpc class Buffer - + attr_accessor :mode, :data, :size - + MODES = [:read, :write] - + + # constantize this so we don't re-initialize the regex every time we need it + SIZE_REGEX = /^\d+-/ + def initialize(mode=:read) @flush = false @data = "" @size = 0 self.mode = mode end - + def mode=(mode) if MODES.include?(mode) @mode = mode @@ -21,26 +24,21 @@ def mode=(mode) end end - def size_prefixed_data - @size = @data.length - return "#{@size}-#{@data}" - end - def write(force_mode=true) if force_mode and reading? mode = :write elsif not force_mode and reading? raise = 'You chose to write the buffer when in read mode' end - + @size = @data.length '%d-%s' % [@size, @data] end - + def <<(data) @data << data if reading? - @size = @data.size + get_data_size check_for_flush end end @@ -49,21 +47,27 @@ def set_data(data) @data = data.is_a?(Protobuf::Message) ? data.serialize_to_string : data.to_s @size = @data.size end - + def reading? mode == :read end - + def writing? mode == :write end - + def flushed? @flush end - + private - + def get_data_size + if @size == 0 || @data.match(SIZE_REGEX) + sliced_size = @data.slice!(SIZE_REGEX) + @size = sliced_size.gsub('-', '').to_i unless(sliced_size.nil?) + end + end + def check_for_flush if !@size.nil? && @data.length == @size @flush = true diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index a3f5745d..63183307 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -44,7 +44,7 @@ def on_complete(&complete_cb) end def send_data - super(@request_buffer.data) + super(@request_buffer.write) end def receive_data(data) diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index a8038467..dcbd3781 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -48,7 +48,7 @@ def read_data end str_size_io = size_io.string - "#{@socket.read(str_size_io.to_i)}" + "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" end def read_response @@ -57,7 +57,7 @@ def read_response end def send_data - @socket.write(@request_buffer.size_prefixed_data) + @socket.write(@request_buffer.write) @socket.flush log_debug "[client-#{self.class}] write closed" end diff --git a/lib/protobuf/rpc/servers/evented_server.rb b/lib/protobuf/rpc/servers/evented_server.rb index 4e16bc35..e6b26461 100644 --- a/lib/protobuf/rpc/servers/evented_server.rb +++ b/lib/protobuf/rpc/servers/evented_server.rb @@ -27,7 +27,7 @@ def receive_data(data) end def send_data - super(@response_buffer.data) + super(@response_buffer.write) end end end diff --git a/lib/protobuf/rpc/servers/socket_server.rb b/lib/protobuf/rpc/servers/socket_server.rb index 97eaedfa..71501732 100644 --- a/lib/protobuf/rpc/servers/socket_server.rb +++ b/lib/protobuf/rpc/servers/socket_server.rb @@ -131,12 +131,12 @@ def read_data end str_size_io = size_io.string - "#{@socket.read(str_size_io.to_i)}" + "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" end def send_data - log_debug { "[#{log_signature}] sending data : %s" % @response_buffer.size_prefixed_data } - @socket.write(@response_buffer.size_prefixed_data) + log_debug { "[#{log_signature}] sending data : %s" % @response_buffer.write } + @socket.write(@response_buffer.write) @socket.flush @complete_cb.call(@socket) end From f35e544f1ae447bea1b37901a7763fd3a0a36683 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 18 May 2012 10:30:54 -0600 Subject: [PATCH 0014/1191] some work on zmq compatibility with other server/clients --- lib/protobuf/rpc/buffer.rb | 3 ++- lib/protobuf/rpc/connectors/zmq.rb | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 5a40ae81..b0b4a90b 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -60,7 +60,6 @@ def flushed? @flush end - private def get_data_size if @size == 0 || @data.match(SIZE_REGEX) sliced_size = @data.slice!(SIZE_REGEX) @@ -68,6 +67,8 @@ def get_data_size end end + private + def check_for_flush if !@size.nil? && @data.length == @size @flush = true diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 1d147c85..df87ff73 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -48,14 +48,14 @@ def error? def read_response zmq_error_check(@socket.recv_string(@response_buffer.data)) - @response_buffer.size = @response_buffer.data.size + @response_buffer.get_data_size parse_response end def send_data - log_debug { "[#{log_signature}] Sending Request: %s" % @request_buffer.data } + log_debug { "[#{log_signature}] Sending Request: %s" % @request_buffer.write } @stats.request_size = @request_buffer.size - zmq_error_check(@socket.send_string(@request_buffer.data)) + zmq_error_check(@socket.send_string(@request_buffer.write)) log_debug { "[client-#{self.class}] write closed" } end From 41433d0d2c72fd4c4bd5e3759a0ed17e3814972e Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 18 May 2012 15:19:22 -0600 Subject: [PATCH 0015/1191] made all client/server types work (tentatively, untested) --- lib/protobuf/rpc/connectors/em_client.rb | 1 + lib/protobuf/rpc/connectors/zmq.rb | 1 + lib/protobuf/rpc/servers/evented_server.rb | 1 + lib/protobuf/rpc/servers/zmq_server.rb | 25 +++++++++++++--------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 63183307..87b1c07d 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -44,6 +44,7 @@ def on_complete(&complete_cb) end def send_data + log_debug { "[#{log_signature}] sending data: #{@request_buffer.inspect}" } super(@request_buffer.write) end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index df87ff73..6f7b3d1b 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -35,6 +35,7 @@ def close_connection end def connect_to_rpc_server + log_debug { "[client-#{self.class} Establishing connection: #{options[:host]}:#{options[:port]}" } @zmq_context = ZMQ::Context.new @socket = @zmq_context.socket(ZMQ::REQ) zmq_error_check(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) diff --git a/lib/protobuf/rpc/servers/evented_server.rb b/lib/protobuf/rpc/servers/evented_server.rb index e6b26461..601c251a 100644 --- a/lib/protobuf/rpc/servers/evented_server.rb +++ b/lib/protobuf/rpc/servers/evented_server.rb @@ -27,6 +27,7 @@ def receive_data(data) end def send_data + log_debug { "[#{log_signature}] sending data: #{@response_buffer.inspect}" } super(@response_buffer.write) end end diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb index e427f640..ac7891ab 100644 --- a/lib/protobuf/rpc/servers/zmq_server.rb +++ b/lib/protobuf/rpc/servers/zmq_server.rb @@ -2,36 +2,40 @@ module Protobuf module Rpc - class ZmqServer + class ZmqServer include ::Protobuf::Logger::LogMethods def self.zmq_error_check(return_code) - raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + raise "Last API call failed with \"#{ZMQ::Util.error_string}\"\n\n#{caller(1)}" unless return_code >= 0 end def self.run(opts = {}) host = opts.fetch(:host, "127.0.0.1") + host_ip = Socket.getaddrinfo(host, nil).select{|type| type[0] == 'AF_INET'}[0][3] + port = opts.fetch(:port, 9399) protocol = opts.fetch(:protocol, "tcp") local_worker_threads = opts.fetch(:threads, 10) @zmq_context = ::ZMQ::Context.new @frontend = @zmq_context.socket(::ZMQ::ROUTER) - zmq_error_check(@frontend.bind("#{protocol}://#{host}:#{port}")) + zmq_error_check(@frontend.bind("#{protocol}://#{host_ip}:#{port}")) dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) dealer_host = dealer_options.fetch(:host, "127.0.0.1") + dealer_host_ip = Socket.getaddrinfo(dealer_host, nil).select{|type| type[0] == 'AF_INET'}[0][3] + dealer_port = dealer_options.fetch(:port, 9400) dealer_protocol = dealer_options.fetch(:protocol, "tcp") @backend = @zmq_context.socket(::ZMQ::DEALER) - zmq_error_check(@backend.bind("#{dealer_protocol}://#{dealer_host}:#{dealer_port}")) + zmq_error_check(@backend.bind("#{dealer_protocol}://#{dealer_host_ip}:#{dealer_port}")) @poller = ::ZMQ::Poller.new @poller.register(@frontend, ::ZMQ::POLLIN) @poller.register(@backend, ::ZMQ::POLLIN) @threads = [] - local_worker_threads.times do + local_worker_threads.times do @threads << Thread.new(dealer_options) { |options| ZmqWorker.new(options).run } end @running = true @@ -55,7 +59,7 @@ def self.run(opts = {}) @frontend.send_string(message, more ? ::ZMQ::SNDMORE : 0) end end - end + end end end @@ -88,7 +92,7 @@ def initialize(options) end def self.zmq_error_check(return_code) - raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + raise "Last API call failed with \"#{ZMQ::Util.error_string}\"\n\n#{caller(1)}" unless return_code >= 0 end def run @@ -97,14 +101,15 @@ def run handle_request handle_client end - ensure + ensure @socket.close @zmq_context.terminate end def handle_request zmq_error_check(@socket.recv_string(@request_buffer.data)) - @request_buffer.size = @request_buffer.data.size + # compatibility with other server/client types + @request_buffer.get_data_size log_debug { "[#{log_signature}] handling request" } end @@ -119,7 +124,7 @@ def initialize_buffers end def send_data - zmq_error_check(@socket.send_string(@response_buffer.data)) + zmq_error_check(@socket.send_string(@response_buffer.write)) end def zmq_error_check(return_code) From ab96ba25923f14eeea3b855b2eaaca6ebe6045f2 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Mon, 21 May 2012 11:43:23 -0600 Subject: [PATCH 0016/1191] closer to single responsibility for zmq server Created a separate class for the broker portion of the zmq server code. Fixed the endless hanging with Thread.exit (needs to be re-worked). Created simple test for server and test file for client --- lib/protobuf/rpc/servers/socket_server.rb | 1 + lib/protobuf/rpc/servers/zmq_server.rb | 136 +++++++++++++--------- spec/benchmark/tasks.rb | 1 + spec/unit/rpc/connectors/zmq_spec.rb | 0 spec/unit/rpc/servers/zmq_server_spec.rb | 14 +++ 5 files changed, 98 insertions(+), 54 deletions(-) create mode 100644 spec/unit/rpc/connectors/zmq_spec.rb create mode 100644 spec/unit/rpc/servers/zmq_server_spec.rb diff --git a/lib/protobuf/rpc/servers/socket_server.rb b/lib/protobuf/rpc/servers/socket_server.rb index 71501732..0b2d363d 100644 --- a/lib/protobuf/rpc/servers/socket_server.rb +++ b/lib/protobuf/rpc/servers/socket_server.rb @@ -114,6 +114,7 @@ def initialize(sock, &complete_cb) log_debug { "[#{log_signature}] Post init, new read buffer created" } @stats.client = Socket.unpack_sockaddr_in(@socket.getpeername) + log_debug { "stats are #{@stats.to_s}" } @request_buffer << read_data log_debug { "[#{log_signature}] handling request" } handle_client if @request_buffer.flushed? diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb index ac7891ab..fdfcfd35 100644 --- a/lib/protobuf/rpc/servers/zmq_server.rb +++ b/lib/protobuf/rpc/servers/zmq_server.rb @@ -1,39 +1,22 @@ require 'protobuf/rpc/server' +require 'pry' module Protobuf module Rpc - class ZmqServer - include ::Protobuf::Logger::LogMethods - - def self.zmq_error_check(return_code) + module ZmqUtil + def zmq_error_check(return_code) raise "Last API call failed with \"#{ZMQ::Util.error_string}\"\n\n#{caller(1)}" unless return_code >= 0 end + end - def self.run(opts = {}) - host = opts.fetch(:host, "127.0.0.1") - host_ip = Socket.getaddrinfo(host, nil).select{|type| type[0] == 'AF_INET'}[0][3] + class ZmqServer + include ::Protobuf::Logger::LogMethods - port = opts.fetch(:port, 9399) - protocol = opts.fetch(:protocol, "tcp") + def self.run(opts = {}) + broker = ZmqBroker.new(opts) local_worker_threads = opts.fetch(:threads, 10) - @zmq_context = ::ZMQ::Context.new - @frontend = @zmq_context.socket(::ZMQ::ROUTER) - zmq_error_check(@frontend.bind("#{protocol}://#{host_ip}:#{port}")) - dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) - dealer_host = dealer_options.fetch(:host, "127.0.0.1") - dealer_host_ip = Socket.getaddrinfo(dealer_host, nil).select{|type| type[0] == 'AF_INET'}[0][3] - - dealer_port = dealer_options.fetch(:port, 9400) - dealer_protocol = dealer_options.fetch(:protocol, "tcp") - @backend = @zmq_context.socket(::ZMQ::DEALER) - zmq_error_check(@backend.bind("#{dealer_protocol}://#{dealer_host_ip}:#{dealer_port}")) - - @poller = ::ZMQ::Poller.new - @poller.register(@frontend, ::ZMQ::POLLIN) - @poller.register(@backend, ::ZMQ::POLLIN) - @threads = [] local_worker_threads.times do @threads << Thread.new(dealer_options) { |options| ZmqWorker.new(options).run } @@ -41,25 +24,7 @@ def self.run(opts = {}) @running = true while @running do - @poller.poll(:blocking) - @poller.readables.each do |socket| - more = true - - case socket - when @frontend then - while more do - socket.recv_string(message = '') - more = socket.more_parts? - @backend.send_string(message, more ? ::ZMQ::SNDMORE : 0) - end - when @backend then - while more do - socket.recv_string(message = '') - more = socket.more_parts? - @frontend.send_string(message, more ? ::ZMQ::SNDMORE : 0) - end - end - end + broker.poll end end @@ -72,14 +37,86 @@ def self.running? end def self.stop - @threads.map{ |t| t.join } + until(@threads.select {|t| t.status == 'run'}.count == 0) + # TODO: find a better way of exiting these threads + # joining on an endless loop doesn't work. This is messy though + @threads.map{ |t| t.exit unless(t.status == 'run')} + end @running = false end end + class ZmqBroker + include ::Protobuf::Rpc::ZmqUtil + attr_reader :frontend, :backend, :poller, :context + + def initialize(opts={}) + @context = ::ZMQ::Context.new + @frontend = setup_frontend(opts) + @backend = setup_backend(opts) + @poller = setup_poller + end + + def poll + poller.poll(:blocking) + poller.readables.each do |socket| + more = true + + case socket + when frontend then + while more do + socket.recv_string(message = '') + more = socket.more_parts? + backend.send_string(message, more ? ::ZMQ::SNDMORE : 0) + end + when backend then + while more do + socket.recv_string(message = '') + more = socket.more_parts? + frontend.send_string(message, more ? ::ZMQ::SNDMORE : 0) + end + end + end + end + + private + def setup_frontend(opts={}) + host = opts.fetch(:host, "127.0.0.1") + port = opts.fetch(:port, 9399) + protocol = opts.fetch(:protocol, "tcp") + + zmq_frontend = context.socket(::ZMQ::ROUTER) + zmq_error_check(zmq_frontend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) + zmq_frontend + end + + def setup_backend(opts={}) + dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) + host = dealer_options.fetch(:host, "127.0.0.1") + port = dealer_options.fetch(:port, 9400) + protocol = dealer_options.fetch(:protocol, "tcp") + + zmq_backend = context.socket(::ZMQ::DEALER) + zmq_error_check(zmq_backend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) + zmq_backend + end + + def setup_poller + zmq_poller = ::ZMQ::Poller.new + zmq_poller.register(frontend, ::ZMQ::POLLIN) + zmq_poller.register(backend, ::ZMQ::POLLIN) + zmq_poller + end + + def resolve_ip(hostname) + Socket.getaddrinfo(hostname, nil).select{|type| type[0] == 'AF_INET'}[0][3] + end + end + class ZmqWorker include ::Protobuf::Rpc::Server include ::Protobuf::Logger::LogMethods + include ::Protobuf::Rpc::ZmqUtil def initialize(options) @options = options @@ -91,10 +128,6 @@ def initialize(options) zmq_error_check(@socket.connect("#{protocol}://#{host}:#{port}")) end - def self.zmq_error_check(return_code) - raise "Last API call failed with \"#{ZMQ::Util.error_string}\"\n\n#{caller(1)}" unless return_code >= 0 - end - def run loop do initialize_buffers @@ -108,7 +141,6 @@ def run def handle_request zmq_error_check(@socket.recv_string(@request_buffer.data)) - # compatibility with other server/client types @request_buffer.get_data_size log_debug { "[#{log_signature}] handling request" } end @@ -126,10 +158,6 @@ def initialize_buffers def send_data zmq_error_check(@socket.send_string(@response_buffer.write)) end - - def zmq_error_check(return_code) - self.class.zmq_error_check(return_code) - end end end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 7d8f901b..d46140eb 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -99,6 +99,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) end end end + server.stop end end diff --git a/spec/unit/rpc/connectors/zmq_spec.rb b/spec/unit/rpc/connectors/zmq_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/spec/unit/rpc/servers/zmq_server_spec.rb b/spec/unit/rpc/servers/zmq_server_spec.rb new file mode 100644 index 00000000..df2fa256 --- /dev/null +++ b/spec/unit/rpc/servers/zmq_server_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' +require 'protobuf/rpc/servers/zmq_server' + +describe Protobuf::Rpc::ZmqServer do + it 'functions' do + StubServer.new(:port => 9399, :server => Protobuf::Rpc::ZmqServer) do |server| + with_constants "Protobuf::ClientType" => "Zmq" do + client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client.find(:name => "Test Name", :active => true) + end + server.stop + end + end +end From d4a7db076f07a207757a048fdeafb7820e8e6d12 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Mon, 21 May 2012 13:48:23 -0600 Subject: [PATCH 0017/1191] created simple test for zmq connector --- spec/unit/rpc/connectors/zmq_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spec/unit/rpc/connectors/zmq_spec.rb b/spec/unit/rpc/connectors/zmq_spec.rb index e69de29b..32c3dc7d 100644 --- a/spec/unit/rpc/connectors/zmq_spec.rb +++ b/spec/unit/rpc/connectors/zmq_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe ::Protobuf::Rpc::Connectors::Zmq do + let(:socket_mock) do + sm = mock(::ZMQ::Socket) + sm.stub(:connect).and_return(0) + sm + end + + let(:zmq_context_mock) do + zc = mock(::ZMQ::Context) + zc.stub(:socket).and_return(socket_mock) + zc + end + + before(:each) do + ::ZMQ::Context.stub(:new).and_return(zmq_context_mock) + end + + it 'raises if async is true' do + expect { + described_class.new(async: true).send_request + }.to raise_error + end + + +end From 90a9d12c768a73fcbc53813b7c036ccaa8306f30 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 22 May 2012 10:34:08 -0600 Subject: [PATCH 0018/1191] started changing code for jruby compatibility --- lib/protobuf/rpc/connectors/em_client.rb | 7 +++++++ lib/protobuf/rpc/servers/zmq_server.rb | 9 ++++----- spec/unit/rpc/servers/socket_server_spec.rb | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 87b1c07d..fe115d69 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -48,6 +48,13 @@ def send_data super(@request_buffer.write) end + # overwriting this method for java because it's broken in eventmachine. See https://github.com/eventmachine/eventmachine/issues/14 + if(RUBY_PLATFORM == "java") + def error? + false + end + end + def receive_data(data) log_debug "[#{log_signature}] receive_data: %s" % data @response_buffer << data diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb index fdfcfd35..e34b4b5a 100644 --- a/lib/protobuf/rpc/servers/zmq_server.rb +++ b/lib/protobuf/rpc/servers/zmq_server.rb @@ -37,12 +37,11 @@ def self.running? end def self.stop - until(@threads.select {|t| t.status == 'run'}.count == 0) - # TODO: find a better way of exiting these threads - # joining on an endless loop doesn't work. This is messy though - @threads.map{ |t| t.exit unless(t.status == 'run')} - end + # TODO: find a better way of exiting these threads + # joining on an endless loop doesn't work. This is very brute force though. Potential loss of data + @threads.map{ |t| t.exit; t.join} @running = false + puts @threads.inspect end end diff --git a/spec/unit/rpc/servers/socket_server_spec.rb b/spec/unit/rpc/servers/socket_server_spec.rb index 7ba388bf..0a8703d3 100644 --- a/spec/unit/rpc/servers/socket_server_spec.rb +++ b/spec/unit/rpc/servers/socket_server_spec.rb @@ -4,6 +4,7 @@ describe Protobuf::Rpc::SocketServer do before(:all) do + Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } Thread.pass until Protobuf::Rpc::SocketServer.running? From edc51077cde1355fd28e8f8c1a358aeb8e6af73f Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 22 May 2012 13:37:52 -0600 Subject: [PATCH 0019/1191] broke out zmq server parts Moved separate classes to their own files. Made server worker threads able to check their status and exit when told to. --- lib/protobuf/rpc/servers/zmq/broker.rb | 69 ++++++++++ lib/protobuf/rpc/servers/zmq/server.rb | 46 +++++++ lib/protobuf/rpc/servers/zmq/util.rb | 23 ++++ lib/protobuf/rpc/servers/zmq/worker.rb | 58 ++++++++ lib/protobuf/rpc/servers/zmq_runner.rb | 4 +- lib/protobuf/rpc/servers/zmq_server.rb | 162 ----------------------- spec/helper/server.rb | 8 +- spec/unit/rpc/servers/zmq_server_spec.rb | 6 +- 8 files changed, 205 insertions(+), 171 deletions(-) create mode 100644 lib/protobuf/rpc/servers/zmq/broker.rb create mode 100644 lib/protobuf/rpc/servers/zmq/server.rb create mode 100644 lib/protobuf/rpc/servers/zmq/util.rb create mode 100644 lib/protobuf/rpc/servers/zmq/worker.rb delete mode 100644 lib/protobuf/rpc/servers/zmq_server.rb diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb new file mode 100644 index 00000000..8569e314 --- /dev/null +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -0,0 +1,69 @@ +require 'protobuf/rpc/servers/zmq/util' +module Protobuf + module Rpc + module Zmq + class Broker + include ::Protobuf::Rpc::Zmq::Util + attr_reader :frontend, :backend, :poller, :context + + def initialize(opts={}) + @context = ::ZMQ::Context.new + @frontend = setup_frontend(opts) + @backend = setup_backend(opts) + @poller = setup_poller + end + + def poll + log_debug { "[#{log_signature}] polling for data" } + poller.poll(:blocking) + poller.readables.each do |socket| + more = true + + case socket + when frontend then + while more do + socket.recv_string(message = '') + more = socket.more_parts? + backend.send_string(message, more ? ::ZMQ::SNDMORE : 0) + end + when backend then + while more do + socket.recv_string(message = '') + more = socket.more_parts? + frontend.send_string(message, more ? ::ZMQ::SNDMORE : 0) + end + end + end + end + + private + def setup_frontend(opts={}) + host = opts.fetch(:host, "127.0.0.1") + port = opts.fetch(:port, 9399) + protocol = opts.fetch(:protocol, "tcp") + + zmq_frontend = context.socket(::ZMQ::ROUTER) + zmq_error_check(zmq_frontend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) + zmq_frontend + end + + def setup_backend(opts={}) + zmq_backend = context.socket(::ZMQ::DEALER) + zmq_error_check(zmq_backend.bind("ipc://backend.ipc")) + zmq_backend + end + + def setup_poller + zmq_poller = ::ZMQ::Poller.new + zmq_poller.register(frontend, ::ZMQ::POLLIN) + zmq_poller.register(backend, ::ZMQ::POLLIN) + zmq_poller + end + + def resolve_ip(hostname) + Socket.getaddrinfo(hostname, nil).select{|type| type[0] == 'AF_INET'}[0][3] + end + end + end + end +end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb new file mode 100644 index 00000000..7c0429d9 --- /dev/null +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -0,0 +1,46 @@ +require 'protobuf/rpc/servers/zmq/worker' +require 'protobuf/rpc/servers/zmq/broker' +require 'protobuf/rpc/servers/zmq/util' +require 'pry' + +module Protobuf + module Rpc + module Zmq + class Server + include ::Protobuf::Rpc::Zmq::Util + + def self.run(opts = {}) + log_debug { "[#{log_signature}] initializing broker" } + @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts) + local_worker_threads = opts.fetch(:threads, 10) + + dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) + log_debug { "[#{log_signature}] starting server workers" } + @threads = [] + local_worker_threads.times do + @threads << Thread.new(dealer_options) { |options| Thread.current[:running] = true; sleep 1; ::Protobuf::Rpc::Zmq::Worker.new.run } + end + @running = true + + while @running do + log_debug { "[#{log_signature}] server started" } + @broker.poll + end + end + + def self.running? + @running + end + + def self.stop + @threads.each do |t| + t[:running] = false + t.join + end + + @running = false + end + end + end + end +end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb new file mode 100644 index 00000000..34321953 --- /dev/null +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -0,0 +1,23 @@ +module Protobuf + module Rpc + module Zmq + + module Util + include ::Protobuf::Logger::LogMethods + def self.included(base) + base.extend(Util) + end + + def zmq_error_check(return_code) + raise "Last API call failed with \"#{ZMQ::Util.error_string}\"\n\n#{caller(1)}" unless return_code >= 0 + end + + def log_signature + @log_signature ||= "server-#{self.class}-#{object_id}" + end + + end + + end + end +end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb new file mode 100644 index 00000000..183b75ed --- /dev/null +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -0,0 +1,58 @@ +require 'protobuf/rpc/server' +require 'protobuf/rpc/servers/zmq/util' +module Protobuf + module Rpc + module Zmq + + class Worker + include ::Protobuf::Rpc::Server + include ::Protobuf::Rpc::Zmq::Util + + def initialize + @zmq_context = ::ZMQ::Context.new + @poller = ::ZMQ::Poller.new + @socket = @zmq_context.socket(::ZMQ::REP) + zmq_error_check(@socket.connect("ipc://backend.ipc")) + @poller.register(@socket, ::ZMQ::POLLIN) + end + + def run + while(Thread.current[:running]) + # poll for 100 milliseconds then continue looping + # This lets us see whether we need to die + @poller.poll(100) + @poller.readables.each do |socket| + initialize_buffers + handle_request(socket) + handle_client unless(@request_buffer.data.nil?) + end + end + ensure + @socket.close + @zmq_context.terminate + end + + def handle_request(socket) + zmq_error_check(socket.recv_string(@request_buffer.data)) + @request_buffer.get_data_size + log_debug { "[#{log_signature}] handling request" } + end + + def initialize_buffers + @did_respond = false + @request = ::Protobuf::Socketrpc::Request.new + @response = ::Protobuf::Socketrpc::Response.new + @request_buffer = ::Protobuf::Rpc::Buffer.new(:read) + @response_buffer = ::Protobuf::Rpc::Buffer.new(:write) + @stats = ::Protobuf::Rpc::Stat.new(:SERVER, true) + log_debug { "[#{log_signature}] Post init, new read buffer created" } + end + + def send_data + zmq_error_check(@socket.send_string(@response_buffer.write)) + end + end + + end + end +end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 8857dc73..75d8e52c 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -3,7 +3,7 @@ module Rpc class ZmqRunner def self.stop - Protobuf::Rpc::ZmqServer.stop + Protobuf::Rpc::Zmq::Server.stop Protobuf::Logger.info 'Shutdown complete' end @@ -20,7 +20,7 @@ def self.run(server) raise "Cannot parser Zmq Server - server options" end - Protobuf::Rpc::ZmqServer.run(server_config) + Protobuf::Rpc::Zmq::Server.run(server_config) end end diff --git a/lib/protobuf/rpc/servers/zmq_server.rb b/lib/protobuf/rpc/servers/zmq_server.rb deleted file mode 100644 index e34b4b5a..00000000 --- a/lib/protobuf/rpc/servers/zmq_server.rb +++ /dev/null @@ -1,162 +0,0 @@ -require 'protobuf/rpc/server' -require 'pry' - -module Protobuf - module Rpc - module ZmqUtil - def zmq_error_check(return_code) - raise "Last API call failed with \"#{ZMQ::Util.error_string}\"\n\n#{caller(1)}" unless return_code >= 0 - end - end - - class ZmqServer - include ::Protobuf::Logger::LogMethods - - def self.run(opts = {}) - broker = ZmqBroker.new(opts) - local_worker_threads = opts.fetch(:threads, 10) - - dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) - @threads = [] - local_worker_threads.times do - @threads << Thread.new(dealer_options) { |options| ZmqWorker.new(options).run } - end - @running = true - - while @running do - broker.poll - end - end - - def self.log_signature - @log_signature ||= "server-#{self.class}-#{object_id}" - end - - def self.running? - @running - end - - def self.stop - # TODO: find a better way of exiting these threads - # joining on an endless loop doesn't work. This is very brute force though. Potential loss of data - @threads.map{ |t| t.exit; t.join} - @running = false - puts @threads.inspect - end - end - - class ZmqBroker - include ::Protobuf::Rpc::ZmqUtil - attr_reader :frontend, :backend, :poller, :context - - def initialize(opts={}) - @context = ::ZMQ::Context.new - @frontend = setup_frontend(opts) - @backend = setup_backend(opts) - @poller = setup_poller - end - - def poll - poller.poll(:blocking) - poller.readables.each do |socket| - more = true - - case socket - when frontend then - while more do - socket.recv_string(message = '') - more = socket.more_parts? - backend.send_string(message, more ? ::ZMQ::SNDMORE : 0) - end - when backend then - while more do - socket.recv_string(message = '') - more = socket.more_parts? - frontend.send_string(message, more ? ::ZMQ::SNDMORE : 0) - end - end - end - end - - private - def setup_frontend(opts={}) - host = opts.fetch(:host, "127.0.0.1") - port = opts.fetch(:port, 9399) - protocol = opts.fetch(:protocol, "tcp") - - zmq_frontend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_frontend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) - zmq_frontend - end - - def setup_backend(opts={}) - dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) - host = dealer_options.fetch(:host, "127.0.0.1") - port = dealer_options.fetch(:port, 9400) - protocol = dealer_options.fetch(:protocol, "tcp") - - zmq_backend = context.socket(::ZMQ::DEALER) - zmq_error_check(zmq_backend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) - zmq_backend - end - - def setup_poller - zmq_poller = ::ZMQ::Poller.new - zmq_poller.register(frontend, ::ZMQ::POLLIN) - zmq_poller.register(backend, ::ZMQ::POLLIN) - zmq_poller - end - - def resolve_ip(hostname) - Socket.getaddrinfo(hostname, nil).select{|type| type[0] == 'AF_INET'}[0][3] - end - end - - class ZmqWorker - include ::Protobuf::Rpc::Server - include ::Protobuf::Logger::LogMethods - include ::Protobuf::Rpc::ZmqUtil - - def initialize(options) - @options = options - host = @options.fetch(:host, "127.0.0.1") - port = @options.fetch(:port, 9400) - protocol = @options.fetch(:protocol, "tcp") - @zmq_context = ::ZMQ::Context.new - @socket = @zmq_context.socket(::ZMQ::REP) - zmq_error_check(@socket.connect("#{protocol}://#{host}:#{port}")) - end - - def run - loop do - initialize_buffers - handle_request - handle_client - end - ensure - @socket.close - @zmq_context.terminate - end - - def handle_request - zmq_error_check(@socket.recv_string(@request_buffer.data)) - @request_buffer.get_data_size - log_debug { "[#{log_signature}] handling request" } - end - - def initialize_buffers - @did_respond = false - @request = ::Protobuf::Socketrpc::Request.new - @response = ::Protobuf::Socketrpc::Response.new - @request_buffer = ::Protobuf::Rpc::Buffer.new(:read) - @response_buffer = ::Protobuf::Rpc::Buffer.new(:write) - @stats = ::Protobuf::Rpc::Stat.new(:SERVER, true) - log_debug { "[#{log_signature}] Post init, new read buffer created" } - end - - def send_data - zmq_error_check(@socket.send_string(@response_buffer.write)) - end - end - end -end diff --git a/spec/helper/server.rb b/spec/helper/server.rb index 5fd77a48..2e8243c4 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -3,7 +3,7 @@ require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket_server' require 'protobuf/rpc/servers/socket_runner' -require 'protobuf/rpc/servers/zmq_server' +require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/servers/zmq_runner' require 'spec/proto/test_service_impl' @@ -55,7 +55,7 @@ def initialize(opts = {}) def start case when @options.server == Protobuf::Rpc::EventedServer then start_em_server - when @options.server == Protobuf::Rpc::ZmqServer then start_zmq_server + when @options.server == Protobuf::Rpc::Zmq::Server then start_zmq_server else start_socket_server end @@ -79,14 +79,14 @@ def start_socket_server def start_zmq_server @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } - Thread.pass until Protobuf::Rpc::ZmqServer.running? + Thread.pass until Protobuf::Rpc::Zmq::Server.running? end def stop case when @options.server == Protobuf::Rpc::EventedServer then EventMachine.stop_server(@server_handle) if @server_handle - when @options.server == Protobuf::Rpc::ZmqServer then + when @options.server == Protobuf::Rpc::Zmq::Server then Protobuf::Rpc::ZmqRunner.stop Thread.kill(@zmq_server) if @zmq_server else diff --git a/spec/unit/rpc/servers/zmq_server_spec.rb b/spec/unit/rpc/servers/zmq_server_spec.rb index df2fa256..9fba52d6 100644 --- a/spec/unit/rpc/servers/zmq_server_spec.rb +++ b/spec/unit/rpc/servers/zmq_server_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -require 'protobuf/rpc/servers/zmq_server' +require 'protobuf/rpc/servers/zmq/server' -describe Protobuf::Rpc::ZmqServer do +describe Protobuf::Rpc::Zmq::Server do it 'functions' do - StubServer.new(:port => 9399, :server => Protobuf::Rpc::ZmqServer) do |server| + StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| with_constants "Protobuf::ClientType" => "Zmq" do client = Spec::Proto::TestService.client(:async => false, :port => 9399) client.find(:name => "Test Name", :active => true) From 194d06b9191dd4ceefb53b962329b8a67a3abe0a Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 22 May 2012 14:22:02 -0600 Subject: [PATCH 0020/1191] tests for different portions of the zmq server/broker --- spec/unit/rpc/servers/zmq/broker_spec.rb | 29 ++++++++++++++++ spec/unit/rpc/servers/zmq/server_spec.rb | 42 ++++++++++++++++++++++++ spec/unit/rpc/servers/zmq/util_spec.rb | 41 +++++++++++++++++++++++ spec/unit/rpc/servers/zmq/worker_spec.rb | 36 ++++++++++++++++++++ spec/unit/rpc/servers/zmq_server_spec.rb | 14 -------- 5 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 spec/unit/rpc/servers/zmq/broker_spec.rb create mode 100644 spec/unit/rpc/servers/zmq/server_spec.rb create mode 100644 spec/unit/rpc/servers/zmq/util_spec.rb create mode 100644 spec/unit/rpc/servers/zmq/worker_spec.rb delete mode 100644 spec/unit/rpc/servers/zmq_server_spec.rb diff --git a/spec/unit/rpc/servers/zmq/broker_spec.rb b/spec/unit/rpc/servers/zmq/broker_spec.rb new file mode 100644 index 00000000..302484a4 --- /dev/null +++ b/spec/unit/rpc/servers/zmq/broker_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe ::Protobuf::Rpc::Zmq::Broker do + after(:each) do + subject.frontend.close + subject.backend.close + subject.context.terminate + end + + it 'sets up a context' do + subject.context.should be_a(::ZMQ::Context) + end + + it 'sets up a frontend socket' do + subject.frontend.should be_a(::ZMQ::Socket) + end + + it 'sets up a backend socket' do + subject.backend.should be_a(::ZMQ::Socket) + end + + it 'sets up a polling object' do + subject.poller.should be_a(::ZMQ::Poller) + end + + describe '#poll' do + # no unit tests for this method + end +end diff --git a/spec/unit/rpc/servers/zmq/server_spec.rb b/spec/unit/rpc/servers/zmq/server_spec.rb new file mode 100644 index 00000000..c98aae08 --- /dev/null +++ b/spec/unit/rpc/servers/zmq/server_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' +require 'protobuf/rpc/servers/zmq/server' + +describe Protobuf::Rpc::Zmq::Server do + it 'functions' do + StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| + with_constants "Protobuf::ClientType" => "Zmq" do + client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client.find(:name => "Test Name", :active => true) + end + server.stop + end + end + + describe '.running?' do + it 'returns true if running' do + described_class.instance_variable_set(:@running, true) + described_class.running?.should be_true + end + + it 'returns false if not running' do + described_class.instance_variable_set(:@running, false) + described_class.running?.should be_false + end + end + + describe '.stop' do + it 'tells all threads to stop' do + thread_mock = double(Thread) + thread_mock.should_receive(:join) + thread_mock.should_receive(:[]=).with(:running, false) + described_class.instance_variable_set(:@threads, [thread_mock]) + described_class.stop + end + + it 'sets running to false' do + described_class.instance_variable_set(:@threads, []) + described_class.stop + described_class.instance_variable_get(:@running).should be_false + end + end +end diff --git a/spec/unit/rpc/servers/zmq/util_spec.rb b/spec/unit/rpc/servers/zmq/util_spec.rb new file mode 100644 index 00000000..f03e1d94 --- /dev/null +++ b/spec/unit/rpc/servers/zmq/util_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +class UtilTest + include ::Protobuf::Rpc::Zmq::Util +end + +describe ::Protobuf::Rpc::Zmq::Util do + subject { UtilTest.new } + describe '#zmq_error_check' do + it 'raises when the error code is less than 0' do + expect { + subject.zmq_error_check(-1) + }.to raise_error + end + + it 'retrieves the error string from ZeroMQ' do + ZMQ::Util.stub(:error_string).and_return('an error from zmq') + expect { + subject.zmq_error_check(-1) + }.to raise_error(RuntimeError, /an error from zmq/i) + end + + it 'does nothing if the error code is > 0' do + expect { + subject.zmq_error_check(1) + }.to_not raise_error + end + + it 'does nothing if the error code is == 0' do + expect { + subject.zmq_error_check(0) + }.to_not raise_error + end + end + + describe '#log_signature' do + it 'returns the signature for the log' do + subject.log_signature.should include('server', 'UtilTest') + end + end +end diff --git a/spec/unit/rpc/servers/zmq/worker_spec.rb b/spec/unit/rpc/servers/zmq/worker_spec.rb new file mode 100644 index 00000000..7716bab2 --- /dev/null +++ b/spec/unit/rpc/servers/zmq/worker_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe ::Protobuf::Rpc::Zmq::Worker do + after(:each) do + subject.instance_variable_get(:@socket).close + subject.instance_variable_get(:@zmq_context).terminate + end + + it 'sets the context' do + subject.instance_variable_get(:@zmq_context).should be_a(::ZMQ::Context) + end + + it 'sets the poller' do + subject.instance_variable_get(:@socket).should be_a(::ZMQ::Socket) + end + + it 'sets the socket' do + subject.instance_variable_get(:@poller).should be_a(::ZMQ::Poller) + end + + describe '#run' do + # not tested via unit tests + end + + describe '#handle_request' do + # not tested via unit tests + end + + describe '#initialize_buffers' do + # not tested via unit tests + end + + describe '#send_data' do + # not tested via unit tests + end +end diff --git a/spec/unit/rpc/servers/zmq_server_spec.rb b/spec/unit/rpc/servers/zmq_server_spec.rb deleted file mode 100644 index 9fba52d6..00000000 --- a/spec/unit/rpc/servers/zmq_server_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'spec_helper' -require 'protobuf/rpc/servers/zmq/server' - -describe Protobuf::Rpc::Zmq::Server do - it 'functions' do - StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - with_constants "Protobuf::ClientType" => "Zmq" do - client = Spec::Proto::TestService.client(:async => false, :port => 9399) - client.find(:name => "Test Name", :active => true) - end - server.stop - end - end -end From 49c575053a89e338711619555e3ce5bbad352003 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 22 May 2012 15:10:43 -0600 Subject: [PATCH 0021/1191] added teardown functions for broker --- lib/protobuf/rpc/servers/socket_server.rb | 2 ++ lib/protobuf/rpc/servers/zmq/broker.rb | 6 ++++++ lib/protobuf/rpc/servers/zmq/server.rb | 5 ++++- spec/unit/rpc/servers/zmq/broker_spec.rb | 4 +--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/socket_server.rb b/lib/protobuf/rpc/servers/socket_server.rb index 0b2d363d..aa916c5f 100644 --- a/lib/protobuf/rpc/servers/socket_server.rb +++ b/lib/protobuf/rpc/servers/socket_server.rb @@ -84,6 +84,8 @@ def self.run(opts = {}) end end + rescue Errno::EADDRINUSE + raise rescue # Closing the server causes the loop to raise an exception here raise if running? diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 8569e314..aca49047 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -36,6 +36,12 @@ def poll end end + def teardown + frontend.close + backend.close + context.terminate + end + private def setup_frontend(opts={}) host = opts.fetch(:host, "127.0.0.1") diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 7c0429d9..8d343486 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -26,6 +26,9 @@ def self.run(opts = {}) log_debug { "[#{log_signature}] server started" } @broker.poll end + + ensure + @broker.teardown if(@broker) end def self.running? @@ -36,7 +39,7 @@ def self.stop @threads.each do |t| t[:running] = false t.join - end + end if(@threads) @running = false end diff --git a/spec/unit/rpc/servers/zmq/broker_spec.rb b/spec/unit/rpc/servers/zmq/broker_spec.rb index 302484a4..8696dc96 100644 --- a/spec/unit/rpc/servers/zmq/broker_spec.rb +++ b/spec/unit/rpc/servers/zmq/broker_spec.rb @@ -2,9 +2,7 @@ describe ::Protobuf::Rpc::Zmq::Broker do after(:each) do - subject.frontend.close - subject.backend.close - subject.context.terminate + subject.teardown end it 'sets up a context' do From 7476fb87fd91a17380d11e5d58242ce0ace670bb Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 22 May 2012 15:18:47 -0600 Subject: [PATCH 0022/1191] some cleanup in the zmq server --- lib/protobuf/rpc/servers/zmq/server.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 8d343486..2f5d6281 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -14,11 +14,13 @@ def self.run(opts = {}) @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts) local_worker_threads = opts.fetch(:threads, 10) - dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) log_debug { "[#{log_signature}] starting server workers" } @threads = [] local_worker_threads.times do - @threads << Thread.new(dealer_options) { |options| Thread.current[:running] = true; sleep 1; ::Protobuf::Rpc::Zmq::Worker.new.run } + @threads << Thread.new do + Thread.current[:running] = true + ::Protobuf::Rpc::Zmq::Worker.new.run + end end @running = true From d334bff715b31aefd1a7f7ce996afe51ff714e5d Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 23 May 2012 09:29:34 -0600 Subject: [PATCH 0023/1191] added condition for logging request handling --- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 183b75ed..bc86045f 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -35,7 +35,7 @@ def run def handle_request(socket) zmq_error_check(socket.recv_string(@request_buffer.data)) @request_buffer.get_data_size - log_debug { "[#{log_signature}] handling request" } + log_debug { "[#{log_signature}] handling request" } if(!@request_buffer.data.nil?) end def initialize_buffers From af3843a6e08339a30991054f4546de9adcd38206 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 23 May 2012 09:44:01 -0600 Subject: [PATCH 0024/1191] fixed benchmark zmq task --- spec/benchmark/tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index d46140eb..79e120a5 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -89,7 +89,7 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) end def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) - StubServer.new(:port => 9399, :server => Protobuf::Rpc::ZmqServer) do |server| + StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| with_constants "Protobuf::ClientType" => "Zmq" do client = Spec::Proto::TestService.client(:async => false, :port => 9399) From 1d55bb6330a857fa7d94e0e2ba6c33a1bd128463 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 23 May 2012 09:57:04 -0600 Subject: [PATCH 0025/1191] removed options parameter from backend setup --- lib/protobuf/rpc/servers/zmq/broker.rb | 5 +++-- lib/protobuf/rpc/servers/zmq/worker.rb | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index aca49047..6d437cb2 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -9,7 +9,7 @@ class Broker def initialize(opts={}) @context = ::ZMQ::Context.new @frontend = setup_frontend(opts) - @backend = setup_backend(opts) + @backend = setup_backend @poller = setup_poller end @@ -53,8 +53,9 @@ def setup_frontend(opts={}) zmq_frontend end - def setup_backend(opts={}) + def setup_backend zmq_backend = context.socket(::ZMQ::DEALER) + # needs a unique name zmq_error_check(zmq_backend.bind("ipc://backend.ipc")) zmq_backend end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index bc86045f..c531ebc6 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -12,6 +12,7 @@ def initialize @zmq_context = ::ZMQ::Context.new @poller = ::ZMQ::Poller.new @socket = @zmq_context.socket(::ZMQ::REP) + # needs a unique name that matches the DEALER's name zmq_error_check(@socket.connect("ipc://backend.ipc")) @poller.register(@socket, ::ZMQ::POLLIN) end From 4fe1e4c619b43552f9c5788c8c35a3d5554fe945 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 23 May 2012 09:59:35 -0600 Subject: [PATCH 0026/1191] made some fields in the test.proto required for testing purposes --- spec/proto/test.pb.rb | 4 ++-- spec/proto/test.proto | 2 +- spec/proto/test_service.rb | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/proto/test.pb.rb b/spec/proto/test.pb.rb index 269971c6..9341fbac 100644 --- a/spec/proto/test.pb.rb +++ b/spec/proto/test.pb.rb @@ -16,7 +16,7 @@ class ResourceFindRequest < ::Protobuf::Message optional :bool, :active, 2 end class Resource < ::Protobuf::Message - optional :string, :name, 1 + required :string, :name, 1 optional :int64, :date_created, 2 optional :StatusType, :status, 3 repeated :StatusType, :repeated_enum, 4 @@ -28,4 +28,4 @@ class Nested < ::Protobuf::Message optional :StatusType, :status, 4 end end -end \ No newline at end of file +end diff --git a/spec/proto/test.proto b/spec/proto/test.proto index 31997eff..90337ecf 100644 --- a/spec/proto/test.proto +++ b/spec/proto/test.proto @@ -13,7 +13,7 @@ message ResourceFindRequest { } message Resource { - optional string name = 1; + required string name = 1; optional int64 date_created = 2; optional StatusType status = 3; repeated StatusType repeated_enum = 4; diff --git a/spec/proto/test_service.rb b/spec/proto/test_service.rb index cc146ef7..02699f00 100644 --- a/spec/proto/test_service.rb +++ b/spec/proto/test_service.rb @@ -1,4 +1,5 @@ require 'protobuf/rpc/service' +require 'spec/proto/test.pb' ## !! DO NOT EDIT THIS FILE !! ## From 373120f01007a76fe5f407401410d80751c23e29 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 23 May 2012 10:00:30 -0600 Subject: [PATCH 0027/1191] started tests for message encoder --- spec/lib/protobuf/message/encoder_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 spec/lib/protobuf/message/encoder_spec.rb diff --git a/spec/lib/protobuf/message/encoder_spec.rb b/spec/lib/protobuf/message/encoder_spec.rb new file mode 100644 index 00000000..39d8a938 --- /dev/null +++ b/spec/lib/protobuf/message/encoder_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +class EncoderTest + extend ::Protobuf::Encoder +end + +describe Protobuf::Encoder do + describe '#encode' do + context "when there's no value for a required field" do + let(:message) { ::Spec::Proto::Resource.new } + let(:stream) { StringIO.new } + it "raises a 'message not initialized' error" do + expect { + EncoderTest.__send__(:encode, stream, message) + }.to raise_error(Protobuf::NotInitializedError, /message.*not initialized/i) + end + end + end +end From e87b94dc101cc09991825a140f8b7d5029f5eee3 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 11:33:29 -0600 Subject: [PATCH 0028/1191] use newline global and scope resolution operator --- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- lib/protobuf/rpc/servers/zmq/util.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 6f7b3d1b..09c1292f 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -36,8 +36,8 @@ def close_connection def connect_to_rpc_server log_debug { "[client-#{self.class} Establishing connection: #{options[:host]}:#{options[:port]}" } - @zmq_context = ZMQ::Context.new - @socket = @zmq_context.socket(ZMQ::REQ) + @zmq_context = ::ZMQ::Context.new + @socket = @zmq_context.socket(::ZMQ::REQ) zmq_error_check(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) log_debug { "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" } end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 34321953..3cc161ce 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -5,11 +5,11 @@ module Zmq module Util include ::Protobuf::Logger::LogMethods def self.included(base) - base.extend(Util) + base.extend(::Protobuf::Rpc::Zmq::Util) end def zmq_error_check(return_code) - raise "Last API call failed with \"#{ZMQ::Util.error_string}\"\n\n#{caller(1)}" unless return_code >= 0 + raise "Last API call failed with \"#{::ZMQ::Util.error_string}\"#{$/}#{$/}#{caller(1)}" unless return_code >= 0 end def log_signature From a95924c30130554da761033ec5ea4aa18d39228c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 11:40:41 -0600 Subject: [PATCH 0029/1191] move from using socket library to resolving the address of the server --- lib/protobuf/rpc/servers/zmq/broker.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index aca49047..0ffaa5dc 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -1,4 +1,6 @@ +require 'resolv' require 'protobuf/rpc/servers/zmq/util' + module Protobuf module Rpc module Zmq @@ -43,6 +45,11 @@ def teardown end private + + def resolve_ip(hostname) + Resolv.getaddress(hostname) + end + def setup_frontend(opts={}) host = opts.fetch(:host, "127.0.0.1") port = opts.fetch(:port, 9399) @@ -65,10 +72,6 @@ def setup_poller zmq_poller.register(backend, ::ZMQ::POLLIN) zmq_poller end - - def resolve_ip(hostname) - Socket.getaddrinfo(hostname, nil).select{|type| type[0] == 'AF_INET'}[0][3] - end end end end From 81c838c03cbce7ba961915d3bd14d6bff90323b7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 11:48:33 -0600 Subject: [PATCH 0030/1191] DRY up the poller in the broker --- lib/protobuf/rpc/servers/zmq/broker.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 0ffaa5dc..26892987 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -19,21 +19,11 @@ def poll log_debug { "[#{log_signature}] polling for data" } poller.poll(:blocking) poller.readables.each do |socket| - more = true - case socket when frontend then - while more do - socket.recv_string(message = '') - more = socket.more_parts? - backend.send_string(message, more ? ::ZMQ::SNDMORE : 0) - end + move_to(backend, socket) when backend then - while more do - socket.recv_string(message = '') - more = socket.more_parts? - frontend.send_string(message, more ? ::ZMQ::SNDMORE : 0) - end + move_to(frontend, socket) end end end @@ -46,6 +36,17 @@ def teardown private + def move_to(frontend_or_backend, socket) + more_data = true + + while more_data do + socket.recv_string(data = "") + more_data = socket.more_parts? + more_data_flag = (more_data ? ::ZMQ::SNDMORE : 0) + frontend_or_backend.send_string(data, more_data_flag) + end + end + def resolve_ip(hostname) Resolv.getaddress(hostname) end From a2e7267142b4a4a566db7e4bed902f44d13804cb Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 11:54:59 -0600 Subject: [PATCH 0031/1191] alpha the methods --- lib/protobuf/rpc/servers/zmq/broker.rb | 12 ++++---- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/worker.rb | 38 +++++++++++++++----------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 26892987..5f3c7c03 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -51,6 +51,12 @@ def resolve_ip(hostname) Resolv.getaddress(hostname) end + def setup_backend(opts={}) + zmq_backend = context.socket(::ZMQ::DEALER) + zmq_error_check(zmq_backend.bind("ipc://backend.ipc")) + zmq_backend + end + def setup_frontend(opts={}) host = opts.fetch(:host, "127.0.0.1") port = opts.fetch(:port, 9399) @@ -61,12 +67,6 @@ def setup_frontend(opts={}) zmq_frontend end - def setup_backend(opts={}) - zmq_backend = context.socket(::ZMQ::DEALER) - zmq_error_check(zmq_backend.bind("ipc://backend.ipc")) - zmq_backend - end - def setup_poller zmq_poller = ::ZMQ::Poller.new zmq_poller.register(frontend, ::ZMQ::POLLIN) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 2f5d6281..873509af 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -30,7 +30,7 @@ def self.run(opts = {}) end ensure - @broker.teardown if(@broker) + @broker.teardown if @broker end def self.running? diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 183b75ed..1035d870 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -8,6 +8,9 @@ class Worker include ::Protobuf::Rpc::Server include ::Protobuf::Rpc::Zmq::Util + ## + # Constructor + # def initialize @zmq_context = ::ZMQ::Context.new @poller = ::ZMQ::Poller.new @@ -16,22 +19,9 @@ def initialize @poller.register(@socket, ::ZMQ::POLLIN) end - def run - while(Thread.current[:running]) - # poll for 100 milliseconds then continue looping - # This lets us see whether we need to die - @poller.poll(100) - @poller.readables.each do |socket| - initialize_buffers - handle_request(socket) - handle_client unless(@request_buffer.data.nil?) - end - end - ensure - @socket.close - @zmq_context.terminate - end - + ## + # Instance Methods + # def handle_request(socket) zmq_error_check(socket.recv_string(@request_buffer.data)) @request_buffer.get_data_size @@ -48,6 +38,22 @@ def initialize_buffers log_debug { "[#{log_signature}] Post init, new read buffer created" } end + def run + while(Thread.current[:running]) + # poll for 100 milliseconds then continue looping + # This lets us see whether we need to die + @poller.poll(100) + @poller.readables.each do |socket| + initialize_buffers + handle_request(socket) + handle_client unless(@request_buffer.data.nil?) + end + end + ensure + @socket.close + @zmq_context.terminate + end + def send_data zmq_error_check(@socket.send_string(@response_buffer.write)) end From b77b86da5e807b1cc86c450ffc3dfe6ad613e64a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 12:09:40 -0600 Subject: [PATCH 0032/1191] remove use of thread local variables --- lib/protobuf/rpc/servers/zmq/server.rb | 25 ++++++++++++------------ lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- spec/unit/rpc/servers/zmq/server_spec.rb | 3 +-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 873509af..74056464 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -1,5 +1,5 @@ -require 'protobuf/rpc/servers/zmq/worker' require 'protobuf/rpc/servers/zmq/broker' +require 'protobuf/rpc/servers/zmq/worker' require 'protobuf/rpc/servers/zmq/util' require 'pry' @@ -9,42 +9,41 @@ module Zmq class Server include ::Protobuf::Rpc::Zmq::Util + ## + # Class Methods + # def self.run(opts = {}) log_debug { "[#{log_signature}] initializing broker" } @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts) local_worker_threads = opts.fetch(:threads, 10) log_debug { "[#{log_signature}] starting server workers" } - @threads = [] local_worker_threads.times do - @threads << Thread.new do - Thread.current[:running] = true - ::Protobuf::Rpc::Zmq::Worker.new.run - end + @threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new.run } end @running = true - while @running do + while self.running? do log_debug { "[#{log_signature}] server started" } @broker.poll end - ensure @broker.teardown if @broker end def self.running? - @running + !!@running end def self.stop + @running = false + @threads.each do |t| - t[:running] = false t.join - end if(@threads) - - @running = false + end end + + @threads ||= [] end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 1035d870..9826a122 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -39,7 +39,7 @@ def initialize_buffers end def run - while(Thread.current[:running]) + while ::Protobuf::Rpc::Zmq::Server.running? do # poll for 100 milliseconds then continue looping # This lets us see whether we need to die @poller.poll(100) diff --git a/spec/unit/rpc/servers/zmq/server_spec.rb b/spec/unit/rpc/servers/zmq/server_spec.rb index c98aae08..b0d4a70c 100644 --- a/spec/unit/rpc/servers/zmq/server_spec.rb +++ b/spec/unit/rpc/servers/zmq/server_spec.rb @@ -25,10 +25,9 @@ end describe '.stop' do - it 'tells all threads to stop' do + it 'lets all threads stop' do thread_mock = double(Thread) thread_mock.should_receive(:join) - thread_mock.should_receive(:[]=).with(:running, false) described_class.instance_variable_set(:@threads, [thread_mock]) described_class.stop end From 456bdd3c6080cdf6053b18b27b8f268dcc357528 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 12:13:27 -0600 Subject: [PATCH 0033/1191] do not need Hash check if to_hash is present --- lib/protobuf/rpc/servers/zmq_runner.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 75d8e52c..c04d5a91 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -12,8 +12,6 @@ def self.run(server) server_config = case when server.is_a?(OpenStruct) then server.marshal_dump - when server.is_a?(Hash) then - server when server.respond_to?(:to_hash) then server.to_hash else From 400d05938674d954242e911089ee2c6a0a2482d8 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 14:44:11 -0600 Subject: [PATCH 0034/1191] add documentation and increase polling interval --- lib/protobuf/rpc/servers/zmq/broker.rb | 8 +++++++- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 5f3c7c03..745a5f90 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -8,6 +8,9 @@ class Broker include ::Protobuf::Rpc::Zmq::Util attr_reader :frontend, :backend, :poller, :context + ## + # Constructor + # def initialize(opts={}) @context = ::ZMQ::Context.new @frontend = setup_frontend(opts) @@ -15,6 +18,9 @@ def initialize(opts={}) @poller = setup_poller end + ## + # Instance Methods + # def poll log_debug { "[#{log_signature}] polling for data" } poller.poll(:blocking) @@ -48,7 +54,7 @@ def move_to(frontend_or_backend, socket) end def resolve_ip(hostname) - Resolv.getaddress(hostname) + ::Resolv.getaddress(hostname) end def setup_backend(opts={}) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 9826a122..5930dba8 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -42,7 +42,7 @@ def run while ::Protobuf::Rpc::Zmq::Server.running? do # poll for 100 milliseconds then continue looping # This lets us see whether we need to die - @poller.poll(100) + @poller.poll(1_000) @poller.readables.each do |socket| initialize_buffers handle_request(socket) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index c04d5a91..6428fc2e 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -4,7 +4,7 @@ class ZmqRunner def self.stop Protobuf::Rpc::Zmq::Server.stop - Protobuf::Logger.info 'Shutdown complete' + Protobuf::Logger.info('Shutdown complete') end def self.run(server) From f19910c3b4da76e56cd6b42831be24fb5727f906 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 23 May 2012 16:44:18 -0600 Subject: [PATCH 0035/1191] alpha org em_client --- lib/protobuf/rpc/connectors/em_client.rb | 50 ++++++++++++++---------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index fe115d69..835f1bc6 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -10,12 +10,9 @@ class EMClient < EM::Connection attr_reader :options, :request, :response attr_reader :error, :error_reason, :error_message - def self.connect(options={}) - options = DEFAULT_OPTIONS.merge(options) - log_debug "[client-#{self}] Connecting to server: %s" % options.inspect - EM.connect(options[:host], options[:port], self, options) - end - + ## + # Constructor + # def initialize(options={}, &failure_cb) @failure_cb = failure_cb @options = DEFAULT_OPTIONS.merge(options) @@ -28,19 +25,37 @@ def initialize(options={}, &failure_cb) fail(:RPC_ERROR, 'Failed to initialize connection: %s' % $!.message) end - # Success callback registration - def on_success(&success_cb) - @success_cb = success_cb + ## + # Class Methods + # + def self.connect(options={}) + options = DEFAULT_OPTIONS.merge(options) + log_debug "[client-#{self}] Connecting to server: %s" % options.inspect + EM.connect(options[:host], options[:port], self, options) end - + + ## + # Instance Methods + # + # Completion callback registration + def on_complete(&complete_cb) + @complete_cb = complete_cb + end + # Failure callback registration def on_failure(&failure_cb) @failure_cb = failure_cb end - - # Completion callback registration - def on_complete(&complete_cb) - @complete_cb = complete_cb + + # Success callback registration + def on_success(&success_cb) + @success_cb = success_cb + end + + def receive_data(data) + log_debug "[#{log_signature}] receive_data: %s" % data + @response_buffer << data + parse_response if @response_buffer.flushed? end def send_data @@ -49,17 +64,12 @@ def send_data end # overwriting this method for java because it's broken in eventmachine. See https://github.com/eventmachine/eventmachine/issues/14 - if(RUBY_PLATFORM == "java") + if RUBY_PLATFORM =~ /java/ def error? false end end - def receive_data(data) - log_debug "[#{log_signature}] receive_data: %s" % data - @response_buffer << data - parse_response if @response_buffer.flushed? - end end end end From b0824c9b4ae45304f1c211562694f8b018d0ff32 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Thu, 24 May 2012 14:12:54 -0600 Subject: [PATCH 0036/1191] added pry-nav for development --- Gemfile.lock | 3 +++ protobuf.gemspec | 1 + 2 files changed, 4 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 72090854..0288508c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,6 +31,8 @@ GEM method_source (~> 0.7.1) slop (>= 2.4.4, < 3) spoon (~> 0.0) + pry-nav (0.2.0) + pry (~> 0.9.8.1) rake (0.9.2.2) redcarpet (2.1.1) rspec (2.9.0) @@ -57,6 +59,7 @@ PLATFORMS DEPENDENCIES protobuf! pry + pry-nav rake redcarpet rspec diff --git a/protobuf.gemspec b/protobuf.gemspec index dd9a93eb..1e4aae1f 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'ruby-prof' s.add_development_dependency 'rake' s.add_development_dependency 'pry' + s.add_development_dependency 'pry-nav' s.add_development_dependency 'rspec' s.add_development_dependency 'yard' s.add_development_dependency 'redcarpet' From 68a676287c84216e326b06c483c2759a6ca5e5a3 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Thu, 24 May 2012 15:13:08 -0600 Subject: [PATCH 0037/1191] Fixed client hanging on invalid requests Fixed issue where client hangs if the request is invalid or malformed. --- lib/protobuf/rpc/connectors/common.rb | 2 + lib/protobuf/rpc/connectors/em_client.rb | 6 +- lib/protobuf/rpc/connectors/eventmachine.rb | 2 + lib/protobuf/rpc/connectors/socket.rb | 4 ++ lib/protobuf/rpc/connectors/zmq.rb | 6 +- spec/functional/evented_server_spec.rb | 65 +++++++++++++++++++++ spec/functional/socket_server_spec.rb | 64 ++++++++++++++++++++ spec/functional/zmq_server_spec.rb | 64 ++++++++++++++++++++ spec/proto/test.pb.rb | 2 +- spec/proto/test.proto | 4 +- spec/unit/rpc/servers/zmq/server_spec.rb | 10 ---- spec/unit/rpc/service_spec.rb | 6 +- 12 files changed, 216 insertions(+), 19 deletions(-) create mode 100644 spec/functional/evented_server_spec.rb create mode 100644 spec/functional/socket_server_spec.rb create mode 100644 spec/functional/zmq_server_spec.rb diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index bef89003..b4d05418 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -105,6 +105,8 @@ def request_wrapper :method_name => @options[:method].to_s, :request_proto => @options[:request].serialize_to_string ) + rescue + fail :INVALID_REQUEST_PROTO, "Could not set request proto: #{$!.message}" end def setup_connection diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 835f1bc6..20db5213 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -17,8 +17,6 @@ def initialize(options={}, &failure_cb) @failure_cb = failure_cb @options = DEFAULT_OPTIONS.merge(options) verify_options - initialize_stats - setup_connection log_debug "[#{log_signature}] Client Initialized: %s" % options.inspect rescue @@ -34,6 +32,10 @@ def self.connect(options={}) EM.connect(options[:host], options[:port], self, options) end + # turn post_init back into a no-op for event machine + def post_init + end + ## # Instance Methods # diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index 11d1c088..7b734c11 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -16,6 +16,8 @@ def send_request cnxn.on_success(&success_cb) if success_cb cnxn.on_failure(&ensure_cb) cnxn.on_complete { resume_fiber(f) } unless async? + cnxn.setup_connection + cnxn.send_data log_debug "[#{log_signature}] Connection scheduled" end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index dcbd3781..e5a85bbb 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -30,12 +30,14 @@ def close_connection end def connect_to_rpc_server + return if(@error) @socket = TCPSocket.new(options[:host], options[:port]) log_debug "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" end # Method to determine error state, must be used with Connector api def error? + return true if(@error) log_debug "[client-#{self.class}] Error state : #{@socket.closed?}" @socket.closed? end @@ -52,11 +54,13 @@ def read_data end def read_response + return if(@error) @response_buffer << read_data parse_response if @response_buffer.flushed? end def send_data + return if(@error) @socket.write(@request_buffer.write) @socket.flush log_debug "[client-#{self.class}] write closed" diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 09c1292f..ee9f8565 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -29,12 +29,14 @@ def check_async end def close_connection + return if(@error) zmq_error_check(@socket.close) zmq_error_check(@zmq_context.terminate) log_debug { "[client-#{self.class}] Connector closed" } end def connect_to_rpc_server + return if(@error) log_debug { "[client-#{self.class} Establishing connection: #{options[:host]}:#{options[:port]}" } @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) @@ -44,16 +46,18 @@ def connect_to_rpc_server # Method to determine error state, must be used with Connector api def error? - false + !!@error end def read_response + return if(@error) zmq_error_check(@socket.recv_string(@response_buffer.data)) @response_buffer.get_data_size parse_response end def send_data + return if(@error) log_debug { "[#{log_signature}] Sending Request: %s" % @request_buffer.write } @stats.request_size = @request_buffer.size zmq_error_check(@socket.send_string(@request_buffer.write)) diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb new file mode 100644 index 00000000..aedd4ad9 --- /dev/null +++ b/spec/functional/evented_server_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' +require 'spec/proto/test_service_impl' +require 'pry' + +describe 'Functional EventMachine Client' do + before(:each) do + ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION) + end + + it 'runs fine when required fields are set' do + expect { + EventMachine.fiber_run do + StubServer.new do |server| + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect + end + end + end + EM.stop + end + }.to_not raise_error + end + + it 'calls the on_failure callback when a message is malformed' do + error = nil + EventMachine.fiber_run do + StubServer.new do |server| + request = ::Spec::Proto::ResourceFindRequest.new(:active => true) + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end + end + EM.stop + end + error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ + end + + it 'calls the on_failure callback when the request type is wrong' do + error = nil + EventMachine.fiber_run do + StubServer.new do |server| + request = ::Spec::Proto::Resource.new(:name => 'Test Name') + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end + end + EM.stop + end + error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i + end +end diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb new file mode 100644 index 00000000..8c4de168 --- /dev/null +++ b/spec/functional/socket_server_spec.rb @@ -0,0 +1,64 @@ +require 'spec_helper' +require 'spec/proto/test_service_impl' +require 'pry' + +describe 'Functional Socket Client' do + before(:all) do + Thread.abort_on_exception = true + server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) + @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } + Thread.pass until Protobuf::Rpc::SocketServer.running? + end + + after(:all) do + Protobuf::Rpc::SocketRunner.stop + Thread.kill(@server_thread) + end + + it 'runs fine when required fields are set' do + expect { + with_constants "Protobuf::ClientType" => "Socket" do + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect + end + end + end + }.to_not raise_error + end + + it 'calls the on_failure callback when a message is malformed' do + error = nil + with_constants "Protobuf::ClientType" => "Socket" do + request = ::Spec::Proto::ResourceFindRequest.new(:active => true) + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end + end + error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ + end + + it 'calls the on_failure callback when the request type is wrong' do + error = nil + with_constants "Protobuf::ClientType" => "Socket" do + request = ::Spec::Proto::Resource.new(:name => 'Test Name') + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end + end + error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i + end +end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb new file mode 100644 index 00000000..89dd6d0d --- /dev/null +++ b/spec/functional/zmq_server_spec.rb @@ -0,0 +1,64 @@ +require 'spec_helper' +require 'spec/proto/test_service_impl' +require 'pry' + +describe 'Functional ZMQ Client' do + before(:all) do + Thread.abort_on_exception = true + server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) + @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } + Thread.pass until Protobuf::Rpc::Zmq::Server.running? + end + + after(:all) do + Protobuf::Rpc::ZmqRunner.stop + Thread.kill(@server_thread) + end + + it 'runs fine when required fields are set' do + expect { + with_constants "Protobuf::ClientType" => "Zmq" do + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect + end + end + end + }.to_not raise_error + end + + it 'calls the on_failure callback when a message is malformed' do + error = nil + with_constants "Protobuf::ClientType" => "Zmq" do + request = ::Spec::Proto::ResourceFindRequest.new(:active => true) + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end + end + error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ + end + + it 'calls the on_failure callback when the request type is wrong' do + error = nil + with_constants "Protobuf::ClientType" => "Zmq" do + request = ::Spec::Proto::Resource.new(:name => 'Test Name') + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end + end + error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i + end +end diff --git a/spec/proto/test.pb.rb b/spec/proto/test.pb.rb index 9341fbac..8337b181 100644 --- a/spec/proto/test.pb.rb +++ b/spec/proto/test.pb.rb @@ -12,7 +12,7 @@ class StatusType < ::Protobuf::Enum define :DELETED, 3 end class ResourceFindRequest < ::Protobuf::Message - optional :string, :name, 1 + required :string, :name, 1 optional :bool, :active, 2 end class Resource < ::Protobuf::Message diff --git a/spec/proto/test.proto b/spec/proto/test.proto index 90337ecf..838a6495 100644 --- a/spec/proto/test.proto +++ b/spec/proto/test.proto @@ -8,7 +8,7 @@ enum StatusType { } message ResourceFindRequest { - optional string name = 1; + required string name = 1; optional bool active = 2; } @@ -28,4 +28,4 @@ message Nested { service TestService { rpc Find (ResourceFindRequest) returns (Resource); -} \ No newline at end of file +} diff --git a/spec/unit/rpc/servers/zmq/server_spec.rb b/spec/unit/rpc/servers/zmq/server_spec.rb index b0d4a70c..9ba08365 100644 --- a/spec/unit/rpc/servers/zmq/server_spec.rb +++ b/spec/unit/rpc/servers/zmq/server_spec.rb @@ -2,16 +2,6 @@ require 'protobuf/rpc/servers/zmq/server' describe Protobuf::Rpc::Zmq::Server do - it 'functions' do - StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - with_constants "Protobuf::ClientType" => "Zmq" do - client = Spec::Proto::TestService.client(:async => false, :port => 9399) - client.find(:name => "Test Name", :active => true) - end - server.stop - end - end - describe '.running?' do it 'returns true if running' do described_class.instance_variable_set(:@running, true) diff --git a/spec/unit/rpc/service_spec.rb b/spec/unit/rpc/service_spec.rb index 4b200f74..c02787cc 100644 --- a/spec/unit/rpc/service_spec.rb +++ b/spec/unit/rpc/service_spec.rb @@ -58,18 +58,18 @@ def bad_var it 'raises an undefined method name error when calling a method on a non-existant object' do expect { - req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new.to_s) + req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new(:name => 'mmeh').to_s) ::NewTestService.new.bad_method(req) }.to raise_error(NoMethodError) end it 'raises a name error when accessing a non-existant object' do expect { - req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new.to_s) + req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new(:name => 'mmeh').to_s) ::NewTestService.new.bad_var(req) }.to raise_error(NameError) end end -end \ No newline at end of file +end From 775879265ee6b6d29a12843846510bbe6b61c4cd Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Thu, 24 May 2012 16:01:54 -0600 Subject: [PATCH 0038/1191] fixed dangling specs --- spec/unit/rpc/service_spec.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/unit/rpc/service_spec.rb b/spec/unit/rpc/service_spec.rb index c02787cc..aa6dcf82 100644 --- a/spec/unit/rpc/service_spec.rb +++ b/spec/unit/rpc/service_spec.rb @@ -20,9 +20,13 @@ client.options[:port].should == 12345 end - it 'should be able to configure and read the host' do - Spec::Proto::TestService.configure :host => 'somehost.com' - Spec::Proto::TestService.host.should == 'somehost.com' + context 'configuring host' do + before(:each) { Spec::Proto::TestService.configure :host => 'somehost.com' } + after(:each) { Spec::Proto::TestService.configure :host => '127.0.0.1' } + + it 'should be able to configure and read the host' do + Spec::Proto::TestService.host.should == 'somehost.com' + end end it 'should be able to configure and read the port' do From b293a756c3a5f32a04c059d24642ed14e4d61cf4 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Thu, 24 May 2012 17:18:02 -0600 Subject: [PATCH 0039/1191] converted ipc to tcp --- lib/protobuf/rpc/servers/zmq/broker.rb | 13 +++++++------ lib/protobuf/rpc/servers/zmq/server.rb | 3 ++- lib/protobuf/rpc/servers/zmq/util.rb | 4 ++++ lib/protobuf/rpc/servers/zmq/worker.rb | 16 +++++++++++----- spec/unit/message_spec.rb | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 61bfeb71..30b3a5df 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -14,7 +14,7 @@ class Broker def initialize(opts={}) @context = ::ZMQ::Context.new @frontend = setup_frontend(opts) - @backend = setup_backend + @backend = setup_backend(opts) @poller = setup_poller end @@ -53,13 +53,14 @@ def move_to(frontend_or_backend, socket) end end - def resolve_ip(hostname) - ::Resolv.getaddress(hostname) - end - def setup_backend(opts={}) + dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) + host = dealer_options.fetch(:host, "127.0.0.1") + port = dealer_options.fetch(:port, 9400) + protocol = dealer_options.fetch(:protocol, "tcp") + zmq_backend = context.socket(::ZMQ::DEALER) - zmq_error_check(zmq_backend.bind("ipc://backend.ipc")) + zmq_error_check(zmq_backend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) zmq_backend end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 74056464..03e920ec 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -17,9 +17,10 @@ def self.run(opts = {}) @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts) local_worker_threads = opts.fetch(:threads, 10) + worker_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) log_debug { "[#{log_signature}] starting server workers" } local_worker_threads.times do - @threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new.run } + @threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run } end @running = true diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 3cc161ce..8fa7f2bf 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -16,6 +16,10 @@ def log_signature @log_signature ||= "server-#{self.class}-#{object_id}" end + def resolve_ip(hostname) + ::Resolv.getaddress(hostname) + end + end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index ea1b85f1..ad9e5cba 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -11,12 +11,18 @@ class Worker ## # Constructor # - def initialize + def initialize(opts={}) + + @options = opts + host = @options.fetch(:host, "127.0.0.1") + port = @options.fetch(:port, 9400) + protocol = @options.fetch(:protocol, "tcp") + @zmq_context = ::ZMQ::Context.new - @poller = ::ZMQ::Poller.new @socket = @zmq_context.socket(::ZMQ::REP) - # needs a unique name that matches the DEALER's name - zmq_error_check(@socket.connect("ipc://backend.ipc")) + zmq_error_check(@socket.connect("#{protocol}://#{resolve_ip(host)}:#{port}")) + + @poller = ::ZMQ::Poller.new @poller.register(@socket, ::ZMQ::POLLIN) end @@ -41,7 +47,7 @@ def initialize_buffers def run while ::Protobuf::Rpc::Zmq::Server.running? do - # poll for 100 milliseconds then continue looping + # poll for 1_000 milliseconds then continue looping # This lets us see whether we need to die @poller.poll(1_000) @poller.readables.each do |socket| diff --git a/spec/unit/message_spec.rb b/spec/unit/message_spec.rb index 5a76ad92..a456a698 100644 --- a/spec/unit/message_spec.rb +++ b/spec/unit/message_spec.rb @@ -64,4 +64,4 @@ end -end \ No newline at end of file +end From 99cbef4af4c653d9f753473bfee2e139d2de58b1 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 25 May 2012 11:32:48 -0600 Subject: [PATCH 0040/1191] failing gracefully when send_data errs in eventmachine client --- lib/protobuf/rpc/connectors/em_client.rb | 2 ++ .../connectors/eventmachine_client_spec.rb | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 20db5213..e9c78ba9 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -63,6 +63,8 @@ def receive_data(data) def send_data log_debug { "[#{log_signature}] sending data: #{@request_buffer.inspect}" } super(@request_buffer.write) + rescue + fail(:RPC_ERROR, 'Connection error: %s' % $!.message) end # overwriting this method for java because it's broken in eventmachine. See https://github.com/eventmachine/eventmachine/issues/14 diff --git a/spec/unit/rpc/connectors/eventmachine_client_spec.rb b/spec/unit/rpc/connectors/eventmachine_client_spec.rb index e69de29b..61d9bdd8 100644 --- a/spec/unit/rpc/connectors/eventmachine_client_spec.rb +++ b/spec/unit/rpc/connectors/eventmachine_client_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe ::Protobuf::Rpc::Connectors::EMClient do + describe '#send_data' do + context 'when sending data errs' do + let(:buffer_double) do + bd = double(Protobuf::Rpc::Buffer) + bd.should_receive(:set_data) + bd + end + + it 'sets the error instance' do + buffer_double.should_receive(:write).and_raise(RuntimeError.new('Failure for testing')) + Protobuf::Rpc::Buffer.stub(:new).with(:read).and_return(Protobuf::Rpc::Buffer.new(:read)) + Protobuf::Rpc::Buffer.stub(:new).with(:write).and_return(buffer_double) + error = nil + test_proc = Proc.new do + StubServer.new do |server| + client = ::Spec::Proto::TestService.client + client.find(:name => 'Test Name', :active => true) do |c| + c.on_failure do |f| + error = f + end + end + end + end + test_proc.call + error.should_not be_nil + end + end + end +end From 4f4bb3e7cb56a5502e40a8d1844dd7514494e8ce Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 25 May 2012 15:06:56 -0600 Subject: [PATCH 0041/1191] changed all logging to use blocks instead of strings --- lib/protobuf/rpc/client.rb | 16 ++++++++-------- lib/protobuf/rpc/connectors/em_client.rb | 6 +++--- lib/protobuf/rpc/connectors/eventmachine.rb | 4 ++-- lib/protobuf/rpc/connectors/socket.rb | 10 +++++----- lib/protobuf/rpc/servers/socket_server.rb | 6 +++--- lib/protobuf/rpc/service.rb | 10 +++++----- spec/helper/server.rb | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 189ba982..a3bab0b7 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -29,7 +29,7 @@ class Client def initialize(opts={}) raise "Invalid client configuration. Service must be defined." if opts[:service].nil? @connector = Connector.connector_for_client.new(opts) - log_debug "[#{log_signature}] Initialized with options: %s" % opts.inspect + log_debug { "[#{log_signature}] Initialized with options: %s" % opts.inspect } end def log_signature @@ -109,25 +109,25 @@ def on_success=(callable) def method_missing(method, *params) service = options[:service] unless service.rpcs[service].keys.include?(method) - log_error "[#{log_signature}] %s#%s not rpc method, passing to super" % [service.name, method.to_s] + log_error { "[#{log_signature}] %s#%s not rpc method, passing to super" % [service.name, method.to_s] } super(method, *params) else - log_debug "[#{log_signature}] %s#%s" % [service.name, method.to_s] + log_debug { "[#{log_signature}] %s#%s" % [service.name, method.to_s] } rpc = service.rpcs[service][method.to_sym] options[:request_type] = rpc.request_type - log_debug "[#{log_signature}] Request Type: %s" % options[:request_type].name + log_debug { "[#{log_signature}] Request Type: %s" % options[:request_type].name } options[:response_type] = rpc.response_type - log_debug "[#{log_signature}] Response Type: %s" % options[:response_type].name + log_debug { "[#{log_signature}] Response Type: %s" % options[:response_type].name } options[:method] = method.to_s options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0] - log_debug "[#{log_signature}] Request Data: %s" % options[:request].inspect + log_debug { "[#{log_signature}] Request Data: %s" % options[:request].inspect } # Call client to setup on_success and on_failure event callbacks if block_given? - log_debug "[#{log_signature}] client setup callback given, invoking" + log_debug { "[#{log_signature}] client setup callback given, invoking" } yield(self) else - log_debug "[#{log_signature}] no block given for callbacks" + log_debug { "[#{log_signature}] no block given for callbacks" } end send_request diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index e9c78ba9..96286754 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -18,7 +18,7 @@ def initialize(options={}, &failure_cb) @options = DEFAULT_OPTIONS.merge(options) verify_options - log_debug "[#{log_signature}] Client Initialized: %s" % options.inspect + log_debug { "[#{log_signature}] Client Initialized: %s" % options.inspect } rescue fail(:RPC_ERROR, 'Failed to initialize connection: %s' % $!.message) end @@ -28,7 +28,7 @@ def initialize(options={}, &failure_cb) # def self.connect(options={}) options = DEFAULT_OPTIONS.merge(options) - log_debug "[client-#{self}] Connecting to server: %s" % options.inspect + log_debug { "[client-#{self}] Connecting to server: %s" % options.inspect } EM.connect(options[:host], options[:port], self, options) end @@ -55,7 +55,7 @@ def on_success(&success_cb) end def receive_data(data) - log_debug "[#{log_signature}] receive_data: %s" % data + log_debug { "[#{log_signature}] receive_data: %s" % data } @response_buffer << data parse_response if @response_buffer.flushed? end diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index 7b734c11..52393f30 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -11,14 +11,14 @@ def send_request f = Fiber.current EM.next_tick do - log_debug "[#{log_signature}] Scheduling EventMachine client request to be created on next tick" + log_debug { "[#{log_signature}] Scheduling EventMachine client request to be created on next tick" } cnxn = EMClient.connect(options, &ensure_cb) cnxn.on_success(&success_cb) if success_cb cnxn.on_failure(&ensure_cb) cnxn.on_complete { resume_fiber(f) } unless async? cnxn.setup_connection cnxn.send_data - log_debug "[#{log_signature}] Connection scheduled" + log_debug { "[#{log_signature}] Connection scheduled" } end async? ? true : set_timeout_and_validate_fiber diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index e5a85bbb..6f7dd3a6 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -19,26 +19,26 @@ def send_request def check_async if async? - log_error "[client-#{self.class}] Cannot run in async mode" + log_error { "[client-#{self.class}] Cannot run in async mode" } raise "Cannot use Socket client in async mode" end end def close_connection @socket.close - log_debug "[client-#{self.class}] Connector closed" + log_debug { "[client-#{self.class}] Connector closed" } end def connect_to_rpc_server return if(@error) @socket = TCPSocket.new(options[:host], options[:port]) - log_debug "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" + log_debug { "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" } end # Method to determine error state, must be used with Connector api def error? return true if(@error) - log_debug "[client-#{self.class}] Error state : #{@socket.closed?}" + log_debug { "[client-#{self.class}] Error state : #{@socket.closed?}" } @socket.closed? end @@ -63,7 +63,7 @@ def send_data return if(@error) @socket.write(@request_buffer.write) @socket.flush - log_debug "[client-#{self.class}] write closed" + log_debug { "[client-#{self.class}] write closed" } end end diff --git a/lib/protobuf/rpc/servers/socket_server.rb b/lib/protobuf/rpc/servers/socket_server.rb index aa916c5f..ff13b8bd 100644 --- a/lib/protobuf/rpc/servers/socket_server.rb +++ b/lib/protobuf/rpc/servers/socket_server.rb @@ -40,7 +40,7 @@ def self.new_worker(socket) end def self.run(opts = {}) - log_debug "[#{log_signature}] Run" + log_debug { "[#{log_signature}] Run" } host = opts.fetch(:host, "127.0.0.1") port = opts.fetch(:port, 9399) backlog = opts.fetch(:backlog, 100) @@ -65,13 +65,13 @@ def self.run(opts = {}) when !running? then # no-op when client == @server then - log_debug "[#{log_signature}] Accepted new connection" + log_debug { "[#{log_signature}] Accepted new connection" } client, sockaddr = @server.accept @listen_fds << client else if !@working.include?(client) @working << @listen_fds.delete(client) - log_debug "[#{log_signature}] Working" + log_debug { "[#{log_signature}] Working" } @threads << { :thread => new_worker(client), :socket => client } cleanup_threads if cleanup? diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index f8ceae12..0db5f1c7 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -130,7 +130,7 @@ def method_missing m, *params log_error exc.message raise exc else - log_error "-------------- [#{log_signature}] %s#%s not rpc method, passing to super" % [self.class.name, m.to_s] + log_error { "-------------- [#{log_signature}] %s#%s not rpc method, passing to super" % [self.class.name, m.to_s] } super m, params end end @@ -221,17 +221,17 @@ def call_rpc(method, pb_request) # Setup the response @response = rpcs[method].response_type.new - log_debug "[#{log_signature}] calling service method %s#%s" % [self.class, method] + log_debug { "[#{log_signature}] calling service method %s#%s" % [self.class, method] } # Call the aliased rpc method (e.g. :rpc_find for :find) __send__("rpc_#{method}".to_sym) - log_debug "[#{log_signature}] completed service method %s#%s" % [self.class, method] + log_debug { "[#{log_signature}] completed service method %s#%s" % [self.class, method] } # Pass the populated response back to the server # Note this will only get called if the rpc method didn't explode (by design) if @async_responder - log_debug "[#{log_signature}] async request, not sending response (yet)" + log_debug { "[#{log_signature}] async request, not sending response (yet)" } else - log_debug "[#{log_signature}] trigger server send_response" + log_debug { "[#{log_signature}] trigger server send_response" } send_response end end diff --git a/spec/helper/server.rb b/spec/helper/server.rb index 2e8243c4..5d0874a6 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -59,7 +59,7 @@ def start else start_socket_server end - log_debug "[stub-server] Server started #{@options.host}:#{@options.port}" + log_debug { "[stub-server] Server started #{@options.host}:#{@options.port}" } rescue => ex if ex =~ /no acceptor/ # Means EM didn't shutdown in the next_tick yet stop From 45a233a7be5836efbf938c0da74b0d4a72cd0633 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 25 May 2012 15:12:00 -0600 Subject: [PATCH 0042/1191] zeromq library missing message Let ffi-rzmq tell people they're missing the zeromq library. Only allow this error to pop up if they try requiring the zeromq client or server. --- lib/protobuf.rb | 23 ++++++----------------- spec/spec_helper.rb | 5 +++++ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index df225b10..1ab6b5f7 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -9,13 +9,18 @@ module Protobuf Protobuf::ClientType = ENV['PB_CLIENT_TYPE'] if ENV['PB_CLIENT_TYPE'] Protobuf::ServerType = ENV['PB_SERVER_TYPE'] if ENV['PB_SERVER_TYPE'] +# Socket Client/Server loaded by default as it has no impact on cross-platform issues +require 'protobuf/rpc/servers/socket_server' +require 'protobuf/rpc/connectors/socket' +require 'protobuf/rpc/client' +require 'protobuf/rpc/service' + # When setting up a client case when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Asocket\Z/i then #no-op when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Azmq\Z/i then require 'ffi-rzmq' - require 'protobuf/rpc/client' require 'protobuf/rpc/connectors/zmq' else Protobuf::ClientType = "EventMachine" @@ -30,7 +35,6 @@ module Protobuf #no-op when defined?(Protobuf::ServerType) && Protobuf::ServerType =~ /\Azmq\Z/i then require 'ffi-rzmq' - require 'protobuf/rpc/service' require 'protobuf/rpc/servers/zmq_server' else Protobuf::ServerType = "EventedServer" @@ -38,18 +42,3 @@ module Protobuf require 'protobuf/ext/eventmachine' require 'protobuf/rpc/servers/evented_server' end - -# Socket Client/Server loaded by default as it has no impact on cross-platform issues -require 'protobuf/rpc/service' -require 'protobuf/rpc/servers/socket_server' - - require 'ffi-rzmq' - require 'protobuf/rpc/client' - require 'protobuf/rpc/connectors/zmq' - -require 'protobuf/rpc/client' -require 'protobuf/rpc/connectors/socket' - -# set_trace_func proc { |event, file, line, id, binding, classname| -# printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname -# } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d9e647d9..52a3025b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,11 @@ require File.dirname(__FILE__) + '/helper/all' require 'pry' +# these aren't explicitly required in lib/protobuf.rb. We require them here for +# testing purposes +require 'ffi-rzmq' +require 'protobuf/rpc/connectors/zmq' + # Including a way to turn on debug logger for spec runs if ENV["DEBUG"] debug_log = File.expand_path('../debug_specs.log', File.dirname(__FILE__) ) From cb1305ce75cde4ef1c69c23cddcc394549fa289e Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 25 May 2012 16:54:10 -0600 Subject: [PATCH 0043/1191] removed pry from files that don't need to be requiring it --- lib/protobuf/rpc/servers/zmq/server.rb | 1 - spec/functional/evented_server_spec.rb | 1 - spec/functional/socket_server_spec.rb | 1 - spec/functional/zmq_server_spec.rb | 1 - 4 files changed, 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 03e920ec..31499e15 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -1,7 +1,6 @@ require 'protobuf/rpc/servers/zmq/broker' require 'protobuf/rpc/servers/zmq/worker' require 'protobuf/rpc/servers/zmq/util' -require 'pry' module Protobuf module Rpc diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index aedd4ad9..6eeae3bd 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper' require 'spec/proto/test_service_impl' -require 'pry' describe 'Functional EventMachine Client' do before(:each) do diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 8c4de168..b14b137d 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper' require 'spec/proto/test_service_impl' -require 'pry' describe 'Functional Socket Client' do before(:all) do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 89dd6d0d..217c76d2 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper' require 'spec/proto/test_service_impl' -require 'pry' describe 'Functional ZMQ Client' do before(:all) do From 599b8696c4a88977ff89f07be45a0b55882627ba Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 10:35:43 -0600 Subject: [PATCH 0044/1191] Switched socket server to parse its own buffer socket server now handles its own buffers. Broke out classes into their own files for readability and testability --- lib/protobuf/rpc/server.rb | 32 ++--- lib/protobuf/rpc/servers/socket/server.rb | 106 +++++++++++++++ lib/protobuf/rpc/servers/socket/worker.rb | 58 +++++++++ lib/protobuf/rpc/servers/socket_runner.rb | 4 +- lib/protobuf/rpc/servers/socket_server.rb | 149 ---------------------- 5 files changed, 180 insertions(+), 169 deletions(-) create mode 100644 lib/protobuf/rpc/servers/socket/server.rb create mode 100644 lib/protobuf/rpc/servers/socket/worker.rb delete mode 100644 lib/protobuf/rpc/servers/socket_server.rb diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index c20b1163..63fd2f29 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -6,20 +6,18 @@ module Protobuf module Rpc - module Server - + module Server + # Invoke the service method dictated by the proto wrapper request object def handle_client - @stats.request_size = @request_buffer.size - # Parse the protobuf request from the socket log_debug { "[#{log_signature}] Parsing request from client" } parse_request_from_buffer - + # Determine the service class and method name from the request log_debug { "[#{log_signature}] Extracting procedure call info from request" } parse_service_info - + # Call the service method log_debug { "[#{log_signature}] Dispatching client request to service" } invoke_rpc_method @@ -42,12 +40,12 @@ def handle_error(error) ::Protobuf::Rpc::PbError.new(message, code).to_response(@response) end end - + # Assuming all things check out, we can call the service method def invoke_rpc_method # Get a new instance of the service @service = @klass.new - + # Define our response callback to perform the "successful" response to our client # This decouples the service's rpc method from our response to the client, # allowing the service to be the dictator for when the response should be sent back. @@ -60,14 +58,14 @@ def invoke_rpc_method send_response end end - + @service.on_rpc_failed do |error| unless @did_respond handle_error(error) send_response end end - + # Call the service method log_debug { "[#{log_signature}] Invoking %s#%s with request %s" % [@klass.name, @method, @request.inspect] } @service.__send__(@method, @request) @@ -76,11 +74,11 @@ def invoke_rpc_method def log_signature @log_signature ||= "server-#{self.class}" end - + # Parse the incoming request object into our expected request object def parse_request_from_buffer - log_debug { "[#{log_signature}] parsing request from buffer: %s" % @request_buffer.data.inspect } - @request.parse_from_string(@request_buffer.data) + log_debug { "[#{log_signature}] parsing request from buffer: %s" % @request_data } + @request.parse_from_string(@request_data) rescue => error exc = ::Protobuf::Rpc::BadRequestData.new 'Unable to parse request: %s' % error.message log_error { exc.message } @@ -92,12 +90,12 @@ def parse_request_from_buffer # response to the protobuf response wrapper def parse_response_from_service(response) expected = @klass.rpcs[@klass][@method].response_type - + # Cannibalize the response if it's a Hash response = expected.new(response) if response.is_a?(Hash) actual = response.class log_debug { "[#{log_signature}] response (should/actual): %s/%s" % [expected.name, actual.name] } - + # Determine if the service tried to change response types on us if expected == actual serialize_response(response) @@ -119,7 +117,7 @@ def parse_service_info unless @klass.instance_methods.include?(@method) raise MethodNotFound, "Service method #{@request.method_name} is not defined by the service" end - + @stats.service = @klass.name @stats.method = @method rescue NameError @@ -130,9 +128,7 @@ def parse_service_info def send_response raise 'Response already sent to client' if @did_respond log_debug { "[#{log_signature}] Sending response to client: %s" % @response.inspect } - @response_buffer.set_data(@response) send_data - @stats.response_size = @response_buffer.size @stats.end @stats.log_stats @did_respond = true diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb new file mode 100644 index 00000000..5e626fdf --- /dev/null +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -0,0 +1,106 @@ +module Protobuf + module Rpc + module Socket + + class Server + include ::Protobuf::Rpc::Server + include ::Protobuf::Logger::LogMethods + + def self.cleanup? + # every 10 connections run a cleanup routine after closing the response + @threads.size > (@thread_threshold - 1) && (@threads.size % @thread_threshold) == 0 + end + + def self.cleanup_threads + log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - start" } + + @threads = @threads.select do |t| + if t[:thread].alive? + true + else + t[:thread].join + @working.delete(t[:socket]) + false + end + end + + log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - complete" } + end + + def self.log_signature + @log_signature ||= "server-#{self}" + end + + def self.new_worker(socket) + Thread.new(socket) do |sock| + ::Protobuf::Rpc::SocketServer::Worker.new(sock) do |s| + s.close + end + end + end + + def self.run(opts = {}) + log_debug { "[#{log_signature}] Run" } + host = opts.fetch(:host, "127.0.0.1") + port = opts.fetch(:port, 9399) + backlog = opts.fetch(:backlog, 100) + thread_threshold = opts.fetch(:thread_threshold, 100) + auto_collect_timeout = opts.fetch(:auto_collect_timeout, 20) + + @threads = [] + @thread_threshold = thread_threshold + @server = ::TCPServer.new(host, port) + @server.listen(backlog) + @working = [] + @listen_fds = [@server] + @running = true + + while running? + log_debug { "[#{log_signature}] Waiting for connections" } + + if ready_cnxns = IO.select(@listen_fds, [], [], auto_collect_timeout) + cnxns = ready_cnxns.first + cnxns.each do |client| + case + when !running? then + # no-op + when client == @server then + log_debug { "[#{log_signature}] Accepted new connection" } + client, sockaddr = @server.accept + @listen_fds << client + else + if !@working.include?(client) + @working << @listen_fds.delete(client) + log_debug { "[#{log_signature}] Working" } + @threads << { :thread => new_worker(client), :socket => client } + + cleanup_threads if cleanup? + end + end + end + else + # Run a cleanup if select times out while waiting + cleanup_threads if @threads.size > 1 + end + end + + rescue Errno::EADDRINUSE + raise + rescue + # Closing the server causes the loop to raise an exception here + raise if running? + end + + def self.running? + @running + end + + def self.stop + @running = false + @server.close if @server + end + end + + end + end +end diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb new file mode 100644 index 00000000..2afdb25c --- /dev/null +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -0,0 +1,58 @@ +module Protobuf + module Rpc + module Socket + + class Worker + include ::Protobuf::Rpc::Server + include ::Protobuf::Logger::LogMethods + + def initialize(sock, &complete_cb) + @did_response = false + @socket = sock + @request = Protobuf::Socketrpc::Request.new + @response = Protobuf::Socketrpc::Response.new + @response_buffer = Protobuf::Rpc::Buffer.new(:write) + request_buffer = Protobuf::Rpc::Buffer.new(:read) + @stats = Protobuf::Rpc::Stat.new(:SERVER, true) + @complete_cb = complete_cb + log_debug { "[#{log_signature}] Post init, new read buffer created" } + + @stats.client = Socket.unpack_sockaddr_in(@socket.getpeername) + log_debug { "stats are #{@stats.to_s}" } + request_buffer << read_data + @request_data = request_buffer.data + + @stats.request_size = request_buffer.size + + log_debug { "[#{log_signature}] handling request" } + handle_client if request_buffer.flushed? + end + + def log_signature + @log_signature ||= "server-#{self.class}-#{object_id}" + end + + def read_data + size_io = StringIO.new + + while((size_reader = @socket.getc) != "-") + size_io << size_reader + end + str_size_io = size_io.string + + "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" + end + + def send_data + @response_buffer.set_data(@response) + @stats.response_size = @response_buffer.size + log_debug { "[#{log_signature}] sending data : %s" % @response_buffer.write } + @socket.write(@response_buffer.write) + @socket.flush + @complete_cb.call(@socket) + end + end + + end + end +end diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 54c748f9..d6a64661 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -3,7 +3,7 @@ module Rpc class SocketRunner def self.stop - Protobuf::Rpc::SocketServer.stop + Protobuf::Rpc::Socket::Server.stop Protobuf::Logger.info 'Shutdown complete' end @@ -20,7 +20,7 @@ def self.run(server) raise "Cannot parser Socket Server - server options" end - Protobuf::Rpc::SocketServer.run(server_config) + Protobuf::Rpc::Socket::Server.run(server_config) end end diff --git a/lib/protobuf/rpc/servers/socket_server.rb b/lib/protobuf/rpc/servers/socket_server.rb deleted file mode 100644 index ff13b8bd..00000000 --- a/lib/protobuf/rpc/servers/socket_server.rb +++ /dev/null @@ -1,149 +0,0 @@ -require 'protobuf/rpc/server' - -module Protobuf - module Rpc - class SocketServer - include ::Protobuf::Rpc::Server - include ::Protobuf::Logger::LogMethods - - def self.cleanup? - # every 10 connections run a cleanup routine after closing the response - @threads.size > (@thread_threshold - 1) && (@threads.size % @thread_threshold) == 0 - end - - def self.cleanup_threads - log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - start" } - - @threads = @threads.select do |t| - if t[:thread].alive? - true - else - t[:thread].join - @working.delete(t[:socket]) - false - end - end - - log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - complete" } - end - - def self.log_signature - @log_signature ||= "server-#{self}" - end - - def self.new_worker(socket) - Thread.new(socket) do |sock| - ::Protobuf::Rpc::SocketServer::Worker.new(sock) do |s| - s.close - end - end - end - - def self.run(opts = {}) - log_debug { "[#{log_signature}] Run" } - host = opts.fetch(:host, "127.0.0.1") - port = opts.fetch(:port, 9399) - backlog = opts.fetch(:backlog, 100) - thread_threshold = opts.fetch(:thread_threshold, 100) - auto_collect_timeout = opts.fetch(:auto_collect_timeout, 20) - - @threads = [] - @thread_threshold = thread_threshold - @server = ::TCPServer.new(host, port) - @server.listen(backlog) - @working = [] - @listen_fds = [@server] - @running = true - - while running? - log_debug { "[#{log_signature}] Waiting for connections" } - - if ready_cnxns = IO.select(@listen_fds, [], [], auto_collect_timeout) - cnxns = ready_cnxns.first - cnxns.each do |client| - case - when !running? then - # no-op - when client == @server then - log_debug { "[#{log_signature}] Accepted new connection" } - client, sockaddr = @server.accept - @listen_fds << client - else - if !@working.include?(client) - @working << @listen_fds.delete(client) - log_debug { "[#{log_signature}] Working" } - @threads << { :thread => new_worker(client), :socket => client } - - cleanup_threads if cleanup? - end - end - end - else - # Run a cleanup if select times out while waiting - cleanup_threads if @threads.size > 1 - end - end - - rescue Errno::EADDRINUSE - raise - rescue - # Closing the server causes the loop to raise an exception here - raise if running? - end - - def self.running? - @running - end - - def self.stop - @running = false - @server.close if @server - end - - class Worker - include ::Protobuf::Rpc::Server - include ::Protobuf::Logger::LogMethods - - def initialize(sock, &complete_cb) - @did_response = false - @socket = sock - @request = Protobuf::Socketrpc::Request.new - @response = Protobuf::Socketrpc::Response.new - @response_buffer = Protobuf::Rpc::Buffer.new(:write) - @request_buffer = Protobuf::Rpc::Buffer.new(:read) - @stats = Protobuf::Rpc::Stat.new(:SERVER, true) - @complete_cb = complete_cb - log_debug { "[#{log_signature}] Post init, new read buffer created" } - - @stats.client = Socket.unpack_sockaddr_in(@socket.getpeername) - log_debug { "stats are #{@stats.to_s}" } - @request_buffer << read_data - log_debug { "[#{log_signature}] handling request" } - handle_client if @request_buffer.flushed? - end - - def log_signature - @log_signature ||= "server-#{self.class}-#{object_id}" - end - - def read_data - size_io = StringIO.new - - while((size_reader = @socket.getc) != "-") - size_io << size_reader - end - str_size_io = size_io.string - - "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" - end - - def send_data - log_debug { "[#{log_signature}] sending data : %s" % @response_buffer.write } - @socket.write(@response_buffer.write) - @socket.flush - @complete_cb.call(@socket) - end - end - end - end -end From 5dd57114894bdbdb20ff89253d2f82d7f59ea378 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 10:42:40 -0600 Subject: [PATCH 0045/1191] buffer handling in eventmachine server Broke evented server into its own files according to the newly established pattern. Fixed buffers --- lib/protobuf/rpc/servers/evented/server.rb | 43 ++++++++++++++++++++++ lib/protobuf/rpc/servers/evented_runner.rb | 2 +- lib/protobuf/rpc/servers/evented_server.rb | 35 ------------------ 3 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 lib/protobuf/rpc/servers/evented/server.rb delete mode 100644 lib/protobuf/rpc/servers/evented_server.rb diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb new file mode 100644 index 00000000..77bc6616 --- /dev/null +++ b/lib/protobuf/rpc/servers/evented/server.rb @@ -0,0 +1,43 @@ +require 'protobuf/rpc/server' + +module Protobuf + module Rpc + module Evented + class Server < ::EventMachine::Connection + include ::Protobuf::Rpc::Server + include ::Protobuf::Logger::LogMethods + + # Initialize a new read buffer for storing client request info + def post_init + log_debug { '[server] Post init, new read buffer created' } + @stats = Protobuf::Rpc::Stat.new(:SERVER, true) + @stats.client = Socket.unpack_sockaddr_in(get_peername) + + @response_buffer = Protobuf::Rpc::Buffer.new(:write) + @request_buffer = Protobuf::Rpc::Buffer.new(:read) + @did_respond = false + end + + # Receive a chunk of data, potentially flushed to handle_client + def receive_data(data) + log_debug { '[server] receive_data: %s' % data } + + @request_buffer << data + @request_data = @request_buffer.data + @stats.request_size = @request_buffer.size + + @request = ::Protobuf::Socketrpc::Request.new + @response = ::Protobuf::Socketrpc::Response.new + handle_client if @request_buffer.flushed? + end + + def send_data + @response_buffer.set_data(@response) + @stats.response_size = @response_buffer.size + log_debug { "[#{log_signature}] sending data: #{@response_buffer.inspect}" } + super(@response_buffer.write) + end + end + end + end +end diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index 951f09c1..17818597 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -20,7 +20,7 @@ def self.run(server) # Startup and run the rpc server EM.schedule do - EventMachine.start_server(server.host, server.port, Protobuf::Rpc::EventedServer) && \ + EventMachine.start_server(server.host, server.port, Protobuf::Rpc::Evented::Server) && \ Protobuf::Logger.info('RPC Server listening at %s:%d in %s' % [server.host, server.port, server.env]) end diff --git a/lib/protobuf/rpc/servers/evented_server.rb b/lib/protobuf/rpc/servers/evented_server.rb deleted file mode 100644 index 601c251a..00000000 --- a/lib/protobuf/rpc/servers/evented_server.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'protobuf/rpc/server' - -module Protobuf - module Rpc - class EventedServer < ::EventMachine::Connection - include ::Protobuf::Rpc::Server - include ::Protobuf::Logger::LogMethods - - # Initialize a new read buffer for storing client request info - def post_init - log_debug { '[server] Post init, new read buffer created' } - @stats = Protobuf::Rpc::Stat.new(:SERVER, true) - @stats.client = Socket.unpack_sockaddr_in(get_peername) - - @response_buffer = Protobuf::Rpc::Buffer.new(:write) - @request_buffer = Protobuf::Rpc::Buffer.new(:read) - @did_respond = false - end - - # Receive a chunk of data, potentially flushed to handle_client - def receive_data(data) - log_debug { '[server] receive_data: %s' % data } - @request_buffer << data - @request = ::Protobuf::Socketrpc::Request.new - @response = ::Protobuf::Socketrpc::Response.new - handle_client if @request_buffer.flushed? - end - - def send_data - log_debug { "[#{log_signature}] sending data: #{@response_buffer.inspect}" } - super(@response_buffer.write) - end - end - end -end From e776b565ac16158e76a2f4313f48ed3bc89d039d Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 11:14:31 -0600 Subject: [PATCH 0046/1191] switched buffers out of zmq worker --- lib/protobuf/rpc/servers/zmq/worker.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index ad9e5cba..56dfb42f 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -30,19 +30,16 @@ def initialize(opts={}) # Instance Methods # def handle_request(socket) - zmq_error_check(socket.recv_string(@request_buffer.data)) - @request_buffer.get_data_size - log_debug { "[#{log_signature}] handling request" } if(!@request_buffer.data.nil?) + zmq_error_check(socket.recv_string(@request_data)) + log_debug { "[#{log_signature}] handling request" } if(!@request_data.nil?) end def initialize_buffers @did_respond = false @request = ::Protobuf::Socketrpc::Request.new @response = ::Protobuf::Socketrpc::Response.new - @request_buffer = ::Protobuf::Rpc::Buffer.new(:read) - @response_buffer = ::Protobuf::Rpc::Buffer.new(:write) @stats = ::Protobuf::Rpc::Stat.new(:SERVER, true) - log_debug { "[#{log_signature}] Post init, new read buffer created" } + log_debug { "[#{log_signature}] Post init" } end def run @@ -53,7 +50,7 @@ def run @poller.readables.each do |socket| initialize_buffers handle_request(socket) - handle_client unless(@request_buffer.data.nil?) + handle_client unless(@request_data.nil?) end end ensure @@ -62,7 +59,10 @@ def run end def send_data - zmq_error_check(@socket.send_string(@response_buffer.write)) + response_data = @response.is_a?(Protobuf::Message) ? @response.serialize_to_string : @response.to_s + @stats.response_size = response_data.size + zmq_error_check(@socket.send_string(response_data)) + @did_respond = true end end From bf0ba3ddcd23873ecc4e65473e48d690b24f5ab6 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 11:31:34 -0600 Subject: [PATCH 0047/1191] removed buffers from connectors/common --- lib/protobuf/rpc/connectors/common.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index b4d05418..4ef72da7 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -1,8 +1,8 @@ module Protobuf - module Rpc + module Rpc module Connectors - module Common - + module Common + attr_reader :error def any_callbacks? @@ -33,7 +33,7 @@ def fail(code, message) @error.code = code.is_a?(Symbol) ? Protobuf::Socketrpc::ErrorReason.values[code] : code @error.message = message log_debug { "[#{log_signature}] Server failed request (invoking on_failure): %s" % @error.inspect } - + @failure_cb.call(@error) unless @failure_cb.nil? rescue log_error { "[#{log_signature}] Failure callback error encountered: %s" % $!.message } @@ -49,7 +49,7 @@ def initialize_stats @stats.service = @options[:service].name @stats.method = @options[:method].to_s rescue => ex - fail(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") + fail(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") end def log_signature @@ -61,11 +61,10 @@ def parse_response close_connection log_debug { "[#{log_signature}] Parsing response from server (connection closed)" } - @stats.response_size = @response_buffer.size # Parse out the raw response response_wrapper = Protobuf::Socketrpc::Response.new - response_wrapper.parse_from_string(@response_buffer.data) + response_wrapper.parse_from_string(@response_data) # Determine success or failure based on parsed data if response_wrapper.has_field?(:error_reason) @@ -111,9 +110,6 @@ def request_wrapper def setup_connection initialize_stats - @response_buffer = Protobuf::Rpc::Buffer.new(:read) - @request_buffer = Protobuf::Rpc::Buffer.new(:write) - @request_buffer.set_data(request_wrapper) end def succeed(response) @@ -123,7 +119,7 @@ def succeed(response) log_error { "[#{log_signature}] Success callback error encountered: %s" % $!.message } log_error { "[#{log_signature}] %s" % $!.backtrace.join("\n") } fail :RPC_ERROR, 'An exception occurred while calling on_success: %s' % $!.message - ensure + ensure complete end From d87441e481d959f51756e4907ba636bff1d77cb6 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 11:31:57 -0600 Subject: [PATCH 0048/1191] made socket connector handle buffers as part of its protocol --- lib/protobuf/rpc/connectors/socket.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 6f7dd3a6..4f96f9b7 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -6,7 +6,7 @@ module Connectors class Socket < Base include Protobuf::Rpc::Connectors::Common include Protobuf::Logger::LogMethods - + def send_request check_async setup_connection @@ -20,7 +20,7 @@ def send_request def check_async if async? log_error { "[client-#{self.class}] Cannot run in async mode" } - raise "Cannot use Socket client in async mode" + raise "Cannot use Socket client in async mode" end end @@ -55,13 +55,18 @@ def read_data def read_response return if(@error) - @response_buffer << read_data - parse_response if @response_buffer.flushed? + response_buffer = ::Protobuf::Rpc::Buffer.new(:read) + response_buffer << read_data + @stats.response_size = response_buffer.size + @response_data = response_buffer.write + parse_response if response_buffer.flushed? end def send_data return if(@error) - @socket.write(@request_buffer.write) + request_buffer = ::Protobuf::Rpc::Buffer.new(:write) + request_buffer.set_data(request_wrapper) + @socket.write(request_buffer.write) @socket.flush log_debug { "[client-#{self.class}] write closed" } end From e707fb89b3fa2e71d94a0895a9ac93feeebb02a3 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 11:37:33 -0600 Subject: [PATCH 0049/1191] removed buffer instance variables from em_client --- lib/protobuf/rpc/connectors/em_client.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 96286754..ce23a8fa 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -2,14 +2,14 @@ module Protobuf module Rpc module Connectors - + class EMClient < EM::Connection include Protobuf::Logger::LogMethods include Protobuf::Rpc::Connectors::Common - + attr_reader :options, :request, :response attr_reader :error, :error_reason, :error_message - + ## # Constructor # @@ -48,25 +48,29 @@ def on_complete(&complete_cb) def on_failure(&failure_cb) @failure_cb = failure_cb end - + # Success callback registration def on_success(&success_cb) @success_cb = success_cb end def receive_data(data) + response_buffer = ::Protobuf::Rpc::Buffer.new(:read) log_debug { "[#{log_signature}] receive_data: %s" % data } - @response_buffer << data - parse_response if @response_buffer.flushed? + response_buffer << data + @response_data = response_buffer.data + parse_response if response_buffer.flushed? end def send_data - log_debug { "[#{log_signature}] sending data: #{@request_buffer.inspect}" } - super(@request_buffer.write) + request_buffer = ::Protobuf::Rpc::Buffer.new(:read) + request_buffer.set_data(request_wrapper) + log_debug { "[#{log_signature}] sending data: #{request_buffer.inspect}" } + super(request_buffer.write) rescue fail(:RPC_ERROR, 'Connection error: %s' % $!.message) end - + # overwriting this method for java because it's broken in eventmachine. See https://github.com/eventmachine/eventmachine/issues/14 if RUBY_PLATFORM =~ /java/ def error? From 72c52f9bda83395bdaa6dd0834d0d159b50dd76a Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 11:39:39 -0600 Subject: [PATCH 0050/1191] removed buffers from zmq client --- lib/protobuf/rpc/connectors/zmq.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index ee9f8565..8cb8569d 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -51,16 +51,16 @@ def error? def read_response return if(@error) - zmq_error_check(@socket.recv_string(@response_buffer.data)) - @response_buffer.get_data_size + zmq_error_check(@socket.recv_string(@response_data)) parse_response end def send_data return if(@error) - log_debug { "[#{log_signature}] Sending Request: %s" % @request_buffer.write } - @stats.request_size = @request_buffer.size - zmq_error_check(@socket.send_string(@request_buffer.write)) + request_data = request_wrapper.serialize_to_string + log_debug { "[#{log_signature}] Sending Request: %s" % request_data } + @stats.request_size = request_data.size + zmq_error_check(@socket.send_string(request_data)) log_debug { "[client-#{self.class}] write closed" } end From 5cd0d2f886f6431a46f63538b259a701c1b78ba9 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 16:07:58 -0600 Subject: [PATCH 0051/1191] fixed specs to work with buffer rip-out --- lib/protobuf.rb | 8 +++---- lib/protobuf/rpc/connectors/common.rb | 5 ++-- lib/protobuf/rpc/connectors/em_client.rb | 8 +++---- lib/protobuf/rpc/connectors/socket.rb | 10 ++++---- lib/protobuf/rpc/connectors/zmq.rb | 8 +++---- lib/protobuf/rpc/servers/evented/server.rb | 22 +++++++++--------- lib/protobuf/rpc/servers/socket/server.rb | 4 +++- lib/protobuf/rpc/servers/socket/worker.rb | 12 +++++----- lib/protobuf/rpc/servers/socket_runner.rb | 2 +- lib/protobuf/rpc/servers/zmq/worker.rb | 1 + spec/benchmark/tasks.rb | 4 ++-- spec/functional/evented_server_spec.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/helper/server.rb | 12 +++++----- spec/unit/rpc/connectors/socket_spec.rb | 5 ++-- spec/unit/rpc/servers/evented_server_spec.rb | 6 ++--- spec/unit/rpc/servers/socket_server_spec.rb | 24 ++++++++++---------- 17 files changed, 69 insertions(+), 66 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 1ab6b5f7..9b152629 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -10,7 +10,7 @@ module Protobuf Protobuf::ServerType = ENV['PB_SERVER_TYPE'] if ENV['PB_SERVER_TYPE'] # Socket Client/Server loaded by default as it has no impact on cross-platform issues -require 'protobuf/rpc/servers/socket_server' +require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/connectors/socket' require 'protobuf/rpc/client' require 'protobuf/rpc/service' @@ -35,10 +35,10 @@ module Protobuf #no-op when defined?(Protobuf::ServerType) && Protobuf::ServerType =~ /\Azmq\Z/i then require 'ffi-rzmq' - require 'protobuf/rpc/servers/zmq_server' + require 'protobuf/rpc/servers/zmq/server' else - Protobuf::ServerType = "EventedServer" + Protobuf::ServerType = "Evented::Server" require 'eventmachine' require 'protobuf/ext/eventmachine' - require 'protobuf/rpc/servers/evented_server' + require 'protobuf/rpc/servers/evented/server' end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 4ef72da7..706c13ad 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -96,20 +96,21 @@ def post_init fail(:RPC_ERROR, 'Connection error: %s' % $!.message) end - def request_wrapper + def rpc_request_data validate_request_type return Protobuf::Socketrpc::Request.new( :service_name => @options[:service].name, :method_name => @options[:method].to_s, :request_proto => @options[:request].serialize_to_string - ) + ).serialize_to_string rescue fail :INVALID_REQUEST_PROTO, "Could not set request proto: #{$!.message}" end def setup_connection initialize_stats + @request_data = rpc_request_data end def succeed(response) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index ce23a8fa..94f38be2 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -59,12 +59,12 @@ def receive_data(data) log_debug { "[#{log_signature}] receive_data: %s" % data } response_buffer << data @response_data = response_buffer.data - parse_response if response_buffer.flushed? + parse_response if(!@response_data.nil?) end def send_data - request_buffer = ::Protobuf::Rpc::Buffer.new(:read) - request_buffer.set_data(request_wrapper) + request_buffer = ::Protobuf::Rpc::Buffer.new(:write) + request_buffer.set_data(@request_data) log_debug { "[#{log_signature}] sending data: #{request_buffer.inspect}" } super(request_buffer.write) rescue @@ -74,7 +74,7 @@ def send_data # overwriting this method for java because it's broken in eventmachine. See https://github.com/eventmachine/eventmachine/issues/14 if RUBY_PLATFORM =~ /java/ def error? - false + !!@error end end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 4f96f9b7..460dc804 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -30,7 +30,6 @@ def close_connection end def connect_to_rpc_server - return if(@error) @socket = TCPSocket.new(options[:host], options[:port]) log_debug { "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" } end @@ -54,18 +53,19 @@ def read_data end def read_response - return if(@error) + log_debug { "[client-#{self.class}] error? is #{error?}" } + return if(error?) response_buffer = ::Protobuf::Rpc::Buffer.new(:read) response_buffer << read_data @stats.response_size = response_buffer.size - @response_data = response_buffer.write + @response_data = response_buffer.data parse_response if response_buffer.flushed? end def send_data - return if(@error) + return if(error?) request_buffer = ::Protobuf::Rpc::Buffer.new(:write) - request_buffer.set_data(request_wrapper) + request_buffer.set_data(@request_data) @socket.write(request_buffer.write) @socket.flush log_debug { "[client-#{self.class}] write closed" } diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 8cb8569d..2027efe5 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -51,16 +51,16 @@ def error? def read_response return if(@error) + @response_data = '' zmq_error_check(@socket.recv_string(@response_data)) parse_response end def send_data return if(@error) - request_data = request_wrapper.serialize_to_string - log_debug { "[#{log_signature}] Sending Request: %s" % request_data } - @stats.request_size = request_data.size - zmq_error_check(@socket.send_string(request_data)) + log_debug { "[#{log_signature}] Sending Request: %s" % @request_data } + @stats.request_size = @request_data.size + zmq_error_check(@socket.send_string(@request_data)) log_debug { "[client-#{self.class}] write closed" } end diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb index 77bc6616..c394dac8 100644 --- a/lib/protobuf/rpc/servers/evented/server.rb +++ b/lib/protobuf/rpc/servers/evented/server.rb @@ -11,10 +11,8 @@ class Server < ::EventMachine::Connection def post_init log_debug { '[server] Post init, new read buffer created' } @stats = Protobuf::Rpc::Stat.new(:SERVER, true) - @stats.client = Socket.unpack_sockaddr_in(get_peername) + @stats.client = ::Socket.unpack_sockaddr_in(get_peername) - @response_buffer = Protobuf::Rpc::Buffer.new(:write) - @request_buffer = Protobuf::Rpc::Buffer.new(:read) @did_respond = false end @@ -22,20 +20,22 @@ def post_init def receive_data(data) log_debug { '[server] receive_data: %s' % data } - @request_buffer << data - @request_data = @request_buffer.data - @stats.request_size = @request_buffer.size + request_buffer = Protobuf::Rpc::Buffer.new(:read) + request_buffer << data + @request_data = request_buffer.data + @stats.request_size = request_buffer.size @request = ::Protobuf::Socketrpc::Request.new @response = ::Protobuf::Socketrpc::Response.new - handle_client if @request_buffer.flushed? + handle_client if request_buffer.flushed? end def send_data - @response_buffer.set_data(@response) - @stats.response_size = @response_buffer.size - log_debug { "[#{log_signature}] sending data: #{@response_buffer.inspect}" } - super(@response_buffer.write) + response_buffer = Protobuf::Rpc::Buffer.new(:write) + response_buffer.set_data(@response) + @stats.response_size = response_buffer.size + log_debug { "[#{log_signature}] sending data: #{response_buffer.inspect}" } + super(response_buffer.write) end end end diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 5e626fdf..6faa0957 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -1,3 +1,5 @@ +require 'protobuf/rpc/server' +require 'protobuf/rpc/servers/socket/worker' module Protobuf module Rpc module Socket @@ -33,7 +35,7 @@ def self.log_signature def self.new_worker(socket) Thread.new(socket) do |sock| - ::Protobuf::Rpc::SocketServer::Worker.new(sock) do |s| + ::Protobuf::Rpc::Socket::Worker.new(sock) do |s| s.close end end diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 2afdb25c..a70a42e0 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -11,13 +11,12 @@ def initialize(sock, &complete_cb) @socket = sock @request = Protobuf::Socketrpc::Request.new @response = Protobuf::Socketrpc::Response.new - @response_buffer = Protobuf::Rpc::Buffer.new(:write) request_buffer = Protobuf::Rpc::Buffer.new(:read) @stats = Protobuf::Rpc::Stat.new(:SERVER, true) @complete_cb = complete_cb log_debug { "[#{log_signature}] Post init, new read buffer created" } - @stats.client = Socket.unpack_sockaddr_in(@socket.getpeername) + @stats.client = ::Socket.unpack_sockaddr_in(@socket.getpeername) log_debug { "stats are #{@stats.to_s}" } request_buffer << read_data @request_data = request_buffer.data @@ -44,10 +43,11 @@ def read_data end def send_data - @response_buffer.set_data(@response) - @stats.response_size = @response_buffer.size - log_debug { "[#{log_signature}] sending data : %s" % @response_buffer.write } - @socket.write(@response_buffer.write) + response_buffer = Protobuf::Rpc::Buffer.new(:write) + response_buffer.set_data(@response) + @stats.response_size = response_buffer.size + log_debug { "[#{log_signature}] sending data : %s" % response_buffer.write } + @socket.write(response_buffer.write) @socket.flush @complete_cb.call(@socket) end diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index d6a64661..ea65564e 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -8,7 +8,7 @@ def self.stop end def self.run(server) - Protobuf::Logger.info "SocketServer Running" + Protobuf::Logger.info "Socket::Server Running" server_config = case when server.is_a?(OpenStruct) then server.marshal_dump diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 56dfb42f..72ca8d85 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -30,6 +30,7 @@ def initialize(opts={}) # Instance Methods # def handle_request(socket) + @request_data = '' zmq_error_check(socket.recv_string(@request_data)) log_debug { "[#{log_signature}] handling request" } if(!@request_data.nil?) end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 79e120a5..03396773 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -37,7 +37,7 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::SocketServer, :port => 9399) do |server| + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| client = Spec::Proto::TestService.client(:async => false, :port => 9399) benchmark_wrapper(global_bench) do |bench| @@ -54,7 +54,7 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? - StubServer.new(:server => Protobuf::Rpc::SocketServer, :port => 9399) do |server| + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| with_constants "Protobuf::ClientType" => "Socket" do client = Spec::Proto::TestService.client(:async => false, :port => 9399) diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 6eeae3bd..a0c2238d 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -10,7 +10,7 @@ expect { EventMachine.fiber_run do StubServer.new do |server| - client = ::Spec::Proto::TestService.client(:async => false) + client = ::Spec::Proto::TestService.client(:async => false, :timeout => 5) client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index b14b137d..1bffa857 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -6,7 +6,7 @@ Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } - Thread.pass until Protobuf::Rpc::SocketServer.running? + Thread.pass until Protobuf::Rpc::Socket::Server.running? end after(:all) do diff --git a/spec/helper/server.rb b/spec/helper/server.rb index 5d0874a6..e1245426 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -1,7 +1,7 @@ require 'ostruct' require 'protobuf/common/logger' require 'protobuf/rpc/server' -require 'protobuf/rpc/servers/socket_server' +require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/servers/zmq_runner' @@ -12,7 +12,7 @@ module StubProtobufServerFactory def self.build(delay) - new_server = Class.new(Protobuf::Rpc::EventedServer) do + new_server = Class.new(Protobuf::Rpc::Evented::Server) do def self.sleep_interval @sleep_interval end @@ -43,7 +43,7 @@ def initialize(opts = {}) :host => "127.0.0.1", :port => 9399, :delay => 0, - :server => Protobuf::Rpc::EventedServer + :server => Protobuf::Rpc::Evented::Server }.merge(opts)) start @@ -54,7 +54,7 @@ def initialize(opts = {}) def start case - when @options.server == Protobuf::Rpc::EventedServer then start_em_server + when @options.server == Protobuf::Rpc::Evented::Server then start_em_server when @options.server == Protobuf::Rpc::Zmq::Server then start_zmq_server else start_socket_server @@ -74,7 +74,7 @@ def start_em_server def start_socket_server @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } @sock_server.abort_on_exception = true # Set for testing purposes - Thread.pass until Protobuf::Rpc::SocketServer.running? + Thread.pass until Protobuf::Rpc::Socket::Server.running? end def start_zmq_server @@ -84,7 +84,7 @@ def start_zmq_server def stop case - when @options.server == Protobuf::Rpc::EventedServer then + when @options.server == Protobuf::Rpc::Evented::Server then EventMachine.stop_server(@server_handle) if @server_handle when @options.server == Protobuf::Rpc::Zmq::Server then Protobuf::Rpc::ZmqRunner.stop diff --git a/spec/unit/rpc/connectors/socket_spec.rb b/spec/unit/rpc/connectors/socket_spec.rb index 1e4ecc95..ab6750d3 100644 --- a/spec/unit/rpc/connectors/socket_spec.rb +++ b/spec/unit/rpc/connectors/socket_spec.rb @@ -24,13 +24,12 @@ it "fills the buffer with data from the socket" do socket = StringIO.new("#{data.bytesize}-#{data}") - subject.instance_variable_set(:@response_buffer, Protobuf::Rpc::Buffer.new(:read)) subject.instance_variable_set(:@socket, socket) + subject.instance_variable_set(:@stats, OpenStruct.new) subject.should_receive(:parse_response).and_return(true) subject.__send__(:read_response) - subject.instance_variable_get(:@response_buffer).flushed?.should be_true - subject.instance_variable_get(:@response_buffer).data.should eq(data) + subject.instance_variable_get(:@response_data).should eq(data) end end diff --git a/spec/unit/rpc/servers/evented_server_spec.rb b/spec/unit/rpc/servers/evented_server_spec.rb index 90655a20..58897a3e 100644 --- a/spec/unit/rpc/servers/evented_server_spec.rb +++ b/spec/unit/rpc/servers/evented_server_spec.rb @@ -2,15 +2,15 @@ require 'spec/proto/test_service_impl' require 'protobuf/rpc/servers/evented_runner' -describe Protobuf::Rpc::EventedServer do +describe Protobuf::Rpc::Evented::Server do it "provides a Runner class" do - runner_class = described_class.to_s.gsub(/Server/, "Runner") + runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") expect { Protobuf::Util.constantize(runner_class) }.to_not raise_error end it "Runner provides a stop method" do - runner_class = described_class.to_s.gsub(/Server/, "Runner") + runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") runner_class = Protobuf::Util.constantize(runner_class) runner_class.respond_to?(:stop).should be_true end diff --git a/spec/unit/rpc/servers/socket_server_spec.rb b/spec/unit/rpc/servers/socket_server_spec.rb index 0a8703d3..a2ba7ba5 100644 --- a/spec/unit/rpc/servers/socket_server_spec.rb +++ b/spec/unit/rpc/servers/socket_server_spec.rb @@ -2,21 +2,21 @@ require 'spec/proto/test_service_impl' require 'protobuf/rpc/servers/socket_runner' -describe Protobuf::Rpc::SocketServer do - before(:all) do +describe Protobuf::Rpc::Socket::Server do + before(:all) do Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } - Thread.pass until Protobuf::Rpc::SocketServer.running? + Thread.pass until Protobuf::Rpc::Socket::Server.running? end - after(:all) do + after(:all) do Protobuf::Rpc::SocketRunner.stop Thread.kill(@server_thread) end it "Runner provides a stop method" do - runner_class = described_class.to_s.gsub(/Server/, "Runner") + runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") runner_class = Protobuf::Util.constantize(runner_class) runner_class.respond_to?(:stop).should be_true end @@ -25,17 +25,17 @@ described_class.respond_to?(:stop).should be_true end - it "provides a Runner class" do - runner_class = described_class.to_s.gsub(/Server/, "Runner") - expect { Protobuf::Util.constantize(runner_class) }.to_not raise_error + it "provides a Runner class" do + runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") + expect { Protobuf::Util.constantize(runner_class) }.to_not raise_error end - it "signals the Server is running" do + it "signals the Server is running" do described_class.running?.should be_true end - context "Eventmachine client" do - it "calls the service in the client request" do + context "Eventmachine client" do + it "calls the service in the client request" do with_constants "Protobuf::ClientType" => "Evented" do client = Spec::Proto::TestService.client(:async => false, :port => 9399, :host => "127.0.0.1") @@ -51,7 +51,7 @@ end end end - + end end From 35d84f8a9465df17b1ed613fbe75f843015a5e9f Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 29 May 2012 17:16:03 -0600 Subject: [PATCH 0052/1191] added documentation and fixed order dependant spec --- lib/protobuf/rpc/connectors/common.rb | 4 ++++ lib/protobuf/rpc/servers/socket/worker.rb | 3 ++- spec/functional/zmq_server_spec.rb | 1 - 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 706c13ad..36dbebe4 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -28,6 +28,10 @@ def data_callback(data) @data = data end + # All failures should be routed through this method + # + # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) + # @param [String] message The error message def fail(code, message) @error = ClientError.new @error.code = code.is_a?(Symbol) ? Protobuf::Socketrpc::ErrorReason.values[code] : code diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index a70a42e0..48157f63 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -43,10 +43,11 @@ def read_data end def send_data + raise 'Socket closed unexpectedly' if(@socket.nil? || @socket.closed?) response_buffer = Protobuf::Rpc::Buffer.new(:write) response_buffer.set_data(@response) @stats.response_size = response_buffer.size - log_debug { "[#{log_signature}] sending data : %s" % response_buffer.write } + log_debug { "[#{log_signature}] sending data : %s" % response_buffer.data } @socket.write(response_buffer.write) @socket.flush @complete_cb.call(@socket) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 217c76d2..2a846475 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -10,7 +10,6 @@ end after(:all) do - Protobuf::Rpc::ZmqRunner.stop Thread.kill(@server_thread) end From 0e9ee9c3ca79a502155231c3dc5b2023796b87dd Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 30 May 2012 10:55:21 -0600 Subject: [PATCH 0053/1191] fixed client spec so EM.stop is reachable --- spec/unit/rpc/client_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/unit/rpc/client_spec.rb b/spec/unit/rpc/client_spec.rb index 1647980e..f5682e2f 100644 --- a/spec/unit/rpc/client_spec.rb +++ b/spec/unit/rpc/client_spec.rb @@ -58,17 +58,22 @@ end it "throws a timeout when client timeout is exceeded" do - subject = Proc.new do + error = nil + test_proc = Proc.new do EventMachine.fiber_run do StubServer.new(:delay => 2) do |server| client = Spec::Proto::TestService.client(:async => false, :timeout => 1) - client.find(:name => "Test Name", :active => true) + client.find(:name => "Test Name", :active => true) do |cl| + cl.on_success {} + cl.on_failure {|f| error = f} + end end EM.stop end end - subject.should raise_error(RuntimeError, /timeout/i) + test_proc.call + error.message.should =~ /timeout/i end context "without reactor_running?" do From f1b827d9b8525a38a530df8fe83917b0f96bc30e Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 30 May 2012 10:56:43 -0600 Subject: [PATCH 0054/1191] removed ruby-prof and redcarpet since they don't play nicely with jruby --- Gemfile.lock | 4 ---- protobuf.gemspec | 2 -- 2 files changed, 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0288508c..52c99757 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,7 +34,6 @@ GEM pry-nav (0.2.0) pry (~> 0.9.8.1) rake (0.9.2.2) - redcarpet (2.1.1) rspec (2.9.0) rspec-core (~> 2.9.0) rspec-expectations (~> 2.9.0) @@ -43,7 +42,6 @@ GEM rspec-expectations (2.9.0) diff-lcs (~> 1.1.3) rspec-mocks (2.9.0) - ruby-prof (0.10.8) simplecov (0.6.1) multi_json (~> 1.0) simplecov-html (~> 0.5.3) @@ -61,8 +59,6 @@ DEPENDENCIES pry pry-nav rake - redcarpet rspec - ruby-prof simplecov yard diff --git a/protobuf.gemspec b/protobuf.gemspec index 1e4aae1f..904b14f0 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -23,12 +23,10 @@ Gem::Specification.new do |s| s.add_dependency 'json_pure' s.add_dependency 'ffi-rzmq' - s.add_development_dependency 'ruby-prof' s.add_development_dependency 'rake' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rspec' s.add_development_dependency 'yard' - s.add_development_dependency 'redcarpet' s.add_development_dependency 'simplecov' end From 114900f1bb5f18a4c927d204c70142f690af6c22 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 30 May 2012 10:58:37 -0600 Subject: [PATCH 0055/1191] fixed jruby server hang issues in specs --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 3 ++- spec/helper/server.rb | 4 ++-- spec/unit/rpc/servers/socket_server_spec.rb | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 30b3a5df..ed22610a 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -23,7 +23,7 @@ def initialize(opts={}) # def poll log_debug { "[#{log_signature}] polling for data" } - poller.poll(:blocking) + poller.poll(1000) poller.readables.each do |socket| case socket when frontend then diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 1bffa857..05948911 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -11,7 +11,7 @@ after(:all) do Protobuf::Rpc::SocketRunner.stop - Thread.kill(@server_thread) + @server_thread.join end it 'runs fine when required fields are set' do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 2a846475..cfa715e7 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -10,7 +10,8 @@ end after(:all) do - Thread.kill(@server_thread) + ::Protobuf::Rpc::Zmq::Server.stop + @server_thread.join end it 'runs fine when required fields are set' do diff --git a/spec/helper/server.rb b/spec/helper/server.rb index e1245426..a80fe6be 100644 --- a/spec/helper/server.rb +++ b/spec/helper/server.rb @@ -88,10 +88,10 @@ def stop EventMachine.stop_server(@server_handle) if @server_handle when @options.server == Protobuf::Rpc::Zmq::Server then Protobuf::Rpc::ZmqRunner.stop - Thread.kill(@zmq_server) if @zmq_server + @zmq_server.join if(@zmq_server) else Protobuf::Rpc::SocketRunner.stop - Thread.kill(@sock_server) if @sock_server + @sock_server.join if(@sock_server) end @running = false diff --git a/spec/unit/rpc/servers/socket_server_spec.rb b/spec/unit/rpc/servers/socket_server_spec.rb index a2ba7ba5..ea4d44a7 100644 --- a/spec/unit/rpc/servers/socket_server_spec.rb +++ b/spec/unit/rpc/servers/socket_server_spec.rb @@ -12,7 +12,7 @@ after(:all) do Protobuf::Rpc::SocketRunner.stop - Thread.kill(@server_thread) + @server_thread.join end it "Runner provides a stop method" do From 1b34dc41ba4109d7b561c8d15a65b758106bcc25 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 30 May 2012 11:15:43 -0600 Subject: [PATCH 0056/1191] ensuring @threads variable is clean after mocking Thread --- spec/unit/rpc/servers/zmq/server_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/unit/rpc/servers/zmq/server_spec.rb b/spec/unit/rpc/servers/zmq/server_spec.rb index 9ba08365..8a9caad7 100644 --- a/spec/unit/rpc/servers/zmq/server_spec.rb +++ b/spec/unit/rpc/servers/zmq/server_spec.rb @@ -15,6 +15,12 @@ end describe '.stop' do + # keep threads instance variable from retaining any thread mocks we've + # created (breaks tests down the line, otherwise) + after(:each) do + described_class.instance_variable_set(:@threads, []) + end + it 'lets all threads stop' do thread_mock = double(Thread) thread_mock.should_receive(:join) From 82738c09f9079376a1542e93d7a7eca285c09940 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Wed, 30 May 2012 14:05:06 -0600 Subject: [PATCH 0057/1191] fixed benchmarks and data receiving methods --- lib/protobuf/rpc/connectors/em_client.rb | 8 ++++---- lib/protobuf/rpc/servers/evented/server.rb | 14 +++++++------- spec/benchmark/tasks.rb | 10 ++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 94f38be2..cf482028 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -16,6 +16,7 @@ class EMClient < EM::Connection def initialize(options={}, &failure_cb) @failure_cb = failure_cb @options = DEFAULT_OPTIONS.merge(options) + @response_buffer = ::Protobuf::Rpc::Buffer.new(:read) verify_options log_debug { "[#{log_signature}] Client Initialized: %s" % options.inspect } @@ -55,11 +56,10 @@ def on_success(&success_cb) end def receive_data(data) - response_buffer = ::Protobuf::Rpc::Buffer.new(:read) log_debug { "[#{log_signature}] receive_data: %s" % data } - response_buffer << data - @response_data = response_buffer.data - parse_response if(!@response_data.nil?) + @response_buffer << data + @response_data = @response_buffer.data + parse_response if(!@response_data.nil? && @response_buffer.flushed?) end def send_data diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb index c394dac8..f50903c7 100644 --- a/lib/protobuf/rpc/servers/evented/server.rb +++ b/lib/protobuf/rpc/servers/evented/server.rb @@ -12,6 +12,9 @@ def post_init log_debug { '[server] Post init, new read buffer created' } @stats = Protobuf::Rpc::Stat.new(:SERVER, true) @stats.client = ::Socket.unpack_sockaddr_in(get_peername) + @request_buffer = Protobuf::Rpc::Buffer.new(:read) + @request = ::Protobuf::Socketrpc::Request.new + @response = ::Protobuf::Socketrpc::Response.new @did_respond = false end @@ -20,14 +23,11 @@ def post_init def receive_data(data) log_debug { '[server] receive_data: %s' % data } - request_buffer = Protobuf::Rpc::Buffer.new(:read) - request_buffer << data - @request_data = request_buffer.data - @stats.request_size = request_buffer.size + @request_buffer << data + @request_data = @request_buffer.data + @stats.request_size = @request_buffer.size - @request = ::Protobuf::Socketrpc::Request.new - @response = ::Protobuf::Socketrpc::Response.new - handle_client if request_buffer.flushed? + handle_client if @request_buffer.flushed? end def send_data diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 03396773..9dc4d698 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -2,6 +2,13 @@ require 'helper/all' require 'proto/test_service_impl' +# Including a way to turn on debug logger for spec runs +if ENV["DEBUG"] + puts 'debugging' + debug_log = File.expand_path('../debug_bench.log', File.dirname(__FILE__) ) + Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) +end + namespace :benchmark do include SilentConstants @@ -89,6 +96,9 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) end def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) + require 'ffi-rzmq' + require 'protobuf/rpc/connectors/zmq' + require 'protobuf/rpc/servers/zmq/server' StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| with_constants "Protobuf::ClientType" => "Zmq" do client = Spec::Proto::TestService.client(:async => false, :port => 9399) From be3e5486ff06622c5a47ac22f3c4bb72ad305d11 Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Mon, 4 Jun 2012 10:24:06 -0600 Subject: [PATCH 0058/1191] version bump --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 721ac30f..5798b530 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '1.1.3' + VERSION = '1.2.0' end From c0286297e9cd4352803497a9bb266d4c648b8b8d Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 5 Jun 2012 13:11:27 -0600 Subject: [PATCH 0059/1191] fixed noisy debug logs for zmq --- lib/protobuf/rpc/servers/zmq/broker.rb | 1 - lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index ed22610a..3fc79413 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -22,7 +22,6 @@ def initialize(opts={}) # Instance Methods # def poll - log_debug { "[#{log_signature}] polling for data" } poller.poll(1000) poller.readables.each do |socket| case socket diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 31499e15..8fc61265 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -23,8 +23,8 @@ def self.run(opts = {}) end @running = true + log_debug { "[#{log_signature}] server started" } while self.running? do - log_debug { "[#{log_signature}] server started" } @broker.poll end ensure From e336e70bc4c43ddde7766de5fb70a7225a86a74b Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 5 Jun 2012 13:47:53 -0600 Subject: [PATCH 0060/1191] created ability to specify client/server type via an environment variable or via a passable option --- Gemfile.lock | 4 ++-- bin/rpc_server | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 52c99757..e1d21d28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (1.1.3) + protobuf (1.2.0) eventmachine eventually ffi-rzmq @@ -19,7 +19,7 @@ GEM ffi (1.0.11-java) ffi-rzmq (0.9.3) ffi - json_pure (1.6.6) + json_pure (1.7.3) method_source (0.7.1) multi_json (1.2.0) pry (0.9.8.4) diff --git a/bin/rpc_server b/bin/rpc_server index e4b6f10f..7d963eaf 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -22,6 +22,14 @@ server = OpenStruct.new({ :debug => false }) +class ClientServerParse + def self.parse_client(value) + end + + def self.parse_server(value) + end +end + parser = OptionParser.new do |opts| opts.banner = "Usage: rpc_server [options] app_file.rb" @@ -73,6 +81,14 @@ parser = OptionParser.new do |opts| server.level = ::Logger::DEBUG if v === true end + opts.on("--client-type=CLIENT_TYPE", String, "Client Type to use (Socket or Zmq)") do |v| + ENV['CLIENT_TYPE'] = v + end + + opts.on("--server-type=SERVER_TYPE", String, "Server Type to use (Socket or Zmq)") do |v| + ENV['SERVER_TYPE'] = v + end + opts.separator "" opts.separator "Common options:" @@ -88,6 +104,21 @@ parser = OptionParser.new do |opts| end parser.parse! + +if(ENV['CLIENT_TYPE']) + if(ENV['CLIENT_TYPE'] == "Zmq") + ::Protobuf::ServerType = ENV['CLIENT_TYPE'] + server.runner = ::Protobuf::Rpc::ZmqRunner + end + ::Protobuf::ClientType = ENV['CLIENT_TYPE'] +elsif(ENV['SERVER_TYPE']) + if(ENV['SERVER_TYPE'] == "Zmq") + ::Protobuf::ClientType = ENV['SERVER_TYPE'] + server.runner = ::Protobuf::Rpc::ZmqRunner + end + ::Protobuf::ServerType = ENV['SERVER_TYPE'] +end + require 'protobuf' [:INT, :QUIT, :TERM].each do |sig| From 2601e97fe46ad7dce83738ec682e0d70c1d0c57d Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Tue, 5 Jun 2012 14:43:44 -0600 Subject: [PATCH 0061/1191] parsing PB_CLIENT_TYPE and PB_SERVER_TYPE and setting the env variable if needed --- bin/rpc_server | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/bin/rpc_server b/bin/rpc_server index 7d963eaf..43380a20 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -62,17 +62,18 @@ parser = OptionParser.new do |opts| end opts.on("-c", "--client_socket", "Socket Mode for client connections (No EventMachine)") do |v| - ::Protobuf::ClientType = "Socket" + ENV['PB_CLIENT_TYPE'] = "Socket" end opts.on("-s", "--socket", "Socket Server Mode (No EventMachine)") do |v| - ::Protobuf::ServerType = "Socket" + ENV['PB_SERVER_TYPE'] = "Socket" server.runner = ::Protobuf::Rpc::SocketRunner end opts.on("-z", "--zmq", "ZeroMQ Socket Mode for client and server connections (they must be used together)") do |v| - ::Protobuf::ClientType = "Zmq" - ::Protobuf::ServerType = "Zmq" + ENV['PB_CLIENT_TYPE'] = 'Zmq' + ENV['PB_SERVER_TYPE'] = 'Zmq' + server.runner = ::Protobuf::Rpc::ZmqRunner end @@ -81,12 +82,12 @@ parser = OptionParser.new do |opts| server.level = ::Logger::DEBUG if v === true end - opts.on("--client-type=CLIENT_TYPE", String, "Client Type to use (Socket or Zmq)") do |v| - ENV['CLIENT_TYPE'] = v + opts.on("--client-type=PB_CLIENT_TYPE", String, "Client Type to use (Socket or Zmq)") do |v| + ENV['PB_CLIENT_TYPE'] = v end - opts.on("--server-type=SERVER_TYPE", String, "Server Type to use (Socket or Zmq)") do |v| - ENV['SERVER_TYPE'] = v + opts.on("--server-type=PB_SERVER_TYPE", String, "Server Type to use (Socket or Zmq)") do |v| + ENV['PB_SERVER_TYPE'] = v end opts.separator "" @@ -105,20 +106,22 @@ end parser.parse! -if(ENV['CLIENT_TYPE']) - if(ENV['CLIENT_TYPE'] == "Zmq") - ::Protobuf::ServerType = ENV['CLIENT_TYPE'] - server.runner = ::Protobuf::Rpc::ZmqRunner - end - ::Protobuf::ClientType = ENV['CLIENT_TYPE'] -elsif(ENV['SERVER_TYPE']) - if(ENV['SERVER_TYPE'] == "Zmq") - ::Protobuf::ClientType = ENV['SERVER_TYPE'] - server.runner = ::Protobuf::Rpc::ZmqRunner - end - ::Protobuf::ServerType = ENV['SERVER_TYPE'] +# Used to ensure we set the PB_CLIENT_TYPE and PB_SERVER_TYPE to the same thing +# if one of them is set to Zmq +if(ENV['PB_CLIENT_TYPE'] == "Zmq") + # make server and client types the same if we're using Zmq + ENV['PB_SERVER_TYPE'] = ENV['PB_CLIENT_TYPE'] + server.runner = ::Protobuf::Rpc::ZmqRunner +elsif(ENV['PB_SERVER_TYPE'] == "Zmq") + # make server and client types the same if we're using Zmq + ENV['PB_CLIENT_TYPE'] = ENV['PB_SERVER_TYPE'] + server.runner = ::Protobuf::Rpc::ZmqRunner +elsif(ENV['PB_SERVER_TYPE'] == 'Socket') + server.runner = ::Protobuf::Rpc::SocketRunner end +# protobuf.rb picks up PB_CLIENT_TYPE and PB_SERVER_TYPE and does something +# useful with them require 'protobuf' [:INT, :QUIT, :TERM].each do |sig| From cb8355398f154467a14a2e861f58102be88fe324 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 8 Jun 2012 09:51:36 -0600 Subject: [PATCH 0062/1191] update rpc_server to use regexes when choosing client/server types --- bin/rpc_server | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/rpc_server b/bin/rpc_server index 43380a20..8ef23297 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -108,15 +108,15 @@ parser.parse! # Used to ensure we set the PB_CLIENT_TYPE and PB_SERVER_TYPE to the same thing # if one of them is set to Zmq -if(ENV['PB_CLIENT_TYPE'] == "Zmq") +if(ENV['PB_CLIENT_TYPE'] =~ /zmq/i) # make server and client types the same if we're using Zmq ENV['PB_SERVER_TYPE'] = ENV['PB_CLIENT_TYPE'] server.runner = ::Protobuf::Rpc::ZmqRunner -elsif(ENV['PB_SERVER_TYPE'] == "Zmq") +elsif(ENV['PB_SERVER_TYPE'] =~ /zmq/i) # make server and client types the same if we're using Zmq ENV['PB_CLIENT_TYPE'] = ENV['PB_SERVER_TYPE'] server.runner = ::Protobuf::Rpc::ZmqRunner -elsif(ENV['PB_SERVER_TYPE'] == 'Socket') +elsif(ENV['PB_SERVER_TYPE'] =~ /socket/i) server.runner = ::Protobuf::Rpc::SocketRunner end From c80bf7cba5b761b0f58a6c23714dac0dba6bcc4a Mon Sep 17 00:00:00 2001 From: Tracey Eubanks Date: Fri, 8 Jun 2012 11:00:49 -0600 Subject: [PATCH 0063/1191] decreased number of threads that start up by default (for zmq) --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 8fc61265..5504506a 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -14,7 +14,7 @@ class Server def self.run(opts = {}) log_debug { "[#{log_signature}] initializing broker" } @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts) - local_worker_threads = opts.fetch(:threads, 10) + local_worker_threads = opts.fetch(:threads, 5) worker_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) log_debug { "[#{log_signature}] starting server workers" } From f16642a0fe40b29d4698e9ce4b9e46dbd9b5faa9 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Jun 2012 14:17:52 -0600 Subject: [PATCH 0064/1191] Bump version to 1.3.0. Support added for ZMQ sockets. --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 90937270..8ece188b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (1.2.0) + protobuf (1.3.0) eventmachine eventually ffi-rzmq diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5798b530..b957f457 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '1.2.0' + VERSION = '1.3.0' end From feb305f3ac91c6ebf18be4e2ed4ef37598cb0b14 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 17 Sep 2012 10:48:18 -0600 Subject: [PATCH 0065/1191] add field caching by name to message definitions --- .gitignore | 1 + Gemfile.lock | 51 ++++++++++++++------------------- lib/protobuf/message/enum.rb | 2 +- lib/protobuf/message/field.rb | 9 ++++-- lib/protobuf/message/message.rb | 45 ++++++++++++++++++++++------- spec/unit/common/logger_spec.rb | 4 +-- spec/unit/rpc/client_spec.rb | 2 +- 7 files changed, 67 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 10e31749..1eeb6209 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ doc .yardoc .DS_Store *.bin +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock index 8ece188b..e8cbdbd9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,46 +10,39 @@ PATH GEM remote: http://rubygems.org/ specs: - coderay (1.0.5) + coderay (1.0.7) diff-lcs (1.1.3) - eventmachine (0.12.10) + eventmachine (1.0.0) eventually (0.1.1) - ffi (1.0.11) - ffi-rzmq (0.9.3) + ffi (1.1.5) + ffi-rzmq (0.9.6) ffi - json_pure (1.7.3) - method_source (0.7.1) - multi_json (1.2.0) - pry (0.9.8.4) + json_pure (1.7.5) + method_source (0.8) + multi_json (1.3.6) + pry (0.9.10) coderay (~> 1.0.5) - method_source (~> 0.7.1) - slop (>= 2.4.4, < 3) - pry (0.9.8.4-java) - coderay (~> 1.0.5) - method_source (~> 0.7.1) - slop (>= 2.4.4, < 3) - spoon (~> 0.0) - pry-nav (0.2.0) - pry (~> 0.9.8.1) + method_source (~> 0.8) + slop (~> 3.3.1) + pry-nav (0.2.2) + pry (~> 0.9.10) rake (0.9.2.2) - rspec (2.9.0) - rspec-core (~> 2.9.0) - rspec-expectations (~> 2.9.0) - rspec-mocks (~> 2.9.0) - rspec-core (2.9.0) - rspec-expectations (2.9.0) + rspec (2.11.0) + rspec-core (~> 2.11.0) + rspec-expectations (~> 2.11.0) + rspec-mocks (~> 2.11.0) + rspec-core (2.11.1) + rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) - rspec-mocks (2.9.0) - simplecov (0.6.1) + rspec-mocks (2.11.2) + simplecov (0.6.4) multi_json (~> 1.0) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) - slop (2.4.4) - spoon (0.0.1) - yard (0.7.5) + slop (3.3.3) + yard (0.8.2.1) PLATFORMS - java ruby DEPENDENCIES diff --git a/lib/protobuf/message/enum.rb b/lib/protobuf/message/enum.rb index b3573081..3566606b 100644 --- a/lib/protobuf/message/enum.rb +++ b/lib/protobuf/message/enum.rb @@ -4,7 +4,7 @@ module Protobuf class Enum - class < Date: Mon, 17 Sep 2012 14:32:19 -0600 Subject: [PATCH 0066/1191] remove all the class_evaling from initialization of protobuf message --- lib/protobuf/message/field.rb | 4 ++ lib/protobuf/message/message.rb | 95 ++++++++++++++++++++++++--------- 2 files changed, 75 insertions(+), 24 deletions(-) diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index 83eaf4ea..1a383729 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -129,6 +129,10 @@ def merge(message_instance, value) end end + def extension? + !!@extension + end + # Is this a repeated field? def repeated? return @_repeated unless @_repeated.nil? diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 23335bcb..8980383a 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -28,6 +28,14 @@ def include_tag?(tag) class << self include Protoable + def all_fields + @all_fields ||= begin + fields_hash = fields.merge(extension_fields) + ordered_keys = fields_hash.keys.sort + ordered_keys.map { |key| fields_hash[key] } + end + end + # Reserve field numbers for extensions. Don't use this method directly. def extensions(range) @extension_fields = ExtensionFields.new(range) @@ -48,13 +56,19 @@ def repeated(type, name, tag, options={}) define_field(:repeated, type, name, tag, options) end + def descriptor + @descriptor ||= Descriptor::Descriptor.new(self) + end + # Define a field. Don't use this method directly. def define_field(rule, type, fname, tag, options) field_hash = options[:extension] ? extension_fields : fields field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name + if field_hash.keys.include?(tag) raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! end + field_definition = Field.build(self, rule, type, fname, tag, options) field_name_hash[fname.to_sym] = field_definition field_hash[tag] = field_definition @@ -82,6 +96,14 @@ def fields_by_name @field_by_name ||= {} end + def repeated_fields + @repeated_fields ||= [] + end + + def repeated_extension_fields + @repeated_extension_fields ||= [] + end + # Find a field object by +name+. def get_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value @@ -122,44 +144,68 @@ def get_ext_field(tag_or_name) end end - def descriptor - @descriptor ||= Descriptor::Descriptor.new(self) + def initialize_unready_fields + unless @unready_initialized + initialize_type_fields + initialize_type_extension_fields + @unready_initialized = true + end end - end - def initialize(values={}) - @values = {} - - self.class.fields.each do |tag, field| - unless field.ready? - field = field.setup - self.class.class_eval { + def initialize_type_fields + fields.each do |tag, field| + unless field.ready? + field = field.setup fields[tag] = field fields_by_name[field.name.to_sym] = field fields_by_name[field.name] = field - } - end - if field.repeated? - @values[field.name] = Field::FieldArray.new(field) + end end end - # TODO - self.class.extension_fields.each do |tag, field| - unless field.ready? - field = field.setup - self.class.class_eval { + def initialize_type_extension_fields + extension_fields.each do |tag, field| + unless field.ready? + field = field.setup extension_fields[tag] = field extension_fields_by_name[field.name.to_sym] = field extension_fields_by_name[field.name] = field - } + end end - if field.repeated? - @values[field.name] = Field::FieldArray.new(field) + end + + def setup_repeated_field_arrays + unless @repeated_fields_setup + all_fields.each do |field| + next unless field.repeated? + + if field.extension? + repeated_extension_fields << field + else + repeated_fields << field + end + end + + @repeated_fields_setup = true end end + end + + def initialize(values={}) + @values = {} + + self.class.initialize_unready_fields + self.class.setup_repeated_field_arrays + + self.class.repeated_fields.each do |field| + @values[field.name] = Field::FieldArray.new(field) + end + + self.class.repeated_extension_fields.each do |field| + @values[field.name] = Field::FieldArray.new(field) + end - values.each {|tag, val| self[tag] = val} + values.each { |tag, val| self[tag] = val} end def initialized? @@ -334,7 +380,8 @@ def []=(tag_or_name, value) # Returns a hash; which key is a tag number, and value is a field object. def all_fields - @all_fields ||= fields.merge(extension_fields).sort_by { |tag, _| tag } +# self.class.all_fields + @all_fields ||= fields.merge(extension_fields).sort_by {|tag, _| tag} end def fields From 1b40f3964fa878979c51144fc7988a7a673e5f2c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 17 Sep 2012 14:50:55 -0600 Subject: [PATCH 0067/1191] move to array each on all_fields --- lib/protobuf/message/message.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 8980383a..0f61ff8e 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -380,8 +380,7 @@ def []=(tag_or_name, value) # Returns a hash; which key is a tag number, and value is a field object. def all_fields -# self.class.all_fields - @all_fields ||= fields.merge(extension_fields).sort_by {|tag, _| tag} + self.class.all_fields end def fields @@ -425,7 +424,7 @@ def get_ext_field(tag_or_name) # :nodoc: # # do something # end def each_field - all_fields.each do |_, field| + all_fields.each do |field| value = __send__(field.name) yield(field, value) end From 4894174b9a4d42ed6406d90e6e60d3e71aade70f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 17 Sep 2012 16:57:26 -0600 Subject: [PATCH 0068/1191] remove merge functionality from messages --- lib/protobuf/message/field.rb | 20 -------------------- lib/protobuf/message/message.rb | 13 +------------ 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index 1a383729..59ebd30b 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -120,15 +120,6 @@ def encode(value) raise NotImplementedError, "#{self.class.name}\#encode" end - # Merge +value+ with +message_instance+. - def merge(message_instance, value) - if repeated? - merge_array(message_instance, value) - else - merge_value(message_instance, value) - end - end - def extension? !!@extension end @@ -221,14 +212,6 @@ def define_array_setter end end - def merge_array(message_instance, value) - message_instance.__send__(@name).concat(value) - end - - def merge_value(message_instance, value) - message_instance.__send__("#{@name}=", value) - end - def typed_default_value if @default.nil? self.class.default @@ -645,9 +628,6 @@ def define_setter end end - def merge_value(message_instance, value) - message_instance.__send__(@name).merge_from(value) - end end diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 0f61ff8e..ee00316d 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -346,22 +346,11 @@ def serialize_to(stream) Encoder.encode(stream, self) end - def merge_from(message) - # TODO - fields.each {|tag, field| merge_field(tag, message.__send__(field.name))} - extension_fields.each {|tag, field| merge_field(tag, message.__send__(field.name))} - end - def set_field(tag, bytes) field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) field.set(self, bytes) if field end - def merge_field(tag, value) - #get_field_by_tag(tag).merge self, bytes #TODO - (get_field_by_tag(tag) || get_ext_field_by_tag(tag)).merge(self, value) - end - def [](tag_or_name) if field = get_field(tag_or_name) || get_ext_field(tag_or_name) __send__(field.name) @@ -432,7 +421,7 @@ def each_field def to_hash result = {} - build_value = lambda {|field, value| + build_value = lambda { |field, value| if !field.optional? || (field.optional? && has_field?(field.name)) case field when Field::MessageField then From 55066ed08fbcd438333249a3e59d7fb38aa966f1 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 17 Sep 2012 18:39:56 -0600 Subject: [PATCH 0069/1191] add a field cache for fields of a proto message --- lib/protobuf/message/message.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index ee00316d..d0472140 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -115,9 +115,13 @@ def get_field_by_tag(tag) fields[tag] end + def field_cache + @field_cache ||= {} + end + # Find a field object by +tag_or_name+. def get_field(tag_or_name) - case tag_or_name + field_cache[tag_or_name] ||= case tag_or_name when Integer then get_field_by_tag(tag_or_name) when String, Symbol then get_field_by_name(tag_or_name) else raise TypeError, tag_or_name.class From aba02714e0cf13f35c1141f175234dd4eb3b7ce4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 17 Sep 2012 19:19:41 -0600 Subject: [PATCH 0070/1191] memoize the field and all_fields on the instance --- lib/protobuf/message/field.rb | 2 +- lib/protobuf/message/message.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index 59ebd30b..e5fce9f7 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -355,7 +355,7 @@ class VarintField < BaseField UINT32_MAX = 2**32 - 1 UINT64_MAX = 2**64 - 1 - class < Date: Mon, 17 Sep 2012 20:33:31 -0600 Subject: [PATCH 0071/1191] update getter to not check has_key --- lib/protobuf/message/field.rb | 11 ++++++----- lib/protobuf/message/message.rb | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index e5fce9f7..c6ae77c1 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -181,11 +181,12 @@ def define_getter field = self @message_class.class_eval do define_method(field.name) do - if @values.has_key?(field.name) - @values[field.name] - else - field.default_value - end + @values[field.name] || field.default_value +# if @values.has_key?(field.name) +# @values[field.name] +# else +# field.default_value +# end end end end diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index f813ba4d..46e29766 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -274,7 +274,7 @@ def copy_to(object, method) def inspect(indent=0) result = [] i = ' ' * indent - field_value_to_string = lambda {|field, value| + field_value_to_string = lambda { |field, value| result << \ if field.optional? && ! has_field?(field.name) '' From fe6595e40da2bf02aa2a26599fe7c9b59a82f57b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 18 Sep 2012 17:27:44 -0600 Subject: [PATCH 0072/1191] add in request and serialization gc pausing --- bin/rpc_server | 29 ++++++++++++++++++----- lib/protobuf/rpc/server.rb | 20 ++++++++++++++++ lib/protobuf/rpc/servers/socket_runner.rb | 10 ++++---- lib/protobuf/rpc/servers/zmq/worker.rb | 3 +-- 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/bin/rpc_server b/bin/rpc_server index 8ef23297..17be82b9 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -12,6 +12,8 @@ require 'protobuf/rpc/servers/zmq_runner' server = OpenStruct.new({ :app => nil, :env => ENV['RPC_SERVER_ENV'] || 'development', + :gc_pause_during_request => false, + :gc_pause_during_serialization => false, :host => '127.0.0.1', :port => 9595, :backlog => 100, @@ -76,6 +78,14 @@ parser = OptionParser.new do |opts| server.runner = ::Protobuf::Rpc::ZmqRunner end + + opts.on("--[no-]gc-pause-request", "Enable/Disable GC pause during request.") do |v| + server.gc_pause_during_request = v + end + + opts.on("--[no-]gc-pause-serialization", "Enable/Disable GC pause during serialization.") do |v| + server.gc_pause_during_serialization = v + end opts.on("-d", "--[no-]debug", "Debug Mode. Override log level to DEBUG.") do |v| server.debug = v @@ -120,6 +130,13 @@ elsif(ENV['PB_SERVER_TYPE'] =~ /socket/i) server.runner = ::Protobuf::Rpc::SocketRunner end +## +# Setup GC settings +# +::Protobuf::Rpc::GC_PAUSE_REQUEST = server.gc_pause_during_request +# If we pause during request we don't need to pause in serialization +::Protobuf::Rpc::GC_PAUSE_SERIALIZATION = (!server.gc_pause_during_request && server.gc_pause_during_serialization) + # protobuf.rb picks up PB_CLIENT_TYPE and PB_SERVER_TYPE and does something # useful with them require 'protobuf' @@ -141,11 +158,11 @@ begin end # Configure the ::Protobuf::Logger - ::Protobuf::Logger.configure :file => server.log, :level => server.debug ? ::Logger::DEBUG : server.level + ::Protobuf::Logger.configure(:file => server.log, :level => server.debug ? ::Logger::DEBUG : server.level) # Output the server opts - ::Protobuf::Logger.debug 'Debugging options:' - ::Protobuf::Logger.debug server.inspect + ::Protobuf::Logger.debug { 'Debugging options:' } + ::Protobuf::Logger.debug { server.inspect } # Set the name of the process $0 = 'rpc_server %s:%d %s' % [server.host, server.port, server.app] @@ -156,8 +173,8 @@ begin server.runner.run(server) rescue msg = 'ERROR: RPC Server failed to start. %s' % $!.inspect - $stderr.puts msg, *($!.backtrace) - ::Protobuf::Logger.error msg - ::Protobuf::Logger.error $!.backtrace.join("\n") + $stderr.puts(msg, *($!.backtrace)) + ::Protobuf::Logger.error { msg } + ::Protobuf::Logger.error { $!.backtrace.join("\n") } exit 1 end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 63fd2f29..1ba02aca 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -8,6 +8,20 @@ module Protobuf module Rpc module Server + def _gc_pause_request + @_gc_pause_request ||= begin + defined?(::Protobuf::Rpc::GC_PAUSE_REQUEST) && + ::Protobuf::Rpc::GC_PAUSE_REQUEST + end + end + + def _gc_pause_serialization + @_gc_pause_serialization ||= begin + defined?(::Protobuf::Rpc::GC_PAUSE_SERIALIZATION) && + ::Protobuf::Rpc::GC_PAUSE_SERIALIZATION + end + end + # Invoke the service method dictated by the proto wrapper request object def handle_client # Parse the protobuf request from the socket @@ -20,6 +34,7 @@ def handle_client # Call the service method log_debug { "[#{log_signature}] Dispatching client request to service" } + GC.disable if _gc_pause_request invoke_rpc_method rescue => error # Ensure we're handling any errors that try to slip out the back door @@ -132,13 +147,18 @@ def send_response @stats.end @stats.log_stats @did_respond = true + ensure + GC.enable if _gc_pause_request end def serialize_response(response) + GC.disable if _gc_pause_serialization log_debug { "[#{log_signature}] serializing response: %s" % response.inspect } @response.response_proto = response.serialize_to_string rescue raise BadResponseProto, $!.message + ensure + GC.enable if _gc_pause_serialization end end end diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index ea65564e..fef4c158 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -3,12 +3,12 @@ module Rpc class SocketRunner def self.stop - Protobuf::Rpc::Socket::Server.stop - Protobuf::Logger.info 'Shutdown complete' + ::Protobuf::Rpc::Socket::Server.stop + ::Protobuf::Logger.info { 'Shutdown complete' } end def self.run(server) - Protobuf::Logger.info "Socket::Server Running" + ::Protobuf::Logger.info { "Socket::Server Running" } server_config = case when server.is_a?(OpenStruct) then server.marshal_dump @@ -20,9 +20,9 @@ def self.run(server) raise "Cannot parser Socket Server - server options" end - Protobuf::Rpc::Socket::Server.run(server_config) + ::Protobuf::Rpc::Socket::Server.run(server_config) end - end + end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 72ca8d85..4fc2909e 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -12,7 +12,6 @@ class Worker # Constructor # def initialize(opts={}) - @options = opts host = @options.fetch(:host, "127.0.0.1") port = @options.fetch(:port, 9400) @@ -60,7 +59,7 @@ def run end def send_data - response_data = @response.is_a?(Protobuf::Message) ? @response.serialize_to_string : @response.to_s + response_data = @response.is_a?(::Protobuf::Message) ? @response.serialize_to_string : @response.to_s @stats.response_size = response_data.size zmq_error_check(@socket.send_string(response_data)) @did_respond = true From ef81ac86538ab6914158576a61a373c7104f6e75 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 18 Sep 2012 19:02:03 -0600 Subject: [PATCH 0073/1191] gc pausing is a boolean, should not use ||= --- lib/protobuf/rpc/server.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 1ba02aca..3cfdbe40 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -9,17 +9,13 @@ module Rpc module Server def _gc_pause_request - @_gc_pause_request ||= begin - defined?(::Protobuf::Rpc::GC_PAUSE_REQUEST) && - ::Protobuf::Rpc::GC_PAUSE_REQUEST - end + return @_gc_pause_request unless @_gc_pause_request.nil? + @_gc_pause_request ||= (defined?(::Protobuf::Rpc::GC_PAUSE_REQUEST) && ::Protobuf::Rpc::GC_PAUSE_REQUEST) end def _gc_pause_serialization - @_gc_pause_serialization ||= begin - defined?(::Protobuf::Rpc::GC_PAUSE_SERIALIZATION) && - ::Protobuf::Rpc::GC_PAUSE_SERIALIZATION - end + return @_gc_pause_serialization unless @_gc_pause_serialization.nil? + @_gc_pause_serialization ||= (defined?(::Protobuf::Rpc::GC_PAUSE_SERIALIZATION) && ::Protobuf::Rpc::GC_PAUSE_SERIALIZATION) end # Invoke the service method dictated by the proto wrapper request object From 83eb0fd7913972cb1a37094454d8666469f503d3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Sep 2012 21:42:03 -0600 Subject: [PATCH 0074/1191] Bump version 1.4.0. Supports GC pause, field caching --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e8cbdbd9..a75d70d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (1.3.0) + protobuf (1.4.0) eventmachine eventually ffi-rzmq diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b957f457..7bb61bbc 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '1.3.0' + VERSION = '1.4.0' end From 49bd8e4f178f5d402ffa070299e82ebabaea0bf5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 19 Sep 2012 13:01:08 -0600 Subject: [PATCH 0075/1191] add rpc_server startup hook to build and cache the message definitions of inherited classes --- bin/rpc_server | 6 ++++++ lib/protobuf/message/message.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/bin/rpc_server b/bin/rpc_server index 17be82b9..8b8a796f 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -12,6 +12,7 @@ require 'protobuf/rpc/servers/zmq_runner' server = OpenStruct.new({ :app => nil, :env => ENV['RPC_SERVER_ENV'] || 'development', + :pre_cache_definitions => false, :gc_pause_during_request => false, :gc_pause_during_serialization => false, :host => '127.0.0.1', @@ -79,6 +80,10 @@ parser = OptionParser.new do |opts| server.runner = ::Protobuf::Rpc::ZmqRunner end + opts.on("--[no-]-pre-cache-definitions", "Enable/Disable Message class pre-caching") do |v| + server.pre_cache_definitions = v + end + opts.on("--[no-]gc-pause-request", "Enable/Disable GC pause during request.") do |v| server.gc_pause_during_request = v end @@ -170,6 +175,7 @@ begin # Require the given application file require server.app + ::Protobuf::Message::Message.pre_cache_class_definitions if server.pre_cache_definitions server.runner.run(server) rescue msg = 'ERROR: RPC Server failed to start. %s' % $!.inspect diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 46e29766..4d7a6525 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -1,3 +1,4 @@ +require 'set' require 'protobuf/descriptor/descriptor' require 'protobuf/message/decoder' require 'protobuf/message/encoder' @@ -25,6 +26,18 @@ def include_tag?(tag) end end + def self.inherited(klass) + @_children ||= Set.new + @_children << klass + end + + def self.pre_cache_class_definitions + @_children ||= Set.new + @_children.each do |child_class| + child_class.new + end + end + class << self include Protoable From f1b5c766ca1a8f992ef6b92b28020943ecbe9a2b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 19 Sep 2012 13:04:44 -0600 Subject: [PATCH 0076/1191] correct rpc_server option syntax --- bin/rpc_server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/rpc_server b/bin/rpc_server index 8b8a796f..747465b0 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -80,7 +80,7 @@ parser = OptionParser.new do |opts| server.runner = ::Protobuf::Rpc::ZmqRunner end - opts.on("--[no-]-pre-cache-definitions", "Enable/Disable Message class pre-caching") do |v| + opts.on("--[no-]pre-cache-definitions", "Enable/Disable Message class pre-caching") do |v| server.pre_cache_definitions = v end From adef33a51ad2e112535b606fad0e5ca228d2a3dc Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 19 Sep 2012 13:48:12 -0600 Subject: [PATCH 0077/1191] correct namespace on message for pre-caching --- bin/rpc_server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/rpc_server b/bin/rpc_server index 747465b0..677c39e2 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -175,7 +175,7 @@ begin # Require the given application file require server.app - ::Protobuf::Message::Message.pre_cache_class_definitions if server.pre_cache_definitions + ::Protobuf::Message.pre_cache_class_definitions if server.pre_cache_definitions server.runner.run(server) rescue msg = 'ERROR: RPC Server failed to start. %s' % $!.inspect From 39029a4803740504dca0bab045be7312c1ed596a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Sep 2012 13:52:00 -0600 Subject: [PATCH 0078/1191] Bump version 1.4.1 Adds support for pre-caching message fields in the rpc_server by providing a configuration option to do so. --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a75d70d6..bf1fd6a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (1.4.0) + protobuf (1.4.1) eventmachine eventually ffi-rzmq diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 7bb61bbc..537a579a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '1.4.0' + VERSION = '1.4.1' end From 56b82de6a73f84d1ba6d3687bea4680fa8c37b9e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 19 Sep 2012 18:43:05 -0600 Subject: [PATCH 0079/1191] add a flag to track a stop during startup of rpc_server (quick hack) --- bin/rpc_server | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/rpc_server b/bin/rpc_server index 677c39e2..87ffb5ae 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -22,7 +22,8 @@ server = OpenStruct.new({ :log => File.expand_path('./protobuf.log'), :level => ::Logger::INFO, :runner => ::Protobuf::Rpc::EventedRunner, - :debug => false + :debug => false, + :stopped_during_startup => false }) class ClientServerParse @@ -148,6 +149,7 @@ require 'protobuf' [:INT, :QUIT, :TERM].each do |sig| trap(sig) do + server.stopped_during_startup = true server.runner.stop end end @@ -173,10 +175,13 @@ begin $0 = 'rpc_server %s:%d %s' % [server.host, server.port, server.app] # Require the given application file - require server.app + require server.app unless server.stopped_during_startup - ::Protobuf::Message.pre_cache_class_definitions if server.pre_cache_definitions - server.runner.run(server) + if server.pre_cache_definitions && !server.stopped_during_startup + ::Protobuf::Message.pre_cache_class_definitions + end + + server.runner.run(server) unless server.stopped_during_startup rescue msg = 'ERROR: RPC Server failed to start. %s' % $!.inspect $stderr.puts(msg, *($!.backtrace)) From 1ba531494debbb2dc3d78ca11f961500433980be Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 20 Sep 2012 02:53:46 -0400 Subject: [PATCH 0080/1191] need to access the field via fetch because the field may be falsey --- lib/protobuf/message/field.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index c6ae77c1..09d0d477 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -181,12 +181,7 @@ def define_getter field = self @message_class.class_eval do define_method(field.name) do - @values[field.name] || field.default_value -# if @values.has_key?(field.name) -# @values[field.name] -# else -# field.default_value -# end + @values.fetch(field.name, field.default_value) end end end From 385b6b4e3706a7248fac0d0dd31de711b8171233 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 20 Sep 2012 10:17:12 -0600 Subject: [PATCH 0081/1191] Bump version 1.4.2 --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bf1fd6a2..bc511307 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (1.4.1) + protobuf (1.4.2) eventmachine eventually ffi-rzmq diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 537a579a..616ebb27 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '1.4.1' + VERSION = '1.4.2' end From 0134965b293b8712a5c9e8ea0add13d3d037c292 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 20 Sep 2012 18:22:52 -0600 Subject: [PATCH 0082/1191] do not have to serialize message 2x for rpc message requests --- lib/protobuf/message/field.rb | 16 ++++++++++++---- lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/server.rb | 17 +++-------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index 09d0d477..1e2e0d9b 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -319,8 +319,11 @@ def wire_type end def acceptable?(val) - raise TypeError unless val.instance_of?(String) - true + if val.is_a?(::Protobuf::Message) || val.instance_of?(String) + return true + end + + raise TypeError end def decode(bytes) @@ -329,8 +332,13 @@ def decode(bytes) end def encode(value) - value = value.dup - value.force_encoding('ASCII-8BIT') if value.respond_to?(:force_encoding) + if value.is_a?(::Protobuf::Message) + value = value.serialize_to_string + else + value = value.dup + value.force_encoding('ASCII-8BIT') if value.respond_to?(:force_encoding) + end + string_size = VarintField.encode(value.size) string_size << value end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index b0b4a90b..0dc11ef2 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -44,7 +44,7 @@ def <<(data) end def set_data(data) - @data = data.is_a?(Protobuf::Message) ? data.serialize_to_string : data.to_s + @data = data.is_a?(::Protobuf::Message) ? data.serialize_to_string : data.to_s @size = @data.size end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 3cfdbe40..e5ecfe85 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -108,11 +108,10 @@ def parse_response_from_service(response) log_debug { "[#{log_signature}] response (should/actual): %s/%s" % [expected.name, actual.name] } # Determine if the service tried to change response types on us - if expected == actual - serialize_response(response) - else - # response types do not match, throw the appropriate error + if expected != actual raise ::Protobuf::Rpc::BadResponseProto, 'Response proto changed from %s to %s' % [expected.name, actual.name] + else + @response.response_proto = response end rescue => error log_error error.message @@ -146,16 +145,6 @@ def send_response ensure GC.enable if _gc_pause_request end - - def serialize_response(response) - GC.disable if _gc_pause_serialization - log_debug { "[#{log_signature}] serializing response: %s" % response.inspect } - @response.response_proto = response.serialize_to_string - rescue - raise BadResponseProto, $!.message - ensure - GC.enable if _gc_pause_serialization - end end end end From 0a0a6c5fe1cae504e2492b94255ee944caf04284 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 23 Sep 2012 00:09:36 -0400 Subject: [PATCH 0083/1191] move all field definitions into separate files and start moving away from custom string methods and towards activesupport --- Gemfile.lock | 9 +- lib/protobuf/descriptor/descriptor_builder.rb | 129 ++-- lib/protobuf/descriptor/field_descriptor.rb | 4 +- lib/protobuf/field/base_field.rb | 199 ++++++ lib/protobuf/field/bool_field.rb | 24 + lib/protobuf/field/bytes_field.rb | 38 + lib/protobuf/field/double_field.rb | 19 + lib/protobuf/field/enum_field.rb | 58 ++ lib/protobuf/field/field_array.rb | 47 ++ lib/protobuf/field/field_proxy.rb | 47 ++ lib/protobuf/field/fixed32_field.rb | 19 + lib/protobuf/field/fixed64_field.rb | 22 + lib/protobuf/field/float_field.rb | 29 + lib/protobuf/field/int32_field.rb | 10 + lib/protobuf/field/int64_field.rb | 10 + lib/protobuf/field/integer_field.rb | 19 + lib/protobuf/field/message_field.rb | 48 ++ lib/protobuf/field/sfixed32_field.rb | 21 + lib/protobuf/field/sfixed64_field.rb | 24 + lib/protobuf/field/signed_integer_field.rb | 23 + lib/protobuf/field/sint32_field.rb | 10 + lib/protobuf/field/sint64_field.rb | 10 + lib/protobuf/field/string_field.rb | 12 + lib/protobuf/field/uint32_field.rb | 10 + lib/protobuf/field/uint64_field.rb | 10 + lib/protobuf/field/varint_field.rb | 59 ++ lib/protobuf/message/field.rb | 665 +----------------- lib/protobuf/message/message.rb | 1 - protobuf.gemspec | 3 +- 29 files changed, 831 insertions(+), 748 deletions(-) create mode 100644 lib/protobuf/field/base_field.rb create mode 100644 lib/protobuf/field/bool_field.rb create mode 100644 lib/protobuf/field/bytes_field.rb create mode 100644 lib/protobuf/field/double_field.rb create mode 100644 lib/protobuf/field/enum_field.rb create mode 100644 lib/protobuf/field/field_array.rb create mode 100644 lib/protobuf/field/field_proxy.rb create mode 100644 lib/protobuf/field/fixed32_field.rb create mode 100644 lib/protobuf/field/fixed64_field.rb create mode 100644 lib/protobuf/field/float_field.rb create mode 100644 lib/protobuf/field/int32_field.rb create mode 100644 lib/protobuf/field/int64_field.rb create mode 100644 lib/protobuf/field/integer_field.rb create mode 100644 lib/protobuf/field/message_field.rb create mode 100644 lib/protobuf/field/sfixed32_field.rb create mode 100644 lib/protobuf/field/sfixed64_field.rb create mode 100644 lib/protobuf/field/signed_integer_field.rb create mode 100644 lib/protobuf/field/sint32_field.rb create mode 100644 lib/protobuf/field/sint64_field.rb create mode 100644 lib/protobuf/field/string_field.rb create mode 100644 lib/protobuf/field/uint32_field.rb create mode 100644 lib/protobuf/field/uint64_field.rb create mode 100644 lib/protobuf/field/varint_field.rb diff --git a/Gemfile.lock b/Gemfile.lock index bf1fd6a2..0733c00f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,22 +2,23 @@ PATH remote: . specs: protobuf (1.4.1) + activesupport eventmachine - eventually ffi-rzmq - json_pure GEM remote: http://rubygems.org/ specs: + activesupport (3.2.8) + i18n (~> 0.6) + multi_json (~> 1.0) coderay (1.0.7) diff-lcs (1.1.3) eventmachine (1.0.0) - eventually (0.1.1) ffi (1.1.5) ffi-rzmq (0.9.6) ffi - json_pure (1.7.5) + i18n (0.6.1) method_source (0.8) multi_json (1.3.6) pry (0.9.10) diff --git a/lib/protobuf/descriptor/descriptor_builder.rb b/lib/protobuf/descriptor/descriptor_builder.rb index 3eea9c58..72552dd3 100644 --- a/lib/protobuf/descriptor/descriptor_builder.rb +++ b/lib/protobuf/descriptor/descriptor_builder.rb @@ -5,41 +5,41 @@ module Descriptor def self.id2type(type_id) require 'protobuf/descriptor/descriptor_proto' case type_id - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE then :double - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT then :float - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64 then :int64 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64 then :unit64 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32 then :int64 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64 then :fixed64 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32 then :fixed32 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL then :bool - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING then :string - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP then :group - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE then :message - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES then :bytes - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32 then :uint32 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM then :enum - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32 then :sfixed32 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64 then :sfixed64 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32 then :sint32 - when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64 then + when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64 then :sint64 else raise ArgumentError, "Invalid type: #{proto.type}" @@ -49,55 +49,37 @@ def self.id2type(type_id) def self.type2id(type) require 'protobuf/descriptor/descriptor_proto' case type - when :double then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE - when :float then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT - when :int64 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64 - when :unit64 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64 - when :int64 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32 - when :fixed64 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64 - when :fixed32 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32 - when :bool then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL - when :string then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING - when :group then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP - when :message then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE - when :bytes then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES - when :uint32 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32 - when :enum then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM - when :sfixed32 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32 - when :sfixed64 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64 - when :sint32 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32 - when :sint64 then - Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64 + when :double then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE + when :float then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT + when :int64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64 + when :unit64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64 + when :int64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32 + when :fixed64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64 + when :fixed32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32 + when :bool then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL + when :string then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING + when :group then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP + when :message then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE + when :bytes then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES + when :uint32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32 + when :enum then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM + when :sfixed32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32 + when :sfixed64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64 + when :sint32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32 + when :sint64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64 else - Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE + ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE end end def self.id2label(label_id) require 'protobuf/descriptor/descriptor_proto' case label_id - when Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED then + when ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED then :required - when Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL then + when ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL then :optional - when Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED then + when ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED then :repeated else raise ArgumentError, "Invalid label: #{proto.label}" @@ -108,33 +90,30 @@ def self.label2id(label) require 'protobuf/descriptor/descriptor_proto' case label when :required then - Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED + ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED when :optional then - Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL + ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL when :repeated then - Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED + ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED else raise ArgumentError, "Invalid label: #{label}" end end class DescriptorBuilder - class <> 32].pack('VV') + end + end + end +end diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb new file mode 100644 index 00000000..ff9f252b --- /dev/null +++ b/lib/protobuf/field/float_field.rb @@ -0,0 +1,29 @@ +require 'protobuf/field/base_field' + +module Protobuf + module Field + class FloatField < BaseField + def self.default; 0.0; end + def self.max; 1.0/0; end + def self.min; -1.0/0; end + + def wire_type + WireType::FIXED32 + end + + def decode(bytes) + bytes.unpack('e').first + end + + def encode(value) + [value].pack('e') + end + + def acceptable?(val) + raise TypeError, val.class.name unless val.is_a?(Numeric) + raise RangeError if val < min || max < val + true + end + end + end +end diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb new file mode 100644 index 00000000..b3eee379 --- /dev/null +++ b/lib/protobuf/field/int32_field.rb @@ -0,0 +1,10 @@ +require 'protobuf/field/integer_field' + +module Protobuf + module Field + class Int32Field < IntegerField + def self.max; INT32_MAX; end + def self.min; INT32_MIN; end + end + end +end diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb new file mode 100644 index 00000000..67f36313 --- /dev/null +++ b/lib/protobuf/field/int64_field.rb @@ -0,0 +1,10 @@ +require 'protobuf/field/integer_field' + +module Protobuf + module Field + class Int64Field < IntegerField + def self.max; INT64_MAX; end + def self.min; INT64_MIN; end + end + end +end diff --git a/lib/protobuf/field/integer_field.rb b/lib/protobuf/field/integer_field.rb new file mode 100644 index 00000000..b05e8866 --- /dev/null +++ b/lib/protobuf/field/integer_field.rb @@ -0,0 +1,19 @@ +require 'protobuf/field/varint_field' + +module Protobuf + module Field + class IntegerField < VarintField + + def encode(value) + # original Google's library uses 64bits integer for negative value + VarintField.encode(value & 0xffff_ffff_ffff_ffff) + end + + def decode(value) + value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? + value + end + + end + end +end diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb new file mode 100644 index 00000000..25609759 --- /dev/null +++ b/lib/protobuf/field/message_field.rb @@ -0,0 +1,48 @@ +require 'protobuf/field/base_field' + +module Protobuf + module Field + class MessageField < BaseField + def wire_type + WireType::LENGTH_DELIMITED + end + + def acceptable?(val) + raise TypeError unless val.instance_of?(type) || val.instance_of?(Hash) + true + end + + def decode(bytes) + message = type.new + message.parse_from_string(bytes) + message + end + + def encode(value) + bytes = value.serialize_to_string + result = VarintField.encode(bytes.size) + result << bytes + end + + private + + def define_setter + field = self + @message_class.class_eval do + define_method("#{field.name}=") do |val| + case val + when nil then + @values.delete(field.name) + when Hash then + @values[field.name] = field.type.new(val) + when field.type then + @values[field.name] = val + else + raise TypeError, "Expected value of type '#{field.type}', but got '#{val.class}'" + end + end + end + end + end + end +end diff --git a/lib/protobuf/field/sfixed32_field.rb b/lib/protobuf/field/sfixed32_field.rb new file mode 100644 index 00000000..3c2f55a4 --- /dev/null +++ b/lib/protobuf/field/sfixed32_field.rb @@ -0,0 +1,21 @@ +require 'protobuf/field/int32_field' + +module Protobuf + module Field + class Sfixed32Field < Int32Field + def wire_type + ::WireType::FIXED32 + end + + def decode(bytes) + value = bytes.unpack('V').first + value -= 0x1_0000_0000 if (value & 0x8000_0000).nonzero? + value + end + + def encode(value) + [value].pack('V') + end + end + end +end diff --git a/lib/protobuf/field/sfixed64_field.rb b/lib/protobuf/field/sfixed64_field.rb new file mode 100644 index 00000000..0ba7f1d9 --- /dev/null +++ b/lib/protobuf/field/sfixed64_field.rb @@ -0,0 +1,24 @@ +require 'protobuf/field/int64_field' + +module Protobuf + module Field + class Sfixed64Field < Int64Field + def wire_type + ::WireType::FIXED64 + end + + def decode(bytes) + # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. + values = bytes.unpack('VV') + value = values[0] + (values[1] << 32) + value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? + value + end + + def encode(value) + # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. + [value & 0xffff_ffff, value >> 32].pack('VV') + end + end + end +end diff --git a/lib/protobuf/field/signed_integer_field.rb b/lib/protobuf/field/signed_integer_field.rb new file mode 100644 index 00000000..1410213e --- /dev/null +++ b/lib/protobuf/field/signed_integer_field.rb @@ -0,0 +1,23 @@ +require 'protobuf/field/varint_field' + +module Protobuf + module Field + class SignedIntegerField < VarintField + def decode(value) + if (value & 1).zero? + value >> 1 # positive value + else + ~value >> 1 # negative value + end + end + + def encode(value) + if value >= 0 + VarintField.encode(value << 1) + else + VarintField.encode(~(value << 1)) + end + end + end + end +end diff --git a/lib/protobuf/field/sint32_field.rb b/lib/protobuf/field/sint32_field.rb new file mode 100644 index 00000000..17e6bba8 --- /dev/null +++ b/lib/protobuf/field/sint32_field.rb @@ -0,0 +1,10 @@ +require 'protobuf/field/signed_integer_field' + +module Protobuf + module Field + class Sint32Field < SignedIntegerField + def self.max; INT32_MAX; end + def self.min; INT32_MIN; end + end + end +end diff --git a/lib/protobuf/field/sint64_field.rb b/lib/protobuf/field/sint64_field.rb new file mode 100644 index 00000000..b49bb74f --- /dev/null +++ b/lib/protobuf/field/sint64_field.rb @@ -0,0 +1,10 @@ +require 'protobuf/field/signed_integer_field' + +module Protobuf + module Field + class Sint64Field < SignedIntegerField + def self.max; INT64_MAX; end + def self.min; INT64_MIN; end + end + end +end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb new file mode 100644 index 00000000..da56e2e1 --- /dev/null +++ b/lib/protobuf/field/string_field.rb @@ -0,0 +1,12 @@ +require 'protobuf/field/bytes_field' + +module Protobuf + module Field + class StringField < BytesField + def decode(bytes) + bytes.force_encoding('UTF-8') if bytes.respond_to?(:force_encoding) + bytes + end + end + end +end diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb new file mode 100644 index 00000000..3caa31c2 --- /dev/null +++ b/lib/protobuf/field/uint32_field.rb @@ -0,0 +1,10 @@ +require 'protobuf/field/varint_field' + +module Protobuf + module Field + class Uint32Field < VarintField + def self.max; UINT32_MAX; end + def self.min; 0; end + end + end +end diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb new file mode 100644 index 00000000..89d9d971 --- /dev/null +++ b/lib/protobuf/field/uint64_field.rb @@ -0,0 +1,10 @@ +require 'protobuf/field/varint_field' + +module Protobuf + module Field + class Uint64Field < VarintField + def self.max; UINT64_MAX; end + def self.min; 0; end + end + end +end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb new file mode 100644 index 00000000..3d5b13d8 --- /dev/null +++ b/lib/protobuf/field/varint_field.rb @@ -0,0 +1,59 @@ +require 'protobuf/field/base_field' + +module Protobuf + module Field + class VarintField < BaseField + INT32_MAX = 2**31 - 1 + INT32_MIN = -2**31 + INT64_MAX = 2**63 - 1 + INT64_MIN = -2**63 + UINT32_MAX = 2**32 - 1 + UINT64_MAX = 2**64 - 1 + + class << self + def default + 0 + end + + def decode(bytes) + value = 0 + bytes.each_with_index do |byte, index| + value |= byte << (7 * index) + end + value + end + + def encode(value) + raise RangeError, "#{value} is negative" if value < 0 + return [value].pack('C') if value < 128 + bytes = [] + until value == 0 + bytes << (0x80 | (value & 0x7f)) + value >>= 7 + end + bytes[-1] &= 0x7f + bytes.pack('C*') + end + end + + def wire_type + WireType::VARINT + end + + def decode(value) + value + end + + def encode(value) + self.class.encode(value) + end + + def acceptable?(val) + raise TypeError, val.class.name unless val.is_a?(Integer) + raise RangeError if val < min || max < val + true + end + end + end +end + diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index 1e2e0d9b..1c4e9bae 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -1,4 +1,3 @@ -require 'protobuf/common/util' require 'protobuf/common/wire_type' require 'protobuf/descriptor/field_descriptor' @@ -19,674 +18,12 @@ module Field def self.build(message_class, rule, type, name, tag, options={}) field_class = \ if PREDEFINED_TYPES.include?(type) - const_get("#{type.to_s.capitalize}Field") + "#{type.to_s.capitalize}Field".constantize else FieldProxy end field_class.new(message_class, rule, type, name, tag, options) end - class BaseField - - def self.descriptor - @descriptor ||= Descriptor::FieldDescriptor.new - end - - def self.default - nil - end - - attr_reader :message_class, :rule, :type, :name, :tag, :default - attr_reader :default_value - - def descriptor - @descriptor ||= Descriptor::FieldDescriptor.new(self) - end - - def initialize(message_class, rule, type, name, tag, options) - @message_class, @rule, @type, @name, @tag = \ - message_class, rule, type, name, tag - - @default = options.delete(:default) - @extension = options.delete(:extension) - @packed = repeated? && options.delete(:packed) - unless options.empty? - warn "WARNING: Invalid options: #{options.inspect} (in #{@message_class.name.split('::').last}.#{@name})" - end - if packed? && ! [WireType::VARINT, WireType::FIXED32, WireType::FIXED64].include?(wire_type) - raise "Can't use packed encoding for `#{@type}' type" - end - - @default_value = \ - case @rule - when :repeated then - FieldArray.new(self).freeze - when :required then - nil - when :optional then - typed_default_value - end - - define_accessor - end - - def ready? - true - end - - def initialized?(message_instance) - value = message_instance.__send__(@name) - case @rule - when :required then - ! value.nil? && (! kind_of?(MessageField) || value.initialized?) - when :repeated then - value.all? {|msg| ! kind_of?(MessageField) || msg.initialized? } - when :optional then - value.nil? || ! kind_of?(MessageField) || value.initialized? - end - end - - # Decode +bytes+ and pass to +message_instance+. - def set(message_instance, bytes) - if packed? - array = message_instance.__send__(@name) - method = \ - case wire_type - when WireType::FIXED32 then :read_fixed32 - when WireType::FIXED64 then :read_fixed64 - when WireType::VARINT then :read_varint - end - stream = StringIO.new(bytes) - until stream.eof? - array << decode(Decoder.__send__(method, stream)) - end - else - value = decode(bytes) - if repeated? - message_instance.__send__(@name) << value - else - message_instance.__send__("#{@name}=", value) - end - end - end - - # Decode +bytes+ and return a field value. - def decode(bytes) - raise NotImplementedError, "#{self.class.name}\#decode" - end - - # Encode +value+ and return a byte string. - def encode(value) - raise NotImplementedError, "#{self.class.name}\#encode" - end - - def extension? - !!@extension - end - - # Is this a repeated field? - def repeated? - return @_repeated unless @_repeated.nil? - @_repeated = (@rule == :repeated) - end - - # Is this a required field? - def required? - return @_required unless @_required.nil? - @_required = (@rule == :required) - end - - # Is this a optional field? - def optional? - return @_optional unless @_optional.nil? - @_optional = (@rule == :optional) - end - - # Is this a packed repeated field? - def packed? - !!@packed - end - - # Upper limit for this field. - def max - self.class.max - end - - # Lower limit for this field. - def min - self.class.min - end - - # Is a +value+ acceptable for this field? - def acceptable?(value) - true - end - - def to_s - "#{@rule} #{@type} #{@name} = #{@tag} #{@default ? "[default=#{@default.inspect}]" : ''}" - end - - private - - def define_accessor - define_getter - if repeated? - define_array_setter - else - define_setter - end - end - - def define_getter - field = self - @message_class.class_eval do - define_method(field.name) do - @values.fetch(field.name, field.default_value) - end - end - end - - def define_setter - field = self - @message_class.class_eval do - define_method("#{field.name}=") do |val| - if val.nil? - @values.delete(field.name) - elsif field.acceptable?(val) - @values[field.name] = val - end - end - end - end - - def define_array_setter - field = self - @message_class.class_eval do - define_method("#{field.name}=") do |val| - @values[field.name].replace(val) - end - end - end - - def typed_default_value - if @default.nil? - self.class.default - else - @default - end - end - - end # BaseField - - - class FieldProxy - - def initialize(message_class, rule, type, name, tag, options) - @message_class, @rule, @type, @name, @tag, @options = - message_class, rule, type, name, tag, options - end - - def ready? - false - end - - def setup - type = typename_to_class(@message_class, @type) - field_class = \ - if type < Enum - EnumField - elsif type < Message - MessageField - else - raise TypeError, type.inspect - end - field_class.new(@message_class, @rule, type, @name, @tag, @options) - end - - private - - def typename_to_class(message_class, type) - names = type.to_s.split('::').map {|s| Util.camelize(s) } - outer = message_class.to_s.split('::') - args = (Object.method(:const_defined?).arity == 1) ? [] : [false] - while - mod = outer.empty? ? Object : eval(outer.join('::')) - mod = names.inject(mod) {|m, s| - m && m.const_defined?(s, *args) && m.const_get(s) - } - break if mod - raise NameError.new("type not found: #{type}", type) if outer.empty? - outer.pop - end - mod - end - - end - - class FieldArray < Array - - def initialize(field) - @field = field - end - - def []=(nth, val) - super(nth, normalize(val)) - end - - def <<(val) - super(normalize(val)) - end - - def push(val) - super(normalize(val)) - end - - def unshift(val) - super(normalize(val)) - end - - def replace(val) - raise TypeError unless val.is_a?(Array) - val = val.map {|v| normalize(v)} - super(val) - end - - def to_s - "[#{@field.name}]" - end - - private - - def normalize(val) - raise TypeError unless @field.acceptable?(val) - if @field.is_a?(MessageField) && val.is_a?(Hash) - @field.type.new(val) - else - val - end - end - - end - - # Field class for +bytes+ type. - class BytesField < BaseField - def self.default - '' - end - - def wire_type - WireType::LENGTH_DELIMITED - end - - def acceptable?(val) - if val.is_a?(::Protobuf::Message) || val.instance_of?(String) - return true - end - - raise TypeError - end - - def decode(bytes) - bytes.force_encoding('ASCII-8BIT') if bytes.respond_to?(:force_encoding) - bytes - end - - def encode(value) - if value.is_a?(::Protobuf::Message) - value = value.serialize_to_string - else - value = value.dup - value.force_encoding('ASCII-8BIT') if value.respond_to?(:force_encoding) - end - - string_size = VarintField.encode(value.size) - string_size << value - end - end - - class StringField < BytesField - def decode(bytes) - bytes.force_encoding('UTF-8') if bytes.respond_to?(:force_encoding) - bytes - end - end - - class VarintField < BaseField - INT32_MAX = 2**31 - 1 - INT32_MIN = -2**31 - INT64_MAX = 2**63 - 1 - INT64_MIN = -2**63 - UINT32_MAX = 2**32 - 1 - UINT64_MAX = 2**64 - 1 - - class << self - def default - 0 - end - - def decode(bytes) - value = 0 - bytes.each_with_index do |byte, index| - value |= byte << (7 * index) - end - value - end - - def encode(value) - raise RangeError, "#{value} is negative" if value < 0 - return [value].pack('C') if value < 128 - bytes = [] - until value == 0 - bytes << (0x80 | (value & 0x7f)) - value >>= 7 - end - bytes[-1] &= 0x7f - bytes.pack('C*') - end - end - - def wire_type - WireType::VARINT - end - - def decode(value) - value - end - - def encode(value) - self.class.encode(value) - end - - def acceptable?(val) - raise TypeError, val.class.name unless val.is_a?(Integer) - raise RangeError if val < min || max < val - true - end - end - - # Base class for int32 and int64 - class IntegerField < VarintField - def encode(value) - # original Google's library uses 64bits integer for negative value - VarintField.encode(value & 0xffff_ffff_ffff_ffff) - end - - def decode(value) - value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? - value - end - end - - class Int32Field < IntegerField - def self.max; INT32_MAX; end - def self.min; INT32_MIN; end - end - - class Int64Field < IntegerField - def self.max; INT64_MAX; end - def self.min; INT64_MIN; end - end - - class Uint32Field < VarintField - def self.max; UINT32_MAX; end - def self.min; 0; end - end - - class Uint64Field < VarintField - def self.max; UINT64_MAX; end - def self.min; 0; end - end - - # Base class for sint32 and sint64 - class SignedIntegerField < VarintField - def decode(value) - if (value & 1).zero? - value >> 1 # positive value - else - ~value >> 1 # negative value - end - end - - def encode(value) - if value >= 0 - VarintField.encode(value << 1) - else - VarintField.encode(~(value << 1)) - end - end - end - - class Sint32Field < SignedIntegerField - def self.max; INT32_MAX; end - def self.min; INT32_MIN; end - end - - class Sint64Field < SignedIntegerField - def self.max; INT64_MAX; end - def self.min; INT64_MIN; end - end - - class FloatField < BaseField - def self.default; 0.0; end - def self.max; 1.0/0; end - def self.min; -1.0/0; end - - def wire_type - WireType::FIXED32 - end - - def decode(bytes) - bytes.unpack('e').first - end - - def encode(value) - [value].pack('e') - end - - def acceptable?(val) - raise TypeError, val.class.name unless val.is_a?(Numeric) - raise RangeError if val < min || max < val - true - end - end - - class DoubleField < FloatField - def wire_type - WireType::FIXED64 - end - - def decode(bytes) - bytes.unpack('E').first - end - - def encode(value) - [value].pack('E') - end - end - - class Fixed32Field < Uint32Field - def wire_type - WireType::FIXED32 - end - - def decode(bytes) - bytes.unpack('V').first - end - - def encode(value) - [value].pack('V') - end - end - - class Fixed64Field < Uint64Field - def wire_type - WireType::FIXED64 - end - - def decode(bytes) - # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. - values = bytes.unpack('VV') - values[0] + (values[1] << 32) - end - - def encode(value) - # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. - [value & 0xffff_ffff, value >> 32].pack('VV') - end - end - - class Sfixed32Field < Int32Field - def wire_type - WireType::FIXED32 - end - - def decode(bytes) - value = bytes.unpack('V').first - value -= 0x1_0000_0000 if (value & 0x8000_0000).nonzero? - value - end - - def encode(value) - [value].pack('V') - end - end - - class Sfixed64Field < Int64Field - def wire_type - WireType::FIXED64 - end - - def decode(bytes) - # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. - values = bytes.unpack('VV') - value = values[0] + (values[1] << 32) - value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? - value - end - - def encode(value) - # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. - [value & 0xffff_ffff, value >> 32].pack('VV') - end - end - - class BoolField < VarintField - def self.default - false - end - - def acceptable?(val) - raise TypeError unless [true, false].include?(val) - true - end - - def decode(value) - value == 1 - end - - def encode(value) - [value ? 1 : 0].pack('C') - end - end - - - class MessageField < BaseField - def wire_type - WireType::LENGTH_DELIMITED - end - - def acceptable?(val) - raise TypeError unless val.instance_of?(type) || val.instance_of?(Hash) - true - end - - def decode(bytes) - message = type.new - message.parse_from_string(bytes) - message - end - - def encode(value) - bytes = value.serialize_to_string - result = VarintField.encode(bytes.size) - result << bytes - end - - private - - def define_setter - field = self - @message_class.class_eval do - define_method("#{field.name}=") do |val| - case val - when nil then - @values.delete(field.name) - when Hash then - @values[field.name] = field.type.new(val) - when field.type then - @values[field.name] = val - else - raise TypeError, "Expected value of type '#{field.type}', but got '#{val.class}'" - end - end - end - end - - end - - - class EnumField < VarintField - def acceptable?(val) - case val - when Symbol then - raise TypeError unless @type.const_defined?(val) - when EnumValue then - raise TypeError if val.parent_class != @type - else - raise TypeError unless @type.valid_tag?(val) - end - true - end - - def encode(value) - super(value.to_i) - end - - private - - def typed_default_value - if @default.is_a?(Symbol) - @type.const_get(@default) - else - self.class.default - end - end - - def define_setter - field = self - @message_class.class_eval do - define_method("#{field.name}=") do |val| - if val.nil? - @values.delete(field.name) - else - val = \ - case val - when Symbol then - field.type.const_get(val) rescue nil - when Integer then - field.type.const_get(field.type.name_by_value(val)) rescue nil - when EnumValue then - raise TypeError, "Invalid value: #{val.inspect} for #{field.name}" if val.parent_class != field.type - val - end - raise TypeError, "Invalid value: #{val.inspect} for #{field.name}" unless val - - @values[field.name] = val - end - end - end - end - - end end end diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 4d7a6525..3233af44 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -4,7 +4,6 @@ require 'protobuf/message/encoder' require 'protobuf/message/field' require 'protobuf/message/protoable' -require 'json' module Protobuf OPTIONS = {} diff --git a/protobuf.gemspec b/protobuf.gemspec index 72a741c8..5366b470 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -18,9 +18,8 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] + s.add_dependency 'activesupport' s.add_dependency 'eventmachine' - s.add_dependency 'eventually' - s.add_dependency 'json_pure' s.add_dependency 'ffi-rzmq' s.add_development_dependency 'rake' From feb8eb240f877f21017b13b6cf96dde26b9c5090 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 23 Sep 2012 00:28:03 -0400 Subject: [PATCH 0084/1191] move primitives to a hash instead of lazy lookup --- lib/protobuf/message/field.rb | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/message/field.rb index 1c4e9bae..dbbf04c0 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/message/field.rb @@ -3,27 +3,27 @@ module Protobuf module Field - - PREDEFINED_TYPES = [ - :double, :float, - :int32, :int64, - :uint32, :uint64, - :sint32, :sint64, - :fixed32, :fixed64, - :sfixed32, :sfixed64, - :string, :bytes, - :bool, - ].freeze + PREDEFINED_TYPES = { + :double => ::Protobuf::Field::DoubleField, + :float => ::Protobuf::Field::FloatField, + :int32 => ::Protobuf::Field::Int32Field, + :int64 => ::Protobuf::Field::Int64Field, + :uint32 => ::Protobuf::Field::Uint32Field, + :uint64 => ::Protobuf::Field::Uint64Field, + :sint32 => ::Protobuf::Field::Sint32Field, + :sint64 => ::Protobuf::Field::Sint64Field, + :fixed32 => ::Protobuf::Field::Fixed32Field, + :fixed64 => ::Protobuf::Field::Fixed64Field, + :sfixed32 => ::Protobuf::Field::Sfixed32Field, + :sfixed64 => ::Protobuf::Field::Sfixed64Field, + :string => ::Protobuf::Field::StringField, + :bytes => ::Protobuf::Field::BytesField, + :bool => ::Protobuf::Field::BoolField + }.freeze def self.build(message_class, rule, type, name, tag, options={}) - field_class = \ - if PREDEFINED_TYPES.include?(type) - "#{type.to_s.capitalize}Field".constantize - else - FieldProxy - end + field_class = ::Protobuf::Field::PREDEFINED_TYPES.fetch(type, ::Protobuf::Field::FieldProxy) field_class.new(message_class, rule, type, name, tag, options) end - end end From 43ba798391ce20c30ffd1d76c10a51e896f6522f Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 23 Sep 2012 02:56:09 -0400 Subject: [PATCH 0085/1191] add active_support and remove Util --- lib/protobuf.rb | 1 + lib/protobuf/common/util.rb | 59 ------------------- lib/protobuf/compiler/nodes.rb | 5 +- .../template/rpc_service_implementation.erb | 6 +- lib/protobuf/compiler/visitors.rb | 15 +++-- lib/protobuf/{message => }/field.rb | 24 +++++++- lib/protobuf/field/base_field.rb | 59 +++++++++++-------- lib/protobuf/field/field_array.rb | 14 ++++- lib/protobuf/field/field_proxy.rb | 2 +- lib/protobuf/field/message_field.rb | 13 ++-- lib/protobuf/message/message.rb | 2 +- lib/protobuf/rpc/server.rb | 4 +- spec/unit/common/util_spec.rb | 17 ------ spec/unit/rpc/servers/evented_server_spec.rb | 5 +- spec/unit/rpc/servers/socket_server_spec.rb | 5 +- 15 files changed, 100 insertions(+), 131 deletions(-) delete mode 100644 lib/protobuf/common/util.rb rename lib/protobuf/{message => }/field.rb (56%) delete mode 100644 spec/unit/common/util_spec.rb diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 9b152629..309c0832 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -2,6 +2,7 @@ require 'socket' require 'pp' require 'stringio' +require 'active_support/all' module Protobuf end diff --git a/lib/protobuf/common/util.rb b/lib/protobuf/common/util.rb deleted file mode 100644 index d0e4d446..00000000 --- a/lib/protobuf/common/util.rb +++ /dev/null @@ -1,59 +0,0 @@ -module Protobuf - module Util - module_function - - # Takes a string or symbol and camelizes it: - # Expects: some_long_name - # Returns: SomeLongName - def camelize(str) - if (str.is_a? Array) - str.map{|p| camelize(p.to_s) }.join('::') - else - str.to_s.gsub(/(?:\A|_)(\w)/) { $1.upcase } - end - end - - # Expects: SomeLongName, SOMELongName - # Returns: some_long_name - def underscore(str) - str.to_s.gsub(/\B[A-Z](?:[a-z])/, '_\&').downcase - end - - # Expects: SomeModule::Path - # Returns: some_module/path - def module_to_path(str) - pkg = str.to_s.split('::') - pkg.map{|e| underscore(e) }.join('/') - end - - # Expects: PackageA.PackageB - # Returns: package_a/package_b - def package_to_path(str) - str.to_s.split('.').map{|e| underscore(e) }.join('/') - end - - # Takes a class constant and converts it to a string resembling a java package path - # Expects: ModA::ModB::MyService - # Returns: mod_a.mod_b.MyService - def packagize(klass) - klass = klass.to_s.split('::') unless klass.is_a? Array - klass_name = klass.pop - klass.map{|e| underscore(e) }.join('.') + ".#{klass_name}" - end - - # The reverse of packagize. Takes a string resembling a java package path - # and converts it into a module constant - # Expects: mod_a.mod_b.MyService - # Returns: ModA::ModB::MyService - def moduleize(str) - str = str.join('.') if str.is_a? Array - str.split('.').map{|e| camelize(e) }.join('::') - end - - def constantize(klass) - constants = moduleize(klass).split('::') - constants.inject(Module.const_get(constants.shift)) {|const, obj| const.const_get(obj) } - end - - end -end diff --git a/lib/protobuf/compiler/nodes.rb b/lib/protobuf/compiler/nodes.rb index eccddf70..1cf974be 100644 --- a/lib/protobuf/compiler/nodes.rb +++ b/lib/protobuf/compiler/nodes.rb @@ -1,4 +1,3 @@ -require 'protobuf/common/util' require 'protobuf/descriptor/descriptor_proto' module Protobuf @@ -73,7 +72,7 @@ def initialize(path_list) def accept_message_visitor(visitor) visitor.package = @path_list.dup @path_list.each do |path| - visitor.write("module #{Util.camelize(path)}") + visitor.write("module #{path.camelize}") visitor.increment end end @@ -251,7 +250,7 @@ def accept_message_visitor(visitor) opts << ', :extension => true' end type = if @type.is_a?(Array) - then (@type.size > 1) ? "'#{@type.map{|e| Util.camelize(e) }.join('::')}'" : @type[0] + then (@type.size > 1) ? "'#{@type.map{ |e| e.camelize }.join('::')}'" : @type[0] else @type end visitor.write("#{@label} :#{type}, :#{@name}, #{@value}#{opts}") diff --git a/lib/protobuf/compiler/template/rpc_service_implementation.erb b/lib/protobuf/compiler/template/rpc_service_implementation.erb index 4c295e57..faaef5d9 100644 --- a/lib/protobuf/compiler/template/rpc_service_implementation.erb +++ b/lib/protobuf/compiler/template/rpc_service_implementation.erb @@ -18,8 +18,8 @@ require '<%= required_file %>' <%- rpcs.each do |name, request, response| -%> ## <%= class_indent %> # request -> <%= module_name %>::<%= request %> ## <%= class_indent %> # response -> <%= module_name %>::<%= response %> -## <%= class_indent %> def <%= Util.underscore(name) %> -## <%= class_indent %> # TODO: implement <%= Util.underscore(name) %> +## <%= class_indent %> def <%= name.underscore %> +## <%= class_indent %> # TODO: implement <%= name.underscore %> ## <%= class_indent %> end ## <%= class_indent %> <%- end -%> @@ -34,7 +34,7 @@ require '<%= required_file %>' <%- end -%> <%= class_indent %>class <%= service_name %> < Protobuf::Rpc::Service <%- rpcs.each do |name, request, response| -%> -<%= class_indent %> rpc :<%= Util.underscore(name) %>, <%= request %>, <%= response %> +<%= class_indent %> rpc :<%= name.underscore %>, <%= request %>, <%= response %> <%- end -%> <%= class_indent %>end <%- (module_array.size-1).downto(0) do |i| -%> diff --git a/lib/protobuf/compiler/visitors.rb b/lib/protobuf/compiler/visitors.rb index 807d5c39..3cb19417 100644 --- a/lib/protobuf/compiler/visitors.rb +++ b/lib/protobuf/compiler/visitors.rb @@ -120,7 +120,7 @@ def create_files(filename, out_dir, file_create) else file = File.basename(filename) - message_module = Util.module_to_path(package.map{|p| p.to_s.capitalize}.join('::')) + message_module = (package.map{|p| p.to_s.capitalize}.join('::')).underscore filename = "#{out_dir}/#{message_module}/#{file}" if file_create @@ -148,16 +148,19 @@ def visit(node) end def add_rpc(name, request, response) - (@services[@current_service] ||= []) << [name, Util.moduleize(request), Util.moduleize(response)] + request_module = request.gsub(".", "_").classify + response_module = request.gsub(".", "_").classify + + (@services[@current_service] ||= []) << [name, request_module, response_module] end def create_files(message_file, out_dir, create_file=true) @create_file = create_file @services.each do |service_name, rpcs| - underscored_name = Util.underscore(service_name.to_s) - message_module = package.map{|p| p.to_s.capitalize}.join('::') + underscored_name = "#{service_name}".underscore + message_module = package.map{ |p| p.to_s.capitalize}.join('::') required_file = [ - Util.module_to_path(message_module), + message_module.underscore, File.basename(message_file, '.rb') ].join('/').gsub(/\/{2,}/, '/') @@ -167,7 +170,7 @@ def create_files(message_file, out_dir, create_file=true) end def create_service(message_file, out_dir, underscored_name, module_name, service_name, rpcs, required_file) - service_filename = "#{out_dir}/#{Util.module_to_path(module_name)}/#{underscored_name}.rb" + service_filename = "#{out_dir}/#{module_name.underscore}/#{underscored_name}.rb" service_contents = template_erb('rpc_service_implementation').result(binding) create_file_with_backup(service_filename, service_contents) if @create_file @file_contents[service_filename] = service_contents diff --git a/lib/protobuf/message/field.rb b/lib/protobuf/field.rb similarity index 56% rename from lib/protobuf/message/field.rb rename to lib/protobuf/field.rb index dbbf04c0..d3033d31 100644 --- a/lib/protobuf/message/field.rb +++ b/lib/protobuf/field.rb @@ -1,5 +1,25 @@ -require 'protobuf/common/wire_type' -require 'protobuf/descriptor/field_descriptor' +require 'protobuf/field/base_field' +require 'protobuf/field/bytes_field' +require 'protobuf/field/float_field' +require 'protobuf/field/message_field' +require 'protobuf/field/varint_field' +require 'protobuf/field/string_field' +require 'protobuf/field/double_field' +require 'protobuf/field/enum_field' +require 'protobuf/field/integer_field' +require 'protobuf/field/signed_integer_field' +require 'protobuf/field/uint32_field' +require 'protobuf/field/uint64_field' +require 'protobuf/field/int32_field' +require 'protobuf/field/int64_field' +require 'protobuf/field/sint32_field' +require 'protobuf/field/sint64_field' +require 'protobuf/field/bool_field' +require 'protobuf/field/sfixed32_field' +require 'protobuf/field/sfixed64_field' +require 'protobuf/field/fixed32_field' +require 'protobuf/field/fixed64_field' +require 'protobuf/field/field_proxy' module Protobuf module Field diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index ece9dc3b..584c143c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,26 +1,29 @@ -require 'protobuf/field/field_array' require 'protobuf/common/wire_type' require 'protobuf/descriptor/field_descriptor' +require 'protobuf/field/field_array' module Protobuf module Field class BaseField - - attr_reader :message_class, :rule, :type, :name, :tag, :default - attr_reader :default_value + ## + # Attributes + # + attr_reader :message_class, :rule, :type, :name, :tag, :default, :default_value - def self.descriptor - @descriptor ||= ::Protobuf::Descriptor::FieldDescriptor.new - end - + ## + # Class Methods + # def self.default nil end - def descriptor - @descriptor ||= ::Protobuf::Descriptor::FieldDescriptor.new(self) + def self.descriptor + @descriptor ||= ::Protobuf::Descriptor::FieldDescriptor.new end + ## + # Constructor + # def initialize(message_class, rule, type, name, tag, options) @message_class, @rule, @type, @name, @tag = \ message_class, rule, type, name, tag @@ -49,6 +52,17 @@ def initialize(message_class, rule, type, name, tag, options) define_accessor end + ## + # Public Instance Methods + # + def acceptable?(value) + true + end + + def descriptor + @descriptor ||= ::Protobuf::Descriptor::FieldDescriptor.new(self) + end + def ready? true end @@ -136,10 +150,6 @@ def min self.class.min end - # Is a +value+ acceptable for this field? - def acceptable?(value) - true - end def to_s "#{@rule} #{@type} #{@name} = #{@tag} #{@default ? "[default=#{@default.inspect}]" : ''}" @@ -147,6 +157,9 @@ def to_s private + ## + # Private Instance Methods + # def define_accessor define_getter if repeated? @@ -156,6 +169,15 @@ def define_accessor end end + def define_array_setter + field = self + @message_class.class_eval do + define_method("#{field.name}=") do |val| + @values[field.name].replace(val) + end + end + end + def define_getter field = self @message_class.class_eval do @@ -178,15 +200,6 @@ def define_setter end end - def define_array_setter - field = self - @message_class.class_eval do - define_method("#{field.name}=") do |val| - @values[field.name].replace(val) - end - end - end - def typed_default_value if @default.nil? self.class.default diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 701f6c70..2de0df0d 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -1,11 +1,16 @@ module Protobuf module Field class FieldArray < Array - + ## + # Constructor + # def initialize(field) @field = field end + ## + # Public Instance Methods + # def []=(nth, val) super(nth, normalize(val)) end @@ -31,12 +36,15 @@ def replace(val) def to_s "[#{@field.name}]" end - + private + ## + # Private Instance Methods + # def normalize(val) raise TypeError unless @field.acceptable?(val) - if @field.is_a?(MessageField) && val.is_a?(Hash) + if @field.is_a?(::Protobuf::Field::MessageField) && val.is_a?(Hash) @field.type.new(val) else val diff --git a/lib/protobuf/field/field_proxy.rb b/lib/protobuf/field/field_proxy.rb index 4228a3f6..616ad209 100644 --- a/lib/protobuf/field/field_proxy.rb +++ b/lib/protobuf/field/field_proxy.rb @@ -27,7 +27,7 @@ def setup private def typename_to_class(message_class, type) - names = type.to_s.split('::').map {|s| Util.camelize(s) } + names = type.to_s.split('::').map { |s| s.camelize } outer = message_class.to_s.split('::') args = (Object.method(:const_defined?).arity == 1) ? [] : [false] while diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 25609759..6ce64d87 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -3,10 +3,9 @@ module Protobuf module Field class MessageField < BaseField - def wire_type - WireType::LENGTH_DELIMITED - end - + ## + # Public Instance Methods + # def acceptable?(val) raise TypeError unless val.instance_of?(type) || val.instance_of?(Hash) true @@ -17,13 +16,17 @@ def decode(bytes) message.parse_from_string(bytes) message end - + def encode(value) bytes = value.serialize_to_string result = VarintField.encode(bytes.size) result << bytes end + def wire_type + ::WireType::LENGTH_DELIMITED + end + private def define_setter diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 3233af44..97b4bb3e 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -1,8 +1,8 @@ require 'set' +require 'protobuf/field' require 'protobuf/descriptor/descriptor' require 'protobuf/message/decoder' require 'protobuf/message/encoder' -require 'protobuf/message/field' require 'protobuf/message/protoable' module Protobuf diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index e5ecfe85..f5821820 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -121,8 +121,8 @@ def parse_response_from_service(response) # Parses and returns the service and method name from the request wrapper proto def parse_service_info - @klass = ::Protobuf::Util.constantize(@request.service_name) - @method = ::Protobuf::Util.underscore(@request.method_name).to_sym + @klass = @request.service_name.constantize + @method = @request.method_name.underscore.to_sym unless @klass.instance_methods.include?(@method) raise MethodNotFound, "Service method #{@request.method_name} is not defined by the service" diff --git a/spec/unit/common/util_spec.rb b/spec/unit/common/util_spec.rb deleted file mode 100644 index 820dbca7..00000000 --- a/spec/unit/common/util_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe Protobuf::Util do - - describe '.underscore' do - it 'underscores constant name' do - Protobuf::Util.underscore("HelloMoto").should eq "hello_moto" - end - - context 'when constant name has uppercased word' do - it 'keeps the uppercased word together' do - Protobuf::Util.underscore("UPPERCase").should eq "upper_case" - Protobuf::Util.underscore("MDXService").should eq "mdx_service" - end - end - end -end \ No newline at end of file diff --git a/spec/unit/rpc/servers/evented_server_spec.rb b/spec/unit/rpc/servers/evented_server_spec.rb index 58897a3e..ddb3aa36 100644 --- a/spec/unit/rpc/servers/evented_server_spec.rb +++ b/spec/unit/rpc/servers/evented_server_spec.rb @@ -6,12 +6,11 @@ it "provides a Runner class" do runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") - expect { Protobuf::Util.constantize(runner_class) }.to_not raise_error + expect { runner_class.constantize }.to_not raise_error end it "Runner provides a stop method" do - runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") - runner_class = Protobuf::Util.constantize(runner_class) + runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner").constantize runner_class.respond_to?(:stop).should be_true end diff --git a/spec/unit/rpc/servers/socket_server_spec.rb b/spec/unit/rpc/servers/socket_server_spec.rb index ea4d44a7..cb51459d 100644 --- a/spec/unit/rpc/servers/socket_server_spec.rb +++ b/spec/unit/rpc/servers/socket_server_spec.rb @@ -16,8 +16,7 @@ end it "Runner provides a stop method" do - runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") - runner_class = Protobuf::Util.constantize(runner_class) + runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner").constantize runner_class.respond_to?(:stop).should be_true end @@ -27,7 +26,7 @@ it "provides a Runner class" do runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") - expect { Protobuf::Util.constantize(runner_class) }.to_not raise_error + expect { runner_class.constantize }.to_not raise_error end it "signals the Server is running" do From 1fc0a649b8f561d3cf89715c3fb740f482cd4f26 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 24 Sep 2012 00:59:18 -0400 Subject: [PATCH 0086/1191] move message to the right file and extend protoable instead of including in eigen --- lib/protobuf/compiler/nodes.rb | 3 - lib/protobuf/field.rb | 1 + lib/protobuf/field/extension_fields.rb | 24 ++ lib/protobuf/field/field_proxy.rb | 6 + lib/protobuf/message.rb | 460 ++++++++++++++++++++++++ lib/protobuf/message/message.rb | 475 +------------------------ 6 files changed, 492 insertions(+), 477 deletions(-) create mode 100644 lib/protobuf/field/extension_fields.rb create mode 100644 lib/protobuf/message.rb diff --git a/lib/protobuf/compiler/nodes.rb b/lib/protobuf/compiler/nodes.rb index 1cf974be..514c4fe5 100644 --- a/lib/protobuf/compiler/nodes.rb +++ b/lib/protobuf/compiler/nodes.rb @@ -305,9 +305,6 @@ def initialize(low, high=nil) @low, @high = low, high end - #def accept_message_visitor(visitor) - #end - def to_s if @high.nil? @low.to_s diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index d3033d31..df81b6c5 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -20,6 +20,7 @@ require 'protobuf/field/fixed32_field' require 'protobuf/field/fixed64_field' require 'protobuf/field/field_proxy' +require 'protobuf/field/extension_fields' module Protobuf module Field diff --git a/lib/protobuf/field/extension_fields.rb b/lib/protobuf/field/extension_fields.rb new file mode 100644 index 00000000..43bd8ad1 --- /dev/null +++ b/lib/protobuf/field/extension_fields.rb @@ -0,0 +1,24 @@ +module Protobuf + module Field + class ExtensionFields < Hash + ## + # Constructor + # + def initialize(key_range=0..-1) + @key_range = key_range + end + + ## + # Public Instance Methods + # + def []=(key, value) + raise RangeError, "#{key} is not in #{@key_range}" unless @key_range.include?(key) + super + end + + def include_tag?(tag) + @key_range.include?(tag) + end + end + end +end diff --git a/lib/protobuf/field/field_proxy.rb b/lib/protobuf/field/field_proxy.rb index 616ad209..3f76a653 100644 --- a/lib/protobuf/field/field_proxy.rb +++ b/lib/protobuf/field/field_proxy.rb @@ -2,11 +2,17 @@ module Protobuf module Field class FieldProxy + ## + # Constructor + # def initialize(message_class, rule, type, name, tag, options) @message_class, @rule, @type, @name, @tag, @options = message_class, rule, type, name, tag, options end + ## + # Public Instance Methods + # def ready? false end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb new file mode 100644 index 00000000..198cd1d6 --- /dev/null +++ b/lib/protobuf/message.rb @@ -0,0 +1,460 @@ +require 'set' +require 'protobuf/field' +require 'protobuf/descriptor/descriptor' +require 'protobuf/message/decoder' +require 'protobuf/message/encoder' +require 'protobuf/message/protoable' + +module Protobuf + class Message + extend ::Protobuf::Protoable + + def self.inherited(klass) + @_children ||= Set.new + @_children << klass + end + + def self.pre_cache_class_definitions + @_children ||= Set.new + @_children.each do |child_class| + child_class.new + end + end + + class << self + + def all_fields + @all_fields ||= begin + fields_hash = fields.merge(extension_fields) + ordered_keys = fields_hash.keys.sort + ordered_keys.map { |key| fields_hash[key] } + end + end + + # Reserve field numbers for extensions. Don't use this method directly. + def extensions(range) + @extension_fields = ::Protobuf::Field::ExtensionFields.new(range) + end + + # Define a required field. Don't use this method directly. + def required(type, name, tag, options={}) + define_field(:required, type, name, tag, options) + end + + # Define a optional field. Don't use this method directly. + def optional(type, name, tag, options={}) + define_field(:optional, type, name, tag, options) + end + + # Define a repeated field. Don't use this method directly. + def repeated(type, name, tag, options={}) + define_field(:repeated, type, name, tag, options) + end + + def descriptor + @descriptor ||= Descriptor::Descriptor.new(self) + end + + # Define a field. Don't use this method directly. + def define_field(rule, type, fname, tag, options) + field_hash = options[:extension] ? extension_fields : fields + field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name + + if field_hash.keys.include?(tag) + raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! + end + + field_definition = Field.build(self, rule, type, fname, tag, options) + field_name_hash[fname.to_sym] = field_definition + field_hash[tag] = field_definition + end + + def extension_tag?(tag) + extension_fields.include_tag?(tag) + end + + # An extension field object. + def extension_fields + @extension_fields ||= ::Protobuf::Field::ExtensionFields.new + end + + def extension_fields_by_name + @extension_fields_by_name ||= {} + end + + # A collection of field object. + def fields + @fields ||= {} + end + + def fields_by_name + @field_by_name ||= {} + end + + def repeated_fields + @repeated_fields ||= [] + end + + def repeated_extension_fields + @repeated_extension_fields ||= [] + end + + # Find a field object by +name+. + def get_field_by_name(name) + # Check if the name has been used before, if not then set it to the sym value + fields_by_name[name] ||= fields_by_name[name.to_sym] + end + + # Find a field object by +tag+ number. + def get_field_by_tag(tag) + fields[tag] + end + + def field_cache + @field_cache ||= {} + end + + # Find a field object by +tag_or_name+. + def get_field(tag_or_name) + field_cache[tag_or_name] ||= case tag_or_name + when Integer then get_field_by_tag(tag_or_name) + when String, Symbol then get_field_by_name(tag_or_name) + else raise TypeError, tag_or_name.class + end + end + + #TODO merge to get_field_by_name + def get_ext_field_by_name(name) + # Check if the name has been used before, if not then set it to the sym value + extension_fields_by_name[name] ||= extension_fields_by_name[name.to_sym] + end + + #TODO merge to get_field_by_tag + def get_ext_field_by_tag(tag) + extension_fields[tag] + end + + #TODO merge to get_field + def get_ext_field(tag_or_name) + case tag_or_name + when Integer then get_ext_field_by_tag(tag_or_name) + when String, Symbol then get_ext_field_by_name(tag_or_name) + else raise TypeError, tag_or_name.class + end + end + + def initialize_unready_fields + unless @unready_initialized + initialize_type_fields + initialize_type_extension_fields + @unready_initialized = true + end + end + + def initialize_type_fields + fields.each do |tag, field| + unless field.ready? + field = field.setup + fields[tag] = field + fields_by_name[field.name.to_sym] = field + fields_by_name[field.name] = field + end + end + end + + def initialize_type_extension_fields + extension_fields.each do |tag, field| + unless field.ready? + field = field.setup + extension_fields[tag] = field + extension_fields_by_name[field.name.to_sym] = field + extension_fields_by_name[field.name] = field + end + end + end + + def setup_repeated_field_arrays + unless @repeated_fields_setup + all_fields.each do |field| + next unless field.repeated? + + if field.extension? + repeated_extension_fields << field + else + repeated_fields << field + end + end + + @repeated_fields_setup = true + end + end + end + + ## + # Constructor + # + def initialize(values={}) + @values = {} + + self.class.initialize_unready_fields + self.class.setup_repeated_field_arrays + + self.class.repeated_fields.each do |field| + @values[field.name] = Field::FieldArray.new(field) + end + + self.class.repeated_extension_fields.each do |field| + @values[field.name] = Field::FieldArray.new(field) + end + + values.each { |tag, val| self[tag] = val} + end + + def initialized? + fields.all? {|tag, field| field.initialized?(self) } && \ + extension_fields.all? {|tag, field| field.initialized?(self) } + end + + def has_field?(tag_or_name) + field = get_field(tag_or_name) || get_ext_field(tag_or_name) + raise ArgumentError, "unknown field: #{tag_or_name.inspect}" unless field + @values.has_key?(field.name) + end + + def ==(obj) + return false unless obj.is_a?(self.class) + each_field do |field, value| + return false unless value == obj.__send__(field.name) + end + true + end + + def clear! + @values.delete_if do |_, value| + if value.is_a?(Field::FieldArray) + value.clear + false + else + true + end + end + self + end + + def dup + copy_to(super, :dup) + end + + def clone + copy_to(super, :clone) + end + + def copy_to(object, method) + duplicate = proc {|obj| + case obj + when Message, String then obj.__send__(method) + else obj + end + } + + object.__send__(:initialize) + @values.each do |name, value| + if value.is_a?(Field::FieldArray) + object.__send__(name).replace(value.map {|v| duplicate.call(v)}) + else + object.__send__("#{name}=", duplicate.call(value)) + end + end + object + end + private :copy_to + + def inspect(indent=0) + result = [] + i = ' ' * indent + field_value_to_string = lambda { |field, value| + result << \ + if field.optional? && ! has_field?(field.name) + '' + else + case field + when Field::MessageField then + if value.nil? + "#{i}#{field.name} {}\n" + else + "#{i}#{field.name} {\n#{value.inspect(indent + 1)}#{i}}\n" + end + when Field::EnumField then + if value.is_a?(EnumValue) + "#{i}#{field.name}: #{value.name}\n" + else + "#{i}#{field.name}: #{field.type.name_by_value(value)}\n" + end + else + "#{i}#{field.name}: #{value.inspect}\n" + end + end + } + each_field do |field, value| + if field.repeated? + value.each do |v| + field_value_to_string.call(field, v) + end + else + field_value_to_string.call(field, value) + end + end + result.join + end + + def parse_from_string(string) + parse_from(StringIO.new(string)) + end + + def parse_from_file(filename) + if filename.is_a?(File) + parse_from(filename) + else + File.open(filename, 'rb') do |f| + parse_from(f) + end + end + end + + def parse_from(stream) + Decoder.decode(stream, self) + end + + def serialize_to_string(string='') + io = StringIO.new(string) + serialize_to(io) + result = io.string + result.force_encoding('ASCII-8BIT') if result.respond_to?(:force_encoding) + result + end + alias to_s serialize_to_string + + def serialize_to_file(filename) + if filename.is_a?(File) + serialize_to(filename) + else + File.open(filename, 'wb') do |f| + serialize_to(f) + end + end + end + + def serialize_to(stream) + Encoder.encode(stream, self) + end + + def set_field(tag, bytes) + field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) + field.set(self, bytes) if field + end + + def [](tag_or_name) + if field = get_field(tag_or_name) || get_ext_field(tag_or_name) + __send__(field.name) + else + raise NoMethodError, "No such field: #{tag_or_name.inspect}" + end + end + + def []=(tag_or_name, value) + if field = get_field(tag_or_name) || get_ext_field(tag_or_name) + __send__("#{field.name}=", value) + else + raise NoMethodError, "No such field: #{tag_or_name.inspect}" + end + end + + # Returns a hash; which key is a tag number, and value is a field object. + def all_fields + @_all_fields ||= self.class.all_fields + end + + def fields + @_fields ||= self.class.fields + end + + # Returns field object or +nil+. + def get_field_by_name(name) + self.class.get_field_by_name(name) + end + + # Returns field object or +nil+. + def get_field_by_tag(tag) + self.class.get_field_by_tag(tag) + end + + # Returns field object or +nil+. + def get_field(tag_or_name) + self.class.get_field(tag_or_name) + end + + # Returns extension fields. See Message#fields method. + def extension_fields + self.class.extension_fields + end + + def get_ext_field_by_name(name) # :nodoc: + self.class.get_ext_field_by_name(name) + end + + def get_ext_field_by_tag(tag) # :nodoc: + self.class.get_ext_field_by_tag(tag) + end + + def get_ext_field(tag_or_name) # :nodoc: + self.class.get_ext_field(tag_or_name) + end + + # Iterate over a field collection. + # message.each_field do |field_object, value| + # # do something + # end + def each_field + all_fields.each do |field| + value = __send__(field.name) + yield(field, value) + end + end + + def to_hash + result = {} + build_value = lambda { |field, value| + if !field.optional? || (field.optional? && has_field?(field.name)) + case field + when Field::MessageField then + value.to_hash + when Field::EnumField then + if value.is_a?(EnumValue) + value.to_i + elsif value.is_a?(Symbol) + field.type[value].to_i + else + value + end + else + value + end + end + } + each_field do |field, value| + if field.repeated? + result[field.name] = value.map do |v| + build_value.call(field, v) + end + else + result[field.name] = build_value.call(field, value) + end + end + result + end + + def to_json + to_hash.to_json + end + end +end diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 97b4bb3e..fafcd564 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -1,474 +1 @@ -require 'set' -require 'protobuf/field' -require 'protobuf/descriptor/descriptor' -require 'protobuf/message/decoder' -require 'protobuf/message/encoder' -require 'protobuf/message/protoable' - -module Protobuf - OPTIONS = {} - - class Message - - class ExtensionFields < Hash - def initialize(key_range=0..-1) - @key_range = key_range - end - - def []=(key, value) - raise RangeError, "#{key} is not in #{@key_range}" unless @key_range.include?(key) - super - end - - def include_tag?(tag) - @key_range.include?(tag) - end - end - - def self.inherited(klass) - @_children ||= Set.new - @_children << klass - end - - def self.pre_cache_class_definitions - @_children ||= Set.new - @_children.each do |child_class| - child_class.new - end - end - - class << self - include Protoable - - def all_fields - @all_fields ||= begin - fields_hash = fields.merge(extension_fields) - ordered_keys = fields_hash.keys.sort - ordered_keys.map { |key| fields_hash[key] } - end - end - - # Reserve field numbers for extensions. Don't use this method directly. - def extensions(range) - @extension_fields = ExtensionFields.new(range) - end - - # Define a required field. Don't use this method directly. - def required(type, name, tag, options={}) - define_field(:required, type, name, tag, options) - end - - # Define a optional field. Don't use this method directly. - def optional(type, name, tag, options={}) - define_field(:optional, type, name, tag, options) - end - - # Define a repeated field. Don't use this method directly. - def repeated(type, name, tag, options={}) - define_field(:repeated, type, name, tag, options) - end - - def descriptor - @descriptor ||= Descriptor::Descriptor.new(self) - end - - # Define a field. Don't use this method directly. - def define_field(rule, type, fname, tag, options) - field_hash = options[:extension] ? extension_fields : fields - field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name - - if field_hash.keys.include?(tag) - raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! - end - - field_definition = Field.build(self, rule, type, fname, tag, options) - field_name_hash[fname.to_sym] = field_definition - field_hash[tag] = field_definition - end - - def extension_tag?(tag) - extension_fields.include_tag?(tag) - end - - # An extension field object. - def extension_fields - @extension_fields ||= ExtensionFields.new - end - - def extension_fields_by_name - @extension_fields_by_name ||= {} - end - - # A collection of field object. - def fields - @fields ||= {} - end - - def fields_by_name - @field_by_name ||= {} - end - - def repeated_fields - @repeated_fields ||= [] - end - - def repeated_extension_fields - @repeated_extension_fields ||= [] - end - - # Find a field object by +name+. - def get_field_by_name(name) - # Check if the name has been used before, if not then set it to the sym value - fields_by_name[name] ||= fields_by_name[name.to_sym] - end - - # Find a field object by +tag+ number. - def get_field_by_tag(tag) - fields[tag] - end - - def field_cache - @field_cache ||= {} - end - - # Find a field object by +tag_or_name+. - def get_field(tag_or_name) - field_cache[tag_or_name] ||= case tag_or_name - when Integer then get_field_by_tag(tag_or_name) - when String, Symbol then get_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end - end - - #TODO merge to get_field_by_name - def get_ext_field_by_name(name) - # Check if the name has been used before, if not then set it to the sym value - extension_fields_by_name[name] ||= extension_fields_by_name[name.to_sym] - end - - #TODO merge to get_field_by_tag - def get_ext_field_by_tag(tag) - extension_fields[tag] - end - - #TODO merge to get_field - def get_ext_field(tag_or_name) - case tag_or_name - when Integer then get_ext_field_by_tag(tag_or_name) - when String, Symbol then get_ext_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end - end - - def initialize_unready_fields - unless @unready_initialized - initialize_type_fields - initialize_type_extension_fields - @unready_initialized = true - end - end - - def initialize_type_fields - fields.each do |tag, field| - unless field.ready? - field = field.setup - fields[tag] = field - fields_by_name[field.name.to_sym] = field - fields_by_name[field.name] = field - end - end - end - - def initialize_type_extension_fields - extension_fields.each do |tag, field| - unless field.ready? - field = field.setup - extension_fields[tag] = field - extension_fields_by_name[field.name.to_sym] = field - extension_fields_by_name[field.name] = field - end - end - end - - def setup_repeated_field_arrays - unless @repeated_fields_setup - all_fields.each do |field| - next unless field.repeated? - - if field.extension? - repeated_extension_fields << field - else - repeated_fields << field - end - end - - @repeated_fields_setup = true - end - end - end - - def initialize(values={}) - @values = {} - - self.class.initialize_unready_fields - self.class.setup_repeated_field_arrays - - self.class.repeated_fields.each do |field| - @values[field.name] = Field::FieldArray.new(field) - end - - self.class.repeated_extension_fields.each do |field| - @values[field.name] = Field::FieldArray.new(field) - end - - values.each { |tag, val| self[tag] = val} - end - - def initialized? - fields.all? {|tag, field| field.initialized?(self) } && \ - extension_fields.all? {|tag, field| field.initialized?(self) } - end - - def has_field?(tag_or_name) - field = get_field(tag_or_name) || get_ext_field(tag_or_name) - raise ArgumentError, "unknown field: #{tag_or_name.inspect}" unless field - @values.has_key?(field.name) - end - - def ==(obj) - return false unless obj.is_a?(self.class) - each_field do |field, value| - return false unless value == obj.__send__(field.name) - end - true - end - - def clear! - @values.delete_if do |_, value| - if value.is_a?(Field::FieldArray) - value.clear - false - else - true - end - end - self - end - - def dup - copy_to(super, :dup) - end - - def clone - copy_to(super, :clone) - end - - def copy_to(object, method) - duplicate = proc {|obj| - case obj - when Message, String then obj.__send__(method) - else obj - end - } - - object.__send__(:initialize) - @values.each do |name, value| - if value.is_a?(Field::FieldArray) - object.__send__(name).replace(value.map {|v| duplicate.call(v)}) - else - object.__send__("#{name}=", duplicate.call(value)) - end - end - object - end - private :copy_to - - def inspect(indent=0) - result = [] - i = ' ' * indent - field_value_to_string = lambda { |field, value| - result << \ - if field.optional? && ! has_field?(field.name) - '' - else - case field - when Field::MessageField then - if value.nil? - "#{i}#{field.name} {}\n" - else - "#{i}#{field.name} {\n#{value.inspect(indent + 1)}#{i}}\n" - end - when Field::EnumField then - if value.is_a?(EnumValue) - "#{i}#{field.name}: #{value.name}\n" - else - "#{i}#{field.name}: #{field.type.name_by_value(value)}\n" - end - else - "#{i}#{field.name}: #{value.inspect}\n" - end - end - } - each_field do |field, value| - if field.repeated? - value.each do |v| - field_value_to_string.call(field, v) - end - else - field_value_to_string.call(field, value) - end - end - result.join - end - - def parse_from_string(string) - parse_from(StringIO.new(string)) - end - - def parse_from_file(filename) - if filename.is_a?(File) - parse_from(filename) - else - File.open(filename, 'rb') do |f| - parse_from(f) - end - end - end - - def parse_from(stream) - Decoder.decode(stream, self) - end - - def serialize_to_string(string='') - io = StringIO.new(string) - serialize_to(io) - result = io.string - result.force_encoding('ASCII-8BIT') if result.respond_to?(:force_encoding) - result - end - alias to_s serialize_to_string - - def serialize_to_file(filename) - if filename.is_a?(File) - serialize_to(filename) - else - File.open(filename, 'wb') do |f| - serialize_to(f) - end - end - end - - def serialize_to(stream) - Encoder.encode(stream, self) - end - - def set_field(tag, bytes) - field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) - field.set(self, bytes) if field - end - - def [](tag_or_name) - if field = get_field(tag_or_name) || get_ext_field(tag_or_name) - __send__(field.name) - else - raise NoMethodError, "No such field: #{tag_or_name.inspect}" - end - end - - def []=(tag_or_name, value) - if field = get_field(tag_or_name) || get_ext_field(tag_or_name) - __send__("#{field.name}=", value) - else - raise NoMethodError, "No such field: #{tag_or_name.inspect}" - end - end - - # Returns a hash; which key is a tag number, and value is a field object. - def all_fields - @_all_fields ||= self.class.all_fields - end - - def fields - @_fields ||= self.class.fields - end - - # Returns field object or +nil+. - def get_field_by_name(name) - self.class.get_field_by_name(name) - end - - # Returns field object or +nil+. - def get_field_by_tag(tag) - self.class.get_field_by_tag(tag) - end - - # Returns field object or +nil+. - def get_field(tag_or_name) - self.class.get_field(tag_or_name) - end - - # Returns extension fields. See Message#fields method. - def extension_fields - self.class.extension_fields - end - - def get_ext_field_by_name(name) # :nodoc: - self.class.get_ext_field_by_name(name) - end - - def get_ext_field_by_tag(tag) # :nodoc: - self.class.get_ext_field_by_tag(tag) - end - - def get_ext_field(tag_or_name) # :nodoc: - self.class.get_ext_field(tag_or_name) - end - - # Iterate over a field collection. - # message.each_field do |field_object, value| - # # do something - # end - def each_field - all_fields.each do |field| - value = __send__(field.name) - yield(field, value) - end - end - - def to_hash - result = {} - build_value = lambda { |field, value| - if !field.optional? || (field.optional? && has_field?(field.name)) - case field - when Field::MessageField then - value.to_hash - when Field::EnumField then - if value.is_a?(EnumValue) - value.to_i - elsif value.is_a?(Symbol) - field.type[value].to_i - else - value - end - else - value - end - end - } - each_field do |field, value| - if field.repeated? - result[field.name] = value.map do |v| - build_value.call(field, v) - end - else - result[field.name] = build_value.call(field, value) - end - end - result - end - - def to_json - to_hash.to_json - end - end -end +require 'protobuf/message' # Need to get rid of this From 6b745d773d2f55a6280b1f1936c2869753de6e9f Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 24 Sep 2012 01:06:00 -0400 Subject: [PATCH 0087/1191] remove class << self style from message --- lib/protobuf/message.rb | 262 ++++++++++++++++++++-------------------- 1 file changed, 128 insertions(+), 134 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 198cd1d6..8e86c778 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -21,172 +21,166 @@ def self.pre_cache_class_definitions end end - class << self + def self.all_fields + @all_fields ||= begin + fields_hash = fields.merge(extension_fields) + ordered_keys = fields_hash.keys.sort + ordered_keys.map { |key| fields_hash[key] } + end + end - def all_fields - @all_fields ||= begin - fields_hash = fields.merge(extension_fields) - ordered_keys = fields_hash.keys.sort - ordered_keys.map { |key| fields_hash[key] } - end - end + # Reserve field numbers for extensions. Don't use this method directly. + def self.extensions(range) + @extension_fields = ::Protobuf::Field::ExtensionFields.new(range) + end - # Reserve field numbers for extensions. Don't use this method directly. - def extensions(range) - @extension_fields = ::Protobuf::Field::ExtensionFields.new(range) - end + # Define a required field. Don't use this method directly. + def self.required(type, name, tag, options={}) + define_field(:required, type, name, tag, options) + end - # Define a required field. Don't use this method directly. - def required(type, name, tag, options={}) - define_field(:required, type, name, tag, options) - end + # Define a optional field. Don't use this method directly. + def self.optional(type, name, tag, options={}) + define_field(:optional, type, name, tag, options) + end - # Define a optional field. Don't use this method directly. - def optional(type, name, tag, options={}) - define_field(:optional, type, name, tag, options) - end + # Define a repeated field. Don't use this method directly. + def self.repeated(type, name, tag, options={}) + define_field(:repeated, type, name, tag, options) + end - # Define a repeated field. Don't use this method directly. - def repeated(type, name, tag, options={}) - define_field(:repeated, type, name, tag, options) - end + def self.descriptor + @descriptor ||= Descriptor::Descriptor.new(self) + end - def descriptor - @descriptor ||= Descriptor::Descriptor.new(self) - end + # Define a field. Don't use this method directly. + def self.define_field(rule, type, fname, tag, options) + field_hash = options[:extension] ? extension_fields : fields + field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name - # Define a field. Don't use this method directly. - def define_field(rule, type, fname, tag, options) - field_hash = options[:extension] ? extension_fields : fields - field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name + if field_hash.keys.include?(tag) + raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! + end - if field_hash.keys.include?(tag) - raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! - end + field_definition = Field.build(self, rule, type, fname, tag, options) + field_name_hash[fname.to_sym] = field_definition + field_hash[tag] = field_definition + end - field_definition = Field.build(self, rule, type, fname, tag, options) - field_name_hash[fname.to_sym] = field_definition - field_hash[tag] = field_definition - end + def self.extension_tag?(tag) + extension_fields.include_tag?(tag) + end - def extension_tag?(tag) - extension_fields.include_tag?(tag) - end - - # An extension field object. - def extension_fields - @extension_fields ||= ::Protobuf::Field::ExtensionFields.new - end + # An extension field object. + def self.extension_fields + @extension_fields ||= ::Protobuf::Field::ExtensionFields.new + end - def extension_fields_by_name - @extension_fields_by_name ||= {} - end + def self.extension_fields_by_name + @extension_fields_by_name ||= {} + end - # A collection of field object. - def fields - @fields ||= {} - end + # A collection of field object. + def self.fields + @fields ||= {} + end - def fields_by_name - @field_by_name ||= {} - end + def self.fields_by_name + @field_by_name ||= {} + end - def repeated_fields - @repeated_fields ||= [] - end + def self.repeated_fields + @repeated_fields ||= [] + end - def repeated_extension_fields - @repeated_extension_fields ||= [] - end + def self.repeated_extension_fields + @repeated_extension_fields ||= [] + end - # Find a field object by +name+. - def get_field_by_name(name) - # Check if the name has been used before, if not then set it to the sym value - fields_by_name[name] ||= fields_by_name[name.to_sym] - end + # Find a field object by +name+. + def self.get_field_by_name(name) + # Check if the name has been used before, if not then set it to the sym value + fields_by_name[name] ||= fields_by_name[name.to_sym] + end - # Find a field object by +tag+ number. - def get_field_by_tag(tag) - fields[tag] - end + # Find a field object by +tag+ number. + def self.get_field_by_tag(tag) + fields[tag] + end - def field_cache - @field_cache ||= {} - end + def self.field_cache + @field_cache ||= {} + end - # Find a field object by +tag_or_name+. - def get_field(tag_or_name) - field_cache[tag_or_name] ||= case tag_or_name - when Integer then get_field_by_tag(tag_or_name) - when String, Symbol then get_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end - end + # Find a field object by +tag_or_name+. + def self.get_field(tag_or_name) + field_cache[tag_or_name] ||= case tag_or_name + when Integer then get_field_by_tag(tag_or_name) + when String, Symbol then get_field_by_name(tag_or_name) + else raise TypeError, tag_or_name.class + end + end - #TODO merge to get_field_by_name - def get_ext_field_by_name(name) - # Check if the name has been used before, if not then set it to the sym value - extension_fields_by_name[name] ||= extension_fields_by_name[name.to_sym] - end + def self.get_ext_field_by_name(name) + # Check if the name has been used before, if not then set it to the sym value + extension_fields_by_name[name] ||= extension_fields_by_name[name.to_sym] + end - #TODO merge to get_field_by_tag - def get_ext_field_by_tag(tag) - extension_fields[tag] - end + def self.get_ext_field_by_tag(tag) + extension_fields[tag] + end - #TODO merge to get_field - def get_ext_field(tag_or_name) - case tag_or_name - when Integer then get_ext_field_by_tag(tag_or_name) - when String, Symbol then get_ext_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end + def self.get_ext_field(tag_or_name) + case tag_or_name + when Integer then get_ext_field_by_tag(tag_or_name) + when String, Symbol then get_ext_field_by_name(tag_or_name) + else raise TypeError, tag_or_name.class end + end - def initialize_unready_fields - unless @unready_initialized - initialize_type_fields - initialize_type_extension_fields - @unready_initialized = true - end + def self.initialize_unready_fields + unless @unready_initialized + initialize_type_fields + initialize_type_extension_fields + @unready_initialized = true end + end - def initialize_type_fields - fields.each do |tag, field| - unless field.ready? - field = field.setup - fields[tag] = field - fields_by_name[field.name.to_sym] = field - fields_by_name[field.name] = field - end + def self.initialize_type_fields + fields.each do |tag, field| + unless field.ready? + field = field.setup + fields[tag] = field + fields_by_name[field.name.to_sym] = field + fields_by_name[field.name] = field end end + end - def initialize_type_extension_fields - extension_fields.each do |tag, field| - unless field.ready? - field = field.setup - extension_fields[tag] = field - extension_fields_by_name[field.name.to_sym] = field - extension_fields_by_name[field.name] = field - end + def self.initialize_type_extension_fields + extension_fields.each do |tag, field| + unless field.ready? + field = field.setup + extension_fields[tag] = field + extension_fields_by_name[field.name.to_sym] = field + extension_fields_by_name[field.name] = field end end + end - def setup_repeated_field_arrays - unless @repeated_fields_setup - all_fields.each do |field| - next unless field.repeated? + def self.setup_repeated_field_arrays + unless @repeated_fields_setup + all_fields.each do |field| + next unless field.repeated? - if field.extension? - repeated_extension_fields << field - else - repeated_fields << field - end + if field.extension? + repeated_extension_fields << field + else + repeated_fields << field end - - @repeated_fields_setup = true end + + @repeated_fields_setup = true end end @@ -250,7 +244,7 @@ def clone end def copy_to(object, method) - duplicate = proc {|obj| + duplicate = proc { |obj| case obj when Message, String then obj.__send__(method) else obj @@ -420,7 +414,7 @@ def each_field yield(field, value) end end - + def to_hash result = {} build_value = lambda { |field, value| @@ -452,7 +446,7 @@ def to_hash end result end - + def to_json to_hash.to_json end From 2f7dcff3dda724a6dacbc055f4b2af5b9b8dfd12 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 25 Sep 2012 15:08:21 -0600 Subject: [PATCH 0088/1191] Add RubyGenerator.cpp to hook in to the protoc compiler --- generator/Makefile | 11 + generator/RubyGenerator.cpp | 436 ++++++++++++++++++++++++++++++++++++ generator/RubyGenerator.h | 161 +++++++++++++ generator/main.cpp | 13 ++ 4 files changed, 621 insertions(+) create mode 100644 generator/Makefile create mode 100644 generator/RubyGenerator.cpp create mode 100644 generator/RubyGenerator.h create mode 100644 generator/main.cpp diff --git a/generator/Makefile b/generator/Makefile new file mode 100644 index 00000000..12776e75 --- /dev/null +++ b/generator/Makefile @@ -0,0 +1,11 @@ +all: \ + RubyGenerator.h \ + RubyGenerator.cpp \ + main.cpp + g++ -Wall -I/code/src/utilities/protobuf-2.4.1/src -lprotoc -lprotobuf -lpthread -o protoc-ruby RubyGenerator.cpp main.cpp + +test: + rm -rf test/out/* + ./protoc-ruby --proto_path=defs --ruby_out=out defs/atlas/util.proto defs/atlas/newman/*.proto + +.PHONY: all test diff --git a/generator/RubyGenerator.cpp b/generator/RubyGenerator.cpp new file mode 100644 index 00000000..a7bf4ca9 --- /dev/null +++ b/generator/RubyGenerator.cpp @@ -0,0 +1,436 @@ +#include "RubyGenerator.h" + +namespace google { +namespace protobuf { +namespace compiler { +namespace ruby { + +RubyGenerator::RubyGenerator() {} // Constructor +RubyGenerator::~RubyGenerator() {} // Destructor + +// Generate one or more ruby source files for the given proto file. +bool RubyGenerator::Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* context, + string* error) const { + file_ = file; + context_ = context; + + filename = CreateRubyFileName(file_->name()); + ns_vector.clear(); + SplitStringUsing(file_->package(), ".", &ns_vector); + + // Get a ZeroCopyOutputStream object of the data. + scoped_ptr output(context_->Open(filename)); + + // Check the data against Google's proto checking algorithm. + GOOGLE_CHECK(output.get()); + + // Get a printer. + io::Printer printer(output.get(), '$'); + printer_ = &printer; + + PrintGeneratedFileComment(); + PrintGenericRequires(); + PrintImportRequires(); + + PrintEnclosingNamespaceModules(); + + PrintEnumsForFileDescriptor(file_, false); + PrintNewLine(); + PrintMessagesForFileDescriptor(file_, false); + PrintNewLine(); + + PrintEnumsForFileDescriptor(file_, true); + PrintNewLine(); + PrintMessagesForFileDescriptor(file_, true); + PrintNewLine(); + + PrintServices(); + + PrintEnclosingNamespaceModuleEnds(); + + if (printer.failed()) { + *error = "An unknown error occured writing file " + filename; + return false; + } + else { + return true; + } +} // end Generate() + +// +///////////////////////////////////////////////// [ namespaces ] ////////////// +// + +void RubyGenerator::PrintEnclosingNamespaceModules() const { + PrintNewLine(); + vector::iterator iter; + map data; + for (iter = ns_vector.begin(); iter < ns_vector.end(); iter++) { + data["ns"] = Constantize(*iter, false); + + printer_->Print(data, "module $ns$"); + PrintNewLine(); + printer_->Indent(); + } +} + +void RubyGenerator::PrintEnclosingNamespaceModuleEnds() const { + vector::iterator iter; + for (iter = ns_vector.begin(); iter < ns_vector.end(); iter++) { + printer_->Outdent(); + printer_->Print("end"); + PrintNewLine(); + } +} + + +// +///////////////////////////////////////////////// [ messages ] //////////////// +// + +void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const { + if (descriptor->message_type_count() > 0) { + if (print_fields) { + PrintComment("Message Fields", true); + } + else { + PrintComment("Message Classes", true); + } + + for (int i = 0; i < descriptor->message_type_count(); i++) { + if (print_fields) { + PrintMessageFields(descriptor->message_type(i)); + } + else { + PrintMessageClass(descriptor->message_type(i)); + } + } + } +} + +void RubyGenerator::PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const { + for (int i = 0; i < descriptor->nested_type_count(); i++) { + if (print_fields) { + PrintMessageFields(descriptor->nested_type(i)); + } + else { + PrintMessageClass(descriptor->nested_type(i)); + } + } +} +// +// Print out the given descriptor message as a Ruby class. +void RubyGenerator::PrintMessageClass(const Descriptor* descriptor) const { + map data; + data["class_name"] = descriptor->name(); + + printer_->Print(data, "class $class_name$ < ::Protobuf::Message; end"); + PrintNewLine(); + + PrintEnumsForDescriptor(descriptor, false); + PrintMessagesForDescriptor(descriptor, false); +} + +void RubyGenerator::PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const { + if (descriptor->extension_range_count() > 0) { + for (int i = 0; i < descriptor->extension_range_count(); i++) { + const Descriptor::ExtensionRange* range = descriptor->extension_range(i); + map data; + data["message_class"] = Constantize(descriptor->full_name()); + data["start"] = SimpleItoa(range->start); + data["end"] = SimpleItoa(range->end); + printer_->Print(data, "$message_class$.extensions $start$...$end$"); + PrintNewLine(); + } + } +} + +// Print out the given descriptor message as a Ruby class. +void RubyGenerator::PrintMessageFields(const Descriptor* descriptor) const { + PrintExtensionRangesForDescriptor(descriptor); + + if (descriptor->field_count() > 0) { + for (int i = 0; i < descriptor->field_count(); i++) { + PrintMessageField(descriptor->field(i)); + } + + // Print Extension Fields + if (descriptor->extension_count() > 0) { + for (int i = 0; i < descriptor->extension_count(); i++) { + PrintMessageField(descriptor->extension(i)); + } + } + PrintNewLine(); + } + + PrintEnumsForDescriptor(descriptor, true); + PrintMessagesForDescriptor(descriptor, true); + PrintNewLine(); +} + +// Print the given FieldDescriptor to the Message DSL methods. +void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { + map data; + data["message_class"] = Constantize(descriptor->containing_type()->full_name()); + data["field_name"] = descriptor->lowercase_name(); + data["tag_number"] = SimpleItoa(descriptor->number()); + data["data_type"] = ""; + data["default_opt"] = ""; + data["packed_opt"] = ""; + data["deprecated_opt"] = ""; + data["extension_opt"] = ""; + + if (descriptor->is_required()) { + data["field_label"] = "required"; + } + else if (descriptor->is_optional()) { + data["field_label"] = "optional"; + } + else if (descriptor->is_repeated()) { + data["field_label"] = "repeated"; + } + + switch (descriptor->type()) { + // Primitives + case FieldDescriptor::TYPE_DOUBLE: data["data_type"] = "::Protobuf::Field::DoubleField"; break; + case FieldDescriptor::TYPE_FLOAT: data["data_type"] = "::Protobuf::Field::FloatField"; break; + case FieldDescriptor::TYPE_INT64: data["data_type"] = "::Protobuf::Field::Int64Field"; break; + case FieldDescriptor::TYPE_UINT64: data["data_type"] = "::Protobuf::Field::Uint64Field"; break; + case FieldDescriptor::TYPE_INT32: data["data_type"] = "::Protobuf::Field::Int32Field"; break; + case FieldDescriptor::TYPE_FIXED64: data["data_type"] = "::Protobuf::Field::Fixed64Field"; break; + case FieldDescriptor::TYPE_FIXED32: data["data_type"] = "::Protobuf::Field::Fixed32Field"; break; + case FieldDescriptor::TYPE_BOOL: data["data_type"] = "::Protobuf::Field::BoolField"; break; + case FieldDescriptor::TYPE_STRING: data["data_type"] = "::Protobuf::Field::StringField"; break; + case FieldDescriptor::TYPE_BYTES: data["data_type"] = "::Protobuf::Field::BytesField"; break; + case FieldDescriptor::TYPE_UINT32: data["data_type"] = "::Protobuf::Field::Uint32Field"; break; + case FieldDescriptor::TYPE_SFIXED32: data["data_type"] = "::Protobuf::Field::Sfixed32Field"; break; + case FieldDescriptor::TYPE_SFIXED64: data["data_type"] = "::Protobuf::Field::Sfixed64Field"; break; + case FieldDescriptor::TYPE_SINT32: data["data_type"] = "::Protobuf::Field::Sint32Field"; break; + case FieldDescriptor::TYPE_SINT64: data["data_type"] = "::Protobuf::Field::Sint64Field"; break; + + // Enums + case FieldDescriptor::TYPE_ENUM: + data["data_type"] = Constantize(descriptor->enum_type()->full_name()); + break; + + // Messages + case FieldDescriptor::TYPE_GROUP: + case FieldDescriptor::TYPE_MESSAGE: + default: + data["data_type"] = Constantize(descriptor->message_type()->full_name()); + break; + } + + if (descriptor->has_default_value()) { + string value; + switch(descriptor->cpp_type()) { + case FieldDescriptor::CPPTYPE_INT32: value = SimpleItoa(descriptor->default_value_int32()); break; + case FieldDescriptor::CPPTYPE_INT64: value = SimpleItoa(descriptor->default_value_int64()); break; + case FieldDescriptor::CPPTYPE_UINT32: value = SimpleItoa(descriptor->default_value_uint32()); break; + case FieldDescriptor::CPPTYPE_UINT64: value = SimpleItoa(descriptor->default_value_uint64()); break; + case FieldDescriptor::CPPTYPE_DOUBLE: value = SimpleDtoa(descriptor->default_value_double()); break; + case FieldDescriptor::CPPTYPE_FLOAT: value = SimpleFtoa(descriptor->default_value_float()); break; + case FieldDescriptor::CPPTYPE_BOOL: value = descriptor->default_value_bool() ? "true" : "false"; break; + case FieldDescriptor::CPPTYPE_ENUM: value = Constantize(descriptor->default_value_enum()->full_name()); break; + case FieldDescriptor::CPPTYPE_STRING: value = "\"" + descriptor->default_value_string() + "\""; break; + default: break; + } + data["default_opt"] = strings::Substitute(", :default => $0", value); + } + + if (descriptor->is_packable() && descriptor->options().has_packed()) { + string packed_bool = descriptor->options().packed() ? "true" : "false"; + data["packed_opt"] = strings::Substitute(", :packed => $0", packed_bool); + } + + if (descriptor->options().has_deprecated()) { + string deprecated_bool = descriptor->options().deprecated() ? "true" : "false"; + data["deprecated_opt"] = strings::Substitute(", :deprecated => $0", deprecated_bool); + } + + if (descriptor->is_extension()) { + data["extension_opt"] = ", :extension => true"; + } + + printer_->Print(data, + "$message_class$.$field_label$" + "$data_type$, " + ":$field_name$, " + "$tag_number$" + "$default_opt$" + "$packed_opt$" + "$deprecated_opt$" + "$extension_opt$" + "\n"); +} + + +// +///////////////////////////////////////////////// [ enums ] /////////////////// +// + +void RubyGenerator::PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const { + for (int i = 0; i < descriptor->enum_type_count(); i++) { + if (print_values) { + PrintEnumValues(descriptor->enum_type(i)); + } + else { + PrintEnumClass(descriptor->enum_type(i)); + } + } +} + +void RubyGenerator::PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const { + if (descriptor->enum_type_count() > 0) { + if (print_values) { + PrintComment("Enum Values", true); + } + else { + PrintComment("Enum Classes", true); + } + + for (int i = 0; i < descriptor->enum_type_count(); i++) { + if (print_values) { + PrintEnumValues(descriptor->enum_type(i)); + } + else { + PrintEnumClass(descriptor->enum_type(i)); + } + } + } +} + +// Print the given enum descriptor as a Ruby class. +void RubyGenerator::PrintEnumClass(const EnumDescriptor* descriptor) const { + map data; + data["class_name"] = descriptor->name(); + printer_->Print(data, "class $class_name$ < ::Protobuf::Enum; end"); + PrintNewLine(); +} + +// Print the given enum descriptor as a Ruby class. +void RubyGenerator::PrintEnumValues(const EnumDescriptor* descriptor) const { + for (int i = 0; i < descriptor->value_count(); i++) { + PrintEnumValue(descriptor->value(i)); + } + PrintNewLine(); +} + +// Print the given enum value to the Enum class DSL methods. +void RubyGenerator::PrintEnumValue(const EnumValueDescriptor* descriptor) const { + map data; + data["enum_class"] = Constantize(descriptor->type()->full_name()); + data["name"] = descriptor->name(); + data["number"] = ConvertIntToString(descriptor->number()); + printer_->Print(data, "$enum_class$.define :$name$, $number$\n"); +} + +// +///////////////////////////////////////////////// [ services ] //////////////// +// + +void RubyGenerator::PrintServices() const { + if (file_->service_count() > 0) { + PrintComment("Services", true); + for (int i = 0; i < file_->service_count(); i++) { + PrintService(file_->service(i)); + } + } +} + +// Print the given service as a Ruby class. +void RubyGenerator::PrintService(const ServiceDescriptor* descriptor) const { + map data; + data["class_name"] = descriptor->name(); + + printer_->Print(data, "class $class_name$ < ::Protobuf::Service"); + PrintNewLine(); + printer_->Indent(); + + for (int i = 0; i < descriptor->method_count(); i++) { + PrintServiceMethod(descriptor->method(i)); + } + + printer_->Outdent(); + printer_->Print("end"); + PrintNewLine(); +} + +// Print the rpc DSL declaration to the Ruby service class. +void RubyGenerator::PrintServiceMethod(const MethodDescriptor* descriptor) const { + map data; + data["name"] = Underscore(descriptor->name()); + data["request_klass"] = Constantize(descriptor->input_type()->full_name()); + data["response_klass"] = Constantize(descriptor->output_type()->full_name()); + printer_->Print(data, "rpc :$name$, $request_klass$, $response_klass$"); + PrintNewLine(); +} + + +// +///////////////////////////////////////////////// [ general ] //////////////// +// + +// Print a header or one-line comment (as indicated by the as_header bool). +void RubyGenerator::PrintComment(string comment, bool as_header) const { + char format[] = "# $comment$\n"; + char format_multi[] = "##\n# $comment$\n#\n"; + + map data; + data["comment"] = comment; + + if (as_header) { + printer_->Print(data, format_multi); + } + else { + printer_->Print(data, format); + } +} + +// Prints a require with the given ruby library. +void RubyGenerator::PrintRequire(string lib_name) const { + map data; + data["lib"] = lib_name; + printer_->Print(data, "require '$lib$'\n"); +} + +// Print a comment indicating that the file was generated. +void RubyGenerator::PrintGeneratedFileComment() const { + PrintComment("This file is auto-generated. DO NOT EDIT!", true); +} + +// Print out message requires as they pertain to the ruby library. +void RubyGenerator::PrintGenericRequires() const { + if (file_->message_type_count() > 0) { + PrintRequire("protobuf/message"); + } + if (file_->service_count() > 0) { + PrintRequire("protobuf/rpc/service"); + } +} + +void RubyGenerator::PrintImportRequires() const { + if (file_->dependency_count() > 0) { + PrintNewLine(); + PrintComment("Imports", true); + for (int i = 0; i < file_->dependency_count(); i++) { + PrintRequire(CreateRubyFileName(file_->dependency(i)->name(), true)); + } + } +} + +// Print a one-line comment. +void RubyGenerator::PrintComment(string comment) const { + PrintComment(comment, false); +} + +void RubyGenerator::PrintNewLine() const { + printer_->Print("\n"); +} + +} // namespace ruby +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/generator/RubyGenerator.h b/generator/RubyGenerator.h new file mode 100644 index 00000000..45c68d7a --- /dev/null +++ b/generator/RubyGenerator.h @@ -0,0 +1,161 @@ +#ifndef GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H +#define GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace ruby { + +class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { + public: + RubyGenerator(); + ~RubyGenerator(); + + // implemented Generate method from parent + bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* context, + string* error) const; + + + private: + mutable GeneratorContext* context_; + mutable io::Printer* printer_; + mutable const FileDescriptor* file_; + mutable string filename; + mutable vector ns_vector; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RubyGenerator); + + void PrintEnclosingNamespaceModules() const; + void PrintEnclosingNamespaceModuleEnds() const; + + void PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const; + void PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const; + void PrintMessageClass(const Descriptor* descriptor) const; + void PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const; + void PrintMessageFields(const Descriptor* descriptor) const; + void PrintMessageField(const FieldDescriptor* descriptor) const; + + void PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const; + void PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const; + void PrintEnumClass(const EnumDescriptor* descriptor) const; + void PrintEnumValues(const EnumDescriptor* descriptor) const; + void PrintEnumValue(const EnumValueDescriptor* descriptor) const; + + void PrintServices() const; + void PrintService(const ServiceDescriptor* descriptor) const; + void PrintServiceMethod(const MethodDescriptor* descriptor) const; + + void PrintGeneratedFileComment() const; + void PrintGenericRequires() const; + void PrintImportRequires() const; + void PrintComment(string comment) const; + void PrintComment(string comment, bool as_header) const; + void PrintRequire(string lib_name) const; + void PrintNewLine() const; + + // Take the proto file name, strip ".proto" + // from the end and add ".pb.rb" + static string CreateRubyFileName(const string proto_filename) { + return CreateRubyFileName(proto_filename, false); + } + + static string CreateRubyFileName(const string proto_filename, bool for_require) { + string replacement = for_require ? ".pb" : ".pb.rb"; + return StringReplace(proto_filename, ".proto", replacement, false); + } + + static string ConvertIntToString(int number) { + stringstream stream; + stream << number; + return stream.str(); + } + + static string ConvertDoubleToString(double number) { + stringstream stream; + stream << number; + return stream.str(); + } + + static string ConvertFloatToString(float number) { + stringstream stream; + stream << number; + return stream.str(); + } + + static string Constantize(string full_path) { + return Constantize(full_path, true); + } + + static string Constantize(string full_path, bool is_top_level) { + stringstream constantized; + + if (is_top_level) { + constantized << "::"; + } + + string::iterator i; + bool segment_end = true; + for (i = full_path.begin(); i < full_path.end(); i++) { + char c = *i; + if (c == 46) { // period char + constantized << ':' << ':'; + segment_end = true; + continue; + } + else if (c == 95) { // underscore char + segment_end = true; + continue; + } + else if (segment_end) { + if (c >= 97 && c <= 122) { // a-z chars + c -= 32; + } + segment_end = false; + } + constantized << c; + } + + return constantized.str(); + } + + static string Underscore(string name) { + stringstream underscored; + + string::iterator i; + for (i = name.begin(); i < name.end(); i++) { + char c = *i; + if (c >= 65 && c <= 90) { // a-z chars + if (i != name.begin()) { + underscored << '_'; + } + c += 32; + } + underscored << c; + } + + return underscored.str(); + } + +}; // class RubyGenerator + +} // namespace ruby +} // namespace compiler +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H diff --git a/generator/main.cpp b/generator/main.cpp new file mode 100644 index 00000000..c0590f8c --- /dev/null +++ b/generator/main.cpp @@ -0,0 +1,13 @@ +#include +#include "RubyGenerator.h" + +int main (int argc, char* argv[]) { + google::protobuf::compiler::CommandLineInterface cli; + + // Support generation of C++ source and headers. + google::protobuf::compiler::ruby::RubyGenerator ruby_generator; + cli.RegisterGenerator("--ruby_out", &ruby_generator, + "Generate Ruby-compatible protobuf message and service classes."); + + return cli.Run(argc, argv); +} From 0e093e6345cdb77022f6144c5aa60e04832b061f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 25 Sep 2012 15:13:49 -0600 Subject: [PATCH 0089/1191] Fix formatting issue --- generator/RubyGenerator.h | 90 +++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/generator/RubyGenerator.h b/generator/RubyGenerator.h index 45c68d7a..87b108ce 100644 --- a/generator/RubyGenerator.h +++ b/generator/RubyGenerator.h @@ -20,52 +20,52 @@ namespace compiler { namespace ruby { class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { - public: - RubyGenerator(); - ~RubyGenerator(); - - // implemented Generate method from parent - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const; - - - private: - mutable GeneratorContext* context_; - mutable io::Printer* printer_; - mutable const FileDescriptor* file_; - mutable string filename; + public: + RubyGenerator(); + ~RubyGenerator(); + + // implemented Generate method from parent + bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* context, + string* error) const; + + + private: + mutable GeneratorContext* context_; + mutable io::Printer* printer_; + mutable const FileDescriptor* file_; + mutable string filename; mutable vector ns_vector; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RubyGenerator); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RubyGenerator); void PrintEnclosingNamespaceModules() const; void PrintEnclosingNamespaceModuleEnds() const; - void PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const; - void PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const; - void PrintMessageClass(const Descriptor* descriptor) const; + void PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const; + void PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const; + void PrintMessageClass(const Descriptor* descriptor) const; void PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const; void PrintMessageFields(const Descriptor* descriptor) const; - void PrintMessageField(const FieldDescriptor* descriptor) const; + void PrintMessageField(const FieldDescriptor* descriptor) const; - void PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const; - void PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const; - void PrintEnumClass(const EnumDescriptor* descriptor) const; - void PrintEnumValues(const EnumDescriptor* descriptor) const; - void PrintEnumValue(const EnumValueDescriptor* descriptor) const; + void PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const; + void PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const; + void PrintEnumClass(const EnumDescriptor* descriptor) const; + void PrintEnumValues(const EnumDescriptor* descriptor) const; + void PrintEnumValue(const EnumValueDescriptor* descriptor) const; - void PrintServices() const; - void PrintService(const ServiceDescriptor* descriptor) const; - void PrintServiceMethod(const MethodDescriptor* descriptor) const; + void PrintServices() const; + void PrintService(const ServiceDescriptor* descriptor) const; + void PrintServiceMethod(const MethodDescriptor* descriptor) const; - void PrintGeneratedFileComment() const; - void PrintGenericRequires() const; + void PrintGeneratedFileComment() const; + void PrintGenericRequires() const; void PrintImportRequires() const; - void PrintComment(string comment) const; - void PrintComment(string comment, bool as_header) const; - void PrintRequire(string lib_name) const; + void PrintComment(string comment) const; + void PrintComment(string comment, bool as_header) const; + void PrintRequire(string lib_name) const; void PrintNewLine() const; // Take the proto file name, strip ".proto" @@ -79,22 +79,22 @@ class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { return StringReplace(proto_filename, ".proto", replacement, false); } - static string ConvertIntToString(int number) { - stringstream stream; - stream << number; - return stream.str(); - } + static string ConvertIntToString(int number) { + stringstream stream; + stream << number; + return stream.str(); + } static string ConvertDoubleToString(double number) { - stringstream stream; - stream << number; - return stream.str(); + stringstream stream; + stream << number; + return stream.str(); } static string ConvertFloatToString(float number) { - stringstream stream; - stream << number; - return stream.str(); + stringstream stream; + stream << number; + return stream.str(); } static string Constantize(string full_path) { From 47fd41220dbad3ac3dba8d958a1e7315128d24cf Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 26 Sep 2012 23:54:49 -0600 Subject: [PATCH 0090/1191] Converting rpc_server over to Thor --- Gemfile.lock | 2 + bin/rpc_server | 334 ++++++++++----------- {generator => ext}/Makefile | 0 {generator => ext}/RubyGenerator.cpp | 0 {generator => ext}/RubyGenerator.h | 0 {generator => ext}/main.cpp | 0 lib/protobuf.rb | 6 +- lib/protobuf/rpc/server.rb | 3 + lib/protobuf/rpc/servers/evented_runner.rb | 24 +- lib/protobuf/rpc/servers/socket_runner.rb | 11 +- lib/protobuf/rpc/servers/zmq_runner.rb | 9 +- lib/protobuf/version.rb | 1 + protobuf.gemspec | 1 + 13 files changed, 186 insertions(+), 205 deletions(-) rename {generator => ext}/Makefile (100%) rename {generator => ext}/RubyGenerator.cpp (100%) rename {generator => ext}/RubyGenerator.h (100%) rename {generator => ext}/main.cpp (100%) diff --git a/Gemfile.lock b/Gemfile.lock index bc511307..faff7603 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,7 @@ PATH eventually ffi-rzmq json_pure + thor GEM remote: http://rubygems.org/ @@ -40,6 +41,7 @@ GEM simplecov-html (~> 0.5.3) simplecov-html (0.5.3) slop (3.3.3) + thor (0.16.0) yard (0.8.2.1) PLATFORMS diff --git a/bin/rpc_server b/bin/rpc_server index 87ffb5ae..e9dbc2c4 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -1,191 +1,167 @@ #!/usr/bin/env ruby -require 'optparse' -require 'ostruct' -require 'logger' +require 'thor' require 'protobuf/version' +require 'protobuf/common/logger' +require 'protobuf/rpc/server' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq_runner' -# Default options -server = OpenStruct.new({ - :app => nil, - :env => ENV['RPC_SERVER_ENV'] || 'development', - :pre_cache_definitions => false, - :gc_pause_during_request => false, - :gc_pause_during_serialization => false, - :host => '127.0.0.1', - :port => 9595, - :backlog => 100, - :threshold => 100, - :log => File.expand_path('./protobuf.log'), - :level => ::Logger::INFO, - :runner => ::Protobuf::Rpc::EventedRunner, - :debug => false, - :stopped_during_startup => false -}) - -class ClientServerParse - def self.parse_client(value) - end - - def self.parse_server(value) - end -end - -parser = OptionParser.new do |opts| - opts.banner = "Usage: rpc_server [options] app_file.rb" - - opts.on("-e ENVIRONMENT", "--env=ENVIRONMENT", "Environment to run the server") do |v| - server.env = ENV['RACK_ENV'] = ENV['RAILS_ENV'] = ENV['APP_ENV'] = v - end - - opts.on("-o HOST", "--host=HOST", "Server host") do |v| - server.host = v - end - - opts.on("-p PORT", "--port=PORT", Integer, "Server port") do |v| - server.port = v - end - - opts.on("-l LOG_FILE", "--log=LOG_FILE", "Log file or device") do |v| - server.log = v - end - - opts.on("-v N", "--level=N", Integer, "Log level to use, 0-5 (see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/)") do |v| - server.level = v.to_i - end +class RpcServer < ::Thor + include ::Thor::Actions + + attr_accessor :runner, :start_aborted + + default_task :start + + desc 'start APP_FILE', 'Run the RPC server in the given mode, preloading the given APP_FILE. This is the default task.' + + option :env, :type => :string, :default => (ENV['RPC_SERVER_ENV'] || 'development'), :aliases => %w(-e), :desc => 'Environment to run the server (i.e. RAILS_ENV).' + option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-e), :desc => 'Host to bind.' + option :port, :type => :numeric, :default => 9595, :aliases => %w(-p), :desc => 'Port to bind.' + option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.' + option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' + option :log, :type => :string, :default => File.expand_path('./protobuf.log'), :aliases => %w(-l), :desc => 'Log file or device.' + 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/)' + option :client_type, :type => :boolean, :desc => 'Client Type to use (Socket or Zmq).' + option :server_type, :type => :boolean, :desc => 'Server Type to use (Socket or Zmq).' + option :client_socket, :type => :boolean, :aliases => %w(-c), :desc => 'Raw Socket Mode for client connections.' + option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Raw Socket Server Mode.' + option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for client and server connections (they must be used together).' + option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' + option :pre_cache_definitions, :type => :boolean, :default => false, :desc => 'Enable/Disable Message class pre-caching.' + option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' + option :gc_pause_serialization, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during serialization.' + + def start(app_file) + say 'start to configure', :yellow + @start_aborted = false + require 'protobuf' + + configure_traps + configure_runner_mode + configure_gc + configure_logger + + unless @start_aborted + say 'start was not aborted', :yellow + require_application!(app_file) + pre_cache_application_protos! if options.pre_cache_definitions? + configure_process_name(app_file) + start_server! + else + say 'start was aborted', :yellow + end + + rescue => e + msg = "ERROR: RPC Server failed to start: (#{e.class.name}) #{e.message}" + say msg, :red + $stderr.puts *(e.backtrace) + ::Protobuf::Logger.error { msg } + ::Protobuf::Logger.error { e.backtrace.join("\n") } + exit(1) + end + + desc 'version', 'Print ruby and protoc versions and exit.' + def version + $stdout.puts "Ruby Protobuf v#{::Protobuf::VERSION} (Google protoc v#{::Protobuf::PROTOC_VERSION})" + exit(0) + end + + no_tasks do + + # TODO need to figure out a better solution here + # dynamic const assignment is a no-go + def configure_gc + say 'configuring gc', :yellow + #::Protobuf::Rpc::GC_PAUSE_REQUEST = options.gc_pause_request? + # If we pause during request we don't need to pause in serialization + #::Protobuf::Rpc::GC_PAUSE_SERIALIZATION = (!options.gc_pause_request? && options.gc_pause_serialization?) + end + + def configure_logger + say 'configuring logger', :yellow + ::Protobuf::Logger.configure({ :file => options.log, + :level => options.debug? ? ::Logger::DEBUG : options.level }) + + # Output the server opts + ::Protobuf::Logger.debug { 'Debugging options:' } + ::Protobuf::Logger.debug { options.inspect } + end + + def configure_process_name(app_file) + say 'configuring process name', :yellow + $0 = "rpc_server #{options.host}:#{options.port} #{app_file}" + end + + # Used to ensure we set the PB_CLIENT_TYPE and PB_SERVER_TYPE to the same thing + # if one of them is set to Zmq + def configure_runner_mode + say 'configuring runner mode', :yellow + if ENV['PB_CLIENT_TYPE'] =~ /zmq/i + # make server and client types the same if we're using Zmq + # ENV['PB_SERVER_TYPE'] = ENV['PB_CLIENT_TYPE'] + @runner = ::Protobuf::Rpc::ZmqRunner + elsif ENV['PB_SERVER_TYPE'] =~ /zmq/i + # make server and client types the same if we're using Zmq + # ENV['PB_CLIENT_TYPE'] = ENV['PB_SERVER_TYPE'] + @runner = ::Protobuf::Rpc::ZmqRunner + elsif ENV['PB_SERVER_TYPE'] =~ /socket/i + @runner = ::Protobuf::Rpc::SocketRunner + else + @runner = ::Protobuf::Rpc::EventedRunner + end + end + + def configure_traps + say 'configuring traps', :yellow + trap_block = proc { + ::Protobuf::Logger.info { 'RPC Server shutting down...' } + @start_aborted = true + @runner.stop + ::Protobuf::Logger.info { 'Shutdown complete' } + } + + say 'registering INT', :blue + trap(:INT, &trap_block) + say 'registering QUIT', :blue + trap(:QUIT, &trap_block) + say 'registering TERM', :blue + trap(:TERM, &trap_block) + end + + def pre_cache_application_protos! + say 'pre-caching app protos', :yellow + ::Protobuf::Message.pre_cache_class_definitions + end + + def require_application!(app_file) + say 'requiring app file', :yellow + require app_file + rescue LoadError => e + say "Failed to load application file #{app_file}: #{e.message}", :red + puts *(e.backtrace) if options.debug? + exit(1) + end + + def runner_name + case @runner + when ::Protobuf::Rpc::ZmqRunner then "Zmq" + when ::Protobuf::Rpc::SocketRunner then "Socket" + else "Evented" + end + end + + def start_server! + say 'starting server', :yellow + @runner.run(options.dup) do + Protobuf::Logger.info { "pid #{::Process.pid} -- #{runner_name} RPC Server listening at #{options.host}:#{options.port} in #{options.env}" } + end + end - opts.on("-b N", "--backlog=N", Integer, "Backlog for listening socket when using Socket Server") do |v| - server.backlog = v.to_i end - opts.on("-t N", "--threshold=N", Integer, "Multi-threaded Socket Server cleanup threshold") do |v| - server.threshold = v.to_i - end - - opts.on("-c", "--client_socket", "Socket Mode for client connections (No EventMachine)") do |v| - ENV['PB_CLIENT_TYPE'] = "Socket" - end - - opts.on("-s", "--socket", "Socket Server Mode (No EventMachine)") do |v| - ENV['PB_SERVER_TYPE'] = "Socket" - server.runner = ::Protobuf::Rpc::SocketRunner - end - - opts.on("-z", "--zmq", "ZeroMQ Socket Mode for client and server connections (they must be used together)") do |v| - ENV['PB_CLIENT_TYPE'] = 'Zmq' - ENV['PB_SERVER_TYPE'] = 'Zmq' - - server.runner = ::Protobuf::Rpc::ZmqRunner - end - - opts.on("--[no-]pre-cache-definitions", "Enable/Disable Message class pre-caching") do |v| - server.pre_cache_definitions = v - end - - opts.on("--[no-]gc-pause-request", "Enable/Disable GC pause during request.") do |v| - server.gc_pause_during_request = v - end - - opts.on("--[no-]gc-pause-serialization", "Enable/Disable GC pause during serialization.") do |v| - server.gc_pause_during_serialization = v - end - - opts.on("-d", "--[no-]debug", "Debug Mode. Override log level to DEBUG.") do |v| - server.debug = v - server.level = ::Logger::DEBUG if v === true - end - - opts.on("--client-type=PB_CLIENT_TYPE", String, "Client Type to use (Socket or Zmq)") do |v| - ENV['PB_CLIENT_TYPE'] = v - end - - opts.on("--server-type=PB_SERVER_TYPE", String, "Server Type to use (Socket or Zmq)") do |v| - ENV['PB_SERVER_TYPE'] = v - end - - opts.separator "" - opts.separator "Common options:" - - opts.on_tail("-h", "--help", "Show this message") do - puts opts - exit - end - - opts.on_tail("--version", "Show version") do - puts ::Protobuf::VERSION - exit - end -end - -parser.parse! - -# Used to ensure we set the PB_CLIENT_TYPE and PB_SERVER_TYPE to the same thing -# if one of them is set to Zmq -if(ENV['PB_CLIENT_TYPE'] =~ /zmq/i) - # make server and client types the same if we're using Zmq - ENV['PB_SERVER_TYPE'] = ENV['PB_CLIENT_TYPE'] - server.runner = ::Protobuf::Rpc::ZmqRunner -elsif(ENV['PB_SERVER_TYPE'] =~ /zmq/i) - # make server and client types the same if we're using Zmq - ENV['PB_CLIENT_TYPE'] = ENV['PB_SERVER_TYPE'] - server.runner = ::Protobuf::Rpc::ZmqRunner -elsif(ENV['PB_SERVER_TYPE'] =~ /socket/i) - server.runner = ::Protobuf::Rpc::SocketRunner -end - -## -# Setup GC settings -# -::Protobuf::Rpc::GC_PAUSE_REQUEST = server.gc_pause_during_request -# If we pause during request we don't need to pause in serialization -::Protobuf::Rpc::GC_PAUSE_SERIALIZATION = (!server.gc_pause_during_request && server.gc_pause_during_serialization) - -# protobuf.rb picks up PB_CLIENT_TYPE and PB_SERVER_TYPE and does something -# useful with them -require 'protobuf' - -[:INT, :QUIT, :TERM].each do |sig| - trap(sig) do - server.stopped_during_startup = true - server.runner.stop - end end -begin - if ARGV.empty? - puts 'You must specify an app file to use.' - puts parser.help - exit - else - server.app = ARGV.pop - raise 'Invalid app file specified (%s).' % server.app unless File.exists?(server.app) - end - - # Configure the ::Protobuf::Logger - ::Protobuf::Logger.configure(:file => server.log, :level => server.debug ? ::Logger::DEBUG : server.level) - - # Output the server opts - ::Protobuf::Logger.debug { 'Debugging options:' } - ::Protobuf::Logger.debug { server.inspect } - - # Set the name of the process - $0 = 'rpc_server %s:%d %s' % [server.host, server.port, server.app] - - # Require the given application file - require server.app unless server.stopped_during_startup - - if server.pre_cache_definitions && !server.stopped_during_startup - ::Protobuf::Message.pre_cache_class_definitions - end - - server.runner.run(server) unless server.stopped_during_startup -rescue - msg = 'ERROR: RPC Server failed to start. %s' % $!.inspect - $stderr.puts(msg, *($!.backtrace)) - ::Protobuf::Logger.error { msg } - ::Protobuf::Logger.error { $!.backtrace.join("\n") } - exit 1 -end +::RpcServer.start(ARGV) diff --git a/generator/Makefile b/ext/Makefile similarity index 100% rename from generator/Makefile rename to ext/Makefile diff --git a/generator/RubyGenerator.cpp b/ext/RubyGenerator.cpp similarity index 100% rename from generator/RubyGenerator.cpp rename to ext/RubyGenerator.cpp diff --git a/generator/RubyGenerator.h b/ext/RubyGenerator.h similarity index 100% rename from generator/RubyGenerator.h rename to ext/RubyGenerator.h diff --git a/generator/main.cpp b/ext/main.cpp similarity index 100% rename from generator/main.cpp rename to ext/main.cpp diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 9b152629..fe809e26 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -10,16 +10,16 @@ module Protobuf Protobuf::ServerType = ENV['PB_SERVER_TYPE'] if ENV['PB_SERVER_TYPE'] # Socket Client/Server loaded by default as it has no impact on cross-platform issues -require 'protobuf/rpc/servers/socket/server' +require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/connectors/socket' require 'protobuf/rpc/client' require 'protobuf/rpc/service' # When setting up a client case -when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Asocket\Z/i then +when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Asocket\Z/i then #no-op -when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Azmq\Z/i then +when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Azmq\Z/i then require 'ffi-rzmq' require 'protobuf/rpc/connectors/zmq' else diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 3cfdbe40..48bcf5bc 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -6,6 +6,9 @@ module Protobuf module Rpc + GC_PAUSE_REQUEST = false + GC_PAUSE_SERIALIZATION = false + module Server def _gc_pause_request diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index 17818597..dd146f96 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -1,30 +1,30 @@ module Protobuf module Rpc - class EventedRunner + class EventedRunner def self.stop EventMachine.stop_event_loop if EventMachine.reactor_running? - Protobuf::Logger.info 'Shutdown complete' end def self.run(server) # Ensure errors thrown within EM are caught and logged appropriately - EventMachine.error_handler do |error| - if error.message == 'no acceptor' - raise 'Failed binding to %s:%d (%s)' % [server.host, server.port, error.message] - else - Protobuf::Logger.error error.message - Protobuf::Logger.error error.backtrace.join("\n") - end - end + #EventMachine.error_handler do |error| + # raise error + # if error.message == 'no acceptor' + # raise 'Failed binding to %s:%d (%s)' % [server.host, server.port, error.message] + # else + # Protobuf::Logger.error(error.message) + # Protobuf::Logger.error(error.backtrace.join("\n")) + # end + #end # Startup and run the rpc server EM.schedule do - EventMachine.start_server(server.host, server.port, Protobuf::Rpc::Evented::Server) && \ - Protobuf::Logger.info('RPC Server listening at %s:%d in %s' % [server.host, server.port, server.env]) + EventMachine.start_server(server.host, server.port, Protobuf::Rpc::Evented::Server) end # Join or start the reactor + yield if block_given? EM.reactor_running? ? EM.reactor_thread.join : EM.run end end diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index fef4c158..35da4218 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -1,16 +1,14 @@ module Protobuf module Rpc - class SocketRunner + class SocketRunner def self.stop - ::Protobuf::Rpc::Socket::Server.stop - ::Protobuf::Logger.info { 'Shutdown complete' } + ::Protobuf::Rpc::Socket::Server.stop end def self.run(server) - ::Protobuf::Logger.info { "Socket::Server Running" } - server_config = case - when server.is_a?(OpenStruct) then + server_config = case + when server.is_a?(OpenStruct) then server.marshal_dump when server.is_a?(Hash) then server @@ -20,6 +18,7 @@ def self.run(server) raise "Cannot parser Socket Server - server options" end + yield if block_given? ::Protobuf::Rpc::Socket::Server.run(server_config) end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 6428fc2e..0d372d29 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -3,14 +3,12 @@ module Rpc class ZmqRunner def self.stop - Protobuf::Rpc::Zmq::Server.stop - Protobuf::Logger.info('Shutdown complete') + Protobuf::Rpc::Zmq::Server.stop end def self.run(server) - Protobuf::Logger.info "ZmqServer Running" - server_config = case - when server.is_a?(OpenStruct) then + server_config = case + when server.is_a?(OpenStruct) then server.marshal_dump when server.respond_to?(:to_hash) then server.to_hash @@ -18,6 +16,7 @@ def self.run(server) raise "Cannot parser Zmq Server - server options" end + yield if block_given? Protobuf::Rpc::Zmq::Server.run(server_config) end end diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 616ebb27..1b48500d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,4 @@ module Protobuf VERSION = '1.4.2' + PROTOC_VERSION = '2.4.1' end diff --git a/protobuf.gemspec b/protobuf.gemspec index 72a741c8..bc8e2f51 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |s| s.add_dependency 'eventually' s.add_dependency 'json_pure' s.add_dependency 'ffi-rzmq' + s.add_dependency 'thor' s.add_development_dependency 'rake' s.add_development_dependency 'pry' From ce631fc3c897e981239904ea34844a8d01850796 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 27 Sep 2012 00:07:25 -0600 Subject: [PATCH 0091/1191] Remove the yacc compiler --- lib/protobuf/compiler/compiler.rb | 52 - lib/protobuf/compiler/nodes.rb | 323 ---- lib/protobuf/compiler/proto.y | 216 --- lib/protobuf/compiler/proto2.ebnf | 79 - lib/protobuf/compiler/proto_parser.rb | 1425 ----------------- .../template/rpc_service_implementation.erb | 42 - lib/protobuf/compiler/visitors.rb | 282 ---- test/test_compiler.rb | 325 ---- 8 files changed, 2744 deletions(-) delete mode 100644 lib/protobuf/compiler/compiler.rb delete mode 100644 lib/protobuf/compiler/nodes.rb delete mode 100644 lib/protobuf/compiler/proto.y delete mode 100644 lib/protobuf/compiler/proto2.ebnf delete mode 100644 lib/protobuf/compiler/proto_parser.rb delete mode 100644 lib/protobuf/compiler/template/rpc_service_implementation.erb delete mode 100644 lib/protobuf/compiler/visitors.rb delete mode 100644 test/test_compiler.rb diff --git a/lib/protobuf/compiler/compiler.rb b/lib/protobuf/compiler/compiler.rb deleted file mode 100644 index 9e114dfd..00000000 --- a/lib/protobuf/compiler/compiler.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'fileutils' -require 'protobuf/compiler/proto_parser' -require 'protobuf/compiler/nodes' -require 'protobuf/compiler/visitors' - -module Protobuf - class Compiler - def self.compile(proto_file, proto_dir='.', out_dir='.', file_create=true) - self.new.compile(proto_file, proto_dir, out_dir, file_create) - end - - def compile(proto_file, proto_dir='.', out_dir='.', file_create=true) - create_message(proto_file, proto_dir, out_dir, file_create) - create_rpc(proto_file, proto_dir, out_dir, file_create) - end - - def create_message(proto_file, proto_dir='.', out_dir='.', file_create=true) - rb_file = File.join(out_dir, File.basename(proto_file).sub(/\.[^\0]*\z/, '') + '.pb.rb') - proto_path = validate_existence(proto_file, proto_dir) - - message_visitor = Visitor::CreateMessageVisitor.new(proto_file, proto_dir, out_dir) - File.open(proto_path) do |file| - message_visitor.visit(ProtoParser.new.parse(file)) - end - message_visitor.create_files(rb_file, out_dir, file_create) - end - - def create_rpc(proto_file, proto_dir='.', out_dir='.', file_create=true) - message_file = File.join(out_dir, File.basename(proto_file).sub(/\.[^\0]*\z/, '') + '.pb.rb') - proto_path = validate_existence(proto_file, proto_dir) - - rpc_visitor = Visitor::CreateRpcVisitor.new - File.open(proto_path) do |file| - rpc_visitor.visit(ProtoParser.new.parse(file)) - end - rpc_visitor.create_files(message_file, out_dir, file_create) - end - - def validate_existence(path, base_dir) - if File.exist?(path) - path - else - newpath = File.join(base_dir, path) - if File.exist?(newpath) - newpath - else - raise ArgumentError, "File does not exist: #{path}" - end - end - end - end -end diff --git a/lib/protobuf/compiler/nodes.rb b/lib/protobuf/compiler/nodes.rb deleted file mode 100644 index eccddf70..00000000 --- a/lib/protobuf/compiler/nodes.rb +++ /dev/null @@ -1,323 +0,0 @@ -require 'protobuf/common/util' -require 'protobuf/descriptor/descriptor_proto' - -module Protobuf - module Node - class Base - def define_in_the_file(visitor) - visitor.write("defined_in __FILE__") if visitor.attach_proto? - end - - def accept_message_visitor(visitor) - end - - def accept_rpc_visitor(vistor) - end - - def accept_descriptor_visitor(visitor) - end - end - - class ProtoNode < Base - attr_reader :children - - def initialize(children) - @children = children || [] - end - - def accept_message_visitor(visitor) - visitor.write('### Generated by rprotoc. DO NOT EDIT!') - visitor.write("### ") if visitor.attach_proto? - visitor.write(visitor.commented_proto_contents) if visitor.attach_proto? - visitor.write(<<-EOS) -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - EOS - @children.each {|child| child.accept_message_visitor(visitor) } - visitor.close_ruby - end - - def accept_rpc_visitor(visitor) - @children.each {|child| child.accept_rpc_visitor(visitor) } - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::FileDescriptorProto.new(:name => visitor.filename) - visitor.file_descriptor = descriptor - visitor.in_context(descriptor) do - @children.each {|child| child.accept_descriptor_visitor(visitor) } - end - end - end - - class ImportNode < Base - def initialize(path) - @path = path - end - - def accept_message_visitor(visitor) - visitor.write("require '#{visitor.required_message_from_proto(@path)}'") - end - - def accept_descriptor_visitor(visitor) - visitor.current_descriptor.dependency << @path - end - end - - class PackageNode < Base - def initialize(path_list) - @path_list = path_list - end - - def accept_message_visitor(visitor) - visitor.package = @path_list.dup - @path_list.each do |path| - visitor.write("module #{Util.camelize(path)}") - visitor.increment - end - end - - def accept_rpc_visitor(visitor) - visitor.package = @path_list.dup - end - - def accept_descriptor_visitor(visitor) - visitor.current_descriptor.package = @path_list.join('.') - end - end - - class OptionNode < Base - def initialize(name_list, value) - @name_list, @value = name_list, value - end - - def accept_message_visitor(visitor) - visitor.write("::Protobuf::OPTIONS[:#{@name_list.join('.').inspect}] = #{@value.inspect}") - end - - def accept_descriptor_visitor(visitor) - visitor.add_option(@name_list.join('.'), @value) - end - end - - class MessageNode < Base - def initialize(name, children) - @name, @children = name, children - end - - def accept_message_visitor(visitor) - class_name = @name.to_s - class_name.gsub!(/\A[a-z]/) {|c| c.upcase} - visitor.write("class #{class_name} < ::Protobuf::Message") - visitor.in_context(self.class) do - define_in_the_file(visitor) - @children.each {|child| child.accept_message_visitor(visitor) } - end - visitor.write('end') - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::DescriptorProto.new(:name => @name.to_s) - visitor.descriptor = descriptor - visitor.in_context(descriptor) do - @children.each {|child| child.accept_descriptor_visitor(visitor) } - end - end - end - - class ExtendNode < Base - def initialize(name, children) - @name, @children = name, children - end - - def accept_message_visitor(visitor) - name = @name.is_a?(Array) ? @name.join : name.to_s - visitor.write("class #{name} < ::Protobuf::Message") - visitor.in_context(self.class) do - define_in_the_file(visitor) - @children.each {|child| child.accept_message_visitor(visitor) } - end - visitor.write('end') - end - - def accept_descriptor_visitor(visitor) - # TODO: how should i handle this? - end - end - - class EnumNode < Base - def initialize(name, children) - @name, @children = name, children - end - - def accept_message_visitor(visitor) - visitor.write("class #{@name} < ::Protobuf::Enum") - visitor.in_context(self.class) do - define_in_the_file(visitor) - @children.each {|child| child.accept_message_visitor(visitor) } - end - visitor.write('end') - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::EnumDescriptorProto.new(:name => @name.to_s) - visitor.enum_descriptor = descriptor - visitor.in_context(descriptor) do - @children.each {|child| child.accept_descriptor_visitor(visitor) } - end - end - end - - class EnumFieldNode < Base - def initialize(name, value) - @name, @value = name, value - end - - def accept_message_visitor(visitor) - visitor.write("define :#{@name}, #{@value}") - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::EnumValueDescriptorProto.new(:name => @name.to_s, :number => @value) - visitor.enum_value_descriptor = descriptor - end - end - - class ServiceNode < Base - def initialize(name, children) - @name, @children = name, children - end - - def accept_message_visitor(visitor) - # do nothing - end - - def accept_rpc_visitor(visitor) - visitor.current_service = @name - @children.each {|child| child.accept_rpc_visitor(visitor) } - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::ServiceDescriptorProto.new(:name => @name.to_s) - visitor.service_descriptor = descriptor - visitor.in_context(descriptor) do - @children.each {|child| child.accept_descriptor_visitor(visitor) } - end - end - end - - class RpcNode < Base - def initialize(name, request, response) - @name, @request, @response = name, request, response - end - - def accept_message_visitor(visitor) - # do nothing - end - - def accept_rpc_visitor(visitor) - visitor.add_rpc(@name, @request, @response) - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::MethodDescriptorProto.new(:name => @name.to_s, :input_type => @request.to_s, :output_type => @response.to_s) - visitor.method_descriptor = descriptor - end - end - - class GroupNode < Base - def initialize(label, name, value, children) - @label, @name, @value, @children = label, name, value, children - end - - def accept_message_visitor(visitor) - raise NotImplementedError - end - - def accept_descriptor_visitor(visitor) - raise NotImplementedError - end - end - - class FieldNode < Base - def initialize(label, type, name, value, opts={}) - @label, @type, @name, @value, @opts = label, type, name, value, opts - end - - def accept_message_visitor(visitor) - opts = @opts.empty? ? '' : ", #{@opts.map{|k, v| ":#{k} => #{v.inspect}" }.join(', ')}" - if visitor.context.first == ExtendNode - opts << ', :extension => true' - end - type = if @type.is_a?(Array) - then (@type.size > 1) ? "'#{@type.map{|e| Util.camelize(e) }.join('::')}'" : @type[0] - else @type - end - visitor.write("#{@label} :#{type}, :#{@name}, #{@value}#{opts}") - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::FieldDescriptorProto.new(:name => @name.to_s, :number => @value) - descriptor.label = Google::Protobuf::FieldDescriptorProto::Label.const_get("LABEL_#{@label.to_s.upcase}") - descriptor.type = Google::Protobuf::FieldDescriptorProto::Type.const_get("TYPE_#{@type.to_s.upcase}") if predefined_type? - descriptor.type_name = @type.is_a?(Array) ? @type.join : @type.to_s - @opts.each do |key, val| - case key.to_sym - when :default then - descriptor.default_value = val.to_s - end - end - visitor.field_descriptor = descriptor - end - - private - - def predefined_type? - # TODO: constantize - %w{double float int64 uint64 int32 fixed64 fixed32 bool string group message bytes uint32 enum sfixed32 sfixed64 sint32 sint64}.include?(@type.to_s) - end - end - - class ExtensionsNode < Base - def initialize(range) - @range = range - end - - def accept_message_visitor(visitor) - visitor.write("extensions #{@range.first.to_s}") - end - - def accept_descriptor_visitor(visitor) - descriptor = Google::Protobuf::DescriptorProto::ExtensionRange.new(:start => @range.first.low) - case @range.first.high - when NilClass then # ignore - when :max then descriptor.end = 1 - else descriptor.end = @range.first.high - end - visitor.extension_range_descriptor = descriptor - end - end - - class ExtensionRangeNode < Base - attr_reader :low, :high - - def initialize(low, high=nil) - @low, @high = low, high - end - - #def accept_message_visitor(visitor) - #end - - def to_s - if @high.nil? - @low.to_s - elsif @high == :max - "#{@low}..::Protobuf::Extend::MAX" - else - "#{@low}..#{@high}" - end - end - end - end -end diff --git a/lib/protobuf/compiler/proto.y b/lib/protobuf/compiler/proto.y deleted file mode 100644 index 242e7dd9..00000000 --- a/lib/protobuf/compiler/proto.y +++ /dev/null @@ -1,216 +0,0 @@ -class Protobuf::ProtoParser -rule - proto : proto_item - { result = Protobuf::Node::ProtoNode.new(val) } - | proto proto_item - { result.children << val[1] if val[1]} - - proto_item : message - | extend - | enum - | import - | package - | option - | service - | ';' { result = nil } - - import : 'import' STRING_LITERAL ';' - { result = Protobuf::Node::ImportNode.new(val[1]) } - - package : 'package' IDENT dot_ident_list ';' - { result = Protobuf::Node::PackageNode.new(val[2].unshift(val[1])) } - - dot_ident_list : - { result = [] } - | dot_ident_list '.' IDENT - { result << val[2] } - - option : 'option' option_body ';' - { result = Protobuf::Node::OptionNode.new(*val[1]) } - - option_body : IDENT dot_ident_list '=' constant - { result = [val[1].unshift(val[0]), val[3]] } - - message : 'message' IDENT message_body - { result = Protobuf::Node::MessageNode.new(val[1], val[2]) } - - extend : 'extend' user_type '{' extend_body_list '}' - { result = Protobuf::Node::ExtendNode.new(val[1], val[3]) } - - extend_body_list : - { result = [] } - | extend_body_list extend_body - { result << val[1] if val[1] } - - extend_body : field - | group - | ';' { result = nil } - - enum : 'enum' IDENT '{' enum_body_list '}' - { result = Protobuf::Node::EnumNode.new(val[1], val[3]) } - - enum_body_list : - { result = [] } - | enum_body_list enum_body - { result << val[1] if val[1] } - - enum_body : option - | enum_field - | ';' { result = nil } - - enum_field : IDENT '=' integer_literal ';' - { result = Protobuf::Node::EnumFieldNode.new(val[0], val[2]) } - - service : 'service' IDENT '{' service_body_list '}' - { result = Protobuf::Node::ServiceNode.new(val[1], val[3]) } - - service_body_list : - { result = [] } - | service_body_list service_body - { result << val[1] if val[1] } - - service_body : option - | rpc - | ';' { result = nil} - - rpc : 'rpc' IDENT '(' rpc_arg ')' 'returns' '(' rpc_arg ')' ';' - { result = Protobuf::Node::RpcNode.new(val[1], val[3], val[7]) } - - rpc_arg : - | user_type - - message_body : '{' message_body_body_list '}' - { result = val[1] } - - message_body_body_list : - { result = [] } - | message_body_body_list message_body_body - { result << val[1] if val[1] } - - message_body_body : field - | enum - | message - | extend - | extensions - | group - | option - | ';' { result = nil } - - group : label 'group' CAMEL_IDENT '=' integer_literal message_body - { result = Protobuf::Node::GroupNode.new(val[0], val[2], val[4], val[5]) } - - field : label type field_name '=' integer_literal ';' - { result = Protobuf::Node::FieldNode.new(val[0], val[1], val[2], val[4]) } - | label type field_name '=' integer_literal '[' field_option_list ']' ';' - { result = Protobuf::Node::FieldNode.new(val[0], val[1], val[2], val[4], val[6]) } - - field_name : IDENT | "required" | "optional" | "repeated" | "import" | "package" | "option" | "message" | "extend" | "enum" | "service" | "rpc" | "returns" | "group" | "default" | "extensions" | "to" | "max" | "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes" - - field_option_list : field_option - { result = val } - | field_option_list ',' field_option - { result << val[2] } - - field_option : option_body - | 'default' '=' constant - { result = [:default, val[2]] } - - extensions : 'extensions' extension comma_extension_list ';' - { result = Protobuf::Node::ExtensionsNode.new(val[2].unshift(val[1])) } - - comma_extension_list : - { result = [] } - | ',' extension - { result << val[1] } - - extension : integer_literal - { result = Protobuf::Node::ExtensionRangeNode.new(val[0]) } - | integer_literal 'to' integer_literal - { result = Protobuf::Node::ExtensionRangeNode.new(val[0], val[2]) } - | integer_literal 'to' 'max' - { result = Protobuf::Node::ExtensionRangeNode.new(val[0], :max) } - - label : 'required' - | 'optional' - | 'repeated' - - type : 'double' | 'float' | 'int32' | 'int64' | 'uint32' | 'uint64' - | 'sint32' | 'sint64' | 'fixed32' | 'fixed64' | 'sfixed32' | 'sfixed64' - | 'bool' | 'string' | 'bytes' | user_type - - user_type : IDENT dot_ident_list - { result = val[1].unshift(val[0]) } - | '.' IDENT dot_ident_list - { result = val[1].unshift(val[0]) } - - constant : IDENT - | integer_literal - | FLOAT_LITERAL - | STRING_LITERAL - | BOOLEAN_LITERAL - - integer_literal : DEC_INTEGER - | HEX_INTEGER - | OCT_INTEGER -end - ----- inner - - require 'strscan' - - def parse(f) - @scanner = StringScanner.new(f.read) - yyparse(self, :scan) - end - - def scan_debug - scan do |token, value| - p [token, value] - yield [token, value] - end - end - - def scan - until @scanner.eos? - case - when match(/\s+/, /\/\/.*/) - # skip - when match(/\/\*/) - # C-like comment - raise 'EOF inside block comment' until @scanner.scan_until(/\*\//) - when match(/(?:required|optional|repeated|import|package|option|message|extend|enum|service|rpc|returns|group|default|extensions|to|max|double|float|int32|int64|uint32|uint64|sint32|sint64|fixed32|fixed64|sfixed32|sfixed64|bool|string|bytes)\b/) - yield [@token, @token.to_sym] - when match(/[+-]?\d*\.\d+([Ee][\+-]?\d+)?/) - yield [:FLOAT_LITERAL, @token.to_f] - when match(/[+-]?[1-9]\d*(?!\.)/, /0(?![.xX0-9])/) - yield [:DEC_INTEGER, @token.to_i] - when match(/0[xX]([A-Fa-f0-9])+/) - yield [:HEX_INTEGER, @token.to_i(0)] - when match(/0[0-7]+/) - yield [:OCT_INTEGER, @token.to_i(0)] - when match(/(true|false)\b/) - yield [:BOOLEAN_LITERAL, @token == 'true'] - when match(/"(?:[^"\\]+|\\.)*"/, /'(?:[^'\\]+|\\.)*'/) - yield [:STRING_LITERAL, eval(@token)] - when match(/[a-zA-Z_]\w*/) - yield [:IDENT, @token.to_sym] - when match(/[A-Z]\w*/) - yield [:CAMEL_IDENT, @token.to_sym] - when match(/./) - yield [@token, @token] - else - raise "parse error around #{@scanner.string[@scanner.pos, 32].inspect}" - end - end - yield [false, nil] - end - - def match(*regular_expressions) - regular_expressions.each do |re| - if @scanner.scan(re) - @token = @scanner[0] - return true - end - end - false - end diff --git a/lib/protobuf/compiler/proto2.ebnf b/lib/protobuf/compiler/proto2.ebnf deleted file mode 100644 index c24c2e2c..00000000 --- a/lib/protobuf/compiler/proto2.ebnf +++ /dev/null @@ -1,79 +0,0 @@ -# See: http://groups.google.com/group/protobuf/browse_thread/thread/1cccfc624cd612da - -proto ::= ( message | extend | enum | import | package | option | ";" )* - -import ::= "import" strLit ";" - -package ::= "package" ident ( "." ident )* ";" - -option ::= "option" optionBody ";" - -optionBody ::= ident ( "." ident )* "=" constant - -message ::= "message" ident messageBody - -extend ::= "extend" userType "{" ( field | group | ";" )* "}" - -enum ::= "enum" ident "{" ( option | enumField | ";" )* "}" - -enumField ::= ident "=" intLit ";" - -service ::= "service" ident "{" ( option | rpc | ";" )* "}" - -rpc ::= "rpc" ident "(" userType ")" "returns" "(" userType ")" ";" - -messageBody ::= "{" ( field | enum | message | extend | extensions | group | option | ":" )* "}" - -group ::= label "group" camelIdent "=" intLit messageBody - -field ::= label type ident "=" intLit ( "[" fieldOption ( "," fieldOption )* "]" )? ";" -# tag number must be 2^29-1 or lower, not 0, and not 19000-19999 (reserved) - -fieldOption ::= optionBody | "default" "=" constant - -# extension numbers must not overlap with field or other extension numbers -extensions ::= "extensions" extension ( "," extension )* ";" - -extension ::= intLit ( "to" ( intLit | "max" ) )? - -label ::= "required" | "optional" | "repeated" - -type ::= "double" | "float" | "int32" | "int64" | "uint32" | "uint64" - | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" - | "bool" | "string" | "bytes" | userType - -# leading dot for identifiers means they're fully qualified -userType ::= "."? ident ( "." ident )* - -constant ::= ident | intLit | floatLit | strLit | boolLit - -ident ::= /[A-Za-z_][\w_]*/ - -# according to parser.cc, group names must start with a capital letter as a -# hack for backwards-compatibility -camelIdent ::= /[A-Z][\w_]*/ - -intLit ::= decInt | hexInt | octInt - -decInt ::= /[1-9]\d*/ - -hexInt ::= /0[xX]([A-Fa-f0-9])+/ - -octInt ::= /0[0-7]+/ - -# allow_f_after_float_ is disabled by default in tokenizer.cc -floatLit ::= /\d+(\.\d+)?([Ee][\+-]?\d+)?/ - -boolLit ::= "true" | "false" - -# contents must not contain unescaped quote character -strLit ::= quote ( hexEscape | octEscape | charEscape | /[^\0\n]/ )* quote - -quote ::= /["']/ - -hexEscape ::= /\\[Xx][A-Fa-f0-9]{1,2}/ - -octEscape ::= /\\0?[0-7]{1,3}/ - -charEscape ::= /\\[abfnrtv\\\?'"]/ - diff --git a/lib/protobuf/compiler/proto_parser.rb b/lib/protobuf/compiler/proto_parser.rb deleted file mode 100644 index 62cb4f47..00000000 --- a/lib/protobuf/compiler/proto_parser.rb +++ /dev/null @@ -1,1425 +0,0 @@ -# -# DO NOT MODIFY!!!! -# This file is automatically generated by racc 1.4.5 -# from racc grammer file "lib/protobuf/compiler/proto.y". -# -# -# lib/protobuf/compiler/proto_parser.rb: generated by racc (runtime embedded) -# -###### racc/parser.rb begin -unless $".index 'racc/parser.rb' -$".push 'racc/parser.rb' - -self.class.module_eval <<'..end racc/parser.rb modeval..id24fd9e97a6', 'racc/parser.rb', 1 -# -# $Id: parser.rb,v 1.7 2005/11/20 17:31:32 aamine Exp $ -# -# Copyright (c) 1999-2005 Minero Aoki -# -# This program is free software. -# You can distribute/modify this program under the same terms of ruby. -# -# As a special exception, when this code is copied by Racc -# into a Racc output file, you may use that output file -# without restriction. -# - -unless defined?(NotImplementedError) - NotImplementedError = NotImplementError -end - -module Racc - class ParseError < StandardError; end -end -unless defined?(::ParseError) - ParseError = Racc::ParseError -end - -module Racc - - unless defined?(Racc_No_Extentions) - Racc_No_Extentions = false - end - - class Parser - - Racc_Runtime_Version = '1.4.5' - Racc_Runtime_Revision = '$Revision: 1.7 $'.split[1] - - Racc_Runtime_Core_Version_R = '1.4.5' - Racc_Runtime_Core_Revision_R = '$Revision: 1.7 $'.split[1] - begin - require 'racc/cparse' - # Racc_Runtime_Core_Version_C = (defined in extention) - Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2] - unless new.respond_to?(:_racc_do_parse_c, true) - raise LoadError, 'old cparse.so' - end - if Racc_No_Extentions - raise LoadError, 'selecting ruby version of racc runtime core' - end - - Racc_Main_Parsing_Routine = :_racc_do_parse_c - Racc_YY_Parse_Method = :_racc_yyparse_c - Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C - Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C - Racc_Runtime_Type = 'c' - rescue LoadError - $stderr.puts $! - Racc_Main_Parsing_Routine = :_racc_do_parse_rb - Racc_YY_Parse_Method = :_racc_yyparse_rb - Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R - Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_R - Racc_Runtime_Type = 'ruby' - end - - def Parser.racc_runtime_type - Racc_Runtime_Type - end - - private - - def _racc_setup - @yydebug = false unless self.class::Racc_debug_parser - @yydebug = false unless defined?(@yydebug) - if @yydebug - @racc_debug_out = $stderr unless defined?(@racc_debug_out) - @racc_debug_out ||= $stderr - end - arg = self.class::Racc_arg - arg[13] = true if arg.size < 14 - arg - end - - def _racc_init_sysvars - @racc_state = [0] - @racc_tstack = [] - @racc_vstack = [] - - @racc_t = nil - @racc_val = nil - - @racc_read_next = true - - @racc_user_yyerror = false - @racc_error_status = 0 - end - - ### - ### do_parse - ### - - def do_parse - __send__(Racc_Main_Parsing_Routine, _racc_setup(), false) - end - - def next_token - raise NotImplementedError, "#{self.class}\#next_token is not defined" - end - - def _racc_do_parse_rb(arg, in_debug) - action_table, action_check, action_default, action_pointer, - goto_table, goto_check, goto_default, goto_pointer, - nt_base, reduce_table, token_table, shift_n, - reduce_n, use_result, * = arg - - _racc_init_sysvars - tok = act = i = nil - nerr = 0 - - catch(:racc_end_parse) { - while true - if i = action_pointer[@racc_state[-1]] - if @racc_read_next - if @racc_t != 0 # not EOF - tok, @racc_val = next_token() - unless tok # EOF - @racc_t = 0 - else - @racc_t = (token_table[tok] or 1) # error token - end - racc_read_token(@racc_t, tok, @racc_val) if @yydebug - @racc_read_next = false - end - end - i += @racc_t - unless i >= 0 and - act = action_table[i] and - action_check[i] == @racc_state[-1] - act = action_default[@racc_state[-1]] - end - else - act = action_default[@racc_state[-1]] - end - while act = _racc_evalact(act, arg) - ; - end - end - } - end - - ### - ### yyparse - ### - - def yyparse(recv, mid) - __send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true) - end - - def _racc_yyparse_rb(recv, mid, arg, c_debug) - action_table, action_check, action_default, action_pointer, - goto_table, goto_check, goto_default, goto_pointer, - nt_base, reduce_table, token_table, shift_n, - reduce_n, use_result, * = arg - - _racc_init_sysvars - tok = nil - act = nil - i = nil - nerr = 0 - - catch(:racc_end_parse) { - until i = action_pointer[@racc_state[-1]] - while act = _racc_evalact(action_default[@racc_state[-1]], arg) - ; - end - end - recv.__send__(mid) do |tok, val| - unless tok - @racc_t = 0 - else - @racc_t = (token_table[tok] or 1) # error token - end - @racc_val = val - @racc_read_next = false - - i += @racc_t - unless i >= 0 and - act = action_table[i] and - action_check[i] == @racc_state[-1] - act = action_default[@racc_state[-1]] - end - while act = _racc_evalact(act, arg) - ; - end - - while not (i = action_pointer[@racc_state[-1]]) or - not @racc_read_next or - @racc_t == 0 # $ - unless i and i += @racc_t and - i >= 0 and - act = action_table[i] and - action_check[i] == @racc_state[-1] - act = action_default[@racc_state[-1]] - end - while act = _racc_evalact(act, arg) - ; - end - end - end - } - end - - ### - ### common - ### - - def _racc_evalact(act, arg) - action_table, action_check, action_default, action_pointer, - goto_table, goto_check, goto_default, goto_pointer, - nt_base, reduce_table, token_table, shift_n, - reduce_n, use_result, * = arg - nerr = 0 # tmp - - if act > 0 and act < shift_n - # - # shift - # - if @racc_error_status > 0 - @racc_error_status -= 1 unless @racc_t == 1 # error token - end - @racc_vstack.push @racc_val - @racc_state.push act - @racc_read_next = true - if @yydebug - @racc_tstack.push @racc_t - racc_shift @racc_t, @racc_tstack, @racc_vstack - end - - elsif act < 0 and act > -reduce_n - # - # reduce - # - code = catch(:racc_jump) { - @racc_state.push _racc_do_reduce(arg, act) - false - } - if code - case code - when 1 then # yyerror - @racc_user_yyerror = true # user_yyerror - return -reduce_n - when 2 then # yyaccept - return shift_n - else - raise '[Racc Bug] unknown jump code' - end - end - - elsif act == shift_n - # - # accept - # - racc_accept if @yydebug - throw :racc_end_parse, @racc_vstack[0] - - elsif act == -reduce_n - # - # error - # - case @racc_error_status - when 0 then - unless arg[21] # user_yyerror - nerr += 1 - on_error @racc_t, @racc_val, @racc_vstack - end - when 3 then - if @racc_t == 0 # is $ - throw :racc_end_parse, nil - end - @racc_read_next = true - end - @racc_user_yyerror = false - @racc_error_status = 3 - while true - if i = action_pointer[@racc_state[-1]] - i += 1 # error token - if i >= 0 and - (act = action_table[i]) and - action_check[i] == @racc_state[-1] - break - end - end - throw :racc_end_parse, nil if @racc_state.size <= 1 - @racc_state.pop - @racc_vstack.pop - if @yydebug - @racc_tstack.pop - racc_e_pop @racc_state, @racc_tstack, @racc_vstack - end - end - return act - - else - raise "[Racc Bug] unknown action #{act.inspect}" - end - - racc_next_state(@racc_state[-1], @racc_state) if @yydebug - - nil - end - - def _racc_do_reduce(arg, act) - action_table, action_check, action_default, action_pointer, - goto_table, goto_check, goto_default, goto_pointer, - nt_base, reduce_table, token_table, shift_n, - reduce_n, use_result, * = arg - state = @racc_state - vstack = @racc_vstack - tstack = @racc_tstack - - i = act * -3 - len = reduce_table[i] - reduce_to = reduce_table[i+1] - method_id = reduce_table[i+2] - void_array = [] - - tmp_t = tstack[-len, len] if @yydebug - tmp_v = vstack[-len, len] - tstack[-len, len] = void_array if @yydebug - vstack[-len, len] = void_array - state[-len, len] = void_array - - # tstack must be updated AFTER method call - if use_result - vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0]) - else - vstack.push __send__(method_id, tmp_v, vstack) - end - tstack.push reduce_to - - racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug - - k1 = reduce_to - nt_base - if i = goto_pointer[k1] - i += state[-1] - if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1 - return curstate - end - end - goto_default[k1] - end - - def on_error(t, val, vstack) - raise ParseError, sprintf("\nparse error on value %s (%s)", - val.inspect, token_to_str(t) || '?') - end - - def yyerror - throw :racc_jump, 1 - end - - def yyaccept - throw :racc_jump, 2 - end - - def yyerrok - @racc_error_status = 0 - end - - # - # for debugging output - # - - def racc_read_token(t, tok, val) - @racc_debug_out.print 'read ' - @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') ' - @racc_debug_out.puts val.inspect - @racc_debug_out.puts - end - - def racc_shift(tok, tstack, vstack) - @racc_debug_out.puts "shift #{racc_token2str tok}" - racc_print_stacks tstack, vstack - @racc_debug_out.puts - end - - def racc_reduce(toks, sim, tstack, vstack) - out = @racc_debug_out - out.print 'reduce ' - if toks.empty? - out.print ' ' - else - toks.each {|t| out.print ' ', racc_token2str(t) } - end - out.puts " --> #{racc_token2str(sim)}" - - racc_print_stacks tstack, vstack - @racc_debug_out.puts - end - - def racc_accept - @racc_debug_out.puts 'accept' - @racc_debug_out.puts - end - - def racc_e_pop(state, tstack, vstack) - @racc_debug_out.puts 'error recovering mode: pop token' - racc_print_states state - racc_print_stacks tstack, vstack - @racc_debug_out.puts - end - - def racc_next_state(curstate, state) - @racc_debug_out.puts "goto #{curstate}" - racc_print_states state - @racc_debug_out.puts - end - - def racc_print_stacks(t, v) - out = @racc_debug_out - out.print ' [' - t.each_index do |i| - out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')' - end - out.puts ' ]' - end - - def racc_print_states(s) - out = @racc_debug_out - out.print ' [' - s.each {|st| out.print ' ', st } - out.puts ' ]' - end - - def racc_token2str(tok) - self.class::Racc_token_to_s_table[tok] or - raise "[Racc Bug] can't convert token #{tok} to string" - end - - def token_to_str(t) - self.class::Racc_token_to_s_table[t] - end - - end - -end -..end racc/parser.rb modeval..id24fd9e97a6 -end -###### racc/parser.rb end - - -module Protobuf - - class ProtoParser < Racc::Parser - -module_eval <<'..end lib/protobuf/compiler/proto.y modeval..id110d2bf917', 'lib/protobuf/compiler/proto.y', 158 - - require 'strscan' - - def parse(f) - @scanner = StringScanner.new(f.read) - yyparse(self, :scan) - end - - def scan_debug - scan do |token, value| - p [token, value] - yield [token, value] - end - end - - def scan - until @scanner.eos? - case - when match(/\s+/, /\/\/.*/) then - # skip - when match(/\/\*/) then - # C-like comment - raise 'EOF inside block comment' until @scanner.scan_until(/\*\//) - when match(/(?:required|optional|repeated|import|package|option|message|extend|enum|service|rpc|returns|group|default|extensions|to|max|double|float|int32|int64|uint32|uint64|sint32|sint64|fixed32|fixed64|sfixed32|sfixed64|bool|string|bytes)\b/) then - yield [@token, @token.to_sym] - when match(/[+-]?\d*\.\d+([Ee][\+-]?\d+)?/) then - yield [:FLOAT_LITERAL, @token.to_f] - when match(/[+-]?[1-9]\d*(?!\.)/, /0(?![.xX0-9])/) then - yield [:DEC_INTEGER, @token.to_i] - when match(/0[xX]([A-Fa-f0-9])+/) then - yield [:HEX_INTEGER, @token.to_i(0)] - when match(/0[0-7]+/) then - yield [:OCT_INTEGER, @token.to_i(0)] - when match(/(true|false)\b/) then - yield [:BOOLEAN_LITERAL, @token == 'true'] - when match(/"(?:[^"\\]+|\\.)*"/, /'(?:[^'\\]+|\\.)*'/) then - yield [:STRING_LITERAL, eval(@token)] - when match(/[a-zA-Z_]\w*/) then - yield [:IDENT, @token.to_sym] - when match(/[A-Z]\w*/) then - yield [:CAMEL_IDENT, @token.to_sym] - when match(/./) then - yield [@token, @token] - else - raise "parse error around #{@scanner.string[@scanner.pos, 32].inspect}" - end - end - yield [false, nil] - end - - def match(*regular_expressions) - regular_expressions.each do |re| - if @scanner.scan(re) - @token = @scanner[0] - return true - end - end - false - end -..end lib/protobuf/compiler/proto.y modeval..id110d2bf917 - -##### racc 1.4.5 generates ### - -racc_reduce_table = [ - 0, 0, :racc_error, - 1, 53, :_reduce_1, - 2, 53, :_reduce_2, - 1, 54, :_reduce_none, - 1, 54, :_reduce_none, - 1, 54, :_reduce_none, - 1, 54, :_reduce_none, - 1, 54, :_reduce_none, - 1, 54, :_reduce_none, - 1, 54, :_reduce_none, - 1, 54, :_reduce_10, - 3, 58, :_reduce_11, - 4, 59, :_reduce_12, - 0, 62, :_reduce_13, - 3, 62, :_reduce_14, - 3, 60, :_reduce_15, - 4, 63, :_reduce_16, - 3, 55, :_reduce_17, - 5, 56, :_reduce_18, - 0, 67, :_reduce_19, - 2, 67, :_reduce_20, - 1, 68, :_reduce_none, - 1, 68, :_reduce_none, - 1, 68, :_reduce_23, - 5, 57, :_reduce_24, - 0, 71, :_reduce_25, - 2, 71, :_reduce_26, - 1, 72, :_reduce_none, - 1, 72, :_reduce_none, - 1, 72, :_reduce_29, - 4, 73, :_reduce_30, - 5, 61, :_reduce_31, - 0, 75, :_reduce_32, - 2, 75, :_reduce_33, - 1, 76, :_reduce_none, - 1, 76, :_reduce_none, - 1, 76, :_reduce_36, - 10, 77, :_reduce_37, - 0, 78, :_reduce_none, - 1, 78, :_reduce_none, - 3, 65, :_reduce_40, - 0, 79, :_reduce_41, - 2, 79, :_reduce_42, - 1, 80, :_reduce_none, - 1, 80, :_reduce_none, - 1, 80, :_reduce_none, - 1, 80, :_reduce_none, - 1, 80, :_reduce_none, - 1, 80, :_reduce_none, - 1, 80, :_reduce_none, - 1, 80, :_reduce_50, - 6, 70, :_reduce_51, - 6, 69, :_reduce_52, - 9, 69, :_reduce_53, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 84, :_reduce_none, - 1, 85, :_reduce_87, - 3, 85, :_reduce_88, - 1, 86, :_reduce_none, - 3, 86, :_reduce_90, - 4, 81, :_reduce_91, - 0, 88, :_reduce_92, - 2, 88, :_reduce_93, - 1, 87, :_reduce_94, - 3, 87, :_reduce_95, - 3, 87, :_reduce_96, - 1, 82, :_reduce_none, - 1, 82, :_reduce_none, - 1, 82, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 2, 66, :_reduce_116, - 3, 66, :_reduce_117, - 1, 64, :_reduce_none, - 1, 64, :_reduce_none, - 1, 64, :_reduce_none, - 1, 64, :_reduce_none, - 1, 64, :_reduce_none, - 1, 74, :_reduce_none, - 1, 74, :_reduce_none, - 1, 74, :_reduce_none ] - -racc_reduce_n = 126 - -racc_shift_n = 184 - -racc_action_table = [ - 74, 51, 77, 19, 20, 74, 25, 77, 67, 60, - 32, 47, 53, 63, 14, 14, 43, 107, 39, 68, - 61, 38, 69, 50, 54, 56, 110, 170, 106, 109, - 94, 96, 97, 98, 99, 100, 101, 103, 104, 105, - 108, 93, 95, 72, 73, 75, 76, 78, 72, 73, - 75, 76, 78, 123, 111, 131, 134, 43, 141, 48, - 147, 116, 19, 20, 122, 126, 130, 19, 20, 140, - 144, 75, 76, 78, 120, 124, 127, 129, 133, 136, - 139, 143, 146, 115, 118, 119, 121, 125, 128, 132, - 135, 138, 142, 145, 114, 117, 83, 167, 176, 75, - 76, 78, 14, 25, 16, 1, 159, 85, 6, 75, - 76, 78, 75, 76, 78, 19, 20, 166, 50, 54, - 56, 177, 91, 35, 170, 75, 76, 78, 27, 34, - 4, 7, 148, 11, 33, 150, 14, 151, 16, 1, - 153, 154, 6, 9, 4, 7, 155, 11, 156, 43, - 14, 40, 16, 1, 161, 30, 6, 9, 75, 76, - 78, 29, 25, 165, 24, 40, 169, 23, 174, 175, - 22, 43, 21, 180, 59, 182, 183 ] - -racc_action_check = [ - 48, 42, 48, 58, 58, 175, 177, 175, 46, 45, - 20, 36, 42, 45, 46, 45, 36, 58, 27, 46, - 45, 26, 46, 42, 42, 42, 63, 177, 58, 58, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 58, 48, 48, 48, 48, 48, 175, 175, - 175, 175, 175, 102, 69, 102, 102, 37, 102, 37, - 102, 102, 150, 150, 102, 102, 102, 1, 1, 102, - 102, 91, 91, 91, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 49, 163, 172, 110, - 110, 110, 49, 166, 49, 49, 151, 49, 49, 154, - 154, 154, 153, 153, 153, 174, 174, 163, 49, 49, - 49, 172, 49, 23, 166, 151, 151, 151, 15, 22, - 15, 15, 107, 15, 21, 111, 15, 112, 15, 15, - 113, 137, 15, 15, 0, 0, 148, 0, 149, 44, - 0, 29, 0, 0, 152, 18, 0, 0, 155, 155, - 155, 16, 14, 158, 11, 164, 165, 9, 169, 170, - 7, 31, 6, 176, 43, 178, 182 ] - -racc_action_pointer = [ - 142, 61, nil, nil, nil, nil, 166, 166, nil, 161, - nil, 158, nil, nil, 156, 128, 155, nil, 143, nil, - 4, 122, 127, 111, nil, nil, 19, 18, nil, 139, - nil, 164, nil, nil, nil, nil, 9, 50, nil, nil, - nil, nil, -1, 168, 142, 7, 6, nil, -4, 94, - nil, nil, nil, nil, nil, nil, nil, nil, -3, nil, - nil, nil, nil, 17, nil, nil, nil, nil, nil, 48, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 22, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 50, nil, nil, nil, nil, 111, nil, nil, - 50, 118, 108, 94, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, 132, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, 137, 146, - 56, 76, 152, 63, 60, 109, nil, nil, 145, nil, - nil, nil, nil, 95, 153, 147, 97, nil, nil, 151, - 160, nil, 75, nil, 109, 1, 171, 0, 157, nil, - nil, nil, 174, nil ] - -racc_action_default = [ - -126, -126, -3, -4, -10, -5, -126, -126, -6, -126, - -7, -126, -8, -9, -126, -126, -126, -1, -126, -13, - -126, -126, -126, -126, -13, -13, -126, -126, -2, -126, - -19, -116, -13, -25, -11, -32, -126, -126, -15, 184, - -41, -17, -126, -126, -117, -126, -126, -12, -126, -126, - -97, -23, -20, -18, -98, -21, -99, -22, -126, -14, - -29, -24, -27, -126, -26, -28, -35, -36, -31, -126, - -34, -33, -120, -122, -121, -123, -124, -118, -125, -119, - -16, -45, -46, -50, -44, -40, -43, -42, -48, -47, - -49, -126, -115, -113, -102, -114, -103, -104, -105, -106, - -107, -108, -126, -109, -110, -111, -100, -126, -112, -101, - -126, -126, -94, -92, -85, -74, -62, -86, -75, -76, - -55, -77, -63, -58, -56, -78, -64, -57, -79, -68, - -65, -59, -80, -69, -54, -81, -70, -126, -82, -71, - -66, -60, -83, -72, -67, -84, -73, -61, -126, -126, - -38, -126, -126, -126, -126, -126, -30, -39, -126, -96, - -95, -91, -93, -126, -126, -126, -126, -52, -51, -126, - -126, -89, -126, -87, -38, -126, -126, -126, -126, -90, - -53, -88, -126, -37 ] - -racc_goto_table = [ - 41, 80, 112, 18, 158, 113, 31, 17, 57, 173, - 55, 36, 37, 64, 42, 88, 26, 86, 45, 44, - 181, 149, 28, 62, 70, 52, 65, 90, 178, 84, - 46, 71, 66, 82, 49, 87, 89, 102, 137, 172, - 81, 15, 152, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 92, nil, 160, nil, 112, 163, 164, 162, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, 179, nil, - nil, nil, nil, nil, nil, 168 ] - -racc_goto_check = [ - 13, 12, 22, 14, 26, 35, 10, 2, 18, 34, - 17, 10, 10, 20, 15, 18, 11, 17, 19, 10, - 34, 22, 2, 8, 8, 16, 21, 8, 26, 5, - 23, 24, 25, 4, 27, 28, 29, 31, 32, 33, - 3, 1, 36, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 14, nil, 22, nil, 22, 22, 22, 35, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, 12, nil, - nil, nil, nil, nil, nil, 13 ] - -racc_goto_pointer = [ - nil, 41, 7, -9, -16, -20, nil, nil, -22, nil, - -13, 2, -47, -29, 2, -16, -17, -32, -34, -15, - -32, -19, -89, -5, -15, -14, -146, -6, -14, -13, - nil, -21, -64, -127, -157, -86, -71 ] - -racc_goto_default = [ - nil, nil, nil, 2, 3, 5, 8, 10, 12, 13, - nil, 171, nil, nil, 157, nil, nil, nil, nil, nil, - nil, nil, 79, nil, nil, nil, nil, nil, nil, nil, - 58, nil, nil, nil, nil, nil, nil ] - -racc_token_table = { - false => 0, - Object.new => 1, - ";" => 2, - "import" => 3, - :STRING_LITERAL => 4, - "package" => 5, - :IDENT => 6, - "." => 7, - "option" => 8, - "=" => 9, - "message" => 10, - "extend" => 11, - "{" => 12, - "}" => 13, - "enum" => 14, - "service" => 15, - "rpc" => 16, - "(" => 17, - ")" => 18, - "returns" => 19, - "group" => 20, - :CAMEL_IDENT => 21, - "[" => 22, - "]" => 23, - "required" => 24, - "optional" => 25, - "repeated" => 26, - "default" => 27, - "extensions" => 28, - "to" => 29, - "max" => 30, - "double" => 31, - "float" => 32, - "int32" => 33, - "int64" => 34, - "uint32" => 35, - "uint64" => 36, - "sint32" => 37, - "sint64" => 38, - "fixed32" => 39, - "fixed64" => 40, - "sfixed32" => 41, - "sfixed64" => 42, - "bool" => 43, - "string" => 44, - "bytes" => 45, - "," => 46, - :FLOAT_LITERAL => 47, - :BOOLEAN_LITERAL => 48, - :DEC_INTEGER => 49, - :HEX_INTEGER => 50, - :OCT_INTEGER => 51 } - -racc_use_result_var = true - -racc_nt_base = 52 - -Racc_arg = [ - racc_action_table, - racc_action_check, - racc_action_default, - racc_action_pointer, - racc_goto_table, - racc_goto_check, - racc_goto_default, - racc_goto_pointer, - racc_nt_base, - racc_reduce_table, - racc_token_table, - racc_shift_n, - racc_reduce_n, - racc_use_result_var ] - -Racc_token_to_s_table = [ -'$end', -'error', -'";"', -'"import"', -'STRING_LITERAL', -'"package"', -'IDENT', -'"."', -'"option"', -'"="', -'"message"', -'"extend"', -'"{"', -'"}"', -'"enum"', -'"service"', -'"rpc"', -'"("', -'")"', -'"returns"', -'"group"', -'CAMEL_IDENT', -'"["', -'"]"', -'"required"', -'"optional"', -'"repeated"', -'"default"', -'"extensions"', -'"to"', -'"max"', -'"double"', -'"float"', -'"int32"', -'"int64"', -'"uint32"', -'"uint64"', -'"sint32"', -'"sint64"', -'"fixed32"', -'"fixed64"', -'"sfixed32"', -'"sfixed64"', -'"bool"', -'"string"', -'"bytes"', -'","', -'FLOAT_LITERAL', -'BOOLEAN_LITERAL', -'DEC_INTEGER', -'HEX_INTEGER', -'OCT_INTEGER', -'$start', -'proto', -'proto_item', -'message', -'extend', -'enum', -'import', -'package', -'option', -'service', -'dot_ident_list', -'option_body', -'constant', -'message_body', -'user_type', -'extend_body_list', -'extend_body', -'field', -'group', -'enum_body_list', -'enum_body', -'enum_field', -'integer_literal', -'service_body_list', -'service_body', -'rpc', -'rpc_arg', -'message_body_body_list', -'message_body_body', -'extensions', -'label', -'type', -'field_name', -'field_option_list', -'field_option', -'extension', -'comma_extension_list'] - -Racc_debug_parser = false - -##### racc system variables end ##### - - # reduce 0 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 3 - def _reduce_1( val, _values, result ) - result = Protobuf::Node::ProtoNode.new(val) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 5 - def _reduce_2( val, _values, result ) - result.children << val[1] if val[1] - result - end -.,., - - # reduce 3 omitted - - # reduce 4 omitted - - # reduce 5 omitted - - # reduce 6 omitted - - # reduce 7 omitted - - # reduce 8 omitted - - # reduce 9 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 14 - def _reduce_10( val, _values, result ) - result = nil - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 17 - def _reduce_11( val, _values, result ) - result = Protobuf::Node::ImportNode.new(val[1]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 20 - def _reduce_12( val, _values, result ) - result = Protobuf::Node::PackageNode.new(val[2].unshift(val[1])) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 23 - def _reduce_13( val, _values, result ) - result = [] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 25 - def _reduce_14( val, _values, result ) - result << val[2] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 28 - def _reduce_15( val, _values, result ) - result = Protobuf::Node::OptionNode.new(*val[1]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 31 - def _reduce_16( val, _values, result ) - result = [val[1].unshift(val[0]), val[3]] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 34 - def _reduce_17( val, _values, result ) - result = Protobuf::Node::MessageNode.new(val[1], val[2]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 37 - def _reduce_18( val, _values, result ) - result = Protobuf::Node::ExtendNode.new(val[1], val[3]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 40 - def _reduce_19( val, _values, result ) - result = [] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 42 - def _reduce_20( val, _values, result ) - result << val[1] if val[1] - result - end -.,., - - # reduce 21 omitted - - # reduce 22 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 46 - def _reduce_23( val, _values, result ) - result = nil - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 49 - def _reduce_24( val, _values, result ) - result = Protobuf::Node::EnumNode.new(val[1], val[3]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 52 - def _reduce_25( val, _values, result ) - result = [] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 54 - def _reduce_26( val, _values, result ) - result << val[1] if val[1] - result - end -.,., - - # reduce 27 omitted - - # reduce 28 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 58 - def _reduce_29( val, _values, result ) - result = nil - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 61 - def _reduce_30( val, _values, result ) - result = Protobuf::Node::EnumFieldNode.new(val[0], val[2]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 64 - def _reduce_31( val, _values, result ) - result = Protobuf::Node::ServiceNode.new(val[1], val[3]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 67 - def _reduce_32( val, _values, result ) - result = [] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 69 - def _reduce_33( val, _values, result ) - result << val[1] if val[1] - result - end -.,., - - # reduce 34 omitted - - # reduce 35 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 73 - def _reduce_36( val, _values, result ) - result = nil - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 76 - def _reduce_37( val, _values, result ) - result = Protobuf::Node::RpcNode.new(val[1], val[3], val[7]) - result - end -.,., - - # reduce 38 omitted - - # reduce 39 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 82 - def _reduce_40( val, _values, result ) - result = val[1] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 85 - def _reduce_41( val, _values, result ) - result = [] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 87 - def _reduce_42( val, _values, result ) - result << val[1] if val[1] - result - end -.,., - - # reduce 43 omitted - - # reduce 44 omitted - - # reduce 45 omitted - - # reduce 46 omitted - - # reduce 47 omitted - - # reduce 48 omitted - - # reduce 49 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 96 - def _reduce_50( val, _values, result ) - result = nil - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 99 - def _reduce_51( val, _values, result ) - result = Protobuf::Node::GroupNode.new(val[0], val[2], val[4], val[5]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 102 - def _reduce_52( val, _values, result ) - result = Protobuf::Node::FieldNode.new(val[0], val[1], val[2], val[4]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 104 - def _reduce_53( val, _values, result ) - result = Protobuf::Node::FieldNode.new(val[0], val[1], val[2], val[4], val[6]) - result - end -.,., - - # reduce 54 omitted - - # reduce 55 omitted - - # reduce 56 omitted - - # reduce 57 omitted - - # reduce 58 omitted - - # reduce 59 omitted - - # reduce 60 omitted - - # reduce 61 omitted - - # reduce 62 omitted - - # reduce 63 omitted - - # reduce 64 omitted - - # reduce 65 omitted - - # reduce 66 omitted - - # reduce 67 omitted - - # reduce 68 omitted - - # reduce 69 omitted - - # reduce 70 omitted - - # reduce 71 omitted - - # reduce 72 omitted - - # reduce 73 omitted - - # reduce 74 omitted - - # reduce 75 omitted - - # reduce 76 omitted - - # reduce 77 omitted - - # reduce 78 omitted - - # reduce 79 omitted - - # reduce 80 omitted - - # reduce 81 omitted - - # reduce 82 omitted - - # reduce 83 omitted - - # reduce 84 omitted - - # reduce 85 omitted - - # reduce 86 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 109 - def _reduce_87( val, _values, result ) - result = val - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 111 - def _reduce_88( val, _values, result ) - result << val[2] - result - end -.,., - - # reduce 89 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 115 - def _reduce_90( val, _values, result ) - result = [:default, val[2]] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 118 - def _reduce_91( val, _values, result ) - result = Protobuf::Node::ExtensionsNode.new(val[2].unshift(val[1])) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 121 - def _reduce_92( val, _values, result ) - result = [] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 123 - def _reduce_93( val, _values, result ) - result << val[1] - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 126 - def _reduce_94( val, _values, result ) - result = Protobuf::Node::ExtensionRangeNode.new(val[0]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 128 - def _reduce_95( val, _values, result ) - result = Protobuf::Node::ExtensionRangeNode.new(val[0], val[2]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 130 - def _reduce_96( val, _values, result ) - result = Protobuf::Node::ExtensionRangeNode.new(val[0], :max) - result - end -.,., - - # reduce 97 omitted - - # reduce 98 omitted - - # reduce 99 omitted - - # reduce 100 omitted - - # reduce 101 omitted - - # reduce 102 omitted - - # reduce 103 omitted - - # reduce 104 omitted - - # reduce 105 omitted - - # reduce 106 omitted - - # reduce 107 omitted - - # reduce 108 omitted - - # reduce 109 omitted - - # reduce 110 omitted - - # reduce 111 omitted - - # reduce 112 omitted - - # reduce 113 omitted - - # reduce 114 omitted - - # reduce 115 omitted - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 141 - def _reduce_116( val, _values, result ) - result = val[1].unshift(val[0]) - result - end -.,., - -module_eval <<'.,.,', 'lib/protobuf/compiler/proto.y', 143 - def _reduce_117( val, _values, result ) - result = val[1].unshift(val[0]) - result - end -.,., - - # reduce 118 omitted - - # reduce 119 omitted - - # reduce 120 omitted - - # reduce 121 omitted - - # reduce 122 omitted - - # reduce 123 omitted - - # reduce 124 omitted - - # reduce 125 omitted - - def _reduce_none( val, _values, result ) - result - end - - end # class ProtoParser - -end # module Protobuf diff --git a/lib/protobuf/compiler/template/rpc_service_implementation.erb b/lib/protobuf/compiler/template/rpc_service_implementation.erb deleted file mode 100644 index 4c295e57..00000000 --- a/lib/protobuf/compiler/template/rpc_service_implementation.erb +++ /dev/null @@ -1,42 +0,0 @@ -<%- -module_array = module_name.split('::') -class_indent = ' '*(module_array.size) --%> -require 'protobuf/rpc/service' -require '<%= required_file %>' - -## !! DO NOT EDIT THIS FILE !! -## -## To implement this service as defined by the protobuf, simply -## reopen <%= module_name %>::<%= service_name %> and implement each service method: -## -<%- module_array.each_with_index do |m, i| -%> -## <%= "#{"\t"*i}module #{m}" %> -<%- end -%> -## <%= class_indent %>class <%= service_name %> -## <%= class_indent %> -<%- rpcs.each do |name, request, response| -%> -## <%= class_indent %> # request -> <%= module_name %>::<%= request %> -## <%= class_indent %> # response -> <%= module_name %>::<%= response %> -## <%= class_indent %> def <%= Util.underscore(name) %> -## <%= class_indent %> # TODO: implement <%= Util.underscore(name) %> -## <%= class_indent %> end -## <%= class_indent %> -<%- end -%> -## <%= class_indent %>end -<%- (module_array.size-1).downto(0) do |i| -%> -## <%= "#{"\t"*i}end" %> -<%- end -%> -## - -<%- module_array.each_with_index do |m, i| -%> -<%= "#{"\t"*i}module #{m}" %> -<%- end -%> -<%= class_indent %>class <%= service_name %> < Protobuf::Rpc::Service -<%- rpcs.each do |name, request, response| -%> -<%= class_indent %> rpc :<%= Util.underscore(name) %>, <%= request %>, <%= response %> -<%- end -%> -<%= class_indent %>end -<%- (module_array.size-1).downto(0) do |i| -%> -<%= "#{"\t"*i}end" %> -<%- end -%> diff --git a/lib/protobuf/compiler/visitors.rb b/lib/protobuf/compiler/visitors.rb deleted file mode 100644 index 807d5c39..00000000 --- a/lib/protobuf/compiler/visitors.rb +++ /dev/null @@ -1,282 +0,0 @@ -require 'erb' -require 'fileutils' -require 'protobuf/descriptor/descriptor_proto' - -module Protobuf - module Visitor - class Base - attr_reader :silent - - def create_file_with_backup(filename, contents, executable=false) - if File.exist?(filename) - if File.read(filename) == contents - # do nothing - return - else - backup_filename = "#{filename}.#{Time.now.to_i}" - log_writing("#{backup_filename}", "backingup...") - FileUtils.copy(filename, backup_filename) - end - end - - FileUtils.mkpath(File.dirname(filename)) - File.open(filename, 'w') do |file| - log_writing(filename) - file.write(contents) - end - FileUtils.chmod(0755, filename) if executable - end - - def log_writing(filename, message="wrote") - puts "#{message} #{filename}" unless silent - end - end - - class CreateMessageVisitor < Base - attr_accessor :package, :indent, :context, :attach_proto, :proto_file - - def initialize(proto_file=nil, proto_dir='.', out_dir='.') - @proto_dir, @out_dir = proto_dir, out_dir - @indent = 0 - @context = [] - @attach_proto = false - @proto_file = proto_file - end - - def attach_proto? - @attach_proto - end - - def commented_proto_contents - if proto_file - proto_filepath = if File.exist?(proto_file) - then proto_file - else "#{@proto_dir}/#{proto_file}" - end - File.read(proto_filepath).gsub(/^/, '# ') - end - end - - def write(str) - ruby << "#{' ' * @indent}#{str}" - end - - def increment - @indent += 1 - end - - def decrement - @indent -= 1 - end - - def close_ruby - while 0 < indent - decrement - write('end') - end - end - - def ruby - @ruby ||= [] - end - - def to_s - @ruby.join("\n") - end - - def in_context(klass, &block) - increment - context.push klass - block.call - context.pop - decrement - end - - def visit(node) - node.accept_message_visitor(self) - self - end - - def required_message_from_proto(proto_file) - rb_path = [ - proto_file.sub(/\.proto\z/, '.pb.rb') - ].join('/').gsub(/\/{2,}/, '/') - - unless File.exist?(rb_path) - Compiler.compile(proto_file, @proto_dir, @out_dir) - end - - rb_path.sub(/\.rb$/, '') - end - - def create_files(filename, out_dir, file_create) - $: << File.expand_path(out_dir) - Class.new.class_eval(to_s) # check the message - $:.delete File.expand_path(out_dir) - rescue LoadError - puts "Error creating file #{filename}" - puts $!.message - exit 1 - else - - file = File.basename(filename) - message_module = Util.module_to_path(package.map{|p| p.to_s.capitalize}.join('::')) - filename = "#{out_dir}/#{message_module}/#{file}" - - if file_create - log_writing(filename) - FileUtils.mkpath(File.dirname(filename)) - File.open(filename, 'w') {|file| file.write(to_s) } - else - to_s - end - end - end - - class CreateRpcVisitor < Base - attr_accessor :package, :services, :current_service, :file_contents - - def initialize - @services = {} - @create_file = true - @file_contents = {} - end - - def visit(node) - node.accept_rpc_visitor(self) - self - end - - def add_rpc(name, request, response) - (@services[@current_service] ||= []) << [name, Util.moduleize(request), Util.moduleize(response)] - end - - def create_files(message_file, out_dir, create_file=true) - @create_file = create_file - @services.each do |service_name, rpcs| - underscored_name = Util.underscore(service_name.to_s) - message_module = package.map{|p| p.to_s.capitalize}.join('::') - required_file = [ - Util.module_to_path(message_module), - File.basename(message_file, '.rb') - ].join('/').gsub(/\/{2,}/, '/') - - create_service(message_file, out_dir, underscored_name, message_module, service_name, rpcs, required_file) - end - @file_contents - end - - def create_service(message_file, out_dir, underscored_name, module_name, service_name, rpcs, required_file) - service_filename = "#{out_dir}/#{Util.module_to_path(module_name)}/#{underscored_name}.rb" - service_contents = template_erb('rpc_service_implementation').result(binding) - create_file_with_backup(service_filename, service_contents) if @create_file - @file_contents[service_filename] = service_contents - end - - private - - def template_erb(template) - ERB.new(File.read("#{File.dirname(__FILE__)}/template/#{template}.erb"), nil, '-') - end - end - - class CreateDescriptorVisitor < Base - attr_reader :file_descriptor - attr_accessor :filename - - def initialize(filename=nil) - @context = [] - @filename = filename - end - - def visit(node) - node.accept_descriptor_visitor(self) - self - end - - def in_context(descriptor, &block) - @context.push descriptor - block.call - @context.pop - end - - def current_descriptor - @context.last - end - - def file_descriptor=(descriptor) - @file_descriptor = descriptor - @file_descriptor.name = @filename - end - - def add_option(name, value) - options = - case current_descriptor - when Google::Protobuf::FileDescriptorProto then - Google::Protobuf::FileOptions.new - when Google::Protobuf::DescriptorProto then - Google::Protobuf::MessageOptions.new - when Google::Protobuf::FieldDescriptorProto then - Google::Protobuf::FieldOptions.new - when Google::Protobuf::EnumDescriptorProto then - Google::Protobuf::EnumOptions.new - when Google::Protobuf::EnumValueDescriptorProto then - Google::Protobuf::EnumValueOptions.new - when Google::Protobuf::ServiceDescriptorProto then - Google::Protobuf::ServiceOptions.new - when Google::Protobuf::MethodDescriptorProto then - Google::Protobuf::MethodOptions.new - else - raise ArgumentError, 'Invalid context' - end - #TODO how should options be handled? - #current_descriptor.options << option - end - - def descriptor=(descriptor) - case current_descriptor - when Google::Protobuf::FileDescriptorProto then - current_descriptor.message_type << descriptor - when Google::Protobuf::DescriptorProto then - current_descriptor.nested_type << descriptor - else - raise ArgumentError, 'Invalid context' - end - end - alias message_descriptor= descriptor= - - def enum_descriptor=(descriptor) - current_descriptor.enum_type << descriptor - end - - def enum_value_descriptor=(descriptor) - current_descriptor.value << descriptor - end - - def service_descriptor=(descriptor) - current_descriptor.service << descriptor - end - - def method_descriptor=(descriptor) - current_descriptor.method << descriptor - end - - def field_descriptor=(descriptor) - case current_descriptor - when Google::Protobuf::FileDescriptorProto then - current_descriptor.extension << descriptor - when Google::Protobuf::DescriptorProto then - current_descriptor.field << descriptor - #TODO: how should i distiguish between field and extension - #current_descriptor.extension << descriptor - else - raise ArgumentError, 'Invalid context' - end - end - - def extension_range_descriptor=(descriptor) - current_descriptor.extension_range << descriptor - end - end - end -end diff --git a/test/test_compiler.rb b/test/test_compiler.rb deleted file mode 100644 index 055c18f6..00000000 --- a/test/test_compiler.rb +++ /dev/null @@ -1,325 +0,0 @@ -require 'test/unit' -require 'protobuf/compiler/compiler' - -class CompilerTest < Test::Unit::TestCase - # Issue 12: Parse error on float default value - def test_compile_float_default - assert_compile_proto(<<-EOS, 'test/proto/float_default.proto') -### Generated by rprotoc. DO NOT EDIT! -### -# message M { -# optional float f = 1 [default = 4.2]; -# optional float g = 2 [default = -4.2]; -# optional float h = 3 [default = 4352]; -# optional float i = 4 [default = 23145.2 ]; -# optional float j = 5 [default = -5 ]; -# optional float k = 6 [default = +23 ]; -# optional float l = 7 [default = +23.42 ]; -# } -# - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -class M < ::Protobuf::Message - defined_in __FILE__ - optional :float, :f, 1, :default => 4.2 - optional :float, :g, 2, :default => -4.2 - optional :float, :h, 3, :default => 4352 - optional :float, :i, 4, :default => 23145.2 - optional :float, :j, 5, :default => -5 - optional :float, :k, 6, :default => 23 - optional :float, :l, 7, :default => 23.42 -end - EOS - end - - def test_create_message - assert_compile_proto(<<-EOS, 'test/proto/addressbook.proto') -### Generated by rprotoc. DO NOT EDIT! -### -# package tutorial; -# -# message Person { -# required string name = 1; -# required int32 id = 2; -# optional string email = 3; -# -# enum PhoneType { -# MOBILE = 0; -# HOME = 1; -# WORK = 2; -# } -# -# message PhoneNumber { -# required string number = 1; -# optional PhoneType type = 2 [default = HOME]; -# } -# -# repeated PhoneNumber phone = 4; -# optional uint32 age = 5 [default = 20]; -# -# extensions 100 to 200; -# } -# -# /* -# extend Person { -# optional int32 age = 100; -# } -# */ -# -# message AddressBook { -# repeated Person person = 1; -# } -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Tutorial - - class Person < ::Protobuf::Message - defined_in __FILE__ - required :string, :name, 1 - required :int32, :id, 2 - optional :string, :email, 3 - - class PhoneType < ::Protobuf::Enum - defined_in __FILE__ - define :MOBILE, 0 - define :HOME, 1 - define :WORK, 2 - end - - class PhoneNumber < ::Protobuf::Message - defined_in __FILE__ - required :string, :number, 1 - optional :PhoneType, :type, 2, :default => :HOME - end - - repeated :PhoneNumber, :phone, 4 - optional :uint32, :age, 5, :default => 20 - - extensions 100..200 - end - - class AddressBook < ::Protobuf::Message - defined_in __FILE__ - repeated :Person, :person, 1 - end -end - EOS - end - - def test_create_nested_message - assert_compile_proto(<<-EOS, 'test/proto/nested.proto') -### Generated by rprotoc. DO NOT EDIT! -### -# package test.nested; -# -# message Foo { -# message Bar { -# } -# } -# message Baaz { -# optional Foo.Bar x = 1; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Test - module Nested - class Foo < ::Protobuf::Message - defined_in __FILE__ - class Bar < ::Protobuf::Message - defined_in __FILE__ - end - end - class Baaz < ::Protobuf::Message - defined_in __FILE__ - optional :'Foo::Bar', :x, 1 - end - end -end - EOS - end - - def test_nested_message - file_contents = Protobuf::Compiler.new.create_message('test/proto/nested.proto', '.', '.', false) - assert_nothing_raised {Object.class_eval file_contents} - assert_raise(TypeError) {Test::Nested::Baaz.new.x = 1} - assert_nothing_raised {Test::Nested::Baaz.new.x = Test::Nested::Foo::Bar.new} - end - - def test_create_rpc - file_contents = Protobuf::Compiler.new.create_rpc('test/proto/rpc.proto', '.', 'test/proto', false) - - assert_source(<<-EOS, file_contents['test/proto/address_book_service.rb']) -require 'protobuf/rpc/server' -require 'protobuf/rpc/handler' -require 'test/proto/rpc.pb' - -class Tutorial::SearchHandler < Protobuf::Rpc::Handler - request Tutorial::Person - response Tutorial::AddressBook - - def self.process_request(request, response) - # TODO: edit this method - end -end - -class Tutorial::AddHandler < Protobuf::Rpc::Handler - request Tutorial::Person - response Tutorial::Person - - def self.process_request(request, response) - # TODO: edit this method - end -end - -class Tutorial::AddressBookService < Protobuf::Rpc::Server - def setup_handlers - @handlers = { - :search => Tutorial::SearchHandler, - :add => Tutorial::AddHandler, - } - end -end - EOS - - assert_source(<<-EOS, file_contents['test/proto/start_address_book_service']) -#!/usr/bin/env ruby -require 'address_book_service' - -Tutorial::AddressBookService.new(:Port => 9999).start - EOS - - assert_source(<<-EOS, file_contents['test/proto/client_search.rb']) -#!/usr/bin/env ruby -require 'protobuf/rpc/client' -require 'test/proto/rpc.pb' - -# build request -request = Tutorial::Person.new -# TODO: setup a request -raise StandardError, 'setup a request' - -# create blunk response -response = Tutorial::AddressBook.new - -# execute rpc -Protobuf::Rpc::Client.new('localhost', 9999).call :search, request, response - -# show response -puts response - EOS - - assert_source(<<-EOS, file_contents['test/proto/client_add.rb']) -#!/usr/bin/env ruby -require 'protobuf/rpc/client' -require 'test/proto/rpc.pb' - -# build request -request = Tutorial::Person.new -# TODO: setup a request -raise StandardError, 'setup a request' - -# create blunk response -response = Tutorial::Person.new - -# execute rpc -Protobuf::Rpc::Client.new('localhost', 9999).call :add, request, response - -# show response -puts response - EOS - end - - def test_create_descriptor - proto_path = 'test/proto/addressbook.proto' - visitor = Protobuf::Visitor::CreateDescriptorVisitor.new(proto_path) - File.open(proto_path) do |file| - visitor.visit Protobuf::ProtoParser.new.parse(file) - end - file_descriptor = visitor.file_descriptor - assert_equal(proto_path, file_descriptor.name) - assert_equal('tutorial', file_descriptor.package) - - person_descriptor = file_descriptor.message_type[0] - assert_equal('Person', person_descriptor.name) - assert_equal([:name, :id, :email, :phone, :age].size, person_descriptor.field.size) - - name_field_descriptor = person_descriptor.field.find {|d| d.name == 'name'} - assert_equal(1, name_field_descriptor.number) - assert_equal(Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING, name_field_descriptor.type) - assert_equal(Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED, name_field_descriptor.label) - assert_equal('string', name_field_descriptor.type_name) - - phone_field_descriptor = person_descriptor.field.find {|d| d.name == 'phone'} - assert_equal(4, phone_field_descriptor.number) - assert_equal(0, phone_field_descriptor.type) #TODO: is this right? - assert_equal(Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED, phone_field_descriptor.label) - assert_equal('PhoneNumber', phone_field_descriptor.type_name) - - age_field_descriptor = person_descriptor.field.find {|d| d.name == 'age'} - assert_equal(5, age_field_descriptor.number) - assert_equal(Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32, age_field_descriptor.type) - assert_equal(Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL, age_field_descriptor.label) - assert_equal('uint32', age_field_descriptor.type_name) - assert_equal('20', age_field_descriptor.default_value) - - phone_type_descriptor = person_descriptor.enum_type.first - assert_equal('PhoneType', phone_type_descriptor.name) - assert_equal(3, phone_type_descriptor.value.size) - - phone_type_home_descriptor = phone_type_descriptor.value.find {|d| d.name == 'HOME'} - assert_equal('HOME', phone_type_home_descriptor.name) - assert_equal(1, phone_type_home_descriptor.number) - - extensions_descriptor = person_descriptor.extension_range.first - assert_equal(100, extensions_descriptor.start) - assert_equal(200, extensions_descriptor.end) - - phone_number_descriptor = person_descriptor.nested_type.first - assert_equal('PhoneNumber', phone_number_descriptor.name) - assert_equal([:number, :type].size, phone_number_descriptor.field.size) - - #TODO: test extend - #extend_person_descriptor = ?? - #assert_equal extend_person_descriptor - - addressbook_descriptor = file_descriptor.message_type[1] - assert_equal('AddressBook', addressbook_descriptor.name) - end - - def test_collision - assert_raise(Protobuf::TagCollisionError) do require 'test/proto/collision.pb' end - assert_raise(Protobuf::TagCollisionError) do - Protobuf::Compiler.new.create_message('test/proto/collision.proto', '.', '.', false) - end - end - - def test_ext_collision - assert_raise(Protobuf::TagCollisionError) do require 'test/proto/ext_collision.pb' end - assert_raise(Protobuf::TagCollisionError) do - Protobuf::Compiler.new.create_message('test/proto/ext_collision.proto', '.', '.', false) - end - end - - def test_ext_range - assert_raise(RangeError) do require 'test/proto/ext_range.pb' end - assert_raise(RangeError) do - Protobuf::Compiler.new.create_message('test/proto/ext_range.proto', '.', '.', false) - end - end - - def assert_compile_proto(ideal, filename) - assert_equal(ideal.gsub(/^\s*\n/, '').strip, Protobuf::Compiler.new.create_message(filename, '.', '.', false).gsub(/^\s*\n/, '').strip) - end - - def assert_source(ideal, real) - assert_equal(ideal.strip.gsub(/^\s*\n/, '').gsub(/\s+\n/, "\n"), real.strip.gsub(/^\s*\n/, '').gsub(/\s+\n/, "\n")) - end -end From 7cd88f8e1aae447db0a29c03cfeb78b5071ace1b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Sep 2012 15:35:45 -0600 Subject: [PATCH 0092/1191] update gemspec to not force eventmachine or ffi-rzmq, those are individual requirements --- Gemfile.lock | 12 ++++++------ protobuf.gemspec | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index faff7603..0dbbd19e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,10 +2,7 @@ PATH remote: . specs: protobuf (1.4.2) - eventmachine - eventually - ffi-rzmq - json_pure + multi_json thor GEM @@ -14,11 +11,9 @@ GEM coderay (1.0.7) diff-lcs (1.1.3) eventmachine (1.0.0) - eventually (0.1.1) ffi (1.1.5) ffi-rzmq (0.9.6) ffi - json_pure (1.7.5) method_source (0.8) multi_json (1.3.6) pry (0.9.10) @@ -28,6 +23,8 @@ GEM pry-nav (0.2.2) pry (~> 0.9.10) rake (0.9.2.2) + rake-compiler (0.8.1) + rake rspec (2.11.0) rspec-core (~> 2.11.0) rspec-expectations (~> 2.11.0) @@ -48,10 +45,13 @@ PLATFORMS ruby DEPENDENCIES + eventmachine + ffi-rzmq protobuf! pry pry-nav rake + rake-compiler rspec simplecov yard diff --git a/protobuf.gemspec b/protobuf.gemspec index bc8e2f51..fc21e09b 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -18,16 +18,16 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'eventmachine' - s.add_dependency 'eventually' - s.add_dependency 'json_pure' - s.add_dependency 'ffi-rzmq' + s.add_dependency 'multi_json' s.add_dependency 'thor' - s.add_development_dependency 'rake' + s.add_development_dependency 'eventmachine' + s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' + s.add_development_dependency 'rake' + s.add_development_dependency 'rake-compiler' s.add_development_dependency 'rspec' - s.add_development_dependency 'yard' s.add_development_dependency 'simplecov' + s.add_development_dependency 'yard' end From 1feecab7a17f42ec5ccb6d0786ff79e95d3481cd Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Sep 2012 15:57:35 -0600 Subject: [PATCH 0093/1191] update gemspec to use ffi for binding to compiler --- protobuf.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/protobuf.gemspec b/protobuf.gemspec index fc21e09b..64e21803 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] + s.add_dependency 'ffi' s.add_dependency 'multi_json' s.add_dependency 'thor' From 0d4932a67017d86dcfefbbbc1b82289c73140aab Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Sep 2012 15:58:14 -0600 Subject: [PATCH 0094/1191] add extern interface to get the .so binding from ffi --- ext/RubyGenerator.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ext/RubyGenerator.h b/ext/RubyGenerator.h index 87b108ce..1f76701c 100644 --- a/ext/RubyGenerator.h +++ b/ext/RubyGenerator.h @@ -158,4 +158,22 @@ class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { } // namespace protobuf } // namespace google +#ifdef __cplusplus +extern "C" { +#endif + +int _rprotoc_extern(int argc, char* argv[]) { + google::protobuf::compiler::CommandLineInterface cli; + + google::protobuf::compiler::ruby::RubyGenerator ruby_generator; + cli.RegisterGenerator("--ruby_out", &ruby_generator, + "Generate Ruby-compatible protobuf message and service classes."); + + return cli.Run(argc, argv); +} + +#ifdef __cplusplus +} +#endif + #endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H From 5eff3f7e7dce2ec5cee11f31a87c4b6d61d19797 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Sep 2012 18:28:15 -0600 Subject: [PATCH 0095/1191] only release with header files --- .gitignore | 2 + Gemfile.lock | 1 + Rakefile | 7 + bin/rprotoc | 77 +- ext/main.cpp | 13 - .../google/protobuf/compiler/code_generator.h | 142 + .../compiler/command_line_interface.h | 318 + .../google/protobuf/compiler/cpp/cpp_enum.h | 99 + .../protobuf/compiler/cpp/cpp_enum_field.h | 103 + .../protobuf/compiler/cpp/cpp_extension.h | 85 + .../google/protobuf/compiler/cpp/cpp_field.h | 167 + .../google/protobuf/compiler/cpp/cpp_file.h | 98 + .../protobuf/compiler/cpp/cpp_generator.h | 72 + .../protobuf/compiler/cpp/cpp_helpers.h | 159 + .../protobuf/compiler/cpp/cpp_message.h | 170 + .../protobuf/compiler/cpp/cpp_message_field.h | 102 + .../compiler/cpp/cpp_primitive_field.h | 103 + .../protobuf/compiler/cpp/cpp_service.h | 118 + .../protobuf/compiler/cpp/cpp_string_field.h | 104 + .../cpp/cpp_test_bad_identifiers.pb.h | 2721 ++++ .../src/google/protobuf/compiler/importer.h | 303 + .../google/protobuf/compiler/java/java_enum.h | 84 + .../protobuf/compiler/java/java_enum_field.h | 121 + .../protobuf/compiler/java/java_extension.h | 77 + .../protobuf/compiler/java/java_field.h | 108 + .../google/protobuf/compiler/java/java_file.h | 101 + .../protobuf/compiler/java/java_generator.h | 72 + .../protobuf/compiler/java/java_helpers.h | 213 + .../protobuf/compiler/java/java_message.h | 109 + .../compiler/java/java_message_field.h | 134 + .../compiler/java/java_primitive_field.h | 121 + .../protobuf/compiler/java/java_service.h | 113 + .../compiler/java/java_string_field.h | 120 + .../protobuf/compiler/mock_code_generator.h | 113 + .../google/protobuf/compiler/package_info.h | 64 + .../src/google/protobuf/compiler/parser.h | 434 + .../src/google/protobuf/compiler/plugin.h | 73 + .../src/google/protobuf/compiler/plugin.pb.h | 790 + .../compiler/python/python_generator.h | 156 + .../src/google/protobuf/compiler/subprocess.h | 108 + .../src/google/protobuf/compiler/zip_writer.h | 93 + .../src/google/protobuf/descriptor.h | 1367 ++ .../src/google/protobuf/descriptor.pb.h | 5223 +++++++ .../src/google/protobuf/descriptor_database.h | 366 + .../src/google/protobuf/dynamic_message.h | 136 + .../src/google/protobuf/extension_set.h | 904 ++ .../protobuf/generated_message_reflection.h | 424 + .../google/protobuf/generated_message_util.h | 82 + .../src/google/protobuf/io/coded_stream.h | 1102 ++ .../src/google/protobuf/io/coded_stream_inl.h | 64 + .../src/google/protobuf/io/gzip_stream.h | 207 + .../src/google/protobuf/io/package_info.h | 54 + .../src/google/protobuf/io/printer.h | 136 + .../src/google/protobuf/io/tokenizer.h | 313 + .../src/google/protobuf/io/zero_copy_stream.h | 238 + .../protobuf/io/zero_copy_stream_impl.h | 357 + .../protobuf/io/zero_copy_stream_impl_lite.h | 340 + .../src/google/protobuf/message.h | 692 + .../src/google/protobuf/message_lite.h | 239 + .../src/google/protobuf/package_info.h | 64 + .../src/google/protobuf/reflection_ops.h | 80 + .../src/google/protobuf/repeated_field.h | 1295 ++ .../src/google/protobuf/service.h | 291 + .../src/google/protobuf/stubs/common.h | 1211 ++ .../src/google/protobuf/stubs/hash.h | 220 + .../src/google/protobuf/stubs/map-util.h | 119 + .../src/google/protobuf/stubs/once.h | 123 + .../src/google/protobuf/stubs/stl_util-inl.h | 121 + .../src/google/protobuf/stubs/strutil.h | 457 + .../src/google/protobuf/stubs/substitute.h | 170 + .../src/google/protobuf/test_util.h | 174 + .../src/google/protobuf/test_util_lite.h | 101 + .../src/google/protobuf/testing/file.h | 83 + .../src/google/protobuf/testing/googletest.h | 98 + .../src/google/protobuf/text_format.h | 285 + .../src/google/protobuf/unittest.pb.h | 11915 ++++++++++++++++ .../protobuf/unittest_custom_options.pb.h | 2895 ++++ .../protobuf/unittest_embed_optimize_for.pb.h | 211 + .../src/google/protobuf/unittest_empty.pb.h | 56 + .../src/google/protobuf/unittest_import.pb.h | 188 + .../google/protobuf/unittest_import_lite.pb.h | 151 + .../src/google/protobuf/unittest_lite.pb.h | 4752 ++++++ .../unittest_lite_imports_nonlite.pb.h | 150 + .../src/google/protobuf/unittest_mset.pb.h | 816 ++ .../unittest_no_generic_services.pb.h | 197 + .../protobuf/unittest_optimize_for.pb.h | 403 + .../src/google/protobuf/unknown_field_set.h | 268 + .../src/google/protobuf/wire_format.h | 304 + .../src/google/protobuf/wire_format_lite.h | 620 + .../google/protobuf/wire_format_lite_inl.h | 774 + ext/{ => ruby_generator}/RubyGenerator.cpp | 0 ext/{ => ruby_generator}/RubyGenerator.h | 1 + ext/ruby_generator/extconf.rb | 131 + lib/ruby_generator.so | Bin 0 -> 310588 bytes protobuf.gemspec | 1 + 95 files changed, 49086 insertions(+), 51 deletions(-) delete mode 100644 ext/main.cpp create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/descriptor.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/extension_set.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/printer.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/message.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/message_lite.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/package_info.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/service.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/test_util.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/testing/file.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/text_format.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/wire_format.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h create mode 100644 ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h rename ext/{ => ruby_generator}/RubyGenerator.cpp (100%) rename ext/{ => ruby_generator}/RubyGenerator.h (98%) create mode 100644 ext/ruby_generator/extconf.rb create mode 100644 lib/ruby_generator.so diff --git a/.gitignore b/.gitignore index 1eeb6209..da761fa8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,7 @@ coverage doc .yardoc .DS_Store +*.so *.bin Gemfile.lock +tmp/* diff --git a/Gemfile.lock b/Gemfile.lock index 0dbbd19e..5e215519 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: protobuf (1.4.2) + ffi multi_json thor diff --git a/Rakefile b/Rakefile index b4b50bb7..dbf9b7f6 100644 --- a/Rakefile +++ b/Rakefile @@ -18,3 +18,10 @@ task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new(:spec) + +## +# Rake-compiler +# +require 'rake/extensiontask' + +Rake::ExtensionTask.new("ruby_generator") diff --git a/bin/rprotoc b/bin/rprotoc index e0b32b9a..4a9cee78 100755 --- a/bin/rprotoc +++ b/bin/rprotoc @@ -1,46 +1,47 @@ #!/usr/bin/env ruby -require 'optparse' +require 'rubygems' +require 'ffi' + +generator_file = File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "ruby_generator.so") + +unless File.exists?(generator_file) + $stdout << <<-WARNING + Cannot locate shared object to plugin to protocol buffers generator. + Thought the file would be located at #{generator_file} + + If you are running on Jruby or Windows you should compile protocol buffer + definitions on another computer and then use those definitions locally. + + Only the compiler is restricted by this. The definitions should work without issue. + WARNING -if File.directory?("#{File.dirname(__FILE__)}/../lib") - $: << "#{File.dirname(__FILE__)}/../lib" -else - require 'rubygems' - gem 'protobuf' -end -require 'protobuf' -require 'protobuf/version' -require 'protobuf/compiler/compiler' - -::Version = Protobuf::VERSION - -options = { - :proto_path => '.', - :out => '.', -} -opts = OptionParser.new("#{$0} [OPTIONS] PROTO_FILE") -opts.on('-p', '--proto_path ', 'Specify the directory in which to search for imports. The current directory is default.'){|v| options[:proto_path] = v} -opts.on('-o', '--out ', 'Specify the directory in which Ruby source file is generated. The current directory is default.'){|v| options[:out] = v} -opts.on_tail('-v', '--version', 'Show version.'){ puts(opts.ver); exit } -opts.on_tail('-h', '--help', 'Show this message.'){ puts(opts.help); exit } - -begin - opts.order! -rescue OptionParser::ParseError - $stderr.puts $!.to_s exit 1 end -unless ARGV.size > 0 - puts opts - exit -end +module Protobuf + module RProtoC + extend FFI::Library + ffi_lib generator_file + attach_function :_rprotoc_extern, [:int32, :pointer], :int32 -begin - ARGV.each do |proto_file| - Protobuf::Compiler.compile(proto_file, options[:proto_path], options[:out]) + def self.compile_proto(args) + args.unshift("protoc-ruby") + + ptr_params = [] + args.each do |param| + ptr_params << ::FFI::MemoryPointer.from_string(param) + end + ptr_params << nil + + argv = ::FFI::MemoryPointer.new(:pointer, ptr_params.size) + ptr_params.each_with_index do |param_pointer, index| + argv[index].put_pointer(0, param_pointer) + end + + self._rprotoc_extern(argv.size, argv) + end end -rescue - $stderr.puts $!.message - exit 1 -end \ No newline at end of file +end + +::Protobuf::RProtoC.compile_proto(ARGV.dup) diff --git a/ext/main.cpp b/ext/main.cpp deleted file mode 100644 index c0590f8c..00000000 --- a/ext/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "RubyGenerator.h" - -int main (int argc, char* argv[]) { - google::protobuf::compiler::CommandLineInterface cli; - - // Support generation of C++ source and headers. - google::protobuf::compiler::ruby::RubyGenerator ruby_generator; - cli.RegisterGenerator("--ruby_out", &ruby_generator, - "Generate Ruby-compatible protobuf message and service classes."); - - return cli.Run(argc, argv); -} diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h new file mode 100644 index 00000000..252f68d1 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h @@ -0,0 +1,142 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Defines the abstract interface implemented by each of the language-specific +// code generators. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ + +#include +#include +#include +#include + +namespace google { +namespace protobuf { + +namespace io { class ZeroCopyOutputStream; } +class FileDescriptor; + +namespace compiler { + +// Defined in this file. +class CodeGenerator; +class GeneratorContext; + +// The abstract interface to a class which generates code implementing a +// particular proto file in a particular language. A number of these may +// be registered with CommandLineInterface to support various languages. +class LIBPROTOC_EXPORT CodeGenerator { + public: + inline CodeGenerator() {} + virtual ~CodeGenerator(); + + // Generates code for the given proto file, generating one or more files in + // the given output directory. + // + // A parameter to be passed to the generator can be specified on the + // command line. This is intended to be used by Java and similar languages + // to specify which specific class from the proto file is to be generated, + // though it could have other uses as well. It is empty if no parameter was + // given. + // + // Returns true if successful. Otherwise, sets *error to a description of + // the problem (e.g. "invalid parameter") and returns false. + virtual bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* generator_context, + string* error) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); +}; + +// CodeGenerators generate one or more files in a given directory. This +// abstract interface represents the directory to which the CodeGenerator is +// to write and other information about the context in which the Generator +// runs. +class LIBPROTOC_EXPORT GeneratorContext { + public: + inline GeneratorContext() {} + virtual ~GeneratorContext(); + + // Opens the given file, truncating it if it exists, and returns a + // ZeroCopyOutputStream that writes to the file. The caller takes ownership + // of the returned object. This method never fails (a dummy stream will be + // returned instead). + // + // The filename given should be relative to the root of the source tree. + // E.g. the C++ generator, when generating code for "foo/bar.proto", will + // generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that + // "foo/" is included in these filenames. The filename is not allowed to + // contain "." or ".." components. + virtual io::ZeroCopyOutputStream* Open(const string& filename) = 0; + + // Creates a ZeroCopyOutputStream which will insert code into the given file + // at the given insertion point. See plugin.proto (plugin.pb.h) for more + // information on insertion points. The default implementation + // assert-fails -- it exists only for backwards-compatibility. + // + // WARNING: This feature is currently EXPERIMENTAL and is subject to change. + virtual io::ZeroCopyOutputStream* OpenForInsert( + const string& filename, const string& insertion_point); + + // Returns a vector of FileDescriptors for all the files being compiled + // in this run. Useful for languages, such as Go, that treat files + // differently when compiled as a set rather than individually. + virtual void ListParsedFiles(vector* output); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext); +}; + +// The type GeneratorContext was once called OutputDirectory. This typedef +// provides backward compatibility. +typedef GeneratorContext OutputDirectory; + +// Several code generators treat the parameter argument as holding a +// list of options separated by commas. This helper function parses +// a set of comma-delimited name/value pairs: e.g., +// "foo=bar,baz,qux=corge" +// parses to the pairs: +// ("foo", "bar"), ("baz", ""), ("qux", "corge") +extern void ParseGeneratorParameter(const string&, + vector >*); + +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h new file mode 100644 index 00000000..0b507d80 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h @@ -0,0 +1,318 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Implements the Protocol Compiler front-end such that it may be reused by +// custom compilers written to support other languages. + +#ifndef GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ +#define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ + +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { + +class FileDescriptor; // descriptor.h +class DescriptorPool; // descriptor.h +class FileDescriptorProto; // descriptor.pb.h +template class RepeatedPtrField; // repeated_field.h + +namespace compiler { + +class CodeGenerator; // code_generator.h +class GeneratorContext; // code_generator.h +class DiskSourceTree; // importer.h + +// This class implements the command-line interface to the protocol compiler. +// It is designed to make it very easy to create a custom protocol compiler +// supporting the languages of your choice. For example, if you wanted to +// create a custom protocol compiler binary which includes both the regular +// C++ support plus support for your own custom output "Foo", you would +// write a class "FooGenerator" which implements the CodeGenerator interface, +// then write a main() procedure like this: +// +// int main(int argc, char* argv[]) { +// google::protobuf::compiler::CommandLineInterface cli; +// +// // Support generation of C++ source and headers. +// google::protobuf::compiler::cpp::CppGenerator cpp_generator; +// cli.RegisterGenerator("--cpp_out", &cpp_generator, +// "Generate C++ source and header."); +// +// // Support generation of Foo code. +// FooGenerator foo_generator; +// cli.RegisterGenerator("--foo_out", &foo_generator, +// "Generate Foo file."); +// +// return cli.Run(argc, argv); +// } +// +// The compiler is invoked with syntax like: +// protoc --cpp_out=outdir --foo_out=outdir --proto_path=src src/foo.proto +// +// For a full description of the command-line syntax, invoke it with --help. +class LIBPROTOC_EXPORT CommandLineInterface { + public: + CommandLineInterface(); + ~CommandLineInterface(); + + // Register a code generator for a language. + // + // Parameters: + // * flag_name: The command-line flag used to specify an output file of + // this type. The name must start with a '-'. If the name is longer + // than one letter, it must start with two '-'s. + // * generator: The CodeGenerator which will be called to generate files + // of this type. + // * help_text: Text describing this flag in the --help output. + // + // Some generators accept extra parameters. You can specify this parameter + // on the command-line by placing it before the output directory, separated + // by a colon: + // protoc --foo_out=enable_bar:outdir + // The text before the colon is passed to CodeGenerator::Generate() as the + // "parameter". + void RegisterGenerator(const string& flag_name, + CodeGenerator* generator, + const string& help_text); + + // Enables "plugins". In this mode, if a command-line flag ends with "_out" + // but does not match any registered generator, the compiler will attempt to + // find a "plugin" to implement the generator. Plugins are just executables. + // They should live somewhere in the PATH. + // + // The compiler determines the executable name to search for by concatenating + // exe_name_prefix with the unrecognized flag name, removing "_out". So, for + // example, if exe_name_prefix is "protoc-" and you pass the flag --foo_out, + // the compiler will try to run the program "protoc-foo". + // + // The plugin program should implement the following usage: + // plugin [--out=OUTDIR] [--parameter=PARAMETER] PROTO_FILES < DESCRIPTORS + // --out indicates the output directory (as passed to the --foo_out + // parameter); if omitted, the current directory should be used. --parameter + // gives the generator parameter, if any was provided. The PROTO_FILES list + // the .proto files which were given on the compiler command-line; these are + // the files for which the plugin is expected to generate output code. + // Finally, DESCRIPTORS is an encoded FileDescriptorSet (as defined in + // descriptor.proto). This is piped to the plugin's stdin. The set will + // include descriptors for all the files listed in PROTO_FILES as well as + // all files that they import. The plugin MUST NOT attempt to read the + // PROTO_FILES directly -- it must use the FileDescriptorSet. + // + // The plugin should generate whatever files are necessary, as code generators + // normally do. It should write the names of all files it generates to + // stdout. The names should be relative to the output directory, NOT absolute + // names or relative to the current directory. If any errors occur, error + // messages should be written to stderr. If an error is fatal, the plugin + // should exit with a non-zero exit code. + void AllowPlugins(const string& exe_name_prefix); + + // Run the Protocol Compiler with the given command-line parameters. + // Returns the error code which should be returned by main(). + // + // It may not be safe to call Run() in a multi-threaded environment because + // it calls strerror(). I'm not sure why you'd want to do this anyway. + int Run(int argc, const char* const argv[]); + + // Call SetInputsAreCwdRelative(true) if the input files given on the command + // line should be interpreted relative to the proto import path specified + // using --proto_path or -I flags. Otherwise, input file names will be + // interpreted relative to the current working directory (or as absolute + // paths if they start with '/'), though they must still reside inside + // a directory given by --proto_path or the compiler will fail. The latter + // mode is generally more intuitive and easier to use, especially e.g. when + // defining implicit rules in Makefiles. + void SetInputsAreProtoPathRelative(bool enable) { + inputs_are_proto_path_relative_ = enable; + } + + // Provides some text which will be printed when the --version flag is + // used. The version of libprotoc will also be printed on the next line + // after this text. + void SetVersionInfo(const string& text) { + version_info_ = text; + } + + + private: + // ----------------------------------------------------------------- + + class ErrorPrinter; + class GeneratorContextImpl; + class MemoryOutputStream; + + // Clear state from previous Run(). + void Clear(); + + // Remaps each file in input_files_ so that it is relative to one of the + // directories in proto_path_. Returns false if an error occurred. This + // is only used if inputs_are_proto_path_relative_ is false. + bool MakeInputsBeProtoPathRelative( + DiskSourceTree* source_tree); + + // Parse all command-line arguments. + bool ParseArguments(int argc, const char* const argv[]); + + // Parses a command-line argument into a name/value pair. Returns + // true if the next argument in the argv should be used as the value, + // false otherwise. + // + // Exmaples: + // "-Isrc/protos" -> + // name = "-I", value = "src/protos" + // "--cpp_out=src/foo.pb2.cc" -> + // name = "--cpp_out", value = "src/foo.pb2.cc" + // "foo.proto" -> + // name = "", value = "foo.proto" + bool ParseArgument(const char* arg, string* name, string* value); + + // Interprets arguments parsed with ParseArgument. + bool InterpretArgument(const string& name, const string& value); + + // Print the --help text to stderr. + void PrintHelpText(); + + // Generate the given output file from the given input. + struct OutputDirective; // see below + bool GenerateOutput(const vector& parsed_files, + const OutputDirective& output_directive, + GeneratorContext* generator_context); + bool GeneratePluginOutput(const vector& parsed_files, + const string& plugin_name, + const string& parameter, + GeneratorContext* generator_context, + string* error); + + // Implements --encode and --decode. + bool EncodeOrDecode(const DescriptorPool* pool); + + // Implements the --descriptor_set_out option. + bool WriteDescriptorSet(const vector parsed_files); + + // Get all transitive dependencies of the given file (including the file + // itself), adding them to the given list of FileDescriptorProtos. The + // protos will be ordered such that every file is listed before any file that + // depends on it, so that you can call DescriptorPool::BuildFile() on them + // in order. Any files in *already_seen will not be added, and each file + // added will be inserted into *already_seen. + static void GetTransitiveDependencies( + const FileDescriptor* file, + set* already_seen, + RepeatedPtrField* output); + + // ----------------------------------------------------------------- + + // The name of the executable as invoked (i.e. argv[0]). + string executable_name_; + + // Version info set with SetVersionInfo(). + string version_info_; + + // Map from flag names to registered generators. + struct GeneratorInfo { + CodeGenerator* generator; + string help_text; + }; + typedef map GeneratorMap; + GeneratorMap generators_; + + // See AllowPlugins(). If this is empty, plugins aren't allowed. + string plugin_prefix_; + + // Maps specific plugin names to files. When executing a plugin, this map + // is searched first to find the plugin executable. If not found here, the + // PATH (or other OS-specific search strategy) is searched. + map plugins_; + + // Stuff parsed from command line. + enum Mode { + MODE_COMPILE, // Normal mode: parse .proto files and compile them. + MODE_ENCODE, // --encode: read text from stdin, write binary to stdout. + MODE_DECODE // --decode: read binary from stdin, write text to stdout. + }; + + Mode mode_; + + enum ErrorFormat { + ERROR_FORMAT_GCC, // GCC error output format (default). + ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs). + }; + + ErrorFormat error_format_; + + vector > proto_path_; // Search path for proto files. + vector input_files_; // Names of the input proto files. + + // output_directives_ lists all the files we are supposed to output and what + // generator to use for each. + struct OutputDirective { + string name; // E.g. "--foo_out" + CodeGenerator* generator; // NULL for plugins + string parameter; + string output_location; + }; + vector output_directives_; + + // When using --encode or --decode, this names the type we are encoding or + // decoding. (Empty string indicates --decode_raw.) + string codec_type_; + + // If --descriptor_set_out was given, this is the filename to which the + // FileDescriptorSet should be written. Otherwise, empty. + string descriptor_set_name_; + + // True if --include_imports was given, meaning that we should + // write all transitive dependencies to the DescriptorSet. Otherwise, only + // the .proto files listed on the command-line are added. + bool imports_in_descriptor_set_; + + // Was the --disallow_services flag used? + bool disallow_services_; + + // See SetInputsAreProtoPathRelative(). + bool inputs_are_proto_path_relative_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface); +}; + +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h new file mode 100644 index 00000000..58f7721e --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h @@ -0,0 +1,99 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ + +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace cpp { + +class EnumGenerator { + public: + // See generator.cc for the meaning of dllexport_decl. + explicit EnumGenerator(const EnumDescriptor* descriptor, + const string& dllexport_decl); + ~EnumGenerator(); + + // Header stuff. + + // Generate header code defining the enum. This code should be placed + // within the enum's package namespace, but NOT within any class, even for + // nested enums. + void GenerateDefinition(io::Printer* printer); + + // Generate specialization of GetEnumDescriptor(). + // Precondition: in ::google::protobuf namespace. + void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); + + // For enums nested within a message, generate code to import all the enum's + // symbols (e.g. the enum type name, all its values, etc.) into the class's + // namespace. This should be placed inside the class definition in the + // header. + void GenerateSymbolImports(io::Printer* printer); + + // Source file stuff. + + // Generate code that initializes the global variable storing the enum's + // descriptor. + void GenerateDescriptorInitializer(io::Printer* printer, int index); + + // Generate non-inline methods related to the enum, such as IsValidValue(). + // Goes in the .cc file. + void GenerateMethods(io::Printer* printer); + + private: + const EnumDescriptor* descriptor_; + string classname_; + string dllexport_decl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h new file mode 100644 index 00000000..0793430c --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h @@ -0,0 +1,103 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace cpp { + +class EnumFieldGenerator : public FieldGenerator { + public: + explicit EnumFieldGenerator(const FieldDescriptor* descriptor); + ~EnumFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); +}; + +class RepeatedEnumFieldGenerator : public FieldGenerator { + public: + explicit RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor); + ~RepeatedEnumFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h new file mode 100644 index 00000000..3068b091 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h @@ -0,0 +1,85 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__ + +#include +#include + +namespace google { +namespace protobuf { + class FieldDescriptor; // descriptor.h + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace cpp { + +// Generates code for an extension, which may be within the scope of some +// message or may be at file scope. This is much simpler than FieldGenerator +// since extensions are just simple identifiers with interesting types. +class ExtensionGenerator { + public: + // See generator.cc for the meaning of dllexport_decl. + explicit ExtensionGenerator(const FieldDescriptor* descriptor, + const string& dllexport_decl); + ~ExtensionGenerator(); + + // Header stuff. + void GenerateDeclaration(io::Printer* printer); + + // Source file stuff. + void GenerateDefinition(io::Printer* printer); + + // Generate code to register the extension. + void GenerateRegistration(io::Printer* printer); + + private: + const FieldDescriptor* descriptor_; + string type_traits_; + string dllexport_decl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h new file mode 100644 index 00000000..c303a337 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h @@ -0,0 +1,167 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ + +#include +#include + +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace cpp { + +// Helper function: set variables in the map that are the same for all +// field code generators. +// ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', +// 'deprecation']. +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + map* variables); + +class FieldGenerator { + public: + FieldGenerator() {} + virtual ~FieldGenerator(); + + // Generate lines of code declaring members fields of the message class + // needed to represent this field. These are placed inside the message + // class. + virtual void GeneratePrivateMembers(io::Printer* printer) const = 0; + + // Generate prototypes for all of the accessor functions related to this + // field. These are placed inside the class definition. + virtual void GenerateAccessorDeclarations(io::Printer* printer) const = 0; + + // Generate inline definitions of accessor functions for this field. + // These are placed inside the header after all class definitions. + virtual void GenerateInlineAccessorDefinitions( + io::Printer* printer) const = 0; + + // Generate definitions of accessors that aren't inlined. These are + // placed somewhere in the .cc file. + // Most field types don't need this, so the default implementation is empty. + virtual void GenerateNonInlineAccessorDefinitions( + io::Printer* printer) const {} + + // Generate lines of code (statements, not declarations) which clear the + // field. This is used to define the clear_$name$() method as well as + // the Clear() method for the whole message. + virtual void GenerateClearingCode(io::Printer* printer) const = 0; + + // Generate lines of code (statements, not declarations) which merges the + // contents of the field from the current message to the target message, + // which is stored in the generated code variable "from". + // This is used to fill in the MergeFrom method for the whole message. + // Details of this usage can be found in message.cc under the + // GenerateMergeFrom method. + virtual void GenerateMergingCode(io::Printer* printer) const = 0; + + // Generate lines of code (statements, not declarations) which swaps + // this field and the corresponding field of another message, which + // is stored in the generated code variable "other". This is used to + // define the Swap method. Details of usage can be found in + // message.cc under the GenerateSwap method. + virtual void GenerateSwappingCode(io::Printer* printer) const = 0; + + // Generate initialization code for private members declared by + // GeneratePrivateMembers(). These go into the message class's SharedCtor() + // method, invoked by each of the generated constructors. + virtual void GenerateConstructorCode(io::Printer* printer) const = 0; + + // Generate any code that needs to go in the class's SharedDtor() method, + // invoked by the destructor. + // Most field types don't need this, so the default implementation is empty. + virtual void GenerateDestructorCode(io::Printer* printer) const {} + + // Generate lines to decode this field, which will be placed inside the + // message's MergeFromCodedStream() method. + virtual void GenerateMergeFromCodedStream(io::Printer* printer) const = 0; + + // Generate lines to decode this field from a packed value, which will be + // placed inside the message's MergeFromCodedStream() method. + virtual void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) + const; + + // Generate lines to serialize this field, which are placed within the + // message's SerializeWithCachedSizes() method. + virtual void GenerateSerializeWithCachedSizes(io::Printer* printer) const = 0; + + // Generate lines to serialize this field directly to the array "target", + // which are placed within the message's SerializeWithCachedSizesToArray() + // method. This must also advance "target" past the written bytes. + virtual void GenerateSerializeWithCachedSizesToArray( + io::Printer* printer) const = 0; + + // Generate lines to compute the serialized size of this field, which + // are placed in the message's ByteSize() method. + virtual void GenerateByteSize(io::Printer* printer) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); +}; + +// Convenience class which constructs FieldGenerators for a Descriptor. +class FieldGeneratorMap { + public: + explicit FieldGeneratorMap(const Descriptor* descriptor); + ~FieldGeneratorMap(); + + const FieldGenerator& get(const FieldDescriptor* field) const; + + private: + const Descriptor* descriptor_; + scoped_array > field_generators_; + + static FieldGenerator* MakeGenerator(const FieldDescriptor* field); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); +}; + + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h new file mode 100644 index 00000000..b4e01285 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h @@ -0,0 +1,98 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ + +#include +#include +#include +#include + +namespace google { +namespace protobuf { + class FileDescriptor; // descriptor.h + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace cpp { + +class EnumGenerator; // enum.h +class MessageGenerator; // message.h +class ServiceGenerator; // service.h +class ExtensionGenerator; // extension.h + +class FileGenerator { + public: + // See generator.cc for the meaning of dllexport_decl. + explicit FileGenerator(const FileDescriptor* file, + const string& dllexport_decl); + ~FileGenerator(); + + void GenerateHeader(io::Printer* printer); + void GenerateSource(io::Printer* printer); + + private: + // Generate the BuildDescriptors() procedure, which builds all descriptors + // for types defined in the file. + void GenerateBuildDescriptors(io::Printer* printer); + + void GenerateNamespaceOpeners(io::Printer* printer); + void GenerateNamespaceClosers(io::Printer* printer); + + const FileDescriptor* file_; + + scoped_array > message_generators_; + scoped_array > enum_generators_; + scoped_array > service_generators_; + scoped_array > extension_generators_; + + // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}. + vector package_parts_; + + string dllexport_decl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h new file mode 100644 index 00000000..a90e84d7 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h @@ -0,0 +1,72 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Generates C++ code for a given .proto file. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ + +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace cpp { + +// CodeGenerator implementation which generates a C++ source file and +// header. If you create your own protocol compiler binary and you want +// it to support C++ output, you can do so by registering an instance of this +// CodeGenerator with the CommandLineInterface in your main() function. +class LIBPROTOC_EXPORT CppGenerator : public CodeGenerator { + public: + CppGenerator(); + ~CppGenerator(); + + // implements CodeGenerator ---------------------------------------- + bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* generator_context, + string* error) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CppGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h new file mode 100644 index 00000000..b13d53be --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -0,0 +1,159 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace cpp { + +// Commonly-used separator comments. Thick is a line of '=', thin is a line +// of '-'. +extern const char kThickSeparator[]; +extern const char kThinSeparator[]; + +// Returns the non-nested type name for the given type. If "qualified" is +// true, prefix the type with the full namespace. For example, if you had: +// package foo.bar; +// message Baz { message Qux {} } +// Then the qualified ClassName for Qux would be: +// ::foo::bar::Baz_Qux +// While the non-qualified version would be: +// Baz_Qux +string ClassName(const Descriptor* descriptor, bool qualified); +string ClassName(const EnumDescriptor* enum_descriptor, bool qualified); + +string SuperClassName(const Descriptor* descriptor); + +// Get the (unqualified) name that should be used for this field in C++ code. +// The name is coerced to lower-case to emulate proto1 behavior. People +// should be using lowercase-with-underscores style for proto field names +// anyway, so normally this just returns field->name(). +string FieldName(const FieldDescriptor* field); + +// Get the unqualified name that should be used for a field's field +// number constant. +string FieldConstantName(const FieldDescriptor *field); + +// Returns the scope where the field was defined (for extensions, this is +// different from the message type to which the field applies). +inline const Descriptor* FieldScope(const FieldDescriptor* field) { + return field->is_extension() ? + field->extension_scope() : field->containing_type(); +} + +// Returns the fully-qualified type name field->message_type(). Usually this +// is just ClassName(field->message_type(), true); +string FieldMessageTypeName(const FieldDescriptor* field); + +// Strips ".proto" or ".protodevel" from the end of a filename. +string StripProto(const string& filename); + +// Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.). +// Note: non-built-in type names will be qualified, meaning they will start +// with a ::. If you are using the type as a template parameter, you will +// need to insure there is a space between the < and the ::, because the +// ridiculous C++ standard defines "<:" to be a synonym for "[". +const char* PrimitiveTypeName(FieldDescriptor::CppType type); + +// Get the declared type name in CamelCase format, as is used e.g. for the +// methods of WireFormat. For example, TYPE_INT32 becomes "Int32". +const char* DeclaredTypeMethodName(FieldDescriptor::Type type); + +// Get code that evaluates to the field's default value. +string DefaultValue(const FieldDescriptor* field); + +// Convert a file name into a valid identifier. +string FilenameIdentifier(const string& filename); + +// Return the name of the AddDescriptors() function for a given file. +string GlobalAddDescriptorsName(const string& filename); + +// Return the name of the AssignDescriptors() function for a given file. +string GlobalAssignDescriptorsName(const string& filename); + +// Return the name of the ShutdownFile() function for a given file. +string GlobalShutdownFileName(const string& filename); + +// Escape C++ trigraphs by escaping question marks to \? +string EscapeTrigraphs(const string& to_escape); + +// Do message classes in this file keep track of unknown fields? +inline bool HasUnknownFields(const FileDescriptor *file) { + return file->options().optimize_for() != FileOptions::LITE_RUNTIME; +} + +// Does this file have generated parsing, serialization, and other +// standard methods for which reflection-based fallback implementations exist? +inline bool HasGeneratedMethods(const FileDescriptor *file) { + return file->options().optimize_for() != FileOptions::CODE_SIZE; +} + +// Do message classes in this file have descriptor and refelction methods? +inline bool HasDescriptorMethods(const FileDescriptor *file) { + return file->options().optimize_for() != FileOptions::LITE_RUNTIME; +} + +// Should we generate generic services for this file? +inline bool HasGenericServices(const FileDescriptor *file) { + return file->service_count() > 0 && + file->options().optimize_for() != FileOptions::LITE_RUNTIME && + file->options().cc_generic_services(); +} + +// Should string fields in this file verify that their contents are UTF-8? +inline bool HasUtf8Verification(const FileDescriptor* file) { + return file->options().optimize_for() != FileOptions::LITE_RUNTIME; +} + +// Should we generate a separate, super-optimized code path for serializing to +// flat arrays? We don't do this in Lite mode because we'd rather reduce code +// size. +inline bool HasFastArraySerialization(const FileDescriptor* file) { + return file->options().optimize_for() == FileOptions::SPEED; +} + + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h new file mode 100644 index 00000000..04778f6d --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h @@ -0,0 +1,170 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace cpp { + +class EnumGenerator; // enum.h +class ExtensionGenerator; // extension.h + +class MessageGenerator { + public: + // See generator.cc for the meaning of dllexport_decl. + explicit MessageGenerator(const Descriptor* descriptor, + const string& dllexport_decl); + ~MessageGenerator(); + + // Header stuff. + + // Generate foward declarations for this class and all its nested types. + void GenerateForwardDeclaration(io::Printer* printer); + + // Generate definitions of all nested enums (must come before class + // definitions because those classes use the enums definitions). + void GenerateEnumDefinitions(io::Printer* printer); + + // Generate specializations of GetEnumDescriptor(). + // Precondition: in ::google::protobuf namespace. + void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); + + // Generate definitions for this class and all its nested types. + void GenerateClassDefinition(io::Printer* printer); + + // Generate definitions of inline methods (placed at the end of the header + // file). + void GenerateInlineMethods(io::Printer* printer); + + // Source file stuff. + + // Generate code which declares all the global descriptor pointers which + // will be initialized by the methods below. + void GenerateDescriptorDeclarations(io::Printer* printer); + + // Generate code that initializes the global variable storing the message's + // descriptor. + void GenerateDescriptorInitializer(io::Printer* printer, int index); + + // Generate code that calls MessageFactory::InternalRegisterGeneratedMessage() + // for all types. + void GenerateTypeRegistrations(io::Printer* printer); + + // Generates code that allocates the message's default instance. + void GenerateDefaultInstanceAllocator(io::Printer* printer); + + // Generates code that initializes the message's default instance. This + // is separate from allocating because all default instances must be + // allocated before any can be initialized. + void GenerateDefaultInstanceInitializer(io::Printer* printer); + + // Generates code that should be run when ShutdownProtobufLibrary() is called, + // to delete all dynamically-allocated objects. + void GenerateShutdownCode(io::Printer* printer); + + // Generate all non-inline methods for this class. + void GenerateClassMethods(io::Printer* printer); + + private: + // Generate declarations and definitions of accessors for fields. + void GenerateFieldAccessorDeclarations(io::Printer* printer); + void GenerateFieldAccessorDefinitions(io::Printer* printer); + + // Generate the field offsets array. + void GenerateOffsets(io::Printer* printer); + + // Generate constructors and destructor. + void GenerateStructors(io::Printer* printer); + + // The compiler typically generates multiple copies of each constructor and + // destructor: http://gcc.gnu.org/bugs.html#nonbugs_cxx + // Placing common code in a separate method reduces the generated code size. + // + // Generate the shared constructor code. + void GenerateSharedConstructorCode(io::Printer* printer); + // Generate the shared destructor code. + void GenerateSharedDestructorCode(io::Printer* printer); + + // Generate standard Message methods. + void GenerateClear(io::Printer* printer); + void GenerateMergeFromCodedStream(io::Printer* printer); + void GenerateSerializeWithCachedSizes(io::Printer* printer); + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer); + void GenerateSerializeWithCachedSizesBody(io::Printer* printer, + bool to_array); + void GenerateByteSize(io::Printer* printer); + void GenerateMergeFrom(io::Printer* printer); + void GenerateCopyFrom(io::Printer* printer); + void GenerateSwap(io::Printer* printer); + void GenerateIsInitialized(io::Printer* printer); + + // Helpers for GenerateSerializeWithCachedSizes(). + void GenerateSerializeOneField(io::Printer* printer, + const FieldDescriptor* field, + bool unbounded); + void GenerateSerializeOneExtensionRange( + io::Printer* printer, const Descriptor::ExtensionRange* range, + bool unbounded); + + + const Descriptor* descriptor_; + string classname_; + string dllexport_decl_; + FieldGeneratorMap field_generators_; + scoped_array > nested_generators_; + scoped_array > enum_generators_; + scoped_array > extension_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h new file mode 100644 index 00000000..f5147278 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h @@ -0,0 +1,102 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace cpp { + +class MessageFieldGenerator : public FieldGenerator { + public: + explicit MessageFieldGenerator(const FieldDescriptor* descriptor); + ~MessageFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); +}; + +class RepeatedMessageFieldGenerator : public FieldGenerator { + public: + explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor); + ~RepeatedMessageFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h new file mode 100644 index 00000000..8fcd74ae --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h @@ -0,0 +1,103 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace cpp { + +class PrimitiveFieldGenerator : public FieldGenerator { + public: + explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor); + ~PrimitiveFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); +}; + +class RepeatedPrimitiveFieldGenerator : public FieldGenerator { + public: + explicit RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor); + ~RepeatedPrimitiveFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h new file mode 100644 index 00000000..10e9dd3c --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h @@ -0,0 +1,118 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ + +#include +#include +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace cpp { + +class ServiceGenerator { + public: + // See generator.cc for the meaning of dllexport_decl. + explicit ServiceGenerator(const ServiceDescriptor* descriptor, + const string& dllexport_decl); + ~ServiceGenerator(); + + // Header stuff. + + // Generate the class definitions for the service's interface and the + // stub implementation. + void GenerateDeclarations(io::Printer* printer); + + // Source file stuff. + + // Generate code that initializes the global variable storing the service's + // descriptor. + void GenerateDescriptorInitializer(io::Printer* printer, int index); + + // Generate implementations of everything declared by GenerateDeclarations(). + void GenerateImplementation(io::Printer* printer); + + private: + enum RequestOrResponse { REQUEST, RESPONSE }; + enum VirtualOrNon { VIRTUAL, NON_VIRTUAL }; + + // Header stuff. + + // Generate the service abstract interface. + void GenerateInterface(io::Printer* printer); + + // Generate the stub class definition. + void GenerateStubDefinition(io::Printer* printer); + + // Prints signatures for all methods in the + void GenerateMethodSignatures(VirtualOrNon virtual_or_non, + io::Printer* printer); + + // Source file stuff. + + // Generate the default implementations of the service methods, which + // produce a "not implemented" error. + void GenerateNotImplementedMethods(io::Printer* printer); + + // Generate the CallMethod() method of the service. + void GenerateCallMethod(io::Printer* printer); + + // Generate the Get{Request,Response}Prototype() methods. + void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); + + // Generate the stub's implementations of the service methods. + void GenerateStubMethods(io::Printer* printer); + + const ServiceDescriptor* descriptor_; + map vars_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h new file mode 100644 index 00000000..7f45107d --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h @@ -0,0 +1,104 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace cpp { + +class StringFieldGenerator : public FieldGenerator { + public: + explicit StringFieldGenerator(const FieldDescriptor* descriptor); + ~StringFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateDestructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator); +}; + +class RepeatedStringFieldGenerator : public FieldGenerator { + public: + explicit RepeatedStringFieldGenerator(const FieldDescriptor* descriptor); + ~RepeatedStringFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + void GeneratePrivateMembers(io::Printer* printer) const; + void GenerateAccessorDeclarations(io::Printer* printer) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateClearingCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateSwappingCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const; + void GenerateMergeFromCodedStream(io::Printer* printer) const; + void GenerateSerializeWithCachedSizes(io::Printer* printer) const; + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; + void GenerateByteSize(io::Printer* printer) const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator); +}; + +} // namespace cpp +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h new file mode 100644 index 00000000..bd467602 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h @@ -0,0 +1,2721 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto + +#ifndef PROTOBUF_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + +class TestConflictingSymbolNames; +class TestConflictingSymbolNames_BuildDescriptors; +class TestConflictingSymbolNames_TypeTraits; +class TestConflictingSymbolNames_Data1; +class TestConflictingSymbolNames_Data2; +class TestConflictingSymbolNames_Data3; +class TestConflictingSymbolNames_Data4; +class TestConflictingSymbolNames_Data5; +class TestConflictingSymbolNames_Data6; +class TestConflictingSymbolNames_Cord; +class TestConflictingSymbolNames_StringPiece; +class TestConflictingSymbolNames_DO; +class DummyMessage; + +enum TestConflictingSymbolNames_TestEnum { + TestConflictingSymbolNames_TestEnum_FOO = 1 +}; +bool TestConflictingSymbolNames_TestEnum_IsValid(int value); +const TestConflictingSymbolNames_TestEnum TestConflictingSymbolNames_TestEnum_TestEnum_MIN = TestConflictingSymbolNames_TestEnum_FOO; +const TestConflictingSymbolNames_TestEnum TestConflictingSymbolNames_TestEnum_TestEnum_MAX = TestConflictingSymbolNames_TestEnum_FOO; +const int TestConflictingSymbolNames_TestEnum_TestEnum_ARRAYSIZE = TestConflictingSymbolNames_TestEnum_TestEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* TestConflictingSymbolNames_TestEnum_descriptor(); +inline const ::std::string& TestConflictingSymbolNames_TestEnum_Name(TestConflictingSymbolNames_TestEnum value) { + return ::google::protobuf::internal::NameOfEnum( + TestConflictingSymbolNames_TestEnum_descriptor(), value); +} +inline bool TestConflictingSymbolNames_TestEnum_Parse( + const ::std::string& name, TestConflictingSymbolNames_TestEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + TestConflictingSymbolNames_TestEnum_descriptor(), name, value); +} +// =================================================================== + +class TestConflictingSymbolNames_BuildDescriptors : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_BuildDescriptors(); + virtual ~TestConflictingSymbolNames_BuildDescriptors(); + + TestConflictingSymbolNames_BuildDescriptors(const TestConflictingSymbolNames_BuildDescriptors& from); + + inline TestConflictingSymbolNames_BuildDescriptors& operator=(const TestConflictingSymbolNames_BuildDescriptors& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_BuildDescriptors& default_instance(); + + void Swap(TestConflictingSymbolNames_BuildDescriptors* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_BuildDescriptors* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_BuildDescriptors& from); + void MergeFrom(const TestConflictingSymbolNames_BuildDescriptors& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.BuildDescriptors) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_BuildDescriptors* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_TypeTraits : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_TypeTraits(); + virtual ~TestConflictingSymbolNames_TypeTraits(); + + TestConflictingSymbolNames_TypeTraits(const TestConflictingSymbolNames_TypeTraits& from); + + inline TestConflictingSymbolNames_TypeTraits& operator=(const TestConflictingSymbolNames_TypeTraits& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_TypeTraits& default_instance(); + + void Swap(TestConflictingSymbolNames_TypeTraits* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_TypeTraits* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_TypeTraits& from); + void MergeFrom(const TestConflictingSymbolNames_TypeTraits& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.TypeTraits) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_TypeTraits* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_Data1 : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_Data1(); + virtual ~TestConflictingSymbolNames_Data1(); + + TestConflictingSymbolNames_Data1(const TestConflictingSymbolNames_Data1& from); + + inline TestConflictingSymbolNames_Data1& operator=(const TestConflictingSymbolNames_Data1& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_Data1& default_instance(); + + void Swap(TestConflictingSymbolNames_Data1* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_Data1* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_Data1& from); + void MergeFrom(const TestConflictingSymbolNames_Data1& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated int32 data = 1; + inline int data_size() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + inline ::google::protobuf::int32 data(int index) const; + inline void set_data(int index, ::google::protobuf::int32 value); + inline void add_data(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + data() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_data(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data1) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_Data1* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_Data2 : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_Data2(); + virtual ~TestConflictingSymbolNames_Data2(); + + TestConflictingSymbolNames_Data2(const TestConflictingSymbolNames_Data2& from); + + inline TestConflictingSymbolNames_Data2& operator=(const TestConflictingSymbolNames_Data2& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_Data2& default_instance(); + + void Swap(TestConflictingSymbolNames_Data2* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_Data2* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_Data2& from); + void MergeFrom(const TestConflictingSymbolNames_Data2& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .protobuf_unittest.TestConflictingSymbolNames.TestEnum data = 1; + inline int data_size() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + inline ::protobuf_unittest::TestConflictingSymbolNames_TestEnum data(int index) const; + inline void set_data(int index, ::protobuf_unittest::TestConflictingSymbolNames_TestEnum value); + inline void add_data(::protobuf_unittest::TestConflictingSymbolNames_TestEnum value); + inline const ::google::protobuf::RepeatedField& data() const; + inline ::google::protobuf::RepeatedField* mutable_data(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data2) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedField data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_Data2* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_Data3 : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_Data3(); + virtual ~TestConflictingSymbolNames_Data3(); + + TestConflictingSymbolNames_Data3(const TestConflictingSymbolNames_Data3& from); + + inline TestConflictingSymbolNames_Data3& operator=(const TestConflictingSymbolNames_Data3& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_Data3& default_instance(); + + void Swap(TestConflictingSymbolNames_Data3* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_Data3* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_Data3& from); + void MergeFrom(const TestConflictingSymbolNames_Data3& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated string data = 1; + inline int data_size() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + inline const ::std::string& data(int index) const; + inline ::std::string* mutable_data(int index); + inline void set_data(int index, const ::std::string& value); + inline void set_data(int index, const char* value); + inline void set_data(int index, const char* value, size_t size); + inline ::std::string* add_data(); + inline void add_data(const ::std::string& value); + inline void add_data(const char* value); + inline void add_data(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& data() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_data(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data3) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::std::string> data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_Data3* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_Data4 : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_Data4(); + virtual ~TestConflictingSymbolNames_Data4(); + + TestConflictingSymbolNames_Data4(const TestConflictingSymbolNames_Data4& from); + + inline TestConflictingSymbolNames_Data4& operator=(const TestConflictingSymbolNames_Data4& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_Data4& default_instance(); + + void Swap(TestConflictingSymbolNames_Data4* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_Data4* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_Data4& from); + void MergeFrom(const TestConflictingSymbolNames_Data4& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .protobuf_unittest.TestConflictingSymbolNames.Data4 data = 1; + inline int data_size() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + inline const ::protobuf_unittest::TestConflictingSymbolNames_Data4& data(int index) const; + inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* mutable_data(int index); + inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* add_data(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >& + data() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >* + mutable_data(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data4) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 > data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_Data4* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_Data5 : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_Data5(); + virtual ~TestConflictingSymbolNames_Data5(); + + TestConflictingSymbolNames_Data5(const TestConflictingSymbolNames_Data5& from); + + inline TestConflictingSymbolNames_Data5& operator=(const TestConflictingSymbolNames_Data5& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_Data5& default_instance(); + + void Swap(TestConflictingSymbolNames_Data5* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_Data5* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_Data5& from); + void MergeFrom(const TestConflictingSymbolNames_Data5& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated string data = 1 [ctype = STRING_PIECE]; + inline int data_size() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& data(int index) const; + inline ::std::string* mutable_data(int index); + inline void set_data(int index, const ::std::string& value); + inline void set_data(int index, const char* value); + inline void set_data(int index, const char* value, size_t size); + inline ::std::string* add_data(); + inline void add_data(const ::std::string& value); + inline void add_data(const char* value); + inline void add_data(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& data() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_data(); + public: + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data5) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::std::string> data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_Data5* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_Data6 : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_Data6(); + virtual ~TestConflictingSymbolNames_Data6(); + + TestConflictingSymbolNames_Data6(const TestConflictingSymbolNames_Data6& from); + + inline TestConflictingSymbolNames_Data6& operator=(const TestConflictingSymbolNames_Data6& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_Data6& default_instance(); + + void Swap(TestConflictingSymbolNames_Data6* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_Data6* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_Data6& from); + void MergeFrom(const TestConflictingSymbolNames_Data6& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated string data = 1 [ctype = CORD]; + inline int data_size() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& data(int index) const; + inline ::std::string* mutable_data(int index); + inline void set_data(int index, const ::std::string& value); + inline void set_data(int index, const char* value); + inline void set_data(int index, const char* value, size_t size); + inline ::std::string* add_data(); + inline void add_data(const ::std::string& value); + inline void add_data(const char* value); + inline void add_data(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& data() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_data(); + public: + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data6) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::std::string> data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_Data6* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_Cord : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_Cord(); + virtual ~TestConflictingSymbolNames_Cord(); + + TestConflictingSymbolNames_Cord(const TestConflictingSymbolNames_Cord& from); + + inline TestConflictingSymbolNames_Cord& operator=(const TestConflictingSymbolNames_Cord& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_Cord& default_instance(); + + void Swap(TestConflictingSymbolNames_Cord* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_Cord* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_Cord& from); + void MergeFrom(const TestConflictingSymbolNames_Cord& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Cord) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_Cord* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_StringPiece : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_StringPiece(); + virtual ~TestConflictingSymbolNames_StringPiece(); + + TestConflictingSymbolNames_StringPiece(const TestConflictingSymbolNames_StringPiece& from); + + inline TestConflictingSymbolNames_StringPiece& operator=(const TestConflictingSymbolNames_StringPiece& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_StringPiece& default_instance(); + + void Swap(TestConflictingSymbolNames_StringPiece* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_StringPiece* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_StringPiece& from); + void MergeFrom(const TestConflictingSymbolNames_StringPiece& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.StringPiece) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_StringPiece* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames_DO : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames_DO(); + virtual ~TestConflictingSymbolNames_DO(); + + TestConflictingSymbolNames_DO(const TestConflictingSymbolNames_DO& from); + + inline TestConflictingSymbolNames_DO& operator=(const TestConflictingSymbolNames_DO& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames_DO& default_instance(); + + void Swap(TestConflictingSymbolNames_DO* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames_DO* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames_DO& from); + void MergeFrom(const TestConflictingSymbolNames_DO& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.DO) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames_DO* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestConflictingSymbolNames : public ::google::protobuf::Message { + public: + TestConflictingSymbolNames(); + virtual ~TestConflictingSymbolNames(); + + TestConflictingSymbolNames(const TestConflictingSymbolNames& from); + + inline TestConflictingSymbolNames& operator=(const TestConflictingSymbolNames& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestConflictingSymbolNames& default_instance(); + + void Swap(TestConflictingSymbolNames* other); + + // implements Message ---------------------------------------------- + + TestConflictingSymbolNames* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestConflictingSymbolNames& from); + void MergeFrom(const TestConflictingSymbolNames& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef TestConflictingSymbolNames_BuildDescriptors BuildDescriptors; + typedef TestConflictingSymbolNames_TypeTraits TypeTraits; + typedef TestConflictingSymbolNames_Data1 Data1; + typedef TestConflictingSymbolNames_Data2 Data2; + typedef TestConflictingSymbolNames_Data3 Data3; + typedef TestConflictingSymbolNames_Data4 Data4; + typedef TestConflictingSymbolNames_Data5 Data5; + typedef TestConflictingSymbolNames_Data6 Data6; + typedef TestConflictingSymbolNames_Cord Cord; + typedef TestConflictingSymbolNames_StringPiece StringPiece; + typedef TestConflictingSymbolNames_DO DO; + + typedef TestConflictingSymbolNames_TestEnum TestEnum; + static const TestEnum FOO = TestConflictingSymbolNames_TestEnum_FOO; + static inline bool TestEnum_IsValid(int value) { + return TestConflictingSymbolNames_TestEnum_IsValid(value); + } + static const TestEnum TestEnum_MIN = + TestConflictingSymbolNames_TestEnum_TestEnum_MIN; + static const TestEnum TestEnum_MAX = + TestConflictingSymbolNames_TestEnum_TestEnum_MAX; + static const int TestEnum_ARRAYSIZE = + TestConflictingSymbolNames_TestEnum_TestEnum_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + TestEnum_descriptor() { + return TestConflictingSymbolNames_TestEnum_descriptor(); + } + static inline const ::std::string& TestEnum_Name(TestEnum value) { + return TestConflictingSymbolNames_TestEnum_Name(value); + } + static inline bool TestEnum_Parse(const ::std::string& name, + TestEnum* value) { + return TestConflictingSymbolNames_TestEnum_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // optional int32 input = 1; + inline bool has_input() const; + inline void clear_input(); + static const int kInputFieldNumber = 1; + inline ::google::protobuf::int32 input() const; + inline void set_input(::google::protobuf::int32 value); + + // optional int32 output = 2; + inline bool has_output() const; + inline void clear_output(); + static const int kOutputFieldNumber = 2; + inline ::google::protobuf::int32 output() const; + inline void set_output(::google::protobuf::int32 value); + + // optional string length = 3; + inline bool has_length() const; + inline void clear_length(); + static const int kLengthFieldNumber = 3; + inline const ::std::string& length() const; + inline void set_length(const ::std::string& value); + inline void set_length(const char* value); + inline void set_length(const char* value, size_t size); + inline ::std::string* mutable_length(); + inline ::std::string* release_length(); + + // repeated int32 i = 4; + inline int i_size() const; + inline void clear_i(); + static const int kIFieldNumber = 4; + inline ::google::protobuf::int32 i(int index) const; + inline void set_i(int index, ::google::protobuf::int32 value); + inline void add_i(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + i() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_i(); + + // repeated string new_element = 5 [ctype = STRING_PIECE]; + inline int new_element_size() const; + inline void clear_new_element(); + static const int kNewElementFieldNumber = 5; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& new_element(int index) const; + inline ::std::string* mutable_new_element(int index); + inline void set_new_element(int index, const ::std::string& value); + inline void set_new_element(int index, const char* value); + inline void set_new_element(int index, const char* value, size_t size); + inline ::std::string* add_new_element(); + inline void add_new_element(const ::std::string& value); + inline void add_new_element(const char* value); + inline void add_new_element(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& new_element() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_new_element(); + public: + + // optional int32 total_size = 6; + inline bool has_total_size() const; + inline void clear_total_size(); + static const int kTotalSizeFieldNumber = 6; + inline ::google::protobuf::int32 total_size() const; + inline void set_total_size(::google::protobuf::int32 value); + + // optional int32 tag = 7; + inline bool has_tag() const; + inline void clear_tag(); + static const int kTagFieldNumber = 7; + inline ::google::protobuf::int32 tag() const; + inline void set_tag(::google::protobuf::int32 value); + + // optional int32 source = 8; + inline bool has_source() const; + inline void clear_source(); + static const int kSourceFieldNumber = 8; + inline ::google::protobuf::int32 source() const; + inline void set_source(::google::protobuf::int32 value); + + // optional int32 value = 9; + inline bool has_value() const; + inline void clear_value(); + static const int kValueFieldNumber = 9; + inline ::google::protobuf::int32 value() const; + inline void set_value(::google::protobuf::int32 value); + + // optional int32 file = 10; + inline bool has_file() const; + inline void clear_file(); + static const int kFileFieldNumber = 10; + inline ::google::protobuf::int32 file() const; + inline void set_file(::google::protobuf::int32 value); + + // optional int32 from = 11; + inline bool has_from() const; + inline void clear_from(); + static const int kFromFieldNumber = 11; + inline ::google::protobuf::int32 from() const; + inline void set_from(::google::protobuf::int32 value); + + // optional int32 handle_uninterpreted = 12; + inline bool has_handle_uninterpreted() const; + inline void clear_handle_uninterpreted(); + static const int kHandleUninterpretedFieldNumber = 12; + inline ::google::protobuf::int32 handle_uninterpreted() const; + inline void set_handle_uninterpreted(::google::protobuf::int32 value); + + // repeated int32 index = 13; + inline int index_size() const; + inline void clear_index(); + static const int kIndexFieldNumber = 13; + inline ::google::protobuf::int32 index(int index) const; + inline void set_index(int index, ::google::protobuf::int32 value); + inline void add_index(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + index() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_index(); + + // optional int32 controller = 14; + inline bool has_controller() const; + inline void clear_controller(); + static const int kControllerFieldNumber = 14; + inline ::google::protobuf::int32 controller() const; + inline void set_controller(::google::protobuf::int32 value); + + // optional int32 already_here = 15; + inline bool has_already_here() const; + inline void clear_already_here(); + static const int kAlreadyHereFieldNumber = 15; + inline ::google::protobuf::int32 already_here() const; + inline void set_already_here(::google::protobuf::int32 value); + + // optional uint32 uint32 = 16; + inline bool has_uint32() const; + inline void clear_uint32(); + static const int kUint32FieldNumber = 16; + inline ::google::protobuf::uint32 uint32() const; + inline void set_uint32(::google::protobuf::uint32 value); + + // optional uint64 uint64 = 17; + inline bool has_uint64() const; + inline void clear_uint64(); + static const int kUint64FieldNumber = 17; + inline ::google::protobuf::uint64 uint64() const; + inline void set_uint64(::google::protobuf::uint64 value); + + // optional string string = 18; + inline bool has_string() const; + inline void clear_string(); + static const int kStringFieldNumber = 18; + inline const ::std::string& string() const; + inline void set_string(const ::std::string& value); + inline void set_string(const char* value); + inline void set_string(const char* value, size_t size); + inline ::std::string* mutable_string(); + inline ::std::string* release_string(); + + // optional int32 memset = 19; + inline bool has_memset() const; + inline void clear_memset(); + static const int kMemsetFieldNumber = 19; + inline ::google::protobuf::int32 memset() const; + inline void set_memset(::google::protobuf::int32 value); + + // optional int32 int32 = 20; + inline bool has_int32() const; + inline void clear_int32(); + static const int kInt32FieldNumber = 20; + inline ::google::protobuf::int32 int32() const; + inline void set_int32(::google::protobuf::int32 value); + + // optional int64 int64 = 21; + inline bool has_int64() const; + inline void clear_int64(); + static const int kInt64FieldNumber = 21; + inline ::google::protobuf::int64 int64() const; + inline void set_int64(::google::protobuf::int64 value); + + // optional uint32 cached_size = 22; + inline bool has_cached_size() const; + inline void clear_cached_size(); + static const int kCachedSizeFieldNumber = 22; + inline ::google::protobuf::uint32 cached_size() const; + inline void set_cached_size(::google::protobuf::uint32 value); + + // optional uint32 extensions = 23; + inline bool has_extensions() const; + inline void clear_extensions(); + static const int kExtensionsFieldNumber = 23; + inline ::google::protobuf::uint32 extensions() const; + inline void set_extensions(::google::protobuf::uint32 value); + + // optional uint32 bit = 24; + inline bool has_bit() const; + inline void clear_bit(); + static const int kBitFieldNumber = 24; + inline ::google::protobuf::uint32 bit() const; + inline void set_bit(::google::protobuf::uint32 value); + + // optional uint32 bits = 25; + inline bool has_bits() const; + inline void clear_bits(); + static const int kBitsFieldNumber = 25; + inline ::google::protobuf::uint32 bits() const; + inline void set_bits(::google::protobuf::uint32 value); + + // optional uint32 offsets = 26; + inline bool has_offsets() const; + inline void clear_offsets(); + static const int kOffsetsFieldNumber = 26; + inline ::google::protobuf::uint32 offsets() const; + inline void set_offsets(::google::protobuf::uint32 value); + + // optional uint32 reflection = 27; + inline bool has_reflection() const; + inline void clear_reflection(); + static const int kReflectionFieldNumber = 27; + inline ::google::protobuf::uint32 reflection() const; + inline void set_reflection(::google::protobuf::uint32 value); + + // optional string some_cord = 28 [ctype = CORD]; + inline bool has_some_cord() const; + inline void clear_some_cord(); + static const int kSomeCordFieldNumber = 28; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& some_cord() const; + inline void set_some_cord(const ::std::string& value); + inline void set_some_cord(const char* value); + inline void set_some_cord(const char* value, size_t size); + inline ::std::string* mutable_some_cord(); + inline ::std::string* release_some_cord(); + public: + + // optional string some_string_piece = 29 [ctype = STRING_PIECE]; + inline bool has_some_string_piece() const; + inline void clear_some_string_piece(); + static const int kSomeStringPieceFieldNumber = 29; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& some_string_piece() const; + inline void set_some_string_piece(const ::std::string& value); + inline void set_some_string_piece(const char* value); + inline void set_some_string_piece(const char* value, size_t size); + inline ::std::string* mutable_some_string_piece(); + inline ::std::string* release_some_string_piece(); + public: + + // optional uint32 int = 30; + inline bool has_int_() const; + inline void clear_int_(); + static const int kIntFieldNumber = 30; + inline ::google::protobuf::uint32 int_() const; + inline void set_int_(::google::protobuf::uint32 value); + + // optional uint32 friend = 31; + inline bool has_friend_() const; + inline void clear_friend_(); + static const int kFriendFieldNumber = 31; + inline ::google::protobuf::uint32 friend_() const; + inline void set_friend_(::google::protobuf::uint32 value); + + // optional .protobuf_unittest.TestConflictingSymbolNames.DO do = 32; + inline bool has_do_() const; + inline void clear_do_(); + static const int kDoFieldNumber = 32; + inline const ::protobuf_unittest::TestConflictingSymbolNames_DO& do_() const; + inline ::protobuf_unittest::TestConflictingSymbolNames_DO* mutable_do_(); + inline ::protobuf_unittest::TestConflictingSymbolNames_DO* release_do_(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestConflictingSymbolNames) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames) + private: + inline void set_has_input(); + inline void clear_has_input(); + inline void set_has_output(); + inline void clear_has_output(); + inline void set_has_length(); + inline void clear_has_length(); + inline void set_has_total_size(); + inline void clear_has_total_size(); + inline void set_has_tag(); + inline void clear_has_tag(); + inline void set_has_source(); + inline void clear_has_source(); + inline void set_has_value(); + inline void clear_has_value(); + inline void set_has_file(); + inline void clear_has_file(); + inline void set_has_from(); + inline void clear_has_from(); + inline void set_has_handle_uninterpreted(); + inline void clear_has_handle_uninterpreted(); + inline void set_has_controller(); + inline void clear_has_controller(); + inline void set_has_already_here(); + inline void clear_has_already_here(); + inline void set_has_uint32(); + inline void clear_has_uint32(); + inline void set_has_uint64(); + inline void clear_has_uint64(); + inline void set_has_string(); + inline void clear_has_string(); + inline void set_has_memset(); + inline void clear_has_memset(); + inline void set_has_int32(); + inline void clear_has_int32(); + inline void set_has_int64(); + inline void clear_has_int64(); + inline void set_has_cached_size(); + inline void clear_has_cached_size(); + inline void set_has_extensions(); + inline void clear_has_extensions(); + inline void set_has_bit(); + inline void clear_has_bit(); + inline void set_has_bits(); + inline void clear_has_bits(); + inline void set_has_offsets(); + inline void clear_has_offsets(); + inline void set_has_reflection(); + inline void clear_has_reflection(); + inline void set_has_some_cord(); + inline void clear_has_some_cord(); + inline void set_has_some_string_piece(); + inline void clear_has_some_string_piece(); + inline void set_has_int_(); + inline void clear_has_int_(); + inline void set_has_friend_(); + inline void clear_has_friend_(); + inline void set_has_do_(); + inline void clear_has_do_(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 input_; + ::google::protobuf::int32 output_; + ::std::string* length_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > i_; + ::google::protobuf::RepeatedPtrField< ::std::string> new_element_; + ::google::protobuf::int32 total_size_; + ::google::protobuf::int32 tag_; + ::google::protobuf::int32 source_; + ::google::protobuf::int32 value_; + ::google::protobuf::int32 file_; + ::google::protobuf::int32 from_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > index_; + ::google::protobuf::int32 handle_uninterpreted_; + ::google::protobuf::int32 controller_; + ::google::protobuf::int32 already_here_; + ::google::protobuf::uint32 uint32_; + ::google::protobuf::uint64 uint64_; + ::std::string* string_; + ::google::protobuf::int32 memset_; + ::google::protobuf::int32 int32_; + ::google::protobuf::int64 int64_; + ::google::protobuf::uint32 cached_size_; + ::google::protobuf::uint32 extensions_; + ::google::protobuf::uint32 bit_; + ::google::protobuf::uint32 bits_; + ::google::protobuf::uint32 offsets_; + ::google::protobuf::uint32 reflection_; + ::std::string* some_cord_; + ::std::string* some_string_piece_; + ::google::protobuf::uint32 int__; + ::google::protobuf::uint32 friend__; + ::protobuf_unittest::TestConflictingSymbolNames_DO* do__; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(32 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static TestConflictingSymbolNames* default_instance_; +}; +// ------------------------------------------------------------------- + +class DummyMessage : public ::google::protobuf::Message { + public: + DummyMessage(); + virtual ~DummyMessage(); + + DummyMessage(const DummyMessage& from); + + inline DummyMessage& operator=(const DummyMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const DummyMessage& default_instance(); + + void Swap(DummyMessage* other); + + // implements Message ---------------------------------------------- + + DummyMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const DummyMessage& from); + void MergeFrom(const DummyMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.DummyMessage) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); + + void InitAsDefaultInstance(); + static DummyMessage* default_instance_; +}; +// =================================================================== + +class TestConflictingMethodNames_Stub; + +class TestConflictingMethodNames : public ::google::protobuf::Service { + protected: + // This class should be treated as an abstract interface. + inline TestConflictingMethodNames() {}; + public: + virtual ~TestConflictingMethodNames(); + + typedef TestConflictingMethodNames_Stub Stub; + + static const ::google::protobuf::ServiceDescriptor* descriptor(); + + virtual void Closure(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::DummyMessage* request, + ::protobuf_unittest::DummyMessage* response, + ::google::protobuf::Closure* done); + + // implements Service ---------------------------------------------- + + const ::google::protobuf::ServiceDescriptor* GetDescriptor(); + void CallMethod(const ::google::protobuf::MethodDescriptor* method, + ::google::protobuf::RpcController* controller, + const ::google::protobuf::Message* request, + ::google::protobuf::Message* response, + ::google::protobuf::Closure* done); + const ::google::protobuf::Message& GetRequestPrototype( + const ::google::protobuf::MethodDescriptor* method) const; + const ::google::protobuf::Message& GetResponsePrototype( + const ::google::protobuf::MethodDescriptor* method) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestConflictingMethodNames); +}; + +class TestConflictingMethodNames_Stub : public TestConflictingMethodNames { + public: + TestConflictingMethodNames_Stub(::google::protobuf::RpcChannel* channel); + TestConflictingMethodNames_Stub(::google::protobuf::RpcChannel* channel, + ::google::protobuf::Service::ChannelOwnership ownership); + ~TestConflictingMethodNames_Stub(); + + inline ::google::protobuf::RpcChannel* channel() { return channel_; } + + // implements TestConflictingMethodNames ------------------------------------------ + + void Closure(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::DummyMessage* request, + ::protobuf_unittest::DummyMessage* response, + ::google::protobuf::Closure* done); + private: + ::google::protobuf::RpcChannel* channel_; + bool owns_channel_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestConflictingMethodNames_Stub); +}; + + +// =================================================================== + + +// =================================================================== + +// TestConflictingSymbolNames_BuildDescriptors + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_TypeTraits + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_Data1 + +// repeated int32 data = 1; +inline int TestConflictingSymbolNames_Data1::data_size() const { + return data_.size(); +} +inline void TestConflictingSymbolNames_Data1::clear_data() { + data_.Clear(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames_Data1::data(int index) const { + return data_.Get(index); +} +inline void TestConflictingSymbolNames_Data1::set_data(int index, ::google::protobuf::int32 value) { + data_.Set(index, value); +} +inline void TestConflictingSymbolNames_Data1::add_data(::google::protobuf::int32 value) { + data_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestConflictingSymbolNames_Data1::data() const { + return data_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestConflictingSymbolNames_Data1::mutable_data() { + return &data_; +} + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_Data2 + +// repeated .protobuf_unittest.TestConflictingSymbolNames.TestEnum data = 1; +inline int TestConflictingSymbolNames_Data2::data_size() const { + return data_.size(); +} +inline void TestConflictingSymbolNames_Data2::clear_data() { + data_.Clear(); +} +inline ::protobuf_unittest::TestConflictingSymbolNames_TestEnum TestConflictingSymbolNames_Data2::data(int index) const { + return static_cast< ::protobuf_unittest::TestConflictingSymbolNames_TestEnum >(data_.Get(index)); +} +inline void TestConflictingSymbolNames_Data2::set_data(int index, ::protobuf_unittest::TestConflictingSymbolNames_TestEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestConflictingSymbolNames_TestEnum_IsValid(value)); + data_.Set(index, value); +} +inline void TestConflictingSymbolNames_Data2::add_data(::protobuf_unittest::TestConflictingSymbolNames_TestEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestConflictingSymbolNames_TestEnum_IsValid(value)); + data_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestConflictingSymbolNames_Data2::data() const { + return data_; +} +inline ::google::protobuf::RepeatedField* +TestConflictingSymbolNames_Data2::mutable_data() { + return &data_; +} + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_Data3 + +// repeated string data = 1; +inline int TestConflictingSymbolNames_Data3::data_size() const { + return data_.size(); +} +inline void TestConflictingSymbolNames_Data3::clear_data() { + data_.Clear(); +} +inline const ::std::string& TestConflictingSymbolNames_Data3::data(int index) const { + return data_.Get(index); +} +inline ::std::string* TestConflictingSymbolNames_Data3::mutable_data(int index) { + return data_.Mutable(index); +} +inline void TestConflictingSymbolNames_Data3::set_data(int index, const ::std::string& value) { + data_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames_Data3::set_data(int index, const char* value) { + data_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames_Data3::set_data(int index, const char* value, size_t size) { + data_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames_Data3::add_data() { + return data_.Add(); +} +inline void TestConflictingSymbolNames_Data3::add_data(const ::std::string& value) { + data_.Add()->assign(value); +} +inline void TestConflictingSymbolNames_Data3::add_data(const char* value) { + data_.Add()->assign(value); +} +inline void TestConflictingSymbolNames_Data3::add_data(const char* value, size_t size) { + data_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestConflictingSymbolNames_Data3::data() const { + return data_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestConflictingSymbolNames_Data3::mutable_data() { + return &data_; +} + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_Data4 + +// repeated .protobuf_unittest.TestConflictingSymbolNames.Data4 data = 1; +inline int TestConflictingSymbolNames_Data4::data_size() const { + return data_.size(); +} +inline void TestConflictingSymbolNames_Data4::clear_data() { + data_.Clear(); +} +inline const ::protobuf_unittest::TestConflictingSymbolNames_Data4& TestConflictingSymbolNames_Data4::data(int index) const { + return data_.Get(index); +} +inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* TestConflictingSymbolNames_Data4::mutable_data(int index) { + return data_.Mutable(index); +} +inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* TestConflictingSymbolNames_Data4::add_data() { + return data_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >& +TestConflictingSymbolNames_Data4::data() const { + return data_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >* +TestConflictingSymbolNames_Data4::mutable_data() { + return &data_; +} + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_Data5 + +// repeated string data = 1 [ctype = STRING_PIECE]; +inline int TestConflictingSymbolNames_Data5::data_size() const { + return data_.size(); +} +inline void TestConflictingSymbolNames_Data5::clear_data() { + data_.Clear(); +} +inline const ::std::string& TestConflictingSymbolNames_Data5::data(int index) const { + return data_.Get(index); +} +inline ::std::string* TestConflictingSymbolNames_Data5::mutable_data(int index) { + return data_.Mutable(index); +} +inline void TestConflictingSymbolNames_Data5::set_data(int index, const ::std::string& value) { + data_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames_Data5::set_data(int index, const char* value) { + data_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames_Data5::set_data(int index, const char* value, size_t size) { + data_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames_Data5::add_data() { + return data_.Add(); +} +inline void TestConflictingSymbolNames_Data5::add_data(const ::std::string& value) { + data_.Add()->assign(value); +} +inline void TestConflictingSymbolNames_Data5::add_data(const char* value) { + data_.Add()->assign(value); +} +inline void TestConflictingSymbolNames_Data5::add_data(const char* value, size_t size) { + data_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestConflictingSymbolNames_Data5::data() const { + return data_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestConflictingSymbolNames_Data5::mutable_data() { + return &data_; +} + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_Data6 + +// repeated string data = 1 [ctype = CORD]; +inline int TestConflictingSymbolNames_Data6::data_size() const { + return data_.size(); +} +inline void TestConflictingSymbolNames_Data6::clear_data() { + data_.Clear(); +} +inline const ::std::string& TestConflictingSymbolNames_Data6::data(int index) const { + return data_.Get(index); +} +inline ::std::string* TestConflictingSymbolNames_Data6::mutable_data(int index) { + return data_.Mutable(index); +} +inline void TestConflictingSymbolNames_Data6::set_data(int index, const ::std::string& value) { + data_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames_Data6::set_data(int index, const char* value) { + data_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames_Data6::set_data(int index, const char* value, size_t size) { + data_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames_Data6::add_data() { + return data_.Add(); +} +inline void TestConflictingSymbolNames_Data6::add_data(const ::std::string& value) { + data_.Add()->assign(value); +} +inline void TestConflictingSymbolNames_Data6::add_data(const char* value) { + data_.Add()->assign(value); +} +inline void TestConflictingSymbolNames_Data6::add_data(const char* value, size_t size) { + data_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestConflictingSymbolNames_Data6::data() const { + return data_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestConflictingSymbolNames_Data6::mutable_data() { + return &data_; +} + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_Cord + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_StringPiece + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames_DO + +// ------------------------------------------------------------------- + +// TestConflictingSymbolNames + +// optional int32 input = 1; +inline bool TestConflictingSymbolNames::has_input() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestConflictingSymbolNames::set_has_input() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestConflictingSymbolNames::clear_has_input() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestConflictingSymbolNames::clear_input() { + input_ = 0; + clear_has_input(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::input() const { + return input_; +} +inline void TestConflictingSymbolNames::set_input(::google::protobuf::int32 value) { + set_has_input(); + input_ = value; +} + +// optional int32 output = 2; +inline bool TestConflictingSymbolNames::has_output() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestConflictingSymbolNames::set_has_output() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestConflictingSymbolNames::clear_has_output() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestConflictingSymbolNames::clear_output() { + output_ = 0; + clear_has_output(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::output() const { + return output_; +} +inline void TestConflictingSymbolNames::set_output(::google::protobuf::int32 value) { + set_has_output(); + output_ = value; +} + +// optional string length = 3; +inline bool TestConflictingSymbolNames::has_length() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestConflictingSymbolNames::set_has_length() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestConflictingSymbolNames::clear_has_length() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestConflictingSymbolNames::clear_length() { + if (length_ != &::google::protobuf::internal::kEmptyString) { + length_->clear(); + } + clear_has_length(); +} +inline const ::std::string& TestConflictingSymbolNames::length() const { + return *length_; +} +inline void TestConflictingSymbolNames::set_length(const ::std::string& value) { + set_has_length(); + if (length_ == &::google::protobuf::internal::kEmptyString) { + length_ = new ::std::string; + } + length_->assign(value); +} +inline void TestConflictingSymbolNames::set_length(const char* value) { + set_has_length(); + if (length_ == &::google::protobuf::internal::kEmptyString) { + length_ = new ::std::string; + } + length_->assign(value); +} +inline void TestConflictingSymbolNames::set_length(const char* value, size_t size) { + set_has_length(); + if (length_ == &::google::protobuf::internal::kEmptyString) { + length_ = new ::std::string; + } + length_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames::mutable_length() { + set_has_length(); + if (length_ == &::google::protobuf::internal::kEmptyString) { + length_ = new ::std::string; + } + return length_; +} +inline ::std::string* TestConflictingSymbolNames::release_length() { + clear_has_length(); + if (length_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = length_; + length_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated int32 i = 4; +inline int TestConflictingSymbolNames::i_size() const { + return i_.size(); +} +inline void TestConflictingSymbolNames::clear_i() { + i_.Clear(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::i(int index) const { + return i_.Get(index); +} +inline void TestConflictingSymbolNames::set_i(int index, ::google::protobuf::int32 value) { + i_.Set(index, value); +} +inline void TestConflictingSymbolNames::add_i(::google::protobuf::int32 value) { + i_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestConflictingSymbolNames::i() const { + return i_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestConflictingSymbolNames::mutable_i() { + return &i_; +} + +// repeated string new_element = 5 [ctype = STRING_PIECE]; +inline int TestConflictingSymbolNames::new_element_size() const { + return new_element_.size(); +} +inline void TestConflictingSymbolNames::clear_new_element() { + new_element_.Clear(); +} +inline const ::std::string& TestConflictingSymbolNames::new_element(int index) const { + return new_element_.Get(index); +} +inline ::std::string* TestConflictingSymbolNames::mutable_new_element(int index) { + return new_element_.Mutable(index); +} +inline void TestConflictingSymbolNames::set_new_element(int index, const ::std::string& value) { + new_element_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames::set_new_element(int index, const char* value) { + new_element_.Mutable(index)->assign(value); +} +inline void TestConflictingSymbolNames::set_new_element(int index, const char* value, size_t size) { + new_element_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames::add_new_element() { + return new_element_.Add(); +} +inline void TestConflictingSymbolNames::add_new_element(const ::std::string& value) { + new_element_.Add()->assign(value); +} +inline void TestConflictingSymbolNames::add_new_element(const char* value) { + new_element_.Add()->assign(value); +} +inline void TestConflictingSymbolNames::add_new_element(const char* value, size_t size) { + new_element_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestConflictingSymbolNames::new_element() const { + return new_element_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestConflictingSymbolNames::mutable_new_element() { + return &new_element_; +} + +// optional int32 total_size = 6; +inline bool TestConflictingSymbolNames::has_total_size() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void TestConflictingSymbolNames::set_has_total_size() { + _has_bits_[0] |= 0x00000020u; +} +inline void TestConflictingSymbolNames::clear_has_total_size() { + _has_bits_[0] &= ~0x00000020u; +} +inline void TestConflictingSymbolNames::clear_total_size() { + total_size_ = 0; + clear_has_total_size(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::total_size() const { + return total_size_; +} +inline void TestConflictingSymbolNames::set_total_size(::google::protobuf::int32 value) { + set_has_total_size(); + total_size_ = value; +} + +// optional int32 tag = 7; +inline bool TestConflictingSymbolNames::has_tag() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void TestConflictingSymbolNames::set_has_tag() { + _has_bits_[0] |= 0x00000040u; +} +inline void TestConflictingSymbolNames::clear_has_tag() { + _has_bits_[0] &= ~0x00000040u; +} +inline void TestConflictingSymbolNames::clear_tag() { + tag_ = 0; + clear_has_tag(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::tag() const { + return tag_; +} +inline void TestConflictingSymbolNames::set_tag(::google::protobuf::int32 value) { + set_has_tag(); + tag_ = value; +} + +// optional int32 source = 8; +inline bool TestConflictingSymbolNames::has_source() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void TestConflictingSymbolNames::set_has_source() { + _has_bits_[0] |= 0x00000080u; +} +inline void TestConflictingSymbolNames::clear_has_source() { + _has_bits_[0] &= ~0x00000080u; +} +inline void TestConflictingSymbolNames::clear_source() { + source_ = 0; + clear_has_source(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::source() const { + return source_; +} +inline void TestConflictingSymbolNames::set_source(::google::protobuf::int32 value) { + set_has_source(); + source_ = value; +} + +// optional int32 value = 9; +inline bool TestConflictingSymbolNames::has_value() const { + return (_has_bits_[0] & 0x00000100u) != 0; +} +inline void TestConflictingSymbolNames::set_has_value() { + _has_bits_[0] |= 0x00000100u; +} +inline void TestConflictingSymbolNames::clear_has_value() { + _has_bits_[0] &= ~0x00000100u; +} +inline void TestConflictingSymbolNames::clear_value() { + value_ = 0; + clear_has_value(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::value() const { + return value_; +} +inline void TestConflictingSymbolNames::set_value(::google::protobuf::int32 value) { + set_has_value(); + value_ = value; +} + +// optional int32 file = 10; +inline bool TestConflictingSymbolNames::has_file() const { + return (_has_bits_[0] & 0x00000200u) != 0; +} +inline void TestConflictingSymbolNames::set_has_file() { + _has_bits_[0] |= 0x00000200u; +} +inline void TestConflictingSymbolNames::clear_has_file() { + _has_bits_[0] &= ~0x00000200u; +} +inline void TestConflictingSymbolNames::clear_file() { + file_ = 0; + clear_has_file(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::file() const { + return file_; +} +inline void TestConflictingSymbolNames::set_file(::google::protobuf::int32 value) { + set_has_file(); + file_ = value; +} + +// optional int32 from = 11; +inline bool TestConflictingSymbolNames::has_from() const { + return (_has_bits_[0] & 0x00000400u) != 0; +} +inline void TestConflictingSymbolNames::set_has_from() { + _has_bits_[0] |= 0x00000400u; +} +inline void TestConflictingSymbolNames::clear_has_from() { + _has_bits_[0] &= ~0x00000400u; +} +inline void TestConflictingSymbolNames::clear_from() { + from_ = 0; + clear_has_from(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::from() const { + return from_; +} +inline void TestConflictingSymbolNames::set_from(::google::protobuf::int32 value) { + set_has_from(); + from_ = value; +} + +// optional int32 handle_uninterpreted = 12; +inline bool TestConflictingSymbolNames::has_handle_uninterpreted() const { + return (_has_bits_[0] & 0x00000800u) != 0; +} +inline void TestConflictingSymbolNames::set_has_handle_uninterpreted() { + _has_bits_[0] |= 0x00000800u; +} +inline void TestConflictingSymbolNames::clear_has_handle_uninterpreted() { + _has_bits_[0] &= ~0x00000800u; +} +inline void TestConflictingSymbolNames::clear_handle_uninterpreted() { + handle_uninterpreted_ = 0; + clear_has_handle_uninterpreted(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::handle_uninterpreted() const { + return handle_uninterpreted_; +} +inline void TestConflictingSymbolNames::set_handle_uninterpreted(::google::protobuf::int32 value) { + set_has_handle_uninterpreted(); + handle_uninterpreted_ = value; +} + +// repeated int32 index = 13; +inline int TestConflictingSymbolNames::index_size() const { + return index_.size(); +} +inline void TestConflictingSymbolNames::clear_index() { + index_.Clear(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::index(int index) const { + return index_.Get(index); +} +inline void TestConflictingSymbolNames::set_index(int index, ::google::protobuf::int32 value) { + index_.Set(index, value); +} +inline void TestConflictingSymbolNames::add_index(::google::protobuf::int32 value) { + index_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestConflictingSymbolNames::index() const { + return index_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestConflictingSymbolNames::mutable_index() { + return &index_; +} + +// optional int32 controller = 14; +inline bool TestConflictingSymbolNames::has_controller() const { + return (_has_bits_[0] & 0x00002000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_controller() { + _has_bits_[0] |= 0x00002000u; +} +inline void TestConflictingSymbolNames::clear_has_controller() { + _has_bits_[0] &= ~0x00002000u; +} +inline void TestConflictingSymbolNames::clear_controller() { + controller_ = 0; + clear_has_controller(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::controller() const { + return controller_; +} +inline void TestConflictingSymbolNames::set_controller(::google::protobuf::int32 value) { + set_has_controller(); + controller_ = value; +} + +// optional int32 already_here = 15; +inline bool TestConflictingSymbolNames::has_already_here() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_already_here() { + _has_bits_[0] |= 0x00004000u; +} +inline void TestConflictingSymbolNames::clear_has_already_here() { + _has_bits_[0] &= ~0x00004000u; +} +inline void TestConflictingSymbolNames::clear_already_here() { + already_here_ = 0; + clear_has_already_here(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::already_here() const { + return already_here_; +} +inline void TestConflictingSymbolNames::set_already_here(::google::protobuf::int32 value) { + set_has_already_here(); + already_here_ = value; +} + +// optional uint32 uint32 = 16; +inline bool TestConflictingSymbolNames::has_uint32() const { + return (_has_bits_[0] & 0x00008000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_uint32() { + _has_bits_[0] |= 0x00008000u; +} +inline void TestConflictingSymbolNames::clear_has_uint32() { + _has_bits_[0] &= ~0x00008000u; +} +inline void TestConflictingSymbolNames::clear_uint32() { + uint32_ = 0u; + clear_has_uint32(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::uint32() const { + return uint32_; +} +inline void TestConflictingSymbolNames::set_uint32(::google::protobuf::uint32 value) { + set_has_uint32(); + uint32_ = value; +} + +// optional uint64 uint64 = 17; +inline bool TestConflictingSymbolNames::has_uint64() const { + return (_has_bits_[0] & 0x00010000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_uint64() { + _has_bits_[0] |= 0x00010000u; +} +inline void TestConflictingSymbolNames::clear_has_uint64() { + _has_bits_[0] &= ~0x00010000u; +} +inline void TestConflictingSymbolNames::clear_uint64() { + uint64_ = GOOGLE_ULONGLONG(0); + clear_has_uint64(); +} +inline ::google::protobuf::uint64 TestConflictingSymbolNames::uint64() const { + return uint64_; +} +inline void TestConflictingSymbolNames::set_uint64(::google::protobuf::uint64 value) { + set_has_uint64(); + uint64_ = value; +} + +// optional string string = 18; +inline bool TestConflictingSymbolNames::has_string() const { + return (_has_bits_[0] & 0x00020000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_string() { + _has_bits_[0] |= 0x00020000u; +} +inline void TestConflictingSymbolNames::clear_has_string() { + _has_bits_[0] &= ~0x00020000u; +} +inline void TestConflictingSymbolNames::clear_string() { + if (string_ != &::google::protobuf::internal::kEmptyString) { + string_->clear(); + } + clear_has_string(); +} +inline const ::std::string& TestConflictingSymbolNames::string() const { + return *string_; +} +inline void TestConflictingSymbolNames::set_string(const ::std::string& value) { + set_has_string(); + if (string_ == &::google::protobuf::internal::kEmptyString) { + string_ = new ::std::string; + } + string_->assign(value); +} +inline void TestConflictingSymbolNames::set_string(const char* value) { + set_has_string(); + if (string_ == &::google::protobuf::internal::kEmptyString) { + string_ = new ::std::string; + } + string_->assign(value); +} +inline void TestConflictingSymbolNames::set_string(const char* value, size_t size) { + set_has_string(); + if (string_ == &::google::protobuf::internal::kEmptyString) { + string_ = new ::std::string; + } + string_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames::mutable_string() { + set_has_string(); + if (string_ == &::google::protobuf::internal::kEmptyString) { + string_ = new ::std::string; + } + return string_; +} +inline ::std::string* TestConflictingSymbolNames::release_string() { + clear_has_string(); + if (string_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = string_; + string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional int32 memset = 19; +inline bool TestConflictingSymbolNames::has_memset() const { + return (_has_bits_[0] & 0x00040000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_memset() { + _has_bits_[0] |= 0x00040000u; +} +inline void TestConflictingSymbolNames::clear_has_memset() { + _has_bits_[0] &= ~0x00040000u; +} +inline void TestConflictingSymbolNames::clear_memset() { + memset_ = 0; + clear_has_memset(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::memset() const { + return memset_; +} +inline void TestConflictingSymbolNames::set_memset(::google::protobuf::int32 value) { + set_has_memset(); + memset_ = value; +} + +// optional int32 int32 = 20; +inline bool TestConflictingSymbolNames::has_int32() const { + return (_has_bits_[0] & 0x00080000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_int32() { + _has_bits_[0] |= 0x00080000u; +} +inline void TestConflictingSymbolNames::clear_has_int32() { + _has_bits_[0] &= ~0x00080000u; +} +inline void TestConflictingSymbolNames::clear_int32() { + int32_ = 0; + clear_has_int32(); +} +inline ::google::protobuf::int32 TestConflictingSymbolNames::int32() const { + return int32_; +} +inline void TestConflictingSymbolNames::set_int32(::google::protobuf::int32 value) { + set_has_int32(); + int32_ = value; +} + +// optional int64 int64 = 21; +inline bool TestConflictingSymbolNames::has_int64() const { + return (_has_bits_[0] & 0x00100000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_int64() { + _has_bits_[0] |= 0x00100000u; +} +inline void TestConflictingSymbolNames::clear_has_int64() { + _has_bits_[0] &= ~0x00100000u; +} +inline void TestConflictingSymbolNames::clear_int64() { + int64_ = GOOGLE_LONGLONG(0); + clear_has_int64(); +} +inline ::google::protobuf::int64 TestConflictingSymbolNames::int64() const { + return int64_; +} +inline void TestConflictingSymbolNames::set_int64(::google::protobuf::int64 value) { + set_has_int64(); + int64_ = value; +} + +// optional uint32 cached_size = 22; +inline bool TestConflictingSymbolNames::has_cached_size() const { + return (_has_bits_[0] & 0x00200000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_cached_size() { + _has_bits_[0] |= 0x00200000u; +} +inline void TestConflictingSymbolNames::clear_has_cached_size() { + _has_bits_[0] &= ~0x00200000u; +} +inline void TestConflictingSymbolNames::clear_cached_size() { + cached_size_ = 0u; + clear_has_cached_size(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::cached_size() const { + return cached_size_; +} +inline void TestConflictingSymbolNames::set_cached_size(::google::protobuf::uint32 value) { + set_has_cached_size(); + cached_size_ = value; +} + +// optional uint32 extensions = 23; +inline bool TestConflictingSymbolNames::has_extensions() const { + return (_has_bits_[0] & 0x00400000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_extensions() { + _has_bits_[0] |= 0x00400000u; +} +inline void TestConflictingSymbolNames::clear_has_extensions() { + _has_bits_[0] &= ~0x00400000u; +} +inline void TestConflictingSymbolNames::clear_extensions() { + extensions_ = 0u; + clear_has_extensions(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::extensions() const { + return extensions_; +} +inline void TestConflictingSymbolNames::set_extensions(::google::protobuf::uint32 value) { + set_has_extensions(); + extensions_ = value; +} + +// optional uint32 bit = 24; +inline bool TestConflictingSymbolNames::has_bit() const { + return (_has_bits_[0] & 0x00800000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_bit() { + _has_bits_[0] |= 0x00800000u; +} +inline void TestConflictingSymbolNames::clear_has_bit() { + _has_bits_[0] &= ~0x00800000u; +} +inline void TestConflictingSymbolNames::clear_bit() { + bit_ = 0u; + clear_has_bit(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::bit() const { + return bit_; +} +inline void TestConflictingSymbolNames::set_bit(::google::protobuf::uint32 value) { + set_has_bit(); + bit_ = value; +} + +// optional uint32 bits = 25; +inline bool TestConflictingSymbolNames::has_bits() const { + return (_has_bits_[0] & 0x01000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_bits() { + _has_bits_[0] |= 0x01000000u; +} +inline void TestConflictingSymbolNames::clear_has_bits() { + _has_bits_[0] &= ~0x01000000u; +} +inline void TestConflictingSymbolNames::clear_bits() { + bits_ = 0u; + clear_has_bits(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::bits() const { + return bits_; +} +inline void TestConflictingSymbolNames::set_bits(::google::protobuf::uint32 value) { + set_has_bits(); + bits_ = value; +} + +// optional uint32 offsets = 26; +inline bool TestConflictingSymbolNames::has_offsets() const { + return (_has_bits_[0] & 0x02000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_offsets() { + _has_bits_[0] |= 0x02000000u; +} +inline void TestConflictingSymbolNames::clear_has_offsets() { + _has_bits_[0] &= ~0x02000000u; +} +inline void TestConflictingSymbolNames::clear_offsets() { + offsets_ = 0u; + clear_has_offsets(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::offsets() const { + return offsets_; +} +inline void TestConflictingSymbolNames::set_offsets(::google::protobuf::uint32 value) { + set_has_offsets(); + offsets_ = value; +} + +// optional uint32 reflection = 27; +inline bool TestConflictingSymbolNames::has_reflection() const { + return (_has_bits_[0] & 0x04000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_reflection() { + _has_bits_[0] |= 0x04000000u; +} +inline void TestConflictingSymbolNames::clear_has_reflection() { + _has_bits_[0] &= ~0x04000000u; +} +inline void TestConflictingSymbolNames::clear_reflection() { + reflection_ = 0u; + clear_has_reflection(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::reflection() const { + return reflection_; +} +inline void TestConflictingSymbolNames::set_reflection(::google::protobuf::uint32 value) { + set_has_reflection(); + reflection_ = value; +} + +// optional string some_cord = 28 [ctype = CORD]; +inline bool TestConflictingSymbolNames::has_some_cord() const { + return (_has_bits_[0] & 0x08000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_some_cord() { + _has_bits_[0] |= 0x08000000u; +} +inline void TestConflictingSymbolNames::clear_has_some_cord() { + _has_bits_[0] &= ~0x08000000u; +} +inline void TestConflictingSymbolNames::clear_some_cord() { + if (some_cord_ != &::google::protobuf::internal::kEmptyString) { + some_cord_->clear(); + } + clear_has_some_cord(); +} +inline const ::std::string& TestConflictingSymbolNames::some_cord() const { + return *some_cord_; +} +inline void TestConflictingSymbolNames::set_some_cord(const ::std::string& value) { + set_has_some_cord(); + if (some_cord_ == &::google::protobuf::internal::kEmptyString) { + some_cord_ = new ::std::string; + } + some_cord_->assign(value); +} +inline void TestConflictingSymbolNames::set_some_cord(const char* value) { + set_has_some_cord(); + if (some_cord_ == &::google::protobuf::internal::kEmptyString) { + some_cord_ = new ::std::string; + } + some_cord_->assign(value); +} +inline void TestConflictingSymbolNames::set_some_cord(const char* value, size_t size) { + set_has_some_cord(); + if (some_cord_ == &::google::protobuf::internal::kEmptyString) { + some_cord_ = new ::std::string; + } + some_cord_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames::mutable_some_cord() { + set_has_some_cord(); + if (some_cord_ == &::google::protobuf::internal::kEmptyString) { + some_cord_ = new ::std::string; + } + return some_cord_; +} +inline ::std::string* TestConflictingSymbolNames::release_some_cord() { + clear_has_some_cord(); + if (some_cord_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = some_cord_; + some_cord_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string some_string_piece = 29 [ctype = STRING_PIECE]; +inline bool TestConflictingSymbolNames::has_some_string_piece() const { + return (_has_bits_[0] & 0x10000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_some_string_piece() { + _has_bits_[0] |= 0x10000000u; +} +inline void TestConflictingSymbolNames::clear_has_some_string_piece() { + _has_bits_[0] &= ~0x10000000u; +} +inline void TestConflictingSymbolNames::clear_some_string_piece() { + if (some_string_piece_ != &::google::protobuf::internal::kEmptyString) { + some_string_piece_->clear(); + } + clear_has_some_string_piece(); +} +inline const ::std::string& TestConflictingSymbolNames::some_string_piece() const { + return *some_string_piece_; +} +inline void TestConflictingSymbolNames::set_some_string_piece(const ::std::string& value) { + set_has_some_string_piece(); + if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { + some_string_piece_ = new ::std::string; + } + some_string_piece_->assign(value); +} +inline void TestConflictingSymbolNames::set_some_string_piece(const char* value) { + set_has_some_string_piece(); + if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { + some_string_piece_ = new ::std::string; + } + some_string_piece_->assign(value); +} +inline void TestConflictingSymbolNames::set_some_string_piece(const char* value, size_t size) { + set_has_some_string_piece(); + if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { + some_string_piece_ = new ::std::string; + } + some_string_piece_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestConflictingSymbolNames::mutable_some_string_piece() { + set_has_some_string_piece(); + if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { + some_string_piece_ = new ::std::string; + } + return some_string_piece_; +} +inline ::std::string* TestConflictingSymbolNames::release_some_string_piece() { + clear_has_some_string_piece(); + if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = some_string_piece_; + some_string_piece_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional uint32 int = 30; +inline bool TestConflictingSymbolNames::has_int_() const { + return (_has_bits_[0] & 0x20000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_int_() { + _has_bits_[0] |= 0x20000000u; +} +inline void TestConflictingSymbolNames::clear_has_int_() { + _has_bits_[0] &= ~0x20000000u; +} +inline void TestConflictingSymbolNames::clear_int_() { + int__ = 0u; + clear_has_int_(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::int_() const { + return int__; +} +inline void TestConflictingSymbolNames::set_int_(::google::protobuf::uint32 value) { + set_has_int_(); + int__ = value; +} + +// optional uint32 friend = 31; +inline bool TestConflictingSymbolNames::has_friend_() const { + return (_has_bits_[0] & 0x40000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_friend_() { + _has_bits_[0] |= 0x40000000u; +} +inline void TestConflictingSymbolNames::clear_has_friend_() { + _has_bits_[0] &= ~0x40000000u; +} +inline void TestConflictingSymbolNames::clear_friend_() { + friend__ = 0u; + clear_has_friend_(); +} +inline ::google::protobuf::uint32 TestConflictingSymbolNames::friend_() const { + return friend__; +} +inline void TestConflictingSymbolNames::set_friend_(::google::protobuf::uint32 value) { + set_has_friend_(); + friend__ = value; +} + +// optional .protobuf_unittest.TestConflictingSymbolNames.DO do = 32; +inline bool TestConflictingSymbolNames::has_do_() const { + return (_has_bits_[0] & 0x80000000u) != 0; +} +inline void TestConflictingSymbolNames::set_has_do_() { + _has_bits_[0] |= 0x80000000u; +} +inline void TestConflictingSymbolNames::clear_has_do_() { + _has_bits_[0] &= ~0x80000000u; +} +inline void TestConflictingSymbolNames::clear_do_() { + if (do__ != NULL) do__->::protobuf_unittest::TestConflictingSymbolNames_DO::Clear(); + clear_has_do_(); +} +inline const ::protobuf_unittest::TestConflictingSymbolNames_DO& TestConflictingSymbolNames::do_() const { + return do__ != NULL ? *do__ : *default_instance_->do__; +} +inline ::protobuf_unittest::TestConflictingSymbolNames_DO* TestConflictingSymbolNames::mutable_do_() { + set_has_do_(); + if (do__ == NULL) do__ = new ::protobuf_unittest::TestConflictingSymbolNames_DO; + return do__; +} +inline ::protobuf_unittest::TestConflictingSymbolNames_DO* TestConflictingSymbolNames::release_do_() { + clear_has_do_(); + ::protobuf_unittest::TestConflictingSymbolNames_DO* temp = do__; + do__ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// DummyMessage + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +#ifndef SWIG +namespace google { +namespace protobuf { + +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestConflictingSymbolNames_TestEnum>() { + return ::protobuf_unittest::TestConflictingSymbolNames_TestEnum_descriptor(); +} + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h new file mode 100644 index 00000000..7a2efc29 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h @@ -0,0 +1,303 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file is the public interface to the .proto file parser. + +#ifndef GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ +#define GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ + +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { + +namespace io { class ZeroCopyInputStream; } + +namespace compiler { + +// Defined in this file. +class Importer; +class MultiFileErrorCollector; +class SourceTree; +class DiskSourceTree; + +// TODO(kenton): Move all SourceTree stuff to a separate file? + +// An implementation of DescriptorDatabase which loads files from a SourceTree +// and parses them. +// +// Note: This class is not thread-safe since it maintains a table of source +// code locations for error reporting. However, when a DescriptorPool wraps +// a DescriptorDatabase, it uses mutex locking to make sure only one method +// of the database is called at a time, even if the DescriptorPool is used +// from multiple threads. Therefore, there is only a problem if you create +// multiple DescriptorPools wrapping the same SourceTreeDescriptorDatabase +// and use them from multiple threads. +// +// Note: This class does not implement FindFileContainingSymbol() or +// FindFileContainingExtension(); these will always return false. +class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase { + public: + SourceTreeDescriptorDatabase(SourceTree* source_tree); + ~SourceTreeDescriptorDatabase(); + + // Instructs the SourceTreeDescriptorDatabase to report any parse errors + // to the given MultiFileErrorCollector. This should be called before + // parsing. error_collector must remain valid until either this method + // is called again or the SourceTreeDescriptorDatabase is destroyed. + void RecordErrorsTo(MultiFileErrorCollector* error_collector) { + error_collector_ = error_collector; + } + + // Gets a DescriptorPool::ErrorCollector which records errors to the + // MultiFileErrorCollector specified with RecordErrorsTo(). This collector + // has the ability to determine exact line and column numbers of errors + // from the information given to it by the DescriptorPool. + DescriptorPool::ErrorCollector* GetValidationErrorCollector() { + using_validation_error_collector_ = true; + return &validation_error_collector_; + } + + // implements DescriptorDatabase ----------------------------------- + bool FindFileByName(const string& filename, FileDescriptorProto* output); + bool FindFileContainingSymbol(const string& symbol_name, + FileDescriptorProto* output); + bool FindFileContainingExtension(const string& containing_type, + int field_number, + FileDescriptorProto* output); + + private: + class SingleFileErrorCollector; + + SourceTree* source_tree_; + MultiFileErrorCollector* error_collector_; + + class LIBPROTOBUF_EXPORT ValidationErrorCollector : public DescriptorPool::ErrorCollector { + public: + ValidationErrorCollector(SourceTreeDescriptorDatabase* owner); + ~ValidationErrorCollector(); + + // implements ErrorCollector --------------------------------------- + void AddError(const string& filename, + const string& element_name, + const Message* descriptor, + ErrorLocation location, + const string& message); + + private: + SourceTreeDescriptorDatabase* owner_; + }; + friend class ValidationErrorCollector; + + bool using_validation_error_collector_; + SourceLocationTable source_locations_; + ValidationErrorCollector validation_error_collector_; +}; + +// Simple interface for parsing .proto files. This wraps the process +// of opening the file, parsing it with a Parser, recursively parsing all its +// imports, and then cross-linking the results to produce a FileDescriptor. +// +// This is really just a thin wrapper around SourceTreeDescriptorDatabase. +// You may find that SourceTreeDescriptorDatabase is more flexible. +// +// TODO(kenton): I feel like this class is not well-named. +class LIBPROTOBUF_EXPORT Importer { + public: + Importer(SourceTree* source_tree, + MultiFileErrorCollector* error_collector); + ~Importer(); + + // Import the given file and build a FileDescriptor representing it. If + // the file is already in the DescriptorPool, the existing FileDescriptor + // will be returned. The FileDescriptor is property of the DescriptorPool, + // and will remain valid until it is destroyed. If any errors occur, they + // will be reported using the error collector and Import() will return NULL. + // + // A particular Importer object will only report errors for a particular + // file once. All future attempts to import the same file will return NULL + // without reporting any errors. The idea is that you might want to import + // a lot of files without seeing the same errors over and over again. If + // you want to see errors for the same files repeatedly, you can use a + // separate Importer object to import each one (but use the same + // DescriptorPool so that they can be cross-linked). + const FileDescriptor* Import(const string& filename); + + // The DescriptorPool in which all imported FileDescriptors and their + // contents are stored. + inline const DescriptorPool* pool() const { + return &pool_; + } + + private: + SourceTreeDescriptorDatabase database_; + DescriptorPool pool_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); +}; + +// If the importer encounters problems while trying to import the proto files, +// it reports them to a MultiFileErrorCollector. +class LIBPROTOBUF_EXPORT MultiFileErrorCollector { + public: + inline MultiFileErrorCollector() {} + virtual ~MultiFileErrorCollector(); + + // Line and column numbers are zero-based. A line number of -1 indicates + // an error with the entire file (e.g. "not found"). + virtual void AddError(const string& filename, int line, int column, + const string& message) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); +}; + +// Abstract interface which represents a directory tree containing proto files. +// Used by the default implementation of Importer to resolve import statements +// Most users will probably want to use the DiskSourceTree implementation, +// below. +class LIBPROTOBUF_EXPORT SourceTree { + public: + inline SourceTree() {} + virtual ~SourceTree(); + + // Open the given file and return a stream that reads it, or NULL if not + // found. The caller takes ownership of the returned object. The filename + // must be a path relative to the root of the source tree and must not + // contain "." or ".." components. + virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); +}; + +// An implementation of SourceTree which loads files from locations on disk. +// Multiple mappings can be set up to map locations in the DiskSourceTree to +// locations in the physical filesystem. +class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { + public: + DiskSourceTree(); + ~DiskSourceTree(); + + // Map a path on disk to a location in the SourceTree. The path may be + // either a file or a directory. If it is a directory, the entire tree + // under it will be mapped to the given virtual location. To map a directory + // to the root of the source tree, pass an empty string for virtual_path. + // + // If multiple mapped paths apply when opening a file, they will be searched + // in order. For example, if you do: + // MapPath("bar", "foo/bar"); + // MapPath("", "baz"); + // and then you do: + // Open("bar/qux"); + // the DiskSourceTree will first try to open foo/bar/qux, then baz/bar/qux, + // returning the first one that opens successfuly. + // + // disk_path may be an absolute path or relative to the current directory, + // just like a path you'd pass to open(). + void MapPath(const string& virtual_path, const string& disk_path); + + // Return type for DiskFileToVirtualFile(). + enum DiskFileToVirtualFileResult { + SUCCESS, + SHADOWED, + CANNOT_OPEN, + NO_MAPPING + }; + + // Given a path to a file on disk, find a virtual path mapping to that + // file. The first mapping created with MapPath() whose disk_path contains + // the filename is used. However, that virtual path may not actually be + // usable to open the given file. Possible return values are: + // * SUCCESS: The mapping was found. *virtual_file is filled in so that + // calling Open(*virtual_file) will open the file named by disk_file. + // * SHADOWED: A mapping was found, but using Open() to open this virtual + // path will end up returning some different file. This is because some + // other mapping with a higher precedence also matches this virtual path + // and maps it to a different file that exists on disk. *virtual_file + // is filled in as it would be in the SUCCESS case. *shadowing_disk_file + // is filled in with the disk path of the file which would be opened if + // you were to call Open(*virtual_file). + // * CANNOT_OPEN: The mapping was found and was not shadowed, but the + // file specified cannot be opened. When this value is returned, + // errno will indicate the reason the file cannot be opened. *virtual_file + // will be set to the virtual path as in the SUCCESS case, even though + // it is not useful. + // * NO_MAPPING: Indicates that no mapping was found which contains this + // file. + DiskFileToVirtualFileResult + DiskFileToVirtualFile(const string& disk_file, + string* virtual_file, + string* shadowing_disk_file); + + // Given a virtual path, find the path to the file on disk. + // Return true and update disk_file with the on-disk path if the file exists. + // Return false and leave disk_file untouched if the file doesn't exist. + bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); + + // implements SourceTree ------------------------------------------- + io::ZeroCopyInputStream* Open(const string& filename); + + private: + struct Mapping { + string virtual_path; + string disk_path; + + inline Mapping(const string& virtual_path, const string& disk_path) + : virtual_path(virtual_path), disk_path(disk_path) {} + }; + vector mappings_; + + // Like Open(), but returns the on-disk path in disk_file if disk_file is + // non-NULL and the file could be successfully opened. + io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, + string* disk_file); + + // Like Open() but given the actual on-disk path. + io::ZeroCopyInputStream* OpenDiskFile(const string& filename); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); +}; + +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h new file mode 100644 index 00000000..05ece1f1 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h @@ -0,0 +1,84 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace java { + +class EnumGenerator { + public: + explicit EnumGenerator(const EnumDescriptor* descriptor); + ~EnumGenerator(); + + void Generate(io::Printer* printer); + + private: + const EnumDescriptor* descriptor_; + + // The proto language allows multiple enum constants to have the same numeric + // value. Java, however, does not allow multiple enum constants to be + // considered equivalent. We treat the first defined constant for any + // given numeric value as "canonical" and the rest as aliases of that + // canonical value. + vector canonical_values_; + + struct Alias { + const EnumValueDescriptor* value; + const EnumValueDescriptor* canonical_value; + }; + vector aliases_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h new file mode 100644 index 00000000..0cad6be0 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h @@ -0,0 +1,121 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +class EnumFieldGenerator : public FieldGenerator { + public: + explicit EnumFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~EnumFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); +}; + +class RepeatedEnumFieldGenerator : public FieldGenerator { + public: + explicit RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~RepeatedEnumFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateParsingCodeFromPacked(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h new file mode 100644 index 00000000..009ed9ff --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h @@ -0,0 +1,77 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ + +#include + +#include + +namespace google { +namespace protobuf { + class FieldDescriptor; // descriptor.h + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace java { + +// Generates code for an extension, which may be within the scope of some +// message or may be at file scope. This is much simpler than FieldGenerator +// since extensions are just simple identifiers with interesting types. +class ExtensionGenerator { + public: + explicit ExtensionGenerator(const FieldDescriptor* descriptor); + ~ExtensionGenerator(); + + void Generate(io::Printer* printer); + void GenerateNonNestedInitializationCode(io::Printer* printer); + void GenerateRegistrationCode(io::Printer* printer); + + private: + const FieldDescriptor* descriptor_; + string scope_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h new file mode 100644 index 00000000..6097f357 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h @@ -0,0 +1,108 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace java { + +class FieldGenerator { + public: + FieldGenerator() {} + virtual ~FieldGenerator(); + + virtual int GetNumBitsForMessage() const = 0; + virtual int GetNumBitsForBuilder() const = 0; + virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; + virtual void GenerateMembers(io::Printer* printer) const = 0; + virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; + virtual void GenerateInitializationCode(io::Printer* printer) const = 0; + virtual void GenerateBuilderClearCode(io::Printer* printer) const = 0; + virtual void GenerateMergingCode(io::Printer* printer) const = 0; + virtual void GenerateBuildingCode(io::Printer* printer) const = 0; + virtual void GenerateParsingCode(io::Printer* printer) const = 0; + virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const; + virtual void GenerateSerializationCode(io::Printer* printer) const = 0; + virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0; + virtual void GenerateFieldBuilderInitializationCode(io::Printer* printer) + const = 0; + + virtual void GenerateEqualsCode(io::Printer* printer) const = 0; + virtual void GenerateHashCode(io::Printer* printer) const = 0; + + virtual string GetBoxedType() const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); +}; + +// Convenience class which constructs FieldGenerators for a Descriptor. +class FieldGeneratorMap { + public: + explicit FieldGeneratorMap(const Descriptor* descriptor); + ~FieldGeneratorMap(); + + const FieldGenerator& get(const FieldDescriptor* field) const; + const FieldGenerator& get_extension(int index) const; + + private: + const Descriptor* descriptor_; + scoped_array > field_generators_; + scoped_array > extension_generators_; + + static FieldGenerator* MakeGenerator(const FieldDescriptor* field, + int messageBitIndex, int builderBitIndex); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h new file mode 100644 index 00000000..59911462 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h @@ -0,0 +1,101 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + class FileDescriptor; // descriptor.h + namespace io { + class Printer; // printer.h + } + namespace compiler { + class GeneratorContext; // code_generator.h + } +} + +namespace protobuf { +namespace compiler { +namespace java { + +class FileGenerator { + public: + explicit FileGenerator(const FileDescriptor* file); + ~FileGenerator(); + + // Checks for problems that would otherwise lead to cryptic compile errors. + // Returns true if there are no problems, or writes an error description to + // the given string and returns false otherwise. + bool Validate(string* error); + + void Generate(io::Printer* printer); + + // If we aren't putting everything into one file, this will write all the + // files other than the outer file (i.e. one for each message, enum, and + // service type). + void GenerateSiblings(const string& package_dir, + GeneratorContext* generator_context, + vector* file_list); + + const string& java_package() { return java_package_; } + const string& classname() { return classname_; } + + + private: + // Returns whether the dependency should be included in the output file. + // Always returns true for opensource, but used internally at Google to help + // improve compatibility with version 1 of protocol buffers. + bool ShouldIncludeDependency(const FileDescriptor* descriptor); + + const FileDescriptor* file_; + string java_package_; + string classname_; + + + void GenerateEmbeddedDescriptor(io::Printer* printer); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h new file mode 100644 index 00000000..888b8d85 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h @@ -0,0 +1,72 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Generates Java code for a given .proto file. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ + +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +// CodeGenerator implementation which generates Java code. If you create your +// own protocol compiler binary and you want it to support Java output, you +// can do so by registering an instance of this CodeGenerator with the +// CommandLineInterface in your main() function. +class LIBPROTOC_EXPORT JavaGenerator : public CodeGenerator { + public: + JavaGenerator(); + ~JavaGenerator(); + + // implements CodeGenerator ---------------------------------------- + bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* context, + string* error) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h new file mode 100644 index 00000000..4ae07f15 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h @@ -0,0 +1,213 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +// Commonly-used separator comments. Thick is a line of '=', thin is a line +// of '-'. +extern const char kThickSeparator[]; +extern const char kThinSeparator[]; + +// Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes +// "fooBarBaz" or "FooBarBaz", respectively. +string UnderscoresToCamelCase(const FieldDescriptor* field); +string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field); + +// Similar, but for method names. (Typically, this merely has the effect +// of lower-casing the first letter of the name.) +string UnderscoresToCamelCase(const MethodDescriptor* method); + +// Strips ".proto" or ".protodevel" from the end of a filename. +string StripProto(const string& filename); + +// Gets the unqualified class name for the file. Each .proto file becomes a +// single Java class, with all its contents nested in that class. +string FileClassName(const FileDescriptor* file); + +// Returns the file's Java package name. +string FileJavaPackage(const FileDescriptor* file); + +// Returns output directory for the given package name. +string JavaPackageToDir(string package_name); + +// Converts the given fully-qualified name in the proto namespace to its +// fully-qualified name in the Java namespace, given that it is in the given +// file. +string ToJavaName(const string& full_name, const FileDescriptor* file); + +// These return the fully-qualified class name corresponding to the given +// descriptor. +inline string ClassName(const Descriptor* descriptor) { + return ToJavaName(descriptor->full_name(), descriptor->file()); +} +inline string ClassName(const EnumDescriptor* descriptor) { + return ToJavaName(descriptor->full_name(), descriptor->file()); +} +inline string ClassName(const ServiceDescriptor* descriptor) { + return ToJavaName(descriptor->full_name(), descriptor->file()); +} +inline string ExtensionIdentifierName(const FieldDescriptor* descriptor) { + return ToJavaName(descriptor->full_name(), descriptor->file()); +} +string ClassName(const FileDescriptor* descriptor); + +// Get the unqualified name that should be used for a field's field +// number constant. +string FieldConstantName(const FieldDescriptor *field); + +// Returns the type of the FieldDescriptor. +// This does nothing interesting for the open source release, but is used for +// hacks that improve compatability with version 1 protocol buffers at Google. +FieldDescriptor::Type GetType(const FieldDescriptor* field); + +enum JavaType { + JAVATYPE_INT, + JAVATYPE_LONG, + JAVATYPE_FLOAT, + JAVATYPE_DOUBLE, + JAVATYPE_BOOLEAN, + JAVATYPE_STRING, + JAVATYPE_BYTES, + JAVATYPE_ENUM, + JAVATYPE_MESSAGE +}; + +JavaType GetJavaType(const FieldDescriptor* field); + +// Get the fully-qualified class name for a boxed primitive type, e.g. +// "java.lang.Integer" for JAVATYPE_INT. Returns NULL for enum and message +// types. +const char* BoxedPrimitiveTypeName(JavaType type); + +string DefaultValue(const FieldDescriptor* field); +bool IsDefaultValueJavaDefault(const FieldDescriptor* field); + +// Does this message class keep track of unknown fields? +inline bool HasUnknownFields(const Descriptor* descriptor) { + return descriptor->file()->options().optimize_for() != + FileOptions::LITE_RUNTIME; +} + +// Does this message class have generated parsing, serialization, and other +// standard methods for which reflection-based fallback implementations exist? +inline bool HasGeneratedMethods(const Descriptor* descriptor) { + return descriptor->file()->options().optimize_for() != + FileOptions::CODE_SIZE; +} + +// Does this message have specialized equals() and hashCode() methods? +inline bool HasEqualsAndHashCode(const Descriptor* descriptor) { + return descriptor->file()->options().java_generate_equals_and_hash(); +} + +// Does this message class have descriptor and reflection methods? +inline bool HasDescriptorMethods(const Descriptor* descriptor) { + return descriptor->file()->options().optimize_for() != + FileOptions::LITE_RUNTIME; +} +inline bool HasDescriptorMethods(const EnumDescriptor* descriptor) { + return descriptor->file()->options().optimize_for() != + FileOptions::LITE_RUNTIME; +} +inline bool HasDescriptorMethods(const FileDescriptor* descriptor) { + return descriptor->options().optimize_for() != + FileOptions::LITE_RUNTIME; +} + +inline bool HasNestedBuilders(const Descriptor* descriptor) { + // The proto-lite version doesn't support nested builders. + return descriptor->file()->options().optimize_for() != + FileOptions::LITE_RUNTIME; +} + +// Should we generate generic services for this file? +inline bool HasGenericServices(const FileDescriptor *file) { + return file->service_count() > 0 && + file->options().optimize_for() != FileOptions::LITE_RUNTIME && + file->options().java_generic_services(); +} + + +// Methods for shared bitfields. + +// Gets the name of the shared bitfield for the given index. +string GetBitFieldName(int index); + +// Gets the name of the shared bitfield for the given bit index. +// Effectively, GetBitFieldName(bitIndex / 32) +string GetBitFieldNameForBit(int bitIndex); + +// Generates the java code for the expression that returns the boolean value +// of the bit of the shared bitfields for the given bit index. +// Example: "((bitField1_ & 0x04) == 0x04)" +string GenerateGetBit(int bitIndex); + +// Generates the java code for the expression that sets the bit of the shared +// bitfields for the given bit index. +// Example: "bitField1_ = (bitField1_ | 0x04)" +string GenerateSetBit(int bitIndex); + +// Generates the java code for the expression that clears the bit of the shared +// bitfields for the given bit index. +// Example: "bitField1_ = (bitField1_ & ~0x04)" +string GenerateClearBit(int bitIndex); + +// Does the same as GenerateGetBit but operates on the bit field on a local +// variable. This is used by the builder to copy the value in the builder to +// the message. +// Example: "((from_bitField1_ & 0x04) == 0x04)" +string GenerateGetBitFromLocal(int bitIndex); + +// Does the same as GenerateSetBit but operates on the bit field on a local +// variable. This is used by the builder to copy the value in the builder to +// the message. +// Example: "to_bitField1_ = (to_bitField1_ | 0x04)" +string GenerateSetBitToLocal(int bitIndex); + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h new file mode 100644 index 00000000..4c6fbbe5 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h @@ -0,0 +1,109 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace java { + +class MessageGenerator { + public: + explicit MessageGenerator(const Descriptor* descriptor); + ~MessageGenerator(); + + // All static variables have to be declared at the top-level of the file + // so that we can control initialization order, which is important for + // DescriptorProto bootstrapping to work. + void GenerateStaticVariables(io::Printer* printer); + + // Output code which initializes the static variables generated by + // GenerateStaticVariables(). + void GenerateStaticVariableInitializers(io::Printer* printer); + + // Generate the class itself. + void Generate(io::Printer* printer); + + // Generates the base interface that both the class and its builder implement + void GenerateInterface(io::Printer* printer); + + // Generate code to register all contained extensions with an + // ExtensionRegistry. + void GenerateExtensionRegistrationCode(io::Printer* printer); + + private: + enum UseMemoization { + MEMOIZE, + DONT_MEMOIZE + }; + + void GenerateMessageSerializationMethods(io::Printer* printer); + void GenerateParseFromMethods(io::Printer* printer); + void GenerateSerializeOneField(io::Printer* printer, + const FieldDescriptor* field); + void GenerateSerializeOneExtensionRange( + io::Printer* printer, const Descriptor::ExtensionRange* range); + + void GenerateBuilder(io::Printer* printer); + void GenerateCommonBuilderMethods(io::Printer* printer); + void GenerateDescriptorMethods(io::Printer* printer); + void GenerateBuilderParsingMethods(io::Printer* printer); + void GenerateIsInitialized(io::Printer* printer, + UseMemoization useMemoization); + void GenerateEqualsAndHashCode(io::Printer* printer); + + const Descriptor* descriptor_; + FieldGeneratorMap field_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h new file mode 100644 index 00000000..2efbcd97 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h @@ -0,0 +1,134 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +class MessageFieldGenerator : public FieldGenerator { + public: + explicit MessageFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~MessageFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); + + void PrintNestedBuilderCondition(io::Printer* printer, + const char* regular_case, const char* nested_builder_case) const; + void PrintNestedBuilderFunction(io::Printer* printer, + const char* method_prototype, const char* regular_case, + const char* nested_builder_case, + const char* trailing_code) const; +}; + +class RepeatedMessageFieldGenerator : public FieldGenerator { + public: + explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~RepeatedMessageFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); + + void PrintNestedBuilderCondition(io::Printer* printer, + const char* regular_case, const char* nested_builder_case) const; + void PrintNestedBuilderFunction(io::Printer* printer, + const char* method_prototype, const char* regular_case, + const char* nested_builder_case, + const char* trailing_code) const; +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h new file mode 100644 index 00000000..7900fac5 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h @@ -0,0 +1,121 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +class PrimitiveFieldGenerator : public FieldGenerator { + public: + explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~PrimitiveFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); +}; + +class RepeatedPrimitiveFieldGenerator : public FieldGenerator { + public: + explicit RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~RepeatedPrimitiveFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateParsingCodeFromPacked(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h new file mode 100644 index 00000000..e07eebf7 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h @@ -0,0 +1,113 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ + +#include +#include + +namespace google { +namespace protobuf { + namespace io { + class Printer; // printer.h + } +} + +namespace protobuf { +namespace compiler { +namespace java { + +class ServiceGenerator { + public: + explicit ServiceGenerator(const ServiceDescriptor* descriptor); + ~ServiceGenerator(); + + void Generate(io::Printer* printer); + + private: + + // Generate the getDescriptorForType() method. + void GenerateGetDescriptorForType(io::Printer* printer); + + // Generate a Java interface for the service. + void GenerateInterface(io::Printer* printer); + + // Generate newReflectiveService() method. + void GenerateNewReflectiveServiceMethod(io::Printer* printer); + + // Generate newReflectiveBlockingService() method. + void GenerateNewReflectiveBlockingServiceMethod(io::Printer* printer); + + // Generate abstract method declarations for all methods. + void GenerateAbstractMethods(io::Printer* printer); + + // Generate the implementation of Service.callMethod(). + void GenerateCallMethod(io::Printer* printer); + + // Generate the implementation of BlockingService.callBlockingMethod(). + void GenerateCallBlockingMethod(io::Printer* printer); + + // Generate the implementations of Service.get{Request,Response}Prototype(). + enum RequestOrResponse { REQUEST, RESPONSE }; + void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); + + // Generate a stub implementation of the service. + void GenerateStub(io::Printer* printer); + + // Generate a method signature, possibly abstract, without body or trailing + // semicolon. + enum IsAbstract { IS_ABSTRACT, IS_CONCRETE }; + void GenerateMethodSignature(io::Printer* printer, + const MethodDescriptor* method, + IsAbstract is_abstract); + + // Generate a blocking stub interface and implementation of the service. + void GenerateBlockingStub(io::Printer* printer); + + // Generate the method signature for one method of a blocking stub. + void GenerateBlockingMethodSignature(io::Printer* printer, + const MethodDescriptor* method); + + const ServiceDescriptor* descriptor_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +#endif // NET_PROTO2_COMPILER_JAVA_SERVICE_H__ +} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h new file mode 100644 index 00000000..8cb41469 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h @@ -0,0 +1,120 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Author: jonp@google.com (Jon Perlow) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace java { + +class StringFieldGenerator : public FieldGenerator { + public: + explicit StringFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~StringFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator); +}; + +class RepeatedStringFieldGenerator : public FieldGenerator { + public: + explicit RepeatedStringFieldGenerator(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex); + ~RepeatedStringFieldGenerator(); + + // implements FieldGenerator --------------------------------------- + int GetNumBitsForMessage() const; + int GetNumBitsForBuilder() const; + void GenerateInterfaceMembers(io::Printer* printer) const; + void GenerateMembers(io::Printer* printer) const; + void GenerateBuilderMembers(io::Printer* printer) const; + void GenerateInitializationCode(io::Printer* printer) const; + void GenerateBuilderClearCode(io::Printer* printer) const; + void GenerateMergingCode(io::Printer* printer) const; + void GenerateBuildingCode(io::Printer* printer) const; + void GenerateParsingCode(io::Printer* printer) const; + void GenerateParsingCodeFromPacked(io::Printer* printer) const; + void GenerateSerializationCode(io::Printer* printer) const; + void GenerateSerializedSizeCode(io::Printer* printer) const; + void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; + void GenerateEqualsCode(io::Printer* printer) const; + void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; + + private: + const FieldDescriptor* descriptor_; + map variables_; + const int messageBitIndex_; + const int builderBitIndex_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator); +}; + +} // namespace java +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h new file mode 100644 index 00000000..5c7942bd --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h @@ -0,0 +1,113 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) + +#ifndef GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ + +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { + +// A mock CodeGenerator, used by command_line_interface_unittest. This is in +// its own file so that it can be used both directly and as a plugin. +// +// Generate() produces some output which can be checked by ExpectCalled(). The +// generator can run in a different process (e.g. a plugin). +// +// If the parameter is "insert=NAMES", the MockCodeGenerator will insert lines +// into the files generated by other MockCodeGenerators instead of creating +// its own file. NAMES is a comma-separated list of the names of those other +// MockCodeGenerators. +// +// MockCodeGenerator will also modify its behavior slightly if the input file +// contains a message type with one of the following names: +// MockCodeGenerator_Error: Causes Generate() to return false and set the +// error message to "Saw message type MockCodeGenerator_Error." +// MockCodeGenerator_Exit: Generate() prints "Saw message type +// MockCodeGenerator_Exit." to stderr and then calls exit(123). +// MockCodeGenerator_Abort: Generate() prints "Saw message type +// MockCodeGenerator_Abort." to stderr and then calls abort(). +class MockCodeGenerator : public CodeGenerator { + public: + MockCodeGenerator(const string& name); + virtual ~MockCodeGenerator(); + + // Expect (via gTest) that a MockCodeGenerator with the given name was called + // with the given parameters by inspecting the output location. + // + // |insertions| is a comma-separated list of names of MockCodeGenerators which + // should have inserted lines into this file. + // |parsed_file_list| is a comma-separated list of names of the files + // that are being compiled together in this run. + static void ExpectGenerated(const string& name, + const string& parameter, + const string& insertions, + const string& file, + const string& first_message_name, + const string& parsed_file_list, + const string& output_directory); + + // Get the name of the file which would be written by the given generator. + static string GetOutputFileName(const string& generator_name, + const FileDescriptor* file); + static string GetOutputFileName(const string& generator_name, + const string& file); + + // implements CodeGenerator ---------------------------------------- + + virtual bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* context, + string* error) const; + + private: + string name_; + + static string GetOutputFileContent(const string& generator_name, + const string& parameter, + const FileDescriptor* file, + GeneratorContext *context); + static string GetOutputFileContent(const string& generator_name, + const string& parameter, + const string& file, + const string& parsed_file_list, + const string& first_message_name); +}; + +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h new file mode 100644 index 00000000..b8971267 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h @@ -0,0 +1,64 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file exists solely to document the google::protobuf::compiler namespace. +// It is not compiled into anything, but it may be read by an automated +// documentation generator. + +namespace google { + +namespace protobuf { + +// Implementation of the Protocol Buffer compiler. +// +// This package contains code for parsing .proto files and generating code +// based on them. There are two reasons you might be interested in this +// package: +// - You want to parse .proto files at runtime. In this case, you should +// look at importer.h. Since this functionality is widely useful, it is +// included in the libprotobuf base library; you do not have to link against +// libprotoc. +// - You want to write a custom protocol compiler which generates different +// kinds of code, e.g. code in a different language which is not supported +// by the official compiler. For this purpose, command_line_interface.h +// provides you with a complete compiler front-end, so all you need to do +// is write a custom implementation of CodeGenerator and a trivial main() +// function. You can even make your compiler support the official languages +// in addition to your own. Since this functionality is only useful to those +// writing custom compilers, it is in a separate library called "libprotoc" +// which you will have to link against. +namespace compiler {} + +} // namespace protobuf +} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h new file mode 100644 index 00000000..4cc90a29 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h @@ -0,0 +1,434 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Implements parsing of .proto files to FileDescriptorProtos. + +#ifndef GOOGLE_PROTOBUF_COMPILER_PARSER_H__ +#define GOOGLE_PROTOBUF_COMPILER_PARSER_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { class Message; } + +namespace protobuf { +namespace compiler { + +// Defined in this file. +class Parser; +class SourceLocationTable; + +// Implements parsing of protocol definitions (such as .proto files). +// +// Note that most users will be more interested in the Importer class. +// Parser is a lower-level class which simply converts a single .proto file +// to a FileDescriptorProto. It does not resolve import directives or perform +// many other kinds of validation needed to construct a complete +// FileDescriptor. +class LIBPROTOBUF_EXPORT Parser { + public: + Parser(); + ~Parser(); + + // Parse the entire input and construct a FileDescriptorProto representing + // it. Returns true if no errors occurred, false otherwise. + bool Parse(io::Tokenizer* input, FileDescriptorProto* file); + + // Optional fetaures: + + // DEPRECATED: New code should use the SourceCodeInfo embedded in the + // FileDescriptorProto. + // + // Requests that locations of certain definitions be recorded to the given + // SourceLocationTable while parsing. This can be used to look up exact line + // and column numbers for errors reported by DescriptorPool during validation. + // Set to NULL (the default) to discard source location information. + void RecordSourceLocationsTo(SourceLocationTable* location_table) { + source_location_table_ = location_table; + } + + // Requests that errors be recorded to the given ErrorCollector while + // parsing. Set to NULL (the default) to discard error messages. + void RecordErrorsTo(io::ErrorCollector* error_collector) { + error_collector_ = error_collector; + } + + // Returns the identifier used in the "syntax = " declaration, if one was + // seen during the last call to Parse(), or the empty string otherwise. + const string& GetSyntaxIdentifier() { return syntax_identifier_; } + + // If set true, input files will be required to begin with a syntax + // identifier. Otherwise, files may omit this. If a syntax identifier + // is provided, it must be 'syntax = "proto2";' and must appear at the + // top of this file regardless of whether or not it was required. + void SetRequireSyntaxIdentifier(bool value) { + require_syntax_identifier_ = value; + } + + // Call SetStopAfterSyntaxIdentifier(true) to tell the parser to stop + // parsing as soon as it has seen the syntax identifier, or lack thereof. + // This is useful for quickly identifying the syntax of the file without + // parsing the whole thing. If this is enabled, no error will be recorded + // if the syntax identifier is something other than "proto2" (since + // presumably the caller intends to deal with that), but other kinds of + // errors (e.g. parse errors) will still be reported. When this is enabled, + // you may pass a NULL FileDescriptorProto to Parse(). + void SetStopAfterSyntaxIdentifier(bool value) { + stop_after_syntax_identifier_ = value; + } + + private: + // ================================================================= + // Error recovery helpers + + // Consume the rest of the current statement. This consumes tokens + // until it sees one of: + // ';' Consumes the token and returns. + // '{' Consumes the brace then calls SkipRestOfBlock(). + // '}' Returns without consuming. + // EOF Returns (can't consume). + // The Parser often calls SkipStatement() after encountering a syntax + // error. This allows it to go on parsing the following lines, allowing + // it to report more than just one error in the file. + void SkipStatement(); + + // Consume the rest of the current block, including nested blocks, + // ending after the closing '}' is encountered and consumed, or at EOF. + void SkipRestOfBlock(); + + // ----------------------------------------------------------------- + // Single-token consuming helpers + // + // These make parsing code more readable. + + // True if the current token is TYPE_END. + inline bool AtEnd(); + + // True if the next token matches the given text. + inline bool LookingAt(const char* text); + // True if the next token is of the given type. + inline bool LookingAtType(io::Tokenizer::TokenType token_type); + + // If the next token exactly matches the text given, consume it and return + // true. Otherwise, return false without logging an error. + bool TryConsume(const char* text); + + // These attempt to read some kind of token from the input. If successful, + // they return true. Otherwise they return false and add the given error + // to the error list. + + // Consume a token with the exact text given. + bool Consume(const char* text, const char* error); + // Same as above, but automatically generates the error "Expected \"text\".", + // where "text" is the expected token text. + bool Consume(const char* text); + // Consume a token of type IDENTIFIER and store its text in "output". + bool ConsumeIdentifier(string* output, const char* error); + // Consume an integer and store its value in "output". + bool ConsumeInteger(int* output, const char* error); + // Consume a 64-bit integer and store its value in "output". If the value + // is greater than max_value, an error will be reported. + bool ConsumeInteger64(uint64 max_value, uint64* output, const char* error); + // Consume a number and store its value in "output". This will accept + // tokens of either INTEGER or FLOAT type. + bool ConsumeNumber(double* output, const char* error); + // Consume a string literal and store its (unescaped) value in "output". + bool ConsumeString(string* output, const char* error); + + // ----------------------------------------------------------------- + // Error logging helpers + + // Invokes error_collector_->AddError(), if error_collector_ is not NULL. + void AddError(int line, int column, const string& error); + + // Invokes error_collector_->AddError() with the line and column number + // of the current token. + void AddError(const string& error); + + // Records a location in the SourceCodeInfo.location table (see + // descriptor.proto). We use RAII to ensure that the start and end locations + // are recorded -- the constructor records the start location and the + // destructor records the end location. Since the parser is + // recursive-descent, this works out beautifully. + class LIBPROTOBUF_EXPORT LocationRecorder { + public: + // Construct the file's "root" location. + LocationRecorder(Parser* parser); + + // Construct a location that represents a declaration nested within the + // given parent. E.g. a field's location is nested within the location + // for a message type. The parent's path will be copied, so you should + // call AddPath() only to add the path components leading from the parent + // to the child (as opposed to leading from the root to the child). + LocationRecorder(const LocationRecorder& parent); + + // Convenience constructors that call AddPath() one or two times. + LocationRecorder(const LocationRecorder& parent, int path1); + LocationRecorder(const LocationRecorder& parent, int path1, int path2); + + ~LocationRecorder(); + + // Add a path component. See SourceCodeInfo.Location.path in + // descriptor.proto. + void AddPath(int path_component); + + // By default the location is considered to start at the current token at + // the time the LocationRecorder is created. StartAt() sets the start + // location to the given token instead. + void StartAt(const io::Tokenizer::Token& token); + + // By default the location is considered to end at the previous token at + // the time the LocationRecorder is destroyed. EndAt() sets the end + // location to the given token instead. + void EndAt(const io::Tokenizer::Token& token); + + // Records the start point of this location to the SourceLocationTable that + // was passed to RecordSourceLocationsTo(), if any. SourceLocationTable + // is an older way of keeping track of source locations which is still + // used in some places. + void RecordLegacyLocation(const Message* descriptor, + DescriptorPool::ErrorCollector::ErrorLocation location); + + private: + Parser* parser_; + SourceCodeInfo::Location* location_; + + void Init(const LocationRecorder& parent); + }; + + // ================================================================= + // Parsers for various language constructs + + // Parses the "syntax = \"proto2\";" line at the top of the file. Returns + // false if it failed to parse or if the syntax identifier was not + // recognized. + bool ParseSyntaxIdentifier(); + + // These methods parse various individual bits of code. They return + // false if they completely fail to parse the construct. In this case, + // it is probably necessary to skip the rest of the statement to recover. + // However, if these methods return true, it does NOT mean that there + // were no errors; only that there were no *syntax* errors. For instance, + // if a service method is defined using proper syntax but uses a primitive + // type as its input or output, ParseMethodField() still returns true + // and only reports the error by calling AddError(). In practice, this + // makes logic much simpler for the caller. + + // Parse a top-level message, enum, service, etc. + bool ParseTopLevelStatement(FileDescriptorProto* file, + const LocationRecorder& root_location); + + // Parse various language high-level language construrcts. + bool ParseMessageDefinition(DescriptorProto* message, + const LocationRecorder& message_location); + bool ParseEnumDefinition(EnumDescriptorProto* enum_type, + const LocationRecorder& enum_location); + bool ParseServiceDefinition(ServiceDescriptorProto* service, + const LocationRecorder& service_location); + bool ParsePackage(FileDescriptorProto* file, + const LocationRecorder& root_location); + bool ParseImport(string* import_filename, + const LocationRecorder& root_location, + int index); + bool ParseOption(Message* options, + const LocationRecorder& options_location); + + // These methods parse the contents of a message, enum, or service type and + // add them to the given object. They consume the entire block including + // the beginning and ending brace. + bool ParseMessageBlock(DescriptorProto* message, + const LocationRecorder& message_location); + bool ParseEnumBlock(EnumDescriptorProto* enum_type, + const LocationRecorder& enum_location); + bool ParseServiceBlock(ServiceDescriptorProto* service, + const LocationRecorder& service_location); + + // Parse one statement within a message, enum, or service block, inclunding + // final semicolon. + bool ParseMessageStatement(DescriptorProto* message, + const LocationRecorder& message_location); + bool ParseEnumStatement(EnumDescriptorProto* message, + const LocationRecorder& enum_location); + bool ParseServiceStatement(ServiceDescriptorProto* message, + const LocationRecorder& service_location); + + // Parse a field of a message. If the field is a group, its type will be + // added to "messages". + // + // parent_location and location_field_number_for_nested_type are needed when + // parsing groups -- we need to generate a nested message type within the + // parent and record its location accordingly. Since the parent could be + // either a FileDescriptorProto or a DescriptorProto, we must pass in the + // correct field number to use. + bool ParseMessageField(FieldDescriptorProto* field, + RepeatedPtrField* messages, + const LocationRecorder& parent_location, + int location_field_number_for_nested_type, + const LocationRecorder& field_location); + + // Parse an "extensions" declaration. + bool ParseExtensions(DescriptorProto* message, + const LocationRecorder& extensions_location); + + // Parse an "extend" declaration. (See also comments for + // ParseMessageField().) + bool ParseExtend(RepeatedPtrField* extensions, + RepeatedPtrField* messages, + const LocationRecorder& parent_location, + int location_field_number_for_nested_type, + const LocationRecorder& extend_location); + + // Parse a single enum value within an enum block. + bool ParseEnumConstant(EnumValueDescriptorProto* enum_value, + const LocationRecorder& enum_value_location); + + // Parse enum constant options, i.e. the list in square brackets at the end + // of the enum constant value definition. + bool ParseEnumConstantOptions(EnumValueDescriptorProto* value, + const LocationRecorder& enum_value_location); + + // Parse a single method within a service definition. + bool ParseServiceMethod(MethodDescriptorProto* method, + const LocationRecorder& method_location); + + // Parse "required", "optional", or "repeated" and fill in "label" + // with the value. + bool ParseLabel(FieldDescriptorProto::Label* label); + + // Parse a type name and fill in "type" (if it is a primitive) or + // "type_name" (if it is not) with the type parsed. + bool ParseType(FieldDescriptorProto::Type* type, + string* type_name); + // Parse a user-defined type and fill in "type_name" with the name. + // If a primitive type is named, it is treated as an error. + bool ParseUserDefinedType(string* type_name); + + // Parses field options, i.e. the stuff in square brackets at the end + // of a field definition. Also parses default value. + bool ParseFieldOptions(FieldDescriptorProto* field, + const LocationRecorder& field_location); + + // Parse the "default" option. This needs special handling because its + // type is the field's type. + bool ParseDefaultAssignment(FieldDescriptorProto* field, + const LocationRecorder& field_location); + + // Parse a single option name/value pair, e.g. "ctype = CORD". The name + // identifies a field of the given Message, and the value of that field + // is set to the parsed value. + bool ParseOptionAssignment(Message* options, + const LocationRecorder& options_location); + + // Parses a single part of a multipart option name. A multipart name consists + // of names separated by dots. Each name is either an identifier or a series + // of identifiers separated by dots and enclosed in parentheses. E.g., + // "foo.(bar.baz).qux". + bool ParseOptionNamePart(UninterpretedOption* uninterpreted_option, + const LocationRecorder& part_location); + + // Parses a string surrounded by balanced braces. Strips off the outer + // braces and stores the enclosed string in *value. + // E.g., + // { foo } *value gets 'foo' + // { foo { bar: box } } *value gets 'foo { bar: box }' + // {} *value gets '' + // + // REQUIRES: LookingAt("{") + // When finished successfully, we are looking at the first token past + // the ending brace. + bool ParseUninterpretedBlock(string* value); + + // ================================================================= + + io::Tokenizer* input_; + io::ErrorCollector* error_collector_; + SourceCodeInfo* source_code_info_; + SourceLocationTable* source_location_table_; // legacy + bool had_errors_; + bool require_syntax_identifier_; + bool stop_after_syntax_identifier_; + string syntax_identifier_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser); +}; + +// A table mapping (descriptor, ErrorLocation) pairs -- as reported by +// DescriptorPool when validating descriptors -- to line and column numbers +// within the original source code. +// +// This is semi-obsolete: FileDescriptorProto.source_code_info now contains +// far more complete information about source locations. However, as of this +// writing you still need to use SourceLocationTable when integrating with +// DescriptorPool. +class LIBPROTOBUF_EXPORT SourceLocationTable { + public: + SourceLocationTable(); + ~SourceLocationTable(); + + // Finds the precise location of the given error and fills in *line and + // *column with the line and column numbers. If not found, sets *line to + // -1 and *column to 0 (since line = -1 is used to mean "error has no exact + // location" in the ErrorCollector interface). Returns true if found, false + // otherwise. + bool Find(const Message* descriptor, + DescriptorPool::ErrorCollector::ErrorLocation location, + int* line, int* column) const; + + // Adds a location to the table. + void Add(const Message* descriptor, + DescriptorPool::ErrorCollector::ErrorLocation location, + int line, int column); + + // Clears the contents of the table. + void Clear(); + + private: + typedef map< + pair, + pair > LocationMap; + LocationMap location_map_; +}; + +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_PARSER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h new file mode 100644 index 00000000..64dfb1d2 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h @@ -0,0 +1,73 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// +// Front-end for protoc code generator plugins written in C++. +// +// To implement a protoc plugin in C++, simply write an implementation of +// CodeGenerator, then create a main() function like: +// int main(int argc, char* argv[]) { +// MyCodeGenerator generator; +// return google::protobuf::compiler::PluginMain(argc, argv, &generator); +// } +// You must link your plugin against libprotobuf and libprotoc. +// +// To get protoc to use the plugin, do one of the following: +// * Place the plugin binary somewhere in the PATH and give it the name +// "protoc-gen-NAME" (replacing "NAME" with the name of your plugin). If you +// then invoke protoc with the parameter --NAME_out=OUT_DIR (again, replace +// "NAME" with your plugin's name), protoc will invoke your plugin to generate +// the output, which will be placed in OUT_DIR. +// * Place the plugin binary anywhere, with any name, and pass the --plugin +// parameter to protoc to direct it to your plugin like so: +// protoc --plugin=protoc-gen-NAME=path/to/mybinary --NAME_out=OUT_DIR +// On Windows, make sure to include the .exe suffix: +// protoc --plugin=protoc-gen-NAME=path/to/mybinary.exe --NAME_out=OUT_DIR + +#ifndef GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ +#define GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ + +#include + +namespace google { +namespace protobuf { +namespace compiler { + +class CodeGenerator; // code_generator.h + +// Implements main() for a protoc plugin exposing the given code generator. +int PluginMain(int argc, char* argv[], const CodeGenerator* generator); + +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h new file mode 100644 index 00000000..14216c2a --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h @@ -0,0 +1,790 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/compiler/plugin.proto + +#ifndef PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +#include "google/protobuf/descriptor.pb.h" +// @@protoc_insertion_point(includes) + +namespace google { +namespace protobuf { +namespace compiler { + +// Internal implementation detail -- do not call these. +void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + +class CodeGeneratorRequest; +class CodeGeneratorResponse; +class CodeGeneratorResponse_File; + +// =================================================================== + +class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message { + public: + CodeGeneratorRequest(); + virtual ~CodeGeneratorRequest(); + + CodeGeneratorRequest(const CodeGeneratorRequest& from); + + inline CodeGeneratorRequest& operator=(const CodeGeneratorRequest& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CodeGeneratorRequest& default_instance(); + + void Swap(CodeGeneratorRequest* other); + + // implements Message ---------------------------------------------- + + CodeGeneratorRequest* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CodeGeneratorRequest& from); + void MergeFrom(const CodeGeneratorRequest& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated string file_to_generate = 1; + inline int file_to_generate_size() const; + inline void clear_file_to_generate(); + static const int kFileToGenerateFieldNumber = 1; + inline const ::std::string& file_to_generate(int index) const; + inline ::std::string* mutable_file_to_generate(int index); + inline void set_file_to_generate(int index, const ::std::string& value); + inline void set_file_to_generate(int index, const char* value); + inline void set_file_to_generate(int index, const char* value, size_t size); + inline ::std::string* add_file_to_generate(); + inline void add_file_to_generate(const ::std::string& value); + inline void add_file_to_generate(const char* value); + inline void add_file_to_generate(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& file_to_generate() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_file_to_generate(); + + // optional string parameter = 2; + inline bool has_parameter() const; + inline void clear_parameter(); + static const int kParameterFieldNumber = 2; + inline const ::std::string& parameter() const; + inline void set_parameter(const ::std::string& value); + inline void set_parameter(const char* value); + inline void set_parameter(const char* value, size_t size); + inline ::std::string* mutable_parameter(); + inline ::std::string* release_parameter(); + + // repeated .google.protobuf.FileDescriptorProto proto_file = 15; + inline int proto_file_size() const; + inline void clear_proto_file(); + static const int kProtoFileFieldNumber = 15; + inline const ::google::protobuf::FileDescriptorProto& proto_file(int index) const; + inline ::google::protobuf::FileDescriptorProto* mutable_proto_file(int index); + inline ::google::protobuf::FileDescriptorProto* add_proto_file(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& + proto_file() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* + mutable_proto_file(); + + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorRequest) + private: + inline void set_has_parameter(); + inline void clear_has_parameter(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::std::string> file_to_generate_; + ::std::string* parameter_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > proto_file_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + + void InitAsDefaultInstance(); + static CodeGeneratorRequest* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Message { + public: + CodeGeneratorResponse_File(); + virtual ~CodeGeneratorResponse_File(); + + CodeGeneratorResponse_File(const CodeGeneratorResponse_File& from); + + inline CodeGeneratorResponse_File& operator=(const CodeGeneratorResponse_File& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CodeGeneratorResponse_File& default_instance(); + + void Swap(CodeGeneratorResponse_File* other); + + // implements Message ---------------------------------------------- + + CodeGeneratorResponse_File* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CodeGeneratorResponse_File& from); + void MergeFrom(const CodeGeneratorResponse_File& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // optional string insertion_point = 2; + inline bool has_insertion_point() const; + inline void clear_insertion_point(); + static const int kInsertionPointFieldNumber = 2; + inline const ::std::string& insertion_point() const; + inline void set_insertion_point(const ::std::string& value); + inline void set_insertion_point(const char* value); + inline void set_insertion_point(const char* value, size_t size); + inline ::std::string* mutable_insertion_point(); + inline ::std::string* release_insertion_point(); + + // optional string content = 15; + inline bool has_content() const; + inline void clear_content(); + static const int kContentFieldNumber = 15; + inline const ::std::string& content() const; + inline void set_content(const ::std::string& value); + inline void set_content(const char* value); + inline void set_content(const char* value, size_t size); + inline ::std::string* mutable_content(); + inline ::std::string* release_content(); + + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse.File) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_insertion_point(); + inline void clear_has_insertion_point(); + inline void set_has_content(); + inline void clear_has_content(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::std::string* insertion_point_; + ::std::string* content_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + + void InitAsDefaultInstance(); + static CodeGeneratorResponse_File* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Message { + public: + CodeGeneratorResponse(); + virtual ~CodeGeneratorResponse(); + + CodeGeneratorResponse(const CodeGeneratorResponse& from); + + inline CodeGeneratorResponse& operator=(const CodeGeneratorResponse& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CodeGeneratorResponse& default_instance(); + + void Swap(CodeGeneratorResponse* other); + + // implements Message ---------------------------------------------- + + CodeGeneratorResponse* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CodeGeneratorResponse& from); + void MergeFrom(const CodeGeneratorResponse& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef CodeGeneratorResponse_File File; + + // accessors ------------------------------------------------------- + + // optional string error = 1; + inline bool has_error() const; + inline void clear_error(); + static const int kErrorFieldNumber = 1; + inline const ::std::string& error() const; + inline void set_error(const ::std::string& value); + inline void set_error(const char* value); + inline void set_error(const char* value, size_t size); + inline ::std::string* mutable_error(); + inline ::std::string* release_error(); + + // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; + inline int file_size() const; + inline void clear_file(); + static const int kFileFieldNumber = 15; + inline const ::google::protobuf::compiler::CodeGeneratorResponse_File& file(int index) const; + inline ::google::protobuf::compiler::CodeGeneratorResponse_File* mutable_file(int index); + inline ::google::protobuf::compiler::CodeGeneratorResponse_File* add_file(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >& + file() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >* + mutable_file(); + + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse) + private: + inline void set_has_error(); + inline void clear_has_error(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* error_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File > file_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + + void InitAsDefaultInstance(); + static CodeGeneratorResponse* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// CodeGeneratorRequest + +// repeated string file_to_generate = 1; +inline int CodeGeneratorRequest::file_to_generate_size() const { + return file_to_generate_.size(); +} +inline void CodeGeneratorRequest::clear_file_to_generate() { + file_to_generate_.Clear(); +} +inline const ::std::string& CodeGeneratorRequest::file_to_generate(int index) const { + return file_to_generate_.Get(index); +} +inline ::std::string* CodeGeneratorRequest::mutable_file_to_generate(int index) { + return file_to_generate_.Mutable(index); +} +inline void CodeGeneratorRequest::set_file_to_generate(int index, const ::std::string& value) { + file_to_generate_.Mutable(index)->assign(value); +} +inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { + file_to_generate_.Mutable(index)->assign(value); +} +inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, size_t size) { + file_to_generate_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* CodeGeneratorRequest::add_file_to_generate() { + return file_to_generate_.Add(); +} +inline void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) { + file_to_generate_.Add()->assign(value); +} +inline void CodeGeneratorRequest::add_file_to_generate(const char* value) { + file_to_generate_.Add()->assign(value); +} +inline void CodeGeneratorRequest::add_file_to_generate(const char* value, size_t size) { + file_to_generate_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +CodeGeneratorRequest::file_to_generate() const { + return file_to_generate_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +CodeGeneratorRequest::mutable_file_to_generate() { + return &file_to_generate_; +} + +// optional string parameter = 2; +inline bool CodeGeneratorRequest::has_parameter() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void CodeGeneratorRequest::set_has_parameter() { + _has_bits_[0] |= 0x00000002u; +} +inline void CodeGeneratorRequest::clear_has_parameter() { + _has_bits_[0] &= ~0x00000002u; +} +inline void CodeGeneratorRequest::clear_parameter() { + if (parameter_ != &::google::protobuf::internal::kEmptyString) { + parameter_->clear(); + } + clear_has_parameter(); +} +inline const ::std::string& CodeGeneratorRequest::parameter() const { + return *parameter_; +} +inline void CodeGeneratorRequest::set_parameter(const ::std::string& value) { + set_has_parameter(); + if (parameter_ == &::google::protobuf::internal::kEmptyString) { + parameter_ = new ::std::string; + } + parameter_->assign(value); +} +inline void CodeGeneratorRequest::set_parameter(const char* value) { + set_has_parameter(); + if (parameter_ == &::google::protobuf::internal::kEmptyString) { + parameter_ = new ::std::string; + } + parameter_->assign(value); +} +inline void CodeGeneratorRequest::set_parameter(const char* value, size_t size) { + set_has_parameter(); + if (parameter_ == &::google::protobuf::internal::kEmptyString) { + parameter_ = new ::std::string; + } + parameter_->assign(reinterpret_cast(value), size); +} +inline ::std::string* CodeGeneratorRequest::mutable_parameter() { + set_has_parameter(); + if (parameter_ == &::google::protobuf::internal::kEmptyString) { + parameter_ = new ::std::string; + } + return parameter_; +} +inline ::std::string* CodeGeneratorRequest::release_parameter() { + clear_has_parameter(); + if (parameter_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = parameter_; + parameter_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated .google.protobuf.FileDescriptorProto proto_file = 15; +inline int CodeGeneratorRequest::proto_file_size() const { + return proto_file_.size(); +} +inline void CodeGeneratorRequest::clear_proto_file() { + proto_file_.Clear(); +} +inline const ::google::protobuf::FileDescriptorProto& CodeGeneratorRequest::proto_file(int index) const { + return proto_file_.Get(index); +} +inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::mutable_proto_file(int index) { + return proto_file_.Mutable(index); +} +inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::add_proto_file() { + return proto_file_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& +CodeGeneratorRequest::proto_file() const { + return proto_file_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* +CodeGeneratorRequest::mutable_proto_file() { + return &proto_file_; +} + +// ------------------------------------------------------------------- + +// CodeGeneratorResponse_File + +// optional string name = 1; +inline bool CodeGeneratorResponse_File::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void CodeGeneratorResponse_File::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void CodeGeneratorResponse_File::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void CodeGeneratorResponse_File::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& CodeGeneratorResponse_File::name() const { + return *name_; +} +inline void CodeGeneratorResponse_File::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void CodeGeneratorResponse_File::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void CodeGeneratorResponse_File::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* CodeGeneratorResponse_File::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* CodeGeneratorResponse_File::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string insertion_point = 2; +inline bool CodeGeneratorResponse_File::has_insertion_point() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void CodeGeneratorResponse_File::set_has_insertion_point() { + _has_bits_[0] |= 0x00000002u; +} +inline void CodeGeneratorResponse_File::clear_has_insertion_point() { + _has_bits_[0] &= ~0x00000002u; +} +inline void CodeGeneratorResponse_File::clear_insertion_point() { + if (insertion_point_ != &::google::protobuf::internal::kEmptyString) { + insertion_point_->clear(); + } + clear_has_insertion_point(); +} +inline const ::std::string& CodeGeneratorResponse_File::insertion_point() const { + return *insertion_point_; +} +inline void CodeGeneratorResponse_File::set_insertion_point(const ::std::string& value) { + set_has_insertion_point(); + if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { + insertion_point_ = new ::std::string; + } + insertion_point_->assign(value); +} +inline void CodeGeneratorResponse_File::set_insertion_point(const char* value) { + set_has_insertion_point(); + if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { + insertion_point_ = new ::std::string; + } + insertion_point_->assign(value); +} +inline void CodeGeneratorResponse_File::set_insertion_point(const char* value, size_t size) { + set_has_insertion_point(); + if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { + insertion_point_ = new ::std::string; + } + insertion_point_->assign(reinterpret_cast(value), size); +} +inline ::std::string* CodeGeneratorResponse_File::mutable_insertion_point() { + set_has_insertion_point(); + if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { + insertion_point_ = new ::std::string; + } + return insertion_point_; +} +inline ::std::string* CodeGeneratorResponse_File::release_insertion_point() { + clear_has_insertion_point(); + if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = insertion_point_; + insertion_point_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string content = 15; +inline bool CodeGeneratorResponse_File::has_content() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void CodeGeneratorResponse_File::set_has_content() { + _has_bits_[0] |= 0x00000004u; +} +inline void CodeGeneratorResponse_File::clear_has_content() { + _has_bits_[0] &= ~0x00000004u; +} +inline void CodeGeneratorResponse_File::clear_content() { + if (content_ != &::google::protobuf::internal::kEmptyString) { + content_->clear(); + } + clear_has_content(); +} +inline const ::std::string& CodeGeneratorResponse_File::content() const { + return *content_; +} +inline void CodeGeneratorResponse_File::set_content(const ::std::string& value) { + set_has_content(); + if (content_ == &::google::protobuf::internal::kEmptyString) { + content_ = new ::std::string; + } + content_->assign(value); +} +inline void CodeGeneratorResponse_File::set_content(const char* value) { + set_has_content(); + if (content_ == &::google::protobuf::internal::kEmptyString) { + content_ = new ::std::string; + } + content_->assign(value); +} +inline void CodeGeneratorResponse_File::set_content(const char* value, size_t size) { + set_has_content(); + if (content_ == &::google::protobuf::internal::kEmptyString) { + content_ = new ::std::string; + } + content_->assign(reinterpret_cast(value), size); +} +inline ::std::string* CodeGeneratorResponse_File::mutable_content() { + set_has_content(); + if (content_ == &::google::protobuf::internal::kEmptyString) { + content_ = new ::std::string; + } + return content_; +} +inline ::std::string* CodeGeneratorResponse_File::release_content() { + clear_has_content(); + if (content_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = content_; + content_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// CodeGeneratorResponse + +// optional string error = 1; +inline bool CodeGeneratorResponse::has_error() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void CodeGeneratorResponse::set_has_error() { + _has_bits_[0] |= 0x00000001u; +} +inline void CodeGeneratorResponse::clear_has_error() { + _has_bits_[0] &= ~0x00000001u; +} +inline void CodeGeneratorResponse::clear_error() { + if (error_ != &::google::protobuf::internal::kEmptyString) { + error_->clear(); + } + clear_has_error(); +} +inline const ::std::string& CodeGeneratorResponse::error() const { + return *error_; +} +inline void CodeGeneratorResponse::set_error(const ::std::string& value) { + set_has_error(); + if (error_ == &::google::protobuf::internal::kEmptyString) { + error_ = new ::std::string; + } + error_->assign(value); +} +inline void CodeGeneratorResponse::set_error(const char* value) { + set_has_error(); + if (error_ == &::google::protobuf::internal::kEmptyString) { + error_ = new ::std::string; + } + error_->assign(value); +} +inline void CodeGeneratorResponse::set_error(const char* value, size_t size) { + set_has_error(); + if (error_ == &::google::protobuf::internal::kEmptyString) { + error_ = new ::std::string; + } + error_->assign(reinterpret_cast(value), size); +} +inline ::std::string* CodeGeneratorResponse::mutable_error() { + set_has_error(); + if (error_ == &::google::protobuf::internal::kEmptyString) { + error_ = new ::std::string; + } + return error_; +} +inline ::std::string* CodeGeneratorResponse::release_error() { + clear_has_error(); + if (error_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = error_; + error_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; +inline int CodeGeneratorResponse::file_size() const { + return file_.size(); +} +inline void CodeGeneratorResponse::clear_file() { + file_.Clear(); +} +inline const ::google::protobuf::compiler::CodeGeneratorResponse_File& CodeGeneratorResponse::file(int index) const { + return file_.Get(index); +} +inline ::google::protobuf::compiler::CodeGeneratorResponse_File* CodeGeneratorResponse::mutable_file(int index) { + return file_.Mutable(index); +} +inline ::google::protobuf::compiler::CodeGeneratorResponse_File* CodeGeneratorResponse::add_file() { + return file_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >& +CodeGeneratorResponse::file() const { + return file_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >* +CodeGeneratorResponse::mutable_file() { + return &file_; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace compiler +} // namespace protobuf +} // namespace google + +#ifndef SWIG +namespace google { +namespace protobuf { + + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h new file mode 100644 index 00000000..84eaf8ab --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h @@ -0,0 +1,156 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: robinson@google.com (Will Robinson) +// +// Generates Python code for a given .proto file. + +#ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ + +#include + +#include +#include + +namespace google { +namespace protobuf { + +class Descriptor; +class EnumDescriptor; +class EnumValueDescriptor; +class FieldDescriptor; +class ServiceDescriptor; + +namespace io { class Printer; } + +namespace compiler { +namespace python { + +// CodeGenerator implementation for generated Python protocol buffer classes. +// If you create your own protocol compiler binary and you want it to support +// Python output, you can do so by registering an instance of this +// CodeGenerator with the CommandLineInterface in your main() function. +class LIBPROTOC_EXPORT Generator : public CodeGenerator { + public: + Generator(); + virtual ~Generator(); + + // CodeGenerator methods. + virtual bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* generator_context, + string* error) const; + + private: + void PrintImports() const; + void PrintFileDescriptor() const; + void PrintTopLevelEnums() const; + void PrintAllNestedEnumsInFile() const; + void PrintNestedEnums(const Descriptor& descriptor) const; + void PrintEnum(const EnumDescriptor& enum_descriptor) const; + + void PrintTopLevelExtensions() const; + + void PrintFieldDescriptor( + const FieldDescriptor& field, bool is_extension) const; + void PrintFieldDescriptorsInDescriptor( + const Descriptor& message_descriptor, + bool is_extension, + const string& list_variable_name, + int (Descriptor::*CountFn)() const, + const FieldDescriptor* (Descriptor::*GetterFn)(int) const) const; + void PrintFieldsInDescriptor(const Descriptor& message_descriptor) const; + void PrintExtensionsInDescriptor(const Descriptor& message_descriptor) const; + void PrintMessageDescriptors() const; + void PrintDescriptor(const Descriptor& message_descriptor) const; + void PrintNestedDescriptors(const Descriptor& containing_descriptor) const; + + void PrintMessages() const; + void PrintMessage(const Descriptor& message_descriptor) const; + void PrintNestedMessages(const Descriptor& containing_descriptor) const; + + void FixForeignFieldsInDescriptors() const; + void FixForeignFieldsInDescriptor( + const Descriptor& descriptor, + const Descriptor* containing_descriptor) const; + void FixForeignFieldsInField(const Descriptor* containing_type, + const FieldDescriptor& field, + const string& python_dict_name) const; + void AddMessageToFileDescriptor(const Descriptor& descriptor) const; + string FieldReferencingExpression(const Descriptor* containing_type, + const FieldDescriptor& field, + const string& python_dict_name) const; + template + void FixContainingTypeInDescriptor( + const DescriptorT& descriptor, + const Descriptor* containing_descriptor) const; + + void FixForeignFieldsInExtensions() const; + void FixForeignFieldsInExtension( + const FieldDescriptor& extension_field) const; + void FixForeignFieldsInNestedExtensions(const Descriptor& descriptor) const; + + void PrintServices() const; + void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; + void PrintServiceClass(const ServiceDescriptor& descriptor) const; + void PrintServiceStub(const ServiceDescriptor& descriptor) const; + + void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; + string OptionsValue(const string& class_name, + const string& serialized_options) const; + bool GeneratingDescriptorProto() const; + + template + string ModuleLevelDescriptorName(const DescriptorT& descriptor) const; + string ModuleLevelMessageName(const Descriptor& descriptor) const; + string ModuleLevelServiceDescriptorName( + const ServiceDescriptor& descriptor) const; + + template + void PrintSerializedPbInterval( + const DescriptorT& descriptor, DescriptorProtoT& proto) const; + + // Very coarse-grained lock to ensure that Generate() is reentrant. + // Guards file_, printer_ and file_descriptor_serialized_. + mutable Mutex mutex_; + mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. + mutable string file_descriptor_serialized_; + mutable io::Printer* printer_; // Set in Generate(). Under mutex_. + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator); +}; + +} // namespace python +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h new file mode 100644 index 00000000..de9fce9e --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h @@ -0,0 +1,108 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) + +#ifndef GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ +#define GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN // right... +#include +#else // _WIN32 +#include +#include +#endif // !_WIN32 +#include + +#include + + +namespace google { +namespace protobuf { + +class Message; + +namespace compiler { + +// Utility class for launching sub-processes. +class Subprocess { + public: + Subprocess(); + ~Subprocess(); + + enum SearchMode { + SEARCH_PATH, // Use PATH environment variable. + EXACT_NAME // Program is an exact file name; don't use the PATH. + }; + + // Start the subprocess. Currently we don't provide a way to specify + // arguments as protoc plugins don't have any. + void Start(const string& program, SearchMode search_mode); + + // Serialize the input message and pipe it to the subprocess's stdin, then + // close the pipe. Meanwhile, read from the subprocess's stdout and parse + // the data into *output. All this is done carefully to avoid deadlocks. + // Returns true if successful. On any sort of error, returns false and sets + // *error to a description of the problem. + bool Communicate(const Message& input, Message* output, string* error); + +#ifdef _WIN32 + // Given an error code, returns a human-readable error message. This is + // defined here so that CommandLineInterface can share it. + static string Win32ErrorMessage(DWORD error_code); +#endif + + private: +#ifdef _WIN32 + DWORD process_start_error_; + HANDLE child_handle_; + + // The file handles for our end of the child's pipes. We close each and + // set it to NULL when no longer needed. + HANDLE child_stdin_; + HANDLE child_stdout_; + +#else // _WIN32 + pid_t child_pid_; + + // The file descriptors for our end of the child's pipes. We close each and + // set it to -1 when no longer needed. + int child_stdin_; + int child_stdout_; + +#endif // !_WIN32 +}; + +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h new file mode 100644 index 00000000..be73972a --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h @@ -0,0 +1,93 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { + +class ZipWriter { + public: + ZipWriter(io::ZeroCopyOutputStream* raw_output); + ~ZipWriter(); + + bool Write(const string& filename, const string& contents); + bool WriteDirectory(); + + private: + struct FileInfo { + string name; + uint32 offset; + uint32 size; + uint32 crc32; + }; + + io::ZeroCopyOutputStream* raw_output_; + vector files_; +}; + +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h b/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h new file mode 100644 index 00000000..7f87dd80 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h @@ -0,0 +1,1367 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file contains classes which describe a type of protocol message. +// You can use a message's descriptor to learn at runtime what fields +// it contains and what the types of those fields are. The Message +// interface also allows you to dynamically access and modify individual +// fields by passing the FieldDescriptor of the field you are interested +// in. +// +// Most users will not care about descriptors, because they will write +// code specific to certain protocol types and will simply use the classes +// generated by the protocol compiler directly. Advanced users who want +// to operate on arbitrary types (not known at compile time) may want to +// read descriptors in order to learn about the contents of a message. +// A very small number of users will want to construct their own +// Descriptors, either because they are implementing Message manually or +// because they are writing something like the protocol compiler. +// +// For an example of how you might use descriptors, see the code example +// at the top of message.h. + +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_H__ +#define GOOGLE_PROTOBUF_DESCRIPTOR_H__ + +#include +#include +#include + + +namespace google { +namespace protobuf { + +// Defined in this file. +class Descriptor; +class FieldDescriptor; +class EnumDescriptor; +class EnumValueDescriptor; +class ServiceDescriptor; +class MethodDescriptor; +class FileDescriptor; +class DescriptorDatabase; +class DescriptorPool; + +// Defined in descriptor.proto +class DescriptorProto; +class FieldDescriptorProto; +class EnumDescriptorProto; +class EnumValueDescriptorProto; +class ServiceDescriptorProto; +class MethodDescriptorProto; +class FileDescriptorProto; +class MessageOptions; +class FieldOptions; +class EnumOptions; +class EnumValueOptions; +class ServiceOptions; +class MethodOptions; +class FileOptions; +class UninterpretedOption; + +// Defined in message.h +class Message; + +// Defined in descriptor.cc +class DescriptorBuilder; +class FileDescriptorTables; + +// Defined in unknown_field_set.h. +class UnknownField; + +// Describes a type of protocol message, or a particular group within a +// message. To obtain the Descriptor for a given message object, call +// Message::GetDescriptor(). Generated message classes also have a +// static method called descriptor() which returns the type's descriptor. +// Use DescriptorPool to construct your own descriptors. +class LIBPROTOBUF_EXPORT Descriptor { + public: + // The name of the message type, not including its scope. + const string& name() const; + + // The fully-qualified name of the message type, scope delimited by + // periods. For example, message type "Foo" which is declared in package + // "bar" has full name "bar.Foo". If a type "Baz" is nested within + // Foo, Baz's full_name is "bar.Foo.Baz". To get only the part that + // comes after the last '.', use name(). + const string& full_name() const; + + // Index of this descriptor within the file or containing type's message + // type array. + int index() const; + + // The .proto file in which this message type was defined. Never NULL. + const FileDescriptor* file() const; + + // If this Descriptor describes a nested type, this returns the type + // in which it is nested. Otherwise, returns NULL. + const Descriptor* containing_type() const; + + // Get options for this message type. These are specified in the .proto file + // by placing lines like "option foo = 1234;" in the message definition. + // Allowed options are defined by MessageOptions in + // google/protobuf/descriptor.proto, and any available extensions of that + // message. + const MessageOptions& options() const; + + // Write the contents of this Descriptor into the given DescriptorProto. + // The target DescriptorProto must be clear before calling this; if it + // isn't, the result may be garbage. + void CopyTo(DescriptorProto* proto) const; + + // Write the contents of this decriptor in a human-readable form. Output + // will be suitable for re-parsing. + string DebugString() const; + + // Field stuff ----------------------------------------------------- + + // The number of fields in this message type. + int field_count() const; + // Gets a field by index, where 0 <= index < field_count(). + // These are returned in the order they were defined in the .proto file. + const FieldDescriptor* field(int index) const; + + // Looks up a field by declared tag number. Returns NULL if no such field + // exists. + const FieldDescriptor* FindFieldByNumber(int number) const; + // Looks up a field by name. Returns NULL if no such field exists. + const FieldDescriptor* FindFieldByName(const string& name) const; + + // Looks up a field by lowercased name (as returned by lowercase_name()). + // This lookup may be ambiguous if multiple field names differ only by case, + // in which case the field returned is chosen arbitrarily from the matches. + const FieldDescriptor* FindFieldByLowercaseName( + const string& lowercase_name) const; + + // Looks up a field by camel-case name (as returned by camelcase_name()). + // This lookup may be ambiguous if multiple field names differ in a way that + // leads them to have identical camel-case names, in which case the field + // returned is chosen arbitrarily from the matches. + const FieldDescriptor* FindFieldByCamelcaseName( + const string& camelcase_name) const; + + // Nested type stuff ----------------------------------------------- + + // The number of nested types in this message type. + int nested_type_count() const; + // Gets a nested type by index, where 0 <= index < nested_type_count(). + // These are returned in the order they were defined in the .proto file. + const Descriptor* nested_type(int index) const; + + // Looks up a nested type by name. Returns NULL if no such nested type + // exists. + const Descriptor* FindNestedTypeByName(const string& name) const; + + // Enum stuff ------------------------------------------------------ + + // The number of enum types in this message type. + int enum_type_count() const; + // Gets an enum type by index, where 0 <= index < enum_type_count(). + // These are returned in the order they were defined in the .proto file. + const EnumDescriptor* enum_type(int index) const; + + // Looks up an enum type by name. Returns NULL if no such enum type exists. + const EnumDescriptor* FindEnumTypeByName(const string& name) const; + + // Looks up an enum value by name, among all enum types in this message. + // Returns NULL if no such value exists. + const EnumValueDescriptor* FindEnumValueByName(const string& name) const; + + // Extensions ------------------------------------------------------ + + // A range of field numbers which are designated for third-party + // extensions. + struct ExtensionRange { + int start; // inclusive + int end; // exclusive + }; + + // The number of extension ranges in this message type. + int extension_range_count() const; + // Gets an extension range by index, where 0 <= index < + // extension_range_count(). These are returned in the order they were defined + // in the .proto file. + const ExtensionRange* extension_range(int index) const; + + // Returns true if the number is in one of the extension ranges. + bool IsExtensionNumber(int number) const; + + // The number of extensions -- extending *other* messages -- that were + // defined nested within this message type's scope. + int extension_count() const; + // Get an extension by index, where 0 <= index < extension_count(). + // These are returned in the order they were defined in the .proto file. + const FieldDescriptor* extension(int index) const; + + // Looks up a named extension (which extends some *other* message type) + // defined within this message type's scope. + const FieldDescriptor* FindExtensionByName(const string& name) const; + + // Similar to FindFieldByLowercaseName(), but finds extensions defined within + // this message type's scope. + const FieldDescriptor* FindExtensionByLowercaseName(const string& name) const; + + // Similar to FindFieldByCamelcaseName(), but finds extensions defined within + // this message type's scope. + const FieldDescriptor* FindExtensionByCamelcaseName(const string& name) const; + + private: + typedef MessageOptions OptionsType; + + // Internal version of DebugString; controls the level of indenting for + // correct depth + void DebugString(int depth, string *contents) const; + + const string* name_; + const string* full_name_; + const FileDescriptor* file_; + const Descriptor* containing_type_; + const MessageOptions* options_; + + // True if this is a placeholder for an unknown type. + bool is_placeholder_; + // True if this is a placeholder and the type name wasn't fully-qualified. + bool is_unqualified_placeholder_; + + int field_count_; + FieldDescriptor* fields_; + int nested_type_count_; + Descriptor* nested_types_; + int enum_type_count_; + EnumDescriptor* enum_types_; + int extension_range_count_; + ExtensionRange* extension_ranges_; + int extension_count_; + FieldDescriptor* extensions_; + // IMPORTANT: If you add a new field, make sure to search for all instances + // of Allocate() and AllocateArray() in descriptor.cc + // and update them to initialize the field. + + // Must be constructed using DescriptorPool. + Descriptor() {} + friend class DescriptorBuilder; + friend class EnumDescriptor; + friend class FieldDescriptor; + friend class MethodDescriptor; + friend class FileDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor); +}; + +// Describes a single field of a message. To get the descriptor for a given +// field, first get the Descriptor for the message in which it is defined, +// then call Descriptor::FindFieldByName(). To get a FieldDescriptor for +// an extension, do one of the following: +// - Get the Descriptor or FileDescriptor for its containing scope, then +// call Descriptor::FindExtensionByName() or +// FileDescriptor::FindExtensionByName(). +// - Given a DescriptorPool, call DescriptorPool::FindExtensionByNumber(). +// - Given a Reflection for a message object, call +// Reflection::FindKnownExtensionByName() or +// Reflection::FindKnownExtensionByNumber(). +// Use DescriptorPool to construct your own descriptors. +class LIBPROTOBUF_EXPORT FieldDescriptor { + public: + // Identifies a field type. 0 is reserved for errors. The order is weird + // for historical reasons. Types 12 and up are new in proto2. + enum Type { + TYPE_DOUBLE = 1, // double, exactly eight bytes on the wire. + TYPE_FLOAT = 2, // float, exactly four bytes on the wire. + TYPE_INT64 = 3, // int64, varint on the wire. Negative numbers + // take 10 bytes. Use TYPE_SINT64 if negative + // values are likely. + TYPE_UINT64 = 4, // uint64, varint on the wire. + TYPE_INT32 = 5, // int32, varint on the wire. Negative numbers + // take 10 bytes. Use TYPE_SINT32 if negative + // values are likely. + TYPE_FIXED64 = 6, // uint64, exactly eight bytes on the wire. + TYPE_FIXED32 = 7, // uint32, exactly four bytes on the wire. + TYPE_BOOL = 8, // bool, varint on the wire. + TYPE_STRING = 9, // UTF-8 text. + TYPE_GROUP = 10, // Tag-delimited message. Deprecated. + TYPE_MESSAGE = 11, // Length-delimited message. + + TYPE_BYTES = 12, // Arbitrary byte array. + TYPE_UINT32 = 13, // uint32, varint on the wire + TYPE_ENUM = 14, // Enum, varint on the wire + TYPE_SFIXED32 = 15, // int32, exactly four bytes on the wire + TYPE_SFIXED64 = 16, // int64, exactly eight bytes on the wire + TYPE_SINT32 = 17, // int32, ZigZag-encoded varint on the wire + TYPE_SINT64 = 18, // int64, ZigZag-encoded varint on the wire + + MAX_TYPE = 18, // Constant useful for defining lookup tables + // indexed by Type. + }; + + // Specifies the C++ data type used to represent the field. There is a + // fixed mapping from Type to CppType where each Type maps to exactly one + // CppType. 0 is reserved for errors. + enum CppType { + CPPTYPE_INT32 = 1, // TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32 + CPPTYPE_INT64 = 2, // TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64 + CPPTYPE_UINT32 = 3, // TYPE_UINT32, TYPE_FIXED32 + CPPTYPE_UINT64 = 4, // TYPE_UINT64, TYPE_FIXED64 + CPPTYPE_DOUBLE = 5, // TYPE_DOUBLE + CPPTYPE_FLOAT = 6, // TYPE_FLOAT + CPPTYPE_BOOL = 7, // TYPE_BOOL + CPPTYPE_ENUM = 8, // TYPE_ENUM + CPPTYPE_STRING = 9, // TYPE_STRING, TYPE_BYTES + CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP + + MAX_CPPTYPE = 10, // Constant useful for defining lookup tables + // indexed by CppType. + }; + + // Identifies whether the field is optional, required, or repeated. 0 is + // reserved for errors. + enum Label { + LABEL_OPTIONAL = 1, // optional + LABEL_REQUIRED = 2, // required + LABEL_REPEATED = 3, // repeated + + MAX_LABEL = 3, // Constant useful for defining lookup tables + // indexed by Label. + }; + + // Valid field numbers are positive integers up to kMaxNumber. + static const int kMaxNumber = (1 << 29) - 1; + + // First field number reserved for the protocol buffer library implementation. + // Users may not declare fields that use reserved numbers. + static const int kFirstReservedNumber = 19000; + // Last field number reserved for the protocol buffer library implementation. + // Users may not declare fields that use reserved numbers. + static const int kLastReservedNumber = 19999; + + const string& name() const; // Name of this field within the message. + const string& full_name() const; // Fully-qualified name of the field. + const FileDescriptor* file() const;// File in which this field was defined. + bool is_extension() const; // Is this an extension field? + int number() const; // Declared tag number. + + // Same as name() except converted to lower-case. This (and especially the + // FindFieldByLowercaseName() method) can be useful when parsing formats + // which prefer to use lowercase naming style. (Although, technically + // field names should be lowercased anyway according to the protobuf style + // guide, so this only makes a difference when dealing with old .proto files + // which do not follow the guide.) + const string& lowercase_name() const; + + // Same as name() except converted to camel-case. In this conversion, any + // time an underscore appears in the name, it is removed and the next + // letter is capitalized. Furthermore, the first letter of the name is + // lower-cased. Examples: + // FooBar -> fooBar + // foo_bar -> fooBar + // fooBar -> fooBar + // This (and especially the FindFieldByCamelcaseName() method) can be useful + // when parsing formats which prefer to use camel-case naming style. + const string& camelcase_name() const; + + Type type() const; // Declared type of this field. + CppType cpp_type() const; // C++ type of this field. + Label label() const; // optional/required/repeated + + bool is_required() const; // shorthand for label() == LABEL_REQUIRED + bool is_optional() const; // shorthand for label() == LABEL_OPTIONAL + bool is_repeated() const; // shorthand for label() == LABEL_REPEATED + bool is_packable() const; // shorthand for is_repeated() && + // IsTypePackable(type()) + + // Index of this field within the message's field array, or the file or + // extension scope's extensions array. + int index() const; + + // Does this field have an explicitly-declared default value? + bool has_default_value() const; + + // Get the field default value if cpp_type() == CPPTYPE_INT32. If no + // explicit default was defined, the default is 0. + int32 default_value_int32() const; + // Get the field default value if cpp_type() == CPPTYPE_INT64. If no + // explicit default was defined, the default is 0. + int64 default_value_int64() const; + // Get the field default value if cpp_type() == CPPTYPE_UINT32. If no + // explicit default was defined, the default is 0. + uint32 default_value_uint32() const; + // Get the field default value if cpp_type() == CPPTYPE_UINT64. If no + // explicit default was defined, the default is 0. + uint64 default_value_uint64() const; + // Get the field default value if cpp_type() == CPPTYPE_FLOAT. If no + // explicit default was defined, the default is 0.0. + float default_value_float() const; + // Get the field default value if cpp_type() == CPPTYPE_DOUBLE. If no + // explicit default was defined, the default is 0.0. + double default_value_double() const; + // Get the field default value if cpp_type() == CPPTYPE_BOOL. If no + // explicit default was defined, the default is false. + bool default_value_bool() const; + // Get the field default value if cpp_type() == CPPTYPE_ENUM. If no + // explicit default was defined, the default is the first value defined + // in the enum type (all enum types are required to have at least one value). + // This never returns NULL. + const EnumValueDescriptor* default_value_enum() const; + // Get the field default value if cpp_type() == CPPTYPE_STRING. If no + // explicit default was defined, the default is the empty string. + const string& default_value_string() const; + + // The Descriptor for the message of which this is a field. For extensions, + // this is the extended type. Never NULL. + const Descriptor* containing_type() const; + + // An extension may be declared within the scope of another message. If this + // field is an extension (is_extension() is true), then extension_scope() + // returns that message, or NULL if the extension was declared at global + // scope. If this is not an extension, extension_scope() is undefined (may + // assert-fail). + const Descriptor* extension_scope() const; + + // If type is TYPE_MESSAGE or TYPE_GROUP, returns a descriptor for the + // message or the group type. Otherwise, undefined. + const Descriptor* message_type() const; + // If type is TYPE_ENUM, returns a descriptor for the enum. Otherwise, + // undefined. + const EnumDescriptor* enum_type() const; + + // EXPERIMENTAL; DO NOT USE. + // If this field is a map field, experimental_map_key() is the field + // that is the key for this map. + // experimental_map_key()->containing_type() is the same as message_type(). + const FieldDescriptor* experimental_map_key() const; + + // Get the FieldOptions for this field. This includes things listed in + // square brackets after the field definition. E.g., the field: + // optional string text = 1 [ctype=CORD]; + // has the "ctype" option set. Allowed options are defined by FieldOptions + // in google/protobuf/descriptor.proto, and any available extensions of that + // message. + const FieldOptions& options() const; + + // See Descriptor::CopyTo(). + void CopyTo(FieldDescriptorProto* proto) const; + + // See Descriptor::DebugString(). + string DebugString() const; + + // Helper method to get the CppType for a particular Type. + static CppType TypeToCppType(Type type); + + // Return true iff [packed = true] is valid for fields of this type. + static inline bool IsTypePackable(Type field_type); + + private: + typedef FieldOptions OptionsType; + + // See Descriptor::DebugString(). + void DebugString(int depth, string *contents) const; + + // formats the default value appropriately and returns it as a string. + // Must have a default value to call this. If quote_string_type is true, then + // types of CPPTYPE_STRING whill be surrounded by quotes and CEscaped. + string DefaultValueAsString(bool quote_string_type) const; + + const string* name_; + const string* full_name_; + const string* lowercase_name_; + const string* camelcase_name_; + const FileDescriptor* file_; + int number_; + Type type_; + Label label_; + bool is_extension_; + const Descriptor* containing_type_; + const Descriptor* extension_scope_; + const Descriptor* message_type_; + const EnumDescriptor* enum_type_; + const FieldDescriptor* experimental_map_key_; + const FieldOptions* options_; + // IMPORTANT: If you add a new field, make sure to search for all instances + // of Allocate() and AllocateArray() in + // descriptor.cc and update them to initialize the field. + + bool has_default_value_; + union { + int32 default_value_int32_; + int64 default_value_int64_; + uint32 default_value_uint32_; + uint64 default_value_uint64_; + float default_value_float_; + double default_value_double_; + bool default_value_bool_; + + const EnumValueDescriptor* default_value_enum_; + const string* default_value_string_; + }; + + static const CppType kTypeToCppTypeMap[MAX_TYPE + 1]; + + static const char * const kTypeToName[MAX_TYPE + 1]; + + static const char * const kLabelToName[MAX_LABEL + 1]; + + // Must be constructed using DescriptorPool. + FieldDescriptor() {} + friend class DescriptorBuilder; + friend class FileDescriptor; + friend class Descriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor); +}; + +// Describes an enum type defined in a .proto file. To get the EnumDescriptor +// for a generated enum type, call TypeName_descriptor(). Use DescriptorPool +// to construct your own descriptors. +class LIBPROTOBUF_EXPORT EnumDescriptor { + public: + // The name of this enum type in the containing scope. + const string& name() const; + + // The fully-qualified name of the enum type, scope delimited by periods. + const string& full_name() const; + + // Index of this enum within the file or containing message's enum array. + int index() const; + + // The .proto file in which this enum type was defined. Never NULL. + const FileDescriptor* file() const; + + // The number of values for this EnumDescriptor. Guaranteed to be greater + // than zero. + int value_count() const; + // Gets a value by index, where 0 <= index < value_count(). + // These are returned in the order they were defined in the .proto file. + const EnumValueDescriptor* value(int index) const; + + // Looks up a value by name. Returns NULL if no such value exists. + const EnumValueDescriptor* FindValueByName(const string& name) const; + // Looks up a value by number. Returns NULL if no such value exists. If + // multiple values have this number, the first one defined is returned. + const EnumValueDescriptor* FindValueByNumber(int number) const; + + // If this enum type is nested in a message type, this is that message type. + // Otherwise, NULL. + const Descriptor* containing_type() const; + + // Get options for this enum type. These are specified in the .proto file by + // placing lines like "option foo = 1234;" in the enum definition. Allowed + // options are defined by EnumOptions in google/protobuf/descriptor.proto, + // and any available extensions of that message. + const EnumOptions& options() const; + + // See Descriptor::CopyTo(). + void CopyTo(EnumDescriptorProto* proto) const; + + // See Descriptor::DebugString(). + string DebugString() const; + + private: + typedef EnumOptions OptionsType; + + // See Descriptor::DebugString(). + void DebugString(int depth, string *contents) const; + + const string* name_; + const string* full_name_; + const FileDescriptor* file_; + const Descriptor* containing_type_; + const EnumOptions* options_; + + // True if this is a placeholder for an unknown type. + bool is_placeholder_; + // True if this is a placeholder and the type name wasn't fully-qualified. + bool is_unqualified_placeholder_; + + int value_count_; + EnumValueDescriptor* values_; + // IMPORTANT: If you add a new field, make sure to search for all instances + // of Allocate() and AllocateArray() in + // descriptor.cc and update them to initialize the field. + + // Must be constructed using DescriptorPool. + EnumDescriptor() {} + friend class DescriptorBuilder; + friend class Descriptor; + friend class FieldDescriptor; + friend class EnumValueDescriptor; + friend class FileDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor); +}; + +// Describes an individual enum constant of a particular type. To get the +// EnumValueDescriptor for a given enum value, first get the EnumDescriptor +// for its type, then use EnumDescriptor::FindValueByName() or +// EnumDescriptor::FindValueByNumber(). Use DescriptorPool to construct +// your own descriptors. +class LIBPROTOBUF_EXPORT EnumValueDescriptor { + public: + const string& name() const; // Name of this enum constant. + int index() const; // Index within the enums's Descriptor. + int number() const; // Numeric value of this enum constant. + + // The full_name of an enum value is a sibling symbol of the enum type. + // e.g. the full name of FieldDescriptorProto::TYPE_INT32 is actually + // "google.protobuf.FieldDescriptorProto.TYPE_INT32", NOT + // "google.protobuf.FieldDescriptorProto.Type.TYPE_INT32". This is to conform + // with C++ scoping rules for enums. + const string& full_name() const; + + // The type of this value. Never NULL. + const EnumDescriptor* type() const; + + // Get options for this enum value. These are specified in the .proto file + // by adding text like "[foo = 1234]" after an enum value definition. + // Allowed options are defined by EnumValueOptions in + // google/protobuf/descriptor.proto, and any available extensions of that + // message. + const EnumValueOptions& options() const; + + // See Descriptor::CopyTo(). + void CopyTo(EnumValueDescriptorProto* proto) const; + + // See Descriptor::DebugString(). + string DebugString() const; + + private: + typedef EnumValueOptions OptionsType; + + // See Descriptor::DebugString(). + void DebugString(int depth, string *contents) const; + + const string* name_; + const string* full_name_; + int number_; + const EnumDescriptor* type_; + const EnumValueOptions* options_; + // IMPORTANT: If you add a new field, make sure to search for all instances + // of Allocate() and AllocateArray() + // in descriptor.cc and update them to initialize the field. + + // Must be constructed using DescriptorPool. + EnumValueDescriptor() {} + friend class DescriptorBuilder; + friend class EnumDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor); +}; + +// Describes an RPC service. To get the ServiceDescriptor for a service, +// call Service::GetDescriptor(). Generated service classes also have a +// static method called descriptor() which returns the type's +// ServiceDescriptor. Use DescriptorPool to construct your own descriptors. +class LIBPROTOBUF_EXPORT ServiceDescriptor { + public: + // The name of the service, not including its containing scope. + const string& name() const; + // The fully-qualified name of the service, scope delimited by periods. + const string& full_name() const; + // Index of this service within the file's services array. + int index() const; + + // The .proto file in which this service was defined. Never NULL. + const FileDescriptor* file() const; + + // Get options for this service type. These are specified in the .proto file + // by placing lines like "option foo = 1234;" in the service definition. + // Allowed options are defined by ServiceOptions in + // google/protobuf/descriptor.proto, and any available extensions of that + // message. + const ServiceOptions& options() const; + + // The number of methods this service defines. + int method_count() const; + // Gets a MethodDescriptor by index, where 0 <= index < method_count(). + // These are returned in the order they were defined in the .proto file. + const MethodDescriptor* method(int index) const; + + // Look up a MethodDescriptor by name. + const MethodDescriptor* FindMethodByName(const string& name) const; + + // See Descriptor::CopyTo(). + void CopyTo(ServiceDescriptorProto* proto) const; + + // See Descriptor::DebugString(). + string DebugString() const; + + private: + typedef ServiceOptions OptionsType; + + // See Descriptor::DebugString(). + void DebugString(string *contents) const; + + const string* name_; + const string* full_name_; + const FileDescriptor* file_; + const ServiceOptions* options_; + int method_count_; + MethodDescriptor* methods_; + // IMPORTANT: If you add a new field, make sure to search for all instances + // of Allocate() and AllocateArray() in + // descriptor.cc and update them to initialize the field. + + // Must be constructed using DescriptorPool. + ServiceDescriptor() {} + friend class DescriptorBuilder; + friend class FileDescriptor; + friend class MethodDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor); +}; + +// Describes an individual service method. To obtain a MethodDescriptor given +// a service, first get its ServiceDescriptor, then call +// ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your +// own descriptors. +class LIBPROTOBUF_EXPORT MethodDescriptor { + public: + // Name of this method, not including containing scope. + const string& name() const; + // The fully-qualified name of the method, scope delimited by periods. + const string& full_name() const; + // Index within the service's Descriptor. + int index() const; + + // Gets the service to which this method belongs. Never NULL. + const ServiceDescriptor* service() const; + + // Gets the type of protocol message which this method accepts as input. + const Descriptor* input_type() const; + // Gets the type of protocol message which this message produces as output. + const Descriptor* output_type() const; + + // Get options for this method. These are specified in the .proto file by + // placing lines like "option foo = 1234;" in curly-braces after a method + // declaration. Allowed options are defined by MethodOptions in + // google/protobuf/descriptor.proto, and any available extensions of that + // message. + const MethodOptions& options() const; + + // See Descriptor::CopyTo(). + void CopyTo(MethodDescriptorProto* proto) const; + + // See Descriptor::DebugString(). + string DebugString() const; + + private: + typedef MethodOptions OptionsType; + + // See Descriptor::DebugString(). + void DebugString(int depth, string *contents) const; + + const string* name_; + const string* full_name_; + const ServiceDescriptor* service_; + const Descriptor* input_type_; + const Descriptor* output_type_; + const MethodOptions* options_; + // IMPORTANT: If you add a new field, make sure to search for all instances + // of Allocate() and AllocateArray() in + // descriptor.cc and update them to initialize the field. + + // Must be constructed using DescriptorPool. + MethodDescriptor() {} + friend class DescriptorBuilder; + friend class ServiceDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MethodDescriptor); +}; + +// Describes a whole .proto file. To get the FileDescriptor for a compiled-in +// file, get the descriptor for something defined in that file and call +// descriptor->file(). Use DescriptorPool to construct your own descriptors. +class LIBPROTOBUF_EXPORT FileDescriptor { + public: + // The filename, relative to the source tree. + // e.g. "google/protobuf/descriptor.proto" + const string& name() const; + + // The package, e.g. "google.protobuf.compiler". + const string& package() const; + + // The DescriptorPool in which this FileDescriptor and all its contents were + // allocated. Never NULL. + const DescriptorPool* pool() const; + + // The number of files imported by this one. + int dependency_count() const; + // Gets an imported file by index, where 0 <= index < dependency_count(). + // These are returned in the order they were defined in the .proto file. + const FileDescriptor* dependency(int index) const; + + // Number of top-level message types defined in this file. (This does not + // include nested types.) + int message_type_count() const; + // Gets a top-level message type, where 0 <= index < message_type_count(). + // These are returned in the order they were defined in the .proto file. + const Descriptor* message_type(int index) const; + + // Number of top-level enum types defined in this file. (This does not + // include nested types.) + int enum_type_count() const; + // Gets a top-level enum type, where 0 <= index < enum_type_count(). + // These are returned in the order they were defined in the .proto file. + const EnumDescriptor* enum_type(int index) const; + + // Number of services defined in this file. + int service_count() const; + // Gets a service, where 0 <= index < service_count(). + // These are returned in the order they were defined in the .proto file. + const ServiceDescriptor* service(int index) const; + + // Number of extensions defined at file scope. (This does not include + // extensions nested within message types.) + int extension_count() const; + // Gets an extension's descriptor, where 0 <= index < extension_count(). + // These are returned in the order they were defined in the .proto file. + const FieldDescriptor* extension(int index) const; + + // Get options for this file. These are specified in the .proto file by + // placing lines like "option foo = 1234;" at the top level, outside of any + // other definitions. Allowed options are defined by FileOptions in + // google/protobuf/descriptor.proto, and any available extensions of that + // message. + const FileOptions& options() const; + + // Find a top-level message type by name. Returns NULL if not found. + const Descriptor* FindMessageTypeByName(const string& name) const; + // Find a top-level enum type by name. Returns NULL if not found. + const EnumDescriptor* FindEnumTypeByName(const string& name) const; + // Find an enum value defined in any top-level enum by name. Returns NULL if + // not found. + const EnumValueDescriptor* FindEnumValueByName(const string& name) const; + // Find a service definition by name. Returns NULL if not found. + const ServiceDescriptor* FindServiceByName(const string& name) const; + // Find a top-level extension definition by name. Returns NULL if not found. + const FieldDescriptor* FindExtensionByName(const string& name) const; + // Similar to FindExtensionByName(), but searches by lowercased-name. See + // Descriptor::FindFieldByLowercaseName(). + const FieldDescriptor* FindExtensionByLowercaseName(const string& name) const; + // Similar to FindExtensionByName(), but searches by camelcased-name. See + // Descriptor::FindFieldByCamelcaseName(). + const FieldDescriptor* FindExtensionByCamelcaseName(const string& name) const; + + // See Descriptor::CopyTo(). + void CopyTo(FileDescriptorProto* proto) const; + + // See Descriptor::DebugString(). + string DebugString() const; + + private: + typedef FileOptions OptionsType; + + const string* name_; + const string* package_; + const DescriptorPool* pool_; + int dependency_count_; + const FileDescriptor** dependencies_; + int message_type_count_; + Descriptor* message_types_; + int enum_type_count_; + EnumDescriptor* enum_types_; + int service_count_; + ServiceDescriptor* services_; + int extension_count_; + FieldDescriptor* extensions_; + const FileOptions* options_; + + const FileDescriptorTables* tables_; + // IMPORTANT: If you add a new field, make sure to search for all instances + // of Allocate() and AllocateArray() in + // descriptor.cc and update them to initialize the field. + + FileDescriptor() {} + friend class DescriptorBuilder; + friend class Descriptor; + friend class FieldDescriptor; + friend class EnumDescriptor; + friend class ServiceDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor); +}; + +// =================================================================== + +// Used to construct descriptors. +// +// Normally you won't want to build your own descriptors. Message classes +// constructed by the protocol compiler will provide them for you. However, +// if you are implementing Message on your own, or if you are writing a +// program which can operate on totally arbitrary types and needs to load +// them from some sort of database, you might need to. +// +// Since Descriptors are composed of a whole lot of cross-linked bits of +// data that would be a pain to put together manually, the +// DescriptorPool class is provided to make the process easier. It can +// take a FileDescriptorProto (defined in descriptor.proto), validate it, +// and convert it to a set of nicely cross-linked Descriptors. +// +// DescriptorPool also helps with memory management. Descriptors are +// composed of many objects containing static data and pointers to each +// other. In all likelihood, when it comes time to delete this data, +// you'll want to delete it all at once. In fact, it is not uncommon to +// have a whole pool of descriptors all cross-linked with each other which +// you wish to delete all at once. This class represents such a pool, and +// handles the memory management for you. +// +// You can also search for descriptors within a DescriptorPool by name, and +// extensions by number. +class LIBPROTOBUF_EXPORT DescriptorPool { + public: + // Create a normal, empty DescriptorPool. + DescriptorPool(); + + // Constructs a DescriptorPool that, when it can't find something among the + // descriptors already in the pool, looks for it in the given + // DescriptorDatabase. + // Notes: + // - If a DescriptorPool is constructed this way, its BuildFile*() methods + // must not be called (they will assert-fail). The only way to populate + // the pool with descriptors is to call the Find*By*() methods. + // - The Find*By*() methods may block the calling thread if the + // DescriptorDatabase blocks. This in turn means that parsing messages + // may block if they need to look up extensions. + // - The Find*By*() methods will use mutexes for thread-safety, thus making + // them slower even when they don't have to fall back to the database. + // In fact, even the Find*By*() methods of descriptor objects owned by + // this pool will be slower, since they will have to obtain locks too. + // - An ErrorCollector may optionally be given to collect validation errors + // in files loaded from the database. If not given, errors will be printed + // to GOOGLE_LOG(ERROR). Remember that files are built on-demand, so this + // ErrorCollector may be called from any thread that calls one of the + // Find*By*() methods. + class ErrorCollector; + explicit DescriptorPool(DescriptorDatabase* fallback_database, + ErrorCollector* error_collector = NULL); + + ~DescriptorPool(); + + // Get a pointer to the generated pool. Generated protocol message classes + // which are compiled into the binary will allocate their descriptors in + // this pool. Do not add your own descriptors to this pool. + static const DescriptorPool* generated_pool(); + + // Find a FileDescriptor in the pool by file name. Returns NULL if not + // found. + const FileDescriptor* FindFileByName(const string& name) const; + + // Find the FileDescriptor in the pool which defines the given symbol. + // If any of the Find*ByName() methods below would succeed, then this is + // equivalent to calling that method and calling the result's file() method. + // Otherwise this returns NULL. + const FileDescriptor* FindFileContainingSymbol( + const string& symbol_name) const; + + // Looking up descriptors ------------------------------------------ + // These find descriptors by fully-qualified name. These will find both + // top-level descriptors and nested descriptors. They return NULL if not + // found. + + const Descriptor* FindMessageTypeByName(const string& name) const; + const FieldDescriptor* FindFieldByName(const string& name) const; + const FieldDescriptor* FindExtensionByName(const string& name) const; + const EnumDescriptor* FindEnumTypeByName(const string& name) const; + const EnumValueDescriptor* FindEnumValueByName(const string& name) const; + const ServiceDescriptor* FindServiceByName(const string& name) const; + const MethodDescriptor* FindMethodByName(const string& name) const; + + // Finds an extension of the given type by number. The extendee must be + // a member of this DescriptorPool or one of its underlays. + const FieldDescriptor* FindExtensionByNumber(const Descriptor* extendee, + int number) const; + + // Finds extensions of extendee. The extensions will be appended to + // out in an undefined order. Only extensions defined directly in + // this DescriptorPool or one of its underlays are guaranteed to be + // found: extensions defined in the fallback database might not be found + // depending on the database implementation. + void FindAllExtensions(const Descriptor* extendee, + vector* out) const; + + // Building descriptors -------------------------------------------- + + // When converting a FileDescriptorProto to a FileDescriptor, various + // errors might be detected in the input. The caller may handle these + // programmatically by implementing an ErrorCollector. + class LIBPROTOBUF_EXPORT ErrorCollector { + public: + inline ErrorCollector() {} + virtual ~ErrorCollector(); + + // These constants specify what exact part of the construct is broken. + // This is useful e.g. for mapping the error back to an exact location + // in a .proto file. + enum ErrorLocation { + NAME, // the symbol name, or the package name for files + NUMBER, // field or extension range number + TYPE, // field type + EXTENDEE, // field extendee + DEFAULT_VALUE, // field default value + INPUT_TYPE, // method input type + OUTPUT_TYPE, // method output type + OPTION_NAME, // name in assignment + OPTION_VALUE, // value in option assignment + OTHER // some other problem + }; + + // Reports an error in the FileDescriptorProto. + virtual void AddError( + const string& filename, // File name in which the error occurred. + const string& element_name, // Full name of the erroneous element. + const Message* descriptor, // Descriptor of the erroneous element. + ErrorLocation location, // One of the location constants, above. + const string& message // Human-readable error message. + ) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); + }; + + // Convert the FileDescriptorProto to real descriptors and place them in + // this DescriptorPool. All dependencies of the file must already be in + // the pool. Returns the resulting FileDescriptor, or NULL if there were + // problems with the input (e.g. the message was invalid, or dependencies + // were missing). Details about the errors are written to GOOGLE_LOG(ERROR). + const FileDescriptor* BuildFile(const FileDescriptorProto& proto); + + // Same as BuildFile() except errors are sent to the given ErrorCollector. + const FileDescriptor* BuildFileCollectingErrors( + const FileDescriptorProto& proto, + ErrorCollector* error_collector); + + // By default, it is an error if a FileDescriptorProto contains references + // to types or other files that are not found in the DescriptorPool (or its + // backing DescriptorDatabase, if any). If you call + // AllowUnknownDependencies(), however, then unknown types and files + // will be replaced by placeholder descriptors. This can allow you to + // perform some useful operations with a .proto file even if you do not + // have access to other .proto files on which it depends. However, some + // heuristics must be used to fill in the gaps in information, and these + // can lead to descriptors which are inaccurate. For example, the + // DescriptorPool may be forced to guess whether an unknown type is a message + // or an enum, as well as what package it resides in. Furthermore, + // placeholder types will not be discoverable via FindMessageTypeByName() + // and similar methods, which could confuse some descriptor-based algorithms. + // Generally, the results of this option should only be relied upon for + // debugging purposes. + void AllowUnknownDependencies() { allow_unknown_ = true; } + + // Internal stuff -------------------------------------------------- + // These methods MUST NOT be called from outside the proto2 library. + // These methods may contain hidden pitfalls and may be removed in a + // future library version. + + // Create a DescriptorPool which is overlaid on top of some other pool. + // If you search for a descriptor in the overlay and it is not found, the + // underlay will be searched as a backup. If the underlay has its own + // underlay, that will be searched next, and so on. This also means that + // files built in the overlay will be cross-linked with the underlay's + // descriptors if necessary. The underlay remains property of the caller; + // it must remain valid for the lifetime of the newly-constructed pool. + // + // Example: Say you want to parse a .proto file at runtime in order to use + // its type with a DynamicMessage. Say this .proto file has dependencies, + // but you know that all the dependencies will be things that are already + // compiled into the binary. For ease of use, you'd like to load the types + // right out of generated_pool() rather than have to parse redundant copies + // of all these .protos and runtime. But, you don't want to add the parsed + // types directly into generated_pool(): this is not allowed, and would be + // bad design anyway. So, instead, you could use generated_pool() as an + // underlay for a new DescriptorPool in which you add only the new file. + // + // WARNING: Use of underlays can lead to many subtle gotchas. Instead, + // try to formulate what you want to do in terms of DescriptorDatabases. + explicit DescriptorPool(const DescriptorPool* underlay); + + // Called by generated classes at init time to add their descriptors to + // generated_pool. Do NOT call this in your own code! filename must be a + // permanent string (e.g. a string literal). + static void InternalAddGeneratedFile( + const void* encoded_file_descriptor, int size); + + + // For internal use only: Gets a non-const pointer to the generated pool. + // This is called at static-initialization time only, so thread-safety is + // not a concern. If both an underlay and a fallback database are present, + // the fallback database takes precedence. + static DescriptorPool* internal_generated_pool(); + + // For internal use only: Changes the behavior of BuildFile() such that it + // allows the file to make reference to message types declared in other files + // which it did not officially declare as dependencies. + void InternalDontEnforceDependencies(); + + // For internal use only. + void internal_set_underlay(const DescriptorPool* underlay) { + underlay_ = underlay; + } + + // For internal (unit test) use only: Returns true if a FileDescriptor has + // been constructed for the given file, false otherwise. Useful for testing + // lazy descriptor initialization behavior. + bool InternalIsFileLoaded(const string& filename) const; + + private: + friend class Descriptor; + friend class FieldDescriptor; + friend class EnumDescriptor; + friend class ServiceDescriptor; + friend class FileDescriptor; + friend class DescriptorBuilder; + + // Tries to find something in the fallback database and link in the + // corresponding proto file. Returns true if successful, in which case + // the caller should search for the thing again. These are declared + // const because they are called by (semantically) const methods. + bool TryFindFileInFallbackDatabase(const string& name) const; + bool TryFindSymbolInFallbackDatabase(const string& name) const; + bool TryFindExtensionInFallbackDatabase(const Descriptor* containing_type, + int field_number) const; + + // Like BuildFile() but called internally when the file has been loaded from + // fallback_database_. Declared const because it is called by (semantically) + // const methods. + const FileDescriptor* BuildFileFromDatabase( + const FileDescriptorProto& proto) const; + + // If fallback_database_ is NULL, this is NULL. Otherwise, this is a mutex + // which must be locked while accessing tables_. + Mutex* mutex_; + + // See constructor. + DescriptorDatabase* fallback_database_; + ErrorCollector* default_error_collector_; + const DescriptorPool* underlay_; + + // This class contains a lot of hash maps with complicated types that + // we'd like to keep out of the header. + class Tables; + scoped_ptr tables_; + + bool enforce_dependencies_; + bool allow_unknown_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool); +}; + +// inline methods ==================================================== + +// These macros makes this repetitive code more readable. +#define PROTOBUF_DEFINE_ACCESSOR(CLASS, FIELD, TYPE) \ + inline TYPE CLASS::FIELD() const { return FIELD##_; } + +// Strings fields are stored as pointers but returned as const references. +#define PROTOBUF_DEFINE_STRING_ACCESSOR(CLASS, FIELD) \ + inline const string& CLASS::FIELD() const { return *FIELD##_; } + +// Arrays take an index parameter, obviously. +#define PROTOBUF_DEFINE_ARRAY_ACCESSOR(CLASS, FIELD, TYPE) \ + inline TYPE CLASS::FIELD(int index) const { return FIELD##s_ + index; } + +#define PROTOBUF_DEFINE_OPTIONS_ACCESSOR(CLASS, TYPE) \ + inline const TYPE& CLASS::options() const { return *options_; } + +PROTOBUF_DEFINE_STRING_ACCESSOR(Descriptor, name) +PROTOBUF_DEFINE_STRING_ACCESSOR(Descriptor, full_name) +PROTOBUF_DEFINE_ACCESSOR(Descriptor, file, const FileDescriptor*) +PROTOBUF_DEFINE_ACCESSOR(Descriptor, containing_type, const Descriptor*) + +PROTOBUF_DEFINE_ACCESSOR(Descriptor, field_count, int) +PROTOBUF_DEFINE_ACCESSOR(Descriptor, nested_type_count, int) +PROTOBUF_DEFINE_ACCESSOR(Descriptor, enum_type_count, int) + +PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, field, const FieldDescriptor*) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, nested_type, const Descriptor*) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, enum_type, const EnumDescriptor*) + +PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_range_count, int) +PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_count, int) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension_range, + const Descriptor::ExtensionRange*) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension, + const FieldDescriptor*) +PROTOBUF_DEFINE_OPTIONS_ACCESSOR(Descriptor, MessageOptions); + +PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, name) +PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, full_name) +PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, lowercase_name) +PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, camelcase_name) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, type, FieldDescriptor::Type) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, label, FieldDescriptor::Label) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, experimental_map_key, + const FieldDescriptor*) +PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions); +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32 , int32 ) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64 , int64 ) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32, uint32) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64, uint64) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float , float ) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool , bool ) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_enum, + const EnumValueDescriptor*) +PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string) + +PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, name) +PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, full_name) +PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, file, const FileDescriptor*) +PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, containing_type, const Descriptor*) +PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, value_count, int) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value, + const EnumValueDescriptor*) +PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions); + +PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, name) +PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, full_name) +PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, number, int) +PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, type, const EnumDescriptor*) +PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumValueDescriptor, EnumValueOptions); + +PROTOBUF_DEFINE_STRING_ACCESSOR(ServiceDescriptor, name) +PROTOBUF_DEFINE_STRING_ACCESSOR(ServiceDescriptor, full_name) +PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, file, const FileDescriptor*) +PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, method_count, int) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(ServiceDescriptor, method, + const MethodDescriptor*) +PROTOBUF_DEFINE_OPTIONS_ACCESSOR(ServiceDescriptor, ServiceOptions); + +PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, name) +PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, full_name) +PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, service, const ServiceDescriptor*) +PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, input_type, const Descriptor*) +PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, output_type, const Descriptor*) +PROTOBUF_DEFINE_OPTIONS_ACCESSOR(MethodDescriptor, MethodOptions); + +PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, name) +PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, package) +PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, pool, const DescriptorPool*) +PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, dependency_count, int) +PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, message_type_count, int) +PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, enum_type_count, int) +PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, service_count, int) +PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, extension_count, int) +PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FileDescriptor, FileOptions); + +PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, message_type, const Descriptor*) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, enum_type, const EnumDescriptor*) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, service, + const ServiceDescriptor*) +PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, extension, + const FieldDescriptor*) + +#undef PROTOBUF_DEFINE_ACCESSOR +#undef PROTOBUF_DEFINE_STRING_ACCESSOR +#undef PROTOBUF_DEFINE_ARRAY_ACCESSOR + +// A few accessors differ from the macros... + +inline bool FieldDescriptor::is_required() const { + return label() == LABEL_REQUIRED; +} + +inline bool FieldDescriptor::is_optional() const { + return label() == LABEL_OPTIONAL; +} + +inline bool FieldDescriptor::is_repeated() const { + return label() == LABEL_REPEATED; +} + +inline bool FieldDescriptor::is_packable() const { + return is_repeated() && IsTypePackable(type()); +} + +// To save space, index() is computed by looking at the descriptor's position +// in the parent's array of children. +inline int FieldDescriptor::index() const { + if (!is_extension_) { + return this - containing_type_->fields_; + } else if (extension_scope_ != NULL) { + return this - extension_scope_->extensions_; + } else { + return this - file_->extensions_; + } +} + +inline int Descriptor::index() const { + if (containing_type_ == NULL) { + return this - file_->message_types_; + } else { + return this - containing_type_->nested_types_; + } +} + +inline int EnumDescriptor::index() const { + if (containing_type_ == NULL) { + return this - file_->enum_types_; + } else { + return this - containing_type_->enum_types_; + } +} + +inline int EnumValueDescriptor::index() const { + return this - type_->values_; +} + +inline int ServiceDescriptor::index() const { + return this - file_->services_; +} + +inline int MethodDescriptor::index() const { + return this - service_->methods_; +} + +inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const { + return kTypeToCppTypeMap[type_]; +} + +inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) { + return kTypeToCppTypeMap[type]; +} + +inline bool FieldDescriptor::IsTypePackable(Type field_type) { + return (field_type != FieldDescriptor::TYPE_STRING && + field_type != FieldDescriptor::TYPE_GROUP && + field_type != FieldDescriptor::TYPE_MESSAGE && + field_type != FieldDescriptor::TYPE_BYTES); +} + +inline const FileDescriptor* FileDescriptor::dependency(int index) const { + return dependencies_[index]; +} + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_DESCRIPTOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h new file mode 100644 index 00000000..95febb81 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h @@ -0,0 +1,5223 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/descriptor.proto + +#ifndef PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace google { +namespace protobuf { + +// Internal implementation detail -- do not call these. +void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + +class FileDescriptorSet; +class FileDescriptorProto; +class DescriptorProto; +class DescriptorProto_ExtensionRange; +class FieldDescriptorProto; +class EnumDescriptorProto; +class EnumValueDescriptorProto; +class ServiceDescriptorProto; +class MethodDescriptorProto; +class FileOptions; +class MessageOptions; +class FieldOptions; +class EnumOptions; +class EnumValueOptions; +class ServiceOptions; +class MethodOptions; +class UninterpretedOption; +class UninterpretedOption_NamePart; +class SourceCodeInfo; +class SourceCodeInfo_Location; + +enum FieldDescriptorProto_Type { + FieldDescriptorProto_Type_TYPE_DOUBLE = 1, + FieldDescriptorProto_Type_TYPE_FLOAT = 2, + FieldDescriptorProto_Type_TYPE_INT64 = 3, + FieldDescriptorProto_Type_TYPE_UINT64 = 4, + FieldDescriptorProto_Type_TYPE_INT32 = 5, + FieldDescriptorProto_Type_TYPE_FIXED64 = 6, + FieldDescriptorProto_Type_TYPE_FIXED32 = 7, + FieldDescriptorProto_Type_TYPE_BOOL = 8, + FieldDescriptorProto_Type_TYPE_STRING = 9, + FieldDescriptorProto_Type_TYPE_GROUP = 10, + FieldDescriptorProto_Type_TYPE_MESSAGE = 11, + FieldDescriptorProto_Type_TYPE_BYTES = 12, + FieldDescriptorProto_Type_TYPE_UINT32 = 13, + FieldDescriptorProto_Type_TYPE_ENUM = 14, + FieldDescriptorProto_Type_TYPE_SFIXED32 = 15, + FieldDescriptorProto_Type_TYPE_SFIXED64 = 16, + FieldDescriptorProto_Type_TYPE_SINT32 = 17, + FieldDescriptorProto_Type_TYPE_SINT64 = 18 +}; +LIBPROTOBUF_EXPORT bool FieldDescriptorProto_Type_IsValid(int value); +const FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MIN = FieldDescriptorProto_Type_TYPE_DOUBLE; +const FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MAX = FieldDescriptorProto_Type_TYPE_SINT64; +const int FieldDescriptorProto_Type_Type_ARRAYSIZE = FieldDescriptorProto_Type_Type_MAX + 1; + +LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Type_descriptor(); +inline const ::std::string& FieldDescriptorProto_Type_Name(FieldDescriptorProto_Type value) { + return ::google::protobuf::internal::NameOfEnum( + FieldDescriptorProto_Type_descriptor(), value); +} +inline bool FieldDescriptorProto_Type_Parse( + const ::std::string& name, FieldDescriptorProto_Type* value) { + return ::google::protobuf::internal::ParseNamedEnum( + FieldDescriptorProto_Type_descriptor(), name, value); +} +enum FieldDescriptorProto_Label { + FieldDescriptorProto_Label_LABEL_OPTIONAL = 1, + FieldDescriptorProto_Label_LABEL_REQUIRED = 2, + FieldDescriptorProto_Label_LABEL_REPEATED = 3 +}; +LIBPROTOBUF_EXPORT bool FieldDescriptorProto_Label_IsValid(int value); +const FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MIN = FieldDescriptorProto_Label_LABEL_OPTIONAL; +const FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MAX = FieldDescriptorProto_Label_LABEL_REPEATED; +const int FieldDescriptorProto_Label_Label_ARRAYSIZE = FieldDescriptorProto_Label_Label_MAX + 1; + +LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Label_descriptor(); +inline const ::std::string& FieldDescriptorProto_Label_Name(FieldDescriptorProto_Label value) { + return ::google::protobuf::internal::NameOfEnum( + FieldDescriptorProto_Label_descriptor(), value); +} +inline bool FieldDescriptorProto_Label_Parse( + const ::std::string& name, FieldDescriptorProto_Label* value) { + return ::google::protobuf::internal::ParseNamedEnum( + FieldDescriptorProto_Label_descriptor(), name, value); +} +enum FileOptions_OptimizeMode { + FileOptions_OptimizeMode_SPEED = 1, + FileOptions_OptimizeMode_CODE_SIZE = 2, + FileOptions_OptimizeMode_LITE_RUNTIME = 3 +}; +LIBPROTOBUF_EXPORT bool FileOptions_OptimizeMode_IsValid(int value); +const FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MIN = FileOptions_OptimizeMode_SPEED; +const FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MAX = FileOptions_OptimizeMode_LITE_RUNTIME; +const int FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE = FileOptions_OptimizeMode_OptimizeMode_MAX + 1; + +LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FileOptions_OptimizeMode_descriptor(); +inline const ::std::string& FileOptions_OptimizeMode_Name(FileOptions_OptimizeMode value) { + return ::google::protobuf::internal::NameOfEnum( + FileOptions_OptimizeMode_descriptor(), value); +} +inline bool FileOptions_OptimizeMode_Parse( + const ::std::string& name, FileOptions_OptimizeMode* value) { + return ::google::protobuf::internal::ParseNamedEnum( + FileOptions_OptimizeMode_descriptor(), name, value); +} +enum FieldOptions_CType { + FieldOptions_CType_STRING = 0, + FieldOptions_CType_CORD = 1, + FieldOptions_CType_STRING_PIECE = 2 +}; +LIBPROTOBUF_EXPORT bool FieldOptions_CType_IsValid(int value); +const FieldOptions_CType FieldOptions_CType_CType_MIN = FieldOptions_CType_STRING; +const FieldOptions_CType FieldOptions_CType_CType_MAX = FieldOptions_CType_STRING_PIECE; +const int FieldOptions_CType_CType_ARRAYSIZE = FieldOptions_CType_CType_MAX + 1; + +LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldOptions_CType_descriptor(); +inline const ::std::string& FieldOptions_CType_Name(FieldOptions_CType value) { + return ::google::protobuf::internal::NameOfEnum( + FieldOptions_CType_descriptor(), value); +} +inline bool FieldOptions_CType_Parse( + const ::std::string& name, FieldOptions_CType* value) { + return ::google::protobuf::internal::ParseNamedEnum( + FieldOptions_CType_descriptor(), name, value); +} +// =================================================================== + +class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message { + public: + FileDescriptorSet(); + virtual ~FileDescriptorSet(); + + FileDescriptorSet(const FileDescriptorSet& from); + + inline FileDescriptorSet& operator=(const FileDescriptorSet& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FileDescriptorSet& default_instance(); + + void Swap(FileDescriptorSet* other); + + // implements Message ---------------------------------------------- + + FileDescriptorSet* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const FileDescriptorSet& from); + void MergeFrom(const FileDescriptorSet& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.FileDescriptorProto file = 1; + inline int file_size() const; + inline void clear_file(); + static const int kFileFieldNumber = 1; + inline const ::google::protobuf::FileDescriptorProto& file(int index) const; + inline ::google::protobuf::FileDescriptorProto* mutable_file(int index); + inline ::google::protobuf::FileDescriptorProto* add_file(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& + file() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* + mutable_file(); + + // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorSet) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > file_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static FileDescriptorSet* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Message { + public: + FileDescriptorProto(); + virtual ~FileDescriptorProto(); + + FileDescriptorProto(const FileDescriptorProto& from); + + inline FileDescriptorProto& operator=(const FileDescriptorProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FileDescriptorProto& default_instance(); + + void Swap(FileDescriptorProto* other); + + // implements Message ---------------------------------------------- + + FileDescriptorProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const FileDescriptorProto& from); + void MergeFrom(const FileDescriptorProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // optional string package = 2; + inline bool has_package() const; + inline void clear_package(); + static const int kPackageFieldNumber = 2; + inline const ::std::string& package() const; + inline void set_package(const ::std::string& value); + inline void set_package(const char* value); + inline void set_package(const char* value, size_t size); + inline ::std::string* mutable_package(); + inline ::std::string* release_package(); + + // repeated string dependency = 3; + inline int dependency_size() const; + inline void clear_dependency(); + static const int kDependencyFieldNumber = 3; + inline const ::std::string& dependency(int index) const; + inline ::std::string* mutable_dependency(int index); + inline void set_dependency(int index, const ::std::string& value); + inline void set_dependency(int index, const char* value); + inline void set_dependency(int index, const char* value, size_t size); + inline ::std::string* add_dependency(); + inline void add_dependency(const ::std::string& value); + inline void add_dependency(const char* value); + inline void add_dependency(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& dependency() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_dependency(); + + // repeated .google.protobuf.DescriptorProto message_type = 4; + inline int message_type_size() const; + inline void clear_message_type(); + static const int kMessageTypeFieldNumber = 4; + inline const ::google::protobuf::DescriptorProto& message_type(int index) const; + inline ::google::protobuf::DescriptorProto* mutable_message_type(int index); + inline ::google::protobuf::DescriptorProto* add_message_type(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& + message_type() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* + mutable_message_type(); + + // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; + inline int enum_type_size() const; + inline void clear_enum_type(); + static const int kEnumTypeFieldNumber = 5; + inline const ::google::protobuf::EnumDescriptorProto& enum_type(int index) const; + inline ::google::protobuf::EnumDescriptorProto* mutable_enum_type(int index); + inline ::google::protobuf::EnumDescriptorProto* add_enum_type(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& + enum_type() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* + mutable_enum_type(); + + // repeated .google.protobuf.ServiceDescriptorProto service = 6; + inline int service_size() const; + inline void clear_service(); + static const int kServiceFieldNumber = 6; + inline const ::google::protobuf::ServiceDescriptorProto& service(int index) const; + inline ::google::protobuf::ServiceDescriptorProto* mutable_service(int index); + inline ::google::protobuf::ServiceDescriptorProto* add_service(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >& + service() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >* + mutable_service(); + + // repeated .google.protobuf.FieldDescriptorProto extension = 7; + inline int extension_size() const; + inline void clear_extension(); + static const int kExtensionFieldNumber = 7; + inline const ::google::protobuf::FieldDescriptorProto& extension(int index) const; + inline ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); + inline ::google::protobuf::FieldDescriptorProto* add_extension(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& + extension() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* + mutable_extension(); + + // optional .google.protobuf.FileOptions options = 8; + inline bool has_options() const; + inline void clear_options(); + static const int kOptionsFieldNumber = 8; + inline const ::google::protobuf::FileOptions& options() const; + inline ::google::protobuf::FileOptions* mutable_options(); + inline ::google::protobuf::FileOptions* release_options(); + + // optional .google.protobuf.SourceCodeInfo source_code_info = 9; + inline bool has_source_code_info() const; + inline void clear_source_code_info(); + static const int kSourceCodeInfoFieldNumber = 9; + inline const ::google::protobuf::SourceCodeInfo& source_code_info() const; + inline ::google::protobuf::SourceCodeInfo* mutable_source_code_info(); + inline ::google::protobuf::SourceCodeInfo* release_source_code_info(); + + // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorProto) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_package(); + inline void clear_has_package(); + inline void set_has_options(); + inline void clear_has_options(); + inline void set_has_source_code_info(); + inline void clear_has_source_code_info(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::std::string* package_; + ::google::protobuf::RepeatedPtrField< ::std::string> dependency_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > message_type_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto > service_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; + ::google::protobuf::FileOptions* options_; + ::google::protobuf::SourceCodeInfo* source_code_info_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(9 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static FileDescriptorProto* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::protobuf::Message { + public: + DescriptorProto_ExtensionRange(); + virtual ~DescriptorProto_ExtensionRange(); + + DescriptorProto_ExtensionRange(const DescriptorProto_ExtensionRange& from); + + inline DescriptorProto_ExtensionRange& operator=(const DescriptorProto_ExtensionRange& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const DescriptorProto_ExtensionRange& default_instance(); + + void Swap(DescriptorProto_ExtensionRange* other); + + // implements Message ---------------------------------------------- + + DescriptorProto_ExtensionRange* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const DescriptorProto_ExtensionRange& from); + void MergeFrom(const DescriptorProto_ExtensionRange& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 start = 1; + inline bool has_start() const; + inline void clear_start(); + static const int kStartFieldNumber = 1; + inline ::google::protobuf::int32 start() const; + inline void set_start(::google::protobuf::int32 value); + + // optional int32 end = 2; + inline bool has_end() const; + inline void clear_end(); + static const int kEndFieldNumber = 2; + inline ::google::protobuf::int32 end() const; + inline void set_end(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto.ExtensionRange) + private: + inline void set_has_start(); + inline void clear_has_start(); + inline void set_has_end(); + inline void clear_has_end(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 start_; + ::google::protobuf::int32 end_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static DescriptorProto_ExtensionRange* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message { + public: + DescriptorProto(); + virtual ~DescriptorProto(); + + DescriptorProto(const DescriptorProto& from); + + inline DescriptorProto& operator=(const DescriptorProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const DescriptorProto& default_instance(); + + void Swap(DescriptorProto* other); + + // implements Message ---------------------------------------------- + + DescriptorProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const DescriptorProto& from); + void MergeFrom(const DescriptorProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef DescriptorProto_ExtensionRange ExtensionRange; + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // repeated .google.protobuf.FieldDescriptorProto field = 2; + inline int field_size() const; + inline void clear_field(); + static const int kFieldFieldNumber = 2; + inline const ::google::protobuf::FieldDescriptorProto& field(int index) const; + inline ::google::protobuf::FieldDescriptorProto* mutable_field(int index); + inline ::google::protobuf::FieldDescriptorProto* add_field(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& + field() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* + mutable_field(); + + // repeated .google.protobuf.FieldDescriptorProto extension = 6; + inline int extension_size() const; + inline void clear_extension(); + static const int kExtensionFieldNumber = 6; + inline const ::google::protobuf::FieldDescriptorProto& extension(int index) const; + inline ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); + inline ::google::protobuf::FieldDescriptorProto* add_extension(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& + extension() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* + mutable_extension(); + + // repeated .google.protobuf.DescriptorProto nested_type = 3; + inline int nested_type_size() const; + inline void clear_nested_type(); + static const int kNestedTypeFieldNumber = 3; + inline const ::google::protobuf::DescriptorProto& nested_type(int index) const; + inline ::google::protobuf::DescriptorProto* mutable_nested_type(int index); + inline ::google::protobuf::DescriptorProto* add_nested_type(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& + nested_type() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* + mutable_nested_type(); + + // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; + inline int enum_type_size() const; + inline void clear_enum_type(); + static const int kEnumTypeFieldNumber = 4; + inline const ::google::protobuf::EnumDescriptorProto& enum_type(int index) const; + inline ::google::protobuf::EnumDescriptorProto* mutable_enum_type(int index); + inline ::google::protobuf::EnumDescriptorProto* add_enum_type(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& + enum_type() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* + mutable_enum_type(); + + // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; + inline int extension_range_size() const; + inline void clear_extension_range(); + static const int kExtensionRangeFieldNumber = 5; + inline const ::google::protobuf::DescriptorProto_ExtensionRange& extension_range(int index) const; + inline ::google::protobuf::DescriptorProto_ExtensionRange* mutable_extension_range(int index); + inline ::google::protobuf::DescriptorProto_ExtensionRange* add_extension_range(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >& + extension_range() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >* + mutable_extension_range(); + + // optional .google.protobuf.MessageOptions options = 7; + inline bool has_options() const; + inline void clear_options(); + static const int kOptionsFieldNumber = 7; + inline const ::google::protobuf::MessageOptions& options() const; + inline ::google::protobuf::MessageOptions* mutable_options(); + inline ::google::protobuf::MessageOptions* release_options(); + + // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_options(); + inline void clear_has_options(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > field_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > nested_type_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange > extension_range_; + ::google::protobuf::MessageOptions* options_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(7 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static DescriptorProto* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Message { + public: + FieldDescriptorProto(); + virtual ~FieldDescriptorProto(); + + FieldDescriptorProto(const FieldDescriptorProto& from); + + inline FieldDescriptorProto& operator=(const FieldDescriptorProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FieldDescriptorProto& default_instance(); + + void Swap(FieldDescriptorProto* other); + + // implements Message ---------------------------------------------- + + FieldDescriptorProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const FieldDescriptorProto& from); + void MergeFrom(const FieldDescriptorProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef FieldDescriptorProto_Type Type; + static const Type TYPE_DOUBLE = FieldDescriptorProto_Type_TYPE_DOUBLE; + static const Type TYPE_FLOAT = FieldDescriptorProto_Type_TYPE_FLOAT; + static const Type TYPE_INT64 = FieldDescriptorProto_Type_TYPE_INT64; + static const Type TYPE_UINT64 = FieldDescriptorProto_Type_TYPE_UINT64; + static const Type TYPE_INT32 = FieldDescriptorProto_Type_TYPE_INT32; + static const Type TYPE_FIXED64 = FieldDescriptorProto_Type_TYPE_FIXED64; + static const Type TYPE_FIXED32 = FieldDescriptorProto_Type_TYPE_FIXED32; + static const Type TYPE_BOOL = FieldDescriptorProto_Type_TYPE_BOOL; + static const Type TYPE_STRING = FieldDescriptorProto_Type_TYPE_STRING; + static const Type TYPE_GROUP = FieldDescriptorProto_Type_TYPE_GROUP; + static const Type TYPE_MESSAGE = FieldDescriptorProto_Type_TYPE_MESSAGE; + static const Type TYPE_BYTES = FieldDescriptorProto_Type_TYPE_BYTES; + static const Type TYPE_UINT32 = FieldDescriptorProto_Type_TYPE_UINT32; + static const Type TYPE_ENUM = FieldDescriptorProto_Type_TYPE_ENUM; + static const Type TYPE_SFIXED32 = FieldDescriptorProto_Type_TYPE_SFIXED32; + static const Type TYPE_SFIXED64 = FieldDescriptorProto_Type_TYPE_SFIXED64; + static const Type TYPE_SINT32 = FieldDescriptorProto_Type_TYPE_SINT32; + static const Type TYPE_SINT64 = FieldDescriptorProto_Type_TYPE_SINT64; + static inline bool Type_IsValid(int value) { + return FieldDescriptorProto_Type_IsValid(value); + } + static const Type Type_MIN = + FieldDescriptorProto_Type_Type_MIN; + static const Type Type_MAX = + FieldDescriptorProto_Type_Type_MAX; + static const int Type_ARRAYSIZE = + FieldDescriptorProto_Type_Type_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + Type_descriptor() { + return FieldDescriptorProto_Type_descriptor(); + } + static inline const ::std::string& Type_Name(Type value) { + return FieldDescriptorProto_Type_Name(value); + } + static inline bool Type_Parse(const ::std::string& name, + Type* value) { + return FieldDescriptorProto_Type_Parse(name, value); + } + + typedef FieldDescriptorProto_Label Label; + static const Label LABEL_OPTIONAL = FieldDescriptorProto_Label_LABEL_OPTIONAL; + static const Label LABEL_REQUIRED = FieldDescriptorProto_Label_LABEL_REQUIRED; + static const Label LABEL_REPEATED = FieldDescriptorProto_Label_LABEL_REPEATED; + static inline bool Label_IsValid(int value) { + return FieldDescriptorProto_Label_IsValid(value); + } + static const Label Label_MIN = + FieldDescriptorProto_Label_Label_MIN; + static const Label Label_MAX = + FieldDescriptorProto_Label_Label_MAX; + static const int Label_ARRAYSIZE = + FieldDescriptorProto_Label_Label_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + Label_descriptor() { + return FieldDescriptorProto_Label_descriptor(); + } + static inline const ::std::string& Label_Name(Label value) { + return FieldDescriptorProto_Label_Name(value); + } + static inline bool Label_Parse(const ::std::string& name, + Label* value) { + return FieldDescriptorProto_Label_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // optional int32 number = 3; + inline bool has_number() const; + inline void clear_number(); + static const int kNumberFieldNumber = 3; + inline ::google::protobuf::int32 number() const; + inline void set_number(::google::protobuf::int32 value); + + // optional .google.protobuf.FieldDescriptorProto.Label label = 4; + inline bool has_label() const; + inline void clear_label(); + static const int kLabelFieldNumber = 4; + inline ::google::protobuf::FieldDescriptorProto_Label label() const; + inline void set_label(::google::protobuf::FieldDescriptorProto_Label value); + + // optional .google.protobuf.FieldDescriptorProto.Type type = 5; + inline bool has_type() const; + inline void clear_type(); + static const int kTypeFieldNumber = 5; + inline ::google::protobuf::FieldDescriptorProto_Type type() const; + inline void set_type(::google::protobuf::FieldDescriptorProto_Type value); + + // optional string type_name = 6; + inline bool has_type_name() const; + inline void clear_type_name(); + static const int kTypeNameFieldNumber = 6; + inline const ::std::string& type_name() const; + inline void set_type_name(const ::std::string& value); + inline void set_type_name(const char* value); + inline void set_type_name(const char* value, size_t size); + inline ::std::string* mutable_type_name(); + inline ::std::string* release_type_name(); + + // optional string extendee = 2; + inline bool has_extendee() const; + inline void clear_extendee(); + static const int kExtendeeFieldNumber = 2; + inline const ::std::string& extendee() const; + inline void set_extendee(const ::std::string& value); + inline void set_extendee(const char* value); + inline void set_extendee(const char* value, size_t size); + inline ::std::string* mutable_extendee(); + inline ::std::string* release_extendee(); + + // optional string default_value = 7; + inline bool has_default_value() const; + inline void clear_default_value(); + static const int kDefaultValueFieldNumber = 7; + inline const ::std::string& default_value() const; + inline void set_default_value(const ::std::string& value); + inline void set_default_value(const char* value); + inline void set_default_value(const char* value, size_t size); + inline ::std::string* mutable_default_value(); + inline ::std::string* release_default_value(); + + // optional .google.protobuf.FieldOptions options = 8; + inline bool has_options() const; + inline void clear_options(); + static const int kOptionsFieldNumber = 8; + inline const ::google::protobuf::FieldOptions& options() const; + inline ::google::protobuf::FieldOptions* mutable_options(); + inline ::google::protobuf::FieldOptions* release_options(); + + // @@protoc_insertion_point(class_scope:google.protobuf.FieldDescriptorProto) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_number(); + inline void clear_has_number(); + inline void set_has_label(); + inline void clear_has_label(); + inline void set_has_type(); + inline void clear_has_type(); + inline void set_has_type_name(); + inline void clear_has_type_name(); + inline void set_has_extendee(); + inline void clear_has_extendee(); + inline void set_has_default_value(); + inline void clear_has_default_value(); + inline void set_has_options(); + inline void clear_has_options(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::google::protobuf::int32 number_; + int label_; + ::std::string* type_name_; + ::std::string* extendee_; + ::std::string* default_value_; + ::google::protobuf::FieldOptions* options_; + int type_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(8 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static FieldDescriptorProto* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Message { + public: + EnumDescriptorProto(); + virtual ~EnumDescriptorProto(); + + EnumDescriptorProto(const EnumDescriptorProto& from); + + inline EnumDescriptorProto& operator=(const EnumDescriptorProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const EnumDescriptorProto& default_instance(); + + void Swap(EnumDescriptorProto* other); + + // implements Message ---------------------------------------------- + + EnumDescriptorProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const EnumDescriptorProto& from); + void MergeFrom(const EnumDescriptorProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // repeated .google.protobuf.EnumValueDescriptorProto value = 2; + inline int value_size() const; + inline void clear_value(); + static const int kValueFieldNumber = 2; + inline const ::google::protobuf::EnumValueDescriptorProto& value(int index) const; + inline ::google::protobuf::EnumValueDescriptorProto* mutable_value(int index); + inline ::google::protobuf::EnumValueDescriptorProto* add_value(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >& + value() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >* + mutable_value(); + + // optional .google.protobuf.EnumOptions options = 3; + inline bool has_options() const; + inline void clear_options(); + static const int kOptionsFieldNumber = 3; + inline const ::google::protobuf::EnumOptions& options() const; + inline ::google::protobuf::EnumOptions* mutable_options(); + inline ::google::protobuf::EnumOptions* release_options(); + + // @@protoc_insertion_point(class_scope:google.protobuf.EnumDescriptorProto) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_options(); + inline void clear_has_options(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto > value_; + ::google::protobuf::EnumOptions* options_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static EnumDescriptorProto* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::Message { + public: + EnumValueDescriptorProto(); + virtual ~EnumValueDescriptorProto(); + + EnumValueDescriptorProto(const EnumValueDescriptorProto& from); + + inline EnumValueDescriptorProto& operator=(const EnumValueDescriptorProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const EnumValueDescriptorProto& default_instance(); + + void Swap(EnumValueDescriptorProto* other); + + // implements Message ---------------------------------------------- + + EnumValueDescriptorProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const EnumValueDescriptorProto& from); + void MergeFrom(const EnumValueDescriptorProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // optional int32 number = 2; + inline bool has_number() const; + inline void clear_number(); + static const int kNumberFieldNumber = 2; + inline ::google::protobuf::int32 number() const; + inline void set_number(::google::protobuf::int32 value); + + // optional .google.protobuf.EnumValueOptions options = 3; + inline bool has_options() const; + inline void clear_options(); + static const int kOptionsFieldNumber = 3; + inline const ::google::protobuf::EnumValueOptions& options() const; + inline ::google::protobuf::EnumValueOptions* mutable_options(); + inline ::google::protobuf::EnumValueOptions* release_options(); + + // @@protoc_insertion_point(class_scope:google.protobuf.EnumValueDescriptorProto) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_number(); + inline void clear_has_number(); + inline void set_has_options(); + inline void clear_has_options(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::google::protobuf::EnumValueOptions* options_; + ::google::protobuf::int32 number_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static EnumValueDescriptorProto* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Message { + public: + ServiceDescriptorProto(); + virtual ~ServiceDescriptorProto(); + + ServiceDescriptorProto(const ServiceDescriptorProto& from); + + inline ServiceDescriptorProto& operator=(const ServiceDescriptorProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ServiceDescriptorProto& default_instance(); + + void Swap(ServiceDescriptorProto* other); + + // implements Message ---------------------------------------------- + + ServiceDescriptorProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ServiceDescriptorProto& from); + void MergeFrom(const ServiceDescriptorProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // repeated .google.protobuf.MethodDescriptorProto method = 2; + inline int method_size() const; + inline void clear_method(); + static const int kMethodFieldNumber = 2; + inline const ::google::protobuf::MethodDescriptorProto& method(int index) const; + inline ::google::protobuf::MethodDescriptorProto* mutable_method(int index); + inline ::google::protobuf::MethodDescriptorProto* add_method(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >& + method() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >* + mutable_method(); + + // optional .google.protobuf.ServiceOptions options = 3; + inline bool has_options() const; + inline void clear_options(); + static const int kOptionsFieldNumber = 3; + inline const ::google::protobuf::ServiceOptions& options() const; + inline ::google::protobuf::ServiceOptions* mutable_options(); + inline ::google::protobuf::ServiceOptions* release_options(); + + // @@protoc_insertion_point(class_scope:google.protobuf.ServiceDescriptorProto) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_options(); + inline void clear_has_options(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto > method_; + ::google::protobuf::ServiceOptions* options_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static ServiceDescriptorProto* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Message { + public: + MethodDescriptorProto(); + virtual ~MethodDescriptorProto(); + + MethodDescriptorProto(const MethodDescriptorProto& from); + + inline MethodDescriptorProto& operator=(const MethodDescriptorProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const MethodDescriptorProto& default_instance(); + + void Swap(MethodDescriptorProto* other); + + // implements Message ---------------------------------------------- + + MethodDescriptorProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const MethodDescriptorProto& from); + void MergeFrom(const MethodDescriptorProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline bool has_name() const; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + + // optional string input_type = 2; + inline bool has_input_type() const; + inline void clear_input_type(); + static const int kInputTypeFieldNumber = 2; + inline const ::std::string& input_type() const; + inline void set_input_type(const ::std::string& value); + inline void set_input_type(const char* value); + inline void set_input_type(const char* value, size_t size); + inline ::std::string* mutable_input_type(); + inline ::std::string* release_input_type(); + + // optional string output_type = 3; + inline bool has_output_type() const; + inline void clear_output_type(); + static const int kOutputTypeFieldNumber = 3; + inline const ::std::string& output_type() const; + inline void set_output_type(const ::std::string& value); + inline void set_output_type(const char* value); + inline void set_output_type(const char* value, size_t size); + inline ::std::string* mutable_output_type(); + inline ::std::string* release_output_type(); + + // optional .google.protobuf.MethodOptions options = 4; + inline bool has_options() const; + inline void clear_options(); + static const int kOptionsFieldNumber = 4; + inline const ::google::protobuf::MethodOptions& options() const; + inline ::google::protobuf::MethodOptions* mutable_options(); + inline ::google::protobuf::MethodOptions* release_options(); + + // @@protoc_insertion_point(class_scope:google.protobuf.MethodDescriptorProto) + private: + inline void set_has_name(); + inline void clear_has_name(); + inline void set_has_input_type(); + inline void clear_has_input_type(); + inline void set_has_output_type(); + inline void clear_has_output_type(); + inline void set_has_options(); + inline void clear_has_options(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_; + ::std::string* input_type_; + ::std::string* output_type_; + ::google::protobuf::MethodOptions* options_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(4 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static MethodDescriptorProto* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message { + public: + FileOptions(); + virtual ~FileOptions(); + + FileOptions(const FileOptions& from); + + inline FileOptions& operator=(const FileOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FileOptions& default_instance(); + + void Swap(FileOptions* other); + + // implements Message ---------------------------------------------- + + FileOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const FileOptions& from); + void MergeFrom(const FileOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef FileOptions_OptimizeMode OptimizeMode; + static const OptimizeMode SPEED = FileOptions_OptimizeMode_SPEED; + static const OptimizeMode CODE_SIZE = FileOptions_OptimizeMode_CODE_SIZE; + static const OptimizeMode LITE_RUNTIME = FileOptions_OptimizeMode_LITE_RUNTIME; + static inline bool OptimizeMode_IsValid(int value) { + return FileOptions_OptimizeMode_IsValid(value); + } + static const OptimizeMode OptimizeMode_MIN = + FileOptions_OptimizeMode_OptimizeMode_MIN; + static const OptimizeMode OptimizeMode_MAX = + FileOptions_OptimizeMode_OptimizeMode_MAX; + static const int OptimizeMode_ARRAYSIZE = + FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + OptimizeMode_descriptor() { + return FileOptions_OptimizeMode_descriptor(); + } + static inline const ::std::string& OptimizeMode_Name(OptimizeMode value) { + return FileOptions_OptimizeMode_Name(value); + } + static inline bool OptimizeMode_Parse(const ::std::string& name, + OptimizeMode* value) { + return FileOptions_OptimizeMode_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // optional string java_package = 1; + inline bool has_java_package() const; + inline void clear_java_package(); + static const int kJavaPackageFieldNumber = 1; + inline const ::std::string& java_package() const; + inline void set_java_package(const ::std::string& value); + inline void set_java_package(const char* value); + inline void set_java_package(const char* value, size_t size); + inline ::std::string* mutable_java_package(); + inline ::std::string* release_java_package(); + + // optional string java_outer_classname = 8; + inline bool has_java_outer_classname() const; + inline void clear_java_outer_classname(); + static const int kJavaOuterClassnameFieldNumber = 8; + inline const ::std::string& java_outer_classname() const; + inline void set_java_outer_classname(const ::std::string& value); + inline void set_java_outer_classname(const char* value); + inline void set_java_outer_classname(const char* value, size_t size); + inline ::std::string* mutable_java_outer_classname(); + inline ::std::string* release_java_outer_classname(); + + // optional bool java_multiple_files = 10 [default = false]; + inline bool has_java_multiple_files() const; + inline void clear_java_multiple_files(); + static const int kJavaMultipleFilesFieldNumber = 10; + inline bool java_multiple_files() const; + inline void set_java_multiple_files(bool value); + + // optional bool java_generate_equals_and_hash = 20 [default = false]; + inline bool has_java_generate_equals_and_hash() const; + inline void clear_java_generate_equals_and_hash(); + static const int kJavaGenerateEqualsAndHashFieldNumber = 20; + inline bool java_generate_equals_and_hash() const; + inline void set_java_generate_equals_and_hash(bool value); + + // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + inline bool has_optimize_for() const; + inline void clear_optimize_for(); + static const int kOptimizeForFieldNumber = 9; + inline ::google::protobuf::FileOptions_OptimizeMode optimize_for() const; + inline void set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value); + + // optional bool cc_generic_services = 16 [default = false]; + inline bool has_cc_generic_services() const; + inline void clear_cc_generic_services(); + static const int kCcGenericServicesFieldNumber = 16; + inline bool cc_generic_services() const; + inline void set_cc_generic_services(bool value); + + // optional bool java_generic_services = 17 [default = false]; + inline bool has_java_generic_services() const; + inline void clear_java_generic_services(); + static const int kJavaGenericServicesFieldNumber = 17; + inline bool java_generic_services() const; + inline void set_java_generic_services(bool value); + + // optional bool py_generic_services = 18 [default = false]; + inline bool has_py_generic_services() const; + inline void clear_py_generic_services(); + static const int kPyGenericServicesFieldNumber = 18; + inline bool py_generic_services() const; + inline void set_py_generic_services(bool value); + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + inline int uninterpreted_option_size() const; + inline void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FileOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.FileOptions) + private: + inline void set_has_java_package(); + inline void clear_has_java_package(); + inline void set_has_java_outer_classname(); + inline void clear_has_java_outer_classname(); + inline void set_has_java_multiple_files(); + inline void clear_has_java_multiple_files(); + inline void set_has_java_generate_equals_and_hash(); + inline void clear_has_java_generate_equals_and_hash(); + inline void set_has_optimize_for(); + inline void clear_has_optimize_for(); + inline void set_has_cc_generic_services(); + inline void clear_has_cc_generic_services(); + inline void set_has_java_generic_services(); + inline void clear_has_java_generic_services(); + inline void set_has_py_generic_services(); + inline void clear_has_py_generic_services(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* java_package_; + ::std::string* java_outer_classname_; + int optimize_for_; + bool java_multiple_files_; + bool java_generate_equals_and_hash_; + bool cc_generic_services_; + bool java_generic_services_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + bool py_generic_services_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(9 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static FileOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message { + public: + MessageOptions(); + virtual ~MessageOptions(); + + MessageOptions(const MessageOptions& from); + + inline MessageOptions& operator=(const MessageOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const MessageOptions& default_instance(); + + void Swap(MessageOptions* other); + + // implements Message ---------------------------------------------- + + MessageOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const MessageOptions& from); + void MergeFrom(const MessageOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional bool message_set_wire_format = 1 [default = false]; + inline bool has_message_set_wire_format() const; + inline void clear_message_set_wire_format(); + static const int kMessageSetWireFormatFieldNumber = 1; + inline bool message_set_wire_format() const; + inline void set_message_set_wire_format(bool value); + + // optional bool no_standard_descriptor_accessor = 2 [default = false]; + inline bool has_no_standard_descriptor_accessor() const; + inline void clear_no_standard_descriptor_accessor(); + static const int kNoStandardDescriptorAccessorFieldNumber = 2; + inline bool no_standard_descriptor_accessor() const; + inline void set_no_standard_descriptor_accessor(bool value); + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + inline int uninterpreted_option_size() const; + inline void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MessageOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.MessageOptions) + private: + inline void set_has_message_set_wire_format(); + inline void clear_has_message_set_wire_format(); + inline void set_has_no_standard_descriptor_accessor(); + inline void clear_has_no_standard_descriptor_accessor(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + bool message_set_wire_format_; + bool no_standard_descriptor_accessor_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static MessageOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message { + public: + FieldOptions(); + virtual ~FieldOptions(); + + FieldOptions(const FieldOptions& from); + + inline FieldOptions& operator=(const FieldOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FieldOptions& default_instance(); + + void Swap(FieldOptions* other); + + // implements Message ---------------------------------------------- + + FieldOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const FieldOptions& from); + void MergeFrom(const FieldOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef FieldOptions_CType CType; + static const CType STRING = FieldOptions_CType_STRING; + static const CType CORD = FieldOptions_CType_CORD; + static const CType STRING_PIECE = FieldOptions_CType_STRING_PIECE; + static inline bool CType_IsValid(int value) { + return FieldOptions_CType_IsValid(value); + } + static const CType CType_MIN = + FieldOptions_CType_CType_MIN; + static const CType CType_MAX = + FieldOptions_CType_CType_MAX; + static const int CType_ARRAYSIZE = + FieldOptions_CType_CType_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + CType_descriptor() { + return FieldOptions_CType_descriptor(); + } + static inline const ::std::string& CType_Name(CType value) { + return FieldOptions_CType_Name(value); + } + static inline bool CType_Parse(const ::std::string& name, + CType* value) { + return FieldOptions_CType_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; + inline bool has_ctype() const; + inline void clear_ctype(); + static const int kCtypeFieldNumber = 1; + inline ::google::protobuf::FieldOptions_CType ctype() const; + inline void set_ctype(::google::protobuf::FieldOptions_CType value); + + // optional bool packed = 2; + inline bool has_packed() const; + inline void clear_packed(); + static const int kPackedFieldNumber = 2; + inline bool packed() const; + inline void set_packed(bool value); + + // optional bool deprecated = 3 [default = false]; + inline bool has_deprecated() const; + inline void clear_deprecated(); + static const int kDeprecatedFieldNumber = 3; + inline bool deprecated() const; + inline void set_deprecated(bool value); + + // optional string experimental_map_key = 9; + inline bool has_experimental_map_key() const; + inline void clear_experimental_map_key(); + static const int kExperimentalMapKeyFieldNumber = 9; + inline const ::std::string& experimental_map_key() const; + inline void set_experimental_map_key(const ::std::string& value); + inline void set_experimental_map_key(const char* value); + inline void set_experimental_map_key(const char* value, size_t size); + inline ::std::string* mutable_experimental_map_key(); + inline ::std::string* release_experimental_map_key(); + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + inline int uninterpreted_option_size() const; + inline void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FieldOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.FieldOptions) + private: + inline void set_has_ctype(); + inline void clear_has_ctype(); + inline void set_has_packed(); + inline void clear_has_packed(); + inline void set_has_deprecated(); + inline void clear_has_deprecated(); + inline void set_has_experimental_map_key(); + inline void clear_has_experimental_map_key(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + int ctype_; + bool packed_; + bool deprecated_; + ::std::string* experimental_map_key_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(5 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static FieldOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message { + public: + EnumOptions(); + virtual ~EnumOptions(); + + EnumOptions(const EnumOptions& from); + + inline EnumOptions& operator=(const EnumOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const EnumOptions& default_instance(); + + void Swap(EnumOptions* other); + + // implements Message ---------------------------------------------- + + EnumOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const EnumOptions& from); + void MergeFrom(const EnumOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + inline int uninterpreted_option_size() const; + inline void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.EnumOptions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static EnumOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message { + public: + EnumValueOptions(); + virtual ~EnumValueOptions(); + + EnumValueOptions(const EnumValueOptions& from); + + inline EnumValueOptions& operator=(const EnumValueOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const EnumValueOptions& default_instance(); + + void Swap(EnumValueOptions* other); + + // implements Message ---------------------------------------------- + + EnumValueOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const EnumValueOptions& from); + void MergeFrom(const EnumValueOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + inline int uninterpreted_option_size() const; + inline void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumValueOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.EnumValueOptions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static EnumValueOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message { + public: + ServiceOptions(); + virtual ~ServiceOptions(); + + ServiceOptions(const ServiceOptions& from); + + inline ServiceOptions& operator=(const ServiceOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ServiceOptions& default_instance(); + + void Swap(ServiceOptions* other); + + // implements Message ---------------------------------------------- + + ServiceOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ServiceOptions& from); + void MergeFrom(const ServiceOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + inline int uninterpreted_option_size() const; + inline void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ServiceOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.ServiceOptions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static ServiceOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message { + public: + MethodOptions(); + virtual ~MethodOptions(); + + MethodOptions(const MethodOptions& from); + + inline MethodOptions& operator=(const MethodOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const MethodOptions& default_instance(); + + void Swap(MethodOptions* other); + + // implements Message ---------------------------------------------- + + MethodOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const MethodOptions& from); + void MergeFrom(const MethodOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + inline int uninterpreted_option_size() const; + inline void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MethodOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.MethodOptions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static MethodOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobuf::Message { + public: + UninterpretedOption_NamePart(); + virtual ~UninterpretedOption_NamePart(); + + UninterpretedOption_NamePart(const UninterpretedOption_NamePart& from); + + inline UninterpretedOption_NamePart& operator=(const UninterpretedOption_NamePart& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const UninterpretedOption_NamePart& default_instance(); + + void Swap(UninterpretedOption_NamePart* other); + + // implements Message ---------------------------------------------- + + UninterpretedOption_NamePart* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const UninterpretedOption_NamePart& from); + void MergeFrom(const UninterpretedOption_NamePart& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // required string name_part = 1; + inline bool has_name_part() const; + inline void clear_name_part(); + static const int kNamePartFieldNumber = 1; + inline const ::std::string& name_part() const; + inline void set_name_part(const ::std::string& value); + inline void set_name_part(const char* value); + inline void set_name_part(const char* value, size_t size); + inline ::std::string* mutable_name_part(); + inline ::std::string* release_name_part(); + + // required bool is_extension = 2; + inline bool has_is_extension() const; + inline void clear_is_extension(); + static const int kIsExtensionFieldNumber = 2; + inline bool is_extension() const; + inline void set_is_extension(bool value); + + // @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption.NamePart) + private: + inline void set_has_name_part(); + inline void clear_has_name_part(); + inline void set_has_is_extension(); + inline void clear_has_is_extension(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* name_part_; + bool is_extension_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static UninterpretedOption_NamePart* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Message { + public: + UninterpretedOption(); + virtual ~UninterpretedOption(); + + UninterpretedOption(const UninterpretedOption& from); + + inline UninterpretedOption& operator=(const UninterpretedOption& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const UninterpretedOption& default_instance(); + + void Swap(UninterpretedOption* other); + + // implements Message ---------------------------------------------- + + UninterpretedOption* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const UninterpretedOption& from); + void MergeFrom(const UninterpretedOption& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef UninterpretedOption_NamePart NamePart; + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; + inline int name_size() const; + inline void clear_name(); + static const int kNameFieldNumber = 2; + inline const ::google::protobuf::UninterpretedOption_NamePart& name(int index) const; + inline ::google::protobuf::UninterpretedOption_NamePart* mutable_name(int index); + inline ::google::protobuf::UninterpretedOption_NamePart* add_name(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >& + name() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >* + mutable_name(); + + // optional string identifier_value = 3; + inline bool has_identifier_value() const; + inline void clear_identifier_value(); + static const int kIdentifierValueFieldNumber = 3; + inline const ::std::string& identifier_value() const; + inline void set_identifier_value(const ::std::string& value); + inline void set_identifier_value(const char* value); + inline void set_identifier_value(const char* value, size_t size); + inline ::std::string* mutable_identifier_value(); + inline ::std::string* release_identifier_value(); + + // optional uint64 positive_int_value = 4; + inline bool has_positive_int_value() const; + inline void clear_positive_int_value(); + static const int kPositiveIntValueFieldNumber = 4; + inline ::google::protobuf::uint64 positive_int_value() const; + inline void set_positive_int_value(::google::protobuf::uint64 value); + + // optional int64 negative_int_value = 5; + inline bool has_negative_int_value() const; + inline void clear_negative_int_value(); + static const int kNegativeIntValueFieldNumber = 5; + inline ::google::protobuf::int64 negative_int_value() const; + inline void set_negative_int_value(::google::protobuf::int64 value); + + // optional double double_value = 6; + inline bool has_double_value() const; + inline void clear_double_value(); + static const int kDoubleValueFieldNumber = 6; + inline double double_value() const; + inline void set_double_value(double value); + + // optional bytes string_value = 7; + inline bool has_string_value() const; + inline void clear_string_value(); + static const int kStringValueFieldNumber = 7; + inline const ::std::string& string_value() const; + inline void set_string_value(const ::std::string& value); + inline void set_string_value(const char* value); + inline void set_string_value(const void* value, size_t size); + inline ::std::string* mutable_string_value(); + inline ::std::string* release_string_value(); + + // optional string aggregate_value = 8; + inline bool has_aggregate_value() const; + inline void clear_aggregate_value(); + static const int kAggregateValueFieldNumber = 8; + inline const ::std::string& aggregate_value() const; + inline void set_aggregate_value(const ::std::string& value); + inline void set_aggregate_value(const char* value); + inline void set_aggregate_value(const char* value, size_t size); + inline ::std::string* mutable_aggregate_value(); + inline ::std::string* release_aggregate_value(); + + // @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption) + private: + inline void set_has_identifier_value(); + inline void clear_has_identifier_value(); + inline void set_has_positive_int_value(); + inline void clear_has_positive_int_value(); + inline void set_has_negative_int_value(); + inline void clear_has_negative_int_value(); + inline void set_has_double_value(); + inline void clear_has_double_value(); + inline void set_has_string_value(); + inline void clear_has_string_value(); + inline void set_has_aggregate_value(); + inline void clear_has_aggregate_value(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart > name_; + ::std::string* identifier_value_; + ::google::protobuf::uint64 positive_int_value_; + ::google::protobuf::int64 negative_int_value_; + double double_value_; + ::std::string* string_value_; + ::std::string* aggregate_value_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(7 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static UninterpretedOption* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Message { + public: + SourceCodeInfo_Location(); + virtual ~SourceCodeInfo_Location(); + + SourceCodeInfo_Location(const SourceCodeInfo_Location& from); + + inline SourceCodeInfo_Location& operator=(const SourceCodeInfo_Location& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const SourceCodeInfo_Location& default_instance(); + + void Swap(SourceCodeInfo_Location* other); + + // implements Message ---------------------------------------------- + + SourceCodeInfo_Location* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const SourceCodeInfo_Location& from); + void MergeFrom(const SourceCodeInfo_Location& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated int32 path = 1 [packed = true]; + inline int path_size() const; + inline void clear_path(); + static const int kPathFieldNumber = 1; + inline ::google::protobuf::int32 path(int index) const; + inline void set_path(int index, ::google::protobuf::int32 value); + inline void add_path(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + path() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_path(); + + // repeated int32 span = 2 [packed = true]; + inline int span_size() const; + inline void clear_span(); + static const int kSpanFieldNumber = 2; + inline ::google::protobuf::int32 span(int index) const; + inline void set_span(int index, ::google::protobuf::int32 value); + inline void add_span(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + span() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_span(); + + // @@protoc_insertion_point(class_scope:google.protobuf.SourceCodeInfo.Location) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > path_; + mutable int _path_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > span_; + mutable int _span_cached_byte_size_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static SourceCodeInfo_Location* default_instance_; +}; +// ------------------------------------------------------------------- + +class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message { + public: + SourceCodeInfo(); + virtual ~SourceCodeInfo(); + + SourceCodeInfo(const SourceCodeInfo& from); + + inline SourceCodeInfo& operator=(const SourceCodeInfo& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const SourceCodeInfo& default_instance(); + + void Swap(SourceCodeInfo* other); + + // implements Message ---------------------------------------------- + + SourceCodeInfo* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const SourceCodeInfo& from); + void MergeFrom(const SourceCodeInfo& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef SourceCodeInfo_Location Location; + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.SourceCodeInfo.Location location = 1; + inline int location_size() const; + inline void clear_location(); + static const int kLocationFieldNumber = 1; + inline const ::google::protobuf::SourceCodeInfo_Location& location(int index) const; + inline ::google::protobuf::SourceCodeInfo_Location* mutable_location(int index); + inline ::google::protobuf::SourceCodeInfo_Location* add_location(); + inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >& + location() const; + inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >* + mutable_location(); + + // @@protoc_insertion_point(class_scope:google.protobuf.SourceCodeInfo) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location > location_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); + + void InitAsDefaultInstance(); + static SourceCodeInfo* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// FileDescriptorSet + +// repeated .google.protobuf.FileDescriptorProto file = 1; +inline int FileDescriptorSet::file_size() const { + return file_.size(); +} +inline void FileDescriptorSet::clear_file() { + file_.Clear(); +} +inline const ::google::protobuf::FileDescriptorProto& FileDescriptorSet::file(int index) const { + return file_.Get(index); +} +inline ::google::protobuf::FileDescriptorProto* FileDescriptorSet::mutable_file(int index) { + return file_.Mutable(index); +} +inline ::google::protobuf::FileDescriptorProto* FileDescriptorSet::add_file() { + return file_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& +FileDescriptorSet::file() const { + return file_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* +FileDescriptorSet::mutable_file() { + return &file_; +} + +// ------------------------------------------------------------------- + +// FileDescriptorProto + +// optional string name = 1; +inline bool FileDescriptorProto::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void FileDescriptorProto::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void FileDescriptorProto::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void FileDescriptorProto::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& FileDescriptorProto::name() const { + return *name_; +} +inline void FileDescriptorProto::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void FileDescriptorProto::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void FileDescriptorProto::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FileDescriptorProto::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* FileDescriptorProto::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string package = 2; +inline bool FileDescriptorProto::has_package() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void FileDescriptorProto::set_has_package() { + _has_bits_[0] |= 0x00000002u; +} +inline void FileDescriptorProto::clear_has_package() { + _has_bits_[0] &= ~0x00000002u; +} +inline void FileDescriptorProto::clear_package() { + if (package_ != &::google::protobuf::internal::kEmptyString) { + package_->clear(); + } + clear_has_package(); +} +inline const ::std::string& FileDescriptorProto::package() const { + return *package_; +} +inline void FileDescriptorProto::set_package(const ::std::string& value) { + set_has_package(); + if (package_ == &::google::protobuf::internal::kEmptyString) { + package_ = new ::std::string; + } + package_->assign(value); +} +inline void FileDescriptorProto::set_package(const char* value) { + set_has_package(); + if (package_ == &::google::protobuf::internal::kEmptyString) { + package_ = new ::std::string; + } + package_->assign(value); +} +inline void FileDescriptorProto::set_package(const char* value, size_t size) { + set_has_package(); + if (package_ == &::google::protobuf::internal::kEmptyString) { + package_ = new ::std::string; + } + package_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FileDescriptorProto::mutable_package() { + set_has_package(); + if (package_ == &::google::protobuf::internal::kEmptyString) { + package_ = new ::std::string; + } + return package_; +} +inline ::std::string* FileDescriptorProto::release_package() { + clear_has_package(); + if (package_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = package_; + package_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated string dependency = 3; +inline int FileDescriptorProto::dependency_size() const { + return dependency_.size(); +} +inline void FileDescriptorProto::clear_dependency() { + dependency_.Clear(); +} +inline const ::std::string& FileDescriptorProto::dependency(int index) const { + return dependency_.Get(index); +} +inline ::std::string* FileDescriptorProto::mutable_dependency(int index) { + return dependency_.Mutable(index); +} +inline void FileDescriptorProto::set_dependency(int index, const ::std::string& value) { + dependency_.Mutable(index)->assign(value); +} +inline void FileDescriptorProto::set_dependency(int index, const char* value) { + dependency_.Mutable(index)->assign(value); +} +inline void FileDescriptorProto::set_dependency(int index, const char* value, size_t size) { + dependency_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* FileDescriptorProto::add_dependency() { + return dependency_.Add(); +} +inline void FileDescriptorProto::add_dependency(const ::std::string& value) { + dependency_.Add()->assign(value); +} +inline void FileDescriptorProto::add_dependency(const char* value) { + dependency_.Add()->assign(value); +} +inline void FileDescriptorProto::add_dependency(const char* value, size_t size) { + dependency_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +FileDescriptorProto::dependency() const { + return dependency_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +FileDescriptorProto::mutable_dependency() { + return &dependency_; +} + +// repeated .google.protobuf.DescriptorProto message_type = 4; +inline int FileDescriptorProto::message_type_size() const { + return message_type_.size(); +} +inline void FileDescriptorProto::clear_message_type() { + message_type_.Clear(); +} +inline const ::google::protobuf::DescriptorProto& FileDescriptorProto::message_type(int index) const { + return message_type_.Get(index); +} +inline ::google::protobuf::DescriptorProto* FileDescriptorProto::mutable_message_type(int index) { + return message_type_.Mutable(index); +} +inline ::google::protobuf::DescriptorProto* FileDescriptorProto::add_message_type() { + return message_type_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& +FileDescriptorProto::message_type() const { + return message_type_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* +FileDescriptorProto::mutable_message_type() { + return &message_type_; +} + +// repeated .google.protobuf.EnumDescriptorProto enum_type = 5; +inline int FileDescriptorProto::enum_type_size() const { + return enum_type_.size(); +} +inline void FileDescriptorProto::clear_enum_type() { + enum_type_.Clear(); +} +inline const ::google::protobuf::EnumDescriptorProto& FileDescriptorProto::enum_type(int index) const { + return enum_type_.Get(index); +} +inline ::google::protobuf::EnumDescriptorProto* FileDescriptorProto::mutable_enum_type(int index) { + return enum_type_.Mutable(index); +} +inline ::google::protobuf::EnumDescriptorProto* FileDescriptorProto::add_enum_type() { + return enum_type_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& +FileDescriptorProto::enum_type() const { + return enum_type_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* +FileDescriptorProto::mutable_enum_type() { + return &enum_type_; +} + +// repeated .google.protobuf.ServiceDescriptorProto service = 6; +inline int FileDescriptorProto::service_size() const { + return service_.size(); +} +inline void FileDescriptorProto::clear_service() { + service_.Clear(); +} +inline const ::google::protobuf::ServiceDescriptorProto& FileDescriptorProto::service(int index) const { + return service_.Get(index); +} +inline ::google::protobuf::ServiceDescriptorProto* FileDescriptorProto::mutable_service(int index) { + return service_.Mutable(index); +} +inline ::google::protobuf::ServiceDescriptorProto* FileDescriptorProto::add_service() { + return service_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >& +FileDescriptorProto::service() const { + return service_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >* +FileDescriptorProto::mutable_service() { + return &service_; +} + +// repeated .google.protobuf.FieldDescriptorProto extension = 7; +inline int FileDescriptorProto::extension_size() const { + return extension_.size(); +} +inline void FileDescriptorProto::clear_extension() { + extension_.Clear(); +} +inline const ::google::protobuf::FieldDescriptorProto& FileDescriptorProto::extension(int index) const { + return extension_.Get(index); +} +inline ::google::protobuf::FieldDescriptorProto* FileDescriptorProto::mutable_extension(int index) { + return extension_.Mutable(index); +} +inline ::google::protobuf::FieldDescriptorProto* FileDescriptorProto::add_extension() { + return extension_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& +FileDescriptorProto::extension() const { + return extension_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* +FileDescriptorProto::mutable_extension() { + return &extension_; +} + +// optional .google.protobuf.FileOptions options = 8; +inline bool FileDescriptorProto::has_options() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void FileDescriptorProto::set_has_options() { + _has_bits_[0] |= 0x00000080u; +} +inline void FileDescriptorProto::clear_has_options() { + _has_bits_[0] &= ~0x00000080u; +} +inline void FileDescriptorProto::clear_options() { + if (options_ != NULL) options_->::google::protobuf::FileOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { + return options_ != NULL ? *options_ : *default_instance_->options_; +} +inline ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { + set_has_options(); + if (options_ == NULL) options_ = new ::google::protobuf::FileOptions; + return options_; +} +inline ::google::protobuf::FileOptions* FileDescriptorProto::release_options() { + clear_has_options(); + ::google::protobuf::FileOptions* temp = options_; + options_ = NULL; + return temp; +} + +// optional .google.protobuf.SourceCodeInfo source_code_info = 9; +inline bool FileDescriptorProto::has_source_code_info() const { + return (_has_bits_[0] & 0x00000100u) != 0; +} +inline void FileDescriptorProto::set_has_source_code_info() { + _has_bits_[0] |= 0x00000100u; +} +inline void FileDescriptorProto::clear_has_source_code_info() { + _has_bits_[0] &= ~0x00000100u; +} +inline void FileDescriptorProto::clear_source_code_info() { + if (source_code_info_ != NULL) source_code_info_->::google::protobuf::SourceCodeInfo::Clear(); + clear_has_source_code_info(); +} +inline const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { + return source_code_info_ != NULL ? *source_code_info_ : *default_instance_->source_code_info_; +} +inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { + set_has_source_code_info(); + if (source_code_info_ == NULL) source_code_info_ = new ::google::protobuf::SourceCodeInfo; + return source_code_info_; +} +inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::release_source_code_info() { + clear_has_source_code_info(); + ::google::protobuf::SourceCodeInfo* temp = source_code_info_; + source_code_info_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// DescriptorProto_ExtensionRange + +// optional int32 start = 1; +inline bool DescriptorProto_ExtensionRange::has_start() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void DescriptorProto_ExtensionRange::set_has_start() { + _has_bits_[0] |= 0x00000001u; +} +inline void DescriptorProto_ExtensionRange::clear_has_start() { + _has_bits_[0] &= ~0x00000001u; +} +inline void DescriptorProto_ExtensionRange::clear_start() { + start_ = 0; + clear_has_start(); +} +inline ::google::protobuf::int32 DescriptorProto_ExtensionRange::start() const { + return start_; +} +inline void DescriptorProto_ExtensionRange::set_start(::google::protobuf::int32 value) { + set_has_start(); + start_ = value; +} + +// optional int32 end = 2; +inline bool DescriptorProto_ExtensionRange::has_end() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void DescriptorProto_ExtensionRange::set_has_end() { + _has_bits_[0] |= 0x00000002u; +} +inline void DescriptorProto_ExtensionRange::clear_has_end() { + _has_bits_[0] &= ~0x00000002u; +} +inline void DescriptorProto_ExtensionRange::clear_end() { + end_ = 0; + clear_has_end(); +} +inline ::google::protobuf::int32 DescriptorProto_ExtensionRange::end() const { + return end_; +} +inline void DescriptorProto_ExtensionRange::set_end(::google::protobuf::int32 value) { + set_has_end(); + end_ = value; +} + +// ------------------------------------------------------------------- + +// DescriptorProto + +// optional string name = 1; +inline bool DescriptorProto::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void DescriptorProto::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void DescriptorProto::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void DescriptorProto::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& DescriptorProto::name() const { + return *name_; +} +inline void DescriptorProto::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void DescriptorProto::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void DescriptorProto::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* DescriptorProto::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* DescriptorProto::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated .google.protobuf.FieldDescriptorProto field = 2; +inline int DescriptorProto::field_size() const { + return field_.size(); +} +inline void DescriptorProto::clear_field() { + field_.Clear(); +} +inline const ::google::protobuf::FieldDescriptorProto& DescriptorProto::field(int index) const { + return field_.Get(index); +} +inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::mutable_field(int index) { + return field_.Mutable(index); +} +inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::add_field() { + return field_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& +DescriptorProto::field() const { + return field_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* +DescriptorProto::mutable_field() { + return &field_; +} + +// repeated .google.protobuf.FieldDescriptorProto extension = 6; +inline int DescriptorProto::extension_size() const { + return extension_.size(); +} +inline void DescriptorProto::clear_extension() { + extension_.Clear(); +} +inline const ::google::protobuf::FieldDescriptorProto& DescriptorProto::extension(int index) const { + return extension_.Get(index); +} +inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::mutable_extension(int index) { + return extension_.Mutable(index); +} +inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::add_extension() { + return extension_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& +DescriptorProto::extension() const { + return extension_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* +DescriptorProto::mutable_extension() { + return &extension_; +} + +// repeated .google.protobuf.DescriptorProto nested_type = 3; +inline int DescriptorProto::nested_type_size() const { + return nested_type_.size(); +} +inline void DescriptorProto::clear_nested_type() { + nested_type_.Clear(); +} +inline const ::google::protobuf::DescriptorProto& DescriptorProto::nested_type(int index) const { + return nested_type_.Get(index); +} +inline ::google::protobuf::DescriptorProto* DescriptorProto::mutable_nested_type(int index) { + return nested_type_.Mutable(index); +} +inline ::google::protobuf::DescriptorProto* DescriptorProto::add_nested_type() { + return nested_type_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& +DescriptorProto::nested_type() const { + return nested_type_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* +DescriptorProto::mutable_nested_type() { + return &nested_type_; +} + +// repeated .google.protobuf.EnumDescriptorProto enum_type = 4; +inline int DescriptorProto::enum_type_size() const { + return enum_type_.size(); +} +inline void DescriptorProto::clear_enum_type() { + enum_type_.Clear(); +} +inline const ::google::protobuf::EnumDescriptorProto& DescriptorProto::enum_type(int index) const { + return enum_type_.Get(index); +} +inline ::google::protobuf::EnumDescriptorProto* DescriptorProto::mutable_enum_type(int index) { + return enum_type_.Mutable(index); +} +inline ::google::protobuf::EnumDescriptorProto* DescriptorProto::add_enum_type() { + return enum_type_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& +DescriptorProto::enum_type() const { + return enum_type_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* +DescriptorProto::mutable_enum_type() { + return &enum_type_; +} + +// repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; +inline int DescriptorProto::extension_range_size() const { + return extension_range_.size(); +} +inline void DescriptorProto::clear_extension_range() { + extension_range_.Clear(); +} +inline const ::google::protobuf::DescriptorProto_ExtensionRange& DescriptorProto::extension_range(int index) const { + return extension_range_.Get(index); +} +inline ::google::protobuf::DescriptorProto_ExtensionRange* DescriptorProto::mutable_extension_range(int index) { + return extension_range_.Mutable(index); +} +inline ::google::protobuf::DescriptorProto_ExtensionRange* DescriptorProto::add_extension_range() { + return extension_range_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >& +DescriptorProto::extension_range() const { + return extension_range_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >* +DescriptorProto::mutable_extension_range() { + return &extension_range_; +} + +// optional .google.protobuf.MessageOptions options = 7; +inline bool DescriptorProto::has_options() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void DescriptorProto::set_has_options() { + _has_bits_[0] |= 0x00000040u; +} +inline void DescriptorProto::clear_has_options() { + _has_bits_[0] &= ~0x00000040u; +} +inline void DescriptorProto::clear_options() { + if (options_ != NULL) options_->::google::protobuf::MessageOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::MessageOptions& DescriptorProto::options() const { + return options_ != NULL ? *options_ : *default_instance_->options_; +} +inline ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { + set_has_options(); + if (options_ == NULL) options_ = new ::google::protobuf::MessageOptions; + return options_; +} +inline ::google::protobuf::MessageOptions* DescriptorProto::release_options() { + clear_has_options(); + ::google::protobuf::MessageOptions* temp = options_; + options_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// FieldDescriptorProto + +// optional string name = 1; +inline bool FieldDescriptorProto::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void FieldDescriptorProto::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void FieldDescriptorProto::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void FieldDescriptorProto::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& FieldDescriptorProto::name() const { + return *name_; +} +inline void FieldDescriptorProto::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void FieldDescriptorProto::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void FieldDescriptorProto::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FieldDescriptorProto::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* FieldDescriptorProto::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional int32 number = 3; +inline bool FieldDescriptorProto::has_number() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void FieldDescriptorProto::set_has_number() { + _has_bits_[0] |= 0x00000002u; +} +inline void FieldDescriptorProto::clear_has_number() { + _has_bits_[0] &= ~0x00000002u; +} +inline void FieldDescriptorProto::clear_number() { + number_ = 0; + clear_has_number(); +} +inline ::google::protobuf::int32 FieldDescriptorProto::number() const { + return number_; +} +inline void FieldDescriptorProto::set_number(::google::protobuf::int32 value) { + set_has_number(); + number_ = value; +} + +// optional .google.protobuf.FieldDescriptorProto.Label label = 4; +inline bool FieldDescriptorProto::has_label() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void FieldDescriptorProto::set_has_label() { + _has_bits_[0] |= 0x00000004u; +} +inline void FieldDescriptorProto::clear_has_label() { + _has_bits_[0] &= ~0x00000004u; +} +inline void FieldDescriptorProto::clear_label() { + label_ = 1; + clear_has_label(); +} +inline ::google::protobuf::FieldDescriptorProto_Label FieldDescriptorProto::label() const { + return static_cast< ::google::protobuf::FieldDescriptorProto_Label >(label_); +} +inline void FieldDescriptorProto::set_label(::google::protobuf::FieldDescriptorProto_Label value) { + GOOGLE_DCHECK(::google::protobuf::FieldDescriptorProto_Label_IsValid(value)); + set_has_label(); + label_ = value; +} + +// optional .google.protobuf.FieldDescriptorProto.Type type = 5; +inline bool FieldDescriptorProto::has_type() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void FieldDescriptorProto::set_has_type() { + _has_bits_[0] |= 0x00000008u; +} +inline void FieldDescriptorProto::clear_has_type() { + _has_bits_[0] &= ~0x00000008u; +} +inline void FieldDescriptorProto::clear_type() { + type_ = 1; + clear_has_type(); +} +inline ::google::protobuf::FieldDescriptorProto_Type FieldDescriptorProto::type() const { + return static_cast< ::google::protobuf::FieldDescriptorProto_Type >(type_); +} +inline void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorProto_Type value) { + GOOGLE_DCHECK(::google::protobuf::FieldDescriptorProto_Type_IsValid(value)); + set_has_type(); + type_ = value; +} + +// optional string type_name = 6; +inline bool FieldDescriptorProto::has_type_name() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void FieldDescriptorProto::set_has_type_name() { + _has_bits_[0] |= 0x00000010u; +} +inline void FieldDescriptorProto::clear_has_type_name() { + _has_bits_[0] &= ~0x00000010u; +} +inline void FieldDescriptorProto::clear_type_name() { + if (type_name_ != &::google::protobuf::internal::kEmptyString) { + type_name_->clear(); + } + clear_has_type_name(); +} +inline const ::std::string& FieldDescriptorProto::type_name() const { + return *type_name_; +} +inline void FieldDescriptorProto::set_type_name(const ::std::string& value) { + set_has_type_name(); + if (type_name_ == &::google::protobuf::internal::kEmptyString) { + type_name_ = new ::std::string; + } + type_name_->assign(value); +} +inline void FieldDescriptorProto::set_type_name(const char* value) { + set_has_type_name(); + if (type_name_ == &::google::protobuf::internal::kEmptyString) { + type_name_ = new ::std::string; + } + type_name_->assign(value); +} +inline void FieldDescriptorProto::set_type_name(const char* value, size_t size) { + set_has_type_name(); + if (type_name_ == &::google::protobuf::internal::kEmptyString) { + type_name_ = new ::std::string; + } + type_name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FieldDescriptorProto::mutable_type_name() { + set_has_type_name(); + if (type_name_ == &::google::protobuf::internal::kEmptyString) { + type_name_ = new ::std::string; + } + return type_name_; +} +inline ::std::string* FieldDescriptorProto::release_type_name() { + clear_has_type_name(); + if (type_name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = type_name_; + type_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string extendee = 2; +inline bool FieldDescriptorProto::has_extendee() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void FieldDescriptorProto::set_has_extendee() { + _has_bits_[0] |= 0x00000020u; +} +inline void FieldDescriptorProto::clear_has_extendee() { + _has_bits_[0] &= ~0x00000020u; +} +inline void FieldDescriptorProto::clear_extendee() { + if (extendee_ != &::google::protobuf::internal::kEmptyString) { + extendee_->clear(); + } + clear_has_extendee(); +} +inline const ::std::string& FieldDescriptorProto::extendee() const { + return *extendee_; +} +inline void FieldDescriptorProto::set_extendee(const ::std::string& value) { + set_has_extendee(); + if (extendee_ == &::google::protobuf::internal::kEmptyString) { + extendee_ = new ::std::string; + } + extendee_->assign(value); +} +inline void FieldDescriptorProto::set_extendee(const char* value) { + set_has_extendee(); + if (extendee_ == &::google::protobuf::internal::kEmptyString) { + extendee_ = new ::std::string; + } + extendee_->assign(value); +} +inline void FieldDescriptorProto::set_extendee(const char* value, size_t size) { + set_has_extendee(); + if (extendee_ == &::google::protobuf::internal::kEmptyString) { + extendee_ = new ::std::string; + } + extendee_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FieldDescriptorProto::mutable_extendee() { + set_has_extendee(); + if (extendee_ == &::google::protobuf::internal::kEmptyString) { + extendee_ = new ::std::string; + } + return extendee_; +} +inline ::std::string* FieldDescriptorProto::release_extendee() { + clear_has_extendee(); + if (extendee_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = extendee_; + extendee_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string default_value = 7; +inline bool FieldDescriptorProto::has_default_value() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void FieldDescriptorProto::set_has_default_value() { + _has_bits_[0] |= 0x00000040u; +} +inline void FieldDescriptorProto::clear_has_default_value() { + _has_bits_[0] &= ~0x00000040u; +} +inline void FieldDescriptorProto::clear_default_value() { + if (default_value_ != &::google::protobuf::internal::kEmptyString) { + default_value_->clear(); + } + clear_has_default_value(); +} +inline const ::std::string& FieldDescriptorProto::default_value() const { + return *default_value_; +} +inline void FieldDescriptorProto::set_default_value(const ::std::string& value) { + set_has_default_value(); + if (default_value_ == &::google::protobuf::internal::kEmptyString) { + default_value_ = new ::std::string; + } + default_value_->assign(value); +} +inline void FieldDescriptorProto::set_default_value(const char* value) { + set_has_default_value(); + if (default_value_ == &::google::protobuf::internal::kEmptyString) { + default_value_ = new ::std::string; + } + default_value_->assign(value); +} +inline void FieldDescriptorProto::set_default_value(const char* value, size_t size) { + set_has_default_value(); + if (default_value_ == &::google::protobuf::internal::kEmptyString) { + default_value_ = new ::std::string; + } + default_value_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FieldDescriptorProto::mutable_default_value() { + set_has_default_value(); + if (default_value_ == &::google::protobuf::internal::kEmptyString) { + default_value_ = new ::std::string; + } + return default_value_; +} +inline ::std::string* FieldDescriptorProto::release_default_value() { + clear_has_default_value(); + if (default_value_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = default_value_; + default_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional .google.protobuf.FieldOptions options = 8; +inline bool FieldDescriptorProto::has_options() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void FieldDescriptorProto::set_has_options() { + _has_bits_[0] |= 0x00000080u; +} +inline void FieldDescriptorProto::clear_has_options() { + _has_bits_[0] &= ~0x00000080u; +} +inline void FieldDescriptorProto::clear_options() { + if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { + return options_ != NULL ? *options_ : *default_instance_->options_; +} +inline ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { + set_has_options(); + if (options_ == NULL) options_ = new ::google::protobuf::FieldOptions; + return options_; +} +inline ::google::protobuf::FieldOptions* FieldDescriptorProto::release_options() { + clear_has_options(); + ::google::protobuf::FieldOptions* temp = options_; + options_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// EnumDescriptorProto + +// optional string name = 1; +inline bool EnumDescriptorProto::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void EnumDescriptorProto::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void EnumDescriptorProto::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void EnumDescriptorProto::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& EnumDescriptorProto::name() const { + return *name_; +} +inline void EnumDescriptorProto::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void EnumDescriptorProto::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void EnumDescriptorProto::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* EnumDescriptorProto::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* EnumDescriptorProto::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated .google.protobuf.EnumValueDescriptorProto value = 2; +inline int EnumDescriptorProto::value_size() const { + return value_.size(); +} +inline void EnumDescriptorProto::clear_value() { + value_.Clear(); +} +inline const ::google::protobuf::EnumValueDescriptorProto& EnumDescriptorProto::value(int index) const { + return value_.Get(index); +} +inline ::google::protobuf::EnumValueDescriptorProto* EnumDescriptorProto::mutable_value(int index) { + return value_.Mutable(index); +} +inline ::google::protobuf::EnumValueDescriptorProto* EnumDescriptorProto::add_value() { + return value_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >& +EnumDescriptorProto::value() const { + return value_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >* +EnumDescriptorProto::mutable_value() { + return &value_; +} + +// optional .google.protobuf.EnumOptions options = 3; +inline bool EnumDescriptorProto::has_options() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void EnumDescriptorProto::set_has_options() { + _has_bits_[0] |= 0x00000004u; +} +inline void EnumDescriptorProto::clear_has_options() { + _has_bits_[0] &= ~0x00000004u; +} +inline void EnumDescriptorProto::clear_options() { + if (options_ != NULL) options_->::google::protobuf::EnumOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { + return options_ != NULL ? *options_ : *default_instance_->options_; +} +inline ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { + set_has_options(); + if (options_ == NULL) options_ = new ::google::protobuf::EnumOptions; + return options_; +} +inline ::google::protobuf::EnumOptions* EnumDescriptorProto::release_options() { + clear_has_options(); + ::google::protobuf::EnumOptions* temp = options_; + options_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// EnumValueDescriptorProto + +// optional string name = 1; +inline bool EnumValueDescriptorProto::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void EnumValueDescriptorProto::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void EnumValueDescriptorProto::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void EnumValueDescriptorProto::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& EnumValueDescriptorProto::name() const { + return *name_; +} +inline void EnumValueDescriptorProto::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void EnumValueDescriptorProto::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void EnumValueDescriptorProto::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* EnumValueDescriptorProto::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* EnumValueDescriptorProto::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional int32 number = 2; +inline bool EnumValueDescriptorProto::has_number() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void EnumValueDescriptorProto::set_has_number() { + _has_bits_[0] |= 0x00000002u; +} +inline void EnumValueDescriptorProto::clear_has_number() { + _has_bits_[0] &= ~0x00000002u; +} +inline void EnumValueDescriptorProto::clear_number() { + number_ = 0; + clear_has_number(); +} +inline ::google::protobuf::int32 EnumValueDescriptorProto::number() const { + return number_; +} +inline void EnumValueDescriptorProto::set_number(::google::protobuf::int32 value) { + set_has_number(); + number_ = value; +} + +// optional .google.protobuf.EnumValueOptions options = 3; +inline bool EnumValueDescriptorProto::has_options() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void EnumValueDescriptorProto::set_has_options() { + _has_bits_[0] |= 0x00000004u; +} +inline void EnumValueDescriptorProto::clear_has_options() { + _has_bits_[0] &= ~0x00000004u; +} +inline void EnumValueDescriptorProto::clear_options() { + if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { + return options_ != NULL ? *options_ : *default_instance_->options_; +} +inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { + set_has_options(); + if (options_ == NULL) options_ = new ::google::protobuf::EnumValueOptions; + return options_; +} +inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::release_options() { + clear_has_options(); + ::google::protobuf::EnumValueOptions* temp = options_; + options_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// ServiceDescriptorProto + +// optional string name = 1; +inline bool ServiceDescriptorProto::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ServiceDescriptorProto::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void ServiceDescriptorProto::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ServiceDescriptorProto::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& ServiceDescriptorProto::name() const { + return *name_; +} +inline void ServiceDescriptorProto::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void ServiceDescriptorProto::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void ServiceDescriptorProto::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* ServiceDescriptorProto::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* ServiceDescriptorProto::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated .google.protobuf.MethodDescriptorProto method = 2; +inline int ServiceDescriptorProto::method_size() const { + return method_.size(); +} +inline void ServiceDescriptorProto::clear_method() { + method_.Clear(); +} +inline const ::google::protobuf::MethodDescriptorProto& ServiceDescriptorProto::method(int index) const { + return method_.Get(index); +} +inline ::google::protobuf::MethodDescriptorProto* ServiceDescriptorProto::mutable_method(int index) { + return method_.Mutable(index); +} +inline ::google::protobuf::MethodDescriptorProto* ServiceDescriptorProto::add_method() { + return method_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >& +ServiceDescriptorProto::method() const { + return method_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >* +ServiceDescriptorProto::mutable_method() { + return &method_; +} + +// optional .google.protobuf.ServiceOptions options = 3; +inline bool ServiceDescriptorProto::has_options() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void ServiceDescriptorProto::set_has_options() { + _has_bits_[0] |= 0x00000004u; +} +inline void ServiceDescriptorProto::clear_has_options() { + _has_bits_[0] &= ~0x00000004u; +} +inline void ServiceDescriptorProto::clear_options() { + if (options_ != NULL) options_->::google::protobuf::ServiceOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { + return options_ != NULL ? *options_ : *default_instance_->options_; +} +inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { + set_has_options(); + if (options_ == NULL) options_ = new ::google::protobuf::ServiceOptions; + return options_; +} +inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::release_options() { + clear_has_options(); + ::google::protobuf::ServiceOptions* temp = options_; + options_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// MethodDescriptorProto + +// optional string name = 1; +inline bool MethodDescriptorProto::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void MethodDescriptorProto::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void MethodDescriptorProto::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void MethodDescriptorProto::clear_name() { + if (name_ != &::google::protobuf::internal::kEmptyString) { + name_->clear(); + } + clear_has_name(); +} +inline const ::std::string& MethodDescriptorProto::name() const { + return *name_; +} +inline void MethodDescriptorProto::set_name(const ::std::string& value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void MethodDescriptorProto::set_name(const char* value) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(value); +} +inline void MethodDescriptorProto::set_name(const char* value, size_t size) { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + name_->assign(reinterpret_cast(value), size); +} +inline ::std::string* MethodDescriptorProto::mutable_name() { + set_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + name_ = new ::std::string; + } + return name_; +} +inline ::std::string* MethodDescriptorProto::release_name() { + clear_has_name(); + if (name_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_; + name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string input_type = 2; +inline bool MethodDescriptorProto::has_input_type() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void MethodDescriptorProto::set_has_input_type() { + _has_bits_[0] |= 0x00000002u; +} +inline void MethodDescriptorProto::clear_has_input_type() { + _has_bits_[0] &= ~0x00000002u; +} +inline void MethodDescriptorProto::clear_input_type() { + if (input_type_ != &::google::protobuf::internal::kEmptyString) { + input_type_->clear(); + } + clear_has_input_type(); +} +inline const ::std::string& MethodDescriptorProto::input_type() const { + return *input_type_; +} +inline void MethodDescriptorProto::set_input_type(const ::std::string& value) { + set_has_input_type(); + if (input_type_ == &::google::protobuf::internal::kEmptyString) { + input_type_ = new ::std::string; + } + input_type_->assign(value); +} +inline void MethodDescriptorProto::set_input_type(const char* value) { + set_has_input_type(); + if (input_type_ == &::google::protobuf::internal::kEmptyString) { + input_type_ = new ::std::string; + } + input_type_->assign(value); +} +inline void MethodDescriptorProto::set_input_type(const char* value, size_t size) { + set_has_input_type(); + if (input_type_ == &::google::protobuf::internal::kEmptyString) { + input_type_ = new ::std::string; + } + input_type_->assign(reinterpret_cast(value), size); +} +inline ::std::string* MethodDescriptorProto::mutable_input_type() { + set_has_input_type(); + if (input_type_ == &::google::protobuf::internal::kEmptyString) { + input_type_ = new ::std::string; + } + return input_type_; +} +inline ::std::string* MethodDescriptorProto::release_input_type() { + clear_has_input_type(); + if (input_type_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = input_type_; + input_type_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string output_type = 3; +inline bool MethodDescriptorProto::has_output_type() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void MethodDescriptorProto::set_has_output_type() { + _has_bits_[0] |= 0x00000004u; +} +inline void MethodDescriptorProto::clear_has_output_type() { + _has_bits_[0] &= ~0x00000004u; +} +inline void MethodDescriptorProto::clear_output_type() { + if (output_type_ != &::google::protobuf::internal::kEmptyString) { + output_type_->clear(); + } + clear_has_output_type(); +} +inline const ::std::string& MethodDescriptorProto::output_type() const { + return *output_type_; +} +inline void MethodDescriptorProto::set_output_type(const ::std::string& value) { + set_has_output_type(); + if (output_type_ == &::google::protobuf::internal::kEmptyString) { + output_type_ = new ::std::string; + } + output_type_->assign(value); +} +inline void MethodDescriptorProto::set_output_type(const char* value) { + set_has_output_type(); + if (output_type_ == &::google::protobuf::internal::kEmptyString) { + output_type_ = new ::std::string; + } + output_type_->assign(value); +} +inline void MethodDescriptorProto::set_output_type(const char* value, size_t size) { + set_has_output_type(); + if (output_type_ == &::google::protobuf::internal::kEmptyString) { + output_type_ = new ::std::string; + } + output_type_->assign(reinterpret_cast(value), size); +} +inline ::std::string* MethodDescriptorProto::mutable_output_type() { + set_has_output_type(); + if (output_type_ == &::google::protobuf::internal::kEmptyString) { + output_type_ = new ::std::string; + } + return output_type_; +} +inline ::std::string* MethodDescriptorProto::release_output_type() { + clear_has_output_type(); + if (output_type_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = output_type_; + output_type_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional .google.protobuf.MethodOptions options = 4; +inline bool MethodDescriptorProto::has_options() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void MethodDescriptorProto::set_has_options() { + _has_bits_[0] |= 0x00000008u; +} +inline void MethodDescriptorProto::clear_has_options() { + _has_bits_[0] &= ~0x00000008u; +} +inline void MethodDescriptorProto::clear_options() { + if (options_ != NULL) options_->::google::protobuf::MethodOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { + return options_ != NULL ? *options_ : *default_instance_->options_; +} +inline ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { + set_has_options(); + if (options_ == NULL) options_ = new ::google::protobuf::MethodOptions; + return options_; +} +inline ::google::protobuf::MethodOptions* MethodDescriptorProto::release_options() { + clear_has_options(); + ::google::protobuf::MethodOptions* temp = options_; + options_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// FileOptions + +// optional string java_package = 1; +inline bool FileOptions::has_java_package() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void FileOptions::set_has_java_package() { + _has_bits_[0] |= 0x00000001u; +} +inline void FileOptions::clear_has_java_package() { + _has_bits_[0] &= ~0x00000001u; +} +inline void FileOptions::clear_java_package() { + if (java_package_ != &::google::protobuf::internal::kEmptyString) { + java_package_->clear(); + } + clear_has_java_package(); +} +inline const ::std::string& FileOptions::java_package() const { + return *java_package_; +} +inline void FileOptions::set_java_package(const ::std::string& value) { + set_has_java_package(); + if (java_package_ == &::google::protobuf::internal::kEmptyString) { + java_package_ = new ::std::string; + } + java_package_->assign(value); +} +inline void FileOptions::set_java_package(const char* value) { + set_has_java_package(); + if (java_package_ == &::google::protobuf::internal::kEmptyString) { + java_package_ = new ::std::string; + } + java_package_->assign(value); +} +inline void FileOptions::set_java_package(const char* value, size_t size) { + set_has_java_package(); + if (java_package_ == &::google::protobuf::internal::kEmptyString) { + java_package_ = new ::std::string; + } + java_package_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FileOptions::mutable_java_package() { + set_has_java_package(); + if (java_package_ == &::google::protobuf::internal::kEmptyString) { + java_package_ = new ::std::string; + } + return java_package_; +} +inline ::std::string* FileOptions::release_java_package() { + clear_has_java_package(); + if (java_package_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = java_package_; + java_package_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string java_outer_classname = 8; +inline bool FileOptions::has_java_outer_classname() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void FileOptions::set_has_java_outer_classname() { + _has_bits_[0] |= 0x00000002u; +} +inline void FileOptions::clear_has_java_outer_classname() { + _has_bits_[0] &= ~0x00000002u; +} +inline void FileOptions::clear_java_outer_classname() { + if (java_outer_classname_ != &::google::protobuf::internal::kEmptyString) { + java_outer_classname_->clear(); + } + clear_has_java_outer_classname(); +} +inline const ::std::string& FileOptions::java_outer_classname() const { + return *java_outer_classname_; +} +inline void FileOptions::set_java_outer_classname(const ::std::string& value) { + set_has_java_outer_classname(); + if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { + java_outer_classname_ = new ::std::string; + } + java_outer_classname_->assign(value); +} +inline void FileOptions::set_java_outer_classname(const char* value) { + set_has_java_outer_classname(); + if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { + java_outer_classname_ = new ::std::string; + } + java_outer_classname_->assign(value); +} +inline void FileOptions::set_java_outer_classname(const char* value, size_t size) { + set_has_java_outer_classname(); + if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { + java_outer_classname_ = new ::std::string; + } + java_outer_classname_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FileOptions::mutable_java_outer_classname() { + set_has_java_outer_classname(); + if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { + java_outer_classname_ = new ::std::string; + } + return java_outer_classname_; +} +inline ::std::string* FileOptions::release_java_outer_classname() { + clear_has_java_outer_classname(); + if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = java_outer_classname_; + java_outer_classname_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional bool java_multiple_files = 10 [default = false]; +inline bool FileOptions::has_java_multiple_files() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void FileOptions::set_has_java_multiple_files() { + _has_bits_[0] |= 0x00000004u; +} +inline void FileOptions::clear_has_java_multiple_files() { + _has_bits_[0] &= ~0x00000004u; +} +inline void FileOptions::clear_java_multiple_files() { + java_multiple_files_ = false; + clear_has_java_multiple_files(); +} +inline bool FileOptions::java_multiple_files() const { + return java_multiple_files_; +} +inline void FileOptions::set_java_multiple_files(bool value) { + set_has_java_multiple_files(); + java_multiple_files_ = value; +} + +// optional bool java_generate_equals_and_hash = 20 [default = false]; +inline bool FileOptions::has_java_generate_equals_and_hash() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void FileOptions::set_has_java_generate_equals_and_hash() { + _has_bits_[0] |= 0x00000008u; +} +inline void FileOptions::clear_has_java_generate_equals_and_hash() { + _has_bits_[0] &= ~0x00000008u; +} +inline void FileOptions::clear_java_generate_equals_and_hash() { + java_generate_equals_and_hash_ = false; + clear_has_java_generate_equals_and_hash(); +} +inline bool FileOptions::java_generate_equals_and_hash() const { + return java_generate_equals_and_hash_; +} +inline void FileOptions::set_java_generate_equals_and_hash(bool value) { + set_has_java_generate_equals_and_hash(); + java_generate_equals_and_hash_ = value; +} + +// optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; +inline bool FileOptions::has_optimize_for() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void FileOptions::set_has_optimize_for() { + _has_bits_[0] |= 0x00000010u; +} +inline void FileOptions::clear_has_optimize_for() { + _has_bits_[0] &= ~0x00000010u; +} +inline void FileOptions::clear_optimize_for() { + optimize_for_ = 1; + clear_has_optimize_for(); +} +inline ::google::protobuf::FileOptions_OptimizeMode FileOptions::optimize_for() const { + return static_cast< ::google::protobuf::FileOptions_OptimizeMode >(optimize_for_); +} +inline void FileOptions::set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value) { + GOOGLE_DCHECK(::google::protobuf::FileOptions_OptimizeMode_IsValid(value)); + set_has_optimize_for(); + optimize_for_ = value; +} + +// optional bool cc_generic_services = 16 [default = false]; +inline bool FileOptions::has_cc_generic_services() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void FileOptions::set_has_cc_generic_services() { + _has_bits_[0] |= 0x00000020u; +} +inline void FileOptions::clear_has_cc_generic_services() { + _has_bits_[0] &= ~0x00000020u; +} +inline void FileOptions::clear_cc_generic_services() { + cc_generic_services_ = false; + clear_has_cc_generic_services(); +} +inline bool FileOptions::cc_generic_services() const { + return cc_generic_services_; +} +inline void FileOptions::set_cc_generic_services(bool value) { + set_has_cc_generic_services(); + cc_generic_services_ = value; +} + +// optional bool java_generic_services = 17 [default = false]; +inline bool FileOptions::has_java_generic_services() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void FileOptions::set_has_java_generic_services() { + _has_bits_[0] |= 0x00000040u; +} +inline void FileOptions::clear_has_java_generic_services() { + _has_bits_[0] &= ~0x00000040u; +} +inline void FileOptions::clear_java_generic_services() { + java_generic_services_ = false; + clear_has_java_generic_services(); +} +inline bool FileOptions::java_generic_services() const { + return java_generic_services_; +} +inline void FileOptions::set_java_generic_services(bool value) { + set_has_java_generic_services(); + java_generic_services_ = value; +} + +// optional bool py_generic_services = 18 [default = false]; +inline bool FileOptions::has_py_generic_services() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void FileOptions::set_has_py_generic_services() { + _has_bits_[0] |= 0x00000080u; +} +inline void FileOptions::clear_has_py_generic_services() { + _has_bits_[0] &= ~0x00000080u; +} +inline void FileOptions::clear_py_generic_services() { + py_generic_services_ = false; + clear_has_py_generic_services(); +} +inline bool FileOptions::py_generic_services() const { + return py_generic_services_; +} +inline void FileOptions::set_py_generic_services(bool value) { + set_has_py_generic_services(); + py_generic_services_ = value; +} + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int FileOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void FileOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& FileOptions::uninterpreted_option(int index) const { + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* FileOptions::mutable_uninterpreted_option(int index) { + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* FileOptions::add_uninterpreted_option() { + return uninterpreted_option_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +FileOptions::uninterpreted_option() const { + return uninterpreted_option_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +FileOptions::mutable_uninterpreted_option() { + return &uninterpreted_option_; +} + +// ------------------------------------------------------------------- + +// MessageOptions + +// optional bool message_set_wire_format = 1 [default = false]; +inline bool MessageOptions::has_message_set_wire_format() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void MessageOptions::set_has_message_set_wire_format() { + _has_bits_[0] |= 0x00000001u; +} +inline void MessageOptions::clear_has_message_set_wire_format() { + _has_bits_[0] &= ~0x00000001u; +} +inline void MessageOptions::clear_message_set_wire_format() { + message_set_wire_format_ = false; + clear_has_message_set_wire_format(); +} +inline bool MessageOptions::message_set_wire_format() const { + return message_set_wire_format_; +} +inline void MessageOptions::set_message_set_wire_format(bool value) { + set_has_message_set_wire_format(); + message_set_wire_format_ = value; +} + +// optional bool no_standard_descriptor_accessor = 2 [default = false]; +inline bool MessageOptions::has_no_standard_descriptor_accessor() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void MessageOptions::set_has_no_standard_descriptor_accessor() { + _has_bits_[0] |= 0x00000002u; +} +inline void MessageOptions::clear_has_no_standard_descriptor_accessor() { + _has_bits_[0] &= ~0x00000002u; +} +inline void MessageOptions::clear_no_standard_descriptor_accessor() { + no_standard_descriptor_accessor_ = false; + clear_has_no_standard_descriptor_accessor(); +} +inline bool MessageOptions::no_standard_descriptor_accessor() const { + return no_standard_descriptor_accessor_; +} +inline void MessageOptions::set_no_standard_descriptor_accessor(bool value) { + set_has_no_standard_descriptor_accessor(); + no_standard_descriptor_accessor_ = value; +} + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int MessageOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void MessageOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& MessageOptions::uninterpreted_option(int index) const { + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* MessageOptions::mutable_uninterpreted_option(int index) { + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* MessageOptions::add_uninterpreted_option() { + return uninterpreted_option_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +MessageOptions::uninterpreted_option() const { + return uninterpreted_option_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +MessageOptions::mutable_uninterpreted_option() { + return &uninterpreted_option_; +} + +// ------------------------------------------------------------------- + +// FieldOptions + +// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; +inline bool FieldOptions::has_ctype() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void FieldOptions::set_has_ctype() { + _has_bits_[0] |= 0x00000001u; +} +inline void FieldOptions::clear_has_ctype() { + _has_bits_[0] &= ~0x00000001u; +} +inline void FieldOptions::clear_ctype() { + ctype_ = 0; + clear_has_ctype(); +} +inline ::google::protobuf::FieldOptions_CType FieldOptions::ctype() const { + return static_cast< ::google::protobuf::FieldOptions_CType >(ctype_); +} +inline void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value) { + GOOGLE_DCHECK(::google::protobuf::FieldOptions_CType_IsValid(value)); + set_has_ctype(); + ctype_ = value; +} + +// optional bool packed = 2; +inline bool FieldOptions::has_packed() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void FieldOptions::set_has_packed() { + _has_bits_[0] |= 0x00000002u; +} +inline void FieldOptions::clear_has_packed() { + _has_bits_[0] &= ~0x00000002u; +} +inline void FieldOptions::clear_packed() { + packed_ = false; + clear_has_packed(); +} +inline bool FieldOptions::packed() const { + return packed_; +} +inline void FieldOptions::set_packed(bool value) { + set_has_packed(); + packed_ = value; +} + +// optional bool deprecated = 3 [default = false]; +inline bool FieldOptions::has_deprecated() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void FieldOptions::set_has_deprecated() { + _has_bits_[0] |= 0x00000004u; +} +inline void FieldOptions::clear_has_deprecated() { + _has_bits_[0] &= ~0x00000004u; +} +inline void FieldOptions::clear_deprecated() { + deprecated_ = false; + clear_has_deprecated(); +} +inline bool FieldOptions::deprecated() const { + return deprecated_; +} +inline void FieldOptions::set_deprecated(bool value) { + set_has_deprecated(); + deprecated_ = value; +} + +// optional string experimental_map_key = 9; +inline bool FieldOptions::has_experimental_map_key() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void FieldOptions::set_has_experimental_map_key() { + _has_bits_[0] |= 0x00000008u; +} +inline void FieldOptions::clear_has_experimental_map_key() { + _has_bits_[0] &= ~0x00000008u; +} +inline void FieldOptions::clear_experimental_map_key() { + if (experimental_map_key_ != &::google::protobuf::internal::kEmptyString) { + experimental_map_key_->clear(); + } + clear_has_experimental_map_key(); +} +inline const ::std::string& FieldOptions::experimental_map_key() const { + return *experimental_map_key_; +} +inline void FieldOptions::set_experimental_map_key(const ::std::string& value) { + set_has_experimental_map_key(); + if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { + experimental_map_key_ = new ::std::string; + } + experimental_map_key_->assign(value); +} +inline void FieldOptions::set_experimental_map_key(const char* value) { + set_has_experimental_map_key(); + if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { + experimental_map_key_ = new ::std::string; + } + experimental_map_key_->assign(value); +} +inline void FieldOptions::set_experimental_map_key(const char* value, size_t size) { + set_has_experimental_map_key(); + if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { + experimental_map_key_ = new ::std::string; + } + experimental_map_key_->assign(reinterpret_cast(value), size); +} +inline ::std::string* FieldOptions::mutable_experimental_map_key() { + set_has_experimental_map_key(); + if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { + experimental_map_key_ = new ::std::string; + } + return experimental_map_key_; +} +inline ::std::string* FieldOptions::release_experimental_map_key() { + clear_has_experimental_map_key(); + if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = experimental_map_key_; + experimental_map_key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int FieldOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void FieldOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& FieldOptions::uninterpreted_option(int index) const { + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* FieldOptions::mutable_uninterpreted_option(int index) { + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* FieldOptions::add_uninterpreted_option() { + return uninterpreted_option_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +FieldOptions::uninterpreted_option() const { + return uninterpreted_option_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +FieldOptions::mutable_uninterpreted_option() { + return &uninterpreted_option_; +} + +// ------------------------------------------------------------------- + +// EnumOptions + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int EnumOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void EnumOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& EnumOptions::uninterpreted_option(int index) const { + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* EnumOptions::mutable_uninterpreted_option(int index) { + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* EnumOptions::add_uninterpreted_option() { + return uninterpreted_option_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +EnumOptions::uninterpreted_option() const { + return uninterpreted_option_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +EnumOptions::mutable_uninterpreted_option() { + return &uninterpreted_option_; +} + +// ------------------------------------------------------------------- + +// EnumValueOptions + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int EnumValueOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void EnumValueOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& EnumValueOptions::uninterpreted_option(int index) const { + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* EnumValueOptions::mutable_uninterpreted_option(int index) { + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* EnumValueOptions::add_uninterpreted_option() { + return uninterpreted_option_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +EnumValueOptions::uninterpreted_option() const { + return uninterpreted_option_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +EnumValueOptions::mutable_uninterpreted_option() { + return &uninterpreted_option_; +} + +// ------------------------------------------------------------------- + +// ServiceOptions + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int ServiceOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void ServiceOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& ServiceOptions::uninterpreted_option(int index) const { + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* ServiceOptions::mutable_uninterpreted_option(int index) { + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* ServiceOptions::add_uninterpreted_option() { + return uninterpreted_option_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +ServiceOptions::uninterpreted_option() const { + return uninterpreted_option_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +ServiceOptions::mutable_uninterpreted_option() { + return &uninterpreted_option_; +} + +// ------------------------------------------------------------------- + +// MethodOptions + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int MethodOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void MethodOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& MethodOptions::uninterpreted_option(int index) const { + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* MethodOptions::mutable_uninterpreted_option(int index) { + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* MethodOptions::add_uninterpreted_option() { + return uninterpreted_option_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +MethodOptions::uninterpreted_option() const { + return uninterpreted_option_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +MethodOptions::mutable_uninterpreted_option() { + return &uninterpreted_option_; +} + +// ------------------------------------------------------------------- + +// UninterpretedOption_NamePart + +// required string name_part = 1; +inline bool UninterpretedOption_NamePart::has_name_part() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void UninterpretedOption_NamePart::set_has_name_part() { + _has_bits_[0] |= 0x00000001u; +} +inline void UninterpretedOption_NamePart::clear_has_name_part() { + _has_bits_[0] &= ~0x00000001u; +} +inline void UninterpretedOption_NamePart::clear_name_part() { + if (name_part_ != &::google::protobuf::internal::kEmptyString) { + name_part_->clear(); + } + clear_has_name_part(); +} +inline const ::std::string& UninterpretedOption_NamePart::name_part() const { + return *name_part_; +} +inline void UninterpretedOption_NamePart::set_name_part(const ::std::string& value) { + set_has_name_part(); + if (name_part_ == &::google::protobuf::internal::kEmptyString) { + name_part_ = new ::std::string; + } + name_part_->assign(value); +} +inline void UninterpretedOption_NamePart::set_name_part(const char* value) { + set_has_name_part(); + if (name_part_ == &::google::protobuf::internal::kEmptyString) { + name_part_ = new ::std::string; + } + name_part_->assign(value); +} +inline void UninterpretedOption_NamePart::set_name_part(const char* value, size_t size) { + set_has_name_part(); + if (name_part_ == &::google::protobuf::internal::kEmptyString) { + name_part_ = new ::std::string; + } + name_part_->assign(reinterpret_cast(value), size); +} +inline ::std::string* UninterpretedOption_NamePart::mutable_name_part() { + set_has_name_part(); + if (name_part_ == &::google::protobuf::internal::kEmptyString) { + name_part_ = new ::std::string; + } + return name_part_; +} +inline ::std::string* UninterpretedOption_NamePart::release_name_part() { + clear_has_name_part(); + if (name_part_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = name_part_; + name_part_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// required bool is_extension = 2; +inline bool UninterpretedOption_NamePart::has_is_extension() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void UninterpretedOption_NamePart::set_has_is_extension() { + _has_bits_[0] |= 0x00000002u; +} +inline void UninterpretedOption_NamePart::clear_has_is_extension() { + _has_bits_[0] &= ~0x00000002u; +} +inline void UninterpretedOption_NamePart::clear_is_extension() { + is_extension_ = false; + clear_has_is_extension(); +} +inline bool UninterpretedOption_NamePart::is_extension() const { + return is_extension_; +} +inline void UninterpretedOption_NamePart::set_is_extension(bool value) { + set_has_is_extension(); + is_extension_ = value; +} + +// ------------------------------------------------------------------- + +// UninterpretedOption + +// repeated .google.protobuf.UninterpretedOption.NamePart name = 2; +inline int UninterpretedOption::name_size() const { + return name_.size(); +} +inline void UninterpretedOption::clear_name() { + name_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption_NamePart& UninterpretedOption::name(int index) const { + return name_.Get(index); +} +inline ::google::protobuf::UninterpretedOption_NamePart* UninterpretedOption::mutable_name(int index) { + return name_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption_NamePart* UninterpretedOption::add_name() { + return name_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >& +UninterpretedOption::name() const { + return name_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >* +UninterpretedOption::mutable_name() { + return &name_; +} + +// optional string identifier_value = 3; +inline bool UninterpretedOption::has_identifier_value() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void UninterpretedOption::set_has_identifier_value() { + _has_bits_[0] |= 0x00000002u; +} +inline void UninterpretedOption::clear_has_identifier_value() { + _has_bits_[0] &= ~0x00000002u; +} +inline void UninterpretedOption::clear_identifier_value() { + if (identifier_value_ != &::google::protobuf::internal::kEmptyString) { + identifier_value_->clear(); + } + clear_has_identifier_value(); +} +inline const ::std::string& UninterpretedOption::identifier_value() const { + return *identifier_value_; +} +inline void UninterpretedOption::set_identifier_value(const ::std::string& value) { + set_has_identifier_value(); + if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { + identifier_value_ = new ::std::string; + } + identifier_value_->assign(value); +} +inline void UninterpretedOption::set_identifier_value(const char* value) { + set_has_identifier_value(); + if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { + identifier_value_ = new ::std::string; + } + identifier_value_->assign(value); +} +inline void UninterpretedOption::set_identifier_value(const char* value, size_t size) { + set_has_identifier_value(); + if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { + identifier_value_ = new ::std::string; + } + identifier_value_->assign(reinterpret_cast(value), size); +} +inline ::std::string* UninterpretedOption::mutable_identifier_value() { + set_has_identifier_value(); + if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { + identifier_value_ = new ::std::string; + } + return identifier_value_; +} +inline ::std::string* UninterpretedOption::release_identifier_value() { + clear_has_identifier_value(); + if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = identifier_value_; + identifier_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional uint64 positive_int_value = 4; +inline bool UninterpretedOption::has_positive_int_value() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void UninterpretedOption::set_has_positive_int_value() { + _has_bits_[0] |= 0x00000004u; +} +inline void UninterpretedOption::clear_has_positive_int_value() { + _has_bits_[0] &= ~0x00000004u; +} +inline void UninterpretedOption::clear_positive_int_value() { + positive_int_value_ = GOOGLE_ULONGLONG(0); + clear_has_positive_int_value(); +} +inline ::google::protobuf::uint64 UninterpretedOption::positive_int_value() const { + return positive_int_value_; +} +inline void UninterpretedOption::set_positive_int_value(::google::protobuf::uint64 value) { + set_has_positive_int_value(); + positive_int_value_ = value; +} + +// optional int64 negative_int_value = 5; +inline bool UninterpretedOption::has_negative_int_value() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void UninterpretedOption::set_has_negative_int_value() { + _has_bits_[0] |= 0x00000008u; +} +inline void UninterpretedOption::clear_has_negative_int_value() { + _has_bits_[0] &= ~0x00000008u; +} +inline void UninterpretedOption::clear_negative_int_value() { + negative_int_value_ = GOOGLE_LONGLONG(0); + clear_has_negative_int_value(); +} +inline ::google::protobuf::int64 UninterpretedOption::negative_int_value() const { + return negative_int_value_; +} +inline void UninterpretedOption::set_negative_int_value(::google::protobuf::int64 value) { + set_has_negative_int_value(); + negative_int_value_ = value; +} + +// optional double double_value = 6; +inline bool UninterpretedOption::has_double_value() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void UninterpretedOption::set_has_double_value() { + _has_bits_[0] |= 0x00000010u; +} +inline void UninterpretedOption::clear_has_double_value() { + _has_bits_[0] &= ~0x00000010u; +} +inline void UninterpretedOption::clear_double_value() { + double_value_ = 0; + clear_has_double_value(); +} +inline double UninterpretedOption::double_value() const { + return double_value_; +} +inline void UninterpretedOption::set_double_value(double value) { + set_has_double_value(); + double_value_ = value; +} + +// optional bytes string_value = 7; +inline bool UninterpretedOption::has_string_value() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void UninterpretedOption::set_has_string_value() { + _has_bits_[0] |= 0x00000020u; +} +inline void UninterpretedOption::clear_has_string_value() { + _has_bits_[0] &= ~0x00000020u; +} +inline void UninterpretedOption::clear_string_value() { + if (string_value_ != &::google::protobuf::internal::kEmptyString) { + string_value_->clear(); + } + clear_has_string_value(); +} +inline const ::std::string& UninterpretedOption::string_value() const { + return *string_value_; +} +inline void UninterpretedOption::set_string_value(const ::std::string& value) { + set_has_string_value(); + if (string_value_ == &::google::protobuf::internal::kEmptyString) { + string_value_ = new ::std::string; + } + string_value_->assign(value); +} +inline void UninterpretedOption::set_string_value(const char* value) { + set_has_string_value(); + if (string_value_ == &::google::protobuf::internal::kEmptyString) { + string_value_ = new ::std::string; + } + string_value_->assign(value); +} +inline void UninterpretedOption::set_string_value(const void* value, size_t size) { + set_has_string_value(); + if (string_value_ == &::google::protobuf::internal::kEmptyString) { + string_value_ = new ::std::string; + } + string_value_->assign(reinterpret_cast(value), size); +} +inline ::std::string* UninterpretedOption::mutable_string_value() { + set_has_string_value(); + if (string_value_ == &::google::protobuf::internal::kEmptyString) { + string_value_ = new ::std::string; + } + return string_value_; +} +inline ::std::string* UninterpretedOption::release_string_value() { + clear_has_string_value(); + if (string_value_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = string_value_; + string_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string aggregate_value = 8; +inline bool UninterpretedOption::has_aggregate_value() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void UninterpretedOption::set_has_aggregate_value() { + _has_bits_[0] |= 0x00000040u; +} +inline void UninterpretedOption::clear_has_aggregate_value() { + _has_bits_[0] &= ~0x00000040u; +} +inline void UninterpretedOption::clear_aggregate_value() { + if (aggregate_value_ != &::google::protobuf::internal::kEmptyString) { + aggregate_value_->clear(); + } + clear_has_aggregate_value(); +} +inline const ::std::string& UninterpretedOption::aggregate_value() const { + return *aggregate_value_; +} +inline void UninterpretedOption::set_aggregate_value(const ::std::string& value) { + set_has_aggregate_value(); + if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { + aggregate_value_ = new ::std::string; + } + aggregate_value_->assign(value); +} +inline void UninterpretedOption::set_aggregate_value(const char* value) { + set_has_aggregate_value(); + if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { + aggregate_value_ = new ::std::string; + } + aggregate_value_->assign(value); +} +inline void UninterpretedOption::set_aggregate_value(const char* value, size_t size) { + set_has_aggregate_value(); + if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { + aggregate_value_ = new ::std::string; + } + aggregate_value_->assign(reinterpret_cast(value), size); +} +inline ::std::string* UninterpretedOption::mutable_aggregate_value() { + set_has_aggregate_value(); + if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { + aggregate_value_ = new ::std::string; + } + return aggregate_value_; +} +inline ::std::string* UninterpretedOption::release_aggregate_value() { + clear_has_aggregate_value(); + if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = aggregate_value_; + aggregate_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// SourceCodeInfo_Location + +// repeated int32 path = 1 [packed = true]; +inline int SourceCodeInfo_Location::path_size() const { + return path_.size(); +} +inline void SourceCodeInfo_Location::clear_path() { + path_.Clear(); +} +inline ::google::protobuf::int32 SourceCodeInfo_Location::path(int index) const { + return path_.Get(index); +} +inline void SourceCodeInfo_Location::set_path(int index, ::google::protobuf::int32 value) { + path_.Set(index, value); +} +inline void SourceCodeInfo_Location::add_path(::google::protobuf::int32 value) { + path_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +SourceCodeInfo_Location::path() const { + return path_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +SourceCodeInfo_Location::mutable_path() { + return &path_; +} + +// repeated int32 span = 2 [packed = true]; +inline int SourceCodeInfo_Location::span_size() const { + return span_.size(); +} +inline void SourceCodeInfo_Location::clear_span() { + span_.Clear(); +} +inline ::google::protobuf::int32 SourceCodeInfo_Location::span(int index) const { + return span_.Get(index); +} +inline void SourceCodeInfo_Location::set_span(int index, ::google::protobuf::int32 value) { + span_.Set(index, value); +} +inline void SourceCodeInfo_Location::add_span(::google::protobuf::int32 value) { + span_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +SourceCodeInfo_Location::span() const { + return span_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +SourceCodeInfo_Location::mutable_span() { + return &span_; +} + +// ------------------------------------------------------------------- + +// SourceCodeInfo + +// repeated .google.protobuf.SourceCodeInfo.Location location = 1; +inline int SourceCodeInfo::location_size() const { + return location_.size(); +} +inline void SourceCodeInfo::clear_location() { + location_.Clear(); +} +inline const ::google::protobuf::SourceCodeInfo_Location& SourceCodeInfo::location(int index) const { + return location_.Get(index); +} +inline ::google::protobuf::SourceCodeInfo_Location* SourceCodeInfo::mutable_location(int index) { + return location_.Mutable(index); +} +inline ::google::protobuf::SourceCodeInfo_Location* SourceCodeInfo::add_location() { + return location_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >& +SourceCodeInfo::location() const { + return location_; +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >* +SourceCodeInfo::mutable_location() { + return &location_; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf +} // namespace google + +#ifndef SWIG +namespace google { +namespace protobuf { + +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldDescriptorProto_Type>() { + return ::google::protobuf::FieldDescriptorProto_Type_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldDescriptorProto_Label>() { + return ::google::protobuf::FieldDescriptorProto_Label_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FileOptions_OptimizeMode>() { + return ::google::protobuf::FileOptions_OptimizeMode_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldOptions_CType>() { + return ::google::protobuf::FieldOptions_CType_descriptor(); +} + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h b/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h new file mode 100644 index 00000000..f32b1db9 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h @@ -0,0 +1,366 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Interface for manipulating databases of descriptors. + +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ +#define GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ + +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { + +// Defined in this file. +class DescriptorDatabase; +class SimpleDescriptorDatabase; +class EncodedDescriptorDatabase; +class DescriptorPoolDatabase; +class MergedDescriptorDatabase; + +// Abstract interface for a database of descriptors. +// +// This is useful if you want to create a DescriptorPool which loads +// descriptors on-demand from some sort of large database. If the database +// is large, it may be inefficient to enumerate every .proto file inside it +// calling DescriptorPool::BuildFile() for each one. Instead, a DescriptorPool +// can be created which wraps a DescriptorDatabase and only builds particular +// descriptors when they are needed. +class LIBPROTOBUF_EXPORT DescriptorDatabase { + public: + inline DescriptorDatabase() {} + virtual ~DescriptorDatabase(); + + // Find a file by file name. Fills in in *output and returns true if found. + // Otherwise, returns false, leaving the contents of *output undefined. + virtual bool FindFileByName(const string& filename, + FileDescriptorProto* output) = 0; + + // Find the file that declares the given fully-qualified symbol name. + // If found, fills in *output and returns true, otherwise returns false + // and leaves *output undefined. + virtual bool FindFileContainingSymbol(const string& symbol_name, + FileDescriptorProto* output) = 0; + + // Find the file which defines an extension extending the given message type + // with the given field number. If found, fills in *output and returns true, + // otherwise returns false and leaves *output undefined. containing_type + // must be a fully-qualified type name. + virtual bool FindFileContainingExtension(const string& containing_type, + int field_number, + FileDescriptorProto* output) = 0; + + // Finds the tag numbers used by all known extensions of + // extendee_type, and appends them to output in an undefined + // order. This method is best-effort: it's not guaranteed that the + // database will find all extensions, and it's not guaranteed that + // FindFileContainingExtension will return true on all of the found + // numbers. Returns true if the search was successful, otherwise + // returns false and leaves output unchanged. + // + // This method has a default implementation that always returns + // false. + virtual bool FindAllExtensionNumbers(const string& extendee_type, + vector* output) { + return false; + } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase); +}; + +// A DescriptorDatabase into which you can insert files manually. +// +// FindFileContainingSymbol() is fully-implemented. When you add a file, its +// symbols will be indexed for this purpose. Note that the implementation +// may return false positives, but only if it isn't possible for the symbol +// to be defined in any other file. In particular, if a file defines a symbol +// "Foo", then searching for "Foo.[anything]" will match that file. This way, +// the database does not need to aggressively index all children of a symbol. +// +// FindFileContainingExtension() is mostly-implemented. It works if and only +// if the original FieldDescriptorProto defining the extension has a +// fully-qualified type name in its "extendee" field (i.e. starts with a '.'). +// If the extendee is a relative name, SimpleDescriptorDatabase will not +// attempt to resolve the type, so it will not know what type the extension is +// extending. Therefore, calling FindFileContainingExtension() with the +// extension's containing type will never actually find that extension. Note +// that this is an unlikely problem, as all FileDescriptorProtos created by the +// protocol compiler (as well as ones created by calling +// FileDescriptor::CopyTo()) will always use fully-qualified names for all +// types. You only need to worry if you are constructing FileDescriptorProtos +// yourself, or are calling compiler::Parser directly. +class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { + public: + SimpleDescriptorDatabase(); + ~SimpleDescriptorDatabase(); + + // Adds the FileDescriptorProto to the database, making a copy. The object + // can be deleted after Add() returns. Returns false if the file conflicted + // with a file already in the database, in which case an error will have + // been written to GOOGLE_LOG(ERROR). + bool Add(const FileDescriptorProto& file); + + // Adds the FileDescriptorProto to the database and takes ownership of it. + bool AddAndOwn(const FileDescriptorProto* file); + + // implements DescriptorDatabase ----------------------------------- + bool FindFileByName(const string& filename, + FileDescriptorProto* output); + bool FindFileContainingSymbol(const string& symbol_name, + FileDescriptorProto* output); + bool FindFileContainingExtension(const string& containing_type, + int field_number, + FileDescriptorProto* output); + bool FindAllExtensionNumbers(const string& extendee_type, + vector* output); + + private: + // So that it can use DescriptorIndex. + friend class EncodedDescriptorDatabase; + + // An index mapping file names, symbol names, and extension numbers to + // some sort of values. + template + class DescriptorIndex { + public: + // Helpers to recursively add particular descriptors and all their contents + // to the index. + bool AddFile(const FileDescriptorProto& file, + Value value); + bool AddSymbol(const string& name, Value value); + bool AddNestedExtensions(const DescriptorProto& message_type, + Value value); + bool AddExtension(const FieldDescriptorProto& field, + Value value); + + Value FindFile(const string& filename); + Value FindSymbol(const string& name); + Value FindExtension(const string& containing_type, int field_number); + bool FindAllExtensionNumbers(const string& containing_type, + vector* output); + + private: + map by_name_; + map by_symbol_; + map, Value> by_extension_; + + // Invariant: The by_symbol_ map does not contain any symbols which are + // prefixes of other symbols in the map. For example, "foo.bar" is a + // prefix of "foo.bar.baz" (but is not a prefix of "foo.barbaz"). + // + // This invariant is important because it means that given a symbol name, + // we can find a key in the map which is a prefix of the symbol in O(lg n) + // time, and we know that there is at most one such key. + // + // The prefix lookup algorithm works like so: + // 1) Find the last key in the map which is less than or equal to the + // search key. + // 2) If the found key is a prefix of the search key, then return it. + // Otherwise, there is no match. + // + // I am sure this algorithm has been described elsewhere, but since I + // wasn't able to find it quickly I will instead prove that it works + // myself. The key to the algorithm is that if a match exists, step (1) + // will find it. Proof: + // 1) Define the "search key" to be the key we are looking for, the "found + // key" to be the key found in step (1), and the "match key" to be the + // key which actually matches the serach key (i.e. the key we're trying + // to find). + // 2) The found key must be less than or equal to the search key by + // definition. + // 3) The match key must also be less than or equal to the search key + // (because it is a prefix). + // 4) The match key cannot be greater than the found key, because if it + // were, then step (1) of the algorithm would have returned the match + // key instead (since it finds the *greatest* key which is less than or + // equal to the search key). + // 5) Therefore, the found key must be between the match key and the search + // key, inclusive. + // 6) Since the search key must be a sub-symbol of the match key, if it is + // not equal to the match key, then search_key[match_key.size()] must + // be '.'. + // 7) Since '.' sorts before any other character that is valid in a symbol + // name, then if the found key is not equal to the match key, then + // found_key[match_key.size()] must also be '.', because any other value + // would make it sort after the search key. + // 8) Therefore, if the found key is not equal to the match key, then the + // found key must be a sub-symbol of the match key. However, this would + // contradict our map invariant which says that no symbol in the map is + // a sub-symbol of any other. + // 9) Therefore, the found key must match the match key. + // + // The above proof assumes the match key exists. In the case that the + // match key does not exist, then step (1) will return some other symbol. + // That symbol cannot be a super-symbol of the search key since if it were, + // then it would be a match, and we're assuming the match key doesn't exist. + // Therefore, step 2 will correctly return no match. + + // Find the last entry in the by_symbol_ map whose key is less than or + // equal to the given name. + typename map::iterator FindLastLessOrEqual( + const string& name); + + // True if either the arguments are equal or super_symbol identifies a + // parent symbol of sub_symbol (e.g. "foo.bar" is a parent of + // "foo.bar.baz", but not a parent of "foo.barbaz"). + bool IsSubSymbol(const string& sub_symbol, const string& super_symbol); + + // Returns true if and only if all characters in the name are alphanumerics, + // underscores, or periods. + bool ValidateSymbolName(const string& name); + }; + + + DescriptorIndex index_; + vector files_to_delete_; + + // If file is non-NULL, copy it into *output and return true, otherwise + // return false. + bool MaybeCopy(const FileDescriptorProto* file, + FileDescriptorProto* output); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase); +}; + +// Very similar to SimpleDescriptorDatabase, but stores all the descriptors +// as raw bytes and generally tries to use as little memory as possible. +// +// The same caveats regarding FindFileContainingExtension() apply as with +// SimpleDescriptorDatabase. +class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { + public: + EncodedDescriptorDatabase(); + ~EncodedDescriptorDatabase(); + + // Adds the FileDescriptorProto to the database. The descriptor is provided + // in encoded form. The database does not make a copy of the bytes, nor + // does it take ownership; it's up to the caller to make sure the bytes + // remain valid for the life of the database. Returns false and logs an error + // if the bytes are not a valid FileDescriptorProto or if the file conflicted + // with a file already in the database. + bool Add(const void* encoded_file_descriptor, int size); + + // Like Add(), but makes a copy of the data, so that the caller does not + // need to keep it around. + bool AddCopy(const void* encoded_file_descriptor, int size); + + // Like FindFileContainingSymbol but returns only the name of the file. + bool FindNameOfFileContainingSymbol(const string& symbol_name, + string* output); + + // implements DescriptorDatabase ----------------------------------- + bool FindFileByName(const string& filename, + FileDescriptorProto* output); + bool FindFileContainingSymbol(const string& symbol_name, + FileDescriptorProto* output); + bool FindFileContainingExtension(const string& containing_type, + int field_number, + FileDescriptorProto* output); + bool FindAllExtensionNumbers(const string& extendee_type, + vector* output); + + private: + SimpleDescriptorDatabase::DescriptorIndex > index_; + vector files_to_delete_; + + // If encoded_file.first is non-NULL, parse the data into *output and return + // true, otherwise return false. + bool MaybeParse(pair encoded_file, + FileDescriptorProto* output); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase); +}; + +// A DescriptorDatabase that fetches files from a given pool. +class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { + public: + DescriptorPoolDatabase(const DescriptorPool& pool); + ~DescriptorPoolDatabase(); + + // implements DescriptorDatabase ----------------------------------- + bool FindFileByName(const string& filename, + FileDescriptorProto* output); + bool FindFileContainingSymbol(const string& symbol_name, + FileDescriptorProto* output); + bool FindFileContainingExtension(const string& containing_type, + int field_number, + FileDescriptorProto* output); + bool FindAllExtensionNumbers(const string& extendee_type, + vector* output); + + private: + const DescriptorPool& pool_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase); +}; + +// A DescriptorDatabase that wraps two or more others. It first searches the +// first database and, if that fails, tries the second, and so on. +class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { + public: + // Merge just two databases. The sources remain property of the caller. + MergedDescriptorDatabase(DescriptorDatabase* source1, + DescriptorDatabase* source2); + // Merge more than two databases. The sources remain property of the caller. + // The vector may be deleted after the constructor returns but the + // DescriptorDatabases need to stick around. + MergedDescriptorDatabase(const vector& sources); + ~MergedDescriptorDatabase(); + + // implements DescriptorDatabase ----------------------------------- + bool FindFileByName(const string& filename, + FileDescriptorProto* output); + bool FindFileContainingSymbol(const string& symbol_name, + FileDescriptorProto* output); + bool FindFileContainingExtension(const string& containing_type, + int field_number, + FileDescriptorProto* output); + // Merges the results of calling all databases. Returns true iff any + // of the databases returned true. + bool FindAllExtensionNumbers(const string& extendee_type, + vector* output); + + private: + vector sources_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h b/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h new file mode 100644 index 00000000..81dd2c63 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h @@ -0,0 +1,136 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Defines an implementation of Message which can emulate types which are not +// known at compile-time. + +#ifndef GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ +#define GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ + +#include +#include + +namespace google { +namespace protobuf { + +// Defined in other files. +class Descriptor; // descriptor.h +class DescriptorPool; // descriptor.h + +// Constructs implementations of Message which can emulate types which are not +// known at compile-time. +// +// Sometimes you want to be able to manipulate protocol types that you don't +// know about at compile time. It would be nice to be able to construct +// a Message object which implements the message type given by any arbitrary +// Descriptor. DynamicMessage provides this. +// +// As it turns out, a DynamicMessage needs to construct extra +// information about its type in order to operate. Most of this information +// can be shared between all DynamicMessages of the same type. But, caching +// this information in some sort of global map would be a bad idea, since +// the cached information for a particular descriptor could outlive the +// descriptor itself. To avoid this problem, DynamicMessageFactory +// encapsulates this "cache". All DynamicMessages of the same type created +// from the same factory will share the same support data. Any Descriptors +// used with a particular factory must outlive the factory. +class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { + public: + // Construct a DynamicMessageFactory that will search for extensions in + // the DescriptorPool in which the exendee is defined. + DynamicMessageFactory(); + + // Construct a DynamicMessageFactory that will search for extensions in + // the given DescriptorPool. + // + // DEPRECATED: Use CodedInputStream::SetExtensionRegistry() to tell the + // parser to look for extensions in an alternate pool. However, note that + // this is almost never what you want to do. Almost all users should use + // the zero-arg constructor. + DynamicMessageFactory(const DescriptorPool* pool); + + ~DynamicMessageFactory(); + + // Call this to tell the DynamicMessageFactory that if it is given a + // Descriptor d for which: + // d->file()->pool() == DescriptorPool::generated_pool(), + // then it should delegate to MessageFactory::generated_factory() instead + // of constructing a dynamic implementation of the message. In theory there + // is no down side to doing this, so it may become the default in the future. + void SetDelegateToGeneratedFactory(bool enable) { + delegate_to_generated_factory_ = enable; + } + + // implements MessageFactory --------------------------------------- + + // Given a Descriptor, constructs the default (prototype) Message of that + // type. You can then call that message's New() method to construct a + // mutable message of that type. + // + // Calling this method twice with the same Descriptor returns the same + // object. The returned object remains property of the factory and will + // be destroyed when the factory is destroyed. Also, any objects created + // by calling the prototype's New() method share some data with the + // prototype, so these must be destoyed before the DynamicMessageFactory + // is destroyed. + // + // The given descriptor must outlive the returned message, and hence must + // outlive the DynamicMessageFactory. + // + // The method is thread-safe. + const Message* GetPrototype(const Descriptor* type); + + private: + const DescriptorPool* pool_; + bool delegate_to_generated_factory_; + + // This struct just contains a hash_map. We can't #include from + // this header due to hacks needed for hash_map portability in the open source + // release. Namely, stubs/hash.h, which defines hash_map portably, is not a + // public header (for good reason), but dynamic_message.h is, and public + // headers may only #include other public headers. + struct PrototypeMap; + scoped_ptr prototypes_; + mutable Mutex prototypes_mutex_; + + friend class DynamicMessage; + const Message* GetPrototypeNoLock(const Descriptor* type); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h b/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h new file mode 100644 index 00000000..ac1ada02 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h @@ -0,0 +1,904 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This header is logically internal, but is made public because it is used +// from protocol-compiler-generated code, which may reside in other components. + +#ifndef GOOGLE_PROTOBUF_EXTENSION_SET_H__ +#define GOOGLE_PROTOBUF_EXTENSION_SET_H__ + +#include +#include +#include +#include + + +#include + +namespace google { + +namespace protobuf { + class Descriptor; // descriptor.h + class FieldDescriptor; // descriptor.h + class DescriptorPool; // descriptor.h + class MessageLite; // message_lite.h + class Message; // message.h + class MessageFactory; // message.h + class UnknownFieldSet; // unknown_field_set.h + namespace io { + class CodedInputStream; // coded_stream.h + class CodedOutputStream; // coded_stream.h + } + namespace internal { + class FieldSkipper; // wire_format_lite.h + class RepeatedPtrFieldBase; // repeated_field.h + } + template class RepeatedField; // repeated_field.h + template class RepeatedPtrField; // repeated_field.h +} + +namespace protobuf { +namespace internal { + +// Used to store values of type WireFormatLite::FieldType without having to +// #include wire_format_lite.h. Also, ensures that we use only one byte to +// store these values, which is important to keep the layout of +// ExtensionSet::Extension small. +typedef uint8 FieldType; + +// A function which, given an integer value, returns true if the number +// matches one of the defined values for the corresponding enum type. This +// is used with RegisterEnumExtension, below. +typedef bool EnumValidityFunc(int number); + +// Version of the above which takes an argument. This is needed to deal with +// extensions that are not compiled in. +typedef bool EnumValidityFuncWithArg(const void* arg, int number); + +// Information about a registered extension. +struct ExtensionInfo { + inline ExtensionInfo() {} + inline ExtensionInfo(FieldType type, bool is_repeated, bool is_packed) + : type(type), is_repeated(is_repeated), is_packed(is_packed), + descriptor(NULL) {} + + FieldType type; + bool is_repeated; + bool is_packed; + + struct EnumValidityCheck { + EnumValidityFuncWithArg* func; + const void* arg; + }; + + union { + EnumValidityCheck enum_validity_check; + const MessageLite* message_prototype; + }; + + // The descriptor for this extension, if one exists and is known. May be + // NULL. Must not be NULL if the descriptor for the extension does not + // live in the same pool as the descriptor for the containing type. + const FieldDescriptor* descriptor; +}; + +// Abstract interface for an object which looks up extension definitions. Used +// when parsing. +class LIBPROTOBUF_EXPORT ExtensionFinder { + public: + virtual ~ExtensionFinder(); + + // Find the extension with the given containing type and number. + virtual bool Find(int number, ExtensionInfo* output) = 0; +}; + +// Implementation of ExtensionFinder which finds extensions defined in .proto +// files which have been compiled into the binary. +class LIBPROTOBUF_EXPORT GeneratedExtensionFinder : public ExtensionFinder { + public: + GeneratedExtensionFinder(const MessageLite* containing_type) + : containing_type_(containing_type) {} + virtual ~GeneratedExtensionFinder() {} + + // Returns true and fills in *output if found, otherwise returns false. + virtual bool Find(int number, ExtensionInfo* output); + + private: + const MessageLite* containing_type_; +}; + +// Note: extension_set_heavy.cc defines DescriptorPoolExtensionFinder for +// finding extensions from a DescriptorPool. + +// This is an internal helper class intended for use within the protocol buffer +// library and generated classes. Clients should not use it directly. Instead, +// use the generated accessors such as GetExtension() of the class being +// extended. +// +// This class manages extensions for a protocol message object. The +// message's HasExtension(), GetExtension(), MutableExtension(), and +// ClearExtension() methods are just thin wrappers around the embedded +// ExtensionSet. When parsing, if a tag number is encountered which is +// inside one of the message type's extension ranges, the tag is passed +// off to the ExtensionSet for parsing. Etc. +class LIBPROTOBUF_EXPORT ExtensionSet { + public: + ExtensionSet(); + ~ExtensionSet(); + + // These are called at startup by protocol-compiler-generated code to + // register known extensions. The registrations are used by ParseField() + // to look up extensions for parsed field numbers. Note that dynamic parsing + // does not use ParseField(); only protocol-compiler-generated parsing + // methods do. + static void RegisterExtension(const MessageLite* containing_type, + int number, FieldType type, + bool is_repeated, bool is_packed); + static void RegisterEnumExtension(const MessageLite* containing_type, + int number, FieldType type, + bool is_repeated, bool is_packed, + EnumValidityFunc* is_valid); + static void RegisterMessageExtension(const MessageLite* containing_type, + int number, FieldType type, + bool is_repeated, bool is_packed, + const MessageLite* prototype); + + // ================================================================= + + // Add all fields which are currently present to the given vector. This + // is useful to implement Reflection::ListFields(). + void AppendToList(const Descriptor* containing_type, + const DescriptorPool* pool, + vector* output) const; + + // ================================================================= + // Accessors + // + // Generated message classes include type-safe templated wrappers around + // these methods. Generally you should use those rather than call these + // directly, unless you are doing low-level memory management. + // + // When calling any of these accessors, the extension number requested + // MUST exist in the DescriptorPool provided to the constructor. Otheriwse, + // the method will fail an assert. Normally, though, you would not call + // these directly; you would either call the generated accessors of your + // message class (e.g. GetExtension()) or you would call the accessors + // of the reflection interface. In both cases, it is impossible to + // trigger this assert failure: the generated accessors only accept + // linked-in extension types as parameters, while the Reflection interface + // requires you to provide the FieldDescriptor describing the extension. + // + // When calling any of these accessors, a protocol-compiler-generated + // implementation of the extension corresponding to the number MUST + // be linked in, and the FieldDescriptor used to refer to it MUST be + // the one generated by that linked-in code. Otherwise, the method will + // die on an assert failure. The message objects returned by the message + // accessors are guaranteed to be of the correct linked-in type. + // + // These methods pretty much match Reflection except that: + // - They're not virtual. + // - They identify fields by number rather than FieldDescriptors. + // - They identify enum values using integers rather than descriptors. + // - Strings provide Mutable() in addition to Set() accessors. + + bool Has(int number) const; + int ExtensionSize(int number) const; // Size of a repeated extension. + FieldType ExtensionType(int number) const; + void ClearExtension(int number); + + // singular fields ------------------------------------------------- + + int32 GetInt32 (int number, int32 default_value) const; + int64 GetInt64 (int number, int64 default_value) const; + uint32 GetUInt32(int number, uint32 default_value) const; + uint64 GetUInt64(int number, uint64 default_value) const; + float GetFloat (int number, float default_value) const; + double GetDouble(int number, double default_value) const; + bool GetBool (int number, bool default_value) const; + int GetEnum (int number, int default_value) const; + const string & GetString (int number, const string& default_value) const; + const MessageLite& GetMessage(int number, + const MessageLite& default_value) const; + const MessageLite& GetMessage(int number, const Descriptor* message_type, + MessageFactory* factory) const; + + // |descriptor| may be NULL so long as it is known that the descriptor for + // the extension lives in the same pool as the descriptor for the containing + // type. +#define desc const FieldDescriptor* descriptor // avoid line wrapping + void SetInt32 (int number, FieldType type, int32 value, desc); + void SetInt64 (int number, FieldType type, int64 value, desc); + void SetUInt32(int number, FieldType type, uint32 value, desc); + void SetUInt64(int number, FieldType type, uint64 value, desc); + void SetFloat (int number, FieldType type, float value, desc); + void SetDouble(int number, FieldType type, double value, desc); + void SetBool (int number, FieldType type, bool value, desc); + void SetEnum (int number, FieldType type, int value, desc); + void SetString(int number, FieldType type, const string& value, desc); + string * MutableString (int number, FieldType type, desc); + MessageLite* MutableMessage(int number, FieldType type, + const MessageLite& prototype, desc); + MessageLite* MutableMessage(const FieldDescriptor* decsriptor, + MessageFactory* factory); +#undef desc + + // repeated fields ------------------------------------------------- + + int32 GetRepeatedInt32 (int number, int index) const; + int64 GetRepeatedInt64 (int number, int index) const; + uint32 GetRepeatedUInt32(int number, int index) const; + uint64 GetRepeatedUInt64(int number, int index) const; + float GetRepeatedFloat (int number, int index) const; + double GetRepeatedDouble(int number, int index) const; + bool GetRepeatedBool (int number, int index) const; + int GetRepeatedEnum (int number, int index) const; + const string & GetRepeatedString (int number, int index) const; + const MessageLite& GetRepeatedMessage(int number, int index) const; + + void SetRepeatedInt32 (int number, int index, int32 value); + void SetRepeatedInt64 (int number, int index, int64 value); + void SetRepeatedUInt32(int number, int index, uint32 value); + void SetRepeatedUInt64(int number, int index, uint64 value); + void SetRepeatedFloat (int number, int index, float value); + void SetRepeatedDouble(int number, int index, double value); + void SetRepeatedBool (int number, int index, bool value); + void SetRepeatedEnum (int number, int index, int value); + void SetRepeatedString(int number, int index, const string& value); + string * MutableRepeatedString (int number, int index); + MessageLite* MutableRepeatedMessage(int number, int index); + +#define desc const FieldDescriptor* descriptor // avoid line wrapping + void AddInt32 (int number, FieldType type, bool packed, int32 value, desc); + void AddInt64 (int number, FieldType type, bool packed, int64 value, desc); + void AddUInt32(int number, FieldType type, bool packed, uint32 value, desc); + void AddUInt64(int number, FieldType type, bool packed, uint64 value, desc); + void AddFloat (int number, FieldType type, bool packed, float value, desc); + void AddDouble(int number, FieldType type, bool packed, double value, desc); + void AddBool (int number, FieldType type, bool packed, bool value, desc); + void AddEnum (int number, FieldType type, bool packed, int value, desc); + void AddString(int number, FieldType type, const string& value, desc); + string * AddString (int number, FieldType type, desc); + MessageLite* AddMessage(int number, FieldType type, + const MessageLite& prototype, desc); + MessageLite* AddMessage(const FieldDescriptor* descriptor, + MessageFactory* factory); +#undef desc + + void RemoveLast(int number); + void SwapElements(int number, int index1, int index2); + + // ----------------------------------------------------------------- + // TODO(kenton): Hardcore memory management accessors + + // ================================================================= + // convenience methods for implementing methods of Message + // + // These could all be implemented in terms of the other methods of this + // class, but providing them here helps keep the generated code size down. + + void Clear(); + void MergeFrom(const ExtensionSet& other); + void Swap(ExtensionSet* other); + bool IsInitialized() const; + + // Parses a single extension from the input. The input should start out + // positioned immediately after the tag. |containing_type| is the default + // instance for the containing message; it is used only to look up the + // extension by number. See RegisterExtension(), above. Unlike the other + // methods of ExtensionSet, this only works for generated message types -- + // it looks up extensions registered using RegisterExtension(). + bool ParseField(uint32 tag, io::CodedInputStream* input, + ExtensionFinder* extension_finder, + FieldSkipper* field_skipper); + + // Specific versions for lite or full messages (constructs the appropriate + // FieldSkipper automatically). + bool ParseField(uint32 tag, io::CodedInputStream* input, + const MessageLite* containing_type); + bool ParseField(uint32 tag, io::CodedInputStream* input, + const Message* containing_type, + UnknownFieldSet* unknown_fields); + + // Parse an entire message in MessageSet format. Such messages have no + // fields, only extensions. + bool ParseMessageSet(io::CodedInputStream* input, + ExtensionFinder* extension_finder, + FieldSkipper* field_skipper); + + // Specific versions for lite or full messages (constructs the appropriate + // FieldSkipper automatically). + bool ParseMessageSet(io::CodedInputStream* input, + const MessageLite* containing_type); + bool ParseMessageSet(io::CodedInputStream* input, + const Message* containing_type, + UnknownFieldSet* unknown_fields); + + // Write all extension fields with field numbers in the range + // [start_field_number, end_field_number) + // to the output stream, using the cached sizes computed when ByteSize() was + // last called. Note that the range bounds are inclusive-exclusive. + void SerializeWithCachedSizes(int start_field_number, + int end_field_number, + io::CodedOutputStream* output) const; + + // Same as SerializeWithCachedSizes, but without any bounds checking. + // The caller must ensure that target has sufficient capacity for the + // serialized extensions. + // + // Returns a pointer past the last written byte. + uint8* SerializeWithCachedSizesToArray(int start_field_number, + int end_field_number, + uint8* target) const; + + // Like above but serializes in MessageSet format. + void SerializeMessageSetWithCachedSizes(io::CodedOutputStream* output) const; + uint8* SerializeMessageSetWithCachedSizesToArray(uint8* target) const; + + // Returns the total serialized size of all the extensions. + int ByteSize() const; + + // Like ByteSize() but uses MessageSet format. + int MessageSetByteSize() const; + + // Returns (an estimate of) the total number of bytes used for storing the + // extensions in memory, excluding sizeof(*this). If the ExtensionSet is + // for a lite message (and thus possibly contains lite messages), the results + // are undefined (might work, might crash, might corrupt data, might not even + // be linked in). It's up to the protocol compiler to avoid calling this on + // such ExtensionSets (easy enough since lite messages don't implement + // SpaceUsed()). + int SpaceUsedExcludingSelf() const; + + private: + + struct Extension { + union { + int32 int32_value; + int64 int64_value; + uint32 uint32_value; + uint64 uint64_value; + float float_value; + double double_value; + bool bool_value; + int enum_value; + string* string_value; + MessageLite* message_value; + + RepeatedField * repeated_int32_value; + RepeatedField * repeated_int64_value; + RepeatedField * repeated_uint32_value; + RepeatedField * repeated_uint64_value; + RepeatedField * repeated_float_value; + RepeatedField * repeated_double_value; + RepeatedField * repeated_bool_value; + RepeatedField * repeated_enum_value; + RepeatedPtrField* repeated_string_value; + RepeatedPtrField* repeated_message_value; + }; + + FieldType type; + bool is_repeated; + + // For singular types, indicates if the extension is "cleared". This + // happens when an extension is set and then later cleared by the caller. + // We want to keep the Extension object around for reuse, so instead of + // removing it from the map, we just set is_cleared = true. This has no + // meaning for repeated types; for those, the size of the RepeatedField + // simply becomes zero when cleared. + bool is_cleared; + + // For repeated types, this indicates if the [packed=true] option is set. + bool is_packed; + + // The descriptor for this extension, if one exists and is known. May be + // NULL. Must not be NULL if the descriptor for the extension does not + // live in the same pool as the descriptor for the containing type. + const FieldDescriptor* descriptor; + + // For packed fields, the size of the packed data is recorded here when + // ByteSize() is called then used during serialization. + // TODO(kenton): Use atomic when C++ supports it. + mutable int cached_size; + + // Some helper methods for operations on a single Extension. + void SerializeFieldWithCachedSizes( + int number, + io::CodedOutputStream* output) const; + uint8* SerializeFieldWithCachedSizesToArray( + int number, + uint8* target) const; + void SerializeMessageSetItemWithCachedSizes( + int number, + io::CodedOutputStream* output) const; + uint8* SerializeMessageSetItemWithCachedSizesToArray( + int number, + uint8* target) const; + int ByteSize(int number) const; + int MessageSetItemByteSize(int number) const; + void Clear(); + int GetSize() const; + void Free(); + int SpaceUsedExcludingSelf() const; + }; + + + // Gets the extension with the given number, creating it if it does not + // already exist. Returns true if the extension did not already exist. + bool MaybeNewExtension(int number, const FieldDescriptor* descriptor, + Extension** result); + + // Parse a single MessageSet item -- called just after the item group start + // tag has been read. + bool ParseMessageSetItem(io::CodedInputStream* input, + ExtensionFinder* extension_finder, + FieldSkipper* field_skipper); + + + // Hack: RepeatedPtrFieldBase declares ExtensionSet as a friend. This + // friendship should automatically extend to ExtensionSet::Extension, but + // unfortunately some older compilers (e.g. GCC 3.4.4) do not implement this + // correctly. So, we must provide helpers for calling methods of that + // class. + + // Defined in extension_set_heavy.cc. + static inline int RepeatedMessage_SpaceUsedExcludingSelf( + RepeatedPtrFieldBase* field); + + // The Extension struct is small enough to be passed by value, so we use it + // directly as the value type in the map rather than use pointers. We use + // a map rather than hash_map here because we expect most ExtensionSets will + // only contain a small number of extensions whereas hash_map is optimized + // for 100 elements or more. Also, we want AppendToList() to order fields + // by field number. + map extensions_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionSet); +}; + +// These are just for convenience... +inline void ExtensionSet::SetString(int number, FieldType type, + const string& value, + const FieldDescriptor* descriptor) { + MutableString(number, type, descriptor)->assign(value); +} +inline void ExtensionSet::SetRepeatedString(int number, int index, + const string& value) { + MutableRepeatedString(number, index)->assign(value); +} +inline void ExtensionSet::AddString(int number, FieldType type, + const string& value, + const FieldDescriptor* descriptor) { + AddString(number, type, descriptor)->assign(value); +} + +// =================================================================== +// Glue for generated extension accessors + +// ------------------------------------------------------------------- +// Template magic + +// First we have a set of classes representing "type traits" for different +// field types. A type traits class knows how to implement basic accessors +// for extensions of a particular type given an ExtensionSet. The signature +// for a type traits class looks like this: +// +// class TypeTraits { +// public: +// typedef ? ConstType; +// typedef ? MutableType; +// +// static inline ConstType Get(int number, const ExtensionSet& set); +// static inline void Set(int number, ConstType value, ExtensionSet* set); +// static inline MutableType Mutable(int number, ExtensionSet* set); +// +// // Variants for repeated fields. +// static inline ConstType Get(int number, const ExtensionSet& set, +// int index); +// static inline void Set(int number, int index, +// ConstType value, ExtensionSet* set); +// static inline MutableType Mutable(int number, int index, +// ExtensionSet* set); +// static inline void Add(int number, ConstType value, ExtensionSet* set); +// static inline MutableType Add(int number, ExtensionSet* set); +// }; +// +// Not all of these methods make sense for all field types. For example, the +// "Mutable" methods only make sense for strings and messages, and the +// repeated methods only make sense for repeated types. So, each type +// traits class implements only the set of methods from this signature that it +// actually supports. This will cause a compiler error if the user tries to +// access an extension using a method that doesn't make sense for its type. +// For example, if "foo" is an extension of type "optional int32", then if you +// try to write code like: +// my_message.MutableExtension(foo) +// you will get a compile error because PrimitiveTypeTraits does not +// have a "Mutable()" method. + +// ------------------------------------------------------------------- +// PrimitiveTypeTraits + +// Since the ExtensionSet has different methods for each primitive type, +// we must explicitly define the methods of the type traits class for each +// known type. +template +class PrimitiveTypeTraits { + public: + typedef Type ConstType; + + static inline ConstType Get(int number, const ExtensionSet& set, + ConstType default_value); + static inline void Set(int number, FieldType field_type, + ConstType value, ExtensionSet* set); +}; + +template +class RepeatedPrimitiveTypeTraits { + public: + typedef Type ConstType; + + static inline Type Get(int number, const ExtensionSet& set, int index); + static inline void Set(int number, int index, Type value, ExtensionSet* set); + static inline void Add(int number, FieldType field_type, + bool is_packed, Type value, ExtensionSet* set); +}; + +#define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \ +template<> inline TYPE PrimitiveTypeTraits::Get( \ + int number, const ExtensionSet& set, TYPE default_value) { \ + return set.Get##METHOD(number, default_value); \ +} \ +template<> inline void PrimitiveTypeTraits::Set( \ + int number, FieldType field_type, TYPE value, ExtensionSet* set) { \ + set->Set##METHOD(number, field_type, value, NULL); \ +} \ + \ +template<> inline TYPE RepeatedPrimitiveTypeTraits::Get( \ + int number, const ExtensionSet& set, int index) { \ + return set.GetRepeated##METHOD(number, index); \ +} \ +template<> inline void RepeatedPrimitiveTypeTraits::Set( \ + int number, int index, TYPE value, ExtensionSet* set) { \ + set->SetRepeated##METHOD(number, index, value); \ +} \ +template<> inline void RepeatedPrimitiveTypeTraits::Add( \ + int number, FieldType field_type, bool is_packed, \ + TYPE value, ExtensionSet* set) { \ + set->Add##METHOD(number, field_type, is_packed, value, NULL); \ +} + +PROTOBUF_DEFINE_PRIMITIVE_TYPE( int32, Int32) +PROTOBUF_DEFINE_PRIMITIVE_TYPE( int64, Int64) +PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint32, UInt32) +PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint64, UInt64) +PROTOBUF_DEFINE_PRIMITIVE_TYPE( float, Float) +PROTOBUF_DEFINE_PRIMITIVE_TYPE(double, Double) +PROTOBUF_DEFINE_PRIMITIVE_TYPE( bool, Bool) + +#undef PROTOBUF_DEFINE_PRIMITIVE_TYPE + +// ------------------------------------------------------------------- +// StringTypeTraits + +// Strings support both Set() and Mutable(). +class LIBPROTOBUF_EXPORT StringTypeTraits { + public: + typedef const string& ConstType; + typedef string* MutableType; + + static inline const string& Get(int number, const ExtensionSet& set, + ConstType default_value) { + return set.GetString(number, default_value); + } + static inline void Set(int number, FieldType field_type, + const string& value, ExtensionSet* set) { + set->SetString(number, field_type, value, NULL); + } + static inline string* Mutable(int number, FieldType field_type, + ExtensionSet* set) { + return set->MutableString(number, field_type, NULL); + } +}; + +class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { + public: + typedef const string& ConstType; + typedef string* MutableType; + + static inline const string& Get(int number, const ExtensionSet& set, + int index) { + return set.GetRepeatedString(number, index); + } + static inline void Set(int number, int index, + const string& value, ExtensionSet* set) { + set->SetRepeatedString(number, index, value); + } + static inline string* Mutable(int number, int index, ExtensionSet* set) { + return set->MutableRepeatedString(number, index); + } + static inline void Add(int number, FieldType field_type, + bool /*is_packed*/, const string& value, + ExtensionSet* set) { + set->AddString(number, field_type, value, NULL); + } + static inline string* Add(int number, FieldType field_type, + ExtensionSet* set) { + return set->AddString(number, field_type, NULL); + } +}; + +// ------------------------------------------------------------------- +// EnumTypeTraits + +// ExtensionSet represents enums using integers internally, so we have to +// static_cast around. +template +class EnumTypeTraits { + public: + typedef Type ConstType; + + static inline ConstType Get(int number, const ExtensionSet& set, + ConstType default_value) { + return static_cast(set.GetEnum(number, default_value)); + } + static inline void Set(int number, FieldType field_type, + ConstType value, ExtensionSet* set) { + GOOGLE_DCHECK(IsValid(value)); + set->SetEnum(number, field_type, value, NULL); + } +}; + +template +class RepeatedEnumTypeTraits { + public: + typedef Type ConstType; + + static inline ConstType Get(int number, const ExtensionSet& set, int index) { + return static_cast(set.GetRepeatedEnum(number, index)); + } + static inline void Set(int number, int index, + ConstType value, ExtensionSet* set) { + GOOGLE_DCHECK(IsValid(value)); + set->SetRepeatedEnum(number, index, value); + } + static inline void Add(int number, FieldType field_type, + bool is_packed, ConstType value, ExtensionSet* set) { + GOOGLE_DCHECK(IsValid(value)); + set->AddEnum(number, field_type, is_packed, value, NULL); + } +}; + +// ------------------------------------------------------------------- +// MessageTypeTraits + +// ExtensionSet guarantees that when manipulating extensions with message +// types, the implementation used will be the compiled-in class representing +// that type. So, we can static_cast down to the exact type we expect. +template +class MessageTypeTraits { + public: + typedef const Type& ConstType; + typedef Type* MutableType; + + static inline ConstType Get(int number, const ExtensionSet& set, + ConstType default_value) { + return static_cast( + set.GetMessage(number, default_value)); + } + static inline MutableType Mutable(int number, FieldType field_type, + ExtensionSet* set) { + return static_cast( + set->MutableMessage(number, field_type, Type::default_instance(), NULL)); + } +}; + +template +class RepeatedMessageTypeTraits { + public: + typedef const Type& ConstType; + typedef Type* MutableType; + + static inline ConstType Get(int number, const ExtensionSet& set, int index) { + return static_cast(set.GetRepeatedMessage(number, index)); + } + static inline MutableType Mutable(int number, int index, ExtensionSet* set) { + return static_cast(set->MutableRepeatedMessage(number, index)); + } + static inline MutableType Add(int number, FieldType field_type, + ExtensionSet* set) { + return static_cast( + set->AddMessage(number, field_type, Type::default_instance(), NULL)); + } +}; + +// ------------------------------------------------------------------- +// ExtensionIdentifier + +// This is the type of actual extension objects. E.g. if you have: +// extends Foo with optional int32 bar = 1234; +// then "bar" will be defined in C++ as: +// ExtensionIdentifier, 1, false> bar(1234); +// +// Note that we could, in theory, supply the field number as a template +// parameter, and thus make an instance of ExtensionIdentifier have no +// actual contents. However, if we did that, then using at extension +// identifier would not necessarily cause the compiler to output any sort +// of reference to any simple defined in the extension's .pb.o file. Some +// linkers will actually drop object files that are not explicitly referenced, +// but that would be bad because it would cause this extension to not be +// registered at static initialization, and therefore using it would crash. + +template +class ExtensionIdentifier { + public: + typedef TypeTraitsType TypeTraits; + typedef ExtendeeType Extendee; + + ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value) + : number_(number), default_value_(default_value) {} + inline int number() const { return number_; } + typename TypeTraits::ConstType default_value() const { + return default_value_; + } + + private: + const int number_; + typename TypeTraits::ConstType default_value_; +}; + +// ------------------------------------------------------------------- +// Generated accessors + +// This macro should be expanded in the context of a generated type which +// has extensions. +// +// We use "_proto_TypeTraits" as a type name below because "TypeTraits" +// causes problems if the class has a nested message or enum type with that +// name and "_TypeTraits" is technically reserved for the C++ library since +// it starts with an underscore followed by a capital letter. +#define GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(CLASSNAME) \ + /* Has, Size, Clear */ \ + template \ + inline bool HasExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) const { \ + return _extensions_.Has(id.number()); \ + } \ + \ + template \ + inline void ClearExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) { \ + _extensions_.ClearExtension(id.number()); \ + } \ + \ + template \ + inline int ExtensionSize( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) const { \ + return _extensions_.ExtensionSize(id.number()); \ + } \ + \ + /* Singular accessors */ \ + template \ + inline typename _proto_TypeTraits::ConstType GetExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) const { \ + return _proto_TypeTraits::Get(id.number(), _extensions_, \ + id.default_value()); \ + } \ + \ + template \ + inline typename _proto_TypeTraits::MutableType MutableExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) { \ + return _proto_TypeTraits::Mutable(id.number(), field_type, &_extensions_);\ + } \ + \ + template \ + inline void SetExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ + typename _proto_TypeTraits::ConstType value) { \ + _proto_TypeTraits::Set(id.number(), field_type, value, &_extensions_); \ + } \ + \ + /* Repeated accessors */ \ + template \ + inline typename _proto_TypeTraits::ConstType GetExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ + int index) const { \ + return _proto_TypeTraits::Get(id.number(), _extensions_, index); \ + } \ + \ + template \ + inline typename _proto_TypeTraits::MutableType MutableExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ + int index) { \ + return _proto_TypeTraits::Mutable(id.number(), index, &_extensions_); \ + } \ + \ + template \ + inline void SetExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ + int index, typename _proto_TypeTraits::ConstType value) { \ + _proto_TypeTraits::Set(id.number(), index, value, &_extensions_); \ + } \ + \ + template \ + inline typename _proto_TypeTraits::MutableType AddExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) { \ + return _proto_TypeTraits::Add(id.number(), field_type, &_extensions_); \ + } \ + \ + template \ + inline void AddExtension( \ + const ::google::protobuf::internal::ExtensionIdentifier< \ + CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ + typename _proto_TypeTraits::ConstType value) { \ + _proto_TypeTraits::Add(id.number(), field_type, is_packed, \ + value, &_extensions_); \ + } + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h b/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h new file mode 100644 index 00000000..b545fa1a --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h @@ -0,0 +1,424 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This header is logically internal, but is made public because it is used +// from protocol-compiler-generated code, which may reside in other components. + +#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ + +#include +#include +#include +#include + + +namespace google { +namespace protobuf { + class DescriptorPool; + // Generated code needs these to have been forward-declared. Easier to do it + // here than to print them inside every .pb.h file. + class FileDescriptor; + class EnumDescriptor; +} + +namespace protobuf { +namespace internal { + +// Defined in this file. +class GeneratedMessageReflection; + +// Defined in other files. +class ExtensionSet; // extension_set.h + +// THIS CLASS IS NOT INTENDED FOR DIRECT USE. It is intended for use +// by generated code. This class is just a big hack that reduces code +// size. +// +// A GeneratedMessageReflection is an implementation of Reflection +// which expects all fields to be backed by simple variables located in +// memory. The locations are given using a base pointer and a set of +// offsets. +// +// It is required that the user represents fields of each type in a standard +// way, so that GeneratedMessageReflection can cast the void* pointer to +// the appropriate type. For primitive fields and string fields, each field +// should be represented using the obvious C++ primitive type. Enums and +// Messages are different: +// - Singular Message fields are stored as a pointer to a Message. These +// should start out NULL, except for in the default instance where they +// should start out pointing to other default instances. +// - Enum fields are stored as an int. This int must always contain +// a valid value, such that EnumDescriptor::FindValueByNumber() would +// not return NULL. +// - Repeated fields are stored as RepeatedFields or RepeatedPtrFields +// of whatever type the individual field would be. Strings and +// Messages use RepeatedPtrFields while everything else uses +// RepeatedFields. +class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection { + public: + // Constructs a GeneratedMessageReflection. + // Parameters: + // descriptor: The descriptor for the message type being implemented. + // default_instance: The default instance of the message. This is only + // used to obtain pointers to default instances of embedded + // messages, which GetMessage() will return if the particular + // sub-message has not been initialized yet. (Thus, all + // embedded message fields *must* have non-NULL pointers + // in the default instance.) + // offsets: An array of ints giving the byte offsets, relative to + // the start of the message object, of each field. These can + // be computed at compile time using the + // GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro, defined + // below. + // has_bits_offset: Offset in the message of an array of uint32s of size + // descriptor->field_count()/32, rounded up. This is a + // bitfield where each bit indicates whether or not the + // corresponding field of the message has been initialized. + // The bit for field index i is obtained by the expression: + // has_bits[i / 32] & (1 << (i % 32)) + // unknown_fields_offset: Offset in the message of the UnknownFieldSet for + // the message. + // extensions_offset: Offset in the message of the ExtensionSet for the + // message, or -1 if the message type has no extension + // ranges. + // pool: DescriptorPool to search for extension definitions. Only + // used by FindKnownExtensionByName() and + // FindKnownExtensionByNumber(). + // factory: MessageFactory to use to construct extension messages. + // object_size: The size of a message object of this type, as measured + // by sizeof(). + GeneratedMessageReflection(const Descriptor* descriptor, + const Message* default_instance, + const int offsets[], + int has_bits_offset, + int unknown_fields_offset, + int extensions_offset, + const DescriptorPool* pool, + MessageFactory* factory, + int object_size); + ~GeneratedMessageReflection(); + + // implements Reflection ------------------------------------------- + + const UnknownFieldSet& GetUnknownFields(const Message& message) const; + UnknownFieldSet* MutableUnknownFields(Message* message) const; + + int SpaceUsed(const Message& message) const; + + bool HasField(const Message& message, const FieldDescriptor* field) const; + int FieldSize(const Message& message, const FieldDescriptor* field) const; + void ClearField(Message* message, const FieldDescriptor* field) const; + void RemoveLast(Message* message, const FieldDescriptor* field) const; + void Swap(Message* message1, Message* message2) const; + void SwapElements(Message* message, const FieldDescriptor* field, + int index1, int index2) const; + void ListFields(const Message& message, + vector* output) const; + + int32 GetInt32 (const Message& message, + const FieldDescriptor* field) const; + int64 GetInt64 (const Message& message, + const FieldDescriptor* field) const; + uint32 GetUInt32(const Message& message, + const FieldDescriptor* field) const; + uint64 GetUInt64(const Message& message, + const FieldDescriptor* field) const; + float GetFloat (const Message& message, + const FieldDescriptor* field) const; + double GetDouble(const Message& message, + const FieldDescriptor* field) const; + bool GetBool (const Message& message, + const FieldDescriptor* field) const; + string GetString(const Message& message, + const FieldDescriptor* field) const; + const string& GetStringReference(const Message& message, + const FieldDescriptor* field, + string* scratch) const; + const EnumValueDescriptor* GetEnum(const Message& message, + const FieldDescriptor* field) const; + const Message& GetMessage(const Message& message, + const FieldDescriptor* field, + MessageFactory* factory = NULL) const; + + void SetInt32 (Message* message, + const FieldDescriptor* field, int32 value) const; + void SetInt64 (Message* message, + const FieldDescriptor* field, int64 value) const; + void SetUInt32(Message* message, + const FieldDescriptor* field, uint32 value) const; + void SetUInt64(Message* message, + const FieldDescriptor* field, uint64 value) const; + void SetFloat (Message* message, + const FieldDescriptor* field, float value) const; + void SetDouble(Message* message, + const FieldDescriptor* field, double value) const; + void SetBool (Message* message, + const FieldDescriptor* field, bool value) const; + void SetString(Message* message, + const FieldDescriptor* field, + const string& value) const; + void SetEnum (Message* message, const FieldDescriptor* field, + const EnumValueDescriptor* value) const; + Message* MutableMessage(Message* message, const FieldDescriptor* field, + MessageFactory* factory = NULL) const; + + int32 GetRepeatedInt32 (const Message& message, + const FieldDescriptor* field, int index) const; + int64 GetRepeatedInt64 (const Message& message, + const FieldDescriptor* field, int index) const; + uint32 GetRepeatedUInt32(const Message& message, + const FieldDescriptor* field, int index) const; + uint64 GetRepeatedUInt64(const Message& message, + const FieldDescriptor* field, int index) const; + float GetRepeatedFloat (const Message& message, + const FieldDescriptor* field, int index) const; + double GetRepeatedDouble(const Message& message, + const FieldDescriptor* field, int index) const; + bool GetRepeatedBool (const Message& message, + const FieldDescriptor* field, int index) const; + string GetRepeatedString(const Message& message, + const FieldDescriptor* field, int index) const; + const string& GetRepeatedStringReference(const Message& message, + const FieldDescriptor* field, + int index, string* scratch) const; + const EnumValueDescriptor* GetRepeatedEnum(const Message& message, + const FieldDescriptor* field, + int index) const; + const Message& GetRepeatedMessage(const Message& message, + const FieldDescriptor* field, + int index) const; + + // Set the value of a field. + void SetRepeatedInt32 (Message* message, + const FieldDescriptor* field, int index, int32 value) const; + void SetRepeatedInt64 (Message* message, + const FieldDescriptor* field, int index, int64 value) const; + void SetRepeatedUInt32(Message* message, + const FieldDescriptor* field, int index, uint32 value) const; + void SetRepeatedUInt64(Message* message, + const FieldDescriptor* field, int index, uint64 value) const; + void SetRepeatedFloat (Message* message, + const FieldDescriptor* field, int index, float value) const; + void SetRepeatedDouble(Message* message, + const FieldDescriptor* field, int index, double value) const; + void SetRepeatedBool (Message* message, + const FieldDescriptor* field, int index, bool value) const; + void SetRepeatedString(Message* message, + const FieldDescriptor* field, int index, + const string& value) const; + void SetRepeatedEnum(Message* message, const FieldDescriptor* field, + int index, const EnumValueDescriptor* value) const; + // Get a mutable pointer to a field with a message type. + Message* MutableRepeatedMessage(Message* message, + const FieldDescriptor* field, + int index) const; + + void AddInt32 (Message* message, + const FieldDescriptor* field, int32 value) const; + void AddInt64 (Message* message, + const FieldDescriptor* field, int64 value) const; + void AddUInt32(Message* message, + const FieldDescriptor* field, uint32 value) const; + void AddUInt64(Message* message, + const FieldDescriptor* field, uint64 value) const; + void AddFloat (Message* message, + const FieldDescriptor* field, float value) const; + void AddDouble(Message* message, + const FieldDescriptor* field, double value) const; + void AddBool (Message* message, + const FieldDescriptor* field, bool value) const; + void AddString(Message* message, + const FieldDescriptor* field, const string& value) const; + void AddEnum(Message* message, + const FieldDescriptor* field, + const EnumValueDescriptor* value) const; + Message* AddMessage(Message* message, const FieldDescriptor* field, + MessageFactory* factory = NULL) const; + + const FieldDescriptor* FindKnownExtensionByName(const string& name) const; + const FieldDescriptor* FindKnownExtensionByNumber(int number) const; + + private: + friend class GeneratedMessage; + + const Descriptor* descriptor_; + const Message* default_instance_; + const int* offsets_; + + int has_bits_offset_; + int unknown_fields_offset_; + int extensions_offset_; + int object_size_; + + const DescriptorPool* descriptor_pool_; + MessageFactory* message_factory_; + + template + inline const Type& GetRaw(const Message& message, + const FieldDescriptor* field) const; + template + inline Type* MutableRaw(Message* message, + const FieldDescriptor* field) const; + template + inline const Type& DefaultRaw(const FieldDescriptor* field) const; + inline const Message* GetMessagePrototype(const FieldDescriptor* field) const; + + inline const uint32* GetHasBits(const Message& message) const; + inline uint32* MutableHasBits(Message* message) const; + inline const ExtensionSet& GetExtensionSet(const Message& message) const; + inline ExtensionSet* MutableExtensionSet(Message* message) const; + + inline bool HasBit(const Message& message, + const FieldDescriptor* field) const; + inline void SetBit(Message* message, + const FieldDescriptor* field) const; + inline void ClearBit(Message* message, + const FieldDescriptor* field) const; + + template + inline const Type& GetField(const Message& message, + const FieldDescriptor* field) const; + template + inline void SetField(Message* message, + const FieldDescriptor* field, const Type& value) const; + template + inline Type* MutableField(Message* message, + const FieldDescriptor* field) const; + template + inline const Type& GetRepeatedField(const Message& message, + const FieldDescriptor* field, + int index) const; + template + inline const Type& GetRepeatedPtrField(const Message& message, + const FieldDescriptor* field, + int index) const; + template + inline void SetRepeatedField(Message* message, + const FieldDescriptor* field, int index, + Type value) const; + template + inline Type* MutableRepeatedField(Message* message, + const FieldDescriptor* field, + int index) const; + template + inline void AddField(Message* message, + const FieldDescriptor* field, const Type& value) const; + template + inline Type* AddField(Message* message, + const FieldDescriptor* field) const; + + int GetExtensionNumberOrDie(const Descriptor* type) const; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratedMessageReflection); +}; + +// Returns the offset of the given field within the given aggregate type. +// This is equivalent to the ANSI C offsetof() macro. However, according +// to the C++ standard, offsetof() only works on POD types, and GCC +// enforces this requirement with a warning. In practice, this rule is +// unnecessarily strict; there is probably no compiler or platform on +// which the offsets of the direct fields of a class are non-constant. +// Fields inherited from superclasses *can* have non-constant offsets, +// but that's not what this macro will be used for. +// +// Note that we calculate relative to the pointer value 16 here since if we +// just use zero, GCC complains about dereferencing a NULL pointer. We +// choose 16 rather than some other number just in case the compiler would +// be confused by an unaligned pointer. +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ + static_cast( \ + reinterpret_cast( \ + &reinterpret_cast(16)->FIELD) - \ + reinterpret_cast(16)) + +// There are some places in proto2 where dynamic_cast would be useful as an +// optimization. For example, take Message::MergeFrom(const Message& other). +// For a given generated message FooMessage, we generate these two methods: +// void MergeFrom(const FooMessage& other); +// void MergeFrom(const Message& other); +// The former method can be implemented directly in terms of FooMessage's +// inline accessors, but the latter method must work with the reflection +// interface. However, if the parameter to the latter method is actually of +// type FooMessage, then we'd like to be able to just call the other method +// as an optimization. So, we use dynamic_cast to check this. +// +// That said, dynamic_cast requires RTTI, which many people like to disable +// for performance and code size reasons. When RTTI is not available, we +// still need to produce correct results. So, in this case we have to fall +// back to using reflection, which is what we would have done anyway if the +// objects were not of the exact same class. +// +// dynamic_cast_if_available() implements this logic. If RTTI is +// enabled, it does a dynamic_cast. If RTTI is disabled, it just returns +// NULL. +// +// If you need to compile without RTTI, simply #define GOOGLE_PROTOBUF_NO_RTTI. +// On MSVC, this should be detected automatically. +template +inline To dynamic_cast_if_available(From from) { +#if defined(GOOGLE_PROTOBUF_NO_RTTI) || (defined(_MSC_VER)&&!defined(_CPPRTTI)) + return NULL; +#else + return dynamic_cast(from); +#endif +} + +// Helper for EnumType_Parse functions: try to parse the string 'name' as an +// enum name of the given type, returning true and filling in value on success, +// or returning false and leaving value unchanged on failure. +LIBPROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor, + const string& name, + int* value); + +template +bool ParseNamedEnum(const EnumDescriptor* descriptor, + const string& name, + EnumType* value) { + int tmp; + if (!ParseNamedEnum(descriptor, name, &tmp)) return false; + *value = static_cast(tmp); + return true; +} + +// Just a wrapper around printing the name of a value. The main point of this +// function is not to be inlined, so that you can do this without including +// descriptor.h. +LIBPROTOBUF_EXPORT const string& NameOfEnum(const EnumDescriptor* descriptor, int value); + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h b/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h new file mode 100644 index 00000000..1a2343d4 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h @@ -0,0 +1,82 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file contains miscellaneous helper code used by generated code -- +// including lite types -- but which should not be used directly by users. + +#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ + +#include + +#include + + +namespace google { +namespace protobuf { + namespace io { + class CodedInputStream; // coded_stream.h + } +} + +namespace protobuf { +namespace internal { + +// Annotation for the compiler to emit a deprecation message if a field marked +// with option 'deprecated=true' is used in the code, or for other things in +// generated code which are deprecated. +// +// For internal use in the pb.cc files, deprecation warnings are suppressed +// there. +#undef DEPRECATED_PROTOBUF_FIELD +#if !defined(INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION) +# define PROTOBUF_DEPRECATED GOOGLE_ATTRIBUTE_DEPRECATED +#else +# define PROTOBUF_DEPRECATED +#endif + + +// Constants for special floating point values. +double Infinity(); +double NaN(); + +// Constant used for empty default strings. +extern const ::std::string kEmptyString; + + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h b/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h new file mode 100644 index 00000000..1b6b4e18 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h @@ -0,0 +1,1102 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file contains the CodedInputStream and CodedOutputStream classes, +// which wrap a ZeroCopyInputStream or ZeroCopyOutputStream, respectively, +// and allow you to read or write individual pieces of data in various +// formats. In particular, these implement the varint encoding for +// integers, a simple variable-length encoding in which smaller numbers +// take fewer bytes. +// +// Typically these classes will only be used internally by the protocol +// buffer library in order to encode and decode protocol buffers. Clients +// of the library only need to know about this class if they wish to write +// custom message parsing or serialization procedures. +// +// CodedOutputStream example: +// // Write some data to "myfile". First we write a 4-byte "magic number" +// // to identify the file type, then write a length-delimited string. The +// // string is composed of a varint giving the length followed by the raw +// // bytes. +// int fd = open("myfile", O_WRONLY); +// ZeroCopyOutputStream* raw_output = new FileOutputStream(fd); +// CodedOutputStream* coded_output = new CodedOutputStream(raw_output); +// +// int magic_number = 1234; +// char text[] = "Hello world!"; +// coded_output->WriteLittleEndian32(magic_number); +// coded_output->WriteVarint32(strlen(text)); +// coded_output->WriteRaw(text, strlen(text)); +// +// delete coded_output; +// delete raw_output; +// close(fd); +// +// CodedInputStream example: +// // Read a file created by the above code. +// int fd = open("myfile", O_RDONLY); +// ZeroCopyInputStream* raw_input = new FileInputStream(fd); +// CodedInputStream coded_input = new CodedInputStream(raw_input); +// +// coded_input->ReadLittleEndian32(&magic_number); +// if (magic_number != 1234) { +// cerr << "File not in expected format." << endl; +// return; +// } +// +// uint32 size; +// coded_input->ReadVarint32(&size); +// +// char* text = new char[size + 1]; +// coded_input->ReadRaw(buffer, size); +// text[size] = '\0'; +// +// delete coded_input; +// delete raw_input; +// close(fd); +// +// cout << "Text is: " << text << endl; +// delete [] text; +// +// For those who are interested, varint encoding is defined as follows: +// +// The encoding operates on unsigned integers of up to 64 bits in length. +// Each byte of the encoded value has the format: +// * bits 0-6: Seven bits of the number being encoded. +// * bit 7: Zero if this is the last byte in the encoding (in which +// case all remaining bits of the number are zero) or 1 if +// more bytes follow. +// The first byte contains the least-significant 7 bits of the number, the +// second byte (if present) contains the next-least-significant 7 bits, +// and so on. So, the binary number 1011000101011 would be encoded in two +// bytes as "10101011 00101100". +// +// In theory, varint could be used to encode integers of any length. +// However, for practicality we set a limit at 64 bits. The maximum encoded +// length of a number is thus 10 bytes. + +#ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ +#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ + +#include +#ifdef _MSC_VER + #if defined(_M_IX86) && \ + !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) + #define PROTOBUF_LITTLE_ENDIAN 1 + #endif + #if _MSC_VER >= 1300 + // If MSVC has "/RTCc" set, it will complain about truncating casts at + // runtime. This file contains some intentional truncating casts. + #pragma runtime_checks("c", off) + #endif +#else + #include // __BYTE_ORDER + #if defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN && \ + !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) + #define PROTOBUF_LITTLE_ENDIAN 1 + #endif +#endif +#include + + +namespace google { +namespace protobuf { + +class DescriptorPool; +class MessageFactory; + +namespace io { + +// Defined in this file. +class CodedInputStream; +class CodedOutputStream; + +// Defined in other files. +class ZeroCopyInputStream; // zero_copy_stream.h +class ZeroCopyOutputStream; // zero_copy_stream.h + +// Class which reads and decodes binary data which is composed of varint- +// encoded integers and fixed-width pieces. Wraps a ZeroCopyInputStream. +// Most users will not need to deal with CodedInputStream. +// +// Most methods of CodedInputStream that return a bool return false if an +// underlying I/O error occurs or if the data is malformed. Once such a +// failure occurs, the CodedInputStream is broken and is no longer useful. +class LIBPROTOBUF_EXPORT CodedInputStream { + public: + // Create a CodedInputStream that reads from the given ZeroCopyInputStream. + explicit CodedInputStream(ZeroCopyInputStream* input); + + // Create a CodedInputStream that reads from the given flat array. This is + // faster than using an ArrayInputStream. PushLimit(size) is implied by + // this constructor. + explicit CodedInputStream(const uint8* buffer, int size); + + // Destroy the CodedInputStream and position the underlying + // ZeroCopyInputStream at the first unread byte. If an error occurred while + // reading (causing a method to return false), then the exact position of + // the input stream may be anywhere between the last value that was read + // successfully and the stream's byte limit. + ~CodedInputStream(); + + + // Skips a number of bytes. Returns false if an underlying read error + // occurs. + bool Skip(int count); + + // Sets *data to point directly at the unread part of the CodedInputStream's + // underlying buffer, and *size to the size of that buffer, but does not + // advance the stream's current position. This will always either produce + // a non-empty buffer or return false. If the caller consumes any of + // this data, it should then call Skip() to skip over the consumed bytes. + // This may be useful for implementing external fast parsing routines for + // types of data not covered by the CodedInputStream interface. + bool GetDirectBufferPointer(const void** data, int* size); + + // Like GetDirectBufferPointer, but this method is inlined, and does not + // attempt to Refresh() if the buffer is currently empty. + inline void GetDirectBufferPointerInline(const void** data, + int* size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + // Read raw bytes, copying them into the given buffer. + bool ReadRaw(void* buffer, int size); + + // Like ReadRaw, but reads into a string. + // + // Implementation Note: ReadString() grows the string gradually as it + // reads in the data, rather than allocating the entire requested size + // upfront. This prevents denial-of-service attacks in which a client + // could claim that a string is going to be MAX_INT bytes long in order to + // crash the server because it can't allocate this much space at once. + bool ReadString(string* buffer, int size); + // Like the above, with inlined optimizations. This should only be used + // by the protobuf implementation. + inline bool InternalReadStringInline(string* buffer, + int size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + + // Read a 32-bit little-endian integer. + bool ReadLittleEndian32(uint32* value); + // Read a 64-bit little-endian integer. + bool ReadLittleEndian64(uint64* value); + + // These methods read from an externally provided buffer. The caller is + // responsible for ensuring that the buffer has sufficient space. + // Read a 32-bit little-endian integer. + static const uint8* ReadLittleEndian32FromArray(const uint8* buffer, + uint32* value); + // Read a 64-bit little-endian integer. + static const uint8* ReadLittleEndian64FromArray(const uint8* buffer, + uint64* value); + + // Read an unsigned integer with Varint encoding, truncating to 32 bits. + // Reading a 32-bit value is equivalent to reading a 64-bit one and casting + // it to uint32, but may be more efficient. + bool ReadVarint32(uint32* value); + // Read an unsigned integer with Varint encoding. + bool ReadVarint64(uint64* value); + + // Read a tag. This calls ReadVarint32() and returns the result, or returns + // zero (which is not a valid tag) if ReadVarint32() fails. Also, it updates + // the last tag value, which can be checked with LastTagWas(). + // Always inline because this is only called in once place per parse loop + // but it is called for every iteration of said loop, so it should be fast. + // GCC doesn't want to inline this by default. + uint32 ReadTag() GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + // Usually returns true if calling ReadVarint32() now would produce the given + // value. Will always return false if ReadVarint32() would not return the + // given value. If ExpectTag() returns true, it also advances past + // the varint. For best performance, use a compile-time constant as the + // parameter. + // Always inline because this collapses to a small number of instructions + // when given a constant parameter, but GCC doesn't want to inline by default. + bool ExpectTag(uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + // Like above, except this reads from the specified buffer. The caller is + // responsible for ensuring that the buffer is large enough to read a varint + // of the expected size. For best performance, use a compile-time constant as + // the expected tag parameter. + // + // Returns a pointer beyond the expected tag if it was found, or NULL if it + // was not. + static const uint8* ExpectTagFromArray( + const uint8* buffer, + uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + // Usually returns true if no more bytes can be read. Always returns false + // if more bytes can be read. If ExpectAtEnd() returns true, a subsequent + // call to LastTagWas() will act as if ReadTag() had been called and returned + // zero, and ConsumedEntireMessage() will return true. + bool ExpectAtEnd(); + + // If the last call to ReadTag() returned the given value, returns true. + // Otherwise, returns false; + // + // This is needed because parsers for some types of embedded messages + // (with field type TYPE_GROUP) don't actually know that they've reached the + // end of a message until they see an ENDGROUP tag, which was actually part + // of the enclosing message. The enclosing message would like to check that + // tag to make sure it had the right number, so it calls LastTagWas() on + // return from the embedded parser to check. + bool LastTagWas(uint32 expected); + + // When parsing message (but NOT a group), this method must be called + // immediately after MergeFromCodedStream() returns (if it returns true) + // to further verify that the message ended in a legitimate way. For + // example, this verifies that parsing did not end on an end-group tag. + // It also checks for some cases where, due to optimizations, + // MergeFromCodedStream() can incorrectly return true. + bool ConsumedEntireMessage(); + + // Limits ---------------------------------------------------------- + // Limits are used when parsing length-delimited embedded messages. + // After the message's length is read, PushLimit() is used to prevent + // the CodedInputStream from reading beyond that length. Once the + // embedded message has been parsed, PopLimit() is called to undo the + // limit. + + // Opaque type used with PushLimit() and PopLimit(). Do not modify + // values of this type yourself. The only reason that this isn't a + // struct with private internals is for efficiency. + typedef int Limit; + + // Places a limit on the number of bytes that the stream may read, + // starting from the current position. Once the stream hits this limit, + // it will act like the end of the input has been reached until PopLimit() + // is called. + // + // As the names imply, the stream conceptually has a stack of limits. The + // shortest limit on the stack is always enforced, even if it is not the + // top limit. + // + // The value returned by PushLimit() is opaque to the caller, and must + // be passed unchanged to the corresponding call to PopLimit(). + Limit PushLimit(int byte_limit); + + // Pops the last limit pushed by PushLimit(). The input must be the value + // returned by that call to PushLimit(). + void PopLimit(Limit limit); + + // Returns the number of bytes left until the nearest limit on the + // stack is hit, or -1 if no limits are in place. + int BytesUntilLimit(); + + // Total Bytes Limit ----------------------------------------------- + // To prevent malicious users from sending excessively large messages + // and causing integer overflows or memory exhaustion, CodedInputStream + // imposes a hard limit on the total number of bytes it will read. + + // Sets the maximum number of bytes that this CodedInputStream will read + // before refusing to continue. To prevent integer overflows in the + // protocol buffers implementation, as well as to prevent servers from + // allocating enormous amounts of memory to hold parsed messages, the + // maximum message length should be limited to the shortest length that + // will not harm usability. The theoretical shortest message that could + // cause integer overflows is 512MB. The default limit is 64MB. Apps + // should set shorter limits if possible. If warning_threshold is not -1, + // a warning will be printed to stderr after warning_threshold bytes are + // read. An error will always be printed to stderr if the limit is + // reached. + // + // This is unrelated to PushLimit()/PopLimit(). + // + // Hint: If you are reading this because your program is printing a + // warning about dangerously large protocol messages, you may be + // confused about what to do next. The best option is to change your + // design such that excessively large messages are not necessary. + // For example, try to design file formats to consist of many small + // messages rather than a single large one. If this is infeasible, + // you will need to increase the limit. Chances are, though, that + // your code never constructs a CodedInputStream on which the limit + // can be set. You probably parse messages by calling things like + // Message::ParseFromString(). In this case, you will need to change + // your code to instead construct some sort of ZeroCopyInputStream + // (e.g. an ArrayInputStream), construct a CodedInputStream around + // that, then call Message::ParseFromCodedStream() instead. Then + // you can adjust the limit. Yes, it's more work, but you're doing + // something unusual. + void SetTotalBytesLimit(int total_bytes_limit, int warning_threshold); + + // Recursion Limit ------------------------------------------------- + // To prevent corrupt or malicious messages from causing stack overflows, + // we must keep track of the depth of recursion when parsing embedded + // messages and groups. CodedInputStream keeps track of this because it + // is the only object that is passed down the stack during parsing. + + // Sets the maximum recursion depth. The default is 64. + void SetRecursionLimit(int limit); + + // Increments the current recursion depth. Returns true if the depth is + // under the limit, false if it has gone over. + bool IncrementRecursionDepth(); + + // Decrements the recursion depth. + void DecrementRecursionDepth(); + + // Extension Registry ---------------------------------------------- + // ADVANCED USAGE: 99.9% of people can ignore this section. + // + // By default, when parsing extensions, the parser looks for extension + // definitions in the pool which owns the outer message's Descriptor. + // However, you may call SetExtensionRegistry() to provide an alternative + // pool instead. This makes it possible, for example, to parse a message + // using a generated class, but represent some extensions using + // DynamicMessage. + + // Set the pool used to look up extensions. Most users do not need to call + // this as the correct pool will be chosen automatically. + // + // WARNING: It is very easy to misuse this. Carefully read the requirements + // below. Do not use this unless you are sure you need it. Almost no one + // does. + // + // Let's say you are parsing a message into message object m, and you want + // to take advantage of SetExtensionRegistry(). You must follow these + // requirements: + // + // The given DescriptorPool must contain m->GetDescriptor(). It is not + // sufficient for it to simply contain a descriptor that has the same name + // and content -- it must be the *exact object*. In other words: + // assert(pool->FindMessageTypeByName(m->GetDescriptor()->full_name()) == + // m->GetDescriptor()); + // There are two ways to satisfy this requirement: + // 1) Use m->GetDescriptor()->pool() as the pool. This is generally useless + // because this is the pool that would be used anyway if you didn't call + // SetExtensionRegistry() at all. + // 2) Use a DescriptorPool which has m->GetDescriptor()->pool() as an + // "underlay". Read the documentation for DescriptorPool for more + // information about underlays. + // + // You must also provide a MessageFactory. This factory will be used to + // construct Message objects representing extensions. The factory's + // GetPrototype() MUST return non-NULL for any Descriptor which can be found + // through the provided pool. + // + // If the provided factory might return instances of protocol-compiler- + // generated (i.e. compiled-in) types, or if the outer message object m is + // a generated type, then the given factory MUST have this property: If + // GetPrototype() is given a Descriptor which resides in + // DescriptorPool::generated_pool(), the factory MUST return the same + // prototype which MessageFactory::generated_factory() would return. That + // is, given a descriptor for a generated type, the factory must return an + // instance of the generated class (NOT DynamicMessage). However, when + // given a descriptor for a type that is NOT in generated_pool, the factory + // is free to return any implementation. + // + // The reason for this requirement is that generated sub-objects may be + // accessed via the standard (non-reflection) extension accessor methods, + // and these methods will down-cast the object to the generated class type. + // If the object is not actually of that type, the results would be undefined. + // On the other hand, if an extension is not compiled in, then there is no + // way the code could end up accessing it via the standard accessors -- the + // only way to access the extension is via reflection. When using reflection, + // DynamicMessage and generated messages are indistinguishable, so it's fine + // if these objects are represented using DynamicMessage. + // + // Using DynamicMessageFactory on which you have called + // SetDelegateToGeneratedFactory(true) should be sufficient to satisfy the + // above requirement. + // + // If either pool or factory is NULL, both must be NULL. + // + // Note that this feature is ignored when parsing "lite" messages as they do + // not have descriptors. + void SetExtensionRegistry(DescriptorPool* pool, MessageFactory* factory); + + // Get the DescriptorPool set via SetExtensionRegistry(), or NULL if no pool + // has been provided. + const DescriptorPool* GetExtensionPool(); + + // Get the MessageFactory set via SetExtensionRegistry(), or NULL if no + // factory has been provided. + MessageFactory* GetExtensionFactory(); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream); + + ZeroCopyInputStream* input_; + const uint8* buffer_; + const uint8* buffer_end_; // pointer to the end of the buffer. + int total_bytes_read_; // total bytes read from input_, including + // the current buffer + + // If total_bytes_read_ surpasses INT_MAX, we record the extra bytes here + // so that we can BackUp() on destruction. + int overflow_bytes_; + + // LastTagWas() stuff. + uint32 last_tag_; // result of last ReadTag(). + + // This is set true by ReadTag{Fallback/Slow}() if it is called when exactly + // at EOF, or by ExpectAtEnd() when it returns true. This happens when we + // reach the end of a message and attempt to read another tag. + bool legitimate_message_end_; + + // See EnableAliasing(). + bool aliasing_enabled_; + + // Limits + Limit current_limit_; // if position = -1, no limit is applied + + // For simplicity, if the current buffer crosses a limit (either a normal + // limit created by PushLimit() or the total bytes limit), buffer_size_ + // only tracks the number of bytes before that limit. This field + // contains the number of bytes after it. Note that this implies that if + // buffer_size_ == 0 and buffer_size_after_limit_ > 0, we know we've + // hit a limit. However, if both are zero, it doesn't necessarily mean + // we aren't at a limit -- the buffer may have ended exactly at the limit. + int buffer_size_after_limit_; + + // Maximum number of bytes to read, period. This is unrelated to + // current_limit_. Set using SetTotalBytesLimit(). + int total_bytes_limit_; + int total_bytes_warning_threshold_; + + // Current recursion depth, controlled by IncrementRecursionDepth() and + // DecrementRecursionDepth(). + int recursion_depth_; + // Recursion depth limit, set by SetRecursionLimit(). + int recursion_limit_; + + // See SetExtensionRegistry(). + const DescriptorPool* extension_pool_; + MessageFactory* extension_factory_; + + // Private member functions. + + // Advance the buffer by a given number of bytes. + void Advance(int amount); + + // Back up input_ to the current buffer position. + void BackUpInputToCurrentPosition(); + + // Recomputes the value of buffer_size_after_limit_. Must be called after + // current_limit_ or total_bytes_limit_ changes. + void RecomputeBufferLimits(); + + // Writes an error message saying that we hit total_bytes_limit_. + void PrintTotalBytesLimitError(); + + // Called when the buffer runs out to request more data. Implies an + // Advance(BufferSize()). + bool Refresh(); + + // When parsing varints, we optimize for the common case of small values, and + // then optimize for the case when the varint fits within the current buffer + // piece. The Fallback method is used when we can't use the one-byte + // optimization. The Slow method is yet another fallback when the buffer is + // not large enough. Making the slow path out-of-line speeds up the common + // case by 10-15%. The slow path is fairly uncommon: it only triggers when a + // message crosses multiple buffers. + bool ReadVarint32Fallback(uint32* value); + bool ReadVarint64Fallback(uint64* value); + bool ReadVarint32Slow(uint32* value); + bool ReadVarint64Slow(uint64* value); + bool ReadLittleEndian32Fallback(uint32* value); + bool ReadLittleEndian64Fallback(uint64* value); + // Fallback/slow methods for reading tags. These do not update last_tag_, + // but will set legitimate_message_end_ if we are at the end of the input + // stream. + uint32 ReadTagFallback(); + uint32 ReadTagSlow(); + bool ReadStringFallback(string* buffer, int size); + + // Return the size of the buffer. + int BufferSize() const; + + static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB + + static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB + static const int kDefaultRecursionLimit = 64; +}; + +// Class which encodes and writes binary data which is composed of varint- +// encoded integers and fixed-width pieces. Wraps a ZeroCopyOutputStream. +// Most users will not need to deal with CodedOutputStream. +// +// Most methods of CodedOutputStream which return a bool return false if an +// underlying I/O error occurs. Once such a failure occurs, the +// CodedOutputStream is broken and is no longer useful. The Write* methods do +// not return the stream status, but will invalidate the stream if an error +// occurs. The client can probe HadError() to determine the status. +// +// Note that every method of CodedOutputStream which writes some data has +// a corresponding static "ToArray" version. These versions write directly +// to the provided buffer, returning a pointer past the last written byte. +// They require that the buffer has sufficient capacity for the encoded data. +// This allows an optimization where we check if an output stream has enough +// space for an entire message before we start writing and, if there is, we +// call only the ToArray methods to avoid doing bound checks for each +// individual value. +// i.e., in the example above: +// +// CodedOutputStream coded_output = new CodedOutputStream(raw_output); +// int magic_number = 1234; +// char text[] = "Hello world!"; +// +// int coded_size = sizeof(magic_number) + +// CodedOutputStream::VarintSize32(strlen(text)) + +// strlen(text); +// +// uint8* buffer = +// coded_output->GetDirectBufferForNBytesAndAdvance(coded_size); +// if (buffer != NULL) { +// // The output stream has enough space in the buffer: write directly to +// // the array. +// buffer = CodedOutputStream::WriteLittleEndian32ToArray(magic_number, +// buffer); +// buffer = CodedOutputStream::WriteVarint32ToArray(strlen(text), buffer); +// buffer = CodedOutputStream::WriteRawToArray(text, strlen(text), buffer); +// } else { +// // Make bound-checked writes, which will ask the underlying stream for +// // more space as needed. +// coded_output->WriteLittleEndian32(magic_number); +// coded_output->WriteVarint32(strlen(text)); +// coded_output->WriteRaw(text, strlen(text)); +// } +// +// delete coded_output; +class LIBPROTOBUF_EXPORT CodedOutputStream { + public: + // Create an CodedOutputStream that writes to the given ZeroCopyOutputStream. + explicit CodedOutputStream(ZeroCopyOutputStream* output); + + // Destroy the CodedOutputStream and position the underlying + // ZeroCopyOutputStream immediately after the last byte written. + ~CodedOutputStream(); + + // Skips a number of bytes, leaving the bytes unmodified in the underlying + // buffer. Returns false if an underlying write error occurs. This is + // mainly useful with GetDirectBufferPointer(). + bool Skip(int count); + + // Sets *data to point directly at the unwritten part of the + // CodedOutputStream's underlying buffer, and *size to the size of that + // buffer, but does not advance the stream's current position. This will + // always either produce a non-empty buffer or return false. If the caller + // writes any data to this buffer, it should then call Skip() to skip over + // the consumed bytes. This may be useful for implementing external fast + // serialization routines for types of data not covered by the + // CodedOutputStream interface. + bool GetDirectBufferPointer(void** data, int* size); + + // If there are at least "size" bytes available in the current buffer, + // returns a pointer directly into the buffer and advances over these bytes. + // The caller may then write directly into this buffer (e.g. using the + // *ToArray static methods) rather than go through CodedOutputStream. If + // there are not enough bytes available, returns NULL. The return pointer is + // invalidated as soon as any other non-const method of CodedOutputStream + // is called. + inline uint8* GetDirectBufferForNBytesAndAdvance(int size); + + // Write raw bytes, copying them from the given buffer. + void WriteRaw(const void* buffer, int size); + // Like WriteRaw() but writing directly to the target array. + // This is _not_ inlined, as the compiler often optimizes memcpy into inline + // copy loops. Since this gets called by every field with string or bytes + // type, inlining may lead to a significant amount of code bloat, with only a + // minor performance gain. + static uint8* WriteRawToArray(const void* buffer, int size, uint8* target); + + // Equivalent to WriteRaw(str.data(), str.size()). + void WriteString(const string& str); + // Like WriteString() but writing directly to the target array. + static uint8* WriteStringToArray(const string& str, uint8* target); + + + // Write a 32-bit little-endian integer. + void WriteLittleEndian32(uint32 value); + // Like WriteLittleEndian32() but writing directly to the target array. + static uint8* WriteLittleEndian32ToArray(uint32 value, uint8* target); + // Write a 64-bit little-endian integer. + void WriteLittleEndian64(uint64 value); + // Like WriteLittleEndian64() but writing directly to the target array. + static uint8* WriteLittleEndian64ToArray(uint64 value, uint8* target); + + // Write an unsigned integer with Varint encoding. Writing a 32-bit value + // is equivalent to casting it to uint64 and writing it as a 64-bit value, + // but may be more efficient. + void WriteVarint32(uint32 value); + // Like WriteVarint32() but writing directly to the target array. + static uint8* WriteVarint32ToArray(uint32 value, uint8* target); + // Write an unsigned integer with Varint encoding. + void WriteVarint64(uint64 value); + // Like WriteVarint64() but writing directly to the target array. + static uint8* WriteVarint64ToArray(uint64 value, uint8* target); + + // Equivalent to WriteVarint32() except when the value is negative, + // in which case it must be sign-extended to a full 10 bytes. + void WriteVarint32SignExtended(int32 value); + // Like WriteVarint32SignExtended() but writing directly to the target array. + static uint8* WriteVarint32SignExtendedToArray(int32 value, uint8* target); + + // This is identical to WriteVarint32(), but optimized for writing tags. + // In particular, if the input is a compile-time constant, this method + // compiles down to a couple instructions. + // Always inline because otherwise the aformentioned optimization can't work, + // but GCC by default doesn't want to inline this. + void WriteTag(uint32 value); + // Like WriteTag() but writing directly to the target array. + static uint8* WriteTagToArray( + uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + // Returns the number of bytes needed to encode the given value as a varint. + static int VarintSize32(uint32 value); + // Returns the number of bytes needed to encode the given value as a varint. + static int VarintSize64(uint64 value); + + // If negative, 10 bytes. Otheriwse, same as VarintSize32(). + static int VarintSize32SignExtended(int32 value); + + // Returns the total number of bytes written since this object was created. + inline int ByteCount() const; + + // Returns true if there was an underlying I/O error since this object was + // created. + bool HadError() const { return had_error_; } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); + + ZeroCopyOutputStream* output_; + uint8* buffer_; + int buffer_size_; + int total_bytes_; // Sum of sizes of all buffers seen so far. + bool had_error_; // Whether an error occurred during output. + + // Advance the buffer by a given number of bytes. + void Advance(int amount); + + // Called when the buffer runs out to request more data. Implies an + // Advance(buffer_size_). + bool Refresh(); + + static uint8* WriteVarint32FallbackToArray(uint32 value, uint8* target); + + // Always-inlined versions of WriteVarint* functions so that code can be + // reused, while still controlling size. For instance, WriteVarint32ToArray() + // should not directly call this: since it is inlined itself, doing so + // would greatly increase the size of generated code. Instead, it should call + // WriteVarint32FallbackToArray. Meanwhile, WriteVarint32() is already + // out-of-line, so it should just invoke this directly to avoid any extra + // function call overhead. + static uint8* WriteVarint32FallbackToArrayInline( + uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + static uint8* WriteVarint64ToArrayInline( + uint64 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + static int VarintSize32Fallback(uint32 value); +}; + +// inline methods ==================================================== +// The vast majority of varints are only one byte. These inline +// methods optimize for that case. + +inline bool CodedInputStream::ReadVarint32(uint32* value) { + if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) { + *value = *buffer_; + Advance(1); + return true; + } else { + return ReadVarint32Fallback(value); + } +} + +inline bool CodedInputStream::ReadVarint64(uint64* value) { + if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) { + *value = *buffer_; + Advance(1); + return true; + } else { + return ReadVarint64Fallback(value); + } +} + +// static +inline const uint8* CodedInputStream::ReadLittleEndian32FromArray( + const uint8* buffer, + uint32* value) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + memcpy(value, buffer, sizeof(*value)); + return buffer + sizeof(*value); +#else + *value = (static_cast(buffer[0]) ) | + (static_cast(buffer[1]) << 8) | + (static_cast(buffer[2]) << 16) | + (static_cast(buffer[3]) << 24); + return buffer + sizeof(*value); +#endif +} +// static +inline const uint8* CodedInputStream::ReadLittleEndian64FromArray( + const uint8* buffer, + uint64* value) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + memcpy(value, buffer, sizeof(*value)); + return buffer + sizeof(*value); +#else + uint32 part0 = (static_cast(buffer[0]) ) | + (static_cast(buffer[1]) << 8) | + (static_cast(buffer[2]) << 16) | + (static_cast(buffer[3]) << 24); + uint32 part1 = (static_cast(buffer[4]) ) | + (static_cast(buffer[5]) << 8) | + (static_cast(buffer[6]) << 16) | + (static_cast(buffer[7]) << 24); + *value = static_cast(part0) | + (static_cast(part1) << 32); + return buffer + sizeof(*value); +#endif +} + +inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { + memcpy(value, buffer_, sizeof(*value)); + Advance(sizeof(*value)); + return true; + } else { + return ReadLittleEndian32Fallback(value); + } +#else + return ReadLittleEndian32Fallback(value); +#endif +} + +inline bool CodedInputStream::ReadLittleEndian64(uint64* value) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { + memcpy(value, buffer_, sizeof(*value)); + Advance(sizeof(*value)); + return true; + } else { + return ReadLittleEndian64Fallback(value); + } +#else + return ReadLittleEndian64Fallback(value); +#endif +} + +inline uint32 CodedInputStream::ReadTag() { + if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] < 0x80) { + last_tag_ = buffer_[0]; + Advance(1); + return last_tag_; + } else { + last_tag_ = ReadTagFallback(); + return last_tag_; + } +} + +inline bool CodedInputStream::LastTagWas(uint32 expected) { + return last_tag_ == expected; +} + +inline bool CodedInputStream::ConsumedEntireMessage() { + return legitimate_message_end_; +} + +inline bool CodedInputStream::ExpectTag(uint32 expected) { + if (expected < (1 << 7)) { + if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] == expected) { + Advance(1); + return true; + } else { + return false; + } + } else if (expected < (1 << 14)) { + if (GOOGLE_PREDICT_TRUE(BufferSize() >= 2) && + buffer_[0] == static_cast(expected | 0x80) && + buffer_[1] == static_cast(expected >> 7)) { + Advance(2); + return true; + } else { + return false; + } + } else { + // Don't bother optimizing for larger values. + return false; + } +} + +inline const uint8* CodedInputStream::ExpectTagFromArray( + const uint8* buffer, uint32 expected) { + if (expected < (1 << 7)) { + if (buffer[0] == expected) { + return buffer + 1; + } + } else if (expected < (1 << 14)) { + if (buffer[0] == static_cast(expected | 0x80) && + buffer[1] == static_cast(expected >> 7)) { + return buffer + 2; + } + } + return NULL; +} + +inline void CodedInputStream::GetDirectBufferPointerInline(const void** data, + int* size) { + *data = buffer_; + *size = buffer_end_ - buffer_; +} + +inline bool CodedInputStream::ExpectAtEnd() { + // If we are at a limit we know no more bytes can be read. Otherwise, it's + // hard to say without calling Refresh(), and we'd rather not do that. + + if (buffer_ == buffer_end_ && buffer_size_after_limit_ != 0) { + last_tag_ = 0; // Pretend we called ReadTag()... + legitimate_message_end_ = true; // ... and it hit EOF. + return true; + } else { + return false; + } +} + +inline uint8* CodedOutputStream::GetDirectBufferForNBytesAndAdvance(int size) { + if (buffer_size_ < size) { + return NULL; + } else { + uint8* result = buffer_; + Advance(size); + return result; + } +} + +inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value, + uint8* target) { + if (value < 0x80) { + *target = value; + return target + 1; + } else { + return WriteVarint32FallbackToArray(value, target); + } +} + +inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) { + if (value < 0) { + WriteVarint64(static_cast(value)); + } else { + WriteVarint32(static_cast(value)); + } +} + +inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray( + int32 value, uint8* target) { + if (value < 0) { + return WriteVarint64ToArray(static_cast(value), target); + } else { + return WriteVarint32ToArray(static_cast(value), target); + } +} + +inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value, + uint8* target) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + memcpy(target, &value, sizeof(value)); +#else + target[0] = static_cast(value); + target[1] = static_cast(value >> 8); + target[2] = static_cast(value >> 16); + target[3] = static_cast(value >> 24); +#endif + return target + sizeof(value); +} + +inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value, + uint8* target) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + memcpy(target, &value, sizeof(value)); +#else + uint32 part0 = static_cast(value); + uint32 part1 = static_cast(value >> 32); + + target[0] = static_cast(part0); + target[1] = static_cast(part0 >> 8); + target[2] = static_cast(part0 >> 16); + target[3] = static_cast(part0 >> 24); + target[4] = static_cast(part1); + target[5] = static_cast(part1 >> 8); + target[6] = static_cast(part1 >> 16); + target[7] = static_cast(part1 >> 24); +#endif + return target + sizeof(value); +} + +inline void CodedOutputStream::WriteTag(uint32 value) { + WriteVarint32(value); +} + +inline uint8* CodedOutputStream::WriteTagToArray( + uint32 value, uint8* target) { + if (value < (1 << 7)) { + target[0] = value; + return target + 1; + } else if (value < (1 << 14)) { + target[0] = static_cast(value | 0x80); + target[1] = static_cast(value >> 7); + return target + 2; + } else { + return WriteVarint32FallbackToArray(value, target); + } +} + +inline int CodedOutputStream::VarintSize32(uint32 value) { + if (value < (1 << 7)) { + return 1; + } else { + return VarintSize32Fallback(value); + } +} + +inline int CodedOutputStream::VarintSize32SignExtended(int32 value) { + if (value < 0) { + return 10; // TODO(kenton): Make this a symbolic constant. + } else { + return VarintSize32(static_cast(value)); + } +} + +inline void CodedOutputStream::WriteString(const string& str) { + WriteRaw(str.data(), static_cast(str.size())); +} + +inline uint8* CodedOutputStream::WriteStringToArray( + const string& str, uint8* target) { + return WriteRawToArray(str.data(), static_cast(str.size()), target); +} + +inline int CodedOutputStream::ByteCount() const { + return total_bytes_ - buffer_size_; +} + +inline void CodedInputStream::Advance(int amount) { + buffer_ += amount; +} + +inline void CodedOutputStream::Advance(int amount) { + buffer_ += amount; + buffer_size_ -= amount; +} + +inline void CodedInputStream::SetRecursionLimit(int limit) { + recursion_limit_ = limit; +} + +inline bool CodedInputStream::IncrementRecursionDepth() { + ++recursion_depth_; + return recursion_depth_ <= recursion_limit_; +} + +inline void CodedInputStream::DecrementRecursionDepth() { + if (recursion_depth_ > 0) --recursion_depth_; +} + +inline void CodedInputStream::SetExtensionRegistry(DescriptorPool* pool, + MessageFactory* factory) { + extension_pool_ = pool; + extension_factory_ = factory; +} + +inline const DescriptorPool* CodedInputStream::GetExtensionPool() { + return extension_pool_; +} + +inline MessageFactory* CodedInputStream::GetExtensionFactory() { + return extension_factory_; +} + +inline int CodedInputStream::BufferSize() const { + return buffer_end_ - buffer_; +} + +inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input) + : input_(input), + buffer_(NULL), + buffer_end_(NULL), + total_bytes_read_(0), + overflow_bytes_(0), + last_tag_(0), + legitimate_message_end_(false), + aliasing_enabled_(false), + current_limit_(kint32max), + buffer_size_after_limit_(0), + total_bytes_limit_(kDefaultTotalBytesLimit), + total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), + recursion_depth_(0), + recursion_limit_(kDefaultRecursionLimit), + extension_pool_(NULL), + extension_factory_(NULL) { + // Eagerly Refresh() so buffer space is immediately available. + Refresh(); +} + +inline CodedInputStream::CodedInputStream(const uint8* buffer, int size) + : input_(NULL), + buffer_(buffer), + buffer_end_(buffer + size), + total_bytes_read_(size), + overflow_bytes_(0), + last_tag_(0), + legitimate_message_end_(false), + aliasing_enabled_(false), + current_limit_(size), + buffer_size_after_limit_(0), + total_bytes_limit_(kDefaultTotalBytesLimit), + total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), + recursion_depth_(0), + recursion_limit_(kDefaultRecursionLimit), + extension_pool_(NULL), + extension_factory_(NULL) { + // Note that setting current_limit_ == size is important to prevent some + // code paths from trying to access input_ and segfaulting. +} + +inline CodedInputStream::~CodedInputStream() { + if (input_ != NULL) { + BackUpInputToCurrentPosition(); + } +} + +} // namespace io +} // namespace protobuf + + +#if defined(_MSC_VER) && _MSC_VER >= 1300 + #pragma runtime_checks("c", restore) +#endif // _MSC_VER + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h b/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h new file mode 100644 index 00000000..e9799d47 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h @@ -0,0 +1,64 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: jasonh@google.com (Jason Hsueh) +// +// Implements methods of coded_stream.h that need to be inlined for performance +// reasons, but should not be defined in a public header. + +#ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ +#define GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace io { + +inline bool CodedInputStream::InternalReadStringInline(string* buffer, + int size) { + if (size < 0) return false; // security: size is often user-supplied + + if (BufferSize() >= size) { + STLStringResizeUninitialized(buffer, size); + memcpy(string_as_array(buffer), buffer_, size); + Advance(size); + return true; + } + + return ReadStringFallback(buffer, size); +} + +} // namespace io +} // namespace protobuf +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h b/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h new file mode 100644 index 00000000..65dbc5b5 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h @@ -0,0 +1,207 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: brianolson@google.com (Brian Olson) +// +// This file contains the definition for classes GzipInputStream and +// GzipOutputStream. +// +// GzipInputStream decompresses data from an underlying +// ZeroCopyInputStream and provides the decompressed data as a +// ZeroCopyInputStream. +// +// GzipOutputStream is an ZeroCopyOutputStream that compresses data to +// an underlying ZeroCopyOutputStream. + +#ifndef GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ +#define GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ + +#include + +#include + +namespace google { +namespace protobuf { +namespace io { + +// A ZeroCopyInputStream that reads compressed data through zlib +class LIBPROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream { + public: + // Format key for constructor + enum Format { + // zlib will autodetect gzip header or deflate stream + AUTO = 0, + + // GZIP streams have some extra header data for file attributes. + GZIP = 1, + + // Simpler zlib stream format. + ZLIB = 2, + }; + + // buffer_size and format may be -1 for default of 64kB and GZIP format + explicit GzipInputStream( + ZeroCopyInputStream* sub_stream, + Format format = AUTO, + int buffer_size = -1); + virtual ~GzipInputStream(); + + // Return last error message or NULL if no error. + inline const char* ZlibErrorMessage() const { + return zcontext_.msg; + } + inline int ZlibErrorCode() const { + return zerror_; + } + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + private: + Format format_; + + ZeroCopyInputStream* sub_stream_; + + z_stream zcontext_; + int zerror_; + + void* output_buffer_; + void* output_position_; + size_t output_buffer_length_; + + int Inflate(int flush); + void DoNextOutput(const void** data, int* size); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipInputStream); +}; + + +class LIBPROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { + public: + // Format key for constructor + enum Format { + // GZIP streams have some extra header data for file attributes. + GZIP = 1, + + // Simpler zlib stream format. + ZLIB = 2, + }; + + struct Options { + // Defaults to GZIP. + Format format; + + // What size buffer to use internally. Defaults to 64kB. + int buffer_size; + + // A number between 0 and 9, where 0 is no compression and 9 is best + // compression. Defaults to Z_DEFAULT_COMPRESSION (see zlib.h). + int compression_level; + + // Defaults to Z_DEFAULT_STRATEGY. Can also be set to Z_FILTERED, + // Z_HUFFMAN_ONLY, or Z_RLE. See the documentation for deflateInit2 in + // zlib.h for definitions of these constants. + int compression_strategy; + + Options(); // Initializes with default values. + }; + + // Create a GzipOutputStream with default options. + explicit GzipOutputStream(ZeroCopyOutputStream* sub_stream); + + // Create a GzipOutputStream with the given options. + GzipOutputStream( + ZeroCopyOutputStream* sub_stream, + const Options& options); + + // DEPRECATED: Use one of the above constructors instead. + GzipOutputStream( + ZeroCopyOutputStream* sub_stream, + Format format, + int buffer_size = -1) GOOGLE_ATTRIBUTE_DEPRECATED; + + virtual ~GzipOutputStream(); + + // Return last error message or NULL if no error. + inline const char* ZlibErrorMessage() const { + return zcontext_.msg; + } + inline int ZlibErrorCode() const { + return zerror_; + } + + // Flushes data written so far to zipped data in the underlying stream. + // It is the caller's responsibility to flush the underlying stream if + // necessary. + // Compression may be less efficient stopping and starting around flushes. + // Returns true if no error. + bool Flush(); + + // Writes out all data and closes the gzip stream. + // It is the caller's responsibility to close the underlying stream if + // necessary. + // Returns true if no error. + bool Close(); + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + ZeroCopyOutputStream* sub_stream_; + // Result from calling Next() on sub_stream_ + void* sub_data_; + int sub_data_size_; + + z_stream zcontext_; + int zerror_; + void* input_buffer_; + size_t input_buffer_length_; + + // Shared constructor code. + void Init(ZeroCopyOutputStream* sub_stream, const Options& options); + + // Do some compression. + // Takes zlib flush mode. + // Returns zlib error code. + int Deflate(int flush); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipOutputStream); +}; + +} // namespace io +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h b/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h new file mode 100644 index 00000000..7a7a4e77 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h @@ -0,0 +1,54 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file exists solely to document the google::protobuf::io namespace. +// It is not compiled into anything, but it may be read by an automated +// documentation generator. + +namespace google { + +namespace protobuf { + +// Auxiliary classes used for I/O. +// +// The Protocol Buffer library uses the classes in this package to deal with +// I/O and encoding/decoding raw bytes. Most users will not need to +// deal with this package. However, users who want to adapt the system to +// work with their own I/O abstractions -- e.g., to allow Protocol Buffers +// to be read from a different kind of input stream without the need for a +// temporary buffer -- should take a closer look. +namespace io {} + +} // namespace protobuf +} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h b/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h new file mode 100644 index 00000000..5be48543 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h @@ -0,0 +1,136 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Utility class for writing text to a ZeroCopyOutputStream. + +#ifndef GOOGLE_PROTOBUF_IO_PRINTER_H__ +#define GOOGLE_PROTOBUF_IO_PRINTER_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace io { + +class ZeroCopyOutputStream; // zero_copy_stream.h + +// This simple utility class assists in code generation. It basically +// allows the caller to define a set of variables and then output some +// text with variable substitutions. Example usage: +// +// Printer printer(output, '$'); +// map vars; +// vars["name"] = "Bob"; +// printer.Print(vars, "My name is $name$."); +// +// The above writes "My name is Bob." to the output stream. +// +// Printer aggressively enforces correct usage, crashing (with assert failures) +// in the case of undefined variables in debug builds. This helps greatly in +// debugging code which uses it. +class LIBPROTOBUF_EXPORT Printer { + public: + // Create a printer that writes text to the given output stream. Use the + // given character as the delimiter for variables. + Printer(ZeroCopyOutputStream* output, char variable_delimiter); + ~Printer(); + + // Print some text after applying variable substitutions. If a particular + // variable in the text is not defined, this will crash. Variables to be + // substituted are identified by their names surrounded by delimiter + // characters (as given to the constructor). The variable bindings are + // defined by the given map. + void Print(const map& variables, const char* text); + + // Like the first Print(), except the substitutions are given as parameters. + void Print(const char* text); + // Like the first Print(), except the substitutions are given as parameters. + void Print(const char* text, const char* variable, const string& value); + // Like the first Print(), except the substitutions are given as parameters. + void Print(const char* text, const char* variable1, const string& value1, + const char* variable2, const string& value2); + // Like the first Print(), except the substitutions are given as parameters. + void Print(const char* text, const char* variable1, const string& value1, + const char* variable2, const string& value2, + const char* variable3, const string& value3); + // TODO(kenton): Overloaded versions with more variables? Three seems + // to be enough. + + // Indent text by two spaces. After calling Indent(), two spaces will be + // inserted at the beginning of each line of text. Indent() may be called + // multiple times to produce deeper indents. + void Indent(); + + // Reduces the current indent level by two spaces, or crashes if the indent + // level is zero. + void Outdent(); + + // Write a string to the output buffer. + // This method does not look for newlines to add indentation. + void PrintRaw(const string& data); + + // Write a zero-delimited string to output buffer. + // This method does not look for newlines to add indentation. + void PrintRaw(const char* data); + + // Write some bytes to the output buffer. + // This method does not look for newlines to add indentation. + void WriteRaw(const char* data, int size); + + // True if any write to the underlying stream failed. (We don't just + // crash in this case because this is an I/O failure, not a programming + // error.) + bool failed() const { return failed_; } + + private: + const char variable_delimiter_; + + ZeroCopyOutputStream* const output_; + char* buffer_; + int buffer_size_; + + string indent_; + bool at_start_of_line_; + bool failed_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Printer); +}; + +} // namespace io +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_PRINTER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h b/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h new file mode 100644 index 00000000..8f759abb --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h @@ -0,0 +1,313 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Class for parsing tokenized text from a ZeroCopyInputStream. + +#ifndef GOOGLE_PROTOBUF_IO_TOKENIZER_H__ +#define GOOGLE_PROTOBUF_IO_TOKENIZER_H__ + +#include +#include + +namespace google { +namespace protobuf { +namespace io { + +class ZeroCopyInputStream; // zero_copy_stream.h + +// Defined in this file. +class ErrorCollector; +class Tokenizer; + +// Abstract interface for an object which collects the errors that occur +// during parsing. A typical implementation might simply print the errors +// to stdout. +class LIBPROTOBUF_EXPORT ErrorCollector { + public: + inline ErrorCollector() {} + virtual ~ErrorCollector(); + + // Indicates that there was an error in the input at the given line and + // column numbers. The numbers are zero-based, so you may want to add + // 1 to each before printing them. + virtual void AddError(int line, int column, const string& message) = 0; + + // Indicates that there was a warning in the input at the given line and + // column numbers. The numbers are zero-based, so you may want to add + // 1 to each before printing them. + virtual void AddWarning(int line, int column, const string& message) { } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); +}; + +// This class converts a stream of raw text into a stream of tokens for +// the protocol definition parser to parse. The tokens recognized are +// similar to those that make up the C language; see the TokenType enum for +// precise descriptions. Whitespace and comments are skipped. By default, +// C- and C++-style comments are recognized, but other styles can be used by +// calling set_comment_style(). +class LIBPROTOBUF_EXPORT Tokenizer { + public: + // Construct a Tokenizer that reads and tokenizes text from the given + // input stream and writes errors to the given error_collector. + // The caller keeps ownership of input and error_collector. + Tokenizer(ZeroCopyInputStream* input, ErrorCollector* error_collector); + ~Tokenizer(); + + enum TokenType { + TYPE_START, // Next() has not yet been called. + TYPE_END, // End of input reached. "text" is empty. + + TYPE_IDENTIFIER, // A sequence of letters, digits, and underscores, not + // starting with a digit. It is an error for a number + // to be followed by an identifier with no space in + // between. + TYPE_INTEGER, // A sequence of digits representing an integer. Normally + // the digits are decimal, but a prefix of "0x" indicates + // a hex number and a leading zero indicates octal, just + // like with C numeric literals. A leading negative sign + // is NOT included in the token; it's up to the parser to + // interpret the unary minus operator on its own. + TYPE_FLOAT, // A floating point literal, with a fractional part and/or + // an exponent. Always in decimal. Again, never + // negative. + TYPE_STRING, // A quoted sequence of escaped characters. Either single + // or double quotes can be used, but they must match. + // A string literal cannot cross a line break. + TYPE_SYMBOL, // Any other printable character, like '!' or '+'. + // Symbols are always a single character, so "!+$%" is + // four tokens. + }; + + // Structure representing a token read from the token stream. + struct Token { + TokenType type; + string text; // The exact text of the token as it appeared in + // the input. e.g. tokens of TYPE_STRING will still + // be escaped and in quotes. + + // "line" and "column" specify the position of the first character of + // the token within the input stream. They are zero-based. + int line; + int column; + int end_column; + }; + + // Get the current token. This is updated when Next() is called. Before + // the first call to Next(), current() has type TYPE_START and no contents. + const Token& current(); + + // Return the previous token -- i.e. what current() returned before the + // previous call to Next(). + const Token& previous(); + + // Advance to the next token. Returns false if the end of the input is + // reached. + bool Next(); + + // Parse helpers --------------------------------------------------- + + // Parses a TYPE_FLOAT token. This never fails, so long as the text actually + // comes from a TYPE_FLOAT token parsed by Tokenizer. If it doesn't, the + // result is undefined (possibly an assert failure). + static double ParseFloat(const string& text); + + // Parses a TYPE_STRING token. This never fails, so long as the text actually + // comes from a TYPE_STRING token parsed by Tokenizer. If it doesn't, the + // result is undefined (possibly an assert failure). + static void ParseString(const string& text, string* output); + + // Identical to ParseString, but appends to output. + static void ParseStringAppend(const string& text, string* output); + + // Parses a TYPE_INTEGER token. Returns false if the result would be + // greater than max_value. Otherwise, returns true and sets *output to the + // result. If the text is not from a Token of type TYPE_INTEGER originally + // parsed by a Tokenizer, the result is undefined (possibly an assert + // failure). + static bool ParseInteger(const string& text, uint64 max_value, + uint64* output); + + // Options --------------------------------------------------------- + + // Set true to allow floats to be suffixed with the letter 'f'. Tokens + // which would otherwise be integers but which have the 'f' suffix will be + // forced to be interpreted as floats. For all other purposes, the 'f' is + // ignored. + void set_allow_f_after_float(bool value) { allow_f_after_float_ = value; } + + // Valid values for set_comment_style(). + enum CommentStyle { + // Line comments begin with "//", block comments are delimited by "/*" and + // "*/". + CPP_COMMENT_STYLE, + // Line comments begin with "#". No way to write block comments. + SH_COMMENT_STYLE + }; + + // Sets the comment style. + void set_comment_style(CommentStyle style) { comment_style_ = style; } + + // ----------------------------------------------------------------- + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Tokenizer); + + Token current_; // Returned by current(). + Token previous_; // Returned by previous(). + + ZeroCopyInputStream* input_; + ErrorCollector* error_collector_; + + char current_char_; // == buffer_[buffer_pos_], updated by NextChar(). + const char* buffer_; // Current buffer returned from input_. + int buffer_size_; // Size of buffer_. + int buffer_pos_; // Current position within the buffer. + bool read_error_; // Did we previously encounter a read error? + + // Line and column number of current_char_ within the whole input stream. + int line_; + int column_; + + // Position in buffer_ where StartToken() was called. If the token + // started in the previous buffer, this is zero, and current_.text already + // contains the part of the token from the previous buffer. If not + // currently parsing a token, this is -1. + int token_start_; + + // Options. + bool allow_f_after_float_; + CommentStyle comment_style_; + + // Since we count columns we need to interpret tabs somehow. We'll take + // the standard 8-character definition for lack of any way to do better. + static const int kTabWidth = 8; + + // ----------------------------------------------------------------- + // Helper methods. + + // Consume this character and advance to the next one. + void NextChar(); + + // Read a new buffer from the input. + void Refresh(); + + // Called when the current character is the first character of a new + // token (not including whitespace or comments). + inline void StartToken(); + // Called when the current character is the first character after the + // end of the last token. After this returns, current_.text will + // contain all text consumed since StartToken() was called. + inline void EndToken(); + + // Convenience method to add an error at the current line and column. + void AddError(const string& message) { + error_collector_->AddError(line_, column_, message); + } + + // ----------------------------------------------------------------- + // The following four methods are used to consume tokens of specific + // types. They are actually used to consume all characters *after* + // the first, since the calling function consumes the first character + // in order to decide what kind of token is being read. + + // Read and consume a string, ending when the given delimiter is + // consumed. + void ConsumeString(char delimiter); + + // Read and consume a number, returning TYPE_FLOAT or TYPE_INTEGER + // depending on what was read. This needs to know if the first + // character was a zero in order to correctly recognize hex and octal + // numbers. + // It also needs to know if the first characted was a . to parse floating + // point correctly. + TokenType ConsumeNumber(bool started_with_zero, bool started_with_dot); + + // Consume the rest of a line. + void ConsumeLineComment(); + // Consume until "*/". + void ConsumeBlockComment(); + + // ----------------------------------------------------------------- + // These helper methods make the parsing code more readable. The + // "character classes" refered to are defined at the top of the .cc file. + // Basically it is a C++ class with one method: + // static bool InClass(char c); + // The method returns true if c is a member of this "class", like "Letter" + // or "Digit". + + // Returns true if the current character is of the given character + // class, but does not consume anything. + template + inline bool LookingAt(); + + // If the current character is in the given class, consume it and return + // true. Otherwise return false. + // e.g. TryConsumeOne() + template + inline bool TryConsumeOne(); + + // Like above, but try to consume the specific character indicated. + inline bool TryConsume(char c); + + // Consume zero or more of the given character class. + template + inline void ConsumeZeroOrMore(); + + // Consume one or more of the given character class or log the given + // error message. + // e.g. ConsumeOneOrMore("Expected digits."); + template + inline void ConsumeOneOrMore(const char* error); +}; + +// inline methods ==================================================== +inline const Tokenizer::Token& Tokenizer::current() { + return current_; +} + +inline const Tokenizer::Token& Tokenizer::previous() { + return previous_; +} + +inline void Tokenizer::ParseString(const string& text, string* output) { + output->clear(); + ParseStringAppend(text, output); +} + +} // namespace io +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_TOKENIZER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h new file mode 100644 index 00000000..db5326f7 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h @@ -0,0 +1,238 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file contains the ZeroCopyInputStream and ZeroCopyOutputStream +// interfaces, which represent abstract I/O streams to and from which +// protocol buffers can be read and written. For a few simple +// implementations of these interfaces, see zero_copy_stream_impl.h. +// +// These interfaces are different from classic I/O streams in that they +// try to minimize the amount of data copying that needs to be done. +// To accomplish this, responsibility for allocating buffers is moved to +// the stream object, rather than being the responsibility of the caller. +// So, the stream can return a buffer which actually points directly into +// the final data structure where the bytes are to be stored, and the caller +// can interact directly with that buffer, eliminating an intermediate copy +// operation. +// +// As an example, consider the common case in which you are reading bytes +// from an array that is already in memory (or perhaps an mmap()ed file). +// With classic I/O streams, you would do something like: +// char buffer[BUFFER_SIZE]; +// input->Read(buffer, BUFFER_SIZE); +// DoSomething(buffer, BUFFER_SIZE); +// Then, the stream basically just calls memcpy() to copy the data from +// the array into your buffer. With a ZeroCopyInputStream, you would do +// this instead: +// const void* buffer; +// int size; +// input->Next(&buffer, &size); +// DoSomething(buffer, size); +// Here, no copy is performed. The input stream returns a pointer directly +// into the backing array, and the caller ends up reading directly from it. +// +// If you want to be able to read the old-fashion way, you can create +// a CodedInputStream or CodedOutputStream wrapping these objects and use +// their ReadRaw()/WriteRaw() methods. These will, of course, add a copy +// step, but Coded*Stream will handle buffering so at least it will be +// reasonably efficient. +// +// ZeroCopyInputStream example: +// // Read in a file and print its contents to stdout. +// int fd = open("myfile", O_RDONLY); +// ZeroCopyInputStream* input = new FileInputStream(fd); +// +// const void* buffer; +// int size; +// while (input->Next(&buffer, &size)) { +// cout.write(buffer, size); +// } +// +// delete input; +// close(fd); +// +// ZeroCopyOutputStream example: +// // Copy the contents of "infile" to "outfile", using plain read() for +// // "infile" but a ZeroCopyOutputStream for "outfile". +// int infd = open("infile", O_RDONLY); +// int outfd = open("outfile", O_WRONLY); +// ZeroCopyOutputStream* output = new FileOutputStream(outfd); +// +// void* buffer; +// int size; +// while (output->Next(&buffer, &size)) { +// int bytes = read(infd, buffer, size); +// if (bytes < size) { +// // Reached EOF. +// output->BackUp(size - bytes); +// break; +// } +// } +// +// delete output; +// close(infd); +// close(outfd); + +#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ +#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ + +#include +#include + +namespace google { + +namespace protobuf { +namespace io { + +// Defined in this file. +class ZeroCopyInputStream; +class ZeroCopyOutputStream; + +// Abstract interface similar to an input stream but designed to minimize +// copying. +class LIBPROTOBUF_EXPORT ZeroCopyInputStream { + public: + inline ZeroCopyInputStream() {} + virtual ~ZeroCopyInputStream(); + + // Obtains a chunk of data from the stream. + // + // Preconditions: + // * "size" and "data" are not NULL. + // + // Postconditions: + // * If the returned value is false, there is no more data to return or + // an error occurred. All errors are permanent. + // * Otherwise, "size" points to the actual number of bytes read and "data" + // points to a pointer to a buffer containing these bytes. + // * Ownership of this buffer remains with the stream, and the buffer + // remains valid only until some other method of the stream is called + // or the stream is destroyed. + // * It is legal for the returned buffer to have zero size, as long + // as repeatedly calling Next() eventually yields a buffer with non-zero + // size. + virtual bool Next(const void** data, int* size) = 0; + + // Backs up a number of bytes, so that the next call to Next() returns + // data again that was already returned by the last call to Next(). This + // is useful when writing procedures that are only supposed to read up + // to a certain point in the input, then return. If Next() returns a + // buffer that goes beyond what you wanted to read, you can use BackUp() + // to return to the point where you intended to finish. + // + // Preconditions: + // * The last method called must have been Next(). + // * count must be less than or equal to the size of the last buffer + // returned by Next(). + // + // Postconditions: + // * The last "count" bytes of the last buffer returned by Next() will be + // pushed back into the stream. Subsequent calls to Next() will return + // the same data again before producing new data. + virtual void BackUp(int count) = 0; + + // Skips a number of bytes. Returns false if the end of the stream is + // reached or some input error occurred. In the end-of-stream case, the + // stream is advanced to the end of the stream (so ByteCount() will return + // the total size of the stream). + virtual bool Skip(int count) = 0; + + // Returns the total number of bytes read since this object was created. + virtual int64 ByteCount() const = 0; + + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyInputStream); +}; + +// Abstract interface similar to an output stream but designed to minimize +// copying. +class LIBPROTOBUF_EXPORT ZeroCopyOutputStream { + public: + inline ZeroCopyOutputStream() {} + virtual ~ZeroCopyOutputStream(); + + // Obtains a buffer into which data can be written. Any data written + // into this buffer will eventually (maybe instantly, maybe later on) + // be written to the output. + // + // Preconditions: + // * "size" and "data" are not NULL. + // + // Postconditions: + // * If the returned value is false, an error occurred. All errors are + // permanent. + // * Otherwise, "size" points to the actual number of bytes in the buffer + // and "data" points to the buffer. + // * Ownership of this buffer remains with the stream, and the buffer + // remains valid only until some other method of the stream is called + // or the stream is destroyed. + // * Any data which the caller stores in this buffer will eventually be + // written to the output (unless BackUp() is called). + // * It is legal for the returned buffer to have zero size, as long + // as repeatedly calling Next() eventually yields a buffer with non-zero + // size. + virtual bool Next(void** data, int* size) = 0; + + // Backs up a number of bytes, so that the end of the last buffer returned + // by Next() is not actually written. This is needed when you finish + // writing all the data you want to write, but the last buffer was bigger + // than you needed. You don't want to write a bunch of garbage after the + // end of your data, so you use BackUp() to back up. + // + // Preconditions: + // * The last method called must have been Next(). + // * count must be less than or equal to the size of the last buffer + // returned by Next(). + // * The caller must not have written anything to the last "count" bytes + // of that buffer. + // + // Postconditions: + // * The last "count" bytes of the last buffer returned by Next() will be + // ignored. + virtual void BackUp(int count) = 0; + + // Returns the total number of bytes written since this object was created. + virtual int64 ByteCount() const = 0; + + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyOutputStream); +}; + +} // namespace io +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h new file mode 100644 index 00000000..9fedb005 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h @@ -0,0 +1,357 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file contains common implementations of the interfaces defined in +// zero_copy_stream.h which are only included in the full (non-lite) +// protobuf library. These implementations include Unix file descriptors +// and C++ iostreams. See also: zero_copy_stream_impl_lite.h + +#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ +#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ + +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace io { + + +// =================================================================== + +// A ZeroCopyInputStream which reads from a file descriptor. +// +// FileInputStream is preferred over using an ifstream with IstreamInputStream. +// The latter will introduce an extra layer of buffering, harming performance. +// Also, it's conceivable that FileInputStream could someday be enhanced +// to use zero-copy file descriptors on OSs which support them. +class LIBPROTOBUF_EXPORT FileInputStream : public ZeroCopyInputStream { + public: + // Creates a stream that reads from the given Unix file descriptor. + // If a block_size is given, it specifies the number of bytes that + // should be read and returned with each call to Next(). Otherwise, + // a reasonable default is used. + explicit FileInputStream(int file_descriptor, int block_size = -1); + ~FileInputStream(); + + // Flushes any buffers and closes the underlying file. Returns false if + // an error occurs during the process; use GetErrno() to examine the error. + // Even if an error occurs, the file descriptor is closed when this returns. + bool Close(); + + // By default, the file descriptor is not closed when the stream is + // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: + // This leaves no way for the caller to detect if close() fails. If + // detecting close() errors is important to you, you should arrange + // to close the descriptor yourself. + void SetCloseOnDelete(bool value) { copying_input_.SetCloseOnDelete(value); } + + // If an I/O error has occurred on this file descriptor, this is the + // errno from that error. Otherwise, this is zero. Once an error + // occurs, the stream is broken and all subsequent operations will + // fail. + int GetErrno() { return copying_input_.GetErrno(); } + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingFileInputStream : public CopyingInputStream { + public: + CopyingFileInputStream(int file_descriptor); + ~CopyingFileInputStream(); + + bool Close(); + void SetCloseOnDelete(bool value) { close_on_delete_ = value; } + int GetErrno() { return errno_; } + + // implements CopyingInputStream --------------------------------- + int Read(void* buffer, int size); + int Skip(int count); + + private: + // The file descriptor. + const int file_; + bool close_on_delete_; + bool is_closed_; + + // The errno of the I/O error, if one has occurred. Otherwise, zero. + int errno_; + + // Did we try to seek once and fail? If so, we assume this file descriptor + // doesn't support seeking and won't try again. + bool previous_seek_failed_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileInputStream); + }; + + CopyingFileInputStream copying_input_; + CopyingInputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileInputStream); +}; + +// =================================================================== + +// A ZeroCopyOutputStream which writes to a file descriptor. +// +// FileOutputStream is preferred over using an ofstream with +// OstreamOutputStream. The latter will introduce an extra layer of buffering, +// harming performance. Also, it's conceivable that FileOutputStream could +// someday be enhanced to use zero-copy file descriptors on OSs which +// support them. +class LIBPROTOBUF_EXPORT FileOutputStream : public ZeroCopyOutputStream { + public: + // Creates a stream that writes to the given Unix file descriptor. + // If a block_size is given, it specifies the size of the buffers + // that should be returned by Next(). Otherwise, a reasonable default + // is used. + explicit FileOutputStream(int file_descriptor, int block_size = -1); + ~FileOutputStream(); + + // Flushes any buffers and closes the underlying file. Returns false if + // an error occurs during the process; use GetErrno() to examine the error. + // Even if an error occurs, the file descriptor is closed when this returns. + bool Close(); + + // Flushes FileOutputStream's buffers but does not close the + // underlying file. No special measures are taken to ensure that + // underlying operating system file object is synchronized to disk. + bool Flush(); + + // By default, the file descriptor is not closed when the stream is + // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: + // This leaves no way for the caller to detect if close() fails. If + // detecting close() errors is important to you, you should arrange + // to close the descriptor yourself. + void SetCloseOnDelete(bool value) { copying_output_.SetCloseOnDelete(value); } + + // If an I/O error has occurred on this file descriptor, this is the + // errno from that error. Otherwise, this is zero. Once an error + // occurs, the stream is broken and all subsequent operations will + // fail. + int GetErrno() { return copying_output_.GetErrno(); } + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingFileOutputStream : public CopyingOutputStream { + public: + CopyingFileOutputStream(int file_descriptor); + ~CopyingFileOutputStream(); + + bool Close(); + void SetCloseOnDelete(bool value) { close_on_delete_ = value; } + int GetErrno() { return errno_; } + + // implements CopyingOutputStream -------------------------------- + bool Write(const void* buffer, int size); + + private: + // The file descriptor. + const int file_; + bool close_on_delete_; + bool is_closed_; + + // The errno of the I/O error, if one has occurred. Otherwise, zero. + int errno_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileOutputStream); + }; + + CopyingFileOutputStream copying_output_; + CopyingOutputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileOutputStream); +}; + +// =================================================================== + +// A ZeroCopyInputStream which reads from a C++ istream. +// +// Note that for reading files (or anything represented by a file descriptor), +// FileInputStream is more efficient. +class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { + public: + // Creates a stream that reads from the given C++ istream. + // If a block_size is given, it specifies the number of bytes that + // should be read and returned with each call to Next(). Otherwise, + // a reasonable default is used. + explicit IstreamInputStream(istream* stream, int block_size = -1); + ~IstreamInputStream(); + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream { + public: + CopyingIstreamInputStream(istream* input); + ~CopyingIstreamInputStream(); + + // implements CopyingInputStream --------------------------------- + int Read(void* buffer, int size); + // (We use the default implementation of Skip().) + + private: + // The stream. + istream* input_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); + }; + + CopyingIstreamInputStream copying_input_; + CopyingInputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream); +}; + +// =================================================================== + +// A ZeroCopyOutputStream which writes to a C++ ostream. +// +// Note that for writing files (or anything represented by a file descriptor), +// FileOutputStream is more efficient. +class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { + public: + // Creates a stream that writes to the given C++ ostream. + // If a block_size is given, it specifies the size of the buffers + // that should be returned by Next(). Otherwise, a reasonable default + // is used. + explicit OstreamOutputStream(ostream* stream, int block_size = -1); + ~OstreamOutputStream(); + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStream { + public: + CopyingOstreamOutputStream(ostream* output); + ~CopyingOstreamOutputStream(); + + // implements CopyingOutputStream -------------------------------- + bool Write(const void* buffer, int size); + + private: + // The stream. + ostream* output_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); + }; + + CopyingOstreamOutputStream copying_output_; + CopyingOutputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream); +}; + +// =================================================================== + +// A ZeroCopyInputStream which reads from several other streams in sequence. +// ConcatenatingInputStream is unable to distinguish between end-of-stream +// and read errors in the underlying streams, so it assumes any errors mean +// end-of-stream. So, if the underlying streams fail for any other reason, +// ConcatenatingInputStream may do odd things. It is suggested that you do +// not use ConcatenatingInputStream on streams that might produce read errors +// other than end-of-stream. +class LIBPROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream { + public: + // All streams passed in as well as the array itself must remain valid + // until the ConcatenatingInputStream is destroyed. + ConcatenatingInputStream(ZeroCopyInputStream* const streams[], int count); + ~ConcatenatingInputStream(); + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + + private: + // As streams are retired, streams_ is incremented and count_ is + // decremented. + ZeroCopyInputStream* const* streams_; + int stream_count_; + int64 bytes_retired_; // Bytes read from previous streams. + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ConcatenatingInputStream); +}; + +// =================================================================== + +// A ZeroCopyInputStream which wraps some other stream and limits it to +// a particular byte count. +class LIBPROTOBUF_EXPORT LimitingInputStream : public ZeroCopyInputStream { + public: + LimitingInputStream(ZeroCopyInputStream* input, int64 limit); + ~LimitingInputStream(); + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + + private: + ZeroCopyInputStream* input_; + int64 limit_; // Decreases as we go, becomes negative if we overshoot. + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); +}; + +// =================================================================== + +} // namespace io +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h new file mode 100644 index 00000000..153f543e --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h @@ -0,0 +1,340 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file contains common implementations of the interfaces defined in +// zero_copy_stream.h which are included in the "lite" protobuf library. +// These implementations cover I/O on raw arrays and strings, as well as +// adaptors which make it easy to implement streams based on traditional +// streams. Of course, many users will probably want to write their own +// implementations of these interfaces specific to the particular I/O +// abstractions they prefer to use, but these should cover the most common +// cases. + +#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ +#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ + +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace io { + +// =================================================================== + +// A ZeroCopyInputStream backed by an in-memory array of bytes. +class LIBPROTOBUF_EXPORT ArrayInputStream : public ZeroCopyInputStream { + public: + // Create an InputStream that returns the bytes pointed to by "data". + // "data" remains the property of the caller but must remain valid until + // the stream is destroyed. If a block_size is given, calls to Next() + // will return data blocks no larger than the given size. Otherwise, the + // first call to Next() returns the entire array. block_size is mainly + // useful for testing; in production you would probably never want to set + // it. + ArrayInputStream(const void* data, int size, int block_size = -1); + ~ArrayInputStream(); + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + + private: + const uint8* const data_; // The byte array. + const int size_; // Total size of the array. + const int block_size_; // How many bytes to return at a time. + + int position_; + int last_returned_size_; // How many bytes we returned last time Next() + // was called (used for error checking only). + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayInputStream); +}; + +// =================================================================== + +// A ZeroCopyOutputStream backed by an in-memory array of bytes. +class LIBPROTOBUF_EXPORT ArrayOutputStream : public ZeroCopyOutputStream { + public: + // Create an OutputStream that writes to the bytes pointed to by "data". + // "data" remains the property of the caller but must remain valid until + // the stream is destroyed. If a block_size is given, calls to Next() + // will return data blocks no larger than the given size. Otherwise, the + // first call to Next() returns the entire array. block_size is mainly + // useful for testing; in production you would probably never want to set + // it. + ArrayOutputStream(void* data, int size, int block_size = -1); + ~ArrayOutputStream(); + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + uint8* const data_; // The byte array. + const int size_; // Total size of the array. + const int block_size_; // How many bytes to return at a time. + + int position_; + int last_returned_size_; // How many bytes we returned last time Next() + // was called (used for error checking only). + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayOutputStream); +}; + +// =================================================================== + +// A ZeroCopyOutputStream which appends bytes to a string. +class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream { + public: + // Create a StringOutputStream which appends bytes to the given string. + // The string remains property of the caller, but it MUST NOT be accessed + // in any way until the stream is destroyed. + // + // Hint: If you call target->reserve(n) before creating the stream, + // the first call to Next() will return at least n bytes of buffer + // space. + explicit StringOutputStream(string* target); + ~StringOutputStream(); + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + static const int kMinimumSize = 16; + + string* target_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream); +}; + +// Note: There is no StringInputStream. Instead, just create an +// ArrayInputStream as follows: +// ArrayInputStream input(str.data(), str.size()); + +// =================================================================== + +// A generic traditional input stream interface. +// +// Lots of traditional input streams (e.g. file descriptors, C stdio +// streams, and C++ iostreams) expose an interface where every read +// involves copying bytes into a buffer. If you want to take such an +// interface and make a ZeroCopyInputStream based on it, simply implement +// CopyingInputStream and then use CopyingInputStreamAdaptor. +// +// CopyingInputStream implementations should avoid buffering if possible. +// CopyingInputStreamAdaptor does its own buffering and will read data +// in large blocks. +class LIBPROTOBUF_EXPORT CopyingInputStream { + public: + virtual ~CopyingInputStream(); + + // Reads up to "size" bytes into the given buffer. Returns the number of + // bytes read. Read() waits until at least one byte is available, or + // returns zero if no bytes will ever become available (EOF), or -1 if a + // permanent read error occurred. + virtual int Read(void* buffer, int size) = 0; + + // Skips the next "count" bytes of input. Returns the number of bytes + // actually skipped. This will always be exactly equal to "count" unless + // EOF was reached or a permanent read error occurred. + // + // The default implementation just repeatedly calls Read() into a scratch + // buffer. + virtual int Skip(int count); +}; + +// A ZeroCopyInputStream which reads from a CopyingInputStream. This is +// useful for implementing ZeroCopyInputStreams that read from traditional +// streams. Note that this class is not really zero-copy. +// +// If you want to read from file descriptors or C++ istreams, this is +// already implemented for you: use FileInputStream or IstreamInputStream +// respectively. +class LIBPROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream { + public: + // Creates a stream that reads from the given CopyingInputStream. + // If a block_size is given, it specifies the number of bytes that + // should be read and returned with each call to Next(). Otherwise, + // a reasonable default is used. The caller retains ownership of + // copying_stream unless SetOwnsCopyingStream(true) is called. + explicit CopyingInputStreamAdaptor(CopyingInputStream* copying_stream, + int block_size = -1); + ~CopyingInputStreamAdaptor(); + + // Call SetOwnsCopyingStream(true) to tell the CopyingInputStreamAdaptor to + // delete the underlying CopyingInputStream when it is destroyed. + void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; } + + // implements ZeroCopyInputStream ---------------------------------- + bool Next(const void** data, int* size); + void BackUp(int count); + bool Skip(int count); + int64 ByteCount() const; + + private: + // Insures that buffer_ is not NULL. + void AllocateBufferIfNeeded(); + // Frees the buffer and resets buffer_used_. + void FreeBuffer(); + + // The underlying copying stream. + CopyingInputStream* copying_stream_; + bool owns_copying_stream_; + + // True if we have seen a permenant error from the underlying stream. + bool failed_; + + // The current position of copying_stream_, relative to the point where + // we started reading. + int64 position_; + + // Data is read into this buffer. It may be NULL if no buffer is currently + // in use. Otherwise, it points to an array of size buffer_size_. + scoped_array buffer_; + const int buffer_size_; + + // Number of valid bytes currently in the buffer (i.e. the size last + // returned by Next()). 0 <= buffer_used_ <= buffer_size_. + int buffer_used_; + + // Number of bytes in the buffer which were backed up over by a call to + // BackUp(). These need to be returned again. + // 0 <= backup_bytes_ <= buffer_used_ + int backup_bytes_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingInputStreamAdaptor); +}; + +// =================================================================== + +// A generic traditional output stream interface. +// +// Lots of traditional output streams (e.g. file descriptors, C stdio +// streams, and C++ iostreams) expose an interface where every write +// involves copying bytes from a buffer. If you want to take such an +// interface and make a ZeroCopyOutputStream based on it, simply implement +// CopyingOutputStream and then use CopyingOutputStreamAdaptor. +// +// CopyingOutputStream implementations should avoid buffering if possible. +// CopyingOutputStreamAdaptor does its own buffering and will write data +// in large blocks. +class LIBPROTOBUF_EXPORT CopyingOutputStream { + public: + virtual ~CopyingOutputStream(); + + // Writes "size" bytes from the given buffer to the output. Returns true + // if successful, false on a write error. + virtual bool Write(const void* buffer, int size) = 0; +}; + +// A ZeroCopyOutputStream which writes to a CopyingOutputStream. This is +// useful for implementing ZeroCopyOutputStreams that write to traditional +// streams. Note that this class is not really zero-copy. +// +// If you want to write to file descriptors or C++ ostreams, this is +// already implemented for you: use FileOutputStream or OstreamOutputStream +// respectively. +class LIBPROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStream { + public: + // Creates a stream that writes to the given Unix file descriptor. + // If a block_size is given, it specifies the size of the buffers + // that should be returned by Next(). Otherwise, a reasonable default + // is used. + explicit CopyingOutputStreamAdaptor(CopyingOutputStream* copying_stream, + int block_size = -1); + ~CopyingOutputStreamAdaptor(); + + // Writes all pending data to the underlying stream. Returns false if a + // write error occurred on the underlying stream. (The underlying + // stream itself is not necessarily flushed.) + bool Flush(); + + // Call SetOwnsCopyingStream(true) to tell the CopyingOutputStreamAdaptor to + // delete the underlying CopyingOutputStream when it is destroyed. + void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; } + + // implements ZeroCopyOutputStream --------------------------------- + bool Next(void** data, int* size); + void BackUp(int count); + int64 ByteCount() const; + + private: + // Write the current buffer, if it is present. + bool WriteBuffer(); + // Insures that buffer_ is not NULL. + void AllocateBufferIfNeeded(); + // Frees the buffer. + void FreeBuffer(); + + // The underlying copying stream. + CopyingOutputStream* copying_stream_; + bool owns_copying_stream_; + + // True if we have seen a permenant error from the underlying stream. + bool failed_; + + // The current position of copying_stream_, relative to the point where + // we started writing. + int64 position_; + + // Data is written from this buffer. It may be NULL if no buffer is + // currently in use. Otherwise, it points to an array of size buffer_size_. + scoped_array buffer_; + const int buffer_size_; + + // Number of valid bytes currently in the buffer (i.e. the size last + // returned by Next()). When BackUp() is called, we just reduce this. + // 0 <= buffer_used_ <= buffer_size_. + int buffer_used_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOutputStreamAdaptor); +}; + +// =================================================================== + +} // namespace io +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/message.h b/ext/protobuf-2.4.1/src/google/protobuf/message.h new file mode 100644 index 00000000..4bbc6418 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/message.h @@ -0,0 +1,692 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Defines Message, the abstract interface implemented by non-lite +// protocol message objects. Although it's possible to implement this +// interface manually, most users will use the protocol compiler to +// generate implementations. +// +// Example usage: +// +// Say you have a message defined as: +// +// message Foo { +// optional string text = 1; +// repeated int32 numbers = 2; +// } +// +// Then, if you used the protocol compiler to generate a class from the above +// definition, you could use it like so: +// +// string data; // Will store a serialized version of the message. +// +// { +// // Create a message and serialize it. +// Foo foo; +// foo.set_text("Hello World!"); +// foo.add_numbers(1); +// foo.add_numbers(5); +// foo.add_numbers(42); +// +// foo.SerializeToString(&data); +// } +// +// { +// // Parse the serialized message and check that it contains the +// // correct data. +// Foo foo; +// foo.ParseFromString(data); +// +// assert(foo.text() == "Hello World!"); +// assert(foo.numbers_size() == 3); +// assert(foo.numbers(0) == 1); +// assert(foo.numbers(1) == 5); +// assert(foo.numbers(2) == 42); +// } +// +// { +// // Same as the last block, but do it dynamically via the Message +// // reflection interface. +// Message* foo = new Foo; +// Descriptor* descriptor = foo->GetDescriptor(); +// +// // Get the descriptors for the fields we're interested in and verify +// // their types. +// FieldDescriptor* text_field = descriptor->FindFieldByName("text"); +// assert(text_field != NULL); +// assert(text_field->type() == FieldDescriptor::TYPE_STRING); +// assert(text_field->label() == FieldDescriptor::TYPE_OPTIONAL); +// FieldDescriptor* numbers_field = descriptor->FindFieldByName("numbers"); +// assert(numbers_field != NULL); +// assert(numbers_field->type() == FieldDescriptor::TYPE_INT32); +// assert(numbers_field->label() == FieldDescriptor::TYPE_REPEATED); +// +// // Parse the message. +// foo->ParseFromString(data); +// +// // Use the reflection interface to examine the contents. +// const Reflection* reflection = foo->GetReflection(); +// assert(reflection->GetString(foo, text_field) == "Hello World!"); +// assert(reflection->FieldSize(foo, numbers_field) == 3); +// assert(reflection->GetRepeatedInt32(foo, numbers_field, 0) == 1); +// assert(reflection->GetRepeatedInt32(foo, numbers_field, 1) == 5); +// assert(reflection->GetRepeatedInt32(foo, numbers_field, 2) == 42); +// +// delete foo; +// } + +#ifndef GOOGLE_PROTOBUF_MESSAGE_H__ +#define GOOGLE_PROTOBUF_MESSAGE_H__ + +#include +#include + +#ifdef __DECCXX +// HP C++'s iosfwd doesn't work. +#include +#else +#include +#endif + +#include + +#include + + +namespace google { +namespace protobuf { + +// Defined in this file. +class Message; +class Reflection; +class MessageFactory; + +// Defined in other files. +class Descriptor; // descriptor.h +class FieldDescriptor; // descriptor.h +class EnumDescriptor; // descriptor.h +class EnumValueDescriptor; // descriptor.h +namespace io { + class ZeroCopyInputStream; // zero_copy_stream.h + class ZeroCopyOutputStream; // zero_copy_stream.h + class CodedInputStream; // coded_stream.h + class CodedOutputStream; // coded_stream.h +} +class UnknownFieldSet; // unknown_field_set.h + +// A container to hold message metadata. +struct Metadata { + const Descriptor* descriptor; + const Reflection* reflection; +}; + +// Returns the EnumDescriptor for enum type E, which must be a +// proto-declared enum type. Code generated by the protocol compiler +// will include specializations of this template for each enum type declared. +template +const EnumDescriptor* GetEnumDescriptor(); + +// Abstract interface for protocol messages. +// +// See also MessageLite, which contains most every-day operations. Message +// adds descriptors and reflection on top of that. +// +// The methods of this class that are virtual but not pure-virtual have +// default implementations based on reflection. Message classes which are +// optimized for speed will want to override these with faster implementations, +// but classes optimized for code size may be happy with keeping them. See +// the optimize_for option in descriptor.proto. +class LIBPROTOBUF_EXPORT Message : public MessageLite { + public: + inline Message() {} + virtual ~Message(); + + // Basic Operations ------------------------------------------------ + + // Construct a new instance of the same type. Ownership is passed to the + // caller. (This is also defined in MessageLite, but is defined again here + // for return-type covariance.) + virtual Message* New() const = 0; + + // Make this message into a copy of the given message. The given message + // must have the same descriptor, but need not necessarily be the same class. + // By default this is just implemented as "Clear(); MergeFrom(from);". + virtual void CopyFrom(const Message& from); + + // Merge the fields from the given message into this message. Singular + // fields will be overwritten, except for embedded messages which will + // be merged. Repeated fields will be concatenated. The given message + // must be of the same type as this message (i.e. the exact same class). + virtual void MergeFrom(const Message& from); + + // Verifies that IsInitialized() returns true. GOOGLE_CHECK-fails otherwise, with + // a nice error message. + void CheckInitialized() const; + + // Slowly build a list of all required fields that are not set. + // This is much, much slower than IsInitialized() as it is implemented + // purely via reflection. Generally, you should not call this unless you + // have already determined that an error exists by calling IsInitialized(). + void FindInitializationErrors(vector* errors) const; + + // Like FindInitializationErrors, but joins all the strings, delimited by + // commas, and returns them. + string InitializationErrorString() const; + + // Clears all unknown fields from this message and all embedded messages. + // Normally, if unknown tag numbers are encountered when parsing a message, + // the tag and value are stored in the message's UnknownFieldSet and + // then written back out when the message is serialized. This allows servers + // which simply route messages to other servers to pass through messages + // that have new field definitions which they don't yet know about. However, + // this behavior can have security implications. To avoid it, call this + // method after parsing. + // + // See Reflection::GetUnknownFields() for more on unknown fields. + virtual void DiscardUnknownFields(); + + // Computes (an estimate of) the total number of bytes currently used for + // storing the message in memory. The default implementation calls the + // Reflection object's SpaceUsed() method. + virtual int SpaceUsed() const; + + // Debugging & Testing---------------------------------------------- + + // Generates a human readable form of this message, useful for debugging + // and other purposes. + string DebugString() const; + // Like DebugString(), but with less whitespace. + string ShortDebugString() const; + // Like DebugString(), but do not escape UTF-8 byte sequences. + string Utf8DebugString() const; + // Convenience function useful in GDB. Prints DebugString() to stdout. + void PrintDebugString() const; + + // Heavy I/O ------------------------------------------------------- + // Additional parsing and serialization methods not implemented by + // MessageLite because they are not supported by the lite library. + + // Parse a protocol buffer from a file descriptor. If successful, the entire + // input will be consumed. + bool ParseFromFileDescriptor(int file_descriptor); + // Like ParseFromFileDescriptor(), but accepts messages that are missing + // required fields. + bool ParsePartialFromFileDescriptor(int file_descriptor); + // Parse a protocol buffer from a C++ istream. If successful, the entire + // input will be consumed. + bool ParseFromIstream(istream* input); + // Like ParseFromIstream(), but accepts messages that are missing + // required fields. + bool ParsePartialFromIstream(istream* input); + + // Serialize the message and write it to the given file descriptor. All + // required fields must be set. + bool SerializeToFileDescriptor(int file_descriptor) const; + // Like SerializeToFileDescriptor(), but allows missing required fields. + bool SerializePartialToFileDescriptor(int file_descriptor) const; + // Serialize the message and write it to the given C++ ostream. All + // required fields must be set. + bool SerializeToOstream(ostream* output) const; + // Like SerializeToOstream(), but allows missing required fields. + bool SerializePartialToOstream(ostream* output) const; + + + // Reflection-based methods ---------------------------------------- + // These methods are pure-virtual in MessageLite, but Message provides + // reflection-based default implementations. + + virtual string GetTypeName() const; + virtual void Clear(); + virtual bool IsInitialized() const; + virtual void CheckTypeAndMergeFrom(const MessageLite& other); + virtual bool MergePartialFromCodedStream(io::CodedInputStream* input); + virtual int ByteSize() const; + virtual void SerializeWithCachedSizes(io::CodedOutputStream* output) const; + + private: + // This is called only by the default implementation of ByteSize(), to + // update the cached size. If you override ByteSize(), you do not need + // to override this. If you do not override ByteSize(), you MUST override + // this; the default implementation will crash. + // + // The method is private because subclasses should never call it; only + // override it. Yes, C++ lets you do that. Crazy, huh? + virtual void SetCachedSize(int size) const; + + public: + + // Introspection --------------------------------------------------- + + // Typedef for backwards-compatibility. + typedef google::protobuf::Reflection Reflection; + + // Get a Descriptor for this message's type. This describes what + // fields the message contains, the types of those fields, etc. + const Descriptor* GetDescriptor() const { return GetMetadata().descriptor; } + + // Get the Reflection interface for this Message, which can be used to + // read and modify the fields of the Message dynamically (in other words, + // without knowing the message type at compile time). This object remains + // property of the Message. + // + // This method remains virtual in case a subclass does not implement + // reflection and wants to override the default behavior. + virtual const Reflection* GetReflection() const { + return GetMetadata().reflection; + } + + protected: + // Get a struct containing the metadata for the Message. Most subclasses only + // need to implement this method, rather than the GetDescriptor() and + // GetReflection() wrappers. + virtual Metadata GetMetadata() const = 0; + + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Message); +}; + +// This interface contains methods that can be used to dynamically access +// and modify the fields of a protocol message. Their semantics are +// similar to the accessors the protocol compiler generates. +// +// To get the Reflection for a given Message, call Message::GetReflection(). +// +// This interface is separate from Message only for efficiency reasons; +// the vast majority of implementations of Message will share the same +// implementation of Reflection (GeneratedMessageReflection, +// defined in generated_message.h), and all Messages of a particular class +// should share the same Reflection object (though you should not rely on +// the latter fact). +// +// There are several ways that these methods can be used incorrectly. For +// example, any of the following conditions will lead to undefined +// results (probably assertion failures): +// - The FieldDescriptor is not a field of this message type. +// - The method called is not appropriate for the field's type. For +// each field type in FieldDescriptor::TYPE_*, there is only one +// Get*() method, one Set*() method, and one Add*() method that is +// valid for that type. It should be obvious which (except maybe +// for TYPE_BYTES, which are represented using strings in C++). +// - A Get*() or Set*() method for singular fields is called on a repeated +// field. +// - GetRepeated*(), SetRepeated*(), or Add*() is called on a non-repeated +// field. +// - The Message object passed to any method is not of the right type for +// this Reflection object (i.e. message.GetReflection() != reflection). +// +// You might wonder why there is not any abstract representation for a field +// of arbitrary type. E.g., why isn't there just a "GetField()" method that +// returns "const Field&", where "Field" is some class with accessors like +// "GetInt32Value()". The problem is that someone would have to deal with +// allocating these Field objects. For generated message classes, having to +// allocate space for an additional object to wrap every field would at least +// double the message's memory footprint, probably worse. Allocating the +// objects on-demand, on the other hand, would be expensive and prone to +// memory leaks. So, instead we ended up with this flat interface. +// +// TODO(kenton): Create a utility class which callers can use to read and +// write fields from a Reflection without paying attention to the type. +class LIBPROTOBUF_EXPORT Reflection { + public: + // TODO(kenton): Remove parameter. + inline Reflection() {} + virtual ~Reflection(); + + // Get the UnknownFieldSet for the message. This contains fields which + // were seen when the Message was parsed but were not recognized according + // to the Message's definition. + virtual const UnknownFieldSet& GetUnknownFields( + const Message& message) const = 0; + // Get a mutable pointer to the UnknownFieldSet for the message. This + // contains fields which were seen when the Message was parsed but were not + // recognized according to the Message's definition. + virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0; + + // Estimate the amount of memory used by the message object. + virtual int SpaceUsed(const Message& message) const = 0; + + // Check if the given non-repeated field is set. + virtual bool HasField(const Message& message, + const FieldDescriptor* field) const = 0; + + // Get the number of elements of a repeated field. + virtual int FieldSize(const Message& message, + const FieldDescriptor* field) const = 0; + + // Clear the value of a field, so that HasField() returns false or + // FieldSize() returns zero. + virtual void ClearField(Message* message, + const FieldDescriptor* field) const = 0; + + // Remove the last element of a repeated field. + // We don't provide a way to remove any element other than the last + // because it invites inefficient use, such as O(n^2) filtering loops + // that should have been O(n). If you want to remove an element other + // than the last, the best way to do it is to re-arrange the elements + // (using Swap()) so that the one you want removed is at the end, then + // call RemoveLast(). + virtual void RemoveLast(Message* message, + const FieldDescriptor* field) const = 0; + + // Swap the complete contents of two messages. + virtual void Swap(Message* message1, Message* message2) const = 0; + + // Swap two elements of a repeated field. + virtual void SwapElements(Message* message, + const FieldDescriptor* field, + int index1, + int index2) const = 0; + + // List all fields of the message which are currently set. This includes + // extensions. Singular fields will only be listed if HasField(field) would + // return true and repeated fields will only be listed if FieldSize(field) + // would return non-zero. Fields (both normal fields and extension fields) + // will be listed ordered by field number. + virtual void ListFields(const Message& message, + vector* output) const = 0; + + // Singular field getters ------------------------------------------ + // These get the value of a non-repeated field. They return the default + // value for fields that aren't set. + + virtual int32 GetInt32 (const Message& message, + const FieldDescriptor* field) const = 0; + virtual int64 GetInt64 (const Message& message, + const FieldDescriptor* field) const = 0; + virtual uint32 GetUInt32(const Message& message, + const FieldDescriptor* field) const = 0; + virtual uint64 GetUInt64(const Message& message, + const FieldDescriptor* field) const = 0; + virtual float GetFloat (const Message& message, + const FieldDescriptor* field) const = 0; + virtual double GetDouble(const Message& message, + const FieldDescriptor* field) const = 0; + virtual bool GetBool (const Message& message, + const FieldDescriptor* field) const = 0; + virtual string GetString(const Message& message, + const FieldDescriptor* field) const = 0; + virtual const EnumValueDescriptor* GetEnum( + const Message& message, const FieldDescriptor* field) const = 0; + // See MutableMessage() for the meaning of the "factory" parameter. + virtual const Message& GetMessage(const Message& message, + const FieldDescriptor* field, + MessageFactory* factory = NULL) const = 0; + + // Get a string value without copying, if possible. + // + // GetString() necessarily returns a copy of the string. This can be + // inefficient when the string is already stored in a string object in the + // underlying message. GetStringReference() will return a reference to the + // underlying string in this case. Otherwise, it will copy the string into + // *scratch and return that. + // + // Note: It is perfectly reasonable and useful to write code like: + // str = reflection->GetStringReference(field, &str); + // This line would ensure that only one copy of the string is made + // regardless of the field's underlying representation. When initializing + // a newly-constructed string, though, it's just as fast and more readable + // to use code like: + // string str = reflection->GetString(field); + virtual const string& GetStringReference(const Message& message, + const FieldDescriptor* field, + string* scratch) const = 0; + + + // Singular field mutators ----------------------------------------- + // These mutate the value of a non-repeated field. + + virtual void SetInt32 (Message* message, + const FieldDescriptor* field, int32 value) const = 0; + virtual void SetInt64 (Message* message, + const FieldDescriptor* field, int64 value) const = 0; + virtual void SetUInt32(Message* message, + const FieldDescriptor* field, uint32 value) const = 0; + virtual void SetUInt64(Message* message, + const FieldDescriptor* field, uint64 value) const = 0; + virtual void SetFloat (Message* message, + const FieldDescriptor* field, float value) const = 0; + virtual void SetDouble(Message* message, + const FieldDescriptor* field, double value) const = 0; + virtual void SetBool (Message* message, + const FieldDescriptor* field, bool value) const = 0; + virtual void SetString(Message* message, + const FieldDescriptor* field, + const string& value) const = 0; + virtual void SetEnum (Message* message, + const FieldDescriptor* field, + const EnumValueDescriptor* value) const = 0; + // Get a mutable pointer to a field with a message type. If a MessageFactory + // is provided, it will be used to construct instances of the sub-message; + // otherwise, the default factory is used. If the field is an extension that + // does not live in the same pool as the containing message's descriptor (e.g. + // it lives in an overlay pool), then a MessageFactory must be provided. + // If you have no idea what that meant, then you probably don't need to worry + // about it (don't provide a MessageFactory). WARNING: If the + // FieldDescriptor is for a compiled-in extension, then + // factory->GetPrototype(field->message_type() MUST return an instance of the + // compiled-in class for this type, NOT DynamicMessage. + virtual Message* MutableMessage(Message* message, + const FieldDescriptor* field, + MessageFactory* factory = NULL) const = 0; + + + // Repeated field getters ------------------------------------------ + // These get the value of one element of a repeated field. + + virtual int32 GetRepeatedInt32 (const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual int64 GetRepeatedInt64 (const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual uint32 GetRepeatedUInt32(const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual uint64 GetRepeatedUInt64(const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual float GetRepeatedFloat (const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual double GetRepeatedDouble(const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual bool GetRepeatedBool (const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual string GetRepeatedString(const Message& message, + const FieldDescriptor* field, + int index) const = 0; + virtual const EnumValueDescriptor* GetRepeatedEnum( + const Message& message, + const FieldDescriptor* field, int index) const = 0; + virtual const Message& GetRepeatedMessage( + const Message& message, + const FieldDescriptor* field, int index) const = 0; + + // See GetStringReference(), above. + virtual const string& GetRepeatedStringReference( + const Message& message, const FieldDescriptor* field, + int index, string* scratch) const = 0; + + + // Repeated field mutators ----------------------------------------- + // These mutate the value of one element of a repeated field. + + virtual void SetRepeatedInt32 (Message* message, + const FieldDescriptor* field, + int index, int32 value) const = 0; + virtual void SetRepeatedInt64 (Message* message, + const FieldDescriptor* field, + int index, int64 value) const = 0; + virtual void SetRepeatedUInt32(Message* message, + const FieldDescriptor* field, + int index, uint32 value) const = 0; + virtual void SetRepeatedUInt64(Message* message, + const FieldDescriptor* field, + int index, uint64 value) const = 0; + virtual void SetRepeatedFloat (Message* message, + const FieldDescriptor* field, + int index, float value) const = 0; + virtual void SetRepeatedDouble(Message* message, + const FieldDescriptor* field, + int index, double value) const = 0; + virtual void SetRepeatedBool (Message* message, + const FieldDescriptor* field, + int index, bool value) const = 0; + virtual void SetRepeatedString(Message* message, + const FieldDescriptor* field, + int index, const string& value) const = 0; + virtual void SetRepeatedEnum(Message* message, + const FieldDescriptor* field, int index, + const EnumValueDescriptor* value) const = 0; + // Get a mutable pointer to an element of a repeated field with a message + // type. + virtual Message* MutableRepeatedMessage( + Message* message, const FieldDescriptor* field, int index) const = 0; + + + // Repeated field adders ------------------------------------------- + // These add an element to a repeated field. + + virtual void AddInt32 (Message* message, + const FieldDescriptor* field, int32 value) const = 0; + virtual void AddInt64 (Message* message, + const FieldDescriptor* field, int64 value) const = 0; + virtual void AddUInt32(Message* message, + const FieldDescriptor* field, uint32 value) const = 0; + virtual void AddUInt64(Message* message, + const FieldDescriptor* field, uint64 value) const = 0; + virtual void AddFloat (Message* message, + const FieldDescriptor* field, float value) const = 0; + virtual void AddDouble(Message* message, + const FieldDescriptor* field, double value) const = 0; + virtual void AddBool (Message* message, + const FieldDescriptor* field, bool value) const = 0; + virtual void AddString(Message* message, + const FieldDescriptor* field, + const string& value) const = 0; + virtual void AddEnum (Message* message, + const FieldDescriptor* field, + const EnumValueDescriptor* value) const = 0; + // See MutableMessage() for comments on the "factory" parameter. + virtual Message* AddMessage(Message* message, + const FieldDescriptor* field, + MessageFactory* factory = NULL) const = 0; + + + // Extensions ------------------------------------------------------ + + // Try to find an extension of this message type by fully-qualified field + // name. Returns NULL if no extension is known for this name or number. + virtual const FieldDescriptor* FindKnownExtensionByName( + const string& name) const = 0; + + // Try to find an extension of this message type by field number. + // Returns NULL if no extension is known for this name or number. + virtual const FieldDescriptor* FindKnownExtensionByNumber( + int number) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reflection); +}; + +// Abstract interface for a factory for message objects. +class LIBPROTOBUF_EXPORT MessageFactory { + public: + inline MessageFactory() {} + virtual ~MessageFactory(); + + // Given a Descriptor, gets or constructs the default (prototype) Message + // of that type. You can then call that message's New() method to construct + // a mutable message of that type. + // + // Calling this method twice with the same Descriptor returns the same + // object. The returned object remains property of the factory. Also, any + // objects created by calling the prototype's New() method share some data + // with the prototype, so these must be destoyed before the MessageFactory + // is destroyed. + // + // The given descriptor must outlive the returned message, and hence must + // outlive the MessageFactory. + // + // Some implementations do not support all types. GetPrototype() will + // return NULL if the descriptor passed in is not supported. + // + // This method may or may not be thread-safe depending on the implementation. + // Each implementation should document its own degree thread-safety. + virtual const Message* GetPrototype(const Descriptor* type) = 0; + + // Gets a MessageFactory which supports all generated, compiled-in messages. + // In other words, for any compiled-in type FooMessage, the following is true: + // MessageFactory::generated_factory()->GetPrototype( + // FooMessage::descriptor()) == FooMessage::default_instance() + // This factory supports all types which are found in + // DescriptorPool::generated_pool(). If given a descriptor from any other + // pool, GetPrototype() will return NULL. (You can also check if a + // descriptor is for a generated message by checking if + // descriptor->file()->pool() == DescriptorPool::generated_pool().) + // + // This factory is 100% thread-safe; calling GetPrototype() does not modify + // any shared data. + // + // This factory is a singleton. The caller must not delete the object. + static MessageFactory* generated_factory(); + + // For internal use only: Registers a .proto file at static initialization + // time, to be placed in generated_factory. The first time GetPrototype() + // is called with a descriptor from this file, |register_messages| will be + // called, with the file name as the parameter. It must call + // InternalRegisterGeneratedMessage() (below) to register each message type + // in the file. This strange mechanism is necessary because descriptors are + // built lazily, so we can't register types by their descriptor until we + // know that the descriptor exists. |filename| must be a permanent string. + static void InternalRegisterGeneratedFile( + const char* filename, void (*register_messages)(const string&)); + + // For internal use only: Registers a message type. Called only by the + // functions which are registered with InternalRegisterGeneratedFile(), + // above. + static void InternalRegisterGeneratedMessage(const Descriptor* descriptor, + const Message* prototype); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFactory); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h new file mode 100644 index 00000000..ebf4ba3c --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h @@ -0,0 +1,239 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Authors: wink@google.com (Wink Saville), +// kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Defines MessageLite, the abstract interface implemented by all (lite +// and non-lite) protocol message objects. + +#ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ +#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ + +#include +#include + +namespace google { +namespace protobuf { + +// Interface to light weight protocol messages. +// +// This interface is implemented by all protocol message objects. Non-lite +// messages additionally implement the Message interface, which is a +// subclass of MessageLite. Use MessageLite instead when you only need +// the subset of features which it supports -- namely, nothing that uses +// descriptors or reflection. You can instruct the protocol compiler +// to generate classes which implement only MessageLite, not the full +// Message interface, by adding the following line to the .proto file: +// +// option optimize_for = LITE_RUNTIME; +// +// This is particularly useful on resource-constrained systems where +// the full protocol buffers runtime library is too big. +// +// Note that on non-constrained systems (e.g. servers) when you need +// to link in lots of protocol definitions, a better way to reduce +// total code footprint is to use optimize_for = CODE_SIZE. This +// will make the generated code smaller while still supporting all the +// same features (at the expense of speed). optimize_for = LITE_RUNTIME +// is best when you only have a small number of message types linked +// into your binary, in which case the size of the protocol buffers +// runtime itself is the biggest problem. +class LIBPROTOBUF_EXPORT MessageLite { + public: + inline MessageLite() {} + virtual ~MessageLite(); + + // Basic Operations ------------------------------------------------ + + // Get the name of this message type, e.g. "foo.bar.BazProto". + virtual string GetTypeName() const = 0; + + // Construct a new instance of the same type. Ownership is passed to the + // caller. + virtual MessageLite* New() const = 0; + + // Clear all fields of the message and set them to their default values. + // Clear() avoids freeing memory, assuming that any memory allocated + // to hold parts of the message will be needed again to hold the next + // message. If you actually want to free the memory used by a Message, + // you must delete it. + virtual void Clear() = 0; + + // Quickly check if all required fields have values set. + virtual bool IsInitialized() const = 0; + + // This is not implemented for Lite messages -- it just returns "(cannot + // determine missing fields for lite message)". However, it is implemented + // for full messages. See message.h. + virtual string InitializationErrorString() const; + + // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, + // results are undefined (probably crash). + virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; + + // Parsing --------------------------------------------------------- + // Methods for parsing in protocol buffer format. Most of these are + // just simple wrappers around MergeFromCodedStream(). + + // Fill the message with a protocol buffer parsed from the given input + // stream. Returns false on a read error or if the input is in the + // wrong format. + bool ParseFromCodedStream(io::CodedInputStream* input); + // Like ParseFromCodedStream(), but accepts messages that are missing + // required fields. + bool ParsePartialFromCodedStream(io::CodedInputStream* input); + // Read a protocol buffer from the given zero-copy input stream. If + // successful, the entire input will be consumed. + bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); + // Like ParseFromZeroCopyStream(), but accepts messages that are missing + // required fields. + bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input); + // Read a protocol buffer from the given zero-copy input stream, expecting + // the message to be exactly "size" bytes long. If successful, exactly + // this many bytes will have been consumed from the input. + bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size); + // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are + // missing required fields. + bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, + int size); + // Parse a protocol buffer contained in a string. + bool ParseFromString(const string& data); + // Like ParseFromString(), but accepts messages that are missing + // required fields. + bool ParsePartialFromString(const string& data); + // Parse a protocol buffer contained in an array of bytes. + bool ParseFromArray(const void* data, int size); + // Like ParseFromArray(), but accepts messages that are missing + // required fields. + bool ParsePartialFromArray(const void* data, int size); + + + // Reads a protocol buffer from the stream and merges it into this + // Message. Singular fields read from the input overwrite what is + // already in the Message and repeated fields are appended to those + // already present. + // + // It is the responsibility of the caller to call input->LastTagWas() + // (for groups) or input->ConsumedEntireMessage() (for non-groups) after + // this returns to verify that the message's end was delimited correctly. + // + // ParsefromCodedStream() is implemented as Clear() followed by + // MergeFromCodedStream(). + bool MergeFromCodedStream(io::CodedInputStream* input); + + // Like MergeFromCodedStream(), but succeeds even if required fields are + // missing in the input. + // + // MergeFromCodedStream() is just implemented as MergePartialFromCodedStream() + // followed by IsInitialized(). + virtual bool MergePartialFromCodedStream(io::CodedInputStream* input) = 0; + + // Serialization --------------------------------------------------- + // Methods for serializing in protocol buffer format. Most of these + // are just simple wrappers around ByteSize() and SerializeWithCachedSizes(). + + // Write a protocol buffer of this message to the given output. Returns + // false on a write error. If the message is missing required fields, + // this may GOOGLE_CHECK-fail. + bool SerializeToCodedStream(io::CodedOutputStream* output) const; + // Like SerializeToCodedStream(), but allows missing required fields. + bool SerializePartialToCodedStream(io::CodedOutputStream* output) const; + // Write the message to the given zero-copy output stream. All required + // fields must be set. + bool SerializeToZeroCopyStream(io::ZeroCopyOutputStream* output) const; + // Like SerializeToZeroCopyStream(), but allows missing required fields. + bool SerializePartialToZeroCopyStream(io::ZeroCopyOutputStream* output) const; + // Serialize the message and store it in the given string. All required + // fields must be set. + bool SerializeToString(string* output) const; + // Like SerializeToString(), but allows missing required fields. + bool SerializePartialToString(string* output) const; + // Serialize the message and store it in the given byte array. All required + // fields must be set. + bool SerializeToArray(void* data, int size) const; + // Like SerializeToArray(), but allows missing required fields. + bool SerializePartialToArray(void* data, int size) const; + + // Make a string encoding the message. Is equivalent to calling + // SerializeToString() on a string and using that. Returns the empty + // string if SerializeToString() would have returned an error. + // Note: If you intend to generate many such strings, you may + // reduce heap fragmentation by instead re-using the same string + // object with calls to SerializeToString(). + string SerializeAsString() const; + // Like SerializeAsString(), but allows missing required fields. + string SerializePartialAsString() const; + + // Like SerializeToString(), but appends to the data to the string's existing + // contents. All required fields must be set. + bool AppendToString(string* output) const; + // Like AppendToString(), but allows missing required fields. + bool AppendPartialToString(string* output) const; + + // Computes the serialized size of the message. This recursively calls + // ByteSize() on all embedded messages. If a subclass does not override + // this, it MUST override SetCachedSize(). + virtual int ByteSize() const = 0; + + // Serializes the message without recomputing the size. The message must + // not have changed since the last call to ByteSize(); if it has, the results + // are undefined. + virtual void SerializeWithCachedSizes( + io::CodedOutputStream* output) const = 0; + + // Like SerializeWithCachedSizes, but writes directly to *target, returning + // a pointer to the byte immediately after the last byte written. "target" + // must point at a byte array of at least ByteSize() bytes. + virtual uint8* SerializeWithCachedSizesToArray(uint8* target) const; + + // Returns the result of the last call to ByteSize(). An embedded message's + // size is needed both to serialize it (because embedded messages are + // length-delimited) and to compute the outer message's size. Caching + // the size avoids computing it multiple times. + // + // ByteSize() does not automatically use the cached size when available + // because this would require invalidating it every time the message was + // modified, which would be too hard and expensive. (E.g. if a deeply-nested + // sub-message is changed, all of its parents' cached sizes would need to be + // invalidated, which is too much work for an otherwise inlined setter + // method.) + virtual int GetCachedSize() const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/package_info.h b/ext/protobuf-2.4.1/src/google/protobuf/package_info.h new file mode 100644 index 00000000..60cd3994 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/package_info.h @@ -0,0 +1,64 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This file exists solely to document the google::protobuf namespace. +// It is not compiled into anything, but it may be read by an automated +// documentation generator. + +namespace google { + +// Core components of the Protocol Buffers runtime library. +// +// The files in this package represent the core of the Protocol Buffer +// system. All of them are part of the libprotobuf library. +// +// A note on thread-safety: +// +// Thread-safety in the Protocol Buffer library follows a simple rule: +// unless explicitly noted otherwise, it is always safe to use an object +// from multiple threads simultaneously as long as the object is declared +// const in all threads (or, it is only used in ways that would be allowed +// if it were declared const). However, if an object is accessed in one +// thread in a way that would not be allowed if it were const, then it is +// not safe to access that object in any other thread simultaneously. +// +// Put simply, read-only access to an object can happen in multiple threads +// simultaneously, but write access can only happen in a single thread at +// a time. +// +// The implementation does contain some "const" methods which actually modify +// the object behind the scenes -- e.g., to cache results -- but in these cases +// mutex locking is used to make the access thread-safe. +namespace protobuf {} +} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h b/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h new file mode 100644 index 00000000..355a0a5d --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h @@ -0,0 +1,80 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This header is logically internal, but is made public because it is used +// from protocol-compiler-generated code, which may reside in other components. + +#ifndef GOOGLE_PROTOBUF_REFLECTION_OPS_H__ +#define GOOGLE_PROTOBUF_REFLECTION_OPS_H__ + +#include + +namespace google { +namespace protobuf { +namespace internal { + +// Basic operations that can be performed using reflection. +// These can be used as a cheap way to implement the corresponding +// methods of the Message interface, though they are likely to be +// slower than implementations tailored for the specific message type. +// +// This class should stay limited to operations needed to implement +// the Message interface. +// +// This class is really a namespace that contains only static methods. +class LIBPROTOBUF_EXPORT ReflectionOps { + public: + static void Copy(const Message& from, Message* to); + static void Merge(const Message& from, Message* to); + static void Clear(Message* message); + static bool IsInitialized(const Message& message); + static void DiscardUnknownFields(Message* message); + + // Finds all unset required fields in the message and adds their full + // paths (e.g. "foo.bar[5].baz") to *names. "prefix" will be attached to + // the front of each name. + static void FindInitializationErrors(const Message& message, + const string& prefix, + vector* errors); + + private: + // All methods are static. No need to construct. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionOps); +}; + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_REFLECTION_OPS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h b/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h new file mode 100644 index 00000000..6080ddcc --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h @@ -0,0 +1,1295 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// RepeatedField and RepeatedPtrField are used by generated protocol message +// classes to manipulate repeated fields. These classes are very similar to +// STL's vector, but include a number of optimizations found to be useful +// specifically in the case of Protocol Buffers. RepeatedPtrField is +// particularly different from STL vector as it manages ownership of the +// pointers that it contains. +// +// Typically, clients should not need to access RepeatedField objects directly, +// but should instead use the accessor functions generated automatically by the +// protocol compiler. + +#ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_H__ +#define GOOGLE_PROTOBUF_REPEATED_FIELD_H__ + +#include +#include +#include +#include + +namespace google { + +namespace protobuf { + +class Message; + +namespace internal { + +// We need this (from generated_message_reflection.cc). +LIBPROTOBUF_EXPORT int StringSpaceUsedExcludingSelf(const string& str); + +} // namespace internal + +// RepeatedField is used to represent repeated fields of a primitive type (in +// other words, everything except strings and nested Messages). Most users will +// not ever use a RepeatedField directly; they will use the get-by-index, +// set-by-index, and add accessors that are generated for all repeated fields. +template +class RepeatedField { + public: + RepeatedField(); + RepeatedField(const RepeatedField& other); + ~RepeatedField(); + + RepeatedField& operator=(const RepeatedField& other); + + int size() const; + + const Element& Get(int index) const; + Element* Mutable(int index); + void Set(int index, const Element& value); + void Add(const Element& value); + Element* Add(); + // Remove the last element in the array. + // We don't provide a way to remove any element other than the last + // because it invites inefficient use, such as O(n^2) filtering loops + // that should have been O(n). If you want to remove an element other + // than the last, the best way to do it is to re-arrange the elements + // so that the one you want removed is at the end, then call RemoveLast(). + void RemoveLast(); + void Clear(); + void MergeFrom(const RepeatedField& other); + void CopyFrom(const RepeatedField& other); + + // Reserve space to expand the field to at least the given size. If the + // array is grown, it will always be at least doubled in size. + void Reserve(int new_size); + + // Resize the RepeatedField to a new, smaller size. This is O(1). + void Truncate(int new_size); + + void AddAlreadyReserved(const Element& value); + Element* AddAlreadyReserved(); + int Capacity() const; + + // Gets the underlying array. This pointer is possibly invalidated by + // any add or remove operation. + Element* mutable_data(); + const Element* data() const; + + // Swap entire contents with "other". + void Swap(RepeatedField* other); + + // Swap two elements. + void SwapElements(int index1, int index2); + + // STL-like iterator support + typedef Element* iterator; + typedef const Element* const_iterator; + typedef Element value_type; + + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + + // Returns the number of bytes used by the repeated field, excluding + // sizeof(*this) + int SpaceUsedExcludingSelf() const; + + private: + static const int kInitialSize = 4; + + Element* elements_; + int current_size_; + int total_size_; + + Element initial_space_[kInitialSize]; + + // Move the contents of |from| into |to|, possibly clobbering |from| in the + // process. For primitive types this is just a memcpy(), but it could be + // specialized for non-primitive types to, say, swap each element instead. + void MoveArray(Element to[], Element from[], int size); + + // Copy the elements of |from| into |to|. + void CopyArray(Element to[], const Element from[], int size); +}; + +namespace internal { +template class RepeatedPtrIterator; +template class RepeatedPtrOverPtrsIterator; +} // namespace internal + +namespace internal { + +// This is the common base class for RepeatedPtrFields. It deals only in void* +// pointers. Users should not use this interface directly. +// +// The methods of this interface correspond to the methods of RepeatedPtrField, +// but may have a template argument called TypeHandler. Its signature is: +// class TypeHandler { +// public: +// typedef MyType Type; +// static Type* New(); +// static void Delete(Type*); +// static void Clear(Type*); +// static void Merge(const Type& from, Type* to); +// +// // Only needs to be implemented if SpaceUsedExcludingSelf() is called. +// static int SpaceUsed(const Type&); +// }; +class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { + protected: + // The reflection implementation needs to call protected methods directly, + // reinterpreting pointers as being to Message instead of a specific Message + // subclass. + friend class GeneratedMessageReflection; + + // ExtensionSet stores repeated message extensions as + // RepeatedPtrField, but non-lite ExtensionSets need to + // implement SpaceUsed(), and thus need to call SpaceUsedExcludingSelf() + // reinterpreting MessageLite as Message. ExtensionSet also needs to make + // use of AddFromCleared(), which is not part of the public interface. + friend class ExtensionSet; + + RepeatedPtrFieldBase(); + + // Must be called from destructor. + template + void Destroy(); + + int size() const; + + template + const typename TypeHandler::Type& Get(int index) const; + template + typename TypeHandler::Type* Mutable(int index); + template + typename TypeHandler::Type* Add(); + template + void RemoveLast(); + template + void Clear(); + template + void MergeFrom(const RepeatedPtrFieldBase& other); + template + void CopyFrom(const RepeatedPtrFieldBase& other); + + void Reserve(int new_size); + + int Capacity() const; + + // Used for constructing iterators. + void* const* raw_data() const; + void** raw_mutable_data() const; + + template + typename TypeHandler::Type** mutable_data(); + template + const typename TypeHandler::Type* const* data() const; + + void Swap(RepeatedPtrFieldBase* other); + + void SwapElements(int index1, int index2); + + template + int SpaceUsedExcludingSelf() const; + + + // Advanced memory management -------------------------------------- + + // Like Add(), but if there are no cleared objects to use, returns NULL. + template + typename TypeHandler::Type* AddFromCleared(); + + template + void AddAllocated(typename TypeHandler::Type* value); + template + typename TypeHandler::Type* ReleaseLast(); + + int ClearedCount() const; + template + void AddCleared(typename TypeHandler::Type* value); + template + typename TypeHandler::Type* ReleaseCleared(); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPtrFieldBase); + + static const int kInitialSize = 4; + + void** elements_; + int current_size_; + int allocated_size_; + int total_size_; + + void* initial_space_[kInitialSize]; + + template + static inline typename TypeHandler::Type* cast(void* element) { + return reinterpret_cast(element); + } + template + static inline const typename TypeHandler::Type* cast(const void* element) { + return reinterpret_cast(element); + } +}; + +template +class GenericTypeHandler { + public: + typedef GenericType Type; + static GenericType* New() { return new GenericType; } + static void Delete(GenericType* value) { delete value; } + static void Clear(GenericType* value) { value->Clear(); } + static void Merge(const GenericType& from, GenericType* to) { + to->MergeFrom(from); + } + static int SpaceUsed(const GenericType& value) { return value.SpaceUsed(); } +}; + +template <> +inline void GenericTypeHandler::Merge( + const MessageLite& from, MessageLite* to) { + to->CheckTypeAndMergeFrom(from); +} + +// HACK: If a class is declared as DLL-exported in MSVC, it insists on +// generating copies of all its methods -- even inline ones -- to include +// in the DLL. But SpaceUsed() calls StringSpaceUsedExcludingSelf() which +// isn't in the lite library, therefore the lite library cannot link if +// StringTypeHandler is exported. So, we factor out StringTypeHandlerBase, +// export that, then make StringTypeHandler be a subclass which is NOT +// exported. +// TODO(kenton): There has to be a better way. +class LIBPROTOBUF_EXPORT StringTypeHandlerBase { + public: + typedef string Type; + static string* New(); + static void Delete(string* value); + static void Clear(string* value) { value->clear(); } + static void Merge(const string& from, string* to) { *to = from; } +}; + +class LIBPROTOBUF_EXPORT StringTypeHandler : public StringTypeHandlerBase { + public: + static int SpaceUsed(const string& value) { + return sizeof(value) + StringSpaceUsedExcludingSelf(value); + } +}; + + +} // namespace internal + +// RepeatedPtrField is like RepeatedField, but used for repeated strings or +// Messages. +template +class RepeatedPtrField : public internal::RepeatedPtrFieldBase { + public: + RepeatedPtrField(); + RepeatedPtrField(const RepeatedPtrField& other); + ~RepeatedPtrField(); + + RepeatedPtrField& operator=(const RepeatedPtrField& other); + + int size() const; + + const Element& Get(int index) const; + Element* Mutable(int index); + Element* Add(); + void RemoveLast(); // Remove the last element in the array. + void Clear(); + void MergeFrom(const RepeatedPtrField& other); + void CopyFrom(const RepeatedPtrField& other); + + // Reserve space to expand the field to at least the given size. This only + // resizes the pointer array; it doesn't allocate any objects. If the + // array is grown, it will always be at least doubled in size. + void Reserve(int new_size); + + int Capacity() const; + + // Gets the underlying array. This pointer is possibly invalidated by + // any add or remove operation. + Element** mutable_data(); + const Element* const* data() const; + + // Swap entire contents with "other". + void Swap(RepeatedPtrField* other); + + // Swap two elements. + void SwapElements(int index1, int index2); + + // STL-like iterator support + typedef internal::RepeatedPtrIterator iterator; + typedef internal::RepeatedPtrIterator const_iterator; + typedef Element value_type; + + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + + // Custom STL-like iterator that iterates over and returns the underlying + // pointers to Element rather than Element itself. + typedef internal::RepeatedPtrOverPtrsIterator pointer_iterator; + pointer_iterator pointer_begin(); + pointer_iterator pointer_end(); + + // Returns (an estimate of) the number of bytes used by the repeated field, + // excluding sizeof(*this). + int SpaceUsedExcludingSelf() const; + + // Advanced memory management -------------------------------------- + // When hardcore memory management becomes necessary -- as it often + // does here at Google -- the following methods may be useful. + + // Add an already-allocated object, passing ownership to the + // RepeatedPtrField. + void AddAllocated(Element* value); + // Remove the last element and return it, passing ownership to the + // caller. + // Requires: size() > 0 + Element* ReleaseLast(); + + // When elements are removed by calls to RemoveLast() or Clear(), they + // are not actually freed. Instead, they are cleared and kept so that + // they can be reused later. This can save lots of CPU time when + // repeatedly reusing a protocol message for similar purposes. + // + // Really, extremely hardcore programs may actually want to manipulate + // these objects to better-optimize memory management. These methods + // allow that. + + // Get the number of cleared objects that are currently being kept + // around for reuse. + int ClearedCount() const; + // Add an element to the pool of cleared objects, passing ownership to + // the RepeatedPtrField. The element must be cleared prior to calling + // this method. + void AddCleared(Element* value); + // Remove a single element from the cleared pool and return it, passing + // ownership to the caller. The element is guaranteed to be cleared. + // Requires: ClearedCount() > 0 + Element* ReleaseCleared(); + + protected: + // Note: RepeatedPtrField SHOULD NOT be subclassed by users. We only + // subclass it in one place as a hack for compatibility with proto1. The + // subclass needs to know about TypeHandler in order to call protected + // methods on RepeatedPtrFieldBase. + class TypeHandler; + +}; + +// implementation ==================================================== + +template +inline RepeatedField::RepeatedField() + : elements_(initial_space_), + current_size_(0), + total_size_(kInitialSize) { +} + +template +inline RepeatedField::RepeatedField(const RepeatedField& other) + : elements_(initial_space_), + current_size_(0), + total_size_(kInitialSize) { + CopyFrom(other); +} + +template +RepeatedField::~RepeatedField() { + if (elements_ != initial_space_) { + delete [] elements_; + } +} + +template +inline RepeatedField& +RepeatedField::operator=(const RepeatedField& other) { + CopyFrom(other); + return *this; +} + +template +inline int RepeatedField::size() const { + return current_size_; +} + +template +inline int RepeatedField::Capacity() const { + return total_size_; +} + +template +inline void RepeatedField::AddAlreadyReserved(const Element& value) { + GOOGLE_DCHECK_LT(size(), Capacity()); + elements_[current_size_++] = value; +} + +template +inline Element* RepeatedField::AddAlreadyReserved() { + GOOGLE_DCHECK_LT(size(), Capacity()); + return &elements_[current_size_++]; +} + +template +inline const Element& RepeatedField::Get(int index) const { + GOOGLE_DCHECK_LT(index, size()); + return elements_[index]; +} + +template +inline Element* RepeatedField::Mutable(int index) { + GOOGLE_DCHECK_LT(index, size()); + return elements_ + index; +} + +template +inline void RepeatedField::Set(int index, const Element& value) { + GOOGLE_DCHECK_LT(index, size()); + elements_[index] = value; +} + +template +inline void RepeatedField::Add(const Element& value) { + if (current_size_ == total_size_) Reserve(total_size_ + 1); + elements_[current_size_++] = value; +} + +template +inline Element* RepeatedField::Add() { + if (current_size_ == total_size_) Reserve(total_size_ + 1); + return &elements_[current_size_++]; +} + +template +inline void RepeatedField::RemoveLast() { + GOOGLE_DCHECK_GT(current_size_, 0); + --current_size_; +} + +template +inline void RepeatedField::Clear() { + current_size_ = 0; +} + +template +inline void RepeatedField::MergeFrom(const RepeatedField& other) { + Reserve(current_size_ + other.current_size_); + CopyArray(elements_ + current_size_, other.elements_, other.current_size_); + current_size_ += other.current_size_; +} + +template +inline void RepeatedField::CopyFrom(const RepeatedField& other) { + Clear(); + MergeFrom(other); +} + +template +inline Element* RepeatedField::mutable_data() { + return elements_; +} + +template +inline const Element* RepeatedField::data() const { + return elements_; +} + + +template +void RepeatedField::Swap(RepeatedField* other) { + Element* swap_elements = elements_; + int swap_current_size = current_size_; + int swap_total_size = total_size_; + // We may not be using initial_space_ but it's not worth checking. Just + // copy it anyway. + Element swap_initial_space[kInitialSize]; + MoveArray(swap_initial_space, initial_space_, kInitialSize); + + elements_ = other->elements_; + current_size_ = other->current_size_; + total_size_ = other->total_size_; + MoveArray(initial_space_, other->initial_space_, kInitialSize); + + other->elements_ = swap_elements; + other->current_size_ = swap_current_size; + other->total_size_ = swap_total_size; + MoveArray(other->initial_space_, swap_initial_space, kInitialSize); + + if (elements_ == other->initial_space_) { + elements_ = initial_space_; + } + if (other->elements_ == initial_space_) { + other->elements_ = other->initial_space_; + } +} + +template +void RepeatedField::SwapElements(int index1, int index2) { + std::swap(elements_[index1], elements_[index2]); +} + +template +inline typename RepeatedField::iterator +RepeatedField::begin() { + return elements_; +} +template +inline typename RepeatedField::const_iterator +RepeatedField::begin() const { + return elements_; +} +template +inline typename RepeatedField::iterator +RepeatedField::end() { + return elements_ + current_size_; +} +template +inline typename RepeatedField::const_iterator +RepeatedField::end() const { + return elements_ + current_size_; +} + +template +inline int RepeatedField::SpaceUsedExcludingSelf() const { + return (elements_ != initial_space_) ? total_size_ * sizeof(elements_[0]) : 0; +} + +// Avoid inlining of Reserve(): new, memcpy, and delete[] lead to a significant +// amount of code bloat. +template +void RepeatedField::Reserve(int new_size) { + if (total_size_ >= new_size) return; + + Element* old_elements = elements_; + total_size_ = max(total_size_ * 2, new_size); + elements_ = new Element[total_size_]; + MoveArray(elements_, old_elements, current_size_); + if (old_elements != initial_space_) { + delete [] old_elements; + } +} + +template +inline void RepeatedField::Truncate(int new_size) { + GOOGLE_DCHECK_LE(new_size, current_size_); + current_size_ = new_size; +} + +template +inline void RepeatedField::MoveArray( + Element to[], Element from[], int array_size) { + memcpy(to, from, array_size * sizeof(Element)); +} + +template +inline void RepeatedField::CopyArray( + Element to[], const Element from[], int array_size) { + memcpy(to, from, array_size * sizeof(Element)); +} + + +// ------------------------------------------------------------------- + +namespace internal { + +inline RepeatedPtrFieldBase::RepeatedPtrFieldBase() + : elements_(initial_space_), + current_size_(0), + allocated_size_(0), + total_size_(kInitialSize) { +} + +template +void RepeatedPtrFieldBase::Destroy() { + for (int i = 0; i < allocated_size_; i++) { + TypeHandler::Delete(cast(elements_[i])); + } + if (elements_ != initial_space_) { + delete [] elements_; + } +} + +inline int RepeatedPtrFieldBase::size() const { + return current_size_; +} + + +template +inline const typename TypeHandler::Type& +RepeatedPtrFieldBase::Get(int index) const { + GOOGLE_DCHECK_LT(index, size()); + return *cast(elements_[index]); +} + +template +inline typename TypeHandler::Type* +RepeatedPtrFieldBase::Mutable(int index) { + GOOGLE_DCHECK_LT(index, size()); + return cast(elements_[index]); +} + +template +inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add() { + if (current_size_ < allocated_size_) { + return cast(elements_[current_size_++]); + } + if (allocated_size_ == total_size_) Reserve(total_size_ + 1); + ++allocated_size_; + typename TypeHandler::Type* result = TypeHandler::New(); + elements_[current_size_++] = result; + return result; +} + +template +inline void RepeatedPtrFieldBase::RemoveLast() { + GOOGLE_DCHECK_GT(current_size_, 0); + TypeHandler::Clear(cast(elements_[--current_size_])); +} + +template +void RepeatedPtrFieldBase::Clear() { + for (int i = 0; i < current_size_; i++) { + TypeHandler::Clear(cast(elements_[i])); + } + current_size_ = 0; +} + +template +inline void RepeatedPtrFieldBase::MergeFrom(const RepeatedPtrFieldBase& other) { + Reserve(current_size_ + other.current_size_); + for (int i = 0; i < other.current_size_; i++) { + TypeHandler::Merge(other.template Get(i), Add()); + } +} + +template +inline void RepeatedPtrFieldBase::CopyFrom(const RepeatedPtrFieldBase& other) { + RepeatedPtrFieldBase::Clear(); + RepeatedPtrFieldBase::MergeFrom(other); +} + +inline int RepeatedPtrFieldBase::Capacity() const { + return total_size_; +} + +inline void* const* RepeatedPtrFieldBase::raw_data() const { + return elements_; +} + +inline void** RepeatedPtrFieldBase::raw_mutable_data() const { + return elements_; +} + +template +inline typename TypeHandler::Type** RepeatedPtrFieldBase::mutable_data() { + // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this + // method entirely. + return reinterpret_cast(elements_); +} + +template +inline const typename TypeHandler::Type* const* +RepeatedPtrFieldBase::data() const { + // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this + // method entirely. + return reinterpret_cast(elements_); +} + +inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) { + std::swap(elements_[index1], elements_[index2]); +} + +template +inline int RepeatedPtrFieldBase::SpaceUsedExcludingSelf() const { + int allocated_bytes = + (elements_ != initial_space_) ? total_size_ * sizeof(elements_[0]) : 0; + for (int i = 0; i < allocated_size_; ++i) { + allocated_bytes += TypeHandler::SpaceUsed(*cast(elements_[i])); + } + return allocated_bytes; +} + +template +inline typename TypeHandler::Type* RepeatedPtrFieldBase::AddFromCleared() { + if (current_size_ < allocated_size_) { + return cast(elements_[current_size_++]); + } else { + return NULL; + } +} + +template +void RepeatedPtrFieldBase::AddAllocated( + typename TypeHandler::Type* value) { + // Make room for the new pointer. + if (current_size_ == total_size_) { + // The array is completely full with no cleared objects, so grow it. + Reserve(total_size_ + 1); + ++allocated_size_; + } else if (allocated_size_ == total_size_) { + // There is no more space in the pointer array because it contains some + // cleared objects awaiting reuse. We don't want to grow the array in this + // case because otherwise a loop calling AddAllocated() followed by Clear() + // would leak memory. + TypeHandler::Delete(cast(elements_[current_size_])); + } else if (current_size_ < allocated_size_) { + // We have some cleared objects. We don't care about their order, so we + // can just move the first one to the end to make space. + elements_[allocated_size_] = elements_[current_size_]; + ++allocated_size_; + } else { + // There are no cleared objects. + ++allocated_size_; + } + + elements_[current_size_++] = value; +} + +template +inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseLast() { + GOOGLE_DCHECK_GT(current_size_, 0); + typename TypeHandler::Type* result = + cast(elements_[--current_size_]); + --allocated_size_; + if (current_size_ < allocated_size_) { + // There are cleared elements on the end; replace the removed element + // with the last allocated element. + elements_[current_size_] = elements_[allocated_size_]; + } + return result; +} + + +inline int RepeatedPtrFieldBase::ClearedCount() const { + return allocated_size_ - current_size_; +} + +template +inline void RepeatedPtrFieldBase::AddCleared( + typename TypeHandler::Type* value) { + if (allocated_size_ == total_size_) Reserve(total_size_ + 1); + elements_[allocated_size_++] = value; +} + +template +inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseCleared() { + GOOGLE_DCHECK_GT(allocated_size_, current_size_); + return cast(elements_[--allocated_size_]); +} + +} // namespace internal + +// ------------------------------------------------------------------- + +template +class RepeatedPtrField::TypeHandler + : public internal::GenericTypeHandler {}; + +template <> +class RepeatedPtrField::TypeHandler + : public internal::StringTypeHandler {}; + + +template +inline RepeatedPtrField::RepeatedPtrField() {} + +template +inline RepeatedPtrField::RepeatedPtrField( + const RepeatedPtrField& other) { + CopyFrom(other); +} + +template +RepeatedPtrField::~RepeatedPtrField() { + Destroy(); +} + +template +inline RepeatedPtrField& RepeatedPtrField::operator=( + const RepeatedPtrField& other) { + CopyFrom(other); + return *this; +} + +template +inline int RepeatedPtrField::size() const { + return RepeatedPtrFieldBase::size(); +} + +template +inline const Element& RepeatedPtrField::Get(int index) const { + return RepeatedPtrFieldBase::Get(index); +} + +template +inline Element* RepeatedPtrField::Mutable(int index) { + return RepeatedPtrFieldBase::Mutable(index); +} + +template +inline Element* RepeatedPtrField::Add() { + return RepeatedPtrFieldBase::Add(); +} + +template +inline void RepeatedPtrField::RemoveLast() { + RepeatedPtrFieldBase::RemoveLast(); +} + +template +inline void RepeatedPtrField::Clear() { + RepeatedPtrFieldBase::Clear(); +} + +template +inline void RepeatedPtrField::MergeFrom( + const RepeatedPtrField& other) { + RepeatedPtrFieldBase::MergeFrom(other); +} + +template +inline void RepeatedPtrField::CopyFrom( + const RepeatedPtrField& other) { + RepeatedPtrFieldBase::CopyFrom(other); +} + +template +inline Element** RepeatedPtrField::mutable_data() { + return RepeatedPtrFieldBase::mutable_data(); +} + +template +inline const Element* const* RepeatedPtrField::data() const { + return RepeatedPtrFieldBase::data(); +} + +template +void RepeatedPtrField::Swap(RepeatedPtrField* other) { + RepeatedPtrFieldBase::Swap(other); +} + +template +void RepeatedPtrField::SwapElements(int index1, int index2) { + RepeatedPtrFieldBase::SwapElements(index1, index2); +} + +template +inline int RepeatedPtrField::SpaceUsedExcludingSelf() const { + return RepeatedPtrFieldBase::SpaceUsedExcludingSelf(); +} + +template +inline void RepeatedPtrField::AddAllocated(Element* value) { + RepeatedPtrFieldBase::AddAllocated(value); +} + +template +inline Element* RepeatedPtrField::ReleaseLast() { + return RepeatedPtrFieldBase::ReleaseLast(); +} + + +template +inline int RepeatedPtrField::ClearedCount() const { + return RepeatedPtrFieldBase::ClearedCount(); +} + +template +inline void RepeatedPtrField::AddCleared(Element* value) { + return RepeatedPtrFieldBase::AddCleared(value); +} + +template +inline Element* RepeatedPtrField::ReleaseCleared() { + return RepeatedPtrFieldBase::ReleaseCleared(); +} + +template +inline void RepeatedPtrField::Reserve(int new_size) { + return RepeatedPtrFieldBase::Reserve(new_size); +} + +template +inline int RepeatedPtrField::Capacity() const { + return RepeatedPtrFieldBase::Capacity(); +} + +// ------------------------------------------------------------------- + +namespace internal { + +// STL-like iterator implementation for RepeatedPtrField. You should not +// refer to this class directly; use RepeatedPtrField::iterator instead. +// +// The iterator for RepeatedPtrField, RepeatedPtrIterator, is +// very similar to iterator_ptr in util/gtl/iterator_adaptors-inl.h, +// but adds random-access operators and is modified to wrap a void** base +// iterator (since RepeatedPtrField stores its array as a void* array and +// casting void** to T** would violate C++ aliasing rules). +// +// This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin +// (jyasskin@google.com). +template +class RepeatedPtrIterator + : public std::iterator< + std::random_access_iterator_tag, Element> { + public: + typedef RepeatedPtrIterator iterator; + typedef std::iterator< + std::random_access_iterator_tag, Element> superclass; + + // Let the compiler know that these are type names, so we don't have to + // write "typename" in front of them everywhere. + typedef typename superclass::reference reference; + typedef typename superclass::pointer pointer; + typedef typename superclass::difference_type difference_type; + + RepeatedPtrIterator() : it_(NULL) {} + explicit RepeatedPtrIterator(void* const* it) : it_(it) {} + + // Allow "upcasting" from RepeatedPtrIterator to + // RepeatedPtrIterator. + template + RepeatedPtrIterator(const RepeatedPtrIterator& other) + : it_(other.it_) { + // Force a compiler error if the other type is not convertible to ours. + if (false) { + implicit_cast(0); + } + } + + // dereferenceable + reference operator*() const { return *reinterpret_cast(*it_); } + pointer operator->() const { return &(operator*()); } + + // {inc,dec}rementable + iterator& operator++() { ++it_; return *this; } + iterator operator++(int) { return iterator(it_++); } + iterator& operator--() { --it_; return *this; } + iterator operator--(int) { return iterator(it_--); } + + // equality_comparable + bool operator==(const iterator& x) const { return it_ == x.it_; } + bool operator!=(const iterator& x) const { return it_ != x.it_; } + + // less_than_comparable + bool operator<(const iterator& x) const { return it_ < x.it_; } + bool operator<=(const iterator& x) const { return it_ <= x.it_; } + bool operator>(const iterator& x) const { return it_ > x.it_; } + bool operator>=(const iterator& x) const { return it_ >= x.it_; } + + // addable, subtractable + iterator& operator+=(difference_type d) { + it_ += d; + return *this; + } + friend iterator operator+(iterator it, difference_type d) { + it += d; + return it; + } + friend iterator operator+(difference_type d, iterator it) { + it += d; + return it; + } + iterator& operator-=(difference_type d) { + it_ -= d; + return *this; + } + friend iterator operator-(iterator it, difference_type d) { + it -= d; + return it; + } + + // indexable + reference operator[](difference_type d) const { return *(*this + d); } + + // random access iterator + difference_type operator-(const iterator& x) const { return it_ - x.it_; } + + private: + template + friend class RepeatedPtrIterator; + + // The internal iterator. + void* const* it_; +}; + +// Provide an iterator that operates on pointers to the underlying objects +// rather than the objects themselves as RepeatedPtrIterator does. +// Consider using this when working with stl algorithms that change +// the array. +template +class RepeatedPtrOverPtrsIterator + : public std::iterator { + public: + typedef RepeatedPtrOverPtrsIterator iterator; + typedef std::iterator< + std::random_access_iterator_tag, Element*> superclass; + + // Let the compiler know that these are type names, so we don't have to + // write "typename" in front of them everywhere. + typedef typename superclass::reference reference; + typedef typename superclass::pointer pointer; + typedef typename superclass::difference_type difference_type; + + RepeatedPtrOverPtrsIterator() : it_(NULL) {} + explicit RepeatedPtrOverPtrsIterator(void** it) : it_(it) {} + + // dereferenceable + reference operator*() const { return *reinterpret_cast(it_); } + pointer operator->() const { return &(operator*()); } + + // {inc,dec}rementable + iterator& operator++() { ++it_; return *this; } + iterator operator++(int) { return iterator(it_++); } + iterator& operator--() { --it_; return *this; } + iterator operator--(int) { return iterator(it_--); } + + // equality_comparable + bool operator==(const iterator& x) const { return it_ == x.it_; } + bool operator!=(const iterator& x) const { return it_ != x.it_; } + + // less_than_comparable + bool operator<(const iterator& x) const { return it_ < x.it_; } + bool operator<=(const iterator& x) const { return it_ <= x.it_; } + bool operator>(const iterator& x) const { return it_ > x.it_; } + bool operator>=(const iterator& x) const { return it_ >= x.it_; } + + // addable, subtractable + iterator& operator+=(difference_type d) { + it_ += d; + return *this; + } + friend iterator operator+(iterator it, difference_type d) { + it += d; + return it; + } + friend iterator operator+(difference_type d, iterator it) { + it += d; + return it; + } + iterator& operator-=(difference_type d) { + it_ -= d; + return *this; + } + friend iterator operator-(iterator it, difference_type d) { + it -= d; + return it; + } + + // indexable + reference operator[](difference_type d) const { return *(*this + d); } + + // random access iterator + difference_type operator-(const iterator& x) const { return it_ - x.it_; } + + private: + template + friend class RepeatedPtrIterator; + + // The internal iterator. + void** it_; +}; + + +} // namespace internal + +template +inline typename RepeatedPtrField::iterator +RepeatedPtrField::begin() { + return iterator(raw_data()); +} +template +inline typename RepeatedPtrField::const_iterator +RepeatedPtrField::begin() const { + return iterator(raw_data()); +} +template +inline typename RepeatedPtrField::iterator +RepeatedPtrField::end() { + return iterator(raw_data() + size()); +} +template +inline typename RepeatedPtrField::const_iterator +RepeatedPtrField::end() const { + return iterator(raw_data() + size()); +} + +template +inline typename RepeatedPtrField::pointer_iterator +RepeatedPtrField::pointer_begin() { + return pointer_iterator(raw_mutable_data()); +} +template +inline typename RepeatedPtrField::pointer_iterator +RepeatedPtrField::pointer_end() { + return pointer_iterator(raw_mutable_data() + size()); +} + + +// Iterators and helper functions that follow the spirit of the STL +// std::back_insert_iterator and std::back_inserter but are tailor-made +// for RepeatedField and RepatedPtrField. Typical usage would be: +// +// std::copy(some_sequence.begin(), some_sequence.end(), +// google::protobuf::RepeatedFieldBackInserter(proto.mutable_sequence())); +// +// Ported by johannes from util/gtl/proto-array-iterators-inl.h + +namespace internal { +// A back inserter for RepeatedField objects. +template class RepeatedFieldBackInsertIterator + : public std::iterator { + public: + explicit RepeatedFieldBackInsertIterator( + RepeatedField* const mutable_field) + : field_(mutable_field) { + } + RepeatedFieldBackInsertIterator& operator=(const T& value) { + field_->Add(value); + return *this; + } + RepeatedFieldBackInsertIterator& operator*() { + return *this; + } + RepeatedFieldBackInsertIterator& operator++() { + return *this; + } + RepeatedFieldBackInsertIterator& operator++(int ignores_parameter) { + return *this; + } + + private: + RepeatedField* field_; +}; + +// A back inserter for RepeatedPtrField objects. +template class RepeatedPtrFieldBackInsertIterator + : public std::iterator { + public: + RepeatedPtrFieldBackInsertIterator( + RepeatedPtrField* const mutable_field) + : field_(mutable_field) { + } + RepeatedPtrFieldBackInsertIterator& operator=(const T& value) { + *field_->Add() = value; + return *this; + } + RepeatedPtrFieldBackInsertIterator& operator=( + const T* const ptr_to_value) { + *field_->Add() = *ptr_to_value; + return *this; + } + RepeatedPtrFieldBackInsertIterator& operator*() { + return *this; + } + RepeatedPtrFieldBackInsertIterator& operator++() { + return *this; + } + RepeatedPtrFieldBackInsertIterator& operator++(int ignores_parameter) { + return *this; + } + + private: + RepeatedPtrField* field_; +}; + +// A back inserter for RepeatedPtrFields that inserts by transfering ownership +// of a pointer. +template class AllocatedRepeatedPtrFieldBackInsertIterator + : public std::iterator { + public: + explicit AllocatedRepeatedPtrFieldBackInsertIterator( + RepeatedPtrField* const mutable_field) + : field_(mutable_field) { + } + AllocatedRepeatedPtrFieldBackInsertIterator& operator=( + T* const ptr_to_value) { + field_->AddAllocated(ptr_to_value); + return *this; + } + AllocatedRepeatedPtrFieldBackInsertIterator& operator*() { + return *this; + } + AllocatedRepeatedPtrFieldBackInsertIterator& operator++() { + return *this; + } + AllocatedRepeatedPtrFieldBackInsertIterator& operator++( + int ignores_parameter) { + return *this; + } + + private: + RepeatedPtrField* field_; +}; +} // namespace internal + +// Provides a back insert iterator for RepeatedField instances, +// similar to std::back_inserter(). Note the identically named +// function for RepeatedPtrField instances. +template internal::RepeatedFieldBackInsertIterator +RepeatedFieldBackInserter(RepeatedField* const mutable_field) { + return internal::RepeatedFieldBackInsertIterator(mutable_field); +} + +// Provides a back insert iterator for RepeatedPtrField instances, +// similar to std::back_inserter(). Note the identically named +// function for RepeatedField instances. +template internal::RepeatedPtrFieldBackInsertIterator +RepeatedFieldBackInserter(RepeatedPtrField* const mutable_field) { + return internal::RepeatedPtrFieldBackInsertIterator(mutable_field); +} + +// Provides a back insert iterator for RepeatedPtrField instances +// similar to std::back_inserter() which transfers the ownership while +// copying elements. +template internal::AllocatedRepeatedPtrFieldBackInsertIterator +AllocatedRepeatedPtrFieldBackInserter( + RepeatedPtrField* const mutable_field) { + return internal::AllocatedRepeatedPtrFieldBackInsertIterator( + mutable_field); +} + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_REPEATED_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/service.h b/ext/protobuf-2.4.1/src/google/protobuf/service.h new file mode 100644 index 00000000..a6a7d16d --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/service.h @@ -0,0 +1,291 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// DEPRECATED: This module declares the abstract interfaces underlying proto2 +// RPC services. These are intented to be independent of any particular RPC +// implementation, so that proto2 services can be used on top of a variety +// of implementations. Starting with version 2.3.0, RPC implementations should +// not try to build on these, but should instead provide code generator plugins +// which generate code specific to the particular RPC implementation. This way +// the generated code can be more appropriate for the implementation in use +// and can avoid unnecessary layers of indirection. +// +// +// When you use the protocol compiler to compile a service definition, it +// generates two classes: An abstract interface for the service (with +// methods matching the service definition) and a "stub" implementation. +// A stub is just a type-safe wrapper around an RpcChannel which emulates a +// local implementation of the service. +// +// For example, the service definition: +// service MyService { +// rpc Foo(MyRequest) returns(MyResponse); +// } +// will generate abstract interface "MyService" and class "MyService::Stub". +// You could implement a MyService as follows: +// class MyServiceImpl : public MyService { +// public: +// MyServiceImpl() {} +// ~MyServiceImpl() {} +// +// // implements MyService --------------------------------------- +// +// void Foo(google::protobuf::RpcController* controller, +// const MyRequest* request, +// MyResponse* response, +// Closure* done) { +// // ... read request and fill in response ... +// done->Run(); +// } +// }; +// You would then register an instance of MyServiceImpl with your RPC server +// implementation. (How to do that depends on the implementation.) +// +// To call a remote MyServiceImpl, first you need an RpcChannel connected to it. +// How to construct a channel depends, again, on your RPC implementation. +// Here we use a hypothentical "MyRpcChannel" as an example: +// MyRpcChannel channel("rpc:hostname:1234/myservice"); +// MyRpcController controller; +// MyServiceImpl::Stub stub(&channel); +// FooRequest request; +// FooRespnose response; +// +// // ... fill in request ... +// +// stub.Foo(&controller, request, &response, NewCallback(HandleResponse)); +// +// On Thread-Safety: +// +// Different RPC implementations may make different guarantees about what +// threads they may run callbacks on, and what threads the application is +// allowed to use to call the RPC system. Portable software should be ready +// for callbacks to be called on any thread, but should not try to call the +// RPC system from any thread except for the ones on which it received the +// callbacks. Realistically, though, simple software will probably want to +// use a single-threaded RPC system while high-end software will want to +// use multiple threads. RPC implementations should provide multiple +// choices. + +#ifndef GOOGLE_PROTOBUF_SERVICE_H__ +#define GOOGLE_PROTOBUF_SERVICE_H__ + +#include +#include + +namespace google { +namespace protobuf { + +// Defined in this file. +class Service; +class RpcController; +class RpcChannel; + +// Defined in other files. +class Descriptor; // descriptor.h +class ServiceDescriptor; // descriptor.h +class MethodDescriptor; // descriptor.h +class Message; // message.h + +// Abstract base interface for protocol-buffer-based RPC services. Services +// themselves are abstract interfaces (implemented either by servers or as +// stubs), but they subclass this base interface. The methods of this +// interface can be used to call the methods of the Service without knowing +// its exact type at compile time (analogous to Reflection). +class LIBPROTOBUF_EXPORT Service { + public: + inline Service() {} + virtual ~Service(); + + // When constructing a stub, you may pass STUB_OWNS_CHANNEL as the second + // parameter to the constructor to tell it to delete its RpcChannel when + // destroyed. + enum ChannelOwnership { + STUB_OWNS_CHANNEL, + STUB_DOESNT_OWN_CHANNEL + }; + + // Get the ServiceDescriptor describing this service and its methods. + virtual const ServiceDescriptor* GetDescriptor() = 0; + + // Call a method of the service specified by MethodDescriptor. This is + // normally implemented as a simple switch() that calls the standard + // definitions of the service's methods. + // + // Preconditions: + // * method->service() == GetDescriptor() + // * request and response are of the exact same classes as the objects + // returned by GetRequestPrototype(method) and + // GetResponsePrototype(method). + // * After the call has started, the request must not be modified and the + // response must not be accessed at all until "done" is called. + // * "controller" is of the correct type for the RPC implementation being + // used by this Service. For stubs, the "correct type" depends on the + // RpcChannel which the stub is using. Server-side Service + // implementations are expected to accept whatever type of RpcController + // the server-side RPC implementation uses. + // + // Postconditions: + // * "done" will be called when the method is complete. This may be + // before CallMethod() returns or it may be at some point in the future. + // * If the RPC succeeded, "response" contains the response returned by + // the server. + // * If the RPC failed, "response"'s contents are undefined. The + // RpcController can be queried to determine if an error occurred and + // possibly to get more information about the error. + virtual void CallMethod(const MethodDescriptor* method, + RpcController* controller, + const Message* request, + Message* response, + Closure* done) = 0; + + // CallMethod() requires that the request and response passed in are of a + // particular subclass of Message. GetRequestPrototype() and + // GetResponsePrototype() get the default instances of these required types. + // You can then call Message::New() on these instances to construct mutable + // objects which you can then pass to CallMethod(). + // + // Example: + // const MethodDescriptor* method = + // service->GetDescriptor()->FindMethodByName("Foo"); + // Message* request = stub->GetRequestPrototype (method)->New(); + // Message* response = stub->GetResponsePrototype(method)->New(); + // request->ParseFromString(input); + // service->CallMethod(method, *request, response, callback); + virtual const Message& GetRequestPrototype( + const MethodDescriptor* method) const = 0; + virtual const Message& GetResponsePrototype( + const MethodDescriptor* method) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Service); +}; + +// An RpcController mediates a single method call. The primary purpose of +// the controller is to provide a way to manipulate settings specific to the +// RPC implementation and to find out about RPC-level errors. +// +// The methods provided by the RpcController interface are intended to be a +// "least common denominator" set of features which we expect all +// implementations to support. Specific implementations may provide more +// advanced features (e.g. deadline propagation). +class LIBPROTOBUF_EXPORT RpcController { + public: + inline RpcController() {} + virtual ~RpcController(); + + // Client-side methods --------------------------------------------- + // These calls may be made from the client side only. Their results + // are undefined on the server side (may crash). + + // Resets the RpcController to its initial state so that it may be reused in + // a new call. Must not be called while an RPC is in progress. + virtual void Reset() = 0; + + // After a call has finished, returns true if the call failed. The possible + // reasons for failure depend on the RPC implementation. Failed() must not + // be called before a call has finished. If Failed() returns true, the + // contents of the response message are undefined. + virtual bool Failed() const = 0; + + // If Failed() is true, returns a human-readable description of the error. + virtual string ErrorText() const = 0; + + // Advises the RPC system that the caller desires that the RPC call be + // canceled. The RPC system may cancel it immediately, may wait awhile and + // then cancel it, or may not even cancel the call at all. If the call is + // canceled, the "done" callback will still be called and the RpcController + // will indicate that the call failed at that time. + virtual void StartCancel() = 0; + + // Server-side methods --------------------------------------------- + // These calls may be made from the server side only. Their results + // are undefined on the client side (may crash). + + // Causes Failed() to return true on the client side. "reason" will be + // incorporated into the message returned by ErrorText(). If you find + // you need to return machine-readable information about failures, you + // should incorporate it into your response protocol buffer and should + // NOT call SetFailed(). + virtual void SetFailed(const string& reason) = 0; + + // If true, indicates that the client canceled the RPC, so the server may + // as well give up on replying to it. The server should still call the + // final "done" callback. + virtual bool IsCanceled() const = 0; + + // Asks that the given callback be called when the RPC is canceled. The + // callback will always be called exactly once. If the RPC completes without + // being canceled, the callback will be called after completion. If the RPC + // has already been canceled when NotifyOnCancel() is called, the callback + // will be called immediately. + // + // NotifyOnCancel() must be called no more than once per request. + virtual void NotifyOnCancel(Closure* callback) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcController); +}; + +// Abstract interface for an RPC channel. An RpcChannel represents a +// communication line to a Service which can be used to call that Service's +// methods. The Service may be running on another machine. Normally, you +// should not call an RpcChannel directly, but instead construct a stub Service +// wrapping it. Example: +// RpcChannel* channel = new MyRpcChannel("remotehost.example.com:1234"); +// MyService* service = new MyService::Stub(channel); +// service->MyMethod(request, &response, callback); +class LIBPROTOBUF_EXPORT RpcChannel { + public: + inline RpcChannel() {} + virtual ~RpcChannel(); + + // Call the given method of the remote service. The signature of this + // procedure looks the same as Service::CallMethod(), but the requirements + // are less strict in one important way: the request and response objects + // need not be of any specific class as long as their descriptors are + // method->input_type() and method->output_type(). + virtual void CallMethod(const MethodDescriptor* method, + RpcController* controller, + const Message* request, + Message* response, + Closure* done) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcChannel); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_SERVICE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h new file mode 100644 index 00000000..7173a84d --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h @@ -0,0 +1,1211 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) and others +// +// Contains basic types and utilities used by the rest of the library. + +#ifndef GOOGLE_PROTOBUF_COMMON_H__ +#define GOOGLE_PROTOBUF_COMMON_H__ + +#include +#include +#include +#include +#include +#if defined(__osf__) +// Tru64 lacks stdint.h, but has inttypes.h which defines a superset of +// what stdint.h would define. +#include +#elif !defined(_MSC_VER) +#include +#endif + +#if defined(_MSC_VER) && defined(_CPPUNWIND) + #define PROTOBUF_USE_EXCEPTIONS +#elif defined(__EXCEPTIONS) + #define PROTOBUF_USE_EXCEPTIONS +#endif +#ifdef PROTOBUF_USE_EXCEPTIONS +#include +#endif + +#if defined(_WIN32) && defined(GetMessage) +// Allow GetMessage to be used as a valid method name in protobuf classes. +// windows.h defines GetMessage() as a macro. Let's re-define it as an inline +// function. The inline function should be equivalent for C++ users. +inline BOOL GetMessage_Win32( + LPMSG lpMsg, HWND hWnd, + UINT wMsgFilterMin, UINT wMsgFilterMax) { + return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); +} +#undef GetMessage +inline BOOL GetMessage( + LPMSG lpMsg, HWND hWnd, + UINT wMsgFilterMin, UINT wMsgFilterMax) { + return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); +} +#endif + + +namespace std {} + +namespace google { +namespace protobuf { + +#undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS +#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + +#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS) + #ifdef LIBPROTOBUF_EXPORTS + #define LIBPROTOBUF_EXPORT __declspec(dllexport) + #else + #define LIBPROTOBUF_EXPORT __declspec(dllimport) + #endif + #ifdef LIBPROTOC_EXPORTS + #define LIBPROTOC_EXPORT __declspec(dllexport) + #else + #define LIBPROTOC_EXPORT __declspec(dllimport) + #endif +#else + #define LIBPROTOBUF_EXPORT + #define LIBPROTOC_EXPORT +#endif + +namespace internal { + +// Some of these constants are macros rather than const ints so that they can +// be used in #if directives. + +// The current version, represented as a single integer to make comparison +// easier: major * 10^6 + minor * 10^3 + micro +#define GOOGLE_PROTOBUF_VERSION 2004001 + +// The minimum library version which works with the current version of the +// headers. +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2004000 + +// The minimum header version which works with the current version of +// the library. This constant should only be used by protoc's C++ code +// generator. +static const int kMinHeaderVersionForLibrary = 2004000; + +// The minimum protoc version which works with the current version of the +// headers. +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2004000 + +// The minimum header version which works with the current version of +// protoc. This constant should only be used in VerifyVersion(). +static const int kMinHeaderVersionForProtoc = 2004000; + +// Verifies that the headers and libraries are compatible. Use the macro +// below to call this. +void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, + const char* filename); + +// Converts a numeric version number to a string. +std::string LIBPROTOBUF_EXPORT VersionString(int version); + +} // namespace internal + +// Place this macro in your main() function (or somewhere before you attempt +// to use the protobuf library) to verify that the version you link against +// matches the headers you compiled against. If a version mismatch is +// detected, the process will abort. +#define GOOGLE_PROTOBUF_VERIFY_VERSION \ + ::google::protobuf::internal::VerifyVersion( \ + GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION, \ + __FILE__) + +// =================================================================== +// from google3/base/port.h + +typedef unsigned int uint; + +#ifdef _MSC_VER +typedef __int8 int8; +typedef __int16 int16; +typedef __int32 int32; +typedef __int64 int64; + +typedef unsigned __int8 uint8; +typedef unsigned __int16 uint16; +typedef unsigned __int32 uint32; +typedef unsigned __int64 uint64; +#else +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; +#endif + +// long long macros to be used because gcc and vc++ use different suffixes, +// and different size specifiers in format strings +#undef GOOGLE_LONGLONG +#undef GOOGLE_ULONGLONG +#undef GOOGLE_LL_FORMAT + +#ifdef _MSC_VER +#define GOOGLE_LONGLONG(x) x##I64 +#define GOOGLE_ULONGLONG(x) x##UI64 +#define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...) +#else +#define GOOGLE_LONGLONG(x) x##LL +#define GOOGLE_ULONGLONG(x) x##ULL +#define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also. +#endif + +static const int32 kint32max = 0x7FFFFFFF; +static const int32 kint32min = -kint32max - 1; +static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF); +static const int64 kint64min = -kint64max - 1; +static const uint32 kuint32max = 0xFFFFFFFFu; +static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF); + +// ------------------------------------------------------------------- +// Annotations: Some parts of the code have been annotated in ways that might +// be useful to some compilers or tools, but are not supported universally. +// You can #define these annotations yourself if the default implementation +// is not right for you. + +#ifndef GOOGLE_ATTRIBUTE_ALWAYS_INLINE +#if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) +// For functions we want to force inline. +// Introduced in gcc 3.1. +#define GOOGLE_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) +#else +// Other compilers will have to figure it out for themselves. +#define GOOGLE_ATTRIBUTE_ALWAYS_INLINE +#endif +#endif + +#ifndef GOOGLE_ATTRIBUTE_DEPRECATED +#ifdef __GNUC__ +// If the method/variable/type is used anywhere, produce a warning. +#define GOOGLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated)) +#else +#define GOOGLE_ATTRIBUTE_DEPRECATED +#endif +#endif + +#ifndef GOOGLE_PREDICT_TRUE +#ifdef __GNUC__ +// Provided at least since GCC 3.0. +#define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) +#else +#define GOOGLE_PREDICT_TRUE +#endif +#endif + +// Delimits a block of code which may write to memory which is simultaneously +// written by other threads, but which has been determined to be thread-safe +// (e.g. because it is an idempotent write). +#ifndef GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN +#define GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN() +#endif +#ifndef GOOGLE_SAFE_CONCURRENT_WRITES_END +#define GOOGLE_SAFE_CONCURRENT_WRITES_END() +#endif + +// =================================================================== +// from google3/base/basictypes.h + +// The GOOGLE_ARRAYSIZE(arr) macro returns the # of elements in an array arr. +// The expression is a compile-time constant, and therefore can be +// used in defining new arrays, for example. +// +// GOOGLE_ARRAYSIZE catches a few type errors. If you see a compiler error +// +// "warning: division by zero in ..." +// +// when using GOOGLE_ARRAYSIZE, you are (wrongfully) giving it a pointer. +// You should only use GOOGLE_ARRAYSIZE on statically allocated arrays. +// +// The following comments are on the implementation details, and can +// be ignored by the users. +// +// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in +// the array) and sizeof(*(arr)) (the # of bytes in one array +// element). If the former is divisible by the latter, perhaps arr is +// indeed an array, in which case the division result is the # of +// elements in the array. Otherwise, arr cannot possibly be an array, +// and we generate a compiler error to prevent the code from +// compiling. +// +// Since the size of bool is implementation-defined, we need to cast +// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final +// result has type size_t. +// +// This macro is not perfect as it wrongfully accepts certain +// pointers, namely where the pointer size is divisible by the pointee +// size. Since all our code has to go through a 32-bit compiler, +// where a pointer is 4 bytes, this means all pointers to a type whose +// size is 3 or greater than 4 will be (righteously) rejected. +// +// Kudos to Jorg Brown for this simple and elegant implementation. + +#undef GOOGLE_ARRAYSIZE +#define GOOGLE_ARRAYSIZE(a) \ + ((sizeof(a) / sizeof(*(a))) / \ + static_cast(!(sizeof(a) % sizeof(*(a))))) + +namespace internal { + +// Use implicit_cast as a safe version of static_cast or const_cast +// for upcasting in the type hierarchy (i.e. casting a pointer to Foo +// to a pointer to SuperclassOfFoo or casting a pointer to Foo to +// a const pointer to Foo). +// When you use implicit_cast, the compiler checks that the cast is safe. +// Such explicit implicit_casts are necessary in surprisingly many +// situations where C++ demands an exact type match instead of an +// argument type convertable to a target type. +// +// The From type can be inferred, so the preferred syntax for using +// implicit_cast is the same as for static_cast etc.: +// +// implicit_cast(expr) +// +// implicit_cast would have been part of the C++ standard library, +// but the proposal was submitted too late. It will probably make +// its way into the language in the future. +template +inline To implicit_cast(From const &f) { + return f; +} + +// When you upcast (that is, cast a pointer from type Foo to type +// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts +// always succeed. When you downcast (that is, cast a pointer from +// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because +// how do you know the pointer is really of type SubclassOfFoo? It +// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, +// when you downcast, you should use this macro. In debug mode, we +// use dynamic_cast<> to double-check the downcast is legal (we die +// if it's not). In normal mode, we do the efficient static_cast<> +// instead. Thus, it's important to test in debug mode to make sure +// the cast is legal! +// This is the only place in the code we should use dynamic_cast<>. +// In particular, you SHOULDN'T be using dynamic_cast<> in order to +// do RTTI (eg code like this: +// if (dynamic_cast(foo)) HandleASubclass1Object(foo); +// if (dynamic_cast(foo)) HandleASubclass2Object(foo); +// You should design the code some other way not to need this. + +template // use like this: down_cast(foo); +inline To down_cast(From* f) { // so we only accept pointers + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away + // completely. + if (false) { + implicit_cast(0); + } + +#if !defined(NDEBUG) && !defined(GOOGLE_PROTOBUF_NO_RTTI) + assert(f == NULL || dynamic_cast(f) != NULL); // RTTI: debug mode only! +#endif + return static_cast(f); +} + +} // namespace internal + +// We made these internal so that they would show up as such in the docs, +// but we don't want to stick "internal::" in front of them everywhere. +using internal::implicit_cast; +using internal::down_cast; + +// The COMPILE_ASSERT macro can be used to verify that a compile time +// expression is true. For example, you could use it to verify the +// size of a static array: +// +// COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES, +// content_type_names_incorrect_size); +// +// or to make sure a struct is smaller than a certain size: +// +// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); +// +// The second argument to the macro is the name of the variable. If +// the expression is false, most compilers will issue a warning/error +// containing the name of the variable. + +namespace internal { + +template +struct CompileAssert { +}; + +} // namespace internal + +#undef GOOGLE_COMPILE_ASSERT +#define GOOGLE_COMPILE_ASSERT(expr, msg) \ + typedef ::google::protobuf::internal::CompileAssert<(bool(expr))> \ + msg[bool(expr) ? 1 : -1] + + +// Implementation details of COMPILE_ASSERT: +// +// - COMPILE_ASSERT works by defining an array type that has -1 +// elements (and thus is invalid) when the expression is false. +// +// - The simpler definition +// +// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] +// +// does not work, as gcc supports variable-length arrays whose sizes +// are determined at run-time (this is gcc's extension and not part +// of the C++ standard). As a result, gcc fails to reject the +// following code with the simple definition: +// +// int foo; +// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is +// // not a compile-time constant. +// +// - By using the type CompileAssert<(bool(expr))>, we ensures that +// expr is a compile-time constant. (Template arguments must be +// determined at compile-time.) +// +// - The outter parentheses in CompileAssert<(bool(expr))> are necessary +// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written +// +// CompileAssert +// +// instead, these compilers will refuse to compile +// +// COMPILE_ASSERT(5 > 0, some_message); +// +// (They seem to think the ">" in "5 > 0" marks the end of the +// template argument list.) +// +// - The array size is (bool(expr) ? 1 : -1), instead of simply +// +// ((expr) ? 1 : -1). +// +// This is to avoid running into a bug in MS VC 7.1, which +// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. + +// =================================================================== +// from google3/base/scoped_ptr.h + +namespace internal { + +// This is an implementation designed to match the anticipated future TR2 +// implementation of the scoped_ptr class, and its closely-related brethren, +// scoped_array, scoped_ptr_malloc, and make_scoped_ptr. + +template class scoped_ptr; +template class scoped_array; + +// A scoped_ptr is like a T*, except that the destructor of scoped_ptr +// automatically deletes the pointer it holds (if any). +// That is, scoped_ptr owns the T object that it points to. +// Like a T*, a scoped_ptr may hold either NULL or a pointer to a T object. +// +// The size of a scoped_ptr is small: +// sizeof(scoped_ptr) == sizeof(C*) +template +class scoped_ptr { + public: + + // The element type + typedef C element_type; + + // Constructor. Defaults to intializing with NULL. + // There is no way to create an uninitialized scoped_ptr. + // The input parameter must be allocated with new. + explicit scoped_ptr(C* p = NULL) : ptr_(p) { } + + // Destructor. If there is a C object, delete it. + // We don't need to test ptr_ == NULL because C++ does that for us. + ~scoped_ptr() { + enum { type_must_be_complete = sizeof(C) }; + delete ptr_; + } + + // Reset. Deletes the current owned object, if any. + // Then takes ownership of a new object, if given. + // this->reset(this->get()) works. + void reset(C* p = NULL) { + if (p != ptr_) { + enum { type_must_be_complete = sizeof(C) }; + delete ptr_; + ptr_ = p; + } + } + + // Accessors to get the owned object. + // operator* and operator-> will assert() if there is no current object. + C& operator*() const { + assert(ptr_ != NULL); + return *ptr_; + } + C* operator->() const { + assert(ptr_ != NULL); + return ptr_; + } + C* get() const { return ptr_; } + + // Comparison operators. + // These return whether two scoped_ptr refer to the same object, not just to + // two different but equal objects. + bool operator==(C* p) const { return ptr_ == p; } + bool operator!=(C* p) const { return ptr_ != p; } + + // Swap two scoped pointers. + void swap(scoped_ptr& p2) { + C* tmp = ptr_; + ptr_ = p2.ptr_; + p2.ptr_ = tmp; + } + + // Release a pointer. + // The return value is the current pointer held by this object. + // If this object holds a NULL pointer, the return value is NULL. + // After this operation, this object will hold a NULL pointer, + // and will not own the object any more. + C* release() { + C* retVal = ptr_; + ptr_ = NULL; + return retVal; + } + + private: + C* ptr_; + + // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't + // make sense, and if C2 == C, it still doesn't make sense because you should + // never have the same object owned by two different scoped_ptrs. + template bool operator==(scoped_ptr const& p2) const; + template bool operator!=(scoped_ptr const& p2) const; + + // Disallow evil constructors + scoped_ptr(const scoped_ptr&); + void operator=(const scoped_ptr&); +}; + +// scoped_array is like scoped_ptr, except that the caller must allocate +// with new [] and the destructor deletes objects with delete []. +// +// As with scoped_ptr, a scoped_array either points to an object +// or is NULL. A scoped_array owns the object that it points to. +// +// Size: sizeof(scoped_array) == sizeof(C*) +template +class scoped_array { + public: + + // The element type + typedef C element_type; + + // Constructor. Defaults to intializing with NULL. + // There is no way to create an uninitialized scoped_array. + // The input parameter must be allocated with new []. + explicit scoped_array(C* p = NULL) : array_(p) { } + + // Destructor. If there is a C object, delete it. + // We don't need to test ptr_ == NULL because C++ does that for us. + ~scoped_array() { + enum { type_must_be_complete = sizeof(C) }; + delete[] array_; + } + + // Reset. Deletes the current owned object, if any. + // Then takes ownership of a new object, if given. + // this->reset(this->get()) works. + void reset(C* p = NULL) { + if (p != array_) { + enum { type_must_be_complete = sizeof(C) }; + delete[] array_; + array_ = p; + } + } + + // Get one element of the current object. + // Will assert() if there is no current object, or index i is negative. + C& operator[](std::ptrdiff_t i) const { + assert(i >= 0); + assert(array_ != NULL); + return array_[i]; + } + + // Get a pointer to the zeroth element of the current object. + // If there is no current object, return NULL. + C* get() const { + return array_; + } + + // Comparison operators. + // These return whether two scoped_array refer to the same object, not just to + // two different but equal objects. + bool operator==(C* p) const { return array_ == p; } + bool operator!=(C* p) const { return array_ != p; } + + // Swap two scoped arrays. + void swap(scoped_array& p2) { + C* tmp = array_; + array_ = p2.array_; + p2.array_ = tmp; + } + + // Release an array. + // The return value is the current pointer held by this object. + // If this object holds a NULL pointer, the return value is NULL. + // After this operation, this object will hold a NULL pointer, + // and will not own the object any more. + C* release() { + C* retVal = array_; + array_ = NULL; + return retVal; + } + + private: + C* array_; + + // Forbid comparison of different scoped_array types. + template bool operator==(scoped_array const& p2) const; + template bool operator!=(scoped_array const& p2) const; + + // Disallow evil constructors + scoped_array(const scoped_array&); + void operator=(const scoped_array&); +}; + +} // namespace internal + +// We made these internal so that they would show up as such in the docs, +// but we don't want to stick "internal::" in front of them everywhere. +using internal::scoped_ptr; +using internal::scoped_array; + +// =================================================================== +// emulates google3/base/logging.h + +enum LogLevel { + LOGLEVEL_INFO, // Informational. This is never actually used by + // libprotobuf. + LOGLEVEL_WARNING, // Warns about issues that, although not technically a + // problem now, could cause problems in the future. For + // example, a // warning will be printed when parsing a + // message that is near the message size limit. + LOGLEVEL_ERROR, // An error occurred which should never happen during + // normal use. + LOGLEVEL_FATAL, // An error occurred from which the library cannot + // recover. This usually indicates a programming error + // in the code which calls the library, especially when + // compiled in debug mode. + +#ifdef NDEBUG + LOGLEVEL_DFATAL = LOGLEVEL_ERROR +#else + LOGLEVEL_DFATAL = LOGLEVEL_FATAL +#endif +}; + +namespace internal { + +class LogFinisher; + +class LIBPROTOBUF_EXPORT LogMessage { + public: + LogMessage(LogLevel level, const char* filename, int line); + ~LogMessage(); + + LogMessage& operator<<(const std::string& value); + LogMessage& operator<<(const char* value); + LogMessage& operator<<(char value); + LogMessage& operator<<(int value); + LogMessage& operator<<(uint value); + LogMessage& operator<<(long value); + LogMessage& operator<<(unsigned long value); + LogMessage& operator<<(double value); + + private: + friend class LogFinisher; + void Finish(); + + LogLevel level_; + const char* filename_; + int line_; + std::string message_; +}; + +// Used to make the entire "LOG(BLAH) << etc." expression have a void return +// type and print a newline after each message. +class LIBPROTOBUF_EXPORT LogFinisher { + public: + void operator=(LogMessage& other); +}; + +} // namespace internal + +// Undef everything in case we're being mixed with some other Google library +// which already defined them itself. Presumably all Google libraries will +// support the same syntax for these so it should not be a big deal if they +// end up using our definitions instead. +#undef GOOGLE_LOG +#undef GOOGLE_LOG_IF + +#undef GOOGLE_CHECK +#undef GOOGLE_CHECK_EQ +#undef GOOGLE_CHECK_NE +#undef GOOGLE_CHECK_LT +#undef GOOGLE_CHECK_LE +#undef GOOGLE_CHECK_GT +#undef GOOGLE_CHECK_GE + +#undef GOOGLE_DLOG +#undef GOOGLE_DCHECK +#undef GOOGLE_DCHECK_EQ +#undef GOOGLE_DCHECK_NE +#undef GOOGLE_DCHECK_LT +#undef GOOGLE_DCHECK_LE +#undef GOOGLE_DCHECK_GT +#undef GOOGLE_DCHECK_GE + +#define GOOGLE_LOG(LEVEL) \ + ::google::protobuf::internal::LogFinisher() = \ + ::google::protobuf::internal::LogMessage( \ + ::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__) +#define GOOGLE_LOG_IF(LEVEL, CONDITION) \ + !(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL) + +#define GOOGLE_CHECK(EXPRESSION) \ + GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": " +#define GOOGLE_CHECK_EQ(A, B) GOOGLE_CHECK((A) == (B)) +#define GOOGLE_CHECK_NE(A, B) GOOGLE_CHECK((A) != (B)) +#define GOOGLE_CHECK_LT(A, B) GOOGLE_CHECK((A) < (B)) +#define GOOGLE_CHECK_LE(A, B) GOOGLE_CHECK((A) <= (B)) +#define GOOGLE_CHECK_GT(A, B) GOOGLE_CHECK((A) > (B)) +#define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B)) + +#ifdef NDEBUG + +#define GOOGLE_DLOG GOOGLE_LOG_IF(INFO, false) + +#define GOOGLE_DCHECK(EXPRESSION) while(false) GOOGLE_CHECK(EXPRESSION) +#define GOOGLE_DCHECK_EQ(A, B) GOOGLE_DCHECK((A) == (B)) +#define GOOGLE_DCHECK_NE(A, B) GOOGLE_DCHECK((A) != (B)) +#define GOOGLE_DCHECK_LT(A, B) GOOGLE_DCHECK((A) < (B)) +#define GOOGLE_DCHECK_LE(A, B) GOOGLE_DCHECK((A) <= (B)) +#define GOOGLE_DCHECK_GT(A, B) GOOGLE_DCHECK((A) > (B)) +#define GOOGLE_DCHECK_GE(A, B) GOOGLE_DCHECK((A) >= (B)) + +#else // NDEBUG + +#define GOOGLE_DLOG GOOGLE_LOG + +#define GOOGLE_DCHECK GOOGLE_CHECK +#define GOOGLE_DCHECK_EQ GOOGLE_CHECK_EQ +#define GOOGLE_DCHECK_NE GOOGLE_CHECK_NE +#define GOOGLE_DCHECK_LT GOOGLE_CHECK_LT +#define GOOGLE_DCHECK_LE GOOGLE_CHECK_LE +#define GOOGLE_DCHECK_GT GOOGLE_CHECK_GT +#define GOOGLE_DCHECK_GE GOOGLE_CHECK_GE + +#endif // !NDEBUG + +typedef void LogHandler(LogLevel level, const char* filename, int line, + const std::string& message); + +// The protobuf library sometimes writes warning and error messages to +// stderr. These messages are primarily useful for developers, but may +// also help end users figure out a problem. If you would prefer that +// these messages be sent somewhere other than stderr, call SetLogHandler() +// to set your own handler. This returns the old handler. Set the handler +// to NULL to ignore log messages (but see also LogSilencer, below). +// +// Obviously, SetLogHandler is not thread-safe. You should only call it +// at initialization time, and probably not from library code. If you +// simply want to suppress log messages temporarily (e.g. because you +// have some code that tends to trigger them frequently and you know +// the warnings are not important to you), use the LogSilencer class +// below. +LIBPROTOBUF_EXPORT LogHandler* SetLogHandler(LogHandler* new_func); + +// Create a LogSilencer if you want to temporarily suppress all log +// messages. As long as any LogSilencer objects exist, non-fatal +// log messages will be discarded (the current LogHandler will *not* +// be called). Constructing a LogSilencer is thread-safe. You may +// accidentally suppress log messages occurring in another thread, but +// since messages are generally for debugging purposes only, this isn't +// a big deal. If you want to intercept log messages, use SetLogHandler(). +class LIBPROTOBUF_EXPORT LogSilencer { + public: + LogSilencer(); + ~LogSilencer(); +}; + +// =================================================================== +// emulates google3/base/callback.h + +// Abstract interface for a callback. When calling an RPC, you must provide +// a Closure to call when the procedure completes. See the Service interface +// in service.h. +// +// To automatically construct a Closure which calls a particular function or +// method with a particular set of parameters, use the NewCallback() function. +// Example: +// void FooDone(const FooResponse* response) { +// ... +// } +// +// void CallFoo() { +// ... +// // When done, call FooDone() and pass it a pointer to the response. +// Closure* callback = NewCallback(&FooDone, response); +// // Make the call. +// service->Foo(controller, request, response, callback); +// } +// +// Example that calls a method: +// class Handler { +// public: +// ... +// +// void FooDone(const FooResponse* response) { +// ... +// } +// +// void CallFoo() { +// ... +// // When done, call FooDone() and pass it a pointer to the response. +// Closure* callback = NewCallback(this, &Handler::FooDone, response); +// // Make the call. +// service->Foo(controller, request, response, callback); +// } +// }; +// +// Currently NewCallback() supports binding zero, one, or two arguments. +// +// Callbacks created with NewCallback() automatically delete themselves when +// executed. They should be used when a callback is to be called exactly +// once (usually the case with RPC callbacks). If a callback may be called +// a different number of times (including zero), create it with +// NewPermanentCallback() instead. You are then responsible for deleting the +// callback (using the "delete" keyword as normal). +// +// Note that NewCallback() is a bit touchy regarding argument types. Generally, +// the values you provide for the parameter bindings must exactly match the +// types accepted by the callback function. For example: +// void Foo(string s); +// NewCallback(&Foo, "foo"); // WON'T WORK: const char* != string +// NewCallback(&Foo, string("foo")); // WORKS +// Also note that the arguments cannot be references: +// void Foo(const string& s); +// string my_str; +// NewCallback(&Foo, my_str); // WON'T WORK: Can't use referecnes. +// However, correctly-typed pointers will work just fine. +class LIBPROTOBUF_EXPORT Closure { + public: + Closure() {} + virtual ~Closure(); + + virtual void Run() = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Closure); +}; + +namespace internal { + +class LIBPROTOBUF_EXPORT FunctionClosure0 : public Closure { + public: + typedef void (*FunctionType)(); + + FunctionClosure0(FunctionType function, bool self_deleting) + : function_(function), self_deleting_(self_deleting) {} + ~FunctionClosure0(); + + void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes + function_(); + if (needs_delete) delete this; + } + + private: + FunctionType function_; + bool self_deleting_; +}; + +template +class MethodClosure0 : public Closure { + public: + typedef void (Class::*MethodType)(); + + MethodClosure0(Class* object, MethodType method, bool self_deleting) + : object_(object), method_(method), self_deleting_(self_deleting) {} + ~MethodClosure0() {} + + void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes + (object_->*method_)(); + if (needs_delete) delete this; + } + + private: + Class* object_; + MethodType method_; + bool self_deleting_; +}; + +template +class FunctionClosure1 : public Closure { + public: + typedef void (*FunctionType)(Arg1 arg1); + + FunctionClosure1(FunctionType function, bool self_deleting, + Arg1 arg1) + : function_(function), self_deleting_(self_deleting), + arg1_(arg1) {} + ~FunctionClosure1() {} + + void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes + function_(arg1_); + if (needs_delete) delete this; + } + + private: + FunctionType function_; + bool self_deleting_; + Arg1 arg1_; +}; + +template +class MethodClosure1 : public Closure { + public: + typedef void (Class::*MethodType)(Arg1 arg1); + + MethodClosure1(Class* object, MethodType method, bool self_deleting, + Arg1 arg1) + : object_(object), method_(method), self_deleting_(self_deleting), + arg1_(arg1) {} + ~MethodClosure1() {} + + void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes + (object_->*method_)(arg1_); + if (needs_delete) delete this; + } + + private: + Class* object_; + MethodType method_; + bool self_deleting_; + Arg1 arg1_; +}; + +template +class FunctionClosure2 : public Closure { + public: + typedef void (*FunctionType)(Arg1 arg1, Arg2 arg2); + + FunctionClosure2(FunctionType function, bool self_deleting, + Arg1 arg1, Arg2 arg2) + : function_(function), self_deleting_(self_deleting), + arg1_(arg1), arg2_(arg2) {} + ~FunctionClosure2() {} + + void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes + function_(arg1_, arg2_); + if (needs_delete) delete this; + } + + private: + FunctionType function_; + bool self_deleting_; + Arg1 arg1_; + Arg2 arg2_; +}; + +template +class MethodClosure2 : public Closure { + public: + typedef void (Class::*MethodType)(Arg1 arg1, Arg2 arg2); + + MethodClosure2(Class* object, MethodType method, bool self_deleting, + Arg1 arg1, Arg2 arg2) + : object_(object), method_(method), self_deleting_(self_deleting), + arg1_(arg1), arg2_(arg2) {} + ~MethodClosure2() {} + + void Run() { + bool needs_delete = self_deleting_; // read in case callback deletes + (object_->*method_)(arg1_, arg2_); + if (needs_delete) delete this; + } + + private: + Class* object_; + MethodType method_; + bool self_deleting_; + Arg1 arg1_; + Arg2 arg2_; +}; + +} // namespace internal + +// See Closure. +inline Closure* NewCallback(void (*function)()) { + return new internal::FunctionClosure0(function, true); +} + +// See Closure. +inline Closure* NewPermanentCallback(void (*function)()) { + return new internal::FunctionClosure0(function, false); +} + +// See Closure. +template +inline Closure* NewCallback(Class* object, void (Class::*method)()) { + return new internal::MethodClosure0(object, method, true); +} + +// See Closure. +template +inline Closure* NewPermanentCallback(Class* object, void (Class::*method)()) { + return new internal::MethodClosure0(object, method, false); +} + +// See Closure. +template +inline Closure* NewCallback(void (*function)(Arg1), + Arg1 arg1) { + return new internal::FunctionClosure1(function, true, arg1); +} + +// See Closure. +template +inline Closure* NewPermanentCallback(void (*function)(Arg1), + Arg1 arg1) { + return new internal::FunctionClosure1(function, false, arg1); +} + +// See Closure. +template +inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1), + Arg1 arg1) { + return new internal::MethodClosure1(object, method, true, arg1); +} + +// See Closure. +template +inline Closure* NewPermanentCallback(Class* object, void (Class::*method)(Arg1), + Arg1 arg1) { + return new internal::MethodClosure1(object, method, false, arg1); +} + +// See Closure. +template +inline Closure* NewCallback(void (*function)(Arg1, Arg2), + Arg1 arg1, Arg2 arg2) { + return new internal::FunctionClosure2( + function, true, arg1, arg2); +} + +// See Closure. +template +inline Closure* NewPermanentCallback(void (*function)(Arg1, Arg2), + Arg1 arg1, Arg2 arg2) { + return new internal::FunctionClosure2( + function, false, arg1, arg2); +} + +// See Closure. +template +inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1, Arg2), + Arg1 arg1, Arg2 arg2) { + return new internal::MethodClosure2( + object, method, true, arg1, arg2); +} + +// See Closure. +template +inline Closure* NewPermanentCallback( + Class* object, void (Class::*method)(Arg1, Arg2), + Arg1 arg1, Arg2 arg2) { + return new internal::MethodClosure2( + object, method, false, arg1, arg2); +} + +// A function which does nothing. Useful for creating no-op callbacks, e.g.: +// Closure* nothing = NewCallback(&DoNothing); +void LIBPROTOBUF_EXPORT DoNothing(); + +// =================================================================== +// emulates google3/base/mutex.h + +namespace internal { + +// A Mutex is a non-reentrant (aka non-recursive) mutex. At most one thread T +// may hold a mutex at a given time. If T attempts to Lock() the same Mutex +// while holding it, T will deadlock. +class LIBPROTOBUF_EXPORT Mutex { + public: + // Create a Mutex that is not held by anybody. + Mutex(); + + // Destructor + ~Mutex(); + + // Block if necessary until this Mutex is free, then acquire it exclusively. + void Lock(); + + // Release this Mutex. Caller must hold it exclusively. + void Unlock(); + + // Crash if this Mutex is not held exclusively by this thread. + // May fail to crash when it should; will never crash when it should not. + void AssertHeld(); + + private: + struct Internal; + Internal* mInternal; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Mutex); +}; + +// MutexLock(mu) acquires mu when constructed and releases it when destroyed. +class LIBPROTOBUF_EXPORT MutexLock { + public: + explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); } + ~MutexLock() { this->mu_->Unlock(); } + private: + Mutex *const mu_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLock); +}; + +// TODO(kenton): Implement these? Hard to implement portably. +typedef MutexLock ReaderMutexLock; +typedef MutexLock WriterMutexLock; + +// MutexLockMaybe is like MutexLock, but is a no-op when mu is NULL. +class LIBPROTOBUF_EXPORT MutexLockMaybe { + public: + explicit MutexLockMaybe(Mutex *mu) : + mu_(mu) { if (this->mu_ != NULL) { this->mu_->Lock(); } } + ~MutexLockMaybe() { if (this->mu_ != NULL) { this->mu_->Unlock(); } } + private: + Mutex *const mu_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLockMaybe); +}; + +} // namespace internal + +// We made these internal so that they would show up as such in the docs, +// but we don't want to stick "internal::" in front of them everywhere. +using internal::Mutex; +using internal::MutexLock; +using internal::ReaderMutexLock; +using internal::WriterMutexLock; +using internal::MutexLockMaybe; + +// =================================================================== +// from google3/base/type_traits.h + +namespace internal { + +// Specified by TR1 [4.7.4] Pointer modifications. +template struct remove_pointer { typedef T type; }; +template struct remove_pointer { typedef T type; }; +template struct remove_pointer { typedef T type; }; +template struct remove_pointer { typedef T type; }; +template struct remove_pointer { + typedef T type; }; + +// =================================================================== + +// Checks if the buffer contains structurally-valid UTF-8. Implemented in +// structurally_valid.cc. +LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); + +} // namespace internal + +// =================================================================== +// Shutdown support. + +// Shut down the entire protocol buffers library, deleting all static-duration +// objects allocated by the library or by generated .pb.cc files. +// +// There are two reasons you might want to call this: +// * You use a draconian definition of "memory leak" in which you expect +// every single malloc() to have a corresponding free(), even for objects +// which live until program exit. +// * You are writing a dynamically-loaded library which needs to clean up +// after itself when the library is unloaded. +// +// It is safe to call this multiple times. However, it is not safe to use +// any other part of the protocol buffers library after +// ShutdownProtobufLibrary() has been called. +LIBPROTOBUF_EXPORT void ShutdownProtobufLibrary(); + +namespace internal { + +// Register a function to be called when ShutdownProtocolBuffers() is called. +LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); + +} // namespace internal + +#ifdef PROTOBUF_USE_EXCEPTIONS +class FatalException : public std::exception { + public: + FatalException(const char* filename, int line, const std::string& message) + : filename_(filename), line_(line), message_(message) {} + virtual ~FatalException() throw(); + + virtual const char* what() const throw(); + + const char* filename() const { return filename_; } + int line() const { return line_; } + const std::string& message() const { return message_; } + + private: + const char* filename_; + const int line_; + const std::string message_; +}; +#endif + +// This is at the end of the file instead of the beginning to work around a bug +// in some versions of MSVC. +using namespace std; // Don't do this at home, kids. + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_COMMON_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h new file mode 100644 index 00000000..822d6050 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h @@ -0,0 +1,220 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// +// Deals with the fact that hash_map is not defined everywhere. + +#ifndef GOOGLE_PROTOBUF_STUBS_HASH_H__ +#define GOOGLE_PROTOBUF_STUBS_HASH_H__ + +#include +#include +#include "config.h" + +#if defined(HAVE_HASH_MAP) && defined(HAVE_HASH_SET) +#include HASH_MAP_H +#include HASH_SET_H +#else +#define MISSING_HASH +#include +#include +#endif + +namespace google { +namespace protobuf { + +#ifdef MISSING_HASH + +// This system doesn't have hash_map or hash_set. Emulate them using map and +// set. + +// Make hash be the same as less. Note that everywhere where custom +// hash functions are defined in the protobuf code, they are also defined such +// that they can be used as "less" functions, which is required by MSVC anyway. +template +struct hash { + // Dummy, just to make derivative hash functions compile. + int operator()(const Key& key) { + GOOGLE_LOG(FATAL) << "Should never be called."; + return 0; + } + + inline bool operator()(const Key& a, const Key& b) const { + return a < b; + } +}; + +// Make sure char* is compared by value. +template <> +struct hash { + // Dummy, just to make derivative hash functions compile. + int operator()(const char* key) { + GOOGLE_LOG(FATAL) << "Should never be called."; + return 0; + } + + inline bool operator()(const char* a, const char* b) const { + return strcmp(a, b) < 0; + } +}; + +template , + typename EqualKey = int > +class hash_map : public std::map { +}; + +template , + typename EqualKey = int > +class hash_set : public std::set { +}; + +#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) + +template +struct hash : public HASH_NAMESPACE::hash_compare { +}; + +// MSVC's hash_compare hashes based on the string contents but +// compares based on the string pointer. WTF? +class CstringLess { + public: + inline bool operator()(const char* a, const char* b) const { + return strcmp(a, b) < 0; + } +}; + +template <> +struct hash + : public HASH_NAMESPACE::hash_compare { +}; + +template , + typename EqualKey = int > +class hash_map : public HASH_NAMESPACE::hash_map< + Key, Data, HashFcn> { +}; + +template , + typename EqualKey = int > +class hash_set : public HASH_NAMESPACE::hash_set< + Key, HashFcn> { +}; + +#else + +template +struct hash : public HASH_NAMESPACE::hash { +}; + +template +struct hash { + inline size_t operator()(const Key* key) const { + return reinterpret_cast(key); + } +}; + +// Unlike the old SGI version, the TR1 "hash" does not special-case char*. So, +// we go ahead and provide our own implementation. +template <> +struct hash { + inline size_t operator()(const char* str) const { + size_t result = 0; + for (; *str != '\0'; str++) { + result = 5 * result + *str; + } + return result; + } +}; + +template , + typename EqualKey = std::equal_to > +class hash_map : public HASH_NAMESPACE::HASH_MAP_CLASS< + Key, Data, HashFcn, EqualKey> { +}; + +template , + typename EqualKey = std::equal_to > +class hash_set : public HASH_NAMESPACE::HASH_SET_CLASS< + Key, HashFcn, EqualKey> { +}; + +#endif + +template <> +struct hash { + inline size_t operator()(const string& key) const { + return hash()(key.c_str()); + } + + static const size_t bucket_size = 4; + static const size_t min_buckets = 8; + inline size_t operator()(const string& a, const string& b) const { + return a < b; + } +}; + +template +struct hash > { + inline size_t operator()(const pair& key) const { + size_t first_hash = hash()(key.first); + size_t second_hash = hash()(key.second); + + // FIXME(kenton): What is the best way to compute this hash? I have + // no idea! This seems a bit better than an XOR. + return first_hash * ((1 << 16) - 1) + second_hash; + } + + static const size_t bucket_size = 4; + static const size_t min_buckets = 8; + inline size_t operator()(const pair& a, + const pair& b) const { + return a < b; + } +}; + +// Used by GCC/SGI STL only. (Why isn't this provided by the standard +// library? :( ) +struct streq { + inline bool operator()(const char* a, const char* b) const { + return strcmp(a, b) == 0; + } +}; + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_HASH_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h new file mode 100644 index 00000000..f5c9d6b6 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h @@ -0,0 +1,119 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// from google3/util/gtl/map-util.h +// Author: Anton Carver + +#ifndef GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ +#define GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ + +#include + +namespace google { +namespace protobuf { + +// Perform a lookup in a map or hash_map. +// If the key is present in the map then the value associated with that +// key is returned, otherwise the value passed as a default is returned. +template +const typename Collection::value_type::second_type& +FindWithDefault(const Collection& collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return value; + } + return it->second; +} + +// Perform a lookup in a map or hash_map. +// If the key is present a const pointer to the associated value is returned, +// otherwise a NULL pointer is returned. +template +const typename Collection::value_type::second_type* +FindOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + return &it->second; +} + +// Perform a lookup in a map or hash_map whose values are pointers. +// If the key is present a const pointer to the associated value is returned, +// otherwise a NULL pointer is returned. +// This function does not distinguish between a missing key and a key mapped +// to a NULL value. +template +const typename Collection::value_type::second_type +FindPtrOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + return it->second; +} + +// Change the value associated with a particular key in a map or hash_map. +// If the key is not present in the map the key and value are inserted, +// otherwise the value is updated to be a copy of the value provided. +// True indicates that an insert took place, false indicates an update. +template +bool InsertOrUpdate(Collection * const collection, + const Key& key, const Value& value) { + pair ret = + collection->insert(typename Collection::value_type(key, value)); + if (!ret.second) { + // update + ret.first->second = value; + return false; + } + return true; +} + +// Insert a new key and value into a map or hash_map. +// If the key is not present in the map the key and value are +// inserted, otherwise nothing happens. True indicates that an insert +// took place, false indicates the key was already present. +template +bool InsertIfNotPresent(Collection * const collection, + const Key& key, const Value& value) { + pair ret = + collection->insert(typename Collection::value_type(key, value)); + return ret.second; +} + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h new file mode 100644 index 00000000..0dee4076 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h @@ -0,0 +1,123 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// +// emulates google3/base/once.h +// +// This header is intended to be included only by internal .cc files and +// generated .pb.cc files. Users should not use this directly. +// +// This is basically a portable version of pthread_once(). +// +// This header declares three things: +// * A type called ProtobufOnceType. +// * A macro GOOGLE_PROTOBUF_DECLARE_ONCE() which declares a variable of type +// ProtobufOnceType. This is the only legal way to declare such a variable. +// The macro may only be used at the global scope (you cannot create local +// or class member variables of this type). +// * A function GogoleOnceInit(ProtobufOnceType* once, void (*init_func)()). +// This function, when invoked multiple times given the same ProtobufOnceType +// object, will invoke init_func on the first call only, and will make sure +// none of the calls return before that first call to init_func has finished. +// +// This implements a way to perform lazy initialization. It's more efficient +// than using mutexes as no lock is needed if initialization has already +// happened. +// +// Example usage: +// void Init(); +// GOOGLE_PROTOBUF_DECLARE_ONCE(once_init); +// +// // Calls Init() exactly once. +// void InitOnce() { +// GoogleOnceInit(&once_init, &Init); +// } +// +// Note that if GoogleOnceInit() is called before main() has begun, it must +// only be called by the thread that will eventually call main() -- that is, +// the thread that performs dynamic initialization. In general this is a safe +// assumption since people don't usually construct threads before main() starts, +// but it is technically not guaranteed. Unfortunately, Win32 provides no way +// whatsoever to statically-initialize its synchronization primitives, so our +// only choice is to assume that dynamic initialization is single-threaded. + +#ifndef GOOGLE_PROTOBUF_STUBS_ONCE_H__ +#define GOOGLE_PROTOBUF_STUBS_ONCE_H__ + +#include + +#ifndef _WIN32 +#include +#endif + +namespace google { +namespace protobuf { + +#ifdef _WIN32 + +struct ProtobufOnceInternal; + +struct LIBPROTOBUF_EXPORT ProtobufOnceType { + ProtobufOnceType(); + ~ProtobufOnceType(); + void Init(void (*init_func)()); + + volatile bool initialized_; + ProtobufOnceInternal* internal_; +}; + +#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ + ::google::protobuf::ProtobufOnceType NAME + +inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) { + // Note: Double-checked locking is safe on x86. + if (!once->initialized_) { + once->Init(init_func); + } +} + +#else + +typedef pthread_once_t ProtobufOnceType; + +#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ + pthread_once_t NAME = PTHREAD_ONCE_INIT + +inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) { + pthread_once(once, init_func); +} + +#endif + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_ONCE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h new file mode 100644 index 00000000..a2e671bb --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h @@ -0,0 +1,121 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// from google3/util/gtl/stl_util-inl.h + +#ifndef GOOGLE_PROTOBUF_STUBS_STL_UTIL_INL_H__ +#define GOOGLE_PROTOBUF_STUBS_STL_UTIL_INL_H__ + +#include + +namespace google { +namespace protobuf { + +// STLDeleteContainerPointers() +// For a range within a container of pointers, calls delete +// (non-array version) on these pointers. +// NOTE: for these three functions, we could just implement a DeleteObject +// functor and then call for_each() on the range and functor, but this +// requires us to pull in all of algorithm.h, which seems expensive. +// For hash_[multi]set, it is important that this deletes behind the iterator +// because the hash_set may call the hash function on the iterator when it is +// advanced, which could result in the hash function trying to deference a +// stale pointer. +template +void STLDeleteContainerPointers(ForwardIterator begin, + ForwardIterator end) { + while (begin != end) { + ForwardIterator temp = begin; + ++begin; + delete *temp; + } +} + +// Inside Google, this function implements a horrible, disgusting hack in which +// we reach into the string's private implementation and resize it without +// initializing the new bytes. In some cases doing this can significantly +// improve performance. However, since it's totally non-portable it has no +// place in open source code. Feel free to fill this function in with your +// own disgusting hack if you want the perf boost. +inline void STLStringResizeUninitialized(string* s, size_t new_size) { + s->resize(new_size); +} + +// Return a mutable char* pointing to a string's internal buffer, +// which may not be null-terminated. Writing through this pointer will +// modify the string. +// +// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the +// next call to a string method that invalidates iterators. +// +// As of 2006-04, there is no standard-blessed way of getting a +// mutable reference to a string's internal buffer. However, issue 530 +// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) +// proposes this as the method. According to Matt Austern, this should +// already work on all current implementations. +inline char* string_as_array(string* str) { + // DO NOT USE const_cast(str->data())! See the unittest for why. + return str->empty() ? NULL : &*str->begin(); +} + +// STLDeleteElements() deletes all the elements in an STL container and clears +// the container. This function is suitable for use with a vector, set, +// hash_set, or any other STL container which defines sensible begin(), end(), +// and clear() methods. +// +// If container is NULL, this function is a no-op. +// +// As an alternative to calling STLDeleteElements() directly, consider +// ElementDeleter (defined below), which ensures that your container's elements +// are deleted when the ElementDeleter goes out of scope. +template +void STLDeleteElements(T *container) { + if (!container) return; + STLDeleteContainerPointers(container->begin(), container->end()); + container->clear(); +} + +// Given an STL container consisting of (key, value) pairs, STLDeleteValues +// deletes all the "value" components and clears the container. Does nothing +// in the case it's given a NULL pointer. + +template +void STLDeleteValues(T *v) { + if (!v) return; + for (typename T::iterator i = v->begin(); i != v->end(); ++i) { + delete i->second; + } + v->clear(); +} + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_STL_UTIL_INL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h new file mode 100644 index 00000000..4a79c224 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h @@ -0,0 +1,457 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// from google3/strings/strutil.h + +#ifndef GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ +#define GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + +#ifdef _MSC_VER +#define strtoll _strtoi64 +#define strtoull _strtoui64 +#elif defined(__DECCXX) && defined(__osf__) +// HP C++ on Tru64 does not have strtoll, but strtol is already 64-bit. +#define strtoll strtol +#define strtoull strtoul +#endif + +// ---------------------------------------------------------------------- +// ascii_isalnum() +// Check if an ASCII character is alphanumeric. We can't use ctype's +// isalnum() because it is affected by locale. This function is applied +// to identifiers in the protocol buffer language, not to natural-language +// strings, so locale should not be taken into account. +// ascii_isdigit() +// Like above, but only accepts digits. +// ---------------------------------------------------------------------- + +inline bool ascii_isalnum(char c) { + return ('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z') || + ('0' <= c && c <= '9'); +} + +inline bool ascii_isdigit(char c) { + return ('0' <= c && c <= '9'); +} + +// ---------------------------------------------------------------------- +// HasPrefixString() +// Check if a string begins with a given prefix. +// StripPrefixString() +// Given a string and a putative prefix, returns the string minus the +// prefix string if the prefix matches, otherwise the original +// string. +// ---------------------------------------------------------------------- +inline bool HasPrefixString(const string& str, + const string& prefix) { + return str.size() >= prefix.size() && + str.compare(0, prefix.size(), prefix) == 0; +} + +inline string StripPrefixString(const string& str, const string& prefix) { + if (HasPrefixString(str, prefix)) { + return str.substr(prefix.size()); + } else { + return str; + } +} + +// ---------------------------------------------------------------------- +// HasSuffixString() +// Return true if str ends in suffix. +// StripSuffixString() +// Given a string and a putative suffix, returns the string minus the +// suffix string if the suffix matches, otherwise the original +// string. +// ---------------------------------------------------------------------- +inline bool HasSuffixString(const string& str, + const string& suffix) { + return str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} + +inline string StripSuffixString(const string& str, const string& suffix) { + if (HasSuffixString(str, suffix)) { + return str.substr(0, str.size() - suffix.size()); + } else { + return str; + } +} + +// ---------------------------------------------------------------------- +// StripString +// Replaces any occurrence of the character 'remove' (or the characters +// in 'remove') with the character 'replacewith'. +// Good for keeping html characters or protocol characters (\t) out +// of places where they might cause a problem. +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT void StripString(string* s, const char* remove, + char replacewith); + +// ---------------------------------------------------------------------- +// LowerString() +// UpperString() +// Convert the characters in "s" to lowercase or uppercase. ASCII-only: +// these functions intentionally ignore locale because they are applied to +// identifiers used in the Protocol Buffer language, not to natural-language +// strings. +// ---------------------------------------------------------------------- + +inline void LowerString(string * s) { + string::iterator end = s->end(); + for (string::iterator i = s->begin(); i != end; ++i) { + // tolower() changes based on locale. We don't want this! + if ('A' <= *i && *i <= 'Z') *i += 'a' - 'A'; + } +} + +inline void UpperString(string * s) { + string::iterator end = s->end(); + for (string::iterator i = s->begin(); i != end; ++i) { + // toupper() changes based on locale. We don't want this! + if ('a' <= *i && *i <= 'z') *i += 'A' - 'a'; + } +} + +// ---------------------------------------------------------------------- +// StringReplace() +// Give me a string and two patterns "old" and "new", and I replace +// the first instance of "old" in the string with "new", if it +// exists. RETURN a new string, regardless of whether the replacement +// happened or not. +// ---------------------------------------------------------------------- + +LIBPROTOBUF_EXPORT string StringReplace(const string& s, const string& oldsub, + const string& newsub, bool replace_all); + +// ---------------------------------------------------------------------- +// SplitStringUsing() +// Split a string using a character delimiter. Append the components +// to 'result'. If there are consecutive delimiters, this function skips +// over all of them. +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT void SplitStringUsing(const string& full, const char* delim, + vector* res); + +// ---------------------------------------------------------------------- +// JoinStrings() +// These methods concatenate a vector of strings into a C++ string, using +// the C-string "delim" as a separator between components. There are two +// flavors of the function, one flavor returns the concatenated string, +// another takes a pointer to the target string. In the latter case the +// target string is cleared and overwritten. +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT void JoinStrings(const vector& components, + const char* delim, string* result); + +inline string JoinStrings(const vector& components, + const char* delim) { + string result; + JoinStrings(components, delim, &result); + return result; +} + +// ---------------------------------------------------------------------- +// UnescapeCEscapeSequences() +// Copies "source" to "dest", rewriting C-style escape sequences +// -- '\n', '\r', '\\', '\ooo', etc -- to their ASCII +// equivalents. "dest" must be sufficiently large to hold all +// the characters in the rewritten string (i.e. at least as large +// as strlen(source) + 1 should be safe, since the replacements +// are always shorter than the original escaped sequences). It's +// safe for source and dest to be the same. RETURNS the length +// of dest. +// +// It allows hex sequences \xhh, or generally \xhhhhh with an +// arbitrary number of hex digits, but all of them together must +// specify a value of a single byte (e.g. \x0045 is equivalent +// to \x45, and \x1234 is erroneous). +// +// It also allows escape sequences of the form \uhhhh (exactly four +// hex digits, upper or lower case) or \Uhhhhhhhh (exactly eight +// hex digits, upper or lower case) to specify a Unicode code +// point. The dest array will contain the UTF8-encoded version of +// that code-point (e.g., if source contains \u2019, then dest will +// contain the three bytes 0xE2, 0x80, and 0x99). +// +// Errors: In the first form of the call, errors are reported with +// LOG(ERROR). The same is true for the second form of the call if +// the pointer to the string vector is NULL; otherwise, error +// messages are stored in the vector. In either case, the effect on +// the dest array is not defined, but rest of the source will be +// processed. +// ---------------------------------------------------------------------- + +LIBPROTOBUF_EXPORT int UnescapeCEscapeSequences(const char* source, char* dest); +LIBPROTOBUF_EXPORT int UnescapeCEscapeSequences(const char* source, char* dest, + vector *errors); + +// ---------------------------------------------------------------------- +// UnescapeCEscapeString() +// This does the same thing as UnescapeCEscapeSequences, but creates +// a new string. The caller does not need to worry about allocating +// a dest buffer. This should be used for non performance critical +// tasks such as printing debug messages. It is safe for src and dest +// to be the same. +// +// The second call stores its errors in a supplied string vector. +// If the string vector pointer is NULL, it reports the errors with LOG(). +// +// In the first and second calls, the length of dest is returned. In the +// the third call, the new string is returned. +// ---------------------------------------------------------------------- + +LIBPROTOBUF_EXPORT int UnescapeCEscapeString(const string& src, string* dest); +LIBPROTOBUF_EXPORT int UnescapeCEscapeString(const string& src, string* dest, + vector *errors); +LIBPROTOBUF_EXPORT string UnescapeCEscapeString(const string& src); + +// ---------------------------------------------------------------------- +// CEscapeString() +// Copies 'src' to 'dest', escaping dangerous characters using +// C-style escape sequences. This is very useful for preparing query +// flags. 'src' and 'dest' should not overlap. +// Returns the number of bytes written to 'dest' (not including the \0) +// or -1 if there was insufficient space. +// +// Currently only \n, \r, \t, ", ', \ and !isprint() chars are escaped. +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT int CEscapeString(const char* src, int src_len, + char* dest, int dest_len); + +// ---------------------------------------------------------------------- +// CEscape() +// More convenient form of CEscapeString: returns result as a "string". +// This version is slower than CEscapeString() because it does more +// allocation. However, it is much more convenient to use in +// non-speed-critical code like logging messages etc. +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT string CEscape(const string& src); + +namespace strings { +// Like CEscape() but does not escape bytes with the upper bit set. +LIBPROTOBUF_EXPORT string Utf8SafeCEscape(const string& src); + +// Like CEscape() but uses hex (\x) escapes instead of octals. +LIBPROTOBUF_EXPORT string CHexEscape(const string& src); +} // namespace strings + +// ---------------------------------------------------------------------- +// strto32() +// strtou32() +// strto64() +// strtou64() +// Architecture-neutral plug compatible replacements for strtol() and +// strtoul(). Long's have different lengths on ILP-32 and LP-64 +// platforms, so using these is safer, from the point of view of +// overflow behavior, than using the standard libc functions. +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT int32 strto32_adaptor(const char *nptr, char **endptr, + int base); +LIBPROTOBUF_EXPORT uint32 strtou32_adaptor(const char *nptr, char **endptr, + int base); + +inline int32 strto32(const char *nptr, char **endptr, int base) { + if (sizeof(int32) == sizeof(long)) + return strtol(nptr, endptr, base); + else + return strto32_adaptor(nptr, endptr, base); +} + +inline uint32 strtou32(const char *nptr, char **endptr, int base) { + if (sizeof(uint32) == sizeof(unsigned long)) + return strtoul(nptr, endptr, base); + else + return strtou32_adaptor(nptr, endptr, base); +} + +// For now, long long is 64-bit on all the platforms we care about, so these +// functions can simply pass the call to strto[u]ll. +inline int64 strto64(const char *nptr, char **endptr, int base) { + GOOGLE_COMPILE_ASSERT(sizeof(int64) == sizeof(long long), + sizeof_int64_is_not_sizeof_long_long); + return strtoll(nptr, endptr, base); +} + +inline uint64 strtou64(const char *nptr, char **endptr, int base) { + GOOGLE_COMPILE_ASSERT(sizeof(uint64) == sizeof(unsigned long long), + sizeof_uint64_is_not_sizeof_long_long); + return strtoull(nptr, endptr, base); +} + +// ---------------------------------------------------------------------- +// FastIntToBuffer() +// FastHexToBuffer() +// FastHex64ToBuffer() +// FastHex32ToBuffer() +// FastTimeToBuffer() +// These are intended for speed. FastIntToBuffer() assumes the +// integer is non-negative. FastHexToBuffer() puts output in +// hex rather than decimal. FastTimeToBuffer() puts the output +// into RFC822 format. +// +// FastHex64ToBuffer() puts a 64-bit unsigned value in hex-format, +// padded to exactly 16 bytes (plus one byte for '\0') +// +// FastHex32ToBuffer() puts a 32-bit unsigned value in hex-format, +// padded to exactly 8 bytes (plus one byte for '\0') +// +// All functions take the output buffer as an arg. +// They all return a pointer to the beginning of the output, +// which may not be the beginning of the input buffer. +// ---------------------------------------------------------------------- + +// Suggested buffer size for FastToBuffer functions. Also works with +// DoubleToBuffer() and FloatToBuffer(). +static const int kFastToBufferSize = 32; + +LIBPROTOBUF_EXPORT char* FastInt32ToBuffer(int32 i, char* buffer); +LIBPROTOBUF_EXPORT char* FastInt64ToBuffer(int64 i, char* buffer); +char* FastUInt32ToBuffer(uint32 i, char* buffer); // inline below +char* FastUInt64ToBuffer(uint64 i, char* buffer); // inline below +LIBPROTOBUF_EXPORT char* FastHexToBuffer(int i, char* buffer); +LIBPROTOBUF_EXPORT char* FastHex64ToBuffer(uint64 i, char* buffer); +LIBPROTOBUF_EXPORT char* FastHex32ToBuffer(uint32 i, char* buffer); + +// at least 22 bytes long +inline char* FastIntToBuffer(int i, char* buffer) { + return (sizeof(i) == 4 ? + FastInt32ToBuffer(i, buffer) : FastInt64ToBuffer(i, buffer)); +} +inline char* FastUIntToBuffer(unsigned int i, char* buffer) { + return (sizeof(i) == 4 ? + FastUInt32ToBuffer(i, buffer) : FastUInt64ToBuffer(i, buffer)); +} +inline char* FastLongToBuffer(long i, char* buffer) { + return (sizeof(i) == 4 ? + FastInt32ToBuffer(i, buffer) : FastInt64ToBuffer(i, buffer)); +} +inline char* FastULongToBuffer(unsigned long i, char* buffer) { + return (sizeof(i) == 4 ? + FastUInt32ToBuffer(i, buffer) : FastUInt64ToBuffer(i, buffer)); +} + +// ---------------------------------------------------------------------- +// FastInt32ToBufferLeft() +// FastUInt32ToBufferLeft() +// FastInt64ToBufferLeft() +// FastUInt64ToBufferLeft() +// +// Like the Fast*ToBuffer() functions above, these are intended for speed. +// Unlike the Fast*ToBuffer() functions, however, these functions write +// their output to the beginning of the buffer (hence the name, as the +// output is left-aligned). The caller is responsible for ensuring that +// the buffer has enough space to hold the output. +// +// Returns a pointer to the end of the string (i.e. the null character +// terminating the string). +// ---------------------------------------------------------------------- + +LIBPROTOBUF_EXPORT char* FastInt32ToBufferLeft(int32 i, char* buffer); +LIBPROTOBUF_EXPORT char* FastUInt32ToBufferLeft(uint32 i, char* buffer); +LIBPROTOBUF_EXPORT char* FastInt64ToBufferLeft(int64 i, char* buffer); +LIBPROTOBUF_EXPORT char* FastUInt64ToBufferLeft(uint64 i, char* buffer); + +// Just define these in terms of the above. +inline char* FastUInt32ToBuffer(uint32 i, char* buffer) { + FastUInt32ToBufferLeft(i, buffer); + return buffer; +} +inline char* FastUInt64ToBuffer(uint64 i, char* buffer) { + FastUInt64ToBufferLeft(i, buffer); + return buffer; +} + +// ---------------------------------------------------------------------- +// SimpleItoa() +// Description: converts an integer to a string. +// +// Return value: string +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT string SimpleItoa(int i); +LIBPROTOBUF_EXPORT string SimpleItoa(unsigned int i); +LIBPROTOBUF_EXPORT string SimpleItoa(long i); +LIBPROTOBUF_EXPORT string SimpleItoa(unsigned long i); +LIBPROTOBUF_EXPORT string SimpleItoa(long long i); +LIBPROTOBUF_EXPORT string SimpleItoa(unsigned long long i); + +// ---------------------------------------------------------------------- +// SimpleDtoa() +// SimpleFtoa() +// DoubleToBuffer() +// FloatToBuffer() +// Description: converts a double or float to a string which, if +// passed to NoLocaleStrtod(), will produce the exact same original double +// (except in case of NaN; all NaNs are considered the same value). +// We try to keep the string short but it's not guaranteed to be as +// short as possible. +// +// DoubleToBuffer() and FloatToBuffer() write the text to the given +// buffer and return it. The buffer must be at least +// kDoubleToBufferSize bytes for doubles and kFloatToBufferSize +// bytes for floats. kFastToBufferSize is also guaranteed to be large +// enough to hold either. +// +// Return value: string +// ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT string SimpleDtoa(double value); +LIBPROTOBUF_EXPORT string SimpleFtoa(float value); + +LIBPROTOBUF_EXPORT char* DoubleToBuffer(double i, char* buffer); +LIBPROTOBUF_EXPORT char* FloatToBuffer(float i, char* buffer); + +// In practice, doubles should never need more than 24 bytes and floats +// should never need more than 14 (including null terminators), but we +// overestimate to be safe. +static const int kDoubleToBufferSize = 32; +static const int kFloatToBufferSize = 24; + +// ---------------------------------------------------------------------- +// NoLocaleStrtod() +// Exactly like strtod(), except it always behaves as if in the "C" +// locale (i.e. decimal points must be '.'s). +// ---------------------------------------------------------------------- + +LIBPROTOBUF_EXPORT double NoLocaleStrtod(const char* text, char** endptr); + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ + + diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h new file mode 100644 index 00000000..2581793b --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h @@ -0,0 +1,170 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// from google3/strings/substitute.h + +#include +#include +#include + +#ifndef GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ +#define GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ + +namespace google { +namespace protobuf { +namespace strings { + +// ---------------------------------------------------------------------- +// strings::Substitute() +// strings::SubstituteAndAppend() +// Kind of like StringPrintf, but different. +// +// Example: +// string GetMessage(string first_name, string last_name, int age) { +// return strings::Substitute("My name is $0 $1 and I am $2 years old.", +// first_name, last_name, age); +// } +// +// Differences from StringPrintf: +// * The format string does not identify the types of arguments. +// Instead, the magic of C++ deals with this for us. See below +// for a list of accepted types. +// * Substitutions in the format string are identified by a '$' +// followed by a digit. So, you can use arguments out-of-order and +// use the same argument multiple times. +// * It's much faster than StringPrintf. +// +// Supported types: +// * Strings (const char*, const string&) +// * Note that this means you do not have to add .c_str() to all of +// your strings. In fact, you shouldn't; it will be slower. +// * int32, int64, uint32, uint64: Formatted using SimpleItoa(). +// * float, double: Formatted using SimpleFtoa() and SimpleDtoa(). +// * bool: Printed as "true" or "false". +// +// SubstituteAndAppend() is like Substitute() but appends the result to +// *output. Example: +// +// string str; +// strings::SubstituteAndAppend(&str, +// "My name is $0 $1 and I am $2 years old.", +// first_name, last_name, age); +// +// Substitute() is significantly faster than StringPrintf(). For very +// large strings, it may be orders of magnitude faster. +// ---------------------------------------------------------------------- + +namespace internal { // Implementation details. + +class SubstituteArg { + public: + inline SubstituteArg(const char* value) + : text_(value), size_(strlen(text_)) {} + inline SubstituteArg(const string& value) + : text_(value.data()), size_(value.size()) {} + + // Indicates that no argument was given. + inline explicit SubstituteArg() + : text_(NULL), size_(-1) {} + + // Primitives + // We don't overload for signed and unsigned char because if people are + // explicitly declaring their chars as signed or unsigned then they are + // probably actually using them as 8-bit integers and would probably + // prefer an integer representation. But, we don't really know. So, we + // make the caller decide what to do. + inline SubstituteArg(char value) + : text_(scratch_), size_(1) { scratch_[0] = value; } + inline SubstituteArg(short value) + : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned short value) + : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(int value) + : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned int value) + : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(long value) + : text_(FastLongToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned long value) + : text_(FastULongToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(long long value) + : text_(FastInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned long long value) + : text_(FastUInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(float value) + : text_(FloatToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(double value) + : text_(DoubleToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(bool value) + : text_(value ? "true" : "false"), size_(strlen(text_)) {} + + inline const char* data() const { return text_; } + inline int size() const { return size_; } + + private: + const char* text_; + int size_; + char scratch_[kFastToBufferSize]; +}; + +} // namespace internal + +LIBPROTOBUF_EXPORT string Substitute( + const char* format, + const internal::SubstituteArg& arg0 = internal::SubstituteArg(), + const internal::SubstituteArg& arg1 = internal::SubstituteArg(), + const internal::SubstituteArg& arg2 = internal::SubstituteArg(), + const internal::SubstituteArg& arg3 = internal::SubstituteArg(), + const internal::SubstituteArg& arg4 = internal::SubstituteArg(), + const internal::SubstituteArg& arg5 = internal::SubstituteArg(), + const internal::SubstituteArg& arg6 = internal::SubstituteArg(), + const internal::SubstituteArg& arg7 = internal::SubstituteArg(), + const internal::SubstituteArg& arg8 = internal::SubstituteArg(), + const internal::SubstituteArg& arg9 = internal::SubstituteArg()); + +LIBPROTOBUF_EXPORT void SubstituteAndAppend( + string* output, const char* format, + const internal::SubstituteArg& arg0 = internal::SubstituteArg(), + const internal::SubstituteArg& arg1 = internal::SubstituteArg(), + const internal::SubstituteArg& arg2 = internal::SubstituteArg(), + const internal::SubstituteArg& arg3 = internal::SubstituteArg(), + const internal::SubstituteArg& arg4 = internal::SubstituteArg(), + const internal::SubstituteArg& arg5 = internal::SubstituteArg(), + const internal::SubstituteArg& arg6 = internal::SubstituteArg(), + const internal::SubstituteArg& arg7 = internal::SubstituteArg(), + const internal::SubstituteArg& arg8 = internal::SubstituteArg(), + const internal::SubstituteArg& arg9 = internal::SubstituteArg()); + +} // namespace strings +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/test_util.h b/ext/protobuf-2.4.1/src/google/protobuf/test_util.h new file mode 100644 index 00000000..25165f3a --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/test_util.h @@ -0,0 +1,174 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_TEST_UTIL_H__ +#define GOOGLE_PROTOBUF_TEST_UTIL_H__ + +#include +#include +#include +#include + +namespace google { +namespace protobuf { + +namespace unittest = protobuf_unittest; +namespace unittest_import = protobuf_unittest_import; + +class TestUtil { + public: + // Set every field in the message to a unique value. + static void SetAllFields(unittest::TestAllTypes* message); + static void SetAllExtensions(unittest::TestAllExtensions* message); + static void SetAllFieldsAndExtensions(unittest::TestFieldOrderings* message); + static void SetPackedFields(unittest::TestPackedTypes* message); + static void SetPackedExtensions(unittest::TestPackedExtensions* message); + static void SetUnpackedFields(unittest::TestUnpackedTypes* message); + + // Use the repeated versions of the set_*() accessors to modify all the + // repeated fields of the messsage (which should already have been + // initialized with Set*Fields()). Set*Fields() itself only tests + // the add_*() accessors. + static void ModifyRepeatedFields(unittest::TestAllTypes* message); + static void ModifyRepeatedExtensions(unittest::TestAllExtensions* message); + static void ModifyPackedFields(unittest::TestPackedTypes* message); + static void ModifyPackedExtensions(unittest::TestPackedExtensions* message); + + // Check that all fields have the values that they should have after + // Set*Fields() is called. + static void ExpectAllFieldsSet(const unittest::TestAllTypes& message); + static void ExpectAllExtensionsSet( + const unittest::TestAllExtensions& message); + static void ExpectPackedFieldsSet(const unittest::TestPackedTypes& message); + static void ExpectPackedExtensionsSet( + const unittest::TestPackedExtensions& message); + static void ExpectUnpackedFieldsSet( + const unittest::TestUnpackedTypes& message); + + // Expect that the message is modified as would be expected from + // Modify*Fields(). + static void ExpectRepeatedFieldsModified( + const unittest::TestAllTypes& message); + static void ExpectRepeatedExtensionsModified( + const unittest::TestAllExtensions& message); + static void ExpectPackedFieldsModified( + const unittest::TestPackedTypes& message); + static void ExpectPackedExtensionsModified( + const unittest::TestPackedExtensions& message); + + // Check that all fields have their default values. + static void ExpectClear(const unittest::TestAllTypes& message); + static void ExpectExtensionsClear(const unittest::TestAllExtensions& message); + static void ExpectPackedClear(const unittest::TestPackedTypes& message); + static void ExpectPackedExtensionsClear( + const unittest::TestPackedExtensions& message); + + // Check that the passed-in serialization is the canonical serialization we + // expect for a TestFieldOrderings message filled in by + // SetAllFieldsAndExtensions(). + static void ExpectAllFieldsAndExtensionsInOrder(const string& serialized); + + // Check that all repeated fields have had their last elements removed. + static void ExpectLastRepeatedsRemoved( + const unittest::TestAllTypes& message); + static void ExpectLastRepeatedExtensionsRemoved( + const unittest::TestAllExtensions& message); + + // Check that all repeated fields have had their first and last elements + // swapped. + static void ExpectRepeatedsSwapped(const unittest::TestAllTypes& message); + static void ExpectRepeatedExtensionsSwapped( + const unittest::TestAllExtensions& message); + + // Like above, but use the reflection interface. + class ReflectionTester { + public: + // base_descriptor must be a descriptor for TestAllTypes or + // TestAllExtensions. In the former case, ReflectionTester fetches from + // it the FieldDescriptors needed to use the reflection interface. In + // the latter case, ReflectionTester searches for extension fields in + // its file. + explicit ReflectionTester(const Descriptor* base_descriptor); + + void SetAllFieldsViaReflection(Message* message); + void ModifyRepeatedFieldsViaReflection(Message* message); + void ExpectAllFieldsSetViaReflection(const Message& message); + void ExpectClearViaReflection(const Message& message); + + void SetPackedFieldsViaReflection(Message* message); + void ModifyPackedFieldsViaReflection(Message* message); + void ExpectPackedFieldsSetViaReflection(const Message& message); + void ExpectPackedClearViaReflection(const Message& message); + + void RemoveLastRepeatedsViaReflection(Message* message); + void SwapRepeatedsViaReflection(Message* message); + + private: + const FieldDescriptor* F(const string& name); + + const Descriptor* base_descriptor_; + + const FieldDescriptor* group_a_; + const FieldDescriptor* repeated_group_a_; + const FieldDescriptor* nested_b_; + const FieldDescriptor* foreign_c_; + const FieldDescriptor* import_d_; + + const EnumValueDescriptor* nested_foo_; + const EnumValueDescriptor* nested_bar_; + const EnumValueDescriptor* nested_baz_; + const EnumValueDescriptor* foreign_foo_; + const EnumValueDescriptor* foreign_bar_; + const EnumValueDescriptor* foreign_baz_; + const EnumValueDescriptor* import_foo_; + const EnumValueDescriptor* import_bar_; + const EnumValueDescriptor* import_baz_; + + // We have to split this into three function otherwise it creates a stack + // frame so large that it triggers a warning. + void ExpectAllFieldsSetViaReflection1(const Message& message); + void ExpectAllFieldsSetViaReflection2(const Message& message); + void ExpectAllFieldsSetViaReflection3(const Message& message); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionTester); + }; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestUtil); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_TEST_UTIL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h new file mode 100644 index 00000000..ca35aaa4 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h @@ -0,0 +1,101 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ +#define GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ + +#include + +namespace google { +namespace protobuf { + +namespace unittest = protobuf_unittest; +namespace unittest_import = protobuf_unittest_import; + +class TestUtilLite { + public: + // Set every field in the message to a unique value. + static void SetAllFields(unittest::TestAllTypesLite* message); + static void SetAllExtensions(unittest::TestAllExtensionsLite* message); + static void SetPackedFields(unittest::TestPackedTypesLite* message); + static void SetPackedExtensions(unittest::TestPackedExtensionsLite* message); + + // Use the repeated versions of the set_*() accessors to modify all the + // repeated fields of the messsage (which should already have been + // initialized with Set*Fields()). Set*Fields() itself only tests + // the add_*() accessors. + static void ModifyRepeatedFields(unittest::TestAllTypesLite* message); + static void ModifyRepeatedExtensions( + unittest::TestAllExtensionsLite* message); + static void ModifyPackedFields(unittest::TestPackedTypesLite* message); + static void ModifyPackedExtensions( + unittest::TestPackedExtensionsLite* message); + + // Check that all fields have the values that they should have after + // Set*Fields() is called. + static void ExpectAllFieldsSet(const unittest::TestAllTypesLite& message); + static void ExpectAllExtensionsSet( + const unittest::TestAllExtensionsLite& message); + static void ExpectPackedFieldsSet( + const unittest::TestPackedTypesLite& message); + static void ExpectPackedExtensionsSet( + const unittest::TestPackedExtensionsLite& message); + + // Expect that the message is modified as would be expected from + // Modify*Fields(). + static void ExpectRepeatedFieldsModified( + const unittest::TestAllTypesLite& message); + static void ExpectRepeatedExtensionsModified( + const unittest::TestAllExtensionsLite& message); + static void ExpectPackedFieldsModified( + const unittest::TestPackedTypesLite& message); + static void ExpectPackedExtensionsModified( + const unittest::TestPackedExtensionsLite& message); + + // Check that all fields have their default values. + static void ExpectClear(const unittest::TestAllTypesLite& message); + static void ExpectExtensionsClear( + const unittest::TestAllExtensionsLite& message); + static void ExpectPackedClear(const unittest::TestPackedTypesLite& message); + static void ExpectPackedExtensionsClear( + const unittest::TestPackedExtensionsLite& message); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestUtilLite); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h b/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h new file mode 100644 index 00000000..a6b1c764 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h @@ -0,0 +1,83 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// emulates google3/file/base/file.h + +#ifndef GOOGLE_PROTOBUF_TESTING_FILE_H__ +#define GOOGLE_PROTOBUF_TESTING_FILE_H__ + +#include + +namespace google { +namespace protobuf { + +const int DEFAULT_FILE_MODE = 0777; + +// Protocol buffer code only uses a couple static methods of File, and only +// in tests. +class File { + public: + // Check if the file exists. + static bool Exists(const string& name); + + // Read an entire file to a string. Return true if successful, false + // otherwise. + static bool ReadFileToString(const string& name, string* output); + + // Same as above, but crash on failure. + static void ReadFileToStringOrDie(const string& name, string* output); + + // Create a file and write a string to it. + static void WriteStringToFileOrDie(const string& contents, + const string& name); + + // Create a directory. + static bool CreateDir(const string& name, int mode); + + // Create a directory and all parent directories if necessary. + static bool RecursivelyCreateDir(const string& path, int mode); + + // If "name" is a file, we delete it. If it is a directory, we + // call DeleteRecursively() for each file or directory (other than + // dot and double-dot) within it, and then delete the directory itself. + // The "dummy" parameters have a meaning in the original version of this + // method but they are not used anywhere in protocol buffers. + static void DeleteRecursively(const string& name, + void* dummy1, void* dummy2); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(File); +}; + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_TESTING_FILE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h b/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h new file mode 100644 index 00000000..71444c96 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h @@ -0,0 +1,98 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// emulates google3/testing/base/public/googletest.h + +#ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__ +#define GOOGLE_PROTOBUF_GOOGLETEST_H__ + +#include +#include + +namespace google { +namespace protobuf { + +// When running unittests, get the directory containing the source code. +string TestSourceDir(); + +// When running unittests, get a directory where temporary files may be +// placed. +string TestTempDir(); + +// Capture all text written to stdout or stderr. +void CaptureTestStdout(); +void CaptureTestStderr(); + +// Stop capturing stdout or stderr and return the text captured. +string GetCapturedTestStdout(); +string GetCapturedTestStderr(); + +// For use with ScopedMemoryLog::GetMessages(). Inside Google the LogLevel +// constants don't have the LOGLEVEL_ prefix, so the code that used +// ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR. +#undef ERROR // defend against promiscuous windows.h +static const LogLevel ERROR = LOGLEVEL_ERROR; + +// Receives copies of all LOG(ERROR) messages while in scope. Sample usage: +// { +// ScopedMemoryLog log; // constructor registers object as a log sink +// SomeRoutineThatMayLogMessages(); +// const vector& warnings = log.GetMessages(ERROR); +// } // destructor unregisters object as a log sink +// This is a dummy implementation which covers only what is used by protocol +// buffer unit tests. +class ScopedMemoryLog { + public: + ScopedMemoryLog(); + virtual ~ScopedMemoryLog(); + + // Fetches all messages logged. The internal version of this class + // would only fetch messages at the given security level, but the protobuf + // open source version ignores the argument since we always pass ERROR + // anyway. + const vector& GetMessages(LogLevel dummy) const; + + private: + vector messages_; + LogHandler* old_handler_; + + static void HandleLog(LogLevel level, const char* filename, int line, + const string& message); + + static ScopedMemoryLog* active_log_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog); +}; + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_GOOGLETEST_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/text_format.h b/ext/protobuf-2.4.1/src/google/protobuf/text_format.h new file mode 100644 index 00000000..03c04910 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/text_format.h @@ -0,0 +1,285 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: jschorr@google.com (Joseph Schorr) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Utilities for printing and parsing protocol messages in a human-readable, +// text-based format. + +#ifndef GOOGLE_PROTOBUF_TEXT_FORMAT_H__ +#define GOOGLE_PROTOBUF_TEXT_FORMAT_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + +namespace io { + class ErrorCollector; // tokenizer.h +} + +// This class implements protocol buffer text format. Printing and parsing +// protocol messages in text format is useful for debugging and human editing +// of messages. +// +// This class is really a namespace that contains only static methods. +class LIBPROTOBUF_EXPORT TextFormat { + public: + // Outputs a textual representation of the given message to the given + // output stream. + static bool Print(const Message& message, io::ZeroCopyOutputStream* output); + + // Print the fields in an UnknownFieldSet. They are printed by tag number + // only. Embedded messages are heuristically identified by attempting to + // parse them. + static bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, + io::ZeroCopyOutputStream* output); + + // Like Print(), but outputs directly to a string. + static bool PrintToString(const Message& message, string* output); + + // Like PrintUnknownFields(), but outputs directly to a string. + static bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, + string* output); + + // Outputs a textual representation of the value of the field supplied on + // the message supplied. For non-repeated fields, an index of -1 must + // be supplied. Note that this method will print the default value for a + // field if it is not set. + static void PrintFieldValueToString(const Message& message, + const FieldDescriptor* field, + int index, + string* output); + + // Class for those users which require more fine-grained control over how + // a protobuffer message is printed out. + class LIBPROTOBUF_EXPORT Printer { + public: + Printer(); + ~Printer(); + + // Like TextFormat::Print + bool Print(const Message& message, io::ZeroCopyOutputStream* output) const; + // Like TextFormat::PrintUnknownFields + bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, + io::ZeroCopyOutputStream* output) const; + // Like TextFormat::PrintToString + bool PrintToString(const Message& message, string* output) const; + // Like TextFormat::PrintUnknownFieldsToString + bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, + string* output) const; + // Like TextFormat::PrintFieldValueToString + void PrintFieldValueToString(const Message& message, + const FieldDescriptor* field, + int index, + string* output) const; + + // Adjust the initial indent level of all output. Each indent level is + // equal to two spaces. + void SetInitialIndentLevel(int indent_level) { + initial_indent_level_ = indent_level; + } + + // If printing in single line mode, then the entire message will be output + // on a single line with no line breaks. + void SetSingleLineMode(bool single_line_mode) { + single_line_mode_ = single_line_mode; + } + + // Set true to print repeated primitives in a format like: + // field_name: [1, 2, 3, 4] + // instead of printing each value on its own line. Short format applies + // only to primitive values -- i.e. everything except strings and + // sub-messages/groups. + void SetUseShortRepeatedPrimitives(bool use_short_repeated_primitives) { + use_short_repeated_primitives_ = use_short_repeated_primitives; + } + + // Set true to output UTF-8 instead of ASCII. The only difference + // is that bytes >= 0x80 in string fields will not be escaped, + // because they are assumed to be part of UTF-8 multi-byte + // sequences. + void SetUseUtf8StringEscaping(bool as_utf8) { + utf8_string_escaping_ = as_utf8; + } + + private: + // Forward declaration of an internal class used to print the text + // output to the OutputStream (see text_format.cc for implementation). + class TextGenerator; + + // Internal Print method, used for writing to the OutputStream via + // the TextGenerator class. + void Print(const Message& message, + TextGenerator& generator) const; + + // Print a single field. + void PrintField(const Message& message, + const Reflection* reflection, + const FieldDescriptor* field, + TextGenerator& generator) const; + + // Print a repeated primitive field in short form. + void PrintShortRepeatedField(const Message& message, + const Reflection* reflection, + const FieldDescriptor* field, + TextGenerator& generator) const; + + // Print the name of a field -- i.e. everything that comes before the + // ':' for a single name/value pair. + void PrintFieldName(const Message& message, + const Reflection* reflection, + const FieldDescriptor* field, + TextGenerator& generator) const; + + // Outputs a textual representation of the value of the field supplied on + // the message supplied or the default value if not set. + void PrintFieldValue(const Message& message, + const Reflection* reflection, + const FieldDescriptor* field, + int index, + TextGenerator& generator) const; + + // Print the fields in an UnknownFieldSet. They are printed by tag number + // only. Embedded messages are heuristically identified by attempting to + // parse them. + void PrintUnknownFields(const UnknownFieldSet& unknown_fields, + TextGenerator& generator) const; + + int initial_indent_level_; + + bool single_line_mode_; + + bool use_short_repeated_primitives_; + + bool utf8_string_escaping_; + }; + + // Parses a text-format protocol message from the given input stream to + // the given message object. This function parses the format written + // by Print(). + static bool Parse(io::ZeroCopyInputStream* input, Message* output); + // Like Parse(), but reads directly from a string. + static bool ParseFromString(const string& input, Message* output); + + // Like Parse(), but the data is merged into the given message, as if + // using Message::MergeFrom(). + static bool Merge(io::ZeroCopyInputStream* input, Message* output); + // Like Merge(), but reads directly from a string. + static bool MergeFromString(const string& input, Message* output); + + // Parse the given text as a single field value and store it into the + // given field of the given message. If the field is a repeated field, + // the new value will be added to the end + static bool ParseFieldValueFromString(const string& input, + const FieldDescriptor* field, + Message* message); + + // Interface that TextFormat::Parser can use to find extensions. + // This class may be extended in the future to find more information + // like fields, etc. + class LIBPROTOBUF_EXPORT Finder { + public: + virtual ~Finder(); + + // Try to find an extension of *message by fully-qualified field + // name. Returns NULL if no extension is known for this name or number. + virtual const FieldDescriptor* FindExtension( + Message* message, + const string& name) const = 0; + }; + + // For more control over parsing, use this class. + class LIBPROTOBUF_EXPORT Parser { + public: + Parser(); + ~Parser(); + + // Like TextFormat::Parse(). + bool Parse(io::ZeroCopyInputStream* input, Message* output); + // Like TextFormat::ParseFromString(). + bool ParseFromString(const string& input, Message* output); + // Like TextFormat::Merge(). + bool Merge(io::ZeroCopyInputStream* input, Message* output); + // Like TextFormat::MergeFromString(). + bool MergeFromString(const string& input, Message* output); + + // Set where to report parse errors. If NULL (the default), errors will + // be printed to stderr. + void RecordErrorsTo(io::ErrorCollector* error_collector) { + error_collector_ = error_collector; + } + + // Set how parser finds extensions. If NULL (the default), the + // parser will use the standard Reflection object associated with + // the message being parsed. + void SetFinder(Finder* finder) { + finder_ = finder; + } + + // Normally parsing fails if, after parsing, output->IsInitialized() + // returns false. Call AllowPartialMessage(true) to skip this check. + void AllowPartialMessage(bool allow) { + allow_partial_ = allow; + } + + // Like TextFormat::ParseFieldValueFromString + bool ParseFieldValueFromString(const string& input, + const FieldDescriptor* field, + Message* output); + + private: + // Forward declaration of an internal class used to parse text + // representations (see text_format.cc for implementation). + class ParserImpl; + + // Like TextFormat::Merge(). The provided implementation is used + // to do the parsing. + bool MergeUsingImpl(io::ZeroCopyInputStream* input, + Message* output, + ParserImpl* parser_impl); + + io::ErrorCollector* error_collector_; + Finder* finder_; + bool allow_partial_; + }; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormat); +}; + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h new file mode 100644 index 00000000..e294cf39 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h @@ -0,0 +1,11915 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +#include +#include "google/protobuf/unittest_import.pb.h" +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + +class TestAllTypes; +class TestAllTypes_NestedMessage; +class TestAllTypes_OptionalGroup; +class TestAllTypes_RepeatedGroup; +class TestDeprecatedFields; +class ForeignMessage; +class TestAllExtensions; +class OptionalGroup_extension; +class RepeatedGroup_extension; +class TestNestedExtension; +class TestRequired; +class TestRequiredForeign; +class TestForeignNested; +class TestEmptyMessage; +class TestEmptyMessageWithExtensions; +class TestMultipleExtensionRanges; +class TestReallyLargeTagNumber; +class TestRecursiveMessage; +class TestMutualRecursionA; +class TestMutualRecursionB; +class TestDupFieldNumber; +class TestDupFieldNumber_Foo; +class TestDupFieldNumber_Bar; +class TestNestedMessageHasBits; +class TestNestedMessageHasBits_NestedMessage; +class TestCamelCaseFieldNames; +class TestFieldOrderings; +class TestExtremeDefaultValues; +class SparseEnumMessage; +class OneString; +class OneBytes; +class TestPackedTypes; +class TestUnpackedTypes; +class TestPackedExtensions; +class TestDynamicExtensions; +class TestDynamicExtensions_DynamicMessageType; +class TestRepeatedScalarDifferentTagSizes; +class FooRequest; +class FooResponse; +class BarRequest; +class BarResponse; + +enum TestAllTypes_NestedEnum { + TestAllTypes_NestedEnum_FOO = 1, + TestAllTypes_NestedEnum_BAR = 2, + TestAllTypes_NestedEnum_BAZ = 3 +}; +bool TestAllTypes_NestedEnum_IsValid(int value); +const TestAllTypes_NestedEnum TestAllTypes_NestedEnum_NestedEnum_MIN = TestAllTypes_NestedEnum_FOO; +const TestAllTypes_NestedEnum TestAllTypes_NestedEnum_NestedEnum_MAX = TestAllTypes_NestedEnum_BAZ; +const int TestAllTypes_NestedEnum_NestedEnum_ARRAYSIZE = TestAllTypes_NestedEnum_NestedEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* TestAllTypes_NestedEnum_descriptor(); +inline const ::std::string& TestAllTypes_NestedEnum_Name(TestAllTypes_NestedEnum value) { + return ::google::protobuf::internal::NameOfEnum( + TestAllTypes_NestedEnum_descriptor(), value); +} +inline bool TestAllTypes_NestedEnum_Parse( + const ::std::string& name, TestAllTypes_NestedEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + TestAllTypes_NestedEnum_descriptor(), name, value); +} +enum TestDynamicExtensions_DynamicEnumType { + TestDynamicExtensions_DynamicEnumType_DYNAMIC_FOO = 2200, + TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAR = 2201, + TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAZ = 2202 +}; +bool TestDynamicExtensions_DynamicEnumType_IsValid(int value); +const TestDynamicExtensions_DynamicEnumType TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MIN = TestDynamicExtensions_DynamicEnumType_DYNAMIC_FOO; +const TestDynamicExtensions_DynamicEnumType TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MAX = TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAZ; +const int TestDynamicExtensions_DynamicEnumType_DynamicEnumType_ARRAYSIZE = TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MAX + 1; + +const ::google::protobuf::EnumDescriptor* TestDynamicExtensions_DynamicEnumType_descriptor(); +inline const ::std::string& TestDynamicExtensions_DynamicEnumType_Name(TestDynamicExtensions_DynamicEnumType value) { + return ::google::protobuf::internal::NameOfEnum( + TestDynamicExtensions_DynamicEnumType_descriptor(), value); +} +inline bool TestDynamicExtensions_DynamicEnumType_Parse( + const ::std::string& name, TestDynamicExtensions_DynamicEnumType* value) { + return ::google::protobuf::internal::ParseNamedEnum( + TestDynamicExtensions_DynamicEnumType_descriptor(), name, value); +} +enum ForeignEnum { + FOREIGN_FOO = 4, + FOREIGN_BAR = 5, + FOREIGN_BAZ = 6 +}; +bool ForeignEnum_IsValid(int value); +const ForeignEnum ForeignEnum_MIN = FOREIGN_FOO; +const ForeignEnum ForeignEnum_MAX = FOREIGN_BAZ; +const int ForeignEnum_ARRAYSIZE = ForeignEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* ForeignEnum_descriptor(); +inline const ::std::string& ForeignEnum_Name(ForeignEnum value) { + return ::google::protobuf::internal::NameOfEnum( + ForeignEnum_descriptor(), value); +} +inline bool ForeignEnum_Parse( + const ::std::string& name, ForeignEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + ForeignEnum_descriptor(), name, value); +} +enum TestEnumWithDupValue { + FOO1 = 1, + BAR1 = 2, + BAZ = 3, + FOO2 = 1, + BAR2 = 2 +}; +bool TestEnumWithDupValue_IsValid(int value); +const TestEnumWithDupValue TestEnumWithDupValue_MIN = FOO1; +const TestEnumWithDupValue TestEnumWithDupValue_MAX = BAZ; +const int TestEnumWithDupValue_ARRAYSIZE = TestEnumWithDupValue_MAX + 1; + +const ::google::protobuf::EnumDescriptor* TestEnumWithDupValue_descriptor(); +inline const ::std::string& TestEnumWithDupValue_Name(TestEnumWithDupValue value) { + return ::google::protobuf::internal::NameOfEnum( + TestEnumWithDupValue_descriptor(), value); +} +inline bool TestEnumWithDupValue_Parse( + const ::std::string& name, TestEnumWithDupValue* value) { + return ::google::protobuf::internal::ParseNamedEnum( + TestEnumWithDupValue_descriptor(), name, value); +} +enum TestSparseEnum { + SPARSE_A = 123, + SPARSE_B = 62374, + SPARSE_C = 12589234, + SPARSE_D = -15, + SPARSE_E = -53452, + SPARSE_F = 0, + SPARSE_G = 2 +}; +bool TestSparseEnum_IsValid(int value); +const TestSparseEnum TestSparseEnum_MIN = SPARSE_E; +const TestSparseEnum TestSparseEnum_MAX = SPARSE_C; +const int TestSparseEnum_ARRAYSIZE = TestSparseEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* TestSparseEnum_descriptor(); +inline const ::std::string& TestSparseEnum_Name(TestSparseEnum value) { + return ::google::protobuf::internal::NameOfEnum( + TestSparseEnum_descriptor(), value); +} +inline bool TestSparseEnum_Parse( + const ::std::string& name, TestSparseEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + TestSparseEnum_descriptor(), name, value); +} +// =================================================================== + +class TestAllTypes_NestedMessage : public ::google::protobuf::Message { + public: + TestAllTypes_NestedMessage(); + virtual ~TestAllTypes_NestedMessage(); + + TestAllTypes_NestedMessage(const TestAllTypes_NestedMessage& from); + + inline TestAllTypes_NestedMessage& operator=(const TestAllTypes_NestedMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestAllTypes_NestedMessage& default_instance(); + + void Swap(TestAllTypes_NestedMessage* other); + + // implements Message ---------------------------------------------- + + TestAllTypes_NestedMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestAllTypes_NestedMessage& from); + void MergeFrom(const TestAllTypes_NestedMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 bb = 1; + inline bool has_bb() const; + inline void clear_bb(); + static const int kBbFieldNumber = 1; + inline ::google::protobuf::int32 bb() const; + inline void set_bb(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes.NestedMessage) + private: + inline void set_has_bb(); + inline void clear_has_bb(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 bb_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypes_NestedMessage* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllTypes_OptionalGroup : public ::google::protobuf::Message { + public: + TestAllTypes_OptionalGroup(); + virtual ~TestAllTypes_OptionalGroup(); + + TestAllTypes_OptionalGroup(const TestAllTypes_OptionalGroup& from); + + inline TestAllTypes_OptionalGroup& operator=(const TestAllTypes_OptionalGroup& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestAllTypes_OptionalGroup& default_instance(); + + void Swap(TestAllTypes_OptionalGroup* other); + + // implements Message ---------------------------------------------- + + TestAllTypes_OptionalGroup* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestAllTypes_OptionalGroup& from); + void MergeFrom(const TestAllTypes_OptionalGroup& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 17; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 17; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes.OptionalGroup) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypes_OptionalGroup* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllTypes_RepeatedGroup : public ::google::protobuf::Message { + public: + TestAllTypes_RepeatedGroup(); + virtual ~TestAllTypes_RepeatedGroup(); + + TestAllTypes_RepeatedGroup(const TestAllTypes_RepeatedGroup& from); + + inline TestAllTypes_RepeatedGroup& operator=(const TestAllTypes_RepeatedGroup& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestAllTypes_RepeatedGroup& default_instance(); + + void Swap(TestAllTypes_RepeatedGroup* other); + + // implements Message ---------------------------------------------- + + TestAllTypes_RepeatedGroup* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestAllTypes_RepeatedGroup& from); + void MergeFrom(const TestAllTypes_RepeatedGroup& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 47; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 47; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes.RepeatedGroup) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypes_RepeatedGroup* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllTypes : public ::google::protobuf::Message { + public: + TestAllTypes(); + virtual ~TestAllTypes(); + + TestAllTypes(const TestAllTypes& from); + + inline TestAllTypes& operator=(const TestAllTypes& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestAllTypes& default_instance(); + + void Swap(TestAllTypes* other); + + // implements Message ---------------------------------------------- + + TestAllTypes* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestAllTypes& from); + void MergeFrom(const TestAllTypes& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef TestAllTypes_NestedMessage NestedMessage; + typedef TestAllTypes_OptionalGroup OptionalGroup; + typedef TestAllTypes_RepeatedGroup RepeatedGroup; + + typedef TestAllTypes_NestedEnum NestedEnum; + static const NestedEnum FOO = TestAllTypes_NestedEnum_FOO; + static const NestedEnum BAR = TestAllTypes_NestedEnum_BAR; + static const NestedEnum BAZ = TestAllTypes_NestedEnum_BAZ; + static inline bool NestedEnum_IsValid(int value) { + return TestAllTypes_NestedEnum_IsValid(value); + } + static const NestedEnum NestedEnum_MIN = + TestAllTypes_NestedEnum_NestedEnum_MIN; + static const NestedEnum NestedEnum_MAX = + TestAllTypes_NestedEnum_NestedEnum_MAX; + static const int NestedEnum_ARRAYSIZE = + TestAllTypes_NestedEnum_NestedEnum_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + NestedEnum_descriptor() { + return TestAllTypes_NestedEnum_descriptor(); + } + static inline const ::std::string& NestedEnum_Name(NestedEnum value) { + return TestAllTypes_NestedEnum_Name(value); + } + static inline bool NestedEnum_Parse(const ::std::string& name, + NestedEnum* value) { + return TestAllTypes_NestedEnum_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // optional int32 optional_int32 = 1; + inline bool has_optional_int32() const; + inline void clear_optional_int32(); + static const int kOptionalInt32FieldNumber = 1; + inline ::google::protobuf::int32 optional_int32() const; + inline void set_optional_int32(::google::protobuf::int32 value); + + // optional int64 optional_int64 = 2; + inline bool has_optional_int64() const; + inline void clear_optional_int64(); + static const int kOptionalInt64FieldNumber = 2; + inline ::google::protobuf::int64 optional_int64() const; + inline void set_optional_int64(::google::protobuf::int64 value); + + // optional uint32 optional_uint32 = 3; + inline bool has_optional_uint32() const; + inline void clear_optional_uint32(); + static const int kOptionalUint32FieldNumber = 3; + inline ::google::protobuf::uint32 optional_uint32() const; + inline void set_optional_uint32(::google::protobuf::uint32 value); + + // optional uint64 optional_uint64 = 4; + inline bool has_optional_uint64() const; + inline void clear_optional_uint64(); + static const int kOptionalUint64FieldNumber = 4; + inline ::google::protobuf::uint64 optional_uint64() const; + inline void set_optional_uint64(::google::protobuf::uint64 value); + + // optional sint32 optional_sint32 = 5; + inline bool has_optional_sint32() const; + inline void clear_optional_sint32(); + static const int kOptionalSint32FieldNumber = 5; + inline ::google::protobuf::int32 optional_sint32() const; + inline void set_optional_sint32(::google::protobuf::int32 value); + + // optional sint64 optional_sint64 = 6; + inline bool has_optional_sint64() const; + inline void clear_optional_sint64(); + static const int kOptionalSint64FieldNumber = 6; + inline ::google::protobuf::int64 optional_sint64() const; + inline void set_optional_sint64(::google::protobuf::int64 value); + + // optional fixed32 optional_fixed32 = 7; + inline bool has_optional_fixed32() const; + inline void clear_optional_fixed32(); + static const int kOptionalFixed32FieldNumber = 7; + inline ::google::protobuf::uint32 optional_fixed32() const; + inline void set_optional_fixed32(::google::protobuf::uint32 value); + + // optional fixed64 optional_fixed64 = 8; + inline bool has_optional_fixed64() const; + inline void clear_optional_fixed64(); + static const int kOptionalFixed64FieldNumber = 8; + inline ::google::protobuf::uint64 optional_fixed64() const; + inline void set_optional_fixed64(::google::protobuf::uint64 value); + + // optional sfixed32 optional_sfixed32 = 9; + inline bool has_optional_sfixed32() const; + inline void clear_optional_sfixed32(); + static const int kOptionalSfixed32FieldNumber = 9; + inline ::google::protobuf::int32 optional_sfixed32() const; + inline void set_optional_sfixed32(::google::protobuf::int32 value); + + // optional sfixed64 optional_sfixed64 = 10; + inline bool has_optional_sfixed64() const; + inline void clear_optional_sfixed64(); + static const int kOptionalSfixed64FieldNumber = 10; + inline ::google::protobuf::int64 optional_sfixed64() const; + inline void set_optional_sfixed64(::google::protobuf::int64 value); + + // optional float optional_float = 11; + inline bool has_optional_float() const; + inline void clear_optional_float(); + static const int kOptionalFloatFieldNumber = 11; + inline float optional_float() const; + inline void set_optional_float(float value); + + // optional double optional_double = 12; + inline bool has_optional_double() const; + inline void clear_optional_double(); + static const int kOptionalDoubleFieldNumber = 12; + inline double optional_double() const; + inline void set_optional_double(double value); + + // optional bool optional_bool = 13; + inline bool has_optional_bool() const; + inline void clear_optional_bool(); + static const int kOptionalBoolFieldNumber = 13; + inline bool optional_bool() const; + inline void set_optional_bool(bool value); + + // optional string optional_string = 14; + inline bool has_optional_string() const; + inline void clear_optional_string(); + static const int kOptionalStringFieldNumber = 14; + inline const ::std::string& optional_string() const; + inline void set_optional_string(const ::std::string& value); + inline void set_optional_string(const char* value); + inline void set_optional_string(const char* value, size_t size); + inline ::std::string* mutable_optional_string(); + inline ::std::string* release_optional_string(); + + // optional bytes optional_bytes = 15; + inline bool has_optional_bytes() const; + inline void clear_optional_bytes(); + static const int kOptionalBytesFieldNumber = 15; + inline const ::std::string& optional_bytes() const; + inline void set_optional_bytes(const ::std::string& value); + inline void set_optional_bytes(const char* value); + inline void set_optional_bytes(const void* value, size_t size); + inline ::std::string* mutable_optional_bytes(); + inline ::std::string* release_optional_bytes(); + + // optional group OptionalGroup = 16 { + inline bool has_optionalgroup() const; + inline void clear_optionalgroup(); + static const int kOptionalgroupFieldNumber = 16; + inline const ::protobuf_unittest::TestAllTypes_OptionalGroup& optionalgroup() const; + inline ::protobuf_unittest::TestAllTypes_OptionalGroup* mutable_optionalgroup(); + inline ::protobuf_unittest::TestAllTypes_OptionalGroup* release_optionalgroup(); + + // optional .protobuf_unittest.TestAllTypes.NestedMessage optional_nested_message = 18; + inline bool has_optional_nested_message() const; + inline void clear_optional_nested_message(); + static const int kOptionalNestedMessageFieldNumber = 18; + inline const ::protobuf_unittest::TestAllTypes_NestedMessage& optional_nested_message() const; + inline ::protobuf_unittest::TestAllTypes_NestedMessage* mutable_optional_nested_message(); + inline ::protobuf_unittest::TestAllTypes_NestedMessage* release_optional_nested_message(); + + // optional .protobuf_unittest.ForeignMessage optional_foreign_message = 19; + inline bool has_optional_foreign_message() const; + inline void clear_optional_foreign_message(); + static const int kOptionalForeignMessageFieldNumber = 19; + inline const ::protobuf_unittest::ForeignMessage& optional_foreign_message() const; + inline ::protobuf_unittest::ForeignMessage* mutable_optional_foreign_message(); + inline ::protobuf_unittest::ForeignMessage* release_optional_foreign_message(); + + // optional .protobuf_unittest_import.ImportMessage optional_import_message = 20; + inline bool has_optional_import_message() const; + inline void clear_optional_import_message(); + static const int kOptionalImportMessageFieldNumber = 20; + inline const ::protobuf_unittest_import::ImportMessage& optional_import_message() const; + inline ::protobuf_unittest_import::ImportMessage* mutable_optional_import_message(); + inline ::protobuf_unittest_import::ImportMessage* release_optional_import_message(); + + // optional .protobuf_unittest.TestAllTypes.NestedEnum optional_nested_enum = 21; + inline bool has_optional_nested_enum() const; + inline void clear_optional_nested_enum(); + static const int kOptionalNestedEnumFieldNumber = 21; + inline ::protobuf_unittest::TestAllTypes_NestedEnum optional_nested_enum() const; + inline void set_optional_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value); + + // optional .protobuf_unittest.ForeignEnum optional_foreign_enum = 22; + inline bool has_optional_foreign_enum() const; + inline void clear_optional_foreign_enum(); + static const int kOptionalForeignEnumFieldNumber = 22; + inline protobuf_unittest::ForeignEnum optional_foreign_enum() const; + inline void set_optional_foreign_enum(protobuf_unittest::ForeignEnum value); + + // optional .protobuf_unittest_import.ImportEnum optional_import_enum = 23; + inline bool has_optional_import_enum() const; + inline void clear_optional_import_enum(); + static const int kOptionalImportEnumFieldNumber = 23; + inline protobuf_unittest_import::ImportEnum optional_import_enum() const; + inline void set_optional_import_enum(protobuf_unittest_import::ImportEnum value); + + // optional string optional_string_piece = 24 [ctype = STRING_PIECE]; + inline bool has_optional_string_piece() const; + inline void clear_optional_string_piece(); + static const int kOptionalStringPieceFieldNumber = 24; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& optional_string_piece() const; + inline void set_optional_string_piece(const ::std::string& value); + inline void set_optional_string_piece(const char* value); + inline void set_optional_string_piece(const char* value, size_t size); + inline ::std::string* mutable_optional_string_piece(); + inline ::std::string* release_optional_string_piece(); + public: + + // optional string optional_cord = 25 [ctype = CORD]; + inline bool has_optional_cord() const; + inline void clear_optional_cord(); + static const int kOptionalCordFieldNumber = 25; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& optional_cord() const; + inline void set_optional_cord(const ::std::string& value); + inline void set_optional_cord(const char* value); + inline void set_optional_cord(const char* value, size_t size); + inline ::std::string* mutable_optional_cord(); + inline ::std::string* release_optional_cord(); + public: + + // repeated int32 repeated_int32 = 31; + inline int repeated_int32_size() const; + inline void clear_repeated_int32(); + static const int kRepeatedInt32FieldNumber = 31; + inline ::google::protobuf::int32 repeated_int32(int index) const; + inline void set_repeated_int32(int index, ::google::protobuf::int32 value); + inline void add_repeated_int32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeated_int32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeated_int32(); + + // repeated int64 repeated_int64 = 32; + inline int repeated_int64_size() const; + inline void clear_repeated_int64(); + static const int kRepeatedInt64FieldNumber = 32; + inline ::google::protobuf::int64 repeated_int64(int index) const; + inline void set_repeated_int64(int index, ::google::protobuf::int64 value); + inline void add_repeated_int64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + repeated_int64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_repeated_int64(); + + // repeated uint32 repeated_uint32 = 33; + inline int repeated_uint32_size() const; + inline void clear_repeated_uint32(); + static const int kRepeatedUint32FieldNumber = 33; + inline ::google::protobuf::uint32 repeated_uint32(int index) const; + inline void set_repeated_uint32(int index, ::google::protobuf::uint32 value); + inline void add_repeated_uint32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + repeated_uint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_repeated_uint32(); + + // repeated uint64 repeated_uint64 = 34; + inline int repeated_uint64_size() const; + inline void clear_repeated_uint64(); + static const int kRepeatedUint64FieldNumber = 34; + inline ::google::protobuf::uint64 repeated_uint64(int index) const; + inline void set_repeated_uint64(int index, ::google::protobuf::uint64 value); + inline void add_repeated_uint64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + repeated_uint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_repeated_uint64(); + + // repeated sint32 repeated_sint32 = 35; + inline int repeated_sint32_size() const; + inline void clear_repeated_sint32(); + static const int kRepeatedSint32FieldNumber = 35; + inline ::google::protobuf::int32 repeated_sint32(int index) const; + inline void set_repeated_sint32(int index, ::google::protobuf::int32 value); + inline void add_repeated_sint32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeated_sint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeated_sint32(); + + // repeated sint64 repeated_sint64 = 36; + inline int repeated_sint64_size() const; + inline void clear_repeated_sint64(); + static const int kRepeatedSint64FieldNumber = 36; + inline ::google::protobuf::int64 repeated_sint64(int index) const; + inline void set_repeated_sint64(int index, ::google::protobuf::int64 value); + inline void add_repeated_sint64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + repeated_sint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_repeated_sint64(); + + // repeated fixed32 repeated_fixed32 = 37; + inline int repeated_fixed32_size() const; + inline void clear_repeated_fixed32(); + static const int kRepeatedFixed32FieldNumber = 37; + inline ::google::protobuf::uint32 repeated_fixed32(int index) const; + inline void set_repeated_fixed32(int index, ::google::protobuf::uint32 value); + inline void add_repeated_fixed32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + repeated_fixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_repeated_fixed32(); + + // repeated fixed64 repeated_fixed64 = 38; + inline int repeated_fixed64_size() const; + inline void clear_repeated_fixed64(); + static const int kRepeatedFixed64FieldNumber = 38; + inline ::google::protobuf::uint64 repeated_fixed64(int index) const; + inline void set_repeated_fixed64(int index, ::google::protobuf::uint64 value); + inline void add_repeated_fixed64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + repeated_fixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_repeated_fixed64(); + + // repeated sfixed32 repeated_sfixed32 = 39; + inline int repeated_sfixed32_size() const; + inline void clear_repeated_sfixed32(); + static const int kRepeatedSfixed32FieldNumber = 39; + inline ::google::protobuf::int32 repeated_sfixed32(int index) const; + inline void set_repeated_sfixed32(int index, ::google::protobuf::int32 value); + inline void add_repeated_sfixed32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeated_sfixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeated_sfixed32(); + + // repeated sfixed64 repeated_sfixed64 = 40; + inline int repeated_sfixed64_size() const; + inline void clear_repeated_sfixed64(); + static const int kRepeatedSfixed64FieldNumber = 40; + inline ::google::protobuf::int64 repeated_sfixed64(int index) const; + inline void set_repeated_sfixed64(int index, ::google::protobuf::int64 value); + inline void add_repeated_sfixed64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + repeated_sfixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_repeated_sfixed64(); + + // repeated float repeated_float = 41; + inline int repeated_float_size() const; + inline void clear_repeated_float(); + static const int kRepeatedFloatFieldNumber = 41; + inline float repeated_float(int index) const; + inline void set_repeated_float(int index, float value); + inline void add_repeated_float(float value); + inline const ::google::protobuf::RepeatedField< float >& + repeated_float() const; + inline ::google::protobuf::RepeatedField< float >* + mutable_repeated_float(); + + // repeated double repeated_double = 42; + inline int repeated_double_size() const; + inline void clear_repeated_double(); + static const int kRepeatedDoubleFieldNumber = 42; + inline double repeated_double(int index) const; + inline void set_repeated_double(int index, double value); + inline void add_repeated_double(double value); + inline const ::google::protobuf::RepeatedField< double >& + repeated_double() const; + inline ::google::protobuf::RepeatedField< double >* + mutable_repeated_double(); + + // repeated bool repeated_bool = 43; + inline int repeated_bool_size() const; + inline void clear_repeated_bool(); + static const int kRepeatedBoolFieldNumber = 43; + inline bool repeated_bool(int index) const; + inline void set_repeated_bool(int index, bool value); + inline void add_repeated_bool(bool value); + inline const ::google::protobuf::RepeatedField< bool >& + repeated_bool() const; + inline ::google::protobuf::RepeatedField< bool >* + mutable_repeated_bool(); + + // repeated string repeated_string = 44; + inline int repeated_string_size() const; + inline void clear_repeated_string(); + static const int kRepeatedStringFieldNumber = 44; + inline const ::std::string& repeated_string(int index) const; + inline ::std::string* mutable_repeated_string(int index); + inline void set_repeated_string(int index, const ::std::string& value); + inline void set_repeated_string(int index, const char* value); + inline void set_repeated_string(int index, const char* value, size_t size); + inline ::std::string* add_repeated_string(); + inline void add_repeated_string(const ::std::string& value); + inline void add_repeated_string(const char* value); + inline void add_repeated_string(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string(); + + // repeated bytes repeated_bytes = 45; + inline int repeated_bytes_size() const; + inline void clear_repeated_bytes(); + static const int kRepeatedBytesFieldNumber = 45; + inline const ::std::string& repeated_bytes(int index) const; + inline ::std::string* mutable_repeated_bytes(int index); + inline void set_repeated_bytes(int index, const ::std::string& value); + inline void set_repeated_bytes(int index, const char* value); + inline void set_repeated_bytes(int index, const void* value, size_t size); + inline ::std::string* add_repeated_bytes(); + inline void add_repeated_bytes(const ::std::string& value); + inline void add_repeated_bytes(const char* value); + inline void add_repeated_bytes(const void* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_bytes() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_bytes(); + + // repeated group RepeatedGroup = 46 { + inline int repeatedgroup_size() const; + inline void clear_repeatedgroup(); + static const int kRepeatedgroupFieldNumber = 46; + inline const ::protobuf_unittest::TestAllTypes_RepeatedGroup& repeatedgroup(int index) const; + inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* mutable_repeatedgroup(int index); + inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* add_repeatedgroup(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >& + repeatedgroup() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >* + mutable_repeatedgroup(); + + // repeated .protobuf_unittest.TestAllTypes.NestedMessage repeated_nested_message = 48; + inline int repeated_nested_message_size() const; + inline void clear_repeated_nested_message(); + static const int kRepeatedNestedMessageFieldNumber = 48; + inline const ::protobuf_unittest::TestAllTypes_NestedMessage& repeated_nested_message(int index) const; + inline ::protobuf_unittest::TestAllTypes_NestedMessage* mutable_repeated_nested_message(int index); + inline ::protobuf_unittest::TestAllTypes_NestedMessage* add_repeated_nested_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >& + repeated_nested_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >* + mutable_repeated_nested_message(); + + // repeated .protobuf_unittest.ForeignMessage repeated_foreign_message = 49; + inline int repeated_foreign_message_size() const; + inline void clear_repeated_foreign_message(); + static const int kRepeatedForeignMessageFieldNumber = 49; + inline const ::protobuf_unittest::ForeignMessage& repeated_foreign_message(int index) const; + inline ::protobuf_unittest::ForeignMessage* mutable_repeated_foreign_message(int index); + inline ::protobuf_unittest::ForeignMessage* add_repeated_foreign_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& + repeated_foreign_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* + mutable_repeated_foreign_message(); + + // repeated .protobuf_unittest_import.ImportMessage repeated_import_message = 50; + inline int repeated_import_message_size() const; + inline void clear_repeated_import_message(); + static const int kRepeatedImportMessageFieldNumber = 50; + inline const ::protobuf_unittest_import::ImportMessage& repeated_import_message(int index) const; + inline ::protobuf_unittest_import::ImportMessage* mutable_repeated_import_message(int index); + inline ::protobuf_unittest_import::ImportMessage* add_repeated_import_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >& + repeated_import_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >* + mutable_repeated_import_message(); + + // repeated .protobuf_unittest.TestAllTypes.NestedEnum repeated_nested_enum = 51; + inline int repeated_nested_enum_size() const; + inline void clear_repeated_nested_enum(); + static const int kRepeatedNestedEnumFieldNumber = 51; + inline ::protobuf_unittest::TestAllTypes_NestedEnum repeated_nested_enum(int index) const; + inline void set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypes_NestedEnum value); + inline void add_repeated_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value); + inline const ::google::protobuf::RepeatedField& repeated_nested_enum() const; + inline ::google::protobuf::RepeatedField* mutable_repeated_nested_enum(); + + // repeated .protobuf_unittest.ForeignEnum repeated_foreign_enum = 52; + inline int repeated_foreign_enum_size() const; + inline void clear_repeated_foreign_enum(); + static const int kRepeatedForeignEnumFieldNumber = 52; + inline protobuf_unittest::ForeignEnum repeated_foreign_enum(int index) const; + inline void set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnum value); + inline void add_repeated_foreign_enum(protobuf_unittest::ForeignEnum value); + inline const ::google::protobuf::RepeatedField& repeated_foreign_enum() const; + inline ::google::protobuf::RepeatedField* mutable_repeated_foreign_enum(); + + // repeated .protobuf_unittest_import.ImportEnum repeated_import_enum = 53; + inline int repeated_import_enum_size() const; + inline void clear_repeated_import_enum(); + static const int kRepeatedImportEnumFieldNumber = 53; + inline protobuf_unittest_import::ImportEnum repeated_import_enum(int index) const; + inline void set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnum value); + inline void add_repeated_import_enum(protobuf_unittest_import::ImportEnum value); + inline const ::google::protobuf::RepeatedField& repeated_import_enum() const; + inline ::google::protobuf::RepeatedField* mutable_repeated_import_enum(); + + // repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; + inline int repeated_string_piece_size() const; + inline void clear_repeated_string_piece(); + static const int kRepeatedStringPieceFieldNumber = 54; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& repeated_string_piece(int index) const; + inline ::std::string* mutable_repeated_string_piece(int index); + inline void set_repeated_string_piece(int index, const ::std::string& value); + inline void set_repeated_string_piece(int index, const char* value); + inline void set_repeated_string_piece(int index, const char* value, size_t size); + inline ::std::string* add_repeated_string_piece(); + inline void add_repeated_string_piece(const ::std::string& value); + inline void add_repeated_string_piece(const char* value); + inline void add_repeated_string_piece(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string_piece() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string_piece(); + public: + + // repeated string repeated_cord = 55 [ctype = CORD]; + inline int repeated_cord_size() const; + inline void clear_repeated_cord(); + static const int kRepeatedCordFieldNumber = 55; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& repeated_cord(int index) const; + inline ::std::string* mutable_repeated_cord(int index); + inline void set_repeated_cord(int index, const ::std::string& value); + inline void set_repeated_cord(int index, const char* value); + inline void set_repeated_cord(int index, const char* value, size_t size); + inline ::std::string* add_repeated_cord(); + inline void add_repeated_cord(const ::std::string& value); + inline void add_repeated_cord(const char* value); + inline void add_repeated_cord(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_cord() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_cord(); + public: + + // optional int32 default_int32 = 61 [default = 41]; + inline bool has_default_int32() const; + inline void clear_default_int32(); + static const int kDefaultInt32FieldNumber = 61; + inline ::google::protobuf::int32 default_int32() const; + inline void set_default_int32(::google::protobuf::int32 value); + + // optional int64 default_int64 = 62 [default = 42]; + inline bool has_default_int64() const; + inline void clear_default_int64(); + static const int kDefaultInt64FieldNumber = 62; + inline ::google::protobuf::int64 default_int64() const; + inline void set_default_int64(::google::protobuf::int64 value); + + // optional uint32 default_uint32 = 63 [default = 43]; + inline bool has_default_uint32() const; + inline void clear_default_uint32(); + static const int kDefaultUint32FieldNumber = 63; + inline ::google::protobuf::uint32 default_uint32() const; + inline void set_default_uint32(::google::protobuf::uint32 value); + + // optional uint64 default_uint64 = 64 [default = 44]; + inline bool has_default_uint64() const; + inline void clear_default_uint64(); + static const int kDefaultUint64FieldNumber = 64; + inline ::google::protobuf::uint64 default_uint64() const; + inline void set_default_uint64(::google::protobuf::uint64 value); + + // optional sint32 default_sint32 = 65 [default = -45]; + inline bool has_default_sint32() const; + inline void clear_default_sint32(); + static const int kDefaultSint32FieldNumber = 65; + inline ::google::protobuf::int32 default_sint32() const; + inline void set_default_sint32(::google::protobuf::int32 value); + + // optional sint64 default_sint64 = 66 [default = 46]; + inline bool has_default_sint64() const; + inline void clear_default_sint64(); + static const int kDefaultSint64FieldNumber = 66; + inline ::google::protobuf::int64 default_sint64() const; + inline void set_default_sint64(::google::protobuf::int64 value); + + // optional fixed32 default_fixed32 = 67 [default = 47]; + inline bool has_default_fixed32() const; + inline void clear_default_fixed32(); + static const int kDefaultFixed32FieldNumber = 67; + inline ::google::protobuf::uint32 default_fixed32() const; + inline void set_default_fixed32(::google::protobuf::uint32 value); + + // optional fixed64 default_fixed64 = 68 [default = 48]; + inline bool has_default_fixed64() const; + inline void clear_default_fixed64(); + static const int kDefaultFixed64FieldNumber = 68; + inline ::google::protobuf::uint64 default_fixed64() const; + inline void set_default_fixed64(::google::protobuf::uint64 value); + + // optional sfixed32 default_sfixed32 = 69 [default = 49]; + inline bool has_default_sfixed32() const; + inline void clear_default_sfixed32(); + static const int kDefaultSfixed32FieldNumber = 69; + inline ::google::protobuf::int32 default_sfixed32() const; + inline void set_default_sfixed32(::google::protobuf::int32 value); + + // optional sfixed64 default_sfixed64 = 70 [default = -50]; + inline bool has_default_sfixed64() const; + inline void clear_default_sfixed64(); + static const int kDefaultSfixed64FieldNumber = 70; + inline ::google::protobuf::int64 default_sfixed64() const; + inline void set_default_sfixed64(::google::protobuf::int64 value); + + // optional float default_float = 71 [default = 51.5]; + inline bool has_default_float() const; + inline void clear_default_float(); + static const int kDefaultFloatFieldNumber = 71; + inline float default_float() const; + inline void set_default_float(float value); + + // optional double default_double = 72 [default = 52000]; + inline bool has_default_double() const; + inline void clear_default_double(); + static const int kDefaultDoubleFieldNumber = 72; + inline double default_double() const; + inline void set_default_double(double value); + + // optional bool default_bool = 73 [default = true]; + inline bool has_default_bool() const; + inline void clear_default_bool(); + static const int kDefaultBoolFieldNumber = 73; + inline bool default_bool() const; + inline void set_default_bool(bool value); + + // optional string default_string = 74 [default = "hello"]; + inline bool has_default_string() const; + inline void clear_default_string(); + static const int kDefaultStringFieldNumber = 74; + inline const ::std::string& default_string() const; + inline void set_default_string(const ::std::string& value); + inline void set_default_string(const char* value); + inline void set_default_string(const char* value, size_t size); + inline ::std::string* mutable_default_string(); + inline ::std::string* release_default_string(); + + // optional bytes default_bytes = 75 [default = "world"]; + inline bool has_default_bytes() const; + inline void clear_default_bytes(); + static const int kDefaultBytesFieldNumber = 75; + inline const ::std::string& default_bytes() const; + inline void set_default_bytes(const ::std::string& value); + inline void set_default_bytes(const char* value); + inline void set_default_bytes(const void* value, size_t size); + inline ::std::string* mutable_default_bytes(); + inline ::std::string* release_default_bytes(); + + // optional .protobuf_unittest.TestAllTypes.NestedEnum default_nested_enum = 81 [default = BAR]; + inline bool has_default_nested_enum() const; + inline void clear_default_nested_enum(); + static const int kDefaultNestedEnumFieldNumber = 81; + inline ::protobuf_unittest::TestAllTypes_NestedEnum default_nested_enum() const; + inline void set_default_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value); + + // optional .protobuf_unittest.ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; + inline bool has_default_foreign_enum() const; + inline void clear_default_foreign_enum(); + static const int kDefaultForeignEnumFieldNumber = 82; + inline protobuf_unittest::ForeignEnum default_foreign_enum() const; + inline void set_default_foreign_enum(protobuf_unittest::ForeignEnum value); + + // optional .protobuf_unittest_import.ImportEnum default_import_enum = 83 [default = IMPORT_BAR]; + inline bool has_default_import_enum() const; + inline void clear_default_import_enum(); + static const int kDefaultImportEnumFieldNumber = 83; + inline protobuf_unittest_import::ImportEnum default_import_enum() const; + inline void set_default_import_enum(protobuf_unittest_import::ImportEnum value); + + // optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; + inline bool has_default_string_piece() const; + inline void clear_default_string_piece(); + static const int kDefaultStringPieceFieldNumber = 84; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& default_string_piece() const; + inline void set_default_string_piece(const ::std::string& value); + inline void set_default_string_piece(const char* value); + inline void set_default_string_piece(const char* value, size_t size); + inline ::std::string* mutable_default_string_piece(); + inline ::std::string* release_default_string_piece(); + public: + + // optional string default_cord = 85 [default = "123", ctype = CORD]; + inline bool has_default_cord() const; + inline void clear_default_cord(); + static const int kDefaultCordFieldNumber = 85; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& default_cord() const; + inline void set_default_cord(const ::std::string& value); + inline void set_default_cord(const char* value); + inline void set_default_cord(const char* value, size_t size); + inline ::std::string* mutable_default_cord(); + inline ::std::string* release_default_cord(); + public: + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes) + private: + inline void set_has_optional_int32(); + inline void clear_has_optional_int32(); + inline void set_has_optional_int64(); + inline void clear_has_optional_int64(); + inline void set_has_optional_uint32(); + inline void clear_has_optional_uint32(); + inline void set_has_optional_uint64(); + inline void clear_has_optional_uint64(); + inline void set_has_optional_sint32(); + inline void clear_has_optional_sint32(); + inline void set_has_optional_sint64(); + inline void clear_has_optional_sint64(); + inline void set_has_optional_fixed32(); + inline void clear_has_optional_fixed32(); + inline void set_has_optional_fixed64(); + inline void clear_has_optional_fixed64(); + inline void set_has_optional_sfixed32(); + inline void clear_has_optional_sfixed32(); + inline void set_has_optional_sfixed64(); + inline void clear_has_optional_sfixed64(); + inline void set_has_optional_float(); + inline void clear_has_optional_float(); + inline void set_has_optional_double(); + inline void clear_has_optional_double(); + inline void set_has_optional_bool(); + inline void clear_has_optional_bool(); + inline void set_has_optional_string(); + inline void clear_has_optional_string(); + inline void set_has_optional_bytes(); + inline void clear_has_optional_bytes(); + inline void set_has_optionalgroup(); + inline void clear_has_optionalgroup(); + inline void set_has_optional_nested_message(); + inline void clear_has_optional_nested_message(); + inline void set_has_optional_foreign_message(); + inline void clear_has_optional_foreign_message(); + inline void set_has_optional_import_message(); + inline void clear_has_optional_import_message(); + inline void set_has_optional_nested_enum(); + inline void clear_has_optional_nested_enum(); + inline void set_has_optional_foreign_enum(); + inline void clear_has_optional_foreign_enum(); + inline void set_has_optional_import_enum(); + inline void clear_has_optional_import_enum(); + inline void set_has_optional_string_piece(); + inline void clear_has_optional_string_piece(); + inline void set_has_optional_cord(); + inline void clear_has_optional_cord(); + inline void set_has_default_int32(); + inline void clear_has_default_int32(); + inline void set_has_default_int64(); + inline void clear_has_default_int64(); + inline void set_has_default_uint32(); + inline void clear_has_default_uint32(); + inline void set_has_default_uint64(); + inline void clear_has_default_uint64(); + inline void set_has_default_sint32(); + inline void clear_has_default_sint32(); + inline void set_has_default_sint64(); + inline void clear_has_default_sint64(); + inline void set_has_default_fixed32(); + inline void clear_has_default_fixed32(); + inline void set_has_default_fixed64(); + inline void clear_has_default_fixed64(); + inline void set_has_default_sfixed32(); + inline void clear_has_default_sfixed32(); + inline void set_has_default_sfixed64(); + inline void clear_has_default_sfixed64(); + inline void set_has_default_float(); + inline void clear_has_default_float(); + inline void set_has_default_double(); + inline void clear_has_default_double(); + inline void set_has_default_bool(); + inline void clear_has_default_bool(); + inline void set_has_default_string(); + inline void clear_has_default_string(); + inline void set_has_default_bytes(); + inline void clear_has_default_bytes(); + inline void set_has_default_nested_enum(); + inline void clear_has_default_nested_enum(); + inline void set_has_default_foreign_enum(); + inline void clear_has_default_foreign_enum(); + inline void set_has_default_import_enum(); + inline void clear_has_default_import_enum(); + inline void set_has_default_string_piece(); + inline void clear_has_default_string_piece(); + inline void set_has_default_cord(); + inline void clear_has_default_cord(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 optional_int32_; + ::google::protobuf::uint32 optional_uint32_; + ::google::protobuf::int64 optional_int64_; + ::google::protobuf::uint64 optional_uint64_; + ::google::protobuf::int32 optional_sint32_; + ::google::protobuf::uint32 optional_fixed32_; + ::google::protobuf::int64 optional_sint64_; + ::google::protobuf::uint64 optional_fixed64_; + ::google::protobuf::int32 optional_sfixed32_; + float optional_float_; + ::google::protobuf::int64 optional_sfixed64_; + double optional_double_; + ::std::string* optional_string_; + ::std::string* optional_bytes_; + ::protobuf_unittest::TestAllTypes_OptionalGroup* optionalgroup_; + ::protobuf_unittest::TestAllTypes_NestedMessage* optional_nested_message_; + ::protobuf_unittest::ForeignMessage* optional_foreign_message_; + ::protobuf_unittest_import::ImportMessage* optional_import_message_; + int optional_nested_enum_; + int optional_foreign_enum_; + ::std::string* optional_string_piece_; + ::std::string* optional_cord_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_int32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_int64_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_uint32_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_uint64_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sint32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sint64_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_fixed32_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_fixed64_; + int optional_import_enum_; + bool optional_bool_; + bool default_bool_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sfixed32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sfixed64_; + ::google::protobuf::RepeatedField< float > repeated_float_; + ::google::protobuf::RepeatedField< double > repeated_double_; + ::google::protobuf::RepeatedField< bool > repeated_bool_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_bytes_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup > repeatedgroup_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage > repeated_nested_message_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage > repeated_foreign_message_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage > repeated_import_message_; + ::google::protobuf::RepeatedField repeated_nested_enum_; + ::google::protobuf::RepeatedField repeated_foreign_enum_; + ::google::protobuf::RepeatedField repeated_import_enum_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_piece_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_cord_; + ::google::protobuf::int64 default_int64_; + ::google::protobuf::int32 default_int32_; + ::google::protobuf::uint32 default_uint32_; + ::google::protobuf::uint64 default_uint64_; + ::google::protobuf::int32 default_sint32_; + ::google::protobuf::uint32 default_fixed32_; + ::google::protobuf::int64 default_sint64_; + ::google::protobuf::uint64 default_fixed64_; + ::google::protobuf::int32 default_sfixed32_; + float default_float_; + ::google::protobuf::int64 default_sfixed64_; + double default_double_; + ::std::string* default_string_; + static const ::std::string _default_default_string_; + ::std::string* default_bytes_; + static const ::std::string _default_default_bytes_; + int default_nested_enum_; + int default_foreign_enum_; + ::std::string* default_string_piece_; + static const ::std::string _default_default_string_piece_; + ::std::string* default_cord_; + static const ::std::string _default_default_cord_; + int default_import_enum_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(68 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypes* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestDeprecatedFields : public ::google::protobuf::Message { + public: + TestDeprecatedFields(); + virtual ~TestDeprecatedFields(); + + TestDeprecatedFields(const TestDeprecatedFields& from); + + inline TestDeprecatedFields& operator=(const TestDeprecatedFields& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestDeprecatedFields& default_instance(); + + void Swap(TestDeprecatedFields* other); + + // implements Message ---------------------------------------------- + + TestDeprecatedFields* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestDeprecatedFields& from); + void MergeFrom(const TestDeprecatedFields& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 deprecated_int32 = 1 [deprecated = true]; + inline bool has_deprecated_int32() const PROTOBUF_DEPRECATED; + inline void clear_deprecated_int32() PROTOBUF_DEPRECATED; + static const int kDeprecatedInt32FieldNumber = 1; + inline ::google::protobuf::int32 deprecated_int32() const PROTOBUF_DEPRECATED; + inline void set_deprecated_int32(::google::protobuf::int32 value) PROTOBUF_DEPRECATED; + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDeprecatedFields) + private: + inline void set_has_deprecated_int32(); + inline void clear_has_deprecated_int32(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 deprecated_int32_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestDeprecatedFields* default_instance_; +}; +// ------------------------------------------------------------------- + +class ForeignMessage : public ::google::protobuf::Message { + public: + ForeignMessage(); + virtual ~ForeignMessage(); + + ForeignMessage(const ForeignMessage& from); + + inline ForeignMessage& operator=(const ForeignMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ForeignMessage& default_instance(); + + void Swap(ForeignMessage* other); + + // implements Message ---------------------------------------------- + + ForeignMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ForeignMessage& from); + void MergeFrom(const ForeignMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 c = 1; + inline bool has_c() const; + inline void clear_c(); + static const int kCFieldNumber = 1; + inline ::google::protobuf::int32 c() const; + inline void set_c(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.ForeignMessage) + private: + inline void set_has_c(); + inline void clear_has_c(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 c_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static ForeignMessage* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllExtensions : public ::google::protobuf::Message { + public: + TestAllExtensions(); + virtual ~TestAllExtensions(); + + TestAllExtensions(const TestAllExtensions& from); + + inline TestAllExtensions& operator=(const TestAllExtensions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestAllExtensions& default_instance(); + + void Swap(TestAllExtensions* other); + + // implements Message ---------------------------------------------- + + TestAllExtensions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestAllExtensions& from); + void MergeFrom(const TestAllExtensions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestAllExtensions) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllExtensions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestAllExtensions* default_instance_; +}; +// ------------------------------------------------------------------- + +class OptionalGroup_extension : public ::google::protobuf::Message { + public: + OptionalGroup_extension(); + virtual ~OptionalGroup_extension(); + + OptionalGroup_extension(const OptionalGroup_extension& from); + + inline OptionalGroup_extension& operator=(const OptionalGroup_extension& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const OptionalGroup_extension& default_instance(); + + void Swap(OptionalGroup_extension* other); + + // implements Message ---------------------------------------------- + + OptionalGroup_extension* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const OptionalGroup_extension& from); + void MergeFrom(const OptionalGroup_extension& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 17; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 17; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.OptionalGroup_extension) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static OptionalGroup_extension* default_instance_; +}; +// ------------------------------------------------------------------- + +class RepeatedGroup_extension : public ::google::protobuf::Message { + public: + RepeatedGroup_extension(); + virtual ~RepeatedGroup_extension(); + + RepeatedGroup_extension(const RepeatedGroup_extension& from); + + inline RepeatedGroup_extension& operator=(const RepeatedGroup_extension& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const RepeatedGroup_extension& default_instance(); + + void Swap(RepeatedGroup_extension* other); + + // implements Message ---------------------------------------------- + + RepeatedGroup_extension* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const RepeatedGroup_extension& from); + void MergeFrom(const RepeatedGroup_extension& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 47; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 47; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.RepeatedGroup_extension) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static RepeatedGroup_extension* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestNestedExtension : public ::google::protobuf::Message { + public: + TestNestedExtension(); + virtual ~TestNestedExtension(); + + TestNestedExtension(const TestNestedExtension& from); + + inline TestNestedExtension& operator=(const TestNestedExtension& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestNestedExtension& default_instance(); + + void Swap(TestNestedExtension* other); + + // implements Message ---------------------------------------------- + + TestNestedExtension* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestNestedExtension& from); + void MergeFrom(const TestNestedExtension& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + static const int kTestFieldNumber = 1002; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + test; + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedExtension) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestNestedExtension* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestRequired : public ::google::protobuf::Message { + public: + TestRequired(); + virtual ~TestRequired(); + + TestRequired(const TestRequired& from); + + inline TestRequired& operator=(const TestRequired& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestRequired& default_instance(); + + void Swap(TestRequired* other); + + // implements Message ---------------------------------------------- + + TestRequired* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestRequired& from); + void MergeFrom(const TestRequired& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // required int32 a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // optional int32 dummy2 = 2; + inline bool has_dummy2() const; + inline void clear_dummy2(); + static const int kDummy2FieldNumber = 2; + inline ::google::protobuf::int32 dummy2() const; + inline void set_dummy2(::google::protobuf::int32 value); + + // required int32 b = 3; + inline bool has_b() const; + inline void clear_b(); + static const int kBFieldNumber = 3; + inline ::google::protobuf::int32 b() const; + inline void set_b(::google::protobuf::int32 value); + + // optional int32 dummy4 = 4; + inline bool has_dummy4() const; + inline void clear_dummy4(); + static const int kDummy4FieldNumber = 4; + inline ::google::protobuf::int32 dummy4() const; + inline void set_dummy4(::google::protobuf::int32 value); + + // optional int32 dummy5 = 5; + inline bool has_dummy5() const; + inline void clear_dummy5(); + static const int kDummy5FieldNumber = 5; + inline ::google::protobuf::int32 dummy5() const; + inline void set_dummy5(::google::protobuf::int32 value); + + // optional int32 dummy6 = 6; + inline bool has_dummy6() const; + inline void clear_dummy6(); + static const int kDummy6FieldNumber = 6; + inline ::google::protobuf::int32 dummy6() const; + inline void set_dummy6(::google::protobuf::int32 value); + + // optional int32 dummy7 = 7; + inline bool has_dummy7() const; + inline void clear_dummy7(); + static const int kDummy7FieldNumber = 7; + inline ::google::protobuf::int32 dummy7() const; + inline void set_dummy7(::google::protobuf::int32 value); + + // optional int32 dummy8 = 8; + inline bool has_dummy8() const; + inline void clear_dummy8(); + static const int kDummy8FieldNumber = 8; + inline ::google::protobuf::int32 dummy8() const; + inline void set_dummy8(::google::protobuf::int32 value); + + // optional int32 dummy9 = 9; + inline bool has_dummy9() const; + inline void clear_dummy9(); + static const int kDummy9FieldNumber = 9; + inline ::google::protobuf::int32 dummy9() const; + inline void set_dummy9(::google::protobuf::int32 value); + + // optional int32 dummy10 = 10; + inline bool has_dummy10() const; + inline void clear_dummy10(); + static const int kDummy10FieldNumber = 10; + inline ::google::protobuf::int32 dummy10() const; + inline void set_dummy10(::google::protobuf::int32 value); + + // optional int32 dummy11 = 11; + inline bool has_dummy11() const; + inline void clear_dummy11(); + static const int kDummy11FieldNumber = 11; + inline ::google::protobuf::int32 dummy11() const; + inline void set_dummy11(::google::protobuf::int32 value); + + // optional int32 dummy12 = 12; + inline bool has_dummy12() const; + inline void clear_dummy12(); + static const int kDummy12FieldNumber = 12; + inline ::google::protobuf::int32 dummy12() const; + inline void set_dummy12(::google::protobuf::int32 value); + + // optional int32 dummy13 = 13; + inline bool has_dummy13() const; + inline void clear_dummy13(); + static const int kDummy13FieldNumber = 13; + inline ::google::protobuf::int32 dummy13() const; + inline void set_dummy13(::google::protobuf::int32 value); + + // optional int32 dummy14 = 14; + inline bool has_dummy14() const; + inline void clear_dummy14(); + static const int kDummy14FieldNumber = 14; + inline ::google::protobuf::int32 dummy14() const; + inline void set_dummy14(::google::protobuf::int32 value); + + // optional int32 dummy15 = 15; + inline bool has_dummy15() const; + inline void clear_dummy15(); + static const int kDummy15FieldNumber = 15; + inline ::google::protobuf::int32 dummy15() const; + inline void set_dummy15(::google::protobuf::int32 value); + + // optional int32 dummy16 = 16; + inline bool has_dummy16() const; + inline void clear_dummy16(); + static const int kDummy16FieldNumber = 16; + inline ::google::protobuf::int32 dummy16() const; + inline void set_dummy16(::google::protobuf::int32 value); + + // optional int32 dummy17 = 17; + inline bool has_dummy17() const; + inline void clear_dummy17(); + static const int kDummy17FieldNumber = 17; + inline ::google::protobuf::int32 dummy17() const; + inline void set_dummy17(::google::protobuf::int32 value); + + // optional int32 dummy18 = 18; + inline bool has_dummy18() const; + inline void clear_dummy18(); + static const int kDummy18FieldNumber = 18; + inline ::google::protobuf::int32 dummy18() const; + inline void set_dummy18(::google::protobuf::int32 value); + + // optional int32 dummy19 = 19; + inline bool has_dummy19() const; + inline void clear_dummy19(); + static const int kDummy19FieldNumber = 19; + inline ::google::protobuf::int32 dummy19() const; + inline void set_dummy19(::google::protobuf::int32 value); + + // optional int32 dummy20 = 20; + inline bool has_dummy20() const; + inline void clear_dummy20(); + static const int kDummy20FieldNumber = 20; + inline ::google::protobuf::int32 dummy20() const; + inline void set_dummy20(::google::protobuf::int32 value); + + // optional int32 dummy21 = 21; + inline bool has_dummy21() const; + inline void clear_dummy21(); + static const int kDummy21FieldNumber = 21; + inline ::google::protobuf::int32 dummy21() const; + inline void set_dummy21(::google::protobuf::int32 value); + + // optional int32 dummy22 = 22; + inline bool has_dummy22() const; + inline void clear_dummy22(); + static const int kDummy22FieldNumber = 22; + inline ::google::protobuf::int32 dummy22() const; + inline void set_dummy22(::google::protobuf::int32 value); + + // optional int32 dummy23 = 23; + inline bool has_dummy23() const; + inline void clear_dummy23(); + static const int kDummy23FieldNumber = 23; + inline ::google::protobuf::int32 dummy23() const; + inline void set_dummy23(::google::protobuf::int32 value); + + // optional int32 dummy24 = 24; + inline bool has_dummy24() const; + inline void clear_dummy24(); + static const int kDummy24FieldNumber = 24; + inline ::google::protobuf::int32 dummy24() const; + inline void set_dummy24(::google::protobuf::int32 value); + + // optional int32 dummy25 = 25; + inline bool has_dummy25() const; + inline void clear_dummy25(); + static const int kDummy25FieldNumber = 25; + inline ::google::protobuf::int32 dummy25() const; + inline void set_dummy25(::google::protobuf::int32 value); + + // optional int32 dummy26 = 26; + inline bool has_dummy26() const; + inline void clear_dummy26(); + static const int kDummy26FieldNumber = 26; + inline ::google::protobuf::int32 dummy26() const; + inline void set_dummy26(::google::protobuf::int32 value); + + // optional int32 dummy27 = 27; + inline bool has_dummy27() const; + inline void clear_dummy27(); + static const int kDummy27FieldNumber = 27; + inline ::google::protobuf::int32 dummy27() const; + inline void set_dummy27(::google::protobuf::int32 value); + + // optional int32 dummy28 = 28; + inline bool has_dummy28() const; + inline void clear_dummy28(); + static const int kDummy28FieldNumber = 28; + inline ::google::protobuf::int32 dummy28() const; + inline void set_dummy28(::google::protobuf::int32 value); + + // optional int32 dummy29 = 29; + inline bool has_dummy29() const; + inline void clear_dummy29(); + static const int kDummy29FieldNumber = 29; + inline ::google::protobuf::int32 dummy29() const; + inline void set_dummy29(::google::protobuf::int32 value); + + // optional int32 dummy30 = 30; + inline bool has_dummy30() const; + inline void clear_dummy30(); + static const int kDummy30FieldNumber = 30; + inline ::google::protobuf::int32 dummy30() const; + inline void set_dummy30(::google::protobuf::int32 value); + + // optional int32 dummy31 = 31; + inline bool has_dummy31() const; + inline void clear_dummy31(); + static const int kDummy31FieldNumber = 31; + inline ::google::protobuf::int32 dummy31() const; + inline void set_dummy31(::google::protobuf::int32 value); + + // optional int32 dummy32 = 32; + inline bool has_dummy32() const; + inline void clear_dummy32(); + static const int kDummy32FieldNumber = 32; + inline ::google::protobuf::int32 dummy32() const; + inline void set_dummy32(::google::protobuf::int32 value); + + // required int32 c = 33; + inline bool has_c() const; + inline void clear_c(); + static const int kCFieldNumber = 33; + inline ::google::protobuf::int32 c() const; + inline void set_c(::google::protobuf::int32 value); + + static const int kSingleFieldNumber = 1000; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestRequired >, 11, false > + single; + static const int kMultiFieldNumber = 1001; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::TestRequired >, 11, false > + multi; + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRequired) + private: + inline void set_has_a(); + inline void clear_has_a(); + inline void set_has_dummy2(); + inline void clear_has_dummy2(); + inline void set_has_b(); + inline void clear_has_b(); + inline void set_has_dummy4(); + inline void clear_has_dummy4(); + inline void set_has_dummy5(); + inline void clear_has_dummy5(); + inline void set_has_dummy6(); + inline void clear_has_dummy6(); + inline void set_has_dummy7(); + inline void clear_has_dummy7(); + inline void set_has_dummy8(); + inline void clear_has_dummy8(); + inline void set_has_dummy9(); + inline void clear_has_dummy9(); + inline void set_has_dummy10(); + inline void clear_has_dummy10(); + inline void set_has_dummy11(); + inline void clear_has_dummy11(); + inline void set_has_dummy12(); + inline void clear_has_dummy12(); + inline void set_has_dummy13(); + inline void clear_has_dummy13(); + inline void set_has_dummy14(); + inline void clear_has_dummy14(); + inline void set_has_dummy15(); + inline void clear_has_dummy15(); + inline void set_has_dummy16(); + inline void clear_has_dummy16(); + inline void set_has_dummy17(); + inline void clear_has_dummy17(); + inline void set_has_dummy18(); + inline void clear_has_dummy18(); + inline void set_has_dummy19(); + inline void clear_has_dummy19(); + inline void set_has_dummy20(); + inline void clear_has_dummy20(); + inline void set_has_dummy21(); + inline void clear_has_dummy21(); + inline void set_has_dummy22(); + inline void clear_has_dummy22(); + inline void set_has_dummy23(); + inline void clear_has_dummy23(); + inline void set_has_dummy24(); + inline void clear_has_dummy24(); + inline void set_has_dummy25(); + inline void clear_has_dummy25(); + inline void set_has_dummy26(); + inline void clear_has_dummy26(); + inline void set_has_dummy27(); + inline void clear_has_dummy27(); + inline void set_has_dummy28(); + inline void clear_has_dummy28(); + inline void set_has_dummy29(); + inline void clear_has_dummy29(); + inline void set_has_dummy30(); + inline void clear_has_dummy30(); + inline void set_has_dummy31(); + inline void clear_has_dummy31(); + inline void set_has_dummy32(); + inline void clear_has_dummy32(); + inline void set_has_c(); + inline void clear_has_c(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + ::google::protobuf::int32 dummy2_; + ::google::protobuf::int32 b_; + ::google::protobuf::int32 dummy4_; + ::google::protobuf::int32 dummy5_; + ::google::protobuf::int32 dummy6_; + ::google::protobuf::int32 dummy7_; + ::google::protobuf::int32 dummy8_; + ::google::protobuf::int32 dummy9_; + ::google::protobuf::int32 dummy10_; + ::google::protobuf::int32 dummy11_; + ::google::protobuf::int32 dummy12_; + ::google::protobuf::int32 dummy13_; + ::google::protobuf::int32 dummy14_; + ::google::protobuf::int32 dummy15_; + ::google::protobuf::int32 dummy16_; + ::google::protobuf::int32 dummy17_; + ::google::protobuf::int32 dummy18_; + ::google::protobuf::int32 dummy19_; + ::google::protobuf::int32 dummy20_; + ::google::protobuf::int32 dummy21_; + ::google::protobuf::int32 dummy22_; + ::google::protobuf::int32 dummy23_; + ::google::protobuf::int32 dummy24_; + ::google::protobuf::int32 dummy25_; + ::google::protobuf::int32 dummy26_; + ::google::protobuf::int32 dummy27_; + ::google::protobuf::int32 dummy28_; + ::google::protobuf::int32 dummy29_; + ::google::protobuf::int32 dummy30_; + ::google::protobuf::int32 dummy31_; + ::google::protobuf::int32 dummy32_; + ::google::protobuf::int32 c_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(33 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestRequired* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestRequiredForeign : public ::google::protobuf::Message { + public: + TestRequiredForeign(); + virtual ~TestRequiredForeign(); + + TestRequiredForeign(const TestRequiredForeign& from); + + inline TestRequiredForeign& operator=(const TestRequiredForeign& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestRequiredForeign& default_instance(); + + void Swap(TestRequiredForeign* other); + + // implements Message ---------------------------------------------- + + TestRequiredForeign* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestRequiredForeign& from); + void MergeFrom(const TestRequiredForeign& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestRequired optional_message = 1; + inline bool has_optional_message() const; + inline void clear_optional_message(); + static const int kOptionalMessageFieldNumber = 1; + inline const ::protobuf_unittest::TestRequired& optional_message() const; + inline ::protobuf_unittest::TestRequired* mutable_optional_message(); + inline ::protobuf_unittest::TestRequired* release_optional_message(); + + // repeated .protobuf_unittest.TestRequired repeated_message = 2; + inline int repeated_message_size() const; + inline void clear_repeated_message(); + static const int kRepeatedMessageFieldNumber = 2; + inline const ::protobuf_unittest::TestRequired& repeated_message(int index) const; + inline ::protobuf_unittest::TestRequired* mutable_repeated_message(int index); + inline ::protobuf_unittest::TestRequired* add_repeated_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >& + repeated_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >* + mutable_repeated_message(); + + // optional int32 dummy = 3; + inline bool has_dummy() const; + inline void clear_dummy(); + static const int kDummyFieldNumber = 3; + inline ::google::protobuf::int32 dummy() const; + inline void set_dummy(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRequiredForeign) + private: + inline void set_has_optional_message(); + inline void clear_has_optional_message(); + inline void set_has_dummy(); + inline void clear_has_dummy(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestRequired* optional_message_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired > repeated_message_; + ::google::protobuf::int32 dummy_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestRequiredForeign* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestForeignNested : public ::google::protobuf::Message { + public: + TestForeignNested(); + virtual ~TestForeignNested(); + + TestForeignNested(const TestForeignNested& from); + + inline TestForeignNested& operator=(const TestForeignNested& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestForeignNested& default_instance(); + + void Swap(TestForeignNested* other); + + // implements Message ---------------------------------------------- + + TestForeignNested* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestForeignNested& from); + void MergeFrom(const TestForeignNested& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestAllTypes.NestedMessage foreign_nested = 1; + inline bool has_foreign_nested() const; + inline void clear_foreign_nested(); + static const int kForeignNestedFieldNumber = 1; + inline const ::protobuf_unittest::TestAllTypes_NestedMessage& foreign_nested() const; + inline ::protobuf_unittest::TestAllTypes_NestedMessage* mutable_foreign_nested(); + inline ::protobuf_unittest::TestAllTypes_NestedMessage* release_foreign_nested(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestForeignNested) + private: + inline void set_has_foreign_nested(); + inline void clear_has_foreign_nested(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestAllTypes_NestedMessage* foreign_nested_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestForeignNested* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestEmptyMessage : public ::google::protobuf::Message { + public: + TestEmptyMessage(); + virtual ~TestEmptyMessage(); + + TestEmptyMessage(const TestEmptyMessage& from); + + inline TestEmptyMessage& operator=(const TestEmptyMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestEmptyMessage& default_instance(); + + void Swap(TestEmptyMessage* other); + + // implements Message ---------------------------------------------- + + TestEmptyMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestEmptyMessage& from); + void MergeFrom(const TestEmptyMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestEmptyMessage) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestEmptyMessage* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestEmptyMessageWithExtensions : public ::google::protobuf::Message { + public: + TestEmptyMessageWithExtensions(); + virtual ~TestEmptyMessageWithExtensions(); + + TestEmptyMessageWithExtensions(const TestEmptyMessageWithExtensions& from); + + inline TestEmptyMessageWithExtensions& operator=(const TestEmptyMessageWithExtensions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestEmptyMessageWithExtensions& default_instance(); + + void Swap(TestEmptyMessageWithExtensions* other); + + // implements Message ---------------------------------------------- + + TestEmptyMessageWithExtensions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestEmptyMessageWithExtensions& from); + void MergeFrom(const TestEmptyMessageWithExtensions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestEmptyMessageWithExtensions) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestEmptyMessageWithExtensions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestEmptyMessageWithExtensions* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestMultipleExtensionRanges : public ::google::protobuf::Message { + public: + TestMultipleExtensionRanges(); + virtual ~TestMultipleExtensionRanges(); + + TestMultipleExtensionRanges(const TestMultipleExtensionRanges& from); + + inline TestMultipleExtensionRanges& operator=(const TestMultipleExtensionRanges& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMultipleExtensionRanges& default_instance(); + + void Swap(TestMultipleExtensionRanges* other); + + // implements Message ---------------------------------------------- + + TestMultipleExtensionRanges* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMultipleExtensionRanges& from); + void MergeFrom(const TestMultipleExtensionRanges& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestMultipleExtensionRanges) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMultipleExtensionRanges) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestMultipleExtensionRanges* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestReallyLargeTagNumber : public ::google::protobuf::Message { + public: + TestReallyLargeTagNumber(); + virtual ~TestReallyLargeTagNumber(); + + TestReallyLargeTagNumber(const TestReallyLargeTagNumber& from); + + inline TestReallyLargeTagNumber& operator=(const TestReallyLargeTagNumber& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestReallyLargeTagNumber& default_instance(); + + void Swap(TestReallyLargeTagNumber* other); + + // implements Message ---------------------------------------------- + + TestReallyLargeTagNumber* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestReallyLargeTagNumber& from); + void MergeFrom(const TestReallyLargeTagNumber& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // optional int32 bb = 268435455; + inline bool has_bb() const; + inline void clear_bb(); + static const int kBbFieldNumber = 268435455; + inline ::google::protobuf::int32 bb() const; + inline void set_bb(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestReallyLargeTagNumber) + private: + inline void set_has_a(); + inline void clear_has_a(); + inline void set_has_bb(); + inline void clear_has_bb(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + ::google::protobuf::int32 bb_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestReallyLargeTagNumber* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestRecursiveMessage : public ::google::protobuf::Message { + public: + TestRecursiveMessage(); + virtual ~TestRecursiveMessage(); + + TestRecursiveMessage(const TestRecursiveMessage& from); + + inline TestRecursiveMessage& operator=(const TestRecursiveMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestRecursiveMessage& default_instance(); + + void Swap(TestRecursiveMessage* other); + + // implements Message ---------------------------------------------- + + TestRecursiveMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestRecursiveMessage& from); + void MergeFrom(const TestRecursiveMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestRecursiveMessage a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline const ::protobuf_unittest::TestRecursiveMessage& a() const; + inline ::protobuf_unittest::TestRecursiveMessage* mutable_a(); + inline ::protobuf_unittest::TestRecursiveMessage* release_a(); + + // optional int32 i = 2; + inline bool has_i() const; + inline void clear_i(); + static const int kIFieldNumber = 2; + inline ::google::protobuf::int32 i() const; + inline void set_i(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRecursiveMessage) + private: + inline void set_has_a(); + inline void clear_has_a(); + inline void set_has_i(); + inline void clear_has_i(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestRecursiveMessage* a_; + ::google::protobuf::int32 i_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestRecursiveMessage* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestMutualRecursionA : public ::google::protobuf::Message { + public: + TestMutualRecursionA(); + virtual ~TestMutualRecursionA(); + + TestMutualRecursionA(const TestMutualRecursionA& from); + + inline TestMutualRecursionA& operator=(const TestMutualRecursionA& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMutualRecursionA& default_instance(); + + void Swap(TestMutualRecursionA* other); + + // implements Message ---------------------------------------------- + + TestMutualRecursionA* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMutualRecursionA& from); + void MergeFrom(const TestMutualRecursionA& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestMutualRecursionB bb = 1; + inline bool has_bb() const; + inline void clear_bb(); + static const int kBbFieldNumber = 1; + inline const ::protobuf_unittest::TestMutualRecursionB& bb() const; + inline ::protobuf_unittest::TestMutualRecursionB* mutable_bb(); + inline ::protobuf_unittest::TestMutualRecursionB* release_bb(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMutualRecursionA) + private: + inline void set_has_bb(); + inline void clear_has_bb(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestMutualRecursionB* bb_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestMutualRecursionA* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestMutualRecursionB : public ::google::protobuf::Message { + public: + TestMutualRecursionB(); + virtual ~TestMutualRecursionB(); + + TestMutualRecursionB(const TestMutualRecursionB& from); + + inline TestMutualRecursionB& operator=(const TestMutualRecursionB& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMutualRecursionB& default_instance(); + + void Swap(TestMutualRecursionB* other); + + // implements Message ---------------------------------------------- + + TestMutualRecursionB* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMutualRecursionB& from); + void MergeFrom(const TestMutualRecursionB& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestMutualRecursionA a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline const ::protobuf_unittest::TestMutualRecursionA& a() const; + inline ::protobuf_unittest::TestMutualRecursionA* mutable_a(); + inline ::protobuf_unittest::TestMutualRecursionA* release_a(); + + // optional int32 optional_int32 = 2; + inline bool has_optional_int32() const; + inline void clear_optional_int32(); + static const int kOptionalInt32FieldNumber = 2; + inline ::google::protobuf::int32 optional_int32() const; + inline void set_optional_int32(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMutualRecursionB) + private: + inline void set_has_a(); + inline void clear_has_a(); + inline void set_has_optional_int32(); + inline void clear_has_optional_int32(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestMutualRecursionA* a_; + ::google::protobuf::int32 optional_int32_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestMutualRecursionB* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestDupFieldNumber_Foo : public ::google::protobuf::Message { + public: + TestDupFieldNumber_Foo(); + virtual ~TestDupFieldNumber_Foo(); + + TestDupFieldNumber_Foo(const TestDupFieldNumber_Foo& from); + + inline TestDupFieldNumber_Foo& operator=(const TestDupFieldNumber_Foo& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestDupFieldNumber_Foo& default_instance(); + + void Swap(TestDupFieldNumber_Foo* other); + + // implements Message ---------------------------------------------- + + TestDupFieldNumber_Foo* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestDupFieldNumber_Foo& from); + void MergeFrom(const TestDupFieldNumber_Foo& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDupFieldNumber.Foo) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestDupFieldNumber_Foo* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestDupFieldNumber_Bar : public ::google::protobuf::Message { + public: + TestDupFieldNumber_Bar(); + virtual ~TestDupFieldNumber_Bar(); + + TestDupFieldNumber_Bar(const TestDupFieldNumber_Bar& from); + + inline TestDupFieldNumber_Bar& operator=(const TestDupFieldNumber_Bar& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestDupFieldNumber_Bar& default_instance(); + + void Swap(TestDupFieldNumber_Bar* other); + + // implements Message ---------------------------------------------- + + TestDupFieldNumber_Bar* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestDupFieldNumber_Bar& from); + void MergeFrom(const TestDupFieldNumber_Bar& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDupFieldNumber.Bar) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestDupFieldNumber_Bar* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestDupFieldNumber : public ::google::protobuf::Message { + public: + TestDupFieldNumber(); + virtual ~TestDupFieldNumber(); + + TestDupFieldNumber(const TestDupFieldNumber& from); + + inline TestDupFieldNumber& operator=(const TestDupFieldNumber& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestDupFieldNumber& default_instance(); + + void Swap(TestDupFieldNumber* other); + + // implements Message ---------------------------------------------- + + TestDupFieldNumber* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestDupFieldNumber& from); + void MergeFrom(const TestDupFieldNumber& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef TestDupFieldNumber_Foo Foo; + typedef TestDupFieldNumber_Bar Bar; + + // accessors ------------------------------------------------------- + + // optional int32 a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // optional group Foo = 2 { + inline bool has_foo() const; + inline void clear_foo(); + static const int kFooFieldNumber = 2; + inline const ::protobuf_unittest::TestDupFieldNumber_Foo& foo() const; + inline ::protobuf_unittest::TestDupFieldNumber_Foo* mutable_foo(); + inline ::protobuf_unittest::TestDupFieldNumber_Foo* release_foo(); + + // optional group Bar = 3 { + inline bool has_bar() const; + inline void clear_bar(); + static const int kBarFieldNumber = 3; + inline const ::protobuf_unittest::TestDupFieldNumber_Bar& bar() const; + inline ::protobuf_unittest::TestDupFieldNumber_Bar* mutable_bar(); + inline ::protobuf_unittest::TestDupFieldNumber_Bar* release_bar(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDupFieldNumber) + private: + inline void set_has_a(); + inline void clear_has_a(); + inline void set_has_foo(); + inline void clear_has_foo(); + inline void set_has_bar(); + inline void clear_has_bar(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestDupFieldNumber_Foo* foo_; + ::protobuf_unittest::TestDupFieldNumber_Bar* bar_; + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestDupFieldNumber* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestNestedMessageHasBits_NestedMessage : public ::google::protobuf::Message { + public: + TestNestedMessageHasBits_NestedMessage(); + virtual ~TestNestedMessageHasBits_NestedMessage(); + + TestNestedMessageHasBits_NestedMessage(const TestNestedMessageHasBits_NestedMessage& from); + + inline TestNestedMessageHasBits_NestedMessage& operator=(const TestNestedMessageHasBits_NestedMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestNestedMessageHasBits_NestedMessage& default_instance(); + + void Swap(TestNestedMessageHasBits_NestedMessage* other); + + // implements Message ---------------------------------------------- + + TestNestedMessageHasBits_NestedMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestNestedMessageHasBits_NestedMessage& from); + void MergeFrom(const TestNestedMessageHasBits_NestedMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated int32 nestedmessage_repeated_int32 = 1; + inline int nestedmessage_repeated_int32_size() const; + inline void clear_nestedmessage_repeated_int32(); + static const int kNestedmessageRepeatedInt32FieldNumber = 1; + inline ::google::protobuf::int32 nestedmessage_repeated_int32(int index) const; + inline void set_nestedmessage_repeated_int32(int index, ::google::protobuf::int32 value); + inline void add_nestedmessage_repeated_int32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + nestedmessage_repeated_int32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_nestedmessage_repeated_int32(); + + // repeated .protobuf_unittest.ForeignMessage nestedmessage_repeated_foreignmessage = 2; + inline int nestedmessage_repeated_foreignmessage_size() const; + inline void clear_nestedmessage_repeated_foreignmessage(); + static const int kNestedmessageRepeatedForeignmessageFieldNumber = 2; + inline const ::protobuf_unittest::ForeignMessage& nestedmessage_repeated_foreignmessage(int index) const; + inline ::protobuf_unittest::ForeignMessage* mutable_nestedmessage_repeated_foreignmessage(int index); + inline ::protobuf_unittest::ForeignMessage* add_nestedmessage_repeated_foreignmessage(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& + nestedmessage_repeated_foreignmessage() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* + mutable_nestedmessage_repeated_foreignmessage(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedMessageHasBits.NestedMessage) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > nestedmessage_repeated_int32_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage > nestedmessage_repeated_foreignmessage_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestNestedMessageHasBits_NestedMessage* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestNestedMessageHasBits : public ::google::protobuf::Message { + public: + TestNestedMessageHasBits(); + virtual ~TestNestedMessageHasBits(); + + TestNestedMessageHasBits(const TestNestedMessageHasBits& from); + + inline TestNestedMessageHasBits& operator=(const TestNestedMessageHasBits& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestNestedMessageHasBits& default_instance(); + + void Swap(TestNestedMessageHasBits* other); + + // implements Message ---------------------------------------------- + + TestNestedMessageHasBits* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestNestedMessageHasBits& from); + void MergeFrom(const TestNestedMessageHasBits& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef TestNestedMessageHasBits_NestedMessage NestedMessage; + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestNestedMessageHasBits.NestedMessage optional_nested_message = 1; + inline bool has_optional_nested_message() const; + inline void clear_optional_nested_message(); + static const int kOptionalNestedMessageFieldNumber = 1; + inline const ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage& optional_nested_message() const; + inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* mutable_optional_nested_message(); + inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* release_optional_nested_message(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedMessageHasBits) + private: + inline void set_has_optional_nested_message(); + inline void clear_has_optional_nested_message(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* optional_nested_message_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestNestedMessageHasBits* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestCamelCaseFieldNames : public ::google::protobuf::Message { + public: + TestCamelCaseFieldNames(); + virtual ~TestCamelCaseFieldNames(); + + TestCamelCaseFieldNames(const TestCamelCaseFieldNames& from); + + inline TestCamelCaseFieldNames& operator=(const TestCamelCaseFieldNames& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestCamelCaseFieldNames& default_instance(); + + void Swap(TestCamelCaseFieldNames* other); + + // implements Message ---------------------------------------------- + + TestCamelCaseFieldNames* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestCamelCaseFieldNames& from); + void MergeFrom(const TestCamelCaseFieldNames& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 PrimitiveField = 1; + inline bool has_primitivefield() const; + inline void clear_primitivefield(); + static const int kPrimitiveFieldFieldNumber = 1; + inline ::google::protobuf::int32 primitivefield() const; + inline void set_primitivefield(::google::protobuf::int32 value); + + // optional string StringField = 2; + inline bool has_stringfield() const; + inline void clear_stringfield(); + static const int kStringFieldFieldNumber = 2; + inline const ::std::string& stringfield() const; + inline void set_stringfield(const ::std::string& value); + inline void set_stringfield(const char* value); + inline void set_stringfield(const char* value, size_t size); + inline ::std::string* mutable_stringfield(); + inline ::std::string* release_stringfield(); + + // optional .protobuf_unittest.ForeignEnum EnumField = 3; + inline bool has_enumfield() const; + inline void clear_enumfield(); + static const int kEnumFieldFieldNumber = 3; + inline protobuf_unittest::ForeignEnum enumfield() const; + inline void set_enumfield(protobuf_unittest::ForeignEnum value); + + // optional .protobuf_unittest.ForeignMessage MessageField = 4; + inline bool has_messagefield() const; + inline void clear_messagefield(); + static const int kMessageFieldFieldNumber = 4; + inline const ::protobuf_unittest::ForeignMessage& messagefield() const; + inline ::protobuf_unittest::ForeignMessage* mutable_messagefield(); + inline ::protobuf_unittest::ForeignMessage* release_messagefield(); + + // optional string StringPieceField = 5 [ctype = STRING_PIECE]; + inline bool has_stringpiecefield() const; + inline void clear_stringpiecefield(); + static const int kStringPieceFieldFieldNumber = 5; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& stringpiecefield() const; + inline void set_stringpiecefield(const ::std::string& value); + inline void set_stringpiecefield(const char* value); + inline void set_stringpiecefield(const char* value, size_t size); + inline ::std::string* mutable_stringpiecefield(); + inline ::std::string* release_stringpiecefield(); + public: + + // optional string CordField = 6 [ctype = CORD]; + inline bool has_cordfield() const; + inline void clear_cordfield(); + static const int kCordFieldFieldNumber = 6; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& cordfield() const; + inline void set_cordfield(const ::std::string& value); + inline void set_cordfield(const char* value); + inline void set_cordfield(const char* value, size_t size); + inline ::std::string* mutable_cordfield(); + inline ::std::string* release_cordfield(); + public: + + // repeated int32 RepeatedPrimitiveField = 7; + inline int repeatedprimitivefield_size() const; + inline void clear_repeatedprimitivefield(); + static const int kRepeatedPrimitiveFieldFieldNumber = 7; + inline ::google::protobuf::int32 repeatedprimitivefield(int index) const; + inline void set_repeatedprimitivefield(int index, ::google::protobuf::int32 value); + inline void add_repeatedprimitivefield(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeatedprimitivefield() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeatedprimitivefield(); + + // repeated string RepeatedStringField = 8; + inline int repeatedstringfield_size() const; + inline void clear_repeatedstringfield(); + static const int kRepeatedStringFieldFieldNumber = 8; + inline const ::std::string& repeatedstringfield(int index) const; + inline ::std::string* mutable_repeatedstringfield(int index); + inline void set_repeatedstringfield(int index, const ::std::string& value); + inline void set_repeatedstringfield(int index, const char* value); + inline void set_repeatedstringfield(int index, const char* value, size_t size); + inline ::std::string* add_repeatedstringfield(); + inline void add_repeatedstringfield(const ::std::string& value); + inline void add_repeatedstringfield(const char* value); + inline void add_repeatedstringfield(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeatedstringfield() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeatedstringfield(); + + // repeated .protobuf_unittest.ForeignEnum RepeatedEnumField = 9; + inline int repeatedenumfield_size() const; + inline void clear_repeatedenumfield(); + static const int kRepeatedEnumFieldFieldNumber = 9; + inline protobuf_unittest::ForeignEnum repeatedenumfield(int index) const; + inline void set_repeatedenumfield(int index, protobuf_unittest::ForeignEnum value); + inline void add_repeatedenumfield(protobuf_unittest::ForeignEnum value); + inline const ::google::protobuf::RepeatedField& repeatedenumfield() const; + inline ::google::protobuf::RepeatedField* mutable_repeatedenumfield(); + + // repeated .protobuf_unittest.ForeignMessage RepeatedMessageField = 10; + inline int repeatedmessagefield_size() const; + inline void clear_repeatedmessagefield(); + static const int kRepeatedMessageFieldFieldNumber = 10; + inline const ::protobuf_unittest::ForeignMessage& repeatedmessagefield(int index) const; + inline ::protobuf_unittest::ForeignMessage* mutable_repeatedmessagefield(int index); + inline ::protobuf_unittest::ForeignMessage* add_repeatedmessagefield(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& + repeatedmessagefield() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* + mutable_repeatedmessagefield(); + + // repeated string RepeatedStringPieceField = 11 [ctype = STRING_PIECE]; + inline int repeatedstringpiecefield_size() const; + inline void clear_repeatedstringpiecefield(); + static const int kRepeatedStringPieceFieldFieldNumber = 11; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& repeatedstringpiecefield(int index) const; + inline ::std::string* mutable_repeatedstringpiecefield(int index); + inline void set_repeatedstringpiecefield(int index, const ::std::string& value); + inline void set_repeatedstringpiecefield(int index, const char* value); + inline void set_repeatedstringpiecefield(int index, const char* value, size_t size); + inline ::std::string* add_repeatedstringpiecefield(); + inline void add_repeatedstringpiecefield(const ::std::string& value); + inline void add_repeatedstringpiecefield(const char* value); + inline void add_repeatedstringpiecefield(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeatedstringpiecefield() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeatedstringpiecefield(); + public: + + // repeated string RepeatedCordField = 12 [ctype = CORD]; + inline int repeatedcordfield_size() const; + inline void clear_repeatedcordfield(); + static const int kRepeatedCordFieldFieldNumber = 12; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& repeatedcordfield(int index) const; + inline ::std::string* mutable_repeatedcordfield(int index); + inline void set_repeatedcordfield(int index, const ::std::string& value); + inline void set_repeatedcordfield(int index, const char* value); + inline void set_repeatedcordfield(int index, const char* value, size_t size); + inline ::std::string* add_repeatedcordfield(); + inline void add_repeatedcordfield(const ::std::string& value); + inline void add_repeatedcordfield(const char* value); + inline void add_repeatedcordfield(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeatedcordfield() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeatedcordfield(); + public: + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestCamelCaseFieldNames) + private: + inline void set_has_primitivefield(); + inline void clear_has_primitivefield(); + inline void set_has_stringfield(); + inline void clear_has_stringfield(); + inline void set_has_enumfield(); + inline void clear_has_enumfield(); + inline void set_has_messagefield(); + inline void clear_has_messagefield(); + inline void set_has_stringpiecefield(); + inline void clear_has_stringpiecefield(); + inline void set_has_cordfield(); + inline void clear_has_cordfield(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* stringfield_; + ::google::protobuf::int32 primitivefield_; + int enumfield_; + ::protobuf_unittest::ForeignMessage* messagefield_; + ::std::string* stringpiecefield_; + ::std::string* cordfield_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeatedprimitivefield_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeatedstringfield_; + ::google::protobuf::RepeatedField repeatedenumfield_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage > repeatedmessagefield_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeatedstringpiecefield_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeatedcordfield_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(12 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestCamelCaseFieldNames* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestFieldOrderings : public ::google::protobuf::Message { + public: + TestFieldOrderings(); + virtual ~TestFieldOrderings(); + + TestFieldOrderings(const TestFieldOrderings& from); + + inline TestFieldOrderings& operator=(const TestFieldOrderings& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestFieldOrderings& default_instance(); + + void Swap(TestFieldOrderings* other); + + // implements Message ---------------------------------------------- + + TestFieldOrderings* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestFieldOrderings& from); + void MergeFrom(const TestFieldOrderings& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string my_string = 11; + inline bool has_my_string() const; + inline void clear_my_string(); + static const int kMyStringFieldNumber = 11; + inline const ::std::string& my_string() const; + inline void set_my_string(const ::std::string& value); + inline void set_my_string(const char* value); + inline void set_my_string(const char* value, size_t size); + inline ::std::string* mutable_my_string(); + inline ::std::string* release_my_string(); + + // optional int64 my_int = 1; + inline bool has_my_int() const; + inline void clear_my_int(); + static const int kMyIntFieldNumber = 1; + inline ::google::protobuf::int64 my_int() const; + inline void set_my_int(::google::protobuf::int64 value); + + // optional float my_float = 101; + inline bool has_my_float() const; + inline void clear_my_float(); + static const int kMyFloatFieldNumber = 101; + inline float my_float() const; + inline void set_my_float(float value); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestFieldOrderings) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestFieldOrderings) + private: + inline void set_has_my_string(); + inline void clear_has_my_string(); + inline void set_has_my_int(); + inline void clear_has_my_int(); + inline void set_has_my_float(); + inline void clear_has_my_float(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* my_string_; + ::google::protobuf::int64 my_int_; + float my_float_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestFieldOrderings* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestExtremeDefaultValues : public ::google::protobuf::Message { + public: + TestExtremeDefaultValues(); + virtual ~TestExtremeDefaultValues(); + + TestExtremeDefaultValues(const TestExtremeDefaultValues& from); + + inline TestExtremeDefaultValues& operator=(const TestExtremeDefaultValues& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestExtremeDefaultValues& default_instance(); + + void Swap(TestExtremeDefaultValues* other); + + // implements Message ---------------------------------------------- + + TestExtremeDefaultValues* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestExtremeDefaultValues& from); + void MergeFrom(const TestExtremeDefaultValues& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional bytes escaped_bytes = 1 [default = "\000\001\007\010\014\n\r\t\013\\\'\"\376"]; + inline bool has_escaped_bytes() const; + inline void clear_escaped_bytes(); + static const int kEscapedBytesFieldNumber = 1; + inline const ::std::string& escaped_bytes() const; + inline void set_escaped_bytes(const ::std::string& value); + inline void set_escaped_bytes(const char* value); + inline void set_escaped_bytes(const void* value, size_t size); + inline ::std::string* mutable_escaped_bytes(); + inline ::std::string* release_escaped_bytes(); + + // optional uint32 large_uint32 = 2 [default = 4294967295]; + inline bool has_large_uint32() const; + inline void clear_large_uint32(); + static const int kLargeUint32FieldNumber = 2; + inline ::google::protobuf::uint32 large_uint32() const; + inline void set_large_uint32(::google::protobuf::uint32 value); + + // optional uint64 large_uint64 = 3 [default = 18446744073709551615]; + inline bool has_large_uint64() const; + inline void clear_large_uint64(); + static const int kLargeUint64FieldNumber = 3; + inline ::google::protobuf::uint64 large_uint64() const; + inline void set_large_uint64(::google::protobuf::uint64 value); + + // optional int32 small_int32 = 4 [default = -2147483647]; + inline bool has_small_int32() const; + inline void clear_small_int32(); + static const int kSmallInt32FieldNumber = 4; + inline ::google::protobuf::int32 small_int32() const; + inline void set_small_int32(::google::protobuf::int32 value); + + // optional int64 small_int64 = 5 [default = -9223372036854775807]; + inline bool has_small_int64() const; + inline void clear_small_int64(); + static const int kSmallInt64FieldNumber = 5; + inline ::google::protobuf::int64 small_int64() const; + inline void set_small_int64(::google::protobuf::int64 value); + + // optional string utf8_string = 6 [default = "\341\210\264"]; + inline bool has_utf8_string() const; + inline void clear_utf8_string(); + static const int kUtf8StringFieldNumber = 6; + inline const ::std::string& utf8_string() const; + inline void set_utf8_string(const ::std::string& value); + inline void set_utf8_string(const char* value); + inline void set_utf8_string(const char* value, size_t size); + inline ::std::string* mutable_utf8_string(); + inline ::std::string* release_utf8_string(); + + // optional float zero_float = 7 [default = 0]; + inline bool has_zero_float() const; + inline void clear_zero_float(); + static const int kZeroFloatFieldNumber = 7; + inline float zero_float() const; + inline void set_zero_float(float value); + + // optional float one_float = 8 [default = 1]; + inline bool has_one_float() const; + inline void clear_one_float(); + static const int kOneFloatFieldNumber = 8; + inline float one_float() const; + inline void set_one_float(float value); + + // optional float small_float = 9 [default = 1.5]; + inline bool has_small_float() const; + inline void clear_small_float(); + static const int kSmallFloatFieldNumber = 9; + inline float small_float() const; + inline void set_small_float(float value); + + // optional float negative_one_float = 10 [default = -1]; + inline bool has_negative_one_float() const; + inline void clear_negative_one_float(); + static const int kNegativeOneFloatFieldNumber = 10; + inline float negative_one_float() const; + inline void set_negative_one_float(float value); + + // optional float negative_float = 11 [default = -1.5]; + inline bool has_negative_float() const; + inline void clear_negative_float(); + static const int kNegativeFloatFieldNumber = 11; + inline float negative_float() const; + inline void set_negative_float(float value); + + // optional float large_float = 12 [default = 2e+08]; + inline bool has_large_float() const; + inline void clear_large_float(); + static const int kLargeFloatFieldNumber = 12; + inline float large_float() const; + inline void set_large_float(float value); + + // optional float small_negative_float = 13 [default = -8e-28]; + inline bool has_small_negative_float() const; + inline void clear_small_negative_float(); + static const int kSmallNegativeFloatFieldNumber = 13; + inline float small_negative_float() const; + inline void set_small_negative_float(float value); + + // optional double inf_double = 14 [default = inf]; + inline bool has_inf_double() const; + inline void clear_inf_double(); + static const int kInfDoubleFieldNumber = 14; + inline double inf_double() const; + inline void set_inf_double(double value); + + // optional double neg_inf_double = 15 [default = -inf]; + inline bool has_neg_inf_double() const; + inline void clear_neg_inf_double(); + static const int kNegInfDoubleFieldNumber = 15; + inline double neg_inf_double() const; + inline void set_neg_inf_double(double value); + + // optional double nan_double = 16 [default = nan]; + inline bool has_nan_double() const; + inline void clear_nan_double(); + static const int kNanDoubleFieldNumber = 16; + inline double nan_double() const; + inline void set_nan_double(double value); + + // optional float inf_float = 17 [default = inf]; + inline bool has_inf_float() const; + inline void clear_inf_float(); + static const int kInfFloatFieldNumber = 17; + inline float inf_float() const; + inline void set_inf_float(float value); + + // optional float neg_inf_float = 18 [default = -inf]; + inline bool has_neg_inf_float() const; + inline void clear_neg_inf_float(); + static const int kNegInfFloatFieldNumber = 18; + inline float neg_inf_float() const; + inline void set_neg_inf_float(float value); + + // optional float nan_float = 19 [default = nan]; + inline bool has_nan_float() const; + inline void clear_nan_float(); + static const int kNanFloatFieldNumber = 19; + inline float nan_float() const; + inline void set_nan_float(float value); + + // optional string cpp_trigraph = 20 [default = "? ? ?? ?? ??? ??/ ??-"]; + inline bool has_cpp_trigraph() const; + inline void clear_cpp_trigraph(); + static const int kCppTrigraphFieldNumber = 20; + inline const ::std::string& cpp_trigraph() const; + inline void set_cpp_trigraph(const ::std::string& value); + inline void set_cpp_trigraph(const char* value); + inline void set_cpp_trigraph(const char* value, size_t size); + inline ::std::string* mutable_cpp_trigraph(); + inline ::std::string* release_cpp_trigraph(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestExtremeDefaultValues) + private: + inline void set_has_escaped_bytes(); + inline void clear_has_escaped_bytes(); + inline void set_has_large_uint32(); + inline void clear_has_large_uint32(); + inline void set_has_large_uint64(); + inline void clear_has_large_uint64(); + inline void set_has_small_int32(); + inline void clear_has_small_int32(); + inline void set_has_small_int64(); + inline void clear_has_small_int64(); + inline void set_has_utf8_string(); + inline void clear_has_utf8_string(); + inline void set_has_zero_float(); + inline void clear_has_zero_float(); + inline void set_has_one_float(); + inline void clear_has_one_float(); + inline void set_has_small_float(); + inline void clear_has_small_float(); + inline void set_has_negative_one_float(); + inline void clear_has_negative_one_float(); + inline void set_has_negative_float(); + inline void clear_has_negative_float(); + inline void set_has_large_float(); + inline void clear_has_large_float(); + inline void set_has_small_negative_float(); + inline void clear_has_small_negative_float(); + inline void set_has_inf_double(); + inline void clear_has_inf_double(); + inline void set_has_neg_inf_double(); + inline void clear_has_neg_inf_double(); + inline void set_has_nan_double(); + inline void clear_has_nan_double(); + inline void set_has_inf_float(); + inline void clear_has_inf_float(); + inline void set_has_neg_inf_float(); + inline void clear_has_neg_inf_float(); + inline void set_has_nan_float(); + inline void clear_has_nan_float(); + inline void set_has_cpp_trigraph(); + inline void clear_has_cpp_trigraph(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* escaped_bytes_; + static const ::std::string _default_escaped_bytes_; + ::google::protobuf::uint64 large_uint64_; + ::google::protobuf::uint32 large_uint32_; + ::google::protobuf::int32 small_int32_; + ::google::protobuf::int64 small_int64_; + ::std::string* utf8_string_; + static const ::std::string _default_utf8_string_; + float zero_float_; + float one_float_; + float small_float_; + float negative_one_float_; + float negative_float_; + float large_float_; + double inf_double_; + double neg_inf_double_; + float small_negative_float_; + float inf_float_; + double nan_double_; + float neg_inf_float_; + float nan_float_; + ::std::string* cpp_trigraph_; + static const ::std::string _default_cpp_trigraph_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(20 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestExtremeDefaultValues* default_instance_; +}; +// ------------------------------------------------------------------- + +class SparseEnumMessage : public ::google::protobuf::Message { + public: + SparseEnumMessage(); + virtual ~SparseEnumMessage(); + + SparseEnumMessage(const SparseEnumMessage& from); + + inline SparseEnumMessage& operator=(const SparseEnumMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const SparseEnumMessage& default_instance(); + + void Swap(SparseEnumMessage* other); + + // implements Message ---------------------------------------------- + + SparseEnumMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const SparseEnumMessage& from); + void MergeFrom(const SparseEnumMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestSparseEnum sparse_enum = 1; + inline bool has_sparse_enum() const; + inline void clear_sparse_enum(); + static const int kSparseEnumFieldNumber = 1; + inline protobuf_unittest::TestSparseEnum sparse_enum() const; + inline void set_sparse_enum(protobuf_unittest::TestSparseEnum value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.SparseEnumMessage) + private: + inline void set_has_sparse_enum(); + inline void clear_has_sparse_enum(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + int sparse_enum_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static SparseEnumMessage* default_instance_; +}; +// ------------------------------------------------------------------- + +class OneString : public ::google::protobuf::Message { + public: + OneString(); + virtual ~OneString(); + + OneString(const OneString& from); + + inline OneString& operator=(const OneString& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const OneString& default_instance(); + + void Swap(OneString* other); + + // implements Message ---------------------------------------------- + + OneString* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const OneString& from); + void MergeFrom(const OneString& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string data = 1; + inline bool has_data() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + inline const ::std::string& data() const; + inline void set_data(const ::std::string& value); + inline void set_data(const char* value); + inline void set_data(const char* value, size_t size); + inline ::std::string* mutable_data(); + inline ::std::string* release_data(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.OneString) + private: + inline void set_has_data(); + inline void clear_has_data(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static OneString* default_instance_; +}; +// ------------------------------------------------------------------- + +class OneBytes : public ::google::protobuf::Message { + public: + OneBytes(); + virtual ~OneBytes(); + + OneBytes(const OneBytes& from); + + inline OneBytes& operator=(const OneBytes& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const OneBytes& default_instance(); + + void Swap(OneBytes* other); + + // implements Message ---------------------------------------------- + + OneBytes* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const OneBytes& from); + void MergeFrom(const OneBytes& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional bytes data = 1; + inline bool has_data() const; + inline void clear_data(); + static const int kDataFieldNumber = 1; + inline const ::std::string& data() const; + inline void set_data(const ::std::string& value); + inline void set_data(const char* value); + inline void set_data(const void* value, size_t size); + inline ::std::string* mutable_data(); + inline ::std::string* release_data(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.OneBytes) + private: + inline void set_has_data(); + inline void clear_has_data(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* data_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static OneBytes* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestPackedTypes : public ::google::protobuf::Message { + public: + TestPackedTypes(); + virtual ~TestPackedTypes(); + + TestPackedTypes(const TestPackedTypes& from); + + inline TestPackedTypes& operator=(const TestPackedTypes& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestPackedTypes& default_instance(); + + void Swap(TestPackedTypes* other); + + // implements Message ---------------------------------------------- + + TestPackedTypes* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestPackedTypes& from); + void MergeFrom(const TestPackedTypes& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated int32 packed_int32 = 90 [packed = true]; + inline int packed_int32_size() const; + inline void clear_packed_int32(); + static const int kPackedInt32FieldNumber = 90; + inline ::google::protobuf::int32 packed_int32(int index) const; + inline void set_packed_int32(int index, ::google::protobuf::int32 value); + inline void add_packed_int32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + packed_int32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_packed_int32(); + + // repeated int64 packed_int64 = 91 [packed = true]; + inline int packed_int64_size() const; + inline void clear_packed_int64(); + static const int kPackedInt64FieldNumber = 91; + inline ::google::protobuf::int64 packed_int64(int index) const; + inline void set_packed_int64(int index, ::google::protobuf::int64 value); + inline void add_packed_int64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + packed_int64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_packed_int64(); + + // repeated uint32 packed_uint32 = 92 [packed = true]; + inline int packed_uint32_size() const; + inline void clear_packed_uint32(); + static const int kPackedUint32FieldNumber = 92; + inline ::google::protobuf::uint32 packed_uint32(int index) const; + inline void set_packed_uint32(int index, ::google::protobuf::uint32 value); + inline void add_packed_uint32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + packed_uint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_packed_uint32(); + + // repeated uint64 packed_uint64 = 93 [packed = true]; + inline int packed_uint64_size() const; + inline void clear_packed_uint64(); + static const int kPackedUint64FieldNumber = 93; + inline ::google::protobuf::uint64 packed_uint64(int index) const; + inline void set_packed_uint64(int index, ::google::protobuf::uint64 value); + inline void add_packed_uint64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + packed_uint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_packed_uint64(); + + // repeated sint32 packed_sint32 = 94 [packed = true]; + inline int packed_sint32_size() const; + inline void clear_packed_sint32(); + static const int kPackedSint32FieldNumber = 94; + inline ::google::protobuf::int32 packed_sint32(int index) const; + inline void set_packed_sint32(int index, ::google::protobuf::int32 value); + inline void add_packed_sint32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + packed_sint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_packed_sint32(); + + // repeated sint64 packed_sint64 = 95 [packed = true]; + inline int packed_sint64_size() const; + inline void clear_packed_sint64(); + static const int kPackedSint64FieldNumber = 95; + inline ::google::protobuf::int64 packed_sint64(int index) const; + inline void set_packed_sint64(int index, ::google::protobuf::int64 value); + inline void add_packed_sint64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + packed_sint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_packed_sint64(); + + // repeated fixed32 packed_fixed32 = 96 [packed = true]; + inline int packed_fixed32_size() const; + inline void clear_packed_fixed32(); + static const int kPackedFixed32FieldNumber = 96; + inline ::google::protobuf::uint32 packed_fixed32(int index) const; + inline void set_packed_fixed32(int index, ::google::protobuf::uint32 value); + inline void add_packed_fixed32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + packed_fixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_packed_fixed32(); + + // repeated fixed64 packed_fixed64 = 97 [packed = true]; + inline int packed_fixed64_size() const; + inline void clear_packed_fixed64(); + static const int kPackedFixed64FieldNumber = 97; + inline ::google::protobuf::uint64 packed_fixed64(int index) const; + inline void set_packed_fixed64(int index, ::google::protobuf::uint64 value); + inline void add_packed_fixed64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + packed_fixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_packed_fixed64(); + + // repeated sfixed32 packed_sfixed32 = 98 [packed = true]; + inline int packed_sfixed32_size() const; + inline void clear_packed_sfixed32(); + static const int kPackedSfixed32FieldNumber = 98; + inline ::google::protobuf::int32 packed_sfixed32(int index) const; + inline void set_packed_sfixed32(int index, ::google::protobuf::int32 value); + inline void add_packed_sfixed32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + packed_sfixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_packed_sfixed32(); + + // repeated sfixed64 packed_sfixed64 = 99 [packed = true]; + inline int packed_sfixed64_size() const; + inline void clear_packed_sfixed64(); + static const int kPackedSfixed64FieldNumber = 99; + inline ::google::protobuf::int64 packed_sfixed64(int index) const; + inline void set_packed_sfixed64(int index, ::google::protobuf::int64 value); + inline void add_packed_sfixed64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + packed_sfixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_packed_sfixed64(); + + // repeated float packed_float = 100 [packed = true]; + inline int packed_float_size() const; + inline void clear_packed_float(); + static const int kPackedFloatFieldNumber = 100; + inline float packed_float(int index) const; + inline void set_packed_float(int index, float value); + inline void add_packed_float(float value); + inline const ::google::protobuf::RepeatedField< float >& + packed_float() const; + inline ::google::protobuf::RepeatedField< float >* + mutable_packed_float(); + + // repeated double packed_double = 101 [packed = true]; + inline int packed_double_size() const; + inline void clear_packed_double(); + static const int kPackedDoubleFieldNumber = 101; + inline double packed_double(int index) const; + inline void set_packed_double(int index, double value); + inline void add_packed_double(double value); + inline const ::google::protobuf::RepeatedField< double >& + packed_double() const; + inline ::google::protobuf::RepeatedField< double >* + mutable_packed_double(); + + // repeated bool packed_bool = 102 [packed = true]; + inline int packed_bool_size() const; + inline void clear_packed_bool(); + static const int kPackedBoolFieldNumber = 102; + inline bool packed_bool(int index) const; + inline void set_packed_bool(int index, bool value); + inline void add_packed_bool(bool value); + inline const ::google::protobuf::RepeatedField< bool >& + packed_bool() const; + inline ::google::protobuf::RepeatedField< bool >* + mutable_packed_bool(); + + // repeated .protobuf_unittest.ForeignEnum packed_enum = 103 [packed = true]; + inline int packed_enum_size() const; + inline void clear_packed_enum(); + static const int kPackedEnumFieldNumber = 103; + inline protobuf_unittest::ForeignEnum packed_enum(int index) const; + inline void set_packed_enum(int index, protobuf_unittest::ForeignEnum value); + inline void add_packed_enum(protobuf_unittest::ForeignEnum value); + inline const ::google::protobuf::RepeatedField& packed_enum() const; + inline ::google::protobuf::RepeatedField* mutable_packed_enum(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedTypes) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_int32_; + mutable int _packed_int32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_int64_; + mutable int _packed_int64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_uint32_; + mutable int _packed_uint32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_uint64_; + mutable int _packed_uint64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sint32_; + mutable int _packed_sint32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sint64_; + mutable int _packed_sint64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_fixed32_; + mutable int _packed_fixed32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_fixed64_; + mutable int _packed_fixed64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sfixed32_; + mutable int _packed_sfixed32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sfixed64_; + mutable int _packed_sfixed64_cached_byte_size_; + ::google::protobuf::RepeatedField< float > packed_float_; + mutable int _packed_float_cached_byte_size_; + ::google::protobuf::RepeatedField< double > packed_double_; + mutable int _packed_double_cached_byte_size_; + ::google::protobuf::RepeatedField< bool > packed_bool_; + mutable int _packed_bool_cached_byte_size_; + ::google::protobuf::RepeatedField packed_enum_; + mutable int _packed_enum_cached_byte_size_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(14 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestPackedTypes* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestUnpackedTypes : public ::google::protobuf::Message { + public: + TestUnpackedTypes(); + virtual ~TestUnpackedTypes(); + + TestUnpackedTypes(const TestUnpackedTypes& from); + + inline TestUnpackedTypes& operator=(const TestUnpackedTypes& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestUnpackedTypes& default_instance(); + + void Swap(TestUnpackedTypes* other); + + // implements Message ---------------------------------------------- + + TestUnpackedTypes* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestUnpackedTypes& from); + void MergeFrom(const TestUnpackedTypes& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated int32 unpacked_int32 = 90 [packed = false]; + inline int unpacked_int32_size() const; + inline void clear_unpacked_int32(); + static const int kUnpackedInt32FieldNumber = 90; + inline ::google::protobuf::int32 unpacked_int32(int index) const; + inline void set_unpacked_int32(int index, ::google::protobuf::int32 value); + inline void add_unpacked_int32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + unpacked_int32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_unpacked_int32(); + + // repeated int64 unpacked_int64 = 91 [packed = false]; + inline int unpacked_int64_size() const; + inline void clear_unpacked_int64(); + static const int kUnpackedInt64FieldNumber = 91; + inline ::google::protobuf::int64 unpacked_int64(int index) const; + inline void set_unpacked_int64(int index, ::google::protobuf::int64 value); + inline void add_unpacked_int64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + unpacked_int64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_unpacked_int64(); + + // repeated uint32 unpacked_uint32 = 92 [packed = false]; + inline int unpacked_uint32_size() const; + inline void clear_unpacked_uint32(); + static const int kUnpackedUint32FieldNumber = 92; + inline ::google::protobuf::uint32 unpacked_uint32(int index) const; + inline void set_unpacked_uint32(int index, ::google::protobuf::uint32 value); + inline void add_unpacked_uint32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + unpacked_uint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_unpacked_uint32(); + + // repeated uint64 unpacked_uint64 = 93 [packed = false]; + inline int unpacked_uint64_size() const; + inline void clear_unpacked_uint64(); + static const int kUnpackedUint64FieldNumber = 93; + inline ::google::protobuf::uint64 unpacked_uint64(int index) const; + inline void set_unpacked_uint64(int index, ::google::protobuf::uint64 value); + inline void add_unpacked_uint64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + unpacked_uint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_unpacked_uint64(); + + // repeated sint32 unpacked_sint32 = 94 [packed = false]; + inline int unpacked_sint32_size() const; + inline void clear_unpacked_sint32(); + static const int kUnpackedSint32FieldNumber = 94; + inline ::google::protobuf::int32 unpacked_sint32(int index) const; + inline void set_unpacked_sint32(int index, ::google::protobuf::int32 value); + inline void add_unpacked_sint32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + unpacked_sint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_unpacked_sint32(); + + // repeated sint64 unpacked_sint64 = 95 [packed = false]; + inline int unpacked_sint64_size() const; + inline void clear_unpacked_sint64(); + static const int kUnpackedSint64FieldNumber = 95; + inline ::google::protobuf::int64 unpacked_sint64(int index) const; + inline void set_unpacked_sint64(int index, ::google::protobuf::int64 value); + inline void add_unpacked_sint64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + unpacked_sint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_unpacked_sint64(); + + // repeated fixed32 unpacked_fixed32 = 96 [packed = false]; + inline int unpacked_fixed32_size() const; + inline void clear_unpacked_fixed32(); + static const int kUnpackedFixed32FieldNumber = 96; + inline ::google::protobuf::uint32 unpacked_fixed32(int index) const; + inline void set_unpacked_fixed32(int index, ::google::protobuf::uint32 value); + inline void add_unpacked_fixed32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + unpacked_fixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_unpacked_fixed32(); + + // repeated fixed64 unpacked_fixed64 = 97 [packed = false]; + inline int unpacked_fixed64_size() const; + inline void clear_unpacked_fixed64(); + static const int kUnpackedFixed64FieldNumber = 97; + inline ::google::protobuf::uint64 unpacked_fixed64(int index) const; + inline void set_unpacked_fixed64(int index, ::google::protobuf::uint64 value); + inline void add_unpacked_fixed64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + unpacked_fixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_unpacked_fixed64(); + + // repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; + inline int unpacked_sfixed32_size() const; + inline void clear_unpacked_sfixed32(); + static const int kUnpackedSfixed32FieldNumber = 98; + inline ::google::protobuf::int32 unpacked_sfixed32(int index) const; + inline void set_unpacked_sfixed32(int index, ::google::protobuf::int32 value); + inline void add_unpacked_sfixed32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + unpacked_sfixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_unpacked_sfixed32(); + + // repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; + inline int unpacked_sfixed64_size() const; + inline void clear_unpacked_sfixed64(); + static const int kUnpackedSfixed64FieldNumber = 99; + inline ::google::protobuf::int64 unpacked_sfixed64(int index) const; + inline void set_unpacked_sfixed64(int index, ::google::protobuf::int64 value); + inline void add_unpacked_sfixed64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + unpacked_sfixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_unpacked_sfixed64(); + + // repeated float unpacked_float = 100 [packed = false]; + inline int unpacked_float_size() const; + inline void clear_unpacked_float(); + static const int kUnpackedFloatFieldNumber = 100; + inline float unpacked_float(int index) const; + inline void set_unpacked_float(int index, float value); + inline void add_unpacked_float(float value); + inline const ::google::protobuf::RepeatedField< float >& + unpacked_float() const; + inline ::google::protobuf::RepeatedField< float >* + mutable_unpacked_float(); + + // repeated double unpacked_double = 101 [packed = false]; + inline int unpacked_double_size() const; + inline void clear_unpacked_double(); + static const int kUnpackedDoubleFieldNumber = 101; + inline double unpacked_double(int index) const; + inline void set_unpacked_double(int index, double value); + inline void add_unpacked_double(double value); + inline const ::google::protobuf::RepeatedField< double >& + unpacked_double() const; + inline ::google::protobuf::RepeatedField< double >* + mutable_unpacked_double(); + + // repeated bool unpacked_bool = 102 [packed = false]; + inline int unpacked_bool_size() const; + inline void clear_unpacked_bool(); + static const int kUnpackedBoolFieldNumber = 102; + inline bool unpacked_bool(int index) const; + inline void set_unpacked_bool(int index, bool value); + inline void add_unpacked_bool(bool value); + inline const ::google::protobuf::RepeatedField< bool >& + unpacked_bool() const; + inline ::google::protobuf::RepeatedField< bool >* + mutable_unpacked_bool(); + + // repeated .protobuf_unittest.ForeignEnum unpacked_enum = 103 [packed = false]; + inline int unpacked_enum_size() const; + inline void clear_unpacked_enum(); + static const int kUnpackedEnumFieldNumber = 103; + inline protobuf_unittest::ForeignEnum unpacked_enum(int index) const; + inline void set_unpacked_enum(int index, protobuf_unittest::ForeignEnum value); + inline void add_unpacked_enum(protobuf_unittest::ForeignEnum value); + inline const ::google::protobuf::RepeatedField& unpacked_enum() const; + inline ::google::protobuf::RepeatedField* mutable_unpacked_enum(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestUnpackedTypes) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > unpacked_int32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > unpacked_int64_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > unpacked_uint32_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > unpacked_uint64_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > unpacked_sint32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > unpacked_sint64_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > unpacked_fixed32_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > unpacked_fixed64_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > unpacked_sfixed32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > unpacked_sfixed64_; + ::google::protobuf::RepeatedField< float > unpacked_float_; + ::google::protobuf::RepeatedField< double > unpacked_double_; + ::google::protobuf::RepeatedField< bool > unpacked_bool_; + ::google::protobuf::RepeatedField unpacked_enum_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(14 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestUnpackedTypes* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestPackedExtensions : public ::google::protobuf::Message { + public: + TestPackedExtensions(); + virtual ~TestPackedExtensions(); + + TestPackedExtensions(const TestPackedExtensions& from); + + inline TestPackedExtensions& operator=(const TestPackedExtensions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestPackedExtensions& default_instance(); + + void Swap(TestPackedExtensions* other); + + // implements Message ---------------------------------------------- + + TestPackedExtensions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestPackedExtensions& from); + void MergeFrom(const TestPackedExtensions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestPackedExtensions) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedExtensions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestPackedExtensions* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestDynamicExtensions_DynamicMessageType : public ::google::protobuf::Message { + public: + TestDynamicExtensions_DynamicMessageType(); + virtual ~TestDynamicExtensions_DynamicMessageType(); + + TestDynamicExtensions_DynamicMessageType(const TestDynamicExtensions_DynamicMessageType& from); + + inline TestDynamicExtensions_DynamicMessageType& operator=(const TestDynamicExtensions_DynamicMessageType& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestDynamicExtensions_DynamicMessageType& default_instance(); + + void Swap(TestDynamicExtensions_DynamicMessageType* other); + + // implements Message ---------------------------------------------- + + TestDynamicExtensions_DynamicMessageType* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestDynamicExtensions_DynamicMessageType& from); + void MergeFrom(const TestDynamicExtensions_DynamicMessageType& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 dynamic_field = 2100; + inline bool has_dynamic_field() const; + inline void clear_dynamic_field(); + static const int kDynamicFieldFieldNumber = 2100; + inline ::google::protobuf::int32 dynamic_field() const; + inline void set_dynamic_field(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDynamicExtensions.DynamicMessageType) + private: + inline void set_has_dynamic_field(); + inline void clear_has_dynamic_field(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 dynamic_field_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestDynamicExtensions_DynamicMessageType* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestDynamicExtensions : public ::google::protobuf::Message { + public: + TestDynamicExtensions(); + virtual ~TestDynamicExtensions(); + + TestDynamicExtensions(const TestDynamicExtensions& from); + + inline TestDynamicExtensions& operator=(const TestDynamicExtensions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestDynamicExtensions& default_instance(); + + void Swap(TestDynamicExtensions* other); + + // implements Message ---------------------------------------------- + + TestDynamicExtensions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestDynamicExtensions& from); + void MergeFrom(const TestDynamicExtensions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef TestDynamicExtensions_DynamicMessageType DynamicMessageType; + + typedef TestDynamicExtensions_DynamicEnumType DynamicEnumType; + static const DynamicEnumType DYNAMIC_FOO = TestDynamicExtensions_DynamicEnumType_DYNAMIC_FOO; + static const DynamicEnumType DYNAMIC_BAR = TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAR; + static const DynamicEnumType DYNAMIC_BAZ = TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAZ; + static inline bool DynamicEnumType_IsValid(int value) { + return TestDynamicExtensions_DynamicEnumType_IsValid(value); + } + static const DynamicEnumType DynamicEnumType_MIN = + TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MIN; + static const DynamicEnumType DynamicEnumType_MAX = + TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MAX; + static const int DynamicEnumType_ARRAYSIZE = + TestDynamicExtensions_DynamicEnumType_DynamicEnumType_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + DynamicEnumType_descriptor() { + return TestDynamicExtensions_DynamicEnumType_descriptor(); + } + static inline const ::std::string& DynamicEnumType_Name(DynamicEnumType value) { + return TestDynamicExtensions_DynamicEnumType_Name(value); + } + static inline bool DynamicEnumType_Parse(const ::std::string& name, + DynamicEnumType* value) { + return TestDynamicExtensions_DynamicEnumType_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // optional fixed32 scalar_extension = 2000; + inline bool has_scalar_extension() const; + inline void clear_scalar_extension(); + static const int kScalarExtensionFieldNumber = 2000; + inline ::google::protobuf::uint32 scalar_extension() const; + inline void set_scalar_extension(::google::protobuf::uint32 value); + + // optional .protobuf_unittest.ForeignEnum enum_extension = 2001; + inline bool has_enum_extension() const; + inline void clear_enum_extension(); + static const int kEnumExtensionFieldNumber = 2001; + inline protobuf_unittest::ForeignEnum enum_extension() const; + inline void set_enum_extension(protobuf_unittest::ForeignEnum value); + + // optional .protobuf_unittest.TestDynamicExtensions.DynamicEnumType dynamic_enum_extension = 2002; + inline bool has_dynamic_enum_extension() const; + inline void clear_dynamic_enum_extension(); + static const int kDynamicEnumExtensionFieldNumber = 2002; + inline ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType dynamic_enum_extension() const; + inline void set_dynamic_enum_extension(::protobuf_unittest::TestDynamicExtensions_DynamicEnumType value); + + // optional .protobuf_unittest.ForeignMessage message_extension = 2003; + inline bool has_message_extension() const; + inline void clear_message_extension(); + static const int kMessageExtensionFieldNumber = 2003; + inline const ::protobuf_unittest::ForeignMessage& message_extension() const; + inline ::protobuf_unittest::ForeignMessage* mutable_message_extension(); + inline ::protobuf_unittest::ForeignMessage* release_message_extension(); + + // optional .protobuf_unittest.TestDynamicExtensions.DynamicMessageType dynamic_message_extension = 2004; + inline bool has_dynamic_message_extension() const; + inline void clear_dynamic_message_extension(); + static const int kDynamicMessageExtensionFieldNumber = 2004; + inline const ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType& dynamic_message_extension() const; + inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* mutable_dynamic_message_extension(); + inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* release_dynamic_message_extension(); + + // repeated string repeated_extension = 2005; + inline int repeated_extension_size() const; + inline void clear_repeated_extension(); + static const int kRepeatedExtensionFieldNumber = 2005; + inline const ::std::string& repeated_extension(int index) const; + inline ::std::string* mutable_repeated_extension(int index); + inline void set_repeated_extension(int index, const ::std::string& value); + inline void set_repeated_extension(int index, const char* value); + inline void set_repeated_extension(int index, const char* value, size_t size); + inline ::std::string* add_repeated_extension(); + inline void add_repeated_extension(const ::std::string& value); + inline void add_repeated_extension(const char* value); + inline void add_repeated_extension(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_extension() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_extension(); + + // repeated sint32 packed_extension = 2006 [packed = true]; + inline int packed_extension_size() const; + inline void clear_packed_extension(); + static const int kPackedExtensionFieldNumber = 2006; + inline ::google::protobuf::int32 packed_extension(int index) const; + inline void set_packed_extension(int index, ::google::protobuf::int32 value); + inline void add_packed_extension(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + packed_extension() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_packed_extension(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDynamicExtensions) + private: + inline void set_has_scalar_extension(); + inline void clear_has_scalar_extension(); + inline void set_has_enum_extension(); + inline void clear_has_enum_extension(); + inline void set_has_dynamic_enum_extension(); + inline void clear_has_dynamic_enum_extension(); + inline void set_has_message_extension(); + inline void clear_has_message_extension(); + inline void set_has_dynamic_message_extension(); + inline void clear_has_dynamic_message_extension(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::uint32 scalar_extension_; + int enum_extension_; + ::protobuf_unittest::ForeignMessage* message_extension_; + ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* dynamic_message_extension_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_extension_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_extension_; + mutable int _packed_extension_cached_byte_size_; + int dynamic_enum_extension_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(7 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestDynamicExtensions* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestRepeatedScalarDifferentTagSizes : public ::google::protobuf::Message { + public: + TestRepeatedScalarDifferentTagSizes(); + virtual ~TestRepeatedScalarDifferentTagSizes(); + + TestRepeatedScalarDifferentTagSizes(const TestRepeatedScalarDifferentTagSizes& from); + + inline TestRepeatedScalarDifferentTagSizes& operator=(const TestRepeatedScalarDifferentTagSizes& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestRepeatedScalarDifferentTagSizes& default_instance(); + + void Swap(TestRepeatedScalarDifferentTagSizes* other); + + // implements Message ---------------------------------------------- + + TestRepeatedScalarDifferentTagSizes* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestRepeatedScalarDifferentTagSizes& from); + void MergeFrom(const TestRepeatedScalarDifferentTagSizes& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated fixed32 repeated_fixed32 = 12; + inline int repeated_fixed32_size() const; + inline void clear_repeated_fixed32(); + static const int kRepeatedFixed32FieldNumber = 12; + inline ::google::protobuf::uint32 repeated_fixed32(int index) const; + inline void set_repeated_fixed32(int index, ::google::protobuf::uint32 value); + inline void add_repeated_fixed32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + repeated_fixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_repeated_fixed32(); + + // repeated int32 repeated_int32 = 13; + inline int repeated_int32_size() const; + inline void clear_repeated_int32(); + static const int kRepeatedInt32FieldNumber = 13; + inline ::google::protobuf::int32 repeated_int32(int index) const; + inline void set_repeated_int32(int index, ::google::protobuf::int32 value); + inline void add_repeated_int32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeated_int32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeated_int32(); + + // repeated fixed64 repeated_fixed64 = 2046; + inline int repeated_fixed64_size() const; + inline void clear_repeated_fixed64(); + static const int kRepeatedFixed64FieldNumber = 2046; + inline ::google::protobuf::uint64 repeated_fixed64(int index) const; + inline void set_repeated_fixed64(int index, ::google::protobuf::uint64 value); + inline void add_repeated_fixed64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + repeated_fixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_repeated_fixed64(); + + // repeated int64 repeated_int64 = 2047; + inline int repeated_int64_size() const; + inline void clear_repeated_int64(); + static const int kRepeatedInt64FieldNumber = 2047; + inline ::google::protobuf::int64 repeated_int64(int index) const; + inline void set_repeated_int64(int index, ::google::protobuf::int64 value); + inline void add_repeated_int64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + repeated_int64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_repeated_int64(); + + // repeated float repeated_float = 262142; + inline int repeated_float_size() const; + inline void clear_repeated_float(); + static const int kRepeatedFloatFieldNumber = 262142; + inline float repeated_float(int index) const; + inline void set_repeated_float(int index, float value); + inline void add_repeated_float(float value); + inline const ::google::protobuf::RepeatedField< float >& + repeated_float() const; + inline ::google::protobuf::RepeatedField< float >* + mutable_repeated_float(); + + // repeated uint64 repeated_uint64 = 262143; + inline int repeated_uint64_size() const; + inline void clear_repeated_uint64(); + static const int kRepeatedUint64FieldNumber = 262143; + inline ::google::protobuf::uint64 repeated_uint64(int index) const; + inline void set_repeated_uint64(int index, ::google::protobuf::uint64 value); + inline void add_repeated_uint64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + repeated_uint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_repeated_uint64(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRepeatedScalarDifferentTagSizes) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_fixed32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_int32_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_fixed64_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_int64_; + ::google::protobuf::RepeatedField< float > repeated_float_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_uint64_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(6 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static TestRepeatedScalarDifferentTagSizes* default_instance_; +}; +// ------------------------------------------------------------------- + +class FooRequest : public ::google::protobuf::Message { + public: + FooRequest(); + virtual ~FooRequest(); + + FooRequest(const FooRequest& from); + + inline FooRequest& operator=(const FooRequest& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FooRequest& default_instance(); + + void Swap(FooRequest* other); + + // implements Message ---------------------------------------------- + + FooRequest* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const FooRequest& from); + void MergeFrom(const FooRequest& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.FooRequest) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static FooRequest* default_instance_; +}; +// ------------------------------------------------------------------- + +class FooResponse : public ::google::protobuf::Message { + public: + FooResponse(); + virtual ~FooResponse(); + + FooResponse(const FooResponse& from); + + inline FooResponse& operator=(const FooResponse& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FooResponse& default_instance(); + + void Swap(FooResponse* other); + + // implements Message ---------------------------------------------- + + FooResponse* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const FooResponse& from); + void MergeFrom(const FooResponse& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.FooResponse) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static FooResponse* default_instance_; +}; +// ------------------------------------------------------------------- + +class BarRequest : public ::google::protobuf::Message { + public: + BarRequest(); + virtual ~BarRequest(); + + BarRequest(const BarRequest& from); + + inline BarRequest& operator=(const BarRequest& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const BarRequest& default_instance(); + + void Swap(BarRequest* other); + + // implements Message ---------------------------------------------- + + BarRequest* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const BarRequest& from); + void MergeFrom(const BarRequest& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.BarRequest) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static BarRequest* default_instance_; +}; +// ------------------------------------------------------------------- + +class BarResponse : public ::google::protobuf::Message { + public: + BarResponse(); + virtual ~BarResponse(); + + BarResponse(const BarResponse& from); + + inline BarResponse& operator=(const BarResponse& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const BarResponse& default_instance(); + + void Swap(BarResponse* other); + + // implements Message ---------------------------------------------- + + BarResponse* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const BarResponse& from); + void MergeFrom(const BarResponse& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.BarResponse) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); + + void InitAsDefaultInstance(); + static BarResponse* default_instance_; +}; +// =================================================================== + +class TestService_Stub; + +class TestService : public ::google::protobuf::Service { + protected: + // This class should be treated as an abstract interface. + inline TestService() {}; + public: + virtual ~TestService(); + + typedef TestService_Stub Stub; + + static const ::google::protobuf::ServiceDescriptor* descriptor(); + + virtual void Foo(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::FooRequest* request, + ::protobuf_unittest::FooResponse* response, + ::google::protobuf::Closure* done); + virtual void Bar(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::BarRequest* request, + ::protobuf_unittest::BarResponse* response, + ::google::protobuf::Closure* done); + + // implements Service ---------------------------------------------- + + const ::google::protobuf::ServiceDescriptor* GetDescriptor(); + void CallMethod(const ::google::protobuf::MethodDescriptor* method, + ::google::protobuf::RpcController* controller, + const ::google::protobuf::Message* request, + ::google::protobuf::Message* response, + ::google::protobuf::Closure* done); + const ::google::protobuf::Message& GetRequestPrototype( + const ::google::protobuf::MethodDescriptor* method) const; + const ::google::protobuf::Message& GetResponsePrototype( + const ::google::protobuf::MethodDescriptor* method) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestService); +}; + +class TestService_Stub : public TestService { + public: + TestService_Stub(::google::protobuf::RpcChannel* channel); + TestService_Stub(::google::protobuf::RpcChannel* channel, + ::google::protobuf::Service::ChannelOwnership ownership); + ~TestService_Stub(); + + inline ::google::protobuf::RpcChannel* channel() { return channel_; } + + // implements TestService ------------------------------------------ + + void Foo(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::FooRequest* request, + ::protobuf_unittest::FooResponse* response, + ::google::protobuf::Closure* done); + void Bar(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::BarRequest* request, + ::protobuf_unittest::BarResponse* response, + ::google::protobuf::Closure* done); + private: + ::google::protobuf::RpcChannel* channel_; + bool owns_channel_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestService_Stub); +}; + + +// =================================================================== + +static const int kOptionalInt32ExtensionFieldNumber = 1; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + optional_int32_extension; +static const int kOptionalInt64ExtensionFieldNumber = 2; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > + optional_int64_extension; +static const int kOptionalUint32ExtensionFieldNumber = 3; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > + optional_uint32_extension; +static const int kOptionalUint64ExtensionFieldNumber = 4; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + optional_uint64_extension; +static const int kOptionalSint32ExtensionFieldNumber = 5; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > + optional_sint32_extension; +static const int kOptionalSint64ExtensionFieldNumber = 6; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + optional_sint64_extension; +static const int kOptionalFixed32ExtensionFieldNumber = 7; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > + optional_fixed32_extension; +static const int kOptionalFixed64ExtensionFieldNumber = 8; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + optional_fixed64_extension; +static const int kOptionalSfixed32ExtensionFieldNumber = 9; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + optional_sfixed32_extension; +static const int kOptionalSfixed64ExtensionFieldNumber = 10; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > + optional_sfixed64_extension; +static const int kOptionalFloatExtensionFieldNumber = 11; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > + optional_float_extension; +static const int kOptionalDoubleExtensionFieldNumber = 12; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > + optional_double_extension; +static const int kOptionalBoolExtensionFieldNumber = 13; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > + optional_bool_extension; +static const int kOptionalStringExtensionFieldNumber = 14; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + optional_string_extension; +static const int kOptionalBytesExtensionFieldNumber = 15; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 12, false > + optional_bytes_extension; +static const int kOptionalgroupExtensionFieldNumber = 16; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::OptionalGroup_extension >, 10, false > + optionalgroup_extension; +static const int kOptionalNestedMessageExtensionFieldNumber = 18; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestAllTypes_NestedMessage >, 11, false > + optional_nested_message_extension; +static const int kOptionalForeignMessageExtensionFieldNumber = 19; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ForeignMessage >, 11, false > + optional_foreign_message_extension; +static const int kOptionalImportMessageExtensionFieldNumber = 20; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest_import::ImportMessage >, 11, false > + optional_import_message_extension; +static const int kOptionalNestedEnumExtensionFieldNumber = 21; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypes_NestedEnum, ::protobuf_unittest::TestAllTypes_NestedEnum_IsValid>, 14, false > + optional_nested_enum_extension; +static const int kOptionalForeignEnumExtensionFieldNumber = 22; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, false > + optional_foreign_enum_extension; +static const int kOptionalImportEnumExtensionFieldNumber = 23; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnum, protobuf_unittest_import::ImportEnum_IsValid>, 14, false > + optional_import_enum_extension; +static const int kOptionalStringPieceExtensionFieldNumber = 24; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + optional_string_piece_extension; +static const int kOptionalCordExtensionFieldNumber = 25; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + optional_cord_extension; +static const int kRepeatedInt32ExtensionFieldNumber = 31; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + repeated_int32_extension; +static const int kRepeatedInt64ExtensionFieldNumber = 32; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > + repeated_int64_extension; +static const int kRepeatedUint32ExtensionFieldNumber = 33; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > + repeated_uint32_extension; +static const int kRepeatedUint64ExtensionFieldNumber = 34; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + repeated_uint64_extension; +static const int kRepeatedSint32ExtensionFieldNumber = 35; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > + repeated_sint32_extension; +static const int kRepeatedSint64ExtensionFieldNumber = 36; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + repeated_sint64_extension; +static const int kRepeatedFixed32ExtensionFieldNumber = 37; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > + repeated_fixed32_extension; +static const int kRepeatedFixed64ExtensionFieldNumber = 38; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + repeated_fixed64_extension; +static const int kRepeatedSfixed32ExtensionFieldNumber = 39; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + repeated_sfixed32_extension; +static const int kRepeatedSfixed64ExtensionFieldNumber = 40; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > + repeated_sfixed64_extension; +static const int kRepeatedFloatExtensionFieldNumber = 41; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, false > + repeated_float_extension; +static const int kRepeatedDoubleExtensionFieldNumber = 42; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, false > + repeated_double_extension; +static const int kRepeatedBoolExtensionFieldNumber = 43; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, false > + repeated_bool_extension; +static const int kRepeatedStringExtensionFieldNumber = 44; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > + repeated_string_extension; +static const int kRepeatedBytesExtensionFieldNumber = 45; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedStringTypeTraits, 12, false > + repeated_bytes_extension; +static const int kRepeatedgroupExtensionFieldNumber = 46; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::RepeatedGroup_extension >, 10, false > + repeatedgroup_extension; +static const int kRepeatedNestedMessageExtensionFieldNumber = 48; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::TestAllTypes_NestedMessage >, 11, false > + repeated_nested_message_extension; +static const int kRepeatedForeignMessageExtensionFieldNumber = 49; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::ForeignMessage >, 11, false > + repeated_foreign_message_extension; +static const int kRepeatedImportMessageExtensionFieldNumber = 50; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest_import::ImportMessage >, 11, false > + repeated_import_message_extension; +static const int kRepeatedNestedEnumExtensionFieldNumber = 51; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedEnumTypeTraits< ::protobuf_unittest::TestAllTypes_NestedEnum, ::protobuf_unittest::TestAllTypes_NestedEnum_IsValid>, 14, false > + repeated_nested_enum_extension; +static const int kRepeatedForeignEnumExtensionFieldNumber = 52; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, false > + repeated_foreign_enum_extension; +static const int kRepeatedImportEnumExtensionFieldNumber = 53; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest_import::ImportEnum, protobuf_unittest_import::ImportEnum_IsValid>, 14, false > + repeated_import_enum_extension; +static const int kRepeatedStringPieceExtensionFieldNumber = 54; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > + repeated_string_piece_extension; +static const int kRepeatedCordExtensionFieldNumber = 55; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > + repeated_cord_extension; +static const int kDefaultInt32ExtensionFieldNumber = 61; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + default_int32_extension; +static const int kDefaultInt64ExtensionFieldNumber = 62; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > + default_int64_extension; +static const int kDefaultUint32ExtensionFieldNumber = 63; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > + default_uint32_extension; +static const int kDefaultUint64ExtensionFieldNumber = 64; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + default_uint64_extension; +static const int kDefaultSint32ExtensionFieldNumber = 65; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > + default_sint32_extension; +static const int kDefaultSint64ExtensionFieldNumber = 66; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + default_sint64_extension; +static const int kDefaultFixed32ExtensionFieldNumber = 67; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > + default_fixed32_extension; +static const int kDefaultFixed64ExtensionFieldNumber = 68; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + default_fixed64_extension; +static const int kDefaultSfixed32ExtensionFieldNumber = 69; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + default_sfixed32_extension; +static const int kDefaultSfixed64ExtensionFieldNumber = 70; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > + default_sfixed64_extension; +static const int kDefaultFloatExtensionFieldNumber = 71; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > + default_float_extension; +static const int kDefaultDoubleExtensionFieldNumber = 72; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > + default_double_extension; +static const int kDefaultBoolExtensionFieldNumber = 73; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > + default_bool_extension; +static const int kDefaultStringExtensionFieldNumber = 74; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + default_string_extension; +static const int kDefaultBytesExtensionFieldNumber = 75; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 12, false > + default_bytes_extension; +static const int kDefaultNestedEnumExtensionFieldNumber = 81; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypes_NestedEnum, ::protobuf_unittest::TestAllTypes_NestedEnum_IsValid>, 14, false > + default_nested_enum_extension; +static const int kDefaultForeignEnumExtensionFieldNumber = 82; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, false > + default_foreign_enum_extension; +static const int kDefaultImportEnumExtensionFieldNumber = 83; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnum, protobuf_unittest_import::ImportEnum_IsValid>, 14, false > + default_import_enum_extension; +static const int kDefaultStringPieceExtensionFieldNumber = 84; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + default_string_piece_extension; +static const int kDefaultCordExtensionFieldNumber = 85; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + default_cord_extension; +static const int kMyExtensionStringFieldNumber = 50; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestFieldOrderings, + ::google::protobuf::internal::StringTypeTraits, 9, false > + my_extension_string; +static const int kMyExtensionIntFieldNumber = 5; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestFieldOrderings, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + my_extension_int; +static const int kPackedInt32ExtensionFieldNumber = 90; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, true > + packed_int32_extension; +static const int kPackedInt64ExtensionFieldNumber = 91; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, true > + packed_int64_extension; +static const int kPackedUint32ExtensionFieldNumber = 92; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, true > + packed_uint32_extension; +static const int kPackedUint64ExtensionFieldNumber = 93; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, true > + packed_uint64_extension; +static const int kPackedSint32ExtensionFieldNumber = 94; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, true > + packed_sint32_extension; +static const int kPackedSint64ExtensionFieldNumber = 95; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, true > + packed_sint64_extension; +static const int kPackedFixed32ExtensionFieldNumber = 96; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, true > + packed_fixed32_extension; +static const int kPackedFixed64ExtensionFieldNumber = 97; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, true > + packed_fixed64_extension; +static const int kPackedSfixed32ExtensionFieldNumber = 98; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, true > + packed_sfixed32_extension; +static const int kPackedSfixed64ExtensionFieldNumber = 99; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, true > + packed_sfixed64_extension; +static const int kPackedFloatExtensionFieldNumber = 100; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, true > + packed_float_extension; +static const int kPackedDoubleExtensionFieldNumber = 101; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, true > + packed_double_extension; +static const int kPackedBoolExtensionFieldNumber = 102; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, true > + packed_bool_extension; +static const int kPackedEnumExtensionFieldNumber = 103; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, + ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, true > + packed_enum_extension; + +// =================================================================== + +// TestAllTypes_NestedMessage + +// optional int32 bb = 1; +inline bool TestAllTypes_NestedMessage::has_bb() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypes_NestedMessage::set_has_bb() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypes_NestedMessage::clear_has_bb() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypes_NestedMessage::clear_bb() { + bb_ = 0; + clear_has_bb(); +} +inline ::google::protobuf::int32 TestAllTypes_NestedMessage::bb() const { + return bb_; +} +inline void TestAllTypes_NestedMessage::set_bb(::google::protobuf::int32 value) { + set_has_bb(); + bb_ = value; +} + +// ------------------------------------------------------------------- + +// TestAllTypes_OptionalGroup + +// optional int32 a = 17; +inline bool TestAllTypes_OptionalGroup::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypes_OptionalGroup::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypes_OptionalGroup::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypes_OptionalGroup::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestAllTypes_OptionalGroup::a() const { + return a_; +} +inline void TestAllTypes_OptionalGroup::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestAllTypes_RepeatedGroup + +// optional int32 a = 47; +inline bool TestAllTypes_RepeatedGroup::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypes_RepeatedGroup::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypes_RepeatedGroup::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypes_RepeatedGroup::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestAllTypes_RepeatedGroup::a() const { + return a_; +} +inline void TestAllTypes_RepeatedGroup::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestAllTypes + +// optional int32 optional_int32 = 1; +inline bool TestAllTypes::has_optional_int32() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypes::set_has_optional_int32() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypes::clear_has_optional_int32() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypes::clear_optional_int32() { + optional_int32_ = 0; + clear_has_optional_int32(); +} +inline ::google::protobuf::int32 TestAllTypes::optional_int32() const { + return optional_int32_; +} +inline void TestAllTypes::set_optional_int32(::google::protobuf::int32 value) { + set_has_optional_int32(); + optional_int32_ = value; +} + +// optional int64 optional_int64 = 2; +inline bool TestAllTypes::has_optional_int64() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestAllTypes::set_has_optional_int64() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestAllTypes::clear_has_optional_int64() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestAllTypes::clear_optional_int64() { + optional_int64_ = GOOGLE_LONGLONG(0); + clear_has_optional_int64(); +} +inline ::google::protobuf::int64 TestAllTypes::optional_int64() const { + return optional_int64_; +} +inline void TestAllTypes::set_optional_int64(::google::protobuf::int64 value) { + set_has_optional_int64(); + optional_int64_ = value; +} + +// optional uint32 optional_uint32 = 3; +inline bool TestAllTypes::has_optional_uint32() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestAllTypes::set_has_optional_uint32() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestAllTypes::clear_has_optional_uint32() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestAllTypes::clear_optional_uint32() { + optional_uint32_ = 0u; + clear_has_optional_uint32(); +} +inline ::google::protobuf::uint32 TestAllTypes::optional_uint32() const { + return optional_uint32_; +} +inline void TestAllTypes::set_optional_uint32(::google::protobuf::uint32 value) { + set_has_optional_uint32(); + optional_uint32_ = value; +} + +// optional uint64 optional_uint64 = 4; +inline bool TestAllTypes::has_optional_uint64() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void TestAllTypes::set_has_optional_uint64() { + _has_bits_[0] |= 0x00000008u; +} +inline void TestAllTypes::clear_has_optional_uint64() { + _has_bits_[0] &= ~0x00000008u; +} +inline void TestAllTypes::clear_optional_uint64() { + optional_uint64_ = GOOGLE_ULONGLONG(0); + clear_has_optional_uint64(); +} +inline ::google::protobuf::uint64 TestAllTypes::optional_uint64() const { + return optional_uint64_; +} +inline void TestAllTypes::set_optional_uint64(::google::protobuf::uint64 value) { + set_has_optional_uint64(); + optional_uint64_ = value; +} + +// optional sint32 optional_sint32 = 5; +inline bool TestAllTypes::has_optional_sint32() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void TestAllTypes::set_has_optional_sint32() { + _has_bits_[0] |= 0x00000010u; +} +inline void TestAllTypes::clear_has_optional_sint32() { + _has_bits_[0] &= ~0x00000010u; +} +inline void TestAllTypes::clear_optional_sint32() { + optional_sint32_ = 0; + clear_has_optional_sint32(); +} +inline ::google::protobuf::int32 TestAllTypes::optional_sint32() const { + return optional_sint32_; +} +inline void TestAllTypes::set_optional_sint32(::google::protobuf::int32 value) { + set_has_optional_sint32(); + optional_sint32_ = value; +} + +// optional sint64 optional_sint64 = 6; +inline bool TestAllTypes::has_optional_sint64() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void TestAllTypes::set_has_optional_sint64() { + _has_bits_[0] |= 0x00000020u; +} +inline void TestAllTypes::clear_has_optional_sint64() { + _has_bits_[0] &= ~0x00000020u; +} +inline void TestAllTypes::clear_optional_sint64() { + optional_sint64_ = GOOGLE_LONGLONG(0); + clear_has_optional_sint64(); +} +inline ::google::protobuf::int64 TestAllTypes::optional_sint64() const { + return optional_sint64_; +} +inline void TestAllTypes::set_optional_sint64(::google::protobuf::int64 value) { + set_has_optional_sint64(); + optional_sint64_ = value; +} + +// optional fixed32 optional_fixed32 = 7; +inline bool TestAllTypes::has_optional_fixed32() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void TestAllTypes::set_has_optional_fixed32() { + _has_bits_[0] |= 0x00000040u; +} +inline void TestAllTypes::clear_has_optional_fixed32() { + _has_bits_[0] &= ~0x00000040u; +} +inline void TestAllTypes::clear_optional_fixed32() { + optional_fixed32_ = 0u; + clear_has_optional_fixed32(); +} +inline ::google::protobuf::uint32 TestAllTypes::optional_fixed32() const { + return optional_fixed32_; +} +inline void TestAllTypes::set_optional_fixed32(::google::protobuf::uint32 value) { + set_has_optional_fixed32(); + optional_fixed32_ = value; +} + +// optional fixed64 optional_fixed64 = 8; +inline bool TestAllTypes::has_optional_fixed64() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void TestAllTypes::set_has_optional_fixed64() { + _has_bits_[0] |= 0x00000080u; +} +inline void TestAllTypes::clear_has_optional_fixed64() { + _has_bits_[0] &= ~0x00000080u; +} +inline void TestAllTypes::clear_optional_fixed64() { + optional_fixed64_ = GOOGLE_ULONGLONG(0); + clear_has_optional_fixed64(); +} +inline ::google::protobuf::uint64 TestAllTypes::optional_fixed64() const { + return optional_fixed64_; +} +inline void TestAllTypes::set_optional_fixed64(::google::protobuf::uint64 value) { + set_has_optional_fixed64(); + optional_fixed64_ = value; +} + +// optional sfixed32 optional_sfixed32 = 9; +inline bool TestAllTypes::has_optional_sfixed32() const { + return (_has_bits_[0] & 0x00000100u) != 0; +} +inline void TestAllTypes::set_has_optional_sfixed32() { + _has_bits_[0] |= 0x00000100u; +} +inline void TestAllTypes::clear_has_optional_sfixed32() { + _has_bits_[0] &= ~0x00000100u; +} +inline void TestAllTypes::clear_optional_sfixed32() { + optional_sfixed32_ = 0; + clear_has_optional_sfixed32(); +} +inline ::google::protobuf::int32 TestAllTypes::optional_sfixed32() const { + return optional_sfixed32_; +} +inline void TestAllTypes::set_optional_sfixed32(::google::protobuf::int32 value) { + set_has_optional_sfixed32(); + optional_sfixed32_ = value; +} + +// optional sfixed64 optional_sfixed64 = 10; +inline bool TestAllTypes::has_optional_sfixed64() const { + return (_has_bits_[0] & 0x00000200u) != 0; +} +inline void TestAllTypes::set_has_optional_sfixed64() { + _has_bits_[0] |= 0x00000200u; +} +inline void TestAllTypes::clear_has_optional_sfixed64() { + _has_bits_[0] &= ~0x00000200u; +} +inline void TestAllTypes::clear_optional_sfixed64() { + optional_sfixed64_ = GOOGLE_LONGLONG(0); + clear_has_optional_sfixed64(); +} +inline ::google::protobuf::int64 TestAllTypes::optional_sfixed64() const { + return optional_sfixed64_; +} +inline void TestAllTypes::set_optional_sfixed64(::google::protobuf::int64 value) { + set_has_optional_sfixed64(); + optional_sfixed64_ = value; +} + +// optional float optional_float = 11; +inline bool TestAllTypes::has_optional_float() const { + return (_has_bits_[0] & 0x00000400u) != 0; +} +inline void TestAllTypes::set_has_optional_float() { + _has_bits_[0] |= 0x00000400u; +} +inline void TestAllTypes::clear_has_optional_float() { + _has_bits_[0] &= ~0x00000400u; +} +inline void TestAllTypes::clear_optional_float() { + optional_float_ = 0; + clear_has_optional_float(); +} +inline float TestAllTypes::optional_float() const { + return optional_float_; +} +inline void TestAllTypes::set_optional_float(float value) { + set_has_optional_float(); + optional_float_ = value; +} + +// optional double optional_double = 12; +inline bool TestAllTypes::has_optional_double() const { + return (_has_bits_[0] & 0x00000800u) != 0; +} +inline void TestAllTypes::set_has_optional_double() { + _has_bits_[0] |= 0x00000800u; +} +inline void TestAllTypes::clear_has_optional_double() { + _has_bits_[0] &= ~0x00000800u; +} +inline void TestAllTypes::clear_optional_double() { + optional_double_ = 0; + clear_has_optional_double(); +} +inline double TestAllTypes::optional_double() const { + return optional_double_; +} +inline void TestAllTypes::set_optional_double(double value) { + set_has_optional_double(); + optional_double_ = value; +} + +// optional bool optional_bool = 13; +inline bool TestAllTypes::has_optional_bool() const { + return (_has_bits_[0] & 0x00001000u) != 0; +} +inline void TestAllTypes::set_has_optional_bool() { + _has_bits_[0] |= 0x00001000u; +} +inline void TestAllTypes::clear_has_optional_bool() { + _has_bits_[0] &= ~0x00001000u; +} +inline void TestAllTypes::clear_optional_bool() { + optional_bool_ = false; + clear_has_optional_bool(); +} +inline bool TestAllTypes::optional_bool() const { + return optional_bool_; +} +inline void TestAllTypes::set_optional_bool(bool value) { + set_has_optional_bool(); + optional_bool_ = value; +} + +// optional string optional_string = 14; +inline bool TestAllTypes::has_optional_string() const { + return (_has_bits_[0] & 0x00002000u) != 0; +} +inline void TestAllTypes::set_has_optional_string() { + _has_bits_[0] |= 0x00002000u; +} +inline void TestAllTypes::clear_has_optional_string() { + _has_bits_[0] &= ~0x00002000u; +} +inline void TestAllTypes::clear_optional_string() { + if (optional_string_ != &::google::protobuf::internal::kEmptyString) { + optional_string_->clear(); + } + clear_has_optional_string(); +} +inline const ::std::string& TestAllTypes::optional_string() const { + return *optional_string_; +} +inline void TestAllTypes::set_optional_string(const ::std::string& value) { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + optional_string_->assign(value); +} +inline void TestAllTypes::set_optional_string(const char* value) { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + optional_string_->assign(value); +} +inline void TestAllTypes::set_optional_string(const char* value, size_t size) { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + optional_string_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_optional_string() { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + return optional_string_; +} +inline ::std::string* TestAllTypes::release_optional_string() { + clear_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_string_; + optional_string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional bytes optional_bytes = 15; +inline bool TestAllTypes::has_optional_bytes() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +inline void TestAllTypes::set_has_optional_bytes() { + _has_bits_[0] |= 0x00004000u; +} +inline void TestAllTypes::clear_has_optional_bytes() { + _has_bits_[0] &= ~0x00004000u; +} +inline void TestAllTypes::clear_optional_bytes() { + if (optional_bytes_ != &::google::protobuf::internal::kEmptyString) { + optional_bytes_->clear(); + } + clear_has_optional_bytes(); +} +inline const ::std::string& TestAllTypes::optional_bytes() const { + return *optional_bytes_; +} +inline void TestAllTypes::set_optional_bytes(const ::std::string& value) { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + optional_bytes_->assign(value); +} +inline void TestAllTypes::set_optional_bytes(const char* value) { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + optional_bytes_->assign(value); +} +inline void TestAllTypes::set_optional_bytes(const void* value, size_t size) { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + optional_bytes_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_optional_bytes() { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + return optional_bytes_; +} +inline ::std::string* TestAllTypes::release_optional_bytes() { + clear_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_bytes_; + optional_bytes_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional group OptionalGroup = 16 { +inline bool TestAllTypes::has_optionalgroup() const { + return (_has_bits_[0] & 0x00008000u) != 0; +} +inline void TestAllTypes::set_has_optionalgroup() { + _has_bits_[0] |= 0x00008000u; +} +inline void TestAllTypes::clear_has_optionalgroup() { + _has_bits_[0] &= ~0x00008000u; +} +inline void TestAllTypes::clear_optionalgroup() { + if (optionalgroup_ != NULL) optionalgroup_->::protobuf_unittest::TestAllTypes_OptionalGroup::Clear(); + clear_has_optionalgroup(); +} +inline const ::protobuf_unittest::TestAllTypes_OptionalGroup& TestAllTypes::optionalgroup() const { + return optionalgroup_ != NULL ? *optionalgroup_ : *default_instance_->optionalgroup_; +} +inline ::protobuf_unittest::TestAllTypes_OptionalGroup* TestAllTypes::mutable_optionalgroup() { + set_has_optionalgroup(); + if (optionalgroup_ == NULL) optionalgroup_ = new ::protobuf_unittest::TestAllTypes_OptionalGroup; + return optionalgroup_; +} +inline ::protobuf_unittest::TestAllTypes_OptionalGroup* TestAllTypes::release_optionalgroup() { + clear_has_optionalgroup(); + ::protobuf_unittest::TestAllTypes_OptionalGroup* temp = optionalgroup_; + optionalgroup_ = NULL; + return temp; +} + +// optional .protobuf_unittest.TestAllTypes.NestedMessage optional_nested_message = 18; +inline bool TestAllTypes::has_optional_nested_message() const { + return (_has_bits_[0] & 0x00010000u) != 0; +} +inline void TestAllTypes::set_has_optional_nested_message() { + _has_bits_[0] |= 0x00010000u; +} +inline void TestAllTypes::clear_has_optional_nested_message() { + _has_bits_[0] &= ~0x00010000u; +} +inline void TestAllTypes::clear_optional_nested_message() { + if (optional_nested_message_ != NULL) optional_nested_message_->::protobuf_unittest::TestAllTypes_NestedMessage::Clear(); + clear_has_optional_nested_message(); +} +inline const ::protobuf_unittest::TestAllTypes_NestedMessage& TestAllTypes::optional_nested_message() const { + return optional_nested_message_ != NULL ? *optional_nested_message_ : *default_instance_->optional_nested_message_; +} +inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::mutable_optional_nested_message() { + set_has_optional_nested_message(); + if (optional_nested_message_ == NULL) optional_nested_message_ = new ::protobuf_unittest::TestAllTypes_NestedMessage; + return optional_nested_message_; +} +inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::release_optional_nested_message() { + clear_has_optional_nested_message(); + ::protobuf_unittest::TestAllTypes_NestedMessage* temp = optional_nested_message_; + optional_nested_message_ = NULL; + return temp; +} + +// optional .protobuf_unittest.ForeignMessage optional_foreign_message = 19; +inline bool TestAllTypes::has_optional_foreign_message() const { + return (_has_bits_[0] & 0x00020000u) != 0; +} +inline void TestAllTypes::set_has_optional_foreign_message() { + _has_bits_[0] |= 0x00020000u; +} +inline void TestAllTypes::clear_has_optional_foreign_message() { + _has_bits_[0] &= ~0x00020000u; +} +inline void TestAllTypes::clear_optional_foreign_message() { + if (optional_foreign_message_ != NULL) optional_foreign_message_->::protobuf_unittest::ForeignMessage::Clear(); + clear_has_optional_foreign_message(); +} +inline const ::protobuf_unittest::ForeignMessage& TestAllTypes::optional_foreign_message() const { + return optional_foreign_message_ != NULL ? *optional_foreign_message_ : *default_instance_->optional_foreign_message_; +} +inline ::protobuf_unittest::ForeignMessage* TestAllTypes::mutable_optional_foreign_message() { + set_has_optional_foreign_message(); + if (optional_foreign_message_ == NULL) optional_foreign_message_ = new ::protobuf_unittest::ForeignMessage; + return optional_foreign_message_; +} +inline ::protobuf_unittest::ForeignMessage* TestAllTypes::release_optional_foreign_message() { + clear_has_optional_foreign_message(); + ::protobuf_unittest::ForeignMessage* temp = optional_foreign_message_; + optional_foreign_message_ = NULL; + return temp; +} + +// optional .protobuf_unittest_import.ImportMessage optional_import_message = 20; +inline bool TestAllTypes::has_optional_import_message() const { + return (_has_bits_[0] & 0x00040000u) != 0; +} +inline void TestAllTypes::set_has_optional_import_message() { + _has_bits_[0] |= 0x00040000u; +} +inline void TestAllTypes::clear_has_optional_import_message() { + _has_bits_[0] &= ~0x00040000u; +} +inline void TestAllTypes::clear_optional_import_message() { + if (optional_import_message_ != NULL) optional_import_message_->::protobuf_unittest_import::ImportMessage::Clear(); + clear_has_optional_import_message(); +} +inline const ::protobuf_unittest_import::ImportMessage& TestAllTypes::optional_import_message() const { + return optional_import_message_ != NULL ? *optional_import_message_ : *default_instance_->optional_import_message_; +} +inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::mutable_optional_import_message() { + set_has_optional_import_message(); + if (optional_import_message_ == NULL) optional_import_message_ = new ::protobuf_unittest_import::ImportMessage; + return optional_import_message_; +} +inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::release_optional_import_message() { + clear_has_optional_import_message(); + ::protobuf_unittest_import::ImportMessage* temp = optional_import_message_; + optional_import_message_ = NULL; + return temp; +} + +// optional .protobuf_unittest.TestAllTypes.NestedEnum optional_nested_enum = 21; +inline bool TestAllTypes::has_optional_nested_enum() const { + return (_has_bits_[0] & 0x00080000u) != 0; +} +inline void TestAllTypes::set_has_optional_nested_enum() { + _has_bits_[0] |= 0x00080000u; +} +inline void TestAllTypes::clear_has_optional_nested_enum() { + _has_bits_[0] &= ~0x00080000u; +} +inline void TestAllTypes::clear_optional_nested_enum() { + optional_nested_enum_ = 1; + clear_has_optional_nested_enum(); +} +inline ::protobuf_unittest::TestAllTypes_NestedEnum TestAllTypes::optional_nested_enum() const { + return static_cast< ::protobuf_unittest::TestAllTypes_NestedEnum >(optional_nested_enum_); +} +inline void TestAllTypes::set_optional_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); + set_has_optional_nested_enum(); + optional_nested_enum_ = value; +} + +// optional .protobuf_unittest.ForeignEnum optional_foreign_enum = 22; +inline bool TestAllTypes::has_optional_foreign_enum() const { + return (_has_bits_[0] & 0x00100000u) != 0; +} +inline void TestAllTypes::set_has_optional_foreign_enum() { + _has_bits_[0] |= 0x00100000u; +} +inline void TestAllTypes::clear_has_optional_foreign_enum() { + _has_bits_[0] &= ~0x00100000u; +} +inline void TestAllTypes::clear_optional_foreign_enum() { + optional_foreign_enum_ = 4; + clear_has_optional_foreign_enum(); +} +inline protobuf_unittest::ForeignEnum TestAllTypes::optional_foreign_enum() const { + return static_cast< protobuf_unittest::ForeignEnum >(optional_foreign_enum_); +} +inline void TestAllTypes::set_optional_foreign_enum(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + set_has_optional_foreign_enum(); + optional_foreign_enum_ = value; +} + +// optional .protobuf_unittest_import.ImportEnum optional_import_enum = 23; +inline bool TestAllTypes::has_optional_import_enum() const { + return (_has_bits_[0] & 0x00200000u) != 0; +} +inline void TestAllTypes::set_has_optional_import_enum() { + _has_bits_[0] |= 0x00200000u; +} +inline void TestAllTypes::clear_has_optional_import_enum() { + _has_bits_[0] &= ~0x00200000u; +} +inline void TestAllTypes::clear_optional_import_enum() { + optional_import_enum_ = 7; + clear_has_optional_import_enum(); +} +inline protobuf_unittest_import::ImportEnum TestAllTypes::optional_import_enum() const { + return static_cast< protobuf_unittest_import::ImportEnum >(optional_import_enum_); +} +inline void TestAllTypes::set_optional_import_enum(protobuf_unittest_import::ImportEnum value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); + set_has_optional_import_enum(); + optional_import_enum_ = value; +} + +// optional string optional_string_piece = 24 [ctype = STRING_PIECE]; +inline bool TestAllTypes::has_optional_string_piece() const { + return (_has_bits_[0] & 0x00400000u) != 0; +} +inline void TestAllTypes::set_has_optional_string_piece() { + _has_bits_[0] |= 0x00400000u; +} +inline void TestAllTypes::clear_has_optional_string_piece() { + _has_bits_[0] &= ~0x00400000u; +} +inline void TestAllTypes::clear_optional_string_piece() { + if (optional_string_piece_ != &::google::protobuf::internal::kEmptyString) { + optional_string_piece_->clear(); + } + clear_has_optional_string_piece(); +} +inline const ::std::string& TestAllTypes::optional_string_piece() const { + return *optional_string_piece_; +} +inline void TestAllTypes::set_optional_string_piece(const ::std::string& value) { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + optional_string_piece_->assign(value); +} +inline void TestAllTypes::set_optional_string_piece(const char* value) { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + optional_string_piece_->assign(value); +} +inline void TestAllTypes::set_optional_string_piece(const char* value, size_t size) { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + optional_string_piece_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_optional_string_piece() { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + return optional_string_piece_; +} +inline ::std::string* TestAllTypes::release_optional_string_piece() { + clear_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_string_piece_; + optional_string_piece_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string optional_cord = 25 [ctype = CORD]; +inline bool TestAllTypes::has_optional_cord() const { + return (_has_bits_[0] & 0x00800000u) != 0; +} +inline void TestAllTypes::set_has_optional_cord() { + _has_bits_[0] |= 0x00800000u; +} +inline void TestAllTypes::clear_has_optional_cord() { + _has_bits_[0] &= ~0x00800000u; +} +inline void TestAllTypes::clear_optional_cord() { + if (optional_cord_ != &::google::protobuf::internal::kEmptyString) { + optional_cord_->clear(); + } + clear_has_optional_cord(); +} +inline const ::std::string& TestAllTypes::optional_cord() const { + return *optional_cord_; +} +inline void TestAllTypes::set_optional_cord(const ::std::string& value) { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + optional_cord_->assign(value); +} +inline void TestAllTypes::set_optional_cord(const char* value) { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + optional_cord_->assign(value); +} +inline void TestAllTypes::set_optional_cord(const char* value, size_t size) { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + optional_cord_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_optional_cord() { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + return optional_cord_; +} +inline ::std::string* TestAllTypes::release_optional_cord() { + clear_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_cord_; + optional_cord_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated int32 repeated_int32 = 31; +inline int TestAllTypes::repeated_int32_size() const { + return repeated_int32_.size(); +} +inline void TestAllTypes::clear_repeated_int32() { + repeated_int32_.Clear(); +} +inline ::google::protobuf::int32 TestAllTypes::repeated_int32(int index) const { + return repeated_int32_.Get(index); +} +inline void TestAllTypes::set_repeated_int32(int index, ::google::protobuf::int32 value) { + repeated_int32_.Set(index, value); +} +inline void TestAllTypes::add_repeated_int32(::google::protobuf::int32 value) { + repeated_int32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestAllTypes::repeated_int32() const { + return repeated_int32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestAllTypes::mutable_repeated_int32() { + return &repeated_int32_; +} + +// repeated int64 repeated_int64 = 32; +inline int TestAllTypes::repeated_int64_size() const { + return repeated_int64_.size(); +} +inline void TestAllTypes::clear_repeated_int64() { + repeated_int64_.Clear(); +} +inline ::google::protobuf::int64 TestAllTypes::repeated_int64(int index) const { + return repeated_int64_.Get(index); +} +inline void TestAllTypes::set_repeated_int64(int index, ::google::protobuf::int64 value) { + repeated_int64_.Set(index, value); +} +inline void TestAllTypes::add_repeated_int64(::google::protobuf::int64 value) { + repeated_int64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestAllTypes::repeated_int64() const { + return repeated_int64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestAllTypes::mutable_repeated_int64() { + return &repeated_int64_; +} + +// repeated uint32 repeated_uint32 = 33; +inline int TestAllTypes::repeated_uint32_size() const { + return repeated_uint32_.size(); +} +inline void TestAllTypes::clear_repeated_uint32() { + repeated_uint32_.Clear(); +} +inline ::google::protobuf::uint32 TestAllTypes::repeated_uint32(int index) const { + return repeated_uint32_.Get(index); +} +inline void TestAllTypes::set_repeated_uint32(int index, ::google::protobuf::uint32 value) { + repeated_uint32_.Set(index, value); +} +inline void TestAllTypes::add_repeated_uint32(::google::protobuf::uint32 value) { + repeated_uint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestAllTypes::repeated_uint32() const { + return repeated_uint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestAllTypes::mutable_repeated_uint32() { + return &repeated_uint32_; +} + +// repeated uint64 repeated_uint64 = 34; +inline int TestAllTypes::repeated_uint64_size() const { + return repeated_uint64_.size(); +} +inline void TestAllTypes::clear_repeated_uint64() { + repeated_uint64_.Clear(); +} +inline ::google::protobuf::uint64 TestAllTypes::repeated_uint64(int index) const { + return repeated_uint64_.Get(index); +} +inline void TestAllTypes::set_repeated_uint64(int index, ::google::protobuf::uint64 value) { + repeated_uint64_.Set(index, value); +} +inline void TestAllTypes::add_repeated_uint64(::google::protobuf::uint64 value) { + repeated_uint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestAllTypes::repeated_uint64() const { + return repeated_uint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestAllTypes::mutable_repeated_uint64() { + return &repeated_uint64_; +} + +// repeated sint32 repeated_sint32 = 35; +inline int TestAllTypes::repeated_sint32_size() const { + return repeated_sint32_.size(); +} +inline void TestAllTypes::clear_repeated_sint32() { + repeated_sint32_.Clear(); +} +inline ::google::protobuf::int32 TestAllTypes::repeated_sint32(int index) const { + return repeated_sint32_.Get(index); +} +inline void TestAllTypes::set_repeated_sint32(int index, ::google::protobuf::int32 value) { + repeated_sint32_.Set(index, value); +} +inline void TestAllTypes::add_repeated_sint32(::google::protobuf::int32 value) { + repeated_sint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestAllTypes::repeated_sint32() const { + return repeated_sint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestAllTypes::mutable_repeated_sint32() { + return &repeated_sint32_; +} + +// repeated sint64 repeated_sint64 = 36; +inline int TestAllTypes::repeated_sint64_size() const { + return repeated_sint64_.size(); +} +inline void TestAllTypes::clear_repeated_sint64() { + repeated_sint64_.Clear(); +} +inline ::google::protobuf::int64 TestAllTypes::repeated_sint64(int index) const { + return repeated_sint64_.Get(index); +} +inline void TestAllTypes::set_repeated_sint64(int index, ::google::protobuf::int64 value) { + repeated_sint64_.Set(index, value); +} +inline void TestAllTypes::add_repeated_sint64(::google::protobuf::int64 value) { + repeated_sint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestAllTypes::repeated_sint64() const { + return repeated_sint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestAllTypes::mutable_repeated_sint64() { + return &repeated_sint64_; +} + +// repeated fixed32 repeated_fixed32 = 37; +inline int TestAllTypes::repeated_fixed32_size() const { + return repeated_fixed32_.size(); +} +inline void TestAllTypes::clear_repeated_fixed32() { + repeated_fixed32_.Clear(); +} +inline ::google::protobuf::uint32 TestAllTypes::repeated_fixed32(int index) const { + return repeated_fixed32_.Get(index); +} +inline void TestAllTypes::set_repeated_fixed32(int index, ::google::protobuf::uint32 value) { + repeated_fixed32_.Set(index, value); +} +inline void TestAllTypes::add_repeated_fixed32(::google::protobuf::uint32 value) { + repeated_fixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestAllTypes::repeated_fixed32() const { + return repeated_fixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestAllTypes::mutable_repeated_fixed32() { + return &repeated_fixed32_; +} + +// repeated fixed64 repeated_fixed64 = 38; +inline int TestAllTypes::repeated_fixed64_size() const { + return repeated_fixed64_.size(); +} +inline void TestAllTypes::clear_repeated_fixed64() { + repeated_fixed64_.Clear(); +} +inline ::google::protobuf::uint64 TestAllTypes::repeated_fixed64(int index) const { + return repeated_fixed64_.Get(index); +} +inline void TestAllTypes::set_repeated_fixed64(int index, ::google::protobuf::uint64 value) { + repeated_fixed64_.Set(index, value); +} +inline void TestAllTypes::add_repeated_fixed64(::google::protobuf::uint64 value) { + repeated_fixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestAllTypes::repeated_fixed64() const { + return repeated_fixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestAllTypes::mutable_repeated_fixed64() { + return &repeated_fixed64_; +} + +// repeated sfixed32 repeated_sfixed32 = 39; +inline int TestAllTypes::repeated_sfixed32_size() const { + return repeated_sfixed32_.size(); +} +inline void TestAllTypes::clear_repeated_sfixed32() { + repeated_sfixed32_.Clear(); +} +inline ::google::protobuf::int32 TestAllTypes::repeated_sfixed32(int index) const { + return repeated_sfixed32_.Get(index); +} +inline void TestAllTypes::set_repeated_sfixed32(int index, ::google::protobuf::int32 value) { + repeated_sfixed32_.Set(index, value); +} +inline void TestAllTypes::add_repeated_sfixed32(::google::protobuf::int32 value) { + repeated_sfixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestAllTypes::repeated_sfixed32() const { + return repeated_sfixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestAllTypes::mutable_repeated_sfixed32() { + return &repeated_sfixed32_; +} + +// repeated sfixed64 repeated_sfixed64 = 40; +inline int TestAllTypes::repeated_sfixed64_size() const { + return repeated_sfixed64_.size(); +} +inline void TestAllTypes::clear_repeated_sfixed64() { + repeated_sfixed64_.Clear(); +} +inline ::google::protobuf::int64 TestAllTypes::repeated_sfixed64(int index) const { + return repeated_sfixed64_.Get(index); +} +inline void TestAllTypes::set_repeated_sfixed64(int index, ::google::protobuf::int64 value) { + repeated_sfixed64_.Set(index, value); +} +inline void TestAllTypes::add_repeated_sfixed64(::google::protobuf::int64 value) { + repeated_sfixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestAllTypes::repeated_sfixed64() const { + return repeated_sfixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestAllTypes::mutable_repeated_sfixed64() { + return &repeated_sfixed64_; +} + +// repeated float repeated_float = 41; +inline int TestAllTypes::repeated_float_size() const { + return repeated_float_.size(); +} +inline void TestAllTypes::clear_repeated_float() { + repeated_float_.Clear(); +} +inline float TestAllTypes::repeated_float(int index) const { + return repeated_float_.Get(index); +} +inline void TestAllTypes::set_repeated_float(int index, float value) { + repeated_float_.Set(index, value); +} +inline void TestAllTypes::add_repeated_float(float value) { + repeated_float_.Add(value); +} +inline const ::google::protobuf::RepeatedField< float >& +TestAllTypes::repeated_float() const { + return repeated_float_; +} +inline ::google::protobuf::RepeatedField< float >* +TestAllTypes::mutable_repeated_float() { + return &repeated_float_; +} + +// repeated double repeated_double = 42; +inline int TestAllTypes::repeated_double_size() const { + return repeated_double_.size(); +} +inline void TestAllTypes::clear_repeated_double() { + repeated_double_.Clear(); +} +inline double TestAllTypes::repeated_double(int index) const { + return repeated_double_.Get(index); +} +inline void TestAllTypes::set_repeated_double(int index, double value) { + repeated_double_.Set(index, value); +} +inline void TestAllTypes::add_repeated_double(double value) { + repeated_double_.Add(value); +} +inline const ::google::protobuf::RepeatedField< double >& +TestAllTypes::repeated_double() const { + return repeated_double_; +} +inline ::google::protobuf::RepeatedField< double >* +TestAllTypes::mutable_repeated_double() { + return &repeated_double_; +} + +// repeated bool repeated_bool = 43; +inline int TestAllTypes::repeated_bool_size() const { + return repeated_bool_.size(); +} +inline void TestAllTypes::clear_repeated_bool() { + repeated_bool_.Clear(); +} +inline bool TestAllTypes::repeated_bool(int index) const { + return repeated_bool_.Get(index); +} +inline void TestAllTypes::set_repeated_bool(int index, bool value) { + repeated_bool_.Set(index, value); +} +inline void TestAllTypes::add_repeated_bool(bool value) { + repeated_bool_.Add(value); +} +inline const ::google::protobuf::RepeatedField< bool >& +TestAllTypes::repeated_bool() const { + return repeated_bool_; +} +inline ::google::protobuf::RepeatedField< bool >* +TestAllTypes::mutable_repeated_bool() { + return &repeated_bool_; +} + +// repeated string repeated_string = 44; +inline int TestAllTypes::repeated_string_size() const { + return repeated_string_.size(); +} +inline void TestAllTypes::clear_repeated_string() { + repeated_string_.Clear(); +} +inline const ::std::string& TestAllTypes::repeated_string(int index) const { + return repeated_string_.Get(index); +} +inline ::std::string* TestAllTypes::mutable_repeated_string(int index) { + return repeated_string_.Mutable(index); +} +inline void TestAllTypes::set_repeated_string(int index, const ::std::string& value) { + repeated_string_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_string(int index, const char* value) { + repeated_string_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_string(int index, const char* value, size_t size) { + repeated_string_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::add_repeated_string() { + return repeated_string_.Add(); +} +inline void TestAllTypes::add_repeated_string(const ::std::string& value) { + repeated_string_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_string(const char* value) { + repeated_string_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_string(const char* value, size_t size) { + repeated_string_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypes::repeated_string() const { + return repeated_string_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypes::mutable_repeated_string() { + return &repeated_string_; +} + +// repeated bytes repeated_bytes = 45; +inline int TestAllTypes::repeated_bytes_size() const { + return repeated_bytes_.size(); +} +inline void TestAllTypes::clear_repeated_bytes() { + repeated_bytes_.Clear(); +} +inline const ::std::string& TestAllTypes::repeated_bytes(int index) const { + return repeated_bytes_.Get(index); +} +inline ::std::string* TestAllTypes::mutable_repeated_bytes(int index) { + return repeated_bytes_.Mutable(index); +} +inline void TestAllTypes::set_repeated_bytes(int index, const ::std::string& value) { + repeated_bytes_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_bytes(int index, const char* value) { + repeated_bytes_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_bytes(int index, const void* value, size_t size) { + repeated_bytes_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::add_repeated_bytes() { + return repeated_bytes_.Add(); +} +inline void TestAllTypes::add_repeated_bytes(const ::std::string& value) { + repeated_bytes_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_bytes(const char* value) { + repeated_bytes_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_bytes(const void* value, size_t size) { + repeated_bytes_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypes::repeated_bytes() const { + return repeated_bytes_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypes::mutable_repeated_bytes() { + return &repeated_bytes_; +} + +// repeated group RepeatedGroup = 46 { +inline int TestAllTypes::repeatedgroup_size() const { + return repeatedgroup_.size(); +} +inline void TestAllTypes::clear_repeatedgroup() { + repeatedgroup_.Clear(); +} +inline const ::protobuf_unittest::TestAllTypes_RepeatedGroup& TestAllTypes::repeatedgroup(int index) const { + return repeatedgroup_.Get(index); +} +inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* TestAllTypes::mutable_repeatedgroup(int index) { + return repeatedgroup_.Mutable(index); +} +inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* TestAllTypes::add_repeatedgroup() { + return repeatedgroup_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >& +TestAllTypes::repeatedgroup() const { + return repeatedgroup_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >* +TestAllTypes::mutable_repeatedgroup() { + return &repeatedgroup_; +} + +// repeated .protobuf_unittest.TestAllTypes.NestedMessage repeated_nested_message = 48; +inline int TestAllTypes::repeated_nested_message_size() const { + return repeated_nested_message_.size(); +} +inline void TestAllTypes::clear_repeated_nested_message() { + repeated_nested_message_.Clear(); +} +inline const ::protobuf_unittest::TestAllTypes_NestedMessage& TestAllTypes::repeated_nested_message(int index) const { + return repeated_nested_message_.Get(index); +} +inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::mutable_repeated_nested_message(int index) { + return repeated_nested_message_.Mutable(index); +} +inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::add_repeated_nested_message() { + return repeated_nested_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >& +TestAllTypes::repeated_nested_message() const { + return repeated_nested_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >* +TestAllTypes::mutable_repeated_nested_message() { + return &repeated_nested_message_; +} + +// repeated .protobuf_unittest.ForeignMessage repeated_foreign_message = 49; +inline int TestAllTypes::repeated_foreign_message_size() const { + return repeated_foreign_message_.size(); +} +inline void TestAllTypes::clear_repeated_foreign_message() { + repeated_foreign_message_.Clear(); +} +inline const ::protobuf_unittest::ForeignMessage& TestAllTypes::repeated_foreign_message(int index) const { + return repeated_foreign_message_.Get(index); +} +inline ::protobuf_unittest::ForeignMessage* TestAllTypes::mutable_repeated_foreign_message(int index) { + return repeated_foreign_message_.Mutable(index); +} +inline ::protobuf_unittest::ForeignMessage* TestAllTypes::add_repeated_foreign_message() { + return repeated_foreign_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& +TestAllTypes::repeated_foreign_message() const { + return repeated_foreign_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* +TestAllTypes::mutable_repeated_foreign_message() { + return &repeated_foreign_message_; +} + +// repeated .protobuf_unittest_import.ImportMessage repeated_import_message = 50; +inline int TestAllTypes::repeated_import_message_size() const { + return repeated_import_message_.size(); +} +inline void TestAllTypes::clear_repeated_import_message() { + repeated_import_message_.Clear(); +} +inline const ::protobuf_unittest_import::ImportMessage& TestAllTypes::repeated_import_message(int index) const { + return repeated_import_message_.Get(index); +} +inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::mutable_repeated_import_message(int index) { + return repeated_import_message_.Mutable(index); +} +inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::add_repeated_import_message() { + return repeated_import_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >& +TestAllTypes::repeated_import_message() const { + return repeated_import_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >* +TestAllTypes::mutable_repeated_import_message() { + return &repeated_import_message_; +} + +// repeated .protobuf_unittest.TestAllTypes.NestedEnum repeated_nested_enum = 51; +inline int TestAllTypes::repeated_nested_enum_size() const { + return repeated_nested_enum_.size(); +} +inline void TestAllTypes::clear_repeated_nested_enum() { + repeated_nested_enum_.Clear(); +} +inline ::protobuf_unittest::TestAllTypes_NestedEnum TestAllTypes::repeated_nested_enum(int index) const { + return static_cast< ::protobuf_unittest::TestAllTypes_NestedEnum >(repeated_nested_enum_.Get(index)); +} +inline void TestAllTypes::set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypes_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); + repeated_nested_enum_.Set(index, value); +} +inline void TestAllTypes::add_repeated_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); + repeated_nested_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestAllTypes::repeated_nested_enum() const { + return repeated_nested_enum_; +} +inline ::google::protobuf::RepeatedField* +TestAllTypes::mutable_repeated_nested_enum() { + return &repeated_nested_enum_; +} + +// repeated .protobuf_unittest.ForeignEnum repeated_foreign_enum = 52; +inline int TestAllTypes::repeated_foreign_enum_size() const { + return repeated_foreign_enum_.size(); +} +inline void TestAllTypes::clear_repeated_foreign_enum() { + repeated_foreign_enum_.Clear(); +} +inline protobuf_unittest::ForeignEnum TestAllTypes::repeated_foreign_enum(int index) const { + return static_cast< protobuf_unittest::ForeignEnum >(repeated_foreign_enum_.Get(index)); +} +inline void TestAllTypes::set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + repeated_foreign_enum_.Set(index, value); +} +inline void TestAllTypes::add_repeated_foreign_enum(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + repeated_foreign_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestAllTypes::repeated_foreign_enum() const { + return repeated_foreign_enum_; +} +inline ::google::protobuf::RepeatedField* +TestAllTypes::mutable_repeated_foreign_enum() { + return &repeated_foreign_enum_; +} + +// repeated .protobuf_unittest_import.ImportEnum repeated_import_enum = 53; +inline int TestAllTypes::repeated_import_enum_size() const { + return repeated_import_enum_.size(); +} +inline void TestAllTypes::clear_repeated_import_enum() { + repeated_import_enum_.Clear(); +} +inline protobuf_unittest_import::ImportEnum TestAllTypes::repeated_import_enum(int index) const { + return static_cast< protobuf_unittest_import::ImportEnum >(repeated_import_enum_.Get(index)); +} +inline void TestAllTypes::set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnum value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); + repeated_import_enum_.Set(index, value); +} +inline void TestAllTypes::add_repeated_import_enum(protobuf_unittest_import::ImportEnum value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); + repeated_import_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestAllTypes::repeated_import_enum() const { + return repeated_import_enum_; +} +inline ::google::protobuf::RepeatedField* +TestAllTypes::mutable_repeated_import_enum() { + return &repeated_import_enum_; +} + +// repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; +inline int TestAllTypes::repeated_string_piece_size() const { + return repeated_string_piece_.size(); +} +inline void TestAllTypes::clear_repeated_string_piece() { + repeated_string_piece_.Clear(); +} +inline const ::std::string& TestAllTypes::repeated_string_piece(int index) const { + return repeated_string_piece_.Get(index); +} +inline ::std::string* TestAllTypes::mutable_repeated_string_piece(int index) { + return repeated_string_piece_.Mutable(index); +} +inline void TestAllTypes::set_repeated_string_piece(int index, const ::std::string& value) { + repeated_string_piece_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_string_piece(int index, const char* value) { + repeated_string_piece_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_string_piece(int index, const char* value, size_t size) { + repeated_string_piece_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::add_repeated_string_piece() { + return repeated_string_piece_.Add(); +} +inline void TestAllTypes::add_repeated_string_piece(const ::std::string& value) { + repeated_string_piece_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_string_piece(const char* value) { + repeated_string_piece_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_string_piece(const char* value, size_t size) { + repeated_string_piece_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypes::repeated_string_piece() const { + return repeated_string_piece_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypes::mutable_repeated_string_piece() { + return &repeated_string_piece_; +} + +// repeated string repeated_cord = 55 [ctype = CORD]; +inline int TestAllTypes::repeated_cord_size() const { + return repeated_cord_.size(); +} +inline void TestAllTypes::clear_repeated_cord() { + repeated_cord_.Clear(); +} +inline const ::std::string& TestAllTypes::repeated_cord(int index) const { + return repeated_cord_.Get(index); +} +inline ::std::string* TestAllTypes::mutable_repeated_cord(int index) { + return repeated_cord_.Mutable(index); +} +inline void TestAllTypes::set_repeated_cord(int index, const ::std::string& value) { + repeated_cord_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_cord(int index, const char* value) { + repeated_cord_.Mutable(index)->assign(value); +} +inline void TestAllTypes::set_repeated_cord(int index, const char* value, size_t size) { + repeated_cord_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::add_repeated_cord() { + return repeated_cord_.Add(); +} +inline void TestAllTypes::add_repeated_cord(const ::std::string& value) { + repeated_cord_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_cord(const char* value) { + repeated_cord_.Add()->assign(value); +} +inline void TestAllTypes::add_repeated_cord(const char* value, size_t size) { + repeated_cord_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypes::repeated_cord() const { + return repeated_cord_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypes::mutable_repeated_cord() { + return &repeated_cord_; +} + +// optional int32 default_int32 = 61 [default = 41]; +inline bool TestAllTypes::has_default_int32() const { + return (_has_bits_[1] & 0x00010000u) != 0; +} +inline void TestAllTypes::set_has_default_int32() { + _has_bits_[1] |= 0x00010000u; +} +inline void TestAllTypes::clear_has_default_int32() { + _has_bits_[1] &= ~0x00010000u; +} +inline void TestAllTypes::clear_default_int32() { + default_int32_ = 41; + clear_has_default_int32(); +} +inline ::google::protobuf::int32 TestAllTypes::default_int32() const { + return default_int32_; +} +inline void TestAllTypes::set_default_int32(::google::protobuf::int32 value) { + set_has_default_int32(); + default_int32_ = value; +} + +// optional int64 default_int64 = 62 [default = 42]; +inline bool TestAllTypes::has_default_int64() const { + return (_has_bits_[1] & 0x00020000u) != 0; +} +inline void TestAllTypes::set_has_default_int64() { + _has_bits_[1] |= 0x00020000u; +} +inline void TestAllTypes::clear_has_default_int64() { + _has_bits_[1] &= ~0x00020000u; +} +inline void TestAllTypes::clear_default_int64() { + default_int64_ = GOOGLE_LONGLONG(42); + clear_has_default_int64(); +} +inline ::google::protobuf::int64 TestAllTypes::default_int64() const { + return default_int64_; +} +inline void TestAllTypes::set_default_int64(::google::protobuf::int64 value) { + set_has_default_int64(); + default_int64_ = value; +} + +// optional uint32 default_uint32 = 63 [default = 43]; +inline bool TestAllTypes::has_default_uint32() const { + return (_has_bits_[1] & 0x00040000u) != 0; +} +inline void TestAllTypes::set_has_default_uint32() { + _has_bits_[1] |= 0x00040000u; +} +inline void TestAllTypes::clear_has_default_uint32() { + _has_bits_[1] &= ~0x00040000u; +} +inline void TestAllTypes::clear_default_uint32() { + default_uint32_ = 43u; + clear_has_default_uint32(); +} +inline ::google::protobuf::uint32 TestAllTypes::default_uint32() const { + return default_uint32_; +} +inline void TestAllTypes::set_default_uint32(::google::protobuf::uint32 value) { + set_has_default_uint32(); + default_uint32_ = value; +} + +// optional uint64 default_uint64 = 64 [default = 44]; +inline bool TestAllTypes::has_default_uint64() const { + return (_has_bits_[1] & 0x00080000u) != 0; +} +inline void TestAllTypes::set_has_default_uint64() { + _has_bits_[1] |= 0x00080000u; +} +inline void TestAllTypes::clear_has_default_uint64() { + _has_bits_[1] &= ~0x00080000u; +} +inline void TestAllTypes::clear_default_uint64() { + default_uint64_ = GOOGLE_ULONGLONG(44); + clear_has_default_uint64(); +} +inline ::google::protobuf::uint64 TestAllTypes::default_uint64() const { + return default_uint64_; +} +inline void TestAllTypes::set_default_uint64(::google::protobuf::uint64 value) { + set_has_default_uint64(); + default_uint64_ = value; +} + +// optional sint32 default_sint32 = 65 [default = -45]; +inline bool TestAllTypes::has_default_sint32() const { + return (_has_bits_[1] & 0x00100000u) != 0; +} +inline void TestAllTypes::set_has_default_sint32() { + _has_bits_[1] |= 0x00100000u; +} +inline void TestAllTypes::clear_has_default_sint32() { + _has_bits_[1] &= ~0x00100000u; +} +inline void TestAllTypes::clear_default_sint32() { + default_sint32_ = -45; + clear_has_default_sint32(); +} +inline ::google::protobuf::int32 TestAllTypes::default_sint32() const { + return default_sint32_; +} +inline void TestAllTypes::set_default_sint32(::google::protobuf::int32 value) { + set_has_default_sint32(); + default_sint32_ = value; +} + +// optional sint64 default_sint64 = 66 [default = 46]; +inline bool TestAllTypes::has_default_sint64() const { + return (_has_bits_[1] & 0x00200000u) != 0; +} +inline void TestAllTypes::set_has_default_sint64() { + _has_bits_[1] |= 0x00200000u; +} +inline void TestAllTypes::clear_has_default_sint64() { + _has_bits_[1] &= ~0x00200000u; +} +inline void TestAllTypes::clear_default_sint64() { + default_sint64_ = GOOGLE_LONGLONG(46); + clear_has_default_sint64(); +} +inline ::google::protobuf::int64 TestAllTypes::default_sint64() const { + return default_sint64_; +} +inline void TestAllTypes::set_default_sint64(::google::protobuf::int64 value) { + set_has_default_sint64(); + default_sint64_ = value; +} + +// optional fixed32 default_fixed32 = 67 [default = 47]; +inline bool TestAllTypes::has_default_fixed32() const { + return (_has_bits_[1] & 0x00400000u) != 0; +} +inline void TestAllTypes::set_has_default_fixed32() { + _has_bits_[1] |= 0x00400000u; +} +inline void TestAllTypes::clear_has_default_fixed32() { + _has_bits_[1] &= ~0x00400000u; +} +inline void TestAllTypes::clear_default_fixed32() { + default_fixed32_ = 47u; + clear_has_default_fixed32(); +} +inline ::google::protobuf::uint32 TestAllTypes::default_fixed32() const { + return default_fixed32_; +} +inline void TestAllTypes::set_default_fixed32(::google::protobuf::uint32 value) { + set_has_default_fixed32(); + default_fixed32_ = value; +} + +// optional fixed64 default_fixed64 = 68 [default = 48]; +inline bool TestAllTypes::has_default_fixed64() const { + return (_has_bits_[1] & 0x00800000u) != 0; +} +inline void TestAllTypes::set_has_default_fixed64() { + _has_bits_[1] |= 0x00800000u; +} +inline void TestAllTypes::clear_has_default_fixed64() { + _has_bits_[1] &= ~0x00800000u; +} +inline void TestAllTypes::clear_default_fixed64() { + default_fixed64_ = GOOGLE_ULONGLONG(48); + clear_has_default_fixed64(); +} +inline ::google::protobuf::uint64 TestAllTypes::default_fixed64() const { + return default_fixed64_; +} +inline void TestAllTypes::set_default_fixed64(::google::protobuf::uint64 value) { + set_has_default_fixed64(); + default_fixed64_ = value; +} + +// optional sfixed32 default_sfixed32 = 69 [default = 49]; +inline bool TestAllTypes::has_default_sfixed32() const { + return (_has_bits_[1] & 0x01000000u) != 0; +} +inline void TestAllTypes::set_has_default_sfixed32() { + _has_bits_[1] |= 0x01000000u; +} +inline void TestAllTypes::clear_has_default_sfixed32() { + _has_bits_[1] &= ~0x01000000u; +} +inline void TestAllTypes::clear_default_sfixed32() { + default_sfixed32_ = 49; + clear_has_default_sfixed32(); +} +inline ::google::protobuf::int32 TestAllTypes::default_sfixed32() const { + return default_sfixed32_; +} +inline void TestAllTypes::set_default_sfixed32(::google::protobuf::int32 value) { + set_has_default_sfixed32(); + default_sfixed32_ = value; +} + +// optional sfixed64 default_sfixed64 = 70 [default = -50]; +inline bool TestAllTypes::has_default_sfixed64() const { + return (_has_bits_[1] & 0x02000000u) != 0; +} +inline void TestAllTypes::set_has_default_sfixed64() { + _has_bits_[1] |= 0x02000000u; +} +inline void TestAllTypes::clear_has_default_sfixed64() { + _has_bits_[1] &= ~0x02000000u; +} +inline void TestAllTypes::clear_default_sfixed64() { + default_sfixed64_ = GOOGLE_LONGLONG(-50); + clear_has_default_sfixed64(); +} +inline ::google::protobuf::int64 TestAllTypes::default_sfixed64() const { + return default_sfixed64_; +} +inline void TestAllTypes::set_default_sfixed64(::google::protobuf::int64 value) { + set_has_default_sfixed64(); + default_sfixed64_ = value; +} + +// optional float default_float = 71 [default = 51.5]; +inline bool TestAllTypes::has_default_float() const { + return (_has_bits_[1] & 0x04000000u) != 0; +} +inline void TestAllTypes::set_has_default_float() { + _has_bits_[1] |= 0x04000000u; +} +inline void TestAllTypes::clear_has_default_float() { + _has_bits_[1] &= ~0x04000000u; +} +inline void TestAllTypes::clear_default_float() { + default_float_ = 51.5f; + clear_has_default_float(); +} +inline float TestAllTypes::default_float() const { + return default_float_; +} +inline void TestAllTypes::set_default_float(float value) { + set_has_default_float(); + default_float_ = value; +} + +// optional double default_double = 72 [default = 52000]; +inline bool TestAllTypes::has_default_double() const { + return (_has_bits_[1] & 0x08000000u) != 0; +} +inline void TestAllTypes::set_has_default_double() { + _has_bits_[1] |= 0x08000000u; +} +inline void TestAllTypes::clear_has_default_double() { + _has_bits_[1] &= ~0x08000000u; +} +inline void TestAllTypes::clear_default_double() { + default_double_ = 52000; + clear_has_default_double(); +} +inline double TestAllTypes::default_double() const { + return default_double_; +} +inline void TestAllTypes::set_default_double(double value) { + set_has_default_double(); + default_double_ = value; +} + +// optional bool default_bool = 73 [default = true]; +inline bool TestAllTypes::has_default_bool() const { + return (_has_bits_[1] & 0x10000000u) != 0; +} +inline void TestAllTypes::set_has_default_bool() { + _has_bits_[1] |= 0x10000000u; +} +inline void TestAllTypes::clear_has_default_bool() { + _has_bits_[1] &= ~0x10000000u; +} +inline void TestAllTypes::clear_default_bool() { + default_bool_ = true; + clear_has_default_bool(); +} +inline bool TestAllTypes::default_bool() const { + return default_bool_; +} +inline void TestAllTypes::set_default_bool(bool value) { + set_has_default_bool(); + default_bool_ = value; +} + +// optional string default_string = 74 [default = "hello"]; +inline bool TestAllTypes::has_default_string() const { + return (_has_bits_[1] & 0x20000000u) != 0; +} +inline void TestAllTypes::set_has_default_string() { + _has_bits_[1] |= 0x20000000u; +} +inline void TestAllTypes::clear_has_default_string() { + _has_bits_[1] &= ~0x20000000u; +} +inline void TestAllTypes::clear_default_string() { + if (default_string_ != &_default_default_string_) { + default_string_->assign(_default_default_string_); + } + clear_has_default_string(); +} +inline const ::std::string& TestAllTypes::default_string() const { + return *default_string_; +} +inline void TestAllTypes::set_default_string(const ::std::string& value) { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string; + } + default_string_->assign(value); +} +inline void TestAllTypes::set_default_string(const char* value) { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string; + } + default_string_->assign(value); +} +inline void TestAllTypes::set_default_string(const char* value, size_t size) { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string; + } + default_string_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_default_string() { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string(_default_default_string_); + } + return default_string_; +} +inline ::std::string* TestAllTypes::release_default_string() { + clear_has_default_string(); + if (default_string_ == &_default_default_string_) { + return NULL; + } else { + ::std::string* temp = default_string_; + default_string_ = const_cast< ::std::string*>(&_default_default_string_); + return temp; + } +} + +// optional bytes default_bytes = 75 [default = "world"]; +inline bool TestAllTypes::has_default_bytes() const { + return (_has_bits_[1] & 0x40000000u) != 0; +} +inline void TestAllTypes::set_has_default_bytes() { + _has_bits_[1] |= 0x40000000u; +} +inline void TestAllTypes::clear_has_default_bytes() { + _has_bits_[1] &= ~0x40000000u; +} +inline void TestAllTypes::clear_default_bytes() { + if (default_bytes_ != &_default_default_bytes_) { + default_bytes_->assign(_default_default_bytes_); + } + clear_has_default_bytes(); +} +inline const ::std::string& TestAllTypes::default_bytes() const { + return *default_bytes_; +} +inline void TestAllTypes::set_default_bytes(const ::std::string& value) { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string; + } + default_bytes_->assign(value); +} +inline void TestAllTypes::set_default_bytes(const char* value) { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string; + } + default_bytes_->assign(value); +} +inline void TestAllTypes::set_default_bytes(const void* value, size_t size) { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string; + } + default_bytes_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_default_bytes() { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string(_default_default_bytes_); + } + return default_bytes_; +} +inline ::std::string* TestAllTypes::release_default_bytes() { + clear_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + return NULL; + } else { + ::std::string* temp = default_bytes_; + default_bytes_ = const_cast< ::std::string*>(&_default_default_bytes_); + return temp; + } +} + +// optional .protobuf_unittest.TestAllTypes.NestedEnum default_nested_enum = 81 [default = BAR]; +inline bool TestAllTypes::has_default_nested_enum() const { + return (_has_bits_[1] & 0x80000000u) != 0; +} +inline void TestAllTypes::set_has_default_nested_enum() { + _has_bits_[1] |= 0x80000000u; +} +inline void TestAllTypes::clear_has_default_nested_enum() { + _has_bits_[1] &= ~0x80000000u; +} +inline void TestAllTypes::clear_default_nested_enum() { + default_nested_enum_ = 2; + clear_has_default_nested_enum(); +} +inline ::protobuf_unittest::TestAllTypes_NestedEnum TestAllTypes::default_nested_enum() const { + return static_cast< ::protobuf_unittest::TestAllTypes_NestedEnum >(default_nested_enum_); +} +inline void TestAllTypes::set_default_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); + set_has_default_nested_enum(); + default_nested_enum_ = value; +} + +// optional .protobuf_unittest.ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; +inline bool TestAllTypes::has_default_foreign_enum() const { + return (_has_bits_[2] & 0x00000001u) != 0; +} +inline void TestAllTypes::set_has_default_foreign_enum() { + _has_bits_[2] |= 0x00000001u; +} +inline void TestAllTypes::clear_has_default_foreign_enum() { + _has_bits_[2] &= ~0x00000001u; +} +inline void TestAllTypes::clear_default_foreign_enum() { + default_foreign_enum_ = 5; + clear_has_default_foreign_enum(); +} +inline protobuf_unittest::ForeignEnum TestAllTypes::default_foreign_enum() const { + return static_cast< protobuf_unittest::ForeignEnum >(default_foreign_enum_); +} +inline void TestAllTypes::set_default_foreign_enum(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + set_has_default_foreign_enum(); + default_foreign_enum_ = value; +} + +// optional .protobuf_unittest_import.ImportEnum default_import_enum = 83 [default = IMPORT_BAR]; +inline bool TestAllTypes::has_default_import_enum() const { + return (_has_bits_[2] & 0x00000002u) != 0; +} +inline void TestAllTypes::set_has_default_import_enum() { + _has_bits_[2] |= 0x00000002u; +} +inline void TestAllTypes::clear_has_default_import_enum() { + _has_bits_[2] &= ~0x00000002u; +} +inline void TestAllTypes::clear_default_import_enum() { + default_import_enum_ = 8; + clear_has_default_import_enum(); +} +inline protobuf_unittest_import::ImportEnum TestAllTypes::default_import_enum() const { + return static_cast< protobuf_unittest_import::ImportEnum >(default_import_enum_); +} +inline void TestAllTypes::set_default_import_enum(protobuf_unittest_import::ImportEnum value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); + set_has_default_import_enum(); + default_import_enum_ = value; +} + +// optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; +inline bool TestAllTypes::has_default_string_piece() const { + return (_has_bits_[2] & 0x00000004u) != 0; +} +inline void TestAllTypes::set_has_default_string_piece() { + _has_bits_[2] |= 0x00000004u; +} +inline void TestAllTypes::clear_has_default_string_piece() { + _has_bits_[2] &= ~0x00000004u; +} +inline void TestAllTypes::clear_default_string_piece() { + if (default_string_piece_ != &_default_default_string_piece_) { + default_string_piece_->assign(_default_default_string_piece_); + } + clear_has_default_string_piece(); +} +inline const ::std::string& TestAllTypes::default_string_piece() const { + return *default_string_piece_; +} +inline void TestAllTypes::set_default_string_piece(const ::std::string& value) { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string; + } + default_string_piece_->assign(value); +} +inline void TestAllTypes::set_default_string_piece(const char* value) { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string; + } + default_string_piece_->assign(value); +} +inline void TestAllTypes::set_default_string_piece(const char* value, size_t size) { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string; + } + default_string_piece_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_default_string_piece() { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string(_default_default_string_piece_); + } + return default_string_piece_; +} +inline ::std::string* TestAllTypes::release_default_string_piece() { + clear_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + return NULL; + } else { + ::std::string* temp = default_string_piece_; + default_string_piece_ = const_cast< ::std::string*>(&_default_default_string_piece_); + return temp; + } +} + +// optional string default_cord = 85 [default = "123", ctype = CORD]; +inline bool TestAllTypes::has_default_cord() const { + return (_has_bits_[2] & 0x00000008u) != 0; +} +inline void TestAllTypes::set_has_default_cord() { + _has_bits_[2] |= 0x00000008u; +} +inline void TestAllTypes::clear_has_default_cord() { + _has_bits_[2] &= ~0x00000008u; +} +inline void TestAllTypes::clear_default_cord() { + if (default_cord_ != &_default_default_cord_) { + default_cord_->assign(_default_default_cord_); + } + clear_has_default_cord(); +} +inline const ::std::string& TestAllTypes::default_cord() const { + return *default_cord_; +} +inline void TestAllTypes::set_default_cord(const ::std::string& value) { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string; + } + default_cord_->assign(value); +} +inline void TestAllTypes::set_default_cord(const char* value) { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string; + } + default_cord_->assign(value); +} +inline void TestAllTypes::set_default_cord(const char* value, size_t size) { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string; + } + default_cord_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypes::mutable_default_cord() { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string(_default_default_cord_); + } + return default_cord_; +} +inline ::std::string* TestAllTypes::release_default_cord() { + clear_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + return NULL; + } else { + ::std::string* temp = default_cord_; + default_cord_ = const_cast< ::std::string*>(&_default_default_cord_); + return temp; + } +} + +// ------------------------------------------------------------------- + +// TestDeprecatedFields + +// optional int32 deprecated_int32 = 1 [deprecated = true]; +inline bool TestDeprecatedFields::has_deprecated_int32() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestDeprecatedFields::set_has_deprecated_int32() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestDeprecatedFields::clear_has_deprecated_int32() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestDeprecatedFields::clear_deprecated_int32() { + deprecated_int32_ = 0; + clear_has_deprecated_int32(); +} +inline ::google::protobuf::int32 TestDeprecatedFields::deprecated_int32() const { + return deprecated_int32_; +} +inline void TestDeprecatedFields::set_deprecated_int32(::google::protobuf::int32 value) { + set_has_deprecated_int32(); + deprecated_int32_ = value; +} + +// ------------------------------------------------------------------- + +// ForeignMessage + +// optional int32 c = 1; +inline bool ForeignMessage::has_c() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ForeignMessage::set_has_c() { + _has_bits_[0] |= 0x00000001u; +} +inline void ForeignMessage::clear_has_c() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ForeignMessage::clear_c() { + c_ = 0; + clear_has_c(); +} +inline ::google::protobuf::int32 ForeignMessage::c() const { + return c_; +} +inline void ForeignMessage::set_c(::google::protobuf::int32 value) { + set_has_c(); + c_ = value; +} + +// ------------------------------------------------------------------- + +// TestAllExtensions + +// ------------------------------------------------------------------- + +// OptionalGroup_extension + +// optional int32 a = 17; +inline bool OptionalGroup_extension::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void OptionalGroup_extension::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void OptionalGroup_extension::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void OptionalGroup_extension::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 OptionalGroup_extension::a() const { + return a_; +} +inline void OptionalGroup_extension::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// RepeatedGroup_extension + +// optional int32 a = 47; +inline bool RepeatedGroup_extension::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void RepeatedGroup_extension::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void RepeatedGroup_extension::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void RepeatedGroup_extension::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 RepeatedGroup_extension::a() const { + return a_; +} +inline void RepeatedGroup_extension::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestNestedExtension + +// ------------------------------------------------------------------- + +// TestRequired + +// required int32 a = 1; +inline bool TestRequired::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestRequired::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestRequired::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestRequired::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestRequired::a() const { + return a_; +} +inline void TestRequired::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// optional int32 dummy2 = 2; +inline bool TestRequired::has_dummy2() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestRequired::set_has_dummy2() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestRequired::clear_has_dummy2() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestRequired::clear_dummy2() { + dummy2_ = 0; + clear_has_dummy2(); +} +inline ::google::protobuf::int32 TestRequired::dummy2() const { + return dummy2_; +} +inline void TestRequired::set_dummy2(::google::protobuf::int32 value) { + set_has_dummy2(); + dummy2_ = value; +} + +// required int32 b = 3; +inline bool TestRequired::has_b() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestRequired::set_has_b() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestRequired::clear_has_b() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestRequired::clear_b() { + b_ = 0; + clear_has_b(); +} +inline ::google::protobuf::int32 TestRequired::b() const { + return b_; +} +inline void TestRequired::set_b(::google::protobuf::int32 value) { + set_has_b(); + b_ = value; +} + +// optional int32 dummy4 = 4; +inline bool TestRequired::has_dummy4() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void TestRequired::set_has_dummy4() { + _has_bits_[0] |= 0x00000008u; +} +inline void TestRequired::clear_has_dummy4() { + _has_bits_[0] &= ~0x00000008u; +} +inline void TestRequired::clear_dummy4() { + dummy4_ = 0; + clear_has_dummy4(); +} +inline ::google::protobuf::int32 TestRequired::dummy4() const { + return dummy4_; +} +inline void TestRequired::set_dummy4(::google::protobuf::int32 value) { + set_has_dummy4(); + dummy4_ = value; +} + +// optional int32 dummy5 = 5; +inline bool TestRequired::has_dummy5() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void TestRequired::set_has_dummy5() { + _has_bits_[0] |= 0x00000010u; +} +inline void TestRequired::clear_has_dummy5() { + _has_bits_[0] &= ~0x00000010u; +} +inline void TestRequired::clear_dummy5() { + dummy5_ = 0; + clear_has_dummy5(); +} +inline ::google::protobuf::int32 TestRequired::dummy5() const { + return dummy5_; +} +inline void TestRequired::set_dummy5(::google::protobuf::int32 value) { + set_has_dummy5(); + dummy5_ = value; +} + +// optional int32 dummy6 = 6; +inline bool TestRequired::has_dummy6() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void TestRequired::set_has_dummy6() { + _has_bits_[0] |= 0x00000020u; +} +inline void TestRequired::clear_has_dummy6() { + _has_bits_[0] &= ~0x00000020u; +} +inline void TestRequired::clear_dummy6() { + dummy6_ = 0; + clear_has_dummy6(); +} +inline ::google::protobuf::int32 TestRequired::dummy6() const { + return dummy6_; +} +inline void TestRequired::set_dummy6(::google::protobuf::int32 value) { + set_has_dummy6(); + dummy6_ = value; +} + +// optional int32 dummy7 = 7; +inline bool TestRequired::has_dummy7() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void TestRequired::set_has_dummy7() { + _has_bits_[0] |= 0x00000040u; +} +inline void TestRequired::clear_has_dummy7() { + _has_bits_[0] &= ~0x00000040u; +} +inline void TestRequired::clear_dummy7() { + dummy7_ = 0; + clear_has_dummy7(); +} +inline ::google::protobuf::int32 TestRequired::dummy7() const { + return dummy7_; +} +inline void TestRequired::set_dummy7(::google::protobuf::int32 value) { + set_has_dummy7(); + dummy7_ = value; +} + +// optional int32 dummy8 = 8; +inline bool TestRequired::has_dummy8() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void TestRequired::set_has_dummy8() { + _has_bits_[0] |= 0x00000080u; +} +inline void TestRequired::clear_has_dummy8() { + _has_bits_[0] &= ~0x00000080u; +} +inline void TestRequired::clear_dummy8() { + dummy8_ = 0; + clear_has_dummy8(); +} +inline ::google::protobuf::int32 TestRequired::dummy8() const { + return dummy8_; +} +inline void TestRequired::set_dummy8(::google::protobuf::int32 value) { + set_has_dummy8(); + dummy8_ = value; +} + +// optional int32 dummy9 = 9; +inline bool TestRequired::has_dummy9() const { + return (_has_bits_[0] & 0x00000100u) != 0; +} +inline void TestRequired::set_has_dummy9() { + _has_bits_[0] |= 0x00000100u; +} +inline void TestRequired::clear_has_dummy9() { + _has_bits_[0] &= ~0x00000100u; +} +inline void TestRequired::clear_dummy9() { + dummy9_ = 0; + clear_has_dummy9(); +} +inline ::google::protobuf::int32 TestRequired::dummy9() const { + return dummy9_; +} +inline void TestRequired::set_dummy9(::google::protobuf::int32 value) { + set_has_dummy9(); + dummy9_ = value; +} + +// optional int32 dummy10 = 10; +inline bool TestRequired::has_dummy10() const { + return (_has_bits_[0] & 0x00000200u) != 0; +} +inline void TestRequired::set_has_dummy10() { + _has_bits_[0] |= 0x00000200u; +} +inline void TestRequired::clear_has_dummy10() { + _has_bits_[0] &= ~0x00000200u; +} +inline void TestRequired::clear_dummy10() { + dummy10_ = 0; + clear_has_dummy10(); +} +inline ::google::protobuf::int32 TestRequired::dummy10() const { + return dummy10_; +} +inline void TestRequired::set_dummy10(::google::protobuf::int32 value) { + set_has_dummy10(); + dummy10_ = value; +} + +// optional int32 dummy11 = 11; +inline bool TestRequired::has_dummy11() const { + return (_has_bits_[0] & 0x00000400u) != 0; +} +inline void TestRequired::set_has_dummy11() { + _has_bits_[0] |= 0x00000400u; +} +inline void TestRequired::clear_has_dummy11() { + _has_bits_[0] &= ~0x00000400u; +} +inline void TestRequired::clear_dummy11() { + dummy11_ = 0; + clear_has_dummy11(); +} +inline ::google::protobuf::int32 TestRequired::dummy11() const { + return dummy11_; +} +inline void TestRequired::set_dummy11(::google::protobuf::int32 value) { + set_has_dummy11(); + dummy11_ = value; +} + +// optional int32 dummy12 = 12; +inline bool TestRequired::has_dummy12() const { + return (_has_bits_[0] & 0x00000800u) != 0; +} +inline void TestRequired::set_has_dummy12() { + _has_bits_[0] |= 0x00000800u; +} +inline void TestRequired::clear_has_dummy12() { + _has_bits_[0] &= ~0x00000800u; +} +inline void TestRequired::clear_dummy12() { + dummy12_ = 0; + clear_has_dummy12(); +} +inline ::google::protobuf::int32 TestRequired::dummy12() const { + return dummy12_; +} +inline void TestRequired::set_dummy12(::google::protobuf::int32 value) { + set_has_dummy12(); + dummy12_ = value; +} + +// optional int32 dummy13 = 13; +inline bool TestRequired::has_dummy13() const { + return (_has_bits_[0] & 0x00001000u) != 0; +} +inline void TestRequired::set_has_dummy13() { + _has_bits_[0] |= 0x00001000u; +} +inline void TestRequired::clear_has_dummy13() { + _has_bits_[0] &= ~0x00001000u; +} +inline void TestRequired::clear_dummy13() { + dummy13_ = 0; + clear_has_dummy13(); +} +inline ::google::protobuf::int32 TestRequired::dummy13() const { + return dummy13_; +} +inline void TestRequired::set_dummy13(::google::protobuf::int32 value) { + set_has_dummy13(); + dummy13_ = value; +} + +// optional int32 dummy14 = 14; +inline bool TestRequired::has_dummy14() const { + return (_has_bits_[0] & 0x00002000u) != 0; +} +inline void TestRequired::set_has_dummy14() { + _has_bits_[0] |= 0x00002000u; +} +inline void TestRequired::clear_has_dummy14() { + _has_bits_[0] &= ~0x00002000u; +} +inline void TestRequired::clear_dummy14() { + dummy14_ = 0; + clear_has_dummy14(); +} +inline ::google::protobuf::int32 TestRequired::dummy14() const { + return dummy14_; +} +inline void TestRequired::set_dummy14(::google::protobuf::int32 value) { + set_has_dummy14(); + dummy14_ = value; +} + +// optional int32 dummy15 = 15; +inline bool TestRequired::has_dummy15() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +inline void TestRequired::set_has_dummy15() { + _has_bits_[0] |= 0x00004000u; +} +inline void TestRequired::clear_has_dummy15() { + _has_bits_[0] &= ~0x00004000u; +} +inline void TestRequired::clear_dummy15() { + dummy15_ = 0; + clear_has_dummy15(); +} +inline ::google::protobuf::int32 TestRequired::dummy15() const { + return dummy15_; +} +inline void TestRequired::set_dummy15(::google::protobuf::int32 value) { + set_has_dummy15(); + dummy15_ = value; +} + +// optional int32 dummy16 = 16; +inline bool TestRequired::has_dummy16() const { + return (_has_bits_[0] & 0x00008000u) != 0; +} +inline void TestRequired::set_has_dummy16() { + _has_bits_[0] |= 0x00008000u; +} +inline void TestRequired::clear_has_dummy16() { + _has_bits_[0] &= ~0x00008000u; +} +inline void TestRequired::clear_dummy16() { + dummy16_ = 0; + clear_has_dummy16(); +} +inline ::google::protobuf::int32 TestRequired::dummy16() const { + return dummy16_; +} +inline void TestRequired::set_dummy16(::google::protobuf::int32 value) { + set_has_dummy16(); + dummy16_ = value; +} + +// optional int32 dummy17 = 17; +inline bool TestRequired::has_dummy17() const { + return (_has_bits_[0] & 0x00010000u) != 0; +} +inline void TestRequired::set_has_dummy17() { + _has_bits_[0] |= 0x00010000u; +} +inline void TestRequired::clear_has_dummy17() { + _has_bits_[0] &= ~0x00010000u; +} +inline void TestRequired::clear_dummy17() { + dummy17_ = 0; + clear_has_dummy17(); +} +inline ::google::protobuf::int32 TestRequired::dummy17() const { + return dummy17_; +} +inline void TestRequired::set_dummy17(::google::protobuf::int32 value) { + set_has_dummy17(); + dummy17_ = value; +} + +// optional int32 dummy18 = 18; +inline bool TestRequired::has_dummy18() const { + return (_has_bits_[0] & 0x00020000u) != 0; +} +inline void TestRequired::set_has_dummy18() { + _has_bits_[0] |= 0x00020000u; +} +inline void TestRequired::clear_has_dummy18() { + _has_bits_[0] &= ~0x00020000u; +} +inline void TestRequired::clear_dummy18() { + dummy18_ = 0; + clear_has_dummy18(); +} +inline ::google::protobuf::int32 TestRequired::dummy18() const { + return dummy18_; +} +inline void TestRequired::set_dummy18(::google::protobuf::int32 value) { + set_has_dummy18(); + dummy18_ = value; +} + +// optional int32 dummy19 = 19; +inline bool TestRequired::has_dummy19() const { + return (_has_bits_[0] & 0x00040000u) != 0; +} +inline void TestRequired::set_has_dummy19() { + _has_bits_[0] |= 0x00040000u; +} +inline void TestRequired::clear_has_dummy19() { + _has_bits_[0] &= ~0x00040000u; +} +inline void TestRequired::clear_dummy19() { + dummy19_ = 0; + clear_has_dummy19(); +} +inline ::google::protobuf::int32 TestRequired::dummy19() const { + return dummy19_; +} +inline void TestRequired::set_dummy19(::google::protobuf::int32 value) { + set_has_dummy19(); + dummy19_ = value; +} + +// optional int32 dummy20 = 20; +inline bool TestRequired::has_dummy20() const { + return (_has_bits_[0] & 0x00080000u) != 0; +} +inline void TestRequired::set_has_dummy20() { + _has_bits_[0] |= 0x00080000u; +} +inline void TestRequired::clear_has_dummy20() { + _has_bits_[0] &= ~0x00080000u; +} +inline void TestRequired::clear_dummy20() { + dummy20_ = 0; + clear_has_dummy20(); +} +inline ::google::protobuf::int32 TestRequired::dummy20() const { + return dummy20_; +} +inline void TestRequired::set_dummy20(::google::protobuf::int32 value) { + set_has_dummy20(); + dummy20_ = value; +} + +// optional int32 dummy21 = 21; +inline bool TestRequired::has_dummy21() const { + return (_has_bits_[0] & 0x00100000u) != 0; +} +inline void TestRequired::set_has_dummy21() { + _has_bits_[0] |= 0x00100000u; +} +inline void TestRequired::clear_has_dummy21() { + _has_bits_[0] &= ~0x00100000u; +} +inline void TestRequired::clear_dummy21() { + dummy21_ = 0; + clear_has_dummy21(); +} +inline ::google::protobuf::int32 TestRequired::dummy21() const { + return dummy21_; +} +inline void TestRequired::set_dummy21(::google::protobuf::int32 value) { + set_has_dummy21(); + dummy21_ = value; +} + +// optional int32 dummy22 = 22; +inline bool TestRequired::has_dummy22() const { + return (_has_bits_[0] & 0x00200000u) != 0; +} +inline void TestRequired::set_has_dummy22() { + _has_bits_[0] |= 0x00200000u; +} +inline void TestRequired::clear_has_dummy22() { + _has_bits_[0] &= ~0x00200000u; +} +inline void TestRequired::clear_dummy22() { + dummy22_ = 0; + clear_has_dummy22(); +} +inline ::google::protobuf::int32 TestRequired::dummy22() const { + return dummy22_; +} +inline void TestRequired::set_dummy22(::google::protobuf::int32 value) { + set_has_dummy22(); + dummy22_ = value; +} + +// optional int32 dummy23 = 23; +inline bool TestRequired::has_dummy23() const { + return (_has_bits_[0] & 0x00400000u) != 0; +} +inline void TestRequired::set_has_dummy23() { + _has_bits_[0] |= 0x00400000u; +} +inline void TestRequired::clear_has_dummy23() { + _has_bits_[0] &= ~0x00400000u; +} +inline void TestRequired::clear_dummy23() { + dummy23_ = 0; + clear_has_dummy23(); +} +inline ::google::protobuf::int32 TestRequired::dummy23() const { + return dummy23_; +} +inline void TestRequired::set_dummy23(::google::protobuf::int32 value) { + set_has_dummy23(); + dummy23_ = value; +} + +// optional int32 dummy24 = 24; +inline bool TestRequired::has_dummy24() const { + return (_has_bits_[0] & 0x00800000u) != 0; +} +inline void TestRequired::set_has_dummy24() { + _has_bits_[0] |= 0x00800000u; +} +inline void TestRequired::clear_has_dummy24() { + _has_bits_[0] &= ~0x00800000u; +} +inline void TestRequired::clear_dummy24() { + dummy24_ = 0; + clear_has_dummy24(); +} +inline ::google::protobuf::int32 TestRequired::dummy24() const { + return dummy24_; +} +inline void TestRequired::set_dummy24(::google::protobuf::int32 value) { + set_has_dummy24(); + dummy24_ = value; +} + +// optional int32 dummy25 = 25; +inline bool TestRequired::has_dummy25() const { + return (_has_bits_[0] & 0x01000000u) != 0; +} +inline void TestRequired::set_has_dummy25() { + _has_bits_[0] |= 0x01000000u; +} +inline void TestRequired::clear_has_dummy25() { + _has_bits_[0] &= ~0x01000000u; +} +inline void TestRequired::clear_dummy25() { + dummy25_ = 0; + clear_has_dummy25(); +} +inline ::google::protobuf::int32 TestRequired::dummy25() const { + return dummy25_; +} +inline void TestRequired::set_dummy25(::google::protobuf::int32 value) { + set_has_dummy25(); + dummy25_ = value; +} + +// optional int32 dummy26 = 26; +inline bool TestRequired::has_dummy26() const { + return (_has_bits_[0] & 0x02000000u) != 0; +} +inline void TestRequired::set_has_dummy26() { + _has_bits_[0] |= 0x02000000u; +} +inline void TestRequired::clear_has_dummy26() { + _has_bits_[0] &= ~0x02000000u; +} +inline void TestRequired::clear_dummy26() { + dummy26_ = 0; + clear_has_dummy26(); +} +inline ::google::protobuf::int32 TestRequired::dummy26() const { + return dummy26_; +} +inline void TestRequired::set_dummy26(::google::protobuf::int32 value) { + set_has_dummy26(); + dummy26_ = value; +} + +// optional int32 dummy27 = 27; +inline bool TestRequired::has_dummy27() const { + return (_has_bits_[0] & 0x04000000u) != 0; +} +inline void TestRequired::set_has_dummy27() { + _has_bits_[0] |= 0x04000000u; +} +inline void TestRequired::clear_has_dummy27() { + _has_bits_[0] &= ~0x04000000u; +} +inline void TestRequired::clear_dummy27() { + dummy27_ = 0; + clear_has_dummy27(); +} +inline ::google::protobuf::int32 TestRequired::dummy27() const { + return dummy27_; +} +inline void TestRequired::set_dummy27(::google::protobuf::int32 value) { + set_has_dummy27(); + dummy27_ = value; +} + +// optional int32 dummy28 = 28; +inline bool TestRequired::has_dummy28() const { + return (_has_bits_[0] & 0x08000000u) != 0; +} +inline void TestRequired::set_has_dummy28() { + _has_bits_[0] |= 0x08000000u; +} +inline void TestRequired::clear_has_dummy28() { + _has_bits_[0] &= ~0x08000000u; +} +inline void TestRequired::clear_dummy28() { + dummy28_ = 0; + clear_has_dummy28(); +} +inline ::google::protobuf::int32 TestRequired::dummy28() const { + return dummy28_; +} +inline void TestRequired::set_dummy28(::google::protobuf::int32 value) { + set_has_dummy28(); + dummy28_ = value; +} + +// optional int32 dummy29 = 29; +inline bool TestRequired::has_dummy29() const { + return (_has_bits_[0] & 0x10000000u) != 0; +} +inline void TestRequired::set_has_dummy29() { + _has_bits_[0] |= 0x10000000u; +} +inline void TestRequired::clear_has_dummy29() { + _has_bits_[0] &= ~0x10000000u; +} +inline void TestRequired::clear_dummy29() { + dummy29_ = 0; + clear_has_dummy29(); +} +inline ::google::protobuf::int32 TestRequired::dummy29() const { + return dummy29_; +} +inline void TestRequired::set_dummy29(::google::protobuf::int32 value) { + set_has_dummy29(); + dummy29_ = value; +} + +// optional int32 dummy30 = 30; +inline bool TestRequired::has_dummy30() const { + return (_has_bits_[0] & 0x20000000u) != 0; +} +inline void TestRequired::set_has_dummy30() { + _has_bits_[0] |= 0x20000000u; +} +inline void TestRequired::clear_has_dummy30() { + _has_bits_[0] &= ~0x20000000u; +} +inline void TestRequired::clear_dummy30() { + dummy30_ = 0; + clear_has_dummy30(); +} +inline ::google::protobuf::int32 TestRequired::dummy30() const { + return dummy30_; +} +inline void TestRequired::set_dummy30(::google::protobuf::int32 value) { + set_has_dummy30(); + dummy30_ = value; +} + +// optional int32 dummy31 = 31; +inline bool TestRequired::has_dummy31() const { + return (_has_bits_[0] & 0x40000000u) != 0; +} +inline void TestRequired::set_has_dummy31() { + _has_bits_[0] |= 0x40000000u; +} +inline void TestRequired::clear_has_dummy31() { + _has_bits_[0] &= ~0x40000000u; +} +inline void TestRequired::clear_dummy31() { + dummy31_ = 0; + clear_has_dummy31(); +} +inline ::google::protobuf::int32 TestRequired::dummy31() const { + return dummy31_; +} +inline void TestRequired::set_dummy31(::google::protobuf::int32 value) { + set_has_dummy31(); + dummy31_ = value; +} + +// optional int32 dummy32 = 32; +inline bool TestRequired::has_dummy32() const { + return (_has_bits_[0] & 0x80000000u) != 0; +} +inline void TestRequired::set_has_dummy32() { + _has_bits_[0] |= 0x80000000u; +} +inline void TestRequired::clear_has_dummy32() { + _has_bits_[0] &= ~0x80000000u; +} +inline void TestRequired::clear_dummy32() { + dummy32_ = 0; + clear_has_dummy32(); +} +inline ::google::protobuf::int32 TestRequired::dummy32() const { + return dummy32_; +} +inline void TestRequired::set_dummy32(::google::protobuf::int32 value) { + set_has_dummy32(); + dummy32_ = value; +} + +// required int32 c = 33; +inline bool TestRequired::has_c() const { + return (_has_bits_[1] & 0x00000001u) != 0; +} +inline void TestRequired::set_has_c() { + _has_bits_[1] |= 0x00000001u; +} +inline void TestRequired::clear_has_c() { + _has_bits_[1] &= ~0x00000001u; +} +inline void TestRequired::clear_c() { + c_ = 0; + clear_has_c(); +} +inline ::google::protobuf::int32 TestRequired::c() const { + return c_; +} +inline void TestRequired::set_c(::google::protobuf::int32 value) { + set_has_c(); + c_ = value; +} + +// ------------------------------------------------------------------- + +// TestRequiredForeign + +// optional .protobuf_unittest.TestRequired optional_message = 1; +inline bool TestRequiredForeign::has_optional_message() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestRequiredForeign::set_has_optional_message() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestRequiredForeign::clear_has_optional_message() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestRequiredForeign::clear_optional_message() { + if (optional_message_ != NULL) optional_message_->::protobuf_unittest::TestRequired::Clear(); + clear_has_optional_message(); +} +inline const ::protobuf_unittest::TestRequired& TestRequiredForeign::optional_message() const { + return optional_message_ != NULL ? *optional_message_ : *default_instance_->optional_message_; +} +inline ::protobuf_unittest::TestRequired* TestRequiredForeign::mutable_optional_message() { + set_has_optional_message(); + if (optional_message_ == NULL) optional_message_ = new ::protobuf_unittest::TestRequired; + return optional_message_; +} +inline ::protobuf_unittest::TestRequired* TestRequiredForeign::release_optional_message() { + clear_has_optional_message(); + ::protobuf_unittest::TestRequired* temp = optional_message_; + optional_message_ = NULL; + return temp; +} + +// repeated .protobuf_unittest.TestRequired repeated_message = 2; +inline int TestRequiredForeign::repeated_message_size() const { + return repeated_message_.size(); +} +inline void TestRequiredForeign::clear_repeated_message() { + repeated_message_.Clear(); +} +inline const ::protobuf_unittest::TestRequired& TestRequiredForeign::repeated_message(int index) const { + return repeated_message_.Get(index); +} +inline ::protobuf_unittest::TestRequired* TestRequiredForeign::mutable_repeated_message(int index) { + return repeated_message_.Mutable(index); +} +inline ::protobuf_unittest::TestRequired* TestRequiredForeign::add_repeated_message() { + return repeated_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >& +TestRequiredForeign::repeated_message() const { + return repeated_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >* +TestRequiredForeign::mutable_repeated_message() { + return &repeated_message_; +} + +// optional int32 dummy = 3; +inline bool TestRequiredForeign::has_dummy() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestRequiredForeign::set_has_dummy() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestRequiredForeign::clear_has_dummy() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestRequiredForeign::clear_dummy() { + dummy_ = 0; + clear_has_dummy(); +} +inline ::google::protobuf::int32 TestRequiredForeign::dummy() const { + return dummy_; +} +inline void TestRequiredForeign::set_dummy(::google::protobuf::int32 value) { + set_has_dummy(); + dummy_ = value; +} + +// ------------------------------------------------------------------- + +// TestForeignNested + +// optional .protobuf_unittest.TestAllTypes.NestedMessage foreign_nested = 1; +inline bool TestForeignNested::has_foreign_nested() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestForeignNested::set_has_foreign_nested() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestForeignNested::clear_has_foreign_nested() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestForeignNested::clear_foreign_nested() { + if (foreign_nested_ != NULL) foreign_nested_->::protobuf_unittest::TestAllTypes_NestedMessage::Clear(); + clear_has_foreign_nested(); +} +inline const ::protobuf_unittest::TestAllTypes_NestedMessage& TestForeignNested::foreign_nested() const { + return foreign_nested_ != NULL ? *foreign_nested_ : *default_instance_->foreign_nested_; +} +inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestForeignNested::mutable_foreign_nested() { + set_has_foreign_nested(); + if (foreign_nested_ == NULL) foreign_nested_ = new ::protobuf_unittest::TestAllTypes_NestedMessage; + return foreign_nested_; +} +inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestForeignNested::release_foreign_nested() { + clear_has_foreign_nested(); + ::protobuf_unittest::TestAllTypes_NestedMessage* temp = foreign_nested_; + foreign_nested_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// TestEmptyMessage + +// ------------------------------------------------------------------- + +// TestEmptyMessageWithExtensions + +// ------------------------------------------------------------------- + +// TestMultipleExtensionRanges + +// ------------------------------------------------------------------- + +// TestReallyLargeTagNumber + +// optional int32 a = 1; +inline bool TestReallyLargeTagNumber::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestReallyLargeTagNumber::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestReallyLargeTagNumber::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestReallyLargeTagNumber::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestReallyLargeTagNumber::a() const { + return a_; +} +inline void TestReallyLargeTagNumber::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// optional int32 bb = 268435455; +inline bool TestReallyLargeTagNumber::has_bb() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestReallyLargeTagNumber::set_has_bb() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestReallyLargeTagNumber::clear_has_bb() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestReallyLargeTagNumber::clear_bb() { + bb_ = 0; + clear_has_bb(); +} +inline ::google::protobuf::int32 TestReallyLargeTagNumber::bb() const { + return bb_; +} +inline void TestReallyLargeTagNumber::set_bb(::google::protobuf::int32 value) { + set_has_bb(); + bb_ = value; +} + +// ------------------------------------------------------------------- + +// TestRecursiveMessage + +// optional .protobuf_unittest.TestRecursiveMessage a = 1; +inline bool TestRecursiveMessage::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestRecursiveMessage::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestRecursiveMessage::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestRecursiveMessage::clear_a() { + if (a_ != NULL) a_->::protobuf_unittest::TestRecursiveMessage::Clear(); + clear_has_a(); +} +inline const ::protobuf_unittest::TestRecursiveMessage& TestRecursiveMessage::a() const { + return a_ != NULL ? *a_ : *default_instance_->a_; +} +inline ::protobuf_unittest::TestRecursiveMessage* TestRecursiveMessage::mutable_a() { + set_has_a(); + if (a_ == NULL) a_ = new ::protobuf_unittest::TestRecursiveMessage; + return a_; +} +inline ::protobuf_unittest::TestRecursiveMessage* TestRecursiveMessage::release_a() { + clear_has_a(); + ::protobuf_unittest::TestRecursiveMessage* temp = a_; + a_ = NULL; + return temp; +} + +// optional int32 i = 2; +inline bool TestRecursiveMessage::has_i() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestRecursiveMessage::set_has_i() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestRecursiveMessage::clear_has_i() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestRecursiveMessage::clear_i() { + i_ = 0; + clear_has_i(); +} +inline ::google::protobuf::int32 TestRecursiveMessage::i() const { + return i_; +} +inline void TestRecursiveMessage::set_i(::google::protobuf::int32 value) { + set_has_i(); + i_ = value; +} + +// ------------------------------------------------------------------- + +// TestMutualRecursionA + +// optional .protobuf_unittest.TestMutualRecursionB bb = 1; +inline bool TestMutualRecursionA::has_bb() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestMutualRecursionA::set_has_bb() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestMutualRecursionA::clear_has_bb() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestMutualRecursionA::clear_bb() { + if (bb_ != NULL) bb_->::protobuf_unittest::TestMutualRecursionB::Clear(); + clear_has_bb(); +} +inline const ::protobuf_unittest::TestMutualRecursionB& TestMutualRecursionA::bb() const { + return bb_ != NULL ? *bb_ : *default_instance_->bb_; +} +inline ::protobuf_unittest::TestMutualRecursionB* TestMutualRecursionA::mutable_bb() { + set_has_bb(); + if (bb_ == NULL) bb_ = new ::protobuf_unittest::TestMutualRecursionB; + return bb_; +} +inline ::protobuf_unittest::TestMutualRecursionB* TestMutualRecursionA::release_bb() { + clear_has_bb(); + ::protobuf_unittest::TestMutualRecursionB* temp = bb_; + bb_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// TestMutualRecursionB + +// optional .protobuf_unittest.TestMutualRecursionA a = 1; +inline bool TestMutualRecursionB::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestMutualRecursionB::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestMutualRecursionB::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestMutualRecursionB::clear_a() { + if (a_ != NULL) a_->::protobuf_unittest::TestMutualRecursionA::Clear(); + clear_has_a(); +} +inline const ::protobuf_unittest::TestMutualRecursionA& TestMutualRecursionB::a() const { + return a_ != NULL ? *a_ : *default_instance_->a_; +} +inline ::protobuf_unittest::TestMutualRecursionA* TestMutualRecursionB::mutable_a() { + set_has_a(); + if (a_ == NULL) a_ = new ::protobuf_unittest::TestMutualRecursionA; + return a_; +} +inline ::protobuf_unittest::TestMutualRecursionA* TestMutualRecursionB::release_a() { + clear_has_a(); + ::protobuf_unittest::TestMutualRecursionA* temp = a_; + a_ = NULL; + return temp; +} + +// optional int32 optional_int32 = 2; +inline bool TestMutualRecursionB::has_optional_int32() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestMutualRecursionB::set_has_optional_int32() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestMutualRecursionB::clear_has_optional_int32() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestMutualRecursionB::clear_optional_int32() { + optional_int32_ = 0; + clear_has_optional_int32(); +} +inline ::google::protobuf::int32 TestMutualRecursionB::optional_int32() const { + return optional_int32_; +} +inline void TestMutualRecursionB::set_optional_int32(::google::protobuf::int32 value) { + set_has_optional_int32(); + optional_int32_ = value; +} + +// ------------------------------------------------------------------- + +// TestDupFieldNumber_Foo + +// optional int32 a = 1; +inline bool TestDupFieldNumber_Foo::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestDupFieldNumber_Foo::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestDupFieldNumber_Foo::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestDupFieldNumber_Foo::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestDupFieldNumber_Foo::a() const { + return a_; +} +inline void TestDupFieldNumber_Foo::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestDupFieldNumber_Bar + +// optional int32 a = 1; +inline bool TestDupFieldNumber_Bar::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestDupFieldNumber_Bar::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestDupFieldNumber_Bar::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestDupFieldNumber_Bar::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestDupFieldNumber_Bar::a() const { + return a_; +} +inline void TestDupFieldNumber_Bar::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestDupFieldNumber + +// optional int32 a = 1; +inline bool TestDupFieldNumber::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestDupFieldNumber::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestDupFieldNumber::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestDupFieldNumber::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestDupFieldNumber::a() const { + return a_; +} +inline void TestDupFieldNumber::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// optional group Foo = 2 { +inline bool TestDupFieldNumber::has_foo() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestDupFieldNumber::set_has_foo() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestDupFieldNumber::clear_has_foo() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestDupFieldNumber::clear_foo() { + if (foo_ != NULL) foo_->::protobuf_unittest::TestDupFieldNumber_Foo::Clear(); + clear_has_foo(); +} +inline const ::protobuf_unittest::TestDupFieldNumber_Foo& TestDupFieldNumber::foo() const { + return foo_ != NULL ? *foo_ : *default_instance_->foo_; +} +inline ::protobuf_unittest::TestDupFieldNumber_Foo* TestDupFieldNumber::mutable_foo() { + set_has_foo(); + if (foo_ == NULL) foo_ = new ::protobuf_unittest::TestDupFieldNumber_Foo; + return foo_; +} +inline ::protobuf_unittest::TestDupFieldNumber_Foo* TestDupFieldNumber::release_foo() { + clear_has_foo(); + ::protobuf_unittest::TestDupFieldNumber_Foo* temp = foo_; + foo_ = NULL; + return temp; +} + +// optional group Bar = 3 { +inline bool TestDupFieldNumber::has_bar() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestDupFieldNumber::set_has_bar() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestDupFieldNumber::clear_has_bar() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestDupFieldNumber::clear_bar() { + if (bar_ != NULL) bar_->::protobuf_unittest::TestDupFieldNumber_Bar::Clear(); + clear_has_bar(); +} +inline const ::protobuf_unittest::TestDupFieldNumber_Bar& TestDupFieldNumber::bar() const { + return bar_ != NULL ? *bar_ : *default_instance_->bar_; +} +inline ::protobuf_unittest::TestDupFieldNumber_Bar* TestDupFieldNumber::mutable_bar() { + set_has_bar(); + if (bar_ == NULL) bar_ = new ::protobuf_unittest::TestDupFieldNumber_Bar; + return bar_; +} +inline ::protobuf_unittest::TestDupFieldNumber_Bar* TestDupFieldNumber::release_bar() { + clear_has_bar(); + ::protobuf_unittest::TestDupFieldNumber_Bar* temp = bar_; + bar_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// TestNestedMessageHasBits_NestedMessage + +// repeated int32 nestedmessage_repeated_int32 = 1; +inline int TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_int32_size() const { + return nestedmessage_repeated_int32_.size(); +} +inline void TestNestedMessageHasBits_NestedMessage::clear_nestedmessage_repeated_int32() { + nestedmessage_repeated_int32_.Clear(); +} +inline ::google::protobuf::int32 TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_int32(int index) const { + return nestedmessage_repeated_int32_.Get(index); +} +inline void TestNestedMessageHasBits_NestedMessage::set_nestedmessage_repeated_int32(int index, ::google::protobuf::int32 value) { + nestedmessage_repeated_int32_.Set(index, value); +} +inline void TestNestedMessageHasBits_NestedMessage::add_nestedmessage_repeated_int32(::google::protobuf::int32 value) { + nestedmessage_repeated_int32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_int32() const { + return nestedmessage_repeated_int32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestNestedMessageHasBits_NestedMessage::mutable_nestedmessage_repeated_int32() { + return &nestedmessage_repeated_int32_; +} + +// repeated .protobuf_unittest.ForeignMessage nestedmessage_repeated_foreignmessage = 2; +inline int TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_foreignmessage_size() const { + return nestedmessage_repeated_foreignmessage_.size(); +} +inline void TestNestedMessageHasBits_NestedMessage::clear_nestedmessage_repeated_foreignmessage() { + nestedmessage_repeated_foreignmessage_.Clear(); +} +inline const ::protobuf_unittest::ForeignMessage& TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_foreignmessage(int index) const { + return nestedmessage_repeated_foreignmessage_.Get(index); +} +inline ::protobuf_unittest::ForeignMessage* TestNestedMessageHasBits_NestedMessage::mutable_nestedmessage_repeated_foreignmessage(int index) { + return nestedmessage_repeated_foreignmessage_.Mutable(index); +} +inline ::protobuf_unittest::ForeignMessage* TestNestedMessageHasBits_NestedMessage::add_nestedmessage_repeated_foreignmessage() { + return nestedmessage_repeated_foreignmessage_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& +TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_foreignmessage() const { + return nestedmessage_repeated_foreignmessage_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* +TestNestedMessageHasBits_NestedMessage::mutable_nestedmessage_repeated_foreignmessage() { + return &nestedmessage_repeated_foreignmessage_; +} + +// ------------------------------------------------------------------- + +// TestNestedMessageHasBits + +// optional .protobuf_unittest.TestNestedMessageHasBits.NestedMessage optional_nested_message = 1; +inline bool TestNestedMessageHasBits::has_optional_nested_message() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestNestedMessageHasBits::set_has_optional_nested_message() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestNestedMessageHasBits::clear_has_optional_nested_message() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestNestedMessageHasBits::clear_optional_nested_message() { + if (optional_nested_message_ != NULL) optional_nested_message_->::protobuf_unittest::TestNestedMessageHasBits_NestedMessage::Clear(); + clear_has_optional_nested_message(); +} +inline const ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage& TestNestedMessageHasBits::optional_nested_message() const { + return optional_nested_message_ != NULL ? *optional_nested_message_ : *default_instance_->optional_nested_message_; +} +inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* TestNestedMessageHasBits::mutable_optional_nested_message() { + set_has_optional_nested_message(); + if (optional_nested_message_ == NULL) optional_nested_message_ = new ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage; + return optional_nested_message_; +} +inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* TestNestedMessageHasBits::release_optional_nested_message() { + clear_has_optional_nested_message(); + ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* temp = optional_nested_message_; + optional_nested_message_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// TestCamelCaseFieldNames + +// optional int32 PrimitiveField = 1; +inline bool TestCamelCaseFieldNames::has_primitivefield() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestCamelCaseFieldNames::set_has_primitivefield() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestCamelCaseFieldNames::clear_has_primitivefield() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestCamelCaseFieldNames::clear_primitivefield() { + primitivefield_ = 0; + clear_has_primitivefield(); +} +inline ::google::protobuf::int32 TestCamelCaseFieldNames::primitivefield() const { + return primitivefield_; +} +inline void TestCamelCaseFieldNames::set_primitivefield(::google::protobuf::int32 value) { + set_has_primitivefield(); + primitivefield_ = value; +} + +// optional string StringField = 2; +inline bool TestCamelCaseFieldNames::has_stringfield() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestCamelCaseFieldNames::set_has_stringfield() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestCamelCaseFieldNames::clear_has_stringfield() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestCamelCaseFieldNames::clear_stringfield() { + if (stringfield_ != &::google::protobuf::internal::kEmptyString) { + stringfield_->clear(); + } + clear_has_stringfield(); +} +inline const ::std::string& TestCamelCaseFieldNames::stringfield() const { + return *stringfield_; +} +inline void TestCamelCaseFieldNames::set_stringfield(const ::std::string& value) { + set_has_stringfield(); + if (stringfield_ == &::google::protobuf::internal::kEmptyString) { + stringfield_ = new ::std::string; + } + stringfield_->assign(value); +} +inline void TestCamelCaseFieldNames::set_stringfield(const char* value) { + set_has_stringfield(); + if (stringfield_ == &::google::protobuf::internal::kEmptyString) { + stringfield_ = new ::std::string; + } + stringfield_->assign(value); +} +inline void TestCamelCaseFieldNames::set_stringfield(const char* value, size_t size) { + set_has_stringfield(); + if (stringfield_ == &::google::protobuf::internal::kEmptyString) { + stringfield_ = new ::std::string; + } + stringfield_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestCamelCaseFieldNames::mutable_stringfield() { + set_has_stringfield(); + if (stringfield_ == &::google::protobuf::internal::kEmptyString) { + stringfield_ = new ::std::string; + } + return stringfield_; +} +inline ::std::string* TestCamelCaseFieldNames::release_stringfield() { + clear_has_stringfield(); + if (stringfield_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = stringfield_; + stringfield_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional .protobuf_unittest.ForeignEnum EnumField = 3; +inline bool TestCamelCaseFieldNames::has_enumfield() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestCamelCaseFieldNames::set_has_enumfield() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestCamelCaseFieldNames::clear_has_enumfield() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestCamelCaseFieldNames::clear_enumfield() { + enumfield_ = 4; + clear_has_enumfield(); +} +inline protobuf_unittest::ForeignEnum TestCamelCaseFieldNames::enumfield() const { + return static_cast< protobuf_unittest::ForeignEnum >(enumfield_); +} +inline void TestCamelCaseFieldNames::set_enumfield(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + set_has_enumfield(); + enumfield_ = value; +} + +// optional .protobuf_unittest.ForeignMessage MessageField = 4; +inline bool TestCamelCaseFieldNames::has_messagefield() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void TestCamelCaseFieldNames::set_has_messagefield() { + _has_bits_[0] |= 0x00000008u; +} +inline void TestCamelCaseFieldNames::clear_has_messagefield() { + _has_bits_[0] &= ~0x00000008u; +} +inline void TestCamelCaseFieldNames::clear_messagefield() { + if (messagefield_ != NULL) messagefield_->::protobuf_unittest::ForeignMessage::Clear(); + clear_has_messagefield(); +} +inline const ::protobuf_unittest::ForeignMessage& TestCamelCaseFieldNames::messagefield() const { + return messagefield_ != NULL ? *messagefield_ : *default_instance_->messagefield_; +} +inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::mutable_messagefield() { + set_has_messagefield(); + if (messagefield_ == NULL) messagefield_ = new ::protobuf_unittest::ForeignMessage; + return messagefield_; +} +inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::release_messagefield() { + clear_has_messagefield(); + ::protobuf_unittest::ForeignMessage* temp = messagefield_; + messagefield_ = NULL; + return temp; +} + +// optional string StringPieceField = 5 [ctype = STRING_PIECE]; +inline bool TestCamelCaseFieldNames::has_stringpiecefield() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void TestCamelCaseFieldNames::set_has_stringpiecefield() { + _has_bits_[0] |= 0x00000010u; +} +inline void TestCamelCaseFieldNames::clear_has_stringpiecefield() { + _has_bits_[0] &= ~0x00000010u; +} +inline void TestCamelCaseFieldNames::clear_stringpiecefield() { + if (stringpiecefield_ != &::google::protobuf::internal::kEmptyString) { + stringpiecefield_->clear(); + } + clear_has_stringpiecefield(); +} +inline const ::std::string& TestCamelCaseFieldNames::stringpiecefield() const { + return *stringpiecefield_; +} +inline void TestCamelCaseFieldNames::set_stringpiecefield(const ::std::string& value) { + set_has_stringpiecefield(); + if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { + stringpiecefield_ = new ::std::string; + } + stringpiecefield_->assign(value); +} +inline void TestCamelCaseFieldNames::set_stringpiecefield(const char* value) { + set_has_stringpiecefield(); + if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { + stringpiecefield_ = new ::std::string; + } + stringpiecefield_->assign(value); +} +inline void TestCamelCaseFieldNames::set_stringpiecefield(const char* value, size_t size) { + set_has_stringpiecefield(); + if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { + stringpiecefield_ = new ::std::string; + } + stringpiecefield_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestCamelCaseFieldNames::mutable_stringpiecefield() { + set_has_stringpiecefield(); + if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { + stringpiecefield_ = new ::std::string; + } + return stringpiecefield_; +} +inline ::std::string* TestCamelCaseFieldNames::release_stringpiecefield() { + clear_has_stringpiecefield(); + if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = stringpiecefield_; + stringpiecefield_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string CordField = 6 [ctype = CORD]; +inline bool TestCamelCaseFieldNames::has_cordfield() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void TestCamelCaseFieldNames::set_has_cordfield() { + _has_bits_[0] |= 0x00000020u; +} +inline void TestCamelCaseFieldNames::clear_has_cordfield() { + _has_bits_[0] &= ~0x00000020u; +} +inline void TestCamelCaseFieldNames::clear_cordfield() { + if (cordfield_ != &::google::protobuf::internal::kEmptyString) { + cordfield_->clear(); + } + clear_has_cordfield(); +} +inline const ::std::string& TestCamelCaseFieldNames::cordfield() const { + return *cordfield_; +} +inline void TestCamelCaseFieldNames::set_cordfield(const ::std::string& value) { + set_has_cordfield(); + if (cordfield_ == &::google::protobuf::internal::kEmptyString) { + cordfield_ = new ::std::string; + } + cordfield_->assign(value); +} +inline void TestCamelCaseFieldNames::set_cordfield(const char* value) { + set_has_cordfield(); + if (cordfield_ == &::google::protobuf::internal::kEmptyString) { + cordfield_ = new ::std::string; + } + cordfield_->assign(value); +} +inline void TestCamelCaseFieldNames::set_cordfield(const char* value, size_t size) { + set_has_cordfield(); + if (cordfield_ == &::google::protobuf::internal::kEmptyString) { + cordfield_ = new ::std::string; + } + cordfield_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestCamelCaseFieldNames::mutable_cordfield() { + set_has_cordfield(); + if (cordfield_ == &::google::protobuf::internal::kEmptyString) { + cordfield_ = new ::std::string; + } + return cordfield_; +} +inline ::std::string* TestCamelCaseFieldNames::release_cordfield() { + clear_has_cordfield(); + if (cordfield_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = cordfield_; + cordfield_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated int32 RepeatedPrimitiveField = 7; +inline int TestCamelCaseFieldNames::repeatedprimitivefield_size() const { + return repeatedprimitivefield_.size(); +} +inline void TestCamelCaseFieldNames::clear_repeatedprimitivefield() { + repeatedprimitivefield_.Clear(); +} +inline ::google::protobuf::int32 TestCamelCaseFieldNames::repeatedprimitivefield(int index) const { + return repeatedprimitivefield_.Get(index); +} +inline void TestCamelCaseFieldNames::set_repeatedprimitivefield(int index, ::google::protobuf::int32 value) { + repeatedprimitivefield_.Set(index, value); +} +inline void TestCamelCaseFieldNames::add_repeatedprimitivefield(::google::protobuf::int32 value) { + repeatedprimitivefield_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestCamelCaseFieldNames::repeatedprimitivefield() const { + return repeatedprimitivefield_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestCamelCaseFieldNames::mutable_repeatedprimitivefield() { + return &repeatedprimitivefield_; +} + +// repeated string RepeatedStringField = 8; +inline int TestCamelCaseFieldNames::repeatedstringfield_size() const { + return repeatedstringfield_.size(); +} +inline void TestCamelCaseFieldNames::clear_repeatedstringfield() { + repeatedstringfield_.Clear(); +} +inline const ::std::string& TestCamelCaseFieldNames::repeatedstringfield(int index) const { + return repeatedstringfield_.Get(index); +} +inline ::std::string* TestCamelCaseFieldNames::mutable_repeatedstringfield(int index) { + return repeatedstringfield_.Mutable(index); +} +inline void TestCamelCaseFieldNames::set_repeatedstringfield(int index, const ::std::string& value) { + repeatedstringfield_.Mutable(index)->assign(value); +} +inline void TestCamelCaseFieldNames::set_repeatedstringfield(int index, const char* value) { + repeatedstringfield_.Mutable(index)->assign(value); +} +inline void TestCamelCaseFieldNames::set_repeatedstringfield(int index, const char* value, size_t size) { + repeatedstringfield_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestCamelCaseFieldNames::add_repeatedstringfield() { + return repeatedstringfield_.Add(); +} +inline void TestCamelCaseFieldNames::add_repeatedstringfield(const ::std::string& value) { + repeatedstringfield_.Add()->assign(value); +} +inline void TestCamelCaseFieldNames::add_repeatedstringfield(const char* value) { + repeatedstringfield_.Add()->assign(value); +} +inline void TestCamelCaseFieldNames::add_repeatedstringfield(const char* value, size_t size) { + repeatedstringfield_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestCamelCaseFieldNames::repeatedstringfield() const { + return repeatedstringfield_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestCamelCaseFieldNames::mutable_repeatedstringfield() { + return &repeatedstringfield_; +} + +// repeated .protobuf_unittest.ForeignEnum RepeatedEnumField = 9; +inline int TestCamelCaseFieldNames::repeatedenumfield_size() const { + return repeatedenumfield_.size(); +} +inline void TestCamelCaseFieldNames::clear_repeatedenumfield() { + repeatedenumfield_.Clear(); +} +inline protobuf_unittest::ForeignEnum TestCamelCaseFieldNames::repeatedenumfield(int index) const { + return static_cast< protobuf_unittest::ForeignEnum >(repeatedenumfield_.Get(index)); +} +inline void TestCamelCaseFieldNames::set_repeatedenumfield(int index, protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + repeatedenumfield_.Set(index, value); +} +inline void TestCamelCaseFieldNames::add_repeatedenumfield(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + repeatedenumfield_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestCamelCaseFieldNames::repeatedenumfield() const { + return repeatedenumfield_; +} +inline ::google::protobuf::RepeatedField* +TestCamelCaseFieldNames::mutable_repeatedenumfield() { + return &repeatedenumfield_; +} + +// repeated .protobuf_unittest.ForeignMessage RepeatedMessageField = 10; +inline int TestCamelCaseFieldNames::repeatedmessagefield_size() const { + return repeatedmessagefield_.size(); +} +inline void TestCamelCaseFieldNames::clear_repeatedmessagefield() { + repeatedmessagefield_.Clear(); +} +inline const ::protobuf_unittest::ForeignMessage& TestCamelCaseFieldNames::repeatedmessagefield(int index) const { + return repeatedmessagefield_.Get(index); +} +inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::mutable_repeatedmessagefield(int index) { + return repeatedmessagefield_.Mutable(index); +} +inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::add_repeatedmessagefield() { + return repeatedmessagefield_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& +TestCamelCaseFieldNames::repeatedmessagefield() const { + return repeatedmessagefield_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* +TestCamelCaseFieldNames::mutable_repeatedmessagefield() { + return &repeatedmessagefield_; +} + +// repeated string RepeatedStringPieceField = 11 [ctype = STRING_PIECE]; +inline int TestCamelCaseFieldNames::repeatedstringpiecefield_size() const { + return repeatedstringpiecefield_.size(); +} +inline void TestCamelCaseFieldNames::clear_repeatedstringpiecefield() { + repeatedstringpiecefield_.Clear(); +} +inline const ::std::string& TestCamelCaseFieldNames::repeatedstringpiecefield(int index) const { + return repeatedstringpiecefield_.Get(index); +} +inline ::std::string* TestCamelCaseFieldNames::mutable_repeatedstringpiecefield(int index) { + return repeatedstringpiecefield_.Mutable(index); +} +inline void TestCamelCaseFieldNames::set_repeatedstringpiecefield(int index, const ::std::string& value) { + repeatedstringpiecefield_.Mutable(index)->assign(value); +} +inline void TestCamelCaseFieldNames::set_repeatedstringpiecefield(int index, const char* value) { + repeatedstringpiecefield_.Mutable(index)->assign(value); +} +inline void TestCamelCaseFieldNames::set_repeatedstringpiecefield(int index, const char* value, size_t size) { + repeatedstringpiecefield_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestCamelCaseFieldNames::add_repeatedstringpiecefield() { + return repeatedstringpiecefield_.Add(); +} +inline void TestCamelCaseFieldNames::add_repeatedstringpiecefield(const ::std::string& value) { + repeatedstringpiecefield_.Add()->assign(value); +} +inline void TestCamelCaseFieldNames::add_repeatedstringpiecefield(const char* value) { + repeatedstringpiecefield_.Add()->assign(value); +} +inline void TestCamelCaseFieldNames::add_repeatedstringpiecefield(const char* value, size_t size) { + repeatedstringpiecefield_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestCamelCaseFieldNames::repeatedstringpiecefield() const { + return repeatedstringpiecefield_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestCamelCaseFieldNames::mutable_repeatedstringpiecefield() { + return &repeatedstringpiecefield_; +} + +// repeated string RepeatedCordField = 12 [ctype = CORD]; +inline int TestCamelCaseFieldNames::repeatedcordfield_size() const { + return repeatedcordfield_.size(); +} +inline void TestCamelCaseFieldNames::clear_repeatedcordfield() { + repeatedcordfield_.Clear(); +} +inline const ::std::string& TestCamelCaseFieldNames::repeatedcordfield(int index) const { + return repeatedcordfield_.Get(index); +} +inline ::std::string* TestCamelCaseFieldNames::mutable_repeatedcordfield(int index) { + return repeatedcordfield_.Mutable(index); +} +inline void TestCamelCaseFieldNames::set_repeatedcordfield(int index, const ::std::string& value) { + repeatedcordfield_.Mutable(index)->assign(value); +} +inline void TestCamelCaseFieldNames::set_repeatedcordfield(int index, const char* value) { + repeatedcordfield_.Mutable(index)->assign(value); +} +inline void TestCamelCaseFieldNames::set_repeatedcordfield(int index, const char* value, size_t size) { + repeatedcordfield_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestCamelCaseFieldNames::add_repeatedcordfield() { + return repeatedcordfield_.Add(); +} +inline void TestCamelCaseFieldNames::add_repeatedcordfield(const ::std::string& value) { + repeatedcordfield_.Add()->assign(value); +} +inline void TestCamelCaseFieldNames::add_repeatedcordfield(const char* value) { + repeatedcordfield_.Add()->assign(value); +} +inline void TestCamelCaseFieldNames::add_repeatedcordfield(const char* value, size_t size) { + repeatedcordfield_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestCamelCaseFieldNames::repeatedcordfield() const { + return repeatedcordfield_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestCamelCaseFieldNames::mutable_repeatedcordfield() { + return &repeatedcordfield_; +} + +// ------------------------------------------------------------------- + +// TestFieldOrderings + +// optional string my_string = 11; +inline bool TestFieldOrderings::has_my_string() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestFieldOrderings::set_has_my_string() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestFieldOrderings::clear_has_my_string() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestFieldOrderings::clear_my_string() { + if (my_string_ != &::google::protobuf::internal::kEmptyString) { + my_string_->clear(); + } + clear_has_my_string(); +} +inline const ::std::string& TestFieldOrderings::my_string() const { + return *my_string_; +} +inline void TestFieldOrderings::set_my_string(const ::std::string& value) { + set_has_my_string(); + if (my_string_ == &::google::protobuf::internal::kEmptyString) { + my_string_ = new ::std::string; + } + my_string_->assign(value); +} +inline void TestFieldOrderings::set_my_string(const char* value) { + set_has_my_string(); + if (my_string_ == &::google::protobuf::internal::kEmptyString) { + my_string_ = new ::std::string; + } + my_string_->assign(value); +} +inline void TestFieldOrderings::set_my_string(const char* value, size_t size) { + set_has_my_string(); + if (my_string_ == &::google::protobuf::internal::kEmptyString) { + my_string_ = new ::std::string; + } + my_string_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestFieldOrderings::mutable_my_string() { + set_has_my_string(); + if (my_string_ == &::google::protobuf::internal::kEmptyString) { + my_string_ = new ::std::string; + } + return my_string_; +} +inline ::std::string* TestFieldOrderings::release_my_string() { + clear_has_my_string(); + if (my_string_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = my_string_; + my_string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional int64 my_int = 1; +inline bool TestFieldOrderings::has_my_int() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestFieldOrderings::set_has_my_int() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestFieldOrderings::clear_has_my_int() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestFieldOrderings::clear_my_int() { + my_int_ = GOOGLE_LONGLONG(0); + clear_has_my_int(); +} +inline ::google::protobuf::int64 TestFieldOrderings::my_int() const { + return my_int_; +} +inline void TestFieldOrderings::set_my_int(::google::protobuf::int64 value) { + set_has_my_int(); + my_int_ = value; +} + +// optional float my_float = 101; +inline bool TestFieldOrderings::has_my_float() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestFieldOrderings::set_has_my_float() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestFieldOrderings::clear_has_my_float() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestFieldOrderings::clear_my_float() { + my_float_ = 0; + clear_has_my_float(); +} +inline float TestFieldOrderings::my_float() const { + return my_float_; +} +inline void TestFieldOrderings::set_my_float(float value) { + set_has_my_float(); + my_float_ = value; +} + +// ------------------------------------------------------------------- + +// TestExtremeDefaultValues + +// optional bytes escaped_bytes = 1 [default = "\000\001\007\010\014\n\r\t\013\\\'\"\376"]; +inline bool TestExtremeDefaultValues::has_escaped_bytes() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestExtremeDefaultValues::set_has_escaped_bytes() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestExtremeDefaultValues::clear_has_escaped_bytes() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestExtremeDefaultValues::clear_escaped_bytes() { + if (escaped_bytes_ != &_default_escaped_bytes_) { + escaped_bytes_->assign(_default_escaped_bytes_); + } + clear_has_escaped_bytes(); +} +inline const ::std::string& TestExtremeDefaultValues::escaped_bytes() const { + return *escaped_bytes_; +} +inline void TestExtremeDefaultValues::set_escaped_bytes(const ::std::string& value) { + set_has_escaped_bytes(); + if (escaped_bytes_ == &_default_escaped_bytes_) { + escaped_bytes_ = new ::std::string; + } + escaped_bytes_->assign(value); +} +inline void TestExtremeDefaultValues::set_escaped_bytes(const char* value) { + set_has_escaped_bytes(); + if (escaped_bytes_ == &_default_escaped_bytes_) { + escaped_bytes_ = new ::std::string; + } + escaped_bytes_->assign(value); +} +inline void TestExtremeDefaultValues::set_escaped_bytes(const void* value, size_t size) { + set_has_escaped_bytes(); + if (escaped_bytes_ == &_default_escaped_bytes_) { + escaped_bytes_ = new ::std::string; + } + escaped_bytes_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestExtremeDefaultValues::mutable_escaped_bytes() { + set_has_escaped_bytes(); + if (escaped_bytes_ == &_default_escaped_bytes_) { + escaped_bytes_ = new ::std::string(_default_escaped_bytes_); + } + return escaped_bytes_; +} +inline ::std::string* TestExtremeDefaultValues::release_escaped_bytes() { + clear_has_escaped_bytes(); + if (escaped_bytes_ == &_default_escaped_bytes_) { + return NULL; + } else { + ::std::string* temp = escaped_bytes_; + escaped_bytes_ = const_cast< ::std::string*>(&_default_escaped_bytes_); + return temp; + } +} + +// optional uint32 large_uint32 = 2 [default = 4294967295]; +inline bool TestExtremeDefaultValues::has_large_uint32() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestExtremeDefaultValues::set_has_large_uint32() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestExtremeDefaultValues::clear_has_large_uint32() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestExtremeDefaultValues::clear_large_uint32() { + large_uint32_ = 4294967295u; + clear_has_large_uint32(); +} +inline ::google::protobuf::uint32 TestExtremeDefaultValues::large_uint32() const { + return large_uint32_; +} +inline void TestExtremeDefaultValues::set_large_uint32(::google::protobuf::uint32 value) { + set_has_large_uint32(); + large_uint32_ = value; +} + +// optional uint64 large_uint64 = 3 [default = 18446744073709551615]; +inline bool TestExtremeDefaultValues::has_large_uint64() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestExtremeDefaultValues::set_has_large_uint64() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestExtremeDefaultValues::clear_has_large_uint64() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestExtremeDefaultValues::clear_large_uint64() { + large_uint64_ = GOOGLE_ULONGLONG(18446744073709551615); + clear_has_large_uint64(); +} +inline ::google::protobuf::uint64 TestExtremeDefaultValues::large_uint64() const { + return large_uint64_; +} +inline void TestExtremeDefaultValues::set_large_uint64(::google::protobuf::uint64 value) { + set_has_large_uint64(); + large_uint64_ = value; +} + +// optional int32 small_int32 = 4 [default = -2147483647]; +inline bool TestExtremeDefaultValues::has_small_int32() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void TestExtremeDefaultValues::set_has_small_int32() { + _has_bits_[0] |= 0x00000008u; +} +inline void TestExtremeDefaultValues::clear_has_small_int32() { + _has_bits_[0] &= ~0x00000008u; +} +inline void TestExtremeDefaultValues::clear_small_int32() { + small_int32_ = -2147483647; + clear_has_small_int32(); +} +inline ::google::protobuf::int32 TestExtremeDefaultValues::small_int32() const { + return small_int32_; +} +inline void TestExtremeDefaultValues::set_small_int32(::google::protobuf::int32 value) { + set_has_small_int32(); + small_int32_ = value; +} + +// optional int64 small_int64 = 5 [default = -9223372036854775807]; +inline bool TestExtremeDefaultValues::has_small_int64() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void TestExtremeDefaultValues::set_has_small_int64() { + _has_bits_[0] |= 0x00000010u; +} +inline void TestExtremeDefaultValues::clear_has_small_int64() { + _has_bits_[0] &= ~0x00000010u; +} +inline void TestExtremeDefaultValues::clear_small_int64() { + small_int64_ = GOOGLE_LONGLONG(-9223372036854775807); + clear_has_small_int64(); +} +inline ::google::protobuf::int64 TestExtremeDefaultValues::small_int64() const { + return small_int64_; +} +inline void TestExtremeDefaultValues::set_small_int64(::google::protobuf::int64 value) { + set_has_small_int64(); + small_int64_ = value; +} + +// optional string utf8_string = 6 [default = "\341\210\264"]; +inline bool TestExtremeDefaultValues::has_utf8_string() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void TestExtremeDefaultValues::set_has_utf8_string() { + _has_bits_[0] |= 0x00000020u; +} +inline void TestExtremeDefaultValues::clear_has_utf8_string() { + _has_bits_[0] &= ~0x00000020u; +} +inline void TestExtremeDefaultValues::clear_utf8_string() { + if (utf8_string_ != &_default_utf8_string_) { + utf8_string_->assign(_default_utf8_string_); + } + clear_has_utf8_string(); +} +inline const ::std::string& TestExtremeDefaultValues::utf8_string() const { + return *utf8_string_; +} +inline void TestExtremeDefaultValues::set_utf8_string(const ::std::string& value) { + set_has_utf8_string(); + if (utf8_string_ == &_default_utf8_string_) { + utf8_string_ = new ::std::string; + } + utf8_string_->assign(value); +} +inline void TestExtremeDefaultValues::set_utf8_string(const char* value) { + set_has_utf8_string(); + if (utf8_string_ == &_default_utf8_string_) { + utf8_string_ = new ::std::string; + } + utf8_string_->assign(value); +} +inline void TestExtremeDefaultValues::set_utf8_string(const char* value, size_t size) { + set_has_utf8_string(); + if (utf8_string_ == &_default_utf8_string_) { + utf8_string_ = new ::std::string; + } + utf8_string_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestExtremeDefaultValues::mutable_utf8_string() { + set_has_utf8_string(); + if (utf8_string_ == &_default_utf8_string_) { + utf8_string_ = new ::std::string(_default_utf8_string_); + } + return utf8_string_; +} +inline ::std::string* TestExtremeDefaultValues::release_utf8_string() { + clear_has_utf8_string(); + if (utf8_string_ == &_default_utf8_string_) { + return NULL; + } else { + ::std::string* temp = utf8_string_; + utf8_string_ = const_cast< ::std::string*>(&_default_utf8_string_); + return temp; + } +} + +// optional float zero_float = 7 [default = 0]; +inline bool TestExtremeDefaultValues::has_zero_float() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void TestExtremeDefaultValues::set_has_zero_float() { + _has_bits_[0] |= 0x00000040u; +} +inline void TestExtremeDefaultValues::clear_has_zero_float() { + _has_bits_[0] &= ~0x00000040u; +} +inline void TestExtremeDefaultValues::clear_zero_float() { + zero_float_ = 0; + clear_has_zero_float(); +} +inline float TestExtremeDefaultValues::zero_float() const { + return zero_float_; +} +inline void TestExtremeDefaultValues::set_zero_float(float value) { + set_has_zero_float(); + zero_float_ = value; +} + +// optional float one_float = 8 [default = 1]; +inline bool TestExtremeDefaultValues::has_one_float() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void TestExtremeDefaultValues::set_has_one_float() { + _has_bits_[0] |= 0x00000080u; +} +inline void TestExtremeDefaultValues::clear_has_one_float() { + _has_bits_[0] &= ~0x00000080u; +} +inline void TestExtremeDefaultValues::clear_one_float() { + one_float_ = 1; + clear_has_one_float(); +} +inline float TestExtremeDefaultValues::one_float() const { + return one_float_; +} +inline void TestExtremeDefaultValues::set_one_float(float value) { + set_has_one_float(); + one_float_ = value; +} + +// optional float small_float = 9 [default = 1.5]; +inline bool TestExtremeDefaultValues::has_small_float() const { + return (_has_bits_[0] & 0x00000100u) != 0; +} +inline void TestExtremeDefaultValues::set_has_small_float() { + _has_bits_[0] |= 0x00000100u; +} +inline void TestExtremeDefaultValues::clear_has_small_float() { + _has_bits_[0] &= ~0x00000100u; +} +inline void TestExtremeDefaultValues::clear_small_float() { + small_float_ = 1.5f; + clear_has_small_float(); +} +inline float TestExtremeDefaultValues::small_float() const { + return small_float_; +} +inline void TestExtremeDefaultValues::set_small_float(float value) { + set_has_small_float(); + small_float_ = value; +} + +// optional float negative_one_float = 10 [default = -1]; +inline bool TestExtremeDefaultValues::has_negative_one_float() const { + return (_has_bits_[0] & 0x00000200u) != 0; +} +inline void TestExtremeDefaultValues::set_has_negative_one_float() { + _has_bits_[0] |= 0x00000200u; +} +inline void TestExtremeDefaultValues::clear_has_negative_one_float() { + _has_bits_[0] &= ~0x00000200u; +} +inline void TestExtremeDefaultValues::clear_negative_one_float() { + negative_one_float_ = -1; + clear_has_negative_one_float(); +} +inline float TestExtremeDefaultValues::negative_one_float() const { + return negative_one_float_; +} +inline void TestExtremeDefaultValues::set_negative_one_float(float value) { + set_has_negative_one_float(); + negative_one_float_ = value; +} + +// optional float negative_float = 11 [default = -1.5]; +inline bool TestExtremeDefaultValues::has_negative_float() const { + return (_has_bits_[0] & 0x00000400u) != 0; +} +inline void TestExtremeDefaultValues::set_has_negative_float() { + _has_bits_[0] |= 0x00000400u; +} +inline void TestExtremeDefaultValues::clear_has_negative_float() { + _has_bits_[0] &= ~0x00000400u; +} +inline void TestExtremeDefaultValues::clear_negative_float() { + negative_float_ = -1.5f; + clear_has_negative_float(); +} +inline float TestExtremeDefaultValues::negative_float() const { + return negative_float_; +} +inline void TestExtremeDefaultValues::set_negative_float(float value) { + set_has_negative_float(); + negative_float_ = value; +} + +// optional float large_float = 12 [default = 2e+08]; +inline bool TestExtremeDefaultValues::has_large_float() const { + return (_has_bits_[0] & 0x00000800u) != 0; +} +inline void TestExtremeDefaultValues::set_has_large_float() { + _has_bits_[0] |= 0x00000800u; +} +inline void TestExtremeDefaultValues::clear_has_large_float() { + _has_bits_[0] &= ~0x00000800u; +} +inline void TestExtremeDefaultValues::clear_large_float() { + large_float_ = 2e+08f; + clear_has_large_float(); +} +inline float TestExtremeDefaultValues::large_float() const { + return large_float_; +} +inline void TestExtremeDefaultValues::set_large_float(float value) { + set_has_large_float(); + large_float_ = value; +} + +// optional float small_negative_float = 13 [default = -8e-28]; +inline bool TestExtremeDefaultValues::has_small_negative_float() const { + return (_has_bits_[0] & 0x00001000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_small_negative_float() { + _has_bits_[0] |= 0x00001000u; +} +inline void TestExtremeDefaultValues::clear_has_small_negative_float() { + _has_bits_[0] &= ~0x00001000u; +} +inline void TestExtremeDefaultValues::clear_small_negative_float() { + small_negative_float_ = -8e-28f; + clear_has_small_negative_float(); +} +inline float TestExtremeDefaultValues::small_negative_float() const { + return small_negative_float_; +} +inline void TestExtremeDefaultValues::set_small_negative_float(float value) { + set_has_small_negative_float(); + small_negative_float_ = value; +} + +// optional double inf_double = 14 [default = inf]; +inline bool TestExtremeDefaultValues::has_inf_double() const { + return (_has_bits_[0] & 0x00002000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_inf_double() { + _has_bits_[0] |= 0x00002000u; +} +inline void TestExtremeDefaultValues::clear_has_inf_double() { + _has_bits_[0] &= ~0x00002000u; +} +inline void TestExtremeDefaultValues::clear_inf_double() { + inf_double_ = ::google::protobuf::internal::Infinity(); + clear_has_inf_double(); +} +inline double TestExtremeDefaultValues::inf_double() const { + return inf_double_; +} +inline void TestExtremeDefaultValues::set_inf_double(double value) { + set_has_inf_double(); + inf_double_ = value; +} + +// optional double neg_inf_double = 15 [default = -inf]; +inline bool TestExtremeDefaultValues::has_neg_inf_double() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_neg_inf_double() { + _has_bits_[0] |= 0x00004000u; +} +inline void TestExtremeDefaultValues::clear_has_neg_inf_double() { + _has_bits_[0] &= ~0x00004000u; +} +inline void TestExtremeDefaultValues::clear_neg_inf_double() { + neg_inf_double_ = -::google::protobuf::internal::Infinity(); + clear_has_neg_inf_double(); +} +inline double TestExtremeDefaultValues::neg_inf_double() const { + return neg_inf_double_; +} +inline void TestExtremeDefaultValues::set_neg_inf_double(double value) { + set_has_neg_inf_double(); + neg_inf_double_ = value; +} + +// optional double nan_double = 16 [default = nan]; +inline bool TestExtremeDefaultValues::has_nan_double() const { + return (_has_bits_[0] & 0x00008000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_nan_double() { + _has_bits_[0] |= 0x00008000u; +} +inline void TestExtremeDefaultValues::clear_has_nan_double() { + _has_bits_[0] &= ~0x00008000u; +} +inline void TestExtremeDefaultValues::clear_nan_double() { + nan_double_ = ::google::protobuf::internal::NaN(); + clear_has_nan_double(); +} +inline double TestExtremeDefaultValues::nan_double() const { + return nan_double_; +} +inline void TestExtremeDefaultValues::set_nan_double(double value) { + set_has_nan_double(); + nan_double_ = value; +} + +// optional float inf_float = 17 [default = inf]; +inline bool TestExtremeDefaultValues::has_inf_float() const { + return (_has_bits_[0] & 0x00010000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_inf_float() { + _has_bits_[0] |= 0x00010000u; +} +inline void TestExtremeDefaultValues::clear_has_inf_float() { + _has_bits_[0] &= ~0x00010000u; +} +inline void TestExtremeDefaultValues::clear_inf_float() { + inf_float_ = static_cast(::google::protobuf::internal::Infinity()); + clear_has_inf_float(); +} +inline float TestExtremeDefaultValues::inf_float() const { + return inf_float_; +} +inline void TestExtremeDefaultValues::set_inf_float(float value) { + set_has_inf_float(); + inf_float_ = value; +} + +// optional float neg_inf_float = 18 [default = -inf]; +inline bool TestExtremeDefaultValues::has_neg_inf_float() const { + return (_has_bits_[0] & 0x00020000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_neg_inf_float() { + _has_bits_[0] |= 0x00020000u; +} +inline void TestExtremeDefaultValues::clear_has_neg_inf_float() { + _has_bits_[0] &= ~0x00020000u; +} +inline void TestExtremeDefaultValues::clear_neg_inf_float() { + neg_inf_float_ = static_cast(-::google::protobuf::internal::Infinity()); + clear_has_neg_inf_float(); +} +inline float TestExtremeDefaultValues::neg_inf_float() const { + return neg_inf_float_; +} +inline void TestExtremeDefaultValues::set_neg_inf_float(float value) { + set_has_neg_inf_float(); + neg_inf_float_ = value; +} + +// optional float nan_float = 19 [default = nan]; +inline bool TestExtremeDefaultValues::has_nan_float() const { + return (_has_bits_[0] & 0x00040000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_nan_float() { + _has_bits_[0] |= 0x00040000u; +} +inline void TestExtremeDefaultValues::clear_has_nan_float() { + _has_bits_[0] &= ~0x00040000u; +} +inline void TestExtremeDefaultValues::clear_nan_float() { + nan_float_ = static_cast(::google::protobuf::internal::NaN()); + clear_has_nan_float(); +} +inline float TestExtremeDefaultValues::nan_float() const { + return nan_float_; +} +inline void TestExtremeDefaultValues::set_nan_float(float value) { + set_has_nan_float(); + nan_float_ = value; +} + +// optional string cpp_trigraph = 20 [default = "? ? ?? ?? ??? ??/ ??-"]; +inline bool TestExtremeDefaultValues::has_cpp_trigraph() const { + return (_has_bits_[0] & 0x00080000u) != 0; +} +inline void TestExtremeDefaultValues::set_has_cpp_trigraph() { + _has_bits_[0] |= 0x00080000u; +} +inline void TestExtremeDefaultValues::clear_has_cpp_trigraph() { + _has_bits_[0] &= ~0x00080000u; +} +inline void TestExtremeDefaultValues::clear_cpp_trigraph() { + if (cpp_trigraph_ != &_default_cpp_trigraph_) { + cpp_trigraph_->assign(_default_cpp_trigraph_); + } + clear_has_cpp_trigraph(); +} +inline const ::std::string& TestExtremeDefaultValues::cpp_trigraph() const { + return *cpp_trigraph_; +} +inline void TestExtremeDefaultValues::set_cpp_trigraph(const ::std::string& value) { + set_has_cpp_trigraph(); + if (cpp_trigraph_ == &_default_cpp_trigraph_) { + cpp_trigraph_ = new ::std::string; + } + cpp_trigraph_->assign(value); +} +inline void TestExtremeDefaultValues::set_cpp_trigraph(const char* value) { + set_has_cpp_trigraph(); + if (cpp_trigraph_ == &_default_cpp_trigraph_) { + cpp_trigraph_ = new ::std::string; + } + cpp_trigraph_->assign(value); +} +inline void TestExtremeDefaultValues::set_cpp_trigraph(const char* value, size_t size) { + set_has_cpp_trigraph(); + if (cpp_trigraph_ == &_default_cpp_trigraph_) { + cpp_trigraph_ = new ::std::string; + } + cpp_trigraph_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestExtremeDefaultValues::mutable_cpp_trigraph() { + set_has_cpp_trigraph(); + if (cpp_trigraph_ == &_default_cpp_trigraph_) { + cpp_trigraph_ = new ::std::string(_default_cpp_trigraph_); + } + return cpp_trigraph_; +} +inline ::std::string* TestExtremeDefaultValues::release_cpp_trigraph() { + clear_has_cpp_trigraph(); + if (cpp_trigraph_ == &_default_cpp_trigraph_) { + return NULL; + } else { + ::std::string* temp = cpp_trigraph_; + cpp_trigraph_ = const_cast< ::std::string*>(&_default_cpp_trigraph_); + return temp; + } +} + +// ------------------------------------------------------------------- + +// SparseEnumMessage + +// optional .protobuf_unittest.TestSparseEnum sparse_enum = 1; +inline bool SparseEnumMessage::has_sparse_enum() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void SparseEnumMessage::set_has_sparse_enum() { + _has_bits_[0] |= 0x00000001u; +} +inline void SparseEnumMessage::clear_has_sparse_enum() { + _has_bits_[0] &= ~0x00000001u; +} +inline void SparseEnumMessage::clear_sparse_enum() { + sparse_enum_ = 123; + clear_has_sparse_enum(); +} +inline protobuf_unittest::TestSparseEnum SparseEnumMessage::sparse_enum() const { + return static_cast< protobuf_unittest::TestSparseEnum >(sparse_enum_); +} +inline void SparseEnumMessage::set_sparse_enum(protobuf_unittest::TestSparseEnum value) { + GOOGLE_DCHECK(protobuf_unittest::TestSparseEnum_IsValid(value)); + set_has_sparse_enum(); + sparse_enum_ = value; +} + +// ------------------------------------------------------------------- + +// OneString + +// optional string data = 1; +inline bool OneString::has_data() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void OneString::set_has_data() { + _has_bits_[0] |= 0x00000001u; +} +inline void OneString::clear_has_data() { + _has_bits_[0] &= ~0x00000001u; +} +inline void OneString::clear_data() { + if (data_ != &::google::protobuf::internal::kEmptyString) { + data_->clear(); + } + clear_has_data(); +} +inline const ::std::string& OneString::data() const { + return *data_; +} +inline void OneString::set_data(const ::std::string& value) { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + data_->assign(value); +} +inline void OneString::set_data(const char* value) { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + data_->assign(value); +} +inline void OneString::set_data(const char* value, size_t size) { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + data_->assign(reinterpret_cast(value), size); +} +inline ::std::string* OneString::mutable_data() { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + return data_; +} +inline ::std::string* OneString::release_data() { + clear_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = data_; + data_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// OneBytes + +// optional bytes data = 1; +inline bool OneBytes::has_data() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void OneBytes::set_has_data() { + _has_bits_[0] |= 0x00000001u; +} +inline void OneBytes::clear_has_data() { + _has_bits_[0] &= ~0x00000001u; +} +inline void OneBytes::clear_data() { + if (data_ != &::google::protobuf::internal::kEmptyString) { + data_->clear(); + } + clear_has_data(); +} +inline const ::std::string& OneBytes::data() const { + return *data_; +} +inline void OneBytes::set_data(const ::std::string& value) { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + data_->assign(value); +} +inline void OneBytes::set_data(const char* value) { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + data_->assign(value); +} +inline void OneBytes::set_data(const void* value, size_t size) { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + data_->assign(reinterpret_cast(value), size); +} +inline ::std::string* OneBytes::mutable_data() { + set_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + data_ = new ::std::string; + } + return data_; +} +inline ::std::string* OneBytes::release_data() { + clear_has_data(); + if (data_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = data_; + data_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// TestPackedTypes + +// repeated int32 packed_int32 = 90 [packed = true]; +inline int TestPackedTypes::packed_int32_size() const { + return packed_int32_.size(); +} +inline void TestPackedTypes::clear_packed_int32() { + packed_int32_.Clear(); +} +inline ::google::protobuf::int32 TestPackedTypes::packed_int32(int index) const { + return packed_int32_.Get(index); +} +inline void TestPackedTypes::set_packed_int32(int index, ::google::protobuf::int32 value) { + packed_int32_.Set(index, value); +} +inline void TestPackedTypes::add_packed_int32(::google::protobuf::int32 value) { + packed_int32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestPackedTypes::packed_int32() const { + return packed_int32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestPackedTypes::mutable_packed_int32() { + return &packed_int32_; +} + +// repeated int64 packed_int64 = 91 [packed = true]; +inline int TestPackedTypes::packed_int64_size() const { + return packed_int64_.size(); +} +inline void TestPackedTypes::clear_packed_int64() { + packed_int64_.Clear(); +} +inline ::google::protobuf::int64 TestPackedTypes::packed_int64(int index) const { + return packed_int64_.Get(index); +} +inline void TestPackedTypes::set_packed_int64(int index, ::google::protobuf::int64 value) { + packed_int64_.Set(index, value); +} +inline void TestPackedTypes::add_packed_int64(::google::protobuf::int64 value) { + packed_int64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestPackedTypes::packed_int64() const { + return packed_int64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestPackedTypes::mutable_packed_int64() { + return &packed_int64_; +} + +// repeated uint32 packed_uint32 = 92 [packed = true]; +inline int TestPackedTypes::packed_uint32_size() const { + return packed_uint32_.size(); +} +inline void TestPackedTypes::clear_packed_uint32() { + packed_uint32_.Clear(); +} +inline ::google::protobuf::uint32 TestPackedTypes::packed_uint32(int index) const { + return packed_uint32_.Get(index); +} +inline void TestPackedTypes::set_packed_uint32(int index, ::google::protobuf::uint32 value) { + packed_uint32_.Set(index, value); +} +inline void TestPackedTypes::add_packed_uint32(::google::protobuf::uint32 value) { + packed_uint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestPackedTypes::packed_uint32() const { + return packed_uint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestPackedTypes::mutable_packed_uint32() { + return &packed_uint32_; +} + +// repeated uint64 packed_uint64 = 93 [packed = true]; +inline int TestPackedTypes::packed_uint64_size() const { + return packed_uint64_.size(); +} +inline void TestPackedTypes::clear_packed_uint64() { + packed_uint64_.Clear(); +} +inline ::google::protobuf::uint64 TestPackedTypes::packed_uint64(int index) const { + return packed_uint64_.Get(index); +} +inline void TestPackedTypes::set_packed_uint64(int index, ::google::protobuf::uint64 value) { + packed_uint64_.Set(index, value); +} +inline void TestPackedTypes::add_packed_uint64(::google::protobuf::uint64 value) { + packed_uint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestPackedTypes::packed_uint64() const { + return packed_uint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestPackedTypes::mutable_packed_uint64() { + return &packed_uint64_; +} + +// repeated sint32 packed_sint32 = 94 [packed = true]; +inline int TestPackedTypes::packed_sint32_size() const { + return packed_sint32_.size(); +} +inline void TestPackedTypes::clear_packed_sint32() { + packed_sint32_.Clear(); +} +inline ::google::protobuf::int32 TestPackedTypes::packed_sint32(int index) const { + return packed_sint32_.Get(index); +} +inline void TestPackedTypes::set_packed_sint32(int index, ::google::protobuf::int32 value) { + packed_sint32_.Set(index, value); +} +inline void TestPackedTypes::add_packed_sint32(::google::protobuf::int32 value) { + packed_sint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestPackedTypes::packed_sint32() const { + return packed_sint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestPackedTypes::mutable_packed_sint32() { + return &packed_sint32_; +} + +// repeated sint64 packed_sint64 = 95 [packed = true]; +inline int TestPackedTypes::packed_sint64_size() const { + return packed_sint64_.size(); +} +inline void TestPackedTypes::clear_packed_sint64() { + packed_sint64_.Clear(); +} +inline ::google::protobuf::int64 TestPackedTypes::packed_sint64(int index) const { + return packed_sint64_.Get(index); +} +inline void TestPackedTypes::set_packed_sint64(int index, ::google::protobuf::int64 value) { + packed_sint64_.Set(index, value); +} +inline void TestPackedTypes::add_packed_sint64(::google::protobuf::int64 value) { + packed_sint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestPackedTypes::packed_sint64() const { + return packed_sint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestPackedTypes::mutable_packed_sint64() { + return &packed_sint64_; +} + +// repeated fixed32 packed_fixed32 = 96 [packed = true]; +inline int TestPackedTypes::packed_fixed32_size() const { + return packed_fixed32_.size(); +} +inline void TestPackedTypes::clear_packed_fixed32() { + packed_fixed32_.Clear(); +} +inline ::google::protobuf::uint32 TestPackedTypes::packed_fixed32(int index) const { + return packed_fixed32_.Get(index); +} +inline void TestPackedTypes::set_packed_fixed32(int index, ::google::protobuf::uint32 value) { + packed_fixed32_.Set(index, value); +} +inline void TestPackedTypes::add_packed_fixed32(::google::protobuf::uint32 value) { + packed_fixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestPackedTypes::packed_fixed32() const { + return packed_fixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestPackedTypes::mutable_packed_fixed32() { + return &packed_fixed32_; +} + +// repeated fixed64 packed_fixed64 = 97 [packed = true]; +inline int TestPackedTypes::packed_fixed64_size() const { + return packed_fixed64_.size(); +} +inline void TestPackedTypes::clear_packed_fixed64() { + packed_fixed64_.Clear(); +} +inline ::google::protobuf::uint64 TestPackedTypes::packed_fixed64(int index) const { + return packed_fixed64_.Get(index); +} +inline void TestPackedTypes::set_packed_fixed64(int index, ::google::protobuf::uint64 value) { + packed_fixed64_.Set(index, value); +} +inline void TestPackedTypes::add_packed_fixed64(::google::protobuf::uint64 value) { + packed_fixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestPackedTypes::packed_fixed64() const { + return packed_fixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestPackedTypes::mutable_packed_fixed64() { + return &packed_fixed64_; +} + +// repeated sfixed32 packed_sfixed32 = 98 [packed = true]; +inline int TestPackedTypes::packed_sfixed32_size() const { + return packed_sfixed32_.size(); +} +inline void TestPackedTypes::clear_packed_sfixed32() { + packed_sfixed32_.Clear(); +} +inline ::google::protobuf::int32 TestPackedTypes::packed_sfixed32(int index) const { + return packed_sfixed32_.Get(index); +} +inline void TestPackedTypes::set_packed_sfixed32(int index, ::google::protobuf::int32 value) { + packed_sfixed32_.Set(index, value); +} +inline void TestPackedTypes::add_packed_sfixed32(::google::protobuf::int32 value) { + packed_sfixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestPackedTypes::packed_sfixed32() const { + return packed_sfixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestPackedTypes::mutable_packed_sfixed32() { + return &packed_sfixed32_; +} + +// repeated sfixed64 packed_sfixed64 = 99 [packed = true]; +inline int TestPackedTypes::packed_sfixed64_size() const { + return packed_sfixed64_.size(); +} +inline void TestPackedTypes::clear_packed_sfixed64() { + packed_sfixed64_.Clear(); +} +inline ::google::protobuf::int64 TestPackedTypes::packed_sfixed64(int index) const { + return packed_sfixed64_.Get(index); +} +inline void TestPackedTypes::set_packed_sfixed64(int index, ::google::protobuf::int64 value) { + packed_sfixed64_.Set(index, value); +} +inline void TestPackedTypes::add_packed_sfixed64(::google::protobuf::int64 value) { + packed_sfixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestPackedTypes::packed_sfixed64() const { + return packed_sfixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestPackedTypes::mutable_packed_sfixed64() { + return &packed_sfixed64_; +} + +// repeated float packed_float = 100 [packed = true]; +inline int TestPackedTypes::packed_float_size() const { + return packed_float_.size(); +} +inline void TestPackedTypes::clear_packed_float() { + packed_float_.Clear(); +} +inline float TestPackedTypes::packed_float(int index) const { + return packed_float_.Get(index); +} +inline void TestPackedTypes::set_packed_float(int index, float value) { + packed_float_.Set(index, value); +} +inline void TestPackedTypes::add_packed_float(float value) { + packed_float_.Add(value); +} +inline const ::google::protobuf::RepeatedField< float >& +TestPackedTypes::packed_float() const { + return packed_float_; +} +inline ::google::protobuf::RepeatedField< float >* +TestPackedTypes::mutable_packed_float() { + return &packed_float_; +} + +// repeated double packed_double = 101 [packed = true]; +inline int TestPackedTypes::packed_double_size() const { + return packed_double_.size(); +} +inline void TestPackedTypes::clear_packed_double() { + packed_double_.Clear(); +} +inline double TestPackedTypes::packed_double(int index) const { + return packed_double_.Get(index); +} +inline void TestPackedTypes::set_packed_double(int index, double value) { + packed_double_.Set(index, value); +} +inline void TestPackedTypes::add_packed_double(double value) { + packed_double_.Add(value); +} +inline const ::google::protobuf::RepeatedField< double >& +TestPackedTypes::packed_double() const { + return packed_double_; +} +inline ::google::protobuf::RepeatedField< double >* +TestPackedTypes::mutable_packed_double() { + return &packed_double_; +} + +// repeated bool packed_bool = 102 [packed = true]; +inline int TestPackedTypes::packed_bool_size() const { + return packed_bool_.size(); +} +inline void TestPackedTypes::clear_packed_bool() { + packed_bool_.Clear(); +} +inline bool TestPackedTypes::packed_bool(int index) const { + return packed_bool_.Get(index); +} +inline void TestPackedTypes::set_packed_bool(int index, bool value) { + packed_bool_.Set(index, value); +} +inline void TestPackedTypes::add_packed_bool(bool value) { + packed_bool_.Add(value); +} +inline const ::google::protobuf::RepeatedField< bool >& +TestPackedTypes::packed_bool() const { + return packed_bool_; +} +inline ::google::protobuf::RepeatedField< bool >* +TestPackedTypes::mutable_packed_bool() { + return &packed_bool_; +} + +// repeated .protobuf_unittest.ForeignEnum packed_enum = 103 [packed = true]; +inline int TestPackedTypes::packed_enum_size() const { + return packed_enum_.size(); +} +inline void TestPackedTypes::clear_packed_enum() { + packed_enum_.Clear(); +} +inline protobuf_unittest::ForeignEnum TestPackedTypes::packed_enum(int index) const { + return static_cast< protobuf_unittest::ForeignEnum >(packed_enum_.Get(index)); +} +inline void TestPackedTypes::set_packed_enum(int index, protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + packed_enum_.Set(index, value); +} +inline void TestPackedTypes::add_packed_enum(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + packed_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestPackedTypes::packed_enum() const { + return packed_enum_; +} +inline ::google::protobuf::RepeatedField* +TestPackedTypes::mutable_packed_enum() { + return &packed_enum_; +} + +// ------------------------------------------------------------------- + +// TestUnpackedTypes + +// repeated int32 unpacked_int32 = 90 [packed = false]; +inline int TestUnpackedTypes::unpacked_int32_size() const { + return unpacked_int32_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_int32() { + unpacked_int32_.Clear(); +} +inline ::google::protobuf::int32 TestUnpackedTypes::unpacked_int32(int index) const { + return unpacked_int32_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_int32(int index, ::google::protobuf::int32 value) { + unpacked_int32_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_int32(::google::protobuf::int32 value) { + unpacked_int32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestUnpackedTypes::unpacked_int32() const { + return unpacked_int32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestUnpackedTypes::mutable_unpacked_int32() { + return &unpacked_int32_; +} + +// repeated int64 unpacked_int64 = 91 [packed = false]; +inline int TestUnpackedTypes::unpacked_int64_size() const { + return unpacked_int64_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_int64() { + unpacked_int64_.Clear(); +} +inline ::google::protobuf::int64 TestUnpackedTypes::unpacked_int64(int index) const { + return unpacked_int64_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_int64(int index, ::google::protobuf::int64 value) { + unpacked_int64_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_int64(::google::protobuf::int64 value) { + unpacked_int64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestUnpackedTypes::unpacked_int64() const { + return unpacked_int64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestUnpackedTypes::mutable_unpacked_int64() { + return &unpacked_int64_; +} + +// repeated uint32 unpacked_uint32 = 92 [packed = false]; +inline int TestUnpackedTypes::unpacked_uint32_size() const { + return unpacked_uint32_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_uint32() { + unpacked_uint32_.Clear(); +} +inline ::google::protobuf::uint32 TestUnpackedTypes::unpacked_uint32(int index) const { + return unpacked_uint32_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_uint32(int index, ::google::protobuf::uint32 value) { + unpacked_uint32_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_uint32(::google::protobuf::uint32 value) { + unpacked_uint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestUnpackedTypes::unpacked_uint32() const { + return unpacked_uint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestUnpackedTypes::mutable_unpacked_uint32() { + return &unpacked_uint32_; +} + +// repeated uint64 unpacked_uint64 = 93 [packed = false]; +inline int TestUnpackedTypes::unpacked_uint64_size() const { + return unpacked_uint64_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_uint64() { + unpacked_uint64_.Clear(); +} +inline ::google::protobuf::uint64 TestUnpackedTypes::unpacked_uint64(int index) const { + return unpacked_uint64_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_uint64(int index, ::google::protobuf::uint64 value) { + unpacked_uint64_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_uint64(::google::protobuf::uint64 value) { + unpacked_uint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestUnpackedTypes::unpacked_uint64() const { + return unpacked_uint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestUnpackedTypes::mutable_unpacked_uint64() { + return &unpacked_uint64_; +} + +// repeated sint32 unpacked_sint32 = 94 [packed = false]; +inline int TestUnpackedTypes::unpacked_sint32_size() const { + return unpacked_sint32_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_sint32() { + unpacked_sint32_.Clear(); +} +inline ::google::protobuf::int32 TestUnpackedTypes::unpacked_sint32(int index) const { + return unpacked_sint32_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_sint32(int index, ::google::protobuf::int32 value) { + unpacked_sint32_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_sint32(::google::protobuf::int32 value) { + unpacked_sint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestUnpackedTypes::unpacked_sint32() const { + return unpacked_sint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestUnpackedTypes::mutable_unpacked_sint32() { + return &unpacked_sint32_; +} + +// repeated sint64 unpacked_sint64 = 95 [packed = false]; +inline int TestUnpackedTypes::unpacked_sint64_size() const { + return unpacked_sint64_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_sint64() { + unpacked_sint64_.Clear(); +} +inline ::google::protobuf::int64 TestUnpackedTypes::unpacked_sint64(int index) const { + return unpacked_sint64_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_sint64(int index, ::google::protobuf::int64 value) { + unpacked_sint64_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_sint64(::google::protobuf::int64 value) { + unpacked_sint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestUnpackedTypes::unpacked_sint64() const { + return unpacked_sint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestUnpackedTypes::mutable_unpacked_sint64() { + return &unpacked_sint64_; +} + +// repeated fixed32 unpacked_fixed32 = 96 [packed = false]; +inline int TestUnpackedTypes::unpacked_fixed32_size() const { + return unpacked_fixed32_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_fixed32() { + unpacked_fixed32_.Clear(); +} +inline ::google::protobuf::uint32 TestUnpackedTypes::unpacked_fixed32(int index) const { + return unpacked_fixed32_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_fixed32(int index, ::google::protobuf::uint32 value) { + unpacked_fixed32_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_fixed32(::google::protobuf::uint32 value) { + unpacked_fixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestUnpackedTypes::unpacked_fixed32() const { + return unpacked_fixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestUnpackedTypes::mutable_unpacked_fixed32() { + return &unpacked_fixed32_; +} + +// repeated fixed64 unpacked_fixed64 = 97 [packed = false]; +inline int TestUnpackedTypes::unpacked_fixed64_size() const { + return unpacked_fixed64_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_fixed64() { + unpacked_fixed64_.Clear(); +} +inline ::google::protobuf::uint64 TestUnpackedTypes::unpacked_fixed64(int index) const { + return unpacked_fixed64_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_fixed64(int index, ::google::protobuf::uint64 value) { + unpacked_fixed64_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_fixed64(::google::protobuf::uint64 value) { + unpacked_fixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestUnpackedTypes::unpacked_fixed64() const { + return unpacked_fixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestUnpackedTypes::mutable_unpacked_fixed64() { + return &unpacked_fixed64_; +} + +// repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; +inline int TestUnpackedTypes::unpacked_sfixed32_size() const { + return unpacked_sfixed32_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_sfixed32() { + unpacked_sfixed32_.Clear(); +} +inline ::google::protobuf::int32 TestUnpackedTypes::unpacked_sfixed32(int index) const { + return unpacked_sfixed32_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_sfixed32(int index, ::google::protobuf::int32 value) { + unpacked_sfixed32_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_sfixed32(::google::protobuf::int32 value) { + unpacked_sfixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestUnpackedTypes::unpacked_sfixed32() const { + return unpacked_sfixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestUnpackedTypes::mutable_unpacked_sfixed32() { + return &unpacked_sfixed32_; +} + +// repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; +inline int TestUnpackedTypes::unpacked_sfixed64_size() const { + return unpacked_sfixed64_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_sfixed64() { + unpacked_sfixed64_.Clear(); +} +inline ::google::protobuf::int64 TestUnpackedTypes::unpacked_sfixed64(int index) const { + return unpacked_sfixed64_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_sfixed64(int index, ::google::protobuf::int64 value) { + unpacked_sfixed64_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_sfixed64(::google::protobuf::int64 value) { + unpacked_sfixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestUnpackedTypes::unpacked_sfixed64() const { + return unpacked_sfixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestUnpackedTypes::mutable_unpacked_sfixed64() { + return &unpacked_sfixed64_; +} + +// repeated float unpacked_float = 100 [packed = false]; +inline int TestUnpackedTypes::unpacked_float_size() const { + return unpacked_float_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_float() { + unpacked_float_.Clear(); +} +inline float TestUnpackedTypes::unpacked_float(int index) const { + return unpacked_float_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_float(int index, float value) { + unpacked_float_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_float(float value) { + unpacked_float_.Add(value); +} +inline const ::google::protobuf::RepeatedField< float >& +TestUnpackedTypes::unpacked_float() const { + return unpacked_float_; +} +inline ::google::protobuf::RepeatedField< float >* +TestUnpackedTypes::mutable_unpacked_float() { + return &unpacked_float_; +} + +// repeated double unpacked_double = 101 [packed = false]; +inline int TestUnpackedTypes::unpacked_double_size() const { + return unpacked_double_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_double() { + unpacked_double_.Clear(); +} +inline double TestUnpackedTypes::unpacked_double(int index) const { + return unpacked_double_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_double(int index, double value) { + unpacked_double_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_double(double value) { + unpacked_double_.Add(value); +} +inline const ::google::protobuf::RepeatedField< double >& +TestUnpackedTypes::unpacked_double() const { + return unpacked_double_; +} +inline ::google::protobuf::RepeatedField< double >* +TestUnpackedTypes::mutable_unpacked_double() { + return &unpacked_double_; +} + +// repeated bool unpacked_bool = 102 [packed = false]; +inline int TestUnpackedTypes::unpacked_bool_size() const { + return unpacked_bool_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_bool() { + unpacked_bool_.Clear(); +} +inline bool TestUnpackedTypes::unpacked_bool(int index) const { + return unpacked_bool_.Get(index); +} +inline void TestUnpackedTypes::set_unpacked_bool(int index, bool value) { + unpacked_bool_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_bool(bool value) { + unpacked_bool_.Add(value); +} +inline const ::google::protobuf::RepeatedField< bool >& +TestUnpackedTypes::unpacked_bool() const { + return unpacked_bool_; +} +inline ::google::protobuf::RepeatedField< bool >* +TestUnpackedTypes::mutable_unpacked_bool() { + return &unpacked_bool_; +} + +// repeated .protobuf_unittest.ForeignEnum unpacked_enum = 103 [packed = false]; +inline int TestUnpackedTypes::unpacked_enum_size() const { + return unpacked_enum_.size(); +} +inline void TestUnpackedTypes::clear_unpacked_enum() { + unpacked_enum_.Clear(); +} +inline protobuf_unittest::ForeignEnum TestUnpackedTypes::unpacked_enum(int index) const { + return static_cast< protobuf_unittest::ForeignEnum >(unpacked_enum_.Get(index)); +} +inline void TestUnpackedTypes::set_unpacked_enum(int index, protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + unpacked_enum_.Set(index, value); +} +inline void TestUnpackedTypes::add_unpacked_enum(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + unpacked_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestUnpackedTypes::unpacked_enum() const { + return unpacked_enum_; +} +inline ::google::protobuf::RepeatedField* +TestUnpackedTypes::mutable_unpacked_enum() { + return &unpacked_enum_; +} + +// ------------------------------------------------------------------- + +// TestPackedExtensions + +// ------------------------------------------------------------------- + +// TestDynamicExtensions_DynamicMessageType + +// optional int32 dynamic_field = 2100; +inline bool TestDynamicExtensions_DynamicMessageType::has_dynamic_field() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestDynamicExtensions_DynamicMessageType::set_has_dynamic_field() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestDynamicExtensions_DynamicMessageType::clear_has_dynamic_field() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestDynamicExtensions_DynamicMessageType::clear_dynamic_field() { + dynamic_field_ = 0; + clear_has_dynamic_field(); +} +inline ::google::protobuf::int32 TestDynamicExtensions_DynamicMessageType::dynamic_field() const { + return dynamic_field_; +} +inline void TestDynamicExtensions_DynamicMessageType::set_dynamic_field(::google::protobuf::int32 value) { + set_has_dynamic_field(); + dynamic_field_ = value; +} + +// ------------------------------------------------------------------- + +// TestDynamicExtensions + +// optional fixed32 scalar_extension = 2000; +inline bool TestDynamicExtensions::has_scalar_extension() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestDynamicExtensions::set_has_scalar_extension() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestDynamicExtensions::clear_has_scalar_extension() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestDynamicExtensions::clear_scalar_extension() { + scalar_extension_ = 0u; + clear_has_scalar_extension(); +} +inline ::google::protobuf::uint32 TestDynamicExtensions::scalar_extension() const { + return scalar_extension_; +} +inline void TestDynamicExtensions::set_scalar_extension(::google::protobuf::uint32 value) { + set_has_scalar_extension(); + scalar_extension_ = value; +} + +// optional .protobuf_unittest.ForeignEnum enum_extension = 2001; +inline bool TestDynamicExtensions::has_enum_extension() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestDynamicExtensions::set_has_enum_extension() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestDynamicExtensions::clear_has_enum_extension() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestDynamicExtensions::clear_enum_extension() { + enum_extension_ = 4; + clear_has_enum_extension(); +} +inline protobuf_unittest::ForeignEnum TestDynamicExtensions::enum_extension() const { + return static_cast< protobuf_unittest::ForeignEnum >(enum_extension_); +} +inline void TestDynamicExtensions::set_enum_extension(protobuf_unittest::ForeignEnum value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); + set_has_enum_extension(); + enum_extension_ = value; +} + +// optional .protobuf_unittest.TestDynamicExtensions.DynamicEnumType dynamic_enum_extension = 2002; +inline bool TestDynamicExtensions::has_dynamic_enum_extension() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestDynamicExtensions::set_has_dynamic_enum_extension() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestDynamicExtensions::clear_has_dynamic_enum_extension() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestDynamicExtensions::clear_dynamic_enum_extension() { + dynamic_enum_extension_ = 2200; + clear_has_dynamic_enum_extension(); +} +inline ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType TestDynamicExtensions::dynamic_enum_extension() const { + return static_cast< ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType >(dynamic_enum_extension_); +} +inline void TestDynamicExtensions::set_dynamic_enum_extension(::protobuf_unittest::TestDynamicExtensions_DynamicEnumType value) { + GOOGLE_DCHECK(::protobuf_unittest::TestDynamicExtensions_DynamicEnumType_IsValid(value)); + set_has_dynamic_enum_extension(); + dynamic_enum_extension_ = value; +} + +// optional .protobuf_unittest.ForeignMessage message_extension = 2003; +inline bool TestDynamicExtensions::has_message_extension() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void TestDynamicExtensions::set_has_message_extension() { + _has_bits_[0] |= 0x00000008u; +} +inline void TestDynamicExtensions::clear_has_message_extension() { + _has_bits_[0] &= ~0x00000008u; +} +inline void TestDynamicExtensions::clear_message_extension() { + if (message_extension_ != NULL) message_extension_->::protobuf_unittest::ForeignMessage::Clear(); + clear_has_message_extension(); +} +inline const ::protobuf_unittest::ForeignMessage& TestDynamicExtensions::message_extension() const { + return message_extension_ != NULL ? *message_extension_ : *default_instance_->message_extension_; +} +inline ::protobuf_unittest::ForeignMessage* TestDynamicExtensions::mutable_message_extension() { + set_has_message_extension(); + if (message_extension_ == NULL) message_extension_ = new ::protobuf_unittest::ForeignMessage; + return message_extension_; +} +inline ::protobuf_unittest::ForeignMessage* TestDynamicExtensions::release_message_extension() { + clear_has_message_extension(); + ::protobuf_unittest::ForeignMessage* temp = message_extension_; + message_extension_ = NULL; + return temp; +} + +// optional .protobuf_unittest.TestDynamicExtensions.DynamicMessageType dynamic_message_extension = 2004; +inline bool TestDynamicExtensions::has_dynamic_message_extension() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void TestDynamicExtensions::set_has_dynamic_message_extension() { + _has_bits_[0] |= 0x00000010u; +} +inline void TestDynamicExtensions::clear_has_dynamic_message_extension() { + _has_bits_[0] &= ~0x00000010u; +} +inline void TestDynamicExtensions::clear_dynamic_message_extension() { + if (dynamic_message_extension_ != NULL) dynamic_message_extension_->::protobuf_unittest::TestDynamicExtensions_DynamicMessageType::Clear(); + clear_has_dynamic_message_extension(); +} +inline const ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType& TestDynamicExtensions::dynamic_message_extension() const { + return dynamic_message_extension_ != NULL ? *dynamic_message_extension_ : *default_instance_->dynamic_message_extension_; +} +inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* TestDynamicExtensions::mutable_dynamic_message_extension() { + set_has_dynamic_message_extension(); + if (dynamic_message_extension_ == NULL) dynamic_message_extension_ = new ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType; + return dynamic_message_extension_; +} +inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* TestDynamicExtensions::release_dynamic_message_extension() { + clear_has_dynamic_message_extension(); + ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* temp = dynamic_message_extension_; + dynamic_message_extension_ = NULL; + return temp; +} + +// repeated string repeated_extension = 2005; +inline int TestDynamicExtensions::repeated_extension_size() const { + return repeated_extension_.size(); +} +inline void TestDynamicExtensions::clear_repeated_extension() { + repeated_extension_.Clear(); +} +inline const ::std::string& TestDynamicExtensions::repeated_extension(int index) const { + return repeated_extension_.Get(index); +} +inline ::std::string* TestDynamicExtensions::mutable_repeated_extension(int index) { + return repeated_extension_.Mutable(index); +} +inline void TestDynamicExtensions::set_repeated_extension(int index, const ::std::string& value) { + repeated_extension_.Mutable(index)->assign(value); +} +inline void TestDynamicExtensions::set_repeated_extension(int index, const char* value) { + repeated_extension_.Mutable(index)->assign(value); +} +inline void TestDynamicExtensions::set_repeated_extension(int index, const char* value, size_t size) { + repeated_extension_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestDynamicExtensions::add_repeated_extension() { + return repeated_extension_.Add(); +} +inline void TestDynamicExtensions::add_repeated_extension(const ::std::string& value) { + repeated_extension_.Add()->assign(value); +} +inline void TestDynamicExtensions::add_repeated_extension(const char* value) { + repeated_extension_.Add()->assign(value); +} +inline void TestDynamicExtensions::add_repeated_extension(const char* value, size_t size) { + repeated_extension_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestDynamicExtensions::repeated_extension() const { + return repeated_extension_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestDynamicExtensions::mutable_repeated_extension() { + return &repeated_extension_; +} + +// repeated sint32 packed_extension = 2006 [packed = true]; +inline int TestDynamicExtensions::packed_extension_size() const { + return packed_extension_.size(); +} +inline void TestDynamicExtensions::clear_packed_extension() { + packed_extension_.Clear(); +} +inline ::google::protobuf::int32 TestDynamicExtensions::packed_extension(int index) const { + return packed_extension_.Get(index); +} +inline void TestDynamicExtensions::set_packed_extension(int index, ::google::protobuf::int32 value) { + packed_extension_.Set(index, value); +} +inline void TestDynamicExtensions::add_packed_extension(::google::protobuf::int32 value) { + packed_extension_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestDynamicExtensions::packed_extension() const { + return packed_extension_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestDynamicExtensions::mutable_packed_extension() { + return &packed_extension_; +} + +// ------------------------------------------------------------------- + +// TestRepeatedScalarDifferentTagSizes + +// repeated fixed32 repeated_fixed32 = 12; +inline int TestRepeatedScalarDifferentTagSizes::repeated_fixed32_size() const { + return repeated_fixed32_.size(); +} +inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_fixed32() { + repeated_fixed32_.Clear(); +} +inline ::google::protobuf::uint32 TestRepeatedScalarDifferentTagSizes::repeated_fixed32(int index) const { + return repeated_fixed32_.Get(index); +} +inline void TestRepeatedScalarDifferentTagSizes::set_repeated_fixed32(int index, ::google::protobuf::uint32 value) { + repeated_fixed32_.Set(index, value); +} +inline void TestRepeatedScalarDifferentTagSizes::add_repeated_fixed32(::google::protobuf::uint32 value) { + repeated_fixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestRepeatedScalarDifferentTagSizes::repeated_fixed32() const { + return repeated_fixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestRepeatedScalarDifferentTagSizes::mutable_repeated_fixed32() { + return &repeated_fixed32_; +} + +// repeated int32 repeated_int32 = 13; +inline int TestRepeatedScalarDifferentTagSizes::repeated_int32_size() const { + return repeated_int32_.size(); +} +inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_int32() { + repeated_int32_.Clear(); +} +inline ::google::protobuf::int32 TestRepeatedScalarDifferentTagSizes::repeated_int32(int index) const { + return repeated_int32_.Get(index); +} +inline void TestRepeatedScalarDifferentTagSizes::set_repeated_int32(int index, ::google::protobuf::int32 value) { + repeated_int32_.Set(index, value); +} +inline void TestRepeatedScalarDifferentTagSizes::add_repeated_int32(::google::protobuf::int32 value) { + repeated_int32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestRepeatedScalarDifferentTagSizes::repeated_int32() const { + return repeated_int32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestRepeatedScalarDifferentTagSizes::mutable_repeated_int32() { + return &repeated_int32_; +} + +// repeated fixed64 repeated_fixed64 = 2046; +inline int TestRepeatedScalarDifferentTagSizes::repeated_fixed64_size() const { + return repeated_fixed64_.size(); +} +inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_fixed64() { + repeated_fixed64_.Clear(); +} +inline ::google::protobuf::uint64 TestRepeatedScalarDifferentTagSizes::repeated_fixed64(int index) const { + return repeated_fixed64_.Get(index); +} +inline void TestRepeatedScalarDifferentTagSizes::set_repeated_fixed64(int index, ::google::protobuf::uint64 value) { + repeated_fixed64_.Set(index, value); +} +inline void TestRepeatedScalarDifferentTagSizes::add_repeated_fixed64(::google::protobuf::uint64 value) { + repeated_fixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestRepeatedScalarDifferentTagSizes::repeated_fixed64() const { + return repeated_fixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestRepeatedScalarDifferentTagSizes::mutable_repeated_fixed64() { + return &repeated_fixed64_; +} + +// repeated int64 repeated_int64 = 2047; +inline int TestRepeatedScalarDifferentTagSizes::repeated_int64_size() const { + return repeated_int64_.size(); +} +inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_int64() { + repeated_int64_.Clear(); +} +inline ::google::protobuf::int64 TestRepeatedScalarDifferentTagSizes::repeated_int64(int index) const { + return repeated_int64_.Get(index); +} +inline void TestRepeatedScalarDifferentTagSizes::set_repeated_int64(int index, ::google::protobuf::int64 value) { + repeated_int64_.Set(index, value); +} +inline void TestRepeatedScalarDifferentTagSizes::add_repeated_int64(::google::protobuf::int64 value) { + repeated_int64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestRepeatedScalarDifferentTagSizes::repeated_int64() const { + return repeated_int64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestRepeatedScalarDifferentTagSizes::mutable_repeated_int64() { + return &repeated_int64_; +} + +// repeated float repeated_float = 262142; +inline int TestRepeatedScalarDifferentTagSizes::repeated_float_size() const { + return repeated_float_.size(); +} +inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_float() { + repeated_float_.Clear(); +} +inline float TestRepeatedScalarDifferentTagSizes::repeated_float(int index) const { + return repeated_float_.Get(index); +} +inline void TestRepeatedScalarDifferentTagSizes::set_repeated_float(int index, float value) { + repeated_float_.Set(index, value); +} +inline void TestRepeatedScalarDifferentTagSizes::add_repeated_float(float value) { + repeated_float_.Add(value); +} +inline const ::google::protobuf::RepeatedField< float >& +TestRepeatedScalarDifferentTagSizes::repeated_float() const { + return repeated_float_; +} +inline ::google::protobuf::RepeatedField< float >* +TestRepeatedScalarDifferentTagSizes::mutable_repeated_float() { + return &repeated_float_; +} + +// repeated uint64 repeated_uint64 = 262143; +inline int TestRepeatedScalarDifferentTagSizes::repeated_uint64_size() const { + return repeated_uint64_.size(); +} +inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_uint64() { + repeated_uint64_.Clear(); +} +inline ::google::protobuf::uint64 TestRepeatedScalarDifferentTagSizes::repeated_uint64(int index) const { + return repeated_uint64_.Get(index); +} +inline void TestRepeatedScalarDifferentTagSizes::set_repeated_uint64(int index, ::google::protobuf::uint64 value) { + repeated_uint64_.Set(index, value); +} +inline void TestRepeatedScalarDifferentTagSizes::add_repeated_uint64(::google::protobuf::uint64 value) { + repeated_uint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestRepeatedScalarDifferentTagSizes::repeated_uint64() const { + return repeated_uint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestRepeatedScalarDifferentTagSizes::mutable_repeated_uint64() { + return &repeated_uint64_; +} + +// ------------------------------------------------------------------- + +// FooRequest + +// ------------------------------------------------------------------- + +// FooResponse + +// ------------------------------------------------------------------- + +// BarRequest + +// ------------------------------------------------------------------- + +// BarResponse + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +#ifndef SWIG +namespace google { +namespace protobuf { + +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestAllTypes_NestedEnum>() { + return ::protobuf_unittest::TestAllTypes_NestedEnum_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType>() { + return ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::ForeignEnum>() { + return protobuf_unittest::ForeignEnum_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::TestEnumWithDupValue>() { + return protobuf_unittest::TestEnumWithDupValue_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::TestSparseEnum>() { + return protobuf_unittest::TestSparseEnum_descriptor(); +} + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h new file mode 100644 index 00000000..c4e16bbe --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h @@ -0,0 +1,2895 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_custom_options.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +#include +#include "google/protobuf/descriptor.pb.h" +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + +class TestMessageWithCustomOptions; +class CustomOptionFooRequest; +class CustomOptionFooResponse; +class DummyMessageContainingEnum; +class DummyMessageInvalidAsOptionType; +class CustomOptionMinIntegerValues; +class CustomOptionMaxIntegerValues; +class CustomOptionOtherValues; +class SettingRealsFromPositiveInts; +class SettingRealsFromNegativeInts; +class ComplexOptionType1; +class ComplexOptionType2; +class ComplexOptionType2_ComplexOptionType4; +class ComplexOptionType3; +class ComplexOptionType3_ComplexOptionType5; +class ComplexOpt6; +class VariousComplexOptions; +class AggregateMessageSet; +class AggregateMessageSetElement; +class Aggregate; +class AggregateMessage; + +enum TestMessageWithCustomOptions_AnEnum { + TestMessageWithCustomOptions_AnEnum_ANENUM_VAL1 = 1, + TestMessageWithCustomOptions_AnEnum_ANENUM_VAL2 = 2 +}; +bool TestMessageWithCustomOptions_AnEnum_IsValid(int value); +const TestMessageWithCustomOptions_AnEnum TestMessageWithCustomOptions_AnEnum_AnEnum_MIN = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL1; +const TestMessageWithCustomOptions_AnEnum TestMessageWithCustomOptions_AnEnum_AnEnum_MAX = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL2; +const int TestMessageWithCustomOptions_AnEnum_AnEnum_ARRAYSIZE = TestMessageWithCustomOptions_AnEnum_AnEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* TestMessageWithCustomOptions_AnEnum_descriptor(); +inline const ::std::string& TestMessageWithCustomOptions_AnEnum_Name(TestMessageWithCustomOptions_AnEnum value) { + return ::google::protobuf::internal::NameOfEnum( + TestMessageWithCustomOptions_AnEnum_descriptor(), value); +} +inline bool TestMessageWithCustomOptions_AnEnum_Parse( + const ::std::string& name, TestMessageWithCustomOptions_AnEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + TestMessageWithCustomOptions_AnEnum_descriptor(), name, value); +} +enum DummyMessageContainingEnum_TestEnumType { + DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE1 = 22, + DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE2 = -23 +}; +bool DummyMessageContainingEnum_TestEnumType_IsValid(int value); +const DummyMessageContainingEnum_TestEnumType DummyMessageContainingEnum_TestEnumType_TestEnumType_MIN = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE2; +const DummyMessageContainingEnum_TestEnumType DummyMessageContainingEnum_TestEnumType_TestEnumType_MAX = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE1; +const int DummyMessageContainingEnum_TestEnumType_TestEnumType_ARRAYSIZE = DummyMessageContainingEnum_TestEnumType_TestEnumType_MAX + 1; + +const ::google::protobuf::EnumDescriptor* DummyMessageContainingEnum_TestEnumType_descriptor(); +inline const ::std::string& DummyMessageContainingEnum_TestEnumType_Name(DummyMessageContainingEnum_TestEnumType value) { + return ::google::protobuf::internal::NameOfEnum( + DummyMessageContainingEnum_TestEnumType_descriptor(), value); +} +inline bool DummyMessageContainingEnum_TestEnumType_Parse( + const ::std::string& name, DummyMessageContainingEnum_TestEnumType* value) { + return ::google::protobuf::internal::ParseNamedEnum( + DummyMessageContainingEnum_TestEnumType_descriptor(), name, value); +} +enum MethodOpt1 { + METHODOPT1_VAL1 = 1, + METHODOPT1_VAL2 = 2 +}; +bool MethodOpt1_IsValid(int value); +const MethodOpt1 MethodOpt1_MIN = METHODOPT1_VAL1; +const MethodOpt1 MethodOpt1_MAX = METHODOPT1_VAL2; +const int MethodOpt1_ARRAYSIZE = MethodOpt1_MAX + 1; + +const ::google::protobuf::EnumDescriptor* MethodOpt1_descriptor(); +inline const ::std::string& MethodOpt1_Name(MethodOpt1 value) { + return ::google::protobuf::internal::NameOfEnum( + MethodOpt1_descriptor(), value); +} +inline bool MethodOpt1_Parse( + const ::std::string& name, MethodOpt1* value) { + return ::google::protobuf::internal::ParseNamedEnum( + MethodOpt1_descriptor(), name, value); +} +enum AggregateEnum { + VALUE = 1 +}; +bool AggregateEnum_IsValid(int value); +const AggregateEnum AggregateEnum_MIN = VALUE; +const AggregateEnum AggregateEnum_MAX = VALUE; +const int AggregateEnum_ARRAYSIZE = AggregateEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* AggregateEnum_descriptor(); +inline const ::std::string& AggregateEnum_Name(AggregateEnum value) { + return ::google::protobuf::internal::NameOfEnum( + AggregateEnum_descriptor(), value); +} +inline bool AggregateEnum_Parse( + const ::std::string& name, AggregateEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + AggregateEnum_descriptor(), name, value); +} +// =================================================================== + +class TestMessageWithCustomOptions : public ::google::protobuf::Message { + public: + TestMessageWithCustomOptions(); + virtual ~TestMessageWithCustomOptions(); + + TestMessageWithCustomOptions(const TestMessageWithCustomOptions& from); + + inline TestMessageWithCustomOptions& operator=(const TestMessageWithCustomOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMessageWithCustomOptions& default_instance(); + + void Swap(TestMessageWithCustomOptions* other); + + // implements Message ---------------------------------------------- + + TestMessageWithCustomOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMessageWithCustomOptions& from); + void MergeFrom(const TestMessageWithCustomOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef TestMessageWithCustomOptions_AnEnum AnEnum; + static const AnEnum ANENUM_VAL1 = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL1; + static const AnEnum ANENUM_VAL2 = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL2; + static inline bool AnEnum_IsValid(int value) { + return TestMessageWithCustomOptions_AnEnum_IsValid(value); + } + static const AnEnum AnEnum_MIN = + TestMessageWithCustomOptions_AnEnum_AnEnum_MIN; + static const AnEnum AnEnum_MAX = + TestMessageWithCustomOptions_AnEnum_AnEnum_MAX; + static const int AnEnum_ARRAYSIZE = + TestMessageWithCustomOptions_AnEnum_AnEnum_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + AnEnum_descriptor() { + return TestMessageWithCustomOptions_AnEnum_descriptor(); + } + static inline const ::std::string& AnEnum_Name(AnEnum value) { + return TestMessageWithCustomOptions_AnEnum_Name(value); + } + static inline bool AnEnum_Parse(const ::std::string& name, + AnEnum* value) { + return TestMessageWithCustomOptions_AnEnum_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // optional string field1 = 1 [ctype = CORD]; + inline bool has_field1() const; + inline void clear_field1(); + static const int kField1FieldNumber = 1; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& field1() const; + inline void set_field1(const ::std::string& value); + inline void set_field1(const char* value); + inline void set_field1(const char* value, size_t size); + inline ::std::string* mutable_field1(); + inline ::std::string* release_field1(); + public: + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageWithCustomOptions) + private: + inline void set_has_field1(); + inline void clear_has_field1(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* field1_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static TestMessageWithCustomOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class CustomOptionFooRequest : public ::google::protobuf::Message { + public: + CustomOptionFooRequest(); + virtual ~CustomOptionFooRequest(); + + CustomOptionFooRequest(const CustomOptionFooRequest& from); + + inline CustomOptionFooRequest& operator=(const CustomOptionFooRequest& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CustomOptionFooRequest& default_instance(); + + void Swap(CustomOptionFooRequest* other); + + // implements Message ---------------------------------------------- + + CustomOptionFooRequest* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CustomOptionFooRequest& from); + void MergeFrom(const CustomOptionFooRequest& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionFooRequest) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static CustomOptionFooRequest* default_instance_; +}; +// ------------------------------------------------------------------- + +class CustomOptionFooResponse : public ::google::protobuf::Message { + public: + CustomOptionFooResponse(); + virtual ~CustomOptionFooResponse(); + + CustomOptionFooResponse(const CustomOptionFooResponse& from); + + inline CustomOptionFooResponse& operator=(const CustomOptionFooResponse& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CustomOptionFooResponse& default_instance(); + + void Swap(CustomOptionFooResponse* other); + + // implements Message ---------------------------------------------- + + CustomOptionFooResponse* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CustomOptionFooResponse& from); + void MergeFrom(const CustomOptionFooResponse& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionFooResponse) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static CustomOptionFooResponse* default_instance_; +}; +// ------------------------------------------------------------------- + +class DummyMessageContainingEnum : public ::google::protobuf::Message { + public: + DummyMessageContainingEnum(); + virtual ~DummyMessageContainingEnum(); + + DummyMessageContainingEnum(const DummyMessageContainingEnum& from); + + inline DummyMessageContainingEnum& operator=(const DummyMessageContainingEnum& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const DummyMessageContainingEnum& default_instance(); + + void Swap(DummyMessageContainingEnum* other); + + // implements Message ---------------------------------------------- + + DummyMessageContainingEnum* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const DummyMessageContainingEnum& from); + void MergeFrom(const DummyMessageContainingEnum& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef DummyMessageContainingEnum_TestEnumType TestEnumType; + static const TestEnumType TEST_OPTION_ENUM_TYPE1 = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE1; + static const TestEnumType TEST_OPTION_ENUM_TYPE2 = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE2; + static inline bool TestEnumType_IsValid(int value) { + return DummyMessageContainingEnum_TestEnumType_IsValid(value); + } + static const TestEnumType TestEnumType_MIN = + DummyMessageContainingEnum_TestEnumType_TestEnumType_MIN; + static const TestEnumType TestEnumType_MAX = + DummyMessageContainingEnum_TestEnumType_TestEnumType_MAX; + static const int TestEnumType_ARRAYSIZE = + DummyMessageContainingEnum_TestEnumType_TestEnumType_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + TestEnumType_descriptor() { + return DummyMessageContainingEnum_TestEnumType_descriptor(); + } + static inline const ::std::string& TestEnumType_Name(TestEnumType value) { + return DummyMessageContainingEnum_TestEnumType_Name(value); + } + static inline bool TestEnumType_Parse(const ::std::string& name, + TestEnumType* value) { + return DummyMessageContainingEnum_TestEnumType_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.DummyMessageContainingEnum) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static DummyMessageContainingEnum* default_instance_; +}; +// ------------------------------------------------------------------- + +class DummyMessageInvalidAsOptionType : public ::google::protobuf::Message { + public: + DummyMessageInvalidAsOptionType(); + virtual ~DummyMessageInvalidAsOptionType(); + + DummyMessageInvalidAsOptionType(const DummyMessageInvalidAsOptionType& from); + + inline DummyMessageInvalidAsOptionType& operator=(const DummyMessageInvalidAsOptionType& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const DummyMessageInvalidAsOptionType& default_instance(); + + void Swap(DummyMessageInvalidAsOptionType* other); + + // implements Message ---------------------------------------------- + + DummyMessageInvalidAsOptionType* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const DummyMessageInvalidAsOptionType& from); + void MergeFrom(const DummyMessageInvalidAsOptionType& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.DummyMessageInvalidAsOptionType) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static DummyMessageInvalidAsOptionType* default_instance_; +}; +// ------------------------------------------------------------------- + +class CustomOptionMinIntegerValues : public ::google::protobuf::Message { + public: + CustomOptionMinIntegerValues(); + virtual ~CustomOptionMinIntegerValues(); + + CustomOptionMinIntegerValues(const CustomOptionMinIntegerValues& from); + + inline CustomOptionMinIntegerValues& operator=(const CustomOptionMinIntegerValues& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CustomOptionMinIntegerValues& default_instance(); + + void Swap(CustomOptionMinIntegerValues* other); + + // implements Message ---------------------------------------------- + + CustomOptionMinIntegerValues* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CustomOptionMinIntegerValues& from); + void MergeFrom(const CustomOptionMinIntegerValues& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionMinIntegerValues) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static CustomOptionMinIntegerValues* default_instance_; +}; +// ------------------------------------------------------------------- + +class CustomOptionMaxIntegerValues : public ::google::protobuf::Message { + public: + CustomOptionMaxIntegerValues(); + virtual ~CustomOptionMaxIntegerValues(); + + CustomOptionMaxIntegerValues(const CustomOptionMaxIntegerValues& from); + + inline CustomOptionMaxIntegerValues& operator=(const CustomOptionMaxIntegerValues& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CustomOptionMaxIntegerValues& default_instance(); + + void Swap(CustomOptionMaxIntegerValues* other); + + // implements Message ---------------------------------------------- + + CustomOptionMaxIntegerValues* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CustomOptionMaxIntegerValues& from); + void MergeFrom(const CustomOptionMaxIntegerValues& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionMaxIntegerValues) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static CustomOptionMaxIntegerValues* default_instance_; +}; +// ------------------------------------------------------------------- + +class CustomOptionOtherValues : public ::google::protobuf::Message { + public: + CustomOptionOtherValues(); + virtual ~CustomOptionOtherValues(); + + CustomOptionOtherValues(const CustomOptionOtherValues& from); + + inline CustomOptionOtherValues& operator=(const CustomOptionOtherValues& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CustomOptionOtherValues& default_instance(); + + void Swap(CustomOptionOtherValues* other); + + // implements Message ---------------------------------------------- + + CustomOptionOtherValues* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CustomOptionOtherValues& from); + void MergeFrom(const CustomOptionOtherValues& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionOtherValues) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static CustomOptionOtherValues* default_instance_; +}; +// ------------------------------------------------------------------- + +class SettingRealsFromPositiveInts : public ::google::protobuf::Message { + public: + SettingRealsFromPositiveInts(); + virtual ~SettingRealsFromPositiveInts(); + + SettingRealsFromPositiveInts(const SettingRealsFromPositiveInts& from); + + inline SettingRealsFromPositiveInts& operator=(const SettingRealsFromPositiveInts& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const SettingRealsFromPositiveInts& default_instance(); + + void Swap(SettingRealsFromPositiveInts* other); + + // implements Message ---------------------------------------------- + + SettingRealsFromPositiveInts* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const SettingRealsFromPositiveInts& from); + void MergeFrom(const SettingRealsFromPositiveInts& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.SettingRealsFromPositiveInts) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static SettingRealsFromPositiveInts* default_instance_; +}; +// ------------------------------------------------------------------- + +class SettingRealsFromNegativeInts : public ::google::protobuf::Message { + public: + SettingRealsFromNegativeInts(); + virtual ~SettingRealsFromNegativeInts(); + + SettingRealsFromNegativeInts(const SettingRealsFromNegativeInts& from); + + inline SettingRealsFromNegativeInts& operator=(const SettingRealsFromNegativeInts& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const SettingRealsFromNegativeInts& default_instance(); + + void Swap(SettingRealsFromNegativeInts* other); + + // implements Message ---------------------------------------------- + + SettingRealsFromNegativeInts* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const SettingRealsFromNegativeInts& from); + void MergeFrom(const SettingRealsFromNegativeInts& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.SettingRealsFromNegativeInts) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static SettingRealsFromNegativeInts* default_instance_; +}; +// ------------------------------------------------------------------- + +class ComplexOptionType1 : public ::google::protobuf::Message { + public: + ComplexOptionType1(); + virtual ~ComplexOptionType1(); + + ComplexOptionType1(const ComplexOptionType1& from); + + inline ComplexOptionType1& operator=(const ComplexOptionType1& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ComplexOptionType1& default_instance(); + + void Swap(ComplexOptionType1* other); + + // implements Message ---------------------------------------------- + + ComplexOptionType1* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ComplexOptionType1& from); + void MergeFrom(const ComplexOptionType1& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 foo = 1; + inline bool has_foo() const; + inline void clear_foo(); + static const int kFooFieldNumber = 1; + inline ::google::protobuf::int32 foo() const; + inline void set_foo(::google::protobuf::int32 value); + + // optional int32 foo2 = 2; + inline bool has_foo2() const; + inline void clear_foo2(); + static const int kFoo2FieldNumber = 2; + inline ::google::protobuf::int32 foo2() const; + inline void set_foo2(::google::protobuf::int32 value); + + // optional int32 foo3 = 3; + inline bool has_foo3() const; + inline void clear_foo3(); + static const int kFoo3FieldNumber = 3; + inline ::google::protobuf::int32 foo3() const; + inline void set_foo3(::google::protobuf::int32 value); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ComplexOptionType1) + // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType1) + private: + inline void set_has_foo(); + inline void clear_has_foo(); + inline void set_has_foo2(); + inline void clear_has_foo2(); + inline void set_has_foo3(); + inline void clear_has_foo3(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 foo_; + ::google::protobuf::int32 foo2_; + ::google::protobuf::int32 foo3_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static ComplexOptionType1* default_instance_; +}; +// ------------------------------------------------------------------- + +class ComplexOptionType2_ComplexOptionType4 : public ::google::protobuf::Message { + public: + ComplexOptionType2_ComplexOptionType4(); + virtual ~ComplexOptionType2_ComplexOptionType4(); + + ComplexOptionType2_ComplexOptionType4(const ComplexOptionType2_ComplexOptionType4& from); + + inline ComplexOptionType2_ComplexOptionType4& operator=(const ComplexOptionType2_ComplexOptionType4& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ComplexOptionType2_ComplexOptionType4& default_instance(); + + void Swap(ComplexOptionType2_ComplexOptionType4* other); + + // implements Message ---------------------------------------------- + + ComplexOptionType2_ComplexOptionType4* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ComplexOptionType2_ComplexOptionType4& from); + void MergeFrom(const ComplexOptionType2_ComplexOptionType4& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 waldo = 1; + inline bool has_waldo() const; + inline void clear_waldo(); + static const int kWaldoFieldNumber = 1; + inline ::google::protobuf::int32 waldo() const; + inline void set_waldo(::google::protobuf::int32 value); + + static const int kComplexOpt4FieldNumber = 7633546; + static ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4 >, 11, false > + complex_opt4; + // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType2.ComplexOptionType4) + private: + inline void set_has_waldo(); + inline void clear_has_waldo(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 waldo_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static ComplexOptionType2_ComplexOptionType4* default_instance_; +}; +// ------------------------------------------------------------------- + +class ComplexOptionType2 : public ::google::protobuf::Message { + public: + ComplexOptionType2(); + virtual ~ComplexOptionType2(); + + ComplexOptionType2(const ComplexOptionType2& from); + + inline ComplexOptionType2& operator=(const ComplexOptionType2& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ComplexOptionType2& default_instance(); + + void Swap(ComplexOptionType2* other); + + // implements Message ---------------------------------------------- + + ComplexOptionType2* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ComplexOptionType2& from); + void MergeFrom(const ComplexOptionType2& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef ComplexOptionType2_ComplexOptionType4 ComplexOptionType4; + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.ComplexOptionType1 bar = 1; + inline bool has_bar() const; + inline void clear_bar(); + static const int kBarFieldNumber = 1; + inline const ::protobuf_unittest::ComplexOptionType1& bar() const; + inline ::protobuf_unittest::ComplexOptionType1* mutable_bar(); + inline ::protobuf_unittest::ComplexOptionType1* release_bar(); + + // optional int32 baz = 2; + inline bool has_baz() const; + inline void clear_baz(); + static const int kBazFieldNumber = 2; + inline ::google::protobuf::int32 baz() const; + inline void set_baz(::google::protobuf::int32 value); + + // optional .protobuf_unittest.ComplexOptionType2.ComplexOptionType4 fred = 3; + inline bool has_fred() const; + inline void clear_fred(); + static const int kFredFieldNumber = 3; + inline const ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4& fred() const; + inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* mutable_fred(); + inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* release_fred(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ComplexOptionType2) + // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType2) + private: + inline void set_has_bar(); + inline void clear_has_bar(); + inline void set_has_baz(); + inline void clear_has_baz(); + inline void set_has_fred(); + inline void clear_has_fred(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::ComplexOptionType1* bar_; + ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* fred_; + ::google::protobuf::int32 baz_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static ComplexOptionType2* default_instance_; +}; +// ------------------------------------------------------------------- + +class ComplexOptionType3_ComplexOptionType5 : public ::google::protobuf::Message { + public: + ComplexOptionType3_ComplexOptionType5(); + virtual ~ComplexOptionType3_ComplexOptionType5(); + + ComplexOptionType3_ComplexOptionType5(const ComplexOptionType3_ComplexOptionType5& from); + + inline ComplexOptionType3_ComplexOptionType5& operator=(const ComplexOptionType3_ComplexOptionType5& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ComplexOptionType3_ComplexOptionType5& default_instance(); + + void Swap(ComplexOptionType3_ComplexOptionType5* other); + + // implements Message ---------------------------------------------- + + ComplexOptionType3_ComplexOptionType5* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ComplexOptionType3_ComplexOptionType5& from); + void MergeFrom(const ComplexOptionType3_ComplexOptionType5& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 plugh = 3; + inline bool has_plugh() const; + inline void clear_plugh(); + static const int kPlughFieldNumber = 3; + inline ::google::protobuf::int32 plugh() const; + inline void set_plugh(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType3.ComplexOptionType5) + private: + inline void set_has_plugh(); + inline void clear_has_plugh(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 plugh_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static ComplexOptionType3_ComplexOptionType5* default_instance_; +}; +// ------------------------------------------------------------------- + +class ComplexOptionType3 : public ::google::protobuf::Message { + public: + ComplexOptionType3(); + virtual ~ComplexOptionType3(); + + ComplexOptionType3(const ComplexOptionType3& from); + + inline ComplexOptionType3& operator=(const ComplexOptionType3& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ComplexOptionType3& default_instance(); + + void Swap(ComplexOptionType3* other); + + // implements Message ---------------------------------------------- + + ComplexOptionType3* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ComplexOptionType3& from); + void MergeFrom(const ComplexOptionType3& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef ComplexOptionType3_ComplexOptionType5 ComplexOptionType5; + + // accessors ------------------------------------------------------- + + // optional int32 qux = 1; + inline bool has_qux() const; + inline void clear_qux(); + static const int kQuxFieldNumber = 1; + inline ::google::protobuf::int32 qux() const; + inline void set_qux(::google::protobuf::int32 value); + + // optional group ComplexOptionType5 = 2 { + inline bool has_complexoptiontype5() const; + inline void clear_complexoptiontype5(); + static const int kComplexoptiontype5FieldNumber = 2; + inline const ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5& complexoptiontype5() const; + inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* mutable_complexoptiontype5(); + inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* release_complexoptiontype5(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType3) + private: + inline void set_has_qux(); + inline void clear_has_qux(); + inline void set_has_complexoptiontype5(); + inline void clear_has_complexoptiontype5(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* complexoptiontype5_; + ::google::protobuf::int32 qux_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static ComplexOptionType3* default_instance_; +}; +// ------------------------------------------------------------------- + +class ComplexOpt6 : public ::google::protobuf::Message { + public: + ComplexOpt6(); + virtual ~ComplexOpt6(); + + ComplexOpt6(const ComplexOpt6& from); + + inline ComplexOpt6& operator=(const ComplexOpt6& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ComplexOpt6& default_instance(); + + void Swap(ComplexOpt6* other); + + // implements Message ---------------------------------------------- + + ComplexOpt6* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ComplexOpt6& from); + void MergeFrom(const ComplexOpt6& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 xyzzy = 7593951; + inline bool has_xyzzy() const; + inline void clear_xyzzy(); + static const int kXyzzyFieldNumber = 7593951; + inline ::google::protobuf::int32 xyzzy() const; + inline void set_xyzzy(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOpt6) + private: + inline void set_has_xyzzy(); + inline void clear_has_xyzzy(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 xyzzy_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static ComplexOpt6* default_instance_; +}; +// ------------------------------------------------------------------- + +class VariousComplexOptions : public ::google::protobuf::Message { + public: + VariousComplexOptions(); + virtual ~VariousComplexOptions(); + + VariousComplexOptions(const VariousComplexOptions& from); + + inline VariousComplexOptions& operator=(const VariousComplexOptions& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const VariousComplexOptions& default_instance(); + + void Swap(VariousComplexOptions* other); + + // implements Message ---------------------------------------------- + + VariousComplexOptions* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const VariousComplexOptions& from); + void MergeFrom(const VariousComplexOptions& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // @@protoc_insertion_point(class_scope:protobuf_unittest.VariousComplexOptions) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static VariousComplexOptions* default_instance_; +}; +// ------------------------------------------------------------------- + +class AggregateMessageSet : public ::google::protobuf::Message { + public: + AggregateMessageSet(); + virtual ~AggregateMessageSet(); + + AggregateMessageSet(const AggregateMessageSet& from); + + inline AggregateMessageSet& operator=(const AggregateMessageSet& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const AggregateMessageSet& default_instance(); + + void Swap(AggregateMessageSet* other); + + // implements Message ---------------------------------------------- + + AggregateMessageSet* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const AggregateMessageSet& from); + void MergeFrom(const AggregateMessageSet& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(AggregateMessageSet) + // @@protoc_insertion_point(class_scope:protobuf_unittest.AggregateMessageSet) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static AggregateMessageSet* default_instance_; +}; +// ------------------------------------------------------------------- + +class AggregateMessageSetElement : public ::google::protobuf::Message { + public: + AggregateMessageSetElement(); + virtual ~AggregateMessageSetElement(); + + AggregateMessageSetElement(const AggregateMessageSetElement& from); + + inline AggregateMessageSetElement& operator=(const AggregateMessageSetElement& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const AggregateMessageSetElement& default_instance(); + + void Swap(AggregateMessageSetElement* other); + + // implements Message ---------------------------------------------- + + AggregateMessageSetElement* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const AggregateMessageSetElement& from); + void MergeFrom(const AggregateMessageSetElement& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string s = 1; + inline bool has_s() const; + inline void clear_s(); + static const int kSFieldNumber = 1; + inline const ::std::string& s() const; + inline void set_s(const ::std::string& value); + inline void set_s(const char* value); + inline void set_s(const char* value, size_t size); + inline ::std::string* mutable_s(); + inline ::std::string* release_s(); + + static const int kMessageSetExtensionFieldNumber = 15447542; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::AggregateMessageSet, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::AggregateMessageSetElement >, 11, false > + message_set_extension; + // @@protoc_insertion_point(class_scope:protobuf_unittest.AggregateMessageSetElement) + private: + inline void set_has_s(); + inline void clear_has_s(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* s_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static AggregateMessageSetElement* default_instance_; +}; +// ------------------------------------------------------------------- + +class Aggregate : public ::google::protobuf::Message { + public: + Aggregate(); + virtual ~Aggregate(); + + Aggregate(const Aggregate& from); + + inline Aggregate& operator=(const Aggregate& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const Aggregate& default_instance(); + + void Swap(Aggregate* other); + + // implements Message ---------------------------------------------- + + Aggregate* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const Aggregate& from); + void MergeFrom(const Aggregate& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 i = 1; + inline bool has_i() const; + inline void clear_i(); + static const int kIFieldNumber = 1; + inline ::google::protobuf::int32 i() const; + inline void set_i(::google::protobuf::int32 value); + + // optional string s = 2; + inline bool has_s() const; + inline void clear_s(); + static const int kSFieldNumber = 2; + inline const ::std::string& s() const; + inline void set_s(const ::std::string& value); + inline void set_s(const char* value); + inline void set_s(const char* value, size_t size); + inline ::std::string* mutable_s(); + inline ::std::string* release_s(); + + // optional .protobuf_unittest.Aggregate sub = 3; + inline bool has_sub() const; + inline void clear_sub(); + static const int kSubFieldNumber = 3; + inline const ::protobuf_unittest::Aggregate& sub() const; + inline ::protobuf_unittest::Aggregate* mutable_sub(); + inline ::protobuf_unittest::Aggregate* release_sub(); + + // optional .google.protobuf.FileOptions file = 4; + inline bool has_file() const; + inline void clear_file(); + static const int kFileFieldNumber = 4; + inline const ::google::protobuf::FileOptions& file() const; + inline ::google::protobuf::FileOptions* mutable_file(); + inline ::google::protobuf::FileOptions* release_file(); + + // optional .protobuf_unittest.AggregateMessageSet mset = 5; + inline bool has_mset() const; + inline void clear_mset(); + static const int kMsetFieldNumber = 5; + inline const ::protobuf_unittest::AggregateMessageSet& mset() const; + inline ::protobuf_unittest::AggregateMessageSet* mutable_mset(); + inline ::protobuf_unittest::AggregateMessageSet* release_mset(); + + static const int kNestedFieldNumber = 15476903; + static ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FileOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + nested; + // @@protoc_insertion_point(class_scope:protobuf_unittest.Aggregate) + private: + inline void set_has_i(); + inline void clear_has_i(); + inline void set_has_s(); + inline void clear_has_s(); + inline void set_has_sub(); + inline void clear_has_sub(); + inline void set_has_file(); + inline void clear_has_file(); + inline void set_has_mset(); + inline void clear_has_mset(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* s_; + ::protobuf_unittest::Aggregate* sub_; + ::google::protobuf::FileOptions* file_; + ::protobuf_unittest::AggregateMessageSet* mset_; + ::google::protobuf::int32 i_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(5 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static Aggregate* default_instance_; +}; +// ------------------------------------------------------------------- + +class AggregateMessage : public ::google::protobuf::Message { + public: + AggregateMessage(); + virtual ~AggregateMessage(); + + AggregateMessage(const AggregateMessage& from); + + inline AggregateMessage& operator=(const AggregateMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const AggregateMessage& default_instance(); + + void Swap(AggregateMessage* other); + + // implements Message ---------------------------------------------- + + AggregateMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const AggregateMessage& from); + void MergeFrom(const AggregateMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 fieldname = 1; + inline bool has_fieldname() const; + inline void clear_fieldname(); + static const int kFieldnameFieldNumber = 1; + inline ::google::protobuf::int32 fieldname() const; + inline void set_fieldname(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.AggregateMessage) + private: + inline void set_has_fieldname(); + inline void clear_has_fieldname(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 fieldname_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); + + void InitAsDefaultInstance(); + static AggregateMessage* default_instance_; +}; +// =================================================================== + +class TestServiceWithCustomOptions_Stub; + +class TestServiceWithCustomOptions : public ::google::protobuf::Service { + protected: + // This class should be treated as an abstract interface. + inline TestServiceWithCustomOptions() {}; + public: + virtual ~TestServiceWithCustomOptions(); + + typedef TestServiceWithCustomOptions_Stub Stub; + + static const ::google::protobuf::ServiceDescriptor* descriptor(); + + virtual void Foo(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::CustomOptionFooRequest* request, + ::protobuf_unittest::CustomOptionFooResponse* response, + ::google::protobuf::Closure* done); + + // implements Service ---------------------------------------------- + + const ::google::protobuf::ServiceDescriptor* GetDescriptor(); + void CallMethod(const ::google::protobuf::MethodDescriptor* method, + ::google::protobuf::RpcController* controller, + const ::google::protobuf::Message* request, + ::google::protobuf::Message* response, + ::google::protobuf::Closure* done); + const ::google::protobuf::Message& GetRequestPrototype( + const ::google::protobuf::MethodDescriptor* method) const; + const ::google::protobuf::Message& GetResponsePrototype( + const ::google::protobuf::MethodDescriptor* method) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestServiceWithCustomOptions); +}; + +class TestServiceWithCustomOptions_Stub : public TestServiceWithCustomOptions { + public: + TestServiceWithCustomOptions_Stub(::google::protobuf::RpcChannel* channel); + TestServiceWithCustomOptions_Stub(::google::protobuf::RpcChannel* channel, + ::google::protobuf::Service::ChannelOwnership ownership); + ~TestServiceWithCustomOptions_Stub(); + + inline ::google::protobuf::RpcChannel* channel() { return channel_; } + + // implements TestServiceWithCustomOptions ------------------------------------------ + + void Foo(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::CustomOptionFooRequest* request, + ::protobuf_unittest::CustomOptionFooResponse* response, + ::google::protobuf::Closure* done); + private: + ::google::protobuf::RpcChannel* channel_; + bool owns_channel_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestServiceWithCustomOptions_Stub); +}; + + +// ------------------------------------------------------------------- + +class AggregateService_Stub; + +class AggregateService : public ::google::protobuf::Service { + protected: + // This class should be treated as an abstract interface. + inline AggregateService() {}; + public: + virtual ~AggregateService(); + + typedef AggregateService_Stub Stub; + + static const ::google::protobuf::ServiceDescriptor* descriptor(); + + virtual void Method(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::AggregateMessage* request, + ::protobuf_unittest::AggregateMessage* response, + ::google::protobuf::Closure* done); + + // implements Service ---------------------------------------------- + + const ::google::protobuf::ServiceDescriptor* GetDescriptor(); + void CallMethod(const ::google::protobuf::MethodDescriptor* method, + ::google::protobuf::RpcController* controller, + const ::google::protobuf::Message* request, + ::google::protobuf::Message* response, + ::google::protobuf::Closure* done); + const ::google::protobuf::Message& GetRequestPrototype( + const ::google::protobuf::MethodDescriptor* method) const; + const ::google::protobuf::Message& GetResponsePrototype( + const ::google::protobuf::MethodDescriptor* method) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AggregateService); +}; + +class AggregateService_Stub : public AggregateService { + public: + AggregateService_Stub(::google::protobuf::RpcChannel* channel); + AggregateService_Stub(::google::protobuf::RpcChannel* channel, + ::google::protobuf::Service::ChannelOwnership ownership); + ~AggregateService_Stub(); + + inline ::google::protobuf::RpcChannel* channel() { return channel_; } + + // implements AggregateService ------------------------------------------ + + void Method(::google::protobuf::RpcController* controller, + const ::protobuf_unittest::AggregateMessage* request, + ::protobuf_unittest::AggregateMessage* response, + ::google::protobuf::Closure* done); + private: + ::google::protobuf::RpcChannel* channel_; + bool owns_channel_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AggregateService_Stub); +}; + + +// =================================================================== + +static const int kFileOpt1FieldNumber = 7736974; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FileOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + file_opt1; +static const int kMessageOpt1FieldNumber = 7739036; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + message_opt1; +static const int kFieldOpt1FieldNumber = 7740936; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + field_opt1; +static const int kFieldOpt2FieldNumber = 7753913; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + field_opt2; +static const int kEnumOpt1FieldNumber = 7753576; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + enum_opt1; +static const int kEnumValueOpt1FieldNumber = 1560678; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumValueOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + enum_value_opt1; +static const int kServiceOpt1FieldNumber = 7887650; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::ServiceOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + service_opt1; +static const int kMethodOpt1FieldNumber = 7890860; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::MethodOpt1, protobuf_unittest::MethodOpt1_IsValid>, 14, false > + method_opt1; +static const int kBoolOptFieldNumber = 7706090; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > + bool_opt; +static const int kInt32OptFieldNumber = 7705709; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + int32_opt; +static const int kInt64OptFieldNumber = 7705542; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > + int64_opt; +static const int kUint32OptFieldNumber = 7704880; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > + uint32_opt; +static const int kUint64OptFieldNumber = 7702367; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + uint64_opt; +static const int kSint32OptFieldNumber = 7701568; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > + sint32_opt; +static const int kSint64OptFieldNumber = 7700863; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + sint64_opt; +static const int kFixed32OptFieldNumber = 7700307; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > + fixed32_opt; +static const int kFixed64OptFieldNumber = 7700194; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + fixed64_opt; +static const int kSfixed32OptFieldNumber = 7698645; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + sfixed32_opt; +static const int kSfixed64OptFieldNumber = 7685475; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > + sfixed64_opt; +static const int kFloatOptFieldNumber = 7675390; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > + float_opt; +static const int kDoubleOptFieldNumber = 7673293; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > + double_opt; +static const int kStringOptFieldNumber = 7673285; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::StringTypeTraits, 9, false > + string_opt; +static const int kBytesOptFieldNumber = 7673238; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::StringTypeTraits, 12, false > + bytes_opt; +static const int kEnumOptFieldNumber = 7673233; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType, ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType_IsValid>, 14, false > + enum_opt; +static const int kMessageTypeOptFieldNumber = 7665967; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::DummyMessageInvalidAsOptionType >, 11, false > + message_type_opt; +static const int kQuuxFieldNumber = 7663707; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType1, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + quux; +static const int kCorgeFieldNumber = 7663442; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType1, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType3 >, 11, false > + corge; +static const int kGraultFieldNumber = 7650927; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType2, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + grault; +static const int kGarplyFieldNumber = 7649992; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType2, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType1 >, 11, false > + garply; +static const int kComplexOpt1FieldNumber = 7646756; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType1 >, 11, false > + complex_opt1; +static const int kComplexOpt2FieldNumber = 7636949; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType2 >, 11, false > + complex_opt2; +static const int kComplexOpt3FieldNumber = 7636463; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType3 >, 11, false > + complex_opt3; +static const int kComplexopt6FieldNumber = 7595468; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOpt6 >, 10, false > + complexopt6; +static const int kFileoptFieldNumber = 15478479; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FileOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + fileopt; +static const int kMsgoptFieldNumber = 15480088; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + msgopt; +static const int kFieldoptFieldNumber = 15481374; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + fieldopt; +static const int kEnumoptFieldNumber = 15483218; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + enumopt; +static const int kEnumvaloptFieldNumber = 15486921; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumValueOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + enumvalopt; +static const int kServiceoptFieldNumber = 15497145; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::ServiceOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + serviceopt; +static const int kMethodoptFieldNumber = 15512713; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > + methodopt; + +// =================================================================== + +// TestMessageWithCustomOptions + +// optional string field1 = 1 [ctype = CORD]; +inline bool TestMessageWithCustomOptions::has_field1() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestMessageWithCustomOptions::set_has_field1() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestMessageWithCustomOptions::clear_has_field1() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestMessageWithCustomOptions::clear_field1() { + if (field1_ != &::google::protobuf::internal::kEmptyString) { + field1_->clear(); + } + clear_has_field1(); +} +inline const ::std::string& TestMessageWithCustomOptions::field1() const { + return *field1_; +} +inline void TestMessageWithCustomOptions::set_field1(const ::std::string& value) { + set_has_field1(); + if (field1_ == &::google::protobuf::internal::kEmptyString) { + field1_ = new ::std::string; + } + field1_->assign(value); +} +inline void TestMessageWithCustomOptions::set_field1(const char* value) { + set_has_field1(); + if (field1_ == &::google::protobuf::internal::kEmptyString) { + field1_ = new ::std::string; + } + field1_->assign(value); +} +inline void TestMessageWithCustomOptions::set_field1(const char* value, size_t size) { + set_has_field1(); + if (field1_ == &::google::protobuf::internal::kEmptyString) { + field1_ = new ::std::string; + } + field1_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestMessageWithCustomOptions::mutable_field1() { + set_has_field1(); + if (field1_ == &::google::protobuf::internal::kEmptyString) { + field1_ = new ::std::string; + } + return field1_; +} +inline ::std::string* TestMessageWithCustomOptions::release_field1() { + clear_has_field1(); + if (field1_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = field1_; + field1_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// CustomOptionFooRequest + +// ------------------------------------------------------------------- + +// CustomOptionFooResponse + +// ------------------------------------------------------------------- + +// DummyMessageContainingEnum + +// ------------------------------------------------------------------- + +// DummyMessageInvalidAsOptionType + +// ------------------------------------------------------------------- + +// CustomOptionMinIntegerValues + +// ------------------------------------------------------------------- + +// CustomOptionMaxIntegerValues + +// ------------------------------------------------------------------- + +// CustomOptionOtherValues + +// ------------------------------------------------------------------- + +// SettingRealsFromPositiveInts + +// ------------------------------------------------------------------- + +// SettingRealsFromNegativeInts + +// ------------------------------------------------------------------- + +// ComplexOptionType1 + +// optional int32 foo = 1; +inline bool ComplexOptionType1::has_foo() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ComplexOptionType1::set_has_foo() { + _has_bits_[0] |= 0x00000001u; +} +inline void ComplexOptionType1::clear_has_foo() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ComplexOptionType1::clear_foo() { + foo_ = 0; + clear_has_foo(); +} +inline ::google::protobuf::int32 ComplexOptionType1::foo() const { + return foo_; +} +inline void ComplexOptionType1::set_foo(::google::protobuf::int32 value) { + set_has_foo(); + foo_ = value; +} + +// optional int32 foo2 = 2; +inline bool ComplexOptionType1::has_foo2() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void ComplexOptionType1::set_has_foo2() { + _has_bits_[0] |= 0x00000002u; +} +inline void ComplexOptionType1::clear_has_foo2() { + _has_bits_[0] &= ~0x00000002u; +} +inline void ComplexOptionType1::clear_foo2() { + foo2_ = 0; + clear_has_foo2(); +} +inline ::google::protobuf::int32 ComplexOptionType1::foo2() const { + return foo2_; +} +inline void ComplexOptionType1::set_foo2(::google::protobuf::int32 value) { + set_has_foo2(); + foo2_ = value; +} + +// optional int32 foo3 = 3; +inline bool ComplexOptionType1::has_foo3() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void ComplexOptionType1::set_has_foo3() { + _has_bits_[0] |= 0x00000004u; +} +inline void ComplexOptionType1::clear_has_foo3() { + _has_bits_[0] &= ~0x00000004u; +} +inline void ComplexOptionType1::clear_foo3() { + foo3_ = 0; + clear_has_foo3(); +} +inline ::google::protobuf::int32 ComplexOptionType1::foo3() const { + return foo3_; +} +inline void ComplexOptionType1::set_foo3(::google::protobuf::int32 value) { + set_has_foo3(); + foo3_ = value; +} + +// ------------------------------------------------------------------- + +// ComplexOptionType2_ComplexOptionType4 + +// optional int32 waldo = 1; +inline bool ComplexOptionType2_ComplexOptionType4::has_waldo() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ComplexOptionType2_ComplexOptionType4::set_has_waldo() { + _has_bits_[0] |= 0x00000001u; +} +inline void ComplexOptionType2_ComplexOptionType4::clear_has_waldo() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ComplexOptionType2_ComplexOptionType4::clear_waldo() { + waldo_ = 0; + clear_has_waldo(); +} +inline ::google::protobuf::int32 ComplexOptionType2_ComplexOptionType4::waldo() const { + return waldo_; +} +inline void ComplexOptionType2_ComplexOptionType4::set_waldo(::google::protobuf::int32 value) { + set_has_waldo(); + waldo_ = value; +} + +// ------------------------------------------------------------------- + +// ComplexOptionType2 + +// optional .protobuf_unittest.ComplexOptionType1 bar = 1; +inline bool ComplexOptionType2::has_bar() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ComplexOptionType2::set_has_bar() { + _has_bits_[0] |= 0x00000001u; +} +inline void ComplexOptionType2::clear_has_bar() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ComplexOptionType2::clear_bar() { + if (bar_ != NULL) bar_->::protobuf_unittest::ComplexOptionType1::Clear(); + clear_has_bar(); +} +inline const ::protobuf_unittest::ComplexOptionType1& ComplexOptionType2::bar() const { + return bar_ != NULL ? *bar_ : *default_instance_->bar_; +} +inline ::protobuf_unittest::ComplexOptionType1* ComplexOptionType2::mutable_bar() { + set_has_bar(); + if (bar_ == NULL) bar_ = new ::protobuf_unittest::ComplexOptionType1; + return bar_; +} +inline ::protobuf_unittest::ComplexOptionType1* ComplexOptionType2::release_bar() { + clear_has_bar(); + ::protobuf_unittest::ComplexOptionType1* temp = bar_; + bar_ = NULL; + return temp; +} + +// optional int32 baz = 2; +inline bool ComplexOptionType2::has_baz() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void ComplexOptionType2::set_has_baz() { + _has_bits_[0] |= 0x00000002u; +} +inline void ComplexOptionType2::clear_has_baz() { + _has_bits_[0] &= ~0x00000002u; +} +inline void ComplexOptionType2::clear_baz() { + baz_ = 0; + clear_has_baz(); +} +inline ::google::protobuf::int32 ComplexOptionType2::baz() const { + return baz_; +} +inline void ComplexOptionType2::set_baz(::google::protobuf::int32 value) { + set_has_baz(); + baz_ = value; +} + +// optional .protobuf_unittest.ComplexOptionType2.ComplexOptionType4 fred = 3; +inline bool ComplexOptionType2::has_fred() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void ComplexOptionType2::set_has_fred() { + _has_bits_[0] |= 0x00000004u; +} +inline void ComplexOptionType2::clear_has_fred() { + _has_bits_[0] &= ~0x00000004u; +} +inline void ComplexOptionType2::clear_fred() { + if (fred_ != NULL) fred_->::protobuf_unittest::ComplexOptionType2_ComplexOptionType4::Clear(); + clear_has_fred(); +} +inline const ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4& ComplexOptionType2::fred() const { + return fred_ != NULL ? *fred_ : *default_instance_->fred_; +} +inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* ComplexOptionType2::mutable_fred() { + set_has_fred(); + if (fred_ == NULL) fred_ = new ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4; + return fred_; +} +inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* ComplexOptionType2::release_fred() { + clear_has_fred(); + ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* temp = fred_; + fred_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// ComplexOptionType3_ComplexOptionType5 + +// optional int32 plugh = 3; +inline bool ComplexOptionType3_ComplexOptionType5::has_plugh() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ComplexOptionType3_ComplexOptionType5::set_has_plugh() { + _has_bits_[0] |= 0x00000001u; +} +inline void ComplexOptionType3_ComplexOptionType5::clear_has_plugh() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ComplexOptionType3_ComplexOptionType5::clear_plugh() { + plugh_ = 0; + clear_has_plugh(); +} +inline ::google::protobuf::int32 ComplexOptionType3_ComplexOptionType5::plugh() const { + return plugh_; +} +inline void ComplexOptionType3_ComplexOptionType5::set_plugh(::google::protobuf::int32 value) { + set_has_plugh(); + plugh_ = value; +} + +// ------------------------------------------------------------------- + +// ComplexOptionType3 + +// optional int32 qux = 1; +inline bool ComplexOptionType3::has_qux() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ComplexOptionType3::set_has_qux() { + _has_bits_[0] |= 0x00000001u; +} +inline void ComplexOptionType3::clear_has_qux() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ComplexOptionType3::clear_qux() { + qux_ = 0; + clear_has_qux(); +} +inline ::google::protobuf::int32 ComplexOptionType3::qux() const { + return qux_; +} +inline void ComplexOptionType3::set_qux(::google::protobuf::int32 value) { + set_has_qux(); + qux_ = value; +} + +// optional group ComplexOptionType5 = 2 { +inline bool ComplexOptionType3::has_complexoptiontype5() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void ComplexOptionType3::set_has_complexoptiontype5() { + _has_bits_[0] |= 0x00000002u; +} +inline void ComplexOptionType3::clear_has_complexoptiontype5() { + _has_bits_[0] &= ~0x00000002u; +} +inline void ComplexOptionType3::clear_complexoptiontype5() { + if (complexoptiontype5_ != NULL) complexoptiontype5_->::protobuf_unittest::ComplexOptionType3_ComplexOptionType5::Clear(); + clear_has_complexoptiontype5(); +} +inline const ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5& ComplexOptionType3::complexoptiontype5() const { + return complexoptiontype5_ != NULL ? *complexoptiontype5_ : *default_instance_->complexoptiontype5_; +} +inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* ComplexOptionType3::mutable_complexoptiontype5() { + set_has_complexoptiontype5(); + if (complexoptiontype5_ == NULL) complexoptiontype5_ = new ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5; + return complexoptiontype5_; +} +inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* ComplexOptionType3::release_complexoptiontype5() { + clear_has_complexoptiontype5(); + ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* temp = complexoptiontype5_; + complexoptiontype5_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// ComplexOpt6 + +// optional int32 xyzzy = 7593951; +inline bool ComplexOpt6::has_xyzzy() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ComplexOpt6::set_has_xyzzy() { + _has_bits_[0] |= 0x00000001u; +} +inline void ComplexOpt6::clear_has_xyzzy() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ComplexOpt6::clear_xyzzy() { + xyzzy_ = 0; + clear_has_xyzzy(); +} +inline ::google::protobuf::int32 ComplexOpt6::xyzzy() const { + return xyzzy_; +} +inline void ComplexOpt6::set_xyzzy(::google::protobuf::int32 value) { + set_has_xyzzy(); + xyzzy_ = value; +} + +// ------------------------------------------------------------------- + +// VariousComplexOptions + +// ------------------------------------------------------------------- + +// AggregateMessageSet + +// ------------------------------------------------------------------- + +// AggregateMessageSetElement + +// optional string s = 1; +inline bool AggregateMessageSetElement::has_s() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void AggregateMessageSetElement::set_has_s() { + _has_bits_[0] |= 0x00000001u; +} +inline void AggregateMessageSetElement::clear_has_s() { + _has_bits_[0] &= ~0x00000001u; +} +inline void AggregateMessageSetElement::clear_s() { + if (s_ != &::google::protobuf::internal::kEmptyString) { + s_->clear(); + } + clear_has_s(); +} +inline const ::std::string& AggregateMessageSetElement::s() const { + return *s_; +} +inline void AggregateMessageSetElement::set_s(const ::std::string& value) { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + s_->assign(value); +} +inline void AggregateMessageSetElement::set_s(const char* value) { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + s_->assign(value); +} +inline void AggregateMessageSetElement::set_s(const char* value, size_t size) { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + s_->assign(reinterpret_cast(value), size); +} +inline ::std::string* AggregateMessageSetElement::mutable_s() { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + return s_; +} +inline ::std::string* AggregateMessageSetElement::release_s() { + clear_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = s_; + s_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// Aggregate + +// optional int32 i = 1; +inline bool Aggregate::has_i() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void Aggregate::set_has_i() { + _has_bits_[0] |= 0x00000001u; +} +inline void Aggregate::clear_has_i() { + _has_bits_[0] &= ~0x00000001u; +} +inline void Aggregate::clear_i() { + i_ = 0; + clear_has_i(); +} +inline ::google::protobuf::int32 Aggregate::i() const { + return i_; +} +inline void Aggregate::set_i(::google::protobuf::int32 value) { + set_has_i(); + i_ = value; +} + +// optional string s = 2; +inline bool Aggregate::has_s() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void Aggregate::set_has_s() { + _has_bits_[0] |= 0x00000002u; +} +inline void Aggregate::clear_has_s() { + _has_bits_[0] &= ~0x00000002u; +} +inline void Aggregate::clear_s() { + if (s_ != &::google::protobuf::internal::kEmptyString) { + s_->clear(); + } + clear_has_s(); +} +inline const ::std::string& Aggregate::s() const { + return *s_; +} +inline void Aggregate::set_s(const ::std::string& value) { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + s_->assign(value); +} +inline void Aggregate::set_s(const char* value) { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + s_->assign(value); +} +inline void Aggregate::set_s(const char* value, size_t size) { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + s_->assign(reinterpret_cast(value), size); +} +inline ::std::string* Aggregate::mutable_s() { + set_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + s_ = new ::std::string; + } + return s_; +} +inline ::std::string* Aggregate::release_s() { + clear_has_s(); + if (s_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = s_; + s_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional .protobuf_unittest.Aggregate sub = 3; +inline bool Aggregate::has_sub() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void Aggregate::set_has_sub() { + _has_bits_[0] |= 0x00000004u; +} +inline void Aggregate::clear_has_sub() { + _has_bits_[0] &= ~0x00000004u; +} +inline void Aggregate::clear_sub() { + if (sub_ != NULL) sub_->::protobuf_unittest::Aggregate::Clear(); + clear_has_sub(); +} +inline const ::protobuf_unittest::Aggregate& Aggregate::sub() const { + return sub_ != NULL ? *sub_ : *default_instance_->sub_; +} +inline ::protobuf_unittest::Aggregate* Aggregate::mutable_sub() { + set_has_sub(); + if (sub_ == NULL) sub_ = new ::protobuf_unittest::Aggregate; + return sub_; +} +inline ::protobuf_unittest::Aggregate* Aggregate::release_sub() { + clear_has_sub(); + ::protobuf_unittest::Aggregate* temp = sub_; + sub_ = NULL; + return temp; +} + +// optional .google.protobuf.FileOptions file = 4; +inline bool Aggregate::has_file() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void Aggregate::set_has_file() { + _has_bits_[0] |= 0x00000008u; +} +inline void Aggregate::clear_has_file() { + _has_bits_[0] &= ~0x00000008u; +} +inline void Aggregate::clear_file() { + if (file_ != NULL) file_->::google::protobuf::FileOptions::Clear(); + clear_has_file(); +} +inline const ::google::protobuf::FileOptions& Aggregate::file() const { + return file_ != NULL ? *file_ : *default_instance_->file_; +} +inline ::google::protobuf::FileOptions* Aggregate::mutable_file() { + set_has_file(); + if (file_ == NULL) file_ = new ::google::protobuf::FileOptions; + return file_; +} +inline ::google::protobuf::FileOptions* Aggregate::release_file() { + clear_has_file(); + ::google::protobuf::FileOptions* temp = file_; + file_ = NULL; + return temp; +} + +// optional .protobuf_unittest.AggregateMessageSet mset = 5; +inline bool Aggregate::has_mset() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void Aggregate::set_has_mset() { + _has_bits_[0] |= 0x00000010u; +} +inline void Aggregate::clear_has_mset() { + _has_bits_[0] &= ~0x00000010u; +} +inline void Aggregate::clear_mset() { + if (mset_ != NULL) mset_->::protobuf_unittest::AggregateMessageSet::Clear(); + clear_has_mset(); +} +inline const ::protobuf_unittest::AggregateMessageSet& Aggregate::mset() const { + return mset_ != NULL ? *mset_ : *default_instance_->mset_; +} +inline ::protobuf_unittest::AggregateMessageSet* Aggregate::mutable_mset() { + set_has_mset(); + if (mset_ == NULL) mset_ = new ::protobuf_unittest::AggregateMessageSet; + return mset_; +} +inline ::protobuf_unittest::AggregateMessageSet* Aggregate::release_mset() { + clear_has_mset(); + ::protobuf_unittest::AggregateMessageSet* temp = mset_; + mset_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// AggregateMessage + +// optional int32 fieldname = 1; +inline bool AggregateMessage::has_fieldname() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void AggregateMessage::set_has_fieldname() { + _has_bits_[0] |= 0x00000001u; +} +inline void AggregateMessage::clear_has_fieldname() { + _has_bits_[0] &= ~0x00000001u; +} +inline void AggregateMessage::clear_fieldname() { + fieldname_ = 0; + clear_has_fieldname(); +} +inline ::google::protobuf::int32 AggregateMessage::fieldname() const { + return fieldname_; +} +inline void AggregateMessage::set_fieldname(::google::protobuf::int32 value) { + set_has_fieldname(); + fieldname_ = value; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +#ifndef SWIG +namespace google { +namespace protobuf { + +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestMessageWithCustomOptions_AnEnum>() { + return ::protobuf_unittest::TestMessageWithCustomOptions_AnEnum_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType>() { + return ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::MethodOpt1>() { + return protobuf_unittest::MethodOpt1_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::AggregateEnum>() { + return protobuf_unittest::AggregateEnum_descriptor(); +} + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h new file mode 100644 index 00000000..3bf3b704 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h @@ -0,0 +1,211 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_embed_optimize_for.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +#include "google/protobuf/unittest_optimize_for.pb.h" +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); + +class TestEmbedOptimizedForSize; + +// =================================================================== + +class TestEmbedOptimizedForSize : public ::google::protobuf::Message { + public: + TestEmbedOptimizedForSize(); + virtual ~TestEmbedOptimizedForSize(); + + TestEmbedOptimizedForSize(const TestEmbedOptimizedForSize& from); + + inline TestEmbedOptimizedForSize& operator=(const TestEmbedOptimizedForSize& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestEmbedOptimizedForSize& default_instance(); + + void Swap(TestEmbedOptimizedForSize* other); + + // implements Message ---------------------------------------------- + + TestEmbedOptimizedForSize* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestEmbedOptimizedForSize& from); + void MergeFrom(const TestEmbedOptimizedForSize& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestOptimizedForSize optional_message = 1; + inline bool has_optional_message() const; + inline void clear_optional_message(); + static const int kOptionalMessageFieldNumber = 1; + inline const ::protobuf_unittest::TestOptimizedForSize& optional_message() const; + inline ::protobuf_unittest::TestOptimizedForSize* mutable_optional_message(); + inline ::protobuf_unittest::TestOptimizedForSize* release_optional_message(); + + // repeated .protobuf_unittest.TestOptimizedForSize repeated_message = 2; + inline int repeated_message_size() const; + inline void clear_repeated_message(); + static const int kRepeatedMessageFieldNumber = 2; + inline const ::protobuf_unittest::TestOptimizedForSize& repeated_message(int index) const; + inline ::protobuf_unittest::TestOptimizedForSize* mutable_repeated_message(int index); + inline ::protobuf_unittest::TestOptimizedForSize* add_repeated_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >& + repeated_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >* + mutable_repeated_message(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestEmbedOptimizedForSize) + private: + inline void set_has_optional_message(); + inline void clear_has_optional_message(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestOptimizedForSize* optional_message_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize > repeated_message_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); + + void InitAsDefaultInstance(); + static TestEmbedOptimizedForSize* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// TestEmbedOptimizedForSize + +// optional .protobuf_unittest.TestOptimizedForSize optional_message = 1; +inline bool TestEmbedOptimizedForSize::has_optional_message() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestEmbedOptimizedForSize::set_has_optional_message() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestEmbedOptimizedForSize::clear_has_optional_message() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestEmbedOptimizedForSize::clear_optional_message() { + if (optional_message_ != NULL) optional_message_->::protobuf_unittest::TestOptimizedForSize::Clear(); + clear_has_optional_message(); +} +inline const ::protobuf_unittest::TestOptimizedForSize& TestEmbedOptimizedForSize::optional_message() const { + return optional_message_ != NULL ? *optional_message_ : *default_instance_->optional_message_; +} +inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::mutable_optional_message() { + set_has_optional_message(); + if (optional_message_ == NULL) optional_message_ = new ::protobuf_unittest::TestOptimizedForSize; + return optional_message_; +} +inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::release_optional_message() { + clear_has_optional_message(); + ::protobuf_unittest::TestOptimizedForSize* temp = optional_message_; + optional_message_ = NULL; + return temp; +} + +// repeated .protobuf_unittest.TestOptimizedForSize repeated_message = 2; +inline int TestEmbedOptimizedForSize::repeated_message_size() const { + return repeated_message_.size(); +} +inline void TestEmbedOptimizedForSize::clear_repeated_message() { + repeated_message_.Clear(); +} +inline const ::protobuf_unittest::TestOptimizedForSize& TestEmbedOptimizedForSize::repeated_message(int index) const { + return repeated_message_.Get(index); +} +inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::mutable_repeated_message(int index) { + return repeated_message_.Mutable(index); +} +inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::add_repeated_message() { + return repeated_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >& +TestEmbedOptimizedForSize::repeated_message() const { + return repeated_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >* +TestEmbedOptimizedForSize::mutable_repeated_message() { + return &repeated_message_; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +#ifndef SWIG +namespace google { +namespace protobuf { + + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h new file mode 100644 index 00000000..f9a53872 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h @@ -0,0 +1,56 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_empty.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fempty_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5fempty_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5fempty_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fempty_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fempty_2eproto(); + + +// =================================================================== + + +// =================================================================== + + +// =================================================================== + + +// @@protoc_insertion_point(namespace_scope) + +#ifndef SWIG +namespace google { +namespace protobuf { + + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5fempty_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h new file mode 100644 index 00000000..401905d8 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h @@ -0,0 +1,188 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_import.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fimport_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5fimport_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest_import { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_2eproto(); + +class ImportMessage; + +enum ImportEnum { + IMPORT_FOO = 7, + IMPORT_BAR = 8, + IMPORT_BAZ = 9 +}; +bool ImportEnum_IsValid(int value); +const ImportEnum ImportEnum_MIN = IMPORT_FOO; +const ImportEnum ImportEnum_MAX = IMPORT_BAZ; +const int ImportEnum_ARRAYSIZE = ImportEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* ImportEnum_descriptor(); +inline const ::std::string& ImportEnum_Name(ImportEnum value) { + return ::google::protobuf::internal::NameOfEnum( + ImportEnum_descriptor(), value); +} +inline bool ImportEnum_Parse( + const ::std::string& name, ImportEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + ImportEnum_descriptor(), name, value); +} +// =================================================================== + +class ImportMessage : public ::google::protobuf::Message { + public: + ImportMessage(); + virtual ~ImportMessage(); + + ImportMessage(const ImportMessage& from); + + inline ImportMessage& operator=(const ImportMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ImportMessage& default_instance(); + + void Swap(ImportMessage* other); + + // implements Message ---------------------------------------------- + + ImportMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const ImportMessage& from); + void MergeFrom(const ImportMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 d = 1; + inline bool has_d() const; + inline void clear_d(); + static const int kDFieldNumber = 1; + inline ::google::protobuf::int32 d() const; + inline void set_d(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest_import.ImportMessage) + private: + inline void set_has_d(); + inline void clear_has_d(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 d_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_2eproto(); + + void InitAsDefaultInstance(); + static ImportMessage* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// ImportMessage + +// optional int32 d = 1; +inline bool ImportMessage::has_d() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ImportMessage::set_has_d() { + _has_bits_[0] |= 0x00000001u; +} +inline void ImportMessage::clear_has_d() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ImportMessage::clear_d() { + d_ = 0; + clear_has_d(); +} +inline ::google::protobuf::int32 ImportMessage::d() const { + return d_; +} +inline void ImportMessage::set_d(::google::protobuf::int32 value) { + set_has_d(); + d_ = value; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest_import + +#ifndef SWIG +namespace google { +namespace protobuf { + +template <> +inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest_import::ImportEnum>() { + return protobuf_unittest_import::ImportEnum_descriptor(); +} + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5fimport_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h new file mode 100644 index 00000000..a29b673b --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h @@ -0,0 +1,151 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_import_lite.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fimport_5flite_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5fimport_5flite_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest_import { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); + +class ImportMessageLite; + +enum ImportEnumLite { + IMPORT_LITE_FOO = 7, + IMPORT_LITE_BAR = 8, + IMPORT_LITE_BAZ = 9 +}; +bool ImportEnumLite_IsValid(int value); +const ImportEnumLite ImportEnumLite_MIN = IMPORT_LITE_FOO; +const ImportEnumLite ImportEnumLite_MAX = IMPORT_LITE_BAZ; +const int ImportEnumLite_ARRAYSIZE = ImportEnumLite_MAX + 1; + +// =================================================================== + +class ImportMessageLite : public ::google::protobuf::MessageLite { + public: + ImportMessageLite(); + virtual ~ImportMessageLite(); + + ImportMessageLite(const ImportMessageLite& from); + + inline ImportMessageLite& operator=(const ImportMessageLite& from) { + CopyFrom(from); + return *this; + } + + static const ImportMessageLite& default_instance(); + + void Swap(ImportMessageLite* other); + + // implements Message ---------------------------------------------- + + ImportMessageLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const ImportMessageLite& from); + void MergeFrom(const ImportMessageLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 d = 1; + inline bool has_d() const; + inline void clear_d(); + static const int kDFieldNumber = 1; + inline ::google::protobuf::int32 d() const; + inline void set_d(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest_import.ImportMessageLite) + private: + inline void set_has_d(); + inline void clear_has_d(); + + ::google::protobuf::int32 d_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); + + void InitAsDefaultInstance(); + static ImportMessageLite* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// ImportMessageLite + +// optional int32 d = 1; +inline bool ImportMessageLite::has_d() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ImportMessageLite::set_has_d() { + _has_bits_[0] |= 0x00000001u; +} +inline void ImportMessageLite::clear_has_d() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ImportMessageLite::clear_d() { + d_ = 0; + clear_has_d(); +} +inline ::google::protobuf::int32 ImportMessageLite::d() const { + return d_; +} +inline void ImportMessageLite::set_d(::google::protobuf::int32 value) { + set_has_d(); + d_ = value; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest_import + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5fimport_5flite_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h new file mode 100644 index 00000000..66c9fb41 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h @@ -0,0 +1,4752 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_lite.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5flite_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5flite_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include "google/protobuf/unittest_import_lite.pb.h" +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + +class TestAllTypesLite; +class TestAllTypesLite_NestedMessage; +class TestAllTypesLite_OptionalGroup; +class TestAllTypesLite_RepeatedGroup; +class ForeignMessageLite; +class TestPackedTypesLite; +class TestAllExtensionsLite; +class OptionalGroup_extension_lite; +class RepeatedGroup_extension_lite; +class TestPackedExtensionsLite; +class TestNestedExtensionLite; +class TestDeprecatedLite; + +enum TestAllTypesLite_NestedEnum { + TestAllTypesLite_NestedEnum_FOO = 1, + TestAllTypesLite_NestedEnum_BAR = 2, + TestAllTypesLite_NestedEnum_BAZ = 3 +}; +bool TestAllTypesLite_NestedEnum_IsValid(int value); +const TestAllTypesLite_NestedEnum TestAllTypesLite_NestedEnum_NestedEnum_MIN = TestAllTypesLite_NestedEnum_FOO; +const TestAllTypesLite_NestedEnum TestAllTypesLite_NestedEnum_NestedEnum_MAX = TestAllTypesLite_NestedEnum_BAZ; +const int TestAllTypesLite_NestedEnum_NestedEnum_ARRAYSIZE = TestAllTypesLite_NestedEnum_NestedEnum_MAX + 1; + +enum ForeignEnumLite { + FOREIGN_LITE_FOO = 4, + FOREIGN_LITE_BAR = 5, + FOREIGN_LITE_BAZ = 6 +}; +bool ForeignEnumLite_IsValid(int value); +const ForeignEnumLite ForeignEnumLite_MIN = FOREIGN_LITE_FOO; +const ForeignEnumLite ForeignEnumLite_MAX = FOREIGN_LITE_BAZ; +const int ForeignEnumLite_ARRAYSIZE = ForeignEnumLite_MAX + 1; + +// =================================================================== + +class TestAllTypesLite_NestedMessage : public ::google::protobuf::MessageLite { + public: + TestAllTypesLite_NestedMessage(); + virtual ~TestAllTypesLite_NestedMessage(); + + TestAllTypesLite_NestedMessage(const TestAllTypesLite_NestedMessage& from); + + inline TestAllTypesLite_NestedMessage& operator=(const TestAllTypesLite_NestedMessage& from) { + CopyFrom(from); + return *this; + } + + static const TestAllTypesLite_NestedMessage& default_instance(); + + void Swap(TestAllTypesLite_NestedMessage* other); + + // implements Message ---------------------------------------------- + + TestAllTypesLite_NestedMessage* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestAllTypesLite_NestedMessage& from); + void MergeFrom(const TestAllTypesLite_NestedMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 bb = 1; + inline bool has_bb() const; + inline void clear_bb(); + static const int kBbFieldNumber = 1; + inline ::google::protobuf::int32 bb() const; + inline void set_bb(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite.NestedMessage) + private: + inline void set_has_bb(); + inline void clear_has_bb(); + + ::google::protobuf::int32 bb_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypesLite_NestedMessage* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllTypesLite_OptionalGroup : public ::google::protobuf::MessageLite { + public: + TestAllTypesLite_OptionalGroup(); + virtual ~TestAllTypesLite_OptionalGroup(); + + TestAllTypesLite_OptionalGroup(const TestAllTypesLite_OptionalGroup& from); + + inline TestAllTypesLite_OptionalGroup& operator=(const TestAllTypesLite_OptionalGroup& from) { + CopyFrom(from); + return *this; + } + + static const TestAllTypesLite_OptionalGroup& default_instance(); + + void Swap(TestAllTypesLite_OptionalGroup* other); + + // implements Message ---------------------------------------------- + + TestAllTypesLite_OptionalGroup* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestAllTypesLite_OptionalGroup& from); + void MergeFrom(const TestAllTypesLite_OptionalGroup& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 17; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 17; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite.OptionalGroup) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypesLite_OptionalGroup* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllTypesLite_RepeatedGroup : public ::google::protobuf::MessageLite { + public: + TestAllTypesLite_RepeatedGroup(); + virtual ~TestAllTypesLite_RepeatedGroup(); + + TestAllTypesLite_RepeatedGroup(const TestAllTypesLite_RepeatedGroup& from); + + inline TestAllTypesLite_RepeatedGroup& operator=(const TestAllTypesLite_RepeatedGroup& from) { + CopyFrom(from); + return *this; + } + + static const TestAllTypesLite_RepeatedGroup& default_instance(); + + void Swap(TestAllTypesLite_RepeatedGroup* other); + + // implements Message ---------------------------------------------- + + TestAllTypesLite_RepeatedGroup* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestAllTypesLite_RepeatedGroup& from); + void MergeFrom(const TestAllTypesLite_RepeatedGroup& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 47; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 47; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite.RepeatedGroup) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypesLite_RepeatedGroup* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllTypesLite : public ::google::protobuf::MessageLite { + public: + TestAllTypesLite(); + virtual ~TestAllTypesLite(); + + TestAllTypesLite(const TestAllTypesLite& from); + + inline TestAllTypesLite& operator=(const TestAllTypesLite& from) { + CopyFrom(from); + return *this; + } + + static const TestAllTypesLite& default_instance(); + + void Swap(TestAllTypesLite* other); + + // implements Message ---------------------------------------------- + + TestAllTypesLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestAllTypesLite& from); + void MergeFrom(const TestAllTypesLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + typedef TestAllTypesLite_NestedMessage NestedMessage; + typedef TestAllTypesLite_OptionalGroup OptionalGroup; + typedef TestAllTypesLite_RepeatedGroup RepeatedGroup; + + typedef TestAllTypesLite_NestedEnum NestedEnum; + static const NestedEnum FOO = TestAllTypesLite_NestedEnum_FOO; + static const NestedEnum BAR = TestAllTypesLite_NestedEnum_BAR; + static const NestedEnum BAZ = TestAllTypesLite_NestedEnum_BAZ; + static inline bool NestedEnum_IsValid(int value) { + return TestAllTypesLite_NestedEnum_IsValid(value); + } + static const NestedEnum NestedEnum_MIN = + TestAllTypesLite_NestedEnum_NestedEnum_MIN; + static const NestedEnum NestedEnum_MAX = + TestAllTypesLite_NestedEnum_NestedEnum_MAX; + static const int NestedEnum_ARRAYSIZE = + TestAllTypesLite_NestedEnum_NestedEnum_ARRAYSIZE; + + // accessors ------------------------------------------------------- + + // optional int32 optional_int32 = 1; + inline bool has_optional_int32() const; + inline void clear_optional_int32(); + static const int kOptionalInt32FieldNumber = 1; + inline ::google::protobuf::int32 optional_int32() const; + inline void set_optional_int32(::google::protobuf::int32 value); + + // optional int64 optional_int64 = 2; + inline bool has_optional_int64() const; + inline void clear_optional_int64(); + static const int kOptionalInt64FieldNumber = 2; + inline ::google::protobuf::int64 optional_int64() const; + inline void set_optional_int64(::google::protobuf::int64 value); + + // optional uint32 optional_uint32 = 3; + inline bool has_optional_uint32() const; + inline void clear_optional_uint32(); + static const int kOptionalUint32FieldNumber = 3; + inline ::google::protobuf::uint32 optional_uint32() const; + inline void set_optional_uint32(::google::protobuf::uint32 value); + + // optional uint64 optional_uint64 = 4; + inline bool has_optional_uint64() const; + inline void clear_optional_uint64(); + static const int kOptionalUint64FieldNumber = 4; + inline ::google::protobuf::uint64 optional_uint64() const; + inline void set_optional_uint64(::google::protobuf::uint64 value); + + // optional sint32 optional_sint32 = 5; + inline bool has_optional_sint32() const; + inline void clear_optional_sint32(); + static const int kOptionalSint32FieldNumber = 5; + inline ::google::protobuf::int32 optional_sint32() const; + inline void set_optional_sint32(::google::protobuf::int32 value); + + // optional sint64 optional_sint64 = 6; + inline bool has_optional_sint64() const; + inline void clear_optional_sint64(); + static const int kOptionalSint64FieldNumber = 6; + inline ::google::protobuf::int64 optional_sint64() const; + inline void set_optional_sint64(::google::protobuf::int64 value); + + // optional fixed32 optional_fixed32 = 7; + inline bool has_optional_fixed32() const; + inline void clear_optional_fixed32(); + static const int kOptionalFixed32FieldNumber = 7; + inline ::google::protobuf::uint32 optional_fixed32() const; + inline void set_optional_fixed32(::google::protobuf::uint32 value); + + // optional fixed64 optional_fixed64 = 8; + inline bool has_optional_fixed64() const; + inline void clear_optional_fixed64(); + static const int kOptionalFixed64FieldNumber = 8; + inline ::google::protobuf::uint64 optional_fixed64() const; + inline void set_optional_fixed64(::google::protobuf::uint64 value); + + // optional sfixed32 optional_sfixed32 = 9; + inline bool has_optional_sfixed32() const; + inline void clear_optional_sfixed32(); + static const int kOptionalSfixed32FieldNumber = 9; + inline ::google::protobuf::int32 optional_sfixed32() const; + inline void set_optional_sfixed32(::google::protobuf::int32 value); + + // optional sfixed64 optional_sfixed64 = 10; + inline bool has_optional_sfixed64() const; + inline void clear_optional_sfixed64(); + static const int kOptionalSfixed64FieldNumber = 10; + inline ::google::protobuf::int64 optional_sfixed64() const; + inline void set_optional_sfixed64(::google::protobuf::int64 value); + + // optional float optional_float = 11; + inline bool has_optional_float() const; + inline void clear_optional_float(); + static const int kOptionalFloatFieldNumber = 11; + inline float optional_float() const; + inline void set_optional_float(float value); + + // optional double optional_double = 12; + inline bool has_optional_double() const; + inline void clear_optional_double(); + static const int kOptionalDoubleFieldNumber = 12; + inline double optional_double() const; + inline void set_optional_double(double value); + + // optional bool optional_bool = 13; + inline bool has_optional_bool() const; + inline void clear_optional_bool(); + static const int kOptionalBoolFieldNumber = 13; + inline bool optional_bool() const; + inline void set_optional_bool(bool value); + + // optional string optional_string = 14; + inline bool has_optional_string() const; + inline void clear_optional_string(); + static const int kOptionalStringFieldNumber = 14; + inline const ::std::string& optional_string() const; + inline void set_optional_string(const ::std::string& value); + inline void set_optional_string(const char* value); + inline void set_optional_string(const char* value, size_t size); + inline ::std::string* mutable_optional_string(); + inline ::std::string* release_optional_string(); + + // optional bytes optional_bytes = 15; + inline bool has_optional_bytes() const; + inline void clear_optional_bytes(); + static const int kOptionalBytesFieldNumber = 15; + inline const ::std::string& optional_bytes() const; + inline void set_optional_bytes(const ::std::string& value); + inline void set_optional_bytes(const char* value); + inline void set_optional_bytes(const void* value, size_t size); + inline ::std::string* mutable_optional_bytes(); + inline ::std::string* release_optional_bytes(); + + // optional group OptionalGroup = 16 { + inline bool has_optionalgroup() const; + inline void clear_optionalgroup(); + static const int kOptionalgroupFieldNumber = 16; + inline const ::protobuf_unittest::TestAllTypesLite_OptionalGroup& optionalgroup() const; + inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* mutable_optionalgroup(); + inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* release_optionalgroup(); + + // optional .protobuf_unittest.TestAllTypesLite.NestedMessage optional_nested_message = 18; + inline bool has_optional_nested_message() const; + inline void clear_optional_nested_message(); + static const int kOptionalNestedMessageFieldNumber = 18; + inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& optional_nested_message() const; + inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* mutable_optional_nested_message(); + inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* release_optional_nested_message(); + + // optional .protobuf_unittest.ForeignMessageLite optional_foreign_message = 19; + inline bool has_optional_foreign_message() const; + inline void clear_optional_foreign_message(); + static const int kOptionalForeignMessageFieldNumber = 19; + inline const ::protobuf_unittest::ForeignMessageLite& optional_foreign_message() const; + inline ::protobuf_unittest::ForeignMessageLite* mutable_optional_foreign_message(); + inline ::protobuf_unittest::ForeignMessageLite* release_optional_foreign_message(); + + // optional .protobuf_unittest_import.ImportMessageLite optional_import_message = 20; + inline bool has_optional_import_message() const; + inline void clear_optional_import_message(); + static const int kOptionalImportMessageFieldNumber = 20; + inline const ::protobuf_unittest_import::ImportMessageLite& optional_import_message() const; + inline ::protobuf_unittest_import::ImportMessageLite* mutable_optional_import_message(); + inline ::protobuf_unittest_import::ImportMessageLite* release_optional_import_message(); + + // optional .protobuf_unittest.TestAllTypesLite.NestedEnum optional_nested_enum = 21; + inline bool has_optional_nested_enum() const; + inline void clear_optional_nested_enum(); + static const int kOptionalNestedEnumFieldNumber = 21; + inline ::protobuf_unittest::TestAllTypesLite_NestedEnum optional_nested_enum() const; + inline void set_optional_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value); + + // optional .protobuf_unittest.ForeignEnumLite optional_foreign_enum = 22; + inline bool has_optional_foreign_enum() const; + inline void clear_optional_foreign_enum(); + static const int kOptionalForeignEnumFieldNumber = 22; + inline protobuf_unittest::ForeignEnumLite optional_foreign_enum() const; + inline void set_optional_foreign_enum(protobuf_unittest::ForeignEnumLite value); + + // optional .protobuf_unittest_import.ImportEnumLite optional_import_enum = 23; + inline bool has_optional_import_enum() const; + inline void clear_optional_import_enum(); + static const int kOptionalImportEnumFieldNumber = 23; + inline protobuf_unittest_import::ImportEnumLite optional_import_enum() const; + inline void set_optional_import_enum(protobuf_unittest_import::ImportEnumLite value); + + // optional string optional_string_piece = 24 [ctype = STRING_PIECE]; + inline bool has_optional_string_piece() const; + inline void clear_optional_string_piece(); + static const int kOptionalStringPieceFieldNumber = 24; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& optional_string_piece() const; + inline void set_optional_string_piece(const ::std::string& value); + inline void set_optional_string_piece(const char* value); + inline void set_optional_string_piece(const char* value, size_t size); + inline ::std::string* mutable_optional_string_piece(); + inline ::std::string* release_optional_string_piece(); + public: + + // optional string optional_cord = 25 [ctype = CORD]; + inline bool has_optional_cord() const; + inline void clear_optional_cord(); + static const int kOptionalCordFieldNumber = 25; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& optional_cord() const; + inline void set_optional_cord(const ::std::string& value); + inline void set_optional_cord(const char* value); + inline void set_optional_cord(const char* value, size_t size); + inline ::std::string* mutable_optional_cord(); + inline ::std::string* release_optional_cord(); + public: + + // repeated int32 repeated_int32 = 31; + inline int repeated_int32_size() const; + inline void clear_repeated_int32(); + static const int kRepeatedInt32FieldNumber = 31; + inline ::google::protobuf::int32 repeated_int32(int index) const; + inline void set_repeated_int32(int index, ::google::protobuf::int32 value); + inline void add_repeated_int32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeated_int32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeated_int32(); + + // repeated int64 repeated_int64 = 32; + inline int repeated_int64_size() const; + inline void clear_repeated_int64(); + static const int kRepeatedInt64FieldNumber = 32; + inline ::google::protobuf::int64 repeated_int64(int index) const; + inline void set_repeated_int64(int index, ::google::protobuf::int64 value); + inline void add_repeated_int64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + repeated_int64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_repeated_int64(); + + // repeated uint32 repeated_uint32 = 33; + inline int repeated_uint32_size() const; + inline void clear_repeated_uint32(); + static const int kRepeatedUint32FieldNumber = 33; + inline ::google::protobuf::uint32 repeated_uint32(int index) const; + inline void set_repeated_uint32(int index, ::google::protobuf::uint32 value); + inline void add_repeated_uint32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + repeated_uint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_repeated_uint32(); + + // repeated uint64 repeated_uint64 = 34; + inline int repeated_uint64_size() const; + inline void clear_repeated_uint64(); + static const int kRepeatedUint64FieldNumber = 34; + inline ::google::protobuf::uint64 repeated_uint64(int index) const; + inline void set_repeated_uint64(int index, ::google::protobuf::uint64 value); + inline void add_repeated_uint64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + repeated_uint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_repeated_uint64(); + + // repeated sint32 repeated_sint32 = 35; + inline int repeated_sint32_size() const; + inline void clear_repeated_sint32(); + static const int kRepeatedSint32FieldNumber = 35; + inline ::google::protobuf::int32 repeated_sint32(int index) const; + inline void set_repeated_sint32(int index, ::google::protobuf::int32 value); + inline void add_repeated_sint32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeated_sint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeated_sint32(); + + // repeated sint64 repeated_sint64 = 36; + inline int repeated_sint64_size() const; + inline void clear_repeated_sint64(); + static const int kRepeatedSint64FieldNumber = 36; + inline ::google::protobuf::int64 repeated_sint64(int index) const; + inline void set_repeated_sint64(int index, ::google::protobuf::int64 value); + inline void add_repeated_sint64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + repeated_sint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_repeated_sint64(); + + // repeated fixed32 repeated_fixed32 = 37; + inline int repeated_fixed32_size() const; + inline void clear_repeated_fixed32(); + static const int kRepeatedFixed32FieldNumber = 37; + inline ::google::protobuf::uint32 repeated_fixed32(int index) const; + inline void set_repeated_fixed32(int index, ::google::protobuf::uint32 value); + inline void add_repeated_fixed32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + repeated_fixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_repeated_fixed32(); + + // repeated fixed64 repeated_fixed64 = 38; + inline int repeated_fixed64_size() const; + inline void clear_repeated_fixed64(); + static const int kRepeatedFixed64FieldNumber = 38; + inline ::google::protobuf::uint64 repeated_fixed64(int index) const; + inline void set_repeated_fixed64(int index, ::google::protobuf::uint64 value); + inline void add_repeated_fixed64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + repeated_fixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_repeated_fixed64(); + + // repeated sfixed32 repeated_sfixed32 = 39; + inline int repeated_sfixed32_size() const; + inline void clear_repeated_sfixed32(); + static const int kRepeatedSfixed32FieldNumber = 39; + inline ::google::protobuf::int32 repeated_sfixed32(int index) const; + inline void set_repeated_sfixed32(int index, ::google::protobuf::int32 value); + inline void add_repeated_sfixed32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + repeated_sfixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_repeated_sfixed32(); + + // repeated sfixed64 repeated_sfixed64 = 40; + inline int repeated_sfixed64_size() const; + inline void clear_repeated_sfixed64(); + static const int kRepeatedSfixed64FieldNumber = 40; + inline ::google::protobuf::int64 repeated_sfixed64(int index) const; + inline void set_repeated_sfixed64(int index, ::google::protobuf::int64 value); + inline void add_repeated_sfixed64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + repeated_sfixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_repeated_sfixed64(); + + // repeated float repeated_float = 41; + inline int repeated_float_size() const; + inline void clear_repeated_float(); + static const int kRepeatedFloatFieldNumber = 41; + inline float repeated_float(int index) const; + inline void set_repeated_float(int index, float value); + inline void add_repeated_float(float value); + inline const ::google::protobuf::RepeatedField< float >& + repeated_float() const; + inline ::google::protobuf::RepeatedField< float >* + mutable_repeated_float(); + + // repeated double repeated_double = 42; + inline int repeated_double_size() const; + inline void clear_repeated_double(); + static const int kRepeatedDoubleFieldNumber = 42; + inline double repeated_double(int index) const; + inline void set_repeated_double(int index, double value); + inline void add_repeated_double(double value); + inline const ::google::protobuf::RepeatedField< double >& + repeated_double() const; + inline ::google::protobuf::RepeatedField< double >* + mutable_repeated_double(); + + // repeated bool repeated_bool = 43; + inline int repeated_bool_size() const; + inline void clear_repeated_bool(); + static const int kRepeatedBoolFieldNumber = 43; + inline bool repeated_bool(int index) const; + inline void set_repeated_bool(int index, bool value); + inline void add_repeated_bool(bool value); + inline const ::google::protobuf::RepeatedField< bool >& + repeated_bool() const; + inline ::google::protobuf::RepeatedField< bool >* + mutable_repeated_bool(); + + // repeated string repeated_string = 44; + inline int repeated_string_size() const; + inline void clear_repeated_string(); + static const int kRepeatedStringFieldNumber = 44; + inline const ::std::string& repeated_string(int index) const; + inline ::std::string* mutable_repeated_string(int index); + inline void set_repeated_string(int index, const ::std::string& value); + inline void set_repeated_string(int index, const char* value); + inline void set_repeated_string(int index, const char* value, size_t size); + inline ::std::string* add_repeated_string(); + inline void add_repeated_string(const ::std::string& value); + inline void add_repeated_string(const char* value); + inline void add_repeated_string(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string(); + + // repeated bytes repeated_bytes = 45; + inline int repeated_bytes_size() const; + inline void clear_repeated_bytes(); + static const int kRepeatedBytesFieldNumber = 45; + inline const ::std::string& repeated_bytes(int index) const; + inline ::std::string* mutable_repeated_bytes(int index); + inline void set_repeated_bytes(int index, const ::std::string& value); + inline void set_repeated_bytes(int index, const char* value); + inline void set_repeated_bytes(int index, const void* value, size_t size); + inline ::std::string* add_repeated_bytes(); + inline void add_repeated_bytes(const ::std::string& value); + inline void add_repeated_bytes(const char* value); + inline void add_repeated_bytes(const void* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_bytes() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_bytes(); + + // repeated group RepeatedGroup = 46 { + inline int repeatedgroup_size() const; + inline void clear_repeatedgroup(); + static const int kRepeatedgroupFieldNumber = 46; + inline const ::protobuf_unittest::TestAllTypesLite_RepeatedGroup& repeatedgroup(int index) const; + inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* mutable_repeatedgroup(int index); + inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* add_repeatedgroup(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >& + repeatedgroup() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >* + mutable_repeatedgroup(); + + // repeated .protobuf_unittest.TestAllTypesLite.NestedMessage repeated_nested_message = 48; + inline int repeated_nested_message_size() const; + inline void clear_repeated_nested_message(); + static const int kRepeatedNestedMessageFieldNumber = 48; + inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& repeated_nested_message(int index) const; + inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* mutable_repeated_nested_message(int index); + inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* add_repeated_nested_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >& + repeated_nested_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >* + mutable_repeated_nested_message(); + + // repeated .protobuf_unittest.ForeignMessageLite repeated_foreign_message = 49; + inline int repeated_foreign_message_size() const; + inline void clear_repeated_foreign_message(); + static const int kRepeatedForeignMessageFieldNumber = 49; + inline const ::protobuf_unittest::ForeignMessageLite& repeated_foreign_message(int index) const; + inline ::protobuf_unittest::ForeignMessageLite* mutable_repeated_foreign_message(int index); + inline ::protobuf_unittest::ForeignMessageLite* add_repeated_foreign_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >& + repeated_foreign_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >* + mutable_repeated_foreign_message(); + + // repeated .protobuf_unittest_import.ImportMessageLite repeated_import_message = 50; + inline int repeated_import_message_size() const; + inline void clear_repeated_import_message(); + static const int kRepeatedImportMessageFieldNumber = 50; + inline const ::protobuf_unittest_import::ImportMessageLite& repeated_import_message(int index) const; + inline ::protobuf_unittest_import::ImportMessageLite* mutable_repeated_import_message(int index); + inline ::protobuf_unittest_import::ImportMessageLite* add_repeated_import_message(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >& + repeated_import_message() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >* + mutable_repeated_import_message(); + + // repeated .protobuf_unittest.TestAllTypesLite.NestedEnum repeated_nested_enum = 51; + inline int repeated_nested_enum_size() const; + inline void clear_repeated_nested_enum(); + static const int kRepeatedNestedEnumFieldNumber = 51; + inline ::protobuf_unittest::TestAllTypesLite_NestedEnum repeated_nested_enum(int index) const; + inline void set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypesLite_NestedEnum value); + inline void add_repeated_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value); + inline const ::google::protobuf::RepeatedField& repeated_nested_enum() const; + inline ::google::protobuf::RepeatedField* mutable_repeated_nested_enum(); + + // repeated .protobuf_unittest.ForeignEnumLite repeated_foreign_enum = 52; + inline int repeated_foreign_enum_size() const; + inline void clear_repeated_foreign_enum(); + static const int kRepeatedForeignEnumFieldNumber = 52; + inline protobuf_unittest::ForeignEnumLite repeated_foreign_enum(int index) const; + inline void set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnumLite value); + inline void add_repeated_foreign_enum(protobuf_unittest::ForeignEnumLite value); + inline const ::google::protobuf::RepeatedField& repeated_foreign_enum() const; + inline ::google::protobuf::RepeatedField* mutable_repeated_foreign_enum(); + + // repeated .protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53; + inline int repeated_import_enum_size() const; + inline void clear_repeated_import_enum(); + static const int kRepeatedImportEnumFieldNumber = 53; + inline protobuf_unittest_import::ImportEnumLite repeated_import_enum(int index) const; + inline void set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnumLite value); + inline void add_repeated_import_enum(protobuf_unittest_import::ImportEnumLite value); + inline const ::google::protobuf::RepeatedField& repeated_import_enum() const; + inline ::google::protobuf::RepeatedField* mutable_repeated_import_enum(); + + // repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; + inline int repeated_string_piece_size() const; + inline void clear_repeated_string_piece(); + static const int kRepeatedStringPieceFieldNumber = 54; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& repeated_string_piece(int index) const; + inline ::std::string* mutable_repeated_string_piece(int index); + inline void set_repeated_string_piece(int index, const ::std::string& value); + inline void set_repeated_string_piece(int index, const char* value); + inline void set_repeated_string_piece(int index, const char* value, size_t size); + inline ::std::string* add_repeated_string_piece(); + inline void add_repeated_string_piece(const ::std::string& value); + inline void add_repeated_string_piece(const char* value); + inline void add_repeated_string_piece(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string_piece() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string_piece(); + public: + + // repeated string repeated_cord = 55 [ctype = CORD]; + inline int repeated_cord_size() const; + inline void clear_repeated_cord(); + static const int kRepeatedCordFieldNumber = 55; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& repeated_cord(int index) const; + inline ::std::string* mutable_repeated_cord(int index); + inline void set_repeated_cord(int index, const ::std::string& value); + inline void set_repeated_cord(int index, const char* value); + inline void set_repeated_cord(int index, const char* value, size_t size); + inline ::std::string* add_repeated_cord(); + inline void add_repeated_cord(const ::std::string& value); + inline void add_repeated_cord(const char* value); + inline void add_repeated_cord(const char* value, size_t size); + inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_cord() const; + inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_cord(); + public: + + // optional int32 default_int32 = 61 [default = 41]; + inline bool has_default_int32() const; + inline void clear_default_int32(); + static const int kDefaultInt32FieldNumber = 61; + inline ::google::protobuf::int32 default_int32() const; + inline void set_default_int32(::google::protobuf::int32 value); + + // optional int64 default_int64 = 62 [default = 42]; + inline bool has_default_int64() const; + inline void clear_default_int64(); + static const int kDefaultInt64FieldNumber = 62; + inline ::google::protobuf::int64 default_int64() const; + inline void set_default_int64(::google::protobuf::int64 value); + + // optional uint32 default_uint32 = 63 [default = 43]; + inline bool has_default_uint32() const; + inline void clear_default_uint32(); + static const int kDefaultUint32FieldNumber = 63; + inline ::google::protobuf::uint32 default_uint32() const; + inline void set_default_uint32(::google::protobuf::uint32 value); + + // optional uint64 default_uint64 = 64 [default = 44]; + inline bool has_default_uint64() const; + inline void clear_default_uint64(); + static const int kDefaultUint64FieldNumber = 64; + inline ::google::protobuf::uint64 default_uint64() const; + inline void set_default_uint64(::google::protobuf::uint64 value); + + // optional sint32 default_sint32 = 65 [default = -45]; + inline bool has_default_sint32() const; + inline void clear_default_sint32(); + static const int kDefaultSint32FieldNumber = 65; + inline ::google::protobuf::int32 default_sint32() const; + inline void set_default_sint32(::google::protobuf::int32 value); + + // optional sint64 default_sint64 = 66 [default = 46]; + inline bool has_default_sint64() const; + inline void clear_default_sint64(); + static const int kDefaultSint64FieldNumber = 66; + inline ::google::protobuf::int64 default_sint64() const; + inline void set_default_sint64(::google::protobuf::int64 value); + + // optional fixed32 default_fixed32 = 67 [default = 47]; + inline bool has_default_fixed32() const; + inline void clear_default_fixed32(); + static const int kDefaultFixed32FieldNumber = 67; + inline ::google::protobuf::uint32 default_fixed32() const; + inline void set_default_fixed32(::google::protobuf::uint32 value); + + // optional fixed64 default_fixed64 = 68 [default = 48]; + inline bool has_default_fixed64() const; + inline void clear_default_fixed64(); + static const int kDefaultFixed64FieldNumber = 68; + inline ::google::protobuf::uint64 default_fixed64() const; + inline void set_default_fixed64(::google::protobuf::uint64 value); + + // optional sfixed32 default_sfixed32 = 69 [default = 49]; + inline bool has_default_sfixed32() const; + inline void clear_default_sfixed32(); + static const int kDefaultSfixed32FieldNumber = 69; + inline ::google::protobuf::int32 default_sfixed32() const; + inline void set_default_sfixed32(::google::protobuf::int32 value); + + // optional sfixed64 default_sfixed64 = 70 [default = -50]; + inline bool has_default_sfixed64() const; + inline void clear_default_sfixed64(); + static const int kDefaultSfixed64FieldNumber = 70; + inline ::google::protobuf::int64 default_sfixed64() const; + inline void set_default_sfixed64(::google::protobuf::int64 value); + + // optional float default_float = 71 [default = 51.5]; + inline bool has_default_float() const; + inline void clear_default_float(); + static const int kDefaultFloatFieldNumber = 71; + inline float default_float() const; + inline void set_default_float(float value); + + // optional double default_double = 72 [default = 52000]; + inline bool has_default_double() const; + inline void clear_default_double(); + static const int kDefaultDoubleFieldNumber = 72; + inline double default_double() const; + inline void set_default_double(double value); + + // optional bool default_bool = 73 [default = true]; + inline bool has_default_bool() const; + inline void clear_default_bool(); + static const int kDefaultBoolFieldNumber = 73; + inline bool default_bool() const; + inline void set_default_bool(bool value); + + // optional string default_string = 74 [default = "hello"]; + inline bool has_default_string() const; + inline void clear_default_string(); + static const int kDefaultStringFieldNumber = 74; + inline const ::std::string& default_string() const; + inline void set_default_string(const ::std::string& value); + inline void set_default_string(const char* value); + inline void set_default_string(const char* value, size_t size); + inline ::std::string* mutable_default_string(); + inline ::std::string* release_default_string(); + + // optional bytes default_bytes = 75 [default = "world"]; + inline bool has_default_bytes() const; + inline void clear_default_bytes(); + static const int kDefaultBytesFieldNumber = 75; + inline const ::std::string& default_bytes() const; + inline void set_default_bytes(const ::std::string& value); + inline void set_default_bytes(const char* value); + inline void set_default_bytes(const void* value, size_t size); + inline ::std::string* mutable_default_bytes(); + inline ::std::string* release_default_bytes(); + + // optional .protobuf_unittest.TestAllTypesLite.NestedEnum default_nested_enum = 81 [default = BAR]; + inline bool has_default_nested_enum() const; + inline void clear_default_nested_enum(); + static const int kDefaultNestedEnumFieldNumber = 81; + inline ::protobuf_unittest::TestAllTypesLite_NestedEnum default_nested_enum() const; + inline void set_default_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value); + + // optional .protobuf_unittest.ForeignEnumLite default_foreign_enum = 82 [default = FOREIGN_LITE_BAR]; + inline bool has_default_foreign_enum() const; + inline void clear_default_foreign_enum(); + static const int kDefaultForeignEnumFieldNumber = 82; + inline protobuf_unittest::ForeignEnumLite default_foreign_enum() const; + inline void set_default_foreign_enum(protobuf_unittest::ForeignEnumLite value); + + // optional .protobuf_unittest_import.ImportEnumLite default_import_enum = 83 [default = IMPORT_LITE_BAR]; + inline bool has_default_import_enum() const; + inline void clear_default_import_enum(); + static const int kDefaultImportEnumFieldNumber = 83; + inline protobuf_unittest_import::ImportEnumLite default_import_enum() const; + inline void set_default_import_enum(protobuf_unittest_import::ImportEnumLite value); + + // optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; + inline bool has_default_string_piece() const; + inline void clear_default_string_piece(); + static const int kDefaultStringPieceFieldNumber = 84; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& default_string_piece() const; + inline void set_default_string_piece(const ::std::string& value); + inline void set_default_string_piece(const char* value); + inline void set_default_string_piece(const char* value, size_t size); + inline ::std::string* mutable_default_string_piece(); + inline ::std::string* release_default_string_piece(); + public: + + // optional string default_cord = 85 [default = "123", ctype = CORD]; + inline bool has_default_cord() const; + inline void clear_default_cord(); + static const int kDefaultCordFieldNumber = 85; + private: + // Hidden due to unknown ctype option. + inline const ::std::string& default_cord() const; + inline void set_default_cord(const ::std::string& value); + inline void set_default_cord(const char* value); + inline void set_default_cord(const char* value, size_t size); + inline ::std::string* mutable_default_cord(); + inline ::std::string* release_default_cord(); + public: + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite) + private: + inline void set_has_optional_int32(); + inline void clear_has_optional_int32(); + inline void set_has_optional_int64(); + inline void clear_has_optional_int64(); + inline void set_has_optional_uint32(); + inline void clear_has_optional_uint32(); + inline void set_has_optional_uint64(); + inline void clear_has_optional_uint64(); + inline void set_has_optional_sint32(); + inline void clear_has_optional_sint32(); + inline void set_has_optional_sint64(); + inline void clear_has_optional_sint64(); + inline void set_has_optional_fixed32(); + inline void clear_has_optional_fixed32(); + inline void set_has_optional_fixed64(); + inline void clear_has_optional_fixed64(); + inline void set_has_optional_sfixed32(); + inline void clear_has_optional_sfixed32(); + inline void set_has_optional_sfixed64(); + inline void clear_has_optional_sfixed64(); + inline void set_has_optional_float(); + inline void clear_has_optional_float(); + inline void set_has_optional_double(); + inline void clear_has_optional_double(); + inline void set_has_optional_bool(); + inline void clear_has_optional_bool(); + inline void set_has_optional_string(); + inline void clear_has_optional_string(); + inline void set_has_optional_bytes(); + inline void clear_has_optional_bytes(); + inline void set_has_optionalgroup(); + inline void clear_has_optionalgroup(); + inline void set_has_optional_nested_message(); + inline void clear_has_optional_nested_message(); + inline void set_has_optional_foreign_message(); + inline void clear_has_optional_foreign_message(); + inline void set_has_optional_import_message(); + inline void clear_has_optional_import_message(); + inline void set_has_optional_nested_enum(); + inline void clear_has_optional_nested_enum(); + inline void set_has_optional_foreign_enum(); + inline void clear_has_optional_foreign_enum(); + inline void set_has_optional_import_enum(); + inline void clear_has_optional_import_enum(); + inline void set_has_optional_string_piece(); + inline void clear_has_optional_string_piece(); + inline void set_has_optional_cord(); + inline void clear_has_optional_cord(); + inline void set_has_default_int32(); + inline void clear_has_default_int32(); + inline void set_has_default_int64(); + inline void clear_has_default_int64(); + inline void set_has_default_uint32(); + inline void clear_has_default_uint32(); + inline void set_has_default_uint64(); + inline void clear_has_default_uint64(); + inline void set_has_default_sint32(); + inline void clear_has_default_sint32(); + inline void set_has_default_sint64(); + inline void clear_has_default_sint64(); + inline void set_has_default_fixed32(); + inline void clear_has_default_fixed32(); + inline void set_has_default_fixed64(); + inline void clear_has_default_fixed64(); + inline void set_has_default_sfixed32(); + inline void clear_has_default_sfixed32(); + inline void set_has_default_sfixed64(); + inline void clear_has_default_sfixed64(); + inline void set_has_default_float(); + inline void clear_has_default_float(); + inline void set_has_default_double(); + inline void clear_has_default_double(); + inline void set_has_default_bool(); + inline void clear_has_default_bool(); + inline void set_has_default_string(); + inline void clear_has_default_string(); + inline void set_has_default_bytes(); + inline void clear_has_default_bytes(); + inline void set_has_default_nested_enum(); + inline void clear_has_default_nested_enum(); + inline void set_has_default_foreign_enum(); + inline void clear_has_default_foreign_enum(); + inline void set_has_default_import_enum(); + inline void clear_has_default_import_enum(); + inline void set_has_default_string_piece(); + inline void clear_has_default_string_piece(); + inline void set_has_default_cord(); + inline void clear_has_default_cord(); + + ::google::protobuf::int32 optional_int32_; + ::google::protobuf::uint32 optional_uint32_; + ::google::protobuf::int64 optional_int64_; + ::google::protobuf::uint64 optional_uint64_; + ::google::protobuf::int32 optional_sint32_; + ::google::protobuf::uint32 optional_fixed32_; + ::google::protobuf::int64 optional_sint64_; + ::google::protobuf::uint64 optional_fixed64_; + ::google::protobuf::int32 optional_sfixed32_; + float optional_float_; + ::google::protobuf::int64 optional_sfixed64_; + double optional_double_; + ::std::string* optional_string_; + ::std::string* optional_bytes_; + ::protobuf_unittest::TestAllTypesLite_OptionalGroup* optionalgroup_; + ::protobuf_unittest::TestAllTypesLite_NestedMessage* optional_nested_message_; + ::protobuf_unittest::ForeignMessageLite* optional_foreign_message_; + ::protobuf_unittest_import::ImportMessageLite* optional_import_message_; + int optional_nested_enum_; + int optional_foreign_enum_; + ::std::string* optional_string_piece_; + ::std::string* optional_cord_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_int32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_int64_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_uint32_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_uint64_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sint32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sint64_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_fixed32_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_fixed64_; + int optional_import_enum_; + bool optional_bool_; + bool default_bool_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sfixed32_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sfixed64_; + ::google::protobuf::RepeatedField< float > repeated_float_; + ::google::protobuf::RepeatedField< double > repeated_double_; + ::google::protobuf::RepeatedField< bool > repeated_bool_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_bytes_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup > repeatedgroup_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage > repeated_nested_message_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite > repeated_foreign_message_; + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite > repeated_import_message_; + ::google::protobuf::RepeatedField repeated_nested_enum_; + ::google::protobuf::RepeatedField repeated_foreign_enum_; + ::google::protobuf::RepeatedField repeated_import_enum_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_piece_; + ::google::protobuf::RepeatedPtrField< ::std::string> repeated_cord_; + ::google::protobuf::int64 default_int64_; + ::google::protobuf::int32 default_int32_; + ::google::protobuf::uint32 default_uint32_; + ::google::protobuf::uint64 default_uint64_; + ::google::protobuf::int32 default_sint32_; + ::google::protobuf::uint32 default_fixed32_; + ::google::protobuf::int64 default_sint64_; + ::google::protobuf::uint64 default_fixed64_; + ::google::protobuf::int32 default_sfixed32_; + float default_float_; + ::google::protobuf::int64 default_sfixed64_; + double default_double_; + ::std::string* default_string_; + static const ::std::string _default_default_string_; + ::std::string* default_bytes_; + static const ::std::string _default_default_bytes_; + int default_nested_enum_; + int default_foreign_enum_; + ::std::string* default_string_piece_; + static const ::std::string _default_default_string_piece_; + ::std::string* default_cord_; + static const ::std::string _default_default_cord_; + int default_import_enum_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(68 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestAllTypesLite* default_instance_; +}; +// ------------------------------------------------------------------- + +class ForeignMessageLite : public ::google::protobuf::MessageLite { + public: + ForeignMessageLite(); + virtual ~ForeignMessageLite(); + + ForeignMessageLite(const ForeignMessageLite& from); + + inline ForeignMessageLite& operator=(const ForeignMessageLite& from) { + CopyFrom(from); + return *this; + } + + static const ForeignMessageLite& default_instance(); + + void Swap(ForeignMessageLite* other); + + // implements Message ---------------------------------------------- + + ForeignMessageLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const ForeignMessageLite& from); + void MergeFrom(const ForeignMessageLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 c = 1; + inline bool has_c() const; + inline void clear_c(); + static const int kCFieldNumber = 1; + inline ::google::protobuf::int32 c() const; + inline void set_c(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.ForeignMessageLite) + private: + inline void set_has_c(); + inline void clear_has_c(); + + ::google::protobuf::int32 c_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static ForeignMessageLite* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestPackedTypesLite : public ::google::protobuf::MessageLite { + public: + TestPackedTypesLite(); + virtual ~TestPackedTypesLite(); + + TestPackedTypesLite(const TestPackedTypesLite& from); + + inline TestPackedTypesLite& operator=(const TestPackedTypesLite& from) { + CopyFrom(from); + return *this; + } + + static const TestPackedTypesLite& default_instance(); + + void Swap(TestPackedTypesLite* other); + + // implements Message ---------------------------------------------- + + TestPackedTypesLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestPackedTypesLite& from); + void MergeFrom(const TestPackedTypesLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated int32 packed_int32 = 90 [packed = true]; + inline int packed_int32_size() const; + inline void clear_packed_int32(); + static const int kPackedInt32FieldNumber = 90; + inline ::google::protobuf::int32 packed_int32(int index) const; + inline void set_packed_int32(int index, ::google::protobuf::int32 value); + inline void add_packed_int32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + packed_int32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_packed_int32(); + + // repeated int64 packed_int64 = 91 [packed = true]; + inline int packed_int64_size() const; + inline void clear_packed_int64(); + static const int kPackedInt64FieldNumber = 91; + inline ::google::protobuf::int64 packed_int64(int index) const; + inline void set_packed_int64(int index, ::google::protobuf::int64 value); + inline void add_packed_int64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + packed_int64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_packed_int64(); + + // repeated uint32 packed_uint32 = 92 [packed = true]; + inline int packed_uint32_size() const; + inline void clear_packed_uint32(); + static const int kPackedUint32FieldNumber = 92; + inline ::google::protobuf::uint32 packed_uint32(int index) const; + inline void set_packed_uint32(int index, ::google::protobuf::uint32 value); + inline void add_packed_uint32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + packed_uint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_packed_uint32(); + + // repeated uint64 packed_uint64 = 93 [packed = true]; + inline int packed_uint64_size() const; + inline void clear_packed_uint64(); + static const int kPackedUint64FieldNumber = 93; + inline ::google::protobuf::uint64 packed_uint64(int index) const; + inline void set_packed_uint64(int index, ::google::protobuf::uint64 value); + inline void add_packed_uint64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + packed_uint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_packed_uint64(); + + // repeated sint32 packed_sint32 = 94 [packed = true]; + inline int packed_sint32_size() const; + inline void clear_packed_sint32(); + static const int kPackedSint32FieldNumber = 94; + inline ::google::protobuf::int32 packed_sint32(int index) const; + inline void set_packed_sint32(int index, ::google::protobuf::int32 value); + inline void add_packed_sint32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + packed_sint32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_packed_sint32(); + + // repeated sint64 packed_sint64 = 95 [packed = true]; + inline int packed_sint64_size() const; + inline void clear_packed_sint64(); + static const int kPackedSint64FieldNumber = 95; + inline ::google::protobuf::int64 packed_sint64(int index) const; + inline void set_packed_sint64(int index, ::google::protobuf::int64 value); + inline void add_packed_sint64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + packed_sint64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_packed_sint64(); + + // repeated fixed32 packed_fixed32 = 96 [packed = true]; + inline int packed_fixed32_size() const; + inline void clear_packed_fixed32(); + static const int kPackedFixed32FieldNumber = 96; + inline ::google::protobuf::uint32 packed_fixed32(int index) const; + inline void set_packed_fixed32(int index, ::google::protobuf::uint32 value); + inline void add_packed_fixed32(::google::protobuf::uint32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& + packed_fixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* + mutable_packed_fixed32(); + + // repeated fixed64 packed_fixed64 = 97 [packed = true]; + inline int packed_fixed64_size() const; + inline void clear_packed_fixed64(); + static const int kPackedFixed64FieldNumber = 97; + inline ::google::protobuf::uint64 packed_fixed64(int index) const; + inline void set_packed_fixed64(int index, ::google::protobuf::uint64 value); + inline void add_packed_fixed64(::google::protobuf::uint64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& + packed_fixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* + mutable_packed_fixed64(); + + // repeated sfixed32 packed_sfixed32 = 98 [packed = true]; + inline int packed_sfixed32_size() const; + inline void clear_packed_sfixed32(); + static const int kPackedSfixed32FieldNumber = 98; + inline ::google::protobuf::int32 packed_sfixed32(int index) const; + inline void set_packed_sfixed32(int index, ::google::protobuf::int32 value); + inline void add_packed_sfixed32(::google::protobuf::int32 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + packed_sfixed32() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_packed_sfixed32(); + + // repeated sfixed64 packed_sfixed64 = 99 [packed = true]; + inline int packed_sfixed64_size() const; + inline void clear_packed_sfixed64(); + static const int kPackedSfixed64FieldNumber = 99; + inline ::google::protobuf::int64 packed_sfixed64(int index) const; + inline void set_packed_sfixed64(int index, ::google::protobuf::int64 value); + inline void add_packed_sfixed64(::google::protobuf::int64 value); + inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& + packed_sfixed64() const; + inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* + mutable_packed_sfixed64(); + + // repeated float packed_float = 100 [packed = true]; + inline int packed_float_size() const; + inline void clear_packed_float(); + static const int kPackedFloatFieldNumber = 100; + inline float packed_float(int index) const; + inline void set_packed_float(int index, float value); + inline void add_packed_float(float value); + inline const ::google::protobuf::RepeatedField< float >& + packed_float() const; + inline ::google::protobuf::RepeatedField< float >* + mutable_packed_float(); + + // repeated double packed_double = 101 [packed = true]; + inline int packed_double_size() const; + inline void clear_packed_double(); + static const int kPackedDoubleFieldNumber = 101; + inline double packed_double(int index) const; + inline void set_packed_double(int index, double value); + inline void add_packed_double(double value); + inline const ::google::protobuf::RepeatedField< double >& + packed_double() const; + inline ::google::protobuf::RepeatedField< double >* + mutable_packed_double(); + + // repeated bool packed_bool = 102 [packed = true]; + inline int packed_bool_size() const; + inline void clear_packed_bool(); + static const int kPackedBoolFieldNumber = 102; + inline bool packed_bool(int index) const; + inline void set_packed_bool(int index, bool value); + inline void add_packed_bool(bool value); + inline const ::google::protobuf::RepeatedField< bool >& + packed_bool() const; + inline ::google::protobuf::RepeatedField< bool >* + mutable_packed_bool(); + + // repeated .protobuf_unittest.ForeignEnumLite packed_enum = 103 [packed = true]; + inline int packed_enum_size() const; + inline void clear_packed_enum(); + static const int kPackedEnumFieldNumber = 103; + inline protobuf_unittest::ForeignEnumLite packed_enum(int index) const; + inline void set_packed_enum(int index, protobuf_unittest::ForeignEnumLite value); + inline void add_packed_enum(protobuf_unittest::ForeignEnumLite value); + inline const ::google::protobuf::RepeatedField& packed_enum() const; + inline ::google::protobuf::RepeatedField* mutable_packed_enum(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedTypesLite) + private: + + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_int32_; + mutable int _packed_int32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_int64_; + mutable int _packed_int64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_uint32_; + mutable int _packed_uint32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_uint64_; + mutable int _packed_uint64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sint32_; + mutable int _packed_sint32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sint64_; + mutable int _packed_sint64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_fixed32_; + mutable int _packed_fixed32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_fixed64_; + mutable int _packed_fixed64_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sfixed32_; + mutable int _packed_sfixed32_cached_byte_size_; + ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sfixed64_; + mutable int _packed_sfixed64_cached_byte_size_; + ::google::protobuf::RepeatedField< float > packed_float_; + mutable int _packed_float_cached_byte_size_; + ::google::protobuf::RepeatedField< double > packed_double_; + mutable int _packed_double_cached_byte_size_; + ::google::protobuf::RepeatedField< bool > packed_bool_; + mutable int _packed_bool_cached_byte_size_; + ::google::protobuf::RepeatedField packed_enum_; + mutable int _packed_enum_cached_byte_size_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(14 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestPackedTypesLite* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestAllExtensionsLite : public ::google::protobuf::MessageLite { + public: + TestAllExtensionsLite(); + virtual ~TestAllExtensionsLite(); + + TestAllExtensionsLite(const TestAllExtensionsLite& from); + + inline TestAllExtensionsLite& operator=(const TestAllExtensionsLite& from) { + CopyFrom(from); + return *this; + } + + static const TestAllExtensionsLite& default_instance(); + + void Swap(TestAllExtensionsLite* other); + + // implements Message ---------------------------------------------- + + TestAllExtensionsLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestAllExtensionsLite& from); + void MergeFrom(const TestAllExtensionsLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestAllExtensionsLite) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllExtensionsLite) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestAllExtensionsLite* default_instance_; +}; +// ------------------------------------------------------------------- + +class OptionalGroup_extension_lite : public ::google::protobuf::MessageLite { + public: + OptionalGroup_extension_lite(); + virtual ~OptionalGroup_extension_lite(); + + OptionalGroup_extension_lite(const OptionalGroup_extension_lite& from); + + inline OptionalGroup_extension_lite& operator=(const OptionalGroup_extension_lite& from) { + CopyFrom(from); + return *this; + } + + static const OptionalGroup_extension_lite& default_instance(); + + void Swap(OptionalGroup_extension_lite* other); + + // implements Message ---------------------------------------------- + + OptionalGroup_extension_lite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const OptionalGroup_extension_lite& from); + void MergeFrom(const OptionalGroup_extension_lite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 17; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 17; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.OptionalGroup_extension_lite) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static OptionalGroup_extension_lite* default_instance_; +}; +// ------------------------------------------------------------------- + +class RepeatedGroup_extension_lite : public ::google::protobuf::MessageLite { + public: + RepeatedGroup_extension_lite(); + virtual ~RepeatedGroup_extension_lite(); + + RepeatedGroup_extension_lite(const RepeatedGroup_extension_lite& from); + + inline RepeatedGroup_extension_lite& operator=(const RepeatedGroup_extension_lite& from) { + CopyFrom(from); + return *this; + } + + static const RepeatedGroup_extension_lite& default_instance(); + + void Swap(RepeatedGroup_extension_lite* other); + + // implements Message ---------------------------------------------- + + RepeatedGroup_extension_lite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const RepeatedGroup_extension_lite& from); + void MergeFrom(const RepeatedGroup_extension_lite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 47; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 47; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.RepeatedGroup_extension_lite) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static RepeatedGroup_extension_lite* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestPackedExtensionsLite : public ::google::protobuf::MessageLite { + public: + TestPackedExtensionsLite(); + virtual ~TestPackedExtensionsLite(); + + TestPackedExtensionsLite(const TestPackedExtensionsLite& from); + + inline TestPackedExtensionsLite& operator=(const TestPackedExtensionsLite& from) { + CopyFrom(from); + return *this; + } + + static const TestPackedExtensionsLite& default_instance(); + + void Swap(TestPackedExtensionsLite* other); + + // implements Message ---------------------------------------------- + + TestPackedExtensionsLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestPackedExtensionsLite& from); + void MergeFrom(const TestPackedExtensionsLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestPackedExtensionsLite) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedExtensionsLite) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestPackedExtensionsLite* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestNestedExtensionLite : public ::google::protobuf::MessageLite { + public: + TestNestedExtensionLite(); + virtual ~TestNestedExtensionLite(); + + TestNestedExtensionLite(const TestNestedExtensionLite& from); + + inline TestNestedExtensionLite& operator=(const TestNestedExtensionLite& from) { + CopyFrom(from); + return *this; + } + + static const TestNestedExtensionLite& default_instance(); + + void Swap(TestNestedExtensionLite* other); + + // implements Message ---------------------------------------------- + + TestNestedExtensionLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestNestedExtensionLite& from); + void MergeFrom(const TestNestedExtensionLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + static const int kNestedExtensionFieldNumber = 12345; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + nested_extension; + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedExtensionLite) + private: + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestNestedExtensionLite* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestDeprecatedLite : public ::google::protobuf::MessageLite { + public: + TestDeprecatedLite(); + virtual ~TestDeprecatedLite(); + + TestDeprecatedLite(const TestDeprecatedLite& from); + + inline TestDeprecatedLite& operator=(const TestDeprecatedLite& from) { + CopyFrom(from); + return *this; + } + + static const TestDeprecatedLite& default_instance(); + + void Swap(TestDeprecatedLite* other); + + // implements Message ---------------------------------------------- + + TestDeprecatedLite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestDeprecatedLite& from); + void MergeFrom(const TestDeprecatedLite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 deprecated_field = 1 [deprecated = true]; + inline bool has_deprecated_field() const PROTOBUF_DEPRECATED; + inline void clear_deprecated_field() PROTOBUF_DEPRECATED; + static const int kDeprecatedFieldFieldNumber = 1; + inline ::google::protobuf::int32 deprecated_field() const PROTOBUF_DEPRECATED; + inline void set_deprecated_field(::google::protobuf::int32 value) PROTOBUF_DEPRECATED; + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDeprecatedLite) + private: + inline void set_has_deprecated_field(); + inline void clear_has_deprecated_field(); + + ::google::protobuf::int32 deprecated_field_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); + + void InitAsDefaultInstance(); + static TestDeprecatedLite* default_instance_; +}; +// =================================================================== + +static const int kOptionalInt32ExtensionLiteFieldNumber = 1; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + optional_int32_extension_lite; +static const int kOptionalInt64ExtensionLiteFieldNumber = 2; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > + optional_int64_extension_lite; +static const int kOptionalUint32ExtensionLiteFieldNumber = 3; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > + optional_uint32_extension_lite; +static const int kOptionalUint64ExtensionLiteFieldNumber = 4; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + optional_uint64_extension_lite; +static const int kOptionalSint32ExtensionLiteFieldNumber = 5; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > + optional_sint32_extension_lite; +static const int kOptionalSint64ExtensionLiteFieldNumber = 6; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + optional_sint64_extension_lite; +static const int kOptionalFixed32ExtensionLiteFieldNumber = 7; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > + optional_fixed32_extension_lite; +static const int kOptionalFixed64ExtensionLiteFieldNumber = 8; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + optional_fixed64_extension_lite; +static const int kOptionalSfixed32ExtensionLiteFieldNumber = 9; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + optional_sfixed32_extension_lite; +static const int kOptionalSfixed64ExtensionLiteFieldNumber = 10; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > + optional_sfixed64_extension_lite; +static const int kOptionalFloatExtensionLiteFieldNumber = 11; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > + optional_float_extension_lite; +static const int kOptionalDoubleExtensionLiteFieldNumber = 12; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > + optional_double_extension_lite; +static const int kOptionalBoolExtensionLiteFieldNumber = 13; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > + optional_bool_extension_lite; +static const int kOptionalStringExtensionLiteFieldNumber = 14; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 9, false > + optional_string_extension_lite; +static const int kOptionalBytesExtensionLiteFieldNumber = 15; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 12, false > + optional_bytes_extension_lite; +static const int kOptionalgroupExtensionLiteFieldNumber = 16; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::OptionalGroup_extension_lite >, 10, false > + optionalgroup_extension_lite; +static const int kOptionalNestedMessageExtensionLiteFieldNumber = 18; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedMessage >, 11, false > + optional_nested_message_extension_lite; +static const int kOptionalForeignMessageExtensionLiteFieldNumber = 19; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ForeignMessageLite >, 11, false > + optional_foreign_message_extension_lite; +static const int kOptionalImportMessageExtensionLiteFieldNumber = 20; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest_import::ImportMessageLite >, 11, false > + optional_import_message_extension_lite; +static const int kOptionalNestedEnumExtensionLiteFieldNumber = 21; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedEnum, ::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid>, 14, false > + optional_nested_enum_extension_lite; +static const int kOptionalForeignEnumExtensionLiteFieldNumber = 22; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, false > + optional_foreign_enum_extension_lite; +static const int kOptionalImportEnumExtensionLiteFieldNumber = 23; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnumLite, protobuf_unittest_import::ImportEnumLite_IsValid>, 14, false > + optional_import_enum_extension_lite; +static const int kOptionalStringPieceExtensionLiteFieldNumber = 24; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 9, false > + optional_string_piece_extension_lite; +static const int kOptionalCordExtensionLiteFieldNumber = 25; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 9, false > + optional_cord_extension_lite; +static const int kRepeatedInt32ExtensionLiteFieldNumber = 31; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + repeated_int32_extension_lite; +static const int kRepeatedInt64ExtensionLiteFieldNumber = 32; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > + repeated_int64_extension_lite; +static const int kRepeatedUint32ExtensionLiteFieldNumber = 33; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > + repeated_uint32_extension_lite; +static const int kRepeatedUint64ExtensionLiteFieldNumber = 34; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + repeated_uint64_extension_lite; +static const int kRepeatedSint32ExtensionLiteFieldNumber = 35; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > + repeated_sint32_extension_lite; +static const int kRepeatedSint64ExtensionLiteFieldNumber = 36; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + repeated_sint64_extension_lite; +static const int kRepeatedFixed32ExtensionLiteFieldNumber = 37; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > + repeated_fixed32_extension_lite; +static const int kRepeatedFixed64ExtensionLiteFieldNumber = 38; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + repeated_fixed64_extension_lite; +static const int kRepeatedSfixed32ExtensionLiteFieldNumber = 39; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + repeated_sfixed32_extension_lite; +static const int kRepeatedSfixed64ExtensionLiteFieldNumber = 40; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > + repeated_sfixed64_extension_lite; +static const int kRepeatedFloatExtensionLiteFieldNumber = 41; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, false > + repeated_float_extension_lite; +static const int kRepeatedDoubleExtensionLiteFieldNumber = 42; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, false > + repeated_double_extension_lite; +static const int kRepeatedBoolExtensionLiteFieldNumber = 43; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, false > + repeated_bool_extension_lite; +static const int kRepeatedStringExtensionLiteFieldNumber = 44; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > + repeated_string_extension_lite; +static const int kRepeatedBytesExtensionLiteFieldNumber = 45; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedStringTypeTraits, 12, false > + repeated_bytes_extension_lite; +static const int kRepeatedgroupExtensionLiteFieldNumber = 46; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::RepeatedGroup_extension_lite >, 10, false > + repeatedgroup_extension_lite; +static const int kRepeatedNestedMessageExtensionLiteFieldNumber = 48; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedMessage >, 11, false > + repeated_nested_message_extension_lite; +static const int kRepeatedForeignMessageExtensionLiteFieldNumber = 49; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::ForeignMessageLite >, 11, false > + repeated_foreign_message_extension_lite; +static const int kRepeatedImportMessageExtensionLiteFieldNumber = 50; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest_import::ImportMessageLite >, 11, false > + repeated_import_message_extension_lite; +static const int kRepeatedNestedEnumExtensionLiteFieldNumber = 51; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedEnumTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedEnum, ::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid>, 14, false > + repeated_nested_enum_extension_lite; +static const int kRepeatedForeignEnumExtensionLiteFieldNumber = 52; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, false > + repeated_foreign_enum_extension_lite; +static const int kRepeatedImportEnumExtensionLiteFieldNumber = 53; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest_import::ImportEnumLite, protobuf_unittest_import::ImportEnumLite_IsValid>, 14, false > + repeated_import_enum_extension_lite; +static const int kRepeatedStringPieceExtensionLiteFieldNumber = 54; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > + repeated_string_piece_extension_lite; +static const int kRepeatedCordExtensionLiteFieldNumber = 55; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > + repeated_cord_extension_lite; +static const int kDefaultInt32ExtensionLiteFieldNumber = 61; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + default_int32_extension_lite; +static const int kDefaultInt64ExtensionLiteFieldNumber = 62; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > + default_int64_extension_lite; +static const int kDefaultUint32ExtensionLiteFieldNumber = 63; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > + default_uint32_extension_lite; +static const int kDefaultUint64ExtensionLiteFieldNumber = 64; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > + default_uint64_extension_lite; +static const int kDefaultSint32ExtensionLiteFieldNumber = 65; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > + default_sint32_extension_lite; +static const int kDefaultSint64ExtensionLiteFieldNumber = 66; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > + default_sint64_extension_lite; +static const int kDefaultFixed32ExtensionLiteFieldNumber = 67; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > + default_fixed32_extension_lite; +static const int kDefaultFixed64ExtensionLiteFieldNumber = 68; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > + default_fixed64_extension_lite; +static const int kDefaultSfixed32ExtensionLiteFieldNumber = 69; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > + default_sfixed32_extension_lite; +static const int kDefaultSfixed64ExtensionLiteFieldNumber = 70; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > + default_sfixed64_extension_lite; +static const int kDefaultFloatExtensionLiteFieldNumber = 71; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > + default_float_extension_lite; +static const int kDefaultDoubleExtensionLiteFieldNumber = 72; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > + default_double_extension_lite; +static const int kDefaultBoolExtensionLiteFieldNumber = 73; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > + default_bool_extension_lite; +static const int kDefaultStringExtensionLiteFieldNumber = 74; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 9, false > + default_string_extension_lite; +static const int kDefaultBytesExtensionLiteFieldNumber = 75; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 12, false > + default_bytes_extension_lite; +static const int kDefaultNestedEnumExtensionLiteFieldNumber = 81; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedEnum, ::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid>, 14, false > + default_nested_enum_extension_lite; +static const int kDefaultForeignEnumExtensionLiteFieldNumber = 82; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, false > + default_foreign_enum_extension_lite; +static const int kDefaultImportEnumExtensionLiteFieldNumber = 83; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnumLite, protobuf_unittest_import::ImportEnumLite_IsValid>, 14, false > + default_import_enum_extension_lite; +static const int kDefaultStringPieceExtensionLiteFieldNumber = 84; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 9, false > + default_string_piece_extension_lite; +static const int kDefaultCordExtensionLiteFieldNumber = 85; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, + ::google::protobuf::internal::StringTypeTraits, 9, false > + default_cord_extension_lite; +static const int kPackedInt32ExtensionLiteFieldNumber = 90; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, true > + packed_int32_extension_lite; +static const int kPackedInt64ExtensionLiteFieldNumber = 91; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, true > + packed_int64_extension_lite; +static const int kPackedUint32ExtensionLiteFieldNumber = 92; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, true > + packed_uint32_extension_lite; +static const int kPackedUint64ExtensionLiteFieldNumber = 93; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, true > + packed_uint64_extension_lite; +static const int kPackedSint32ExtensionLiteFieldNumber = 94; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, true > + packed_sint32_extension_lite; +static const int kPackedSint64ExtensionLiteFieldNumber = 95; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, true > + packed_sint64_extension_lite; +static const int kPackedFixed32ExtensionLiteFieldNumber = 96; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, true > + packed_fixed32_extension_lite; +static const int kPackedFixed64ExtensionLiteFieldNumber = 97; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, true > + packed_fixed64_extension_lite; +static const int kPackedSfixed32ExtensionLiteFieldNumber = 98; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, true > + packed_sfixed32_extension_lite; +static const int kPackedSfixed64ExtensionLiteFieldNumber = 99; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, true > + packed_sfixed64_extension_lite; +static const int kPackedFloatExtensionLiteFieldNumber = 100; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, true > + packed_float_extension_lite; +static const int kPackedDoubleExtensionLiteFieldNumber = 101; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, true > + packed_double_extension_lite; +static const int kPackedBoolExtensionLiteFieldNumber = 102; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, true > + packed_bool_extension_lite; +static const int kPackedEnumExtensionLiteFieldNumber = 103; +extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, + ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, true > + packed_enum_extension_lite; + +// =================================================================== + +// TestAllTypesLite_NestedMessage + +// optional int32 bb = 1; +inline bool TestAllTypesLite_NestedMessage::has_bb() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypesLite_NestedMessage::set_has_bb() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypesLite_NestedMessage::clear_has_bb() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypesLite_NestedMessage::clear_bb() { + bb_ = 0; + clear_has_bb(); +} +inline ::google::protobuf::int32 TestAllTypesLite_NestedMessage::bb() const { + return bb_; +} +inline void TestAllTypesLite_NestedMessage::set_bb(::google::protobuf::int32 value) { + set_has_bb(); + bb_ = value; +} + +// ------------------------------------------------------------------- + +// TestAllTypesLite_OptionalGroup + +// optional int32 a = 17; +inline bool TestAllTypesLite_OptionalGroup::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypesLite_OptionalGroup::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypesLite_OptionalGroup::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypesLite_OptionalGroup::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestAllTypesLite_OptionalGroup::a() const { + return a_; +} +inline void TestAllTypesLite_OptionalGroup::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestAllTypesLite_RepeatedGroup + +// optional int32 a = 47; +inline bool TestAllTypesLite_RepeatedGroup::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypesLite_RepeatedGroup::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypesLite_RepeatedGroup::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypesLite_RepeatedGroup::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestAllTypesLite_RepeatedGroup::a() const { + return a_; +} +inline void TestAllTypesLite_RepeatedGroup::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestAllTypesLite + +// optional int32 optional_int32 = 1; +inline bool TestAllTypesLite::has_optional_int32() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestAllTypesLite::set_has_optional_int32() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestAllTypesLite::clear_has_optional_int32() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestAllTypesLite::clear_optional_int32() { + optional_int32_ = 0; + clear_has_optional_int32(); +} +inline ::google::protobuf::int32 TestAllTypesLite::optional_int32() const { + return optional_int32_; +} +inline void TestAllTypesLite::set_optional_int32(::google::protobuf::int32 value) { + set_has_optional_int32(); + optional_int32_ = value; +} + +// optional int64 optional_int64 = 2; +inline bool TestAllTypesLite::has_optional_int64() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestAllTypesLite::set_has_optional_int64() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestAllTypesLite::clear_has_optional_int64() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestAllTypesLite::clear_optional_int64() { + optional_int64_ = GOOGLE_LONGLONG(0); + clear_has_optional_int64(); +} +inline ::google::protobuf::int64 TestAllTypesLite::optional_int64() const { + return optional_int64_; +} +inline void TestAllTypesLite::set_optional_int64(::google::protobuf::int64 value) { + set_has_optional_int64(); + optional_int64_ = value; +} + +// optional uint32 optional_uint32 = 3; +inline bool TestAllTypesLite::has_optional_uint32() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void TestAllTypesLite::set_has_optional_uint32() { + _has_bits_[0] |= 0x00000004u; +} +inline void TestAllTypesLite::clear_has_optional_uint32() { + _has_bits_[0] &= ~0x00000004u; +} +inline void TestAllTypesLite::clear_optional_uint32() { + optional_uint32_ = 0u; + clear_has_optional_uint32(); +} +inline ::google::protobuf::uint32 TestAllTypesLite::optional_uint32() const { + return optional_uint32_; +} +inline void TestAllTypesLite::set_optional_uint32(::google::protobuf::uint32 value) { + set_has_optional_uint32(); + optional_uint32_ = value; +} + +// optional uint64 optional_uint64 = 4; +inline bool TestAllTypesLite::has_optional_uint64() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void TestAllTypesLite::set_has_optional_uint64() { + _has_bits_[0] |= 0x00000008u; +} +inline void TestAllTypesLite::clear_has_optional_uint64() { + _has_bits_[0] &= ~0x00000008u; +} +inline void TestAllTypesLite::clear_optional_uint64() { + optional_uint64_ = GOOGLE_ULONGLONG(0); + clear_has_optional_uint64(); +} +inline ::google::protobuf::uint64 TestAllTypesLite::optional_uint64() const { + return optional_uint64_; +} +inline void TestAllTypesLite::set_optional_uint64(::google::protobuf::uint64 value) { + set_has_optional_uint64(); + optional_uint64_ = value; +} + +// optional sint32 optional_sint32 = 5; +inline bool TestAllTypesLite::has_optional_sint32() const { + return (_has_bits_[0] & 0x00000010u) != 0; +} +inline void TestAllTypesLite::set_has_optional_sint32() { + _has_bits_[0] |= 0x00000010u; +} +inline void TestAllTypesLite::clear_has_optional_sint32() { + _has_bits_[0] &= ~0x00000010u; +} +inline void TestAllTypesLite::clear_optional_sint32() { + optional_sint32_ = 0; + clear_has_optional_sint32(); +} +inline ::google::protobuf::int32 TestAllTypesLite::optional_sint32() const { + return optional_sint32_; +} +inline void TestAllTypesLite::set_optional_sint32(::google::protobuf::int32 value) { + set_has_optional_sint32(); + optional_sint32_ = value; +} + +// optional sint64 optional_sint64 = 6; +inline bool TestAllTypesLite::has_optional_sint64() const { + return (_has_bits_[0] & 0x00000020u) != 0; +} +inline void TestAllTypesLite::set_has_optional_sint64() { + _has_bits_[0] |= 0x00000020u; +} +inline void TestAllTypesLite::clear_has_optional_sint64() { + _has_bits_[0] &= ~0x00000020u; +} +inline void TestAllTypesLite::clear_optional_sint64() { + optional_sint64_ = GOOGLE_LONGLONG(0); + clear_has_optional_sint64(); +} +inline ::google::protobuf::int64 TestAllTypesLite::optional_sint64() const { + return optional_sint64_; +} +inline void TestAllTypesLite::set_optional_sint64(::google::protobuf::int64 value) { + set_has_optional_sint64(); + optional_sint64_ = value; +} + +// optional fixed32 optional_fixed32 = 7; +inline bool TestAllTypesLite::has_optional_fixed32() const { + return (_has_bits_[0] & 0x00000040u) != 0; +} +inline void TestAllTypesLite::set_has_optional_fixed32() { + _has_bits_[0] |= 0x00000040u; +} +inline void TestAllTypesLite::clear_has_optional_fixed32() { + _has_bits_[0] &= ~0x00000040u; +} +inline void TestAllTypesLite::clear_optional_fixed32() { + optional_fixed32_ = 0u; + clear_has_optional_fixed32(); +} +inline ::google::protobuf::uint32 TestAllTypesLite::optional_fixed32() const { + return optional_fixed32_; +} +inline void TestAllTypesLite::set_optional_fixed32(::google::protobuf::uint32 value) { + set_has_optional_fixed32(); + optional_fixed32_ = value; +} + +// optional fixed64 optional_fixed64 = 8; +inline bool TestAllTypesLite::has_optional_fixed64() const { + return (_has_bits_[0] & 0x00000080u) != 0; +} +inline void TestAllTypesLite::set_has_optional_fixed64() { + _has_bits_[0] |= 0x00000080u; +} +inline void TestAllTypesLite::clear_has_optional_fixed64() { + _has_bits_[0] &= ~0x00000080u; +} +inline void TestAllTypesLite::clear_optional_fixed64() { + optional_fixed64_ = GOOGLE_ULONGLONG(0); + clear_has_optional_fixed64(); +} +inline ::google::protobuf::uint64 TestAllTypesLite::optional_fixed64() const { + return optional_fixed64_; +} +inline void TestAllTypesLite::set_optional_fixed64(::google::protobuf::uint64 value) { + set_has_optional_fixed64(); + optional_fixed64_ = value; +} + +// optional sfixed32 optional_sfixed32 = 9; +inline bool TestAllTypesLite::has_optional_sfixed32() const { + return (_has_bits_[0] & 0x00000100u) != 0; +} +inline void TestAllTypesLite::set_has_optional_sfixed32() { + _has_bits_[0] |= 0x00000100u; +} +inline void TestAllTypesLite::clear_has_optional_sfixed32() { + _has_bits_[0] &= ~0x00000100u; +} +inline void TestAllTypesLite::clear_optional_sfixed32() { + optional_sfixed32_ = 0; + clear_has_optional_sfixed32(); +} +inline ::google::protobuf::int32 TestAllTypesLite::optional_sfixed32() const { + return optional_sfixed32_; +} +inline void TestAllTypesLite::set_optional_sfixed32(::google::protobuf::int32 value) { + set_has_optional_sfixed32(); + optional_sfixed32_ = value; +} + +// optional sfixed64 optional_sfixed64 = 10; +inline bool TestAllTypesLite::has_optional_sfixed64() const { + return (_has_bits_[0] & 0x00000200u) != 0; +} +inline void TestAllTypesLite::set_has_optional_sfixed64() { + _has_bits_[0] |= 0x00000200u; +} +inline void TestAllTypesLite::clear_has_optional_sfixed64() { + _has_bits_[0] &= ~0x00000200u; +} +inline void TestAllTypesLite::clear_optional_sfixed64() { + optional_sfixed64_ = GOOGLE_LONGLONG(0); + clear_has_optional_sfixed64(); +} +inline ::google::protobuf::int64 TestAllTypesLite::optional_sfixed64() const { + return optional_sfixed64_; +} +inline void TestAllTypesLite::set_optional_sfixed64(::google::protobuf::int64 value) { + set_has_optional_sfixed64(); + optional_sfixed64_ = value; +} + +// optional float optional_float = 11; +inline bool TestAllTypesLite::has_optional_float() const { + return (_has_bits_[0] & 0x00000400u) != 0; +} +inline void TestAllTypesLite::set_has_optional_float() { + _has_bits_[0] |= 0x00000400u; +} +inline void TestAllTypesLite::clear_has_optional_float() { + _has_bits_[0] &= ~0x00000400u; +} +inline void TestAllTypesLite::clear_optional_float() { + optional_float_ = 0; + clear_has_optional_float(); +} +inline float TestAllTypesLite::optional_float() const { + return optional_float_; +} +inline void TestAllTypesLite::set_optional_float(float value) { + set_has_optional_float(); + optional_float_ = value; +} + +// optional double optional_double = 12; +inline bool TestAllTypesLite::has_optional_double() const { + return (_has_bits_[0] & 0x00000800u) != 0; +} +inline void TestAllTypesLite::set_has_optional_double() { + _has_bits_[0] |= 0x00000800u; +} +inline void TestAllTypesLite::clear_has_optional_double() { + _has_bits_[0] &= ~0x00000800u; +} +inline void TestAllTypesLite::clear_optional_double() { + optional_double_ = 0; + clear_has_optional_double(); +} +inline double TestAllTypesLite::optional_double() const { + return optional_double_; +} +inline void TestAllTypesLite::set_optional_double(double value) { + set_has_optional_double(); + optional_double_ = value; +} + +// optional bool optional_bool = 13; +inline bool TestAllTypesLite::has_optional_bool() const { + return (_has_bits_[0] & 0x00001000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_bool() { + _has_bits_[0] |= 0x00001000u; +} +inline void TestAllTypesLite::clear_has_optional_bool() { + _has_bits_[0] &= ~0x00001000u; +} +inline void TestAllTypesLite::clear_optional_bool() { + optional_bool_ = false; + clear_has_optional_bool(); +} +inline bool TestAllTypesLite::optional_bool() const { + return optional_bool_; +} +inline void TestAllTypesLite::set_optional_bool(bool value) { + set_has_optional_bool(); + optional_bool_ = value; +} + +// optional string optional_string = 14; +inline bool TestAllTypesLite::has_optional_string() const { + return (_has_bits_[0] & 0x00002000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_string() { + _has_bits_[0] |= 0x00002000u; +} +inline void TestAllTypesLite::clear_has_optional_string() { + _has_bits_[0] &= ~0x00002000u; +} +inline void TestAllTypesLite::clear_optional_string() { + if (optional_string_ != &::google::protobuf::internal::kEmptyString) { + optional_string_->clear(); + } + clear_has_optional_string(); +} +inline const ::std::string& TestAllTypesLite::optional_string() const { + return *optional_string_; +} +inline void TestAllTypesLite::set_optional_string(const ::std::string& value) { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + optional_string_->assign(value); +} +inline void TestAllTypesLite::set_optional_string(const char* value) { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + optional_string_->assign(value); +} +inline void TestAllTypesLite::set_optional_string(const char* value, size_t size) { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + optional_string_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_optional_string() { + set_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + optional_string_ = new ::std::string; + } + return optional_string_; +} +inline ::std::string* TestAllTypesLite::release_optional_string() { + clear_has_optional_string(); + if (optional_string_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_string_; + optional_string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional bytes optional_bytes = 15; +inline bool TestAllTypesLite::has_optional_bytes() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_bytes() { + _has_bits_[0] |= 0x00004000u; +} +inline void TestAllTypesLite::clear_has_optional_bytes() { + _has_bits_[0] &= ~0x00004000u; +} +inline void TestAllTypesLite::clear_optional_bytes() { + if (optional_bytes_ != &::google::protobuf::internal::kEmptyString) { + optional_bytes_->clear(); + } + clear_has_optional_bytes(); +} +inline const ::std::string& TestAllTypesLite::optional_bytes() const { + return *optional_bytes_; +} +inline void TestAllTypesLite::set_optional_bytes(const ::std::string& value) { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + optional_bytes_->assign(value); +} +inline void TestAllTypesLite::set_optional_bytes(const char* value) { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + optional_bytes_->assign(value); +} +inline void TestAllTypesLite::set_optional_bytes(const void* value, size_t size) { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + optional_bytes_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_optional_bytes() { + set_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + optional_bytes_ = new ::std::string; + } + return optional_bytes_; +} +inline ::std::string* TestAllTypesLite::release_optional_bytes() { + clear_has_optional_bytes(); + if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_bytes_; + optional_bytes_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional group OptionalGroup = 16 { +inline bool TestAllTypesLite::has_optionalgroup() const { + return (_has_bits_[0] & 0x00008000u) != 0; +} +inline void TestAllTypesLite::set_has_optionalgroup() { + _has_bits_[0] |= 0x00008000u; +} +inline void TestAllTypesLite::clear_has_optionalgroup() { + _has_bits_[0] &= ~0x00008000u; +} +inline void TestAllTypesLite::clear_optionalgroup() { + if (optionalgroup_ != NULL) optionalgroup_->::protobuf_unittest::TestAllTypesLite_OptionalGroup::Clear(); + clear_has_optionalgroup(); +} +inline const ::protobuf_unittest::TestAllTypesLite_OptionalGroup& TestAllTypesLite::optionalgroup() const { + return optionalgroup_ != NULL ? *optionalgroup_ : *default_instance_->optionalgroup_; +} +inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* TestAllTypesLite::mutable_optionalgroup() { + set_has_optionalgroup(); + if (optionalgroup_ == NULL) optionalgroup_ = new ::protobuf_unittest::TestAllTypesLite_OptionalGroup; + return optionalgroup_; +} +inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* TestAllTypesLite::release_optionalgroup() { + clear_has_optionalgroup(); + ::protobuf_unittest::TestAllTypesLite_OptionalGroup* temp = optionalgroup_; + optionalgroup_ = NULL; + return temp; +} + +// optional .protobuf_unittest.TestAllTypesLite.NestedMessage optional_nested_message = 18; +inline bool TestAllTypesLite::has_optional_nested_message() const { + return (_has_bits_[0] & 0x00010000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_nested_message() { + _has_bits_[0] |= 0x00010000u; +} +inline void TestAllTypesLite::clear_has_optional_nested_message() { + _has_bits_[0] &= ~0x00010000u; +} +inline void TestAllTypesLite::clear_optional_nested_message() { + if (optional_nested_message_ != NULL) optional_nested_message_->::protobuf_unittest::TestAllTypesLite_NestedMessage::Clear(); + clear_has_optional_nested_message(); +} +inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& TestAllTypesLite::optional_nested_message() const { + return optional_nested_message_ != NULL ? *optional_nested_message_ : *default_instance_->optional_nested_message_; +} +inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::mutable_optional_nested_message() { + set_has_optional_nested_message(); + if (optional_nested_message_ == NULL) optional_nested_message_ = new ::protobuf_unittest::TestAllTypesLite_NestedMessage; + return optional_nested_message_; +} +inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::release_optional_nested_message() { + clear_has_optional_nested_message(); + ::protobuf_unittest::TestAllTypesLite_NestedMessage* temp = optional_nested_message_; + optional_nested_message_ = NULL; + return temp; +} + +// optional .protobuf_unittest.ForeignMessageLite optional_foreign_message = 19; +inline bool TestAllTypesLite::has_optional_foreign_message() const { + return (_has_bits_[0] & 0x00020000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_foreign_message() { + _has_bits_[0] |= 0x00020000u; +} +inline void TestAllTypesLite::clear_has_optional_foreign_message() { + _has_bits_[0] &= ~0x00020000u; +} +inline void TestAllTypesLite::clear_optional_foreign_message() { + if (optional_foreign_message_ != NULL) optional_foreign_message_->::protobuf_unittest::ForeignMessageLite::Clear(); + clear_has_optional_foreign_message(); +} +inline const ::protobuf_unittest::ForeignMessageLite& TestAllTypesLite::optional_foreign_message() const { + return optional_foreign_message_ != NULL ? *optional_foreign_message_ : *default_instance_->optional_foreign_message_; +} +inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::mutable_optional_foreign_message() { + set_has_optional_foreign_message(); + if (optional_foreign_message_ == NULL) optional_foreign_message_ = new ::protobuf_unittest::ForeignMessageLite; + return optional_foreign_message_; +} +inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::release_optional_foreign_message() { + clear_has_optional_foreign_message(); + ::protobuf_unittest::ForeignMessageLite* temp = optional_foreign_message_; + optional_foreign_message_ = NULL; + return temp; +} + +// optional .protobuf_unittest_import.ImportMessageLite optional_import_message = 20; +inline bool TestAllTypesLite::has_optional_import_message() const { + return (_has_bits_[0] & 0x00040000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_import_message() { + _has_bits_[0] |= 0x00040000u; +} +inline void TestAllTypesLite::clear_has_optional_import_message() { + _has_bits_[0] &= ~0x00040000u; +} +inline void TestAllTypesLite::clear_optional_import_message() { + if (optional_import_message_ != NULL) optional_import_message_->::protobuf_unittest_import::ImportMessageLite::Clear(); + clear_has_optional_import_message(); +} +inline const ::protobuf_unittest_import::ImportMessageLite& TestAllTypesLite::optional_import_message() const { + return optional_import_message_ != NULL ? *optional_import_message_ : *default_instance_->optional_import_message_; +} +inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::mutable_optional_import_message() { + set_has_optional_import_message(); + if (optional_import_message_ == NULL) optional_import_message_ = new ::protobuf_unittest_import::ImportMessageLite; + return optional_import_message_; +} +inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::release_optional_import_message() { + clear_has_optional_import_message(); + ::protobuf_unittest_import::ImportMessageLite* temp = optional_import_message_; + optional_import_message_ = NULL; + return temp; +} + +// optional .protobuf_unittest.TestAllTypesLite.NestedEnum optional_nested_enum = 21; +inline bool TestAllTypesLite::has_optional_nested_enum() const { + return (_has_bits_[0] & 0x00080000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_nested_enum() { + _has_bits_[0] |= 0x00080000u; +} +inline void TestAllTypesLite::clear_has_optional_nested_enum() { + _has_bits_[0] &= ~0x00080000u; +} +inline void TestAllTypesLite::clear_optional_nested_enum() { + optional_nested_enum_ = 1; + clear_has_optional_nested_enum(); +} +inline ::protobuf_unittest::TestAllTypesLite_NestedEnum TestAllTypesLite::optional_nested_enum() const { + return static_cast< ::protobuf_unittest::TestAllTypesLite_NestedEnum >(optional_nested_enum_); +} +inline void TestAllTypesLite::set_optional_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); + set_has_optional_nested_enum(); + optional_nested_enum_ = value; +} + +// optional .protobuf_unittest.ForeignEnumLite optional_foreign_enum = 22; +inline bool TestAllTypesLite::has_optional_foreign_enum() const { + return (_has_bits_[0] & 0x00100000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_foreign_enum() { + _has_bits_[0] |= 0x00100000u; +} +inline void TestAllTypesLite::clear_has_optional_foreign_enum() { + _has_bits_[0] &= ~0x00100000u; +} +inline void TestAllTypesLite::clear_optional_foreign_enum() { + optional_foreign_enum_ = 4; + clear_has_optional_foreign_enum(); +} +inline protobuf_unittest::ForeignEnumLite TestAllTypesLite::optional_foreign_enum() const { + return static_cast< protobuf_unittest::ForeignEnumLite >(optional_foreign_enum_); +} +inline void TestAllTypesLite::set_optional_foreign_enum(protobuf_unittest::ForeignEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); + set_has_optional_foreign_enum(); + optional_foreign_enum_ = value; +} + +// optional .protobuf_unittest_import.ImportEnumLite optional_import_enum = 23; +inline bool TestAllTypesLite::has_optional_import_enum() const { + return (_has_bits_[0] & 0x00200000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_import_enum() { + _has_bits_[0] |= 0x00200000u; +} +inline void TestAllTypesLite::clear_has_optional_import_enum() { + _has_bits_[0] &= ~0x00200000u; +} +inline void TestAllTypesLite::clear_optional_import_enum() { + optional_import_enum_ = 7; + clear_has_optional_import_enum(); +} +inline protobuf_unittest_import::ImportEnumLite TestAllTypesLite::optional_import_enum() const { + return static_cast< protobuf_unittest_import::ImportEnumLite >(optional_import_enum_); +} +inline void TestAllTypesLite::set_optional_import_enum(protobuf_unittest_import::ImportEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); + set_has_optional_import_enum(); + optional_import_enum_ = value; +} + +// optional string optional_string_piece = 24 [ctype = STRING_PIECE]; +inline bool TestAllTypesLite::has_optional_string_piece() const { + return (_has_bits_[0] & 0x00400000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_string_piece() { + _has_bits_[0] |= 0x00400000u; +} +inline void TestAllTypesLite::clear_has_optional_string_piece() { + _has_bits_[0] &= ~0x00400000u; +} +inline void TestAllTypesLite::clear_optional_string_piece() { + if (optional_string_piece_ != &::google::protobuf::internal::kEmptyString) { + optional_string_piece_->clear(); + } + clear_has_optional_string_piece(); +} +inline const ::std::string& TestAllTypesLite::optional_string_piece() const { + return *optional_string_piece_; +} +inline void TestAllTypesLite::set_optional_string_piece(const ::std::string& value) { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + optional_string_piece_->assign(value); +} +inline void TestAllTypesLite::set_optional_string_piece(const char* value) { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + optional_string_piece_->assign(value); +} +inline void TestAllTypesLite::set_optional_string_piece(const char* value, size_t size) { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + optional_string_piece_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_optional_string_piece() { + set_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + optional_string_piece_ = new ::std::string; + } + return optional_string_piece_; +} +inline ::std::string* TestAllTypesLite::release_optional_string_piece() { + clear_has_optional_string_piece(); + if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_string_piece_; + optional_string_piece_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// optional string optional_cord = 25 [ctype = CORD]; +inline bool TestAllTypesLite::has_optional_cord() const { + return (_has_bits_[0] & 0x00800000u) != 0; +} +inline void TestAllTypesLite::set_has_optional_cord() { + _has_bits_[0] |= 0x00800000u; +} +inline void TestAllTypesLite::clear_has_optional_cord() { + _has_bits_[0] &= ~0x00800000u; +} +inline void TestAllTypesLite::clear_optional_cord() { + if (optional_cord_ != &::google::protobuf::internal::kEmptyString) { + optional_cord_->clear(); + } + clear_has_optional_cord(); +} +inline const ::std::string& TestAllTypesLite::optional_cord() const { + return *optional_cord_; +} +inline void TestAllTypesLite::set_optional_cord(const ::std::string& value) { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + optional_cord_->assign(value); +} +inline void TestAllTypesLite::set_optional_cord(const char* value) { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + optional_cord_->assign(value); +} +inline void TestAllTypesLite::set_optional_cord(const char* value, size_t size) { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + optional_cord_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_optional_cord() { + set_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + optional_cord_ = new ::std::string; + } + return optional_cord_; +} +inline ::std::string* TestAllTypesLite::release_optional_cord() { + clear_has_optional_cord(); + if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = optional_cord_; + optional_cord_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// repeated int32 repeated_int32 = 31; +inline int TestAllTypesLite::repeated_int32_size() const { + return repeated_int32_.size(); +} +inline void TestAllTypesLite::clear_repeated_int32() { + repeated_int32_.Clear(); +} +inline ::google::protobuf::int32 TestAllTypesLite::repeated_int32(int index) const { + return repeated_int32_.Get(index); +} +inline void TestAllTypesLite::set_repeated_int32(int index, ::google::protobuf::int32 value) { + repeated_int32_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_int32(::google::protobuf::int32 value) { + repeated_int32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestAllTypesLite::repeated_int32() const { + return repeated_int32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestAllTypesLite::mutable_repeated_int32() { + return &repeated_int32_; +} + +// repeated int64 repeated_int64 = 32; +inline int TestAllTypesLite::repeated_int64_size() const { + return repeated_int64_.size(); +} +inline void TestAllTypesLite::clear_repeated_int64() { + repeated_int64_.Clear(); +} +inline ::google::protobuf::int64 TestAllTypesLite::repeated_int64(int index) const { + return repeated_int64_.Get(index); +} +inline void TestAllTypesLite::set_repeated_int64(int index, ::google::protobuf::int64 value) { + repeated_int64_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_int64(::google::protobuf::int64 value) { + repeated_int64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestAllTypesLite::repeated_int64() const { + return repeated_int64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestAllTypesLite::mutable_repeated_int64() { + return &repeated_int64_; +} + +// repeated uint32 repeated_uint32 = 33; +inline int TestAllTypesLite::repeated_uint32_size() const { + return repeated_uint32_.size(); +} +inline void TestAllTypesLite::clear_repeated_uint32() { + repeated_uint32_.Clear(); +} +inline ::google::protobuf::uint32 TestAllTypesLite::repeated_uint32(int index) const { + return repeated_uint32_.Get(index); +} +inline void TestAllTypesLite::set_repeated_uint32(int index, ::google::protobuf::uint32 value) { + repeated_uint32_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_uint32(::google::protobuf::uint32 value) { + repeated_uint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestAllTypesLite::repeated_uint32() const { + return repeated_uint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestAllTypesLite::mutable_repeated_uint32() { + return &repeated_uint32_; +} + +// repeated uint64 repeated_uint64 = 34; +inline int TestAllTypesLite::repeated_uint64_size() const { + return repeated_uint64_.size(); +} +inline void TestAllTypesLite::clear_repeated_uint64() { + repeated_uint64_.Clear(); +} +inline ::google::protobuf::uint64 TestAllTypesLite::repeated_uint64(int index) const { + return repeated_uint64_.Get(index); +} +inline void TestAllTypesLite::set_repeated_uint64(int index, ::google::protobuf::uint64 value) { + repeated_uint64_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_uint64(::google::protobuf::uint64 value) { + repeated_uint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestAllTypesLite::repeated_uint64() const { + return repeated_uint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestAllTypesLite::mutable_repeated_uint64() { + return &repeated_uint64_; +} + +// repeated sint32 repeated_sint32 = 35; +inline int TestAllTypesLite::repeated_sint32_size() const { + return repeated_sint32_.size(); +} +inline void TestAllTypesLite::clear_repeated_sint32() { + repeated_sint32_.Clear(); +} +inline ::google::protobuf::int32 TestAllTypesLite::repeated_sint32(int index) const { + return repeated_sint32_.Get(index); +} +inline void TestAllTypesLite::set_repeated_sint32(int index, ::google::protobuf::int32 value) { + repeated_sint32_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_sint32(::google::protobuf::int32 value) { + repeated_sint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestAllTypesLite::repeated_sint32() const { + return repeated_sint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestAllTypesLite::mutable_repeated_sint32() { + return &repeated_sint32_; +} + +// repeated sint64 repeated_sint64 = 36; +inline int TestAllTypesLite::repeated_sint64_size() const { + return repeated_sint64_.size(); +} +inline void TestAllTypesLite::clear_repeated_sint64() { + repeated_sint64_.Clear(); +} +inline ::google::protobuf::int64 TestAllTypesLite::repeated_sint64(int index) const { + return repeated_sint64_.Get(index); +} +inline void TestAllTypesLite::set_repeated_sint64(int index, ::google::protobuf::int64 value) { + repeated_sint64_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_sint64(::google::protobuf::int64 value) { + repeated_sint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestAllTypesLite::repeated_sint64() const { + return repeated_sint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestAllTypesLite::mutable_repeated_sint64() { + return &repeated_sint64_; +} + +// repeated fixed32 repeated_fixed32 = 37; +inline int TestAllTypesLite::repeated_fixed32_size() const { + return repeated_fixed32_.size(); +} +inline void TestAllTypesLite::clear_repeated_fixed32() { + repeated_fixed32_.Clear(); +} +inline ::google::protobuf::uint32 TestAllTypesLite::repeated_fixed32(int index) const { + return repeated_fixed32_.Get(index); +} +inline void TestAllTypesLite::set_repeated_fixed32(int index, ::google::protobuf::uint32 value) { + repeated_fixed32_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_fixed32(::google::protobuf::uint32 value) { + repeated_fixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestAllTypesLite::repeated_fixed32() const { + return repeated_fixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestAllTypesLite::mutable_repeated_fixed32() { + return &repeated_fixed32_; +} + +// repeated fixed64 repeated_fixed64 = 38; +inline int TestAllTypesLite::repeated_fixed64_size() const { + return repeated_fixed64_.size(); +} +inline void TestAllTypesLite::clear_repeated_fixed64() { + repeated_fixed64_.Clear(); +} +inline ::google::protobuf::uint64 TestAllTypesLite::repeated_fixed64(int index) const { + return repeated_fixed64_.Get(index); +} +inline void TestAllTypesLite::set_repeated_fixed64(int index, ::google::protobuf::uint64 value) { + repeated_fixed64_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_fixed64(::google::protobuf::uint64 value) { + repeated_fixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestAllTypesLite::repeated_fixed64() const { + return repeated_fixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestAllTypesLite::mutable_repeated_fixed64() { + return &repeated_fixed64_; +} + +// repeated sfixed32 repeated_sfixed32 = 39; +inline int TestAllTypesLite::repeated_sfixed32_size() const { + return repeated_sfixed32_.size(); +} +inline void TestAllTypesLite::clear_repeated_sfixed32() { + repeated_sfixed32_.Clear(); +} +inline ::google::protobuf::int32 TestAllTypesLite::repeated_sfixed32(int index) const { + return repeated_sfixed32_.Get(index); +} +inline void TestAllTypesLite::set_repeated_sfixed32(int index, ::google::protobuf::int32 value) { + repeated_sfixed32_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_sfixed32(::google::protobuf::int32 value) { + repeated_sfixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestAllTypesLite::repeated_sfixed32() const { + return repeated_sfixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestAllTypesLite::mutable_repeated_sfixed32() { + return &repeated_sfixed32_; +} + +// repeated sfixed64 repeated_sfixed64 = 40; +inline int TestAllTypesLite::repeated_sfixed64_size() const { + return repeated_sfixed64_.size(); +} +inline void TestAllTypesLite::clear_repeated_sfixed64() { + repeated_sfixed64_.Clear(); +} +inline ::google::protobuf::int64 TestAllTypesLite::repeated_sfixed64(int index) const { + return repeated_sfixed64_.Get(index); +} +inline void TestAllTypesLite::set_repeated_sfixed64(int index, ::google::protobuf::int64 value) { + repeated_sfixed64_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_sfixed64(::google::protobuf::int64 value) { + repeated_sfixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestAllTypesLite::repeated_sfixed64() const { + return repeated_sfixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestAllTypesLite::mutable_repeated_sfixed64() { + return &repeated_sfixed64_; +} + +// repeated float repeated_float = 41; +inline int TestAllTypesLite::repeated_float_size() const { + return repeated_float_.size(); +} +inline void TestAllTypesLite::clear_repeated_float() { + repeated_float_.Clear(); +} +inline float TestAllTypesLite::repeated_float(int index) const { + return repeated_float_.Get(index); +} +inline void TestAllTypesLite::set_repeated_float(int index, float value) { + repeated_float_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_float(float value) { + repeated_float_.Add(value); +} +inline const ::google::protobuf::RepeatedField< float >& +TestAllTypesLite::repeated_float() const { + return repeated_float_; +} +inline ::google::protobuf::RepeatedField< float >* +TestAllTypesLite::mutable_repeated_float() { + return &repeated_float_; +} + +// repeated double repeated_double = 42; +inline int TestAllTypesLite::repeated_double_size() const { + return repeated_double_.size(); +} +inline void TestAllTypesLite::clear_repeated_double() { + repeated_double_.Clear(); +} +inline double TestAllTypesLite::repeated_double(int index) const { + return repeated_double_.Get(index); +} +inline void TestAllTypesLite::set_repeated_double(int index, double value) { + repeated_double_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_double(double value) { + repeated_double_.Add(value); +} +inline const ::google::protobuf::RepeatedField< double >& +TestAllTypesLite::repeated_double() const { + return repeated_double_; +} +inline ::google::protobuf::RepeatedField< double >* +TestAllTypesLite::mutable_repeated_double() { + return &repeated_double_; +} + +// repeated bool repeated_bool = 43; +inline int TestAllTypesLite::repeated_bool_size() const { + return repeated_bool_.size(); +} +inline void TestAllTypesLite::clear_repeated_bool() { + repeated_bool_.Clear(); +} +inline bool TestAllTypesLite::repeated_bool(int index) const { + return repeated_bool_.Get(index); +} +inline void TestAllTypesLite::set_repeated_bool(int index, bool value) { + repeated_bool_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_bool(bool value) { + repeated_bool_.Add(value); +} +inline const ::google::protobuf::RepeatedField< bool >& +TestAllTypesLite::repeated_bool() const { + return repeated_bool_; +} +inline ::google::protobuf::RepeatedField< bool >* +TestAllTypesLite::mutable_repeated_bool() { + return &repeated_bool_; +} + +// repeated string repeated_string = 44; +inline int TestAllTypesLite::repeated_string_size() const { + return repeated_string_.size(); +} +inline void TestAllTypesLite::clear_repeated_string() { + repeated_string_.Clear(); +} +inline const ::std::string& TestAllTypesLite::repeated_string(int index) const { + return repeated_string_.Get(index); +} +inline ::std::string* TestAllTypesLite::mutable_repeated_string(int index) { + return repeated_string_.Mutable(index); +} +inline void TestAllTypesLite::set_repeated_string(int index, const ::std::string& value) { + repeated_string_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_string(int index, const char* value) { + repeated_string_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_string(int index, const char* value, size_t size) { + repeated_string_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::add_repeated_string() { + return repeated_string_.Add(); +} +inline void TestAllTypesLite::add_repeated_string(const ::std::string& value) { + repeated_string_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_string(const char* value) { + repeated_string_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_string(const char* value, size_t size) { + repeated_string_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypesLite::repeated_string() const { + return repeated_string_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypesLite::mutable_repeated_string() { + return &repeated_string_; +} + +// repeated bytes repeated_bytes = 45; +inline int TestAllTypesLite::repeated_bytes_size() const { + return repeated_bytes_.size(); +} +inline void TestAllTypesLite::clear_repeated_bytes() { + repeated_bytes_.Clear(); +} +inline const ::std::string& TestAllTypesLite::repeated_bytes(int index) const { + return repeated_bytes_.Get(index); +} +inline ::std::string* TestAllTypesLite::mutable_repeated_bytes(int index) { + return repeated_bytes_.Mutable(index); +} +inline void TestAllTypesLite::set_repeated_bytes(int index, const ::std::string& value) { + repeated_bytes_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_bytes(int index, const char* value) { + repeated_bytes_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_bytes(int index, const void* value, size_t size) { + repeated_bytes_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::add_repeated_bytes() { + return repeated_bytes_.Add(); +} +inline void TestAllTypesLite::add_repeated_bytes(const ::std::string& value) { + repeated_bytes_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_bytes(const char* value) { + repeated_bytes_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_bytes(const void* value, size_t size) { + repeated_bytes_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypesLite::repeated_bytes() const { + return repeated_bytes_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypesLite::mutable_repeated_bytes() { + return &repeated_bytes_; +} + +// repeated group RepeatedGroup = 46 { +inline int TestAllTypesLite::repeatedgroup_size() const { + return repeatedgroup_.size(); +} +inline void TestAllTypesLite::clear_repeatedgroup() { + repeatedgroup_.Clear(); +} +inline const ::protobuf_unittest::TestAllTypesLite_RepeatedGroup& TestAllTypesLite::repeatedgroup(int index) const { + return repeatedgroup_.Get(index); +} +inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* TestAllTypesLite::mutable_repeatedgroup(int index) { + return repeatedgroup_.Mutable(index); +} +inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* TestAllTypesLite::add_repeatedgroup() { + return repeatedgroup_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >& +TestAllTypesLite::repeatedgroup() const { + return repeatedgroup_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >* +TestAllTypesLite::mutable_repeatedgroup() { + return &repeatedgroup_; +} + +// repeated .protobuf_unittest.TestAllTypesLite.NestedMessage repeated_nested_message = 48; +inline int TestAllTypesLite::repeated_nested_message_size() const { + return repeated_nested_message_.size(); +} +inline void TestAllTypesLite::clear_repeated_nested_message() { + repeated_nested_message_.Clear(); +} +inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& TestAllTypesLite::repeated_nested_message(int index) const { + return repeated_nested_message_.Get(index); +} +inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::mutable_repeated_nested_message(int index) { + return repeated_nested_message_.Mutable(index); +} +inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::add_repeated_nested_message() { + return repeated_nested_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >& +TestAllTypesLite::repeated_nested_message() const { + return repeated_nested_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >* +TestAllTypesLite::mutable_repeated_nested_message() { + return &repeated_nested_message_; +} + +// repeated .protobuf_unittest.ForeignMessageLite repeated_foreign_message = 49; +inline int TestAllTypesLite::repeated_foreign_message_size() const { + return repeated_foreign_message_.size(); +} +inline void TestAllTypesLite::clear_repeated_foreign_message() { + repeated_foreign_message_.Clear(); +} +inline const ::protobuf_unittest::ForeignMessageLite& TestAllTypesLite::repeated_foreign_message(int index) const { + return repeated_foreign_message_.Get(index); +} +inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::mutable_repeated_foreign_message(int index) { + return repeated_foreign_message_.Mutable(index); +} +inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::add_repeated_foreign_message() { + return repeated_foreign_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >& +TestAllTypesLite::repeated_foreign_message() const { + return repeated_foreign_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >* +TestAllTypesLite::mutable_repeated_foreign_message() { + return &repeated_foreign_message_; +} + +// repeated .protobuf_unittest_import.ImportMessageLite repeated_import_message = 50; +inline int TestAllTypesLite::repeated_import_message_size() const { + return repeated_import_message_.size(); +} +inline void TestAllTypesLite::clear_repeated_import_message() { + repeated_import_message_.Clear(); +} +inline const ::protobuf_unittest_import::ImportMessageLite& TestAllTypesLite::repeated_import_message(int index) const { + return repeated_import_message_.Get(index); +} +inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::mutable_repeated_import_message(int index) { + return repeated_import_message_.Mutable(index); +} +inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::add_repeated_import_message() { + return repeated_import_message_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >& +TestAllTypesLite::repeated_import_message() const { + return repeated_import_message_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >* +TestAllTypesLite::mutable_repeated_import_message() { + return &repeated_import_message_; +} + +// repeated .protobuf_unittest.TestAllTypesLite.NestedEnum repeated_nested_enum = 51; +inline int TestAllTypesLite::repeated_nested_enum_size() const { + return repeated_nested_enum_.size(); +} +inline void TestAllTypesLite::clear_repeated_nested_enum() { + repeated_nested_enum_.Clear(); +} +inline ::protobuf_unittest::TestAllTypesLite_NestedEnum TestAllTypesLite::repeated_nested_enum(int index) const { + return static_cast< ::protobuf_unittest::TestAllTypesLite_NestedEnum >(repeated_nested_enum_.Get(index)); +} +inline void TestAllTypesLite::set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypesLite_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); + repeated_nested_enum_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); + repeated_nested_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestAllTypesLite::repeated_nested_enum() const { + return repeated_nested_enum_; +} +inline ::google::protobuf::RepeatedField* +TestAllTypesLite::mutable_repeated_nested_enum() { + return &repeated_nested_enum_; +} + +// repeated .protobuf_unittest.ForeignEnumLite repeated_foreign_enum = 52; +inline int TestAllTypesLite::repeated_foreign_enum_size() const { + return repeated_foreign_enum_.size(); +} +inline void TestAllTypesLite::clear_repeated_foreign_enum() { + repeated_foreign_enum_.Clear(); +} +inline protobuf_unittest::ForeignEnumLite TestAllTypesLite::repeated_foreign_enum(int index) const { + return static_cast< protobuf_unittest::ForeignEnumLite >(repeated_foreign_enum_.Get(index)); +} +inline void TestAllTypesLite::set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); + repeated_foreign_enum_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_foreign_enum(protobuf_unittest::ForeignEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); + repeated_foreign_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestAllTypesLite::repeated_foreign_enum() const { + return repeated_foreign_enum_; +} +inline ::google::protobuf::RepeatedField* +TestAllTypesLite::mutable_repeated_foreign_enum() { + return &repeated_foreign_enum_; +} + +// repeated .protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53; +inline int TestAllTypesLite::repeated_import_enum_size() const { + return repeated_import_enum_.size(); +} +inline void TestAllTypesLite::clear_repeated_import_enum() { + repeated_import_enum_.Clear(); +} +inline protobuf_unittest_import::ImportEnumLite TestAllTypesLite::repeated_import_enum(int index) const { + return static_cast< protobuf_unittest_import::ImportEnumLite >(repeated_import_enum_.Get(index)); +} +inline void TestAllTypesLite::set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); + repeated_import_enum_.Set(index, value); +} +inline void TestAllTypesLite::add_repeated_import_enum(protobuf_unittest_import::ImportEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); + repeated_import_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestAllTypesLite::repeated_import_enum() const { + return repeated_import_enum_; +} +inline ::google::protobuf::RepeatedField* +TestAllTypesLite::mutable_repeated_import_enum() { + return &repeated_import_enum_; +} + +// repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; +inline int TestAllTypesLite::repeated_string_piece_size() const { + return repeated_string_piece_.size(); +} +inline void TestAllTypesLite::clear_repeated_string_piece() { + repeated_string_piece_.Clear(); +} +inline const ::std::string& TestAllTypesLite::repeated_string_piece(int index) const { + return repeated_string_piece_.Get(index); +} +inline ::std::string* TestAllTypesLite::mutable_repeated_string_piece(int index) { + return repeated_string_piece_.Mutable(index); +} +inline void TestAllTypesLite::set_repeated_string_piece(int index, const ::std::string& value) { + repeated_string_piece_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_string_piece(int index, const char* value) { + repeated_string_piece_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_string_piece(int index, const char* value, size_t size) { + repeated_string_piece_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::add_repeated_string_piece() { + return repeated_string_piece_.Add(); +} +inline void TestAllTypesLite::add_repeated_string_piece(const ::std::string& value) { + repeated_string_piece_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_string_piece(const char* value) { + repeated_string_piece_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_string_piece(const char* value, size_t size) { + repeated_string_piece_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypesLite::repeated_string_piece() const { + return repeated_string_piece_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypesLite::mutable_repeated_string_piece() { + return &repeated_string_piece_; +} + +// repeated string repeated_cord = 55 [ctype = CORD]; +inline int TestAllTypesLite::repeated_cord_size() const { + return repeated_cord_.size(); +} +inline void TestAllTypesLite::clear_repeated_cord() { + repeated_cord_.Clear(); +} +inline const ::std::string& TestAllTypesLite::repeated_cord(int index) const { + return repeated_cord_.Get(index); +} +inline ::std::string* TestAllTypesLite::mutable_repeated_cord(int index) { + return repeated_cord_.Mutable(index); +} +inline void TestAllTypesLite::set_repeated_cord(int index, const ::std::string& value) { + repeated_cord_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_cord(int index, const char* value) { + repeated_cord_.Mutable(index)->assign(value); +} +inline void TestAllTypesLite::set_repeated_cord(int index, const char* value, size_t size) { + repeated_cord_.Mutable(index)->assign( + reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::add_repeated_cord() { + return repeated_cord_.Add(); +} +inline void TestAllTypesLite::add_repeated_cord(const ::std::string& value) { + repeated_cord_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_cord(const char* value) { + repeated_cord_.Add()->assign(value); +} +inline void TestAllTypesLite::add_repeated_cord(const char* value, size_t size) { + repeated_cord_.Add()->assign(reinterpret_cast(value), size); +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +TestAllTypesLite::repeated_cord() const { + return repeated_cord_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +TestAllTypesLite::mutable_repeated_cord() { + return &repeated_cord_; +} + +// optional int32 default_int32 = 61 [default = 41]; +inline bool TestAllTypesLite::has_default_int32() const { + return (_has_bits_[1] & 0x00010000u) != 0; +} +inline void TestAllTypesLite::set_has_default_int32() { + _has_bits_[1] |= 0x00010000u; +} +inline void TestAllTypesLite::clear_has_default_int32() { + _has_bits_[1] &= ~0x00010000u; +} +inline void TestAllTypesLite::clear_default_int32() { + default_int32_ = 41; + clear_has_default_int32(); +} +inline ::google::protobuf::int32 TestAllTypesLite::default_int32() const { + return default_int32_; +} +inline void TestAllTypesLite::set_default_int32(::google::protobuf::int32 value) { + set_has_default_int32(); + default_int32_ = value; +} + +// optional int64 default_int64 = 62 [default = 42]; +inline bool TestAllTypesLite::has_default_int64() const { + return (_has_bits_[1] & 0x00020000u) != 0; +} +inline void TestAllTypesLite::set_has_default_int64() { + _has_bits_[1] |= 0x00020000u; +} +inline void TestAllTypesLite::clear_has_default_int64() { + _has_bits_[1] &= ~0x00020000u; +} +inline void TestAllTypesLite::clear_default_int64() { + default_int64_ = GOOGLE_LONGLONG(42); + clear_has_default_int64(); +} +inline ::google::protobuf::int64 TestAllTypesLite::default_int64() const { + return default_int64_; +} +inline void TestAllTypesLite::set_default_int64(::google::protobuf::int64 value) { + set_has_default_int64(); + default_int64_ = value; +} + +// optional uint32 default_uint32 = 63 [default = 43]; +inline bool TestAllTypesLite::has_default_uint32() const { + return (_has_bits_[1] & 0x00040000u) != 0; +} +inline void TestAllTypesLite::set_has_default_uint32() { + _has_bits_[1] |= 0x00040000u; +} +inline void TestAllTypesLite::clear_has_default_uint32() { + _has_bits_[1] &= ~0x00040000u; +} +inline void TestAllTypesLite::clear_default_uint32() { + default_uint32_ = 43u; + clear_has_default_uint32(); +} +inline ::google::protobuf::uint32 TestAllTypesLite::default_uint32() const { + return default_uint32_; +} +inline void TestAllTypesLite::set_default_uint32(::google::protobuf::uint32 value) { + set_has_default_uint32(); + default_uint32_ = value; +} + +// optional uint64 default_uint64 = 64 [default = 44]; +inline bool TestAllTypesLite::has_default_uint64() const { + return (_has_bits_[1] & 0x00080000u) != 0; +} +inline void TestAllTypesLite::set_has_default_uint64() { + _has_bits_[1] |= 0x00080000u; +} +inline void TestAllTypesLite::clear_has_default_uint64() { + _has_bits_[1] &= ~0x00080000u; +} +inline void TestAllTypesLite::clear_default_uint64() { + default_uint64_ = GOOGLE_ULONGLONG(44); + clear_has_default_uint64(); +} +inline ::google::protobuf::uint64 TestAllTypesLite::default_uint64() const { + return default_uint64_; +} +inline void TestAllTypesLite::set_default_uint64(::google::protobuf::uint64 value) { + set_has_default_uint64(); + default_uint64_ = value; +} + +// optional sint32 default_sint32 = 65 [default = -45]; +inline bool TestAllTypesLite::has_default_sint32() const { + return (_has_bits_[1] & 0x00100000u) != 0; +} +inline void TestAllTypesLite::set_has_default_sint32() { + _has_bits_[1] |= 0x00100000u; +} +inline void TestAllTypesLite::clear_has_default_sint32() { + _has_bits_[1] &= ~0x00100000u; +} +inline void TestAllTypesLite::clear_default_sint32() { + default_sint32_ = -45; + clear_has_default_sint32(); +} +inline ::google::protobuf::int32 TestAllTypesLite::default_sint32() const { + return default_sint32_; +} +inline void TestAllTypesLite::set_default_sint32(::google::protobuf::int32 value) { + set_has_default_sint32(); + default_sint32_ = value; +} + +// optional sint64 default_sint64 = 66 [default = 46]; +inline bool TestAllTypesLite::has_default_sint64() const { + return (_has_bits_[1] & 0x00200000u) != 0; +} +inline void TestAllTypesLite::set_has_default_sint64() { + _has_bits_[1] |= 0x00200000u; +} +inline void TestAllTypesLite::clear_has_default_sint64() { + _has_bits_[1] &= ~0x00200000u; +} +inline void TestAllTypesLite::clear_default_sint64() { + default_sint64_ = GOOGLE_LONGLONG(46); + clear_has_default_sint64(); +} +inline ::google::protobuf::int64 TestAllTypesLite::default_sint64() const { + return default_sint64_; +} +inline void TestAllTypesLite::set_default_sint64(::google::protobuf::int64 value) { + set_has_default_sint64(); + default_sint64_ = value; +} + +// optional fixed32 default_fixed32 = 67 [default = 47]; +inline bool TestAllTypesLite::has_default_fixed32() const { + return (_has_bits_[1] & 0x00400000u) != 0; +} +inline void TestAllTypesLite::set_has_default_fixed32() { + _has_bits_[1] |= 0x00400000u; +} +inline void TestAllTypesLite::clear_has_default_fixed32() { + _has_bits_[1] &= ~0x00400000u; +} +inline void TestAllTypesLite::clear_default_fixed32() { + default_fixed32_ = 47u; + clear_has_default_fixed32(); +} +inline ::google::protobuf::uint32 TestAllTypesLite::default_fixed32() const { + return default_fixed32_; +} +inline void TestAllTypesLite::set_default_fixed32(::google::protobuf::uint32 value) { + set_has_default_fixed32(); + default_fixed32_ = value; +} + +// optional fixed64 default_fixed64 = 68 [default = 48]; +inline bool TestAllTypesLite::has_default_fixed64() const { + return (_has_bits_[1] & 0x00800000u) != 0; +} +inline void TestAllTypesLite::set_has_default_fixed64() { + _has_bits_[1] |= 0x00800000u; +} +inline void TestAllTypesLite::clear_has_default_fixed64() { + _has_bits_[1] &= ~0x00800000u; +} +inline void TestAllTypesLite::clear_default_fixed64() { + default_fixed64_ = GOOGLE_ULONGLONG(48); + clear_has_default_fixed64(); +} +inline ::google::protobuf::uint64 TestAllTypesLite::default_fixed64() const { + return default_fixed64_; +} +inline void TestAllTypesLite::set_default_fixed64(::google::protobuf::uint64 value) { + set_has_default_fixed64(); + default_fixed64_ = value; +} + +// optional sfixed32 default_sfixed32 = 69 [default = 49]; +inline bool TestAllTypesLite::has_default_sfixed32() const { + return (_has_bits_[1] & 0x01000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_sfixed32() { + _has_bits_[1] |= 0x01000000u; +} +inline void TestAllTypesLite::clear_has_default_sfixed32() { + _has_bits_[1] &= ~0x01000000u; +} +inline void TestAllTypesLite::clear_default_sfixed32() { + default_sfixed32_ = 49; + clear_has_default_sfixed32(); +} +inline ::google::protobuf::int32 TestAllTypesLite::default_sfixed32() const { + return default_sfixed32_; +} +inline void TestAllTypesLite::set_default_sfixed32(::google::protobuf::int32 value) { + set_has_default_sfixed32(); + default_sfixed32_ = value; +} + +// optional sfixed64 default_sfixed64 = 70 [default = -50]; +inline bool TestAllTypesLite::has_default_sfixed64() const { + return (_has_bits_[1] & 0x02000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_sfixed64() { + _has_bits_[1] |= 0x02000000u; +} +inline void TestAllTypesLite::clear_has_default_sfixed64() { + _has_bits_[1] &= ~0x02000000u; +} +inline void TestAllTypesLite::clear_default_sfixed64() { + default_sfixed64_ = GOOGLE_LONGLONG(-50); + clear_has_default_sfixed64(); +} +inline ::google::protobuf::int64 TestAllTypesLite::default_sfixed64() const { + return default_sfixed64_; +} +inline void TestAllTypesLite::set_default_sfixed64(::google::protobuf::int64 value) { + set_has_default_sfixed64(); + default_sfixed64_ = value; +} + +// optional float default_float = 71 [default = 51.5]; +inline bool TestAllTypesLite::has_default_float() const { + return (_has_bits_[1] & 0x04000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_float() { + _has_bits_[1] |= 0x04000000u; +} +inline void TestAllTypesLite::clear_has_default_float() { + _has_bits_[1] &= ~0x04000000u; +} +inline void TestAllTypesLite::clear_default_float() { + default_float_ = 51.5f; + clear_has_default_float(); +} +inline float TestAllTypesLite::default_float() const { + return default_float_; +} +inline void TestAllTypesLite::set_default_float(float value) { + set_has_default_float(); + default_float_ = value; +} + +// optional double default_double = 72 [default = 52000]; +inline bool TestAllTypesLite::has_default_double() const { + return (_has_bits_[1] & 0x08000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_double() { + _has_bits_[1] |= 0x08000000u; +} +inline void TestAllTypesLite::clear_has_default_double() { + _has_bits_[1] &= ~0x08000000u; +} +inline void TestAllTypesLite::clear_default_double() { + default_double_ = 52000; + clear_has_default_double(); +} +inline double TestAllTypesLite::default_double() const { + return default_double_; +} +inline void TestAllTypesLite::set_default_double(double value) { + set_has_default_double(); + default_double_ = value; +} + +// optional bool default_bool = 73 [default = true]; +inline bool TestAllTypesLite::has_default_bool() const { + return (_has_bits_[1] & 0x10000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_bool() { + _has_bits_[1] |= 0x10000000u; +} +inline void TestAllTypesLite::clear_has_default_bool() { + _has_bits_[1] &= ~0x10000000u; +} +inline void TestAllTypesLite::clear_default_bool() { + default_bool_ = true; + clear_has_default_bool(); +} +inline bool TestAllTypesLite::default_bool() const { + return default_bool_; +} +inline void TestAllTypesLite::set_default_bool(bool value) { + set_has_default_bool(); + default_bool_ = value; +} + +// optional string default_string = 74 [default = "hello"]; +inline bool TestAllTypesLite::has_default_string() const { + return (_has_bits_[1] & 0x20000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_string() { + _has_bits_[1] |= 0x20000000u; +} +inline void TestAllTypesLite::clear_has_default_string() { + _has_bits_[1] &= ~0x20000000u; +} +inline void TestAllTypesLite::clear_default_string() { + if (default_string_ != &_default_default_string_) { + default_string_->assign(_default_default_string_); + } + clear_has_default_string(); +} +inline const ::std::string& TestAllTypesLite::default_string() const { + return *default_string_; +} +inline void TestAllTypesLite::set_default_string(const ::std::string& value) { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string; + } + default_string_->assign(value); +} +inline void TestAllTypesLite::set_default_string(const char* value) { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string; + } + default_string_->assign(value); +} +inline void TestAllTypesLite::set_default_string(const char* value, size_t size) { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string; + } + default_string_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_default_string() { + set_has_default_string(); + if (default_string_ == &_default_default_string_) { + default_string_ = new ::std::string(_default_default_string_); + } + return default_string_; +} +inline ::std::string* TestAllTypesLite::release_default_string() { + clear_has_default_string(); + if (default_string_ == &_default_default_string_) { + return NULL; + } else { + ::std::string* temp = default_string_; + default_string_ = const_cast< ::std::string*>(&_default_default_string_); + return temp; + } +} + +// optional bytes default_bytes = 75 [default = "world"]; +inline bool TestAllTypesLite::has_default_bytes() const { + return (_has_bits_[1] & 0x40000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_bytes() { + _has_bits_[1] |= 0x40000000u; +} +inline void TestAllTypesLite::clear_has_default_bytes() { + _has_bits_[1] &= ~0x40000000u; +} +inline void TestAllTypesLite::clear_default_bytes() { + if (default_bytes_ != &_default_default_bytes_) { + default_bytes_->assign(_default_default_bytes_); + } + clear_has_default_bytes(); +} +inline const ::std::string& TestAllTypesLite::default_bytes() const { + return *default_bytes_; +} +inline void TestAllTypesLite::set_default_bytes(const ::std::string& value) { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string; + } + default_bytes_->assign(value); +} +inline void TestAllTypesLite::set_default_bytes(const char* value) { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string; + } + default_bytes_->assign(value); +} +inline void TestAllTypesLite::set_default_bytes(const void* value, size_t size) { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string; + } + default_bytes_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_default_bytes() { + set_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + default_bytes_ = new ::std::string(_default_default_bytes_); + } + return default_bytes_; +} +inline ::std::string* TestAllTypesLite::release_default_bytes() { + clear_has_default_bytes(); + if (default_bytes_ == &_default_default_bytes_) { + return NULL; + } else { + ::std::string* temp = default_bytes_; + default_bytes_ = const_cast< ::std::string*>(&_default_default_bytes_); + return temp; + } +} + +// optional .protobuf_unittest.TestAllTypesLite.NestedEnum default_nested_enum = 81 [default = BAR]; +inline bool TestAllTypesLite::has_default_nested_enum() const { + return (_has_bits_[1] & 0x80000000u) != 0; +} +inline void TestAllTypesLite::set_has_default_nested_enum() { + _has_bits_[1] |= 0x80000000u; +} +inline void TestAllTypesLite::clear_has_default_nested_enum() { + _has_bits_[1] &= ~0x80000000u; +} +inline void TestAllTypesLite::clear_default_nested_enum() { + default_nested_enum_ = 2; + clear_has_default_nested_enum(); +} +inline ::protobuf_unittest::TestAllTypesLite_NestedEnum TestAllTypesLite::default_nested_enum() const { + return static_cast< ::protobuf_unittest::TestAllTypesLite_NestedEnum >(default_nested_enum_); +} +inline void TestAllTypesLite::set_default_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value) { + GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); + set_has_default_nested_enum(); + default_nested_enum_ = value; +} + +// optional .protobuf_unittest.ForeignEnumLite default_foreign_enum = 82 [default = FOREIGN_LITE_BAR]; +inline bool TestAllTypesLite::has_default_foreign_enum() const { + return (_has_bits_[2] & 0x00000001u) != 0; +} +inline void TestAllTypesLite::set_has_default_foreign_enum() { + _has_bits_[2] |= 0x00000001u; +} +inline void TestAllTypesLite::clear_has_default_foreign_enum() { + _has_bits_[2] &= ~0x00000001u; +} +inline void TestAllTypesLite::clear_default_foreign_enum() { + default_foreign_enum_ = 5; + clear_has_default_foreign_enum(); +} +inline protobuf_unittest::ForeignEnumLite TestAllTypesLite::default_foreign_enum() const { + return static_cast< protobuf_unittest::ForeignEnumLite >(default_foreign_enum_); +} +inline void TestAllTypesLite::set_default_foreign_enum(protobuf_unittest::ForeignEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); + set_has_default_foreign_enum(); + default_foreign_enum_ = value; +} + +// optional .protobuf_unittest_import.ImportEnumLite default_import_enum = 83 [default = IMPORT_LITE_BAR]; +inline bool TestAllTypesLite::has_default_import_enum() const { + return (_has_bits_[2] & 0x00000002u) != 0; +} +inline void TestAllTypesLite::set_has_default_import_enum() { + _has_bits_[2] |= 0x00000002u; +} +inline void TestAllTypesLite::clear_has_default_import_enum() { + _has_bits_[2] &= ~0x00000002u; +} +inline void TestAllTypesLite::clear_default_import_enum() { + default_import_enum_ = 8; + clear_has_default_import_enum(); +} +inline protobuf_unittest_import::ImportEnumLite TestAllTypesLite::default_import_enum() const { + return static_cast< protobuf_unittest_import::ImportEnumLite >(default_import_enum_); +} +inline void TestAllTypesLite::set_default_import_enum(protobuf_unittest_import::ImportEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); + set_has_default_import_enum(); + default_import_enum_ = value; +} + +// optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; +inline bool TestAllTypesLite::has_default_string_piece() const { + return (_has_bits_[2] & 0x00000004u) != 0; +} +inline void TestAllTypesLite::set_has_default_string_piece() { + _has_bits_[2] |= 0x00000004u; +} +inline void TestAllTypesLite::clear_has_default_string_piece() { + _has_bits_[2] &= ~0x00000004u; +} +inline void TestAllTypesLite::clear_default_string_piece() { + if (default_string_piece_ != &_default_default_string_piece_) { + default_string_piece_->assign(_default_default_string_piece_); + } + clear_has_default_string_piece(); +} +inline const ::std::string& TestAllTypesLite::default_string_piece() const { + return *default_string_piece_; +} +inline void TestAllTypesLite::set_default_string_piece(const ::std::string& value) { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string; + } + default_string_piece_->assign(value); +} +inline void TestAllTypesLite::set_default_string_piece(const char* value) { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string; + } + default_string_piece_->assign(value); +} +inline void TestAllTypesLite::set_default_string_piece(const char* value, size_t size) { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string; + } + default_string_piece_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_default_string_piece() { + set_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + default_string_piece_ = new ::std::string(_default_default_string_piece_); + } + return default_string_piece_; +} +inline ::std::string* TestAllTypesLite::release_default_string_piece() { + clear_has_default_string_piece(); + if (default_string_piece_ == &_default_default_string_piece_) { + return NULL; + } else { + ::std::string* temp = default_string_piece_; + default_string_piece_ = const_cast< ::std::string*>(&_default_default_string_piece_); + return temp; + } +} + +// optional string default_cord = 85 [default = "123", ctype = CORD]; +inline bool TestAllTypesLite::has_default_cord() const { + return (_has_bits_[2] & 0x00000008u) != 0; +} +inline void TestAllTypesLite::set_has_default_cord() { + _has_bits_[2] |= 0x00000008u; +} +inline void TestAllTypesLite::clear_has_default_cord() { + _has_bits_[2] &= ~0x00000008u; +} +inline void TestAllTypesLite::clear_default_cord() { + if (default_cord_ != &_default_default_cord_) { + default_cord_->assign(_default_default_cord_); + } + clear_has_default_cord(); +} +inline const ::std::string& TestAllTypesLite::default_cord() const { + return *default_cord_; +} +inline void TestAllTypesLite::set_default_cord(const ::std::string& value) { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string; + } + default_cord_->assign(value); +} +inline void TestAllTypesLite::set_default_cord(const char* value) { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string; + } + default_cord_->assign(value); +} +inline void TestAllTypesLite::set_default_cord(const char* value, size_t size) { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string; + } + default_cord_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestAllTypesLite::mutable_default_cord() { + set_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + default_cord_ = new ::std::string(_default_default_cord_); + } + return default_cord_; +} +inline ::std::string* TestAllTypesLite::release_default_cord() { + clear_has_default_cord(); + if (default_cord_ == &_default_default_cord_) { + return NULL; + } else { + ::std::string* temp = default_cord_; + default_cord_ = const_cast< ::std::string*>(&_default_default_cord_); + return temp; + } +} + +// ------------------------------------------------------------------- + +// ForeignMessageLite + +// optional int32 c = 1; +inline bool ForeignMessageLite::has_c() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void ForeignMessageLite::set_has_c() { + _has_bits_[0] |= 0x00000001u; +} +inline void ForeignMessageLite::clear_has_c() { + _has_bits_[0] &= ~0x00000001u; +} +inline void ForeignMessageLite::clear_c() { + c_ = 0; + clear_has_c(); +} +inline ::google::protobuf::int32 ForeignMessageLite::c() const { + return c_; +} +inline void ForeignMessageLite::set_c(::google::protobuf::int32 value) { + set_has_c(); + c_ = value; +} + +// ------------------------------------------------------------------- + +// TestPackedTypesLite + +// repeated int32 packed_int32 = 90 [packed = true]; +inline int TestPackedTypesLite::packed_int32_size() const { + return packed_int32_.size(); +} +inline void TestPackedTypesLite::clear_packed_int32() { + packed_int32_.Clear(); +} +inline ::google::protobuf::int32 TestPackedTypesLite::packed_int32(int index) const { + return packed_int32_.Get(index); +} +inline void TestPackedTypesLite::set_packed_int32(int index, ::google::protobuf::int32 value) { + packed_int32_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_int32(::google::protobuf::int32 value) { + packed_int32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestPackedTypesLite::packed_int32() const { + return packed_int32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestPackedTypesLite::mutable_packed_int32() { + return &packed_int32_; +} + +// repeated int64 packed_int64 = 91 [packed = true]; +inline int TestPackedTypesLite::packed_int64_size() const { + return packed_int64_.size(); +} +inline void TestPackedTypesLite::clear_packed_int64() { + packed_int64_.Clear(); +} +inline ::google::protobuf::int64 TestPackedTypesLite::packed_int64(int index) const { + return packed_int64_.Get(index); +} +inline void TestPackedTypesLite::set_packed_int64(int index, ::google::protobuf::int64 value) { + packed_int64_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_int64(::google::protobuf::int64 value) { + packed_int64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestPackedTypesLite::packed_int64() const { + return packed_int64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestPackedTypesLite::mutable_packed_int64() { + return &packed_int64_; +} + +// repeated uint32 packed_uint32 = 92 [packed = true]; +inline int TestPackedTypesLite::packed_uint32_size() const { + return packed_uint32_.size(); +} +inline void TestPackedTypesLite::clear_packed_uint32() { + packed_uint32_.Clear(); +} +inline ::google::protobuf::uint32 TestPackedTypesLite::packed_uint32(int index) const { + return packed_uint32_.Get(index); +} +inline void TestPackedTypesLite::set_packed_uint32(int index, ::google::protobuf::uint32 value) { + packed_uint32_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_uint32(::google::protobuf::uint32 value) { + packed_uint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestPackedTypesLite::packed_uint32() const { + return packed_uint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestPackedTypesLite::mutable_packed_uint32() { + return &packed_uint32_; +} + +// repeated uint64 packed_uint64 = 93 [packed = true]; +inline int TestPackedTypesLite::packed_uint64_size() const { + return packed_uint64_.size(); +} +inline void TestPackedTypesLite::clear_packed_uint64() { + packed_uint64_.Clear(); +} +inline ::google::protobuf::uint64 TestPackedTypesLite::packed_uint64(int index) const { + return packed_uint64_.Get(index); +} +inline void TestPackedTypesLite::set_packed_uint64(int index, ::google::protobuf::uint64 value) { + packed_uint64_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_uint64(::google::protobuf::uint64 value) { + packed_uint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestPackedTypesLite::packed_uint64() const { + return packed_uint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestPackedTypesLite::mutable_packed_uint64() { + return &packed_uint64_; +} + +// repeated sint32 packed_sint32 = 94 [packed = true]; +inline int TestPackedTypesLite::packed_sint32_size() const { + return packed_sint32_.size(); +} +inline void TestPackedTypesLite::clear_packed_sint32() { + packed_sint32_.Clear(); +} +inline ::google::protobuf::int32 TestPackedTypesLite::packed_sint32(int index) const { + return packed_sint32_.Get(index); +} +inline void TestPackedTypesLite::set_packed_sint32(int index, ::google::protobuf::int32 value) { + packed_sint32_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_sint32(::google::protobuf::int32 value) { + packed_sint32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestPackedTypesLite::packed_sint32() const { + return packed_sint32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestPackedTypesLite::mutable_packed_sint32() { + return &packed_sint32_; +} + +// repeated sint64 packed_sint64 = 95 [packed = true]; +inline int TestPackedTypesLite::packed_sint64_size() const { + return packed_sint64_.size(); +} +inline void TestPackedTypesLite::clear_packed_sint64() { + packed_sint64_.Clear(); +} +inline ::google::protobuf::int64 TestPackedTypesLite::packed_sint64(int index) const { + return packed_sint64_.Get(index); +} +inline void TestPackedTypesLite::set_packed_sint64(int index, ::google::protobuf::int64 value) { + packed_sint64_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_sint64(::google::protobuf::int64 value) { + packed_sint64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestPackedTypesLite::packed_sint64() const { + return packed_sint64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestPackedTypesLite::mutable_packed_sint64() { + return &packed_sint64_; +} + +// repeated fixed32 packed_fixed32 = 96 [packed = true]; +inline int TestPackedTypesLite::packed_fixed32_size() const { + return packed_fixed32_.size(); +} +inline void TestPackedTypesLite::clear_packed_fixed32() { + packed_fixed32_.Clear(); +} +inline ::google::protobuf::uint32 TestPackedTypesLite::packed_fixed32(int index) const { + return packed_fixed32_.Get(index); +} +inline void TestPackedTypesLite::set_packed_fixed32(int index, ::google::protobuf::uint32 value) { + packed_fixed32_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_fixed32(::google::protobuf::uint32 value) { + packed_fixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& +TestPackedTypesLite::packed_fixed32() const { + return packed_fixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* +TestPackedTypesLite::mutable_packed_fixed32() { + return &packed_fixed32_; +} + +// repeated fixed64 packed_fixed64 = 97 [packed = true]; +inline int TestPackedTypesLite::packed_fixed64_size() const { + return packed_fixed64_.size(); +} +inline void TestPackedTypesLite::clear_packed_fixed64() { + packed_fixed64_.Clear(); +} +inline ::google::protobuf::uint64 TestPackedTypesLite::packed_fixed64(int index) const { + return packed_fixed64_.Get(index); +} +inline void TestPackedTypesLite::set_packed_fixed64(int index, ::google::protobuf::uint64 value) { + packed_fixed64_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_fixed64(::google::protobuf::uint64 value) { + packed_fixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& +TestPackedTypesLite::packed_fixed64() const { + return packed_fixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* +TestPackedTypesLite::mutable_packed_fixed64() { + return &packed_fixed64_; +} + +// repeated sfixed32 packed_sfixed32 = 98 [packed = true]; +inline int TestPackedTypesLite::packed_sfixed32_size() const { + return packed_sfixed32_.size(); +} +inline void TestPackedTypesLite::clear_packed_sfixed32() { + packed_sfixed32_.Clear(); +} +inline ::google::protobuf::int32 TestPackedTypesLite::packed_sfixed32(int index) const { + return packed_sfixed32_.Get(index); +} +inline void TestPackedTypesLite::set_packed_sfixed32(int index, ::google::protobuf::int32 value) { + packed_sfixed32_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_sfixed32(::google::protobuf::int32 value) { + packed_sfixed32_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +TestPackedTypesLite::packed_sfixed32() const { + return packed_sfixed32_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +TestPackedTypesLite::mutable_packed_sfixed32() { + return &packed_sfixed32_; +} + +// repeated sfixed64 packed_sfixed64 = 99 [packed = true]; +inline int TestPackedTypesLite::packed_sfixed64_size() const { + return packed_sfixed64_.size(); +} +inline void TestPackedTypesLite::clear_packed_sfixed64() { + packed_sfixed64_.Clear(); +} +inline ::google::protobuf::int64 TestPackedTypesLite::packed_sfixed64(int index) const { + return packed_sfixed64_.Get(index); +} +inline void TestPackedTypesLite::set_packed_sfixed64(int index, ::google::protobuf::int64 value) { + packed_sfixed64_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_sfixed64(::google::protobuf::int64 value) { + packed_sfixed64_.Add(value); +} +inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& +TestPackedTypesLite::packed_sfixed64() const { + return packed_sfixed64_; +} +inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* +TestPackedTypesLite::mutable_packed_sfixed64() { + return &packed_sfixed64_; +} + +// repeated float packed_float = 100 [packed = true]; +inline int TestPackedTypesLite::packed_float_size() const { + return packed_float_.size(); +} +inline void TestPackedTypesLite::clear_packed_float() { + packed_float_.Clear(); +} +inline float TestPackedTypesLite::packed_float(int index) const { + return packed_float_.Get(index); +} +inline void TestPackedTypesLite::set_packed_float(int index, float value) { + packed_float_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_float(float value) { + packed_float_.Add(value); +} +inline const ::google::protobuf::RepeatedField< float >& +TestPackedTypesLite::packed_float() const { + return packed_float_; +} +inline ::google::protobuf::RepeatedField< float >* +TestPackedTypesLite::mutable_packed_float() { + return &packed_float_; +} + +// repeated double packed_double = 101 [packed = true]; +inline int TestPackedTypesLite::packed_double_size() const { + return packed_double_.size(); +} +inline void TestPackedTypesLite::clear_packed_double() { + packed_double_.Clear(); +} +inline double TestPackedTypesLite::packed_double(int index) const { + return packed_double_.Get(index); +} +inline void TestPackedTypesLite::set_packed_double(int index, double value) { + packed_double_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_double(double value) { + packed_double_.Add(value); +} +inline const ::google::protobuf::RepeatedField< double >& +TestPackedTypesLite::packed_double() const { + return packed_double_; +} +inline ::google::protobuf::RepeatedField< double >* +TestPackedTypesLite::mutable_packed_double() { + return &packed_double_; +} + +// repeated bool packed_bool = 102 [packed = true]; +inline int TestPackedTypesLite::packed_bool_size() const { + return packed_bool_.size(); +} +inline void TestPackedTypesLite::clear_packed_bool() { + packed_bool_.Clear(); +} +inline bool TestPackedTypesLite::packed_bool(int index) const { + return packed_bool_.Get(index); +} +inline void TestPackedTypesLite::set_packed_bool(int index, bool value) { + packed_bool_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_bool(bool value) { + packed_bool_.Add(value); +} +inline const ::google::protobuf::RepeatedField< bool >& +TestPackedTypesLite::packed_bool() const { + return packed_bool_; +} +inline ::google::protobuf::RepeatedField< bool >* +TestPackedTypesLite::mutable_packed_bool() { + return &packed_bool_; +} + +// repeated .protobuf_unittest.ForeignEnumLite packed_enum = 103 [packed = true]; +inline int TestPackedTypesLite::packed_enum_size() const { + return packed_enum_.size(); +} +inline void TestPackedTypesLite::clear_packed_enum() { + packed_enum_.Clear(); +} +inline protobuf_unittest::ForeignEnumLite TestPackedTypesLite::packed_enum(int index) const { + return static_cast< protobuf_unittest::ForeignEnumLite >(packed_enum_.Get(index)); +} +inline void TestPackedTypesLite::set_packed_enum(int index, protobuf_unittest::ForeignEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); + packed_enum_.Set(index, value); +} +inline void TestPackedTypesLite::add_packed_enum(protobuf_unittest::ForeignEnumLite value) { + GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); + packed_enum_.Add(value); +} +inline const ::google::protobuf::RepeatedField& +TestPackedTypesLite::packed_enum() const { + return packed_enum_; +} +inline ::google::protobuf::RepeatedField* +TestPackedTypesLite::mutable_packed_enum() { + return &packed_enum_; +} + +// ------------------------------------------------------------------- + +// TestAllExtensionsLite + +// ------------------------------------------------------------------- + +// OptionalGroup_extension_lite + +// optional int32 a = 17; +inline bool OptionalGroup_extension_lite::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void OptionalGroup_extension_lite::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void OptionalGroup_extension_lite::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void OptionalGroup_extension_lite::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 OptionalGroup_extension_lite::a() const { + return a_; +} +inline void OptionalGroup_extension_lite::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// RepeatedGroup_extension_lite + +// optional int32 a = 47; +inline bool RepeatedGroup_extension_lite::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void RepeatedGroup_extension_lite::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void RepeatedGroup_extension_lite::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void RepeatedGroup_extension_lite::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 RepeatedGroup_extension_lite::a() const { + return a_; +} +inline void RepeatedGroup_extension_lite::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + +// ------------------------------------------------------------------- + +// TestPackedExtensionsLite + +// ------------------------------------------------------------------- + +// TestNestedExtensionLite + +// ------------------------------------------------------------------- + +// TestDeprecatedLite + +// optional int32 deprecated_field = 1 [deprecated = true]; +inline bool TestDeprecatedLite::has_deprecated_field() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestDeprecatedLite::set_has_deprecated_field() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestDeprecatedLite::clear_has_deprecated_field() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestDeprecatedLite::clear_deprecated_field() { + deprecated_field_ = 0; + clear_has_deprecated_field(); +} +inline ::google::protobuf::int32 TestDeprecatedLite::deprecated_field() const { + return deprecated_field_; +} +inline void TestDeprecatedLite::set_deprecated_field(::google::protobuf::int32 value) { + set_has_deprecated_field(); + deprecated_field_ = value; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5flite_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h new file mode 100644 index 00000000..dceddcec --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h @@ -0,0 +1,150 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_lite_imports_nonlite.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include "google/protobuf/unittest.pb.h" +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); + +class TestLiteImportsNonlite; + +// =================================================================== + +class TestLiteImportsNonlite : public ::google::protobuf::MessageLite { + public: + TestLiteImportsNonlite(); + virtual ~TestLiteImportsNonlite(); + + TestLiteImportsNonlite(const TestLiteImportsNonlite& from); + + inline TestLiteImportsNonlite& operator=(const TestLiteImportsNonlite& from) { + CopyFrom(from); + return *this; + } + + static const TestLiteImportsNonlite& default_instance(); + + void Swap(TestLiteImportsNonlite* other); + + // implements Message ---------------------------------------------- + + TestLiteImportsNonlite* New() const; + void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); + void CopyFrom(const TestLiteImportsNonlite& from); + void MergeFrom(const TestLiteImportsNonlite& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::std::string GetTypeName() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestAllTypes message = 1; + inline bool has_message() const; + inline void clear_message(); + static const int kMessageFieldNumber = 1; + inline const ::protobuf_unittest::TestAllTypes& message() const; + inline ::protobuf_unittest::TestAllTypes* mutable_message(); + inline ::protobuf_unittest::TestAllTypes* release_message(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestLiteImportsNonlite) + private: + inline void set_has_message(); + inline void clear_has_message(); + + ::protobuf_unittest::TestAllTypes* message_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); + + void InitAsDefaultInstance(); + static TestLiteImportsNonlite* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// TestLiteImportsNonlite + +// optional .protobuf_unittest.TestAllTypes message = 1; +inline bool TestLiteImportsNonlite::has_message() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestLiteImportsNonlite::set_has_message() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestLiteImportsNonlite::clear_has_message() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestLiteImportsNonlite::clear_message() { + if (message_ != NULL) message_->::protobuf_unittest::TestAllTypes::Clear(); + clear_has_message(); +} +inline const ::protobuf_unittest::TestAllTypes& TestLiteImportsNonlite::message() const { + return message_ != NULL ? *message_ : *default_instance_->message_; +} +inline ::protobuf_unittest::TestAllTypes* TestLiteImportsNonlite::mutable_message() { + set_has_message(); + if (message_ == NULL) message_ = new ::protobuf_unittest::TestAllTypes; + return message_; +} +inline ::protobuf_unittest::TestAllTypes* TestLiteImportsNonlite::release_message() { + clear_has_message(); + ::protobuf_unittest::TestAllTypes* temp = message_; + message_ = NULL; + return temp; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h new file mode 100644 index 00000000..9bf04902 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h @@ -0,0 +1,816 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_mset.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fmset_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5fmset_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); + +class TestMessageSet; +class TestMessageSetContainer; +class TestMessageSetExtension1; +class TestMessageSetExtension2; +class RawMessageSet; +class RawMessageSet_Item; + +// =================================================================== + +class TestMessageSet : public ::google::protobuf::Message { + public: + TestMessageSet(); + virtual ~TestMessageSet(); + + TestMessageSet(const TestMessageSet& from); + + inline TestMessageSet& operator=(const TestMessageSet& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMessageSet& default_instance(); + + void Swap(TestMessageSet* other); + + // implements Message ---------------------------------------------- + + TestMessageSet* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMessageSet& from); + void MergeFrom(const TestMessageSet& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestMessageSet) + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSet) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[1]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); + + void InitAsDefaultInstance(); + static TestMessageSet* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestMessageSetContainer : public ::google::protobuf::Message { + public: + TestMessageSetContainer(); + virtual ~TestMessageSetContainer(); + + TestMessageSetContainer(const TestMessageSetContainer& from); + + inline TestMessageSetContainer& operator=(const TestMessageSetContainer& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMessageSetContainer& default_instance(); + + void Swap(TestMessageSetContainer* other); + + // implements Message ---------------------------------------------- + + TestMessageSetContainer* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMessageSetContainer& from); + void MergeFrom(const TestMessageSetContainer& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestMessageSet message_set = 1; + inline bool has_message_set() const; + inline void clear_message_set(); + static const int kMessageSetFieldNumber = 1; + inline const ::protobuf_unittest::TestMessageSet& message_set() const; + inline ::protobuf_unittest::TestMessageSet* mutable_message_set(); + inline ::protobuf_unittest::TestMessageSet* release_message_set(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSetContainer) + private: + inline void set_has_message_set(); + inline void clear_has_message_set(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestMessageSet* message_set_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); + + void InitAsDefaultInstance(); + static TestMessageSetContainer* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestMessageSetExtension1 : public ::google::protobuf::Message { + public: + TestMessageSetExtension1(); + virtual ~TestMessageSetExtension1(); + + TestMessageSetExtension1(const TestMessageSetExtension1& from); + + inline TestMessageSetExtension1& operator=(const TestMessageSetExtension1& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMessageSetExtension1& default_instance(); + + void Swap(TestMessageSetExtension1* other); + + // implements Message ---------------------------------------------- + + TestMessageSetExtension1* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMessageSetExtension1& from); + void MergeFrom(const TestMessageSetExtension1& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 i = 15; + inline bool has_i() const; + inline void clear_i(); + static const int kIFieldNumber = 15; + inline ::google::protobuf::int32 i() const; + inline void set_i(::google::protobuf::int32 value); + + static const int kMessageSetExtensionFieldNumber = 1545008; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestMessageSet, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestMessageSetExtension1 >, 11, false > + message_set_extension; + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSetExtension1) + private: + inline void set_has_i(); + inline void clear_has_i(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 i_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); + + void InitAsDefaultInstance(); + static TestMessageSetExtension1* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestMessageSetExtension2 : public ::google::protobuf::Message { + public: + TestMessageSetExtension2(); + virtual ~TestMessageSetExtension2(); + + TestMessageSetExtension2(const TestMessageSetExtension2& from); + + inline TestMessageSetExtension2& operator=(const TestMessageSetExtension2& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMessageSetExtension2& default_instance(); + + void Swap(TestMessageSetExtension2* other); + + // implements Message ---------------------------------------------- + + TestMessageSetExtension2* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMessageSetExtension2& from); + void MergeFrom(const TestMessageSetExtension2& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string str = 25; + inline bool has_str() const; + inline void clear_str(); + static const int kStrFieldNumber = 25; + inline const ::std::string& str() const; + inline void set_str(const ::std::string& value); + inline void set_str(const char* value); + inline void set_str(const char* value, size_t size); + inline ::std::string* mutable_str(); + inline ::std::string* release_str(); + + static const int kMessageSetExtensionFieldNumber = 1547769; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestMessageSet, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestMessageSetExtension2 >, 11, false > + message_set_extension; + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSetExtension2) + private: + inline void set_has_str(); + inline void clear_has_str(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* str_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); + + void InitAsDefaultInstance(); + static TestMessageSetExtension2* default_instance_; +}; +// ------------------------------------------------------------------- + +class RawMessageSet_Item : public ::google::protobuf::Message { + public: + RawMessageSet_Item(); + virtual ~RawMessageSet_Item(); + + RawMessageSet_Item(const RawMessageSet_Item& from); + + inline RawMessageSet_Item& operator=(const RawMessageSet_Item& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const RawMessageSet_Item& default_instance(); + + void Swap(RawMessageSet_Item* other); + + // implements Message ---------------------------------------------- + + RawMessageSet_Item* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const RawMessageSet_Item& from); + void MergeFrom(const RawMessageSet_Item& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // required int32 type_id = 2; + inline bool has_type_id() const; + inline void clear_type_id(); + static const int kTypeIdFieldNumber = 2; + inline ::google::protobuf::int32 type_id() const; + inline void set_type_id(::google::protobuf::int32 value); + + // required bytes message = 3; + inline bool has_message() const; + inline void clear_message(); + static const int kMessageFieldNumber = 3; + inline const ::std::string& message() const; + inline void set_message(const ::std::string& value); + inline void set_message(const char* value); + inline void set_message(const void* value, size_t size); + inline ::std::string* mutable_message(); + inline ::std::string* release_message(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.RawMessageSet.Item) + private: + inline void set_has_type_id(); + inline void clear_has_type_id(); + inline void set_has_message(); + inline void clear_has_message(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* message_; + ::google::protobuf::int32 type_id_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); + + void InitAsDefaultInstance(); + static RawMessageSet_Item* default_instance_; +}; +// ------------------------------------------------------------------- + +class RawMessageSet : public ::google::protobuf::Message { + public: + RawMessageSet(); + virtual ~RawMessageSet(); + + RawMessageSet(const RawMessageSet& from); + + inline RawMessageSet& operator=(const RawMessageSet& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const RawMessageSet& default_instance(); + + void Swap(RawMessageSet* other); + + // implements Message ---------------------------------------------- + + RawMessageSet* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const RawMessageSet& from); + void MergeFrom(const RawMessageSet& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef RawMessageSet_Item Item; + + // accessors ------------------------------------------------------- + + // repeated group Item = 1 { + inline int item_size() const; + inline void clear_item(); + static const int kItemFieldNumber = 1; + inline const ::protobuf_unittest::RawMessageSet_Item& item(int index) const; + inline ::protobuf_unittest::RawMessageSet_Item* mutable_item(int index); + inline ::protobuf_unittest::RawMessageSet_Item* add_item(); + inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >& + item() const; + inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >* + mutable_item(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.RawMessageSet) + private: + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item > item_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); + + void InitAsDefaultInstance(); + static RawMessageSet* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// TestMessageSet + +// ------------------------------------------------------------------- + +// TestMessageSetContainer + +// optional .protobuf_unittest.TestMessageSet message_set = 1; +inline bool TestMessageSetContainer::has_message_set() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestMessageSetContainer::set_has_message_set() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestMessageSetContainer::clear_has_message_set() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestMessageSetContainer::clear_message_set() { + if (message_set_ != NULL) message_set_->::protobuf_unittest::TestMessageSet::Clear(); + clear_has_message_set(); +} +inline const ::protobuf_unittest::TestMessageSet& TestMessageSetContainer::message_set() const { + return message_set_ != NULL ? *message_set_ : *default_instance_->message_set_; +} +inline ::protobuf_unittest::TestMessageSet* TestMessageSetContainer::mutable_message_set() { + set_has_message_set(); + if (message_set_ == NULL) message_set_ = new ::protobuf_unittest::TestMessageSet; + return message_set_; +} +inline ::protobuf_unittest::TestMessageSet* TestMessageSetContainer::release_message_set() { + clear_has_message_set(); + ::protobuf_unittest::TestMessageSet* temp = message_set_; + message_set_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// TestMessageSetExtension1 + +// optional int32 i = 15; +inline bool TestMessageSetExtension1::has_i() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestMessageSetExtension1::set_has_i() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestMessageSetExtension1::clear_has_i() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestMessageSetExtension1::clear_i() { + i_ = 0; + clear_has_i(); +} +inline ::google::protobuf::int32 TestMessageSetExtension1::i() const { + return i_; +} +inline void TestMessageSetExtension1::set_i(::google::protobuf::int32 value) { + set_has_i(); + i_ = value; +} + +// ------------------------------------------------------------------- + +// TestMessageSetExtension2 + +// optional string str = 25; +inline bool TestMessageSetExtension2::has_str() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestMessageSetExtension2::set_has_str() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestMessageSetExtension2::clear_has_str() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestMessageSetExtension2::clear_str() { + if (str_ != &::google::protobuf::internal::kEmptyString) { + str_->clear(); + } + clear_has_str(); +} +inline const ::std::string& TestMessageSetExtension2::str() const { + return *str_; +} +inline void TestMessageSetExtension2::set_str(const ::std::string& value) { + set_has_str(); + if (str_ == &::google::protobuf::internal::kEmptyString) { + str_ = new ::std::string; + } + str_->assign(value); +} +inline void TestMessageSetExtension2::set_str(const char* value) { + set_has_str(); + if (str_ == &::google::protobuf::internal::kEmptyString) { + str_ = new ::std::string; + } + str_->assign(value); +} +inline void TestMessageSetExtension2::set_str(const char* value, size_t size) { + set_has_str(); + if (str_ == &::google::protobuf::internal::kEmptyString) { + str_ = new ::std::string; + } + str_->assign(reinterpret_cast(value), size); +} +inline ::std::string* TestMessageSetExtension2::mutable_str() { + set_has_str(); + if (str_ == &::google::protobuf::internal::kEmptyString) { + str_ = new ::std::string; + } + return str_; +} +inline ::std::string* TestMessageSetExtension2::release_str() { + clear_has_str(); + if (str_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = str_; + str_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// RawMessageSet_Item + +// required int32 type_id = 2; +inline bool RawMessageSet_Item::has_type_id() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void RawMessageSet_Item::set_has_type_id() { + _has_bits_[0] |= 0x00000001u; +} +inline void RawMessageSet_Item::clear_has_type_id() { + _has_bits_[0] &= ~0x00000001u; +} +inline void RawMessageSet_Item::clear_type_id() { + type_id_ = 0; + clear_has_type_id(); +} +inline ::google::protobuf::int32 RawMessageSet_Item::type_id() const { + return type_id_; +} +inline void RawMessageSet_Item::set_type_id(::google::protobuf::int32 value) { + set_has_type_id(); + type_id_ = value; +} + +// required bytes message = 3; +inline bool RawMessageSet_Item::has_message() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void RawMessageSet_Item::set_has_message() { + _has_bits_[0] |= 0x00000002u; +} +inline void RawMessageSet_Item::clear_has_message() { + _has_bits_[0] &= ~0x00000002u; +} +inline void RawMessageSet_Item::clear_message() { + if (message_ != &::google::protobuf::internal::kEmptyString) { + message_->clear(); + } + clear_has_message(); +} +inline const ::std::string& RawMessageSet_Item::message() const { + return *message_; +} +inline void RawMessageSet_Item::set_message(const ::std::string& value) { + set_has_message(); + if (message_ == &::google::protobuf::internal::kEmptyString) { + message_ = new ::std::string; + } + message_->assign(value); +} +inline void RawMessageSet_Item::set_message(const char* value) { + set_has_message(); + if (message_ == &::google::protobuf::internal::kEmptyString) { + message_ = new ::std::string; + } + message_->assign(value); +} +inline void RawMessageSet_Item::set_message(const void* value, size_t size) { + set_has_message(); + if (message_ == &::google::protobuf::internal::kEmptyString) { + message_ = new ::std::string; + } + message_->assign(reinterpret_cast(value), size); +} +inline ::std::string* RawMessageSet_Item::mutable_message() { + set_has_message(); + if (message_ == &::google::protobuf::internal::kEmptyString) { + message_ = new ::std::string; + } + return message_; +} +inline ::std::string* RawMessageSet_Item::release_message() { + clear_has_message(); + if (message_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = message_; + message_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } +} + +// ------------------------------------------------------------------- + +// RawMessageSet + +// repeated group Item = 1 { +inline int RawMessageSet::item_size() const { + return item_.size(); +} +inline void RawMessageSet::clear_item() { + item_.Clear(); +} +inline const ::protobuf_unittest::RawMessageSet_Item& RawMessageSet::item(int index) const { + return item_.Get(index); +} +inline ::protobuf_unittest::RawMessageSet_Item* RawMessageSet::mutable_item(int index) { + return item_.Mutable(index); +} +inline ::protobuf_unittest::RawMessageSet_Item* RawMessageSet::add_item() { + return item_.Add(); +} +inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >& +RawMessageSet::item() const { + return item_; +} +inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >* +RawMessageSet::mutable_item() { + return &item_; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +#ifndef SWIG +namespace google { +namespace protobuf { + + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5fmset_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h new file mode 100644 index 00000000..b2afc88f --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h @@ -0,0 +1,197 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_no_generic_services.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace google { +namespace protobuf { +namespace no_generic_services_test { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); + +class TestMessage; + +enum TestEnum { + FOO = 1 +}; +bool TestEnum_IsValid(int value); +const TestEnum TestEnum_MIN = FOO; +const TestEnum TestEnum_MAX = FOO; +const int TestEnum_ARRAYSIZE = TestEnum_MAX + 1; + +const ::google::protobuf::EnumDescriptor* TestEnum_descriptor(); +inline const ::std::string& TestEnum_Name(TestEnum value) { + return ::google::protobuf::internal::NameOfEnum( + TestEnum_descriptor(), value); +} +inline bool TestEnum_Parse( + const ::std::string& name, TestEnum* value) { + return ::google::protobuf::internal::ParseNamedEnum( + TestEnum_descriptor(), name, value); +} +// =================================================================== + +class TestMessage : public ::google::protobuf::Message { + public: + TestMessage(); + virtual ~TestMessage(); + + TestMessage(const TestMessage& from); + + inline TestMessage& operator=(const TestMessage& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestMessage& default_instance(); + + void Swap(TestMessage* other); + + // implements Message ---------------------------------------------- + + TestMessage* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const TestMessage& from); + void MergeFrom(const TestMessage& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 a = 1; + inline bool has_a() const; + inline void clear_a(); + static const int kAFieldNumber = 1; + inline ::google::protobuf::int32 a() const; + inline void set_a(::google::protobuf::int32 value); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestMessage) + // @@protoc_insertion_point(class_scope:google.protobuf.no_generic_services_test.TestMessage) + private: + inline void set_has_a(); + inline void clear_has_a(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 a_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); + + void InitAsDefaultInstance(); + static TestMessage* default_instance_; +}; +// =================================================================== + +static const int kTestExtensionFieldNumber = 1000; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::no_generic_services_test::TestMessage, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + test_extension; + +// =================================================================== + +// TestMessage + +// optional int32 a = 1; +inline bool TestMessage::has_a() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestMessage::set_has_a() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestMessage::clear_has_a() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestMessage::clear_a() { + a_ = 0; + clear_has_a(); +} +inline ::google::protobuf::int32 TestMessage::a() const { + return a_; +} +inline void TestMessage::set_a(::google::protobuf::int32 value) { + set_has_a(); + a_ = value; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace no_generic_services_test +} // namespace protobuf +} // namespace google + +#ifndef SWIG +namespace google { +namespace protobuf { + +template <> +inline const EnumDescriptor* GetEnumDescriptor< google::protobuf::no_generic_services_test::TestEnum>() { + return google::protobuf::no_generic_services_test::TestEnum_descriptor(); +} + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h new file mode 100644 index 00000000..bcea5ebc --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h @@ -0,0 +1,403 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_optimize_for.proto + +#ifndef PROTOBUF_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 2004000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +#include "google/protobuf/unittest.pb.h" +// @@protoc_insertion_point(includes) + +namespace protobuf_unittest { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); +void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); +void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + +class TestOptimizedForSize; +class TestRequiredOptimizedForSize; +class TestOptionalOptimizedForSize; + +// =================================================================== + +class TestOptimizedForSize : public ::google::protobuf::Message { + public: + TestOptimizedForSize(); + virtual ~TestOptimizedForSize(); + + TestOptimizedForSize(const TestOptimizedForSize& from); + + inline TestOptimizedForSize& operator=(const TestOptimizedForSize& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestOptimizedForSize& default_instance(); + + void Swap(TestOptimizedForSize* other); + + // implements Message ---------------------------------------------- + + TestOptimizedForSize* New() const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 i = 1; + inline bool has_i() const; + inline void clear_i(); + static const int kIFieldNumber = 1; + inline ::google::protobuf::int32 i() const; + inline void set_i(::google::protobuf::int32 value); + + // optional .protobuf_unittest.ForeignMessage msg = 19; + inline bool has_msg() const; + inline void clear_msg(); + static const int kMsgFieldNumber = 19; + inline const ::protobuf_unittest::ForeignMessage& msg() const; + inline ::protobuf_unittest::ForeignMessage* mutable_msg(); + inline ::protobuf_unittest::ForeignMessage* release_msg(); + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestOptimizedForSize) + static const int kTestExtensionFieldNumber = 1234; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestOptimizedForSize, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + test_extension; + static const int kTestExtension2FieldNumber = 1235; + static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestOptimizedForSize, + ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestRequiredOptimizedForSize >, 11, false > + test_extension2; + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestOptimizedForSize) + private: + inline void set_has_i(); + inline void clear_has_i(); + inline void set_has_msg(); + inline void clear_has_msg(); + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::ForeignMessage* msg_; + ::google::protobuf::int32 i_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + + void InitAsDefaultInstance(); + static TestOptimizedForSize* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestRequiredOptimizedForSize : public ::google::protobuf::Message { + public: + TestRequiredOptimizedForSize(); + virtual ~TestRequiredOptimizedForSize(); + + TestRequiredOptimizedForSize(const TestRequiredOptimizedForSize& from); + + inline TestRequiredOptimizedForSize& operator=(const TestRequiredOptimizedForSize& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestRequiredOptimizedForSize& default_instance(); + + void Swap(TestRequiredOptimizedForSize* other); + + // implements Message ---------------------------------------------- + + TestRequiredOptimizedForSize* New() const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // required int32 x = 1; + inline bool has_x() const; + inline void clear_x(); + static const int kXFieldNumber = 1; + inline ::google::protobuf::int32 x() const; + inline void set_x(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRequiredOptimizedForSize) + private: + inline void set_has_x(); + inline void clear_has_x(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::int32 x_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + + void InitAsDefaultInstance(); + static TestRequiredOptimizedForSize* default_instance_; +}; +// ------------------------------------------------------------------- + +class TestOptionalOptimizedForSize : public ::google::protobuf::Message { + public: + TestOptionalOptimizedForSize(); + virtual ~TestOptionalOptimizedForSize(); + + TestOptionalOptimizedForSize(const TestOptionalOptimizedForSize& from); + + inline TestOptionalOptimizedForSize& operator=(const TestOptionalOptimizedForSize& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const TestOptionalOptimizedForSize& default_instance(); + + void Swap(TestOptionalOptimizedForSize* other); + + // implements Message ---------------------------------------------- + + TestOptionalOptimizedForSize* New() const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .protobuf_unittest.TestRequiredOptimizedForSize o = 1; + inline bool has_o() const; + inline void clear_o(); + static const int kOFieldNumber = 1; + inline const ::protobuf_unittest::TestRequiredOptimizedForSize& o() const; + inline ::protobuf_unittest::TestRequiredOptimizedForSize* mutable_o(); + inline ::protobuf_unittest::TestRequiredOptimizedForSize* release_o(); + + // @@protoc_insertion_point(class_scope:protobuf_unittest.TestOptionalOptimizedForSize) + private: + inline void set_has_o(); + inline void clear_has_o(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::protobuf_unittest::TestRequiredOptimizedForSize* o_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + + friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); + + void InitAsDefaultInstance(); + static TestOptionalOptimizedForSize* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// TestOptimizedForSize + +// optional int32 i = 1; +inline bool TestOptimizedForSize::has_i() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestOptimizedForSize::set_has_i() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestOptimizedForSize::clear_has_i() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestOptimizedForSize::clear_i() { + i_ = 0; + clear_has_i(); +} +inline ::google::protobuf::int32 TestOptimizedForSize::i() const { + return i_; +} +inline void TestOptimizedForSize::set_i(::google::protobuf::int32 value) { + set_has_i(); + i_ = value; +} + +// optional .protobuf_unittest.ForeignMessage msg = 19; +inline bool TestOptimizedForSize::has_msg() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void TestOptimizedForSize::set_has_msg() { + _has_bits_[0] |= 0x00000002u; +} +inline void TestOptimizedForSize::clear_has_msg() { + _has_bits_[0] &= ~0x00000002u; +} +inline void TestOptimizedForSize::clear_msg() { + if (msg_ != NULL) msg_->::protobuf_unittest::ForeignMessage::Clear(); + clear_has_msg(); +} +inline const ::protobuf_unittest::ForeignMessage& TestOptimizedForSize::msg() const { + return msg_ != NULL ? *msg_ : *default_instance_->msg_; +} +inline ::protobuf_unittest::ForeignMessage* TestOptimizedForSize::mutable_msg() { + set_has_msg(); + if (msg_ == NULL) msg_ = new ::protobuf_unittest::ForeignMessage; + return msg_; +} +inline ::protobuf_unittest::ForeignMessage* TestOptimizedForSize::release_msg() { + clear_has_msg(); + ::protobuf_unittest::ForeignMessage* temp = msg_; + msg_ = NULL; + return temp; +} + +// ------------------------------------------------------------------- + +// TestRequiredOptimizedForSize + +// required int32 x = 1; +inline bool TestRequiredOptimizedForSize::has_x() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestRequiredOptimizedForSize::set_has_x() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestRequiredOptimizedForSize::clear_has_x() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestRequiredOptimizedForSize::clear_x() { + x_ = 0; + clear_has_x(); +} +inline ::google::protobuf::int32 TestRequiredOptimizedForSize::x() const { + return x_; +} +inline void TestRequiredOptimizedForSize::set_x(::google::protobuf::int32 value) { + set_has_x(); + x_ = value; +} + +// ------------------------------------------------------------------- + +// TestOptionalOptimizedForSize + +// optional .protobuf_unittest.TestRequiredOptimizedForSize o = 1; +inline bool TestOptionalOptimizedForSize::has_o() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void TestOptionalOptimizedForSize::set_has_o() { + _has_bits_[0] |= 0x00000001u; +} +inline void TestOptionalOptimizedForSize::clear_has_o() { + _has_bits_[0] &= ~0x00000001u; +} +inline void TestOptionalOptimizedForSize::clear_o() { + if (o_ != NULL) o_->::protobuf_unittest::TestRequiredOptimizedForSize::Clear(); + clear_has_o(); +} +inline const ::protobuf_unittest::TestRequiredOptimizedForSize& TestOptionalOptimizedForSize::o() const { + return o_ != NULL ? *o_ : *default_instance_->o_; +} +inline ::protobuf_unittest::TestRequiredOptimizedForSize* TestOptionalOptimizedForSize::mutable_o() { + set_has_o(); + if (o_ == NULL) o_ = new ::protobuf_unittest::TestRequiredOptimizedForSize; + return o_; +} +inline ::protobuf_unittest::TestRequiredOptimizedForSize* TestOptionalOptimizedForSize::release_o() { + clear_has_o(); + ::protobuf_unittest::TestRequiredOptimizedForSize* temp = o_; + o_ = NULL; + return temp; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf_unittest + +#ifndef SWIG +namespace google { +namespace protobuf { + + +} // namespace google +} // namespace protobuf +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h b/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h new file mode 100644 index 00000000..84c2e2b6 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h @@ -0,0 +1,268 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// Contains classes used to keep track of unrecognized fields seen while +// parsing a protocol message. + +#ifndef GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ +#define GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { + +class Message; // message.h +class UnknownField; // below + +// An UnknownFieldSet contains fields that were encountered while parsing a +// message but were not defined by its type. Keeping track of these can be +// useful, especially in that they may be written if the message is serialized +// again without being cleared in between. This means that software which +// simply receives messages and forwards them to other servers does not need +// to be updated every time a new field is added to the message definition. +// +// To get the UnknownFieldSet attached to any message, call +// Reflection::GetUnknownFields(). +// +// This class is necessarily tied to the protocol buffer wire format, unlike +// the Reflection interface which is independent of any serialization scheme. +class LIBPROTOBUF_EXPORT UnknownFieldSet { + public: + UnknownFieldSet(); + ~UnknownFieldSet(); + + // Remove all fields. + inline void Clear(); + + // Is this set empty? + inline bool empty() const; + + // Merge the contents of some other UnknownFieldSet with this one. + void MergeFrom(const UnknownFieldSet& other); + + // Swaps the contents of some other UnknownFieldSet with this one. + inline void Swap(UnknownFieldSet* x); + + // Computes (an estimate of) the total number of bytes currently used for + // storing the unknown fields in memory. Does NOT include + // sizeof(*this) in the calculation. + int SpaceUsedExcludingSelf() const; + + // Version of SpaceUsed() including sizeof(*this). + int SpaceUsed() const; + + // Returns the number of fields present in the UnknownFieldSet. + inline int field_count() const; + // Get a field in the set, where 0 <= index < field_count(). The fields + // appear in the order in which they were added. + inline const UnknownField& field(int index) const; + // Get a mutable pointer to a field in the set, where + // 0 <= index < field_count(). The fields appear in the order in which + // they were added. + inline UnknownField* mutable_field(int index); + + // Adding fields --------------------------------------------------- + + void AddVarint(int number, uint64 value); + void AddFixed32(int number, uint32 value); + void AddFixed64(int number, uint64 value); + void AddLengthDelimited(int number, const string& value); + string* AddLengthDelimited(int number); + UnknownFieldSet* AddGroup(int number); + + // Adds an unknown field from another set. + void AddField(const UnknownField& field); + + // Parsing helpers ------------------------------------------------- + // These work exactly like the similarly-named methods of Message. + + bool MergeFromCodedStream(io::CodedInputStream* input); + bool ParseFromCodedStream(io::CodedInputStream* input); + bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); + bool ParseFromArray(const void* data, int size); + inline bool ParseFromString(const string& data) { + return ParseFromArray(data.data(), data.size()); + } + + private: + void ClearFallback(); + + vector* fields_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet); +}; + +// Represents one field in an UnknownFieldSet. +class LIBPROTOBUF_EXPORT UnknownField { + public: + enum Type { + TYPE_VARINT, + TYPE_FIXED32, + TYPE_FIXED64, + TYPE_LENGTH_DELIMITED, + TYPE_GROUP + }; + + // The field's tag number, as seen on the wire. + inline int number() const; + + // The field type. + inline Type type() const; + + // Accessors ------------------------------------------------------- + // Each method works only for UnknownFields of the corresponding type. + + inline uint64 varint() const; + inline uint32 fixed32() const; + inline uint64 fixed64() const; + inline const string& length_delimited() const; + inline const UnknownFieldSet& group() const; + + inline void set_varint(uint64 value); + inline void set_fixed32(uint32 value); + inline void set_fixed64(uint64 value); + inline void set_length_delimited(const string& value); + inline string* mutable_length_delimited(); + inline UnknownFieldSet* mutable_group(); + + private: + friend class UnknownFieldSet; + + // If this UnknownField contains a pointer, delete it. + void Delete(); + + // Make a deep copy of any pointers in this UnknownField. + void DeepCopy(); + + unsigned int number_ : 29; + unsigned int type_ : 3; + union { + uint64 varint_; + uint32 fixed32_; + uint64 fixed64_; + string* length_delimited_; + UnknownFieldSet* group_; + }; +}; + +// =================================================================== +// inline implementations + +inline void UnknownFieldSet::Clear() { + if (fields_ != NULL) { + ClearFallback(); + } +} + +inline bool UnknownFieldSet::empty() const { + return fields_ == NULL || fields_->empty(); +} + +inline void UnknownFieldSet::Swap(UnknownFieldSet* x) { + std::swap(fields_, x->fields_); +} + +inline int UnknownFieldSet::field_count() const { + return (fields_ == NULL) ? 0 : fields_->size(); +} +inline const UnknownField& UnknownFieldSet::field(int index) const { + return (*fields_)[index]; +} +inline UnknownField* UnknownFieldSet::mutable_field(int index) { + return &(*fields_)[index]; +} + +inline void UnknownFieldSet::AddLengthDelimited( + int number, const string& value) { + AddLengthDelimited(number)->assign(value); +} + +inline int UnknownField::number() const { return number_; } +inline UnknownField::Type UnknownField::type() const { + return static_cast(type_); +} + +inline uint64 UnknownField::varint () const { + GOOGLE_DCHECK_EQ(type_, TYPE_VARINT); + return varint_; +} +inline uint32 UnknownField::fixed32() const { + GOOGLE_DCHECK_EQ(type_, TYPE_FIXED32); + return fixed32_; +} +inline uint64 UnknownField::fixed64() const { + GOOGLE_DCHECK_EQ(type_, TYPE_FIXED64); + return fixed64_; +} +inline const string& UnknownField::length_delimited() const { + GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); + return *length_delimited_; +} +inline const UnknownFieldSet& UnknownField::group() const { + GOOGLE_DCHECK_EQ(type_, TYPE_GROUP); + return *group_; +} + +inline void UnknownField::set_varint(uint64 value) { + GOOGLE_DCHECK_EQ(type_, TYPE_VARINT); + varint_ = value; +} +inline void UnknownField::set_fixed32(uint32 value) { + GOOGLE_DCHECK_EQ(type_, TYPE_FIXED32); + fixed32_ = value; +} +inline void UnknownField::set_fixed64(uint64 value) { + GOOGLE_DCHECK_EQ(type_, TYPE_FIXED64); + fixed64_ = value; +} +inline void UnknownField::set_length_delimited(const string& value) { + GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); + length_delimited_->assign(value); +} +inline string* UnknownField::mutable_length_delimited() { + GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); + return length_delimited_; +} +inline UnknownFieldSet* UnknownField::mutable_group() { + GOOGLE_DCHECK_EQ(type_, TYPE_GROUP); + return group_; +} + +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h b/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h new file mode 100644 index 00000000..c7539250 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h @@ -0,0 +1,304 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// atenasio@google.com (Chris Atenasio) (ZigZag transform) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This header is logically internal, but is made public because it is used +// from protocol-compiler-generated code, which may reside in other components. + +#ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_H__ +#define GOOGLE_PROTOBUF_WIRE_FORMAT_H__ + +#include +#include +#include +#include +#include + +// Do UTF-8 validation on string type in Debug build only +#ifndef NDEBUG +#define GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED +#endif + +namespace google { +namespace protobuf { + namespace io { + class CodedInputStream; // coded_stream.h + class CodedOutputStream; // coded_stream.h + } + class UnknownFieldSet; // unknown_field_set.h +} + +namespace protobuf { +namespace internal { + +// This class is for internal use by the protocol buffer library and by +// protocol-complier-generated message classes. It must not be called +// directly by clients. +// +// This class contains code for implementing the binary protocol buffer +// wire format via reflection. The WireFormatLite class implements the +// non-reflection based routines. +// +// This class is really a namespace that contains only static methods +class LIBPROTOBUF_EXPORT WireFormat { + public: + + // Given a field return its WireType + static inline WireFormatLite::WireType WireTypeForField( + const FieldDescriptor* field); + + // Given a FieldSescriptor::Type return its WireType + static inline WireFormatLite::WireType WireTypeForFieldType( + FieldDescriptor::Type type); + + // Compute the byte size of a tag. For groups, this includes both the start + // and end tags. + static inline int TagSize(int field_number, FieldDescriptor::Type type); + + // These procedures can be used to implement the methods of Message which + // handle parsing and serialization of the protocol buffer wire format + // using only the Reflection interface. When you ask the protocol + // compiler to optimize for code size rather than speed, it will implement + // those methods in terms of these procedures. Of course, these are much + // slower than the specialized implementations which the protocol compiler + // generates when told to optimize for speed. + + // Read a message in protocol buffer wire format. + // + // This procedure reads either to the end of the input stream or through + // a WIRETYPE_END_GROUP tag ending the message, whichever comes first. + // It returns false if the input is invalid. + // + // Required fields are NOT checked by this method. You must call + // IsInitialized() on the resulting message yourself. + static bool ParseAndMergePartial(io::CodedInputStream* input, + Message* message); + + // Serialize a message in protocol buffer wire format. + // + // Any embedded messages within the message must have their correct sizes + // cached. However, the top-level message need not; its size is passed as + // a parameter to this procedure. + // + // These return false iff the underlying stream returns a write error. + static void SerializeWithCachedSizes( + const Message& message, + int size, io::CodedOutputStream* output); + + // Implements Message::ByteSize() via reflection. WARNING: The result + // of this method is *not* cached anywhere. However, all embedded messages + // will have their ByteSize() methods called, so their sizes will be cached. + // Therefore, calling this method is sufficient to allow you to call + // WireFormat::SerializeWithCachedSizes() on the same object. + static int ByteSize(const Message& message); + + // ----------------------------------------------------------------- + // Helpers for dealing with unknown fields + + // Skips a field value of the given WireType. The input should start + // positioned immediately after the tag. If unknown_fields is non-NULL, + // the contents of the field will be added to it. + static bool SkipField(io::CodedInputStream* input, uint32 tag, + UnknownFieldSet* unknown_fields); + + // Reads and ignores a message from the input. If unknown_fields is non-NULL, + // the contents will be added to it. + static bool SkipMessage(io::CodedInputStream* input, + UnknownFieldSet* unknown_fields); + + // Write the contents of an UnknownFieldSet to the output. + static void SerializeUnknownFields(const UnknownFieldSet& unknown_fields, + io::CodedOutputStream* output); + // Same as above, except writing directly to the provided buffer. + // Requires that the buffer have sufficient capacity for + // ComputeUnknownFieldsSize(unknown_fields). + // + // Returns a pointer past the last written byte. + static uint8* SerializeUnknownFieldsToArray( + const UnknownFieldSet& unknown_fields, + uint8* target); + + // Same thing except for messages that have the message_set_wire_format + // option. + static void SerializeUnknownMessageSetItems( + const UnknownFieldSet& unknown_fields, + io::CodedOutputStream* output); + // Same as above, except writing directly to the provided buffer. + // Requires that the buffer have sufficient capacity for + // ComputeUnknownMessageSetItemsSize(unknown_fields). + // + // Returns a pointer past the last written byte. + static uint8* SerializeUnknownMessageSetItemsToArray( + const UnknownFieldSet& unknown_fields, + uint8* target); + + // Compute the size of the UnknownFieldSet on the wire. + static int ComputeUnknownFieldsSize(const UnknownFieldSet& unknown_fields); + + // Same thing except for messages that have the message_set_wire_format + // option. + static int ComputeUnknownMessageSetItemsSize( + const UnknownFieldSet& unknown_fields); + + + // Helper functions for encoding and decoding tags. (Inlined below and in + // _inl.h) + // + // This is different from MakeTag(field->number(), field->type()) in the case + // of packed repeated fields. + static uint32 MakeTag(const FieldDescriptor* field); + + // Parse a single field. The input should start out positioned immidately + // after the tag. + static bool ParseAndMergeField( + uint32 tag, + const FieldDescriptor* field, // May be NULL for unknown + Message* message, + io::CodedInputStream* input); + + // Serialize a single field. + static void SerializeFieldWithCachedSizes( + const FieldDescriptor* field, // Cannot be NULL + const Message& message, + io::CodedOutputStream* output); + + // Compute size of a single field. If the field is a message type, this + // will call ByteSize() for the embedded message, insuring that it caches + // its size. + static int FieldByteSize( + const FieldDescriptor* field, // Cannot be NULL + const Message& message); + + // Parse/serialize a MessageSet::Item group. Used with messages that use + // opion message_set_wire_format = true. + static bool ParseAndMergeMessageSetItem( + io::CodedInputStream* input, + Message* message); + static void SerializeMessageSetItemWithCachedSizes( + const FieldDescriptor* field, + const Message& message, + io::CodedOutputStream* output); + static int MessageSetItemByteSize( + const FieldDescriptor* field, + const Message& message); + + // Computes the byte size of a field, excluding tags. For packed fields, it + // only includes the size of the raw data, and not the size of the total + // length, but for other length-delimited types, the size of the length is + // included. + static int FieldDataOnlyByteSize( + const FieldDescriptor* field, // Cannot be NULL + const Message& message); + + enum Operation { + PARSE, + SERIALIZE, + }; + + // Verifies that a string field is valid UTF8, logging an error if not. + static void VerifyUTF8String(const char* data, int size, Operation op); + + private: + // Verifies that a string field is valid UTF8, logging an error if not. + static void VerifyUTF8StringFallback( + const char* data, + int size, + Operation op); + + + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormat); +}; + +// Subclass of FieldSkipper which saves skipped fields to an UnknownFieldSet. +class LIBPROTOBUF_EXPORT UnknownFieldSetFieldSkipper : public FieldSkipper { + public: + UnknownFieldSetFieldSkipper(UnknownFieldSet* unknown_fields) + : unknown_fields_(unknown_fields) {} + virtual ~UnknownFieldSetFieldSkipper() {} + + // implements FieldSkipper ----------------------------------------- + virtual bool SkipField(io::CodedInputStream* input, uint32 tag); + virtual bool SkipMessage(io::CodedInputStream* input); + virtual void SkipUnknownEnum(int field_number, int value); + + private: + UnknownFieldSet* unknown_fields_; +}; + +// inline methods ==================================================== + +inline WireFormatLite::WireType WireFormat::WireTypeForField( + const FieldDescriptor* field) { + if (field->options().packed()) { + return WireFormatLite::WIRETYPE_LENGTH_DELIMITED; + } else { + return WireTypeForFieldType(field->type()); + } +} + +inline WireFormatLite::WireType WireFormat::WireTypeForFieldType( + FieldDescriptor::Type type) { + // Some compilers don't like enum -> enum casts, so we implicit_cast to + // int first. + return WireFormatLite::WireTypeForFieldType( + static_cast( + implicit_cast(type))); +} + +inline uint32 WireFormat::MakeTag(const FieldDescriptor* field) { + return WireFormatLite::MakeTag(field->number(), WireTypeForField(field)); +} + +inline int WireFormat::TagSize(int field_number, FieldDescriptor::Type type) { + // Some compilers don't like enum -> enum casts, so we implicit_cast to + // int first. + return WireFormatLite::TagSize(field_number, + static_cast( + implicit_cast(type))); +} + +inline void WireFormat::VerifyUTF8String(const char* data, int size, + WireFormat::Operation op) { +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + WireFormat::VerifyUTF8StringFallback(data, size, op); +#endif +} + + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_WIRE_FORMAT_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h new file mode 100644 index 00000000..e3d5b2d8 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h @@ -0,0 +1,620 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// atenasio@google.com (Chris Atenasio) (ZigZag transform) +// wink@google.com (Wink Saville) (refactored from wire_format.h) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// This header is logically internal, but is made public because it is used +// from protocol-compiler-generated code, which may reside in other components. + +#ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ +#define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ + +#include +#include + +namespace google { + +namespace protobuf { + template class RepeatedField; // repeated_field.h + namespace io { + class CodedInputStream; // coded_stream.h + class CodedOutputStream; // coded_stream.h + } +} + +namespace protobuf { +namespace internal { + +class StringPieceField; + +// This class is for internal use by the protocol buffer library and by +// protocol-complier-generated message classes. It must not be called +// directly by clients. +// +// This class contains helpers for implementing the binary protocol buffer +// wire format without the need for reflection. Use WireFormat when using +// reflection. +// +// This class is really a namespace that contains only static methods. +class LIBPROTOBUF_EXPORT WireFormatLite { + public: + + // ----------------------------------------------------------------- + // Helper constants and functions related to the format. These are + // mostly meant for internal and generated code to use. + + // The wire format is composed of a sequence of tag/value pairs, each + // of which contains the value of one field (or one element of a repeated + // field). Each tag is encoded as a varint. The lower bits of the tag + // identify its wire type, which specifies the format of the data to follow. + // The rest of the bits contain the field number. Each type of field (as + // declared by FieldDescriptor::Type, in descriptor.h) maps to one of + // these wire types. Immediately following each tag is the field's value, + // encoded in the format specified by the wire type. Because the tag + // identifies the encoding of this data, it is possible to skip + // unrecognized fields for forwards compatibility. + + enum WireType { + WIRETYPE_VARINT = 0, + WIRETYPE_FIXED64 = 1, + WIRETYPE_LENGTH_DELIMITED = 2, + WIRETYPE_START_GROUP = 3, + WIRETYPE_END_GROUP = 4, + WIRETYPE_FIXED32 = 5, + }; + + // Lite alternative to FieldDescriptor::Type. Must be kept in sync. + enum FieldType { + TYPE_DOUBLE = 1, + TYPE_FLOAT = 2, + TYPE_INT64 = 3, + TYPE_UINT64 = 4, + TYPE_INT32 = 5, + TYPE_FIXED64 = 6, + TYPE_FIXED32 = 7, + TYPE_BOOL = 8, + TYPE_STRING = 9, + TYPE_GROUP = 10, + TYPE_MESSAGE = 11, + TYPE_BYTES = 12, + TYPE_UINT32 = 13, + TYPE_ENUM = 14, + TYPE_SFIXED32 = 15, + TYPE_SFIXED64 = 16, + TYPE_SINT32 = 17, + TYPE_SINT64 = 18, + MAX_FIELD_TYPE = 18, + }; + + // Lite alternative to FieldDescriptor::CppType. Must be kept in sync. + enum CppType { + CPPTYPE_INT32 = 1, + CPPTYPE_INT64 = 2, + CPPTYPE_UINT32 = 3, + CPPTYPE_UINT64 = 4, + CPPTYPE_DOUBLE = 5, + CPPTYPE_FLOAT = 6, + CPPTYPE_BOOL = 7, + CPPTYPE_ENUM = 8, + CPPTYPE_STRING = 9, + CPPTYPE_MESSAGE = 10, + MAX_CPPTYPE = 10, + }; + + // Helper method to get the CppType for a particular Type. + static CppType FieldTypeToCppType(FieldType type); + + // Given a FieldSescriptor::Type return its WireType + static inline WireFormatLite::WireType WireTypeForFieldType( + WireFormatLite::FieldType type) { + return kWireTypeForFieldType[type]; + } + + // Number of bits in a tag which identify the wire type. + static const int kTagTypeBits = 3; + // Mask for those bits. + static const uint32 kTagTypeMask = (1 << kTagTypeBits) - 1; + + // Helper functions for encoding and decoding tags. (Inlined below and in + // _inl.h) + // + // This is different from MakeTag(field->number(), field->type()) in the case + // of packed repeated fields. + static uint32 MakeTag(int field_number, WireType type); + static WireType GetTagWireType(uint32 tag); + static int GetTagFieldNumber(uint32 tag); + + // Compute the byte size of a tag. For groups, this includes both the start + // and end tags. + static inline int TagSize(int field_number, WireFormatLite::FieldType type); + + // Skips a field value with the given tag. The input should start + // positioned immediately after the tag. Skipped values are simply discarded, + // not recorded anywhere. See WireFormat::SkipField() for a version that + // records to an UnknownFieldSet. + static bool SkipField(io::CodedInputStream* input, uint32 tag); + + // Reads and ignores a message from the input. Skipped values are simply + // discarded, not recorded anywhere. See WireFormat::SkipMessage() for a + // version that records to an UnknownFieldSet. + static bool SkipMessage(io::CodedInputStream* input); + +// This macro does the same thing as WireFormatLite::MakeTag(), but the +// result is usable as a compile-time constant, which makes it usable +// as a switch case or a template input. WireFormatLite::MakeTag() is more +// type-safe, though, so prefer it if possible. +#define GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(FIELD_NUMBER, TYPE) \ + static_cast( \ + ((FIELD_NUMBER) << ::google::protobuf::internal::WireFormatLite::kTagTypeBits) \ + | (TYPE)) + + // These are the tags for the old MessageSet format, which was defined as: + // message MessageSet { + // repeated group Item = 1 { + // required int32 type_id = 2; + // required string message = 3; + // } + // } + static const int kMessageSetItemNumber = 1; + static const int kMessageSetTypeIdNumber = 2; + static const int kMessageSetMessageNumber = 3; + static const int kMessageSetItemStartTag = + GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetItemNumber, + WireFormatLite::WIRETYPE_START_GROUP); + static const int kMessageSetItemEndTag = + GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetItemNumber, + WireFormatLite::WIRETYPE_END_GROUP); + static const int kMessageSetTypeIdTag = + GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetTypeIdNumber, + WireFormatLite::WIRETYPE_VARINT); + static const int kMessageSetMessageTag = + GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetMessageNumber, + WireFormatLite::WIRETYPE_LENGTH_DELIMITED); + + // Byte size of all tags of a MessageSet::Item combined. + static const int kMessageSetItemTagsSize; + + // Helper functions for converting between floats/doubles and IEEE-754 + // uint32s/uint64s so that they can be written. (Assumes your platform + // uses IEEE-754 floats.) + static uint32 EncodeFloat(float value); + static float DecodeFloat(uint32 value); + static uint64 EncodeDouble(double value); + static double DecodeDouble(uint64 value); + + // Helper functions for mapping signed integers to unsigned integers in + // such a way that numbers with small magnitudes will encode to smaller + // varints. If you simply static_cast a negative number to an unsigned + // number and varint-encode it, it will always take 10 bytes, defeating + // the purpose of varint. So, for the "sint32" and "sint64" field types, + // we ZigZag-encode the values. + static uint32 ZigZagEncode32(int32 n); + static int32 ZigZagDecode32(uint32 n); + static uint64 ZigZagEncode64(int64 n); + static int64 ZigZagDecode64(uint64 n); + + // ================================================================= + // Methods for reading/writing individual field. The implementations + // of these methods are defined in wire_format_lite_inl.h; you must #include + // that file to use these. + +// Avoid ugly line wrapping +#define input io::CodedInputStream* input +#define output io::CodedOutputStream* output +#define field_number int field_number +#define INL GOOGLE_ATTRIBUTE_ALWAYS_INLINE + + // Read fields, not including tags. The assumption is that you already + // read the tag to determine what field to read. + + // For primitive fields, we just use a templatized routine parameterized by + // the represented type and the FieldType. These are specialized with the + // appropriate definition for each declared type. + template + static inline bool ReadPrimitive(input, CType* value) INL; + + // Reads repeated primitive values, with optimizations for repeats. + // tag_size and tag should both be compile-time constants provided by the + // protocol compiler. + template + static inline bool ReadRepeatedPrimitive(int tag_size, + uint32 tag, + input, + RepeatedField* value) INL; + + // Identical to ReadRepeatedPrimitive, except will not inline the + // implementation. + template + static bool ReadRepeatedPrimitiveNoInline(int tag_size, + uint32 tag, + input, + RepeatedField* value); + + // Reads a primitive value directly from the provided buffer. It returns a + // pointer past the segment of data that was read. + // + // This is only implemented for the types with fixed wire size, e.g. + // float, double, and the (s)fixed* types. + template + static inline const uint8* ReadPrimitiveFromArray(const uint8* buffer, + CType* value) INL; + + // Reads a primitive packed field. + // + // This is only implemented for packable types. + template + static inline bool ReadPackedPrimitive(input, + RepeatedField* value) INL; + + // Identical to ReadPackedPrimitive, except will not inline the + // implementation. + template + static bool ReadPackedPrimitiveNoInline(input, RepeatedField* value); + + // Read a packed enum field. Values for which is_valid() returns false are + // dropped. + static bool ReadPackedEnumNoInline(input, + bool (*is_valid)(int), + RepeatedField* value); + + static bool ReadString(input, string* value); + static bool ReadBytes (input, string* value); + + static inline bool ReadGroup (field_number, input, MessageLite* value); + static inline bool ReadMessage(input, MessageLite* value); + + // Like above, but de-virtualize the call to MergePartialFromCodedStream(). + // The pointer must point at an instance of MessageType, *not* a subclass (or + // the subclass must not override MergePartialFromCodedStream()). + template + static inline bool ReadGroupNoVirtual(field_number, input, + MessageType* value); + template + static inline bool ReadMessageNoVirtual(input, MessageType* value); + + // Write a tag. The Write*() functions typically include the tag, so + // normally there's no need to call this unless using the Write*NoTag() + // variants. + static inline void WriteTag(field_number, WireType type, output) INL; + + // Write fields, without tags. + static inline void WriteInt32NoTag (int32 value, output) INL; + static inline void WriteInt64NoTag (int64 value, output) INL; + static inline void WriteUInt32NoTag (uint32 value, output) INL; + static inline void WriteUInt64NoTag (uint64 value, output) INL; + static inline void WriteSInt32NoTag (int32 value, output) INL; + static inline void WriteSInt64NoTag (int64 value, output) INL; + static inline void WriteFixed32NoTag (uint32 value, output) INL; + static inline void WriteFixed64NoTag (uint64 value, output) INL; + static inline void WriteSFixed32NoTag(int32 value, output) INL; + static inline void WriteSFixed64NoTag(int64 value, output) INL; + static inline void WriteFloatNoTag (float value, output) INL; + static inline void WriteDoubleNoTag (double value, output) INL; + static inline void WriteBoolNoTag (bool value, output) INL; + static inline void WriteEnumNoTag (int value, output) INL; + + // Write fields, including tags. + static void WriteInt32 (field_number, int32 value, output); + static void WriteInt64 (field_number, int64 value, output); + static void WriteUInt32 (field_number, uint32 value, output); + static void WriteUInt64 (field_number, uint64 value, output); + static void WriteSInt32 (field_number, int32 value, output); + static void WriteSInt64 (field_number, int64 value, output); + static void WriteFixed32 (field_number, uint32 value, output); + static void WriteFixed64 (field_number, uint64 value, output); + static void WriteSFixed32(field_number, int32 value, output); + static void WriteSFixed64(field_number, int64 value, output); + static void WriteFloat (field_number, float value, output); + static void WriteDouble (field_number, double value, output); + static void WriteBool (field_number, bool value, output); + static void WriteEnum (field_number, int value, output); + + static void WriteString(field_number, const string& value, output); + static void WriteBytes (field_number, const string& value, output); + + static void WriteGroup( + field_number, const MessageLite& value, output); + static void WriteMessage( + field_number, const MessageLite& value, output); + // Like above, but these will check if the output stream has enough + // space to write directly to a flat array. + static void WriteGroupMaybeToArray( + field_number, const MessageLite& value, output); + static void WriteMessageMaybeToArray( + field_number, const MessageLite& value, output); + + // Like above, but de-virtualize the call to SerializeWithCachedSizes(). The + // pointer must point at an instance of MessageType, *not* a subclass (or + // the subclass must not override SerializeWithCachedSizes()). + template + static inline void WriteGroupNoVirtual( + field_number, const MessageType& value, output); + template + static inline void WriteMessageNoVirtual( + field_number, const MessageType& value, output); + +#undef output +#define output uint8* target + + // Like above, but use only *ToArray methods of CodedOutputStream. + static inline uint8* WriteTagToArray(field_number, WireType type, output) INL; + + // Write fields, without tags. + static inline uint8* WriteInt32NoTagToArray (int32 value, output) INL; + static inline uint8* WriteInt64NoTagToArray (int64 value, output) INL; + static inline uint8* WriteUInt32NoTagToArray (uint32 value, output) INL; + static inline uint8* WriteUInt64NoTagToArray (uint64 value, output) INL; + static inline uint8* WriteSInt32NoTagToArray (int32 value, output) INL; + static inline uint8* WriteSInt64NoTagToArray (int64 value, output) INL; + static inline uint8* WriteFixed32NoTagToArray (uint32 value, output) INL; + static inline uint8* WriteFixed64NoTagToArray (uint64 value, output) INL; + static inline uint8* WriteSFixed32NoTagToArray(int32 value, output) INL; + static inline uint8* WriteSFixed64NoTagToArray(int64 value, output) INL; + static inline uint8* WriteFloatNoTagToArray (float value, output) INL; + static inline uint8* WriteDoubleNoTagToArray (double value, output) INL; + static inline uint8* WriteBoolNoTagToArray (bool value, output) INL; + static inline uint8* WriteEnumNoTagToArray (int value, output) INL; + + // Write fields, including tags. + static inline uint8* WriteInt32ToArray( + field_number, int32 value, output) INL; + static inline uint8* WriteInt64ToArray( + field_number, int64 value, output) INL; + static inline uint8* WriteUInt32ToArray( + field_number, uint32 value, output) INL; + static inline uint8* WriteUInt64ToArray( + field_number, uint64 value, output) INL; + static inline uint8* WriteSInt32ToArray( + field_number, int32 value, output) INL; + static inline uint8* WriteSInt64ToArray( + field_number, int64 value, output) INL; + static inline uint8* WriteFixed32ToArray( + field_number, uint32 value, output) INL; + static inline uint8* WriteFixed64ToArray( + field_number, uint64 value, output) INL; + static inline uint8* WriteSFixed32ToArray( + field_number, int32 value, output) INL; + static inline uint8* WriteSFixed64ToArray( + field_number, int64 value, output) INL; + static inline uint8* WriteFloatToArray( + field_number, float value, output) INL; + static inline uint8* WriteDoubleToArray( + field_number, double value, output) INL; + static inline uint8* WriteBoolToArray( + field_number, bool value, output) INL; + static inline uint8* WriteEnumToArray( + field_number, int value, output) INL; + + static inline uint8* WriteStringToArray( + field_number, const string& value, output) INL; + static inline uint8* WriteBytesToArray( + field_number, const string& value, output) INL; + + static inline uint8* WriteGroupToArray( + field_number, const MessageLite& value, output) INL; + static inline uint8* WriteMessageToArray( + field_number, const MessageLite& value, output) INL; + + // Like above, but de-virtualize the call to SerializeWithCachedSizes(). The + // pointer must point at an instance of MessageType, *not* a subclass (or + // the subclass must not override SerializeWithCachedSizes()). + template + static inline uint8* WriteGroupNoVirtualToArray( + field_number, const MessageType& value, output) INL; + template + static inline uint8* WriteMessageNoVirtualToArray( + field_number, const MessageType& value, output) INL; + +#undef output +#undef input +#undef INL + +#undef field_number + + // Compute the byte size of a field. The XxSize() functions do NOT include + // the tag, so you must also call TagSize(). (This is because, for repeated + // fields, you should only call TagSize() once and multiply it by the element + // count, but you may have to call XxSize() for each individual element.) + static inline int Int32Size ( int32 value); + static inline int Int64Size ( int64 value); + static inline int UInt32Size (uint32 value); + static inline int UInt64Size (uint64 value); + static inline int SInt32Size ( int32 value); + static inline int SInt64Size ( int64 value); + static inline int EnumSize ( int value); + + // These types always have the same size. + static const int kFixed32Size = 4; + static const int kFixed64Size = 8; + static const int kSFixed32Size = 4; + static const int kSFixed64Size = 8; + static const int kFloatSize = 4; + static const int kDoubleSize = 8; + static const int kBoolSize = 1; + + static inline int StringSize(const string& value); + static inline int BytesSize (const string& value); + + static inline int GroupSize (const MessageLite& value); + static inline int MessageSize(const MessageLite& value); + + // Like above, but de-virtualize the call to ByteSize(). The + // pointer must point at an instance of MessageType, *not* a subclass (or + // the subclass must not override ByteSize()). + template + static inline int GroupSizeNoVirtual (const MessageType& value); + template + static inline int MessageSizeNoVirtual(const MessageType& value); + + private: + // A helper method for the repeated primitive reader. This method has + // optimizations for primitive types that have fixed size on the wire, and + // can be read using potentially faster paths. + template + static inline bool ReadRepeatedFixedSizePrimitive( + int tag_size, + uint32 tag, + google::protobuf::io::CodedInputStream* input, + RepeatedField* value) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; + + static const CppType kFieldTypeToCppTypeMap[]; + static const WireFormatLite::WireType kWireTypeForFieldType[]; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormatLite); +}; + +// A class which deals with unknown values. The default implementation just +// discards them. WireFormat defines a subclass which writes to an +// UnknownFieldSet. This class is used by ExtensionSet::ParseField(), since +// ExtensionSet is part of the lite library but UnknownFieldSet is not. +class LIBPROTOBUF_EXPORT FieldSkipper { + public: + FieldSkipper() {} + virtual ~FieldSkipper() {} + + // Skip a field whose tag has already been consumed. + virtual bool SkipField(io::CodedInputStream* input, uint32 tag); + + // Skip an entire message or group, up to an end-group tag (which is consumed) + // or end-of-stream. + virtual bool SkipMessage(io::CodedInputStream* input); + + // Deal with an already-parsed unrecognized enum value. The default + // implementation does nothing, but the UnknownFieldSet-based implementation + // saves it as an unknown varint. + virtual void SkipUnknownEnum(int field_number, int value); +}; + +// inline methods ==================================================== + +inline WireFormatLite::CppType +WireFormatLite::FieldTypeToCppType(FieldType type) { + return kFieldTypeToCppTypeMap[type]; +} + +inline uint32 WireFormatLite::MakeTag(int field_number, WireType type) { + return GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(field_number, type); +} + +inline WireFormatLite::WireType WireFormatLite::GetTagWireType(uint32 tag) { + return static_cast(tag & kTagTypeMask); +} + +inline int WireFormatLite::GetTagFieldNumber(uint32 tag) { + return static_cast(tag >> kTagTypeBits); +} + +inline int WireFormatLite::TagSize(int field_number, + WireFormatLite::FieldType type) { + int result = io::CodedOutputStream::VarintSize32( + field_number << kTagTypeBits); + if (type == TYPE_GROUP) { + // Groups have both a start and an end tag. + return result * 2; + } else { + return result; + } +} + +inline uint32 WireFormatLite::EncodeFloat(float value) { + union {float f; uint32 i;}; + f = value; + return i; +} + +inline float WireFormatLite::DecodeFloat(uint32 value) { + union {float f; uint32 i;}; + i = value; + return f; +} + +inline uint64 WireFormatLite::EncodeDouble(double value) { + union {double f; uint64 i;}; + f = value; + return i; +} + +inline double WireFormatLite::DecodeDouble(uint64 value) { + union {double f; uint64 i;}; + i = value; + return f; +} + +// ZigZag Transform: Encodes signed integers so that they can be +// effectively used with varint encoding. +// +// varint operates on unsigned integers, encoding smaller numbers into +// fewer bytes. If you try to use it on a signed integer, it will treat +// this number as a very large unsigned integer, which means that even +// small signed numbers like -1 will take the maximum number of bytes +// (10) to encode. ZigZagEncode() maps signed integers to unsigned +// in such a way that those with a small absolute value will have smaller +// encoded values, making them appropriate for encoding using varint. +// +// int32 -> uint32 +// ------------------------- +// 0 -> 0 +// -1 -> 1 +// 1 -> 2 +// -2 -> 3 +// ... -> ... +// 2147483647 -> 4294967294 +// -2147483648 -> 4294967295 +// +// >> encode >> +// << decode << + +inline uint32 WireFormatLite::ZigZagEncode32(int32 n) { + // Note: the right-shift must be arithmetic + return (n << 1) ^ (n >> 31); +} + +inline int32 WireFormatLite::ZigZagDecode32(uint32 n) { + return (n >> 1) ^ -static_cast(n & 1); +} + +inline uint64 WireFormatLite::ZigZagEncode64(int64 n) { + // Note: the right-shift must be arithmetic + return (n << 1) ^ (n >> 63); +} + +inline int64 WireFormatLite::ZigZagDecode64(uint64 n) { + return (n >> 1) ^ -static_cast(n & 1); +} + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h b/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h new file mode 100644 index 00000000..103b0bd0 --- /dev/null +++ b/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h @@ -0,0 +1,774 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// wink@google.com (Wink Saville) (refactored from wire_format.h) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ +#define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ + +#include +#include +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace internal { + +// Implementation details of ReadPrimitive. + +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + int32* value) { + uint32 temp; + if (!input->ReadVarint32(&temp)) return false; + *value = static_cast(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + int64* value) { + uint64 temp; + if (!input->ReadVarint64(&temp)) return false; + *value = static_cast(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + uint32* value) { + return input->ReadVarint32(value); +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + uint64* value) { + return input->ReadVarint64(value); +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + int32* value) { + uint32 temp; + if (!input->ReadVarint32(&temp)) return false; + *value = ZigZagDecode32(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + int64* value) { + uint64 temp; + if (!input->ReadVarint64(&temp)) return false; + *value = ZigZagDecode64(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + uint32* value) { + return input->ReadLittleEndian32(value); +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + uint64* value) { + return input->ReadLittleEndian64(value); +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + int32* value) { + uint32 temp; + if (!input->ReadLittleEndian32(&temp)) return false; + *value = static_cast(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + int64* value) { + uint64 temp; + if (!input->ReadLittleEndian64(&temp)) return false; + *value = static_cast(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + float* value) { + uint32 temp; + if (!input->ReadLittleEndian32(&temp)) return false; + *value = DecodeFloat(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + double* value) { + uint64 temp; + if (!input->ReadLittleEndian64(&temp)) return false; + *value = DecodeDouble(temp); + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + bool* value) { + uint32 temp; + if (!input->ReadVarint32(&temp)) return false; + *value = temp != 0; + return true; +} +template <> +inline bool WireFormatLite::ReadPrimitive( + io::CodedInputStream* input, + int* value) { + uint32 temp; + if (!input->ReadVarint32(&temp)) return false; + *value = static_cast(temp); + return true; +} + +template <> +inline const uint8* WireFormatLite::ReadPrimitiveFromArray< + uint32, WireFormatLite::TYPE_FIXED32>( + const uint8* buffer, + uint32* value) { + return io::CodedInputStream::ReadLittleEndian32FromArray(buffer, value); +} +template <> +inline const uint8* WireFormatLite::ReadPrimitiveFromArray< + uint64, WireFormatLite::TYPE_FIXED64>( + const uint8* buffer, + uint64* value) { + return io::CodedInputStream::ReadLittleEndian64FromArray(buffer, value); +} +template <> +inline const uint8* WireFormatLite::ReadPrimitiveFromArray< + int32, WireFormatLite::TYPE_SFIXED32>( + const uint8* buffer, + int32* value) { + uint32 temp; + buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp); + *value = static_cast(temp); + return buffer; +} +template <> +inline const uint8* WireFormatLite::ReadPrimitiveFromArray< + int64, WireFormatLite::TYPE_SFIXED64>( + const uint8* buffer, + int64* value) { + uint64 temp; + buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp); + *value = static_cast(temp); + return buffer; +} +template <> +inline const uint8* WireFormatLite::ReadPrimitiveFromArray< + float, WireFormatLite::TYPE_FLOAT>( + const uint8* buffer, + float* value) { + uint32 temp; + buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp); + *value = DecodeFloat(temp); + return buffer; +} +template <> +inline const uint8* WireFormatLite::ReadPrimitiveFromArray< + double, WireFormatLite::TYPE_DOUBLE>( + const uint8* buffer, + double* value) { + uint64 temp; + buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp); + *value = DecodeDouble(temp); + return buffer; +} + +template +inline bool WireFormatLite::ReadRepeatedPrimitive(int, // tag_size, unused. + uint32 tag, + io::CodedInputStream* input, + RepeatedField* values) { + CType value; + if (!ReadPrimitive(input, &value)) return false; + values->Add(value); + int elements_already_reserved = values->Capacity() - values->size(); + while (elements_already_reserved > 0 && input->ExpectTag(tag)) { + if (!ReadPrimitive(input, &value)) return false; + values->AddAlreadyReserved(value); + elements_already_reserved--; + } + return true; +} + +template +inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive( + int tag_size, + uint32 tag, + io::CodedInputStream* input, + RepeatedField* values) { + GOOGLE_DCHECK_EQ(UInt32Size(tag), tag_size); + CType value; + if (!ReadPrimitive(input, &value)) + return false; + values->Add(value); + + // For fixed size values, repeated values can be read more quickly by + // reading directly from a raw array. + // + // We can get a tight loop by only reading as many elements as can be + // added to the RepeatedField without having to do any resizing. Additionally, + // we only try to read as many elements as are available from the current + // buffer space. Doing so avoids having to perform boundary checks when + // reading the value: the maximum number of elements that can be read is + // known outside of the loop. + const void* void_pointer; + int size; + input->GetDirectBufferPointerInline(&void_pointer, &size); + if (size > 0) { + const uint8* buffer = reinterpret_cast(void_pointer); + // The number of bytes each type occupies on the wire. + const int per_value_size = tag_size + sizeof(value); + + int elements_available = min(values->Capacity() - values->size(), + size / per_value_size); + int num_read = 0; + while (num_read < elements_available && + (buffer = io::CodedInputStream::ExpectTagFromArray( + buffer, tag)) != NULL) { + buffer = ReadPrimitiveFromArray(buffer, &value); + values->AddAlreadyReserved(value); + ++num_read; + } + const int read_bytes = num_read * per_value_size; + if (read_bytes > 0) { + input->Skip(read_bytes); + } + } + return true; +} + +// Specializations of ReadRepeatedPrimitive for the fixed size types, which use +// the optimized code path. +#define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \ +template <> \ +inline bool WireFormatLite::ReadRepeatedPrimitive< \ + CPPTYPE, WireFormatLite::DECLARED_TYPE>( \ + int tag_size, \ + uint32 tag, \ + io::CodedInputStream* input, \ + RepeatedField* values) { \ + return ReadRepeatedFixedSizePrimitive< \ + CPPTYPE, WireFormatLite::DECLARED_TYPE>( \ + tag_size, tag, input, values); \ +} + +READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32); +READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64); +READ_REPEATED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32); +READ_REPEATED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64); +READ_REPEATED_FIXED_SIZE_PRIMITIVE(float, TYPE_FLOAT); +READ_REPEATED_FIXED_SIZE_PRIMITIVE(double, TYPE_DOUBLE); + +#undef READ_REPEATED_FIXED_SIZE_PRIMITIVE + +template +bool WireFormatLite::ReadRepeatedPrimitiveNoInline( + int tag_size, + uint32 tag, + io::CodedInputStream* input, + RepeatedField* value) { + return ReadRepeatedPrimitive( + tag_size, tag, input, value); +} + +template +inline bool WireFormatLite::ReadPackedPrimitive(io::CodedInputStream* input, + RepeatedField* values) { + uint32 length; + if (!input->ReadVarint32(&length)) return false; + io::CodedInputStream::Limit limit = input->PushLimit(length); + while (input->BytesUntilLimit() > 0) { + CType value; + if (!ReadPrimitive(input, &value)) return false; + values->Add(value); + } + input->PopLimit(limit); + return true; +} + +template +bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input, + RepeatedField* values) { + return ReadPackedPrimitive(input, values); +} + + +inline bool WireFormatLite::ReadGroup(int field_number, + io::CodedInputStream* input, + MessageLite* value) { + if (!input->IncrementRecursionDepth()) return false; + if (!value->MergePartialFromCodedStream(input)) return false; + input->DecrementRecursionDepth(); + // Make sure the last thing read was an end tag for this group. + if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) { + return false; + } + return true; +} +inline bool WireFormatLite::ReadMessage(io::CodedInputStream* input, + MessageLite* value) { + uint32 length; + if (!input->ReadVarint32(&length)) return false; + if (!input->IncrementRecursionDepth()) return false; + io::CodedInputStream::Limit limit = input->PushLimit(length); + if (!value->MergePartialFromCodedStream(input)) return false; + // Make sure that parsing stopped when the limit was hit, not at an endgroup + // tag. + if (!input->ConsumedEntireMessage()) return false; + input->PopLimit(limit); + input->DecrementRecursionDepth(); + return true; +} + +// We name the template parameter something long and extremely unlikely to occur +// elsewhere because a *qualified* member access expression designed to avoid +// virtual dispatch, C++03 [basic.lookup.classref] 3.4.5/4 requires that the +// name of the qualifying class to be looked up both in the context of the full +// expression (finding the template parameter) and in the context of the object +// whose member we are accessing. This could potentially find a nested type +// within that object. The standard goes on to require these names to refer to +// the same entity, which this collision would violate. The lack of a safe way +// to avoid this collision appears to be a defect in the standard, but until it +// is corrected, we choose the name to avoid accidental collisions. +template +inline bool WireFormatLite::ReadGroupNoVirtual( + int field_number, io::CodedInputStream* input, + MessageType_WorkAroundCppLookupDefect* value) { + if (!input->IncrementRecursionDepth()) return false; + if (!value-> + MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input)) + return false; + input->DecrementRecursionDepth(); + // Make sure the last thing read was an end tag for this group. + if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) { + return false; + } + return true; +} +template +inline bool WireFormatLite::ReadMessageNoVirtual( + io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) { + uint32 length; + if (!input->ReadVarint32(&length)) return false; + if (!input->IncrementRecursionDepth()) return false; + io::CodedInputStream::Limit limit = input->PushLimit(length); + if (!value-> + MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input)) + return false; + // Make sure that parsing stopped when the limit was hit, not at an endgroup + // tag. + if (!input->ConsumedEntireMessage()) return false; + input->PopLimit(limit); + input->DecrementRecursionDepth(); + return true; +} + +// =================================================================== + +inline void WireFormatLite::WriteTag(int field_number, WireType type, + io::CodedOutputStream* output) { + output->WriteTag(MakeTag(field_number, type)); +} + +inline void WireFormatLite::WriteInt32NoTag(int32 value, + io::CodedOutputStream* output) { + output->WriteVarint32SignExtended(value); +} +inline void WireFormatLite::WriteInt64NoTag(int64 value, + io::CodedOutputStream* output) { + output->WriteVarint64(static_cast(value)); +} +inline void WireFormatLite::WriteUInt32NoTag(uint32 value, + io::CodedOutputStream* output) { + output->WriteVarint32(value); +} +inline void WireFormatLite::WriteUInt64NoTag(uint64 value, + io::CodedOutputStream* output) { + output->WriteVarint64(value); +} +inline void WireFormatLite::WriteSInt32NoTag(int32 value, + io::CodedOutputStream* output) { + output->WriteVarint32(ZigZagEncode32(value)); +} +inline void WireFormatLite::WriteSInt64NoTag(int64 value, + io::CodedOutputStream* output) { + output->WriteVarint64(ZigZagEncode64(value)); +} +inline void WireFormatLite::WriteFixed32NoTag(uint32 value, + io::CodedOutputStream* output) { + output->WriteLittleEndian32(value); +} +inline void WireFormatLite::WriteFixed64NoTag(uint64 value, + io::CodedOutputStream* output) { + output->WriteLittleEndian64(value); +} +inline void WireFormatLite::WriteSFixed32NoTag(int32 value, + io::CodedOutputStream* output) { + output->WriteLittleEndian32(static_cast(value)); +} +inline void WireFormatLite::WriteSFixed64NoTag(int64 value, + io::CodedOutputStream* output) { + output->WriteLittleEndian64(static_cast(value)); +} +inline void WireFormatLite::WriteFloatNoTag(float value, + io::CodedOutputStream* output) { + output->WriteLittleEndian32(EncodeFloat(value)); +} +inline void WireFormatLite::WriteDoubleNoTag(double value, + io::CodedOutputStream* output) { + output->WriteLittleEndian64(EncodeDouble(value)); +} +inline void WireFormatLite::WriteBoolNoTag(bool value, + io::CodedOutputStream* output) { + output->WriteVarint32(value ? 1 : 0); +} +inline void WireFormatLite::WriteEnumNoTag(int value, + io::CodedOutputStream* output) { + output->WriteVarint32SignExtended(value); +} + +// See comment on ReadGroupNoVirtual to understand the need for this template +// parameter name. +template +inline void WireFormatLite::WriteGroupNoVirtual( + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + io::CodedOutputStream* output) { + WriteTag(field_number, WIRETYPE_START_GROUP, output); + value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output); + WriteTag(field_number, WIRETYPE_END_GROUP, output); +} +template +inline void WireFormatLite::WriteMessageNoVirtual( + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + io::CodedOutputStream* output) { + WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output); + output->WriteVarint32( + value.MessageType_WorkAroundCppLookupDefect::GetCachedSize()); + value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output); +} + +// =================================================================== + +inline uint8* WireFormatLite::WriteTagToArray(int field_number, + WireType type, + uint8* target) { + return io::CodedOutputStream::WriteTagToArray(MakeTag(field_number, type), + target); +} + +inline uint8* WireFormatLite::WriteInt32NoTagToArray(int32 value, + uint8* target) { + return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target); +} +inline uint8* WireFormatLite::WriteInt64NoTagToArray(int64 value, + uint8* target) { + return io::CodedOutputStream::WriteVarint64ToArray( + static_cast(value), target); +} +inline uint8* WireFormatLite::WriteUInt32NoTagToArray(uint32 value, + uint8* target) { + return io::CodedOutputStream::WriteVarint32ToArray(value, target); +} +inline uint8* WireFormatLite::WriteUInt64NoTagToArray(uint64 value, + uint8* target) { + return io::CodedOutputStream::WriteVarint64ToArray(value, target); +} +inline uint8* WireFormatLite::WriteSInt32NoTagToArray(int32 value, + uint8* target) { + return io::CodedOutputStream::WriteVarint32ToArray(ZigZagEncode32(value), + target); +} +inline uint8* WireFormatLite::WriteSInt64NoTagToArray(int64 value, + uint8* target) { + return io::CodedOutputStream::WriteVarint64ToArray(ZigZagEncode64(value), + target); +} +inline uint8* WireFormatLite::WriteFixed32NoTagToArray(uint32 value, + uint8* target) { + return io::CodedOutputStream::WriteLittleEndian32ToArray(value, target); +} +inline uint8* WireFormatLite::WriteFixed64NoTagToArray(uint64 value, + uint8* target) { + return io::CodedOutputStream::WriteLittleEndian64ToArray(value, target); +} +inline uint8* WireFormatLite::WriteSFixed32NoTagToArray(int32 value, + uint8* target) { + return io::CodedOutputStream::WriteLittleEndian32ToArray( + static_cast(value), target); +} +inline uint8* WireFormatLite::WriteSFixed64NoTagToArray(int64 value, + uint8* target) { + return io::CodedOutputStream::WriteLittleEndian64ToArray( + static_cast(value), target); +} +inline uint8* WireFormatLite::WriteFloatNoTagToArray(float value, + uint8* target) { + return io::CodedOutputStream::WriteLittleEndian32ToArray(EncodeFloat(value), + target); +} +inline uint8* WireFormatLite::WriteDoubleNoTagToArray(double value, + uint8* target) { + return io::CodedOutputStream::WriteLittleEndian64ToArray(EncodeDouble(value), + target); +} +inline uint8* WireFormatLite::WriteBoolNoTagToArray(bool value, + uint8* target) { + return io::CodedOutputStream::WriteVarint32ToArray(value ? 1 : 0, target); +} +inline uint8* WireFormatLite::WriteEnumNoTagToArray(int value, + uint8* target) { + return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target); +} + +inline uint8* WireFormatLite::WriteInt32ToArray(int field_number, + int32 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteInt32NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteInt64ToArray(int field_number, + int64 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteInt64NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteUInt32ToArray(int field_number, + uint32 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteUInt32NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteUInt64ToArray(int field_number, + uint64 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteUInt64NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteSInt32ToArray(int field_number, + int32 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteSInt32NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteSInt64ToArray(int field_number, + int64 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteSInt64NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteFixed32ToArray(int field_number, + uint32 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target); + return WriteFixed32NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteFixed64ToArray(int field_number, + uint64 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target); + return WriteFixed64NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteSFixed32ToArray(int field_number, + int32 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target); + return WriteSFixed32NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteSFixed64ToArray(int field_number, + int64 value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target); + return WriteSFixed64NoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteFloatToArray(int field_number, + float value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target); + return WriteFloatNoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteDoubleToArray(int field_number, + double value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target); + return WriteDoubleNoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteBoolToArray(int field_number, + bool value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteBoolNoTagToArray(value, target); +} +inline uint8* WireFormatLite::WriteEnumToArray(int field_number, + int value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); + return WriteEnumNoTagToArray(value, target); +} + +inline uint8* WireFormatLite::WriteStringToArray(int field_number, + const string& value, + uint8* target) { + // String is for UTF-8 text only + // WARNING: In wire_format.cc, both strings and bytes are handled by + // WriteString() to avoid code duplication. If the implementations become + // different, you will need to update that usage. + target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); + target = io::CodedOutputStream::WriteVarint32ToArray(value.size(), target); + return io::CodedOutputStream::WriteStringToArray(value, target); +} +inline uint8* WireFormatLite::WriteBytesToArray(int field_number, + const string& value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); + target = io::CodedOutputStream::WriteVarint32ToArray(value.size(), target); + return io::CodedOutputStream::WriteStringToArray(value, target); +} + + +inline uint8* WireFormatLite::WriteGroupToArray(int field_number, + const MessageLite& value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); + target = value.SerializeWithCachedSizesToArray(target); + return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); +} +inline uint8* WireFormatLite::WriteMessageToArray(int field_number, + const MessageLite& value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); + target = io::CodedOutputStream::WriteVarint32ToArray( + value.GetCachedSize(), target); + return value.SerializeWithCachedSizesToArray(target); +} + +// See comment on ReadGroupNoVirtual to understand the need for this template +// parameter name. +template +inline uint8* WireFormatLite::WriteGroupNoVirtualToArray( + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); + target = value.MessageType_WorkAroundCppLookupDefect + ::SerializeWithCachedSizesToArray(target); + return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); +} +template +inline uint8* WireFormatLite::WriteMessageNoVirtualToArray( + int field_number, const MessageType_WorkAroundCppLookupDefect& value, + uint8* target) { + target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); + target = io::CodedOutputStream::WriteVarint32ToArray( + value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target); + return value.MessageType_WorkAroundCppLookupDefect + ::SerializeWithCachedSizesToArray(target); +} + +// =================================================================== + +inline int WireFormatLite::Int32Size(int32 value) { + return io::CodedOutputStream::VarintSize32SignExtended(value); +} +inline int WireFormatLite::Int64Size(int64 value) { + return io::CodedOutputStream::VarintSize64(static_cast(value)); +} +inline int WireFormatLite::UInt32Size(uint32 value) { + return io::CodedOutputStream::VarintSize32(value); +} +inline int WireFormatLite::UInt64Size(uint64 value) { + return io::CodedOutputStream::VarintSize64(value); +} +inline int WireFormatLite::SInt32Size(int32 value) { + return io::CodedOutputStream::VarintSize32(ZigZagEncode32(value)); +} +inline int WireFormatLite::SInt64Size(int64 value) { + return io::CodedOutputStream::VarintSize64(ZigZagEncode64(value)); +} +inline int WireFormatLite::EnumSize(int value) { + return io::CodedOutputStream::VarintSize32SignExtended(value); +} + +inline int WireFormatLite::StringSize(const string& value) { + return io::CodedOutputStream::VarintSize32(value.size()) + + value.size(); +} +inline int WireFormatLite::BytesSize(const string& value) { + return io::CodedOutputStream::VarintSize32(value.size()) + + value.size(); +} + + +inline int WireFormatLite::GroupSize(const MessageLite& value) { + return value.ByteSize(); +} +inline int WireFormatLite::MessageSize(const MessageLite& value) { + int size = value.ByteSize(); + return io::CodedOutputStream::VarintSize32(size) + size; +} + +// See comment on ReadGroupNoVirtual to understand the need for this template +// parameter name. +template +inline int WireFormatLite::GroupSizeNoVirtual( + const MessageType_WorkAroundCppLookupDefect& value) { + return value.MessageType_WorkAroundCppLookupDefect::ByteSize(); +} +template +inline int WireFormatLite::MessageSizeNoVirtual( + const MessageType_WorkAroundCppLookupDefect& value) { + int size = value.MessageType_WorkAroundCppLookupDefect::ByteSize(); + return io::CodedOutputStream::VarintSize32(size) + size; +} + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ diff --git a/ext/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp similarity index 100% rename from ext/RubyGenerator.cpp rename to ext/ruby_generator/RubyGenerator.cpp diff --git a/ext/RubyGenerator.h b/ext/ruby_generator/RubyGenerator.h similarity index 98% rename from ext/RubyGenerator.h rename to ext/ruby_generator/RubyGenerator.h index 1f76701c..1f01fbe3 100644 --- a/ext/RubyGenerator.h +++ b/ext/ruby_generator/RubyGenerator.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/ext/ruby_generator/extconf.rb b/ext/ruby_generator/extconf.rb new file mode 100644 index 00000000..f121b7d4 --- /dev/null +++ b/ext/ruby_generator/extconf.rb @@ -0,0 +1,131 @@ +# # # # # # # # # +# by Jan Lelis +# e-mail: mail@janlelis.de +# type/version: ruby +# snippet url: http://rbJL.net/35/os.rb +# original post: http://rbJL.net/35-how-to-properly-check-for-your-ruby-interpreter-version-and-os +# license: CC-BY (DE) +# +# (c) 2010 Jan Lelis. + +require 'rbconfig' +module RubyEngine + class << self + # try to guess it + @interpreter = case + when RUBY_PLATFORM == 'parrot' + 'cardinal' + when Object.constants.include?( :RUBY_ENGINE ) || + Object.constants.include?( 'RUBY_ENGINE' ) + if RUBY_ENGINE == 'ruby' + if RUBY_DESCRIPTION =~ /Enterprise/ + 'ree' + else + 'mri' + end + else + RUBY_ENGINE.to_s # jruby, rbx, ironruby, macruby, etc. + end + else # probably 1.8 + 'mri' + end + + def is?(what) + what === @interpreter + end + alias is is? + + def to_s + @interpreter + end + end + +module_function + + def mri? + RubyEngine.is? 'mri' + end + alias official_ruby? mri? + alias ruby? mri? + + def jruby? + RubyEngine.is? 'jruby' + end + alias java? jruby? + + def rubinius? + RubyEngine.is? 'rbx' + end + alias rbx? rubinius? + + def ree? + RubyEngine.is? 'ree' + end + alias enterprise? ree? + + def ironruby? + RubyEngine.is? 'ironruby' + end + alias iron_ruby? ironruby? + + def cardinal? + RubyEngine.is? 'cardinal' + end + alias parrot? cardinal? + alias perl? cardinal? +end + +module OS + class << self + def is?(what) + what === RbConfig::CONFIG['host_os'] + end + alias is is? + + def to_s + RbConfig::CONFIG['host_os'] + end + end + + module_function + + def linux? + OS.is? /linux|cygwin/ + end + + def mac? + OS.is? /mac|darwin/ + end + + def bsd? + OS.is? /bsd/ + end + + def windows? + OS.is? /mswin|win|mingw/ + end + + def solaris? + OS.is? /solaris|sunos/ + end + + def posix? + linux? or mac? or bsd? or solaris? or Process.respond_to?(:fork) + end +end + +# Bail if windows or jruby or no compiler needed +return if (OS.windows? || RubyEngine.jruby? || ENV['WITHOUT_PROTO_COMPILER']) + +require 'mkmf' + +include_directory = File.join(File.expand_path(File.dirname(__FILE__)), "..", "protobuf-2.4.1", "src") + +$CPPFLAGS << " -I#{include_directory}" +$CPPFLAGS << " -Wall " + +have_library("pthread") +have_library("protoc") +have_library("protobuf") + +create_makefile('ruby_generator') diff --git a/lib/ruby_generator.so b/lib/ruby_generator.so new file mode 100644 index 0000000000000000000000000000000000000000..8302ca207c7176f3ad52e5ac2e51fc26f55f41c2 GIT binary patch literal 310588 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 Date: Fri, 28 Sep 2012 18:34:22 -0600 Subject: [PATCH 0096/1191] remove .so from gem --- lib/ruby_generator.so | Bin 310588 -> 0 bytes protobuf.gemspec | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 lib/ruby_generator.so diff --git a/lib/ruby_generator.so b/lib/ruby_generator.so deleted file mode 100644 index 8302ca207c7176f3ad52e5ac2e51fc26f55f41c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 310588 zcmeEv33wGn_HSot2w}+;fr(Od$gf8^$Qqp!Pg> z=%%)Z9?fS%^76=j-&e?V_ML)$50+?oHnhuKgmPikRnZ^(we_5?>+8%ec~MG?4R!U> zwm!&W_LONejoLk@ZG0`e<(j~5e_h4?F6SOQxBnoP%*VNc2^>QdkTQijeIej)bow;F zt~kfyJQ=4CCy!*DZ0Ay(?E6_buf&;&lgDD5tS6obj^E-;z`2MBjyX6_!Z{jeF3tfs zXXCsICy#kJJ(4nvO28bPm*7mpIR$5LoTuZgz-b?;I&4^c&VUaODZciW7Q78g9c?lYmi{Qj=oLtydf?pS#CDX@zUbfErhi4KeV~8SWH! zG?-$08YwW>z?dj7io9$l^g%!7_~IC%Pvqg`VcWeBX||oZIqk|gVD~Y{u5AmBXO2CN z4UTpCKmD2q{lh*uo@;P^`&!TYKYshAxi^2lJ2!G#@ca`BFY+5{1rL1i>XBYqnI*Al z#V-!%cVyl-2@PjF^pB^aGE4TpH233y4|>x6bns$h-^f$u4;uTyhp&3}pSktIwBtET ziwDo__r=s{FU|eVx1&d&dB;b_ZC*M2k;Ik5PWb)v+biGibM-?7w|;o(dr#hZZr6mU zzrOL(+~^Hse);-uXP^4yyX%&9dHgq}$0}}|_tqb`eE7xOyS@nySakUKryB|ep1Amg zwbNgk+w1zli60!^Ug55&z921Q&xcFC{zJv%!B2V(JF)Q@yIq~ZC?nRe7#tkOIp~qz z4%|*=!QnXO+8-Z)xg-8KI7dhHG3fn{B--#WDc0$iKJJ#ntOh_H+{}&9Vj_57Wvm<&Q23$wM!%q4)s}uS?7#AJsvjXF;BYJEnaxUn^{w9KaM{-I!8AtK)9gmB3o#?Z?lm6}6 z34fpy{pVq_>qyV~PW<)=`nRL;duu0tb+nUyFYClUgF5ktk+54w^`6;@J-_M1e=h2z zzi#ftua0$M&jp>t)zzKY^V3f3xe)`aqjpWiqM)OG31VT=5q)%@N+cH$3L!+-i?)meUvicGU~fXWj&J&dGDim+DGpAx(E zFg9GE2!)y+0X-?lSfdDBd-8Y{i`w3xH>_0nUllOsia(=Xy?Fn#rek=4zo!v%t0rg= ziFt(bvwx=uNw61>6!EtnMoPNECusUd(q8DV7fd5H{ZT-XbFJd%bqJ3L-L6eug=Z^Z z>_xk%zbj16qvgL2esJP2eduiQxtCN^GjTCQUCfCir!z#e;z35d8vv% zMge13oYFt#2F(xq@+gw^41Tf{-l!MbztH`gRIBK{wfydy-*us)hZHbk;s3OcQLhN; zntvEBny62Coub=%mTURh+JDNloWIF<>|yMht_ZWWKK0s9YStoPuRN!sidy8ZL9rhD7dQ4iad7f_t*b%6@)4|!`8;c|>C z9svX&*6UiPaF4e0P1+6{Rw?>}n%@VM{oeGHTQU+26K8`~BZqPRa_!XZ!z?;%~hS_nnHKq=4}c?N<#~D}voG`#Z5)DeS{~n{>Sw zXgSoYcL(eFpdP>Vm5Onl?q4G}cmATX(%ed4euXbL*T^j{E%q6?^8k=lP@T_Yeo65a zMMmxgi*u(J%`dL>6;-5_n^v?WtGKjCRo`B~h~l!b!c|l;T3|-@g#||L%+e*rrG;pJWz`~d1+3v4Ri0m5 zk$GWGWlm*=QjRv#YR<2&&Mhyhs4QdW!BmTrlnIkZzk|S>0-vBqD2Me zmxC+Empnc<*SDaeY)NiO+5F;y+@gw#vI=R&Pqo;{k;(?81tn#b#ijG7_tthH2s#uJcD|}3Td3jN3A$zGE1!aHw07+K^q_8BL zn}Ohy5ahPMAFn zqr08MWaNxOu>S!E>$nO;^U{ps>GjEdFV zlv6nd3%TO?rMCBdFK&K+JpxPpr^^1UIe$cw%=r?-iVL*9dYb=PO=i^P{GU@f7v7JR zZo$Ibf&~k6=j9id{A@e63jG-(#!Cw`7nPS)_}VtGeMC(jnIrQ!7QQ8zETo$-uJ9ji z`Kc~2LaiwE>`+uV8OwCL9kSf`iRK-p7iU$A*AyjtI2q2JNUMz1)2 zglQBnjby%QUH60+B3Lk@c3I>6jP;jZ>*%EbBFdQD+%mOv)3Zs3YEK8}NYygUt(LDD zShULWRopwL5{v$+xg|yU3v;pNEmTV##;4YHV5Qi}YD_JRM?x7@j^WO^Sp2aCrak9> z&#{woiWila6lMC#@-uL)$)5X>4zQPYKhc*|ILYYb65_|NAI4;shA$t!7aqflyN;HX z$;oNF(#kLO;rdyHpEeF^H>kaBev;6i9tM)t1?E(&sc_{yxwxo=moGAOM+??|NQEZ} z`y!{k!pZH+C68S=^lX9x&R{Dy4Rk)^4-Vbr4lcVs5IK+Wv71voU z!tt9QmGN`tqHz*|b8tagjB8@7@XEqnIYy!F`tqlZ9eu+>%eS3mtj7O4(dx=xi~4!f zd+Yo&E58IwPVL0wIsXWyorXDOC6y}H{6sV8J2AG{O1q~2ex@6t#v(Q5{KgsCp|m}r zwj=+Xso%blqU!m69nN|5XUK0GQ`#&CoRT>Rewyt^j1d>t!Rp7?06#}}HHw_^Fx)>(rsxIuC?W*GCrMeR^CVYDU(-UrGa#7RaovP$9Ipw%}m?JTI zChxz=`V;XPmv3Vh;}X5Bf)|XqD6h=uFupsk9(Z?yL48Eh#YGimX=UY?8&YxSn zI2m`-b1RE;3wS?2*N2%J>&Ar*4I>w~J&fTC$`%z3pIcb8q}b;ho>;MX(QxQqTvSPL`7r38IAU1&i1A6o zQOAT1xT`8Fm}N{!OUoSz?WbgAPD;xikvJ-x8j(0!rDx9u$0%4NZT9TcNtwCHi6fmE z>RC)Ab~`%%k*aXDFSa!=8g!M5$EdQGRZ!tpbmlXU2Ooji{Cw=yC5%y`T}PCrD#+ii zI2A_(_DTPr{s%>Hu$C9)S(jnBfoBiA98Yq)8t0tET;@j_n{_^)ne{0y#uNK4MmqBO z%&Y3;VmuL!Hl~I7qm27BKg;{C8jL2J#>JZd)xR!;d7_L38utxehbNtpMx`#lQ9l<1 zQH~AzIorl(-GbY6_hyCLusz+msGkM8U3@I4ACXE%xr1&$GGs=zgN{eg;iJYu$0PLcvD!gL z$A*u32OUqb!^ceyI=V4@Y;e#|4^s_elY_q4L4V9aAMc<@R)=Q`*q4tkM;?sd>H(85QygN`i&;bXRgjx7M;BhNv%eUq6B9CSRI4j<(XIv$~i zk7@@!FHFTgT?hRl2Yt1Jewl+_@1Wz6d-%A?LB|$}@Ug)`$5w*yvC%>A7pB4w9dtbE z4!)S2O3mo(v4!Scw>~hejJNWlG=*u1SCI?-IHp#UdbbC(?Gmbjwr#R#s zchFCD(2Yj7VD$gfB&B|08r_m0U2ho@+|}q7NP4lP)K7e)TN0$7E-CfnZgfk6^fM%- zei9npk|5pQD?vh1qnkk9|4=DGjd6_%BmbF-B)=(*Zh@rtmz4VPHo7H2`dN}vKiQ3L zNswMGDfKhE(JcwmeDfP3X(JcwmYb2$9b~U;s zLHck>sh@p~Zb^{-Ye}h}rbf3UNawo2KCDK!BuQT+DfM%-(JcwmlO?5ojyJj`LHY7VD^k|2G7CK1Fq=p!9;mxDgXL63LPM?2_l2Yr@U+ti$ zI_UKddYXfNlY_p@LEqq@r#t8y9rO$beUpPe&q068L7(iPH#q219P}Ly`g{j{mxG?^ zpzm|g^%gJ5ZF11SH|h;u0%N)r59;#>lU+=5?CoJ+5eOYkd*_abfxUO}8o zt6AI2tJ88mpq|* z!6y*!N4!Sx5yZK~36%?eHgPW1LwSPtC(b2DC|mH8iF2tDN)fy_aV{}JNrJ}`=h7nN z7Ce$TmlPqF;9so-emZeO@K1?zNf0{vE!+PAaX0ZM!4DGWR3F+U_#4Fg6K@cFH}SKG zZxZ}@;vV7~1b>eB0OIw6KS6vT@fyJ&B0h+Cx#0H^=TsZY6Z{V1oH9e%g5OM>Q)MVc z@O8vFMTU|Dzm_II)boKsDxM(`2DIhBOU1wWfOr;t#d z;Qfj7k}H%g_{qdMm4s3R?@gRjMJP$|SmK-_LT;7<^rOuR<$ zhlo!hUM~23#J$Ax1iyngLv$!x@SBM<1cy=tUq_rFHk2gzwZs`(LvF#ZCeDx=atVF~ zafZ^6A$SFGF4aOuzmonZo=v<-@VUf!Nfg>8_{GGh6K@cFI&p^n&?dnzAU=cm2Eiv0 zpGmx4@Cn4Z1PRp$K7#nKh?fg~Hu2fS^91itoJ+A#w%{idznFN6;Jt}oLOe7w-acm5ockCG7+(MTsWb2}(p!6OJa`RX4{zYywaBsV zL$7#)r=7LTZDa)p^Z|gpAab$>zw2%MI?7wy9N`_muhJcN2E5E$+YsUPn~RX2+R|qW zSmz>%{EGLtnbVMrxFmJX&du}U&R7W*v5y`VzPuC_LIK~&V6R;cc4*qm8$9Qks;@&(j(XJ0Ung3DwiJg=W zp8JOtl#J;+h4u~f{p3pEfpgy=2##JVxm#jFcOZ9Oy*F@`3)J~=5E-vCbG-hqRi~6C zcqf)6RVFFB1(v$JwOeDX{UQ`daI_1BtXpV){{idwa1QUpg-I2A*nyW^N)y7~sWZ@` zC8#>n{|#)};L7m^%96Z++yt6o{9C?XC_aj)7k}6s19H`o%)l~Fg14^4XIcrzTUs)M z%RFwY6dadan&m&7Iw$lHDppMX&5F+m^GyaHxUB26a{Umwz5dP3&1kQ=Q(Pn)Zs&y} z(=D&R$1l8rY&UQy^(&X6W&Hw)Y@8|RBIJW_`xGuS;0e*c*lhQgwC_ep{14i<3Ho_! zzu!LZ7k2xu0|)iq3uD^tJe#><47;82VgAcB|2;H5ESQK0t=ic}zc1jY|ABt4PW0P& z%+~K?)NJcD0(G|4t0v614SZ}zFRj-N(hszMmcPVfW%+%cqnZ9=S^j07<6i$9&#qKI z^e*x2%kmd`n!GDMti}Q|EBJt?N$h>t%7ExB{}JnH2+9iH<#8k58@%3gp1{%P!4p|u zB3poBe5;Dt=d0|62$x=zjuUgeljZ-w>;Kpr*6)bb&(>Gqr|JIhnClkoh<~ef52`06 z5$*9?-oULMFC_;a@MHsK1@7|97WjZCPvFBIu7I-wPkG7#y(_k`J)1NA+bAR?&iRG4 zf(G<&W3whhe)GFf5xC`-wjQ=tkoXQL&7aJxZ{A~%6R}?*?e`6hDfVl^h+W_fmUxo9 z!E{edrvGzqaE9l64tLBP-tFlg6^;BykW@~L1Q)HaOS%Uho{rIVR9Y#9$q-8+x!ro6 zHieF#ey;i(BfsxpO7$PIN?9V{^B|@jwr=O}4b1U)y@3)>c2=O!Gdl~ZJj832HAO!(?`5=}!9VM=l5{In_DRGG7X0nukzp_N_mIQ<^3?t^e zDXl*Y%=!dO&CSgya0F=F88tMYwV%{I_4at9H}9h>H+i2t>#W$b+@69mIyHR0#B(&& z{~CS&I6QnK3S$VUPJ2f9uv=2Pt5M`w^S!Lcu^!zIu_c$kEKGU|6A|lvbWL` zdlu9|UoI&1d1AMvdrDAfjwi+I&+>TZfu0@P+WkM&_x~0PNZ)6|E?LkF-Sd)|=!kXf zvzC^OmGAlTGXqzOM$tC^c*c2Fhwc4wQO<4|r}8 z_^@XKAO;A{0h=0j1$nF>j<)@yWwBTM+hsnnE<`=rnaV}c!`3)f&9Sq^nhHgm-)(-| z(I0w<9K{epc>k7Oc;lxnEy=r410CnSPgwe})f+|WzVUQlH@yH3u$4K-!A{Oys4w+b zsk2gNrp|z0)_zz`r}QF-#RL|_*L@Us-H9CS!8x8hYbB+@;mXiu6R_Ho`Aup7_Y+_P zONrIz#0NGJeZRv#Rsb6>ssQj+fE)xSd@jSFFPyf^CV@#@!eU$LQhKaey@Lq z8U&@uA2A)T<3k|DorPc;h(E1f$bNKZ!+Xmj4T@o2Y>jpxrODBi83oAS1aU z%l`?2W0wCr2Ge|)ox$l#$Y8loL>AP~Lf7;W;$iDefi1OLBRI2JFA9%t$ixNlacdT0 zjR<2_Uvg>coYYHGFH6l;W<6r95cwEdTdfvb6#qUXm) zQCYJyK5?jHY$G0v{5hT`6_gQ=*-?m92)J2+L>bu7Bo$W%;dl%y|InDslcqziXTXqK*5g%Znq8r zHouEnXyGqmq2|}?^?I(=|5tptBhoNxm(PZ2mm%sSO2x!ox86hp17=~R8x#0bYItKt zP5~;n_%FJk9Vdko6c6m^?lZ3Wi!XhVS*B8pV&1l9Hq{ zua}s@>3#!+`&UY=@dj6VT!Pd4F$88~-R8**PFbKzAvBVuUbB?5{Ih~^K19wYL9UlT z#msV@>864S;dmcF|5ALC7i%<^cl%1uI56@+GF~T1cH8Nw>^uxl4;I5QR5n56uJj}k ziZsYi@dnCctRo+>i=`irSO*0`D6n>XNV1sAeDAlgv%h8AN{_{$l6;I+H8F_;)R2T4 z(2i;vZMXq>6i}`%M^<`bkja9_Z6>7c$Eu{q*t!QIS#AMojMzLf{e5sfvr-9-s=38zYzvw`fRdRnvTxEXWqq$W_})&ts5co%}JI zXBIFYU7np8ToR8Ojw3IgwK;gfc0JkTG7lDob*%u3()+*#!u9gz%9(MGMxB%B z>vc|U)y=Bj=B@MU9pd3#9L*D~YRI?gh)`jAp02l5>*iXTES@H_?m(O2xz^bdfR9+~ znrT-(-oWLCh0er%8SB^L?miF#=Xk99MW_#B6tOT-?8Ym@8B!XutqXL@Wu-_eor4M2 zl9&z8XW1auBv9KMyx#MSz|lK#H;D7|QQ<$w!q(^zM z+-`xRcmvfg>pQK0*Yb#@hb5|rUCt6yVCJnwP{m}75F3L*c+SL0v*Xsx;`P^xEsWQW zc{mfnpC(N}^_=LB0tyX*%!)!)%}qp+b1VepFc5g|0xJf5&6WfZVNYjl)d8TB0MWb+ zCF8+uErcj`dnKH%c@t734y42zL>Rm98t{awxNx8!kfDkS9MlX6);u!sc0P>C>{-ly z4=GwNlbL6=W{zj3*f|c>)VIC9aIEK6e7Ksug}KaSZABSQ0t|v|s04OKY91Kv;ed#= zOOv@;$CRX^IwL=g;uZn8*1{bG+)v3)lC@e~?I+O`Y@S=9rpbDU<%KK#hSTJ7Kn`(x zW*leFjBp9usgM~$&y1Wj;ia4_1H7qWPm8!FU=$w5EScTtrruf$17`*YmmO5}M0h20 zkyA~rYeb!uo@GK*6RN$wl%aRT$~i1?Y=Jf55c_EcDhimh7TUAXJ_af^8|`8e2jar( z624$Fdxm0!m9|4bwjDYdN+oFPf=q{}FQmh>lyWvN^KX(WT4y5>%1PxE_9X0(LLFx# zDyqq71M5)b^DrrNX)}Wzwp5eK?OAA(md=_UbEF#_=?-Tn$8gxEdG!=@%5U80aWw_0 z-fx|PHh>k@%q9yAB=*qL%0^^aH^TPFZz^^h45b{DP>ge2JWD!Q!PT2mWCp@r0Cw(C ziinmbUM~)p9=I4Y&VDr+oFXAcWwe=bnkRDI{Uh@Y{nlC_>b0A1F2a1XTUGIxbji<| zZzz6(6$ANg=Nm;oDxNsgXgl9L?Ab-5zy)wSQ5GT`2yrXtz`NM%4a^?@JoytTghS=b8q39K|_E@sWvCEeCEGCc%ZGcF!6 zGi<51CXy6vUJXR98`r3bXp40aEn)p1z#BP&tYoTLA+rvG5%_iZT&W|JEPcNhY?^s% ztN9uHgvOw(4ejfL)L&)#zX;zlSn=Vw?#e9~6gkz*W=OFEn&ZX~t_#4)dq2CtAkmb5 zigY-1%1pz!i%#I;U&glh@MOf|@)&Orox`g!|8`DIUTecUuqP%LHL3Y{$#%pF2$8dg z|6h#%Dc;)c3#_6hn*OxgirfrDR{+5Oh4vGH|TUG+*7Wh^LS;rfFjAdLuccTS#%!zBG1c!eu4CMn%f)5NkA-z zf26Q^<(T=fwB61N$!H*?Nc>mq7y~&NI%J0E8rFe>>D4MJX$E2*A`5vpDHQQ@yIhTI zuyN#Vw9}{$>X{c5x^+OOF~b)WqM2F8OoVdA6cwLwr_6epwhx%`%*2>V5&ar+= zdF?hB6Wm~&LPm6t9nQ09nwrC$m*9RkexxxXiGxGM{98Auuyg z1}8mWt#Ar`jcrgjcz&>`HFzt|*!sSc19xh;=2|Al9YDUa7=Q6tYPPdFotSlQ=EpS6WDe7IL`~a;_E< z?-a6730V>r@;nJ>bZ;$WlNM5~gml$HUS+mzlYvUeh_H}4E#$>Faf>)GC8_p!WZX)A zOSATPMBK{zBoP(2@?#`YYp)vGJ8o5fh|dg6@zOU_qLgp)p3m3&X;nPJ5}Mqi+@Uqg z28q2@sGEn{srY!OW^341l=#jU!E=E1Uw8Pr{^bJlnoVnK&;{J>{caE&KVAm&b? zk6s65Is6da_$gN&GG8$lfg5Bm$SpX?Qm$E$tagw$XfpIVE@G81aBXyO?P@K&&n6>) zCU8EaU{-)HwaI~G43c)eNt(=n>n1;I1kX4J4;#hfWE`#0bQnT>f!ZAd#s-9J9tA4y93rOP+gye{X6W^^XM$fDL=M;C;clI zy8Y-9%zs05`4~XDN+KZqFA1*rPe_FSaR;8ZmUkdCkcd-t-?)?I**d>+B4fpgy)%gI7;bJ?S9K-=`d57$6;C03e3`D8uKK=|oGt zOi4Xaq#m#iklT)VBSeGI-y!dbKBD_}>pIdPZtuUyD0ifNyb&N*C_CXiR+fl(SXQkf z%DO^)R;_Qt&kEz}_VqwZR&3$=*l`(>8eljw`!NU?^r`m-qa$0I0!*0G+RzYmht^u% zYL7?7ts3wx*5P5-KK2|!@u?uyRHxHq{BsN_K3RYcba2b@rti6-m98KGNxR-`O%A&@YXtjj2M-&ji>|iGc8p`y6wgL$ zp2ut+kZB_xVb`V_pj$SN9pk8nxb|RL8?K$FoiJZHp$~f=>ADy14Ljk-)`Q^Hu029r z8TosZYflHHFJ1r`>i;!m;woHE<~}7eR%9Nqy0prC+xoTCKl*v}9+x*)ysG3xQqEh) zm7F{+r&7szZZvrhSkJIddw`svotopM$vIlXne?$C11rW{ktNz!u4m7EVosdgO# zPq%Ums|Ov$-J%el=d=MyRy9DN7&uF}rEwVazNr%KCl zX*s1z&c#~JET^1%m7FWIoabLr_L)vO!?YYj%UPu4^wx5EIpyRlIgd!*cI#>_Czf*F zKc?DsR4=(ol$__WZ;q$U$htb^@&2Ad53G zSDkfKnqyFCvg)Kg*|jyg$|6-S@oYSnp*BoA1d#SBNRCjmospDS4n zT2`@=wN%Sm;*|Bg)I0iX?QYF4Q}h9=l5(bLIh(W`z9#^ajns06JLO!hhAU&(1sR&6^>-R-tbP;#EsaxT$w-i291&-`1pt6s~Qr{vtJ<^0Jh=Tj;d z9Q}JO=R_^%7Rp%+IqZ@R2!WY_UzLL|mu=Duajx1wlj0A^18YV=oy7>bgQ9|?hoOXA z9+Ou1lF}@NL6tpoz=~i)kTn=JQsSAcITA<9{Mg9KnTCEAWrBC;Qlr{V3YO=j!D zYDg8gQAt#>4W*iI!2+Y4-E$qy5j0;DU|(9OMPyH?8G7(D3VOh^3-y1N8t0mV_Smts&uoXE(+(fq4nMUW-nSk8 z&3A3(f8Gv%vmL&t9sX21{E>F}t?lsj?eJyo@TzwBoObxkcDUINk8Ova+79mv9KAu; zQn$uq>9**&gU>66^IH3ml9!X%b$kjK-Bq+3-$To35fci~PoUJ3w1bOsvzW9c5GtT#D~ zE(O`9;3jyyb!>+wSl=MdgofLFipL!tJbcLVkBSU+2Tv#-m4{;S(`t`Pi8=afdOQ40 zTzNS2UucJKZHGV54!^q{zNQ^s2fV(u{xF=ES_J@} zr{S*rO)RdS{nu+rp#FhLO1B>yd4rQ&cq$W5nmkz2`5itkf(DN+OZ`qa7hyDDVKVXs8)%Uo*E`_P;82*gMHZJ*tXRwL)spG zzy$hDHr+o5>INstV;&|J(B9J8;3SCZ>qX@hn#!7Cs~;2W$g*GfX8f>Yg&tkr8I%j(DGV%wU`b`rO^vMNU@ww~c@hP0~h zR()H@o* z9mC$~bWByQZxR)dDpWUHgV;PQ;p)*K-e3BYz|mO)fMRJgTeQQ*Yd(FtpMy?aYSCVj zzlHFKl?_Nkdx=9c8UERj#SxE<<#MHW%VuPvE<@%k=MJmq7WKYiolx&6qJ`Y( zIbel^goQL%o$5ts^?t3@OVaB7QK?t0t#`6hy+t&ovfihXJYb!y)$6U*ixu@`^Bp!c zW2eQ61hkX8?`kB6PxtPT6n2(COHMQ~)?I8YUSmMrj@y@*kyQ3pRK_)FP;9c@s#CV% zjCHd#1N$EUX`X8Vn|E?n3!!t!QB4Zh70n0gn|G>pL-X4j?$@wM!+SM+1|G`|clLWK zInulq>uY#4o!OcMm71?Z#AX$D6Ir2)Slb(^N{jU}c$;@4pD__Jwo|8WevsO249%9s zqH}*dw?5!?mDCxT{(s9m6DeM9h95n?KP-ngC6c^BdFH{ll@Ly0YTPXZg%Hgr&85;3 zt?^jK$`pgaLl0ZGu^&`-p2cp4GhYbZ)k`FOkBfsIvUW&wu)k4fS$~Fv3^d7&EwIan zB=1lD2u4%u4-B!)D4!>RowW&U>cxhn)QNcWV%b3owq9?rYZ%?@OiYS@02|qV2l0Bh z_F?OKs#Ciq#dZe!U6Q9n<0IBeQFptw43KX;9NE! z0O0h&NuIk1IKH{`NZ?FpuQ41Ger9ko79>ZQ8=m($`*C0a%1S0MS%t19Y6h7cb@DRA z5$i>exX5wD2JC!3Y`y<9n}5VQ7fP~-9UIQ4I>FIC^c%CkW47#-wsOQtu56WO{bMeDP*IiQP${2585r+6uES&nTNOePXtjeScBxc)*JSK1#3d;x#Gx993 zv)V1R{3TRu*xM-(70i$+9^x}(#UxD&WveWIl?n8nCY3DBqY6K! z*Bz?k7pfxJVMQ#z#1|NYb0pRE`ujwE&)89pj#Hi4+IxMXpv&{;(?(p#s9v`k#eLP( z>J47+Iaj&wkyBv>4DC;;kN<7H=`}@6#)k9$5E16H{W8~Cl9H!QeYc#+v50M0m>=_` zMGwnBrkHvfX2lkU1Un4k?XOJ#c4qz^VmZewB@?Qt6o~n5yR|x8({iMmUjYsK`GQL^ zo#Faf)I4B~MAW5mtSca>`9WyN+_#8quz6dapzH%ySMYKk+b(V%zT%UWymt6LQO$p2 zJr7_QQ&2Q&4$Wx6PZoX@k@tP9X2@hvcvs*NYd>IU2zXG6*Zqj)B49Jc8O{o*-c!n-Jh;YnksjL}t zLr1l>5bu@F#QSG>cmFfImgr6oEFPCpcWimt%H45wH;b36S6_cGeSO&Kf|9MX#S!bC z$Jj=^{|cqk0}E03qvazql8~^P!E766z5Y1)7lOa}rFy>7=;CB{2Ewv+3Z3bQH6Ln-dOFH? zg?glyp`_g4(zDU|66Iw!nt?35nOEQZ9vC@2rGdcy_*c9A{(N_{)l@No$$U3BQ8jSo z?yBK>y`#WyA?qK~-FUtan7msrv*&_8jF=D^Ud!x2jyEs|K{Zg~@n!`I`F3{+-|qI| z!lxE*cT0a9who|nj<-Lv00z;Y0QnlBbjU;hz>SgmAMKB6Cn2C<@w49)cRTVD`rT$|EsNhGyrmjE_*jnxd5YU z@b~%4o&3p)e*ydj-B1Y(;T1{oZ0j>xn3j24;lF1-hBs(>c&CC=-^uu%mcVt~_r~|j zn9?|o2coERd~bW0mErpZkD>{IG!$<5!SUUu-SwHyIj$YS^i2yksK`2M!(sQO1y`8 zImWt)N(Yvrow!fhwFU3m)-~XABW~s72($_*U&{XY@2dqrZp5HzrPnYm&=+cZ{z?x;A z@kZ)1P}uOz!&>c}vFX>bytYKyaV16u}nd{#8tX7vM3=8s|L&~Ltzk1Zgk z`p{)xSg(um_fd`B-T*dG`*F_=s!Ye?nyKy9Sab(CnPFW>ZqVV>f=|>q`Qn5RF$a8S zX?pWsx)LcTgiB(?0gtdbUTFR>e0|*ftn$C+Kf#h@v+pmw%63Yrq=SMWdi+-}d55@Vl zNnXPDa!SQ}`1bqv3EuHv_{#ZZpru~_=eQj`7~g(4VlCZ-I%>a-zzvJ6U|ziMJPcA< z_8zus(BRbV88W?Q`WG3g+oFe})0#NjonWv1(AhS&-CyV{v@?IC3_%2nuHN8PUh5Uq2=dJ&2bYe6Lde4B zx7eAF&>QG5?93e$9nhV*w5@#megZ#N#7}ID<8zDzZ!PX1V4LzxUb3KM0&cg;#UJ`% znFn8@Tp6u%+;&bpbK;S6i_XCmpvvGK6};k!oC|ag8l!UHg$M=6DMXwR4YTkuj;Z(> z$I4ScnHpFE3;y;XDVd-47tvxZ!is;rPA} zh8SeKfm&U_*8G7y=YEH(aJEqXZ8f8k=9inFhiqZpPyAWCJH3I~Fz@yRYYTOez*@WA zZ9QsZ)*RGIACHl*Te29O1lMJ{SWq)kh}*i##;gIlm@9NXqGKqNYOAolRXAsYQ{KN) z-rYB)q^!LllAEVJU7#ZP)tCu%S9Pi5A(5U9sEh8#lO5|{NVM{_N{ z_{xa87l>kD-|b?YZSpeS;^QX_zWXx$dw4yA;L9(1aoE-!%k;nCt5#F?vq=~+Rym~L zf*4h2qG`U95Vg4U>V}48V*bQUu`3g-ukS;>!3#0-@grU7nE&o&pVg)%;JbZRN1>RP zAy^^d%|Z5}zV7q}r{Fts&&91=Dz1`@JGTf8vmk(XnO^aZ-{p;)yu&+w=V$k%#@)Cr zZe3$)!b=%(&m6;bbCugW_&F~>&((5O+}achSn(AaP!qRi7?4!|-qgmA&ydYJGRtnZ z_EKq#sq-*y7&I5(+tOm)jvq|oeD!>@^&T4mjy2$LgwuNa#<<+#g@#kOIE!1^gDbN@ zuc?7ltGPeNp?AfX)L>b3-OkG|WakA^TxvyyZxMR2%)=7$C2!zYRwi2Jeu!FZfBf-6$#@n zjh|QVE25_T{tOomT!}dYCW41$1*Tb3$M4AU?{sv;b8xbR=i{E)UAMdH)Tx6TGgTib z@j#@1yQlk~uiG8xuVoFj)ttaiVnh6R7=%wA$#c1l8xe9Rsd+~=AesS- zIAYC$e>d+EKOBFl+gE`$+w(yH%6NnH4EX@pP*|d_;qvX?+NJS^FB5vpA_QXq_s@~n ze67|y!0BVJ#GvE%NSWVbaSJgacK#7-GnhjcLwCim44|?$GV6R~K~JGSr|9*h4+7mW zz*1*r1#>YWeiFX$&+_kwv)Dt;SCSRzNB?L(S>|oJWA!ibB?Saed{%O|FAHzrD$oDd zf8hDgwR-+lPiP;%@_vZJ;$U~x!@D#d`^UF@NDwXolq&zx9eaxhSX{C00^{r{PB}^mRu+gMSjB0 z5*ROwT4ZreB8yB0JwEirO}E(?Jq90gWOK$=J4>FW<}!5;#L+z7T=evApzf;xTdcVo|5k4 z?WDJf>(4B#za34&HV8iI)ay08OePF(TjOX*%sP2@u-!dh8Q=y_-`xPPIlEG#06IE# z0lVcfRv1i8Vecc?-rCY%m2OtW$gMqqxo+2w+DRejgCuoS;wBC~qN4K0HyoL0LpS z5tbFKz0vJ$YaoTeBGX{DPzY;WxNaU7u04?v+Q&sNmrN*S4FL;Roqv}iN35>}Zf$Oc z?O?a9*7K-{47=ew5{ypLoUag~bubfTF)Zi-nH`P~+~CvvJo1~jHV2^)O%#b;#!}_H}4FGN=a~ajj=HY-xqBCe&xUZ)b{r77q_v2hpk`IMrx6a z{;}^;P+eq>kjx`iESk|;2cCtz&+F_MOeZ_saHQJfExwcRJ?$rf$U2}o2H)fk;5zWc~`Sy)tFQB;uc(yKebo!Ig%jbWD%?9JkX~Xp@O<4ktN0ZM@u*818{ew?|yw zlbD$30lP=>J4J~lCrn5$t3rd619aqgGx1lyZO`i{e{ykkQK8MyfqcpT0q0bI&i04v zw~KdFf6hEA5a#H#or=#^RIzm^5A6+0>!3Y3PJ6Vszh|C=6dC>=PdJizFo1NHbm~yI zr#0Y!uQkqiJgtF-8O})K@r1jVp~i!+0U$C$vMrM#H9Xo-r>E_JgAe?uf9Wx)&11lI z?4jvNgqp>rMUMKAhk!{vepId=zP9ToCJqn(N2BCVz2@qnQC2aWqb>YbkrNBb%WZv9 zOWjqa3rowEl)8&5D#|L{Wd#LQ6-9;aB^AX!{6SK#sZd^_Ag|1zIj{)Xk{n!M!3D7W6 z57r{%02=^j18&-g=WT#BxL?PwF7UZnb{E4)*#$X(O?z8fb^yBfp*-FOZvadHJo;8k zOCDg#+u#E%KL9?!CP2QWZoC8iVn7Gv+u!bks0T3nUDN|;9ByghM!pn4ZrF2KEiL7M zn*jF_4*^HJ>OX{i05<_P02&|TZX4Ts1m)SjPf#B4=%+0$N1?wPw?LAhFAr>hkt5=Y z?CC~CwX4f5vrcy#r}XF=qjt>oL9PeqxLaFV@B(f4ARXT`F!DN}&j5Wj=$Hl!L^8?`Dj9RetOCC-~rem!7xE#!-g zi+UxcDH$LO-vfXtkh7M2#o(LN%XPt;NQlemp?rq+aexy%N&an8E1lqSm6BNvXZY zrS~eosJ82>E^H@1zS{&}Jem6Dp|5WI|%3Kp2jJl5cr`2{z@0E=b%HFKM0roivT-j$$)GDZ0KDE{i zvMwBK59?oz81rYOqoW|djSr=Os`y?2p9`@^^k{*0Ggg_kU8V-3);JHp|WJq+ElU;VgHK=wcYh5xe*asOU%Am2>)E+Nv&a!705qL{F<_{KUa_r$@uz z5aVVc9laOj9rmRBLgcST?4AinjecIqPg@(=&ZJX%9qkvnq*XT*#KCsmh4LFQ->pN@ z=+iOjcVv$yb7pJVwUI3MCd#=mM~q}Y-We{JMsLL6N?Q{R|3rUcOu;i((VeBA`XCkm zN=wTI;L&SUIRqJdV5~vlN}~L8z*i4G5AC)*EMJXV>PdImFS9`-4N%XlaS) z(Zf95I0<$hi4%CN_w=hHjQR+L^&VngW=u7&jWB)(j}au_A7QSIG#-f{-_w+LZKSGd@or)V zBFuYC!-_C(H;t>mAkxHydtapaU8M2%Nb|EuV^5@cZ1($meqMn>g9*C>8N2Gu_tX*|oy;6zsnD~l$49${k1bWNmL z7iFxEG_gFqBhqY+WC740Vu3@tf$mGp$0Ce*u00XPTui zn3tokeji~>MB-xecM(RBiFtGpQ&&M4>P-Ac1Z#UP!iC!QNV++~d_U4SF1oxB$#fGd z{Y=;F;>bVKJl7Zuc%hOqWf0&*b4w&0APU`!)L+;G&qbIkql~=~W=o{;L4+BKG(MH| zR}toW($beBjkS?X-xi54O+X=++srbO%wHMf0H-VQXza6W?3-*XQfnf5z7b*E9%1f| zFkaM+T_5pbr1?U3_F+?Zqc+Ms(%rZt+We-wu|L|pwujNs#eBSnv8T(I5ij>JUWsA$ z>oH{gG{$_hhf&k5_s2bq8@n-mdpFYW@753E_IESC?O`15)_ZMF;~Pn@iaibVr(?}q zdm1}qT@Um$-jwuvu?e8x)ZKi%r?I~~6o0Cx(*Bx=en>nPY3}M_G)9^`dKgVn=H?#8 z_0i__J&Z3*^V9A|eV2xaP07#yerLC_5V|7Pe5kwe*I4tf-HmOr=7#RZE=j)|Ykm@I+(KO*;}5JmX8_;}Fn%|q zF4BCq8&$cvoAFiD-iYD?JE@pE#ox@|M8AAatQna;Q0}&onVx{`HkSM%TqV|Q2A))B`0lKx2OUv#Con`6wU zM;L#OaXm7^ctX-I#gP6{jCuD6NPoDSS(j`ycI)?flJSP5zwBnd zpJc3x?YAe%_){#?&%~NrlZ=1H_Io7Bcu&%`-Oam`jQZ~Vo*QZ0E9o8G&8J5id%E{~ zf28rTq&M}T{LMYgJtK{SJe8E)KhvU&G#qw!>O{cz)@lU;Sgjdvs+68a}6 zQ_lKR%+C{zJ5K5Iej@fkGX2&m=AK03gH!t8(;h2MW%}+@%|{ZAhfeKtccQUV(jT2_ zu1_?+I<-$-qVc=an119m^YdZGbEoxrf0*&Qq`y7Q+%wF$_VhkmhZ(n@&h*yP%}0hA zyHD?P_b?+Q>EIdW`eDY+XY{EXX8cXkd(JRFA8H&tqtE+8jV~qrN4NRbP~$##pWQ=^ zMoGW#HlH7AeCqD=+)%@RCe!zv$+kRxrumPd#=bMnhlU#OpXpjR)Hp8bn*OBU)!)2! zsPVV{eXbsA?2z<_{mrk27+?19^XU+y{w$^+KFj=Ih|zdfpMyh;eUkp>Ec1;ahTqfY zl_ACk57Rq5?5}q{=F3BjFFfWGLyT(&m=6yz)(s%#<^g9T_l*JOUxyeU4KQyWVtg*? z+Xg0p{@Oru-4NqVNv|7ZUOU9tG>FnR4>D_q81G2>--FB*LyYwaq;E_xTh2CiO8U(N z^Nq8On!)DQQATj^N%#uZy^?-$uzB|=5tsi9^ll0AJn{}g%Kc9Wl=Oc~HlK$#! z49EH;H6|a6SY+PT-B@Y{dvcChjgS>-zT3n2TeSIN4`WC4mWYNP#?~(8%{`1QUCH!r zS94tt<7ihGLTPOb(}5V$e;?ByayG}9SNAaXWBheD-j(##-5A!^c5^WdOZvWUlEx)kc)u6={4StAiUO70-!-%+(RbSWbTDGxgj45}$q_vCw=d##nCtDb~0l z!dw??+!nz!77y3P8apCfhq@X2CH=0@F&Bb87-_!K&A2Jj^-4G6en~e(lKyU#`9e42 z#%S~YZpNFYi3l1pPhZ{5cpR}a#<;I5d3JU+--|I`>)QLp7$YR<&$^xl`Ykc$))<6( zrS6c?=CKGP!(71`6sfBtM)MNY#MRh)P&3l_P}1LUPDPkKv%owQVU)URBaIaiOkN)` z2t_wXm|sR1|JF0&Pn5ZAEM!kI4|XvwGym1axWe4ig(muY7n%s^d$5e^!dV?0FxQu+ zu~pJ9M$9%iuieqrcrh{%fzKkYjrQEo)p#=6{Gf}mIobr}rD$d!h{l?;-aLD|X*_L` z@NW}U-r5B}|8xA01^&kZ|6_swvB3Y27HHAOhSavLx9M%E|K~7Vjmt45UO^k5)efKE z4qx03U)2u(T|4~NcKChm@W?pYCKNs`TVgHvFL_< z{++r##pgym?1|Wm_g;A5R*@V@`aUM^7RhlHUYO$1T>*I~pGmp-1!z6%CThryBfz|F zg35CTrnEQ%@8`*}THjx@>3Q-{2G2`$eu5UH#f0noPTyYJHB2$WU*vY1t;bP~@8AtK z9N0eHCSOti-}!ZKcK=t(Bs|@5`F<0W*nt|3(QvYcvoxHi;bIL}X?TN%_h|U2hTAmU ztKlIHk7?LtqN=x_h66Pmqv2!?XK6T3!^Ik|((nci@6qs44Yz5ySHnXZ9@DT3Z>;0! zr{O>i$7ncN!&w^6({Qndt2Dep!+SJ*RKsl=?$z*+hQ~DQa;~ml!+{!((QvYcvoxHi z;bIL}X?TN%_h|U2hTAmUtKlIHk7?NDJYBzr12r6@A^$uGk69Yd({Qndt2Dep!+SJ* zRKsl=?$z*+hQ~DQa=wz^Ps4#4j?r+khO;!Br{Q7^S7~^IhWBXrsD|4#+^gXs4UcKq zB}Lb-;XnCi%CYccg#f*#tm;6#{9Cf z`6WdYCfK{JCQRTKENrK$m@t8x2`5Zwvs0uUYAo3QUyE4w=Fbq3U4cD9(~6d4VY`g+ zG9*;`3ekxC;)-)*znNQb=U%jP3Kry73{`X{bA1*0#lA`*pQq{hB_(Cpbyx-=;5g51 z)BkHZ?(-&0SWfMXS#N1w|7)2O+H9^9jn6*M7;)g|S~H`xprou4JA9^LQ(PtXNEJ<$ zjhq>!g_Xu7O}kw+=Vz$5yp0PQE$?<sOX&kt&aZx@Bq?7G&iTHq^Q7` zT-G8l@&3N+;kuZaz3+Ri-Pc~T zX3j*l{C{zcjrkaZx2^vVjg!&onX3QomM!(2jay)Qg<=`^#S?EasTUr70P9IZ}t22x4sL~|2$G8F`6Fg zH>g(G&_C56zfu}GR4bZnwf)DM+UXy*zFgv;*2UFuS;>E@LH(%KH0Hs7tVsWOYxuBS z1nb;-z59>V@vk1+$xlcpmieb`Yw!L{x5wad1^C75_(?g#Cl8%8asuK-);YXv{XY&i z$`tx{fvL&X8aMA6Lq+VBbGcAg$6r*HgdBJda=6{EzD) zYV@xOI}e{SV*D_xY4ktTV{OU)4>e4-PW@vQJPGBO$=2F7|FjxL$7Jj8|40eXUtU|j zIXt}We^RR=3*wD`tV~ZGwOq^M*}*@XI$BMUYEAo3^~sE$Y@Pp4^<1R?2ekhOZFLQ$ zJP&Dv#~%8D57kM;uP5%FOjhvA;?GK69<1{0ZXi^+iysC$p}4&`*(I9cS03+mk(~H@ zV`K#og0pH_#S-BTc^dvBG~eb35i?fY_C_r09fhm%?E{>$X_K%Sf)oFu1>E9CU>PC0G)Oiqvd zA*aVu@S;InrERU{^msoxZJ#EmCzi|U$!&6a>J2$Py`d}%JhM|y&weJS=PtT1n*4K)8zEZYB|07yqsS9L{0~O zmDB5`@!mpQr8nxy>CMh^dTXql4lczhR4GVL$vK`rl5>duz&RL#b)#V8D{+iVZT3Pc z)TB1AScOk5n&MQV#1M?_ZcMV0TeG0Y`Kwe9kn9YLO84)CSwz$V{eW~CVuEvlwt$?l z2C@`pD7+nfE0MMUB~n1bsstpEoizGKTqJe>7ax-k;Anr1aj)Eb9psb8jmK=Pl06oW z8zUp|YfOq{eTT9lZ;irKk9^RStWcySo)9HQLU^Q^9(ni&{E*Iy9KC|9c@#N!9Zq&+ z-p6?G7>KMHj8rJ{SzV+OBab|QQ+i}Fryy~RIS^@gDIQ8vsI91>iCVP9r^kW z1_M@d(`qQT%7l$vo!>#B$U5ZMk&SP2b%tZ_3`NS;CRAt9e6G$@HBlrB4n#45Dy!dP z!CywB-I3;_;C(#$L(fNxitNJ69=M*$>bM zG&o>c<<6mas#3`=|9k;iRjS!F(X+R3_d8Vn=S<70Qr&)OB3a+#4H;ym5c8{4v8e-u z6Eg8$1S|rb<;nD(KLzMHs=U`lmw9MKTGE%SgqNk#w4H&&UzvKMy-OK>mfI`&nB_h2j!_`7 z_h;ZnP7mh+&*{O{2!73TEO;Of$E2$>Q1ztKyaJ4NBU9^+~~7uj0ntHx1XzknJ_D9aM`6 z`e%)63uOt9a`k+T8*DOF;~oHRRdpLTX9PEHmf^sl<)W)#&_s_}Fu|K(6e-vmtCy1U zd-IXsYM|hP1a9L#Ogpq4HxKBIF?@ZX4qxwj8rLNnU4dh(5NvJlc3715m8Fi4Rt-&? z+Y=X^o>a-SO;}`hXO#-2o#wIZqEd-vh-K|=R1!^)$3RQ5DO6m%# zlv_cS@+#O3dJ+<^hepfmC`pIokjou)M*}YVI2e>v69$Wt&gS#+B)Wx?w!epCiEYPm zdFYn{{qY1u z!nXjls?)?y5buL-M@bkjwX@3h%2f1h6n3RV530-{4*{}zO-I%QYT{yMG?oc`B?l{ma64`}2_!`wMgE!N%KRc!IR!U7DllpHl2dT zA;>I458|$(>@`#uiG)?$7pncWX#)UaL86WZ)U~LiI(T~gC6?;ngdJ?7p!uqE5ZDfW zExHcdQmLwrO-osPPtkrxGp8^k)sdReMHpzsi|=E25Khd=;It$LxjdZGBs#vz~5y4D|+L{?h+u~;Q> zl}@t{99QWAyTEak{$>w2u4K(~75P-_Pn?n(uqT|h@HG#>-7vI2V+1{>0@Lmn9J`YxpSz^;DigWWjU@#SECok0BkG3<$<_*HzO z;75YRJ$S*gG6QjVpN;P@UxeIcFp?IfcWpFN&OP^{z)}z4z#EFyXrAQevl%P(sL8!q za{Ku`j4N$+H7uP$Q##au^1F9SPiZ%*{|-fteR~Yz|c3DJruiVEvp}rX>Z_$ zx0W?asYqLh_2i~tqG9V44X#kyR$nU7Y8uM=X$I5`B9?73u`@cQcCV+QvRN&RaG-Xd z)wphc$1|2yyDw9k56Hn~e`Z)|2hka|d-J&RHpv@7?E%*Tu`>cz3!bw4zhwjmhx_hx z(Cus#S9{b*D;`G`RM!+C zXV5SEp{_txcrMfU03{1>iYiUleS=Q^P-)t3G|82}SXP}uRk#<=sLFEOqEHuC{SAfv zsX&fq2neCs@1TUrsuCRDP<0jMZr9Ct3!*ovuH(>$8XXt?30rjSh$FLvBO+nGQvH`f zKk}H2R@%ofDDy~0my>90d8zsV9-VEf2o9ta(;u4hZ7iDN89>KPVw88n^ix>G6Q z7>rj}myrlBuFi0!h{H3Ap~VNDhxoHfoP#!nz}v<_@)+ErPN1xLxG(a3)qrn64G zvPv8_^ExWbjYcm!pFna0mqHv+^LooAH2fASc1u@tsI91m47%Yl5YDNxbD1HNL9V1@ z^<>}?$7JY_;{KBU=TMzj94dPiI-~Z>v;g^XP~c)DvCRe22J*;oJu+w@Ghd}`%;bZg z83?@hH*?BhldO&VY6uVq0DTn~l^Jv!Yk8NrPl;oLo)*`JR(%6HKBO+p;ILs)Ms@1A z6^z}|9u6q_3X%TJpqF-mut=>hjx~xsK=ra3g}|XqMUag~SMF!FM?F*}ILaxN;O*fJHbC>#!socB z25L}e-ey1Rgd~4A*)U3^*mXCsUfDQqagJP(;lo+Ulxs*X|nRATR z^4w=P)#JG1|0NT(U8l;!DyW70F@|I_YB4VX7K2+6u!JpFm?V;dv2LB3DtC zv%j3(OTbE|P4LBpm32{;^hS9am`jRvjbU-+!n`-2Uaw7nu1eIp4~e@*)0y=v4!~9+ zh!vksdoW3*)hig2{*2M=%D^t6a*&fQd)k##!fk2z_-n2BT6Ap<-DT})@rNj?9=(S< zeo?2GR!)ekk|R!_L-rYrbx!D0WWmeDZBBM5t`hz{UvBp@=#P?3qN#lU*JlvIB5kP# zkOa=*u#4p7P-~MHZUY2BK9f6AUjyj-!5S3*ERar5qAAjkGnvte)ydSsVi7{u(XeMS zX!m#o>4qBQpoEgWo?4+tVz((Hj3Knbe{)CHq=Toy8u0#W(EOFhka1-i3Tl9xm6Age zN|Bm5{MkfR6G#uZAJ~WvZ$Y{mDyJH(W`)$^3MzR7jLDt*W8(WzHrGKY$_ZTou_#}{ ze&e#y6})OHU$zz3r8pb=DV3pnM`BS9r&-8NV2C?a@(O5$$y3pebXtifWsD_7bZ_&s zL;Tz%C-f|iQNC<)6^z=Tdd>J@OWGE!zIrXW)hI75cQi&gs#2k}m+Js)qf&`!U&0fu zcZEt-NK3@xtJguL($hAwmX0b_E3GYS$y2F@X)myrD^;p_+9POXy-q3>OY4lA*m|8+ zszX{!+}_md!V}NV=$6)sQ(aZ6d)kEwNOf1K9%*H{Eg`-623QK_ra5?SXkmFk<;nsr{QQdg(F#X3i*RKGO# zlL;TFkelJYcWwm+f z*+V*8R{cBpQf}17fh9L;X;urqp}gKrJC?mK3%Bj{dm_hP(Hn91be4+pn$Hf6K@T?? zfob~*WlKGQt1>nZzqw)WvT_} z(C;WFA(tibfI`r+bZMT8R;mh=<9_O)8z{RMK|uvdhfl|GLx-9(#Z_?pdSq3l_o1y1 ztcOGSezY&#LZ>=Cj~S%UDIQvtX6FN~L2`;7~+X$tQ$td`FSOBLzU5R1j z?suq;$J1rLxCHrKD5DkEx-($k<{?_D68{{@=|df^V9JDxQU+ijbp}x?98ZUq8;aDK zCm$MjPZLlk(^FE=Gls$)8RmmanMTWD^&I-xQ2H~44=!bvSZ0U*G!&lDQgN3um-tDc zLuu)SS|p85r3;OK-9+)2Q#>~vYQr?Ct#0#;*o1;FQV!;sL!*G|S!6iEMrr-gE5XO< zCRD(o`G#m+Nl#Bg)=Db7*0TD`OiQ7o@VK0zA$r8)m66Qg6SUvtDTAqjEp*faIJ5~9 z%W8tp5mhtQl9;Edn@ib4wf`NZP#FiQlgHyOQe7cWsC8+FX;cx4AN`b;c&Jo^2VIqs zLZ5M~e=?E~k-X89j8QCxmUXhPYK8Aq+EBaBlhj~uyWn#E9uvS9{F0R~Lv07xyP{h1W51+; z1@=btf=Hh6OV+^yLub6bp`-RDBN?VC%GGqPv$uz|!_d$VvNPe#v?r|6lAS%U6P-oB z1xMNy`oRKEU_cpEGtQQxICt51b^>K-VG6o<0V?U-XYb9@MQ`m7eaU{IzIMR>_H@Q*VFIKM+FkH;gZ&+S*h6P15#Hjfh)S|re z@IgIwH+c+M$eNMn)Ou7i4tNYbxkX1U=ap;qZZAaJgzYen&u32M%=Fpy|FOORaB9ZAJL4>9)pWg zHxr%co&xmI66bepX!NQ_k+#*4+q2-W7hsE};wLE3!M5`ml~*Pnrdi;hLQz>Bj~8x-iAd4{EZgnBLjh)bQ=Yr`2=_wZ zcRW&&y3PJ~+(P}%Qo)5ZuaA~`^kP!}&X;0p$350mPk@jAod8-X+*n*2#0I2FC2N~j zdexUJ-M=ExBW_&_Es*62m~JW5-eGZDFk?k|!Ns`6YCZ#>Zq~|||2qM<=1b$QYpJ>W zF2*fZ^C#kZ57xCgeK7&g@zZ_tLR{^hTA)T9(>GpIrTTnutMqEz;tg7$&&33cs4H+N z?j$xc>7Ydy6JTFJxvQxZ!!!#nut%Xh7I0{XCvmayN~KC8;ZH8J9~kFKe19HSRl(9{OI`P^^7{fW|X zPe#`;Pi>6c0(8Q%1T>^;a0GT{t_IC8ngIU16=2`sdKfbSSNg#x_||Apa3iY1xBB#? zALMXX@O69L^SXkc8&HMKyb7w&m@_*Vs;s%edZsbP?4vTQ(z!Kw^Oc%*nMd|3^LS}%_#J;)_PTa>ju92_@W(`I=zf1ykZ{%Y5|L_0g1Jeny~hR0R8FPPp~t2}rS zuBHV;&Nf7AWbE+GU3cvK6&%q5eg9=}c1UYuUr`USzk*B)R&;K9NYgrav|<$$l^25Z zU(ww07vZ9ULQ9H2y-CwndNh9pC*eNSNsFKJx~A>&X#NT^Em+Ihv0T%>^Jv8?C@Q1z zQ`&28VtvzQ!$k#!)+L_*&Vlq`Gmqx4;8ytD&NcCKU)8h$9?f4trUfr|Qs9({wp%@# zDbyWeQ8^=i@er+Y`$f2@ps4KVjQ>#6KJsY(3NFBcb5_NVLx4j{=0A#aks)SUu$L3S zMk2Jj4GgVV1x4jk@&C%vDtlaniwcU$k{;tzWqKOM7mw z6y{3t{yGHLIuHJ(>yYb7aVNQTc+?3Zs4aRYc??glpS#QH0jnt74gZd-ich8QVd$M; za6@@FR`oU{RPaR%vb-pkS_TzKrGq!1yHbKf5fWm|p)O}5z{ z)i%&YGzDj6baNFIE$~tFHG*|K#Mz-vP!#32j26H68(Obx_;4ImQ zoU|Lpp?*tQo4 zlKzkyp3vIO33Y!4Qz7%(uhzPH61xv84^BZR+z%=}={@jS3oCQv8H}mQX&r2EBWjWN zI4o6WdEy#!n7RB-FzT5V>9bGq*8q`6_?f_t5y+}cSB~_uzDz`k)#<`+{LLlJ`lKsZ znN$*Q267Y}f+c2RU}-HjoAQS`gWr$JhGS zo_BG8F7w49ad>jebsS|Fs%AClk$ez7SaaU8-oud7%}iJ$&8b0k8Ugzv?XX^kn+)a( zmj#sh-Ac>>S&Od~A;f4Gk3ebafk(?XVs6pbU?|~UbTbcFGQMe!=h9qYE!BNZ(Z@+h zt4=0KvC$xey_%d5A^Lb{3GPhDzGt0_r z1+Ol1Cuxi6$j?fv?Z`8g|l(A`Vb~m=3X>Agrpz2 zN{|CYl?{M}eHCKbnQu}f%xW%_60TrfV&tJYC)5_n=sH|x%Vj>dtXAf`^cDQZJT~E( z-;lE5mXkLbZ{B5oD;QoDbn=o@kv^_llj!7ay9@ji8n58wogaeqck~-{*%|3h`7>+@ zPEsNk`ya?dBg#L`rr=-n*Cfki*=!5Gr_HOptc7e0exTa0A+F%#Yzyz>poU#W8s9^#Hz3<+Wa5Z=FR43OU`gwAqksE5=d zwj!Cf?a)moH=GKE>U9QL8#`45SyNRvQ9#+F(*F z>MCoslpTSzLuJvMsuc=OrL{1nnF;o3#AwySphkuQ;q)I+W<@(6-HNAP1_{^TCW$4f zO2{mfZggu^opoQ_X{Q{8Smf~WHykHc{IJEZaJ znbRe}sbdepJjAM#;Sfl5ALb_WvO_=O7@db1njPX@ss*dyVeMk8;ND(@2V@4pnrKNbU4hp{7^ApTL9dhS}C&a=8lSYF=ZR@pfr z{()HZ4%qN$HrMDd?ur`k=R)l+0h$;3?hv-PaXwf~SnMTft~X`h#gjdZULavV9{IMxKS`b0Py^862zr<=7chMjQY$ zDS0gRtfZk>GL+OF8I;u@*C|&A>SC&9ZO0RVlzwuZbT1|aCG~xRj}r=5>Mx8kB~`t^ z$H!vGx#s78L3X-q!|5xkTGxCx3+Z_#-8EQ;tfp6HqNiJ;>Tnc7DPsbyaT!V(E2V@| z#s&JJ8ljZ&fdV;C2)vG(^iO#v(3=}Rcpj?N{1iH@Y^jDQ@;O{J8HLQmth3Eu9Fq; ztAf6dLEC%Ko=$w(tTlf6gQ~(f2b)}qbFkZT9Ix*1B_>a~q!r@?Dp8RK34i9xO3H+t zq~P+qIX~E7JxlEEf@9fIgk4+isUBn#QEb>o;Y7u1RR<9KGt4j>?o8Si4MTa zK9OM)QCMUvA|fRs4WY7RBoj9-r6T;^UFpcRn9*e-A5F$D{~|kvk`<0DMoSVSQS2c} zk-gZllOz3?qM9flLlj8vNYzl8$TXBgk>63W9U00Yg~%}}|19bi7iouj1tWt|a(v`4 zbcZ4jOZoLta>+OKbrKy3GEsk^@A^*Mpd3k z`tDZ^p7+3Z^fH5clg?qHi(0MHDp87?(ilanrmS!>&_{fWAx$|t85bp%VuDg1!?6Q7 zXhr)Kn$u|}a}qIgXqMrO4a~I{9S=-jSO#TsNVB~nK zS!Ved2JzYf0Ft)DZ^C4Hr~rdrzQyeTA`NgyO_4R2Np_^)WjyYE?f@G3t18doo-&84 z$sFDmlgXi3Vxz090Dc=b6@_P;HOp*!JLl<#tc z6Ew8-KqR_KB6;ZNxbG|9P0V{_C@ig2e#mJ>d;TsYhDyR2ItNjU^23A{7&;V@iSkp! z9Yx!7N068%31{fLzaybGkHFCN+mX1nHq)%38JK(JZK{9@7O47(g7)x0;U z9cI`q*aMqC@1}aeTWr2VrC@t=LcHfh*>LA~l&vKzP!?NDa4Fn>%3FeCN}lBK-C_#y z&Y037K+_*PN)Xx zQNGOYDsAl+cnUeg$6hzkO6e`vs+GL+r}PNW5TFUq<3M3nil)Aboj#>!faVy)xTqqO zkNT}PSokHD()G&^e8lepkya>>6=l8IA@(cqdMA!izRd3})f*7#nd4S(n6G;5lB5g@ z5CKhKim6@>BSQjI*&wERA~YP;Yi6);UtGG?8yFJ4AC1HO~8;ix4cn$xAp1q2)7m(`D0RMjK)8R-BP^rYUlQ3V2168U5?vUa7B@P*n z7Zf>*_CkA@uMi>L(4#O$tL}CIZn`L5Vpp))B&7?naJUQgyiMWV3QY~2LwPqlRMHZ1L*E` z-;izjAiOeGaxXJ(=)=rYF9*BYT>>i`@oA}_;hnGeig^Zkr0dW zWsYRzNJe(37Alkzx|u<~%$CdC@4%ysJ|~e~inB3Iyw_)Ua0M9R9@nqWzGw2nKjG5y zUY`}B?ro^Q6KGE8431I0yzDfW)M8?z^K$+wid&9S=K*ku*HW49agX#(k4s(OfMJp_ zx{9SkVH;#c`LhVQBh~Df)xkGAt_6^=8ack%G1ugU*8=fo#~K3^nH~R1v@BLjJD9PV zufmI2)SVr>-?gk8IQxi4Sf&VSc5IwZN&_KRRp=tKqXTwu%J3LmX5rb9@UV`8v}Tsn z#LSLQ*PsG}i%3f?+}ZI(9Q5nbSvQY21^KuTsVHCONJfriWQTImoSe{u4Dw~RT;~4B zW0lb-1n;60XBV0sA8`d3^39H)O`iJLgf}~c=*j&>t!2Y!98su@!W;0k)gZz{? zaWFmC%d&Vz(i#s;#hnnqYw1;(NbWG3p7r!rrK{O@8bu?-EiGhv&vxK)}xh5f__7>V`@#=RF_e=&iQbd z62GVT(r%}A^veqR6Is|TxPNRa@XPl35VF5f@)678{3$!`UnWZYljfFlYy2XEvh}5sfR=p&eutt8J;I=DeyPNtF-i>B&Hr#E&-x?<4B3M- z-0GHtZ|zD-ZA;rLP-#`$Mm|t#n`ob!yvDNRhKx*nTAjO@F#2>`U#*KQ)!So$h1$T zw-Lxroa5{q?~KfMMIZ4obyEC|fOOAPDP2sn~6W2Q}*Q!o-XoN@MAyMn8 zDt&w!ynW6dOb>?^dK|rA58!4w@vu|!5dZN|raV=cB5KsmlS)GV#+hEnvK|ofF(%72 zl_{kT@_0CvDx;-|ryYBet2v>IX)qUFNVAaR0-xe0Q)!Me`J$Rr=!O<(QdgV08HMn6 zC9}It<4vae8jkGE8t!e=EgqZ-+X2COtZleW4;n-p=a~5FiM^aRdXZHPWO~I=!Xg|a zSWzo+to<3D&+&##Uok_i+nBt!oH)@wQCIZY2CmEBMniFreZ$Sq?%#u?)NewQw|2U7R0)uz@CHY;H z#AWs+$F<~Ren|mW+AC0|NWS5hC;TA4@tnBU-u0y3#p7`MXnKfW zYEFE>u86xtIP4Zx_dxZIQ(}+6H+uoZ7?8a!%p-yR+fy2%w*=N8TJ#jRWr)X+6%wO7 z-l`r7OdYB_aegtz->*Q&Gl4hiYsOZO!Lv}U#u$A)9JHSUx4fZg?_P}7NnU_VygY8( z52(#g9)$-GHm;_}v`0#iMTG)2nMTIR+zYz8fBJPN-|ALaup%I|Y0zHg^4fR-l=1$E?iwGwZQ zyWwWt4euM!eak}_tKynAQmdHGFheb3X+@0Q*$w3z;)3W58Sn}{iZb5h`EtUZlB7%@ zwPc1Gd96bj-`n%Q(ewYBVmi{;^!#LBsHJOqeK8%v_|1NKqt>y$n2rVosA)=|4W2IT zKp)edVmgG875HKpzTL-+uZ!qtN6S;8Q|lZ4o^tgrg%6Y+;%HrzFLOe? z5#&flPKa}IUxDI=Nqt^M=%HW;c9*1ioDKiaN!pF|N+XE>KuFR`x&}%Tm`0Y)TSqfZ zp3f9&bPFx_&{rS_$DTtIN$0H`vJSDLr-~3_#C~H^Et-YkmH3T^nDL<$stj6EBkGl= zJN=Xq*VZm6O7-De@=T;sa6Pr8GH6LTw56Vwti_;eiv~N>Y)mDQZ0|`bgO-#}rEk_Y zYltVQ!GSayvp{UtT)!k6w4@RAGFl{d@?O8BfD>uMa8i=b`z6`hC9R`%_vt&d5Bwlo zyQBx{{Wtae{?!k%wM*JegU@O(vA5|2^>c@$9W<~mS^NelHDXXYL9H(NHA50U?YGcU zgq{~Ad`w5svaeXf6rsh55KO{ivizGN zja1S^`?qmG`xq2u^M;%>(|+X|y&+Fw(4C@j`=RqjyVcY9!lK9hP1#fg^gFzVf)#1UDN)>bO_^fd*NkT$J}B%*mx!VVlNw{&D;G&bhIO3#5v!e z(&o)y2Ux9|=)j!Nn-GhtOFrV`G|0#aCBWOv34O;PU*?W4gWfLLB%`k{PLXgG+7&~N zFHTX@eQSmz;}%4(?#GcM<=a5{^+V;#Ulp>mu(-Xqjd1U1%&Ct%c= zaF;3LB4a%hYUo*y!4ieX`c>>>GS=^zg3MUg3_<#I5oxJ~JJz3tQ3KT-Vb;x~cT~nY z6{#p+=14|Ph%>T7pGX%sXOJ(mLwuS0ks9lJab1eD3yt*{7<=Q41<-}PQ6X*vnY#Cp{D(h&}c`PEH zHdOK&fU7mAqfr~?;YBGlgKB!9iAHVzO%0q)?HN^iO*ASOE6%2222s6gqEV^UUEzfu zr6r2Oi!M4ERS`i2n>Ko|j7uu%XwnJYy+& z0JP|i)X}JGzqfQWs(}yG(WvtYZmFFZ)bSl1je3Ryf>Pm;3>J2mG`JC+1)3pqfz5#k;UH}cIbM5YA*SrQ8MjKG-?WbeMR2tk-0Dx zjnZTtjaq>UEAl~)tSLGg_5Kcsq95`4yGP-URV&g&qaMS=bEw=PQ$fAlbTld+53E&5 zZ3|OGjdFubG-^q*Wv!M5k7u%26`4}%ARecQMwLKdT4}!b|3$NoMs3Es&Pwxvf2-Mx zMjbT@ebK1DOs2X8lRegpMx_ikJ+J}R&=-wrWDsqZO*HDNC6=|BO=mAd35&3aMlDE0 z?_L4ML}s{VRsv2F?cLa(xCdyd5!d%;h(>L%r23M!dXgp@)qRv2e|pW6G|{NlAuaih zC#eHYx7t79Ev2xd#WGQ(Wvwh+E-id2X!>+p&A-|+yhNCsvhn`=^z7QrNcZDXp4?Uy@cTZ z7H-Q=9z#}$iAH@=MR#KIP@_XLbTsOxUo@kI$KY8Q)-)ZBdbFvg4Z0XjM|v)g`)B~X zk?TDQ54{(SDmZ|;-s_=U4qBt5Q3b7ZN4)4Ud^d23!{big3;AOn%G$&JA|}PX5kUn4 z@QrncNmHa86OCHj8Cq(3l#4{8D&n?|Vupe`>S$DAGu;hC4Cvk_>1b3r3@4XI^O>Q{ zgN`KWXjIc4+MC;0jG?1ZYvI$%qIs=YDLNXJh+8cwxi3H^;!uNO0(2aTv*Gy_jYIM5OkkQX4rO2K=J|}Ei9@A&XaVF* z9BLBkIf)fz7a_#lI8@vq?J@Rc#&jt(CV_Rtp#~k*-96QaW7e<{L>%h%sP5_Io}`IG zRhg_Ua1Ni9@|y0oGw?VTv|mh(l%N>E*q^WBAM%;!vfRVwyedp;81NU@3JR zs(njPUhybAGrc%eZG7Z{J~t@J)^Vt3XXrT8pA5QF)Qv+m#9wQ{dZCIVeV~p*wfsmo zJ<6bO0F>!Vy5Ih0nl?H8jkw#vY}gQox&&@kJJgfr7Gvl*RHco&l>3X7qT^6kV>QTx z-&;(Fjzd+$eS!?qH^p@5IMlO?^`ePKuc=;eYpUZ=<6$qvu+?Tpq1L)_sLtB3U0Fm& zB7GA=6G=&VH?iB$vpJ!$U`N#@AG0MRcNSI@;!*sUC(K(_Ygz9*$nnJ}o;7*l4}gH2 zKSVnqLf(cTg zi^M3p;f9#{c?>SIaExLTCbbOyG-gRnOpM}3_F~o)k(OGxF^UdNz|f_$Ztl80SP|Kw zmyn9`WsYRzNJe((dbAgxcw~?-v*j}PHSiFRiXrk{in9yFC=!vIz>qISQQPFHKlb6p zD1_(@FaLoN#J@m~@@01DBNWx>APyDm+&jnOl|TOZpuLE*QECmmsDO+9^De_XFFD}KFpd(T zR~4*=RsN<)8S2KWZlXE{H4}?F-@dI>x}FwS8ipG0n)JqL5N^+fsiCnR=*@^Ydn>EO ziDhvbin`&%U4Rp}7G0@&u@4g2p$*_g`7)RPs7nQVYuCvbK+Zr{+GS`)3tYWThqyF` zcmO5uLpo{l+;$7_6_pw1l2yBTx)q}QOf@`8Z)nBs(7HA#s5wy^gP3mNr&TTQ{RTJ6 zgSZAm3?nSEo#Z1x_Ebt|bb*Ik=}?JL+%(8-BpEoAT| z2CtRYDtEx%NlUBaH5LXx^&~a8kA7WhDamu5q;d!Bw`gitvhvt)l^^f+3(AbeFxft! zgAehD0Bp>lDl;bTfc-huL4`!Jn_rTB1^Wd3G+#@O^-HolV3)P=D@0`yZuNug4%ij# zwRrDY?8PPzRG$sAYuUZvFwyI#JT-!B1W;%Gc9`ANer1zZe%zB+9|5yl*;~Wf=?qLT z4XR1}VX>C6R<)qJ8t2PYQnOk;5VMEae8Mw{{GzrD$B|E5;)l~I9?5pbJ* z6Y`{f)N08 z?}{_a?%~`D(?I8nP`a2kS3_PE&v(O#?lFjGlB|*Rd3jity{}79 z`NfM-s#1WvWC}GI&1#N&9O)3RwU~jGL99uEq39ech05tk?)6+MJ^T#7ae;2F)dI4q zG4o{At9l*7>cPA3VZ4)X&kpp!R)oL8rWT94H$Oa<*L^<-M%5)Bvn3;U2}TLt&izw- z-p*n!f^&S{&O;_Iya|Zs?Yv|FV}0Wh+AP_r_8s_mKqi!Y!Hg$ZU0A+BR}II z0s+$m@x9%zEU$y56Ad+)AQe(=F7yt02W~+}kHHdZjl1uVS3IDt&u~+a@pe{S3F(DJ zq@@p z^%uiDhen8=L&JZmEGJY2(ow$54h=$4jq-7TLo)jAL+Uy-ElXigT6v&1=x|zCElw_3?SPO~l z&=l~Ze3{FC9S#mnI{b!GoKeW3d4Nk}$mh`PG$G&YQ|$Qp;H`(B{=9%>55mc#K4I5f>Zwyfp6W+oe&3qC>D z=UCPn2Jc|7nY7k8G}q!umq)`b!aNUN{eJQ237ZK@C4mEQ%kn;OKOMaJk*NM($5cShbALmgVR0GI5Z#sjhfzL z%2PInKcwS1G)sTe^3Qql#-VACmwqLRcGv@5ho%pn8_+L>bwe#jR^ZUY<4Hf;NGdzS zZLOO3nlaH{{--5Rz$l9uGC+!99GZ1`P({6qz^+46`HYU;Of6D^>(HENq6=76M1yf? z=B(B#o-!)X0`1Ve8mGk%8F7Hxp&1_0lBfKV0={I|Jf|f~VN~_hQ(vTmL$ml}y%p4A z(47X_p(zbtQ#O+Jo}_VTro#QAp+-u@7K}sF3!XO3HmGrEoLvHD!c^nX%)zgSrMRS7Zu3-eoT&p%aA?wdEvW&cn-}S1~ArFIW!MeM$nm+Y-h%Lz6#&OqOL&n$8@ttOPk#(DIfi7NVZbJy`V5fG<=Sd=ewBqK*MvO|}nwmG4D805=rxy=2U?RiF@ zzmZ*vvkQ4UZ*v70@_9QaOrH7^q@K4UM9o?KanV zJDlzFb}|t2WRyBVG9jO@jJH$!1a^O9(+I|{(U|gf4s5{R!{n;Y_b}t_toC#nZ)dy7 zQw=fR&f6X!%R>Irs_}NdGpLzZm=*AL`Xa<2)1oBmr7Et*+x2#qY)0+sd7w8V;L)&J zoLCm8>MF%ufE2eDU8#DpJQCTVA>c*%GPeNT2X7}~0S1sW3VAzsaA^$ryq(P^&uzE% zcHZ;=X*W-|LX@BB8;?>JT7BM*HP0={bc^zK1~tP-a}BB)Mp$Hxx3m3upgA6D3dfeC zy`6#`mh}*ugu#a9f=|#6+p@MYcs+xca#@z~b~fIxCGYVhjkoj7KvI&=d6LH4*}KiM zCZluduqSD}otF?57|Y-6WIYB|ZDXXpoqCJ3 zN$BVYwYPH#?r7QA(zPCFyqz1ccIg&Vo-#;m1kg`9d{Zl+m2dRqjkoi}%Q}3s*8^Q| zhaZH|7ln00t@d`>eQQ~4K*`1(vudrH_r}}FzZQS>of(%fLz=7@#@h*&#Kfg`MPS$4 zIf-BAO9{h@l;CvaytfUwYM{Mq~2v3GpMG4@pj_cptHIgsjwJ+M}^J(XA@;-5vY{#@mU)18axc+w=?byop@I+xhu!=IEusGk`620ZeC3 zs1jNqRhN9smWs|_Q&4$3l7H32-jA<$ zI(cm$LK0sqvN;`d@|M1cbR6+>Fgv4zlNZH(S5^Y?SC{OJ=}z8zrGb}|Z!6guvz@$M ztS*H(lH_E}BPWmlmSI)}Vo%J;SdENsb&ye=xUx>h>EX+Pj8CnPxx>FzQW9bQ)K-{3)g)JNrCx=atUHohLEYNIH2h_`9@mYt zvR0KX(4Upv=Mne|Okw_tAXIe2yLMUk-wyfbCCR_z9iF~f;llH|Kb6{-#T>)diF!|Zz2M!PyoY{4 zI$q;fIeFu-UhKgQ07T}##E0OvXYtn7L zM!bC)l&*XnK~G-BbeSJ(gZu2{HB+(i_vZq;7)*Wlu?9^*QOWn+lB)^hixE0t!%kjz zTUAZC!z0Mzu0f};r6xaE2KS{>#P(u@Uzb3`)@$F^8s05N*of^TdHaAZx~ESW0vb+m z(vqKAj((Hg3@>&Y?lz!SKM7Gu80PRmc3GC%t(=BTR zch6XZx!Pak*|oQ8S4~*z5w!L_@Wzr~?R6hqbJnn}7~!SC(C}W5A-ZvI7y^pFtpM1E zG3+hZv+(x@bBlkS=h-Jup>e$4s0?~i&0UvJXCw$mm%=_s<7yiMw10nHE?fW^tPlL)gak;= zq#xlpaOcY_07f#zi(ny*gVpbj@+cAd4LJG-s9i)`hvC<^3|{63+uslH78?GVW%2hF zDbEj%V^ez@mDSrX75Kpw*(h@{-EfVbd-MHZ>U98@(55xIo%j2}p**dY(tDR`@I^oP z7Vg`VSJIlVHF(4i-h&&iKP zpU+?;KgiE;k~h$sm_4^M*wqj2{~O>&dIU3B{($uuKez^?n!K52_99FE4)!g6@W60@ zkI;3MbW=9^!6$KZn!KGFVseXN*y{(=lL0%MXTXpv=9L zw^`f6N~oZj31ZD&p*N~(Yt_sT%GUEforR@;82Qx81KUyKhoJTg+6gNqh9=C@jHml# zu%dUP(^~M{T7;B*5I)&z!M@-@ z!$Dcf`*A<{wBjLLYQKI| zgSYuXaS>|SGqA{HML+BZ#Yd=XH^XR%ld#_p&Yp@H(7?W;r{0ym^n+J_h#EGsPr_=- z+zBjqE2J!UjGn=&Om1qQyizl2cnmS!G5QsEImylK$ZpN(;4!$WXqn8jZ2R$UdMXV! z41h9Q+S+%+ZETH>q8mN1lk!yB+tIRcRn{9I%-<4)sJJQ}?3b}3*{7vlhJo8~0lU~^ zU>h7dW)NwYyCLw`S(At0GuXc~&W<2&2$DMjxydL-<%aog$K4P{*azUYVnYxC1z`d= z0VT>`M$Hbf0f)6m20kc_oSYDw_`I$wi#It}i7uX;dU8#&d!Nzs=MApCj4HZH=FepN>Ff3UIpGIoyO?69e4@cP#2k#I zOv_pJL+iBK>V8nRi|g&Oa3^FMxAucFvJ33nyWnG^Xfa*mfqG;Y**6%wK?Y zNA@O1@PW7?KDWCk>zjdCf|oKJj6J!Kpt7iU60)FO>Q`iOH?;c z$?NSSLs_X3P!NVN0hB0z&lbNL$7Ob?zg+WPozI`JZJ4~tuDjYD)3=L^={w$-iorSL z85}V%?~1I9X^ksT>-Y4S!{D^Qdrryk+gZ@fH$-}jx7Y)c^^72DaL${A=X9DlYRDy6OezvL;1_U?mT(b zt}NIw()3wlNr5ql0388g{SCCxVF}qglok*9_X-p!SWC;%I_D!M__Nj;UJoycp z5@dkfNp#ZAL!N9=NpQRjD3j=Wdo#j2GTQb1;DhX;|7fQ?flh!lUFipB9|rh~J^nAf z1&r{6_wtSOZ}y>QG`PSI%Je&LcdL(Y@S_RzfCuW?al!uiAb^(*5aw?_yR(Cw+H%w$te5KyfwWJUPX)5&EW#J?ElWyn@Ua#N7o$mE8HBsyb16pdxPU04l2n6 zxcMB?6C559u_E`@MtY*?61QbjIdtzNjn{JW>U9A=*->#3#7!hFGDYKvn@C*bI!DDt zVoqL(55S+Q@eWSjual6T=I{c*AFdREoatJ%i`{!m;B)M zzXPo6bl#=6wNL%vSUC5|^_@)%w8^_*K-V@^><;lp&O2#ZJoR2*t;9QS>g06LuJh#v zbj2kY(88I0i59=wFwiLRpR=747+KjjXB*HJ&*AOAwe!v~ExyJuATCR-tuqQvuq?Hm z26V;cZavresD~E+$S@!-x9c69-@ECX=|2qUip!$w<^-^nY{oEA%6-1J|H^B*rxSoL zDuIv|22^qD7)dOnw{tlHCeplq#TXLIxXRhwL_3XhiZNEg8YExstVWbd+Q=U>Qj@|h zMS=>~IO%RoV0STwL=^@)t6}Nn*7&Pp3<)a?aVBroj5xH`Uy3#{!=1bOpc^tgbQ>b(PW8U?}oA_h}s1d`Rv> zAG{v2Lu){c@+a=`(O14aEH;F5vqMKDdo-$&BN5#E$x;3z7td2G)FbaW;x{Sh<(hAX zQs@UP!<0QlXCa)B0}6$ih)3ezGx7>iWSxuX2N#`a0&ZFQEdw6Pxk{eTiRk3Ao4u@oc#fB)_2} zc(5S%j9U!o7F-rnGUZ$P7J(RHyjg^y-o;M&jy89Mzj=~T)#84r2@fOU9Vx$2-H@(Z zJhBx71125Ce`BY*$qf%?IsGN_IC}^l!^7Syl>%WnE@bnd>_+eA=<9q4MOB76az;Lf z+#4o8=qz~55d6PruP?dx=P>ZfsnY$dSfF-Un z!(4+f7Yn!o%e?GRV*~5?(Tf_eLEi7Iu1Crs$LOJ&ARln5U8W6f0Sk$-cGvObeUN$E z`K1i0+t*u)F~s70=#-wTEzZ_r42d0oN<={0J(ty9i|+4^)h@E=Av02t10tM7Gnfm?nc9en>G2 z9)pt9zYYnItJ)+lNsi*#q;q6S3{&rpe|f{ zx*BMhUoKO1??p9un&byIj>OBls0ekU+yThx7pR9f5NUx?20cdy0vHe&o(^Dx0aPh5 zDlr=^93Gg2Pi)D;-_H!+>`JB6r6E5#@GN{xW;k@B7-bvGM)H(ED^yBRN}*1LwcG;( zk$hd?QT$Fc^yAUZ@k1Oav*~3&_yM-O=qEo=OEldDk)t9QMk`A!0!qHu>$Q)bj)E?!%^0y}xMpVK!UFV~=U#4npF zP<334-oU(#4s!Y;vd>-=&F~6fb`{*sl;D1qDrfblzIiAlbV~iZFYM^zmgceApj$&BaD_wY2kFHHp4v|ID{lOvYn;4KpmKwe3Tyv+G@e&Q*E)HKNXT4z z*)Y&hS)mU)(601;=GVIfE=qK>v-c9{J#VCx-geY#7fOAM|L~&HtCtiOVk&AGU4>H`u5aEZzrnj(ST9?@8ngLh^dvh~zzqwy1vgT$QYicaiun zRb}VU2dGEFgD8N)FQ77E{tMf9E9r4Y+tW`5HE$)&>;pZW_!9|~jOnRm`HLs&{ji!O zjIK9vIKF|$kl+4kuzQUi5YI0Rin#kylj!J~3Ad0I{ySQ6f&8ZrLhqjcZ-GLhW9p(s z1M9)k&?iO|FFp;!xMmN%VJB4n;?M64gP&c%pDCd*I!^b1gd%H_fTPd<4X~aE>c(Gz zw?4ARUw9i}m%^Z0lQn4gtEkJA*@@ay8O5wEIFL13jo1wi&G$r~#--javTvvxFWZG0 zOhK$Dk14)`D3k4RkfVH=6XMJKK4oy{7rM{B=`q|>e4c{8J+{tPbIY<*XeOguZTf*r zV+!vTlKGfT@sGNh;adP<8S!0RXovj+e5@}p<>(S-tPru7+|`9%v}^;~@)-iv8(amZZJYa9ZAnZg%Xr2LGE7t2g7zgce2~y(s83x1!JZ#SjkrIE& zfUfw$1c-lP&xMJQdLLtk)I0o;YFTqw_0Um!*bR9N;1^iAf5%{K%JsS9aTuGb@YKsK;JGQrCJfExZdT?5#wINQbm0JT z*-FD;@Sl1s*O%;VXdH`^TJIX@N2wklYe548seu7tSVYSR>R|F*izC1&8tei52T5It zF*MTyrucwy#4qFM3US?Ci3#+G2h8#TlW4yOz*9C7Q|PD%bnyXG>30uU>r*wI644R5 z@Ed)=Oseex{2bq{)og0(0sIW#1+J%l9>7)_Z_M!aU+#vM@DO;6Xc`k%;y~85;wzWC z@!f@b*V6eI`^O*S8E`LXQNGN-6Wc7ucdEkUcH=v26?n+K_|8YHn<;7=z*2YPJHHyF zXng0ce9)7yru~8@zEk0QIBBe~J~Qg@6&9q9?;JoLSAwqeKoj425AQ|^IKl%>e5dhM z+BDv3K-svUTgP{vyHm$^9x1{w@txhbqU6^ZRV{9c%0XVociwni*X_7r_~Sb^$XYJS zawfjB?praxN~J&;hx^fcIr=`UA?Q(+p^lu9&p%9KD_r6!&kFNz$1pxVD?FJ?Ws2Vl zFEN?nFd#HRTj2uioAT4lEzGDSVyf?9h5vP2|2&cZuATw470yYwtV@~ywb9LLl@(rw zJ)#ZrDfpyY8`q3#D}2YbT0FxrAg--&>q{&p-rj(&xVFOChxKnR3z#AGc5SS-!sCC{ z1>EB4&~{o|;X~DQDO-!_&{lXxum6X(_kfS8==y-~>}D6-4BT4Q!7_Ma23bC}RKq=ggViyElpN z_kQ2+jk0&AFo z5t@1TXmjr5;MS94ajjz*pi2lao(nbS@fCcsv@Q0)h_}hjqh1U?Gjh4(gb4jwL@+`P z^Y*@oz4*&PR$oPUriYqy9|m9DiWMgp){r2Y3h&^~%N$eqq6p6xroGwVyRY??f!T)u ztZ~9jBoWPM=my_^u$qi*Hxq^=m68LK0ZpQ0Zzl9+LVJ3ZcrdPa;29XTYY-2TUDMwT zo@Qf~AlHu`g~r;swkp6KZE@GBJybW_1}0|O5cOe%#*fUJ=Vm7|SE-XxW>=Wh395WZ z!fU!%h{QyEhZ}md4HmS79yRH+hv-(-tn)133kx6t`>alTdi_`+SU&eze3FK2r*Ljdvsrkzxw2+h17*Nx}q~<9<5JpEkd})9OgX*(|QvCb~LPmeE zvD%HvjEnb*Fl}*mk7nx5H^o0P2*GM6tVPo4W&GnpweFxG++4T@$xRLv0h>fgJZ{Us zL}>p)b*NnZrk9XTR5$#9Z|mNy5@>+(4?bh~DgnA=OrjkJ)#Y<_{&VO;f>Rf!nC}=K zRnLClm}l92VAmmxyq~|9K^#|j0>vPN%iaRDE&(>_0I5Rn2!yZB0YQ9~+!@t~ubPvy zsIQKrstB#1y7;Qe^SDV^02Vd8C62uVE8yuj4wu>FCY)f|HN7nGT(ilGB$y!X+2o@L zF=04Z)bVCbpFZAkj-3tg8A7CUu@sIpm`&d9;F#4(!(A?>%qD;0WMdNH+Y{4N7@190 zfO!ujsv9Cq>ku-V#Q!42vmyxbr@(u@yG~2-)!}+DheU9B?#n_aS)$N_v2_)cTc2oBn6d!`zHj<-_V4(Z7OhE3`E&g zMIqwSqw!)GDckfOl-*i4lel+8xpajGccXlR&2Lpt{f1p6t?r4kqw1fhs$q?$nyO3B zCCpP%OjQ5#)aO5=miDUJ4P>~tqZqoNg=*+Aa@AFBY)>M7tiYa76E$3=rhZK9;ND0R zvQ6oUIH-Z@g8js95n)5_#~3MUs2Y$@oPH5b0$l?GyE`nVZdU=Iv>F#>(@jTUAAJ$* zBK6V;DqR?1gY#Y|$X%)C0-)78H)r0vD6?J-e1|yCxH;#LJ3g)oaAioV_adAG8V(T2 z>>TxO6Jq}w%Qjwcp6YiYs$HNaEFj@$Js+`yhpE`Mm&l3nGC%R`T#Hx~IQxoKBDBWt{@= z1;3u@A=4e>{o?d;kh5p5!4SGqY>=CLUbk2Do?)4CJE(h^#5ApN` zAb#Z`(k_?|l#0@nP*c;=#yf$nzS_t*Nwh{ZK99PYdagu0_lthc55PdpBCxK`r{G|9p8KJi@LiDvDC(w^r z?>G^sA)nJ3tNHV9q7AK_Ye(5+!UuH#4P8gEX(3SDSV}Lk(DUlOeqX3if6S?VWHvq#c8|7pI6nf*v0l6FGP&w;o)FG=l` zPzm+%>m(&1h9&jHPiPi?bZ3j91Q~s#bK%%-jC_KSI|$i>q>Z#lmNunFUFCd?eud+% zAVCF|&4S$QdQ^I)WpimKbPQJ4n=FwMFi*={P+9$(!8sJeaZ4KtjQ+y1DS?9PsNhJf zUG<-qLkV!U5Qo0TqtAa?tifg6B3n_xPL^#7hF%{5;#J_1_a0$4G$11A&uPh@k}$6+(C6`^zHVgv4? zRy^Y*2N-scVC`PDunD4jxB2>puC*GJITM$y-@(9pdUl*a>wQ)RB~-#e{5nZ= zGS9*4PNimVgrM>I8xlg|_{RxVuK~%%f5DDqq zrPX|jP9(E?MAHc8lZZ~1c0$b(0Z%4)4teSvCTI7d*l*I)=BTu^(T<*{=yC)~Oe9^> zsKh6Ykg8Li)8(|FN~k^>bSH^k#Kk`$`ofYf0MSe$XJisN>uQjn0GVw^2{XBM`Eonb zXk?Dl<;$H&A~;_iBaptzq~8L^2>e6QZXBj>A|H>C{XRq9MeX<#WUfad7JZ9K*TYKJ zO>8&pDPLqCi#2`}`bUgG5D9g=QwwR8jpmGUY5-baHvF5^d)u(Jo|&cCB2E`NR#m3TbFM%846tH5a12EiRNqTUjC6 zb=D(o$(KvXt3&kJBR$O$*Bc^zKu#~TL{X8xNT-WEMB1#>J1vnC7%8;D8lumq>9;^I zUK9{7qJ2?)EVe+1wqSKUb{~15vy_~bozU+;6HyvYAE(eQEr=3kMU2m+wqq214#EU8 z`do{?HU{d1Xs2I~utYYo6QYlC=&6=S3FuGX-w3Tr1m_;hq3aH?7Hx0q5=-P64i+B? zixW|d{{oUm5u?p{RL76D5G$U2_)VOPHSy5~CEEvSLdd8o%Rq^mfUrHdgcEw~d=Oh& zA}f@AP6p1Pe^o>^HD=K>6sP_A8jGU@nne2(S@eX%8NVJK%gdq%Hh%W&SspSysxc@| zua6;T^W#T@;&?5QH4c!Ie!VjW;$#h8<~Z;A^+8Lf1azSNkK{nPAIAL#KiWAY4Wxu? zl{V!J3>HT;C+RH|O?u`bD!7aauA_ooY(YwR3wAdJYv8~ILw{oc>!G#?B_MZt2M7zE z4bCDE%nV#l(Q4Ps!1Z`GM%Q2lt|v2axCY=40G_}p_iz)bAi^GlHXXgElZNcvhe)bWpfOLF3D|x6S zl7^Ba9bGM+FbPd+I}X-7Mx%dI(Mge_ja@}e+7xXZPZ(P&Igo=~QtLP<-x)u8IkN1B zlz`}L96~n|hwf>1aY7*?zT_dEh7#(GC9>P*P)p*!WK&Q>Op*su{Fek3{a+&6oma*K zYoyb(V4{{WW|B_m{mlS$0D!d!l#+fSx_L%lV~LkAu{Ynd5jvZ?C<`oJ5d{)VnpQ-C zpq>W0lSBpiCqy^O=#^Fu3pYDKp-v>`xrmr^O`63t)q7*b;Eqy~_z9X4I?ldeC4PL-C`ly(Mj;1VCSb9eRa0tw3N)HGSlfh&eck2yqqwy#YYKW;@m5 z*@vC1BdZ`Sq)oObOIP8>m_1P~^XU{h8$%Ekd_F2?b7D z;sDcy^ww%!^KG#KuehBMU5?j@mN>y6={maZYKdH2I*Hy|t*^5jBcnH8G!6}+{+j`o zaf5SBTKX>+bSH@l@=w;Xd-0ugzrN2(q6FGRyQ*3Ar0rLJ{bCHygvhV_CPdPcy2t$b z{TPUoMURsG<=4MkGKXnX@-HcQ!Ai#|_v?D^h#4q>inGa>^wNU&{JOQ}nFyP;bp<~9 z?$>=R*%Zm52hBhA>sw>VA=>=Z`5@-d!{-S@Na1O@wckVf2I_m%LoX`$z^@;)CAl7> z<_DrCz3AY5zupxCakA)PykGpf%#zJKltoYA{pr`IV#r3|pCYjTBFEY4*NxtlcC!;1 z$X0>SYkxNRb*mVNlSQxN+3wf9J!Ey;idz2{}GUvG{jhYrvL{iY>yq~n38m5)yCoUGJ)a0(lzk6MV-LN8*e9jAZykm+R~ zub}_Y9~|BUO)m&}*{?72km7yl7~!hU^(E|^E_mF z_sSc7z0O0Xx2_!Y>!&|!*Uc?i9GqUa^0r@hvt(nc(6?}6oeQEl0lqK5X&UExO@O-OF2xI|bpg7KLE{X@ zmBsj{v*S>cZD6gkk|}{fNH^$(=vFF`H$?(95ZI`1SS}h?7OHqs);z3fPx% z8aVANM`p$weibNq%QQhJ5cEe2rG&S>(?r8^2nVxnUqVGL`cN!W zSrKBQ2%R2;b`ZKh2-%^VaR1M*iqaf@k>-{sz0#G`;YC)6nm-)~9%qzLIRj4P9VyFc zQH49qKncBHg5**Qq68|VYxQ@l*~ldJ1RH-h%F#DHFzzF~HA&q?$bT(R=b|Z>2(yPA zRp4A;!m2rV3)OwER7Cj7!fGSv3l(ifd&~RAht&em@wZUTJcv7vMex5O6@=AX&=;vO zFIVL1F@dm}2S!-U+=n4UN&79oe^NR6G1HZ4(QFFKCp5*3%C!s;s!!|Ega;+_(|>RcuT z%jF20JdW~3>h}V~D5O+p0w>W882NNFTU>A7zd>fl;thi6aCVletzZp87^A=Wa=ZoU zGoUY1CHQ@mSfLM^!9g$i54$j~Le4U$raz)Cn?4;)JE0Z?ztO<41w4@9X7MpFdL|2c zFOt4oosF5TNUBdmu%*8f_}A)F$62BH^lUbro?WUa&*x~IFGGGMwwXsd@v{lr5~mCI zsx5V}Bev98rBWbbwJIK@ocQ^)9X=oI`v9Nf#4n`Fhi@UjK+)N7xm5n69OIYw{)9|_ z8oaRj4!;W&U8c0S{@7ASe*lVhE*N@_2GAkq7Jc0GMAnWpXtYdZv5L0ziZWSsQkxH!yN-reJQ4fY_cQephYKP@tF1YwR!;0GhAEfJ@%lTFv z>#Z$lp2Ob|4LhMxF1LLOq;=}+o(6EC0CQiu5~F4i-B7zg(P^0ld@n#X_*FKJ^EPST zva}+?w+Wi3fDu-m@Jro9XKjCo0D9Dw{?y>G>IiyRwZJd_LWdB-)!=ejuEnqCRdY5i z*Wx$$h;Ei^@eljVa;?+N8^C&ybDf^+g!D!q`S)D)_LImwT+tE)cAJDl--OtNITfJ{c{3_K};Y-fy3INuttMI#l zWAY*qmI*H4XTUHaYzYTt%Pt1Hitx2W(Ru!KkyA!;9`c3Nl_26TMBj_@UGbSj8J_uF zQ6@w;l{q(9HcwnG_EJS9+e$aQAjj9xz|LP#b9;c>JPyH8ks+=UzT-pZR1d2}(AFy2 z{2niy8FKV>QNhotrO$)8P|=S2BrjxcSltbJSk30&DU778`)n_ASy&BV%qaf73BUMT ztLQr300CPKP;)8QoCD@Em5$%ZXh2v^LTaI+%ZJ_~)t7|T<)Fhy@w-lW`3n_Yiu6*e zhr+4`muiULg^I3W4i#la$g%qHu=)vf{#(SBS|Y4sIYM8zmG1SjtF+QuFA`RY+Q(Ro z>%Ck3js-@kzymZY@Q1nUX>{>?6~`--usR#ZwJL}xbVQ)v$+2b=y% zo4)RWD~C0Y+dkfaoC#?!32u9ZKK@!bXXFUYzkrjt`}hYhq)P2id6ECr$8QSQYJi%T ze-+!u$I$?HAA5^<``F7jee9)H*2nLQGUaltq>t-}jT7bQ>ElLTc9m9Y;zd@~#}6pg z6%U~%JVM))DN<@?AJf(C0@xKtSFcc)VAXFhw}ZAq-N5;uy5J+Y$gff-(CH7V^a1GCo|fr z%c$zg%xD2Yg!C9Ql7E~dx(osn{?URJ7ylq@ydst=ApQZ}DPj$JvfP@v3`}bcD)fmI zO033(l76%%yZ|H37Rm(EUFeh)Dm8^ta5`k{{*bGX6R?F$hyEdj9C2f)_&qnl)uEP` zg0kRe{MQO@o)Fchz$3W22&7#}`a{9K-x1s;*z!t^;P4Mt@FACAr+Tc$XNkabqk=bh z1zTPU%A(?J-&?`cf>Dh#U4p46lSE(-EBFn4h6QtPF5%IBrSOVL@IfrIye>LG0ROT= z3e@E9sZOtpRsjB!i`r_-soKh1)B+L_$6PLIgVfEU%?Ple_Ba^2qUxCfnh{mK1p~dR zR{;K#>bB})s=6}OEucJB^+g_YC2V!7(6lYWp(}rA+Ibkz6`S_5fNZQs zOf0XoX%&F~)HGXlVy!BgW&tArsL-?>qSMYwnr6bzH;YVEurUjRbTl_lq63Y`#!C#Q zm~?nU&t<-AES@X;GU8V@7P|^ypd4YE-&u&a*DC=3$uzdwVC^bQV*!HzaG8eI0yKq| zNz-kNN7K^~-y?yMnr<~NqB`Et`OJ4UeTcNEl=zi3Jxc)LXwy%#5O32f0RO4!wpyo7 z6-~E*6aZqHzKEOtj5OWOiDzb#Dr*)}UeaT-*i=>DoU@6?~7m zxmE30HKO7|>!o;vP#>>Go5XX~ILdr28QQzk-*AR*XrAKe@2b&~U-s^ntHD^BJ4Hmm zUDr#^aX2)(;}^TX$;1qfAg)of>RC+H6t5h-CGFROP zoq`iJJ(Bncq|C&Pt-RKcZ$REdcgJ=T9m;_RbNkQaJsZFXtCjd&rGi0POKe7ZgQ9zS zQ=|ZW0y>zj8gPLNxxiWcTL-_ziteuOFVF%&Yv2OOv!I35i})pBbZfD#eLD%uQn#|O zqhKsiMJ{$ZvBzSyz752%dWe75;Frz;=w#snv0w{12B!f`rwC>dVNMh(fGT%is+?{i zZ!6jd>!R|>7ek+bTWG6A$1g~c}T5SKO*&z`U}6ixv%IJdn>ApMEy`L=QIgQ zNrhS=-MFDKGCjApQyS71TzKmTTw#yGlm$j<@8@K~dbg}5*TK{-9?2TZ` zYT+Hhd?3f*a{pq+@Iq-VPnz^qAo^Px#q3}VuNX`R&JbP-+7evmkB5I$)qxh8320>< zX!*rt7H<$J193eE0TTdT1q*EpXsj>L zlt9lC#EY;IMi|y}{T6Z6QxTUU+Pci+Bq1VmuzWPI&>w z8!LvAKVYV{+~u~!T% z&SO8L6ZUcM7@M6V(nnjH9q^|BS+R$V&Ajl+Z05yOu$dQNLhuqOY)0`nNV&sshbDG7 z+LEPc5QgLUzev;QaJ206tZ8HC;|groa5Tf+7Cb@nk5_x$Bj2(ws9b&pwoAV0`xa8L zw-xYRwO_f8D*B#2<3)eAcPjL~7hw8+HVkI|7AbmQr=Ezh1_&NNRM_MiIa?(X_yiby z+20pqyDBg6!YlIvFQ$SQcmc)>UWMw$3p$=lDT?LKaEcam-yvms%9c(jv)ERtG(lqZ`nI5mtTP$BcE0Vd!=9z$^Wj}-z>ihFF5Au zoeEyy1sE^5rfJj*C_G*xv2&;#gL~iw-c^+u=3Z!Q2ScpPBCE&ZhHDXb<-Ml5rKt93 zyq!h(^s@DNX41IBsav9mHywmksuXRfwc&WD?hDGS{%Rh?t=b|m5pxe1ll|1S&A1!TJZUD{;>vt5i9Q zq6KVXA{oI9gP(095t1^p{wRtPhuulotEl&bl<+G~uB_O)dXu;OAT*9z>I zzNV91YmpNqKlTL2vaAq~A5~zxWK(<1T~}dIED@7L-IvrP?l!s=*4%Yv*@M8Y;;yR= zik|meDsl>poHZ=EpCgME#$M;Y}#{~jXj623lqK(OTo8@WKr zx1=rS*B}-2q2@TwsJ`ad6W!SWuSRj*wl@=`$JAqZSPL&lqNlYEgRn{^BI<79H`>x( zPX?N}v?zZA@8#7KVIu%hi*ScFxzBL;p4q~)>>{wETX<^~J%0MF=yO_*YN6W5#hZbN zaExCx?ljt1EQnI7B#i$Y@QM|^n8dOi1m3!YPxB&O6#hPjkNVp%8UO$y6s7J3c=(r0}1@0zr8MZq} zkExP9&_9O_dp8rt_Gbd^1HJc6IO={eqAkS1JLoeN)ze%MY0b!Qf&V(Wm=1V8e)kWAE z0mxS}sBnXP11D$($K9t1rE39iakUrZgDl1O`19<05PXAgYrZRWo*=TXqrH-hn<#iryth z)ln_t;w~pyt9D{cUm=LjQRH?;z8DP#ZG~4#igbVhqrt$k9E{Ca54W5Ya6BGvSp~#$ zdpJCVUbLpKgz0h?!G;ML>_VP031#@$QlPOaA!H;NyH z30*@HvtkP`=Ql1o2zvDQ;`QdZ4z5>HFUCCwTuOIWv3t&^=X>WMkKhQA57L+l( zrv^&NVRBUWq;hGO_Zr}LgG?2_%26%Jt{gZ|0Lv_J@j5SX4M+551B}E>QhHGxydu!; z?v`6jO2^E7mQx0f$K5X%kq#nPjJvN<^k{2P*lod93p;R)H-jElgYb(f$#Bxf(Nf;AW{Xq+>p7_No0x|FjH56&Rw0PEfm5$UyY65c#9M{s28ETVrst(3=%iJ|576mZkvGfmD2dp%0M<&l zYb%#K0y^!3g4DGx8EpoP=0osaqiA?0OA&`+)SPcoWWGuTT~FT=7gpVo5}+ggM$<>a z)CLeGz@>Zg1z5}y&k|q}11o^g*+V~YqMc2s+i|lvXy|4P=ddb3dV{(jzvBi{Qd=n%81|2uU)6;0J#H=ZDY=E2LX$fwg zM)Pv3Sca2Y`%$Cy)FP_uZ*?yMP*}aqYK?$p!|E8)8x%!m3vG*4Ld|CS8iqa#2A-uO z?KY@=IM7;-{>lw%5~IFk)LVpFr053s8WQxn$Pw~lZ*a#lfu@$0A}x41s~1*FNQV7O z4wOQC5OkKCcc(Rd_8!Rkx~Y*>VIc_vQBh~XSq(x*!W7%?rf8i zJLRbQZsO9e=XXqe9V~#`Eb!`g80ZSbYd8w^A7XTAi`vxHZ=OxMxFb<9=r$6S#YCd^ zXs{WF&x(v-D;kF%H6j@_4wtA`VL{6+2Dd>ggpYrNi1kxzI?etH={1U8Rq~ApDFwYj z{&@{a$akRQX$Jm1%)bZmyGC`xuf;oUa5duC$p(Z^W6Ti#y&Au$1>7adhqT3y07ah@ zA6B(M46C;MdlCPhh2Jfzs0~|WAwMD%C-$o?$9U`vReWsIwBSA40tjeuXZiow0*eo} zr4~HR_=+tU1g>d;#TS9{k1Z$z0Dq2zobK|%p zV?2gH`=yzK2y|x)FKB_vgBiEqXli{5gypnHO^DvECIR!fY76?<#&)vkf>CKEi*#ve zCin?+&H`c?PZleIh?y)hrGo7QoZ2%2{C5;s%#+1@0iIx>kyafeOr)V+nk?*?Ozc3D zMRgvNX2K`}#XVvCaDy?k(-AHETlGJSMuC|yMt~Gn(FwysO9?vsBj^}bt_fq?zl@}P za_%4P2;a+X_Pw%T%Y$r(qdk5e=7otNI)O=YTI&3!HHdMTh0k^JgaTXO6=lU zZR6zf@|w`%QK-lhcV%x$Af`QSdz8>`STvs}#@tv(tM8P1P3uRkHOF2Ug)^~-v5Z&X zKOwh_=fQ)RwN|M?(8!dxX(x`0yg2U2IrDJ=R=7N{OsH+;g*5h z;2hsfym1|OP<=sBnjV=uBA|jC{1+}xPY*&jklarY`qvme&Xpsc z3;Z|3D?CAH5y??xg$34TwBSckst7ef_po{fL~1rI!V`sA24=!t7d4}H9Rb};{+1g| zLec2tKL}Yf`J3g+qoToXIX0ME$o6wZYBNLS3ZRJO!0g{b%M-(r^BA` zPiD9HJEUCvv3FTyMYDU6#_V3|KbqYOj+lLh)LszLqO$doSx8t-6O*Zh-i3rYEq`RS z8Ga>lOqep3EfI~)UW6+)KduHr^eGfDC$3o>UFgJhl!z+;KVi;8K$z7-2@o-Bk#Yf+ z5^(C95n%N;5nwT|Ma~G&=|(^!ZDW$RCvvL=!GJv!5Q5s{g0E#I4I*}X&% zwg_ghgy=Rw1xR$ZTcmm&!b8SVwr^Ahp0Nf4e`Xt@g>bB>go%f_60?oq<=Slob8dc< zOa*Pp5Rr590_5yci`FX^RR%hiTIZfmR^auDIZ4j4Qo1w$1?HQRMMmbG{LSE zQ&LF1=t?mH1HHlUI82H$E5(4AI#G_XD@Dsa%XZb6z|}0lwNkV^E1`m(y8Q;w>1%!OpMQt&WY;ujar zp_dn@eV9w1W$SFgFZnWwOAs*^T5)@KRw~Ymt3upM6ODF<<)}*h7geU67gvS2?sph* z1LUaQY2^_o%{YC#0mfP2+c#DY+$zAma#U~SR}LH_fT=TywX;W6~HtL z+;>&wz-9tyZGo@dQ91C)7^CAcIjUDzR0Psn`!@ z{hG_D^r#Ogj1_?5p4Tk06m(1qKXKDt^V+wf2|ei#{wlnQ%ASj#0LeYC-F36+ik))A zJk*cj73MW7lx{o#YBHlL%xedy7{KQ$l7_0Hk@YOV#Lus2n~i` z#x|h^^9J7Hu-rl5VnX_ZRdP*QOQiI@a;##~D(2mJt5E@0CDSL>ZdNO6MaE7!CQO{m z+L+afmupumYxtUtEmH>32~+;&aX`{E}hMeM(fgdMOr5K33HNxFe}Mdfrwd`j=R-Zzm$MeGa|qS?IXZqUY8aKknSI_ z>(cZn2qvVfUu^`{SB?o&4)G9*F0;J|*D`w{pSf-oM5W{O^)h#ugZZ>3*dDN{CYy=z-a;9I)jFQ9#&W57qfIKZE;OPdXZ{}nRm6|Z3X&%ya6-`jCIP(3adV#)1T34!$_0c zBu90kxS~#lsHuwp+M;fC;spjR0v&RQeSxqoOr7}L3;An=sj6Y5s<^h)e3r6?rFLsyc z5y?0;1cNuM-lQsUlLAOzw5QSh-#TFaWJmKFMH+rBtJV`#@aJV*(50bi<%JoLguk}^ z3ABSjt{(3z?BQ}$KffD=7zvg&f+d`avW=zZNXa!335}q!ID~;bDy-)tkS91 zxRRk!wvq6;l>9X!VU`yXFXsVG<*0sMABC7oEUT0&*&Agq@GYTI|H>Q3{j_SAO9V$cy8fI4sAaMYM{MLs-u0FY3*cPUK8|Q^o z6Ucdysuo5ermZDH!SH@%R@1oDC$)o&-F5K~E^unM@61ehkK z)Jyo*wvHkuaUlAp2DZSW_gz@lAh4qMwb6~D^bOx4*)FTwqcIN^dkxl!~Exlyz{*W3|aBgY6UBW*I(!YjzYQH?Cyxz4STxtsXq z8K&qVIjTu&Cl`0E7dG&T=4e5*g%qIPV-%ff;_(EUx-Sxb8!Ks|`r9jMElYZJx~cPw z9Mwd1VJA}AC2gMY=&K*}rzWTYjET`}1g<~&LIyE{^qQbv=}MAr2Ln&9gY<-&hO}OK zV&-~vCsO7j+q!9{P$>`zt8=cTGUg&1U8p)E+!Ns9LRBeO%onT7RkTyWPaMSjZd_ch zqJiYTidJ3pKVOcxiq??f6|SOLM9(O)!c{bSd*()|yueiMzWVo}u&jR3tA7{;bdhbo z0BrLURqH`~+d(m3fJ$jMB zi-?@t(o{|7q3KdIlj>S&>S@_AQV)zoH$1*38d=Q}7WeK#Mv7MCMMNqxH#}PQA!~`) zljsU;x1r3{2J804q-fag%9J5zcV*~Kz~5zXIM>5d|Hc~^NlSBMMGKAH7h}Dvd93Z)G%&^cAH}DqE z^$c}w@t8{?&x*hka>N$TY(~1ajLb!j(-JFf0IqB^h_2IE`))_Qe32t^H=uby=7DT8 zPMm)s?9l5|qT76yl>%1mHlO7bfaAGs!Lmw;<=*C_nS;Iy-&SUf^jW6jF&!}>^&E>eYWV}&JE_K7NoYjI%UZ@CJ>=$T@l;A|#3pP*$w#2WqjPGsX^)W8-P z%ocbNM3V929#kx4JKkwz90hNE&zO!|d1a*Iu2R`ca8nxycs2z>WyHc%)?44f$L4blGLtIltFlt4 zk}+VQy&yfIrXY>SrDmB)wXp~+125smL){4-om4Z0>kPwyI>*i83J7>M@*`>GrYp2Y7vh{k(ExWO@v=$DtAw+1BGSvt1zklm1nGEo1bvw zkE{$&swP-lLzY2&!VNZ9J2%G$>y9F*E$9e2TYHcJO|ULt=#CF)N~B;)!R7lGv7xj!S&mQpW*t7f<>44W&`5uvwo zSig)>uCQ)`_45VBw4cebs$gyHI|9;TgY{ZPA5TjWy(|vSypn4i45mb?R)Xm)N7YBY zz!=xCSgTs2Kx09i6GeW($gWXo|B*p|T#l-@s*N%4iF@>9M}Z({8yTopjN+BBnP@H& zemU`b#Y{Aol{nlR6D?;1IG%~dvWki2j)@en-rfUaNt`N@V}s6kx-T|ftpiD(W$Vh% zvb_z$IyFd2l|GP6~d2LR`gKsv@x`WUW(Y3G)g$GT;FM+(-cEP=;n^ z3U}FEM8iXj;N8|I#$Os;713chx&9Q+b2EpN=bzJyni(7+%^X8jyayUpQ4>`Zi|7H^ ze4@X0y>U~^H8E9u4$=zsqsG0iwWx~eeJKCngRo?6g0A8G1Gt*6>Kq4uFXvmV2S4Em z^5w|Gg-2lf`hlN8JnMn&{CpWT%=b&U9bIsjNeJIVi&4ZQQP!Uay>65}<%mNs|y7^ zcm9*AF;WHin~{_Q&Qt1A!vT}H$-*T>L4ML)K%P|BgP5Om52w>O-6#d0N>me&R!=J$ z*Y%!Oci~V!=^o}RH=JS|^wVk!4*sOA%qcOPeTMTcbKYdmXGlZn4>Dg2z$ zUk#Y)~S1W>4X7C^J2y~g9AfA z89jfRrT7Og9*$BOb+CLk?GFro2FkP>^Tm2ACpdU?BVfk%$CBP)5*vLU1m*(u*Ncub z1Ltx|D}HUlSE=&a1Ux@*1nEX^4FK*I)#zfl8S=mxI(^)w-8U)-b$-J-2lPfeN!f4J zpHrL&$w%6LrygGwCEZQxey=V=D{aB;r0);v-J?;`ZKUvjRTCX09mchvb|=)QIIE1q zx(PL2XS$x=X48@=>N?Zu7ok&yU^@Kt5ZmE{O^2`i#M&k$=@Xyh>{54Nr=@8PwI60V zgs#T`D^a5}(w(NY)${04L-XxYWw$#{)1dO5u{3{)8kaG{X{i0=rbVPk}p2 zowLv4g1gkG8K9l3GH)cPruu$tX(_wZ_ltqMP+d93$}8Bd{(w6-ZLW%O z-frq})NVEB0{~m7ZJD;PT*kj=-;i%F9))n+OQ}>4D43h9t5$YdSp$6 z7~HL<5%Nma1?`lI5_hYkR8f*DL%b6r)a(nNXxd$^xW%fpeV3xQ-8Sv1COv6^sk>Fl z1)%j-{$ZBpS4s3m%UvpI05~_Q8_{3A;Ab%UE_DhI4>cX87WKoOBusgPLv8>zm@vN(K`7D7wZ$jnTqX-E~Fi|forC}^P!r|ERnudWiBuSAWX8E0w1q<2_m`qU{-(^YEkGkD#bm6`^I1>$n)Z z&_WCDQ6G+myem!*iaAS`q;rJ(YF+9Efbb(Fu(9seDaw`bU{Jh9tq`111&KU$a9N4 zqUw(HiW>VnKIJT;XlB4){$7#z;XKQuNfLin#bJ#Rlid@<%`lTuvC%ZxuwEVCU3+ng zFvtW%dXHQNrJZB~J)u2DG<|Eg$iLVXzW?3|% z2WHdfRT3ohZ0Z}1yV;_2-wR5kM|z&;JJd2lPr2OzDCy56j1__U8`ZrRm2OfCFTtXJ zy$Q^QLdTvv+$9* z)h^P|xOOm18bS$BrHU21dsDZFVvee-F0NC*rmoYZPF;1q`d54qGl;K|qw937nN+i1 zeayNSIW=o`2Lfj3qI7`h3iP;uLrHp7dVGE0lWXB_v@TN6aRSVaBX;%rir7@B1|@6O zq=ML-IoIh|zjKZDNY<)t3dRuupJZ#Tdeky1m~wUE0PTnx@GccnDrf*5Yf-IreNufr ze?&S}R{v7a&#jHKW?w{shLmIl;?N--rPjMs>h!DMqgMNxB(8C!@;FoZS#APs9?911 zU$bd_gTYNlqH&y&(j-b?=|m-^&W%_A3SdI8r2sMo&#OSAV$H-r=n^teVg$r0pC4^F z?xBhD`iXWIMo2KQ(c>Z}QE$eveujE+6lmIp_gP0sHC@05zp-y=?(VjD-z)AcwxTyKa7PvmB!X%7}7b~5xAQPOUn8rvg`S9%Qh&A zCp@T7G6|wYx3dsFy0><0Hyho0pxS_G7nM$l>h3ae&kBYj>{Tqw-EWv_E0o9Q4uYaV zpXSh@uP?>|S4Rp^pOVS1iKr-j(9bhA2$bp`r8I1>jg&G@WIVWkL^@GTuMddOj2GGA zFt8H3<6LL`fz8o_NBN*gUDglrRgMa{bD`Dspho?RN)vSmf>eN7aYICq^?ZD0Erw>A zabv`0ab)!*%$OJrQKh+D0?4kKMhK$Ys2D;u$4QSNpy{K9z=NM`ks+0FxTTI9AF+;_*UU(T>|OmvWI-%|jWME3LoF#ib6v8~k?l>#BMxr3RT1A9{7#)%Rg)S%6(| z!x>t07+WsPJlY^}b7(`!mB(zh7&6HWEH$2_E@1>MDm?4ur#U@ zmtJOc0%v)&9CKE1IkH;6`c!fy<)xn}e=qXjpf#&hP1KGP2itxrai6uFQLWc*4|y)Mm>;?c^_8;BjQf ztvDJRY!hpcob8OJC6rl_?LhwO`V`@wG%19sr%Vd*>1mUK)SaB7);)uincX8HpH^ZqKwu^E#xri=_t zp5nBbnmwh>_(|y#rjE{NlYaT-Z92B@*k;uDP;A0G;} z=`|VBGN()qO&&FM4DmhHl1i4{s(tH@t=qN9o|4{X?BvN~CqxVWp9pP}9hy2yS~p?* zs5WEM)7#AG+$pV7$5s=@PntTT)!0c>$q21GShG~#=+POYrjCta#bm0sVa3`inmaoO z8vY+xv`zZtiJ9XkWT4;wFQkv3j0F_@>uT#>t<$k{124=DO-P%Tkq(DzJr0iQj2f9e zK0PfvG-dpxv4%2!GIALsCpy@iA#~=*@s(ji>FHEHecZ??X`v}2;islJ6&W8gJ{_f` zPo4y+Q`19+G$~_x+QWxjnHq;wZ^_An@n{4<}$~;rPi&R>zsqsHx*8 zgj$WK>m*oTQF{%8lkJhlY!Dhhk=h5iF@s4{4Wt|ZnW1s$)X^@=SWsHQrX#0LAXh=4 zHTtDZpFD*u2ZE86mOf!*b~Xz_BaHcC_3Qr+ zF*=MqY}NSqk~4bdY~}aq*PRf~L!QkKg#23nqA0T<@95^LS$ebH?Dy*xxeCzld?8M! zayn2H$$aSx)z=T?p7aOwr~V>vH_l4kg3K8|LFdm(9d;`J4*gXAeyFhB7f1xLEVs~K zUBBZb>*(8keU~>Zm^;^()*$euuUp-~bI|Y; z<-14)iv2--1+}u@(C$cHQi9~LBBVMb&sjPQnbe`^p8q;0kzAU;c@8)qsz5SwkLK+U zJi%GwJ)E~**9fd%y2aPF!BpQR4b}zH^{7Be@wz}^&l?^batgrL9IEH}{GpS(KhXJg z5Uvc=)3u6BHG5%Xt^eS9=H_pnI}H3URe*Ngiu3mSdIbY*K`B=xVng0ZopVxO9ta)o z7T6tVrb8!>^c%MIreVI;_5BHYYp(A?a*?-v>p4fB^|o&)r&}Zaj&C#4n{xxL1Kl|5 z>#PFVQ*R1f6le;@mR#QjRQxSp;G~`$7p z1N}AZT~nV;74Dlo6og_;>GIh_Pu)2TEqExfAK8zluZLa_`-bXTC0jr}6<31%l9{Qe zz&wch>*QmTNRj! z25h8uPy>8jl)sK%i)w1>FMYlgliSR>5~y6Bn+pE!eCp8#`c;Gs$`vBLF&EymQHS(@ zW*5QE4=Rkn2Kr84ptZl&jUX(~!(eP&xD>TLpaLaO{i)o-Vcn2@!&ijd&fLwMrs(qt ztiKer*Yi$p>2@8+Z}|=*yNMx(Vf_aB3&+<=f%d`d!+Hdn@sdIm{NCrggnVT=I`nnq zzw`N$DZc{w^O677=j%oJmARWw1!(NNrzto*G#k3t2$bk)fz&_`NF8<*Rjkouq+_!; zbK2L2s=F(fZ2xQERNx3oAJGVON`E{nFeXrsM#!IV>wx}26(T)1kGpVppgth;V9|g+ z?x&7hJu8*d6#rJwqTVX-TNkT!Mi;}JHTB1E9JgbwXJ6AFz}L0@D3?kdbg0Qs=cjUd zKhm#M8>&xCFVscsAbUe_C^&&Q2RX`L7z6)5oTH<02a*wW4&y5SubqQ*{@DqP(XCFh ze^7oYOhvAdfN=-U`v2+`b#!}j3a#hlk&FDn1AeYb=5!%E^*tZ?msDY@edD8oA7Wr9c zNVro6$fn0;o4B{%@%2~0E%R}h{{h;=x!`C}B$r|X7_GZ*F@E-6a1-=1`50gn76RlO zg$nLqB3QKVDHzN_t0_oOe*%=uAXCCdEn<)vs5n|c*^*&!%#C@6kwLt`sBp!L%S?`B zz(Fph7*P%@P>g^^-hgpf;>CI#k0NfQ!dyQiNTQ3dn$Y^~+*IAF2-!O^rbIPrT3%NPvr&@|G{;p0^$lNCz168lq*a?flrK}sBnPC*8!h#gJ*I#2bLoE zE(mb9|1zDleVr_fMN=*&Vy*Xcz*PDFXN#ha2}=LG5z`(DX^Bl(q*|5oxVB>$b{ zmrMS8DTI8H=W9*O^{l}$w+8DmNj22RFj$pdBN`lI4Ul6EB01I|l8fPy1_h!)LEh%T z^r;{mj5D@>dS)P5*P;>gv5#Z*!*CM)T)yuzrO!v-)zeP~fY_0L(%(pbcs6zB+qaD& zy^o9D_p#pJy7j(~_5POiUMYHi%X%Znx|sG2UgVjNdX)(_#Kk{x5;joY?;Y!lk8i$NA)>0Z*5C}+4O5u1MBtb zT#j<5Xf@amtR+5Q61mSw5bj5Q6)h-~{u-`E8S1d(xfFqme7t-*0o*=hmzwMkxvU;S zB#n*lO>Vi#eV5CpIx9@>Ta#O9a-}9$Bt!5-P9XUWNL?)XQ<4u${xtHsMW9HJ-K@J5 z>M@vxbPdw*p#%;PrJ25=6bv8q`EZL8BG0kehoKK5jQ+^+wV?3+5l8fcvwicG@@-c^ zfNrEg*+BnBXGJ_8z<(4%zwZ@AB@R10v^V7!-n@ykG$m}tx;?1h#ktdzR9Zpqo&(|& zSW?v2@ALW-fj)IAhy99cL!5xP<^YT!UyJ(gV2{ONbO{*ZAWzG|wOABVz()sAhGqst zf5>u0f0|$Ia*-nZ##|fyX|8>cW*=EC+U0-=^4vxH@;2+nsX8lJC!}5r!yKh`A&T9n zHd9ppDz5}umhdUXYrIA*!GwWmkEy4Ye%6=FXkI>Ds1VNGaPUvI+s9E|+2!@A<-=)7z=iBLq! z{hEt$t@PbKUk6&6EEe`DVV^PV`NGDlM7i`&#KwFR)Tb5AMGJ9;f$>0DUMA=`;Eg<*de&5;3SzLUt=U6Z{ApC**sWkt+BYRbzdO zhE+|pk9~{+SSNO|r^O%#amIf>jJLrDveKXDo@5u%m@fg%k`AUqZy~r!s zQlIg(=XtgKJL^6#mppAQ?MZwFWwGUeH8?rhXPTVszS-+hZAomk7Z;tnIneh0IXB(G zzqijj^%Lp;RQ{O%p#j_S1N#Hr2EYQH$;5pNuep`dh1&yLeAmO5GZD0#FKd|J5A1id!{=5B+^n+-sPBwjGc7RTYJ7a+zxET2{zAIJW4qr=LM)JpDTW?U9wp(#G*UOG7G30oVi!Av! zM+G+CI=p+!?x^uqtZ(A=?mU{s_hH)j%SrWD)4f_FyCeVbe56~Y0xu5ZZmhtlp z9JofD%~g&5pKJ8>r#`5QJ}AFO`s}bnOO<;tY1Y+0&Y}&ud;CLv0ozv&ZXcyT*i!i} zZG2@<_`&_NTf@R{=29!yV9&6IK9)=Rt-(YdhrK$YZ;KBU1}?l=Pp6oL^~0?F`cus9 z)v)tJqxGBG*vwg-J+%9QH&Em`K26?^ZN?hRlCIG!DqGb51TtZfSh$*Y)BVfiY$@kzW@q6E$~MSB?4x zW^`Tw_>mc7Vp{$^wm3*BS`tI4R95N$1eU}X-K`H`xM6?cQ%u}0Qxy@Y`vI!<`S|2{ z+rfKs2KtO0tI8)i2qtC&X*<;+c#lfRso|;T!cyW+=>domx2TVt9 zOMty_^YoJg^aU``#6ZZ`(7K5IKs20`T%<#5c*p=+3v?)<6v??XRsVuPhrO6tJSGnL zTkDOpQ}xFjFP@u8t*Ejqx-Wx-Kb#`{E=1JT$FX_~>Tlplb@jdIIjzg`TF02q_F?yB z`ZVUSIQ<^>e6@Z;ZRT_l3hvh!dvW?PtlsPD_ce{J$7Yknzp&WSIu#4@y84RN1FpIG zIj{ndUf=lm?|6Szh|3$JW?!XACETP>^|PzxrO>Z z?5#(a_p;og^ApdKe!VQWXn9Y|t%d#&FYnFLE3&*#(7(_|3bqz&V(YS!eM7B(hYK{& z3+en7dwhJ_mWokAXITfazYIzf3Rbmo#f5-alKIZFZeiaiu8%qj*HFF;^yBF-ZGgT0 zo#FJQ>w>)_*Qf{4%^GR_M~=#vAio3p4Rq3O9(Zk+v^3ljk(NGVM!OC%SJ3+n33a5) z^!!v+I6~Ku1XFHP2u|c4II)otzDPC zxFx}(N}oRM+V`4}F>*@A=w6ejP73vzhD)%M#wPL)E@M_+!4;lXwQnm|bzBPE4k&$So6b(Y9+>*KGw%?k@Dm#cM-N>|S~8|EuP8z{4g`BrR>y zKoM|zJQdssL>3iA%|j7U zc?J{|0cG`pBD~*s&i6a#*17lAGTqZN@o$tlr%s=9?peR{?VnD-%7(8plU#SFiAC9% zZik*K{}=6EU7Zu9gw;l?+O8h26kFBhx>@f+d&16RYJYgLCaKplGQ1m_5|FA-L#RGQ znR;&gz*>8Ct-Yt(gc1rm%@;~jg|T8jKfX{|uGVEAZrqRlt(1SfIJL4`%Z(Ka#i|qB zxAIYOb^&toN~LJF$myHdWtE$-p?jyxyzcEXt18oL>B8F0GbC>%%Vib%pjQ)MWra2Hwz7r(!f!Uuxt5iE02n z=*jG?!lml~m}HalV@p+Bw%Nj@nOdPe$(c!$x|Dh3p+R92#608yhOD==jv=&CfEjVAW3 zCZj?wxD1#A4l@Ao_)@cB0Hr|f^-nUFtK6~%z|<_&mn&F2oD+LVHvAG!t~OSoZc;wR zW6>Hb;-$!qV3n(_B3^-G6@islajWAb6O27e+Y>-^YNm`8S*>9MYLUIhR@KSegX+or zO4cHdEtc9PJB|>@j8q%jXRHd1-CB9(JV>ZPo3i75yuZK&9C@$tGj5cG0PAi{-btLy zO0!<7<%U~;BGCU?Z8z-;KITvJOrueom@6&dJ_09b;wnMk%x!FLRIVbFlA5h{v9Tl< zq{Y2h@2%7q^)x_A6ll51feE)WH)4>51FND!)ye@=SjFogI#YJE00nMDc%*UBMVn2) zLlL*Ly0W&CpONc5ec+nu{Gt4G@fka3_fPG=Cek^Z6PEaBh@p&$8X7)0*F3dXfYix$ zrQX7Trs{hESL9Oc!GV-7N9OG9ubhylE!ww+Qt0@}fo|t=G0bJEoZnt=w2Kw9ywyl9 z5!4{jTd`a!A2m$?9yb0h#e=!eLJPbv72M{PXsy0jY1T@oiddB6m1YZiZmOhtmBT8p zyfSfpS2qU3*ti!p4X-*c2bzwnotHzk_#ZI9dZi_bi*hmW>H+tUj#g?=PZc$D zdzdTDc5$s;Ls3*4P+n^ zfM)rzrXuY(?vFh`Ayw4M3oucvppu_45H3XX&Bbj^;AUbn`4u2y_9{D&bB3r%E>~-u zs5FZUSU5p>?5iDrEyLk<;6E`c?z+NgG0M-*9+)leJutg(=Unlc-MgdRGc$8H%;bxE zrw{C$GawG&XQX(@q9y{TWZ)Jd$?d>?2%0pv+JPjI_7OgMttkoRwYe~m` zg-6B!Av*L_jk@e|r8!m2j~4|TEJXuIfWXQ1F79@~ z{#s?JjXh0$9OV2Ng2H^RWdWj|$I=?Gj+K>iWFA1M5w~$9l z(Luw+D91WEP}>_8DO5zT)#nKpn!}v$*u^C*9P{)I2yvlogsdro4mao~-mU8L(e?_A zP|VRyj4-*5JC@df()q>A1aIp;&sfk7qIi3PC`Jh$J;97iCoN{21t1Fsi(V4uqXj4H z1_b!3VeSbwo&l8$Me!h0t%C&wNQMXAkh1;1`;(X!_)xdXv6XlI1h9`|^~Q<1?I*EW zV|hGRsVDwiZ&J?}EMTBowy-edissqhb;De~VBTv}ao4H+xXe)vU2DeJPY6@jSM(#wA(rNQcP%7lL4e_Qmz7 z)Ipnn8V0t1+g|SQ=z4N77I=dm1ZD$3VXQ#kYE}mZbHZg$xV{mX$3Wcv)k7f zAYi>uM4ZX*K~fj0V#QGv`wr~M7xVjfBeDD!MQ8R^+D9Aq1+&b`?Lz7_OACU%m%xHC zGB8h#8rwMoAz^_DSSBE=DDK9J#pVJ`W1H2bQ>iQEBpYMG(#nl?*r1M%8lF(+F17YH zn*QygS7)vh#(+{bv{f!*cZE`ut-5NdRBKg?JaYZ_ zBsXqWLpTyeL!-#y$dcuTIF8^|#Fv5Jil9l2ufdGZ=OO2vD}n&j>ydiIa~MR6k@diAruNT`j(|7^VrscgI2$CGJE<_a#$q4bDvEPK zY_sDZB@auF4G$>C9%3v9$J#5!TN_{k3x*V)&s=cLa+9=WU@^weCwI6J?8Zfc(aV(w622{NUV!g!fz zIvKQ_E4!d@iJ_} z@wf?-N#O_KR|DAjJ}_pj4A_3sag)-{9(5!N#id%K)HatBT)p#F(B5?w*9#mHvgvd( zd=k*f@DjSv!-lZRjmH^gaB-1FUm08`KZ^Ip!i+OIY%42ybBTMys&NOfEeys-3zhaE zNREt1Y^fnDoPZkx>D}apcP=ifW)X-@`@Df-RMiiIsO^yF%d%FYJ=NB+LSwC2uFOI8 z!@&NMV?JOx1FZ@8?|?#)#U||Th2o1eNR%bYKo6eVkjkYuNR?q80Jsavk3(mL zGKpQxl!Z;pCT@PZ0vCi0M?bgB4iCl{S!rd@VOREUgHf*wk62xa{q4Lqq# z?iY~}BOfp`m6_Ta6zeQK)%{8jJjyd%deKhkDJYOP^;#z= z=*fMYY{4UrVLzJdD3~JtXW-kEY$nKqf=H^{;z3I8Piv$EX|LT=y&OI9LzNNZ3u%V{ z3T}9E#&Em~#n#cr3FuAQ?lX|NOn0mE!G|Jb-(bxg-GbPnSo(cwIXB0&Bs@Mw{eC6C85fZQh z`H6W7o+V=&@FI-t03|dfBFxs#X2r?7Y$4Hw5s|fB>~KPZnR|?aEYoWqcH}@r8V@`-Zh7F~z8(@A z52&?Uj(5PI#Q7DTq=lSdpoz*1Vt@ebmrr4lRu-(15Z<8irlDobJ}sT7+H=?C3G+v9 z&^^tCs7!v+bJ}LEJ8nJpS@AYsb;m77C>whxV?#@0#~E^w7a|F+lQPK(`vxn`F4_v7 zRsa!aPjBp_;gcSxpWVS2W(BYdYcID64kV{fWY5#}k#sz6kjW6IlF(ieU{w)YWJxH=Mi_ zYeu6Z@CwN0f)>XOr$umKP?=`3tr+=uy0}vuwHA-!`hg{2lrM~M1$pt-St%_R8$t|g zQz}x%RSwcFgHh2bN21H2O|y`Qz9C`A`5;GgU|^6*eOYURiDDEth>MPvS|A!NZ@|2@ z_QZ59zHqY4LQ@|W)TM!h0=mIl3v{#0vm*T@;Y5r%KQd`<9#z!?rnJR})B13tvytJ@ z5O5c`S(DAu3DJ~O^NZdPMmTMF>;rAv(c(&U+H&)7SdIyQ`$>&#aZ&leh2{}D7F6J2{xn1z1 zYe*Oo#?Zh38<%a4341(iqhp8OCl)x?l4Y5NN{nsh;9RG6^T1and^ba!C7m^%g0l!4 z&GW&ntLHR6IFxOdVeJA0d((=I=_JrH?{ITRFr>(0<4aq!)$ zr_wl9y=I?vA--GS2dSLcvuqAPU$5r6;cdP{VG~<@o!Zu>q21IMg9u72bB;D@!0Gfs zAhMMD1Uj8*hw_z-^>%SpRzBRd9@vFNqAX_X4^y(29vT~&NZO9owboH<#fsGsek}IA zAx5DBtHZ&@Rb9r7TpO4Ew8aPXSgrR0rO6r;LFxV)_kBe>$ryP`-I(Ka4Ag?1hLu6u zBS<`8r*+F3Buz5eOo-n1NDN+P`Q%n}$#VLYmN8a{Fj<8!2`GWLi>t<`KoOjBkrJi* zUsyK>Eie&WcYkMv$0y9Tl+)QA7>&dYQSpw?TA?4764u$O)YoBByjWeXw)I)`(2`WS z!%o!bLJw!C={+Wn3#`k6RQ6de;P=@3E*P=FH(+Q5_E)2c5DYS94<@^)ftE%2Ni5Js zVhpq3)U}G=#yr+UJ`+asoJ*0iL&JzH<6958t|vdw;~BN6&kR?yi|VFh3(B4&U$| z2uFyWEB2hyV6a`$yhU5W7$i;0%t)7aPSAZ(*zRFU^c17eKJQHSgYTBRU*Ni6}Y zTee{z4?(LF*>0IW^5PQ)n)a}Imk)(3KKW`A;sr0HRk1cglQ{D{OT*Qk*u+tbzq7#0 z_kpbn#^h167(fXYp|xHDqt?j$E(N*~s^R}nTBX$((gtjM# zFL(08`o?>e>=li&!VZJ#G%HKiXM&snrw|}OBFjUP=pcu_e(+|-bp#=*Mt2?%b-|fh z#&o81(m*mm;=o>SY^4G9Fyna2;vgYV&Fyd!9nZ9kJQ`k4rbYpoM zPEw4k0_d>kWwEm+D5+Z3*7cVs@dTg)^{^|o-3$jSlJqKEwk#y1Qq?gY%2JCy{p zphu^&y!sZDm)g4?nmDP1g3(lk9|zg1`6$^W*F z$NYWF-lPnsTY%DM-)5tr5TpPWf{k-b zFOsTFdr==eAAq*Up@v{xbdA08ztR1WX5k4PFT9hT8X7uLV7ThAGm5w^NM6|Ok#Q5 z1BBV^^ktG7%zXJeC8mS8$gS3NIPLql6|kUh-3mrBhMD zwNsnzLyD!BJKTPjm3W zH!^%e*TRvKPWY#+_4|S8rrJ+lkIx z0=)&$gqF0m9hRxaz{-kveagUsg2xJ1ZuQh$BR|tcKr7n<`14yOclI{zV}iU zE>hIu!wbkk5tHuD4SUNnd@jN5SvUQVper_pb>y77c3%XiOqKoIkW05Aj7IPGhytP5 zT7v+A>#S%>y+}gekH!K<6(OQsvjvpvUU}Z*b$4W;Vr(Kite!nY33&vNhJL^JNv%SP z1CN*;60S|7b(64(Vyu4sH_46K0EVzI%$sy*U@`H&iBJn*tg1-%P?9i>Q_Vn+&g{9* z*7O1LG7|0Ed3{k`;VCSNBf_S!VvljfD|jdxEZ=U{<*Duh?-6gq)_Q4A%y=nEd!Ehl3SSua8YQ0jTwrtI9LmC`xVPfS zIAjNvlc=}`rzLP19PLER?q>U1@i|3Ib+!WKU$H7Rh^qB1zi5bZyPt8wbi7mp4WCC) z?hYNDBJ{ap4~E_#GROu#rwKG(^oN9;qmYH_uAZ4-eHxIX40vSR^A>>y0Vr9|t5Kjs zV~Og%?_@54^}>kJ5HTW9Gm*=q(;Z%q&GNO(n>`{P!Hkna@ybc@n|aj}N1^*AwxA(H zE!ELSX{r+=Rz1AqrP&P^@vzOZC&|BzUAbD5!pejg6WWtbi?3LPn|M3lfoVnI*jaTw zKY&!iNQleTX+sA2tu(?#T>gqk^2d$SFa?$Mx zMK@!JYG`E~;}*EE^mCl}PAI|4jZL-Wa?H@uc|VqTOiFO(_8EI_tE z)3BPT6`3L8$}lDXc8YtDkCUOI$x#QagIX#KIE2tMr!jLr0|VqULmbjqBeocn(G7ge zEbG~Do;&ou)xoWJl!Q*VKf6}nU$6~Pd|8F!uWmT^W#ARbe4_ehpR0R3p~XZ+>P*=} zD;9wGRo%F$#EcN^0vcHB@CMJ}dPb=!>bi3oqcp@C?U?;L^{>My|z@5RvoD>8aV0#1ZcS!S=iCp z1@G~q8-pyn-f2-pQnxw4het*ovbS8RLmOEfrppbt_aZzcv16##ayWxDukM91fJr4o ziY@SVwP@$Ulj(JaLQKU;h@x4pp8aGfKAeCKEzExeMUW%0R6QvweXzO*LQ|0@32{+( zFUkE1c8VJdB^5k zP&PYRuB|Nsz91Nlx(II>dt;|Ne>Q+060X16IMsijVtYd@tJsTzQ*M9Dw zUOzXEy9lmVCzfGd@1;T~BeU;EbO+?b-e533nsA}F5S{LDXlZVJ%V-RdebOo|!E~k@ zt6Zdb{^JR`gMcnIlu10F4m$M5JL(~J9WO(|p^maLpV9S>p6&@5b_RzhHzJ5@g99ptwhGTmgt}i;&H5Eug;`!T?NkPAz?KU z%+w&X1Bpz~4+#sMPHUUc;u_-%7i45Oz_E;sI8`*w=oq^W9GDJKJgY==HlVg!Fo_*D zF$O7#eLWpUv>p6mQD5r*U?(Q-PC|dTqu-M$f|qYfbO>CzWcY69+F$0wQ&8X?v$XFL02&Kzq&3 z?Z5=YTOlsZh;AfuQzKK1rM(yIDP3_-%z&Pri7=tos z5{aNAq>R(q_ov0vr7?WR3j`WBw8T{Taq@tXbV|2E&rOIKx;QC>f?muVJ$w}g^KOzG z347cps<9wOE78hAQ%(S>sEtL3&w{4(M&X!x@irk8z($SOx$plk;=t?9#h#qP!qkaS z=l6s}WIX{XmI>*Z)Z$<`flgotgwVziqwp*3sfY_2B#1QFJ~SAQE8C_v?V+z^eX+t* zzi1K(Pt^b#FdQ^)O$ZG}M$&z0q+*G|NOyx%S930%6=6wz8hV&exk*r(o zIH!!;a{Q(tNS4ztLYkF;6Z_-3Ry7PCG;Se9v^)pHUXBYC6R1I`b}*8YtE$+hFtB@p z6-P0p($3a!RsjXc=A^FyL#2fP#`T;|i;aw5Q)$nM$)X9G9@odC5f|vwLI>j8>$zmY1yow2V{57CH`#cFUCLH+U;jJ{oSt z&YDW|`t{j}T;7jV@Th0FIcG^t$1;S2I{*mw7y)evh(>auf7fhwSh?PA)*=;1?p|G$ zyR#3`xp8t~4OdrWgwi#^4XrZ<*dn>h2)`JPvfR6KZs&BmfONXFP^lHCckV(U?gKM( zQwR2=W`I+ssR_sM%S>W;lOD@B`#9xk3d~s$Vptu9pR)dfywtIaB2%r?Ja2Q3n&%N1 zXyb5|PULfwR@vI!dbdKGvjoC&$#j|Q^dK`h5+iZHf57hNMYqrRGf72`w!_pEg2R^U zHaA*WTWGbbZFnw&#F6rO*$fFq8hb|aD`mVb62C0CI|FY{Ci5xw_5Nkhu91nTW*@C{ zdyG0T+mQ8iW}+2~9?n|7IAV)A*E}WoXTdn9O^IDzISD0J%cl}|`~cU*rj3A^03ZG= z412u@i^~P71y0qrE}_doPxZip=564tV+H_QwG+WH#H<5N11BEf214vDq1iPow^#$g zgk99B4eYkZ&Po8C*DR6v8wsHNHGGe;UT0DDn`ZN%h# z+cla2L6HLLUg|2L+bfXy2GBVT-4$cJZSA8H_hc}xt^-S5DDA#!7K?Y&QW()R6OmiQ zq1fsv+^U3qyPcvFP64q3pp<~p@hjNLXELX!&o%9iD?&$IyuZmE7P<(QeGsE8c7)5! zu$2!;(lM{W6!&_P5b4^`!A54>p%L223p27%3s1UhqN@H;TouT`JhP~zjf}loxlsb= z7iP_PBt?C@8mYt;zQm!3CgOJU!SH@0`F10)8*-Y__EMc|^i%v=x=3_j-FbX6VLBcU z+JSefj~Bwqe0-N(P}Ei*X2`h&`_@T*fzAj>Tv}-_)k@1)WgJEDMHU+?#ZtKp4~mX@ zWl*C85OBPfG%gNfuGY)7Mhj?`=vf-=V?+U5Lv$_Zg=In2;J9yBRxi-^&XY?!6d-0s zP?&nA&gk9an~uw$&1FeGv1IF{^PUo3>_JoZ5ij05DLCgtArT0RZU8R>Gvks3<9{sL zZT3Rcl>`9GwtFtuZdeB4I$Ma*hqkQ=hAEqnfE2+Q856`#&r_-wIpwKu4i!V%$v#ry z*xj{BKPDqP_LYuRYy^v4DFG~C+ng%`U+9RpXC8kKHbO{LPEp_KpQ^A#nIZ`8jTrd& zXOcR`aaD}j*4vUKP>;uhUji1K0b!NpVHh8HeD%5NrdieLqZD=;ggamc8ZS+X?RP3| zTh(p(LJv;|Mtj16*ZToFO^#crW;{{@wGK6H7@R3P)xL}d5XVkqnj;IN-Mvypd-Yq< ziW{vMR8-L^K|$?f)v8pEA&8oJtHhDKZe^S+OI;=LodEKQNO1-c+&9u0*U>SYU>+aJ zUp?=}h{~)4Gy|PWJjy#vkVg-~Vsbh5?{wEZS(@U~$*XsY|N1MhoD=1Y7ThhEF?Xz! zM9!k_s1TaVji!;24Z}T)M20Csi{GqX%3$EX)^W!f6Wln~w-fd)HV{Vi=^r|YLP|_e zOw>qc>HH#6aBQAtJtUt;cLy4o~dbz_&Ul&9qaJ4Z%gp>9VA=I`t7&B3 z$f)55h*Cm7c0pp%CQNsylAeOucRpg)#jz>_^wKLx^@A-;@66M|V5B@H@qommCUf8!Mse((h|Pb#>MIs0qR?T`tCa z+I9%z!7nOEIXa!0fcOHOK z-z%V_O5$U>($=%8(IE8Gw~qHx#0>WjLW6Eph87`j zK>TxaMjTVRmyZFu7z9aTJTn^pO%O?T<0Ug(wHJ=1MPO9Ma)7H zLv&iFp6coJC=soiu+~Kgv0!^@UK_tEU3i++xY!-5lp9@wXbi+uv(<(p6{u)Q>~$Oo z-&@G)07(}FhZM}iuT82}m7hmYndDc81fx%BKrR;#qdlt*_A}Ynebb_$klm;Vf0}mHW{oCTVbTPyASM}nWEm{Sp?w*L(x~)it-JFNm-IXbUdNxo@%152Q9JQ zaY|@=9T*cIb-#FEgk73=BH4n(z z!B-MrR#l80Ufc3wv~_X`-Xu^473>7!?6I2kLl~l)VLZ(aNv*S+9Za$hH*-Ky5lu5v zbs!mvpOkUCZRjG8sjjF(URoHZPK|$vKQm_Lr!Jg2OXTdV)topb)m#s%$b5n|cyoA_ zj9T&})RF^iaB#+lbuY08p{GnNv8P5*GibJl)}T2pL4JlHHa08Og3~QQ-A&v_+3>db zc(EzHkPr>+q=)-|@Z?N^x~{IkyPUCMa}-rvjX&mNE`>Ep*<6;R$6&q*Y<&GI2o8*R zgjW9@U>msTqPxMYmSwIln|Kv1Sw3U---2sC(B;J?D1i#={53; z*gxv0?GWqlC9$8&JNur?&L|{HECeq!9*ya&ylf73c0%KU@5mXF1>!UiDk1fX0o@jy zXX%CZgNML%vxpGgQk(boT+h;xi^f5s3F&S^4=HXD3J<*iJm!Pjz`V_3b5qfCSH~Hh z0)wf9V1RwP2r#TEBW(1#1?xRl&g80PP#aHL8E}kRDBSm^v-OiC zUM{DS7S&)yh!PM5_8cNK7lLsw*A1?xa%26}hG2KFA2!$>-UtVv;>aEH2;x=qS`#rm z@HgbmN+A#-WU`SKfgfQ;N~|@RYSD|dcxvw)dpd+$R$*^;efJKTkEy7+d-=> zrZ}cfWmXsjR71sY+Oy>FeN|JBAu@r+$@;gwL$w?4AbEPRZ)PIq@@A$Sz@~W?f*atlYK$fQCwXZBXD2t|t@Pp?ukd~)wR^TFtS03!wHqeBa@f4bl^PkQ zZ_ODazOXC-;VXq~mtgn?HJPxkty_iNMXRDY;VAvxR_ztHLmyM``zlc%c#3 z$QU@fjT7_rWA(;~dWWxx<54W+snD*%8>}Bk^o^-{d#+J1N;0}!4j(=@1iLuM6p!hm z6+)IwJ2&pAAm}x~Fm0-glNm^b^5e#pooy7`c5;14QW!%snJifB*4;u+4R9mpS3dk1 z1t2sso^uVoNOi-5fHeWFRphBC;kLt}u`y>wh&DlWQqNnD=PWn*j3#_`cpz6m*f+lo zDnZD4$|6r#V+`;LE?%5FLJ0T=sEdfn#<_JimlR*5UVYV6iVOGCFc*Lc6Gy_Fm_Yg@ z!FiNAwZWc+!6YipPN5lLIV;O%MxczF#g<*=l?B)+*|^0CFy|PC>1OBT^`sK?ad!)| z`I-FAIlMgv748U}vnu?3paAgqp!k5j`>6^L(FsJ(fJYj8V+<-Gp4F`l6byiYuh25R zuPv%349Q$r4;$d9D7=Lw6NkwR-7y#3${6gWuaA|ThKCgqgJl!QI?YiRNqkDk6QQFr zq_Z(uzzzWD3V?m1ZUq5&G&5jm--M4bYYd=Z2>#u5OnaSFi%|JDnWk@{Ja61+(J2JQ zX^?$}ZL4wX3lU+t*IhB9+Ps*jW9R$^g-SDJFwzz)UI;E)4|0(}o`EXES+gQub11WW z!Di*s>HSyYGMNLFj1I`_x>F!IXEt(aCb{#;BMUF^7uw=z>K%C?LZyNi9 zPht<46Az{he=6nZck#TD_+L5~6qqk9Mp2neI;4(_(}~CJ2sY`sXbQEBY4# z9i)r!)^%e?;!P;PIg9z%d_HWPln-=7*Uj*6m5)lR;%^C$hH)saw3lTKnNwJ3fng*X zBXS}WAB{cZBS1}^Uz9XeAE0t@D3CJm5Zdf;nig29E}?->Pbm%<4lA~h7O9r_M3@7V zhlFZz>dDq;hJ8Cth|?khqY2F@W}|IzAk^JMKEo=$C0Ae-1`=&^2f|@E3?qXjJO&J3 z9hr(hL3b{a%N*hvxxhgxMld>}Xh#+dSWi(YYtV~pxp(@& z&N=s9UBw$9{4O{WEFmhV!FFX9xZn~M5E5N^73&eAObfG0SY3G<1*v4O?odVSp0 zb}}Tq?b{2ZPJvqB{tHx(9lcZnzLi23^d`MTK_CT3m&ElHL}1XTQlJ%JQztNazGJ9Rr@gjyx-MUG2qRgl zX%^R3<`mN~GeKp2Fo!xnZxs2d)Fo=;su#)qn8)VqP9c?Tsk}04kBntvB_%v^!A91RMKE7* zjAuGMGukv_|5t>0zLgso(3XJwX)fRFSOqjTsa{E~}BbVIwVV<4Qd1-w4G;x~ckM6mN-e zu?!|tOTs$E@DJ;U3|@aa8k+c(HRpA0FZbsG0 zvwu4_ZsSDIHLb&si#awhVZh<)V``c$0}yUJOFfq3e)Y8&`)W}?bjW^wSpy0Ta@=WV4S zCfkPZv{+eKTTUe-awBn~dqS9#h@5UsGEM}G(2XMN&(1h)^V|;IWV(Q&GBgng`zKSy;=m6}7SaiFP zCn9<;X~3}ry}+YjomI;T_^5td2_Bu`bZ@hvvStCrbsz(${(QxO#yorXdYT$S?y;y5j&RHxP^&I$dXZIo2k%pFz(^$XBo=)2%ggR)fZ9G1xdi140Ioqz`R8d>CvL=P%Ka_U8N-A*Mbj&**;e zWwfYbCcIwn#eq&)Kd}H5%*;XsI&w;`MO6xFtf`(j=%y|TYMm01jeCgz`9i(n?wWFV zouIg6njxQtIW|m4sUG4(_C-l_`94hl_Go%d?~E(PdXh`zp=liXcrGq_V-& z&RUxEFy?73c52cTDU5bEqEi_)v~U80q3YXbt@|(ZWe&F$6!rQ2bV|~#V1g$R>gTy= zSB9t#O+h2)9p7>)5)%#N8QUAyXAq9?@g-F#?N2folRz60D_LOUaAFC9S&m6;MKbO& z2HB6NF8n)dLg->UT|o3JiaKxidF6H4Hxficn*ruu{CgQCdQnjZC=BHS1_C7 zBJOFd4VtKK_OwH@`m=di4{Kv_t^sCDte+v(XQU2M(v_zr-2JXH=TU29siD4;&aWwh z4z0=-92x!OCnKD^)AIJ$sf$F@24htlGIo%stIpSA{tdNDY2eSy~*VY z-5Q>STO}&IOVwJ9TyxQ~!F{pXVX3DusePUs_NsxzPFiutqv`#`wW#2hf!39V>40u5 zB0zhw*;0ME(&@+Eg34n8#Nc#W{H4a!cMd=#GShChoTH?q3Z1+>F>or}r>7#&+6n7( zvac5<^+B=j7y%C>(c4TjGM4o?*JnAzDeWWT*Td|Y2LegEw3sfjVJ*k%reQ>e!8C=_ zUvn{=tR1W2``Z=a`F59R!pgn!D?P0!Ce3kC<$qmYA_-$+JP^1w=~SfC&s*rVooY8K zn(LGGl?zxX*0P6IVZ%73u-X$AF3z?&7}k}A<>nTQ8yPp8Ei zvrHA|8!1m^(jAEnHe`eO2#|{Vx|1#jeW=Fhq2Nq>k?aTgm~<1A<(vd&DiGgTcZF#~ z9gLpHjdi+#v5R3zWQ4a{jMRtE`oA=8h<@q617{ySS~;1IrdrOU?tTqVXx%LAtu;#C z(E{EkaJ9RD%f5-|&Ol*6Rs!Lm13Jmr0TwRcn%Q%sF;t_KDJoR)ETpZOBepELnj7BP zf<8+dQA;ufeQC63hN7|Ma)3kSG(w4Bq>hCkAVxYO;H=(@W|sv55hx*)3jFIz`;+vb~V;)W_(E4t?hB>AIip+SPO9G;W)8Ihuu8Ftv(&W z7$-m~KuCg>*oNhDOX5)3GT-d=z;$u7qloyOL_=oEA6rlyjWBqTO@Iu5nyCF8+>9XeWUTmb$*AUavLY$4oL0s|#1qOz+M^8Fw z5@bjztU!#{3G&7K$V$AxV`Sje;%a2xNwGyLN(|WOw1{l)_X_L_h-;zFpj&2V7OO4e znL*fX&emk!8oPS#6ioe65k&LGC4hgZ`#J(QHZi?dmHf(;7rTVf5i8b6bTg3Nsyj5| zhso;S^+g*_b`GrqyB!QHun0<>X3YJ-gms(5H$HT^Mwe={#-BzfMYKb9q*PlyT7o14 zW+E{0`aarDyQ_;@1+*D5!`ub}%1->zkl_g&5?42bQZXnn zZm}jq%O>nZ27jq7bIHZ}3ABjT-Csg!b=^H0L-QyeHO%66MO@8RxmjIB&;p~6A@8X{ z=)IgWv93bmK&&DTv5^!9yHso|N;MXUZ`W zfKzos(@wM}KOXZU>*#=Du$OCSZ~;hNz^b#To5e;fe|dALks+(dW>$R)6dY_zWu^eF zw!H;NyIbKDoEuEf45F!TfQzqnD)3`Q8_=ygha~g_`xH~>g1DGazuLGifgfAzr~$xs z#VFp%SVGvGiyeqg9%{w`N@KouybB}d(J(}DKaWGGQZq8{RJX(EVmOxBKCrBGV9dlJ z(}oQRAOet4Dp%U#3jr2l0n%#t9>tjVY>U*#kKw=vJwV~I0gO<7fH0!gC7^CQxn2(M znkwwDr#P`|4)Uils&gX-{_VET&hv$qaVehyWN3y|hul39k8$R~Nt}=*C)?_j0m}rz zLkD3|@@8BTG8R>%-=zgFWFWugTl-VY@f;q6%EMW@mA~=I9SBz~291`L> z;cc!hz$nY;1c-$N7NVed9sW*IP2yvyZj!j7<@*fXDmX7*mM6OYUMC9RDQ-Rndie>r0NZN_k6@9ZR?OdMcU!*xA9Kiul%-`{*a4?0lY2(u;pUoJ8*wf)k0-4K+0y^A!;fn@B)IkbmuZLy>z4f zJ31oTzc?}yg`*oLbHj{y_Os|c6gyOdLC&WkMloUue$+wYdORD~Qk)%B91eMvV^pTO z_S?u4957#ulxN-cy$KG?#&k>LDB0q0UsJhN5Yqs1w2;8}usIn1r~-2jSy@w}m74^i z`9%>m%9Rl1N(NKInQH*-!1=Jj!BxFE9G26Q$&DGij_F4E*uK)Kg^EQ%Vc;PKB-TP+ zPp);iE)=QbTU(xwAA6T;w&DUFV3A_X@QH=eA}G$hw{8G-w^&_RLN7N^AfXTg{UjE)`KV^QY01|q2LI@PYU zo>6K_Xp}j)xrhF%gvd=fd5+S^AP7KMi>lj!=AMeA0NREe4sfr0bSy7xg~14S-)bp#D8F_z*Qgf9dI;VUbY zt@Af7)Rg7lS*>%**Ng3v^|66F35Z}{ks{PxpjZLj@nWft@C#7&fUpxGs1dal2PcUP zq;Y>jwh_!{PE}xK2>*{p!%?JVNidt3#F#pvsw{$(ZqzKK3a1X>oV;)&BfN046~x97 zS3lE27nn=70o=D9;x!Z8#G?&%;P~w39F$xxPN6tuwGJ&2BW_7#mq0~` zQ2;k0#U%+!fh)B^+z!R))(wuiBLeyivzf$2L`9lKkB7uLjA_`KC}hF<5154EdRudY zl{N7Ki2xjsO8|vhjHVAmw1JSgXZT|rp*c_3e_bTL;?;u|T36FT z>)a08N-D@j$%fgRg|R@0*IX!ql&UVB!kI9UgBER~9=#ozO^Y^lk&4&vgt)jeO^lgp zCcx;Q5hcc*#uC*sbqs$aRMHinIUUx4hKp*%3*c-plrok!F>)ica`D)mOX2YC9Z>5y zr*;(TB@bx04*-^qTug*UR&kB_a5Rn{+Tq9{M+ph);%S^z`pj6MuZmim-6JKl)ecEU zs-VCv*T6?FQ~Vxt;sEfWj5NR*d8Q4&1Y9YCG!bWG>0lFL!A+Kga^TUO87e=?IO13x zZ|0o7ogo({B~;7An5;4g;6>rY;kFshEhxpfj|ju+Fqnpqjw)Y_tzAEA-eN-`^wJcT z88seF%X;GUrqz~2|ctCb{#likW5EP3RAH|`LmNxmKSF(#=o2xOLPRz5ezmKg3aF5 zeidz;sGiParFnR~LfBy+V@Ue|t*l>@60sqw)rxzSDwLV3OX9@e?VET+x3_qMg{(%C ztke6PVFO-jwY?KFiisz3EY>oh zIfF5Y0&G^Z?;(bq70S%AP_Vwy`M|?_3P#>hi_cXl;5FC3f51D^lD0`gXsD&da+`e}6s-$9VwQ=Q@X$RTdRlj5j zIOLwW3?_OeR^IoT8yQf{b53&A1CIR2Fwv-~mI!{P8zo2#ER$B2I`#+#HfjL(g2_yY z=m{vR*M(wW)L7FjzJ`%G*&QY2w{eR$&PcHMz`4exV`i)JgiJv#V|rm2))Ce<63v!y z-Ui;}fFjIBHH_k-ecyK}l+EBC z^$jab_%Eu6i7vO%wQ;=~wue#FfT;qO(}I26iWK)i=0P*t)bX5_>+Pms#`_TL!g>l+ zFt<5udS`pp5uyNy>(!8u=!|3rwvofaeOTcZ=||tk*i@KSCE=m+j=Zrg3xd>kOUtf6J#Lj@r+=j=EM6e z5I0w)6&>3PPtsu^BT*d$b15`H#~zt3((L$fveX}P9Cwr zHaVAzIT}@lNs<{qx!RCO!R2F#8fj{`p4$QTNgFL|P}4N*uowXs(0&6iT!OOAbkq|Q z0?!CW5Cz(1$CLL5Vs}+jf;_W65^HtfX2lo@jt< zToQLq;5x|(TmPN!4;>Q=rQHr4!)J4oaoWrp1x=Ncls!N%jPgfOfsb6qe)J6_Xt`CZ zE_A_ax_Mz#Ki<%UPBk8E=|~NIBh)%a-YFd~!(~d$UKQY_sywCSD&$6>zGww%Ffx^@ zkzwb;M_L<~4QdP496xd6aw*LB+#ZQ_XH~PsjaVeiC?~+QCunnE2)7~))@9?BUF1u| zEQ=Dk(@XQts!V?4tU;n8z?^uF+aNVZFfTl(&zc-4d>|M}#S<+Hv^T>Buh=M%B2Xdr zxeb7_F{d@qdh_0-zz31lUH9CnjYBk*Z0@B#0V)T!I#4OG&Pu^eqql6UWwjssU0D>{ ze=qP%-r>j@SX`kE zvH>U)i>6%>VX|c}vZ=Fj%++K$+6T|j#sa9dt714eGo|)X=s%h$jaD&0xfR9Ta&RIe zHj^)aQ>G@EHmm{eE6JdZyD^^p>_O4*ow`21XLO|d)Nuwv-BW)!2Oe}t?t{{UD?EJ? z#nt9c`h{69@}Y1e;|PoTY?sv${}TIlUN0*Xp6~3}GLs8qF-yy~4ZBNTmyu&ei)5~0 z*xB~foP|@O3d|d-bR&b^EEp9=7{CieZB;vrbsr!qLai*AfZw)PFec*qht`}NjygzR z;|Lo*9_;>37|xQhbc4tG>Pku7+iFK03Y_Kq2r#Ny=&C~4X>o>_YU9QrJ{x6=(ba>+ z`8HIs{gnkz+`ECKqPbCW2^o|^*bi`(G9>sf{8F^w3a7N(`Kud%F=pQm{;H!hZ&j8$ z;xubK3tB8zxV|Y)iVm4Xf|Ix1GP{%b(Ljqfxw{12G5GzqR9UjOkYO;%D7#q=0wsxD zHhLx=Rb>&A9}Q8w9R|hg)P{37Ub1;iOK`+~-Z$M1bf!kPbiR+xf{1Y%4}!YwOF(bn zL9dCksj-xV`D!?TU`7x{9XA2U=>wx=*tKT`Eis-I=v~Ni(?rYCK*JVdWTxtbRsIqnPG7Wx+NJ^FEVykos5hPZ9sp3_@ECV-nDYpY;z!<&d zj$CfEgU=eX<2ft$gZ)d;Eip!f%B>B)1&v9AQW*Cg^q?76WzMEsx+3q`rMQxziR;h> zCzdD6yjbFiup6<|`=bHQZ+t<9PBpHw-b#cOM_(gxK4w>s4hcUZM%YhOz|&l*=g6>G z2hyie_KYahWQaoslS%RE7_ZP}QyTCY0>)b_QV>ppOuijWmB^?AeA;fCb0QFAEI6<3QLp=)9e zvw-|Jnx*9mw(J0&tZ7A7x?&GRo{wq7wU}N^%Gq%{lBSj@Xl5PAW4j}GTOPWUTRh?@=!4<#_-T& zF5x*pZ)r-e>$a|eZ*haK3hV}Ozh%w1!?7pK5nfO&>1s)*yf7eIi`Ati8+^lyQhK!x z9me1xy8QAh-2X!p<%%XWRH2Dpw?xAgqOhtErqR3{RByDrideTxu=8{gNAmmU_nCbQ zuZg>4{i}g_W3bH5Y&^a(@iS(rZx6G(cnzz?o%5-+W=v5ph9{?@T5%oY&3E=K;-AiQg0w+2glgFHo`-%@GInCrKRDM$jK&vINU8|{v8p$5a?wgVB7 zJ1ELW*GwPSwR5^yoGK=_-GG3kusY^J2eZN8i{ecXQQ}uYp|lMk@wSu-N63~uQ%X#{ zpPFZ&Kkuh8br?GUr6QsBYm{*SvuH5slro(f{iWRyDZ_i8+D|X0jaFAw-*WfB?hwc+ zsstdg#i(Kl_?tC*$D=kvqaNT&m8pT>*MzDamEdwaFiDZ=&#ii~zFZ$5?sfzgQRs1S z1;9AiPPP90O4XcX9FhJ((U|ajtWmJEOB~`91f@eq0Yl$d!MHWHjmtT+P+&!{zMx*ys)%Me1HV_P{^2ge!khJ;Jp z;M726IqT@kK%uast~hK?!r#)_KXlg@>?(P}8f%q$(z^E=#ww651{>F8s>x4u*UrfN z_lufd7@fF;`9JYxTWl@=@4foBKiBkvXx{(P=4M`O(}S8y*UTUGWm}lP-Ionz^>w}0 z!RMH*x}ri|v+U`Ds1SB^hgSJTP0f5YUwnzJjk4jacK2vq41n2hx}pNJ57nMfi`nmY zMFnQBaz*pZ?sP>3W~W`zJhL2Vm-+p+8`RvFHOrA)5Y2G}{054c{So)MxvVw#kn8(k zvhRb*z7MkRg6sQW*!OR0pWk+UAL4k~;RVs5{n~+FfJ0$NAJGmz>N+~Y?0v3ihS^Kp zh>q}c-|LEInDrw#awsu^BjE_{(<|{Qe|;`t{?oo}3-h1zWm}oQbeHWFM{y{t|8HqK z95QCNX)_!QX4w;Jg&p0jb2+W4+y&;p?#mK)f$d(Tb#Qu^{iG{8@@dVorwgLQN+mlw z$d3NRb##awea07sGa1%-kN9P~g!!v|*%sz^`LeCdzt5K?mYn_1Y8@;lvoCT*hhL^y z_H;pXI2`DYXqD%?Rt2`Y(--}=X7BbzVMozRZOH|i%HA=5i7(s2{Jbwq%#M9Ml6^+= z%ucwX!c#QMo>G9%mfdzx-=nDviuuR*vMtO%-j{7<{%yW2F;MnDqIIwh%--UP4j=)+rs?&ec4v#pSH*Lhqj3s zv;U83JIt8b2WvA-?_ru{PboA0L+#)q*Q&r)5BEh^YW8Yhh=TlPhFY4%;d=;NB@6!368QrGATO;L1E zvrE1xTs^MTqurni9QuoW5r_URU-W01{Xf2lvw4CWXMwZ1(HC(xf8&eXEZjH?oXrpU zBF^TBFA8UKhaQ2=pUp4%*>oBD?SAO*)vP~!2@L-iHhnf6dTfa~FF*$?=8#O#CJgp17bilJ|2KjUlh9{Dqs zcyc%bf4OgB_H}*)%)ZqX-NYA2LU%R`vupq!0g|-ao&_1XW|v&I2T+;N0?o8 zMFnP`?TU^tODKkMGW!)@i`fUcK^2(&lq))t9A^UY=QusYImE1gGYZV|?EnGD?9<$! z3e4_vMTeN>+%X$w|H9W|maC6i%znn#;zoSa7je#8+?)^bSiRC0@j!pl7jb32>WeN= z0CBMg6wE%<6&+%hkOo6#_BFm1FY`Nn5%2XM`JxaG-KT&0drbv%VgBEIS%L$^c3*T| zCkV{w4*Rifno8Hq?|Fs&8<3NG!XZU$IIInUoG|+WS5$b5X5ZzDn0=2cnrHU=^n+Nt zD>OUeixNZ74xa8hn&anw(-&p6;$Sa`4l?^H*Xjs6;$T4;GkcG#b&y#uR0{o^T&7um z?q#l{!~C4@C_$F)*4lertC{~#*T%O>uv#XxwqGMR=+C*14qmJsu|up$xNID>?`YiR(W$$PhE;0K)=K7vvc8}}m zF#Gl$B@WnvcJOzuqnXcW_N%_=8QSNn>w6|S$iz8#g?8{}*U`aGB>F!1?^<-R>-!)- zSN28W0tvwn+axs3nK&x6a@WojH`>~s9gy8Gs-d!vp>E*FJ5J91LOFNW_M{K3Cx9d`AfaC)v?K zc66WX=t#1o1Qz!5TKgle)y%gv`+aU|GfmCj?u){yy;EE9n-@gaCp)@6+0pf3N0(|x z*SQhhu&CMFebK*Y_TPNbPwL?Aa)Z1f?E8lj9bKR7==x+wi9znvj-Ks4e=yn6L3VVf z8_~gVM4aWir*^lV;79rqok$My#aiTd>0ok~4sw@HXOH{05}&)CpYv0>o}c64z@hk1 zVgzS+PCl$7_?Wx8Gq2LV->m5cQR1QaTdn;$*J}1ct?gHCmQ%Uabu`PV@EaFIv*BK{ z&vke7PF?q3)l|S4^S|TEwlIIUFWbuedwtmu^Y8a%+nE2bFB@il`<-@bz%}j-CmC^Y zf2|FHGPta^1LV6zv+ODb7_y^}x{l_U{e{=q&t4GS@Hx%0LllKW`jB?;$F8FSv;X9Z zW|;lDD>}&R4)?hkX7{?HgUm*5b_EXRyL{23H2XMTv`w>@`=W8p`eiAEv-z}+kK>h> zTL<$5Kd5oda=a<;J9p(`*J}3rHG91;da-8xk|)kJJBp2nBkA(_gWB;)_pO7;Zyo%K z{*^15GLLz!@(S0{3=hS3d{MZJb^TLpUTo#Rm6$3A>suX6wn_l;+f+9222JI@GQY6b zjx3b{&xZFnIm0}&muow))+aUl6kl|mW}oSc!UbU8zwQP#cQNy$+U&yU$i?iP1C_F{ zuT`yoi)(k{66Tw}Yzyzi!RV_KUh-`L*WpH^iTUVl|5wsZP&V?zw?5uhOcpb&ojGE+ktF9qFHv8LdkOk zMK^-EiSh?8)E(wzHA%wf91=Dng5h8n`C~Q;?UT^dmb1bIS%;q+Aw9i{!O3H zPd$U1eE1(Vd$rQaSY`MCGXL%IMXQ=U>5HDD*;o0ZpVREye9=2J`#*irZ)o;CzUcj$ z{je|kd(D2q7k#hJ{^6Qps9QDrC|@+B*(dm-aHYOAZ%eivvMF|dRI}Imq8ZH=e9=vs zz1Ipoam@nu_>-|Ne^ zGJmZv8)AOimu+Ky#+MB<{|sL?$^60_?3l1}cO@2y1O8FhaPDH}pZR**@WSZO#fzH% zomkn&H2;^evcJ;&r($K_(fosSAkyCtX#R&|Wlz+6E>WitP?+ovg=f1v-Tu?=NI+Fr^S|fI z5=i!{{_RDsP7*gBRvl~sPrRY~BxmmasDc$%i* zLGRY=&Ay1)TYXWu9baCvC7(RSF~8zH&v}eaz)u8)y<47m;{%f|Q5d!y*6v3%H6TXw zW4>$)^E-UmR_3qvWkbwA)t7B!ewQyBX1@F^&NW37mV;|(L+lT;6WR_On;n{ES1C*! zb~Noenqzj%b#yq{kzQ=SXdl-OMqH~yY;~0{n%3+gU*x;6xmEpBQ&U-Y=3BmO3-fJX zww3v3`LZGAxBQsxAN?ht9IgLaO|hKJe$5pXnEi$;nrHUkT~Xm8{mz3mP2t_$t+l`I zS{({kfusE%Kk7@E|L?wR3-b^6Wm}ow>dS_h|9)S#jrm9VvSH?bz?V%jKlWTZN&w*7 z64!+Teug$off%gvELUZY+1<~!U1PC!-Db1%nxg1an&kjemh|a5wq2UasbT&aU$%w$ z>wMW(=BItx5c4y>Y#Z};__D-F;y7;5I#>o~U*d`qQf;;>yDD?czQ`3FW|rTF-nU&U z|L+m4{o}4x!T-_b*!q=PMOKRWSNpOp%-`wDwle>EUpB=2Py4cM%)ix_4Kx3%&$Hve zDY`ctTg1WriZ;aZG5Z8<2gw|>m%5^PX4!j+{EmIU-}ODm?BiWW1!mbH7Ma-tz8143 zS2V}$i(FCR6`FmmFZyZCzTFpvi@VP=2F6&+;uTdwHvWArmW=stIt zS5x*YF^-eu)orUM7JW1O!>;cm$q^*($UR#7{hG?T zW&VS{Yzy-r@?~3@|FAC`V*XxVwvG8Ko^NNC_EvBlAJ=v`qRf7mHpAg#c8e>TXO^9( z98vcDdDr(Gvk!3{6`1{AS2V}0?>lkt+4px`-v=M49sIECNV$-HUq7j}AL^SjMkpjRA$HgoG;tL{JbyQ%KQz!Y>4@rec3kV-{;E`Zw<$>taWe_ znSFyRI>hWunAT%bq01-gj~^i#elxj;817bszXLBBL_+i3^)VNL0ihCXUOq~+nH=--77O18Yj z)}ZH*us+>}+^c(cD5y`@EA&7Twx>^&4{LjVZ%F%LzjQpZ(d|#@cW%{`&NAqI;{{s& zdzyydf2o$gO4Fax^sWu6AC8aX;djIF&?^TWX3$H!7$M1*zo@sv{&~a^cf3$(; zyg5&VB|jc!kK*>D^jclbS8=W{eE5C32nfIbU~PYwrh~SB zsJ5dOeb}C+^jY8Es_jo^e7{$Fn$y$CO8EV7zBH_#&-h+gf4kOuN=AKJ<+HytZBJAF zjc(6%xk<+#t|$EkaQ(yY_uHPn7B;#)&()9X_<5c=54xw|`3=9{Z+rT**y#4Wm;X!0 z&wD_4KnEX$Z{hd*ZBMTt8{MAce6+&Z$7)J1KH>MmdLevfyDa$JZ~H5C9B2Cdto9sN zLHj?XDLuJ_-wW%7?;YE59nQ4EkCHZ&;6b0`W(-Bi?kT z?b{jnQNQ2MYEO?JU)27;qA5LqgyW?fkIU|`e|fv6^r>*U{{Asd!}j#lP|?5Bs{-4v zw?17-(6a^mf8;A{&-8S`?}y);)^YLgVf(N?=M#RH-&t>cI;7xt=rDxi3j06b>wh-b z_g>@gRiEoY=PdO4a!Xo`rpxec%gphVoe{fY1aB=wF~Q?)c)z{;!gcdmlpT8`oBBi_nqJG_!3XJp;?er|$7=cm8&v;d?I-Iy!EmC7 z=zQ*As_p5gBdkw90RKblKVDOMp$O||)w@*Nh4tz2<5%^*d_dDb*7RMP(pN*+p6$YV zbR`kiXLqHL#bWcEA|NC40Azk-=$KR_y*W;VIPT$g$?h(TE$*T8g9amUC zJg>dZA00!`t-+VHU-~o%`#<06ujzRE9si*9r?mfln$jc0y#CHwpR9IaeU6)sA>OF{ zzBQx&LF;Gr`<{&cS^kIm_dnJ2qZ#$XdUPSO?M^#Ww)@+R_H;4vR+SggKLkBFyj{y5 zyEj}p`}=#eoPVcNiTMqxf0urr zt$*W`?SW1cuK5xBo30DO{-3S&e?n6_L}2}2)AH|VN>2-S>F<|m`YKH~yMOvKc=vVo z%XCIS{|4cB-l6qapB@XopylhWKdk+XYf8Tf$MiSd9_-8b-ud1>T%RADwk7mj@TUju zZ~9Bfs{baf*Q@?ZwI1vL)@=9w2dz(+4ZHT)e)np6lcwSL&vyOG^t=6zXN%TKd?*Hh1`^C3w`fwfR z(>49NmOoT~e^!5gQPW@3^nIF!qdCR`}zkwcftCxoadGM@F?wv>&SiLzHwiI?xNq+b9=X@ z_h|YD8RvP>`n(t6z4^WjcwE+bAJg=iIu61)`s3f8F}|?<6SN-df4BaAbVmDCEq|7# zuhR4lnm%7sdVLGmljUJMH~ydj-ye>f?*QLBzF!}iw+*@PyhnUTcy73EJZHh@qRsx^ zKP%k4T*v=9O@Ck0lbYV4X;srzO(!(nrD-^y&F-J$eUXl5(D4@ZTywt<>-xM@(~4`eaQXrRn1}<@tEH{tnlN`_1qEy}}8eFRtreoe%ek>&|g;ojER!o8#iRIWCTy ziqs^oe$UhUAmuVd%b^I&*QIZ+R*g5nuh0z@P+j_&d=$1+3t-Q?Z2w@#y2$G zsrB}1xBg@I$oyp<~ndcK6IY8f3}Y6#hSiS)7NK=m-ESL7i>>-K-cG(rYAMM zP1CS`R=wLZ>My*`_VDwX{+_1Xm#}}A1d2)30hd z9h`>kSsu2_8gF>N>6De{?5}j6cu#rXe=uYGXS=^&R(SIXO<$<#J2ZWkrq9=ufZjh^8Fpe*MjHavmHf=W%}@ALsksXE@(^ zZO3)|n*JWr^Y(H5{RK_`m!@}X%6;L!abLJ^+!yX!xZda6_c`CsoTd5FaqjdDb|tR9 z#in%hN>{hzTE43F_Ac6b2le+6O~dsJ`)B)~)%y4M_ThZ*(Rux~I#;1PU#{mjR&9%i z>3W9kKc?;ftVjEc&vN@WJkyShUVy{#_xk>N+kalyVfjWoj+Um|G@a9QNYfwC^b$=U zt?9pOKNsomujub@Y8tLTzsq_bY1$f`|M%#+JVMjYYQO)aDaU!Y{^mG24~~=b;5a!C zj+67?I6061Y~$s6{rD!W7x#tx_CnpqJ2hR?^tqZYXnKpLyEVOD(=kn-qAAY-&q=sn z=lc7%>Nq*SaQ@+Vv+BQ0`w8oZ^W%CQ)cS+2*SoacpKJOFO+Tw?`29iahy5N@xcg2` z`JF5Dclf=q{iC!V>pxh3|M#H3Z)A-BsMc#~`VviFrRlRYrC0ZGJS-2}aXw-Fzb@L6 z_m^z?Pj#E_YS{D-_4mg#eX*vm(e%b+w%(m9HhqEO1+UZ8mim96RL1Z^e&?kAett&% z_iFhcYWi_aKb=wkF*?sDYC56m&W!orr|a}bWjiz8Q{IzszPq&EeoddL>5`^l{l8nV zCI6!7w={iFM*ZjM-(RNbn>2m9reXirYWbX|H*0zc=1*79G`-;Cf8j`ty2kM(!!@9Q*OZ~euS zwujehx}yF5LPq}=wr%|zPS}+7IKOZ_gVulJ@$~-h%^1%&wEnj=-Kpc^_`>mgRqJK7 zTW|fJ)&Ae6Dc9$29sftPoa4AhfB(Lw;rG9>W=p=M>31}}D5L%t_3v!=c&&GPpY@-q z^%xN3TK!$fXkXUyx~6NIW_^$6;rDc$j3(0S{PbJ@-}QWcN7L8qcYasXXKVUOO>fck zq^4JBTF~?&O&_OexIgFmdz{ZpbbRZb&m(l*9;fNQ>bd3qa9yqs)`jcFb?3T0NBjAj zrUx`FX!=A=FVi$!-}8MuoZoNg_y?UI?*r$_bz#3;7xv42;kt$E6}~?V9`qmj&hY*D zfc`$;+y8}*ljG-n{;<#a?9zAlNzbw~WgHxa;|b^gSgptU)B2mia@Je_ppNH|ri>W$ zJpKJlO>3Hl-#g#iFZLM!uj_jLi>3_P!-zfMd|lj|AG3eS-)2*Wq1mD3!&+|t>i-?m za{hf@e;?7**R;7o>tFM1+m4a^PHDfN($xOd|2t^?M?A;24f}sxM*pi?zpd%pg7$tS zHn*&Q&uX{c`j687e@IiV&kJ?@PuFseBm5rM>&vI@U*4+idaZB2^~bc|8#VoqreDzX z?V8@LX<5_Lnug;&+x>Ao@9uLvhxL3eY5Lw^{Wy>3Ykyn^&hvxXj`Mo8{(haNbxl__ z4cFs*`#$IM4IS^G^Wk~qytoeRm+QcOx$a!2aD8r5`1Na=KK{A32H{&+pYZTWTA!i5 zTKb#ta87^U-`eMO+*#xQw5|`M91TCu&TvN4NK*z~3g^%0LJYgJ<@vS-gZ6~=88PP@ zT94sw7@8)m|9P#)`izM)`hu{g{XJ;?XKMd9Ys$zxuhQR)rt@t59e(wEZ@;GF&Km#C zx{j~WGz>oz&iDNpa~ya&d2xL3>X({x7TD%`H=9hx$p1M6M7%YOIf zm)Ml?4~Dh;eVX2*=_R{$rZ2VWyrx^U{B4@PQ`4vIvGty=DgE=`tnKLU^S+ncdd`35 z9rics@^U2zZq+s`kxFm&0y3Fz)X2NBixezz*woI-x#Ts zaV?qh{bW=}2J~af0D6qbM)=PFWrXjHlf_V4j0VLxQ;hb*s5*?B!t-laBlhp*ty3%Q z(n553tKGEeQReE6cIEQr`r73SYt`D~ldFr7`E|6^IvQQRc&d(;Hf=ZUUyfIrt!ks* z@uP^pH7m7}G|=2?tsPxntyl4HyK)l$F5w6M)>tgHOVQ<(qs66WX{Ay;x`?*?g-*-m zV&!DHvf3_UptVYLdAZ$awlD;n{Ad}~r3?8UdNX4ytyIfs+Q3)v&*kRR_A?7DG%Yt) zRw{M;aj~+nwp=VVOZDZ7bZLIBt}WCt5cj)UUy@#J)rEy--iKTmQiYHpBD>w4BKUn9+0u=>zdUw*Qj0XL`p)wj$eIqV4$m za{T_+?|i4h_P0rA_>bu?X@9KG_O@0OO(OGM_#fL3%Vh8$)2;u_{^l6jeyc5xo{m(8 z$oAKMul)nl=X}5Y&3|<`{22*2`A%&7fAA#xC#Dw${TB0*3Y#n5KDtu>s_6_n)?&_Mi~bg}F5Z6T>GlsyfAg7IQ4_Xf z=?jpFx4-0#_Ag8y#)_Kq`z)5{R@!s@hqOIYo&i0gT}f6Of7_0Zo(&i6JK9?|DCV z=d;&6iIcmXncqC`*Yo{8vwI3OG=JUxN!9*I)jlq-c>CYR+CQh-Kd0Kq>Erh=#M+-$ z?N6)r2k|_741{lR{WAVZMfLpmJ~euhH`5i`_b!q9c1D4FF!pX8ZJLA z+b_#g=TpyLpZ|&{;r4H+_HU^6Wj!&~gKnqKZ^zmXoEi|610)z6dY1Mei6ZWVF9~P%6%s$?1lUc>B?e_7~hJ+kawrs4*_%?Wa`x zIR8KOIobY0Ux>EQclvy*Y9Ad1aruu@BfhTkas6Dk)AtJ*?O(h`dYY4UO)1au_Ll(G zx)-Kw-6z|(Vhv)qf**3F;ns|ud`PvY0dQQ8|IgrG+l|(13Xf^y_dh1vfAV7>2p#e9 zLyr=deVCoj!@>{y5N&jR6~+5Hc~cZWuagf&@$;F^bE5bKOy@6Ad>hkwNfiG;C*O$T zAME52QT)PAo)E>M>^lC39`v#8Ovm#O48C8)bexXjA7(oKM)8Z8j;m3;pXqoR#V=tx z4o2}Eoj4c8FJ(G@Me)m+j!RK|C)4pJieHZSF%X8tbsxKe>G%+S*oP>q{eBd`l4*Y) z#jj%8Pe*au4J3~~7E@wH(#JlYBnHyQuFk-($-oCP@Ld^r%&94=K6Y(_p6qRFivEyU zpU2L;7jHl--NKUcy+Pnf`IZHql&=At#%+z_B6LtXx`lQ5ul>QD3NN1;5Y*bwtl^IO zd23X_osX>f-vY(G4CJct0Ce`JKkUCGh0@e*m1ueeoNbQl6j1DUEM`Q1mCq zB%RuZFp9sl-chwKyPOe# z?pNz7AuR5O+;yF7w@QrHfTykZ7r@ij^?U~Yw+x)d*^v@2_6j__B6+<(1E;z~+I+qX zoYtl5ue7hA<8?v5o$0z_UBYY#n}!{r|Dqv**A#wS;OZuH`e_D!Is@N=eP7x z6FB_U=jEU$)!1ta*LB6+N{*)${zOF*YW>*>$3=W#4@jKq8+69draW! zCUp9B2L46{ehCt>wDs=Iz(1RTpAb0o^By^wSv9AZfQxl~MFQks=s0*G;mM;8JZ(M? z3mkTLyKHm#DtZ1#2K^vXqO^YQ&A`8tfxjkj_;bboel_Ji5EaQq*Lk&k9|FFM?PUEb z57GJVDM6oH?_X3u1FHX$BKgQg>GMAzaO8FONkUiAe?No%%?$i{6ll`;GcIsUswzAF znv&Opz)6m}E`LOg`+P<}{THYAzb6Bq%D{gDJk7uTIfMQt2#DmO-w!+jJE!AOfy?Xg z=Wl@1y7c=X%1h{YC4>Icm<-YD_bb;SuF&x#;A#B)eFpxvz!3*0W&1bfiA|%ET?~2n zw`C&!^lQdmMNg|6k3(|DDnQ4OgW1V+kDjj15dM;XB54DpE)bLVSQkD+Whxq;KRU$K0hEkSXc9TG=u(U0tcU!-~O>0 zw;x-_v~dSB@LMwQRtElvz~N`^mILlVUPZ?lfhX$;|5EgKj7hqZJTX?Y8V$a*;x@S- zSYE(tUf>7q#l^uIAM2D08>!4FW>IL6Gl7-nK_Y}(-Zj)u|K-BHAwNioV?dtv>6 z-LyRm{SVe!EyfQ_9oj!O#d(#dJUnU!Q)SK_SG*vd9~>Dfv+-N;N^^0L^QE;l-oi^( zw`nz;V4bh#I=vm5m@tibK0mg9${=RceU~p=%{tzbD$b}`j^92rHeIbSessq4OIE98 zH|xgiWNl@1^uSbgf91B@cyVwDkLQn=LB70T`A!YI_nhVuK5c8IS_7W1En6NBJj)6E zYRxb$d>HW_W=c!0yVS7DEzb?yh4x~ZcHVWH>FBjWOiZ0)#UWsX!u%J^`Pi<-ZAaRT`x96!OQ6B7UXoZz6EEyD|MC zD0XXvSOT9JK-epa3klXun*K2PMa#1d(D(@g(+A5_o(Pen?=>e-ZFpg@Fu1RGe&&l| zef*D~rPvN%P-aV1Y}Z}?Cn^U8_6r%F76OP@WbW0=@`@~(0Guczg!!=JJE%cY+ zJ56J52Cg;i!6_R#n-(egfFVI~#cC1XiSuE`M&w{n2uSNw>u!~F_fAkmnC~?IFUi@A zeVl^fX3~?QOiz?ZdUIFv)dY(>MwOP;3ZV!O4rYS&lqhfL9M0M!rF>~pDW~ZyQt3?@ zbD<>Md5A?JHC5`H3qh%#JmkR;!DdNc3%R4V=T_X-I$T<-9hhQEVF)#g_;hSEGV*AH za?%6~&7g#DTUy8i(!6hPo z5$YkdSuAN4KG5~ZQsMP{!(c1+O0BiNp`QC97Gp7f4c_ z)P{F<2-phEnLMJOWGP2_o(`o>=NP@6HDeA|A;&?wgcNAaT5wkL1zh_MuhEX12kR{x zR=4Ovl{VNm(k_LnH!&mDHG=m+^Gb2eBWEbmH|)-9$9Qe|7+2uY(3=6Md?stBqPHoXst_2E*kwX(M>rSd1Kx0#Q1i1r&-LKE;!2xXbSDO;Zz}S` zy2R6U`!oZQ55!c-Foz%+R3wSHl+&O4Ca;J9lFSQ45wqJ#$8#nsm}!pm9PLc|wGDlF zijs+K3D(PNR#01xTc9c!p_Mw;hgv87?g~l8 zW~!}`?QA68hW7(7V(~Mp-ZL;+de_xFnqtapkC>q}k0)K|{~nFX2u9dx`(Q3SQ8)de zpe~Xg#t%1-J22ik+i$PfkanelmnV2Bv&p Date: Sat, 29 Sep 2012 12:29:26 -0600 Subject: [PATCH 0097/1191] move generated path in to constant and make sure all files are expanded before access --- Gemfile.lock | 9 +++ Rakefile | 7 --- bin/rprotoc | 17 +++--- ext/ruby_generator/extconf.rb | 100 ++++++++-------------------------- protobuf.gemspec | 2 +- 5 files changed, 42 insertions(+), 93 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5e215519..2fa6c938 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,7 +12,9 @@ GEM coderay (1.0.7) diff-lcs (1.1.3) eventmachine (1.0.0) + eventmachine (1.0.0-java) ffi (1.1.5) + ffi (1.1.5-java) ffi-rzmq (0.9.6) ffi method_source (0.8) @@ -21,6 +23,11 @@ GEM coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.3.1) + pry (0.9.10-java) + coderay (~> 1.0.5) + method_source (~> 0.8) + slop (~> 3.3.1) + spoon (~> 0.0) pry-nav (0.2.2) pry (~> 0.9.10) rake (0.9.2.2) @@ -39,10 +46,12 @@ GEM simplecov-html (~> 0.5.3) simplecov-html (0.5.3) slop (3.3.3) + spoon (0.0.1) thor (0.16.0) yard (0.8.2.1) PLATFORMS + java ruby DEPENDENCIES diff --git a/Rakefile b/Rakefile index dbf9b7f6..67c1a92d 100644 --- a/Rakefile +++ b/Rakefile @@ -4,13 +4,6 @@ $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "bundler/gem_tasks" require "benchmark/tasks" -require 'rake/testtask' -Rake::TestTask.new(:test) do |test| - test.libs << 'test:.' - test.pattern = 'test/**/test_*.rb' - test.verbose = true -end - require 'rspec/core/rake_task' desc 'Default: run specs.' diff --git a/bin/rprotoc b/bin/rprotoc index 4a9cee78..c8e6eb5f 100755 --- a/bin/rprotoc +++ b/bin/rprotoc @@ -3,18 +3,18 @@ require 'rubygems' require 'ffi' -generator_file = File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "ruby_generator.so") - -unless File.exists?(generator_file) +GENERATOR_FILE_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "ruby_generator.so")) +unless File.exists?(GENERATOR_FILE_PATH) $stdout << <<-WARNING Cannot locate shared object to plugin to protocol buffers generator. - Thought the file would be located at #{generator_file} + Thought the file would be located at #{GENERATOR_FILE_PATH} - If you are running on Jruby or Windows you should compile protocol buffer - definitions on another computer and then use those definitions locally. + If you are running on Windows you should compile protocol buffer + definitions on another VM and then use those definitions locally. Only the compiler is restricted by this. The definitions should work without issue. WARNING + $stdout << $/ exit 1 end @@ -22,11 +22,12 @@ end module Protobuf module RProtoC extend FFI::Library - ffi_lib generator_file + ffi_lib ::GENERATOR_FILE_PATH attach_function :_rprotoc_extern, [:int32, :pointer], :int32 def self.compile_proto(args) - args.unshift("protoc-ruby") + args.unshift("rprotoc") + args << "--help" if args.size == 1 ptr_params = [] args.each do |param| diff --git a/ext/ruby_generator/extconf.rb b/ext/ruby_generator/extconf.rb index f121b7d4..b9730440 100644 --- a/ext/ruby_generator/extconf.rb +++ b/ext/ruby_generator/extconf.rb @@ -1,3 +1,4 @@ +require 'rbconfig' # # # # # # # # # # by Jan Lelis # e-mail: mail@janlelis.de @@ -8,73 +9,6 @@ # # (c) 2010 Jan Lelis. -require 'rbconfig' -module RubyEngine - class << self - # try to guess it - @interpreter = case - when RUBY_PLATFORM == 'parrot' - 'cardinal' - when Object.constants.include?( :RUBY_ENGINE ) || - Object.constants.include?( 'RUBY_ENGINE' ) - if RUBY_ENGINE == 'ruby' - if RUBY_DESCRIPTION =~ /Enterprise/ - 'ree' - else - 'mri' - end - else - RUBY_ENGINE.to_s # jruby, rbx, ironruby, macruby, etc. - end - else # probably 1.8 - 'mri' - end - - def is?(what) - what === @interpreter - end - alias is is? - - def to_s - @interpreter - end - end - -module_function - - def mri? - RubyEngine.is? 'mri' - end - alias official_ruby? mri? - alias ruby? mri? - - def jruby? - RubyEngine.is? 'jruby' - end - alias java? jruby? - - def rubinius? - RubyEngine.is? 'rbx' - end - alias rbx? rubinius? - - def ree? - RubyEngine.is? 'ree' - end - alias enterprise? ree? - - def ironruby? - RubyEngine.is? 'ironruby' - end - alias iron_ruby? ironruby? - - def cardinal? - RubyEngine.is? 'cardinal' - end - alias parrot? cardinal? - alias perl? cardinal? -end - module OS class << self def is?(what) @@ -113,19 +47,31 @@ def posix? linux? or mac? or bsd? or solaris? or Process.respond_to?(:fork) end end + +# Bail if windows or no compiler needed +return if ::OS.windows? || ENV['WITHOUT_PROTO_COMPILER'] + +begin + require 'mkmf' -# Bail if windows or jruby or no compiler needed -return if (OS.windows? || RubyEngine.jruby? || ENV['WITHOUT_PROTO_COMPILER']) + include_directory = File.expand_path(File.join(File.dirname(__FILE__), "..", "protobuf-2.4.1", "src")) -require 'mkmf' + $CPPFLAGS << " -I#{include_directory}" + $CPPFLAGS << " -Wall " -include_directory = File.join(File.expand_path(File.dirname(__FILE__)), "..", "protobuf-2.4.1", "src") + have_library("pthread") + have_library("protoc") + have_library("protobuf") -$CPPFLAGS << " -I#{include_directory}" -$CPPFLAGS << " -Wall " + create_makefile('ruby_generator') +rescue + $stdout << <<-WARNING + Cannot compile native extension. -have_library("pthread") -have_library("protoc") -have_library("protobuf") + If you are running on Jruby or Windows you should compile protocol buffer + definitions on another computer and then use those definitions locally. -create_makefile('ruby_generator') + Only the compiler is restricted by this. The definitions should work without issue. + WARNING + $stdout << $/ +end diff --git a/protobuf.gemspec b/protobuf.gemspec index 8b56ad89..b16cc44d 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.extensions = [ File.join('ext', 'ruby_generator', 'extconf.rb') ] + s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') s.add_dependency 'ffi' s.add_dependency 'multi_json' From 0ad3a62b12ad9808cee9fb9fe66bce472a147206 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Sep 2012 12:47:20 -0600 Subject: [PATCH 0098/1191] using WITHOUT_PROTO_COMPILER instead of checking os --- ext/ruby_generator/extconf.rb | 53 ----------------------------------- protobuf.gemspec | 5 +++- 2 files changed, 4 insertions(+), 54 deletions(-) diff --git a/ext/ruby_generator/extconf.rb b/ext/ruby_generator/extconf.rb index b9730440..a50886f0 100644 --- a/ext/ruby_generator/extconf.rb +++ b/ext/ruby_generator/extconf.rb @@ -1,56 +1,3 @@ -require 'rbconfig' -# # # # # # # # # -# by Jan Lelis -# e-mail: mail@janlelis.de -# type/version: ruby -# snippet url: http://rbJL.net/35/os.rb -# original post: http://rbJL.net/35-how-to-properly-check-for-your-ruby-interpreter-version-and-os -# license: CC-BY (DE) -# -# (c) 2010 Jan Lelis. - -module OS - class << self - def is?(what) - what === RbConfig::CONFIG['host_os'] - end - alias is is? - - def to_s - RbConfig::CONFIG['host_os'] - end - end - - module_function - - def linux? - OS.is? /linux|cygwin/ - end - - def mac? - OS.is? /mac|darwin/ - end - - def bsd? - OS.is? /bsd/ - end - - def windows? - OS.is? /mswin|win|mingw/ - end - - def solaris? - OS.is? /solaris|sunos/ - end - - def posix? - linux? or mac? or bsd? or solaris? or Process.respond_to?(:fork) - end -end - -# Bail if windows or no compiler needed -return if ::OS.windows? || ENV['WITHOUT_PROTO_COMPILER'] - begin require 'mkmf' diff --git a/protobuf.gemspec b/protobuf.gemspec index b16cc44d..69e035dc 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -17,7 +17,10 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') + + unless ENV['WITHOUT_PROTO_COMPILER'] + s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') + end s.add_dependency 'ffi' s.add_dependency 'multi_json' From 12475bf099e07d01902569b5aa88c54f51049d95 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Sep 2012 13:57:21 -0600 Subject: [PATCH 0099/1191] require multi_json instead of json --- lib/protobuf/message/message.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb index 4d7a6525..c7cbef6d 100644 --- a/lib/protobuf/message/message.rb +++ b/lib/protobuf/message/message.rb @@ -4,7 +4,7 @@ require 'protobuf/message/encoder' require 'protobuf/message/field' require 'protobuf/message/protoable' -require 'json' +require 'multi_json' module Protobuf OPTIONS = {} From 606bfb37b67801ef8494c04683fdeb45dc18dfd0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Sep 2012 14:40:17 -0600 Subject: [PATCH 0100/1191] remove descriptor references in ruby now that we are using a compiler without a ruby representation of the descriptor present --- lib/protobuf/descriptor/descriptor.proto | 286 ------------------ lib/protobuf/descriptor/descriptor.rb | 55 ---- lib/protobuf/descriptor/descriptor_builder.rb | 122 -------- lib/protobuf/descriptor/descriptor_proto.rb | 138 --------- lib/protobuf/descriptor/enum_descriptor.rb | 33 -- lib/protobuf/descriptor/field_descriptor.rb | 49 --- lib/protobuf/descriptor/file_descriptor.rb | 37 --- lib/protobuf/field.rb | 1 + lib/protobuf/field/base_field.rb | 9 - lib/protobuf/message.rb | 5 - lib/protobuf/message/enum.rb | 5 - test/check_unbuild.rb | 30 -- test/test_descriptor.rb | 122 -------- 13 files changed, 1 insertion(+), 891 deletions(-) delete mode 100755 lib/protobuf/descriptor/descriptor.proto delete mode 100644 lib/protobuf/descriptor/descriptor.rb delete mode 100644 lib/protobuf/descriptor/descriptor_builder.rb delete mode 100644 lib/protobuf/descriptor/descriptor_proto.rb delete mode 100644 lib/protobuf/descriptor/enum_descriptor.rb delete mode 100644 lib/protobuf/descriptor/field_descriptor.rb delete mode 100644 lib/protobuf/descriptor/file_descriptor.rb delete mode 100755 test/check_unbuild.rb delete mode 100644 test/test_descriptor.rb diff --git a/lib/protobuf/descriptor/descriptor.proto b/lib/protobuf/descriptor/descriptor.proto deleted file mode 100755 index 13d94780..00000000 --- a/lib/protobuf/descriptor/descriptor.proto +++ /dev/null @@ -1,286 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. -// http://code.google.com/p/protobuf/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// The messages in this file describe the definitions found in .proto files. -// A valid .proto file can be translated directly to a FileDescriptorProto -// without any other information (e.g. without reading its imports). - - - -package google.protobuf; -option java_package = "com.google.protobuf"; -option java_outer_classname = "DescriptorProtos"; - -// descriptor.proto must be optimized for speed because reflection-based -// algorithms don't work during bootstrapping. -option optimize_for = SPEED; - -// Describes a complete .proto file. -message FileDescriptorProto { - optional string name = 1; // file name, relative to root of source tree - optional string package = 2; // e.g. "foo", "foo.bar", etc. - - // Names of files imported by this file. - repeated string dependency = 3; - - // All top-level definitions in this file. - repeated DescriptorProto message_type = 4; - repeated EnumDescriptorProto enum_type = 5; - repeated ServiceDescriptorProto service = 6; - repeated FieldDescriptorProto extension = 7; - - optional FileOptions options = 8; -} - -// Describes a message type. -message DescriptorProto { - optional string name = 1; - - repeated FieldDescriptorProto field = 2; - repeated FieldDescriptorProto extension = 6; - - repeated DescriptorProto nested_type = 3; - repeated EnumDescriptorProto enum_type = 4; - - message ExtensionRange { - optional int32 start = 1; - optional int32 end = 2; - } - repeated ExtensionRange extension_range = 5; - - optional MessageOptions options = 7; -} - -// Describes a field within a message. -message FieldDescriptorProto { - enum Type { - // 0 is reserved for errors. - // Order is weird for historical reasons. - TYPE_DOUBLE = 1; - TYPE_FLOAT = 2; - TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers - // take 10 bytes. Use TYPE_SINT64 if negative - // values are likely. - TYPE_UINT64 = 4; - TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers - // take 10 bytes. Use TYPE_SINT32 if negative - // values are likely. - TYPE_FIXED64 = 6; - TYPE_FIXED32 = 7; - TYPE_BOOL = 8; - TYPE_STRING = 9; - TYPE_GROUP = 10; // Tag-delimited aggregate. - TYPE_MESSAGE = 11; // Length-delimited aggregate. - - // New in version 2. - TYPE_BYTES = 12; - TYPE_UINT32 = 13; - TYPE_ENUM = 14; - TYPE_SFIXED32 = 15; - TYPE_SFIXED64 = 16; - TYPE_SINT32 = 17; // Uses ZigZag encoding. - TYPE_SINT64 = 18; // Uses ZigZag encoding. - }; - - enum Label { - // 0 is reserved for errors - LABEL_OPTIONAL = 1; - LABEL_REQUIRED = 2; - LABEL_REPEATED = 3; - // TODO(sanjay): Should we add LABEL_MAP? - }; - - optional string name = 1; - optional int32 number = 3; - optional Label label = 4; - - // If type_name is set, this need not be set. If both this and type_name - // are set, this must be either TYPE_ENUM or TYPE_MESSAGE. - optional Type type = 5; - - // For message and enum types, this is the name of the type. If the name - // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping - // rules are used to find the type (i.e. first the nested types within this - // message are searched, then within the parent, on up to the root - // namespace). - optional string type_name = 6; - - // For extensions, this is the name of the type being extended. It is - // resolved in the same manner as type_name. - optional string extendee = 2; - - // For numeric types, contains the original text representation of the value. - // For booleans, "true" or "false". - // For strings, contains the default text contents (not escaped in any way). - // For bytes, contains the C escaped value. All bytes >= 128 are escaped. - // TODO(kenton): Base-64 encode? - optional string default_value = 7; - - optional FieldOptions options = 8; -} - -// Describes an enum type. -message EnumDescriptorProto { - optional string name = 1; - - repeated EnumValueDescriptorProto value = 2; - - optional EnumOptions options = 3; -} - -// Describes a value within an enum. -message EnumValueDescriptorProto { - optional string name = 1; - optional int32 number = 2; - - optional EnumValueOptions options = 3; -} - -// Describes a service. -message ServiceDescriptorProto { - optional string name = 1; - repeated MethodDescriptorProto method = 2; - - optional ServiceOptions options = 3; -} - -// Describes a method of a service. -message MethodDescriptorProto { - optional string name = 1; - - // Input and output type names. These are resolved in the same way as - // FieldDescriptorProto.type_name, but must refer to a message type. - optional string input_type = 2; - optional string output_type = 3; - - optional MethodOptions options = 4; -} - -// =================================================================== -// Options - -// Each of the definitions above may have "options" attached. These are -// just annotations which may cause code to be generated slightly differently -// or may contain hints for code that manipulates protocol messages. - -// TODO(kenton): Allow extensions to options. - -message FileOptions { - - // Sets the Java package where classes generated from this .proto will be - // placed. By default, the proto package is used, but this is often - // inappropriate because proto packages do not normally start with backwards - // domain names. - optional string java_package = 1; - - - // If set, all the classes from the .proto file are wrapped in a single - // outer class with the given name. This applies to both Proto1 - // (equivalent to the old "--one_java_file" option) and Proto2 (where - // a .proto always translates to a single class, but you may want to - // explicitly choose the class name). - optional string java_outer_classname = 8; - - // If set true, then the Java code generator will generate a separate .java - // file for each top-level message, enum, and service defined in the .proto - // file. Thus, these types will *not* be nested inside the outer class - // named by java_outer_classname. However, the outer class will still be - // generated to contain the file's getDescriptor() method as well as any - // top-level extensions defined in the file. - optional bool java_multiple_files = 10 [default=false]; - - // Generated classes can be optimized for speed or code size. - enum OptimizeMode { - SPEED = 1; // Generate complete code for parsing, serialization, etc. - CODE_SIZE = 2; // Use ReflectionOps to implement these methods. - } - optional OptimizeMode optimize_for = 9 [default=CODE_SIZE]; -} - -message MessageOptions { - // Set true to use the old proto1 MessageSet wire format for extensions. - // This is provided for backwards-compatibility with the MessageSet wire - // format. You should not use this for any other reason: It's less - // efficient, has fewer features, and is more complicated. - // - // The message must be defined exactly as follows: - // message Foo { - // option message_set_wire_format = true; - // extensions 4 to max; - // } - // Note that the message cannot have any defined fields; MessageSets only - // have extensions. - // - // All extensions of your type must be singular messages; e.g. they cannot - // be int32s, enums, or repeated messages. - // - // Because this is an option, the above two restrictions are not enforced by - // the protocol compiler. - optional bool message_set_wire_format = 1 [default=false]; -} - -message FieldOptions { - // The ctype option instructs the C++ code generator to use a different - // representation of the field than it normally would. See the specific - // options below. This option is not yet implemented in the open source - // release -- sorry, we'll try to include it in a future version! - optional CType ctype = 1; - enum CType { - CORD = 1; - - STRING_PIECE = 2; - } - - // EXPERIMENTAL. DO NOT USE. - // For "map" fields, the name of the field in the enclosed type that - // is the key for this map. For example, suppose we have: - // message Item { - // required string name = 1; - // required string value = 2; - // } - // message Config { - // repeated Item items = 1 [experimental_map_key="name"]; - // } - // In this situation, the map key for Item will be set to "name". - // TODO: Fully-implement this, then remove the "experimental_" prefix. - optional string experimental_map_key = 9; -} - -message EnumOptions { -} - -message EnumValueOptions { -} - -message ServiceOptions { - - // Note: Field numbers 1 through 32 are reserved for Google's internal RPC - // framework. We apologize for hoarding these numbers to ourselves, but - // we were already using them long before we decided to release Protocol - // Buffers. -} - -message MethodOptions { - - // Note: Field numbers 1 through 32 are reserved for Google's internal RPC - // framework. We apologize for hoarding these numbers to ourselves, but - // we were already using them long before we decided to release Protocol - // Buffers. -} diff --git a/lib/protobuf/descriptor/descriptor.rb b/lib/protobuf/descriptor/descriptor.rb deleted file mode 100644 index 0344b2b6..00000000 --- a/lib/protobuf/descriptor/descriptor.rb +++ /dev/null @@ -1,55 +0,0 @@ -module Protobuf - module Descriptor - class Descriptor - def initialize(message_class) - @message_class = message_class - end - - def proto_type - 'Google::Protobuf::DescriptorProto' - end - - def build(proto, opt={}) - mod = opt[:module] - cls = mod.const_set(proto.name, Class.new(@message_class)) - proto.nested_type.each do |message_proto| - Protobuf::Message.descriptor.build(message_proto, :module => cls) - end - proto.enum_type.each do |enum_proto| - Protobuf::Enum.descriptor.build(enum_proto, :module => cls) - end - proto.field.each do |field_proto| - Protobuf::Field::BaseField.descriptor.build(field_proto, :class => cls) - end - end - - def unbuild(parent_proto) - message_proto = Google::Protobuf::DescriptorProto.new - message_proto.name = @message_class.to_s.split('::').last - @message_class.fields.each do |tag, field| - field.descriptor.unbuild(message_proto) - end - ObjectSpace.each_object(Class) do |cls| - if innerclass?(@message_class, cls) - cls.descriptor.unbuild(message_proto) - end - end - - case parent_proto - when Google::Protobuf::FileDescriptorProto - parent_proto.message_type << message_proto - when Google::Protobuf::DescriptorProto - parent_proto.nested_type << message_proto - else - raise TypeError, parent_proto.class.name - end - end - - private - - def innerclass?(parent, child) - child.name =~ /::/ && child.name.split('::')[0..-2].join('::') == parent.name - end - end - end -end diff --git a/lib/protobuf/descriptor/descriptor_builder.rb b/lib/protobuf/descriptor/descriptor_builder.rb deleted file mode 100644 index 72552dd3..00000000 --- a/lib/protobuf/descriptor/descriptor_builder.rb +++ /dev/null @@ -1,122 +0,0 @@ -require 'protobuf/descriptor/file_descriptor' - -module Protobuf - module Descriptor - def self.id2type(type_id) - require 'protobuf/descriptor/descriptor_proto' - case type_id - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE then - :double - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT then - :float - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64 then - :int64 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64 then - :unit64 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32 then - :int64 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64 then - :fixed64 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32 then - :fixed32 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL then - :bool - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING then - :string - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP then - :group - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE then - :message - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES then - :bytes - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32 then - :uint32 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM then - :enum - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32 then - :sfixed32 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64 then - :sfixed64 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32 then - :sint32 - when ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64 then - :sint64 - else - raise ArgumentError, "Invalid type: #{proto.type}" - end - end - - def self.type2id(type) - require 'protobuf/descriptor/descriptor_proto' - case type - when :double then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE - when :float then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT - when :int64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64 - when :unit64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64 - when :int64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32 - when :fixed64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64 - when :fixed32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32 - when :bool then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL - when :string then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING - when :group then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP - when :message then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE - when :bytes then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES - when :uint32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32 - when :enum then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM - when :sfixed32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32 - when :sfixed64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64 - when :sint32 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32 - when :sint64 then ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64 - else - ::Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE - end - end - - def self.id2label(label_id) - require 'protobuf/descriptor/descriptor_proto' - case label_id - when ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED then - :required - when ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL then - :optional - when ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED then - :repeated - else - raise ArgumentError, "Invalid label: #{proto.label}" - end - end - - def self.label2id(label) - require 'protobuf/descriptor/descriptor_proto' - case label - when :required then - ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED - when :optional then - ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL - when :repeated then - ::Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED - else - raise ArgumentError, "Invalid label: #{label}" - end - end - - class DescriptorBuilder - def self.proto_type - nil - end - - def self.build(proto, opt={}) - acceptable_descriptor(proto).build(proto) - end - - def self.acceptable_descriptor(proto) - ::Protobuf::Descriptor.constants.each do |class_name| - descriptor_class = ::Protobuf::Descriptor.const_get(class_name) - if descriptor_class.respond_to?(:proto_type) && descriptor_class.proto_type == proto.class.name - return descriptor_class - end - end - end - end - end -end diff --git a/lib/protobuf/descriptor/descriptor_proto.rb b/lib/protobuf/descriptor/descriptor_proto.rb deleted file mode 100644 index 0eaf486a..00000000 --- a/lib/protobuf/descriptor/descriptor_proto.rb +++ /dev/null @@ -1,138 +0,0 @@ -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Google - module Protobuf - ::Protobuf::OPTIONS[:"java_package"] = "com.google.protobuf" - ::Protobuf::OPTIONS[:"java_outer_classname"] = "DescriptorProtos" - ::Protobuf::OPTIONS[:"optimize_for"] = :SPEED - class FileDescriptorProto < ::Protobuf::Message - defined_in __FILE__ - optional :string, :name, 1 - optional :string, :package, 2 - repeated :string, :dependency, 3 - repeated :DescriptorProto, :message_type, 4 - repeated :EnumDescriptorProto, :enum_type, 5 - repeated :ServiceDescriptorProto, :service, 6 - repeated :FieldDescriptorProto, :extension, 7 - optional :FileOptions, :options, 8 - end - class DescriptorProto < ::Protobuf::Message - defined_in __FILE__ - optional :string, :name, 1 - repeated :FieldDescriptorProto, :field, 2 - repeated :FieldDescriptorProto, :extension, 6 - repeated :DescriptorProto, :nested_type, 3 - repeated :EnumDescriptorProto, :enum_type, 4 - class ExtensionRange < ::Protobuf::Message - defined_in __FILE__ - optional :int32, :start, 1 - optional :int32, :end, 2 - end - repeated :ExtensionRange, :extension_range, 5 - optional :MessageOptions, :options, 7 - end - class FieldDescriptorProto < ::Protobuf::Message - defined_in __FILE__ - class Type < ::Protobuf::Enum - defined_in __FILE__ - define :TYPE_DOUBLE, 1 - define :TYPE_FLOAT, 2 - define :TYPE_INT64, 3 - define :TYPE_UINT64, 4 - define :TYPE_INT32, 5 - define :TYPE_FIXED64, 6 - define :TYPE_FIXED32, 7 - define :TYPE_BOOL, 8 - define :TYPE_STRING, 9 - define :TYPE_GROUP, 10 - define :TYPE_MESSAGE, 11 - define :TYPE_BYTES, 12 - define :TYPE_UINT32, 13 - define :TYPE_ENUM, 14 - define :TYPE_SFIXED32, 15 - define :TYPE_SFIXED64, 16 - define :TYPE_SINT32, 17 - define :TYPE_SINT64, 18 - end - class Label < ::Protobuf::Enum - defined_in __FILE__ - define :LABEL_OPTIONAL, 1 - define :LABEL_REQUIRED, 2 - define :LABEL_REPEATED, 3 - end - optional :string, :name, 1 - optional :int32, :number, 3 - optional :Label, :label, 4 - optional :Type, :type, 5 - optional :string, :type_name, 6 - optional :string, :extendee, 2 - optional :string, :default_value, 7 - optional :FieldOptions, :options, 8 - end - class EnumDescriptorProto < ::Protobuf::Message - defined_in __FILE__ - optional :string, :name, 1 - repeated :EnumValueDescriptorProto, :value, 2 - optional :EnumOptions, :options, 3 - end - class EnumValueDescriptorProto < ::Protobuf::Message - defined_in __FILE__ - optional :string, :name, 1 - optional :int32, :number, 2 - optional :EnumValueOptions, :options, 3 - end - class ServiceDescriptorProto < ::Protobuf::Message - defined_in __FILE__ - optional :string, :name, 1 - repeated :MethodDescriptorProto, :method, 2 - optional :ServiceOptions, :options, 3 - end - class MethodDescriptorProto < ::Protobuf::Message - defined_in __FILE__ - optional :string, :name, 1 - optional :string, :input_type, 2 - optional :string, :output_type, 3 - optional :MethodOptions, :options, 4 - end - class FileOptions < ::Protobuf::Message - defined_in __FILE__ - optional :string, :java_package, 1 - optional :string, :java_outer_classname, 8 - optional :bool, :java_multiple_files, 10, :default => false - class OptimizeMode < ::Protobuf::Enum - defined_in __FILE__ - define :SPEED, 1 - define :CODE_SIZE, 2 - end - optional :OptimizeMode, :optimize_for, 9, :default => :CODE_SIZE - end - class MessageOptions < ::Protobuf::Message - defined_in __FILE__ - optional :bool, :message_set_wire_format, 1, :default => false - end - class FieldOptions < ::Protobuf::Message - defined_in __FILE__ - optional :CType, :ctype, 1 - class CType < ::Protobuf::Enum - defined_in __FILE__ - define :CORD, 1 - define :STRING_PIECE, 2 - end - optional :string, :experimental_map_key, 9 - end - class EnumOptions < ::Protobuf::Message - defined_in __FILE__ - end - class EnumValueOptions < ::Protobuf::Message - defined_in __FILE__ - end - class ServiceOptions < ::Protobuf::Message - defined_in __FILE__ - end - class MethodOptions < ::Protobuf::Message - defined_in __FILE__ - end - end -end diff --git a/lib/protobuf/descriptor/enum_descriptor.rb b/lib/protobuf/descriptor/enum_descriptor.rb deleted file mode 100644 index 9e1e0b12..00000000 --- a/lib/protobuf/descriptor/enum_descriptor.rb +++ /dev/null @@ -1,33 +0,0 @@ -module Protobuf - module Descriptor - class EnumDescriptor - def initialize(enum_class) - @enum_class = enum_class - end - - def proto_type - Google::Protobuf::EnumDescriptorProto - end - - def build(proto, opt) - mod = opt[:module] - cls = mod.const_set(proto.name, Class.new(Protobuf::Enum)) - proto.value.each do |value_proto| - cls.class_eval { define value_proto.name, value_proto.number } - end - end - - def unbuild(parent_proto) - enum_proto = Google::Protobuf::EnumDescriptorProto.new - enum_proto.name = @enum_class.name.split('::').last - @enum_class.values.each do |name, value| - enum_value_proto = Google::Protobuf::EnumValueDescriptorProto.new - enum_value_proto.name = name.to_s - enum_value_proto.number = value.value - enum_proto.value << enum_value_proto - end - parent_proto.enum_type << enum_proto - end - end - end -end diff --git a/lib/protobuf/descriptor/field_descriptor.rb b/lib/protobuf/descriptor/field_descriptor.rb deleted file mode 100644 index abee4664..00000000 --- a/lib/protobuf/descriptor/field_descriptor.rb +++ /dev/null @@ -1,49 +0,0 @@ -module Protobuf - module Descriptor - class FieldDescriptor - def initialize(field_instance = nil) - @field_instance = field_instance - end - - def proto_type - 'Google::Protobuf::FieldDescriptorProto' - end - - def build(proto, opt={}) - cls = opt[:class] - rule = Protobuf::Descriptor.id2label(proto.label) - type = Protobuf::Descriptor.id2type(proto.type) - type = proto.type_name.to_sym if [:message, :enum].include?(type) - opts = {} - opts[:default] = proto.default_value if proto.default_value - cls.define_field(rule, type, proto.name, proto.number, opts) - end - - def unbuild(parent_proto, extension = false) - field_proto = Google::Protobuf::FieldDescriptorProto.new - field_proto.name = @field_instance.name.to_s - field_proto.number = @field_instance.tag - field_proto.label = Protobuf::Descriptor.label2id(@field_instance.rule) - field_proto.type = Protobuf::Descriptor.type2id(@field_instance.type) - if [Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE, - Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM].include? field_proto.type - field_proto.type_name = @field_instance.type.to_s.split('::').last - end - field_proto.default_value = @field_instance.default.to_s if @field_instance.default - - case parent_proto - when Google::Protobuf::FileDescriptorProto then - parent_proto.extension << field_proto - when Google::Protobuf::DescriptorProto then - if extension - parent_proto.extension << field_proto - else - parent_proto.field << field_proto - end - else - raise TypeError, parent_proto.class.name - end - end - end - end -end diff --git a/lib/protobuf/descriptor/file_descriptor.rb b/lib/protobuf/descriptor/file_descriptor.rb deleted file mode 100644 index f0d2f17e..00000000 --- a/lib/protobuf/descriptor/file_descriptor.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Protobuf - module Descriptor - class FileDescriptor - class << self - def proto_type - 'Google::Protobuf::FileDescriptorProto' - end - - def build(proto, opt={}) - mod = Object - if package = proto.package and not package.empty? - module_names = package.split '::' - module_names.each do |module_name| - mod = mod.const_set module_name, Module.new - end - end - proto.message_type.each do |message_proto| - Protobuf::Message.descriptor.build message_proto, :module => mod - end - proto.enum_type.each do |enum_proto| - Protobuf::Enum.descriptor.build enum_proto, :module => mod - end - end - - def unbuild(messages) - messages = [messages] unless messages.is_a? Array - proto = Google::Protobuf::FileDescriptorProto.new - proto.package = messages.first.to_s.split('::')[0..-2].join('::') if messages.first.to_s =~ /::/ - messages.each do |message| - message.descriptor.unbuild proto - end - proto - end - end - end - end -end diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index df81b6c5..5228cc45 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -46,5 +46,6 @@ def self.build(message_class, rule, type, name, tag, options={}) field_class = ::Protobuf::Field::PREDEFINED_TYPES.fetch(type, ::Protobuf::Field::FieldProxy) field_class.new(message_class, rule, type, name, tag, options) end + end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 584c143c..a2327736 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,5 +1,4 @@ require 'protobuf/common/wire_type' -require 'protobuf/descriptor/field_descriptor' require 'protobuf/field/field_array' module Protobuf @@ -17,10 +16,6 @@ def self.default nil end - def self.descriptor - @descriptor ||= ::Protobuf::Descriptor::FieldDescriptor.new - end - ## # Constructor # @@ -59,10 +54,6 @@ def acceptable?(value) true end - def descriptor - @descriptor ||= ::Protobuf::Descriptor::FieldDescriptor.new(self) - end - def ready? true end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 8e86c778..a27d9196 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,6 +1,5 @@ require 'set' require 'protobuf/field' -require 'protobuf/descriptor/descriptor' require 'protobuf/message/decoder' require 'protobuf/message/encoder' require 'protobuf/message/protoable' @@ -49,10 +48,6 @@ def self.repeated(type, name, tag, options={}) define_field(:repeated, type, name, tag, options) end - def self.descriptor - @descriptor ||= Descriptor::Descriptor.new(self) - end - # Define a field. Don't use this method directly. def self.define_field(rule, type, fname, tag, options) field_hash = options[:extension] ? extension_fields : fields diff --git a/lib/protobuf/message/enum.rb b/lib/protobuf/message/enum.rb index 3566606b..7c53dc84 100644 --- a/lib/protobuf/message/enum.rb +++ b/lib/protobuf/message/enum.rb @@ -1,5 +1,4 @@ require 'delegate' -require 'protobuf/descriptor/enum_descriptor' require 'protobuf/message/protoable' module Protobuf @@ -24,10 +23,6 @@ def valid_tag?(tag) !! name_by_value(tag) end - def descriptor - @descriptor ||= Descriptor::EnumDescriptor.new(self) - end - private def define(name, value) diff --git a/test/check_unbuild.rb b/test/check_unbuild.rb deleted file mode 100755 index 3ca0c32e..00000000 --- a/test/check_unbuild.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env ruby - -$:.push "#{File.dirname(__FILE__)}/../lib" - -require 'test/unit' -require 'protobuf/descriptor/descriptor_builder' -require 'protobuf/descriptor/descriptor_proto' - -class DescriptorTest < Test::Unit::TestCase - def test_unbuild - tutorial_proto = Google::Protobuf::FileDescriptorProto.new - tutorial_proto.parse_from_file 'person.bin' - Protobuf::Descriptor::DescriptorBuilder.build tutorial_proto - - assert_nothing_raised {Tutorial::Person} - assert_nothing_raised {Tutorial::Person.new} - assert_equal(['age', 'email', 'id', 'name', 'phone'], - Tutorial::Person.fields.map{|tag, field| field.name}.sort) - - assert_nothing_raised {Tutorial::Person::PhoneNumber} - assert_nothing_raised {Tutorial::Person::PhoneNumber.new} - assert_equal(['number', 'type'], - Tutorial::Person::PhoneNumber.fields.map{|tag, field| field.name}.sort) - - assert_nothing_raised {Tutorial::Person::PhoneType} - assert_equal(0, Tutorial::Person::PhoneType::MOBILE) - assert_equal(1, Tutorial::Person::PhoneType::HOME) - assert_equal(2, Tutorial::Person::PhoneType::WORK) - end -end diff --git a/test/test_descriptor.rb b/test/test_descriptor.rb deleted file mode 100644 index 519e48b7..00000000 --- a/test/test_descriptor.rb +++ /dev/null @@ -1,122 +0,0 @@ -require 'test/unit' -require 'test/proto/addressbook.pb' -require 'protobuf/descriptor/descriptor_builder' -require 'protobuf/descriptor/descriptor_proto' - -class DescriptorTest < Test::Unit::TestCase - include Google::Protobuf - def test_build - tutorial_proto = FileDescriptorProto.new - tutorial_proto.package = 'Build::Tutorial' - - person_proto = DescriptorProto.new - tutorial_proto.message_type << person_proto - person_proto.name = 'Person' - - person_name_proto = FieldDescriptorProto.new - person_proto.field << person_name_proto - person_name_proto.label = FieldDescriptorProto::Label::LABEL_REQUIRED - person_name_proto.type = FieldDescriptorProto::Type::TYPE_STRING - person_name_proto.name = 'name' - person_name_proto.number = 1 - - person_id_proto = FieldDescriptorProto.new - person_proto.field << person_id_proto - person_id_proto.label = FieldDescriptorProto::Label::LABEL_REQUIRED - person_id_proto.type = FieldDescriptorProto::Type::TYPE_INT32 - person_id_proto.name = 'id' - person_id_proto.number = 2 - - person_email_proto = FieldDescriptorProto.new - person_proto.field << person_email_proto - person_email_proto.label = FieldDescriptorProto::Label::LABEL_OPTIONAL - person_email_proto.type = FieldDescriptorProto::Type::TYPE_STRING - person_email_proto.name = 'email' - person_email_proto.number = 3 - - person_phone_type_proto = EnumDescriptorProto.new - person_proto.enum_type << person_phone_type_proto - person_phone_type_proto.name = 'PhoneType' - - person_phone_type_mobile_proto = EnumValueDescriptorProto.new - person_phone_type_proto.value << person_phone_type_mobile_proto - person_phone_type_mobile_proto.name = 'MOBILE' - person_phone_type_mobile_proto.number = 0 - - person_phone_type_home_proto = EnumValueDescriptorProto.new - person_phone_type_proto.value << person_phone_type_home_proto - person_phone_type_home_proto.name = 'HOME' - person_phone_type_home_proto.number = 1 - - person_phone_type_work_proto = EnumValueDescriptorProto.new - person_phone_type_proto.value << person_phone_type_work_proto - person_phone_type_work_proto.name = 'WORK' - person_phone_type_work_proto.number = 2 - - person_phone_number_proto = DescriptorProto.new - person_proto.nested_type << person_phone_number_proto - person_phone_number_proto.name = 'PhoneNumber' - - person_phone_number_number_proto = FieldDescriptorProto.new - person_phone_number_proto.field << person_phone_number_number_proto - person_phone_number_number_proto.label = FieldDescriptorProto::Label::LABEL_REQUIRED - person_phone_number_number_proto.type = FieldDescriptorProto::Type::TYPE_STRING - person_phone_number_number_proto.name = 'number' - person_phone_number_number_proto.number = 1 - - person_phone_number_type_proto = FieldDescriptorProto.new - person_phone_number_proto.field << person_phone_number_type_proto - person_phone_number_type_proto.label = FieldDescriptorProto::Label::LABEL_OPTIONAL - person_phone_number_type_proto.type = FieldDescriptorProto::Type::TYPE_ENUM - person_phone_number_type_proto.type_name = 'PhoneType' - person_phone_number_type_proto.name = 'type' - person_phone_number_type_proto.number = 2 - person_phone_number_type_proto.default_value = 'HOME' - - person_phone_phone_number_proto = FieldDescriptorProto.new - person_proto.field << person_phone_phone_number_proto - person_phone_phone_number_proto.label = FieldDescriptorProto::Label::LABEL_REPEATED - person_phone_phone_number_proto.type = FieldDescriptorProto::Type::TYPE_MESSAGE - person_phone_phone_number_proto.type_name = 'PhoneNumber' - person_phone_phone_number_proto.name = 'phone' - person_phone_phone_number_proto.number = 4 - - address_book_proto = DescriptorProto.new - tutorial_proto.message_type << address_book_proto - address_book_proto.name = 'AddressBook' - - address_book_person_proto = FieldDescriptorProto.new - address_book_proto.field << address_book_person_proto - address_book_person_proto.label = FieldDescriptorProto::Label::LABEL_REPEATED - address_book_person_proto.type = FieldDescriptorProto::Type::TYPE_MESSAGE - address_book_person_proto.type_name = 'Person' - address_book_person_proto.name = 'person' - address_book_person_proto.number = 1 - - Protobuf::Descriptor::DescriptorBuilder.build(tutorial_proto) - - assert_nothing_raised {Build::Tutorial::Person} - assert_nothing_raised {Build::Tutorial::Person.new} - assert_equal(['email', 'id', 'name', 'phone'], - Build::Tutorial::Person.fields.map{|tag, field| field.name}.sort) - - assert_nothing_raised {Build::Tutorial::Person::PhoneNumber} - assert_nothing_raised {Build::Tutorial::Person::PhoneNumber.new} - assert_equal(['number', 'type'], - Build::Tutorial::Person::PhoneNumber.fields.map{|tag, field| field.name}.sort) - - assert_nothing_raised {Build::Tutorial::Person::PhoneType} - assert_equal(0, Build::Tutorial::Person::PhoneType::MOBILE) - assert_equal(1, Build::Tutorial::Person::PhoneType::HOME) - assert_equal(2, Build::Tutorial::Person::PhoneType::WORK) - - assert_nothing_raised {Build::Tutorial::AddressBook} - end - - def test_unbuild - proto = Protobuf::Descriptor::FileDescriptor.unbuild(Tutorial::Person) - proto.serialize_to_file('person.bin') - puts - puts "run `test/check_unbuild.rb'" - end -end From 6f3e04758be1e32630dd97954d833cc14db3312f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Sep 2012 15:07:40 -0600 Subject: [PATCH 0101/1191] no reason to have to "setup" fields anymore and make sure they are "ready?" --- lib/protobuf/field/base_field.rb | 10 +++++++ lib/protobuf/message.rb | 49 -------------------------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index a2327736..579a9546 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -54,6 +54,16 @@ def acceptable?(value) true end + def enum? + return @_enum unless @_enum.nil? + @_enum = (self.class < ::Protobuf::Field::EnumField) + end + + def message? + return @_message unless @_message.nil? + @_message = (self.class < ::Protobuf::Field::MessageField) + end + def ready? true end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a27d9196..6faaf4d8 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -133,61 +133,12 @@ def self.get_ext_field(tag_or_name) end end - def self.initialize_unready_fields - unless @unready_initialized - initialize_type_fields - initialize_type_extension_fields - @unready_initialized = true - end - end - - def self.initialize_type_fields - fields.each do |tag, field| - unless field.ready? - field = field.setup - fields[tag] = field - fields_by_name[field.name.to_sym] = field - fields_by_name[field.name] = field - end - end - end - - def self.initialize_type_extension_fields - extension_fields.each do |tag, field| - unless field.ready? - field = field.setup - extension_fields[tag] = field - extension_fields_by_name[field.name.to_sym] = field - extension_fields_by_name[field.name] = field - end - end - end - - def self.setup_repeated_field_arrays - unless @repeated_fields_setup - all_fields.each do |field| - next unless field.repeated? - - if field.extension? - repeated_extension_fields << field - else - repeated_fields << field - end - end - - @repeated_fields_setup = true - end - end - ## # Constructor # def initialize(values={}) @values = {} - self.class.initialize_unready_fields - self.class.setup_repeated_field_arrays - self.class.repeated_fields.each do |field| @values[field.name] = Field::FieldArray.new(field) end From 1201dbe8461712caecc62041b1b948940ce864eb Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Sep 2012 15:18:30 -0600 Subject: [PATCH 0102/1191] remove field_proxy and have add repeated field definitions to repeated fields when defined --- lib/protobuf/field.rb | 3 +- lib/protobuf/field/base_field.rb | 4 --- lib/protobuf/field/field_proxy.rb | 53 ------------------------------- lib/protobuf/message.rb | 2 ++ 4 files changed, 3 insertions(+), 59 deletions(-) delete mode 100644 lib/protobuf/field/field_proxy.rb diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index 5228cc45..42dabfd5 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -19,7 +19,6 @@ require 'protobuf/field/sfixed64_field' require 'protobuf/field/fixed32_field' require 'protobuf/field/fixed64_field' -require 'protobuf/field/field_proxy' require 'protobuf/field/extension_fields' module Protobuf @@ -43,7 +42,7 @@ module Field }.freeze def self.build(message_class, rule, type, name, tag, options={}) - field_class = ::Protobuf::Field::PREDEFINED_TYPES.fetch(type, ::Protobuf::Field::FieldProxy) + field_class = ::Protobuf::Field::PREDEFINED_TYPES.fetch(type, type) field_class.new(message_class, rule, type, name, tag, options) end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 579a9546..40d39cb1 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -64,10 +64,6 @@ def message? @_message = (self.class < ::Protobuf::Field::MessageField) end - def ready? - true - end - def initialized?(message_instance) value = message_instance.__send__(@name) case @rule diff --git a/lib/protobuf/field/field_proxy.rb b/lib/protobuf/field/field_proxy.rb deleted file mode 100644 index 3f76a653..00000000 --- a/lib/protobuf/field/field_proxy.rb +++ /dev/null @@ -1,53 +0,0 @@ -module Protobuf - module Field - class FieldProxy - - ## - # Constructor - # - def initialize(message_class, rule, type, name, tag, options) - @message_class, @rule, @type, @name, @tag, @options = - message_class, rule, type, name, tag, options - end - - ## - # Public Instance Methods - # - def ready? - false - end - - def setup - type = typename_to_class(@message_class, @type) - field_class = \ - if type < Enum - EnumField - elsif type < Message - MessageField - else - raise TypeError, type.inspect - end - field_class.new(@message_class, @rule, type, @name, @tag, @options) - end - - private - - def typename_to_class(message_class, type) - names = type.to_s.split('::').map { |s| s.camelize } - outer = message_class.to_s.split('::') - args = (Object.method(:const_defined?).arity == 1) ? [] : [false] - while - mod = outer.empty? ? Object : eval(outer.join('::')) - mod = names.inject(mod) {|m, s| - m && m.const_defined?(s, *args) && m.const_get(s) - } - break if mod - raise NameError.new("type not found: #{type}", type) if outer.empty? - outer.pop - end - mod - end - - end - end -end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6faaf4d8..1af2bb06 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -52,6 +52,7 @@ def self.repeated(type, name, tag, options={}) def self.define_field(rule, type, fname, tag, options) field_hash = options[:extension] ? extension_fields : fields field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name + repeated_collection = options[:extension] ? repeated_extension_fields : repeated_fields if field_hash.keys.include?(tag) raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! @@ -59,6 +60,7 @@ def self.define_field(rule, type, fname, tag, options) field_definition = Field.build(self, rule, type, fname, tag, options) field_name_hash[fname.to_sym] = field_definition + repeated_collection << field_definition if field_definition.repeated? field_hash[tag] = field_definition end From b8057f5a135c6d3d88864465626599057822373b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Sep 2012 19:00:04 -0600 Subject: [PATCH 0103/1191] update rprotoc to have an actual argc; update RubyGenerator to paren the calls for field definitions --- Rakefile | 2 +- bin/rprotoc | 12 +++-- ext/ruby_generator/RubyGenerator.cpp | 5 +- spec/proto/test.pb.rb | 73 ++++++++++++++++++---------- 4 files changed, 59 insertions(+), 33 deletions(-) diff --git a/Rakefile b/Rakefile index 67c1a92d..6af33f25 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ $:.push File.expand_path("./", File.dirname(__FILE__)) $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "bundler/gem_tasks" -require "benchmark/tasks" +# require "benchmark/tasks" require 'rspec/core/rake_task' diff --git a/bin/rprotoc b/bin/rprotoc index c8e6eb5f..19c5d2aa 100755 --- a/bin/rprotoc +++ b/bin/rprotoc @@ -23,15 +23,17 @@ module Protobuf module RProtoC extend FFI::Library ffi_lib ::GENERATOR_FILE_PATH - attach_function :_rprotoc_extern, [:int32, :pointer], :int32 + attach_function :_rprotoc_extern, [:int, :pointer], :int32 def self.compile_proto(args) + GC.disable # Don't want strings to be GC'd while protoc has them + args = args.dup args.unshift("rprotoc") args << "--help" if args.size == 1 ptr_params = [] args.each do |param| - ptr_params << ::FFI::MemoryPointer.from_string(param) + ptr_params << ::FFI::MemoryPointer.from_string(param.dup) end ptr_params << nil @@ -40,9 +42,11 @@ module Protobuf argv[index].put_pointer(0, param_pointer) end - self._rprotoc_extern(argv.size, argv) + self._rprotoc_extern(ptr_params.compact.size, argv) + ensure + GC.enable end end end -::Protobuf::RProtoC.compile_proto(ARGV.dup) +::Protobuf::RProtoC.compile_proto(ARGV) diff --git a/ext/ruby_generator/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp index a7bf4ca9..36406bb3 100644 --- a/ext/ruby_generator/RubyGenerator.cpp +++ b/ext/ruby_generator/RubyGenerator.cpp @@ -167,7 +167,6 @@ void RubyGenerator::PrintMessageFields(const Descriptor* descriptor) const { PrintEnumsForDescriptor(descriptor, true); PrintMessagesForDescriptor(descriptor, true); - PrintNewLine(); } // Print the given FieldDescriptor to the Message DSL methods. @@ -255,7 +254,7 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { } printer_->Print(data, - "$message_class$.$field_label$" + "$message_class$.$field_label$(" "$data_type$, " ":$field_name$, " "$tag_number$" @@ -263,7 +262,7 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { "$packed_opt$" "$deprecated_opt$" "$extension_opt$" - "\n"); + ")\n"); } diff --git a/spec/proto/test.pb.rb b/spec/proto/test.pb.rb index 8337b181..7fbc2ebb 100644 --- a/spec/proto/test.pb.rb +++ b/spec/proto/test.pb.rb @@ -1,31 +1,54 @@ -### Generated by rprotoc. DO NOT EDIT! -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' +require 'protobuf/rpc/service' module Spec module Proto - class StatusType < ::Protobuf::Enum - define :PENDING, 0 - define :ENABLED, 1 - define :DISABLED, 2 - define :DELETED, 3 - end - class ResourceFindRequest < ::Protobuf::Message - required :string, :name, 1 - optional :bool, :active, 2 - end - class Resource < ::Protobuf::Message - required :string, :name, 1 - optional :int64, :date_created, 2 - optional :StatusType, :status, 3 - repeated :StatusType, :repeated_enum, 4 - end - class Nested < ::Protobuf::Message - optional :string, :name, 1 - optional :Resource, :resource, 2 - repeated :Resource, :multiple_resources, 3 - optional :StatusType, :status, 4 + ## + # Enum Classes + # + class StatusType < ::Protobuf::Enum; end + + ## + # Message Classes + # + class ResourceFindRequest < ::Protobuf::Message; end + class Resource < ::Protobuf::Message; end + class Nested < ::Protobuf::Message; end + + ## + # Enum Values + # + ::Spec::Proto::StatusType.define :PENDING, 0 + ::Spec::Proto::StatusType.define :ENABLED, 1 + ::Spec::Proto::StatusType.define :DISABLED, 2 + ::Spec::Proto::StatusType.define :DELETED, 3 + + + ## + # Message Fields + # + ::Spec::Proto::ResourceFindRequest.required(::Protobuf::Field::StringField, :name, 1) + ::Spec::Proto::ResourceFindRequest.optional(::Protobuf::Field::BoolField, :active, 2) + + ::Spec::Proto::Resource.required(::Protobuf::Field::StringField, :name, 1) + ::Spec::Proto::Resource.optional(::Protobuf::Field::Int64Field, :date_created, 2) + ::Spec::Proto::Resource.optional(::Spec::Proto::StatusType, :status, 3) + ::Spec::Proto::Resource.repeated(::Spec::Proto::StatusType, :repeated_enum, 4) + + ::Spec::Proto::Nested.optional(::Protobuf::Field::StringField, :name, 1) + ::Spec::Proto::Nested.optional(::Spec::Proto::Resource, :resource, 2) + ::Spec::Proto::Nested.repeated(::Spec::Proto::Resource, :multiple_resources, 3) + ::Spec::Proto::Nested.optional(::Spec::Proto::StatusType, :status, 4) + + + ## + # Services + # + class TestService < ::Protobuf::Service + rpc :find, ::Spec::Proto::ResourceFindRequest, ::Spec::Proto::Resource end end end From 230d0557964451b57bdf20ca8cd4e478805496a8 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Sep 2012 19:59:08 -0600 Subject: [PATCH 0104/1191] recompile proto messages for specs and for rpc interaction and add Rpc to namespace for protobuf service --- Gemfile.lock | 5 ++ examples/addressbook.pb.rb | 4 +- ext/ruby_generator/RubyGenerator.cpp | 2 +- lib/protobuf/{message => }/enum.rb | 2 - lib/protobuf/field.rb | 43 +++++++----- lib/protobuf/message.rb | 3 +- lib/protobuf/rpc/rpc.pb.rb | 101 +++++++++++++++++++-------- proto/rpc.pb.rb | 48 +++++++++++++ protobuf.gemspec | 1 + spec/proto/test.pb.rb | 2 +- test/proto/types.pb.rb | 2 +- test/test_addressbook.rb | 2 +- test/test_enum_value.rb | 2 +- test/test_standard_message.rb | 2 +- 14 files changed, 162 insertions(+), 57 deletions(-) rename lib/protobuf/{message => }/enum.rb (98%) create mode 100644 proto/rpc.pb.rb diff --git a/Gemfile.lock b/Gemfile.lock index bc37fd9c..c5d42518 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: protobuf (1.4.2) + activesupport ffi multi_json thor @@ -9,12 +10,16 @@ PATH GEM remote: http://rubygems.org/ specs: + activesupport (3.2.8) + i18n (~> 0.6) + multi_json (~> 1.0) coderay (1.0.7) diff-lcs (1.1.3) eventmachine (1.0.0) ffi (1.1.5) ffi-rzmq (0.9.6) ffi + i18n (0.6.1) method_source (0.8) multi_json (1.3.6) pry (0.9.10) diff --git a/examples/addressbook.pb.rb b/examples/addressbook.pb.rb index 95621914..552b55b8 100644 --- a/examples/addressbook.pb.rb +++ b/examples/addressbook.pb.rb @@ -26,7 +26,7 @@ # } require 'protobuf/message/message' -require 'protobuf/message/enum' +require 'protobuf/enum' require 'protobuf/message/extend' module Tutorial @@ -52,4 +52,4 @@ class AddressBook < ::Protobuf::Message defined_in __FILE__ repeated :Person, :person, 1 end -end \ No newline at end of file +end diff --git a/ext/ruby_generator/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp index 36406bb3..0302a949 100644 --- a/ext/ruby_generator/RubyGenerator.cpp +++ b/ext/ruby_generator/RubyGenerator.cpp @@ -344,7 +344,7 @@ void RubyGenerator::PrintService(const ServiceDescriptor* descriptor) const { map data; data["class_name"] = descriptor->name(); - printer_->Print(data, "class $class_name$ < ::Protobuf::Service"); + printer_->Print(data, "class $class_name$ < ::Protobuf::Rpc::Service"); PrintNewLine(); printer_->Indent(); diff --git a/lib/protobuf/message/enum.rb b/lib/protobuf/enum.rb similarity index 98% rename from lib/protobuf/message/enum.rb rename to lib/protobuf/enum.rb index 7c53dc84..a3e00c4c 100644 --- a/lib/protobuf/message/enum.rb +++ b/lib/protobuf/enum.rb @@ -23,8 +23,6 @@ def valid_tag?(tag) !! name_by_value(tag) end - private - def define(name, value) enum_value = EnumValue.new(self, name, value) const_set(name, enum_value) diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index 42dabfd5..63fd6c86 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -23,28 +23,35 @@ module Protobuf module Field - PREDEFINED_TYPES = { - :double => ::Protobuf::Field::DoubleField, - :float => ::Protobuf::Field::FloatField, - :int32 => ::Protobuf::Field::Int32Field, - :int64 => ::Protobuf::Field::Int64Field, - :uint32 => ::Protobuf::Field::Uint32Field, - :uint64 => ::Protobuf::Field::Uint64Field, - :sint32 => ::Protobuf::Field::Sint32Field, - :sint64 => ::Protobuf::Field::Sint64Field, - :fixed32 => ::Protobuf::Field::Fixed32Field, - :fixed64 => ::Protobuf::Field::Fixed64Field, - :sfixed32 => ::Protobuf::Field::Sfixed32Field, - :sfixed64 => ::Protobuf::Field::Sfixed64Field, - :string => ::Protobuf::Field::StringField, - :bytes => ::Protobuf::Field::BytesField, - :bool => ::Protobuf::Field::BoolField - }.freeze + PREDEFINED_TYPES = [ + ::Protobuf::Field::DoubleField, + ::Protobuf::Field::FloatField, + ::Protobuf::Field::Int32Field, + ::Protobuf::Field::Int64Field, + ::Protobuf::Field::Uint32Field, + ::Protobuf::Field::Uint64Field, + ::Protobuf::Field::Sint32Field, + ::Protobuf::Field::Sint64Field, + ::Protobuf::Field::Fixed32Field, + ::Protobuf::Field::Fixed64Field, + ::Protobuf::Field::Sfixed32Field, + ::Protobuf::Field::Sfixed64Field, + ::Protobuf::Field::StringField, + ::Protobuf::Field::BytesField, + ::Protobuf::Field::BoolField + ].freeze def self.build(message_class, rule, type, name, tag, options={}) - field_class = ::Protobuf::Field::PREDEFINED_TYPES.fetch(type, type) + field_class = type_message_or_enum(type) field_class.new(message_class, rule, type, name, tag, options) end + def self.type_message_or_enum(defined_type) + return defined_type if ::Protobuf::Field::PREDEFINED_TYPES.include?(defined_type) + return EnumField if defined_type < Enum + return MessageField if defined_type < Message + raise "lost in the wilderness #{defined_type}" + end + end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1af2bb06..3a0ab480 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,5 +1,6 @@ require 'set' require 'protobuf/field' +require 'protobuf/enum' require 'protobuf/message/decoder' require 'protobuf/message/encoder' require 'protobuf/message/protoable' @@ -60,7 +61,7 @@ def self.define_field(rule, type, fname, tag, options) field_definition = Field.build(self, rule, type, fname, tag, options) field_name_hash[fname.to_sym] = field_definition - repeated_collection << field_definition if field_definition.repeated? + repeated_collection << field_definition if rule == :repeated field_hash[tag] = field_definition end diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index 9874d3d0..7d07c0bf 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -73,35 +73,80 @@ # UNKNOWN_HOST = 8; // Could not find supplied host # IO_ERROR = 9; // I/O error while communicating with server # } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' +require 'protobuf/message' module Protobuf module Socketrpc - class Request < ::Protobuf::Message - required :string, :service_name, 1 - required :string, :method_name, 2 - required :bytes, :request_proto, 3 - end - class Response < ::Protobuf::Message - optional :bytes, :response_proto, 1 - optional :string, :error, 2 - optional :bool, :callback, 3, :default => false - optional :ErrorReason, :error_reason, 4 - end - class ErrorReason < ::Protobuf::Enum - define :BAD_REQUEST_DATA, 0 - define :BAD_REQUEST_PROTO, 1 - define :SERVICE_NOT_FOUND, 2 - define :METHOD_NOT_FOUND, 3 - define :RPC_ERROR, 4 - define :RPC_FAILED, 5 - define :INVALID_REQUEST_PROTO, 6 - define :BAD_RESPONSE_PROTO, 7 - define :UNKNOWN_HOST, 8 - define :IO_ERROR, 9 - end + ## + # Enum Classes + # + class ErrorReason < ::Protobuf::Enum; end + + ## + # Message Classes + # + class Request < ::Protobuf::Message; end + class Response < ::Protobuf::Message; end + + ## + # Enum Values + # + ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_DATA, 0 + ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_PROTO, 1 + ::Protobuf::Socketrpc::ErrorReason.define :SERVICE_NOT_FOUND, 2 + ::Protobuf::Socketrpc::ErrorReason.define :METHOD_NOT_FOUND, 3 + ::Protobuf::Socketrpc::ErrorReason.define :RPC_ERROR, 4 + ::Protobuf::Socketrpc::ErrorReason.define :RPC_FAILED, 5 + ::Protobuf::Socketrpc::ErrorReason.define :INVALID_REQUEST_PROTO, 6 + ::Protobuf::Socketrpc::ErrorReason.define :BAD_RESPONSE_PROTO, 7 + ::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8 + ::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9 + + + ## + # Message Fields + # + ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1) + ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2) + ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::BytesField, :request_proto, 3) + + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1) + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2) + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false) + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4) + + end -end \ No newline at end of file +end + +#require 'protobuf/message/message' +#require 'protobuf/message/enum' +#require 'protobuf/message/extend' +# +#module Protobuf +# module Socketrpc +# class Request < ::Protobuf::Message +# required :string, :service_name, 1 +# required :string, :method_name, 2 +# required :bytes, :request_proto, 3 +# end +# class Response < ::Protobuf::Message +# optional :bytes, :response_proto, 1 +# optional :string, :error, 2 +# optional :bool, :callback, 3, :default => false +# optional :ErrorReason, :error_reason, 4 +# end +# class ErrorReason < ::Protobuf::Enum +# define :BAD_REQUEST_DATA, 0 +# define :BAD_REQUEST_PROTO, 1 +# define :SERVICE_NOT_FOUND, 2 +# define :METHOD_NOT_FOUND, 3 +# define :RPC_ERROR, 4 +# define :RPC_FAILED, 5 +# define :INVALID_REQUEST_PROTO, 6 +# define :BAD_RESPONSE_PROTO, 7 +# define :UNKNOWN_HOST, 8 +# define :IO_ERROR, 9 +# end +# end +#end diff --git a/proto/rpc.pb.rb b/proto/rpc.pb.rb new file mode 100644 index 00000000..eca46619 --- /dev/null +++ b/proto/rpc.pb.rb @@ -0,0 +1,48 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Protobuf + module Socketrpc + ## + # Enum Classes + # + class ErrorReason < ::Protobuf::Enum; end + + ## + # Message Classes + # + class Request < ::Protobuf::Message; end + class Response < ::Protobuf::Message; end + + ## + # Enum Values + # + ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_DATA, 0 + ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_PROTO, 1 + ::Protobuf::Socketrpc::ErrorReason.define :SERVICE_NOT_FOUND, 2 + ::Protobuf::Socketrpc::ErrorReason.define :METHOD_NOT_FOUND, 3 + ::Protobuf::Socketrpc::ErrorReason.define :RPC_ERROR, 4 + ::Protobuf::Socketrpc::ErrorReason.define :RPC_FAILED, 5 + ::Protobuf::Socketrpc::ErrorReason.define :INVALID_REQUEST_PROTO, 6 + ::Protobuf::Socketrpc::ErrorReason.define :BAD_RESPONSE_PROTO, 7 + ::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8 + ::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9 + + + ## + # Message Fields + # + ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1) + ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2) + ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::BytesField, :request_proto, 3) + + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1) + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2) + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false) + ::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4) + + + end +end diff --git a/protobuf.gemspec b/protobuf.gemspec index 69e035dc..2abe3401 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |s| s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') end + s.add_dependency 'activesupport' s.add_dependency 'ffi' s.add_dependency 'multi_json' s.add_dependency 'thor' diff --git a/spec/proto/test.pb.rb b/spec/proto/test.pb.rb index 7fbc2ebb..b0cd0dbb 100644 --- a/spec/proto/test.pb.rb +++ b/spec/proto/test.pb.rb @@ -47,7 +47,7 @@ class Nested < ::Protobuf::Message; end ## # Services # - class TestService < ::Protobuf::Service + class TestService < ::Protobuf::Rpc::Service rpc :find, ::Spec::Proto::ResourceFindRequest, ::Spec::Proto::Resource end end diff --git a/test/proto/types.pb.rb b/test/proto/types.pb.rb index f01d30d0..3bc6f0e2 100644 --- a/test/proto/types.pb.rb +++ b/test/proto/types.pb.rb @@ -81,4 +81,4 @@ class RepeatedTypes < ::Protobuf::Message repeated :sfixed64, :type15, 15 end end -end \ No newline at end of file +end diff --git a/test/test_addressbook.rb b/test/test_addressbook.rb index cc04e5f4..35660b86 100644 --- a/test/test_addressbook.rb +++ b/test/test_addressbook.rb @@ -1,6 +1,6 @@ require 'test/unit' require 'protobuf/message/message' -require 'protobuf/message/enum' +require 'protobuf/enum' require 'test/proto/addressbook.pb' class AddressbookTest < Test::Unit::TestCase diff --git a/test/test_enum_value.rb b/test/test_enum_value.rb index 2af2e80f..59f5269a 100644 --- a/test/test_enum_value.rb +++ b/test/test_enum_value.rb @@ -1,6 +1,6 @@ require 'test/unit' require 'protobuf/message/message' -require 'protobuf/message/enum' +require 'protobuf/enum' require 'test/proto/addressbook.pb' require 'test/proto/addressbook_base.pb' diff --git a/test/test_standard_message.rb b/test/test_standard_message.rb index 9f26d324..44e97ce6 100644 --- a/test/test_standard_message.rb +++ b/test/test_standard_message.rb @@ -1,6 +1,6 @@ require 'test/unit' require 'protobuf/message/message' -require 'protobuf/message/enum' +require 'protobuf/enum' require 'test/proto/addressbook.pb' class StandardMessageTest < Test::Unit::TestCase From e5cd147b3a639fcb9adcb55fa814698c65a14f96 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Sep 2012 11:49:00 -0600 Subject: [PATCH 0105/1191] remove precaching of definitions now that setup/ready is gone --- bin/rpc_server | 7 ------- lib/protobuf/message.rb | 7 ------- 2 files changed, 14 deletions(-) diff --git a/bin/rpc_server b/bin/rpc_server index e9dbc2c4..47e67aee 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -30,7 +30,6 @@ class RpcServer < ::Thor option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Raw Socket Server Mode.' option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for client and server connections (they must be used together).' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' - option :pre_cache_definitions, :type => :boolean, :default => false, :desc => 'Enable/Disable Message class pre-caching.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :gc_pause_serialization, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during serialization.' @@ -47,7 +46,6 @@ class RpcServer < ::Thor unless @start_aborted say 'start was not aborted', :yellow require_application!(app_file) - pre_cache_application_protos! if options.pre_cache_definitions? configure_process_name(app_file) start_server! else @@ -131,11 +129,6 @@ class RpcServer < ::Thor trap(:TERM, &trap_block) end - def pre_cache_application_protos! - say 'pre-caching app protos', :yellow - ::Protobuf::Message.pre_cache_class_definitions - end - def require_application!(app_file) say 'requiring app file', :yellow require app_file diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 3a0ab480..582f214e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -14,13 +14,6 @@ def self.inherited(klass) @_children << klass end - def self.pre_cache_class_definitions - @_children ||= Set.new - @_children.each do |child_class| - child_class.new - end - end - def self.all_fields @all_fields ||= begin fields_hash = fields.merge(extension_fields) From 55fadbf3fd85bb0cc785fa2e45889c061186bae9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Sep 2012 11:56:03 -0600 Subject: [PATCH 0106/1191] remove protoable module now that definitions are in cpp compiler --- lib/protobuf/enum.rb | 3 --- lib/protobuf/message.rb | 3 --- lib/protobuf/message/protoable.rb | 38 ------------------------------- 3 files changed, 44 deletions(-) delete mode 100644 lib/protobuf/message/protoable.rb diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index a3e00c4c..3968c37b 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,11 +1,8 @@ require 'delegate' -require 'protobuf/message/protoable' module Protobuf class Enum class << self - include Protoable - attr_reader :values def name_by_value(value) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 582f214e..62d0aa71 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -3,12 +3,9 @@ require 'protobuf/enum' require 'protobuf/message/decoder' require 'protobuf/message/encoder' -require 'protobuf/message/protoable' module Protobuf class Message - extend ::Protobuf::Protoable - def self.inherited(klass) @_children ||= Set.new @_children << klass diff --git a/lib/protobuf/message/protoable.rb b/lib/protobuf/message/protoable.rb deleted file mode 100644 index 3ef8b95c..00000000 --- a/lib/protobuf/message/protoable.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Protobuf - module Protoable - def defined_filenames - @defined_filenames ||= [] - end - - def defined_in(filename) - path = File.expand_path(filename) - defined_filenames << path unless defined_filenames.include?(path) - end - - def proto_filenames - defined_filenames.map do |filename| - retrieve_header(File.read(filename)).first - end - end - - def proto_contents - #TODO: temporary implementation because the result includes not only this message but also all messages - ret = {} - defined_filenames.each do |filename| - header = retrieve_header(File.read(filename)) - ret[header.first] = header.last - end - ret - end - - def retrieve_header(contents) - if contents =~ /### Generated by rprotoc\. DO NOT EDIT!\n### \n((# .*\n)+)/ - proto_filename = $1 - proto_contents = $2.gsub(/^# /, '') - [proto_filename, proto_contents] - else - [nil, nil] - end - end - end -end From 0c996bd25b7d4b456f851f8e10cc4f9505c32405 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Sep 2012 12:09:07 -0600 Subject: [PATCH 0107/1191] remove old comment of protobuf definition --- lib/protobuf/rpc/rpc.pb.rb | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index 7d07c0bf..f7ac8f8e 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -102,7 +102,6 @@ class Response < ::Protobuf::Message; end ::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8 ::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9 - ## # Message Fields # @@ -115,38 +114,5 @@ class Response < ::Protobuf::Message; end ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false) ::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4) - end end - -#require 'protobuf/message/message' -#require 'protobuf/message/enum' -#require 'protobuf/message/extend' -# -#module Protobuf -# module Socketrpc -# class Request < ::Protobuf::Message -# required :string, :service_name, 1 -# required :string, :method_name, 2 -# required :bytes, :request_proto, 3 -# end -# class Response < ::Protobuf::Message -# optional :bytes, :response_proto, 1 -# optional :string, :error, 2 -# optional :bool, :callback, 3, :default => false -# optional :ErrorReason, :error_reason, 4 -# end -# class ErrorReason < ::Protobuf::Enum -# define :BAD_REQUEST_DATA, 0 -# define :BAD_REQUEST_PROTO, 1 -# define :SERVICE_NOT_FOUND, 2 -# define :METHOD_NOT_FOUND, 3 -# define :RPC_ERROR, 4 -# define :RPC_FAILED, 5 -# define :INVALID_REQUEST_PROTO, 6 -# define :BAD_RESPONSE_PROTO, 7 -# define :UNKNOWN_HOST, 8 -# define :IO_ERROR, 9 -# end -# end -#end From c414708ed7ad77c0e7bc80fd4ecaab911e15de71 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Sep 2012 20:26:23 -0600 Subject: [PATCH 0108/1191] remove class << self as means of class methods --- lib/protobuf/field/base_field.rb | 1 - lib/protobuf/field/varint_field.rb | 44 ++++++++++++++++-------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 40d39cb1..83b0864a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -147,7 +147,6 @@ def min self.class.min end - def to_s "#{@rule} #{@type} #{@name} = #{@tag} #{@default ? "[default=#{@default.inspect}]" : ''}" end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 3d5b13d8..d2668d0b 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -10,32 +10,36 @@ class VarintField < BaseField UINT32_MAX = 2**32 - 1 UINT64_MAX = 2**64 - 1 - class << self - def default - 0 - end + ## + # Class Methods + # + def self.default + 0 + end - def decode(bytes) - value = 0 - bytes.each_with_index do |byte, index| - value |= byte << (7 * index) - end - value + def self.decode(bytes) + value = 0 + bytes.each_with_index do |byte, index| + value |= byte << (7 * index) end + value + end - def encode(value) - raise RangeError, "#{value} is negative" if value < 0 - return [value].pack('C') if value < 128 - bytes = [] - until value == 0 - bytes << (0x80 | (value & 0x7f)) - value >>= 7 - end - bytes[-1] &= 0x7f - bytes.pack('C*') + def self.encode(value) + raise RangeError, "#{value} is negative" if value < 0 + return [value].pack('C') if value < 128 + bytes = [] + until value == 0 + bytes << (0x80 | (value & 0x7f)) + value >>= 7 end + bytes[-1] &= 0x7f + bytes.pack('C*') end + ## + # Public Instance Methods + # def wire_type WireType::VARINT end From cf5124fcf6be4308a3404bfa91c709f705766c53 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Sep 2012 20:32:15 -0600 Subject: [PATCH 0109/1191] add back benchmark tasks --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 6af33f25..67c1a92d 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ $:.push File.expand_path("./", File.dirname(__FILE__)) $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "bundler/gem_tasks" -# require "benchmark/tasks" +require "benchmark/tasks" require 'rspec/core/rake_task' From 1d0ec3fe1ec65a1868874cf0b37a83abfc6d4f36 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 1 Oct 2012 10:01:33 -0600 Subject: [PATCH 0110/1191] add profiling support to benchmarks; use constants for setting encodings; reduce number of string objects created and collected during serialization --- Gemfile.lock | 2 ++ lib/protobuf/field/base_field.rb | 18 ++++++++++-------- lib/protobuf/field/bytes_field.rb | 4 ++-- lib/protobuf/field/fixed32_field.rb | 2 +- lib/protobuf/field/fixed64_field.rb | 2 +- lib/protobuf/field/message_field.rb | 2 +- lib/protobuf/field/sfixed32_field.rb | 2 +- lib/protobuf/field/sfixed64_field.rb | 2 +- lib/protobuf/field/string_field.rb | 4 +++- lib/protobuf/field/varint_field.rb | 14 +++++++------- lib/protobuf/message.rb | 27 +++++---------------------- protobuf.gemspec | 1 + spec/benchmark/tasks.rb | 24 +++++++++++++++++++++++- 13 files changed, 58 insertions(+), 46 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c5d42518..a83d6604 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,6 +22,7 @@ GEM i18n (0.6.1) method_source (0.8) multi_json (1.3.6) + perftools.rb (2.0.0) pry (0.9.10) coderay (~> 1.0.5) method_source (~> 0.8) @@ -53,6 +54,7 @@ PLATFORMS DEPENDENCIES eventmachine ffi-rzmq + perftools.rb protobuf! pry pry-nav diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 83b0864a..694608d8 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -7,7 +7,7 @@ class BaseField ## # Attributes # - attr_reader :message_class, :rule, :type, :name, :tag, :default, :default_value + attr_reader :message_class, :rule, :type, :name, :tag, :default, :default_value, :setter_method_name, :getter_method_name ## # Class Methods @@ -23,6 +23,8 @@ def initialize(message_class, rule, type, name, tag, options) @message_class, @rule, @type, @name, @tag = \ message_class, rule, type, name, tag + @getter_method_name = name + @setter_method_name = "#{name}=".to_sym @default = options.delete(:default) @extension = options.delete(:extension) @packed = repeated? && options.delete(:packed) @@ -65,7 +67,7 @@ def message? end def initialized?(message_instance) - value = message_instance.__send__(@name) + value = message_instance.__send__(getter_method_name) case @rule when :required then ! value.nil? && (! kind_of?(MessageField) || value.initialized?) @@ -79,7 +81,7 @@ def initialized?(message_instance) # Decode +bytes+ and pass to +message_instance+. def set(message_instance, bytes) if packed? - array = message_instance.__send__(@name) + array = message_instance.__send__(getter_method_name) method = \ case wire_type when WireType::FIXED32 then :read_fixed32 @@ -93,9 +95,9 @@ def set(message_instance, bytes) else value = decode(bytes) if repeated? - message_instance.__send__(@name) << value + message_instance.__send__(getter_method_name) << value else - message_instance.__send__("#{@name}=", value) + message_instance.__send__(setter_method_name, value) end end end @@ -168,7 +170,7 @@ def define_accessor def define_array_setter field = self @message_class.class_eval do - define_method("#{field.name}=") do |val| + define_method(field.setter_method_name) do |val| @values[field.name].replace(val) end end @@ -177,7 +179,7 @@ def define_array_setter def define_getter field = self @message_class.class_eval do - define_method(field.name) do + define_method(field.getter_method_name) do @values.fetch(field.name, field.default_value) end end @@ -186,7 +188,7 @@ def define_getter def define_setter field = self @message_class.class_eval do - define_method("#{field.name}=") do |val| + define_method(field.setter_method_name) do |val| if val.nil? @values.delete(field.name) elsif field.acceptable?(val) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index af6a244a..153b124e 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -18,7 +18,7 @@ def acceptable?(val) end def decode(bytes) - bytes.force_encoding('ASCII-8BIT') if bytes.respond_to?(:force_encoding) + bytes.force_encoding(::Protobuf::Message::STRING_ENCODING) if bytes.respond_to?(:force_encoding) bytes end @@ -27,7 +27,7 @@ def encode(value) value = value.serialize_to_string else value = value.dup - value.force_encoding('ASCII-8BIT') if value.respond_to?(:force_encoding) + value.force_encoding(::Protobuf::Message::STRING_ENCODING) if value.respond_to?(:force_encoding) end string_size = VarintField.encode(value.size) diff --git a/lib/protobuf/field/fixed32_field.rb b/lib/protobuf/field/fixed32_field.rb index aa3d458d..7311df82 100644 --- a/lib/protobuf/field/fixed32_field.rb +++ b/lib/protobuf/field/fixed32_field.rb @@ -4,7 +4,7 @@ module Protobuf module Field class Fixed32Field < Uint32Field def wire_type - ::WireType::FIXED32 + ::Protobuf::WireType::FIXED32 end def decode(bytes) diff --git a/lib/protobuf/field/fixed64_field.rb b/lib/protobuf/field/fixed64_field.rb index 41643464..7add6f2c 100644 --- a/lib/protobuf/field/fixed64_field.rb +++ b/lib/protobuf/field/fixed64_field.rb @@ -4,7 +4,7 @@ module Protobuf module Field class Fixed64Field < Uint64Field def wire_type - ::WireType::FIXED64 + ::Protobuf::WireType::FIXED64 end def decode(bytes) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 6ce64d87..e89102af 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -24,7 +24,7 @@ def encode(value) end def wire_type - ::WireType::LENGTH_DELIMITED + ::Protobuf::WireType::LENGTH_DELIMITED end private diff --git a/lib/protobuf/field/sfixed32_field.rb b/lib/protobuf/field/sfixed32_field.rb index 3c2f55a4..82c483a1 100644 --- a/lib/protobuf/field/sfixed32_field.rb +++ b/lib/protobuf/field/sfixed32_field.rb @@ -4,7 +4,7 @@ module Protobuf module Field class Sfixed32Field < Int32Field def wire_type - ::WireType::FIXED32 + ::Protobuf::WireType::FIXED32 end def decode(bytes) diff --git a/lib/protobuf/field/sfixed64_field.rb b/lib/protobuf/field/sfixed64_field.rb index 0ba7f1d9..99ad1430 100644 --- a/lib/protobuf/field/sfixed64_field.rb +++ b/lib/protobuf/field/sfixed64_field.rb @@ -4,7 +4,7 @@ module Protobuf module Field class Sfixed64Field < Int64Field def wire_type - ::WireType::FIXED64 + ::Protobuf::WireType::FIXED64 end def decode(bytes) diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index da56e2e1..fac8c5af 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -3,8 +3,10 @@ module Protobuf module Field class StringField < BytesField + ENCODING = 'UTF-8'.freeze + def decode(bytes) - bytes.force_encoding('UTF-8') if bytes.respond_to?(:force_encoding) + bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) if bytes.respond_to?(:force_encoding) bytes end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index d2668d0b..2c1a252e 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -40,8 +40,10 @@ def self.encode(value) ## # Public Instance Methods # - def wire_type - WireType::VARINT + def acceptable?(val) + raise TypeError, val.class.name unless val.is_a?(Integer) + raise RangeError if val < min || max < val + true end def decode(value) @@ -52,12 +54,10 @@ def encode(value) self.class.encode(value) end - def acceptable?(val) - raise TypeError, val.class.name unless val.is_a?(Integer) - raise RangeError if val < min || max < val - true + def wire_type + ::Protobuf::WireType::VARINT end + end end end - diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 62d0aa71..e147d0ca 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -6,6 +6,8 @@ module Protobuf class Message + STRING_ENCODING = "ASCII-8BIT".freeze + def self.inherited(klass) @_children ||= Set.new @_children << klass @@ -244,16 +246,6 @@ def parse_from_string(string) parse_from(StringIO.new(string)) end - def parse_from_file(filename) - if filename.is_a?(File) - parse_from(filename) - else - File.open(filename, 'rb') do |f| - parse_from(f) - end - end - end - def parse_from(stream) Decoder.decode(stream, self) end @@ -262,21 +254,11 @@ def serialize_to_string(string='') io = StringIO.new(string) serialize_to(io) result = io.string - result.force_encoding('ASCII-8BIT') if result.respond_to?(:force_encoding) + result.force_encoding(::Protobuf::Message::STRING_ENCODING) if result.respond_to?(:force_encoding) result end alias to_s serialize_to_string - def serialize_to_file(filename) - if filename.is_a?(File) - serialize_to(filename) - else - File.open(filename, 'wb') do |f| - serialize_to(f) - end - end - end - def serialize_to(stream) Encoder.encode(stream, self) end @@ -296,7 +278,8 @@ def [](tag_or_name) def []=(tag_or_name, value) if field = get_field(tag_or_name) || get_ext_field(tag_or_name) - __send__("#{field.name}=", value) + # __send__("#{field.name}=", value) + __send__(field.setter_method_name, value) else raise NoMethodError, "No such field: #{tag_or_name.inspect}" end diff --git a/protobuf.gemspec b/protobuf.gemspec index 2abe3401..b0201813 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -29,6 +29,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'eventmachine' s.add_development_dependency 'ffi-rzmq' + s.add_development_dependency 'perftools.rb' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 9dc4d698..de26131a 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,9 +1,10 @@ require 'benchmark' require 'helper/all' require 'proto/test_service_impl' +require 'perftools' # Including a way to turn on debug logger for spec runs -if ENV["DEBUG"] +if ENV["DEBUG"] puts 'debugging' debug_log = File.expand_path('../debug_bench.log', File.dirname(__FILE__) ) Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) @@ -119,6 +120,27 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) zmq_client_zmq_server(args[:number], args[:length]) end + desc "benchmark ZMQ client with ZMQ server and profile" + task :zmq_profile, [:number, :length, :profile_output] do |t, args| + args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}") + ::PerfTools::CpuProfiler.start(args[:profile_output]) do + zmq_client_zmq_server(args[:number], args[:length]) + end + + puts args[:profile_output] + end + + desc "benchmark Protobuf Message #new" + task :profile_protobuf_new, [:number, :profile_output] do |t, args| + args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") + create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } + ::PerfTools::CpuProfiler.start(args[:profile_output]) do + args[:number].to_i.times { Spec::Proto::Resource.new(create_params) } + end + + puts args[:profile_output] + end + desc "benchmark EventMachine client with EventMachine server" task :em_client_em_server, [:number, :length] do |t, args| args.with_defaults(:number => 1000, :length => 100) From b04c0df446244f85b4421bffd0c1ba029ab30420 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 1 Oct 2012 11:24:03 -0600 Subject: [PATCH 0111/1191] Finish rpc_server rewrite Add Configuration DSL to top-level Protobuf module for settings such as GC and connector type. Remove usage of environment vars PB_CLIENT_TYPE, PB_SERVER_TYPE and their associated constants in favor of using the appropriate mode switch when running rpc_server, or using a different require in the Gemfile (for client-side) usage: rpc_server --zmq myapp.rb gem 'protobuf', :require => 'protobuf/zmq' Refactored specs whose usage was dependent on constants PB_CLIENT_TYPE, PB_SERVER_TYPE and Protobuf::ClientType. Restructured the spec directory, removing "spec/unit/*" in favor of placing the files directly in "spec/lib/protobuf/*". --- bin/rpc_server | 159 +------------- lib/protobuf.rb | 87 +++++--- lib/protobuf/cli.rb | 176 +++++++++++++++ lib/protobuf/common/logger.rb | 22 +- lib/protobuf/evented.rb | 22 ++ lib/protobuf/rpc/client.rb | 52 ++--- lib/protobuf/rpc/connector.rb | 25 +-- lib/protobuf/rpc/connectors/eventmachine.rb | 26 +-- lib/protobuf/rpc/server.rb | 17 +- lib/protobuf/rpc/servers/evented_runner.rb | 8 +- lib/protobuf/rpc/servers/socket/server.rb | 3 +- lib/protobuf/socket.rb | 22 ++ lib/protobuf/zmq.rb | 21 ++ spec/benchmark/tasks.rb | 38 ++-- spec/functional/socket_server_spec.rb | 47 ++-- spec/functional/zmq_server_spec.rb | 47 ++-- spec/helper/all.rb | 7 - spec/lib/protobuf/cli_spec.rb | 200 ++++++++++++++++++ .../protobuf}/common/logger_spec.rb | 0 spec/lib/protobuf/common/util_spec.rb | 17 ++ .../protobuf/message}/enum_spec.rb | 0 .../protobuf/message}/message_spec.rb | 0 .../{unit => lib/protobuf}/rpc/client_spec.rb | 9 +- spec/lib/protobuf/rpc/connector_spec.rb | 41 ++++ .../protobuf}/rpc/connectors/base_spec.rb | 36 ++-- .../protobuf}/rpc/connectors/common_spec.rb | 40 ++-- .../connectors/eventmachine_client_spec.rb | 1 + .../protobuf}/rpc/connectors/socket_spec.rb | 17 +- .../protobuf}/rpc/connectors/zmq_spec.rb | 2 +- .../rpc/servers/evented_server_spec.rb | 5 +- .../rpc/servers/socket_server_spec.rb | 27 +-- .../protobuf}/rpc/servers/zmq/broker_spec.rb | 1 + .../protobuf}/rpc/servers/zmq/server_spec.rb | 1 + .../protobuf}/rpc/servers/zmq/util_spec.rb | 1 + .../protobuf}/rpc/servers/zmq/worker_spec.rb | 1 + .../protobuf}/rpc/service_spec.rb | 0 spec/spec_helper.rb | 24 +-- spec/support/all.rb | 7 + spec/{helper => support}/server.rb | 12 +- spec/{helper => support}/silent_constants.rb | 4 + spec/support/test_app_file.rb | 2 + spec/{helper => support}/tolerance_matcher.rb | 0 spec/unit/rpc/connector_spec.rb | 31 --- spec/unit/rpc/connectors/eventmachine_spec.rb | 0 44 files changed, 785 insertions(+), 473 deletions(-) create mode 100644 lib/protobuf/cli.rb create mode 100644 lib/protobuf/evented.rb create mode 100644 lib/protobuf/socket.rb create mode 100644 lib/protobuf/zmq.rb delete mode 100644 spec/helper/all.rb create mode 100644 spec/lib/protobuf/cli_spec.rb rename spec/{unit => lib/protobuf}/common/logger_spec.rb (100%) create mode 100644 spec/lib/protobuf/common/util_spec.rb rename spec/{unit => lib/protobuf/message}/enum_spec.rb (100%) rename spec/{unit => lib/protobuf/message}/message_spec.rb (100%) rename spec/{unit => lib/protobuf}/rpc/client_spec.rb (97%) create mode 100644 spec/lib/protobuf/rpc/connector_spec.rb rename spec/{unit => lib/protobuf}/rpc/connectors/base_spec.rb (96%) rename spec/{unit => lib/protobuf}/rpc/connectors/common_spec.rb (82%) rename spec/{unit => lib/protobuf}/rpc/connectors/eventmachine_client_spec.rb (97%) rename spec/{unit => lib/protobuf}/rpc/connectors/socket_spec.rb (80%) rename spec/{unit => lib/protobuf}/rpc/connectors/zmq_spec.rb (95%) rename spec/{unit => lib/protobuf}/rpc/servers/evented_server_spec.rb (78%) rename spec/{unit => lib/protobuf}/rpc/servers/socket_server_spec.rb (67%) rename spec/{unit => lib/protobuf}/rpc/servers/zmq/broker_spec.rb (92%) rename spec/{unit => lib/protobuf}/rpc/servers/zmq/server_spec.rb (96%) rename spec/{unit => lib/protobuf}/rpc/servers/zmq/util_spec.rb (95%) rename spec/{unit => lib/protobuf}/rpc/servers/zmq/worker_spec.rb (94%) rename spec/{unit => lib/protobuf}/rpc/service_spec.rb (100%) create mode 100644 spec/support/all.rb rename spec/{helper => support}/server.rb (90%) rename spec/{helper => support}/silent_constants.rb (97%) create mode 100644 spec/support/test_app_file.rb rename spec/{helper => support}/tolerance_matcher.rb (100%) delete mode 100644 spec/unit/rpc/connector_spec.rb delete mode 100644 spec/unit/rpc/connectors/eventmachine_spec.rb diff --git a/bin/rpc_server b/bin/rpc_server index 47e67aee..cf396cf4 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -1,160 +1,5 @@ #!/usr/bin/env ruby -require 'thor' -require 'protobuf/version' -require 'protobuf/common/logger' -require 'protobuf/rpc/server' -require 'protobuf/rpc/servers/evented_runner' -require 'protobuf/rpc/servers/socket_runner' -require 'protobuf/rpc/servers/zmq_runner' +require 'protobuf/cli' +::Protobuf::CLI.start(ARGV) -class RpcServer < ::Thor - include ::Thor::Actions - - attr_accessor :runner, :start_aborted - - default_task :start - - desc 'start APP_FILE', 'Run the RPC server in the given mode, preloading the given APP_FILE. This is the default task.' - - option :env, :type => :string, :default => (ENV['RPC_SERVER_ENV'] || 'development'), :aliases => %w(-e), :desc => 'Environment to run the server (i.e. RAILS_ENV).' - option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-e), :desc => 'Host to bind.' - option :port, :type => :numeric, :default => 9595, :aliases => %w(-p), :desc => 'Port to bind.' - option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.' - option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' - option :log, :type => :string, :default => File.expand_path('./protobuf.log'), :aliases => %w(-l), :desc => 'Log file or device.' - 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/)' - option :client_type, :type => :boolean, :desc => 'Client Type to use (Socket or Zmq).' - option :server_type, :type => :boolean, :desc => 'Server Type to use (Socket or Zmq).' - option :client_socket, :type => :boolean, :aliases => %w(-c), :desc => 'Raw Socket Mode for client connections.' - option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Raw Socket Server Mode.' - option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for client and server connections (they must be used together).' - option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' - option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' - option :gc_pause_serialization, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during serialization.' - - def start(app_file) - say 'start to configure', :yellow - @start_aborted = false - require 'protobuf' - - configure_traps - configure_runner_mode - configure_gc - configure_logger - - unless @start_aborted - say 'start was not aborted', :yellow - require_application!(app_file) - configure_process_name(app_file) - start_server! - else - say 'start was aborted', :yellow - end - - rescue => e - msg = "ERROR: RPC Server failed to start: (#{e.class.name}) #{e.message}" - say msg, :red - $stderr.puts *(e.backtrace) - ::Protobuf::Logger.error { msg } - ::Protobuf::Logger.error { e.backtrace.join("\n") } - exit(1) - end - - desc 'version', 'Print ruby and protoc versions and exit.' - def version - $stdout.puts "Ruby Protobuf v#{::Protobuf::VERSION} (Google protoc v#{::Protobuf::PROTOC_VERSION})" - exit(0) - end - - no_tasks do - - # TODO need to figure out a better solution here - # dynamic const assignment is a no-go - def configure_gc - say 'configuring gc', :yellow - #::Protobuf::Rpc::GC_PAUSE_REQUEST = options.gc_pause_request? - # If we pause during request we don't need to pause in serialization - #::Protobuf::Rpc::GC_PAUSE_SERIALIZATION = (!options.gc_pause_request? && options.gc_pause_serialization?) - end - - def configure_logger - say 'configuring logger', :yellow - ::Protobuf::Logger.configure({ :file => options.log, - :level => options.debug? ? ::Logger::DEBUG : options.level }) - - # Output the server opts - ::Protobuf::Logger.debug { 'Debugging options:' } - ::Protobuf::Logger.debug { options.inspect } - end - - def configure_process_name(app_file) - say 'configuring process name', :yellow - $0 = "rpc_server #{options.host}:#{options.port} #{app_file}" - end - - # Used to ensure we set the PB_CLIENT_TYPE and PB_SERVER_TYPE to the same thing - # if one of them is set to Zmq - def configure_runner_mode - say 'configuring runner mode', :yellow - if ENV['PB_CLIENT_TYPE'] =~ /zmq/i - # make server and client types the same if we're using Zmq - # ENV['PB_SERVER_TYPE'] = ENV['PB_CLIENT_TYPE'] - @runner = ::Protobuf::Rpc::ZmqRunner - elsif ENV['PB_SERVER_TYPE'] =~ /zmq/i - # make server and client types the same if we're using Zmq - # ENV['PB_CLIENT_TYPE'] = ENV['PB_SERVER_TYPE'] - @runner = ::Protobuf::Rpc::ZmqRunner - elsif ENV['PB_SERVER_TYPE'] =~ /socket/i - @runner = ::Protobuf::Rpc::SocketRunner - else - @runner = ::Protobuf::Rpc::EventedRunner - end - end - - def configure_traps - say 'configuring traps', :yellow - trap_block = proc { - ::Protobuf::Logger.info { 'RPC Server shutting down...' } - @start_aborted = true - @runner.stop - ::Protobuf::Logger.info { 'Shutdown complete' } - } - - say 'registering INT', :blue - trap(:INT, &trap_block) - say 'registering QUIT', :blue - trap(:QUIT, &trap_block) - say 'registering TERM', :blue - trap(:TERM, &trap_block) - end - - def require_application!(app_file) - say 'requiring app file', :yellow - require app_file - rescue LoadError => e - say "Failed to load application file #{app_file}: #{e.message}", :red - puts *(e.backtrace) if options.debug? - exit(1) - end - - def runner_name - case @runner - when ::Protobuf::Rpc::ZmqRunner then "Zmq" - when ::Protobuf::Rpc::SocketRunner then "Socket" - else "Evented" - end - end - - def start_server! - say 'starting server', :yellow - @runner.run(options.dup) do - Protobuf::Logger.info { "pid #{::Process.pid} -- #{runner_name} RPC Server listening at #{options.host}:#{options.port} in #{options.env}" } - end - end - - end - -end - -::RpcServer.start(ARGV) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index be2d96cd..a34bf2c6 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -5,41 +5,62 @@ require 'active_support/all' module Protobuf -end -Protobuf::ClientType = ENV['PB_CLIENT_TYPE'] if ENV['PB_CLIENT_TYPE'] -Protobuf::ServerType = ENV['PB_SERVER_TYPE'] if ENV['PB_SERVER_TYPE'] + # See Protobuf#connector_type documentation. + VALID_CONNECTOR_TYPES = [ :socket, :zmq, :evented ].freeze -# Socket Client/Server loaded by default as it has no impact on cross-platform issues -require 'protobuf/rpc/servers/socket/server' -require 'protobuf/rpc/connectors/socket' -require 'protobuf/rpc/client' -require 'protobuf/rpc/service' + # Default is Socket as it has no external dependencies. + DEFAULT_CONNECTOR_TYPE = :socket -# When setting up a client -case -when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Asocket\Z/i then - #no-op -when defined?(Protobuf::ClientType) && Protobuf::ClientType =~ /\Azmq\Z/i then - require 'ffi-rzmq' - require 'protobuf/rpc/connectors/zmq' -else - Protobuf::ClientType = "EventMachine" - require 'eventmachine' - require 'protobuf/ext/eventmachine' - require 'protobuf/rpc/connectors/eventmachine' -end + module_function + + # GC Pause during server requests + # + # Boolean value to tell the server to disable + # the Garbage Collector when handling an rpc request. + # Once the request is completed, the GC is enabled again. + # This optomization provides a huge boost in speed to rpc requests. + def self.gc_pause_server_request + return @_gc_pause_server_request unless @_gc_pause_server_request.nil? + gc_pause_server_request = false + end + + def self.gc_pause_server_request=(value) + @_gc_pause_server_request = !!value + end + + # GC Pause during serializations (server-side only) + # + # Boolean value to tell the server to disable + # the Garbage Collector when serializing a response proto. + # Once the serialization is completed, the GC is enabled again. + # This optomization provides a large boost in speed to rpc requests. + # Note that this option is ignored if gc_pause_server_request is + # enabled since serialization is during the request cycle. + def self.gc_pause_server_serialization + return @_gc_pause_server_serialization unless @_gc_pause_server_serialization.nil? + gc_pause_server_serialization = false + end + + def self.gc_pause_server_serialization=(value) + @_gc_pause_server_serialization = !!value + end + + # Connector Type + # + # Symbol value which denotes the type of connector to use + # during client requests to an RPC server. + def self.connector_type + @_connector_type ||= DEFAULT_CONNECTOR_TYPE + end + + def self.connector_type=(type) + raise 'Invalid connector type given' unless VALID_CONNECTOR_TYPES.include?(type) + @_connector_type = type + end -# For running the rpc_server -case -when defined?(Protobuf::ServerType) && Protobuf::ServerType =~ /\Asocket\Z/i then - #no-op -when defined?(Protobuf::ServerType) && Protobuf::ServerType =~ /\Azmq\Z/i then - require 'ffi-rzmq' - require 'protobuf/rpc/servers/zmq/server' -else - Protobuf::ServerType = "Evented::Server" - require 'eventmachine' - require 'protobuf/ext/eventmachine' - require 'protobuf/rpc/servers/evented/server' end + +require 'protobuf/rpc/client' +require 'protobuf/rpc/service' +require 'protobuf/socket' diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb new file mode 100644 index 00000000..92a776a0 --- /dev/null +++ b/lib/protobuf/cli.rb @@ -0,0 +1,176 @@ +require 'thor' +require 'pry' +require 'protobuf/version' +require 'protobuf/common/logger' +require 'protobuf/rpc/servers/evented_runner' +require 'protobuf/rpc/servers/socket_runner' +require 'protobuf/rpc/servers/zmq_runner' + +module Protobuf + class CLI < ::Thor + include ::Thor::Actions + + attr_accessor :runner, :mode, :start_aborted + + default_task :start + + desc 'start APP_FILE', 'Run the RPC server in the given mode, preloading the given APP_FILE. This is the default task.' + + option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-o), :desc => 'Host to bind.' + option :port, :type => :numeric, :default => 9595, :aliases => %w(-p), :desc => 'Port to bind.' + + option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.' + option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' + + option :log, :type => :string, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' + 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/)' + + option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.' + option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' + option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' + + option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' + option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' + option :gc_pause_serialization, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during serialization.' + + def start(app_file) + debug_say 'Configuring the rpc_server process' + @start_aborted = false + + configure_logger + configure_traps + configure_server_mode + require_protobuf! + configure_gc + + run_if_no_abort { require_application!(app_file) } + run_if_no_abort { configure_process_name(app_file) } + run_if_no_abort { start_server! } + + rescue => e + say_and_exit!('ERROR: RPC Server failed to start.', e) + end + + desc 'version', 'Print ruby and protoc versions and exit.' + def version + say "Ruby Protobuf v#{::Protobuf::VERSION}, protoc v#{::Protobuf::PROTOC_VERSION}" + end + + no_tasks do + + # If we pause during request we don't need to pause in serialization + def configure_gc + debug_say 'Configuring gc' + ::Protobuf.gc_pause_server_request = options.gc_pause_request? + ::Protobuf.gc_pause_server_serialization = (!options.gc_pause_request? && options.gc_pause_serialization?) + end + + # Setup the protobuf logger. + def configure_logger + debug_say 'Configuring logger' + ::Protobuf::Logger.configure({ :file => options.log || STDOUT, + :level => options.debug? ? ::Logger::DEBUG : options.level }) + + # Debug output the server options to the log file. + ::Protobuf::Logger.debug { 'Debugging options:' } + ::Protobuf::Logger.debug { options.inspect } + end + + # Re-write the $0 var to have a nice process name in ps. + def configure_process_name(app_file) + debug_say 'Configuring process name' + $0 = "rpc_server --#{@mode} #{options.host}:#{options.port} #{app_file}" + end + + # Configure the mode of the server and the runner class. + def configure_server_mode + debug_say 'Configuring runner mode' + if options.zmq? && ! options.evented? && ! options.socket? + @mode = :zmq + @runner = ::Protobuf::Rpc::ZmqRunner + elsif options.evented? && ! options.zmq? && ! options.socket? + @mode = :evented + @runner = ::Protobuf::Rpc::EventedRunner + else + say 'WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow if multi_mode? + @mode = :socket + @runner = ::Protobuf::Rpc::SocketRunner + end + end + + # Configure signal traps. + # TODO add signal handling for hot-reloading the application. + def configure_traps + debug_say 'Configuring traps' + trap_block = proc { + ::Protobuf::Logger.info { 'RPC Server shutting down...' } + @start_aborted = true + @runner.stop + ::Protobuf::Logger.info { 'Shutdown complete' } + } + + debug_say 'Registering INT', :blue + trap(:INT, &trap_block) + debug_say 'Registering QUIT', :blue + trap(:QUIT, &trap_block) + debug_say 'Registering TERM', :blue + trap(:TERM, &trap_block) + end + + # Say something if we're in debug mode. + def debug_say(message, color = :yellow) + say(message, color) if options.debug? + end + + # Internal helper to determine if the modes are multi-set which is not valid. + def multi_mode? + (options.zmq? && (options.evented? || options.socket?)) \ + && (options.evented? && (options.evented? || options.socket?)) \ + && (options.zmq? && (options.evented? || options.socket?)) \ + end + + # Require the application file given, exiting if the file doesn't exist. + def require_application!(app_file) + debug_say 'Requiring app file' + require app_file + rescue LoadError => e + say_and_exit!("Failed to load application file #{app_file}", e) + end + + # Loads protobuf in the given mode, exiting if somehow the mode is wrong. + def require_protobuf! + require "protobuf/#{@mode}.rb" + rescue LoadError => e + puts e.message, *(e.backtrace) + say_and_exit!("Failed to load protobuf runner #{@mode}", e) + end + + def run_if_no_abort + yield unless @start_aborted + end + + def say_and_exit!(message, exception = nil) + message = set_color(message, :red) if ::Protobuf::Logger.file == STDOUT + + ::Protobuf::Logger.error { message } + if exception + ::Protobuf::Logger.error { "[#{exception.class.name}] #{exception.message}" } + ::Protobuf::Logger.debug { exception.backtrace.join("\n") } + end + + exit(1) + end + + # Start the runner and log the relevant options. + def start_server! + debug_say 'Invoking server start' + @runner.run(options.dup) do + Protobuf::Logger.info { "pid #{::Process.pid} -- #{@mode} RPC Server listening at #{options.host}:#{options.port}" } + end + end + + end + + end +end + diff --git a/lib/protobuf/common/logger.rb b/lib/protobuf/common/logger.rb index b53e7746..3cd38489 100644 --- a/lib/protobuf/common/logger.rb +++ b/lib/protobuf/common/logger.rb @@ -2,7 +2,7 @@ module Protobuf class Logger < ::Logger - + class << self attr_accessor :file, :level @@ -13,43 +13,43 @@ class << self end end end - + # One-line file/level configuration def self.configure(options) self.file = options.fetch(:file, false) self.level = options.fetch(:level, false) end - + # Use to reset the instance def self.reset_device! self.file = self.level = @__instance = nil end - + # Singleton instance def self.instance @__instance ||= begin log = nil - + if @file && @level log = new(self.file) log.level = self.level end - + log end end - - # + + # # LogMethods module for log method including, e.g.: - # + # # class MyClass # include Protobuf::Logger::LogMethods # ... # end - # + # # Produce a module to allow "include" in other classes to avoid # cluttering the namespace of the including class with the other methods defined above - # + # module LogMethods [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| define_method("log_#{m}") do |*params, &block| diff --git a/lib/protobuf/evented.rb b/lib/protobuf/evented.rb new file mode 100644 index 00000000..4ba3e84f --- /dev/null +++ b/lib/protobuf/evented.rb @@ -0,0 +1,22 @@ +## +## Evented Mode +## +# +# Require this file if you wish to run your server and/or client RPC +# with the evented handlers via EventMachine. +# +# To run with rpc_server specify the switch `evented`: +# +# rpc_server --evented myapp.rb +# +# To run for client-side only override the require in your Gemfile: +# +# gem 'protobuf', :require => 'protobuf/evented' +# +require 'protobuf' +Protobuf.connector_type = :evented + +require 'eventmachine' +require 'protobuf/ext/eventmachine' +require 'protobuf/rpc/servers/evented/server' +require 'protobuf/rpc/connectors/eventmachine' diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index a3bab0b7..d98cb8e3 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -9,14 +9,14 @@ module Rpc class Client extend Forwardable include Protobuf::Logger::LogMethods - + delegate [:options, :complete_cb, :success_cb, :failure_cb, :async?] => :@connector attr_reader :connector - + # Create a new client with default options (defined in ClientConnection) # See Service#client for a more convenient way to create a client, as well # as Client#method_missing defined below. - # + # # request = WidgetFindRequest.new # client = Client.new({ # :service => WidgetService, @@ -35,33 +35,33 @@ def initialize(opts={}) def log_signature @log_signature ||= "client-#{self.class}" end - - # Set a complete callback on the client to return the object (self). + + # Set a complete callback on the client to return the object (self). # Callback is called regardless of :async setting. - # + # # client = Client.new(:service => WidgetService) # client.on_complete {|obj| ... } - # + # def on_complete(&complete_cb) - @connector.complete_cb = complete_cb + @connector.complete_cb = complete_cb end def on_complete=(callable) if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 raise "callable must take a single argument and respond to :call" end - - @connector.complete_cb = callable + + @connector.complete_cb = callable end - + # Set a failure callback on the client to return the # error returned by the service, if any. If this callback # is called, success_cb will NOT be called. # Callback is called regardless of :async setting. - # + # # client = Client.new(:service => WidgetService) # client.on_failure {|err| ... } - # + # def on_failure(&failure_cb) @connector.failure_cb = failure_cb end @@ -71,17 +71,17 @@ def on_failure=(callable) raise "callable must take a single argument and respond to :call" end - @connector.failure_cb = callable + @connector.failure_cb = callable end - + # Set a success callback on the client to return the # successful response from the service when it is returned. # If this callback is called, failure_cb will NOT be called. # Callback is called regardless of :async setting. - # + # # client = Client.new(:service => WidgetService) # client.on_success {|res| ... } - # + # def on_success(&success_cb) @connector.success_cb = success_cb end @@ -91,9 +91,9 @@ def on_success=(callable) raise "callable must take a single argument and respond to :call" end - @connector.success_cb = callable + @connector.success_cb = callable end - + # Provides a mechanism to call the service method against the client # which will automatically setup the service_class and method_name # in the wrapper protobuf request. @@ -105,7 +105,7 @@ def on_success=(callable) # c.on_success {|res| ... } # c.on_failure {|err| ... } # end - # + # def method_missing(method, *params) service = options[:service] unless service.rpcs[service].keys.include?(method) @@ -121,7 +121,7 @@ def method_missing(method, *params) options[:method] = method.to_s options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0] log_debug { "[#{log_signature}] Request Data: %s" % options[:request].inspect } - + # Call client to setup on_success and on_failure event callbacks if block_given? log_debug { "[#{log_signature}] client setup callback given, invoking" } @@ -129,11 +129,11 @@ def method_missing(method, *params) else log_debug { "[#{log_signature}] no block given for callbacks" } end - + send_request end end - + # Send the request to the service through eventmachine. # This method is usually never called directly # but is invoked by method_missing (see docs above). @@ -146,7 +146,7 @@ def method_missing(method, *params) # :response_type => "WidgetList", # :request => request # }) - # + # # client.on_success do |res| # res.widgets.each{|w| puts w.inspect } # end @@ -154,13 +154,13 @@ def method_missing(method, *params) # client.on_failure do |err| # puts err.message # end - # + # # client.send_request # def send_request @connector.send_request end - + end end end diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb index 5752c2a4..ed5ad88c 100644 --- a/lib/protobuf/rpc/connector.rb +++ b/lib/protobuf/rpc/connector.rb @@ -1,22 +1,19 @@ module Protobuf module Rpc class Connector - + + # Returns a connector class for the pre-defined connector_type. def self.connector_for_client - if defined?(Protobuf::ClientType) - case Protobuf::ClientType - when "Socket" then - ::Protobuf::Rpc::Connectors::Socket - when "Zmq" then - ::Protobuf::Rpc::Connectors::Zmq - else - ::Protobuf::Rpc::Connectors::EventMachine - end - else - ::Protobuf::Rpc::Connectors::EventMachine - end + @_connector ||= case ::Protobuf.connector_type + when :evented then + ::Protobuf::Rpc::Connectors::EventMachine + when :zmq then + ::Protobuf::Rpc::Connectors::Zmq + else + ::Protobuf::Rpc::Connectors::Socket + end end - + end end end diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index 52393f30..864ce1cc 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -7,10 +7,10 @@ module Connectors class EventMachine < Base def send_request - ensure_em_running do + ensure_em_running do f = Fiber.current - EM.next_tick do + ::EM.next_tick do log_debug { "[#{log_signature}] Scheduling EventMachine client request to be created on next tick" } cnxn = EMClient.connect(options, &ensure_cb) cnxn.on_success(&success_cb) if success_cb @@ -26,11 +26,11 @@ def send_request end # Returns a callable that ensures any errors will be returned to the client - # + # # If a failure callback was set, just use that as a direct assignment # otherwise implement one here that simply throws an exception, since we # don't want to swallow the black holes. - # + # def ensure_cb @ensure_cb ||= (@failure_cb || lambda { |error| raise '%s: %s' % [error.code.name, error.message] } ) end @@ -42,42 +42,42 @@ def log_signature private def ensure_em_running(&blk) - if EM.reactor_running? + if ::EM.reactor_running? @using_global_reactor = true yield - else + else @using_global_reactor = false - EM.fiber_run do + ::EM.fiber_run do blk.call - EM.stop + ::EM.stop end end end def resume_fiber(fib) - EM::cancel_timer(@timeout_timer) + ::EM::cancel_timer(@timeout_timer) fib.resume(true) - rescue => ex + rescue => ex message = 'Synchronous client failed: %s' % ex.message error_stop_reactor(message) end def set_timeout_and_validate_fiber - @timeout_timer = EM::add_timer(@options[:timeout]) do + @timeout_timer = ::EM::add_timer(@options[:timeout]) do message = 'Client timeout of %d seconds expired' % @options[:timeout] error_stop_reactor(message) end Fiber.yield rescue FiberError - message = "Synchronous calls must be in 'EM.fiber_run' block" + message = "Synchronous calls must be in 'EM.fiber_run' block" error_stop_reactor(message) end def error_stop_reactor(message) err = Protobuf::Rpc::ClientError.new(Protobuf::Socketrpc::ErrorReason::RPC_ERROR, message) ensure_cb.call(err) - EM.stop unless @using_global_reactor + ::EM.stop unless @using_global_reactor end end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 1d596065..cf489ec7 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -6,21 +6,8 @@ module Protobuf module Rpc - GC_PAUSE_REQUEST = false - GC_PAUSE_SERIALIZATION = false - module Server - def _gc_pause_request - return @_gc_pause_request unless @_gc_pause_request.nil? - @_gc_pause_request ||= (defined?(::Protobuf::Rpc::GC_PAUSE_REQUEST) && ::Protobuf::Rpc::GC_PAUSE_REQUEST) - end - - def _gc_pause_serialization - return @_gc_pause_serialization unless @_gc_pause_serialization.nil? - @_gc_pause_serialization ||= (defined?(::Protobuf::Rpc::GC_PAUSE_SERIALIZATION) && ::Protobuf::Rpc::GC_PAUSE_SERIALIZATION) - end - # Invoke the service method dictated by the proto wrapper request object def handle_client # Parse the protobuf request from the socket @@ -33,7 +20,7 @@ def handle_client # Call the service method log_debug { "[#{log_signature}] Dispatching client request to service" } - GC.disable if _gc_pause_request + ::GC.disable if ::Protobuf.gc_pause_server_request invoke_rpc_method rescue => error # Ensure we're handling any errors that try to slip out the back door @@ -146,7 +133,7 @@ def send_response @stats.log_stats @did_respond = true ensure - GC.enable if _gc_pause_request + ::GC.enable if ::Protobuf.gc_pause_server_request end end end diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index dd146f96..5f0df4aa 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -3,7 +3,7 @@ module Rpc class EventedRunner def self.stop - EventMachine.stop_event_loop if EventMachine.reactor_running? + ::EventMachine.stop_event_loop if ::EventMachine.reactor_running? end def self.run(server) @@ -19,13 +19,13 @@ def self.run(server) #end # Startup and run the rpc server - EM.schedule do - EventMachine.start_server(server.host, server.port, Protobuf::Rpc::Evented::Server) + ::EventMachine.schedule do + ::EventMachine.start_server(server.host, server.port, ::Protobuf::Rpc::Evented::Server) end # Join or start the reactor yield if block_given? - EM.reactor_running? ? EM.reactor_thread.join : EM.run + ::EM.reactor_running? ? ::EM.reactor_thread.join : ::EM.run end end end diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 6faa0957..c88241eb 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -52,6 +52,7 @@ def self.run(opts = {}) @threads = [] @thread_threshold = thread_threshold @server = ::TCPServer.new(host, port) + raise "blah" if @server.closed? @server.listen(backlog) @working = [] @listen_fds = [@server] @@ -90,7 +91,7 @@ def self.run(opts = {}) raise rescue # Closing the server causes the loop to raise an exception here - raise if running? + raise #if running? end def self.running? diff --git a/lib/protobuf/socket.rb b/lib/protobuf/socket.rb new file mode 100644 index 00000000..7731cfa0 --- /dev/null +++ b/lib/protobuf/socket.rb @@ -0,0 +1,22 @@ +## +## Socket Mode +## +# +# Require this file if you wish to run your server and/or client RPC +# with the raw socket handlers. This is the default run mode for bin/rpc_server. +# +# To run with rpc_server either omit any mode switches, or explicitly pass `socket`: +# +# rpc_server myapp.rb +# rpc_server --socket myapp.rb +# +# To run for client-side only override the require in your Gemfile: +# +# gem 'protobuf', :require => 'protobuf/socket' +# +require 'protobuf' +::Protobuf.connector_type = :socket + +require 'protobuf/rpc/servers/socket/server' +require 'protobuf/rpc/connectors/socket' + diff --git a/lib/protobuf/zmq.rb b/lib/protobuf/zmq.rb new file mode 100644 index 00000000..e2adbf5e --- /dev/null +++ b/lib/protobuf/zmq.rb @@ -0,0 +1,21 @@ +## +## ZMQ Mode +## +# +# Require this file if you wish to run your server and/or client RPC +# with the ZeroMQ handlers. +# +# To run with rpc_server specify the switch `zmq`: +# +# rpc_server --zmq myapp.rb +# +# To run for client-side only override the require in your Gemfile: +# +# gem 'protobuf', :require => 'protobuf/zmq' +# +require 'protobuf' +Protobuf.connector_type = :zmq + +require 'ffi-rzmq' +require 'protobuf/rpc/servers/zmq/server' +require 'protobuf/rpc/connectors/zmq' diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index de26131a..52861278 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,5 +1,5 @@ require 'benchmark' -require 'helper/all' +require 'support/all' require 'proto/test_service_impl' require 'perftools' @@ -60,34 +60,32 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) end def sock_client_sock_server(number_tests, test_length, global_bench = nil) + load "protobuf/socket.rb" EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - with_constants "Protobuf::ClientType" => "Socket" do - client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client = Spec::Proto::TestService.client(:async => false, :port => 9399) - benchmark_wrapper(global_bench) do |bench| - bench.report("SS / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } - end + benchmark_wrapper(global_bench) do |bench| + bench.report("SS / SC") do + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end end end def sock_client_em_server(number_tests, test_length, global_bench = nil) + load "protobuf/socket.rb" EM.stop if EM.reactor_running? em_thread = Thread.new { EM.run } Thread.pass until EM.reactor_running? StubServer.new(:port => 9399) do |server| - with_constants "Protobuf::ClientType" => "Socket" do - client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client = Spec::Proto::TestService.client(:async => false, :port => 9399) - benchmark_wrapper(global_bench) do |bench| - bench.report("ES / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } - end + benchmark_wrapper(global_bench) do |bench| + bench.report("ES / SC") do + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end end @@ -97,17 +95,13 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) end def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) - require 'ffi-rzmq' - require 'protobuf/rpc/connectors/zmq' - require 'protobuf/rpc/servers/zmq/server' + load "protobuf/zmq.rb" StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - with_constants "Protobuf::ClientType" => "Zmq" do - client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client = Spec::Proto::TestService.client(:async => false, :port => 9399) - benchmark_wrapper(global_bench) do |bench| - bench.report("ZS / ZC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } - end + benchmark_wrapper(global_bench) do |bench| + bench.report("ZS / ZC") do + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end server.stop diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 05948911..35952763 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -3,6 +3,7 @@ describe 'Functional Socket Client' do before(:all) do + load "protobuf/socket.rb" Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } @@ -16,18 +17,16 @@ it 'runs fine when required fields are set' do expect { - with_constants "Protobuf::ClientType" => "Socket" do - client = ::Spec::Proto::TestService.client(:async => false) - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Spec::Proto::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect end end }.to_not raise_error @@ -35,28 +34,24 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - with_constants "Protobuf::ClientType" => "Socket" do - request = ::Spec::Proto::ResourceFindRequest.new(:active => true) - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Spec::Proto::ResourceFindRequest.new(:active => true) + client = ::Spec::Proto::TestService.client(:async => false) - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ end it 'calls the on_failure callback when the request type is wrong' do error = nil - with_constants "Protobuf::ClientType" => "Socket" do - request = ::Spec::Proto::Resource.new(:name => 'Test Name') - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Spec::Proto::Resource.new(:name => 'Test Name') + client = ::Spec::Proto::TestService.client(:async => false) - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index cfa715e7..0ab5b3a7 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -3,6 +3,7 @@ describe 'Functional ZMQ Client' do before(:all) do + load "protobuf/zmq.rb" Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } @@ -16,18 +17,16 @@ it 'runs fine when required fields are set' do expect { - with_constants "Protobuf::ClientType" => "Zmq" do - client = ::Spec::Proto::TestService.client(:async => false) - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Spec::Proto::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end + client = ::Spec::Proto::TestService.client(:async => false) + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect end end }.to_not raise_error @@ -35,28 +34,24 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - with_constants "Protobuf::ClientType" => "Zmq" do - request = ::Spec::Proto::ResourceFindRequest.new(:active => true) - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Spec::Proto::ResourceFindRequest.new(:active => true) + client = ::Spec::Proto::TestService.client(:async => false) - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ end it 'calls the on_failure callback when the request type is wrong' do error = nil - with_constants "Protobuf::ClientType" => "Zmq" do - request = ::Spec::Proto::Resource.new(:name => 'Test Name') - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Spec::Proto::Resource.new(:name => 'Test Name') + client = ::Spec::Proto::TestService.client(:async => false) - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end diff --git a/spec/helper/all.rb b/spec/helper/all.rb deleted file mode 100644 index 802cc96a..00000000 --- a/spec/helper/all.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'helper/tolerance_matcher' -require 'helper/server' -require 'helper/silent_constants' - -def now - Time.new.to_f -end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb new file mode 100644 index 00000000..f5b4a41c --- /dev/null +++ b/spec/lib/protobuf/cli_spec.rb @@ -0,0 +1,200 @@ +require 'spec_helper' +require 'protobuf/cli' + +describe ::Protobuf::CLI do + + let(:app_file) do + File.expand_path('../../../support/test_app_file.rb', __FILE__) + end + + before do + ::Protobuf::Rpc::SocketRunner.stub(:run) + ::Protobuf::Rpc::ZmqRunner.stub(:run) + ::Protobuf::Rpc::EventedRunner.stub(:run) + end + + describe '#start' do + let(:base_args) { [ 'start', app_file ] } + let(:test_args) { [] } + let(:args) { base_args + test_args } + + context 'host option' do + let(:test_args) { [ '--host=123.123.123.123' ] } + + it 'sends the host option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options.host.should eq '123.123.123.123' + end + described_class.start(args) + end + end + + context 'port option' do + let(:test_args) { [ '--port=12345' ] } + + it 'sends the port option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options.port.should eq 12345 + end + described_class.start(args) + end + end + + context 'backlog option' do + let(:test_args) { [ '--backlog=500' ] } + + it 'sends the backlog option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options.backlog.should eq 500 + end + described_class.start(args) + end + end + + context 'threshold option' do + let(:test_args) { [ '--threshold=500' ] } + + it 'sends the backlog option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options.threshold.should eq 500 + end + described_class.start(args) + end + end + + context 'log options' do + let(:test_args) { [ '--log=mylog.log', '--level=0' ] } + + it 'sends the log file and level options to the runner' do + ::Protobuf::Logger.should_receive(:configure) do |options| + options[:file].should eq 'mylog.log' + options[:level].should eq 0 + end + described_class.start(args) + end + + context 'when debugging' do + let(:test_args) { [ '--level=3', '--debug' ] } + + it 'overrides the log-level to DEBUG' do + ::Protobuf::Logger.should_receive(:configure) do |options| + options[:level].should eq ::Logger::DEBUG + end + described_class.start(args) + end + end + end + + context 'pre-cache options' do + let(:test_args) { [ '--pre_cache_definitions' ] } + + it 'causes the message sub-classes to be pre-cached' do + ::Protobuf::Message.should_receive(:pre_cache_class_definitions) + described_class.start(args) + end + + context 'when pre-cache option is not present' do + let(:test_args) { [] } + + it 'does not invoke the pre-cache call' do + ::Protobuf::Message.should_not_receive(:pre_cache_class_definitions) + described_class.start(args) + end + end + end + + context 'gc options' do + + context 'when gc options are not present' do + let(:test_args) { [] } + + it 'sets both request and serialization pausing to false' do + described_class.start(args) + ::Protobuf.gc_pause_server_request.should be_false + ::Protobuf.gc_pause_server_serialization.should be_false + end + end + + context 'request pausing' do + let(:test_args) { [ '--gc_pause_request' ] } + + it 'sets the configuration option to GC pause server request' do + described_class.start(args) + ::Protobuf.gc_pause_server_request.should be_true + end + end + + context 'serialization pausing' do + let(:test_args) { [ '--gc_pause_serialization' ] } + + it 'sets the configuration option to GC pause server serializations' do + described_class.start(args) + ::Protobuf.gc_pause_server_serialization.should be_true + end + end + end + + context 'run modes' do + + context 'socket' do + let(:test_args) { [ '--socket' ] } + + before do + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + end + + it 'is activated by the --socket switch' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) + described_class.start(args) + end + + it 'configures the connector type to be socket' do + load "protobuf/socket.rb" + ::Protobuf.connector_type.should == :socket + end + end + + context 'evented' do + let(:test_args) { [ '--evented' ] } + + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + end + + it 'is activated by the --evented switch' do + ::Protobuf::Rpc::EventedRunner.should_receive(:run) + described_class.start(args) + end + + it 'configures the connector type to be evented' do + load "protobuf/evented.rb" + ::Protobuf.connector_type.should == :evented + end + end + + context 'zmq' do + let(:test_args) { [ '--zmq' ] } + + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + end + + it 'is activated by the --zmq switch' do + ::Protobuf::Rpc::ZmqRunner.should_receive(:run) + described_class.start(args) + end + + it 'configures the connector type to be zmq' do + load "protobuf/zmq.rb" + ::Protobuf.connector_type.should == :zmq + end + end + + end + + end + +end diff --git a/spec/unit/common/logger_spec.rb b/spec/lib/protobuf/common/logger_spec.rb similarity index 100% rename from spec/unit/common/logger_spec.rb rename to spec/lib/protobuf/common/logger_spec.rb diff --git a/spec/lib/protobuf/common/util_spec.rb b/spec/lib/protobuf/common/util_spec.rb new file mode 100644 index 00000000..820dbca7 --- /dev/null +++ b/spec/lib/protobuf/common/util_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Protobuf::Util do + + describe '.underscore' do + it 'underscores constant name' do + Protobuf::Util.underscore("HelloMoto").should eq "hello_moto" + end + + context 'when constant name has uppercased word' do + it 'keeps the uppercased word together' do + Protobuf::Util.underscore("UPPERCase").should eq "upper_case" + Protobuf::Util.underscore("MDXService").should eq "mdx_service" + end + end + end +end \ No newline at end of file diff --git a/spec/unit/enum_spec.rb b/spec/lib/protobuf/message/enum_spec.rb similarity index 100% rename from spec/unit/enum_spec.rb rename to spec/lib/protobuf/message/enum_spec.rb diff --git a/spec/unit/message_spec.rb b/spec/lib/protobuf/message/message_spec.rb similarity index 100% rename from spec/unit/message_spec.rb rename to spec/lib/protobuf/message/message_spec.rb diff --git a/spec/unit/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb similarity index 97% rename from spec/unit/rpc/client_spec.rb rename to spec/lib/protobuf/rpc/client_spec.rb index 81101b78..fc484038 100644 --- a/spec/unit/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -3,6 +3,7 @@ describe Protobuf::Rpc::Client do before(:each) do + load 'protobuf/evented.rb' ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION) end @@ -16,8 +17,8 @@ client.find(:name => "Test Name", :active => true) do |c| c.on_success do |succ| succ.name.should eq("Test Name") - succ.status.should eq(Spec::Proto::StatusType::ENABLED) - end + succ.status.should eq(Spec::Proto::StatusType::ENABLED) + end c.on_failure do |err| raise err.inspect @@ -76,7 +77,7 @@ error.message.should =~ /timeout/i end - context "without reactor_running?" do + context "without reactor_running?" do it "throws a timeout when client timeout is exceeded" do subject = Proc.new do @@ -154,7 +155,7 @@ context 'when calling methods on a service client' do - # NOTE: we are assuming the service methods are accurately + # NOTE: we are assuming the service methods are accurately # defined inside spec/proto/test_service.rb, # namely the :find method diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb new file mode 100644 index 00000000..8f005890 --- /dev/null +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' +require 'protobuf/socket' +require 'protobuf/evented' +require 'protobuf/zmq' + +describe ::Protobuf::Rpc::Connector do + + describe '.connector_for_client' do + after { described_class.instance_variable_set(:@_connector, nil) } + + context 'Protobuf.connector_type is socket' do + it 'returns a socket connector class' do + ::Protobuf.connector_type = :socket + described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::Socket + end + end + + context 'Protobuf.connector_type is not a known value' do + it 'returns a socket connector class' do + ::Protobuf.stub(:connector_type).and_return('some value') + described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::Socket + end + end + + context 'Protobuf.connector_type is evented' do + it 'returns an eventmachine connector class' do + ::Protobuf.connector_type = :evented + described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::EventMachine + end + end + + context 'Protobuf.connector_type is zmq' do + it 'returns a zmq connector class' do + ::Protobuf.connector_type = :zmq + described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::Zmq + end + end + + end + +end diff --git a/spec/unit/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb similarity index 96% rename from spec/unit/rpc/connectors/base_spec.rb rename to spec/lib/protobuf/rpc/connectors/base_spec.rb index 380fd69b..642923d2 100644 --- a/spec/unit/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' describe Protobuf::Rpc::Connectors::Base do - + let(:opts) do { async: false, timeout: 60 } end - + subject { Protobuf::Rpc::Connectors::Base.new(opts) } - - describe "#send_request" do - it "raising an error when 'send_request' is not overridden" do + + describe "#send_request" do + it "raising an error when 'send_request' is not overridden" do expect{ subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/) end - it "does not raise error when 'send_request' is overridden" do + it "does not raise error when 'send_request' is overridden" do new_sub = Class.new(subject.class){ def send_request; end }.new(opts) expect{ new_sub.send_request }.to_not raise_error end @@ -26,7 +26,7 @@ subject.failure_cb.should be_nil end end - + describe '#success_cb' do it 'allows setting the success callback and calling it' do subject.success_cb.should be_nil @@ -36,7 +36,7 @@ expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb' end end - + describe '#failure_cb' do it 'allows setting the failure callback and calling it' do subject.failure_cb.should be_nil @@ -46,43 +46,43 @@ expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb' end end - + describe '#async?' do context 'when provided options[:async] is false' do let(:opts) do { async: false, timeout: 60 } end - + subject { Protobuf::Rpc::Connectors::Base.new(opts) } - + it 'returns false' do subject.async?.should be_false end end - + context 'when provided options[:async] is true' do let(:opts) do { async: true, timeout: 60 } end - + subject { Protobuf::Rpc::Connectors::Base.new(opts) } - + it 'returns true' do subject.async?.should be_true end end - + context 'when options doesn\'t denote async' do let(:opts) do { timeout: 60 } end - + subject { Protobuf::Rpc::Connectors::Base.new(opts) } - + it 'returns false' do subject.async?.should be_false end end end - + end diff --git a/spec/unit/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb similarity index 82% rename from spec/unit/rpc/connectors/common_spec.rb rename to spec/lib/protobuf/rpc/connectors/common_spec.rb index afd08bfd..2b41bb78 100644 --- a/spec/unit/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' -require 'protobuf/rpc/service' +require 'spec_helper' +require 'protobuf/rpc/service' describe Protobuf::Rpc::Connectors::Common do - let(:common_class) do + let(:common_class) do Class.new(Protobuf::Rpc::Connectors::Base) do - include Protobuf::Rpc::Connectors::Common + include Protobuf::Rpc::Connectors::Common attr_accessor :options attr_accessor :stats end @@ -12,7 +12,7 @@ subject{ @subject ||= common_class.new({}) } - context "API" do + context "API" do specify{ subject.respond_to?(:any_callbacks?).should be_true } specify{ subject.respond_to?(:data_callback).should be_true } specify{ subject.respond_to?(:error).should be_true } @@ -23,16 +23,16 @@ specify{ subject.respond_to?(:verify_callbacks).should be_true } end - context "#any_callbacks?" do + context "#any_callbacks?" do [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| - it "returns true if #{cb} is provided" do + it "returns true if #{cb} is provided" do subject.instance_variable_set(cb, "something") subject.any_callbacks?.should be_true end end - it "returns false when all callbacks are not provided" do + it "returns false when all callbacks are not provided" do subject.instance_variable_set(:@complete_cb, nil) subject.instance_variable_set(:@success_cb, nil) subject.instance_variable_set(:@failure_cb, nil) @@ -42,31 +42,31 @@ end - context "#data_callback" do + context "#data_callback" do it "changes state to use the data callback" do subject.data_callback("data") subject.instance_variable_get(:@used_data_callback).should be_true end - it "sets the data var when using the data_callback" do + it "sets the data var when using the data_callback" do subject.data_callback("data") subject.instance_variable_get(:@data).should eq("data") end end - context "#verify_callbacks" do + context "#verify_callbacks" do - it "sets @failure_cb to #data_callback when no callbacks are defined" do + it "sets @failure_cb to #data_callback when no callbacks are defined" do subject.verify_callbacks - subject.instance_variable_get(:@failure_cb).should eq(subject.method(:data_callback)) + subject.instance_variable_get(:@failure_cb).should eq(subject.method(:data_callback)) end it "sets @success_cb to #data_callback when no callbacks are defined" do subject.verify_callbacks - subject.instance_variable_get(:@success_cb).should eq(subject.method(:data_callback)) + subject.instance_variable_get(:@success_cb).should eq(subject.method(:data_callback)) end - it "doesn't set @failure_cb when already defined" do + it "doesn't set @failure_cb when already defined" do set_cb = lambda{ true } subject.instance_variable_set(:@failure_cb, set_cb) subject.verify_callbacks @@ -74,7 +74,7 @@ subject.instance_variable_get(:@failure_cb).should_not eq(subject.method(:data_callback)) end - it "doesn't set @success_cb when already defined" do + it "doesn't set @success_cb when already defined" do set_cb = lambda{ true } subject.instance_variable_set(:@success_cb, set_cb) subject.verify_callbacks @@ -86,7 +86,7 @@ shared_examples "a ConnectorDisposition" do |meth, cb, *args| - it "calls #complete before exit" do + it "calls #complete before exit" do stats = double("Object") stats.stub(:end) { true } stats.stub(:log_stats) { true } @@ -96,7 +96,7 @@ subject.method(meth).call(*args) end - it "calls the #{cb} callback when provided" do + it "calls the #{cb} callback when provided" do stats = double("Object") stats.stub(:end) { true } stats.stub(:log_stats) { true } @@ -108,13 +108,13 @@ subject.method(meth).call(*args) end - it "calls the complete callback when provided" do + it "calls the complete callback when provided" do stats = double("Object") stats.stub(:end) { true } stats.stub(:log_stats) { true } subject.stats = stats comp_cb = double("Object") - + subject.instance_variable_set(:@complete_cb, comp_cb) comp_cb.should_receive(:call).and_return(true) subject.method(meth).call(*args) diff --git a/spec/unit/rpc/connectors/eventmachine_client_spec.rb b/spec/lib/protobuf/rpc/connectors/eventmachine_client_spec.rb similarity index 97% rename from spec/unit/rpc/connectors/eventmachine_client_spec.rb rename to spec/lib/protobuf/rpc/connectors/eventmachine_client_spec.rb index 61d9bdd8..6f282e66 100644 --- a/spec/unit/rpc/connectors/eventmachine_client_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/eventmachine_client_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'protobuf/evented' describe ::Protobuf::Rpc::Connectors::EMClient do describe '#send_data' do diff --git a/spec/unit/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb similarity index 80% rename from spec/unit/rpc/connectors/socket_spec.rb rename to spec/lib/protobuf/rpc/connectors/socket_spec.rb index ab6750d3..2fd7c16b 100644 --- a/spec/unit/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' +require 'protobuf/socket' -shared_examples "a Protobuf Connector" do +shared_examples "a Protobuf Connector" do subject{ described_class.new({}) } context "API" do @@ -12,17 +13,17 @@ end end -describe Protobuf::Rpc::Connectors::Socket do +describe Protobuf::Rpc::Connectors::Socket do subject{ described_class.new({}) } it_behaves_like "a Protobuf Connector" - + specify{ described_class.include?(Protobuf::Rpc::Connectors::Common).should be_true } context "#read_response" do let(:data){ "New data" } - it "fills the buffer with data from the socket" do + it "fills the buffer with data from the socket" do socket = StringIO.new("#{data.bytesize}-#{data}") subject.instance_variable_set(:@socket, socket) subject.instance_variable_set(:@stats, OpenStruct.new) @@ -33,13 +34,13 @@ end end - context "#check_async" do - it "raises an error when trying to execute asynchronously" do - conn = described_class.new(:async => true) + context "#check_async" do + it "raises an error when trying to execute asynchronously" do + conn = described_class.new(:async => true) expect{ conn.__send__(:check_async) }.to raise_error end - it "allows execution when synchronous" do + it "allows execution when synchronous" do conn = described_class.new(:async => false) expect{ conn.__send__(:check_async) }.to_not raise_error end diff --git a/spec/unit/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb similarity index 95% rename from spec/unit/rpc/connectors/zmq_spec.rb rename to spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 32c3dc7d..2c8e3f0d 100644 --- a/spec/unit/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'protobuf/zmq' describe ::Protobuf::Rpc::Connectors::Zmq do let(:socket_mock) do @@ -23,5 +24,4 @@ }.to raise_error end - end diff --git a/spec/unit/rpc/servers/evented_server_spec.rb b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb similarity index 78% rename from spec/unit/rpc/servers/evented_server_spec.rb rename to spec/lib/protobuf/rpc/servers/evented_server_spec.rb index ddb3aa36..f345f9d7 100644 --- a/spec/unit/rpc/servers/evented_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb @@ -1,12 +1,13 @@ require 'spec_helper' require 'spec/proto/test_service_impl' require 'protobuf/rpc/servers/evented_runner' +require 'protobuf/evented' describe Protobuf::Rpc::Evented::Server do - it "provides a Runner class" do + it "provides a Runner class" do runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") - expect { runner_class.constantize }.to_not raise_error + expect { runner_class.constantize }.to_not raise_error end it "Runner provides a stop method" do diff --git a/spec/unit/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb similarity index 67% rename from spec/unit/rpc/servers/socket_server_spec.rb rename to spec/lib/protobuf/rpc/servers/socket_server_spec.rb index cb51459d..08768c68 100644 --- a/spec/unit/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -1,8 +1,12 @@ require 'spec_helper' require 'spec/proto/test_service_impl' require 'protobuf/rpc/servers/socket_runner' +require 'protobuf/evented' +require 'protobuf/socket' describe Protobuf::Rpc::Socket::Server do + before(:each) { load 'protobuf/socket.rb' } + before(:all) do Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @@ -35,18 +39,17 @@ context "Eventmachine client" do it "calls the service in the client request" do - with_constants "Protobuf::ClientType" => "Evented" do - client = Spec::Proto::TestService.client(:async => false, :port => 9399, :host => "127.0.0.1") - - client.find(:name => "Test Name", :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(Spec::Proto::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end + ::Protobuf::Rpc::Connector.stub(:connector_for_client).and_return(::Protobuf::Rpc::Connectors::EventMachine) + client = Spec::Proto::TestService.client(:async => false, :port => 9399, :host => "127.0.0.1") + + client.find(:name => "Test Name", :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(Spec::Proto::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect end end end diff --git a/spec/unit/rpc/servers/zmq/broker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb similarity index 92% rename from spec/unit/rpc/servers/zmq/broker_spec.rb rename to spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb index 8696dc96..6cd61014 100644 --- a/spec/unit/rpc/servers/zmq/broker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe ::Protobuf::Rpc::Zmq::Broker do + before(:each) { load 'protobuf/zmq.rb' } after(:each) do subject.teardown end diff --git a/spec/unit/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb similarity index 96% rename from spec/unit/rpc/servers/zmq/server_spec.rb rename to spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 8a9caad7..70378101 100644 --- a/spec/unit/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -2,6 +2,7 @@ require 'protobuf/rpc/servers/zmq/server' describe Protobuf::Rpc::Zmq::Server do + before(:each) { load 'protobuf/zmq.rb' } describe '.running?' do it 'returns true if running' do described_class.instance_variable_set(:@running, true) diff --git a/spec/unit/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb similarity index 95% rename from spec/unit/rpc/servers/zmq/util_spec.rb rename to spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index f03e1d94..d4e6d5a6 100644 --- a/spec/unit/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -5,6 +5,7 @@ class UtilTest end describe ::Protobuf::Rpc::Zmq::Util do + before(:each) { load 'protobuf/zmq.rb' } subject { UtilTest.new } describe '#zmq_error_check' do it 'raises when the error code is less than 0' do diff --git a/spec/unit/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb similarity index 94% rename from spec/unit/rpc/servers/zmq/worker_spec.rb rename to spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 7716bab2..2ab8f768 100644 --- a/spec/unit/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe ::Protobuf::Rpc::Zmq::Worker do + before(:each) { load 'protobuf/zmq.rb' } after(:each) do subject.instance_variable_get(:@socket).close subject.instance_variable_get(:@zmq_context).terminate diff --git a/spec/unit/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb similarity index 100% rename from spec/unit/rpc/service_spec.rb rename to spec/lib/protobuf/rpc/service_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 52a3025b..b302a22e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,29 +4,23 @@ require 'rubygems' require 'bundler' Bundler.setup :default, :development, :test +require 'pry' -$:.push File.expand_path('..', File.dirname(__FILE__)) -$:.push File.expand_path('../lib', File.dirname(__FILE__)) +$: << ::File.expand_path('..', File.dirname(__FILE__)) +#$: << ::File.expand_path('../lib', File.dirname(__FILE__)) require 'protobuf' -require 'protobuf/rpc/client' -require File.dirname(__FILE__) + '/helper/all' -require 'pry' - -# these aren't explicitly required in lib/protobuf.rb. We require them here for -# testing purposes -require 'ffi-rzmq' -require 'protobuf/rpc/connectors/zmq' +require ::File.dirname(__FILE__) + '/support/all' # Including a way to turn on debug logger for spec runs if ENV["DEBUG"] - debug_log = File.expand_path('../debug_specs.log', File.dirname(__FILE__) ) - Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) + debug_log = ::File.expand_path('../debug_specs.log', File.dirname(__FILE__) ) + ::Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) end -RSpec.configure do |c| - c.include(SilentConstants) - c.include(Sander6::CustomMatchers) +::RSpec.configure do |c| + c.include(::SilentConstants) + c.include(::Sander6::CustomMatchers) c.mock_with :rspec end diff --git a/spec/support/all.rb b/spec/support/all.rb new file mode 100644 index 00000000..8c85e6f0 --- /dev/null +++ b/spec/support/all.rb @@ -0,0 +1,7 @@ +require 'support/tolerance_matcher' +require 'support/server' +require 'support/silent_constants' + +def now + Time.new.to_f +end diff --git a/spec/helper/server.rb b/spec/support/server.rb similarity index 90% rename from spec/helper/server.rb rename to spec/support/server.rb index a80fe6be..3b379202 100644 --- a/spec/helper/server.rb +++ b/spec/support/server.rb @@ -39,12 +39,10 @@ class StubServer def initialize(opts = {}) @running = true - @options = OpenStruct.new({ - :host => "127.0.0.1", - :port => 9399, - :delay => 0, - :server => Protobuf::Rpc::Evented::Server - }.merge(opts)) + @options = OpenStruct.new({ :host => "127.0.0.1", + :port => 9399, + :delay => 0, + :server => Protobuf::Rpc::Evented::Server }.merge(opts)) start yield self @@ -78,7 +76,7 @@ def start_socket_server end def start_zmq_server - @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } + @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } Thread.pass until Protobuf::Rpc::Zmq::Server.running? end diff --git a/spec/helper/silent_constants.rb b/spec/support/silent_constants.rb similarity index 97% rename from spec/helper/silent_constants.rb rename to spec/support/silent_constants.rb index 2b6b93a3..eea2c7d8 100644 --- a/spec/helper/silent_constants.rb +++ b/spec/support/silent_constants.rb @@ -1,4 +1,5 @@ # Just a way to keep warnings from being flagged in rename of constants during tests +=begin module Kernel def silence_warnings orig_verbosity = $VERBOSE @@ -7,8 +8,10 @@ def silence_warnings $VERBOSE = orig_verbosity end end +=end module SilentConstants +=begin def parse(constant) source, _, constant_name = constant.to_s.rpartition('::') [Object.const_get(source.to_sym), constant_name.to_sym] @@ -37,4 +40,5 @@ def with_constants(constants, &block) end end +=end end diff --git a/spec/support/test_app_file.rb b/spec/support/test_app_file.rb new file mode 100644 index 00000000..31da08a1 --- /dev/null +++ b/spec/support/test_app_file.rb @@ -0,0 +1,2 @@ +# For use in testing the rpc_server +ENV['TEST_APP_FILE_LOADED'] = 'true' diff --git a/spec/helper/tolerance_matcher.rb b/spec/support/tolerance_matcher.rb similarity index 100% rename from spec/helper/tolerance_matcher.rb rename to spec/support/tolerance_matcher.rb diff --git a/spec/unit/rpc/connector_spec.rb b/spec/unit/rpc/connector_spec.rb deleted file mode 100644 index ae966738..00000000 --- a/spec/unit/rpc/connector_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'spec_helper' - -describe Protobuf::Rpc::Connector do - - describe '.connector_for_client' do - - context 'when set to Socket connector' do - it 'returns a socket connector class reference' do - with_constants "Protobuf::ClientType" => "Socket" do - Protobuf::Rpc::Connector.connector_for_client.should eq(Protobuf::Rpc::Connectors::Socket) - end - end - end - - context 'when set to non Socket Connector' do - it 'returns an eventmachine connector class reference' do - with_constants "Protobuf::ClientType" => "EventMachine" do - Protobuf::Rpc::Connector.connector_for_client.should eq Protobuf::Rpc::Connectors::EventMachine - end - end - end - - context 'when connector type not given' do - it 'returns an eventmachine connector class reference' do - Protobuf::Rpc::Connector.connector_for_client.should eq Protobuf::Rpc::Connectors::EventMachine - end - end - - end - -end diff --git a/spec/unit/rpc/connectors/eventmachine_spec.rb b/spec/unit/rpc/connectors/eventmachine_spec.rb deleted file mode 100644 index e69de29b..00000000 From 1a56df8384b2b1af1413ef7e19c5b6db17938bbd Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 1 Oct 2012 11:49:41 -0600 Subject: [PATCH 0112/1191] Add line to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index da761fa8..a242a15d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ doc *.bin Gemfile.lock tmp/* +ext/defs +ext/out From 8cf417e8ec05dc139a7dd83e840354f1f0b4125a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 1 Oct 2012 12:47:00 -0600 Subject: [PATCH 0113/1191] Remove util_spec, leftover from merge --- spec/lib/protobuf/common/util_spec.rb | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 spec/lib/protobuf/common/util_spec.rb diff --git a/spec/lib/protobuf/common/util_spec.rb b/spec/lib/protobuf/common/util_spec.rb deleted file mode 100644 index 820dbca7..00000000 --- a/spec/lib/protobuf/common/util_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe Protobuf::Util do - - describe '.underscore' do - it 'underscores constant name' do - Protobuf::Util.underscore("HelloMoto").should eq "hello_moto" - end - - context 'when constant name has uppercased word' do - it 'keeps the uppercased word together' do - Protobuf::Util.underscore("UPPERCase").should eq "upper_case" - Protobuf::Util.underscore("MDXService").should eq "mdx_service" - end - end - end -end \ No newline at end of file From df55894842ee88e21f7848ab78879ab08f8fb710 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 1 Oct 2012 14:16:28 -0600 Subject: [PATCH 0114/1191] update specs to reflect new connector structure --- lib/protobuf/rpc/connector.rb | 8 +++-- spec/benchmark/tasks.rb | 3 ++ spec/functional/evented_server_spec.rb | 2 ++ spec/functional/socket_server_spec.rb | 1 + spec/functional/zmq_server_spec.rb | 1 + spec/lib/protobuf/cli_spec.rb | 18 ---------- spec/lib/protobuf/rpc/client_spec.rb | 1 + spec/lib/protobuf/rpc/connector_spec.rb | 10 +++--- .../connectors/eventmachine_client_spec.rb | 33 ------------------- .../rpc/servers/socket_server_spec.rb | 26 ++++----------- .../protobuf/rpc/servers/zmq/broker_spec.rb | 6 +++- .../protobuf/rpc/servers/zmq/server_spec.rb | 6 +++- .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 6 +++- .../protobuf/rpc/servers/zmq/worker_spec.rb | 6 +++- 14 files changed, 45 insertions(+), 82 deletions(-) delete mode 100644 spec/lib/protobuf/rpc/connectors/eventmachine_client_spec.rb diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb index ed5ad88c..4b96fb25 100644 --- a/lib/protobuf/rpc/connector.rb +++ b/lib/protobuf/rpc/connector.rb @@ -3,8 +3,9 @@ module Rpc class Connector # Returns a connector class for the pre-defined connector_type. - def self.connector_for_client - @_connector ||= case ::Protobuf.connector_type + def self.connector_for_client(reload = false) + if reload || @_connector.nil? + @_connector = case ::Protobuf.connector_type when :evented then ::Protobuf::Rpc::Connectors::EventMachine when :zmq then @@ -12,6 +13,9 @@ def self.connector_for_client else ::Protobuf::Rpc::Connectors::Socket end + end + + return @_connector end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 52861278..45f557ff 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -61,6 +61,7 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" + ::Protobuf::Rpc::Connector.connector_for_client(true) EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| @@ -76,6 +77,7 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) def sock_client_em_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" + ::Protobuf::Rpc::Connector.connector_for_client(true) EM.stop if EM.reactor_running? em_thread = Thread.new { EM.run } Thread.pass until EM.reactor_running? @@ -96,6 +98,7 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" + ::Protobuf::Rpc::Connector.connector_for_client(true) StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| client = Spec::Proto::TestService.client(:async => false, :port => 9399) diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index a0c2238d..47351fe1 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -3,6 +3,8 @@ describe 'Functional EventMachine Client' do before(:each) do + load 'protobuf/evented.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION) end diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 35952763..54cbea72 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -4,6 +4,7 @@ describe 'Functional Socket Client' do before(:all) do load "protobuf/socket.rb" + ::Protobuf::Rpc::Connector.connector_for_client(true) Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 0ab5b3a7..37670e06 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -4,6 +4,7 @@ describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" + ::Protobuf::Rpc::Connector.connector_for_client(true) Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index f5b4a41c..b103a42b 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -85,24 +85,6 @@ end end - context 'pre-cache options' do - let(:test_args) { [ '--pre_cache_definitions' ] } - - it 'causes the message sub-classes to be pre-cached' do - ::Protobuf::Message.should_receive(:pre_cache_class_definitions) - described_class.start(args) - end - - context 'when pre-cache option is not present' do - let(:test_args) { [] } - - it 'does not invoke the pre-cache call' do - ::Protobuf::Message.should_not_receive(:pre_cache_class_definitions) - described_class.start(args) - end - end - end - context 'gc options' do context 'when gc options are not present' do diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index fc484038..f4d15d00 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -4,6 +4,7 @@ describe Protobuf::Rpc::Client do before(:each) do load 'protobuf/evented.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION) end diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index 8f005890..0f485482 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -5,34 +5,34 @@ describe ::Protobuf::Rpc::Connector do - describe '.connector_for_client' do + describe '.connector_for_client(true)' do after { described_class.instance_variable_set(:@_connector, nil) } context 'Protobuf.connector_type is socket' do it 'returns a socket connector class' do ::Protobuf.connector_type = :socket - described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::Socket + described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket end end context 'Protobuf.connector_type is not a known value' do it 'returns a socket connector class' do ::Protobuf.stub(:connector_type).and_return('some value') - described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::Socket + described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket end end context 'Protobuf.connector_type is evented' do it 'returns an eventmachine connector class' do ::Protobuf.connector_type = :evented - described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::EventMachine + described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::EventMachine end end context 'Protobuf.connector_type is zmq' do it 'returns a zmq connector class' do ::Protobuf.connector_type = :zmq - described_class.connector_for_client.should eq ::Protobuf::Rpc::Connectors::Zmq + described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Zmq end end diff --git a/spec/lib/protobuf/rpc/connectors/eventmachine_client_spec.rb b/spec/lib/protobuf/rpc/connectors/eventmachine_client_spec.rb deleted file mode 100644 index 6f282e66..00000000 --- a/spec/lib/protobuf/rpc/connectors/eventmachine_client_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper' -require 'protobuf/evented' - -describe ::Protobuf::Rpc::Connectors::EMClient do - describe '#send_data' do - context 'when sending data errs' do - let(:buffer_double) do - bd = double(Protobuf::Rpc::Buffer) - bd.should_receive(:set_data) - bd - end - - it 'sets the error instance' do - buffer_double.should_receive(:write).and_raise(RuntimeError.new('Failure for testing')) - Protobuf::Rpc::Buffer.stub(:new).with(:read).and_return(Protobuf::Rpc::Buffer.new(:read)) - Protobuf::Rpc::Buffer.stub(:new).with(:write).and_return(buffer_double) - error = nil - test_proc = Proc.new do - StubServer.new do |server| - client = ::Spec::Proto::TestService.client - client.find(:name => 'Test Name', :active => true) do |c| - c.on_failure do |f| - error = f - end - end - end - end - test_proc.call - error.should_not be_nil - end - end - end -end diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 08768c68..4f69b762 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -5,9 +5,14 @@ require 'protobuf/socket' describe Protobuf::Rpc::Socket::Server do - before(:each) { load 'protobuf/socket.rb' } + before(:each) do + load 'protobuf/socket.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) + end before(:all) do + load 'protobuf/socket.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } @@ -37,23 +42,4 @@ described_class.running?.should be_true end - context "Eventmachine client" do - it "calls the service in the client request" do - ::Protobuf::Rpc::Connector.stub(:connector_for_client).and_return(::Protobuf::Rpc::Connectors::EventMachine) - client = Spec::Proto::TestService.client(:async => false, :port => 9399, :host => "127.0.0.1") - - client.find(:name => "Test Name", :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(Spec::Proto::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end - end - end - - end - end diff --git a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb index 6cd61014..01301d06 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb @@ -1,7 +1,11 @@ require 'spec_helper' describe ::Protobuf::Rpc::Zmq::Broker do - before(:each) { load 'protobuf/zmq.rb' } + before(:each) do + load 'protobuf/zmq.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) + end + after(:each) do subject.teardown end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 70378101..3d3f32c8 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -2,7 +2,11 @@ require 'protobuf/rpc/servers/zmq/server' describe Protobuf::Rpc::Zmq::Server do - before(:each) { load 'protobuf/zmq.rb' } + before(:each) do + load 'protobuf/zmq.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) + end + describe '.running?' do it 'returns true if running' do described_class.instance_variable_set(:@running, true) diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index d4e6d5a6..f4f87cf2 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -5,7 +5,11 @@ class UtilTest end describe ::Protobuf::Rpc::Zmq::Util do - before(:each) { load 'protobuf/zmq.rb' } + before(:each) do + load 'protobuf/zmq.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) + end + subject { UtilTest.new } describe '#zmq_error_check' do it 'raises when the error code is less than 0' do diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 2ab8f768..cbc47d46 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -1,7 +1,11 @@ require 'spec_helper' describe ::Protobuf::Rpc::Zmq::Worker do - before(:each) { load 'protobuf/zmq.rb' } + before(:each) do + load 'protobuf/zmq.rb' + ::Protobuf::Rpc::Connector.connector_for_client(true) + end + after(:each) do subject.instance_variable_get(:@socket).close subject.instance_variable_get(:@zmq_context).terminate From 911eade3e46a1da4462485fd4b99de6c4d13443d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 1 Oct 2012 14:20:42 -0600 Subject: [PATCH 0115/1191] Bump version 2.0.0.rc1 --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a83d6604..423a3b6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (1.4.2) + protobuf (2.0.0.rc1) activesupport ffi multi_json diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 1b48500d..1b425500 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '1.4.2' + VERSION = '2.0.0.rc1' PROTOC_VERSION = '2.4.1' end From 4f0e9fcdc628c87553403bcde6aa08354c890b11 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 1 Oct 2012 14:56:52 -0600 Subject: [PATCH 0116/1191] update rprotoc to check for bundles and dlls --- bin/rprotoc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/rprotoc b/bin/rprotoc index 19c5d2aa..97c21ce4 100755 --- a/bin/rprotoc +++ b/bin/rprotoc @@ -3,7 +3,17 @@ require 'rubygems' require 'ffi' -GENERATOR_FILE_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "ruby_generator.so")) +base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) + +GENERATOR_FILE_PATH = case + when File.exists?(File.join(base_dir, "ruby_generator.bundle")) then + File.join(base_dir, "ruby_generator.bundle") + when File.exists?(File.join(base_dir, "ruby_generator.dll")) then + File.join(base_dir, "ruby_generator.dll") + else + File.join(base_dir, "ruby_generator.so") + end + unless File.exists?(GENERATOR_FILE_PATH) $stdout << <<-WARNING Cannot locate shared object to plugin to protocol buffers generator. From ff7ca603de034f7e624a1285cab5a896561de27e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 1 Oct 2012 14:59:36 -0600 Subject: [PATCH 0117/1191] Bump version 2.0.0.rc2 --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 423a3b6a..24234c3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (2.0.0.rc1) + protobuf (2.0.0.rc2) activesupport ffi multi_json diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 1b425500..de7ede4c 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.0.rc1' + VERSION = '2.0.0.rc2' PROTOC_VERSION = '2.4.1' end From 04d575ec2161b29b3fb797619cfbfbf46229eee1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 2 Oct 2012 12:28:38 -0600 Subject: [PATCH 0118/1191] Add stderr warnings for deprecated fields Fields marked as [deprecated=true] in the proto definition will now print a warning to STDERR when accessed or written to. Add `print_deprecation_warnings?` configuration option to Protobuf module. Add option to rpc_server as a boolean switch (default: true). Default can be overridden via by setting PB_IGNORE_DEPRECATIONS in the process' environment. This is useful for production environments where we do not want log pollution. Add `BaseField#deprecated?` method to simply return the deprecated status of the field. Remove unused `gc_pause_server_serialization` option from Protobuf module and rpc_server options. --- lib/protobuf.rb | 59 ++++++++++++++++-------------- lib/protobuf/cli.rb | 31 +++++++++------- lib/protobuf/field/base_field.rb | 24 ++++++++++--- lib/protobuf/message.rb | 1 + lib/protobuf/rpc/server.rb | 4 +-- spec/lib/protobuf/cli_spec.rb | 41 +++++++++++++++------ spec/lib/protobuf_spec.rb | 62 ++++++++++++++++++++++++++++++++ 7 files changed, 166 insertions(+), 56 deletions(-) create mode 100644 spec/lib/protobuf_spec.rb diff --git a/lib/protobuf.rb b/lib/protobuf.rb index a34bf2c6..0738dc09 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -14,13 +14,31 @@ module Protobuf module_function + # Connector Type + # + # Default: socket + # + # Symbol value which denotes the type of connector to use + # during client requests to an RPC server. + def self.connector_type + @_connector_type ||= DEFAULT_CONNECTOR_TYPE + end + + def self.connector_type=(type) + raise ArgumentError, 'Invalid connector type given' unless VALID_CONNECTOR_TYPES.include?(type) + @_connector_type = type + end + + # GC Pause during server requests # + # Default: false + # # Boolean value to tell the server to disable # the Garbage Collector when handling an rpc request. # Once the request is completed, the GC is enabled again. # This optomization provides a huge boost in speed to rpc requests. - def self.gc_pause_server_request + def self.gc_pause_server_request? return @_gc_pause_server_request unless @_gc_pause_server_request.nil? gc_pause_server_request = false end @@ -29,36 +47,25 @@ def self.gc_pause_server_request=(value) @_gc_pause_server_request = !!value end - # GC Pause during serializations (server-side only) + # Print Deprecation Warnings # - # Boolean value to tell the server to disable - # the Garbage Collector when serializing a response proto. - # Once the serialization is completed, the GC is enabled again. - # This optomization provides a large boost in speed to rpc requests. - # Note that this option is ignored if gc_pause_server_request is - # enabled since serialization is during the request cycle. - def self.gc_pause_server_serialization - return @_gc_pause_server_serialization unless @_gc_pause_server_serialization.nil? - gc_pause_server_serialization = false + # Default: true + # + # Simple boolean to define whether we want field deprecation warnings to + # be printed to stderr or not. The rpc_server has an option to set this value + # explicitly, or you can turn this option off by setting + # ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value. + # + # The rpc_server option will override the ENV setting. + def self.print_deprecation_warnings? + return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil? + print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true end - def self.gc_pause_server_serialization=(value) - @_gc_pause_server_serialization = !!value + def self.print_deprecation_warnings=(value) + @_print_deprecation_warnings = !!value end - # Connector Type - # - # Symbol value which denotes the type of connector to use - # during client requests to an RPC server. - def self.connector_type - @_connector_type ||= DEFAULT_CONNECTOR_TYPE - end - - def self.connector_type=(type) - raise 'Invalid connector type given' unless VALID_CONNECTOR_TYPES.include?(type) - @_connector_type = type - end - end require 'protobuf/rpc/client' diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 92a776a0..0290f572 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -16,22 +16,22 @@ class CLI < ::Thor desc 'start APP_FILE', 'Run the RPC server in the given mode, preloading the given APP_FILE. This is the default task.' - option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-o), :desc => 'Host to bind.' - option :port, :type => :numeric, :default => 9595, :aliases => %w(-p), :desc => 'Port to bind.' + option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-o), :desc => 'Host to bind.' + option :port, :type => :numeric, :default => 9595, :aliases => %w(-p), :desc => 'Port to bind.' - option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.' - option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' + option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.' + option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' - option :log, :type => :string, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' - 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/)' + option :log, :type => :string, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' + 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/)' - option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.' - option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' - option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' + option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.' + option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' + option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' - option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' - option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' - option :gc_pause_serialization, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during serialization.' + option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' + option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' + option :print_deprecation_warnings, :type => :boolean, :default => true, :desc => 'Cause use of deprecated fields to be printed or ignored.' def start(app_file) debug_say 'Configuring the rpc_server process' @@ -42,6 +42,7 @@ def start(app_file) configure_server_mode require_protobuf! configure_gc + configure_deprecation_warnings run_if_no_abort { require_application!(app_file) } run_if_no_abort { configure_process_name(app_file) } @@ -58,11 +59,15 @@ def version no_tasks do + # Tell protobuf how to handle the printing of deprecated field usage. + def configure_deprecation_warnings + ::Protobuf.print_deprecation_warnings = options.print_deprecation_warnings? + end + # If we pause during request we don't need to pause in serialization def configure_gc debug_say 'Configuring gc' ::Protobuf.gc_pause_server_request = options.gc_pause_request? - ::Protobuf.gc_pause_server_serialization = (!options.gc_pause_request? && options.gc_pause_serialization?) end # Setup the protobuf logger. diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 694608d8..708bf1f8 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -8,7 +8,7 @@ class BaseField # Attributes # attr_reader :message_class, :rule, :type, :name, :tag, :default, :default_value, :setter_method_name, :getter_method_name - + ## # Class Methods # @@ -28,6 +28,7 @@ def initialize(message_class, rule, type, name, tag, options) @default = options.delete(:default) @extension = options.delete(:extension) @packed = repeated? && options.delete(:packed) + @deprecated = options.delete(:deprecated) unless options.empty? warn "WARNING: Invalid options: #{options.inspect} (in #{@message_class.name.split('::').last}.#{@name})" end @@ -134,9 +135,14 @@ def optional? @_optional = (@rule == :optional) end + # Is this a deprecated field? + def deprecated? + !! @deprecated + end + # Is this a packed repeated field? def packed? - !!@packed + !! @packed end # Upper limit for this field. @@ -153,9 +159,15 @@ def to_s "#{@rule} #{@type} #{@name} = #{@tag} #{@default ? "[default=#{@default.inspect}]" : ''}" end + def warn_if_deprecated + if ::Protobuf.print_deprecation_warnings? && deprecated? + $stderr.puts("[WARNING] #{@message_class.name}##{@name} field usage is deprecated.") + end + end + private - ## + ## # Private Instance Methods # def define_accessor @@ -171,6 +183,7 @@ def define_array_setter field = self @message_class.class_eval do define_method(field.setter_method_name) do |val| + field.warn_if_deprecated @values[field.name].replace(val) end end @@ -180,6 +193,7 @@ def define_getter field = self @message_class.class_eval do define_method(field.getter_method_name) do + field.warn_if_deprecated @values.fetch(field.name, field.default_value) end end @@ -189,6 +203,7 @@ def define_setter field = self @message_class.class_eval do define_method(field.setter_method_name) do |val| + field.warn_if_deprecated if val.nil? @values.delete(field.name) elsif field.acceptable?(val) @@ -205,6 +220,7 @@ def typed_default_value @default end end - end + + end end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index e147d0ca..ea10f266 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -372,5 +372,6 @@ def to_hash def to_json to_hash.to_json end + end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index cf489ec7..046959d3 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -20,7 +20,7 @@ def handle_client # Call the service method log_debug { "[#{log_signature}] Dispatching client request to service" } - ::GC.disable if ::Protobuf.gc_pause_server_request + ::GC.disable if ::Protobuf.gc_pause_server_request? invoke_rpc_method rescue => error # Ensure we're handling any errors that try to slip out the back door @@ -133,7 +133,7 @@ def send_response @stats.log_stats @did_respond = true ensure - ::GC.enable if ::Protobuf.gc_pause_server_request + ::GC.enable if ::Protobuf.gc_pause_server_request? end end end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index b103a42b..18f89e16 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -92,8 +92,7 @@ it 'sets both request and serialization pausing to false' do described_class.start(args) - ::Protobuf.gc_pause_server_request.should be_false - ::Protobuf.gc_pause_server_serialization.should be_false + ::Protobuf.gc_pause_server_request?.should be_false end end @@ -102,18 +101,38 @@ it 'sets the configuration option to GC pause server request' do described_class.start(args) - ::Protobuf.gc_pause_server_request.should be_true + ::Protobuf.gc_pause_server_request?.should be_true end end + end - context 'serialization pausing' do - let(:test_args) { [ '--gc_pause_serialization' ] } - - it 'sets the configuration option to GC pause server serializations' do - described_class.start(args) - ::Protobuf.gc_pause_server_serialization.should be_true - end - end + context 'deprecation options' do + context 'when not given' do + let(:test_args) { [] } + + it 'sets the deprecation warning flag to its default value' do + described_class.start(args) + ::Protobuf.print_deprecation_warnings?.should be_true + end + end + + context 'when enabled' do + let(:test_args) { [ '--print_deprecation_warnings' ] } + + it 'sets the deprecation warning flag to true' do + described_class.start(args) + ::Protobuf.print_deprecation_warnings?.should be_true + end + end + + context 'when disabled' do + let(:test_args) { [ '--no-print_deprecation_warnings' ] } + + it 'sets the deprecation warning flag to false' do + described_class.start(args) + ::Protobuf.print_deprecation_warnings?.should be_false + end + end end context 'run modes' do diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb new file mode 100644 index 00000000..ee35e9e8 --- /dev/null +++ b/spec/lib/protobuf_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' +require 'protobuf' + +describe ::Protobuf do + + describe '.connector_type' do + before { described_class.instance_variable_set(:@_connector_type, nil) } + + it 'defaults to socket' do + described_class.connector_type.should eq :socket + end + + it 'accepts socket, evented, or zmq' do + [:socket, :evented, :zmq].each do |type| + described_class.connector_type = type + described_class.connector_type.should eq type + end + end + + it 'does not accept other types' do + [:hello, :world].each do |type| + expect { + described_class.connector_type = type + }.to raise_error(ArgumentError) + end + end + end + + describe '.gc_pause_server_request?' do + before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) } + + it 'defaults to a false value' do + described_class.gc_pause_server_request?.should be_false + end + + it 'is settable' do + described_class.gc_pause_server_request = true + described_class.gc_pause_server_request?.should be_true + end + end + + describe '.print_deprecation_warnings?' do + before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) } + + it 'defaults to a true value' do + described_class.print_deprecation_warnings?.should be_true + end + + it 'is settable' do + described_class.print_deprecation_warnings = false + described_class.print_deprecation_warnings?.should be_false + end + + context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do + it 'defaults to a false value' do + ENV['PB_IGNORE_DEPRECATIONS'] = '1' + described_class.print_deprecation_warnings?.should be_false + end + end + end + +end From 8aca031fc3ca72ff28a6c81ec3cc32e3db446fdc Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 2 Oct 2012 14:31:25 -0600 Subject: [PATCH 0119/1191] Support multiple extension field ranges per message --- lib/protobuf/field/extension_fields.rb | 16 ++++++++++++---- lib/protobuf/message.rb | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/field/extension_fields.rb b/lib/protobuf/field/extension_fields.rb index 43bd8ad1..e0175a44 100644 --- a/lib/protobuf/field/extension_fields.rb +++ b/lib/protobuf/field/extension_fields.rb @@ -4,20 +4,28 @@ class ExtensionFields < Hash ## # Constructor # - def initialize(key_range=0..-1) - @key_range = key_range + def initialize + @ranges = [] end ## # Public Instance Methods # + + # Append a range to the list of ranges. + def add_range(range = (0..-1)) + @ranges << range + end + + # Set value at tag location, if tag is in a valid range. def []=(key, value) - raise RangeError, "#{key} is not in #{@key_range}" unless @key_range.include?(key) + raise RangeError, "#{key} is not in #{@ranges.join(', ')}" unless include_tag?(key) super end + # Check if the given tag exists in any of the defined ranges. def include_tag?(tag) - @key_range.include?(tag) + @ranges.any? { |range| range.include?(tag) } end end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index ea10f266..a656cf89 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -23,7 +23,7 @@ def self.all_fields # Reserve field numbers for extensions. Don't use this method directly. def self.extensions(range) - @extension_fields = ::Protobuf::Field::ExtensionFields.new(range) + extension_fields.add_range(range) end # Define a required field. Don't use this method directly. @@ -53,7 +53,7 @@ def self.define_field(rule, type, fname, tag, options) field_definition = Field.build(self, rule, type, fname, tag, options) field_name_hash[fname.to_sym] = field_definition - repeated_collection << field_definition if rule == :repeated + repeated_collection << field_definition if rule == :repeated field_hash[tag] = field_definition end From 39fcbfb5f194fe5e8447605abe99429d4aa872d7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Oct 2012 16:11:47 -0600 Subject: [PATCH 0120/1191] update to using arrays to store fields with offsets instead of hashes --- lib/protobuf/field/base_field.rb | 13 ++- lib/protobuf/field/extension_fields.rb | 4 +- lib/protobuf/message.rb | 109 +++++++------------------ 3 files changed, 42 insertions(+), 84 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 694608d8..66ffbbda 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -159,18 +159,29 @@ def to_s # Private Instance Methods # def define_accessor - define_getter if repeated? + define_array_getter define_array_setter else + define_getter define_setter end end + def define_array_getter + field = self + @message_class.class_eval do + define_method(field.getter_method_name) do + @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) + end + end + end + def define_array_setter field = self @message_class.class_eval do define_method(field.setter_method_name) do |val| + @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) @values[field.name].replace(val) end end diff --git a/lib/protobuf/field/extension_fields.rb b/lib/protobuf/field/extension_fields.rb index 43bd8ad1..0cc21170 100644 --- a/lib/protobuf/field/extension_fields.rb +++ b/lib/protobuf/field/extension_fields.rb @@ -1,10 +1,10 @@ module Protobuf module Field - class ExtensionFields < Hash + class ExtensionFields < Array ## # Constructor # - def initialize(key_range=0..-1) + def initialize(key_range = 0..-1) @key_range = key_range end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index e147d0ca..d046efd2 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -8,16 +8,15 @@ module Protobuf class Message STRING_ENCODING = "ASCII-8BIT".freeze - def self.inherited(klass) - @_children ||= Set.new - @_children << klass - end - def self.all_fields @all_fields ||= begin - fields_hash = fields.merge(extension_fields) - ordered_keys = fields_hash.keys.sort - ordered_keys.map { |key| fields_hash[key] } + all_fields_array = [] + max_fields = fields.size > extension_fields.size ? fields.size : extension_fields.size + max_fields.times do |field_number| + all_fields_array << (fields[field_number] || extension_fields[field_number]) + end + all_fields_array.compact! + all_fields_array end end @@ -43,18 +42,16 @@ def self.repeated(type, name, tag, options={}) # Define a field. Don't use this method directly. def self.define_field(rule, type, fname, tag, options) - field_hash = options[:extension] ? extension_fields : fields - field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name - repeated_collection = options[:extension] ? repeated_extension_fields : repeated_fields + field_array = options[:extension] ? extension_fields : fields + field_name_hash = options[:extension] ? extension_field_name_to_tag : field_name_to_tag - if field_hash.keys.include?(tag) + if field_array[tag] raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! end field_definition = Field.build(self, rule, type, fname, tag, options) - field_name_hash[fname.to_sym] = field_definition - repeated_collection << field_definition if rule == :repeated - field_hash[tag] = field_definition + field_name_hash[fname] = tag + field_array[tag] = field_definition end def self.extension_tag?(tag) @@ -66,31 +63,23 @@ def self.extension_fields @extension_fields ||= ::Protobuf::Field::ExtensionFields.new end - def self.extension_fields_by_name + def self.extension_field_name_to_tag @extension_fields_by_name ||= {} end # A collection of field object. def self.fields - @fields ||= {} - end - - def self.fields_by_name - @field_by_name ||= {} - end - - def self.repeated_fields - @repeated_fields ||= [] + @fields ||= [] end - def self.repeated_extension_fields - @repeated_extension_fields ||= [] + def self.field_name_to_tag + @field_name_to_tag ||= {} end # Find a field object by +name+. def self.get_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value - fields_by_name[name] ||= fields_by_name[name.to_sym] + fields[field_name_to_tag[name]] end # Find a field object by +tag+ number. @@ -98,62 +87,30 @@ def self.get_field_by_tag(tag) fields[tag] end - def self.field_cache - @field_cache ||= {} - end - - # Find a field object by +tag_or_name+. - def self.get_field(tag_or_name) - field_cache[tag_or_name] ||= case tag_or_name - when Integer then get_field_by_tag(tag_or_name) - when String, Symbol then get_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end - end - def self.get_ext_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value - extension_fields_by_name[name] ||= extension_fields_by_name[name.to_sym] + extension_fields[extension_field_name_to_tag[name]] end def self.get_ext_field_by_tag(tag) extension_fields[tag] end - def self.get_ext_field(tag_or_name) - case tag_or_name - when Integer then get_ext_field_by_tag(tag_or_name) - when String, Symbol then get_ext_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end - end - ## # Constructor # def initialize(values={}) @values = {} - self.class.repeated_fields.each do |field| - @values[field.name] = Field::FieldArray.new(field) - end - - self.class.repeated_extension_fields.each do |field| - @values[field.name] = Field::FieldArray.new(field) - end - - values.each { |tag, val| self[tag] = val} + values.each { |name, val| self[name] = val} end def initialized? - fields.all? {|tag, field| field.initialized?(self) } && \ - extension_fields.all? {|tag, field| field.initialized?(self) } + all_fields.all? { |field| field.initialized?(self) } end - def has_field?(tag_or_name) - field = get_field(tag_or_name) || get_ext_field(tag_or_name) - raise ArgumentError, "unknown field: #{tag_or_name.inspect}" unless field - @values.has_key?(field.name) + def has_field?(name) + @values.has_key?(name) end def ==(obj) @@ -268,17 +225,16 @@ def set_field(tag, bytes) field.set(self, bytes) if field end - def [](tag_or_name) - if field = get_field(tag_or_name) || get_ext_field(tag_or_name) + def [](name) + if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.name) else raise NoMethodError, "No such field: #{tag_or_name.inspect}" end end - def []=(tag_or_name, value) - if field = get_field(tag_or_name) || get_ext_field(tag_or_name) - # __send__("#{field.name}=", value) + def []=(name, value) + if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.setter_method_name, value) else raise NoMethodError, "No such field: #{tag_or_name.inspect}" @@ -287,11 +243,11 @@ def []=(tag_or_name, value) # Returns a hash; which key is a tag number, and value is a field object. def all_fields - @_all_fields ||= self.class.all_fields + self.class.all_fields end def fields - @_fields ||= self.class.fields + self.class.fields end # Returns field object or +nil+. @@ -304,11 +260,6 @@ def get_field_by_tag(tag) self.class.get_field_by_tag(tag) end - # Returns field object or +nil+. - def get_field(tag_or_name) - self.class.get_field(tag_or_name) - end - # Returns extension fields. See Message#fields method. def extension_fields self.class.extension_fields @@ -322,10 +273,6 @@ def get_ext_field_by_tag(tag) # :nodoc: self.class.get_ext_field_by_tag(tag) end - def get_ext_field(tag_or_name) # :nodoc: - self.class.get_ext_field(tag_or_name) - end - # Iterate over a field collection. # message.each_field do |field_object, value| # # do something From 6130a9365ffd9d30c915156198fe74f0bbf3a9ba Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Oct 2012 17:07:24 -0600 Subject: [PATCH 0121/1191] keep enum values in array instead of finding all constants and rework acceptable in varint --- lib/protobuf/enum.rb | 49 ++++++++++++++++-------------- lib/protobuf/field/base_field.rb | 2 ++ lib/protobuf/field/varint_field.rb | 10 +++--- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 3968c37b..5b4eab2f 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -2,30 +2,33 @@ module Protobuf class Enum + + def self.name_by_value(value) + @names[value] + end + + def self.valid_tag?(tag) + !! name_by_value(tag) + end + + def self.define(name, value) + enum_value = EnumValue.new(self, name, value) + const_set(name, enum_value) + @values ||= {} + @names ||= [] + @values[name] = enum_value + @names[value] = name + end + + def self.values + @values + end + + ## + # Class Aliases + # class << self - attr_reader :values - - def name_by_value(value) - if not defined?(@values) - constants.find {|c| const_get(c) == value} # for compatibility - else - @values_index ||= @values.inject({}) {|hash, (n, v)| hash[v.value] = n; hash } - @values_index[value] - end - end - - alias get_name_by_tag name_by_value - - def valid_tag?(tag) - !! name_by_value(tag) - end - - def define(name, value) - enum_value = EnumValue.new(self, name, value) - const_set(name, enum_value) - @values ||= {} - @values[name] = enum_value - end + alias_method :get_name_by_tag, :name_by_value end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 66ffbbda..e8d1233c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -204,6 +204,8 @@ def define_setter @values.delete(field.name) elsif field.acceptable?(val) @values[field.name] = val + else + raise TypeError, "unacceptable value #{val} for type #{field.type}" end end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 2c1a252e..b0070287 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -4,8 +4,8 @@ module Protobuf module Field class VarintField < BaseField INT32_MAX = 2**31 - 1 - INT32_MIN = -2**31 - INT64_MAX = 2**63 - 1 + INT32_MIN = -2**31 + INT64_MAX = 2**63 - 1 INT64_MIN = -2**63 UINT32_MAX = 2**32 - 1 UINT64_MAX = 2**64 - 1 @@ -26,8 +26,8 @@ def self.decode(bytes) end def self.encode(value) - raise RangeError, "#{value} is negative" if value < 0 return [value].pack('C') if value < 128 + bytes = [] until value == 0 bytes << (0x80 | (value & 0x7f)) @@ -41,9 +41,7 @@ def self.encode(value) # Public Instance Methods # def acceptable?(val) - raise TypeError, val.class.name unless val.is_a?(Integer) - raise RangeError if val < min || max < val - true + (val > min || val < max) rescue false end def decode(value) From a7d5eee588535ba28495992c5c4c61cd06393245 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Oct 2012 17:10:21 -0600 Subject: [PATCH 0122/1191] correct typo in raise --- lib/protobuf/message.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index d046efd2..b7d75637 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -229,7 +229,7 @@ def [](name) if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.name) else - raise NoMethodError, "No such field: #{tag_or_name.inspect}" + raise NoMethodError, "No such field: #{name.inspect}" end end @@ -237,7 +237,7 @@ def []=(name, value) if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.setter_method_name, value) else - raise NoMethodError, "No such field: #{tag_or_name.inspect}" + raise NoMethodError, "No such field: #{name.inspect}" end end From 2fcff34916a9848c4a07f21e63482955e1b88dd8 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Oct 2012 10:54:36 -0600 Subject: [PATCH 0123/1191] add value_to_name to enum field --- lib/protobuf/enum.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 5b4eab2f..784f2459 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -3,6 +3,15 @@ module Protobuf class Enum + def self.define(name, value) + enum_value = EnumValue.new(self, name, value) + const_set(name, enum_value) + @values ||= {} + @names ||= [] + @values[name] = enum_value + @names[value] = name + end + def self.name_by_value(value) @names[value] end @@ -11,13 +20,8 @@ def self.valid_tag?(tag) !! name_by_value(tag) end - def self.define(name, value) - enum_value = EnumValue.new(self, name, value) - const_set(name, enum_value) - @values ||= {} - @names ||= [] - @values[name] = enum_value - @names[value] = name + def self.value_by_name(name) + @values[name] end def self.values From 8110135ae6b26acf0a50ae62ebe01696288de76f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Oct 2012 16:11:47 -0600 Subject: [PATCH 0124/1191] update to using arrays to store fields with offsets instead of hashes --- lib/protobuf/field/base_field.rb | 13 ++- lib/protobuf/field/extension_fields.rb | 2 +- lib/protobuf/message.rb | 109 +++++++------------------ 3 files changed, 41 insertions(+), 83 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 708bf1f8..d144945a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -171,19 +171,30 @@ def warn_if_deprecated # Private Instance Methods # def define_accessor - define_getter if repeated? + define_array_getter define_array_setter else + define_getter define_setter end end + def define_array_getter + field = self + @message_class.class_eval do + define_method(field.getter_method_name) do + @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) + end + end + end + def define_array_setter field = self @message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated + @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) @values[field.name].replace(val) end end diff --git a/lib/protobuf/field/extension_fields.rb b/lib/protobuf/field/extension_fields.rb index e0175a44..6d27bf8e 100644 --- a/lib/protobuf/field/extension_fields.rb +++ b/lib/protobuf/field/extension_fields.rb @@ -1,6 +1,6 @@ module Protobuf module Field - class ExtensionFields < Hash + class ExtensionFields < Array ## # Constructor # diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a656cf89..808d19d0 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -8,16 +8,15 @@ module Protobuf class Message STRING_ENCODING = "ASCII-8BIT".freeze - def self.inherited(klass) - @_children ||= Set.new - @_children << klass - end - def self.all_fields @all_fields ||= begin - fields_hash = fields.merge(extension_fields) - ordered_keys = fields_hash.keys.sort - ordered_keys.map { |key| fields_hash[key] } + all_fields_array = [] + max_fields = fields.size > extension_fields.size ? fields.size : extension_fields.size + max_fields.times do |field_number| + all_fields_array << (fields[field_number] || extension_fields[field_number]) + end + all_fields_array.compact! + all_fields_array end end @@ -43,18 +42,16 @@ def self.repeated(type, name, tag, options={}) # Define a field. Don't use this method directly. def self.define_field(rule, type, fname, tag, options) - field_hash = options[:extension] ? extension_fields : fields - field_name_hash = options[:extension] ? extension_fields_by_name : fields_by_name - repeated_collection = options[:extension] ? repeated_extension_fields : repeated_fields + field_array = options[:extension] ? extension_fields : fields + field_name_hash = options[:extension] ? extension_field_name_to_tag : field_name_to_tag - if field_hash.keys.include?(tag) + if field_array[tag] raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! end field_definition = Field.build(self, rule, type, fname, tag, options) - field_name_hash[fname.to_sym] = field_definition - repeated_collection << field_definition if rule == :repeated - field_hash[tag] = field_definition + field_name_hash[fname] = tag + field_array[tag] = field_definition end def self.extension_tag?(tag) @@ -66,31 +63,23 @@ def self.extension_fields @extension_fields ||= ::Protobuf::Field::ExtensionFields.new end - def self.extension_fields_by_name + def self.extension_field_name_to_tag @extension_fields_by_name ||= {} end # A collection of field object. def self.fields - @fields ||= {} - end - - def self.fields_by_name - @field_by_name ||= {} - end - - def self.repeated_fields - @repeated_fields ||= [] + @fields ||= [] end - def self.repeated_extension_fields - @repeated_extension_fields ||= [] + def self.field_name_to_tag + @field_name_to_tag ||= {} end # Find a field object by +name+. def self.get_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value - fields_by_name[name] ||= fields_by_name[name.to_sym] + fields[field_name_to_tag[name]] end # Find a field object by +tag+ number. @@ -98,62 +87,30 @@ def self.get_field_by_tag(tag) fields[tag] end - def self.field_cache - @field_cache ||= {} - end - - # Find a field object by +tag_or_name+. - def self.get_field(tag_or_name) - field_cache[tag_or_name] ||= case tag_or_name - when Integer then get_field_by_tag(tag_or_name) - when String, Symbol then get_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end - end - def self.get_ext_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value - extension_fields_by_name[name] ||= extension_fields_by_name[name.to_sym] + extension_fields[extension_field_name_to_tag[name]] end def self.get_ext_field_by_tag(tag) extension_fields[tag] end - def self.get_ext_field(tag_or_name) - case tag_or_name - when Integer then get_ext_field_by_tag(tag_or_name) - when String, Symbol then get_ext_field_by_name(tag_or_name) - else raise TypeError, tag_or_name.class - end - end - ## # Constructor # def initialize(values={}) @values = {} - self.class.repeated_fields.each do |field| - @values[field.name] = Field::FieldArray.new(field) - end - - self.class.repeated_extension_fields.each do |field| - @values[field.name] = Field::FieldArray.new(field) - end - - values.each { |tag, val| self[tag] = val} + values.each { |name, val| self[name] = val} end def initialized? - fields.all? {|tag, field| field.initialized?(self) } && \ - extension_fields.all? {|tag, field| field.initialized?(self) } + all_fields.all? { |field| field.initialized?(self) } end - def has_field?(tag_or_name) - field = get_field(tag_or_name) || get_ext_field(tag_or_name) - raise ArgumentError, "unknown field: #{tag_or_name.inspect}" unless field - @values.has_key?(field.name) + def has_field?(name) + @values.has_key?(name) end def ==(obj) @@ -268,17 +225,16 @@ def set_field(tag, bytes) field.set(self, bytes) if field end - def [](tag_or_name) - if field = get_field(tag_or_name) || get_ext_field(tag_or_name) + def [](name) + if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.name) else raise NoMethodError, "No such field: #{tag_or_name.inspect}" end end - def []=(tag_or_name, value) - if field = get_field(tag_or_name) || get_ext_field(tag_or_name) - # __send__("#{field.name}=", value) + def []=(name, value) + if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.setter_method_name, value) else raise NoMethodError, "No such field: #{tag_or_name.inspect}" @@ -287,11 +243,11 @@ def []=(tag_or_name, value) # Returns a hash; which key is a tag number, and value is a field object. def all_fields - @_all_fields ||= self.class.all_fields + self.class.all_fields end def fields - @_fields ||= self.class.fields + self.class.fields end # Returns field object or +nil+. @@ -304,11 +260,6 @@ def get_field_by_tag(tag) self.class.get_field_by_tag(tag) end - # Returns field object or +nil+. - def get_field(tag_or_name) - self.class.get_field(tag_or_name) - end - # Returns extension fields. See Message#fields method. def extension_fields self.class.extension_fields @@ -322,10 +273,6 @@ def get_ext_field_by_tag(tag) # :nodoc: self.class.get_ext_field_by_tag(tag) end - def get_ext_field(tag_or_name) # :nodoc: - self.class.get_ext_field(tag_or_name) - end - # Iterate over a field collection. # message.each_field do |field_object, value| # # do something From 120f92b6b2ba3dcef2b8b0c973751f7c7b8ac2ed Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Oct 2012 17:07:24 -0600 Subject: [PATCH 0125/1191] keep enum values in array instead of finding all constants and rework acceptable in varint --- lib/protobuf/enum.rb | 49 ++++++++++++++++-------------- lib/protobuf/field/base_field.rb | 2 ++ lib/protobuf/field/varint_field.rb | 10 +++--- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 3968c37b..5b4eab2f 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -2,30 +2,33 @@ module Protobuf class Enum + + def self.name_by_value(value) + @names[value] + end + + def self.valid_tag?(tag) + !! name_by_value(tag) + end + + def self.define(name, value) + enum_value = EnumValue.new(self, name, value) + const_set(name, enum_value) + @values ||= {} + @names ||= [] + @values[name] = enum_value + @names[value] = name + end + + def self.values + @values + end + + ## + # Class Aliases + # class << self - attr_reader :values - - def name_by_value(value) - if not defined?(@values) - constants.find {|c| const_get(c) == value} # for compatibility - else - @values_index ||= @values.inject({}) {|hash, (n, v)| hash[v.value] = n; hash } - @values_index[value] - end - end - - alias get_name_by_tag name_by_value - - def valid_tag?(tag) - !! name_by_value(tag) - end - - def define(name, value) - enum_value = EnumValue.new(self, name, value) - const_set(name, enum_value) - @values ||= {} - @values[name] = enum_value - end + alias_method :get_name_by_tag, :name_by_value end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d144945a..67ffb1de 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -219,6 +219,8 @@ def define_setter @values.delete(field.name) elsif field.acceptable?(val) @values[field.name] = val + else + raise TypeError, "unacceptable value #{val} for type #{field.type}" end end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 2c1a252e..b0070287 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -4,8 +4,8 @@ module Protobuf module Field class VarintField < BaseField INT32_MAX = 2**31 - 1 - INT32_MIN = -2**31 - INT64_MAX = 2**63 - 1 + INT32_MIN = -2**31 + INT64_MAX = 2**63 - 1 INT64_MIN = -2**63 UINT32_MAX = 2**32 - 1 UINT64_MAX = 2**64 - 1 @@ -26,8 +26,8 @@ def self.decode(bytes) end def self.encode(value) - raise RangeError, "#{value} is negative" if value < 0 return [value].pack('C') if value < 128 + bytes = [] until value == 0 bytes << (0x80 | (value & 0x7f)) @@ -41,9 +41,7 @@ def self.encode(value) # Public Instance Methods # def acceptable?(val) - raise TypeError, val.class.name unless val.is_a?(Integer) - raise RangeError if val < min || max < val - true + (val > min || val < max) rescue false end def decode(value) From 6fdff90e29809a8290af34afac93115848b23803 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Oct 2012 17:10:21 -0600 Subject: [PATCH 0126/1191] correct typo in raise --- lib/protobuf/message.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 808d19d0..a67c34f7 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -229,7 +229,7 @@ def [](name) if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.name) else - raise NoMethodError, "No such field: #{tag_or_name.inspect}" + raise NoMethodError, "No such field: #{name.inspect}" end end @@ -237,7 +237,7 @@ def []=(name, value) if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.setter_method_name, value) else - raise NoMethodError, "No such field: #{tag_or_name.inspect}" + raise NoMethodError, "No such field: #{name.inspect}" end end From 9fd2714cab0a0d9d8b82d9bb46509a05c02f6e0e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Oct 2012 10:54:36 -0600 Subject: [PATCH 0127/1191] add value_to_name to enum field --- lib/protobuf/enum.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 5b4eab2f..784f2459 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -3,6 +3,15 @@ module Protobuf class Enum + def self.define(name, value) + enum_value = EnumValue.new(self, name, value) + const_set(name, enum_value) + @values ||= {} + @names ||= [] + @values[name] = enum_value + @names[value] = name + end + def self.name_by_value(value) @names[value] end @@ -11,13 +20,8 @@ def self.valid_tag?(tag) !! name_by_value(tag) end - def self.define(name, value) - enum_value = EnumValue.new(self, name, value) - const_set(name, enum_value) - @values ||= {} - @names ||= [] - @values[name] = enum_value - @names[value] = name + def self.value_by_name(name) + @values[name] end def self.values From 5c76eaae72fc243061355abbb49c721085bc725c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 4 Oct 2012 00:22:28 -0600 Subject: [PATCH 0128/1191] Fix enum field default constant path The cpp EnumValueDesciptor->full_name() value is beholden to the c++ oddity where the enum type is transparent within the enclosing message type or namespace. In the ruby implementation, this is not valid and so we need to actually insert the enum type's name into the namespace path to the actual enum default value constant. Rework message and enum field generation to re-open the ruby class body and apply the DSL methods in the class context, rather than calling from the fully qualified class namespace itself. This change makes the generated files much easier to read and more rubyish. --- .gitignore | 1 + ext/Makefile | 11 -- ext/ruby_generator/Makefile | 10 ++ ext/ruby_generator/RubyGenerator.cpp | 155 +++++++++++++++------------ ext/ruby_generator/RubyGenerator.h | 27 ++++- ext/ruby_generator/protoc-ruby | Bin 0 -> 137316 bytes 6 files changed, 119 insertions(+), 85 deletions(-) delete mode 100644 ext/Makefile create mode 100644 ext/ruby_generator/Makefile create mode 100755 ext/ruby_generator/protoc-ruby diff --git a/.gitignore b/.gitignore index a242a15d..9ab897a8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ Gemfile.lock tmp/* ext/defs ext/out +ext/ruby_generator/protoc-ruby \ No newline at end of file diff --git a/ext/Makefile b/ext/Makefile deleted file mode 100644 index 12776e75..00000000 --- a/ext/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -all: \ - RubyGenerator.h \ - RubyGenerator.cpp \ - main.cpp - g++ -Wall -I/code/src/utilities/protobuf-2.4.1/src -lprotoc -lprotobuf -lpthread -o protoc-ruby RubyGenerator.cpp main.cpp - -test: - rm -rf test/out/* - ./protoc-ruby --proto_path=defs --ruby_out=out defs/atlas/util.proto defs/atlas/newman/*.proto - -.PHONY: all test diff --git a/ext/ruby_generator/Makefile b/ext/ruby_generator/Makefile new file mode 100644 index 00000000..54fc40b9 --- /dev/null +++ b/ext/ruby_generator/Makefile @@ -0,0 +1,10 @@ +all: \ + RubyGenerator.h \ + RubyGenerator.cpp + g++ -Wall -I/code/src/utilities/protobuf-2.4.1/src -lprotoc -lprotobuf -lpthread -o protoc-ruby RubyGenerator.cpp + +test: + rm -rf test/out/* + ./protoc-ruby --proto_path=../defs --ruby_out=../out ../defs/atlas/util.proto ../defs/atlas/newman/*.proto + +.PHONY: all test diff --git a/ext/ruby_generator/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp index 0302a949..e42f6280 100644 --- a/ext/ruby_generator/RubyGenerator.cpp +++ b/ext/ruby_generator/RubyGenerator.cpp @@ -42,9 +42,7 @@ bool RubyGenerator::Generate(const FileDescriptor* file, PrintNewLine(); PrintEnumsForFileDescriptor(file_, true); - PrintNewLine(); PrintMessagesForFileDescriptor(file_, true); - PrintNewLine(); PrintServices(); @@ -100,60 +98,42 @@ void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descrip } for (int i = 0; i < descriptor->message_type_count(); i++) { - if (print_fields) { - PrintMessageFields(descriptor->message_type(i)); - } - else { - PrintMessageClass(descriptor->message_type(i)); - } + PrintMessage(descriptor->message_type(i), print_fields); } } } void RubyGenerator::PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const { for (int i = 0; i < descriptor->nested_type_count(); i++) { - if (print_fields) { - PrintMessageFields(descriptor->nested_type(i)); - } - else { - PrintMessageClass(descriptor->nested_type(i)); - } + PrintMessage(descriptor->nested_type(i), print_fields); } } // // Print out the given descriptor message as a Ruby class. -void RubyGenerator::PrintMessageClass(const Descriptor* descriptor) const { +void RubyGenerator::PrintMessage(const Descriptor* descriptor, bool print_fields) const { map data; data["class_name"] = descriptor->name(); - printer_->Print(data, "class $class_name$ < ::Protobuf::Message; end"); - PrintNewLine(); + if (print_fields) { + printer_->Print(data, "class $class_name$"); + PrintNewLine(); + printer_->Indent(); - PrintEnumsForDescriptor(descriptor, false); - PrintMessagesForDescriptor(descriptor, false); -} + if (descriptor->enum_type_count() > 0) { + PrintEnumsForDescriptor(descriptor, true); + } -void RubyGenerator::PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const { - if (descriptor->extension_range_count() > 0) { - for (int i = 0; i < descriptor->extension_range_count(); i++) { - const Descriptor::ExtensionRange* range = descriptor->extension_range(i); - map data; - data["message_class"] = Constantize(descriptor->full_name()); - data["start"] = SimpleItoa(range->start); - data["end"] = SimpleItoa(range->end); - printer_->Print(data, "$message_class$.extensions $start$...$end$"); - PrintNewLine(); + if (descriptor->nested_type_count() > 0) { + PrintMessagesForDescriptor(descriptor, true); } - } -} -// Print out the given descriptor message as a Ruby class. -void RubyGenerator::PrintMessageFields(const Descriptor* descriptor) const { - PrintExtensionRangesForDescriptor(descriptor); + PrintExtensionRangesForDescriptor(descriptor); - if (descriptor->field_count() > 0) { - for (int i = 0; i < descriptor->field_count(); i++) { - PrintMessageField(descriptor->field(i)); + // Print Fields + if (descriptor->field_count() > 0) { + for (int i = 0; i < descriptor->field_count(); i++) { + PrintMessageField(descriptor->field(i)); + } } // Print Extension Fields @@ -162,17 +142,53 @@ void RubyGenerator::PrintMessageFields(const Descriptor* descriptor) const { PrintMessageField(descriptor->extension(i)); } } + + printer_->Outdent(); + printer_->Print(data, "end"); PrintNewLine(); } + else if (DescriptorHasNestedTypes(descriptor)) { + printer_->Print(data, "class $class_name$ < ::Protobuf::Message"); + PrintNewLine(); + printer_->Indent(); + + if (descriptor->enum_type_count() > 0) { + PrintEnumsForDescriptor(descriptor, false); + } + + if (descriptor->nested_type_count() > 0) { + PrintMessagesForDescriptor(descriptor, false); + } - PrintEnumsForDescriptor(descriptor, true); - PrintMessagesForDescriptor(descriptor, true); + printer_->Outdent(); + printer_->Print(data, "end"); + PrintNewLine(); + } + else { + printer_->Print(data, "class $class_name$ < ::Protobuf::Message; end"); + } + + PrintNewLine(); +} + +void RubyGenerator::PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const { + if (descriptor->extension_range_count() > 0) { + for (int i = 0; i < descriptor->extension_range_count(); i++) { + const Descriptor::ExtensionRange* range = descriptor->extension_range(i); + map data; + data["message_class"] = Constantize(descriptor->full_name()); + data["start"] = SimpleItoa(range->start); + data["end"] = SimpleItoa(range->end); + printer_->Print(data, "extensions $start$...$end$"); + PrintNewLine(); + } + } } // Print the given FieldDescriptor to the Message DSL methods. void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { map data; - data["message_class"] = Constantize(descriptor->containing_type()->full_name()); + data["field_presence"] = ""; data["field_name"] = descriptor->lowercase_name(); data["tag_number"] = SimpleItoa(descriptor->number()); data["data_type"] = ""; @@ -182,13 +198,13 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { data["extension_opt"] = ""; if (descriptor->is_required()) { - data["field_label"] = "required"; + data["field_presence"] = "required"; } else if (descriptor->is_optional()) { - data["field_label"] = "optional"; + data["field_presence"] = "optional"; } else if (descriptor->is_repeated()) { - data["field_label"] = "repeated"; + data["field_presence"] = "repeated"; } switch (descriptor->type()) { @@ -232,7 +248,7 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { case FieldDescriptor::CPPTYPE_DOUBLE: value = SimpleDtoa(descriptor->default_value_double()); break; case FieldDescriptor::CPPTYPE_FLOAT: value = SimpleFtoa(descriptor->default_value_float()); break; case FieldDescriptor::CPPTYPE_BOOL: value = descriptor->default_value_bool() ? "true" : "false"; break; - case FieldDescriptor::CPPTYPE_ENUM: value = Constantize(descriptor->default_value_enum()->full_name()); break; + case FieldDescriptor::CPPTYPE_ENUM: value = FullEnumNamespace(descriptor->default_value_enum()); break; case FieldDescriptor::CPPTYPE_STRING: value = "\"" + descriptor->default_value_string() + "\""; break; default: break; } @@ -254,15 +270,15 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { } printer_->Print(data, - "$message_class$.$field_label$(" + "$field_presence$ " "$data_type$, " ":$field_name$, " "$tag_number$" "$default_opt$" "$packed_opt$" "$deprecated_opt$" - "$extension_opt$" - ")\n"); + "$extension_opt$"); + PrintNewLine(); } @@ -272,12 +288,7 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { void RubyGenerator::PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const { for (int i = 0; i < descriptor->enum_type_count(); i++) { - if (print_values) { - PrintEnumValues(descriptor->enum_type(i)); - } - else { - PrintEnumClass(descriptor->enum_type(i)); - } + PrintEnum(descriptor->enum_type(i), print_values); } } @@ -291,39 +302,43 @@ void RubyGenerator::PrintEnumsForFileDescriptor(const FileDescriptor* descriptor } for (int i = 0; i < descriptor->enum_type_count(); i++) { - if (print_values) { - PrintEnumValues(descriptor->enum_type(i)); - } - else { - PrintEnumClass(descriptor->enum_type(i)); - } + PrintEnum(descriptor->enum_type(i), print_values); } } } // Print the given enum descriptor as a Ruby class. -void RubyGenerator::PrintEnumClass(const EnumDescriptor* descriptor) const { +void RubyGenerator::PrintEnum(const EnumDescriptor* descriptor, bool print_values) const { map data; data["class_name"] = descriptor->name(); - printer_->Print(data, "class $class_name$ < ::Protobuf::Enum; end"); - PrintNewLine(); -} -// Print the given enum descriptor as a Ruby class. -void RubyGenerator::PrintEnumValues(const EnumDescriptor* descriptor) const { - for (int i = 0; i < descriptor->value_count(); i++) { - PrintEnumValue(descriptor->value(i)); + if (print_values) { + printer_->Print(data, "class $class_name$"); + printer_->Indent(); + PrintNewLine(); + + for (int i = 0; i < descriptor->value_count(); i++) { + PrintEnumValue(descriptor->value(i)); + } + + printer_->Outdent(); + printer_->Print(data, "end"); + PrintNewLine(); } + else { + printer_->Print(data, "class $class_name$ < ::Protobuf::Enum; end"); + } + PrintNewLine(); } // Print the given enum value to the Enum class DSL methods. void RubyGenerator::PrintEnumValue(const EnumValueDescriptor* descriptor) const { map data; - data["enum_class"] = Constantize(descriptor->type()->full_name()); data["name"] = descriptor->name(); data["number"] = ConvertIntToString(descriptor->number()); - printer_->Print(data, "$enum_class$.define :$name$, $number$\n"); + printer_->Print(data, "define :$name$, $number$"); + PrintNewLine(); } // diff --git a/ext/ruby_generator/RubyGenerator.h b/ext/ruby_generator/RubyGenerator.h index 1f01fbe3..8582ea14 100644 --- a/ext/ruby_generator/RubyGenerator.h +++ b/ext/ruby_generator/RubyGenerator.h @@ -46,15 +46,13 @@ class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { void PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const; void PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const; - void PrintMessageClass(const Descriptor* descriptor) const; + void PrintMessage(const Descriptor* descriptor, bool print_fields) const; void PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const; - void PrintMessageFields(const Descriptor* descriptor) const; void PrintMessageField(const FieldDescriptor* descriptor) const; void PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const; void PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const; - void PrintEnumClass(const EnumDescriptor* descriptor) const; - void PrintEnumValues(const EnumDescriptor* descriptor) const; + void PrintEnum(const EnumDescriptor* descriptor, bool print_values) const; void PrintEnumValue(const EnumValueDescriptor* descriptor) const; void PrintServices() const; @@ -152,6 +150,17 @@ class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { return underscored.str(); } + static string FullEnumNamespace(const EnumValueDescriptor* descriptor) { + string parent_enum_type = Constantize(descriptor->type()->full_name()); + string enum_name = descriptor->name(); + + return strings::Substitute("$0::$1", parent_enum_type, enum_name); + } + + static bool DescriptorHasNestedTypes(const Descriptor* descriptor) { + return (descriptor->enum_type_count() > 0 || descriptor->nested_type_count() > 0); + } + }; // class RubyGenerator } // namespace ruby @@ -173,6 +182,16 @@ int _rprotoc_extern(int argc, char* argv[]) { return cli.Run(argc, argv); } +/* + +Use for testing: + +int main(int argc, char* argv[]) { + return _rprotoc_extern(argc, argv); +} + +*/ + #ifdef __cplusplus } #endif diff --git a/ext/ruby_generator/protoc-ruby b/ext/ruby_generator/protoc-ruby new file mode 100755 index 0000000000000000000000000000000000000000..7a53215cfbd97f17bccb89edeacdb23e6944d095 GIT binary patch literal 137316 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 Date: Thu, 4 Oct 2012 00:24:52 -0600 Subject: [PATCH 0129/1191] Re-org test proto files, add compilation step to spec suite --- spec/benchmark/tasks.rb | 15 +++--- spec/functional/evented_server_spec.rb | 16 +++--- spec/functional/socket_server_spec.rb | 14 ++--- spec/functional/zmq_server_spec.rb | 14 ++--- spec/lib/protobuf/message/encoder_spec.rb | 2 +- spec/lib/protobuf/message/enum_spec.rb | 4 +- spec/lib/protobuf/rpc/client_spec.rb | 46 ++++++++-------- .../rpc/servers/evented_server_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 36 ++++++------- spec/proto/test.pb.rb | 54 ------------------- spec/proto/test_service.rb | 30 ----------- spec/proto/test_service_impl.rb | 18 ------- spec/spec_helper.rb | 13 ++++- spec/support/all.rb | 1 - spec/support/server.rb | 2 +- spec/support/silent_constants.rb | 44 --------------- spec/support/test/enum.pb.rb | 32 +++++++++++ spec/support/test/enum.proto | 12 +++++ spec/support/test/resource.pb.rb | 52 ++++++++++++++++++ .../test/resource.proto} | 4 +- spec/support/test/resource_service.rb | 14 +++++ 22 files changed, 200 insertions(+), 227 deletions(-) delete mode 100644 spec/proto/test.pb.rb delete mode 100644 spec/proto/test_service.rb delete mode 100644 spec/proto/test_service_impl.rb delete mode 100644 spec/support/silent_constants.rb create mode 100644 spec/support/test/enum.pb.rb create mode 100644 spec/support/test/enum.proto create mode 100644 spec/support/test/resource.pb.rb rename spec/{proto/test.proto => support/test/resource.proto} (92%) create mode 100644 spec/support/test/resource_service.rb diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 45f557ff..d42519c8 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,6 +1,6 @@ require 'benchmark' require 'support/all' -require 'proto/test_service_impl' +require 'support/test/resource_service' require 'perftools' # Including a way to turn on debug logger for spec runs @@ -11,7 +11,6 @@ end namespace :benchmark do - include SilentConstants def benchmark_wrapper(global_bench = nil) if global_bench @@ -28,7 +27,7 @@ def em_client_em_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new do |server| - client = Spec::Proto::TestService.client(:async => false) + client = ::Test::ResourceService.client(:async => false) benchmark_wrapper(global_bench) do |bench| bench.report("ES / EC") do @@ -46,7 +45,7 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client = ::Test::ResourceService.client(:async => false, :port => 9399) benchmark_wrapper(global_bench) do |bench| bench.report("SS / EC") do @@ -65,7 +64,7 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client = ::Test::ResourceService.client(:async => false, :port => 9399) benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do @@ -83,7 +82,7 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) Thread.pass until EM.reactor_running? StubServer.new(:port => 9399) do |server| - client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client = ::Test::ResourceService.client(:async => false, :port => 9399) benchmark_wrapper(global_bench) do |bench| bench.report("ES / SC") do @@ -100,7 +99,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" ::Protobuf::Rpc::Connector.connector_for_client(true) StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - client = Spec::Proto::TestService.client(:async => false, :port => 9399) + client = ::Test::ResourceService.client(:async => false, :port => 9399) benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do @@ -132,7 +131,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } ::PerfTools::CpuProfiler.start(args[:profile_output]) do - args[:number].to_i.times { Spec::Proto::Resource.new(create_params) } + args[:number].to_i.times { Test::Resource.new(create_params) } end puts args[:profile_output] diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 47351fe1..54a5332f 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -1,23 +1,23 @@ require 'spec_helper' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' describe 'Functional EventMachine Client' do before(:each) do load 'protobuf/evented.rb' ::Protobuf::Rpc::Connector.connector_for_client(true) - ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION) + ::Test::ResourceService.configure(::Test::ResourceService::DEFAULT_LOCATION) end it 'runs fine when required fields are set' do expect { EventMachine.fiber_run do StubServer.new do |server| - client = ::Spec::Proto::TestService.client(:async => false, :timeout => 5) + client = ::Test::ResourceService.client(:async => false, :timeout => 5) client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| succ.name.should eq("Test Name") - succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + succ.status.should eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -34,8 +34,8 @@ error = nil EventMachine.fiber_run do StubServer.new do |server| - request = ::Spec::Proto::ResourceFindRequest.new(:active => true) - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client(:async => false) client.find(request) do |c| c.on_success { raise "shouldn't pass"} @@ -51,8 +51,8 @@ error = nil EventMachine.fiber_run do StubServer.new do |server| - request = ::Spec::Proto::Resource.new(:name => 'Test Name') - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client(:async => false) client.find(request) do |c| c.on_success { raise "shouldn't pass"} diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 54cbea72..85dad77e 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' describe 'Functional Socket Client' do before(:all) do @@ -18,12 +18,12 @@ it 'runs fine when required fields are set' do expect { - client = ::Spec::Proto::TestService.client(:async => false) + client = ::Test::ResourceService.client(:async => false) client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| succ.name.should eq("Test Name") - succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + succ.status.should eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -35,8 +35,8 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - request = ::Spec::Proto::ResourceFindRequest.new(:active => true) - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client(:async => false) client.find(request) do |c| c.on_success { raise "shouldn't pass"} @@ -47,8 +47,8 @@ it 'calls the on_failure callback when the request type is wrong' do error = nil - request = ::Spec::Proto::Resource.new(:name => 'Test Name') - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client(:async => false) client.find(request) do |c| c.on_success { raise "shouldn't pass"} diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 37670e06..8c460747 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' describe 'Functional ZMQ Client' do before(:all) do @@ -18,12 +18,12 @@ it 'runs fine when required fields are set' do expect { - client = ::Spec::Proto::TestService.client(:async => false) + client = ::Test::ResourceService.client(:async => false) client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| succ.name.should eq("Test Name") - succ.status.should eq(::Spec::Proto::StatusType::ENABLED) + succ.status.should eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -35,8 +35,8 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - request = ::Spec::Proto::ResourceFindRequest.new(:active => true) - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client(:async => false) client.find(request) do |c| c.on_success { raise "shouldn't pass"} @@ -47,8 +47,8 @@ it 'calls the on_failure callback when the request type is wrong' do error = nil - request = ::Spec::Proto::Resource.new(:name => 'Test Name') - client = ::Spec::Proto::TestService.client(:async => false) + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client(:async => false) client.find(request) do |c| c.on_success { raise "shouldn't pass"} diff --git a/spec/lib/protobuf/message/encoder_spec.rb b/spec/lib/protobuf/message/encoder_spec.rb index 39d8a938..47e93b17 100644 --- a/spec/lib/protobuf/message/encoder_spec.rb +++ b/spec/lib/protobuf/message/encoder_spec.rb @@ -7,7 +7,7 @@ class EncoderTest describe Protobuf::Encoder do describe '#encode' do context "when there's no value for a required field" do - let(:message) { ::Spec::Proto::Resource.new } + let(:message) { ::Test::Resource.new } let(:stream) { StringIO.new } it "raises a 'message not initialized' error" do expect { diff --git a/spec/lib/protobuf/message/enum_spec.rb b/spec/lib/protobuf/message/enum_spec.rb index 2a5f337f..a4295f62 100644 --- a/spec/lib/protobuf/message/enum_spec.rb +++ b/spec/lib/protobuf/message/enum_spec.rb @@ -3,11 +3,11 @@ describe Protobuf::Enum do context 'when coercing from enum' do - subject { Spec::Proto::StatusType::PENDING } + subject { Test::StatusType::PENDING } it { should eq(0) } end context 'when coercing from integer' do - it { 0.should eq(Spec::Proto::StatusType::PENDING) } + it { 0.should eq(Test::StatusType::PENDING) } end end diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index f4d15d00..e2d35071 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -1,24 +1,24 @@ require 'spec_helper' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' describe Protobuf::Rpc::Client do before(:each) do load 'protobuf/evented.rb' ::Protobuf::Rpc::Connector.connector_for_client(true) - ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION) + ::Test::ResourceService.configure(::Test::ResourceService::DEFAULT_LOCATION) end context "when using fiber based calls" do it "waits for response when running synchronously" do EventMachine.fiber_run do StubServer.new(:delay => 3) do |server| - client = Spec::Proto::TestService.client(:async => false) + client = Test::ResourceService.client(:async => false) start = now client.find(:name => "Test Name", :active => true) do |c| c.on_success do |succ| succ.name.should eq("Test Name") - succ.status.should eq(Spec::Proto::StatusType::ENABLED) + succ.status.should eq(Test::StatusType::ENABLED) end c.on_failure do |err| @@ -36,7 +36,7 @@ it "doesn't wait for response when running async call inside fiber" do EventMachine.fiber_run do StubServer.new(:delay => 3) do |server| - client = Spec::Proto::TestService.client(:async => true) + client = Test::ResourceService.client(:async => true) start = now client.find(:name => "Test Name", :active => true) @@ -50,7 +50,7 @@ subject = Proc.new do EventMachine.run do StubServer.new(:delay => 1) do |server| - client = Spec::Proto::TestService.client(:async => false) + client = Test::ResourceService.client(:async => false) client.find(:name => "Test Name", :active => true) end end @@ -64,7 +64,7 @@ test_proc = Proc.new do EventMachine.fiber_run do StubServer.new(:delay => 2) do |server| - client = Spec::Proto::TestService.client(:async => false, :timeout => 1) + client = Test::ResourceService.client(:async => false, :timeout => 1) client.find(:name => "Test Name", :active => true) do |cl| cl.on_success {} cl.on_failure {|f| error = f} @@ -83,7 +83,7 @@ it "throws a timeout when client timeout is exceeded" do subject = Proc.new do StubServer.new(:delay => 2) do |server| - client = Spec::Proto::TestService.client(:async => false, :timeout => 1) + client = Test::ResourceService.client(:async => false, :timeout => 1) client.find(:name => "Test Name", :active => true) end end @@ -96,7 +96,7 @@ subject = Proc.new do StubServer.new(:delay => 2) do |server| - client = Spec::Proto::TestService.client(:async => false, :timeout => 1) + client = Test::ResourceService.client(:async => false, :timeout => 1) client.find(:name => "Test Name", :active => true) do |c| c.on_failure do |f| failure_message = f.message @@ -116,38 +116,38 @@ context 'when creating a client from a service' do it 'should be able to get a client through the Service#client helper method' do - Spec::Proto::TestService.client(:port => 9191).should eq(Protobuf::Rpc::Client.new(:service => Spec::Proto::TestService, :port => 9191)) + Test::ResourceService.client(:port => 9191).should eq(Protobuf::Rpc::Client.new(:service => Test::ResourceService, :port => 9191)) end it "should be able to override a service location's host and port" do - Spec::Proto::TestService.located_at 'somewheregreat.com:12345' - clean_client = Spec::Proto::TestService.client + Test::ResourceService.located_at 'somewheregreat.com:12345' + clean_client = Test::ResourceService.client clean_client.options[:host].should eq('somewheregreat.com') clean_client.options[:port].should eq(12345) - updated_client = Spec::Proto::TestService.client(:host => 'amazing.com', :port => 54321) + updated_client = Test::ResourceService.client(:host => 'amazing.com', :port => 54321) updated_client.options[:host].should eq('amazing.com') updated_client.options[:port].should eq(54321) end it 'should be able to define the syncronicity of the client request' do - client = Spec::Proto::TestService.client(:async => false) + client = Test::ResourceService.client(:async => false) client.options[:async].should be_false client.async?.should be_false - client = Spec::Proto::TestService.client(:async => true) + client = Test::ResourceService.client(:async => true) client.options[:async].should be_true client.async?.should be_true end it 'should be able to define which service to create itself for' do - client = Protobuf::Rpc::Client.new :service => Spec::Proto::TestService - client.options[:service].should eq(Spec::Proto::TestService) + client = Protobuf::Rpc::Client.new :service => Test::ResourceService + client.options[:service].should eq(Test::ResourceService) end it 'should have a hard default for host and port on a service that has not been configured' do - reset_service_location Spec::Proto::TestService - client = Spec::Proto::TestService.client + reset_service_location Test::ResourceService + client = Test::ResourceService.client client.options[:host].should eq(Protobuf::Rpc::Service::DEFAULT_LOCATION[:host]) client.options[:port].should eq(Protobuf::Rpc::Service::DEFAULT_LOCATION[:port]) end @@ -161,7 +161,7 @@ # namely the :find method it 'should respond to defined service methods' do - client = Spec::Proto::TestService.client + client = Test::ResourceService.client client.should_receive(:send_request).and_return(nil) expect { client.find(nil) }.to_not raise_error end @@ -173,7 +173,7 @@ it 'should be able to set and get local variables within client response blocks' do outer_value = 'OUTER' inner_value = 'INNER' - client = Spec::Proto::TestService.client(:async => true) + client = Test::ResourceService.client(:async => true) EM.should_receive(:reactor_running?).and_return(true) EM.stub!(:next_tick) do @@ -194,10 +194,10 @@ context 'when receiving request objects' do it 'should be able to create the correct request object if passed a hash' do - client = Spec::Proto::TestService.client + client = Test::ResourceService.client client.should_receive(:send_request) client.find({:name => 'Test Name', :active => false}) - client.options[:request].should be_a(Spec::Proto::ResourceFindRequest) + client.options[:request].should be_a(Test::ResourceFindRequest) client.options[:request].name.should eq('Test Name') client.options[:request].active.should eq(false) end diff --git a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb index f345f9d7..9ed8b546 100644 --- a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/evented' diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 4f69b762..d70cf6a9 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/evented' require 'protobuf/socket' diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index c95222c7..20bc6d10 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -1,45 +1,45 @@ require 'spec_helper' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' describe Protobuf::Rpc::Service do context 'when configuring' do before :each do - reset_service_location Spec::Proto::TestService + reset_service_location Test::ResourceService end it 'should have a default location configured' do - Spec::Proto::TestService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host] - Spec::Proto::TestService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port] + Test::ResourceService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host] + Test::ResourceService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port] end it "should be able to pre-configure a service location for clients" do - Spec::Proto::TestService.located_at 'google.com:12345' - client = Spec::Proto::TestService.client + Test::ResourceService.located_at 'google.com:12345' + client = Test::ResourceService.client client.options[:host].should == 'google.com' client.options[:port].should == 12345 end context 'configuring host' do - before(:each) { Spec::Proto::TestService.configure :host => 'somehost.com' } - after(:each) { Spec::Proto::TestService.configure :host => '127.0.0.1' } + before(:each) { Test::ResourceService.configure :host => 'somehost.com' } + after(:each) { Test::ResourceService.configure :host => '127.0.0.1' } it 'should be able to configure and read the host' do - Spec::Proto::TestService.host.should == 'somehost.com' + Test::ResourceService.host.should == 'somehost.com' end end it 'should be able to configure and read the port' do - Spec::Proto::TestService.configure :port => 12345 - Spec::Proto::TestService.port.should == 12345 + Test::ResourceService.configure :port => 12345 + Test::ResourceService.port.should == 12345 end it 'should skip configuring location if the location passed does not match host:port syntax' do invalid_locations = [nil, 'myhost:', ':9939', 'badhost123'] invalid_locations.each do |location| - Spec::Proto::TestService.located_at location - Spec::Proto::TestService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host] - Spec::Proto::TestService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port] + Test::ResourceService.located_at location + Test::ResourceService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host] + Test::ResourceService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port] end end end @@ -48,8 +48,8 @@ before(:all) do class ::NewTestService < Protobuf::Rpc::Service - rpc :bad_method, Spec::Proto::ResourceFindRequest, Spec::Proto::Resource - rpc :bad_var, Spec::Proto::ResourceFindRequest, Spec::Proto::Resource + rpc :bad_method, Test::ResourceFindRequest, Test::Resource + rpc :bad_var, Test::ResourceFindRequest, Test::Resource def bad_method hash = {} hash[:one].explode @@ -62,14 +62,14 @@ def bad_var it 'raises an undefined method name error when calling a method on a non-existant object' do expect { - req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new(:name => 'mmeh').to_s) + req = mock('RequestWrapper', :request_proto => Test::ResourceFindRequest.new(:name => 'mmeh').to_s) ::NewTestService.new.bad_method(req) }.to raise_error(NoMethodError) end it 'raises a name error when accessing a non-existant object' do expect { - req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new(:name => 'mmeh').to_s) + req = mock('RequestWrapper', :request_proto => Test::ResourceFindRequest.new(:name => 'mmeh').to_s) ::NewTestService.new.bad_var(req) }.to raise_error(NameError) end diff --git a/spec/proto/test.pb.rb b/spec/proto/test.pb.rb deleted file mode 100644 index b0cd0dbb..00000000 --- a/spec/proto/test.pb.rb +++ /dev/null @@ -1,54 +0,0 @@ -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' -require 'protobuf/rpc/service' - -module Spec - module Proto - ## - # Enum Classes - # - class StatusType < ::Protobuf::Enum; end - - ## - # Message Classes - # - class ResourceFindRequest < ::Protobuf::Message; end - class Resource < ::Protobuf::Message; end - class Nested < ::Protobuf::Message; end - - ## - # Enum Values - # - ::Spec::Proto::StatusType.define :PENDING, 0 - ::Spec::Proto::StatusType.define :ENABLED, 1 - ::Spec::Proto::StatusType.define :DISABLED, 2 - ::Spec::Proto::StatusType.define :DELETED, 3 - - - ## - # Message Fields - # - ::Spec::Proto::ResourceFindRequest.required(::Protobuf::Field::StringField, :name, 1) - ::Spec::Proto::ResourceFindRequest.optional(::Protobuf::Field::BoolField, :active, 2) - - ::Spec::Proto::Resource.required(::Protobuf::Field::StringField, :name, 1) - ::Spec::Proto::Resource.optional(::Protobuf::Field::Int64Field, :date_created, 2) - ::Spec::Proto::Resource.optional(::Spec::Proto::StatusType, :status, 3) - ::Spec::Proto::Resource.repeated(::Spec::Proto::StatusType, :repeated_enum, 4) - - ::Spec::Proto::Nested.optional(::Protobuf::Field::StringField, :name, 1) - ::Spec::Proto::Nested.optional(::Spec::Proto::Resource, :resource, 2) - ::Spec::Proto::Nested.repeated(::Spec::Proto::Resource, :multiple_resources, 3) - ::Spec::Proto::Nested.optional(::Spec::Proto::StatusType, :status, 4) - - - ## - # Services - # - class TestService < ::Protobuf::Rpc::Service - rpc :find, ::Spec::Proto::ResourceFindRequest, ::Spec::Proto::Resource - end - end -end diff --git a/spec/proto/test_service.rb b/spec/proto/test_service.rb deleted file mode 100644 index 02699f00..00000000 --- a/spec/proto/test_service.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'protobuf/rpc/service' -require 'spec/proto/test.pb' - -## !! DO NOT EDIT THIS FILE !! -## -## To implement this service as defined by the protobuf, simply -## reopen Spec::Proto::TestService and implement each service method: -## -## module Spec -## module Proto -## class TestService -## -## # request -> Spec::Proto::ResourceFindRequest -## # response -> Spec::Proto::Resource -## def find -## # TODO: implement find -## end -## -## end -## end -## end -## - -module Spec - module Proto - class TestService < Protobuf::Rpc::Service - rpc :find, ResourceFindRequest, Resource - end - end -end diff --git a/spec/proto/test_service_impl.rb b/spec/proto/test_service_impl.rb deleted file mode 100644 index 0e5bc866..00000000 --- a/spec/proto/test_service_impl.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'protobuf/rpc/service' -require File.dirname(__FILE__) + '/test.pb' -require File.dirname(__FILE__) + '/test_service' - -module Spec - module Proto - class TestService - - # request -> Spec::Proto::ResourceFindRequest - # response -> Spec::Proto::Resource - def find - response.name = request.name - response.status = request.active ? 1 : 0 - end - - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b302a22e..70448f4e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,9 +19,20 @@ end ::RSpec.configure do |c| - c.include(::SilentConstants) c.include(::Sander6::CustomMatchers) c.mock_with :rspec + + c.before(:suite) do + unless ENV['NO_COMPILE_TEST_PROTOS'] + $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' + proto_path = File.expand_path("../support/", __FILE__) + %x{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } + end + end +end + +Dir[File.expand_path('../support/**/*.pb.rb', __FILE__)].each do |proto_file| + require proto_file end class ::Protobuf::Rpc::Client diff --git a/spec/support/all.rb b/spec/support/all.rb index 8c85e6f0..874f31bf 100644 --- a/spec/support/all.rb +++ b/spec/support/all.rb @@ -1,6 +1,5 @@ require 'support/tolerance_matcher' require 'support/server' -require 'support/silent_constants' def now Time.new.to_f diff --git a/spec/support/server.rb b/spec/support/server.rb index 3b379202..5aaccd9a 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -5,7 +5,7 @@ require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/servers/zmq_runner' -require 'spec/proto/test_service_impl' +require 'spec/support/test/resource_service' # Want to abort if server dies? Thread.abort_on_exception = true diff --git a/spec/support/silent_constants.rb b/spec/support/silent_constants.rb deleted file mode 100644 index eea2c7d8..00000000 --- a/spec/support/silent_constants.rb +++ /dev/null @@ -1,44 +0,0 @@ -# Just a way to keep warnings from being flagged in rename of constants during tests -=begin -module Kernel - def silence_warnings - orig_verbosity = $VERBOSE - $VERBOSE = nil - yield - $VERBOSE = orig_verbosity - end -end -=end - -module SilentConstants -=begin - def parse(constant) - source, _, constant_name = constant.to_s.rpartition('::') - [Object.const_get(source.to_sym), constant_name.to_sym] - end - - # Examples - # with_constants "Something" => "nothing" do - # end - # - # with_constants "Something::Foo" => "something else" do - # end - # - def with_constants(constants, &block) - saved_constants = {} - constants.each do |constant, val| - source_object, const_name = parse(constant) - saved_constants[constant] = source_object.const_get(const_name) - Kernel::silence_warnings { source_object.const_set(const_name, val) } - end - - block.call - ensure - constants.each do |constant, val| - source_object, const_name = parse(constant) - Kernel::silence_warnings { source_object.const_set(const_name, saved_constants[constant]) } - end - end - -=end -end diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb new file mode 100644 index 00000000..d6067481 --- /dev/null +++ b/spec/support/test/enum.pb.rb @@ -0,0 +1,32 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Test + ## + # Enum Classes + # + class EnumTestType < ::Protobuf::Enum; end + + ## + # Message Classes + # + class EnumTestMessage < ::Protobuf::Message; end + + ## + # Enum Values + # + ::Test::EnumTestType.define :ONE, 1 + ::Test::EnumTestType.define :TWO, 2 + + + ## + # Message Fields + # + ::Test::EnumTestMessage.optional(::Test::EnumTestType, :non_default_enum, 1) + ::Test::EnumTestMessage.optional(::Test::EnumTestType, :default_enum, 2, :default => ::Test::EnumTestType::ONE) + ::Test::EnumTestMessage.repeated(::Test::EnumTestType, :repeated_enums, 3) + + +end diff --git a/spec/support/test/enum.proto b/spec/support/test/enum.proto new file mode 100644 index 00000000..5bc64226 --- /dev/null +++ b/spec/support/test/enum.proto @@ -0,0 +1,12 @@ +package test; + +enum EnumTestType { + ONE = 1; + TWO = 2; +} + +message EnumTestMessage { + optional EnumTestType non_default_enum = 1; + optional EnumTestType default_enum = 2 [default=ONE]; + repeated EnumTestType repeated_enums = 3; +} diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb new file mode 100644 index 00000000..7db1706d --- /dev/null +++ b/spec/support/test/resource.pb.rb @@ -0,0 +1,52 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' +require 'protobuf/rpc/service' + +module Test + ## + # Enum Classes + # + class StatusType < ::Protobuf::Enum; end + + ## + # Message Classes + # + class ResourceFindRequest < ::Protobuf::Message; end + class Resource < ::Protobuf::Message; end + class Nested < ::Protobuf::Message; end + + ## + # Enum Values + # + ::Test::StatusType.define :PENDING, 0 + ::Test::StatusType.define :ENABLED, 1 + ::Test::StatusType.define :DISABLED, 2 + ::Test::StatusType.define :DELETED, 3 + + + ## + # Message Fields + # + ::Test::ResourceFindRequest.required(::Protobuf::Field::StringField, :name, 1) + ::Test::ResourceFindRequest.optional(::Protobuf::Field::BoolField, :active, 2) + + ::Test::Resource.required(::Protobuf::Field::StringField, :name, 1) + ::Test::Resource.optional(::Protobuf::Field::Int64Field, :date_created, 2) + ::Test::Resource.optional(::Test::StatusType, :status, 3) + ::Test::Resource.repeated(::Test::StatusType, :repeated_enum, 4) + + ::Test::Nested.optional(::Protobuf::Field::StringField, :name, 1) + ::Test::Nested.optional(::Test::Resource, :resource, 2) + ::Test::Nested.repeated(::Test::Resource, :multiple_resources, 3) + ::Test::Nested.optional(::Test::StatusType, :status, 4) + + + ## + # Services + # + class ResourceService < ::Protobuf::Rpc::Service + rpc :find, ::Test::ResourceFindRequest, ::Test::Resource + end +end diff --git a/spec/proto/test.proto b/spec/support/test/resource.proto similarity index 92% rename from spec/proto/test.proto rename to spec/support/test/resource.proto index 838a6495..202df04d 100644 --- a/spec/proto/test.proto +++ b/spec/support/test/resource.proto @@ -1,4 +1,4 @@ -package spec.proto; +package test; enum StatusType { PENDING = 0; @@ -26,6 +26,6 @@ message Nested { optional StatusType status = 4; } -service TestService { +service ResourceService { rpc Find (ResourceFindRequest) returns (Resource); } diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb new file mode 100644 index 00000000..f1dab010 --- /dev/null +++ b/spec/support/test/resource_service.rb @@ -0,0 +1,14 @@ +require ::File.expand_path('../resource.pb', __FILE__) + +module Test + class ResourceService + + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find + response.name = request.name + response.status = request.active ? 1 : 0 + end + + end +end From bb4dab5977a2d06d2b6d7538afed1f5266df0915 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 4 Oct 2012 14:21:08 -0600 Subject: [PATCH 0130/1191] Add Enum.fetch method for coerced EnumValue lookups Use Enum.fetch in EnumField.define_setter to compartmentalize the enum lookups. Add Enum.enum_by_value to return an enum based on a value (tag) lookup. Previously we had a method to return the name by tag, but not the whole enum. Split EnumValue into its own file. Fill out specs for Enum and EnumValue classes. --- lib/protobuf/enum.rb | 44 ++++++------- lib/protobuf/enum_value.rb | 29 +++++++++ lib/protobuf/field/enum_field.rb | 20 ++---- spec/lib/protobuf/enum_spec.rb | 90 ++++++++++++++++++++++++++ spec/lib/protobuf/enum_value_spec.rb | 13 ++++ spec/lib/protobuf/message/enum_spec.rb | 13 ---- 6 files changed, 159 insertions(+), 50 deletions(-) create mode 100644 lib/protobuf/enum_value.rb create mode 100644 spec/lib/protobuf/enum_spec.rb create mode 100644 spec/lib/protobuf/enum_value_spec.rb delete mode 100644 spec/lib/protobuf/message/enum_spec.rb diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 784f2459..f9c067fb 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,10 +1,10 @@ -require 'delegate' +require 'protobuf/enum_value' module Protobuf class Enum def self.define(name, value) - enum_value = EnumValue.new(self, name, value) + enum_value = ::Protobuf::EnumValue.new(self, name, value) const_set(name, enum_value) @values ||= {} @names ||= [] @@ -12,6 +12,25 @@ def self.define(name, value) @names[value] = name end + # Fetch the given enum by a variety of type-checking + # mechanisms. This is useful for the enum field setters + # as well as repeated enum field construction. + def self.fetch(value) + if value.is_a?(::Protobuf::EnumValue) + value + elsif value.respond_to?(:to_sym) + value_by_name(value.to_sym) rescue nil + elsif value.respond_to?(:to_i) + enum_by_value(value.to_i) rescue nil + else + nil + end + end + + def self.enum_by_value(value) + value_by_name(name_by_value(value)) + end + def self.name_by_value(value) @names[value] end @@ -35,25 +54,4 @@ class << self alias_method :get_name_by_tag, :name_by_value end end - - class EnumValue < SimpleDelegator - - attr_reader :parent_class, :name, :value - - def initialize(parent_class, name, value) - @parent_class = parent_class - @name = name - @value = value - super(@value) - end - - def to_s - @name.to_s - end - - def inspect - "\#<#{self.class} #{@parent_class}::#{@name}=#{@value}>" - end - end - end diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb new file mode 100644 index 00000000..82de1aa9 --- /dev/null +++ b/lib/protobuf/enum_value.rb @@ -0,0 +1,29 @@ +require 'delegate' +require 'protobuf/enum' + +module Protobuf + class EnumValue < SimpleDelegator + + attr_reader :parent_class, :name, :value + + def initialize(parent_class, name, value) + @parent_class = parent_class + @name = name + @value = value + super(@value) + end + + def inspect + "\#<#{self.class} #{@parent_class}::#{@name}=#{@value}>" + end + + def to_hash_value + self.to_i + end + + def to_s + @name.to_s + end + end +end + diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 0583b51e..364b1238 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -32,23 +32,15 @@ def typed_default_value def define_setter field = self @message_class.class_eval do - define_method("#{field.name}=") do |val| - if val.nil? + define_method("#{field.name}=") do |value| + orig_value = value + if value.nil? @values.delete(field.name) else - val = \ - case val - when Symbol then - field.type.const_get(val) rescue nil - when Integer then - field.type.const_get(field.type.name_by_value(val)) rescue nil - when EnumValue then - raise TypeError, "Invalid value: #{val.inspect} for #{field.name}" if val.parent_class != field.type - val - end - raise TypeError, "Invalid value: #{val.inspect} for #{field.name}" unless val + value = field.type.fetch(value) + raise TypeError, "Invalid ENUM value: #{orig_value.inspect} for #{field.name}" unless value - @values[field.name] = val + @values[field.name] = value end end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb new file mode 100644 index 00000000..13cf14e1 --- /dev/null +++ b/spec/lib/protobuf/enum_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' + +describe Protobuf::Enum do + let(:name) { :THREE } + let(:tag) { 3 } + + before(:all) do + Test::EnumTestType.define(name, tag) + end + + describe '.define' do + it 'defines a constant enum value on the parent class' do + Test::EnumTestType.constants.should include(name) + Test::EnumTestType::THREE.should be_a(Protobuf::EnumValue) + end + end + + describe '.fetch' do + context 'when value is an EnumValue' do + it 'responds with that object' do + Test::EnumTestType.fetch(Test::EnumTestType::THREE).should eq Test::EnumTestType::THREE + end + end + + context 'when value can be coerced to a symbol' do + it 'fetches based on the symbol name value' do + Test::EnumTestType.fetch("http://github.com/ONE").should eq Test::EnumTestType::ONE + end + end + + context 'when value can be coerced to an integer' do + it 'fetches based on the integer tag value' do + Test::EnumTestType.fetch(3.0).should eq Test::EnumTestType::THREE + end + end + + context 'when value is not an applicable type' do + it 'returns a nil' do + Test::EnumTestType.fetch(Test::Resource.new).should be_nil + end + end + end + + describe '.enum_by_value' do + it 'gets the EnumValue corresponding to the given value (tag)' do + Test::EnumTestType.enum_by_value(tag).should eq Test::EnumTestType::THREE + end + end + + describe '.name_by_value' do + it 'gets the name of the enum corresponding to the given value (tag)' do + Test::EnumTestType.name_by_value(tag).should eq name + end + end + + describe '.valid_tag?' do + context 'when tag is defined' do + specify { Test::EnumTestType.valid_tag?(tag).should be_true } + end + + context 'when tag is not defined' do + specify { Test::EnumTestType.valid_tag?(300).should be_false } + end + end + + describe '.value_by_name' do + it 'gets the EnumValue corresponding to the given name' do + Test::EnumTestType.value_by_name(name).should eq Test::EnumTestType::THREE + end + end + + describe '.values' do + it 'provides a hash of defined EnumValues' do + Test::EnumTestType.values.should eq({ + :ONE => Test::EnumTestType::ONE, + :TWO => Test::EnumTestType::TWO, + :THREE => Test::EnumTestType::THREE + }) + end + end + + context 'when coercing from enum' do + subject { Test::StatusType::PENDING } + it { should eq(0) } + end + + context 'when coercing from integer' do + specify { 0.should eq(Test::StatusType::PENDING) } + end +end diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb new file mode 100644 index 00000000..6676b222 --- /dev/null +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe Protobuf::EnumValue do + + subject { Test::EnumTestType::ONE } + its(:parent_class) { should eq Test::EnumTestType } + its(:name) { should eq :ONE } + its(:value) { should eq 1 } + its(:to_hash_value) { should eq 1 } + its(:to_s) { should eq "ONE" } + its(:inspect) { should eq '#' } + +end diff --git a/spec/lib/protobuf/message/enum_spec.rb b/spec/lib/protobuf/message/enum_spec.rb deleted file mode 100644 index a4295f62..00000000 --- a/spec/lib/protobuf/message/enum_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' -require 'spec/proto/test.pb' - -describe Protobuf::Enum do - context 'when coercing from enum' do - subject { Test::StatusType::PENDING } - it { should eq(0) } - end - - context 'when coercing from integer' do - it { 0.should eq(Test::StatusType::PENDING) } - end -end From 0dfe490088cb57e66f960a7012e5b7962ececce4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 4 Oct 2012 14:24:19 -0600 Subject: [PATCH 0131/1191] Simplify Message#to_hash, #inspect implementations The hash representation of a message now contains only values that have been set previously. Instead of attempting coercion in the message implementation we delegate out to the value to make the conversions, if any. Add support to FieldArray for Message#to_hash. Clean up and add simpler specs to Message#to_hash. --- lib/protobuf/field/field_array.rb | 24 ++++--- lib/protobuf/message.rb | 76 ++++------------------- spec/functional/evented_server_spec.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/message/message_spec.rb | 67 -------------------- spec/lib/protobuf/message_spec.rb | 50 +++++++++++++++ 7 files changed, 82 insertions(+), 141 deletions(-) delete mode 100644 spec/lib/protobuf/message/message_spec.rb create mode 100644 spec/lib/protobuf/message_spec.rb diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 2de0df0d..2322d053 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -8,7 +8,7 @@ def initialize(field) @field = field end - ## + ## # Public Instance Methods # def []=(nth, val) @@ -33,21 +33,31 @@ def replace(val) super(val) end + # Return a hash-representation of the given values for this field type. + # The value in this case would be an array. + def to_hash_value + self.map do |value| + value.respond_to?(:to_hash_value) ? value.to_hash_value : value + end + end + def to_s "[#{@field.name}]" end - + private ## # Private Instance Methods # - def normalize(val) - raise TypeError unless @field.acceptable?(val) - if @field.is_a?(::Protobuf::Field::MessageField) && val.is_a?(Hash) - @field.type.new(val) + def normalize(value) + raise TypeError unless @field.acceptable?(value) + if @field.is_a?(::Protobuf::Field::EnumField) + @field.type.fetch(value) + elsif @field.is_a?(::Protobuf::Field::MessageField) && value.is_a?(Hash) + @field.type.new(value) else - val + value end end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a67c34f7..d82e7d7b 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -161,42 +161,8 @@ def copy_to(object, method) end private :copy_to - def inspect(indent=0) - result = [] - i = ' ' * indent - field_value_to_string = lambda { |field, value| - result << \ - if field.optional? && ! has_field?(field.name) - '' - else - case field - when Field::MessageField then - if value.nil? - "#{i}#{field.name} {}\n" - else - "#{i}#{field.name} {\n#{value.inspect(indent + 1)}#{i}}\n" - end - when Field::EnumField then - if value.is_a?(EnumValue) - "#{i}#{field.name}: #{value.name}\n" - else - "#{i}#{field.name}: #{field.type.name_by_value(value)}\n" - end - else - "#{i}#{field.name}: #{value.inspect}\n" - end - end - } - each_field do |field, value| - if field.repeated? - value.each do |v| - field_value_to_string.call(field, v) - end - else - field_value_to_string.call(field, value) - end - end - result.join + def inspect + to_hash.inspect end def parse_from_string(string) @@ -284,37 +250,19 @@ def each_field end end + # Return a hash-representation of the given fields for this message type. def to_hash - result = {} - build_value = lambda { |field, value| - if !field.optional? || (field.optional? && has_field?(field.name)) - case field - when Field::MessageField then - value.to_hash - when Field::EnumField then - if value.is_a?(EnumValue) - value.to_i - elsif value.is_a?(Symbol) - field.type[value].to_i - else - value - end - else - value - end - end - } - each_field do |field, value| - if field.repeated? - result[field.name] = value.map do |v| - build_value.call(field, v) - end - else - result[field.name] = build_value.call(field, value) - end + result = Hash.new + + @values.keys.each do |field_name| + value = __send__(field_name) + hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value + result.merge!(field_name => hashed_value) end - result + + return result end + alias_method :to_hash_value, :to_hash def to_json to_hash.to_json diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 54a5332f..5e542660 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -44,7 +44,7 @@ end EM.stop end - error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ + error.message.should =~ /ResourceFindRequest.*fields.*improperly set/ end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 85dad77e..081cb43e 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -42,7 +42,7 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ + error.message.should =~ /ResourceFindRequest.*fields.*improperly set/ end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 8c460747..45c36dc8 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -42,7 +42,7 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /ResourceFindRequest.*fields.*improperly set.*"name"/ + error.message.should =~ /ResourceFindRequest.*fields.*improperly set/ end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/lib/protobuf/message/message_spec.rb b/spec/lib/protobuf/message/message_spec.rb deleted file mode 100644 index a456a698..00000000 --- a/spec/lib/protobuf/message/message_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'spec_helper' -require 'spec/proto/test.pb' - -describe Protobuf::Message do - - context 'when converting to json' do - - it "should be jsonable" do - msg = Spec::Proto::ResourceFindRequest.new - msg.should respond_to(:to_json) - msg.name = 'Jeff' - msg.active = false - msg.to_json.should == '{"name":"Jeff","active":false}' - end - - it 'should generate nested messages into nested json objects' do - date_created = Time.now.to_i - - nested = Spec::Proto::Nested.new - nested.name = 'NESTED' - nested.resource = Spec::Proto::Resource.new.tap do |r| - r.name = 'RESOURCE SINGLE' - r.date_created = date_created - r.status = Spec::Proto::StatusType::PENDING - end - 2.times do |i| - nested.multiple_resources << Spec::Proto::Resource.new.tap do |r| - r.name = 'RESOURCE MULTIPLE %d' % i - r.date_created = date_created - r.status = Spec::Proto::StatusType::PENDING - end - end - nested.status = Spec::Proto::StatusType::ENABLED - - nested.to_json.should == %Q{{"name":"NESTED","resource":{"name":"RESOURCE SINGLE","date_created":#{date_created},"status":0,"repeated_enum":[]},"multiple_resources":[{"name":"RESOURCE MULTIPLE 0","date_created":#{date_created},"status":0,"repeated_enum":[]},{"name":"RESOURCE MULTIPLE 1","date_created":#{date_created},"status":0,"repeated_enum":[]}],"status":1}} - end - - - end - - context 'when converting to a hash' do - - context 'when message has repeated enum field' do - - it 'provides an array of integers' do - resource = Spec::Proto::Resource.new :repeated_enum => [ - Spec::Proto::StatusType::PENDING, - Spec::Proto::StatusType::ENABLED, - Spec::Proto::StatusType::ENABLED, - Spec::Proto::StatusType::DISABLED, - Spec::Proto::StatusType::DELETED - ] - - resource.to_hash[:repeated_enum].should == [ - Spec::Proto::StatusType::PENDING.value, - Spec::Proto::StatusType::ENABLED.value, - Spec::Proto::StatusType::ENABLED.value, - Spec::Proto::StatusType::DISABLED.value, - Spec::Proto::StatusType::DELETED.value - ] - end - - end - - end - -end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb new file mode 100644 index 00000000..32614d95 --- /dev/null +++ b/spec/lib/protobuf/message_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe Protobuf::Message do + + describe '#to_hash' do + context 'generating values for an ENUM field' do + it 'converts the enum to its tag representation' do + hash = Test::EnumTestMessage.new(:non_default_enum => :TWO).to_hash + hash.should eq({ :non_default_enum => 2 }) + end + + it 'does not populate default values' do + hash = Test::EnumTestMessage.new.to_hash + hash.should eq(Hash.new) + end + + it 'converts repeated enum fields to an array of the tags' do + hash = Test::EnumTestMessage.new(:repeated_enums => [ :ONE, :TWO, :TWO, :ONE ]).to_hash + hash.should eq({ :repeated_enums => [ 1, 2, 2, 1 ] }) + end + end + + context 'generating values for a Message field' do + it 'recursively hashes field messages' do + hash = Test::Nested.new({ :resource => { :name => 'Nested' } }).to_hash + hash.should eq({ :resource => { :name => 'Nested' } }) + end + + it 'recursively hashes a repeated set of messages' do + proto = Test::Nested.new(:multiple_resources => [ + Test::Resource.new(:name => 'Resource 1'), + Test::Resource.new(:name => 'Resource 2') + ]) + + proto.to_hash.should eq({ :multiple_resources => [ { :name => 'Resource 1' }, + { :name => 'Resource 2' } ] }) + + end + end + end + + describe '#to_json' do + subject do + ::Test::ResourceFindRequest.new({ :name => 'Test Name', :active => false }) + end + + its(:to_json) { should eq '{"name":"Test Name","active":false}' } + end + +end From 7845b6e0017393a40657bfb1ffcb14e61c58ce5a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 4 Oct 2012 14:35:38 -0600 Subject: [PATCH 0132/1191] Bump version 2.0.0.rc3 --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 24234c3c..8427bc36 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (2.0.0.rc2) + protobuf (2.0.0.rc3) activesupport ffi multi_json diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index de7ede4c..81ec2c08 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.0.rc2' + VERSION = '2.0.0.rc3' PROTOC_VERSION = '2.4.1' end From 6ba7f2bb9517847024074af4ab70d2b52e673207 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 10 Oct 2012 17:22:36 -0600 Subject: [PATCH 0133/1191] Move files out of unspecified "common" namespace --- lib/protobuf/cli.rb | 2 +- lib/protobuf/{common => }/exceptions.rb | 0 lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/{common => }/logger.rb | 21 ++ lib/protobuf/message/decoder.rb | 4 +- lib/protobuf/message/encoder.rb | 10 +- lib/protobuf/rpc/client.rb | 23 +- lib/protobuf/rpc/connectors/base.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 10 +- lib/protobuf/rpc/server.rb | 2 +- lib/protobuf/rpc/servers/socket/worker.rb | 3 + lib/protobuf/rpc/service.rb | 317 ++++++------------ lib/protobuf/rpc/stat.rb | 2 +- lib/protobuf/{common => }/wire_type.rb | 0 spec/lib/protobuf/{common => }/logger_spec.rb | 82 +++-- spec/support/server.rb | 2 +- 16 files changed, 201 insertions(+), 281 deletions(-) rename lib/protobuf/{common => }/exceptions.rb (100%) rename lib/protobuf/{common => }/logger.rb (71%) rename lib/protobuf/{common => }/wire_type.rb (100%) rename spec/lib/protobuf/{common => }/logger_spec.rb (72%) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 0290f572..67245748 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,7 +1,7 @@ require 'thor' require 'pry' require 'protobuf/version' -require 'protobuf/common/logger' +require 'protobuf/logger' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq_runner' diff --git a/lib/protobuf/common/exceptions.rb b/lib/protobuf/exceptions.rb similarity index 100% rename from lib/protobuf/common/exceptions.rb rename to lib/protobuf/exceptions.rb diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 67ffb1de..3f60b81c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,4 +1,4 @@ -require 'protobuf/common/wire_type' +require 'protobuf/wire_type' require 'protobuf/field/field_array' module Protobuf diff --git a/lib/protobuf/common/logger.rb b/lib/protobuf/logger.rb similarity index 71% rename from lib/protobuf/common/logger.rb rename to lib/protobuf/logger.rb index 3cd38489..5fe42a47 100644 --- a/lib/protobuf/common/logger.rb +++ b/lib/protobuf/logger.rb @@ -53,13 +53,34 @@ def self.instance module LogMethods [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| define_method("log_#{m}") do |*params, &block| + params.map! { |message| sign_message(message) } Protobuf::Logger.__send__(m, *params, &block) end end + # When included, also extend the LogMethods module for class access. def self.included(base) base.extend(LogMethods) end + + # We often want to log an exception, so let's make that a core + # concern of the logger. + # + def log_exception(ex) + log_error { ex.message } + log_error { ex.backtrace[0..5].join("\n") } + log_debug { ex.backtrace.join("\n") } + end + + def log_signature + @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]" + end + + def sign_message(message) + "#{log_signature} #{message}" + end + end + end end diff --git a/lib/protobuf/message/decoder.rb b/lib/protobuf/message/decoder.rb index c8c9d250..6a1562c9 100644 --- a/lib/protobuf/message/decoder.rb +++ b/lib/protobuf/message/decoder.rb @@ -1,5 +1,5 @@ -require 'protobuf/common/wire_type' -require 'protobuf/common/exceptions' +require 'protobuf/wire_type' +require 'protobuf/exceptions' module Protobuf diff --git a/lib/protobuf/message/encoder.rb b/lib/protobuf/message/encoder.rb index 65557a43..bb570111 100644 --- a/lib/protobuf/message/encoder.rb +++ b/lib/protobuf/message/encoder.rb @@ -1,5 +1,5 @@ -require 'protobuf/common/wire_type' -require 'protobuf/common/exceptions' +require 'protobuf/wire_type' +require 'protobuf/exceptions' module Protobuf @@ -10,8 +10,10 @@ module Encoder # Encode +message+ and write to +stream+. def encode(stream, message) # FIXME make this not as ghetto - raise NotInitializedError, "Message %s is not initialized (one or more fields is improperly set): %s" % [message.class.name, JSON.parse(message.to_json)] unless message.initialized? - + unless message.initialized? + raise NotInitializedError, "Message #{message.class.name} is not initialized (one or more fields is improperly set): #{JSON.parse(message.to_json)}" + end + message.each_field do |field, value| next unless message.has_field?(field.name) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index d98cb8e3..c0040365 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -1,6 +1,6 @@ require 'forwardable' require 'protobuf' -require 'protobuf/common/logger' +require 'protobuf/logger' require 'protobuf/rpc/error' require 'protobuf/rpc/connector' @@ -29,15 +29,14 @@ class Client def initialize(opts={}) raise "Invalid client configuration. Service must be defined." if opts[:service].nil? @connector = Connector.connector_for_client.new(opts) - log_debug { "[#{log_signature}] Initialized with options: %s" % opts.inspect } + log_debug { sign_message("Initialized with options: #{opts.inspect}") } end def log_signature - @log_signature ||= "client-#{self.class}" + @_log_signature ||= "client-#{self.class}" end # Set a complete callback on the client to return the object (self). - # Callback is called regardless of :async setting. # # client = Client.new(:service => WidgetService) # client.on_complete {|obj| ... } @@ -109,25 +108,27 @@ def on_success=(callable) def method_missing(method, *params) service = options[:service] unless service.rpcs[service].keys.include?(method) - log_error { "[#{log_signature}] %s#%s not rpc method, passing to super" % [service.name, method.to_s] } + log_error { sign_message("#{service.name}##{method.to_s} not rpc method, passing to super") } super(method, *params) else - log_debug { "[#{log_signature}] %s#%s" % [service.name, method.to_s] } rpc = service.rpcs[service][method.to_sym] + log_debug { sign_message("#{service.name}##{method.to_s}") } options[:request_type] = rpc.request_type - log_debug { "[#{log_signature}] Request Type: %s" % options[:request_type].name } + log_debug { sign_message("Request Type: #{options[:request_type].name}") } + options[:response_type] = rpc.response_type - log_debug { "[#{log_signature}] Response Type: %s" % options[:response_type].name } + log_debug { sign_message("Response Type: #{options[:response_type].name}") } + options[:method] = method.to_s options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0] - log_debug { "[#{log_signature}] Request Data: %s" % options[:request].inspect } + log_debug { sign_message("Request Data: #{options[:request].inspect}") } # Call client to setup on_success and on_failure event callbacks if block_given? - log_debug { "[#{log_signature}] client setup callback given, invoking" } + log_debug { sign_message("client setup callback given, invoking") } yield(self) else - log_debug { "[#{log_signature}] no block given for callbacks" } + log_debug { sign_message("no block given for callbacks") } end send_request diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 79b3660a..5a3e0712 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -1,4 +1,4 @@ -require 'protobuf/common/logger' +require 'protobuf/logger' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 36dbebe4..8e4cf82f 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -13,12 +13,12 @@ def any_callbacks? def complete @stats.end - @stats.log_stats - log_debug { "[#{log_signature}] Response proceessing complete" } + log_info { @stats.to_s } + log_debug { sign_message('Response proceessing complete') } @complete_cb.call(self) unless @complete_cb.nil? - rescue - log_error { "[#{log_signature}] Complete callback error encountered: %s" % $!.message } - log_error { "[#{log_signature}] %s" % $!.backtrace.join("\n") } + rescue => e + log_error { sign_message('Complete callback error encountered') } + log_exception(e) raise end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 046959d3..9ba81c50 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -1,4 +1,4 @@ -require 'protobuf/common/logger' +require 'protobuf/logger' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 48157f63..63bf4727 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -1,3 +1,6 @@ +require 'protobuf/rpc/server' +require 'protobuf/logger' + module Protobuf module Rpc module Socket diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 0db5f1c7..04cd6d3e 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,243 +1,126 @@ -require 'protobuf/common/logger' +require 'protobuf/logger' require 'protobuf/rpc/client' require 'protobuf/rpc/error' module Protobuf module Rpc # Object to encapsulate the request/response types for a given service method - # - RpcMethod = Struct.new("RpcMethod", :service, :method, :request_type, :response_type) - + # + RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) + class Service include Protobuf::Logger::LogMethods - - attr_reader :request - attr_accessor :response, :async_responder - private :request, :response, :response= - - DEFAULT_LOCATION = { - :host => '127.0.0.1', - :port => 9399 - } - - # Class methods are intended for use on the client-side. - # - class << self - - # You MUST add the method name to this list if you are adding - # instance methods below, otherwise stuff will definitely break - NON_RPC_METHODS = %w( rpcs call_rpc on_rpc_failed rpc_failed request response method_missing async_responder on_send_response send_response log_signature ) - - # Override methods being added to the class - # If the method isn't already a private instance method, or it doesn't start with rpc_, - # or it isn't in the reserved method list (NON_RPC_METHODS), - # We want to remap the method such that we can wrap it in before and after behavior, - # most notably calling call_rpc against the method. See call_rpc for more info. - def method_added(old) - new_method = :"rpc_#{old}" - return if private_instance_methods.include?(new_method) or old =~ /^rpc_/ or NON_RPC_METHODS.include?(old.to_s) - - alias_method new_method, old - private new_method - - define_method(old) do |pb_request| - call_rpc(old.to_sym, pb_request) - end - rescue ArgumentError => e - # Wrap a known issue where an instance method was defined in the class without - # it being ignored with NON_RPC_METHODS. - raise ArgumentError, "#{e.message} (Note: This could mean that you need to add the method #{old} to the NON_RPC_METHODS list)" - end - - # Generated service classes should call this method on themselves to add rpc methods - # to the stack with a given request and response type - def rpc(method, request_type, response_type) - rpcs[self] ||= {} - rpcs[self][method] = RpcMethod.new self, method, request_type, response_type - end - - # Shorthand for @rpcs class instance var - def rpcs - @rpcs ||= {} - end - - # Create a new client for the given service. - # See Client#initialize and ClientConnection::DEFAULT_OPTIONS - # for all available options. - # - def client(options={}) - configure - Client.new({ - :service => self, - :async => false, - :host => self.host, - :port => self.port - }.merge(options)) - end - - # Allows service-level configuration of location. - # Useful for system-startup configuration of a service - # so that any Clients using the Service.client sugar - # will not have to configure the location each time. - # - def configure(config={}) - locations[self] ||= {} - locations[self][:host] = config[:host] if config.key?(:host) - locations[self][:port] = config[:port] if config.key?(:port) - end - - # Shorthand call to configure, passing a string formatted as hostname:port - # e.g. 127.0.0.1:9933 - # e.g. localhost:0 - # - def located_at(location) - return if location.nil? or location.downcase.strip !~ /[a-z0-9.]+:\d+/ - host, port = location.downcase.strip.split ':' - configure :host => host, :port => port.to_i - end - - # The host location of the service - def host - configure - locations[self][:host] || DEFAULT_LOCATION[:host] - end - - # The port of the service on the destination server - def port - configure - locations[self][:port] || DEFAULT_LOCATION[:port] - end - - # Shorthand for @locations class instance var - def locations - @locations ||= {} - end - + + DEFAULT_HOST = '127.0.0.1'.freeze + DEFAULT_PORT = 9399 + + ## + # Class Methods + # + + # Create a new client for the given service. + # See Client#initialize and ClientConnection::DEFAULT_OPTIONS + # for all available options. + # + def self.client(options = {}) + ::Protobuf::Rpc::Client.new({ :service => self, + :host => host, + :port => port }.merge(options)) end - def log_signature - @log_signature ||= "service-#{self.class}" + # Allows service-level configuration of location. + # Useful for system-startup configuration of a service + # so that any Clients using the Service.client sugar + # will not have to configure the location each time. + # + def self.configure(config = {}) + self.host = config.delete(:host) if config.key?(:host) + self.port = config.delete(:port) if config.key?(:port) end - - # If a method comes through that hasn't been found, and it - # is defined in the rpcs method list, we know that the rpc - # stub has been created, but no implementing method provides the - # functionality, so throw an appropriate error, otherwise go to super - # - def method_missing m, *params - if rpcs.key?(m) - exc = MethodNotFound.new "#{self}##{m} was defined as a valid rpc method, but was not implemented." - log_error exc.message - raise exc - else - log_error { "-------------- [#{log_signature}] %s#%s not rpc method, passing to super" % [self.class.name, m.to_s] } - super m, params - end + + # The host location of the service. + # + def self.host + @_host ||= DEFAULT_HOST end - # Convenience wrapper around the rpc method list for a given class - def rpcs - self.class.rpcs[self.class] + # The host location setter. + # + def self.host=(new_host) + @_host = new_host end - - # Callback register for the server when a service - # method calls rpc_failed. Called by Service#rpc_failed. - def on_rpc_failed(&rpc_failure_cb) - @rpc_failure_cb = rpc_failure_cb + + # Shorthand call to configure, passing a string formatted as hostname:port + # e.g. 127.0.0.1:9933 + # e.g. localhost:0 + # + def self.located_at(location) + return if location.nil? || location.downcase.strip !~ /.+:\d+/ + host, port = location.downcase.strip.split ':' + configure(:host => host, :port => port.to_i) end - - # Automatically fail a service method. - # NOTE: This shortcuts the @async_responder paradigm. There is - # not any way to get around this currently (and I'm not sure you should want to). - # - def rpc_failed(message="RPC Failed while executing service method #{@current_method}") - error_message = 'Unable to invoke rpc_failed, no failure callback is setup.' - log_and_raise_error(error_message) if @rpc_failure_cb.nil? - error = message.is_a?(String) ? RpcFailed.new(message) : message - log_warn "[#{log_signature}] RPC Failed: %s" % error.message - @rpc_failure_cb.call(error) + + # The port of the service on the destination server. + # + def self.port + @_port ||= DEFAULT_PORT + end + + # The port location setter. + # + def self.port=(new_port) + @_port = new_port + end + + # Define an rpc method with the given request and response types. + # This methods is only used by the generated service definitions + # and not useful for user code. + # + def self.rpc(method, request_type, response_type) + rpcs[method] = RpcMethod.new(method, request_type, response_type) + end + + # Hash containing the set of methods defined via `rpc`. + # + def self.rpcs + @_rpcs ||= {} end - - # Callback register for the server to be notified - # when it is appropriate to generate a response to the client. - # Used in conjunciton with Service#send_response. - # - def on_send_response(&responder) - @responder = responder + + # Check if the given method name is a known rpc endpoint. + # + def self.rpc_method?(name) + rpcs.key?(name) end - - # Tell the server to generate response and send it to the client. + + + ## + # Instance Methods + # + + # Register a failure callback for use when rpc_failed is invoked. # - # NOTE: If @async_responder is set to true, this MUST be called by - # the implementing service method, otherwise the connection - # will timeout since no data will be sent. + def on_rpc_failed(callable) + @rpc_failed_callback = callable + end + + # Automatically fail a service method. # - def send_response - error_message = "Unable to send response, responder is nil. It appears you aren't inside of an RPC request/response cycle." - log_and_raise_error(error_message) if @responder.nil? - @responder.call(@response) + def rpc_failed(message) + @rpc_failed_callback.call(message) end - - private - def log_and_raise_error(error_message) - log_error(error_message) - raise error_message + # Convenience method to get back to class method. + # + def rpc_method?(name) + self.class.rpc_method?(name) end - - # Call the rpc method that was previously privatized. - # call_rpc allows us to wrap the normal method call with - # before and after behavior, most notably setting up the request - # and response instances. - # - # Implementing rpc methods should be aware - # that request and response are implicitly available, and - # that response should be manipulated during the rpc method, - # as there is no way to reliably determine the response like - # a normal (http-based) controller method would be able to. - # - # Async behavior of responding can be achieved in the rpc method - # by explicitly setting self.async_responder = true. It is then - # the responsibility of the service method to send the response, - # by calling self.send_response without any arguments. The rpc - # server is setup to handle synchronous and asynchronous responses. - # - def call_rpc(method, pb_request) - @current_method = method - - # Allows the service to set whether or not - # it would like to asynchronously respond to the connected client(s) - @async_responder = false - - # Setup the request - @request = rpcs[method].request_type.new - @request.parse_from_string(pb_request.request_proto) - rescue - exc = BadRequestProto.new 'Unable to parse request: %s' % $!.message - log_error exc.message - log_error $!.backtrace.join("\n") - raise exc - else # when no Exception was thrown - # Setup the response - @response = rpcs[method].response_type.new - - log_debug { "[#{log_signature}] calling service method %s#%s" % [self.class, method] } - # Call the aliased rpc method (e.g. :rpc_find for :find) - __send__("rpc_#{method}".to_sym) - log_debug { "[#{log_signature}] completed service method %s#%s" % [self.class, method] } - - # Pass the populated response back to the server - # Note this will only get called if the rpc method didn't explode (by design) - if @async_responder - log_debug { "[#{log_signature}] async request, not sending response (yet)" } - else - log_debug { "[#{log_signature}] trigger server send_response" } - send_response - end + + # Convenience method to get back to class rpcs hash. + # + def rpcs + self.class.rpcs end - + end - end - end diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index c4ba56f5..760d1e32 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -1,5 +1,5 @@ require 'date' -require 'protobuf/common/logger' +require 'protobuf/logger' module Protobuf module Rpc diff --git a/lib/protobuf/common/wire_type.rb b/lib/protobuf/wire_type.rb similarity index 100% rename from lib/protobuf/common/wire_type.rb rename to lib/protobuf/wire_type.rb diff --git a/spec/lib/protobuf/common/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb similarity index 72% rename from spec/lib/protobuf/common/logger_spec.rb rename to spec/lib/protobuf/logger_spec.rb index 1059abb2..2bcd670d 100644 --- a/spec/lib/protobuf/common/logger_spec.rb +++ b/spec/lib/protobuf/logger_spec.rb @@ -1,40 +1,40 @@ -require 'protobuf/common/logger' +require 'protobuf/logger' require 'stringio' describe Protobuf::Logger do - + subject { Protobuf::Logger } - + before(:each) do Protobuf::Logger.reset_device! Protobuf::Logger.file = '/dev/null' Protobuf::Logger.level = ::Logger::INFO end - + describe '.instance' do - + it 'doesn\'t create a logger if the file was not set' do subject.file = nil subject.instance.should be_nil end - + it 'doesn\'t create a logger if the level was not set' do subject.level = nil subject.instance.should be_nil end - + it 'gets a new instance of the logger when file and level are set' do subject.file.should_not be_nil subject.level.should_not be_nil subject.instance.should_not be_nil end - + it 'keeps the same object from multiple calls to instance' do subject.instance === subject.instance end - + end - + describe '.configure' do before(:each) { subject.reset_device! } it 'sets the file and level in one call' do @@ -46,11 +46,11 @@ subject.level.should == ::Logger::WARN subject.instance.level.should == ::Logger::WARN end - + end - + describe '.reset_device!' do - + it 'resets the logger instance, file, and level' do subject.instance.should be subject.file.should be @@ -60,11 +60,11 @@ subject.file.should_not be subject.level.should_not be end - + end - + context 'when logging' do - + it 'doesn\'t raise errors when log instance is nil' do subject.reset_device! subject.instance.should be_nil @@ -78,44 +78,54 @@ subject.log 'No errors here' }.to_not raise_error end - + it 'logs correctly when instance is valid' do subject.instance.should_not be_nil subject.instance.should_receive(:info).with('Should log great') subject.info 'Should log great' end - + end - + describe Protobuf::Logger::LogMethods do - + context 'when included in another class' do - + before(:all) do class MyTestClass include Protobuf::Logger::LogMethods end end - + subject { MyTestClass.new } - - it 'responds to all logger methods' do - subject.should respond_to :log_debug - subject.should respond_to :log_info - subject.should respond_to :log_warn - subject.should respond_to :log_error - subject.should respond_to :log_fatal - subject.should respond_to :log_add - subject.should respond_to :log_log + + it { should respond_to(:log_debug) } + it { should respond_to(:log_info) } + it { should respond_to(:log_warn) } + it { should respond_to(:log_error) } + it { should respond_to(:log_fatal) } + it { should respond_to(:log_add) } + it { should respond_to(:log_log) } + + context '#log_exception' do + it 'logs the exception message as an error and backtrace as debug' do + subject.should_receive(:log_error).twice + subject.should_receive(:log_debug) + subject.log_exception(RuntimeError.new('this is an exception')) + end end - + + its(:log_signature) { should eq "[MyTestClass]" } + describe '#sign_message' do + specify { subject.sign_message("this is a test").should eq "[MyTestClass] this is a test" } + specify { subject.class.sign_message("this is a test").should eq "[MyTestClass] this is a test" } + end + it 'passes all embedded log calls to Logger instance' do - Protobuf::Logger.instance.should_receive(:debug).with('log this') + Protobuf::Logger.instance.should_receive(:debug).with('[MyTestClass] log this') subject.log_debug('log this') end - + end - end - end diff --git a/spec/support/server.rb b/spec/support/server.rb index 5aaccd9a..9445a567 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,5 +1,5 @@ require 'ostruct' -require 'protobuf/common/logger' +require 'protobuf/logger' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/servers/socket_runner' From e3eca37db12ad5c19265da8e541a49328872b6cf Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 10 Oct 2012 20:19:57 -0600 Subject: [PATCH 0134/1191] Use new log sign_message/log_signature api All protobuf logger usage has consisted of manually prepending a custom log signature to the each and every log message. This commit standardizes the approach by making `log_signature` an included method along with `sign_message` for use in signing a log message in the case of block usage (which is all cases currently). Any non-block usage of log methods will auto-sign each string message parameter given. --- lib/protobuf/rpc/connectors/common.rb | 33 ++++++++++--------- lib/protobuf/rpc/connectors/em_client.rb | 8 ++--- lib/protobuf/rpc/connectors/eventmachine.rb | 7 +++- lib/protobuf/rpc/connectors/socket.rb | 14 +++++--- lib/protobuf/rpc/connectors/zmq.rb | 14 +++++--- lib/protobuf/rpc/server.rb | 15 ++++----- lib/protobuf/rpc/servers/evented/server.rb | 4 +-- lib/protobuf/rpc/servers/socket/server.rb | 15 +++++---- lib/protobuf/rpc/servers/socket/worker.rb | 14 ++++---- lib/protobuf/rpc/servers/zmq/server.rb | 6 ++-- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- lib/protobuf/rpc/stat.rb | 12 +++++-- .../protobuf/rpc/connectors/common_spec.rb | 9 ++--- spec/support/server.rb | 6 +++- 14 files changed, 89 insertions(+), 70 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 8e4cf82f..6779fe55 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -12,7 +12,7 @@ def any_callbacks? end def complete - @stats.end + @stats.stop log_info { @stats.to_s } log_debug { sign_message('Response proceessing complete') } @complete_cb.call(self) unless @complete_cb.nil? @@ -23,7 +23,7 @@ def complete end def data_callback(data) - log_debug { "[#{log_signature}] Using data_callback" } + log_debug { sign_message('Using data_callback') } @used_data_callback = true @data = data end @@ -36,12 +36,12 @@ def fail(code, message) @error = ClientError.new @error.code = code.is_a?(Symbol) ? Protobuf::Socketrpc::ErrorReason.values[code] : code @error.message = message - log_debug { "[#{log_signature}] Server failed request (invoking on_failure): %s" % @error.inspect } + log_debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } @failure_cb.call(@error) unless @failure_cb.nil? - rescue - log_error { "[#{log_signature}] Failure callback error encountered: %s" % $!.message } - log_error { "[#{log_signature}] %s" % $!.backtrace.join("\n") } + rescue => e + log_error { sign_message("Failure callback error encountered") } + log_exception(e) raise ensure complete @@ -53,18 +53,19 @@ def initialize_stats @stats.service = @options[:service].name @stats.method = @options[:method].to_s rescue => ex + log_exception(ex) fail(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") end def log_signature - @log_signature ||= "client-#{self.class}" + @_log_signature ||= "client-#{self.class}" end def parse_response # Close up the connection as we no longer need it close_connection - log_debug { "[#{log_signature}] Parsing response from server (connection closed)" } + log_debug { sign_message("Parsing response from server (connection closed)") } # Parse out the raw response response_wrapper = Protobuf::Socketrpc::Response.new @@ -72,13 +73,13 @@ def parse_response # Determine success or failure based on parsed data if response_wrapper.has_field?(:error_reason) - log_debug { "[#{log_signature}] Error response parsed" } + log_debug { sign_message("Error response parsed") } # fail the call if we already know the client is failed # (don't try to parse out the response payload) fail(response_wrapper.error_reason, response_wrapper.error) else - log_debug { "[#{log_signature}] Successful response parsed" } + log_debug { sign_message("Successful response parsed") } # Ensure client_response is an instance response_type = @options[:response_type].new @@ -118,12 +119,12 @@ def setup_connection end def succeed(response) - log_debug { "[#{log_signature}] Server succeeded request (invoking on_success)" } + log_debug { sign_message("Server succeeded request (invoking on_success)") } @success_cb.call(response) unless @success_cb.nil? - rescue - log_error { "[#{log_signature}] Success callback error encountered: %s" % $!.message } - log_error { "[#{log_signature}] %s" % $!.backtrace.join("\n") } - fail :RPC_ERROR, 'An exception occurred while calling on_success: %s' % $!.message + rescue => e + log_error { sign_message("Success callback error encountered") } + log_exception(e) + fail(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") ensure complete end @@ -138,7 +139,7 @@ def validate_request_type def verify_callbacks if !any_callbacks? - log_debug { "[#{log_signature}] No callbacks set, using data_callback" } + log_debug { sign_message("No callbacks set, using data_callback") } @success_cb = @failure_cb = self.method(:data_callback) end end diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index cf482028..06d8ec99 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -19,9 +19,9 @@ def initialize(options={}, &failure_cb) @response_buffer = ::Protobuf::Rpc::Buffer.new(:read) verify_options - log_debug { "[#{log_signature}] Client Initialized: %s" % options.inspect } rescue fail(:RPC_ERROR, 'Failed to initialize connection: %s' % $!.message) + log_debug { sign_message("Client Initialized: #{options.inspect}") } end ## @@ -29,7 +29,7 @@ def initialize(options={}, &failure_cb) # def self.connect(options={}) options = DEFAULT_OPTIONS.merge(options) - log_debug { "[client-#{self}] Connecting to server: %s" % options.inspect } + log_debug { sign_message("Connecting to server: #{options.inspect}") } EM.connect(options[:host], options[:port], self, options) end @@ -56,7 +56,7 @@ def on_success(&success_cb) end def receive_data(data) - log_debug { "[#{log_signature}] receive_data: %s" % data } + log_debug { sign_message("receive_data: #{data}") } @response_buffer << data @response_data = @response_buffer.data parse_response if(!@response_data.nil? && @response_buffer.flushed?) @@ -65,7 +65,7 @@ def receive_data(data) def send_data request_buffer = ::Protobuf::Rpc::Buffer.new(:write) request_buffer.set_data(@request_data) - log_debug { "[#{log_signature}] sending data: #{request_buffer.inspect}" } + log_debug { sign_message("sending data: #{request_buffer.inspect}") } super(request_buffer.write) rescue fail(:RPC_ERROR, 'Connection error: %s' % $!.message) diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index 864ce1cc..ba1065c5 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -12,6 +12,7 @@ def send_request ::EM.next_tick do log_debug { "[#{log_signature}] Scheduling EventMachine client request to be created on next tick" } + log_debug { sign_message('Scheduling EventMachine client request to be created on next tick') } cnxn = EMClient.connect(options, &ensure_cb) cnxn.on_success(&success_cb) if success_cb cnxn.on_failure(&ensure_cb) @@ -19,6 +20,7 @@ def send_request cnxn.setup_connection cnxn.send_data log_debug { "[#{log_signature}] Connection scheduled" } + log_debug { sign_message('Connection scheduled') } end async? ? true : set_timeout_and_validate_fiber @@ -37,6 +39,7 @@ def ensure_cb def log_signature @log_signature ||= "client-#{self.class}" + @_log_signature ||= "client-#{self.class}" end private @@ -59,6 +62,7 @@ def resume_fiber(fib) fib.resume(true) rescue => ex message = 'Synchronous client failed: %s' % ex.message + log_exception(ex) error_stop_reactor(message) end @@ -69,7 +73,8 @@ def set_timeout_and_validate_fiber end Fiber.yield - rescue FiberError + rescue FiberError => ex + log_exception(ex) message = "Synchronous calls must be in 'EM.fiber_run' block" error_stop_reactor(message) end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 460dc804..19d33a43 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -22,22 +22,26 @@ def check_async log_error { "[client-#{self.class}] Cannot run in async mode" } raise "Cannot use Socket client in async mode" end + def log_signature + @_log_signature ||= "[client-#{self.class}]" end + private + def close_connection @socket.close - log_debug { "[client-#{self.class}] Connector closed" } + log_debug { sign_message('Connector closed') } end def connect_to_rpc_server @socket = TCPSocket.new(options[:host], options[:port]) - log_debug { "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" } + log_debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } end # Method to determine error state, must be used with Connector api def error? return true if(@error) - log_debug { "[client-#{self.class}] Error state : #{@socket.closed?}" } + log_debug { sign_message("Error state : #{@socket.closed?}") } @socket.closed? end @@ -53,8 +57,8 @@ def read_data end def read_response - log_debug { "[client-#{self.class}] error? is #{error?}" } return if(error?) + log_debug { sign_message("error? is #{error?}") } response_buffer = ::Protobuf::Rpc::Buffer.new(:read) response_buffer << read_data @stats.response_size = response_buffer.size @@ -68,7 +72,7 @@ def send_data request_buffer.set_data(@request_data) @socket.write(request_buffer.write) @socket.flush - log_debug { "[client-#{self.class}] write closed" } + log_debug { sign_message("write closed") } end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 2027efe5..fa14ab60 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -26,22 +26,26 @@ def check_async log_error { "[client-#{self.class}] Cannot run in async mode" } raise "Cannot use Zmq client in async mode" end + def log_signature + @_log_signature ||= "[client-#{self.class}]" end + private + def close_connection return if(@error) zmq_error_check(@socket.close) zmq_error_check(@zmq_context.terminate) - log_debug { "[client-#{self.class}] Connector closed" } + log_debug { sign_message("Connector closed") } end def connect_to_rpc_server return if(@error) - log_debug { "[client-#{self.class} Establishing connection: #{options[:host]}:#{options[:port]}" } + log_debug { sign_message("Establishing connection: #{options[:host]}:#{options[:port]}") } @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) zmq_error_check(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) - log_debug { "[client-#{self.class}] Connection established #{options[:host]}:#{options[:port]}" } + log_debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } end # Method to determine error state, must be used with Connector api @@ -58,10 +62,10 @@ def read_response def send_data return if(@error) - log_debug { "[#{log_signature}] Sending Request: %s" % @request_data } + log_debug { sign_message("Sending Request: #{@request_data}") } @stats.request_size = @request_data.size zmq_error_check(@socket.send_string(@request_data)) - log_debug { "[client-#{self.class}] write closed" } + log_debug { sign_message("write closed") } end def zmq_error_check(return_code) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 9ba81c50..441cff09 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -23,16 +23,14 @@ def handle_client ::GC.disable if ::Protobuf.gc_pause_server_request? invoke_rpc_method rescue => error - # Ensure we're handling any errors that try to slip out the back door - log_error(error.message) - log_error(error.backtrace.join("\n")) + log_exception(error) handle_error(error) send_response end # Client error handler. Receives an exception object and writes it into the @response def handle_error(error) - log_debug { "[#{log_signature}] handle_error: %s" % error.inspect } + log_debug { sign_message("handle_error: #{error.inspect}") } if error.respond_to?(:to_response) error.to_response(@response) else @@ -73,12 +71,12 @@ def invoke_rpc_method end def log_signature - @log_signature ||= "server-#{self.class}" + @_log_signature ||= "[server-#{self.class.name}]" end # Parse the incoming request object into our expected request object def parse_request_from_buffer - log_debug { "[#{log_signature}] parsing request from buffer: %s" % @request_data } + log_debug { sign_message("Parsing request from buffer: #{@request_data}") } @request.parse_from_string(@request_data) rescue => error exc = ::Protobuf::Rpc::BadRequestData.new 'Unable to parse request: %s' % error.message @@ -127,11 +125,10 @@ def parse_service_info # Write the response wrapper to the client def send_response raise 'Response already sent to client' if @did_respond - log_debug { "[#{log_signature}] Sending response to client: %s" % @response.inspect } + log_debug { sign_message("Sending response to client: #{@response.inspect}") } send_data - @stats.end - @stats.log_stats @did_respond = true + @stats.stop && log_info { @stats.to_s } ensure ::GC.enable if ::Protobuf.gc_pause_server_request? end diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb index f50903c7..b1f919e7 100644 --- a/lib/protobuf/rpc/servers/evented/server.rb +++ b/lib/protobuf/rpc/servers/evented/server.rb @@ -21,7 +21,7 @@ def post_init # Receive a chunk of data, potentially flushed to handle_client def receive_data(data) - log_debug { '[server] receive_data: %s' % data } + log_debug { sign_message("receive_data: #{data}") } @request_buffer << data @request_data = @request_buffer.data @@ -34,7 +34,7 @@ def send_data response_buffer = Protobuf::Rpc::Buffer.new(:write) response_buffer.set_data(@response) @stats.response_size = response_buffer.size - log_debug { "[#{log_signature}] sending data: #{response_buffer.inspect}" } + log_debug { sign_message("sending data: #{response_buffer.inspect}") } super(response_buffer.write) end end diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index c88241eb..eadf709f 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -1,5 +1,6 @@ require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/worker' + module Protobuf module Rpc module Socket @@ -14,7 +15,7 @@ def self.cleanup? end def self.cleanup_threads - log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - start" } + log_debug { sign_message("Thread cleanup - #{@threads.size} - start") } @threads = @threads.select do |t| if t[:thread].alive? @@ -26,11 +27,11 @@ def self.cleanup_threads end end - log_debug { "[#{log_signature}] Thread cleanup - #{@threads.size} - complete" } + log_debug { sign_message("Thread cleanup - #{@threads.size} - complete") } end def self.log_signature - @log_signature ||= "server-#{self}" + @_log_signature ||= "server-#{self.class.name}" end def self.new_worker(socket) @@ -42,7 +43,7 @@ def self.new_worker(socket) end def self.run(opts = {}) - log_debug { "[#{log_signature}] Run" } + log_debug { sign_message("Run") } host = opts.fetch(:host, "127.0.0.1") port = opts.fetch(:port, 9399) backlog = opts.fetch(:backlog, 100) @@ -59,7 +60,7 @@ def self.run(opts = {}) @running = true while running? - log_debug { "[#{log_signature}] Waiting for connections" } + log_debug { sign_message("Waiting for connections") } if ready_cnxns = IO.select(@listen_fds, [], [], auto_collect_timeout) cnxns = ready_cnxns.first @@ -68,13 +69,13 @@ def self.run(opts = {}) when !running? then # no-op when client == @server then - log_debug { "[#{log_signature}] Accepted new connection" } + log_debug { sign_message("Accepted new connection") } client, sockaddr = @server.accept @listen_fds << client else if !@working.include?(client) @working << @listen_fds.delete(client) - log_debug { "[#{log_signature}] Working" } + log_debug { sign_message("Working") } @threads << { :thread => new_worker(client), :socket => client } cleanup_threads if cleanup? diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 63bf4727..a0bc3a1f 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -20,20 +20,16 @@ def initialize(sock, &complete_cb) log_debug { "[#{log_signature}] Post init, new read buffer created" } @stats.client = ::Socket.unpack_sockaddr_in(@socket.getpeername) - log_debug { "stats are #{@stats.to_s}" } + log_debug { sign_message("stats are #{@stats.to_s}") } request_buffer << read_data @request_data = request_buffer.data @stats.request_size = request_buffer.size - log_debug { "[#{log_signature}] handling request" } + log_debug { sign_message("handling request") } handle_client if request_buffer.flushed? end - def log_signature - @log_signature ||= "server-#{self.class}-#{object_id}" - end - def read_data size_io = StringIO.new @@ -50,11 +46,15 @@ def send_data response_buffer = Protobuf::Rpc::Buffer.new(:write) response_buffer.set_data(@response) @stats.response_size = response_buffer.size - log_debug { "[#{log_signature}] sending data : %s" % response_buffer.data } + log_debug { sign_message("sending data : #{response_buffer.data}") } @socket.write(response_buffer.write) @socket.flush @complete_cb.call(@socket) end + + def log_signature + @_log_signature ||= "server-#{self.class}-#{object_id}" + end end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 5504506a..817d80af 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -12,18 +12,18 @@ class Server # Class Methods # def self.run(opts = {}) - log_debug { "[#{log_signature}] initializing broker" } + log_debug { sign_message("initializing broker") } @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts) local_worker_threads = opts.fetch(:threads, 5) worker_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) - log_debug { "[#{log_signature}] starting server workers" } + log_debug { sign_message("starting server workers") } local_worker_threads.times do @threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run } end @running = true - log_debug { "[#{log_signature}] server started" } + log_debug { sign_message("server started") } while self.running? do @broker.poll end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 8fa7f2bf..dfee6029 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -13,7 +13,7 @@ def zmq_error_check(return_code) end def log_signature - @log_signature ||= "server-#{self.class}-#{object_id}" + @_log_signature ||= "server-#{self.class}-#{object_id}" end def resolve_ip(hostname) diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 760d1e32..0dd2872f 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -38,6 +38,8 @@ def start end def end + + def stop start if !@start_time @end_time ||= Time.now end @@ -49,9 +51,13 @@ def rpc def elapsed_time (start_time && end_time ? '%ss' % (end_time - start_time).round(4) : nil) end - - def log_stats - Protobuf::Logger.info(self.to_s) + + def server? + @mode == :SERVER + end + + def client? + @mode == :CLIENT end def to_s diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 2b41bb78..216d977e 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -88,8 +88,7 @@ it "calls #complete before exit" do stats = double("Object") - stats.stub(:end) { true } - stats.stub(:log_stats) { true } + stats.stub(:stop) { true } subject.stats = stats subject.should_receive(:complete) @@ -98,8 +97,7 @@ it "calls the #{cb} callback when provided" do stats = double("Object") - stats.stub(:end) { true } - stats.stub(:log_stats) { true } + stats.stub(:stop) { true } subject.stats = stats _cb = double("Object") @@ -110,8 +108,7 @@ it "calls the complete callback when provided" do stats = double("Object") - stats.stub(:end) { true } - stats.stub(:log_stats) { true } + stats.stub(:stop) { true } subject.stats = stats comp_cb = double("Object") diff --git a/spec/support/server.rb b/spec/support/server.rb index 9445a567..032a68d4 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -57,7 +57,7 @@ def start else start_socket_server end - log_debug { "[stub-server] Server started #{@options.host}:#{@options.port}" } + log_debug { sign_message("Server started #{@options.host}:#{@options.port}") } rescue => ex if ex =~ /no acceptor/ # Means EM didn't shutdown in the next_tick yet stop @@ -94,4 +94,8 @@ def stop @running = false end + + def log_signature + @_log_signature ||= "[stub-server]" + end end From 29aea2064a173098f185d5c4a2d3e402a70ae995 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 10 Oct 2012 20:33:36 -0600 Subject: [PATCH 0135/1191] Fix syntax that was bugging me Things including, but not limited to: * No parens around method params. * Parens and no spaces around control flow expressions (e.g. if(somecondition)) * Move away from percent-based c-style sprintf string interpolation to regular double quote interpolation. * Use `until` instead of `while` when it makes things more clear, and vice versa. * Wrap method call arguments in params. * Use explicit exception variable instead of global `$!`. * Wrap complex conditional expressions in appropriately named predicate methods. * Remove line-ending or excessive whitespace. --- lib/protobuf/rpc/buffer.rb | 4 +-- lib/protobuf/rpc/connectors/base.rb | 4 +-- lib/protobuf/rpc/connectors/common.rb | 10 +++--- lib/protobuf/rpc/connectors/em_client.rb | 10 +++--- lib/protobuf/rpc/connectors/eventmachine.rb | 7 ++-- lib/protobuf/rpc/connectors/socket.rb | 8 ++--- lib/protobuf/rpc/connectors/zmq.rb | 6 ++-- lib/protobuf/rpc/error.rb | 6 ++-- lib/protobuf/rpc/server.rb | 2 +- lib/protobuf/rpc/servers/socket/worker.rb | 8 +++-- lib/protobuf/rpc/servers/zmq/worker.rb | 8 ++--- lib/protobuf/rpc/stat.rb | 39 ++++++++++----------- spec/spec_helper.rb | 2 +- spec/support/server.rb | 4 +-- 14 files changed, 59 insertions(+), 59 deletions(-) diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 0dc11ef2..f91d9a23 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -32,7 +32,7 @@ def write(force_mode=true) end @size = @data.length - '%d-%s' % [@size, @data] + "#{@size}-#{@data}" end def <<(data) @@ -63,7 +63,7 @@ def flushed? def get_data_size if @size == 0 || @data.match(SIZE_REGEX) sliced_size = @data.slice!(SIZE_REGEX) - @size = sliced_size.gsub('-', '').to_i unless(sliced_size.nil?) + @size = sliced_size.gsub('-', '').to_i unless sliced_size.nil? end end diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 5a3e0712..04e51f4a 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -22,14 +22,14 @@ module Connectors class Base include Protobuf::Logger::LogMethods - + attr_reader :options attr_accessor :success_cb, :failure_cb, :complete_cb def initialize(options) @options = DEFAULT_OPTIONS.merge(options) end - + def send_request raise 'If you inherit a Connector from Base you must implement send_request' end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 6779fe55..14d62f60 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -97,8 +97,8 @@ def parse_response def post_init send_data unless error? - rescue - fail(:RPC_ERROR, 'Connection error: %s' % $!.message) + rescue => e + fail(:RPC_ERROR, "Connection error: #{e.message}") end def rpc_request_data @@ -109,8 +109,8 @@ def rpc_request_data :method_name => @options[:method].to_s, :request_proto => @options[:request].serialize_to_string ).serialize_to_string - rescue - fail :INVALID_REQUEST_PROTO, "Could not set request proto: #{$!.message}" + rescue => e + fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") end def setup_connection @@ -133,7 +133,7 @@ def validate_request_type unless @options[:request].class == @options[:request_type] expected = @options[:request_type].name actual = @options[:request].class.name - fail :INVALID_REQUEST_PROTO, 'Expected request type to be type of %s, got %s instead' % [expected, actual] + fail(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead") end end diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index 06d8ec99..f785c72c 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -19,9 +19,9 @@ def initialize(options={}, &failure_cb) @response_buffer = ::Protobuf::Rpc::Buffer.new(:read) verify_options - rescue - fail(:RPC_ERROR, 'Failed to initialize connection: %s' % $!.message) log_debug { sign_message("Client Initialized: #{options.inspect}") } + rescue => e + fail(:RPC_ERROR, "Failed to initialize connection: #{e.message}") end ## @@ -59,7 +59,7 @@ def receive_data(data) log_debug { sign_message("receive_data: #{data}") } @response_buffer << data @response_data = @response_buffer.data - parse_response if(!@response_data.nil? && @response_buffer.flushed?) + parse_response if !@response_data.nil? && @response_buffer.flushed? end def send_data @@ -67,8 +67,8 @@ def send_data request_buffer.set_data(@request_data) log_debug { sign_message("sending data: #{request_buffer.inspect}") } super(request_buffer.write) - rescue - fail(:RPC_ERROR, 'Connection error: %s' % $!.message) + rescue => e + fail(:RPC_ERROR, "Connection error: #{e.message}") end # overwriting this method for java because it's broken in eventmachine. See https://github.com/eventmachine/eventmachine/issues/14 diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index ba1065c5..f553d42c 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -34,11 +34,10 @@ def send_request # don't want to swallow the black holes. # def ensure_cb - @ensure_cb ||= (@failure_cb || lambda { |error| raise '%s: %s' % [error.code.name, error.message] } ) + @ensure_cb ||= (@failure_cb || lambda { |error| raise "#{error.code.name}: #{error.message}" }) end def log_signature - @log_signature ||= "client-#{self.class}" @_log_signature ||= "client-#{self.class}" end @@ -61,14 +60,14 @@ def resume_fiber(fib) ::EM::cancel_timer(@timeout_timer) fib.resume(true) rescue => ex - message = 'Synchronous client failed: %s' % ex.message log_exception(ex) + message = "Synchronous client failed: #{ex.message}" error_stop_reactor(message) end def set_timeout_and_validate_fiber @timeout_timer = ::EM::add_timer(@options[:timeout]) do - message = 'Client timeout of %d seconds expired' % @options[:timeout] + message = "Client timeout of #{@options[:timeout]} seconds expired" error_stop_reactor(message) end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 19d33a43..33e67dfe 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -40,7 +40,7 @@ def connect_to_rpc_server # Method to determine error state, must be used with Connector api def error? - return true if(@error) + return true if @error log_debug { sign_message("Error state : #{@socket.closed?}") } @socket.closed? end @@ -48,7 +48,7 @@ def error? def read_data size_io = StringIO.new - while((size_reader = @socket.getc) != "-") + until (size_reader = @socket.getc) == "-" size_io << size_reader end str_size_io = size_io.string @@ -57,8 +57,8 @@ def read_data end def read_response - return if(error?) log_debug { sign_message("error? is #{error?}") } + return if error? response_buffer = ::Protobuf::Rpc::Buffer.new(:read) response_buffer << read_data @stats.response_size = response_buffer.size @@ -67,7 +67,7 @@ def read_response end def send_data - return if(error?) + return if error? request_buffer = ::Protobuf::Rpc::Buffer.new(:write) request_buffer.set_data(@request_data) @socket.write(request_buffer.write) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index fa14ab60..f74dbc8c 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -33,14 +33,12 @@ def log_signature private def close_connection - return if(@error) zmq_error_check(@socket.close) zmq_error_check(@zmq_context.terminate) log_debug { sign_message("Connector closed") } end def connect_to_rpc_server - return if(@error) log_debug { sign_message("Establishing connection: #{options[:host]}:#{options[:port]}") } @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) @@ -54,14 +52,14 @@ def error? end def read_response - return if(@error) + return if @error @response_data = '' zmq_error_check(@socket.recv_string(@response_data)) parse_response end def send_data - return if(@error) + return if @error log_debug { sign_message("Sending Request: #{@request_data}") } @stats.request_size = @request_data.size zmq_error_check(@socket.send_string(@request_data)) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index bf4a490d..37d0c6c0 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -3,16 +3,16 @@ module Protobuf module Rpc ClientError = Struct.new("ClientError", :code, :message) - + # Base PbError class for client and server errors class PbError < StandardError attr_reader :error_type - + def initialize message='An unknown RpcError occurred', error_type='RPC_ERROR' @error_type = error_type.is_a?(String) ? ::Protobuf::Socketrpc::ErrorReason.const_get(error_type) : error_type super message end - + def to_response response response.error = message response.error_reason = @error_type diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 441cff09..333b5bfc 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -79,7 +79,7 @@ def parse_request_from_buffer log_debug { sign_message("Parsing request from buffer: #{@request_data}") } @request.parse_from_string(@request_data) rescue => error - exc = ::Protobuf::Rpc::BadRequestData.new 'Unable to parse request: %s' % error.message + exc = ::Protobuf::Rpc::BadRequestData.new("Unable to parse request: #{error.message}") log_error { exc.message } raise exc end diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index a0bc3a1f..c8209dfb 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -33,7 +33,7 @@ def initialize(sock, &complete_cb) def read_data size_io = StringIO.new - while((size_reader = @socket.getc) != "-") + until (size_reader = @socket.getc) == "-" size_io << size_reader end str_size_io = size_io.string @@ -42,7 +42,7 @@ def read_data end def send_data - raise 'Socket closed unexpectedly' if(@socket.nil? || @socket.closed?) + raise 'Socket closed unexpectedly' unless socket_writable? response_buffer = Protobuf::Rpc::Buffer.new(:write) response_buffer.set_data(@response) @stats.response_size = response_buffer.size @@ -55,6 +55,10 @@ def send_data def log_signature @_log_signature ||= "server-#{self.class}-#{object_id}" end + + def socket_writable? + ! @socket.nil? && ! @socket.closed? + end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 4fc2909e..3e67aac7 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -13,9 +13,9 @@ class Worker # def initialize(opts={}) @options = opts - host = @options.fetch(:host, "127.0.0.1") - port = @options.fetch(:port, 9400) - protocol = @options.fetch(:protocol, "tcp") + host = @options.fetch(:host) { "127.0.0.1" } + port = @options.fetch(:port) { 9400 } + protocol = @options.fetch(:protocol) { "tcp" } @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REP) @@ -50,7 +50,7 @@ def run @poller.readables.each do |socket| initialize_buffers handle_request(socket) - handle_client unless(@request_data.nil?) + handle_client unless @request_data.nil? end end ensure diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 0dd2872f..01dee122 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -4,52 +4,51 @@ module Protobuf module Rpc class Stat - attr_accessor :type, :start_time, :end_time, :request_size, :response_size, :client, :server, :service, :method - TYPES = [:SERVER, :CLIENT] def initialize type=:SERVER, do_start=true @type = type start if do_start + attr_accessor :mode, :start_time, :end_time, :request_size, :dispatcher + attr_accessor :response_size, :client, :server, :service, :method + end - - def client= peer + + def client=(peer) @client = {:port => peer[0], :ip => peer[1]} end - + def client - @client ? '%s:%d' % [@client[:ip], @client[:port]] : nil + @client ? "#{@client[:ip]}:#{@client[:port]}" : nil end def server= peer @server = {:port => peer[0], :ip => peer[1]} end - + def server - @server ? '%s:%d' % [@server[:ip], @server[:port]] : nil + @server ? "#{@server[:ip]}:#{@server[:port]}" : nil end - + def sizes - '%dB/%dB' % [@request_size || 0, @response_size || 0] + "#{@request_size || 0}B/#{@response_size || 0}B" end - + def start @start_time ||= Time.now end - - def end def stop start if !@start_time @end_time ||= Time.now end - + def rpc - service && method ? '%s#%s' % [service, method] : nil + service && method ? "#{service}##{method}" : nil end - + def elapsed_time - (start_time && end_time ? '%ss' % (end_time - start_time).round(4) : nil) + (start_time && end_time ? "#{(end_time - start_time).round(4)}s" : nil) end def server? @@ -59,7 +58,7 @@ def server? def client? @mode == :CLIENT end - + def to_s [ @type == :SERVER ? "[SRV-#{self.class}]" : "[CLT-#{self.class}]", @@ -67,9 +66,9 @@ def to_s elapsed_time, sizes, @type == :SERVER ? server : client - ].delete_if{|v| v.nil? }.join(' - ') + ].compact.join(' - ') end - + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 70448f4e..15306d86 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,7 +36,7 @@ end class ::Protobuf::Rpc::Client - def == other + def ==(other) connector.options == other.options && \ success_cb == other.success_cb && \ failure_cb == other.failure_cb diff --git a/spec/support/server.rb b/spec/support/server.rb index 032a68d4..364b1df2 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -86,10 +86,10 @@ def stop EventMachine.stop_server(@server_handle) if @server_handle when @options.server == Protobuf::Rpc::Zmq::Server then Protobuf::Rpc::ZmqRunner.stop - @zmq_server.join if(@zmq_server) + @zmq_server.join if @zmq_server else Protobuf::Rpc::SocketRunner.stop - @sock_server.join if(@sock_server) + @sock_server.join if @sock_server end @running = false From ea155152e9feb7a923d166edd866e289936c9db8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 10 Oct 2012 20:38:31 -0600 Subject: [PATCH 0136/1191] Update stats object api --- lib/protobuf/rpc/connectors/common.rb | 4 ++-- lib/protobuf/rpc/stat.rb | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 14d62f60..d65a321b 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -28,7 +28,7 @@ def data_callback(data) @data = data end - # All failures should be routed through this method + # All failures should be routed through this method. # # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) # @param [String] message The error message @@ -48,7 +48,7 @@ def fail(code, message) end def initialize_stats - @stats = Protobuf::Rpc::Stat.new(:CLIENT, true) + @stats = Protobuf::Rpc::Stat.new(:CLIENT) @stats.server = [@options[:port], @options[:host]] @stats.service = @options[:service].name @stats.method = @options[:method].to_s diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 01dee122..ab2c7950 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -4,14 +4,14 @@ module Protobuf module Rpc class Stat - TYPES = [:SERVER, :CLIENT] - - def initialize type=:SERVER, do_start=true - @type = type - start if do_start attr_accessor :mode, :start_time, :end_time, :request_size, :dispatcher attr_accessor :response_size, :client, :server, :service, :method + MODES = [:SERVER, :CLIENT].freeze + + def initialize(mode = :SERVER) + @mode = mode + start end def client=(peer) @@ -21,8 +21,8 @@ def client=(peer) def client @client ? "#{@client[:ip]}:#{@client[:port]}" : nil end - - def server= peer + + def server=(peer) @server = {:port => peer[0], :ip => peer[1]} end @@ -61,11 +61,11 @@ def client? def to_s [ - @type == :SERVER ? "[SRV-#{self.class}]" : "[CLT-#{self.class}]", + server? ? "[SRV-#{self.class}]" : "[CLT-#{self.class}]", rpc, elapsed_time, sizes, - @type == :SERVER ? server : client + server? ? server : client ].compact.join(' - ') end From 68875a514c30846e3315834b959d36f0903d0835 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 10 Oct 2012 20:45:33 -0600 Subject: [PATCH 0137/1191] Centralize server request initialization Pulls from each server object the initialization of request-specific objects, such as the wrapping request and response, stats, and client peer (if any). This makes us less error prone in making changes to the implementing server types. --- lib/protobuf/rpc/connectors/zmq.rb | 2 ++ lib/protobuf/rpc/server.rb | 13 ++++++++++++- lib/protobuf/rpc/servers/evented/server.rb | 12 +++++------- lib/protobuf/rpc/servers/evented_runner.rb | 11 ----------- lib/protobuf/rpc/servers/socket/worker.rb | 12 ++++++------ lib/protobuf/rpc/servers/zmq/worker.rb | 13 ++----------- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index f74dbc8c..82f508aa 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -33,12 +33,14 @@ def log_signature private def close_connection + return if @error zmq_error_check(@socket.close) zmq_error_check(@zmq_context.terminate) log_debug { sign_message("Connector closed") } end def connect_to_rpc_server + return if @error log_debug { sign_message("Establishing connection: #{options[:host]}:#{options[:port]}") } @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 333b5bfc..5227142c 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -8,6 +8,17 @@ module Protobuf module Rpc module Server + def initialize_request! + log_debug { sign_message('Post init') } + @request = ::Protobuf::Socketrpc::Request.new + @response = ::Protobuf::Socketrpc::Response.new + @stats = Protobuf::Rpc::Stat.new(:SERVER) + set_peer + end + + # no-op, implemented by including class if desired. + def set_peer; end + # Invoke the service method dictated by the proto wrapper request object def handle_client # Parse the protobuf request from the socket @@ -35,7 +46,7 @@ def handle_error(error) error.to_response(@response) else message = error.respond_to?(:message) ? error.message : error.to_s - code = error.respond_to?(:code) ? error.code.to_s : "RPC_ERROR" + code = error.respond_to?(:code) ? error.code : 'RPC_ERROR' ::Protobuf::Rpc::PbError.new(message, code).to_response(@response) end end diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb index b1f919e7..2f508acd 100644 --- a/lib/protobuf/rpc/servers/evented/server.rb +++ b/lib/protobuf/rpc/servers/evented/server.rb @@ -9,14 +9,8 @@ class Server < ::EventMachine::Connection # Initialize a new read buffer for storing client request info def post_init - log_debug { '[server] Post init, new read buffer created' } - @stats = Protobuf::Rpc::Stat.new(:SERVER, true) - @stats.client = ::Socket.unpack_sockaddr_in(get_peername) + initialize_request! @request_buffer = Protobuf::Rpc::Buffer.new(:read) - @request = ::Protobuf::Socketrpc::Request.new - @response = ::Protobuf::Socketrpc::Response.new - - @did_respond = false end # Receive a chunk of data, potentially flushed to handle_client @@ -37,6 +31,10 @@ def send_data log_debug { sign_message("sending data: #{response_buffer.inspect}") } super(response_buffer.write) end + + def set_peer + @stats.client = ::Socket.unpack_sockaddr_in(get_peername) + end end end end diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index 5f0df4aa..34c8e3af 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -7,17 +7,6 @@ def self.stop end def self.run(server) - # Ensure errors thrown within EM are caught and logged appropriately - #EventMachine.error_handler do |error| - # raise error - # if error.message == 'no acceptor' - # raise 'Failed binding to %s:%d (%s)' % [server.host, server.port, error.message] - # else - # Protobuf::Logger.error(error.message) - # Protobuf::Logger.error(error.backtrace.join("\n")) - # end - #end - # Startup and run the rpc server ::EventMachine.schedule do ::EventMachine.start_server(server.host, server.port, ::Protobuf::Rpc::Evented::Server) diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index c8209dfb..6f4bf0db 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -10,16 +10,12 @@ class Worker include ::Protobuf::Logger::LogMethods def initialize(sock, &complete_cb) - @did_response = false @socket = sock - @request = Protobuf::Socketrpc::Request.new - @response = Protobuf::Socketrpc::Response.new + initialize_request! + request_buffer = Protobuf::Rpc::Buffer.new(:read) - @stats = Protobuf::Rpc::Stat.new(:SERVER, true) @complete_cb = complete_cb - log_debug { "[#{log_signature}] Post init, new read buffer created" } - @stats.client = ::Socket.unpack_sockaddr_in(@socket.getpeername) log_debug { sign_message("stats are #{@stats.to_s}") } request_buffer << read_data @request_data = request_buffer.data @@ -56,6 +52,10 @@ def log_signature @_log_signature ||= "server-#{self.class}-#{object_id}" end + def set_peer + @stats.client = ::Socket.unpack_sockaddr_in(@socket.getpeername) + end + def socket_writable? ! @socket.nil? && ! @socket.closed? end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 3e67aac7..475221b5 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -31,15 +31,7 @@ def initialize(opts={}) def handle_request(socket) @request_data = '' zmq_error_check(socket.recv_string(@request_data)) - log_debug { "[#{log_signature}] handling request" } if(!@request_data.nil?) - end - - def initialize_buffers - @did_respond = false - @request = ::Protobuf::Socketrpc::Request.new - @response = ::Protobuf::Socketrpc::Response.new - @stats = ::Protobuf::Rpc::Stat.new(:SERVER, true) - log_debug { "[#{log_signature}] Post init" } + log_debug { sign_message("handling request") } if !@request_data.nil? end def run @@ -48,7 +40,7 @@ def run # This lets us see whether we need to die @poller.poll(1_000) @poller.readables.each do |socket| - initialize_buffers + initialize_request! handle_request(socket) handle_client unless @request_data.nil? end @@ -62,7 +54,6 @@ def send_data response_data = @response.is_a?(::Protobuf::Message) ? @response.serialize_to_string : @response.to_s @stats.response_size = response_data.size zmq_error_check(@socket.send_string(response_data)) - @did_respond = true end end From 069507633d7ab5bd1bd98b66864950675b7273a3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 10 Oct 2012 21:00:34 -0600 Subject: [PATCH 0138/1191] Refactor Service API, add ServiceDispatcher Add ServiceDispatcher class to take care of the core concern of sending calls to a service method when a server request has been received. The ServiceDispatcher is also responsible for retrieving the response from the service and ensuring the response type is appropriate. Previously, the ServiceDispatcher functionality was shared between the Server and the Service. The new role of the Server is to simply inflate the request into the wrapper from the socket and hand it to the ServiceDispatcher. By invoking the dispatcher, the server then serializes back to the socket either the response or error. The new role of the Service is to simply act like a PORO. The rpc DSL is still defined on the Service but all method calling and request/response manipulation is left up to the dispatcher. This significantly simplifies both server and service code and allows us to move away from the hook implementaiton used before using `method_added`, aliasing methods and hiding their implementations. One feature that has been removed from the server side due to lack of use in practical applications is async responding. While a "nice to have", it significantly complicated the process of crafting responses to rpc requests. Async responding may be back in a future version, but I would imagine we'd use something closer to an actor implementation or a Fiber-based approach. All in all, this feels like a much cleaner approach. --- lib/protobuf/cli.rb | 1 - lib/protobuf/rpc/client.rb | 9 +- lib/protobuf/rpc/connectors/eventmachine.rb | 1 - lib/protobuf/rpc/server.rb | 102 +++--------- lib/protobuf/rpc/service_dispatcher.rb | 115 +++++++++++++ lib/protobuf/rpc/stat.rb | 8 + spec/functional/evented_server_spec.rb | 1 - spec/lib/protobuf/rpc/client_spec.rb | 7 +- .../protobuf/rpc/service_dispatcher_spec.rb | 94 +++++++++++ spec/lib/protobuf/rpc/service_spec.rb | 157 +++++++++++++----- spec/spec_helper.rb | 5 +- spec/support/test/resource_service.rb | 3 +- 12 files changed, 363 insertions(+), 140 deletions(-) create mode 100644 lib/protobuf/rpc/service_dispatcher.rb create mode 100644 spec/lib/protobuf/rpc/service_dispatcher_spec.rb diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 67245748..b725611a 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,5 +1,4 @@ require 'thor' -require 'pry' require 'protobuf/version' require 'protobuf/logger' require 'protobuf/rpc/servers/evented_runner' diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index c0040365..1ccb6637 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -67,7 +67,7 @@ def on_failure(&failure_cb) def on_failure=(callable) if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 - raise "callable must take a single argument and respond to :call" + raise "Callable must take a single argument and respond to :call" end @connector.failure_cb = callable @@ -87,7 +87,7 @@ def on_success(&success_cb) def on_success=(callable) if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 - raise "callable must take a single argument and respond to :call" + raise "Callable must take a single argument and respond to :call" end @connector.success_cb = callable @@ -107,12 +107,13 @@ def on_success=(callable) # def method_missing(method, *params) service = options[:service] - unless service.rpcs[service].keys.include?(method) + unless service.rpc_method?(method) log_error { sign_message("#{service.name}##{method.to_s} not rpc method, passing to super") } super(method, *params) else - rpc = service.rpcs[service][method.to_sym] log_debug { sign_message("#{service.name}##{method.to_s}") } + rpc = service.rpcs[method.to_sym] + options[:request_type] = rpc.request_type log_debug { sign_message("Request Type: #{options[:request_type].name}") } diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index f553d42c..f433c442 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -19,7 +19,6 @@ def send_request cnxn.on_complete { resume_fiber(f) } unless async? cnxn.setup_connection cnxn.send_data - log_debug { "[#{log_signature}] Connection scheduled" } log_debug { sign_message('Connection scheduled') } end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 5227142c..1a59efb0 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -3,6 +3,7 @@ require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' require 'protobuf/rpc/stat' +require 'protobuf/rpc/service_dispatcher' module Protobuf module Rpc @@ -16,26 +17,34 @@ def initialize_request! set_peer end + def disable_gc! + ::GC.disable if ::Protobuf.gc_pause_server_request? + end + + def enable_gc! + ::GC.enable if ::Protobuf.gc_pause_server_request? + end + # no-op, implemented by including class if desired. def set_peer; end # Invoke the service method dictated by the proto wrapper request object def handle_client - # Parse the protobuf request from the socket - log_debug { "[#{log_signature}] Parsing request from client" } parse_request_from_buffer + @dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(@request) + @stats.dispatcher = @dispatcher - # Determine the service class and method name from the request - log_debug { "[#{log_signature}] Extracting procedure call info from request" } - parse_service_info - - # Call the service method - log_debug { "[#{log_signature}] Dispatching client request to service" } - ::GC.disable if ::Protobuf.gc_pause_server_request? - invoke_rpc_method + disable_gc! + @dispatcher.invoke! + if @dispatcher.success? + @response.response_proto = @dispatcher.response + else + handle_error(@dispatcher.error) + end rescue => error log_exception(error) handle_error(error) + ensure send_response end @@ -51,36 +60,6 @@ def handle_error(error) end end - # Assuming all things check out, we can call the service method - def invoke_rpc_method - # Get a new instance of the service - @service = @klass.new - - # Define our response callback to perform the "successful" response to our client - # This decouples the service's rpc method from our response to the client, - # allowing the service to be the dictator for when the response should be sent back. - # - # In other words, we don't send the response once the service method finishes executing - # since the service may perform it's own operations asynchronously. - @service.on_send_response do |response| - unless @did_respond - parse_response_from_service(response) - send_response - end - end - - @service.on_rpc_failed do |error| - unless @did_respond - handle_error(error) - send_response - end - end - - # Call the service method - log_debug { "[#{log_signature}] Invoking %s#%s with request %s" % [@klass.name, @method, @request.inspect] } - @service.__send__(@method, @request) - end - def log_signature @_log_signature ||= "[server-#{self.class.name}]" end @@ -95,54 +74,15 @@ def parse_request_from_buffer raise exc end - # Read out the response from the service method, - # setting it on the pb request, and serializing the - # response to the protobuf response wrapper - def parse_response_from_service(response) - expected = @klass.rpcs[@klass][@method].response_type - - # Cannibalize the response if it's a Hash - response = expected.new(response) if response.is_a?(Hash) - actual = response.class - log_debug { "[#{log_signature}] response (should/actual): %s/%s" % [expected.name, actual.name] } - - # Determine if the service tried to change response types on us - if expected != actual - raise ::Protobuf::Rpc::BadResponseProto, 'Response proto changed from %s to %s' % [expected.name, actual.name] - else - @response.response_proto = response - end - rescue => error - log_error error.message - log_error error.backtrace.join("\n") - handle_error(error) - end - - # Parses and returns the service and method name from the request wrapper proto - def parse_service_info - @klass = @request.service_name.constantize - @method = @request.method_name.underscore.to_sym - - unless @klass.instance_methods.include?(@method) - raise MethodNotFound, "Service method #{@request.method_name} is not defined by the service" - end - - @stats.service = @klass.name - @stats.method = @method - rescue NameError - raise ServiceNotFound, "Service class #{@request.service_name} is not found" - end - # Write the response wrapper to the client def send_response - raise 'Response already sent to client' if @did_respond log_debug { sign_message("Sending response to client: #{@response.inspect}") } send_data - @did_respond = true @stats.stop && log_info { @stats.to_s } ensure - ::GC.enable if ::Protobuf.gc_pause_server_request? + enable_gc! end end end end + diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb new file mode 100644 index 00000000..a322f4cb --- /dev/null +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -0,0 +1,115 @@ +require 'protobuf/logger' + +module Protobuf + module Rpc + class ServiceDispatcher + + include ::Protobuf::Logger::LogMethods + + attr_accessor :service, :callable_method, :outer_request, :definition + attr_accessor :request, :response, :error + + def initialize(wrapper_request) + self.error = nil + self.outer_request = wrapper_request + + init_service + if service.present? + init_method + register_rpc_failed + end + + if definition.present? + init_request + init_response + end + end + + # Call the given service method. If we get to this point and an error + # has already occurred, do not invoke the method and simply respond. + def invoke! + validate_response(callable_method.call(request, response)) unless error? + return error || response + end + + # We're successful if the error is not populated. + def success? + error.nil? + end + + # We're in error if the error is populated. + def error? + ! success? + end + + private + + def assign_error(error_klass, message) + self.error = error_klass.new(message) + end + + # Get the method for the current request. + def init_method + method_name = outer_request.method_name.underscore.to_sym + if service.rpc_method?(method_name) + self.callable_method = service.method(method_name) + self.definition = service.rpcs[method_name] + else + assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not a defined rpc method.") + end + rescue NameError => e + log_exception(e) + assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not implemented.") + end + + # Initialize the request and parse it from the bytes buffer. + def init_request + self.request = definition.request_type.new.parse_from_string(outer_request.request_proto) + rescue => e + log_exception(e) + assign_error(BadRequestProto, "Unable to parse request: #{e.message}") + end + + # Initialize an empty response for the current method. + def init_response + self.response = definition.response_type.new + end + + # Get the service for the current request. + def init_service + self.service = outer_request.service_name.constantize.new + rescue NameError => e + log_exception(e) + assign_error(ServiceNotFound, "Service class #{outer_request.service_name} is not defined.") + end + + # Make sure we get rpc errors back. + def register_rpc_failed + service.on_rpc_failed(method(:rpc_failed)) + end + + def rpc_failed(message) + assign_error(RpcFailed, (message.respond_to?(:message) ? message.message : message)) + log_error { sign_message("RPC Failed: #{error.message}") } + end + + def validate_response(object) + expected = definition.response_type + + # Cannibalize the response if it's a Hash + object = expected.new(object) if object.is_a?(Hash) + actual = object.class + log_debug { sign_message("response (should/actual): #{expected.name}/#{actual.name}") } + + # Determine if the service tried to change response types on us + if expected != actual + assign_error(BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}") + else + self.response = object + end + end + + end + end +end + diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index ab2c7950..cd0e9992 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -22,6 +22,10 @@ def client @client ? "#{@client[:ip]}:#{@client[:port]}" : nil end + def method + @method ||= @dispatcher.try(:method).try(:name) + end + def server=(peer) @server = {:port => peer[0], :ip => peer[1]} end @@ -30,6 +34,10 @@ def server @server ? "#{@server[:ip]}:#{@server[:port]}" : nil end + def service + @service ||= @dispatcher.try(:service).try(:name) + end + def sizes "#{@request_size || 0}B/#{@response_size || 0}B" end diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 5e542660..6924addd 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -5,7 +5,6 @@ before(:each) do load 'protobuf/evented.rb' ::Protobuf::Rpc::Connector.connector_for_client(true) - ::Test::ResourceService.configure(::Test::ResourceService::DEFAULT_LOCATION) end it 'runs fine when required fields are set' do diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index e2d35071..f90229c1 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -5,7 +5,6 @@ before(:each) do load 'protobuf/evented.rb' ::Protobuf::Rpc::Connector.connector_for_client(true) - ::Test::ResourceService.configure(::Test::ResourceService::DEFAULT_LOCATION) end context "when using fiber based calls" do @@ -114,6 +113,7 @@ end context 'when creating a client from a service' do + before { reset_service_location(Test::ResourceService) } it 'should be able to get a client through the Service#client helper method' do Test::ResourceService.client(:port => 9191).should eq(Protobuf::Rpc::Client.new(:service => Test::ResourceService, :port => 9191)) @@ -146,10 +146,9 @@ end it 'should have a hard default for host and port on a service that has not been configured' do - reset_service_location Test::ResourceService client = Test::ResourceService.client - client.options[:host].should eq(Protobuf::Rpc::Service::DEFAULT_LOCATION[:host]) - client.options[:port].should eq(Protobuf::Rpc::Service::DEFAULT_LOCATION[:port]) + client.options[:host].should eq(Protobuf::Rpc::Service::DEFAULT_HOST) + client.options[:port].should eq(Protobuf::Rpc::Service::DEFAULT_PORT) end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb new file mode 100644 index 00000000..8350a1a3 --- /dev/null +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -0,0 +1,94 @@ +require 'spec_helper' +require 'protobuf/rpc/service_dispatcher' + +describe Protobuf::Rpc::ServiceDispatcher do + let(:service_name) { 'Test::ResourceService' } + let(:method_name) { 'find' } + let(:request) { Test::ResourceFindRequest.new(:name => 'resource') } + let(:request_bytes) { request.to_s } + let(:response) { Test::Resource.new } + let(:wrapper) do + Protobuf::Socketrpc::Request.new({ :service_name => service_name, + :method_name => method_name, + :request_proto => request_bytes }) + + end + + subject { described_class.new(wrapper) } + + context 'creating a new dispatcher' do + its(:service) { should be_instance_of service_name.constantize } + its(:callable_method) { should be_a(Method) } + its(:outer_request) { should eq wrapper } + its(:error) { should be_nil } + + context 'when service name is not a valid constant' do + let(:service_name) { 'FlibbityGibbit' } + its(:success?) { should be_false } + its(:error) { should be_instance_of(Protobuf::Rpc::ServiceNotFound) } + end + + context 'when method is not defined by the service' do + let(:method_name) { 'holly_hooby_whaty' } + its(:success?) { should be_false } + its(:error) { should be_instance_of(Protobuf::Rpc::MethodNotFound) } + end + + context 'when method is defined but is not an rpc method' do + before do + class Test::Resource + def non_rpc_method; end + end + end + + let(:method_name) { 'non_rpc_method' } + its(:success?) { should be_false } + its(:error) { should be_instance_of(Protobuf::Rpc::MethodNotFound) } + end + end + + describe '#invoke!' do + context 'regular invocation' do + before { subject.callable_method.should_receive(:call).with(request, response).and_return(response) } + before { subject.invoke! } + its(:request) { should be_instance_of Test::ResourceFindRequest } + its(:response) { should be_instance_of Test::Resource } + its(:success?) { should be_true } + end + + context 'when service responds with' do + context 'a hash object' do + let(:returned_response) { { :name => 'returned' } } + before { subject.callable_method.should_receive(:call).and_return(returned_response) } + before { subject.invoke! } + its(:success?) { should be_true } + its(:response) { should eq Test::Resource.new(:name => 'returned') } + end + + context 'a type not identified by the rpc definition' do + let(:invalid_response) { "I'm not a valid response" } + before { subject.callable_method.should_receive(:call).and_return(invalid_response) } + before { subject.invoke! } + its(:error) { should be_instance_of(Protobuf::Rpc::BadResponseProto) } + end + end + + context 'when service invokes rpc failed callback' do + before(:all) do + class Test::ResourceService + rpc :find_with_rpc_failed, Test::ResourceFindRequest, Test::Resource + def find_with_rpc_failed(request, response) + rpc_failed('Find failed') + end + end + end + + let(:method_name) { 'find_with_rpc_failed' } + before { subject.service.find_with_rpc_failed(request, response) } + + its(:success?) { should be_false } + its(:error) { should be_instance_of(Protobuf::Rpc::RpcFailed) } + end + end + +end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 20bc6d10..5e3400d6 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -3,75 +3,142 @@ describe Protobuf::Rpc::Service do - context 'when configuring' do + context 'class methods' do + subject { Test::ResourceService } + before :each do reset_service_location Test::ResourceService end - it 'should have a default location configured' do - Test::ResourceService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host] - Test::ResourceService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port] + describe '.host' do + its(:host) { should eq described_class::DEFAULT_HOST } + end + + describe '.host=' do + before { subject.host = 'mynewhost.com' } + its(:host) { should eq 'mynewhost.com' } + end + + describe '.port' do + its(:port) { should eq described_class::DEFAULT_PORT } end - it "should be able to pre-configure a service location for clients" do - Test::ResourceService.located_at 'google.com:12345' - client = Test::ResourceService.client - client.options[:host].should == 'google.com' - client.options[:port].should == 12345 + describe '.port=' do + before { subject.port = 12345 } + its(:port) { should eq 12345 } end - context 'configuring host' do - before(:each) { Test::ResourceService.configure :host => 'somehost.com' } - after(:each) { Test::ResourceService.configure :host => '127.0.0.1' } + describe '.configure' do + context 'when providing a host' do + before { subject.configure(:host => 'mynewhost.com') } + its(:host) { should eq 'mynewhost.com' } + end - it 'should be able to configure and read the host' do - Test::ResourceService.host.should == 'somehost.com' + context 'when providing a port' do + before { subject.configure(:port => 12345) } + its(:port) { should eq 12345 } end end - it 'should be able to configure and read the port' do - Test::ResourceService.configure :port => 12345 - Test::ResourceService.port.should == 12345 + describe '.located_at' do + context 'when given location is empty' do + before { subject.located_at(nil) } + its(:host) { should eq described_class::DEFAULT_HOST } + its(:port) { should eq described_class::DEFAULT_PORT } + end + + context 'when given location is invalid' do + before { subject.located_at('i like pie') } + its(:host) { should eq described_class::DEFAULT_HOST } + its(:port) { should eq described_class::DEFAULT_PORT } + end + + context 'when given location contains a host and port' do + before { subject.located_at('mynewdomain.com:12345') } + its(:host) { should eq 'mynewdomain.com' } + its(:port) { should eq 12345 } + end end - it 'should skip configuring location if the location passed does not match host:port syntax' do - invalid_locations = [nil, 'myhost:', ':9939', 'badhost123'] - invalid_locations.each do |location| - Test::ResourceService.located_at location - Test::ResourceService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host] - Test::ResourceService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port] + describe '.client' do + it 'initializes a client object for this service' do + client = double('client') + ::Protobuf::Rpc::Client.should_receive(:new) + .with(hash_including({ :service => subject, + :host => subject.host, + :port => subject.port })) + .and_return(client) + subject.client.should eq client end end - end - context 'when server calls the service method' do + describe '.rpc' do + before { Test::ResourceService.rpc(:update, Test::ResourceFindRequest, Test::Resource) } + subject { Test::ResourceService.rpcs[:update] } + its(:method) { should eq :update } + its(:request_type) { should eq Test::ResourceFindRequest } + its(:response_type) { should eq Test::Resource } + end + + describe '.rpc_method?' do + before { Test::ResourceService.rpc(:delete, Test::Resource, Test::Resource) } - before(:all) do - class ::NewTestService < Protobuf::Rpc::Service - rpc :bad_method, Test::ResourceFindRequest, Test::Resource - rpc :bad_var, Test::ResourceFindRequest, Test::Resource - def bad_method - hash = {} - hash[:one].explode + context 'when given name is a pre-defined rpc method' do + it 'returns true' do + subject.rpc_method?(:delete).should be_true end - def bad_var - invalidvar + end + + context 'when given name is not a pre-defined rpc method' do + it 'returns false' do + subject.rpc_method?(:zoobaboo).should be_false end end end + end + + context 'instance methods' do + subject { Test::ResourceService.new } + + context 'when invoking a service call' do + before(:all) do + class ::NewTestService < Protobuf::Rpc::Service + rpc :find, Test::ResourceFindRequest, Test::Resource + def find(request, response) + response + end + + rpc :find_with_rpc_failed, Test::ResourceFindRequest, Test::Resource + def find_with_rpc_failed(request, response) + rpc_failed('This is a failed endpoint') + response.name = 'Name will still be set' + return response + end + end + end - it 'raises an undefined method name error when calling a method on a non-existant object' do - expect { - req = mock('RequestWrapper', :request_proto => Test::ResourceFindRequest.new(:name => 'mmeh').to_s) - ::NewTestService.new.bad_method(req) - }.to raise_error(NoMethodError) - end - it 'raises a name error when accessing a non-existant object' do - expect { - req = mock('RequestWrapper', :request_proto => Test::ResourceFindRequest.new(:name => 'mmeh').to_s) - ::NewTestService.new.bad_var(req) - }.to raise_error(NameError) + let(:request) do + Test::ResourceFindRequest.new(:name => 'resource') + end + + let(:response) do + Test::Resource.new + end + + subject { NewTestService.new(:find) } + specify { subject.find(request, response).should eq response } + + context 'when calling rpc_failed in the method' do + it 'invokes the rpc_failed callback with the error' do + error = nil + service = NewTestService.new(:find_with_rpc_failed) + service.on_rpc_failed(lambda { |err| error = err }) + returned_response = service.find_with_rpc_failed(request, response) + error.should eq 'This is a failed endpoint' + returned_response.name.should eq 'Name will still be set' + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 15306d86..b0416d56 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,6 +43,7 @@ def ==(other) end end -def reset_service_location service - service.instance_variable_set :@locations, nil +def reset_service_location(service) + service.host = nil + service.port = nil end diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index f1dab010..a75f2538 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -5,9 +5,10 @@ class ResourceService # request -> Test::ResourceFindRequest # response -> Test::Resource - def find + def find(request, response) response.name = request.name response.status = request.active ? 1 : 0 + return response end end From bb30ad48357387175594e622d6e3d6406056ae64 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 10 Oct 2012 21:04:29 -0600 Subject: [PATCH 0139/1191] Remove client async capabilities The async client calls are the perfect example of a cool idea built before a necessary implementation was needed. I'm removing it for now from the client API in favor of cleaner, easier to test (and refactor) code. I imagine this could make it's way back into this gem in the form of celluloid actors or similar. --- lib/protobuf/rpc/client.rb | 4 +- lib/protobuf/rpc/connectors/base.rb | 5 --- lib/protobuf/rpc/connectors/eventmachine.rb | 5 +-- lib/protobuf/rpc/connectors/socket.rb | 8 ---- lib/protobuf/rpc/connectors/zmq.rb | 8 ---- spec/benchmark/tasks.rb | 36 ++++++++--------- spec/functional/evented_server_spec.rb | 6 +-- spec/functional/socket_server_spec.rb | 6 +-- spec/functional/zmq_server_spec.rb | 6 +-- spec/lib/protobuf/rpc/client_spec.rb | 39 ++++-------------- spec/lib/protobuf/rpc/connectors/base_spec.rb | 40 +------------------ .../protobuf/rpc/connectors/socket_spec.rb | 12 ------ spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 7 +--- 13 files changed, 40 insertions(+), 142 deletions(-) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 1ccb6637..052faa8b 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -10,7 +10,7 @@ class Client extend Forwardable include Protobuf::Logger::LogMethods - delegate [:options, :complete_cb, :success_cb, :failure_cb, :async?] => :@connector + delegate [:options, :complete_cb, :success_cb, :failure_cb] => :@connector attr_reader :connector # Create a new client with default options (defined in ClientConnection) @@ -56,7 +56,6 @@ def on_complete=(callable) # Set a failure callback on the client to return the # error returned by the service, if any. If this callback # is called, success_cb will NOT be called. - # Callback is called regardless of :async setting. # # client = Client.new(:service => WidgetService) # client.on_failure {|err| ... } @@ -76,7 +75,6 @@ def on_failure=(callable) # Set a success callback on the client to return the # successful response from the service when it is returned. # If this callback is called, failure_cb will NOT be called. - # Callback is called regardless of :async setting. # # client = Client.new(:service => WidgetService) # client.on_success {|res| ... } diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 04e51f4a..e47b55ff 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -16,7 +16,6 @@ module Connectors :request => nil, # The request object sent by the client :request_type => nil, # The request type expected by the client :response_type => nil, # The response type expected by the client - :async => false, # Whether or not to block a client call, this is actually handled by client.rb :timeout => 30 # The default timeout for the request, also handled by client.rb } @@ -33,10 +32,6 @@ def initialize(options) def send_request raise 'If you inherit a Connector from Base you must implement send_request' end - - def async? - !!@options[:async] - end end end end diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb index f433c442..4a25cfec 100644 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ b/lib/protobuf/rpc/connectors/eventmachine.rb @@ -11,18 +11,17 @@ def send_request f = Fiber.current ::EM.next_tick do - log_debug { "[#{log_signature}] Scheduling EventMachine client request to be created on next tick" } log_debug { sign_message('Scheduling EventMachine client request to be created on next tick') } cnxn = EMClient.connect(options, &ensure_cb) cnxn.on_success(&success_cb) if success_cb cnxn.on_failure(&ensure_cb) - cnxn.on_complete { resume_fiber(f) } unless async? + cnxn.on_complete { resume_fiber(f) } cnxn.setup_connection cnxn.send_data log_debug { sign_message('Connection scheduled') } end - async? ? true : set_timeout_and_validate_fiber + set_timeout_and_validate_fiber end end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 33e67dfe..d613c37c 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -8,20 +8,12 @@ class Socket < Base include Protobuf::Logger::LogMethods def send_request - check_async setup_connection connect_to_rpc_server post_init read_response end - private - - def check_async - if async? - log_error { "[client-#{self.class}] Cannot run in async mode" } - raise "Cannot use Socket client in async mode" - end def log_signature @_log_signature ||= "[client-#{self.class}]" end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 82f508aa..63bb8fbf 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -8,7 +8,6 @@ class Zmq < Base include Protobuf::Logger::LogMethods def send_request - check_async setup_connection connect_to_rpc_server post_init @@ -19,13 +18,6 @@ def send_request @zmq_context = nil end - private - - def check_async - if async? - log_error { "[client-#{self.class}] Cannot run in async mode" } - raise "Cannot use Zmq client in async mode" - end def log_signature @_log_signature ||= "[client-#{self.class}]" end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index d42519c8..3b3017ea 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -4,7 +4,7 @@ require 'perftools' # Including a way to turn on debug logger for spec runs -if ENV["DEBUG"] +if ENV["DEBUG"] puts 'debugging' debug_log = File.expand_path('../debug_bench.log', File.dirname(__FILE__) ) Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) @@ -25,12 +25,12 @@ def benchmark_wrapper(global_bench = nil) def em_client_em_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? - EventMachine.fiber_run do + EventMachine.fiber_run do StubServer.new do |server| - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client benchmark_wrapper(global_bench) do |bench| - bench.report("ES / EC") do + bench.report("ES / EC") do (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end @@ -44,11 +44,11 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = ::Test::ResourceService.client(:async => false, :port => 9399) + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| + client = ::Test::ResourceService.client(:port => 9399) benchmark_wrapper(global_bench) do |bench| - bench.report("SS / EC") do + bench.report("SS / EC") do (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end @@ -63,11 +63,11 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) ::Protobuf::Rpc::Connector.connector_for_client(true) EM.stop if EM.reactor_running? - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = ::Test::ResourceService.client(:async => false, :port => 9399) + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| + client = ::Test::ResourceService.client(:port => 9399) benchmark_wrapper(global_bench) do |bench| - bench.report("SS / SC") do + bench.report("SS / SC") do (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end @@ -81,11 +81,11 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) em_thread = Thread.new { EM.run } Thread.pass until EM.reactor_running? - StubServer.new(:port => 9399) do |server| - client = ::Test::ResourceService.client(:async => false, :port => 9399) + StubServer.new(:port => 9399) do |server| + client = ::Test::ResourceService.client(:port => 9399) benchmark_wrapper(global_bench) do |bench| - bench.report("ES / SC") do + bench.report("ES / SC") do (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end @@ -98,11 +98,11 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" ::Protobuf::Rpc::Connector.connector_for_client(true) - StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - client = ::Test::ResourceService.client(:async => false, :port => 9399) + StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| + client = ::Test::ResourceService.client(:port => 9399) benchmark_wrapper(global_bench) do |bench| - bench.report("ZS / ZC") do + bench.report("ZS / ZC") do (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end @@ -119,7 +119,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) desc "benchmark ZMQ client with ZMQ server and profile" task :zmq_profile, [:number, :length, :profile_output] do |t, args| args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}") - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + ::PerfTools::CpuProfiler.start(args[:profile_output]) do zmq_client_zmq_server(args[:number], args[:length]) end @@ -130,7 +130,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) task :profile_protobuf_new, [:number, :profile_output] do |t, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + ::PerfTools::CpuProfiler.start(args[:profile_output]) do args[:number].to_i.times { Test::Resource.new(create_params) } end diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 6924addd..81309c87 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -11,7 +11,7 @@ expect { EventMachine.fiber_run do StubServer.new do |server| - client = ::Test::ResourceService.client(:async => false, :timeout => 5) + client = ::Test::ResourceService.client(:timeout => 5) client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| @@ -34,7 +34,7 @@ EventMachine.fiber_run do StubServer.new do |server| request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(request) do |c| c.on_success { raise "shouldn't pass"} @@ -51,7 +51,7 @@ EventMachine.fiber_run do StubServer.new do |server| request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(request) do |c| c.on_success { raise "shouldn't pass"} diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 081cb43e..a7b5aa5f 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -18,7 +18,7 @@ it 'runs fine when required fields are set' do expect { - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| @@ -36,7 +36,7 @@ it 'calls the on_failure callback when a message is malformed' do error = nil request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(request) do |c| c.on_success { raise "shouldn't pass"} @@ -48,7 +48,7 @@ it 'calls the on_failure callback when the request type is wrong' do error = nil request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(request) do |c| c.on_success { raise "shouldn't pass"} diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 45c36dc8..a8ef3f24 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -18,7 +18,7 @@ it 'runs fine when required fields are set' do expect { - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| @@ -36,7 +36,7 @@ it 'calls the on_failure callback when a message is malformed' do error = nil request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(request) do |c| c.on_success { raise "shouldn't pass"} @@ -48,7 +48,7 @@ it 'calls the on_failure callback when the request type is wrong' do error = nil request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client(:async => false) + client = ::Test::ResourceService.client client.find(request) do |c| c.on_success { raise "shouldn't pass"} diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index f90229c1..32964f39 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -8,10 +8,10 @@ end context "when using fiber based calls" do - it "waits for response when running synchronously" do + it "waits for response" do EventMachine.fiber_run do StubServer.new(:delay => 3) do |server| - client = Test::ResourceService.client(:async => false) + client = Test::ResourceService.client start = now client.find(:name => "Test Name", :active => true) do |c| @@ -32,24 +32,11 @@ end end - it "doesn't wait for response when running async call inside fiber" do - EventMachine.fiber_run do - StubServer.new(:delay => 3) do |server| - client = Test::ResourceService.client(:async => true) - start = now - client.find(:name => "Test Name", :active => true) - - (now - start).should_not be_within(server.options.delay* 0.10).of(server.options.delay) - end - EM.stop - end - end - - it "throws and error when synchronous code is attempted without 'EventMachine.fiber_run'" do + it "throws and error when call is attempted without 'EventMachine.fiber_run'" do subject = Proc.new do EventMachine.run do StubServer.new(:delay => 1) do |server| - client = Test::ResourceService.client(:async => false) + client = Test::ResourceService.client client.find(:name => "Test Name", :active => true) end end @@ -63,7 +50,7 @@ test_proc = Proc.new do EventMachine.fiber_run do StubServer.new(:delay => 2) do |server| - client = Test::ResourceService.client(:async => false, :timeout => 1) + client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) do |cl| cl.on_success {} cl.on_failure {|f| error = f} @@ -82,7 +69,7 @@ it "throws a timeout when client timeout is exceeded" do subject = Proc.new do StubServer.new(:delay => 2) do |server| - client = Test::ResourceService.client(:async => false, :timeout => 1) + client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) end end @@ -95,7 +82,7 @@ subject = Proc.new do StubServer.new(:delay => 2) do |server| - client = Test::ResourceService.client(:async => false, :timeout => 1) + client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) do |c| c.on_failure do |f| failure_message = f.message @@ -130,16 +117,6 @@ updated_client.options[:port].should eq(54321) end - it 'should be able to define the syncronicity of the client request' do - client = Test::ResourceService.client(:async => false) - client.options[:async].should be_false - client.async?.should be_false - - client = Test::ResourceService.client(:async => true) - client.options[:async].should be_true - client.async?.should be_true - end - it 'should be able to define which service to create itself for' do client = Protobuf::Rpc::Client.new :service => Test::ResourceService client.options[:service].should eq(Test::ResourceService) @@ -172,7 +149,7 @@ it 'should be able to set and get local variables within client response blocks' do outer_value = 'OUTER' inner_value = 'INNER' - client = Test::ResourceService.client(:async => true) + client = Test::ResourceService.client EM.should_receive(:reactor_running?).and_return(true) EM.stub!(:next_tick) do diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 642923d2..693899fe 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -3,7 +3,7 @@ describe Protobuf::Rpc::Connectors::Base do let(:opts) do - { async: false, timeout: 60 } + { :timeout => 60 } end subject { Protobuf::Rpc::Connectors::Base.new(opts) } @@ -47,42 +47,4 @@ end end - describe '#async?' do - context 'when provided options[:async] is false' do - let(:opts) do - { async: false, timeout: 60 } - end - - subject { Protobuf::Rpc::Connectors::Base.new(opts) } - - it 'returns false' do - subject.async?.should be_false - end - end - - context 'when provided options[:async] is true' do - let(:opts) do - { async: true, timeout: 60 } - end - - subject { Protobuf::Rpc::Connectors::Base.new(opts) } - - it 'returns true' do - subject.async?.should be_true - end - end - - context 'when options doesn\'t denote async' do - let(:opts) do - { timeout: 60 } - end - - subject { Protobuf::Rpc::Connectors::Base.new(opts) } - - it 'returns false' do - subject.async?.should be_false - end - end - end - end diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 2fd7c16b..131d274a 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -33,16 +33,4 @@ subject.instance_variable_get(:@response_data).should eq(data) end end - - context "#check_async" do - it "raises an error when trying to execute asynchronously" do - conn = described_class.new(:async => true) - expect{ conn.__send__(:check_async) }.to raise_error - end - - it "allows execution when synchronous" do - conn = described_class.new(:async => false) - expect{ conn.__send__(:check_async) }.to_not raise_error - end - end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 2c8e3f0d..eeca9fc8 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -18,10 +18,5 @@ ::ZMQ::Context.stub(:new).and_return(zmq_context_mock) end - it 'raises if async is true' do - expect { - described_class.new(async: true).send_request - }.to raise_error - end - + pending end From dbefcdf1d1ab118592b6b061c1a91df89f4568ff Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 11 Oct 2012 09:53:31 -0600 Subject: [PATCH 0140/1191] Fix stat method/service integration with service dispatcher --- lib/protobuf/rpc/stat.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index cd0e9992..47e50400 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -23,7 +23,7 @@ def client end def method - @method ||= @dispatcher.try(:method).try(:name) + @method ||= @dispatcher.try(:callable_method).try(:name) end def server=(peer) @@ -35,7 +35,7 @@ def server end def service - @service ||= @dispatcher.try(:service).try(:name) + @service ||= @dispatcher.try(:service).class.name end def sizes From 6d30d17170e8503a5be071efb209bdd7cf6fda28 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 11 Oct 2012 09:53:57 -0600 Subject: [PATCH 0141/1191] Remove (failing) test that is verifying ruby blocks behavior --- spec/lib/protobuf/rpc/client_spec.rb | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 32964f39..57cdfb24 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -141,30 +141,6 @@ client.should_receive(:send_request).and_return(nil) expect { client.find(nil) }.to_not raise_error end - - it 'raises a NameError when accessing a var that does not exist' do - pending - end - - it 'should be able to set and get local variables within client response blocks' do - outer_value = 'OUTER' - inner_value = 'INNER' - client = Test::ResourceService.client - - EM.should_receive(:reactor_running?).and_return(true) - EM.stub!(:next_tick) do - client.success_cb.call(inner_value) - end - - client.find(nil) do |c| - c.on_success do |response| - outer_value.should eq('OUTER') - outer_value = response - end - end - outer_value.should eq(inner_value) - end - end context 'when receiving request objects' do From cea573a1a7de2c3ff0b6149a633da7cc15a448f3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 15 Oct 2012 11:37:50 -0600 Subject: [PATCH 0142/1191] Change back to implicit request/response service objects When the ServiceDispatcher was introduced I added an explicit approach to request and response objects; both must be given and the response object must be explicitly returned from the method. While it made sense programmatically it just doesn't feel "ruby-ish". Here are some of the changes I've made to get back to a simpler approach: * Service class is given the name of the method the dispatcher will invoke and the request bytes. * Service#request and Service#response are lazily loaded objects of the appropriate type for the given rpc method. * Service#request deserializes the given bytes. * Service#respond_with provides sugar for assigning the response to a different object. * Privateized several service methods that should not be externally accessobile (e.g. respond_with, rpc_failed, request) * ServiceDispatcher no longer deals with setting up the types for request response. * ServiceDispatcher is still responsible for type checking/coercion of the response object. I believe the addition of `respond_with` in addition to implicit request/response objects solves the old issue where you had to use `self.response=` to overwrite the response. It also gives this more of a rails-style controller feel. --- lib/protobuf/rpc/service.rb | 41 +++++++++-- lib/protobuf/rpc/service_dispatcher.rb | 69 +++++++++---------- .../protobuf/rpc/service_dispatcher_spec.rb | 16 ++--- spec/lib/protobuf/rpc/service_spec.rb | 46 +++++++++---- spec/support/test/resource_service.rb | 3 +- 5 files changed, 113 insertions(+), 62 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 04cd6d3e..129dcefc 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -11,6 +11,8 @@ module Rpc class Service include Protobuf::Logger::LogMethods + attr_reader :response + DEFAULT_HOST = '127.0.0.1'.freeze DEFAULT_PORT = 9399 @@ -97,16 +99,23 @@ def self.rpc_method?(name) # Instance Methods # + # Initialize a service with the rpc endpoint name and the bytes + # for the request. + def initialize(rpc, request_bytes) + @rpc = rpc + @request_bytes = request_bytes + end + # Register a failure callback for use when rpc_failed is invoked. # def on_rpc_failed(callable) - @rpc_failed_callback = callable + @rpc_failed_callback ||= callable end - # Automatically fail a service method. + # Response object for this rpc cycle. Not assignable. # - def rpc_failed(message) - @rpc_failed_callback.call(message) + def response + @_response ||= rpcs[@rpc].response_type.new end # Convenience method to get back to class method. @@ -121,6 +130,30 @@ def rpcs self.class.rpcs end + private + + # Request object for this rpc cycle. Not assignable. + # + def request + @_request ||= rpcs[@rpc].request_type.new.parse_from_string(@request_bytes) + rescue => e + raise BadRequestProto, "Unable to parse request: #{e.message}" + end + + # Sugar to make an rpc method feel like a controller method. + # If this method is not called, the response will be the memoized + # object returned by the response reader. + # + def respond_with(candidate) + @_response = candidate + end + + # Automatically fail a service method. + # + def rpc_failed(message) + @rpc_failed_callback.call(message) + end + end end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index a322f4cb..a7bf54c1 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -6,38 +6,38 @@ class ServiceDispatcher include ::Protobuf::Logger::LogMethods - attr_accessor :service, :callable_method, :outer_request, :definition - attr_accessor :request, :response, :error + attr_accessor :service, :service_klass, :callable_method, :outer_request + attr_accessor :definition, :response, :error def initialize(wrapper_request) self.error = nil self.outer_request = wrapper_request init_service - if service.present? - init_method - register_rpc_failed - end - - if definition.present? - init_request - init_response - end + init_method if service_klass.present? + register_rpc_failed if service.present? end # Call the given service method. If we get to this point and an error # has already occurred, do not invoke the method and simply respond. + # def invoke! - validate_response(callable_method.call(request, response)) unless error? + unless error? + callable_method.call + validate_response + end + return error || response end # We're successful if the error is not populated. + # def success? error.nil? end # We're in error if the error is populated. + # def error? ! success? end @@ -49,9 +49,11 @@ def assign_error(error_klass, message) end # Get the method for the current request. + # def init_method method_name = outer_request.method_name.underscore.to_sym - if service.rpc_method?(method_name) + if service_klass.rpc_method?(method_name) + self.service = service_klass.new(method_name, outer_request.request_proto) self.callable_method = service.method(method_name) self.definition = service.rpcs[method_name] else @@ -62,50 +64,47 @@ def init_method assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not implemented.") end - # Initialize the request and parse it from the bytes buffer. - def init_request - self.request = definition.request_type.new.parse_from_string(outer_request.request_proto) - rescue => e - log_exception(e) - assign_error(BadRequestProto, "Unable to parse request: #{e.message}") - end - - # Initialize an empty response for the current method. - def init_response - self.response = definition.response_type.new - end - - # Get the service for the current request. + # Constantize the service for this request. Initialization of the service + # happens when we verify that the method is callable for this service. + # def init_service - self.service = outer_request.service_name.constantize.new + self.service_klass = outer_request.service_name.constantize rescue NameError => e log_exception(e) assign_error(ServiceNotFound, "Service class #{outer_request.service_name} is not defined.") end # Make sure we get rpc errors back. + # def register_rpc_failed - service.on_rpc_failed(method(:rpc_failed)) + service.on_rpc_failed(method(:rpc_failed_callback)) end - def rpc_failed(message) + # Receive the failure message from the service. This method is registered + # as the callable to the service when an `rpc_failed` call is invoked. + # + def rpc_failed_callback(message) assign_error(RpcFailed, (message.respond_to?(:message) ? message.message : message)) log_error { sign_message("RPC Failed: #{error.message}") } end - def validate_response(object) + # Ensure that the response candidate we've been given is of the type + # we expect so that deserialization on the client side works. + # + def validate_response expected = definition.response_type - # Cannibalize the response if it's a Hash - object = expected.new(object) if object.is_a?(Hash) - actual = object.class + candidate = service.response + candidate = expected.new(candidate) if candidate.is_a?(Hash) + + actual = candidate.class log_debug { sign_message("response (should/actual): #{expected.name}/#{actual.name}") } # Determine if the service tried to change response types on us if expected != actual assign_error(BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}") else - self.response = object + self.response = candidate end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 8350a1a3..a7a811db 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -49,25 +49,25 @@ def non_rpc_method; end describe '#invoke!' do context 'regular invocation' do - before { subject.callable_method.should_receive(:call).with(request, response).and_return(response) } + before { subject.callable_method.should_receive(:call) } + before { subject.service.stub(:response).and_return(response) } before { subject.invoke! } - its(:request) { should be_instance_of Test::ResourceFindRequest } its(:response) { should be_instance_of Test::Resource } its(:success?) { should be_true } end context 'when service responds with' do context 'a hash object' do - let(:returned_response) { { :name => 'returned' } } - before { subject.callable_method.should_receive(:call).and_return(returned_response) } + before { subject.callable_method.should_receive(:call) } + before { subject.service.stub(:response).and_return({ :name => 'returned' }) } before { subject.invoke! } its(:success?) { should be_true } its(:response) { should eq Test::Resource.new(:name => 'returned') } end context 'a type not identified by the rpc definition' do - let(:invalid_response) { "I'm not a valid response" } - before { subject.callable_method.should_receive(:call).and_return(invalid_response) } + before { subject.callable_method.should_receive(:call) } + before { subject.service.stub(:response).and_return("I'm not a valid response") } before { subject.invoke! } its(:error) { should be_instance_of(Protobuf::Rpc::BadResponseProto) } end @@ -77,14 +77,14 @@ def non_rpc_method; end before(:all) do class Test::ResourceService rpc :find_with_rpc_failed, Test::ResourceFindRequest, Test::Resource - def find_with_rpc_failed(request, response) + def find_with_rpc_failed rpc_failed('Find failed') end end end let(:method_name) { 'find_with_rpc_failed' } - before { subject.service.find_with_rpc_failed(request, response) } + before { subject.service.find_with_rpc_failed } its(:success?) { should be_false } its(:error) { should be_instance_of(Protobuf::Rpc::RpcFailed) } diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 5e3400d6..b7be4d18 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -98,21 +98,24 @@ end context 'instance methods' do - subject { Test::ResourceService.new } - context 'when invoking a service call' do before(:all) do class ::NewTestService < Protobuf::Rpc::Service - rpc :find, Test::ResourceFindRequest, Test::Resource - def find(request, response) - response + rpc :find_with_implied_response, Test::ResourceFindRequest, Test::Resource + def find_with_implied_response + response.name = 'Implicit response' + end + + rpc :find_with_respond_with, Test::ResourceFindRequest, Test::Resource + def find_with_respond_with + custom = Test::Resource.new(:name => 'Custom response') + respond_with(custom) end rpc :find_with_rpc_failed, Test::ResourceFindRequest, Test::Resource - def find_with_rpc_failed(request, response) + def find_with_rpc_failed rpc_failed('This is a failed endpoint') response.name = 'Name will still be set' - return response end end end @@ -126,17 +129,34 @@ def find_with_rpc_failed(request, response) Test::Resource.new end - subject { NewTestService.new(:find) } - specify { subject.find(request, response).should eq response } + + context 'when calling the rpc method' do + context 'when response is implied' do + subject { NewTestService.new(:find_with_implied_response, request.serialize_to_string) } + + before { subject.find_with_implied_response } + its(:response) { should be_a(Test::Resource) } + specify { subject.response.name.should eq 'Implicit response' } + end + + context 'when using respond_with paradigm' do + subject { NewTestService.new(:find_with_respond_with, request.serialize_to_string) } + + before { subject.find_with_respond_with } + its(:response) { should be_a(Test::Resource) } + specify { subject.response.name.should eq 'Custom response' } + end + end context 'when calling rpc_failed in the method' do + subject { NewTestService.new(:find_with_rpc_failed, request.serialize_to_string) } + it 'invokes the rpc_failed callback with the error' do error = nil - service = NewTestService.new(:find_with_rpc_failed) - service.on_rpc_failed(lambda { |err| error = err }) - returned_response = service.find_with_rpc_failed(request, response) + subject.on_rpc_failed(lambda { |err| error = err }) + subject.find_with_rpc_failed error.should eq 'This is a failed endpoint' - returned_response.name.should eq 'Name will still be set' + subject.response.name.should eq 'Name will still be set' end end end diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index a75f2538..f1dab010 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -5,10 +5,9 @@ class ResourceService # request -> Test::ResourceFindRequest # response -> Test::Resource - def find(request, response) + def find response.name = request.name response.status = request.active ? 1 : 0 - return response end end From a62ce79a3cd592e6f05aaf89dc91dcf99868bb2e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 15 Oct 2012 11:53:41 -0600 Subject: [PATCH 0143/1191] Gobify Service#respond_with --- lib/protobuf/rpc/service.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 129dcefc..3bb8559a 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -147,6 +147,7 @@ def request def respond_with(candidate) @_response = candidate end + alias_method :return_from_whence_you_came, :respond_with # Automatically fail a service method. # From 887d3e831c666ae469b8aaae727fd4a10232ee52 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 15 Oct 2012 12:02:52 -0600 Subject: [PATCH 0144/1191] Use bracket notation instead of #delete on Service.configure --- lib/protobuf/rpc/service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 3bb8559a..46235eb7 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -36,8 +36,8 @@ def self.client(options = {}) # will not have to configure the location each time. # def self.configure(config = {}) - self.host = config.delete(:host) if config.key?(:host) - self.port = config.delete(:port) if config.key?(:port) + self.host = config[:host] if config.key?(:host) + self.port = config[:port] if config.key?(:port) end # The host location of the service. From b6a15d405ae10a7917027fa1f9ff8f36f7b94e3d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 15 Oct 2012 14:31:18 -0600 Subject: [PATCH 0145/1191] Bump version 2.0.0.rc4 --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8427bc36..f5a1f84a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (2.0.0.rc3) + protobuf (2.0.0.rc4) activesupport ffi multi_json diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 81ec2c08..4972ab0e 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.0.rc3' + VERSION = '2.0.0.rc4' PROTOC_VERSION = '2.4.1' end From a71393bf36b55e14283607594e4717a18df99295 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 15 Oct 2012 22:15:38 -0600 Subject: [PATCH 0146/1191] Add to_proto and to_hash type coercion to service dispatcher response handling --- lib/protobuf/rpc/service_dispatcher.rb | 29 +++++++++++++------ .../protobuf/rpc/service_dispatcher_spec.rb | 22 ++++++++++++++ spec/lib/protobuf/rpc/service_spec.rb | 1 - 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index a7bf54c1..d02eadcf 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -48,6 +48,22 @@ def assign_error(error_klass, message) self.error = error_klass.new(message) end + # Prod the object to see if we can produce a proto object as a response + # candidate. Either way, return the candidate for validation. + def coerced_response + candidate = service.response + + if candidate.is_a?(Hash) + candidate = definition.response_type.new(candidate) + elsif candidate.respond_to?(:to_hash) + candidate = definition.response_type.new(candidate.to_hash) + elsif candidate.respond_to?(:to_proto) + candidate = candidate.to_proto + end + + candidate + end + # Get the method for the current request. # def init_method @@ -92,19 +108,14 @@ def rpc_failed_callback(message) # we expect so that deserialization on the client side works. # def validate_response + candidate = coerced_response expected = definition.response_type - - candidate = service.response - candidate = expected.new(candidate) if candidate.is_a?(Hash) - actual = candidate.class - log_debug { sign_message("response (should/actual): #{expected.name}/#{actual.name}") } - # Determine if the service tried to change response types on us - if expected != actual - assign_error(BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}") - else + if expected == actual self.response = candidate + else + assign_error(BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}") end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index a7a811db..5556ce77 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -65,6 +65,28 @@ def non_rpc_method; end its(:response) { should eq Test::Resource.new(:name => 'returned') } end + context 'an object that responds to to_hash but is not a hash' do + let(:hashable) do + mock('hashable', :to_hash => { :name => 'hashable' }) + end + before { subject.callable_method.should_receive(:call) } + before { subject.service.stub(:response).and_return(hashable) } + before { subject.invoke! } + its(:success?) { should be_true } + its(:response) { should eq Test::Resource.new(:name => 'hashable') } + end + + context 'an object that responds to to_proto' do + let(:protoable) do + mock('protoable', :to_proto => Test::Resource.new(:name => 'protoable')) + end + before { subject.callable_method.should_receive(:call) } + before { subject.service.stub(:response).and_return(protoable) } + before { subject.invoke! } + its(:success?) { should be_true } + its(:response) { should eq Test::Resource.new(:name => 'protoable') } + end + context 'a type not identified by the rpc definition' do before { subject.callable_method.should_receive(:call) } before { subject.service.stub(:response).and_return("I'm not a valid response") } diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index b7be4d18..b3f4952f 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -129,7 +129,6 @@ def find_with_rpc_failed Test::Resource.new end - context 'when calling the rpc method' do context 'when response is implied' do subject { NewTestService.new(:find_with_implied_response, request.serialize_to_string) } From c419f0c91e0ac8dbd6cfddd4cc42416b815a3bbb Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 15 Oct 2012 22:23:29 -0600 Subject: [PATCH 0147/1191] Bump version 2.0.0.rc5 --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f5a1f84a..cbcf74bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (2.0.0.rc4) + protobuf (2.0.0.rc5) activesupport ffi multi_json diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 4972ab0e..274f8681 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.0.rc4' + VERSION = '2.0.0.rc5' PROTOC_VERSION = '2.4.1' end From 818cb5c26f62be16958f5695caf648178e94abcc Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 22 Oct 2012 11:18:37 -0600 Subject: [PATCH 0148/1191] Fix options passed from cli to runners --- lib/protobuf/cli.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index b725611a..20e92700 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -20,6 +20,7 @@ class CLI < ::Thor option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.' option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' + option :threads, :type => :numeric, :default => 5, :aliases => %w(-r), :desc => 'Number of worker threads to run. Only applicable in --zmq mode.' option :log, :type => :string, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' 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/)' @@ -33,6 +34,7 @@ class CLI < ::Thor option :print_deprecation_warnings, :type => :boolean, :default => true, :desc => 'Cause use of deprecated fields to be printed or ignored.' def start(app_file) + puts 'RUNNING FROM LOCAL' debug_say 'Configuring the rpc_server process' @start_aborted = false @@ -153,6 +155,14 @@ def run_if_no_abort yield unless @start_aborted end + def runner_options + { :host => options.host, + :port => options.port, + :backlog => options.backlog, + :treshold => options.threshold, + :threads => options.threads } + end + def say_and_exit!(message, exception = nil) message = set_color(message, :red) if ::Protobuf::Logger.file == STDOUT @@ -168,7 +178,7 @@ def say_and_exit!(message, exception = nil) # Start the runner and log the relevant options. def start_server! debug_say 'Invoking server start' - @runner.run(options.dup) do + @runner.run(runner_options) do Protobuf::Logger.info { "pid #{::Process.pid} -- #{@mode} RPC Server listening at #{options.host}:#{options.port}" } end end From d49de3565b14c74943689f929e513c08dbf2adfd Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 22 Oct 2012 11:19:14 -0600 Subject: [PATCH 0149/1191] Bump version 2.0.0.rc6 --- Gemfile.lock | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index cbcf74bb..2a8cd1d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - protobuf (2.0.0.rc5) + protobuf (2.0.0.rc6) activesupport ffi multi_json diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 274f8681..7e3cca4b 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.0.rc5' + VERSION = '2.0.0.rc6' PROTOC_VERSION = '2.4.1' end From d363614571f9a8023f1fc83a195cfa172c360619 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 22 Oct 2012 15:43:54 -0600 Subject: [PATCH 0150/1191] Remove defunct mk_parser script --- script/mk_parser | 2 -- 1 file changed, 2 deletions(-) delete mode 100755 script/mk_parser diff --git a/script/mk_parser b/script/mk_parser deleted file mode 100755 index 2b4a25e5..00000000 --- a/script/mk_parser +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -racc -E lib/protobuf/compiler/proto.y -o lib/protobuf/compiler/proto_parser.rb From 0c1eccdba1671193cf32bc1d512f048c2041f051 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 23 Oct 2012 10:13:01 -0600 Subject: [PATCH 0151/1191] Bump to version 2.0.0! Let the celebrations begin --- Gemfile.lock | 65 ----------------------------------------- lib/protobuf/version.rb | 2 +- protobuf.gemspec | 8 ++--- 3 files changed, 5 insertions(+), 70 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 2a8cd1d6..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,65 +0,0 @@ -PATH - remote: . - specs: - protobuf (2.0.0.rc6) - activesupport - ffi - multi_json - thor - -GEM - remote: http://rubygems.org/ - specs: - activesupport (3.2.8) - i18n (~> 0.6) - multi_json (~> 1.0) - coderay (1.0.7) - diff-lcs (1.1.3) - eventmachine (1.0.0) - ffi (1.1.5) - ffi-rzmq (0.9.6) - ffi - i18n (0.6.1) - method_source (0.8) - multi_json (1.3.6) - perftools.rb (2.0.0) - pry (0.9.10) - coderay (~> 1.0.5) - method_source (~> 0.8) - slop (~> 3.3.1) - pry-nav (0.2.2) - pry (~> 0.9.10) - rake (0.9.2.2) - rake-compiler (0.8.1) - rake - rspec (2.11.0) - rspec-core (~> 2.11.0) - rspec-expectations (~> 2.11.0) - rspec-mocks (~> 2.11.0) - rspec-core (2.11.1) - rspec-expectations (2.11.3) - diff-lcs (~> 1.1.3) - rspec-mocks (2.11.3) - simplecov (0.6.4) - multi_json (~> 1.0) - simplecov-html (~> 0.5.3) - simplecov-html (0.5.3) - slop (3.3.3) - thor (0.16.0) - yard (0.8.2.1) - -PLATFORMS - ruby - -DEPENDENCIES - eventmachine - ffi-rzmq - perftools.rb - protobuf! - pry - pry-nav - rake - rake-compiler - rspec - simplecov - yard diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 7e3cca4b..afab7181 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.0.rc6' + VERSION = '2.0.0' PROTOC_VERSION = '2.4.1' end diff --git a/protobuf.gemspec b/protobuf.gemspec index b0201813..acd4c1b3 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -8,10 +8,10 @@ Gem::Specification.new do |s| s.date = Time.now.strftime('%Y-%m-%d') s.authors = ['BJ Neilsen', 'Brandon Dewitt'] - s.email = ["bj.neilsen@gmail.com", "brandonsdewitt+protobuf@gmail.com"] - s.homepage = %q{https://github.com/localshred/protobuf} - s.summary = 'Ruby implementation for Protocol Buffers. Works with other protobuf rpc implementations (e.g. Java, Python, C++).' - s.description = s.summary + "\n\nThis gem has diverged from https://github.com/macks/ruby-protobuf. All credit for serialization and rprotoc work most certainly goes to the original authors. All RPC implementation code (client/server/service) was written and is maintained by this author. Attempts to reconcile the original codebase with the current RPC implementation went unsuccessful." + s.email = ["bj.neilsen+protobuf@gmail.com", "brandonsdewitt+protobuf@gmail.com"] + s.homepage = "https://github.com/localshred/protobuf" + s.summary = "Google Protocol Buffers v#{Protobuf::PROTOC_VERSION} Serialization and RPC implementation for Ruby." + s.description = s.summary s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From b78b3ee596248dde02c69dfae01073b8f135ae9a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 25 Oct 2012 11:36:23 -0600 Subject: [PATCH 0152/1191] Added UPGRADING.md file to aid in transition from 1.4.2 to 2.0 --- UPGRADING.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 UPGRADING.md diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 00000000..6bf87bd2 --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,60 @@ +# Upgrading from 1.X to 2.0 + +I'm sure I'm missing quite a few of the smaller changes that have been made, but here is a list of changes that should affect any external programs or applications using `protobuf`. + +## `rprotoc` changes + +* New option `--ruby_out` to specify the output directory to place generated ruby files. If not provided, ruby code will not be generated. +* Extends `libprotoc` to hook in directly to google's provided compiler mechanism. +* Removed all previous compiler code including the racc parser, node visitors, etc. +* See `protoc --help` for default options. + +## `rprotoc` generated files changes + +* Import `require`s now occur outside of any module or class declaration which solves ruby vm warnings previously seen. +* Empty inherited Message and Enum classes are pre-defined in the file, then reopened and their fields applied. This solves the issue of recursive field dependencies of two or more types in the same file. +* Generated DSL lines for message fields include the fully qualified name of the type (e.g. optional `::Protobuf::Field::StringField`, :name, 1) +* Support for any combination of `packed`, `deprecated`, and `default` as options to pass to a field definition. +* Services are now generated in the corresponding `.pb.rb` file instead of their own `*_service.rb` files as before. + +## `rpc_server` changes + +* Removed `--env` option. The running application or program is solely in charge of ensuring it's environment is properly loaded. +* Removed reading of `PB_CLIENT_TYPE`, `PB_SERVER_TYPE` environment variables. Should use mode switches or custom requires (see below) instead. +* Removed `--client_socket` in favor of using mode switches. This also means client calls made by the `rpc_server` will run as the same connector type as the given mode (socket, zmq, or evented). +* Removed `--pre-cache-definitions` switch in favor of always pre-caching for performance. +* Removed `--gc-pause-serialization` since using `--gc-pause-request` in conjunction was redundant. +* Removed `--client-type` in favor of mode switches. +* Removed `--server-type` in favor of mode switches. +* Added mode switch `--evented`. +* Added `--threads` to specify number of ZMQ Worker threads to use. Ignored if mode is not zmq. +* Added `--print-deprecation-warnings` switch to tell the server whether or not to print deprecation warnings on field usage. Enabled by default. +* See `rpc_server help start` for all options and usage. Note: the `start` task is the default and not necessary when running the `rpc_server`. + +## Message changes + +* `Message#get_field` usage should now specify either `Message#get_field_by_name` or `Message#get_field_by_tag`, depending on your lookup criteria. +* Support for STDERR output when accessing a message field which has been defined as `[deprecated=true]`. Deprecated warnings can be skipped by running your application or program with `PB_IGNORE_DEPRECATIONS=1`. +* Significant internal refactoring which provides huge boosts in speed and efficiency both in accessing/writing Message field values, as well as serialization and deserialization routines. +* Refactor `Message#to_hash` to delegate hash representations to the field values, simply collecting the display values and returning a hash of fields that are set. This also affects `to_json` output. + +## Enum changes + +* Add `Enum.fetch` class method to polymorphically retrieve an `EnumValue` object. +* Add `Enum.value_by_name` to retrieve the corresponding `EnumValue` to the given symbol name. +* Add `Enum.enum_by_value` to retrieve the corresponding `EnumValue` to the given integer value. + +## RPC Service changes + +* `async_responder` paradigm is no longer supported. +* `self.response=` paradigm should be converted to using `respond_with(object)`. +* Significant internal changes that should not bleed beyond the API but which make maintaining the code much easier. + +## RPC Client changes + +* In the absence of `PB_CLIENT_TYPE` environment var, you should be requiring the specific connector type specifically. For instance, if you wish to run in zmq mode for client requests, update your Gemfile: `gem 'protobuf', :require => 'protobuf/zmq'`. +* `:async` option on client calls is no longer recognized. + +## Other changes + +* Moved files out of `lib/protobuf/common` folder into `lib/protobuf`. Files affected are logger, wire_type, util. The only update would need to be the require path to these files since the modules were always `Protobuf::{TYPE}`. From c9f9e2c0ecf13f27d52ed79f9df702880fcc3773 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 25 Oct 2012 12:21:05 -0600 Subject: [PATCH 0153/1191] Update readme to be compliant with changes in 2.0 --- README.md | 127 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index ea7f11fc..1cede2ab 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,23 @@ # protobuf -Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. It's a gem for managing 3 things: +***IMPORTANT: Those upgrading from version 1.4.2 to 2.0 should read the [UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes*** -1. Compiling `.proto` definitions to ruby -2. Provide a Socket-RPC mechanism for calling services -3. Provide RPC interop between ruby and other protobuf-rpc aware implementations for different languages (e.g. [protobuf-socket-rpc][]) +Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. We currently support version 2.4.0. It's a gem for managing 3 things: + +1. Generating ruby classes from `.proto` files. +2. Provide an RPC mechanism for calling remote services. +3. Provide RPC interop between ruby and other protobuf-rpc aware implementations for different languages (e.g. [protobuf-socket-rpc][]). So let's dive in and see how to work with all three. -## 1. Compile `.proto` definitions to ruby +## 1. Generating ruby classes from `.proto` files Protocol Buffers are great because they allow you to clearly define data storage or data transfer packets. Google officially supports Java, C++, and Python for compilation and usage. Let's make it ruby aware! Let's say you have a `defs.proto` file that defines a User message. ``` -package mycompany; +package foo; message User { required string first_name = 1; required string last_name = 1; @@ -23,21 +25,23 @@ message User { Now let's compile that definition to ruby: -$ rprotoc defs.proto -o ./lib +$ rprotoc defs.proto --ruby_out ./lib ``` -The previous line will take whatever is defined in defs.proto and output ruby classes to the `./lib` directory, obeying the package directive. Assuming that's all defs.proto had defined, `./lib` should now look like this: +The previous line will take whatever is defined in `defs.proto` and output ruby classes to the `./lib` directory, obeying the package directive. Assuming that's all `defs.proto` had defined, `./lib` should now look like this: ``` - lib - |- mycompany + |- foo |- defs.pb.rb ``` -And `defs.pb.rb` should look like this: +The generated file `defs.pb.rb` should look something like this: ```ruby -module Mycompany +module Foo + class User < ::Protobuf::Message; end + class User required :string, :first_name, 1 required :string, :last_name, 2 @@ -45,26 +49,41 @@ module Mycompany end ``` -You can then use that class just like normal: +_Note: The generator will pre-define all the classes empty and then re-open to apply the defined fields. This is an optomization to prevent recursive field errors._ + +The generated class is now just a plain old ruby object and you can use it however you wish. ```ruby -require 'lib/mycompany/user.pb' +require 'lib/foo/user.pb' # dot notation reading/writing fields -user = Mycompany::User.new +user = Foo::User.new user.first_name = "Lloyd" user.last_name = "Christmas" user.first_name # => "Lloyd" # or pass in the fields as a hash to the initializer -user = Mycompany::User.new :first_name => "Lloyd", :last_name => "Christmas" +user = Foo::User.new :first_name => "Lloyd", :last_name => "Christmas" user.first_name # => Lloyd user.last_name # => Christmas ``` +### Message (de)serialization + +Every message object comes ready for serialization or deserialization. Use `serialize_to_string` to write out the byte-string for the message. Use `parse_from_string` on a new message instance to inflate the byte-string back to a message in ruby. + +```ruby +user = Foo::User.new(:first_name => 'Bob') +bytes = user.serialize_to_string +puts bytes #=> binary representation of this message object + +inflated_user = Foo::User.new.parse_from_string(bytes) +inflated_user == user #=> true +``` + ## 2. RPC -RPC is one of many technologies that tries to solve the problem of getting smaller pieces of data from one place to another. Many will argue for or against RPC and its usefulness, but I'm not going to do that here. Google's Protocol Buffers relies on RPC and that's why you're here. +RPC is one of many technologies that tries to solve the problem of getting smaller pieces of data from one place to another. Many will argue for or against RPC and its usefulness, but I'm not going to do that here. Google's Protocol Buffers provides support for Services with RPC and that's why you're here. Any discussion about RPC leads to a discussion about clients and servers and the remote procedures themselves. For our purposes, we'll talk about a `Client` (process that is calling the server/service), a `Service` (the remote procedure), and a `Server` (the process that manages one or more services). We'll start with the Service first. @@ -73,6 +92,7 @@ Any discussion about RPC leads to a discussion about clients and servers and the Services are simply classes that have endpoint methods defined. Here's what one looks like in protobuf: ``` +package foo; message UserRequest { optional string email = 1; } @@ -87,47 +107,53 @@ service UserService { And the equivalent ruby stub for the service (generated with `rprotoc`): ```ruby -# lib/mycompany/user_service.rb -module Mycompany - class UserService < Protobuf::Rpc::Service +# lib/foo/user.pb.rb +module Foo + # UserRequest and UserList Class definitions not shown (see above for generated output of classes). + + class UserService < ::Protobuf::Rpc::Service rpc :find, UserRequest, UserList end end ``` -Recognize that the extra messages would actually have gone into the `defs.pb.rb` file while the service stub would receive it's own file at `user_service.rb`. - -**Important Note: The *stubbed* class here is a *stub*. You should not alter it directly in any way as it will break your definition. Read on to learn how to use this stub.** +**Important Note: The UserService class here is a *stub*. You should not provide your implementation in this generated file as subsequent generations will wipe out your implmentation. Read on to learn how to use this stub.** Did you read the note above? Go read it. I'll wait. -Ok, now that you have a compiled service stub, you'll want to require it from `lib` and implement the methods. You'll notice when you compile the stub there is a large comment at the top of the file. You can use this code comment to start your real implementation. Go ahead and copy it to your services directory (probably `app/services` if we're in rails). +Ok, now that you have a generated service stub, you'll want to require it from `lib` and implement the methods. Create a service implementation file in your project. In rails I'd put this in `app/services/user_service.rb`. ```ruby # app/services/user_service.rb -require 'lib/mycompany/user_service' -module Mycompany +require 'lib/foo/user.pb' + +# Reopen the class and provide the implementation for each rpc method defined. +module Foo class UserService - - # request -> Mycompany::UserRequest - # response -> Mycompany::UserResponse + + # request -> Foo::UserRequest + # response -> Foo::UserResponse def find # request.email will be the unpacked string that was sent by the client request User.find_by_email(request.email).each do |user| - # must only use a proto instance of Mycompany::User when appending to the `users` field + # must only use a proto instance of Foo::User when appending to the `users` field response.users << user.to_proto end end - + end end ``` -Simply implement the instance method for the defined rpc. No other methods will be allowed in the class (even helpers or private methods). An implicit `request` and `response` object are provided for you, pre-instantiated, and in the case of the request, already are populated with the data that was sent by the client. +Simply implement the instance method for the defined rpc. You can provide any other methods in this class as helpers, but only those defined in the proto file will be callable by remote clients. Every request made by a client will provide a non-empty request of the defined type. The server creates a new service instance based on the request, so you should not be constrained to just the endpoint method. This is similar to rails controllers where only methods defined by the routes file are hooked up to HTTP requests, but it's very common to implement private methods the aid in code quality and simpilicity. -If you need to create your own response object (a valid case), be sure to assign it back to the instance by using `self.response = your_response_obj`. The object you assign **MUST** be of the defined return type, in this case `Mycompany::UserList`. Any other type will result in an error. +Every instance has a `request` and `response` object used for fulfilling the call, again, similar to a rails controller action. You should never attempt to modify the `request` object. The `response` object however should be modified or replaced entirely. If you need to create your own response object (a valid case), simply use `respond_with(new_response)`. The returned object should conform to one of three properties: -Triggering an error from the service is simple: +1. Response should be of same type as defined by the rpc definition (in this case, `Foo::UserList`), or +2. Response should be a hash. This hash will be used to construct an instance of the defined type and should therefore conform to the appropriate fields for that type. +3. Response should respond to the `to_proto` method. The object returned by `to_proto` should be an instance of the defined response type. + +If at any time the implementation encounters an error, the client can be instructed of the error using `rpc_failed`: ```ruby #... @@ -141,21 +167,19 @@ end #... ``` -This means that the client's `on_failure` callback will be invoked instead of the `on_success` callback. Read more below on client callbacks. - -I find it very convenient to use a CRUD-style interface when defining certain data services, though this is certainly not always the case. +This means that the client's `on_failure` callback will be invoked instead of the `on_success` callback. Read more below on client callbacks. One drawback to the `rpc_failed` approach is that it does not short-circuit the rest of the method. This means that you must explicitly return from the method if you do not wish the remainder to be executed. ### Servers A service is nothing without being hooked up to a socket. It's the nerdy kid waiting by the telephone for someone to call without knowing that the phone company disconnected their house. Sad and pathetic. So hook the phone lines! ``` -$ rpc_server -o myserver.com -p 9939 -e production -l ./log/protobuf.log config/environment.rb +$ rpc_server -o myserver.com -p 9939 -l ./log/protobuf.log ./config/environment.rb ``` -The previous call will start an EventMachine server running on the given host and port which will load your application into memory. You certainly don't have to run rails or any other framework, just make sure you have some kind of file that will load your services all into memory. The server doesn't know where you put your code, so tell it. +The previous call will start an Socket server running on the given host and port which will load your application into memory. You certainly don't have to run rails or any other framework, just make sure you have some kind of file that will load your services all into memory. The server doesn't know where you put your code, so tell it. -Be aware that server needs to be able to translate the socket stream of bytes into an actual protobuf request object. If the definition for that request object aren't known to the server, you're going to have a long day getting this going. It's necessary to store all your definitions and their generated classes in a shared repository (read: gem) that both client and server have access to in their respective load paths. +Be aware that the server needs to be able to translate the socket stream of bytes into an actual protobuf request object. If the definition for that request object aren't known to the server, you're going to have a long day getting this going. It's necessary to store all your definitions and their generated classes in a shared repository (read: gem) so that both client and server have access to the ruby classes in their respective load paths. Once the server starts, you should see it as a running process with `ps`. Sending a KILL, QUIT, or TERM signal to the pid will result in shutting the server down gracefully. @@ -169,24 +193,24 @@ rpc_server shutdown ### Clients -A lot of work has gone into making the client calls simple and easy to use yet still powerful. Clients have a DSL that feels very ajax-ish, mostly because of the nature of EventMachine, but I also think it works quite well. +A lot of work has gone into making the client calls simple and easy to use yet still powerful. Clients have a DSL that feels very ajaxy. ```ruby # require the defs from the shared gem/repo -require 'sharedgem/mycompany/user.pb' -require 'sharedgem/mycompany/user_service' +require 'sharedgem/foo/user.pb' # Create a request object for the method we are invoking -req = Mycompany::UserRequest.new(:email => 'jeff@gmail.com') +req = Foo::UserRequest.new(:email => 'jeff@gmail.com') # Use the UserService class to generate a client, invoke the rpc method -# while passing the request object -Mycompany::UserService.client.find(req) do |c| +# while passing the request object. +# We could also simply pass a hash to find. +Foo::UserService.client.find(req) do |c| # This block will be executed (registering the callbacks) # before the request actualy occurs. # the `c` param in this block is the `.client` object # that is generated from the call above - + # Register a block for execution when the response # is deemed successful from the service. Accepts # the unpacked response as its only parameter @@ -195,7 +219,7 @@ Mycompany::UserService.client.find(req) do |c| puts u.inspect end end - + # Register a block for execution when the response # is deemed a failure. This can be either a client-side # or server-side failure. The object passed the to the @@ -207,22 +231,21 @@ Mycompany::UserService.client.find(req) do |c| end ``` -Many different options can be passed to the `.client` call above (such as `:async => true` or `:timeout => 600`). See the `lib/protobuf/rpc/client.rb` and `lib/protobuf/rpc/service.rb` files for more documentation. It should be noted that the default behavior of `UserService.client` is to return a blocking client. The nature of using Client calls within a framework like Rails demands a blocking call if the response of a web request is dependent on data returned from the service. +Many different options can be passed to the `.client` call above (such as `:timeout => 600`). See the `lib/protobuf/rpc/client.rb` and `lib/protobuf/rpc/service.rb` files for more documentation. ## 3. RPC Interop -The main reason I wrote this gem was to provide a ruby implementation to google's protobuf that worked on the RPC layer with a Java Service layer that was already running [protobuf-socket-rpc][], the supported socket rpc library for protobuf from Google. The [old gem][] did not provide a very robust RPC implementation and it most certainly did not work with the Java stack. +The main reason I wrote this gem was to provide a ruby implementation to google's protobuf that worked on the RPC layer with a Java Service layer that was already running [protobuf-socket-rpc][], the supported socket rpc library for protobuf from Google. Other ruby protobuf implementations I've used did not provide this kind of support. ## Accreditation & Caveats -It must be noted a large amount of the code in this library was taken from the [ruby-protobuf][old gem] gem. Its authors and I were unable to reach a communication point to be able to merge all of my RPC updates in with their master. Unfortunately I just simply couldn't use their RPC code and so I've decided to diverge from their codeset. I take no credit whatsoever for the (de)serialization and `rprotoc` code generation original work, though I have modified it slightly to be more compliant with my understanding of the pb spec. I want to say thanks to the original devs for the good work they did to get me most of the way there. The code was initially diverged at their 0.4.0 version. +It must be noted that this gem was started originally as a fork of the [ruby-protobuf][old gem] gem. Its authors and I were unable to reach a communication point to be able to merge all of my RPC updates in with their master. Unfortunately I just simply couldn't use their RPC code and so I forked the code. Myself and others have significantly changed the internals of the gem, including the rpc implementation, the message/field implementation, and the compiler implementation. These changes were made to address glaring performance and quality issues in the code. The code was initially diverged at their 0.4.0 version. It should also be noted that there are many more features I haven't really shown here, so please let me know if you have any questions on usage or support for various features. Happy protobufing. --- BJ Neilsen, [@localshred][], [rand9.com][] +-- BJ Neilsen, [@localshred][] [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" [protobuf-socket-rpc]: http://code.google.com/p/protobuf-socket-rpc/ "Google's official Socket-RPC library for protobuf" [old gem]: https://github.com/macks/ruby-protobuf "Macks ruby-protobuf on github" [@localshred]: http://twitter.com/localshred "Follow on twitter @localshred" - [rand9.com]: http://rand9.com "Blog" From eef2c3109bcb6aa34a5c1477c8e3922fb180b30e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 29 Oct 2012 11:21:52 -0600 Subject: [PATCH 0154/1191] Add/arrange new respond_with coercion checks Candidates are coerced if: * Object responds to `to_proto` * Object responds to `to_proto_hash` * Object responds to `to_hash` --- lib/protobuf/rpc/server.rb | 3 ++- lib/protobuf/rpc/service_dispatcher.rb | 13 ++++++++----- lib/protobuf/rpc/stat.rb | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 1a59efb0..9fefe550 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -78,8 +78,9 @@ def parse_request_from_buffer def send_response log_debug { sign_message("Sending response to client: #{@response.inspect}") } send_data - @stats.stop && log_info { @stats.to_s } ensure + @stats.stop + log_info { @stats.to_s } enable_gc! end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index d02eadcf..835cccc5 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -53,12 +53,15 @@ def assign_error(error_klass, message) def coerced_response candidate = service.response - if candidate.is_a?(Hash) - candidate = definition.response_type.new(candidate) - elsif candidate.respond_to?(:to_hash) - candidate = definition.response_type.new(candidate.to_hash) - elsif candidate.respond_to?(:to_proto) + case + when candidate.is_a?(::Protobuf::Message) then + # no-op + when candidate.respond_to?(:to_proto) then candidate = candidate.to_proto + when candidate.respond_to?(:to_proto_hash) then + candidate = definition.response_type.new(candidate.to_proto_hash) + when candidate.respond_to?(:to_hash) then + candidate = definition.response_type.new(candidate.to_hash) end candidate diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 47e50400..9e58fcc6 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -69,7 +69,7 @@ def client? def to_s [ - server? ? "[SRV-#{self.class}]" : "[CLT-#{self.class}]", + server? ? "[SRV]" : "[CLT]", rpc, elapsed_time, sizes, From ca1130adc78bbb8f562310148d4a381d9c17e390 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 29 Oct 2012 11:22:44 -0600 Subject: [PATCH 0155/1191] Passing nil to Enum.name_by_value will return nil --- lib/protobuf/enum.rb | 2 +- lib/protobuf/field.rb | 14 +++++++------- lib/protobuf/field/base_field.rb | 1 + spec/lib/protobuf/enum_spec.rb | 6 ++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index f9c067fb..97a073e5 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -32,7 +32,7 @@ def self.enum_by_value(value) end def self.name_by_value(value) - @names[value] + value.nil? ? nil : @names[value] end def self.valid_tag?(tag) diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index 63fd6c86..5f27f9b2 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -24,25 +24,25 @@ module Protobuf module Field PREDEFINED_TYPES = [ - ::Protobuf::Field::DoubleField, + ::Protobuf::Field::DoubleField, ::Protobuf::Field::FloatField, - ::Protobuf::Field::Int32Field, + ::Protobuf::Field::Int32Field, ::Protobuf::Field::Int64Field, - ::Protobuf::Field::Uint32Field, + ::Protobuf::Field::Uint32Field, ::Protobuf::Field::Uint64Field, - ::Protobuf::Field::Sint32Field, + ::Protobuf::Field::Sint32Field, ::Protobuf::Field::Sint64Field, ::Protobuf::Field::Fixed32Field, ::Protobuf::Field::Fixed64Field, - ::Protobuf::Field::Sfixed32Field, + ::Protobuf::Field::Sfixed32Field, ::Protobuf::Field::Sfixed64Field, - ::Protobuf::Field::StringField, + ::Protobuf::Field::StringField, ::Protobuf::Field::BytesField, ::Protobuf::Field::BoolField ].freeze def self.build(message_class, rule, type, name, tag, options={}) - field_class = type_message_or_enum(type) + field_class = type_message_or_enum(type) field_class.new(message_class, rule, type, name, tag, options) end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 3f60b81c..bb7a57a5 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -184,6 +184,7 @@ def define_array_getter field = self @message_class.class_eval do define_method(field.getter_method_name) do + field.warn_if_deprecated @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 13cf14e1..24f07554 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -51,6 +51,12 @@ it 'gets the name of the enum corresponding to the given value (tag)' do Test::EnumTestType.name_by_value(tag).should eq name end + + context 'when given name is nil' do + it 'returns a nil' do + Test::EnumTestType.name_by_value(nil).should be_nil + end + end end describe '.valid_tag?' do From d92e684eea8c317260f8caf379136ecd947bf7d9 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 29 Oct 2012 11:23:44 -0600 Subject: [PATCH 0156/1191] Add specs to Message#get_field_by_name and #get_field_by_tag Accessing these methods with out-of-bounds values will raise a specific `Protobuf::Message::FieldNotDefinedError` exception. --- lib/protobuf/message.rb | 12 ++++++ spec/lib/protobuf/message_spec.rb | 68 +++++++++++++++++++++++++++++++ spec/spec_helper.rb | 4 +- spec/support/test/enum.pb.rb | 16 ++++---- spec/support/test/resource.pb.rb | 39 ++++++++++-------- 5 files changed, 115 insertions(+), 24 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index d82e7d7b..3fd3eaa3 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -6,6 +6,9 @@ module Protobuf class Message + + class FieldNotDefinedError < StandardError; end + STRING_ENCODING = "ASCII-8BIT".freeze def self.all_fields @@ -80,16 +83,25 @@ def self.field_name_to_tag def self.get_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value fields[field_name_to_tag[name]] + rescue TypeError => e + name = 'nil' if name.nil? + raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") end # Find a field object by +tag+ number. def self.get_field_by_tag(tag) fields[tag] + rescue TypeError => e + tag = tag.nil? ? 'nil' : tag.to_s + raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") end def self.get_ext_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value extension_fields[extension_field_name_to_tag[name]] + rescue TypeError => e + name = 'nil' if name.nil? + raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") end def self.get_ext_field_by_tag(tag) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 32614d95..cdf9235f 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -47,4 +47,72 @@ its(:to_json) { should eq '{"name":"Test Name","active":false}' } end + describe '#get_field_by_name' do + subject do + ::Test::Resource.new({ :name => 'Test Name', :date_created => Time.now.to_i }) + end + + context 'when name is a valid field' do + let(:valid_field) { subject.get_field_by_name(:name) } + specify { valid_field.should be_a ::Protobuf::Field::StringField } + specify { valid_field.name.should eq :name } + end + + context 'when name is not a valid field' do + specify do + expect { + subject.get_field_by_name(1) + }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*1.*#{subject.class.name}/) + end + + specify do + expect { + subject.get_field_by_name(:nothere) + }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*nothere.*#{subject.class.name}/) + end + + specify do + expect { + subject.get_field_by_name(nil) + }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) + end + end + end + + describe '#get_ext_field_by_name' do + pending 'Need to get a proto compiled with extensions first' + end + + describe '#get_field_by_tag' do + subject do + ::Test::Resource.new({ :name => 'Test Name', :date_created => Time.now.to_i }) + end + + context 'when tag references a valid field' do + let(:valid_field) { subject.get_field_by_tag(1) } + specify { valid_field.should be_a ::Protobuf::Field::StringField } + specify { valid_field.name.should eq :name } + end + + context 'when tag does not reference a field' do + it 'returns nil' do + subject.get_field_by_tag(-1).should be_nil + end + end + + context 'when tag is not numeric' do + specify do + expect { + subject.get_field_by_tag("not a number") + }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*not a number.*#{subject.class.name}/) + end + + specify do + expect { + subject.get_field_by_tag(nil) + }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) + end + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b0416d56..57e3d6b3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,7 +26,9 @@ unless ENV['NO_COMPILE_TEST_PROTOS'] $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' proto_path = File.expand_path("../support/", __FILE__) - %x{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } + cmd = %Q{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } + puts cmd + %x{#{cmd}} end end end diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index d6067481..3a95b78c 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -17,16 +17,18 @@ class EnumTestMessage < ::Protobuf::Message; end ## # Enum Values # - ::Test::EnumTestType.define :ONE, 1 - ::Test::EnumTestType.define :TWO, 2 - + class EnumTestType + define :ONE, 1 + define :TWO, 2 + end ## # Message Fields # - ::Test::EnumTestMessage.optional(::Test::EnumTestType, :non_default_enum, 1) - ::Test::EnumTestMessage.optional(::Test::EnumTestType, :default_enum, 2, :default => ::Test::EnumTestType::ONE) - ::Test::EnumTestMessage.repeated(::Test::EnumTestType, :repeated_enums, 3) - + class EnumTestMessage + optional ::Test::EnumTestType, :non_default_enum, 1 + optional ::Test::EnumTestType, :default_enum, 2, :default => ::Test::EnumTestType::ONE + repeated ::Test::EnumTestType, :repeated_enums, 3 + end end diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 7db1706d..7e68dcf2 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -15,33 +15,40 @@ class StatusType < ::Protobuf::Enum; end # class ResourceFindRequest < ::Protobuf::Message; end class Resource < ::Protobuf::Message; end + class Extended < ::Protobuf::Message; end class Nested < ::Protobuf::Message; end ## # Enum Values # - ::Test::StatusType.define :PENDING, 0 - ::Test::StatusType.define :ENABLED, 1 - ::Test::StatusType.define :DISABLED, 2 - ::Test::StatusType.define :DELETED, 3 - + class StatusType + define :PENDING, 0 + define :ENABLED, 1 + define :DISABLED, 2 + define :DELETED, 3 + end ## # Message Fields # - ::Test::ResourceFindRequest.required(::Protobuf::Field::StringField, :name, 1) - ::Test::ResourceFindRequest.optional(::Protobuf::Field::BoolField, :active, 2) - - ::Test::Resource.required(::Protobuf::Field::StringField, :name, 1) - ::Test::Resource.optional(::Protobuf::Field::Int64Field, :date_created, 2) - ::Test::Resource.optional(::Test::StatusType, :status, 3) - ::Test::Resource.repeated(::Test::StatusType, :repeated_enum, 4) + class ResourceFindRequest + required ::Protobuf::Field::StringField, :name, 1 + optional ::Protobuf::Field::BoolField, :active, 2 + end - ::Test::Nested.optional(::Protobuf::Field::StringField, :name, 1) - ::Test::Nested.optional(::Test::Resource, :resource, 2) - ::Test::Nested.repeated(::Test::Resource, :multiple_resources, 3) - ::Test::Nested.optional(::Test::StatusType, :status, 4) + class Resource + required ::Protobuf::Field::StringField, :name, 1 + optional ::Protobuf::Field::Int64Field, :date_created, 2 + optional ::Test::StatusType, :status, 3 + repeated ::Test::StatusType, :repeated_enum, 4 + end + class Nested + optional ::Protobuf::Field::StringField, :name, 1 + optional ::Test::Resource, :resource, 2 + repeated ::Test::Resource, :multiple_resources, 3 + optional ::Test::StatusType, :status, 4 + end ## # Services From 08d7354cf1385b3de87d1958c9d1aa1b3e9551e4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 29 Oct 2012 11:24:14 -0600 Subject: [PATCH 0157/1191] Bump version 2.0.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index afab7181..dc65d2ec 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.0' + VERSION = '2.0.1' PROTOC_VERSION = '2.4.1' end From 4d8feab30f79fac6d9eda82b95368bbf93f55f6b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 30 Oct 2012 10:48:24 -0600 Subject: [PATCH 0158/1191] call to_sym on strings sent into the get_field_by_name method for ActiveModel support --- lib/protobuf/message.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 3fd3eaa3..236aff6a 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -82,8 +82,8 @@ def self.field_name_to_tag # Find a field object by +name+. def self.get_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value - fields[field_name_to_tag[name]] - rescue TypeError => e + fields[field_name_to_tag[name.to_sym]] + rescue TypeError, NoMethodError => e name = 'nil' if name.nil? raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") end @@ -98,8 +98,8 @@ def self.get_field_by_tag(tag) def self.get_ext_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value - extension_fields[extension_field_name_to_tag[name]] - rescue TypeError => e + extension_fields[extension_field_name_to_tag[name.to_sym]] + rescue TypeError, NoMethodError => e name = 'nil' if name.nil? raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") end From a0c13891005a2ac41da6d04915ae3157725c4efa Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 30 Oct 2012 10:48:31 -0600 Subject: [PATCH 0159/1191] bump to 2.0.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index dc65d2ec..7235bd38 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.1' + VERSION = '2.0.2' PROTOC_VERSION = '2.4.1' end From 96040f5c48ec7c6a9c388d3f1ac6d8d3c4b63288 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 30 Oct 2012 11:01:27 -0600 Subject: [PATCH 0160/1191] update min/max on Varint messages to be instance as well --- lib/protobuf/field/float_field.rb | 2 ++ lib/protobuf/field/int32_field.rb | 2 ++ lib/protobuf/field/int64_field.rb | 2 ++ lib/protobuf/field/sint32_field.rb | 2 ++ lib/protobuf/field/sint64_field.rb | 2 ++ lib/protobuf/field/uint32_field.rb | 2 ++ lib/protobuf/field/uint64_field.rb | 2 ++ 7 files changed, 14 insertions(+) diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index ff9f252b..8c475eb4 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -6,6 +6,8 @@ class FloatField < BaseField def self.default; 0.0; end def self.max; 1.0/0; end def self.min; -1.0/0; end + def max; 1.0/0; end + def min; -1.0/0; end def wire_type WireType::FIXED32 diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb index b3eee379..147e11b8 100644 --- a/lib/protobuf/field/int32_field.rb +++ b/lib/protobuf/field/int32_field.rb @@ -5,6 +5,8 @@ module Field class Int32Field < IntegerField def self.max; INT32_MAX; end def self.min; INT32_MIN; end + def max; INT32_MAX; end + def min; INT32_MIN; end end end end diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb index 67f36313..669397d4 100644 --- a/lib/protobuf/field/int64_field.rb +++ b/lib/protobuf/field/int64_field.rb @@ -5,6 +5,8 @@ module Field class Int64Field < IntegerField def self.max; INT64_MAX; end def self.min; INT64_MIN; end + def max; INT64_MAX; end + def min; INT64_MIN; end end end end diff --git a/lib/protobuf/field/sint32_field.rb b/lib/protobuf/field/sint32_field.rb index 17e6bba8..4d71f244 100644 --- a/lib/protobuf/field/sint32_field.rb +++ b/lib/protobuf/field/sint32_field.rb @@ -5,6 +5,8 @@ module Field class Sint32Field < SignedIntegerField def self.max; INT32_MAX; end def self.min; INT32_MIN; end + def max; INT32_MAX; end + def min; INT32_MIN; end end end end diff --git a/lib/protobuf/field/sint64_field.rb b/lib/protobuf/field/sint64_field.rb index b49bb74f..6b256eb2 100644 --- a/lib/protobuf/field/sint64_field.rb +++ b/lib/protobuf/field/sint64_field.rb @@ -5,6 +5,8 @@ module Field class Sint64Field < SignedIntegerField def self.max; INT64_MAX; end def self.min; INT64_MIN; end + def max; INT64_MAX; end + def min; INT64_MIN; end end end end diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb index 3caa31c2..39af71c3 100644 --- a/lib/protobuf/field/uint32_field.rb +++ b/lib/protobuf/field/uint32_field.rb @@ -5,6 +5,8 @@ module Field class Uint32Field < VarintField def self.max; UINT32_MAX; end def self.min; 0; end + def max; UINT32_MAX; end + def min; 0; end end end end diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb index 89d9d971..051b2ffc 100644 --- a/lib/protobuf/field/uint64_field.rb +++ b/lib/protobuf/field/uint64_field.rb @@ -5,6 +5,8 @@ module Field class Uint64Field < VarintField def self.max; UINT64_MAX; end def self.min; 0; end + def max; UINT64_MAX; end + def min; 0; end end end end From bf28f9650cb9b27273d838e50d0131bd75614a67 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 30 Oct 2012 12:10:25 -0600 Subject: [PATCH 0161/1191] Fix cli runner opts threshold option (misspelled) --- lib/protobuf/cli.rb | 6 ++++-- spec/lib/protobuf/cli_spec.rb | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 20e92700..1ba409c3 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -34,7 +34,6 @@ class CLI < ::Thor option :print_deprecation_warnings, :type => :boolean, :default => true, :desc => 'Cause use of deprecated fields to be printed or ignored.' def start(app_file) - puts 'RUNNING FROM LOCAL' debug_say 'Configuring the rpc_server process' @start_aborted = false @@ -159,7 +158,7 @@ def runner_options { :host => options.host, :port => options.port, :backlog => options.backlog, - :treshold => options.threshold, + :threshold => options.threshold, :threads => options.threads } end @@ -168,6 +167,9 @@ def say_and_exit!(message, exception = nil) ::Protobuf::Logger.error { message } if exception + $stderr.puts "[#{exception.class.name}] #{exception.message}" + $stderr.puts exception.backtrace.join("\n") + ::Protobuf::Logger.error { "[#{exception.class.name}] #{exception.message}" } ::Protobuf::Logger.debug { exception.backtrace.join("\n") } end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 18f89e16..61671c63 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -23,7 +23,7 @@ it 'sends the host option to the runner' do ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options.host.should eq '123.123.123.123' + options[:host].should eq '123.123.123.123' end described_class.start(args) end @@ -34,7 +34,18 @@ it 'sends the port option to the runner' do ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options.port.should eq 12345 + options[:port].should eq 12345 + end + described_class.start(args) + end + end + + context 'threads option' do + let(:test_args) { [ '--threads=500' ] } + + it 'sends the threads option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:threads].should eq 500 end described_class.start(args) end @@ -45,7 +56,7 @@ it 'sends the backlog option to the runner' do ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options.backlog.should eq 500 + options[:backlog].should eq 500 end described_class.start(args) end @@ -56,7 +67,7 @@ it 'sends the backlog option to the runner' do ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options.threshold.should eq 500 + options[:threshold].should eq 500 end described_class.start(args) end From 227625bfe1d6ced17c0788f3ea6fa34b8d89100f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 30 Oct 2012 19:52:16 -0600 Subject: [PATCH 0162/1191] replace Hash checking with to_hash checking and substitution --- lib/protobuf/field/field_array.rb | 6 +++--- lib/protobuf/field/message_field.rb | 16 +++++++++------- lib/protobuf/message.rb | 1 + lib/protobuf/version.rb | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 2322d053..d6f16a29 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -29,7 +29,7 @@ def unshift(val) def replace(val) raise TypeError unless val.is_a?(Array) - val = val.map {|v| normalize(v)} + val = val.map { |v| normalize(v)} super(val) end @@ -54,8 +54,8 @@ def normalize(value) raise TypeError unless @field.acceptable?(value) if @field.is_a?(::Protobuf::Field::EnumField) @field.type.fetch(value) - elsif @field.is_a?(::Protobuf::Field::MessageField) && value.is_a?(Hash) - @field.type.new(value) + elsif @field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) + @field.type.new(value.to_hash) else value end diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index e89102af..b5c7f83a 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -3,11 +3,13 @@ module Protobuf module Field class MessageField < BaseField + RAISE_TYPE = lambda { |field, val| raise TypeError, "Expected value of type '#{field.type}', but got '#{val.class}'" } + ## # Public Instance Methods # def acceptable?(val) - raise TypeError unless val.instance_of?(type) || val.instance_of?(Hash) + RAISE_TYPE.call(self, val) unless val.instance_of?(type) || val.respond_to?(:to_hash) true end @@ -33,15 +35,15 @@ def define_setter field = self @message_class.class_eval do define_method("#{field.name}=") do |val| - case val - when nil then + case + when val.nil? then @values.delete(field.name) - when Hash then - @values[field.name] = field.type.new(val) - when field.type then + when val.is_a?(field.type) then @values[field.name] = val + when val.respond_to?(:to_hash) then + @values[field.name] = field.type.new(val.to_hash) else - raise TypeError, "Expected value of type '#{field.type}', but got '#{val.class}'" + RAISE_TYPE.call(field, val) end end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 236aff6a..6945d9d9 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -112,6 +112,7 @@ def self.get_ext_field_by_tag(tag) # Constructor # def initialize(values={}) + values = values.to_hash @values = {} values.each { |name, val| self[name] = val} diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 7235bd38..b2d23adc 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.2' + VERSION = '2.0.3' PROTOC_VERSION = '2.4.1' end From b208d5c1601f6c096e8c3a62b12add46988917a1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sat, 3 Nov 2012 11:16:39 -0600 Subject: [PATCH 0163/1191] Initial stab at callback composition for service methods --- lib/protobuf/rpc/service.rb | 13 +++ lib/protobuf/rpc/service_callbacks.rb | 84 +++++++++++++++++++ lib/protobuf/rpc/service_dispatcher.rb | 2 +- .../protobuf/rpc/service_callbacks_spec.rb | 84 +++++++++++++++++++ 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 lib/protobuf/rpc/service_callbacks.rb create mode 100644 spec/lib/protobuf/rpc/service_callbacks_spec.rb diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 46235eb7..e2a1df95 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,9 +1,13 @@ require 'protobuf/logger' require 'protobuf/rpc/client' require 'protobuf/rpc/error' +require 'protobuf/rpc/service_callbacks' module Protobuf module Rpc + + include Protobuf::Rpc::ServiceCallbacks + # Object to encapsulate the request/response types for a given service method # RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) @@ -130,6 +134,15 @@ def rpcs self.class.rpcs end + # Get a callable object that will be used by the dispatcher + # to invoke the specified rpc method. Facilitates callback dispatch. + # The returned lambda is expected to be called at a later time (which + # is why we wrap the method call). + # + def callable_rpc_method(method_name) + lambda { run_filters { method(method_name).call } } + end + private # Request object for this rpc cycle. Not assignable. diff --git a/lib/protobuf/rpc/service_callbacks.rb b/lib/protobuf/rpc/service_callbacks.rb new file mode 100644 index 00000000..39fd0b78 --- /dev/null +++ b/lib/protobuf/rpc/service_callbacks.rb @@ -0,0 +1,84 @@ +module Protobuf + module Rpc + module ServiceCallbacks + include ActiveSupport::Callbacks + + def self.included(other) + other.class_eval do + extend Protobuf::Rpc::ServiceCallbacks::ClassMethods + include Protobuf::Rpc::ServiceCallbacks::InstanceMethods + end + end + + module ClassMethods + + def after_filter(*args) + set_filters(:after, args) + end + + def around_filter(*args) + set_filters(:around, args) + end + + def before_filter(*args) + set_filters(:before, args) + end + + private + + def set_filters(type, *args) + opts = args.last.is_a?(Hash) ? args.pop : {} + args.each do |callable| + case + when callable.respond_to?(:call) then + # no-op + when self.instance_methods.include?(callable) then + callable = method(callable) + else + raise "Filter #{callable} must be an instance method or be callable" + end + + filters[type] = callable + end + end + + def filters + @filters ||= Hash.new { |h,k| h[k] = Set.new } + end + + end + + module InstanceMethods + + private + + def enumerated_filter_call + lambda { |filter| filter.call } + end + + def run_after_filters + filters[:after].each(&enumerated_filter_call) + end + + def run_around_filters(final) + filters[:around].reverse.inject(final) { |previous, filter| + lambda { __send__(filter, &previous) } + }.call + end + + def run_before_filters + filters[:before].each(&enumerated_filter_call) + end + + + def run_filters(&final) + run_before_filters + run_around_filters(final) + run_after_filters + end + + end + + end + end +end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 835cccc5..181d26c4 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -73,7 +73,7 @@ def init_method method_name = outer_request.method_name.underscore.to_sym if service_klass.rpc_method?(method_name) self.service = service_klass.new(method_name, outer_request.request_proto) - self.callable_method = service.method(method_name) + self.callable_method = service.callable_rpc_method(method_name) self.definition = service.rpcs[method_name] else assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not a defined rpc method.") diff --git a/spec/lib/protobuf/rpc/service_callbacks_spec.rb b/spec/lib/protobuf/rpc/service_callbacks_spec.rb new file mode 100644 index 00000000..a30a8202 --- /dev/null +++ b/spec/lib/protobuf/rpc/service_callbacks_spec.rb @@ -0,0 +1,84 @@ +require 'spec_helper' + +class ServiceWithHooks + include Protobuf::Rpc::ServiceCallbacks + + # Initialize the hash keys as instance vars + def initialize(ivar_hash) + ivar_hash.each_pair do |key, value| + self.class.class_eval do + attr_accessor key + end + __send__("#{key}=", value) + end + end +end + +describe Protobuf::Rpc::ServiceCallbacks do + subject { ServiceWithHooks.new(params) } + + describe '#before_filter' do + before(:all) do + class ServiceWithHooks + def verify_before + @before_filter_called = true + end + end + end + + after(:all) do + class ServiceWithHooks + undef :verify_before + end + end + + let(:params) { { :before_filter_called => false } } + before { ServiceWithHooks.before_filter(:verify_before) } + + context 'when defining a before filter' do + before { subject.run_before_filters! } + + its('class.before_filters') { should include(:verify_before) } + its(:before_filter_called) { should be_true } + end + + context 'when multiple methods are defined' do + pending + end + + context 'when same method is added' do + before { ServiceWithHooks.before_filter(:verify_before) } + before { ServiceWithHooks.before_filter(:verify_before) } + before { ServiceWithHooks.before_filter(:verify_before) } + + it 'calls the method callback a single time' do + subject.should_receive(:verify_before).once + subject.run_before_filters! + end + end + end + + describe '#after_filter' do + before(:all) do + class ServiceWithHooks + def verify_after + @after_filter_called = true + end + end + end + + after(:all) do + class ServiceWithHooks + undef :verify_after + end + end + + let(:params) { { :after_filter_called => false } } + + before { ServiceWithHooks.after_filter(:verify_after) } + before { subject.run_after_filters! } + + its('class.after_filters') { should include(:verify_after) } + its(:after_filter_called) { should be_true } + end +end From c57d244d33dd771a4a677cd493d5d95698bd350f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sat, 3 Nov 2012 21:49:45 -0600 Subject: [PATCH 0164/1191] First cut of filters tested and behaving as expected --- lib/protobuf/rpc/service_callbacks.rb | 104 ++++++++++--- lib/protobuf/rpc/service_dispatcher.rb | 2 + .../protobuf/rpc/service_callbacks_spec.rb | 140 +++++++++++++----- 3 files changed, 189 insertions(+), 57 deletions(-) diff --git a/lib/protobuf/rpc/service_callbacks.rb b/lib/protobuf/rpc/service_callbacks.rb index 39fd0b78..5b4e7981 100644 --- a/lib/protobuf/rpc/service_callbacks.rb +++ b/lib/protobuf/rpc/service_callbacks.rb @@ -12,65 +12,123 @@ def self.included(other) module ClassMethods - def after_filter(*args) - set_filters(:after, args) + [:after, :around, :before].each do |type| + # Setter DSL method for given filter types. + # + define_method "#{type}_filter" do |*args| + set_filters(type, *args) + end end - def around_filter(*args) - set_filters(:around, args) + # Filters hash keyed based on filter type (e.g. :before, :after, :around), + # whose values are Sets. + # + def filters + @filters ||= Hash.new { |h,k| h[k] = [] } end - def before_filter(*args) - set_filters(:before, args) + private + + + def defined_filters + @defined_filters ||= Hash.new { |h,k| h[k] = Set.new } end - private + # Check to see if the filter has been defined. + # + def filter_defined?(type, filter) + defined_filters[type].include?(filter) + end + # Remember that we stored the filter. + # + def remember_filter(type, filter) + defined_filters[type] << filter + end + + # Takes a list of actually (or potentially) callable objects. + # TODO add support for if/unless + # TODO add support for only/except sub-filters + # def set_filters(type, *args) opts = args.last.is_a?(Hash) ? args.pop : {} - args.each do |callable| - case - when callable.respond_to?(:call) then - # no-op - when self.instance_methods.include?(callable) then - callable = method(callable) - else - raise "Filter #{callable} must be an instance method or be callable" - end - - filters[type] = callable + args.each do |filter| + next if filter_defined?(type, filter) + filters[type] << filter + remember_filter(type, filter) end end - def filters - @filters ||= Hash.new { |h,k| h[k] = Set.new } - end - end module InstanceMethods private + # Enumerator block given to Set#each to simply call the given filter. + # See #run_after_filters, #run_before_filters + # def enumerated_filter_call - lambda { |filter| filter.call } + lambda { |filter| __send__(filter) } + end + + # Get back to class filters. + # + def filters + self.class.filters end + # Loop over the after filters and invoke them. + # def run_after_filters filters[:after].each(&enumerated_filter_call) end + # Reverse build a chain of around filters. To implement an around chain, + # simply build a method that yields control when it expects the underlying + # method to be invoked. If the endpoint should not be run (due to some + # condition), simply do not yield. + # + # Around filters are invoked in the order they are defined, outer to inner, + # with the inner-most method called being the actual rpc endpoint. + # + # Let's say you have a class defined with the following filters: + # + # class MyService + # around_filter :filter1, :filter2, :filter3 + # + # def my_endpoint + # # do stuff + # end + # end + # + # When the my_endpoint method is invoked using Service#callable_rpc_method, + # It is similar to this call chain: + # + # filter1 do + # filter2 do + # filter3 do + # my_endpoint + # end + # end + # end + # def run_around_filters(final) filters[:around].reverse.inject(final) { |previous, filter| lambda { __send__(filter, &previous) } }.call end + # Loop over the before filters and invoke them. + # def run_before_filters filters[:before].each(&enumerated_filter_call) end + # Entry method to call each filter type in the appropriate order. This should + # be used instead of the other run methods directly. + # def run_filters(&final) run_before_filters run_around_filters(final) diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 181d26c4..e82f8f06 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -79,6 +79,8 @@ def init_method assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not a defined rpc method.") end rescue NameError => e + # FIXME I think this is no longer applicable since the method extract + # is now wrapped in a lambda (@see Service#callable_rpc_method). log_exception(e) assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not implemented.") end diff --git a/spec/lib/protobuf/rpc/service_callbacks_spec.rb b/spec/lib/protobuf/rpc/service_callbacks_spec.rb index a30a8202..fffdbf0f 100644 --- a/spec/lib/protobuf/rpc/service_callbacks_spec.rb +++ b/spec/lib/protobuf/rpc/service_callbacks_spec.rb @@ -12,73 +12,145 @@ def initialize(ivar_hash) __send__("#{key}=", value) end end + + def endpoint + @called << :endpoint + end + + def self.clear_filters! + @defined_filters = nil + @filters = nil + end end describe Protobuf::Rpc::ServiceCallbacks do subject { ServiceWithHooks.new(params) } + after(:each) { ServiceWithHooks.clear_filters! } describe '#before_filter' do + let(:params) do + { :called => [], + :before_filter_calls => 0 } + end + before(:all) do class ServiceWithHooks def verify_before - @before_filter_called = true + @called << :verify_before + @before_filter_calls += 1 end - end - end - after(:all) do - class ServiceWithHooks - undef :verify_before + def foo + @called << :foo + end end end - let(:params) { { :before_filter_called => false } } - before { ServiceWithHooks.before_filter(:verify_before) } - - context 'when defining a before filter' do - before { subject.run_before_filters! } + before do + ServiceWithHooks.before_filter(:verify_before) + ServiceWithHooks.before_filter(:verify_before) + ServiceWithHooks.before_filter(:foo) + end - its('class.before_filters') { should include(:verify_before) } - its(:before_filter_called) { should be_true } + it 'calls filters in the order they were defined' do + subject.__send__(:run_filters) { subject.endpoint } + subject.called.should eq [ :verify_before, :foo, :endpoint ] + subject.before_filter_calls.should eq 1 end + end - context 'when multiple methods are defined' do - pending + describe '#after_filter' do + let(:params) do + { :called => [], + :after_filter_calls => 0 } end - context 'when same method is added' do - before { ServiceWithHooks.before_filter(:verify_before) } - before { ServiceWithHooks.before_filter(:verify_before) } - before { ServiceWithHooks.before_filter(:verify_before) } + before(:all) do + class ServiceWithHooks + def verify_after + @called << :verify_after + @after_filter_calls += 1 + end - it 'calls the method callback a single time' do - subject.should_receive(:verify_before).once - subject.run_before_filters! + def foo + @called << :foo + end end end + + before do + ServiceWithHooks.after_filter(:verify_after) + ServiceWithHooks.after_filter(:verify_after) + ServiceWithHooks.after_filter(:foo) + end + + it 'calls filters in the order they were defined' do + subject.__send__(:run_filters) { subject.endpoint } + subject.called.should eq [ :endpoint, :verify_after, :foo ] + subject.after_filter_calls.should eq 1 + end end - describe '#after_filter' do + describe '#around_filter' do + let(:params) do + { :called => [] } + end + before(:all) do class ServiceWithHooks - def verify_after - @after_filter_called = true + def outer_around + @called << :outer_around_top + yield + @called << :outer_around_bottom + end + + def inner_around + @called << :inner_around_top + yield + @called << :inner_around_bottom end end end - after(:all) do - class ServiceWithHooks - undef :verify_after - end + before do + ServiceWithHooks.around_filter(:outer_around) + ServiceWithHooks.around_filter(:inner_around) + ServiceWithHooks.around_filter(:outer_around) + ServiceWithHooks.around_filter(:inner_around) + end + + it 'calls filters in the order they were defined' do + subject.__send__(:run_filters) { subject.endpoint } + subject.called.should eq([ :outer_around_top, + :inner_around_top, + :endpoint, + :inner_around_bottom, + :outer_around_bottom ]) end - let(:params) { { :after_filter_called => false } } + context 'when around_filter does not yield' do + before do + class ServiceWithHooks + def inner_around + @called << :inner_around + end + end + end + + before do + ServiceWithHooks.around_filter(:outer_around) + ServiceWithHooks.around_filter(:inner_around) + end - before { ServiceWithHooks.after_filter(:verify_after) } - before { subject.run_after_filters! } + it 'calls filters in the order they were defined' do + subject.should_not_receive(:endpoint) + subject.__send__(:run_filters) { subject.endpoint } + subject.called.should eq([ :outer_around_top, + :inner_around, + :outer_around_bottom ]) + end - its('class.after_filters') { should include(:verify_after) } - its(:after_filter_called) { should be_true } + end end + end From 1b80187da135aa9d1a013c2432336fd0b18d6e6f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sat, 3 Nov 2012 22:16:51 -0600 Subject: [PATCH 0165/1191] Fix broken specs relating to introduction of filters --- lib/protobuf/rpc/client.rb | 14 +++++++------- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/service.rb | 6 +++--- lib/protobuf/rpc/stat.rb | 8 ++++---- spec/lib/protobuf/message_spec.rb | 1 + spec/lib/protobuf/rpc/service_dispatcher_spec.rb | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 052faa8b..8e71472e 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -103,14 +103,14 @@ def on_success=(callable) # c.on_failure {|err| ... } # end # - def method_missing(method, *params) + def method_missing(method_name, *params) service = options[:service] - unless service.rpc_method?(method) - log_error { sign_message("#{service.name}##{method.to_s} not rpc method, passing to super") } - super(method, *params) + unless service.rpc_method?(method_name) + log_error { sign_message("#{service.name}##{method_name.to_s} not rpc method, passing to super") } + super(method_name, *params) else - log_debug { sign_message("#{service.name}##{method.to_s}") } - rpc = service.rpcs[method.to_sym] + log_debug { sign_message("#{service.name}##{method_name.to_s}") } + rpc = service.rpcs[method_name.to_sym] options[:request_type] = rpc.request_type log_debug { sign_message("Request Type: #{options[:request_type].name}") } @@ -118,7 +118,7 @@ def method_missing(method, *params) options[:response_type] = rpc.response_type log_debug { sign_message("Response Type: #{options[:response_type].name}") } - options[:method] = method.to_s + options[:method] = method_name.to_s options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0] log_debug { sign_message("Request Data: #{options[:request].inspect}") } diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index d65a321b..d24ef775 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -51,7 +51,7 @@ def initialize_stats @stats = Protobuf::Rpc::Stat.new(:CLIENT) @stats.server = [@options[:port], @options[:host]] @stats.service = @options[:service].name - @stats.method = @options[:method].to_s + @stats.method_name = @options[:method].to_s rescue => ex log_exception(ex) fail(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index e2a1df95..0a5efe6c 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -6,16 +6,16 @@ module Protobuf module Rpc - include Protobuf::Rpc::ServiceCallbacks - # Object to encapsulate the request/response types for a given service method # RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) class Service + include Protobuf::Rpc::ServiceCallbacks include Protobuf::Logger::LogMethods - attr_reader :response + + attr_reader :response, :rpc DEFAULT_HOST = '127.0.0.1'.freeze DEFAULT_PORT = 9399 diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 9e58fcc6..d6c06b9f 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -5,7 +5,7 @@ module Protobuf module Rpc class Stat attr_accessor :mode, :start_time, :end_time, :request_size, :dispatcher - attr_accessor :response_size, :client, :server, :service, :method + attr_accessor :response_size, :client, :server, :service, :method_name MODES = [:SERVER, :CLIENT].freeze @@ -22,8 +22,8 @@ def client @client ? "#{@client[:ip]}:#{@client[:port]}" : nil end - def method - @method ||= @dispatcher.try(:callable_method).try(:name) + def method_name + @method_name ||= @dispatcher.try(:service).try(:rpc) end def server=(peer) @@ -52,7 +52,7 @@ def stop end def rpc - service && method ? "#{service}##{method}" : nil + service && method_name ? "#{service}##{method_name}" : nil end def elapsed_time diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index cdf9235f..8a9a4586 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -96,6 +96,7 @@ context 'when tag does not reference a field' do it 'returns nil' do + pending 'need to implement a range-limiting array sub-class for field access' subject.get_field_by_tag(-1).should be_nil end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 5556ce77..1a0fed01 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -18,7 +18,7 @@ context 'creating a new dispatcher' do its(:service) { should be_instance_of service_name.constantize } - its(:callable_method) { should be_a(Method) } + its(:callable_method) { should respond_to(:call)} its(:outer_request) { should eq wrapper } its(:error) { should be_nil } From e299a1ebf4ac93f450b33f67bf2fe7d7b4e865e3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sat, 3 Nov 2012 22:24:34 -0600 Subject: [PATCH 0166/1191] Use __send__ instead of method object call in Service#callable_rpc_method --- lib/protobuf/rpc/service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 0a5efe6c..d4af5364 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -140,7 +140,7 @@ def rpcs # is why we wrap the method call). # def callable_rpc_method(method_name) - lambda { run_filters { method(method_name).call } } + lambda { run_filters { __send__(method_name) } } end private From f82ceca88b962a02bcf033254c705734d28d17e6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 4 Nov 2012 17:12:37 -0700 Subject: [PATCH 0167/1191] Add support for only/except options that can be passed in as final filter value --- lib/protobuf/rpc/service_callbacks.rb | 65 ++++++++++-------- .../protobuf/rpc/service_callbacks_spec.rb | 66 +++++++++++++++++-- 2 files changed, 101 insertions(+), 30 deletions(-) diff --git a/lib/protobuf/rpc/service_callbacks.rb b/lib/protobuf/rpc/service_callbacks.rb index 5b4e7981..705a0d56 100644 --- a/lib/protobuf/rpc/service_callbacks.rb +++ b/lib/protobuf/rpc/service_callbacks.rb @@ -29,6 +29,11 @@ def filters private + def define_filter(type, filter, options = {}) + return if filter_defined?(type, filter) + filters[type] << options.merge({ :name => filter }) + remember_filter(type, filter) + end def defined_filters @defined_filters ||= Hash.new { |h,k| h[k] = Set.new } @@ -51,11 +56,9 @@ def remember_filter(type, filter) # TODO add support for only/except sub-filters # def set_filters(type, *args) - opts = args.last.is_a?(Hash) ? args.pop : {} + options = args.last.is_a?(Hash) ? args.pop : {} args.each do |filter| - next if filter_defined?(type, filter) - filters[type] << filter - remember_filter(type, filter) + define_filter(type, filter, options) end end @@ -65,23 +68,34 @@ module InstanceMethods private - # Enumerator block given to Set#each to simply call the given filter. - # See #run_after_filters, #run_before_filters - # - def enumerated_filter_call - lambda { |filter| __send__(filter) } - end - # Get back to class filters. # def filters self.class.filters end - # Loop over the after filters and invoke them. + def invoke_filter?(rpc_method, filter) + return invoke_via_only?(rpc_method, filter) \ + && invoke_via_except?(rpc_method, filter) + end + + def invoke_via_except?(rpc_method, filter) + except = [ filter.fetch(:except) { [] } ].flatten + return except.empty? || ! except.include?(rpc_method) + end + + def invoke_via_only?(rpc_method, filter) + only = [ filter.fetch(:only) { [] } ].flatten + return only.empty? || only.include?(rpc_method) + end + + # Loop over the unwrapped filters and invoke them. An unwrapped filter + # is either a before or after filter, not an around filter. # - def run_after_filters - filters[:after].each(&enumerated_filter_call) + def run_unwrapped_filters(unwrapped_filters, rpc_method) + unwrapped_filters.each do |filter| + __send__(filter[:name]) if invoke_filter?(rpc_method, filter) + end end # Reverse build a chain of around filters. To implement an around chain, @@ -113,26 +127,25 @@ def run_after_filters # end # end # - def run_around_filters(final) + def run_around_filters(rpc_method) + final = lambda { __send__(rpc_method) } filters[:around].reverse.inject(final) { |previous, filter| - lambda { __send__(filter, &previous) } + if invoke_filter?(rpc_method, filter) + lambda { __send__(filter[:name], &previous) } + else + previous + end }.call end - # Loop over the before filters and invoke them. - # - def run_before_filters - filters[:before].each(&enumerated_filter_call) - end - # Entry method to call each filter type in the appropriate order. This should # be used instead of the other run methods directly. # - def run_filters(&final) - run_before_filters - run_around_filters(final) - run_after_filters + def run_filters(rpc_method) + run_unwrapped_filters(filters[:before], rpc_method) + run_around_filters(rpc_method) + run_unwrapped_filters(filters[:after], rpc_method) end end diff --git a/spec/lib/protobuf/rpc/service_callbacks_spec.rb b/spec/lib/protobuf/rpc/service_callbacks_spec.rb index fffdbf0f..aab41678 100644 --- a/spec/lib/protobuf/rpc/service_callbacks_spec.rb +++ b/spec/lib/protobuf/rpc/service_callbacks_spec.rb @@ -53,10 +53,68 @@ def foo end it 'calls filters in the order they were defined' do - subject.__send__(:run_filters) { subject.endpoint } + subject.__send__(:run_filters, :endpoint) subject.called.should eq [ :verify_before, :foo, :endpoint ] subject.before_filter_calls.should eq 1 end + + context 'when filter is configured with "only"' do + before(:all) do + class ServiceWithHooks + def endpoint_with_verify + @called << :endpoint_with_verify + end + end + end + + before do + ServiceWithHooks.clear_filters! + ServiceWithHooks.before_filter(:verify_before, :only => :endpoint_with_verify) + end + + context 'when invoking a method defined in "only" option' do + it 'invokes the filter' do + subject.__send__(:run_filters, :endpoint_with_verify) + subject.called.should eq [ :verify_before, :endpoint_with_verify ] + end + end + + context 'when invoking a method not defined by "only" option' do + it 'does not invoke the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :endpoint ] + end + end + end + + context 'when filter is configured with "except"' do + before(:all) do + class ServiceWithHooks + def endpoint_without_verify + @called << :endpoint_without_verify + end + end + end + + before do + ServiceWithHooks.clear_filters! + ServiceWithHooks.before_filter(:verify_before, :except => :endpoint_without_verify) + end + + context 'when invoking a method not defined in "except" option' do + it 'invokes the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :verify_before, :endpoint ] + end + end + + context 'when invoking a method defined by "except" option' do + it 'does not invoke the filter' do + subject.__send__(:run_filters, :endpoint_without_verify) + subject.called.should eq [ :endpoint_without_verify ] + end + end + end end describe '#after_filter' do @@ -85,7 +143,7 @@ def foo end it 'calls filters in the order they were defined' do - subject.__send__(:run_filters) { subject.endpoint } + subject.__send__(:run_filters, :endpoint) subject.called.should eq [ :endpoint, :verify_after, :foo ] subject.after_filter_calls.should eq 1 end @@ -120,7 +178,7 @@ def inner_around end it 'calls filters in the order they were defined' do - subject.__send__(:run_filters) { subject.endpoint } + subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :outer_around_top, :inner_around_top, :endpoint, @@ -144,7 +202,7 @@ def inner_around it 'calls filters in the order they were defined' do subject.should_not_receive(:endpoint) - subject.__send__(:run_filters) { subject.endpoint } + subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :outer_around_top, :inner_around, :outer_around_bottom ]) From 020ebcbb6835d56ddaff899a77e615b0a3bf5172 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 4 Nov 2012 17:15:47 -0700 Subject: [PATCH 0168/1191] Fix Service#callable_rpc_method to send method name to run_filters --- lib/protobuf/rpc/service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index d4af5364..bcc31564 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -140,7 +140,7 @@ def rpcs # is why we wrap the method call). # def callable_rpc_method(method_name) - lambda { run_filters { __send__(method_name) } } + lambda { run_filters(method_name) } end private From 8940c280094bcee31f77e80b0732b23fa188e050 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 4 Nov 2012 17:20:07 -0700 Subject: [PATCH 0169/1191] Rename service 'callbacks' as 'filters' for clarity --- lib/protobuf/rpc/service.rb | 4 ++-- .../rpc/{service_callbacks.rb => service_filters.rb} | 7 +++---- .../{service_callbacks_spec.rb => service_filters_spec.rb} | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) rename lib/protobuf/rpc/{service_callbacks.rb => service_filters.rb} (95%) rename spec/lib/protobuf/rpc/{service_callbacks_spec.rb => service_filters_spec.rb} (98%) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index bcc31564..cf89e0e3 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,7 +1,7 @@ require 'protobuf/logger' require 'protobuf/rpc/client' require 'protobuf/rpc/error' -require 'protobuf/rpc/service_callbacks' +require 'protobuf/rpc/service_filters' module Protobuf module Rpc @@ -11,7 +11,7 @@ module Rpc RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) class Service - include Protobuf::Rpc::ServiceCallbacks + include Protobuf::Rpc::ServiceFilters include Protobuf::Logger::LogMethods diff --git a/lib/protobuf/rpc/service_callbacks.rb b/lib/protobuf/rpc/service_filters.rb similarity index 95% rename from lib/protobuf/rpc/service_callbacks.rb rename to lib/protobuf/rpc/service_filters.rb index 705a0d56..0dff6963 100644 --- a/lib/protobuf/rpc/service_callbacks.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -1,12 +1,11 @@ module Protobuf module Rpc - module ServiceCallbacks - include ActiveSupport::Callbacks + module ServiceFilters def self.included(other) other.class_eval do - extend Protobuf::Rpc::ServiceCallbacks::ClassMethods - include Protobuf::Rpc::ServiceCallbacks::InstanceMethods + extend Protobuf::Rpc::ServiceFilters::ClassMethods + include Protobuf::Rpc::ServiceFilters::InstanceMethods end end diff --git a/spec/lib/protobuf/rpc/service_callbacks_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb similarity index 98% rename from spec/lib/protobuf/rpc/service_callbacks_spec.rb rename to spec/lib/protobuf/rpc/service_filters_spec.rb index aab41678..a9b7743b 100644 --- a/spec/lib/protobuf/rpc/service_callbacks_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' class ServiceWithHooks - include Protobuf::Rpc::ServiceCallbacks + include Protobuf::Rpc::ServiceFilters # Initialize the hash keys as instance vars def initialize(ivar_hash) @@ -23,7 +23,7 @@ def self.clear_filters! end end -describe Protobuf::Rpc::ServiceCallbacks do +describe Protobuf::Rpc::ServiceFilters do subject { ServiceWithHooks.new(params) } after(:each) { ServiceWithHooks.clear_filters! } From e3e29e5faefe3ee54a1c888483178794d128c357 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 4 Nov 2012 17:35:15 -0700 Subject: [PATCH 0170/1191] Cleanup service filter spec (rename internal test class) --- spec/lib/protobuf/rpc/service_filters_spec.rb | 67 +++++++++---------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index a9b7743b..7e88b780 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -1,10 +1,13 @@ require 'spec_helper' -class ServiceWithHooks +class FilterTest include Protobuf::Rpc::ServiceFilters + attr_accessor :called + # Initialize the hash keys as instance vars def initialize(ivar_hash) + @called = [] ivar_hash.each_pair do |key, value| self.class.class_eval do attr_accessor key @@ -24,17 +27,14 @@ def self.clear_filters! end describe Protobuf::Rpc::ServiceFilters do - subject { ServiceWithHooks.new(params) } - after(:each) { ServiceWithHooks.clear_filters! } + subject { FilterTest.new(params) } + after(:each) { FilterTest.clear_filters! } describe '#before_filter' do - let(:params) do - { :called => [], - :before_filter_calls => 0 } - end + let(:params) { { :before_filter_calls => 0 } } before(:all) do - class ServiceWithHooks + class FilterTest def verify_before @called << :verify_before @before_filter_calls += 1 @@ -47,9 +47,9 @@ def foo end before do - ServiceWithHooks.before_filter(:verify_before) - ServiceWithHooks.before_filter(:verify_before) - ServiceWithHooks.before_filter(:foo) + FilterTest.before_filter(:verify_before) + FilterTest.before_filter(:verify_before) + FilterTest.before_filter(:foo) end it 'calls filters in the order they were defined' do @@ -60,7 +60,7 @@ def foo context 'when filter is configured with "only"' do before(:all) do - class ServiceWithHooks + class FilterTest def endpoint_with_verify @called << :endpoint_with_verify end @@ -68,8 +68,8 @@ def endpoint_with_verify end before do - ServiceWithHooks.clear_filters! - ServiceWithHooks.before_filter(:verify_before, :only => :endpoint_with_verify) + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :only => :endpoint_with_verify) end context 'when invoking a method defined in "only" option' do @@ -89,7 +89,7 @@ def endpoint_with_verify context 'when filter is configured with "except"' do before(:all) do - class ServiceWithHooks + class FilterTest def endpoint_without_verify @called << :endpoint_without_verify end @@ -97,8 +97,8 @@ def endpoint_without_verify end before do - ServiceWithHooks.clear_filters! - ServiceWithHooks.before_filter(:verify_before, :except => :endpoint_without_verify) + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :except => :endpoint_without_verify) end context 'when invoking a method not defined in "except" option' do @@ -118,13 +118,10 @@ def endpoint_without_verify end describe '#after_filter' do - let(:params) do - { :called => [], - :after_filter_calls => 0 } - end + let(:params) { { :after_filter_calls => 0 } } before(:all) do - class ServiceWithHooks + class FilterTest def verify_after @called << :verify_after @after_filter_calls += 1 @@ -137,9 +134,9 @@ def foo end before do - ServiceWithHooks.after_filter(:verify_after) - ServiceWithHooks.after_filter(:verify_after) - ServiceWithHooks.after_filter(:foo) + FilterTest.after_filter(:verify_after) + FilterTest.after_filter(:verify_after) + FilterTest.after_filter(:foo) end it 'calls filters in the order they were defined' do @@ -150,12 +147,10 @@ def foo end describe '#around_filter' do - let(:params) do - { :called => [] } - end + let(:params) { {} } before(:all) do - class ServiceWithHooks + class FilterTest def outer_around @called << :outer_around_top yield @@ -171,10 +166,10 @@ def inner_around end before do - ServiceWithHooks.around_filter(:outer_around) - ServiceWithHooks.around_filter(:inner_around) - ServiceWithHooks.around_filter(:outer_around) - ServiceWithHooks.around_filter(:inner_around) + FilterTest.around_filter(:outer_around) + FilterTest.around_filter(:inner_around) + FilterTest.around_filter(:outer_around) + FilterTest.around_filter(:inner_around) end it 'calls filters in the order they were defined' do @@ -188,7 +183,7 @@ def inner_around context 'when around_filter does not yield' do before do - class ServiceWithHooks + class FilterTest def inner_around @called << :inner_around end @@ -196,8 +191,8 @@ def inner_around end before do - ServiceWithHooks.around_filter(:outer_around) - ServiceWithHooks.around_filter(:inner_around) + FilterTest.around_filter(:outer_around) + FilterTest.around_filter(:inner_around) end it 'calls filters in the order they were defined' do From 550df49e18ad444854cdeb0642ef979dc3bd8f39 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 4 Nov 2012 17:35:49 -0700 Subject: [PATCH 0171/1191] Add support for false return in `before_filter` to short-circuit rpc method call --- lib/protobuf/rpc/service_filters.rb | 17 +++++++++----- spec/lib/protobuf/rpc/service_filters_spec.rb | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 0dff6963..8b9eeb83 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -91,10 +91,15 @@ def invoke_via_only?(rpc_method, filter) # Loop over the unwrapped filters and invoke them. An unwrapped filter # is either a before or after filter, not an around filter. # - def run_unwrapped_filters(unwrapped_filters, rpc_method) + def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = false) unwrapped_filters.each do |filter| - __send__(filter[:name]) if invoke_filter?(rpc_method, filter) + if invoke_filter?(rpc_method, filter) + rv = __send__(filter[:name]) + return false if stop_on_false_return && rv === false + end end + + return true end # Reverse build a chain of around filters. To implement an around chain, @@ -142,9 +147,11 @@ def run_around_filters(rpc_method) # be used instead of the other run methods directly. # def run_filters(rpc_method) - run_unwrapped_filters(filters[:before], rpc_method) - run_around_filters(rpc_method) - run_unwrapped_filters(filters[:after], rpc_method) + continue = run_unwrapped_filters(filters[:before], rpc_method, true) + if continue + run_around_filters(rpc_method) + run_unwrapped_filters(filters[:after], rpc_method) + end end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 7e88b780..e9511b02 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -115,6 +115,28 @@ def endpoint_without_verify end end end + + context 'when filter returns false' do + before(:all) do + class FilterTest + def short_circuit_filter + @called << :short_circuit_filter + return false + end + end + end + + before do + FilterTest.clear_filters! + FilterTest.before_filter(:short_circuit_filter) + end + + it 'does not invoke the rpc method' do + subject.should_not_receive(:endpoint) + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :short_circuit_filter ] + end + end end describe '#after_filter' do From eaa21972e80f914a317b5bac45d44547b0607c99 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 5 Nov 2012 10:14:44 -0700 Subject: [PATCH 0172/1191] Add support for if/unless filter options Can either supply a method name as symbol/string or a callable object such as proc or lambda. --- lib/protobuf/rpc/service_filters.rb | 90 ++++++++++++- spec/lib/protobuf/rpc/service_filters_spec.rb | 127 +++++++++++++++++- 2 files changed, 212 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 8b9eeb83..d41a6682 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -30,7 +30,7 @@ def filters def define_filter(type, filter, options = {}) return if filter_defined?(type, filter) - filters[type] << options.merge({ :name => filter }) + filters[type] << options.merge({ :callable => filter }) remember_filter(type, filter) end @@ -73,28 +73,86 @@ def filters self.class.filters end + # Predicate which uses the filter options to determine if the filter + # should be called. Specifically checks the :if, :unless, :only, and :except + # options for every filter. Each option check is expected to return false + # if the filter should not be invoked, true if invocation should occur. + # def invoke_filter?(rpc_method, filter) return invoke_via_only?(rpc_method, filter) \ - && invoke_via_except?(rpc_method, filter) + && invoke_via_except?(rpc_method, filter) \ + && invoke_via_if?(rpc_method, filter) \ + && invoke_via_unless?(rpc_method, filter) end + # If the target rpc endpoint method is listed under an :except option, + # return false to indicate that the filter should not be invoked. Any + # other target rpc endpoint methods not listed should be invoked. + # This option is the opposite of :only. + # + # Value should be a symbol/string or an array of symbols/strings. + # def invoke_via_except?(rpc_method, filter) except = [ filter.fetch(:except) { [] } ].flatten return except.empty? || ! except.include?(rpc_method) end + # Invoke the given :if callable (if any) and return its return value. + # Used by `invoke_filter?` which expects a true/false + # return value to determine if we should invoke the target filter. + # + # Value can either be a symbol/string indicating an instance method to call + # or an object that responds to `call`. + # + def invoke_via_if?(rpc_method, filter) + if_check = filter.fetch(:if) { lambda { |service| return true } } + do_invoke = case + when if_check.nil? then + true + else + call_or_send(if_check) + end + + return do_invoke + end + + # If the target rpc endpoint method is listed in the :only option, + # it should be invoked. Any target rpc endpoint methods not listed in this + # option should not be invoked. This option is the opposite of :except. + # + # Value should be a symbol/string or an array of symbols/strings. + # def invoke_via_only?(rpc_method, filter) only = [ filter.fetch(:only) { [] } ].flatten return only.empty? || only.include?(rpc_method) end + # Invoke the given :unless callable (if any) and return the opposite + # of it's return value. Used by `invoke_filter?` which expects a true/false + # return value to determine if we should invoke the target filter. + # + # Value can either be a symbol/string indicating an instance method to call + # or an object that responds to `call`. + # + def invoke_via_unless?(rpc_method, filter) + unless_check = filter.fetch(:unless) { lambda { |service| return false } } + skip_invoke = case + when unless_check.nil? then + false + else + call_or_send(unless_check) + end + + return ! skip_invoke + end + # Loop over the unwrapped filters and invoke them. An unwrapped filter # is either a before or after filter, not an around filter. # def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = false) unwrapped_filters.each do |filter| if invoke_filter?(rpc_method, filter) - rv = __send__(filter[:name]) + rv = call_or_send(filter[:callable]) return false if stop_on_false_return && rv === false end end @@ -135,7 +193,7 @@ def run_around_filters(rpc_method) final = lambda { __send__(rpc_method) } filters[:around].reverse.inject(final) { |previous, filter| if invoke_filter?(rpc_method, filter) - lambda { __send__(filter[:name], &previous) } + lambda { call_or_send(filter[:callable], &previous) } else previous end @@ -154,6 +212,30 @@ def run_filters(rpc_method) end end + # Call the object if it is callable, otherwise invoke the method using + # __send__ assuming that we respond_to it. Return the call's return value. + # + def call_or_send(callable, &block) + rv = case + when callable.respond_to?(:call) then + if callable.arity == 1 + callable.call(self, &block) + else + callable.call(&block) + end + when respond_to?(callable, true) then + if method(callable).arity == 1 + __send__(callable, self, &block) + else + __send__(callable, &block) + end + else + raise "Object #{callable} is not callable" + end + + return rv + end + end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index e9511b02..72e9c994 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -35,6 +35,7 @@ def self.clear_filters! before(:all) do class FilterTest + private def verify_before @called << :verify_before @before_filter_calls += 1 @@ -61,6 +62,7 @@ def foo context 'when filter is configured with "only"' do before(:all) do class FilterTest + private def endpoint_with_verify @called << :endpoint_with_verify end @@ -90,6 +92,7 @@ def endpoint_with_verify context 'when filter is configured with "except"' do before(:all) do class FilterTest + private def endpoint_without_verify @called << :endpoint_without_verify end @@ -116,9 +119,128 @@ def endpoint_without_verify end end + context 'when filter is configured with "if"' do + before(:all) do + class FilterTest + private + def check_true; return true; end + def check_false; return false; end + def verify_before; @called << :verify_before; end + end + end + + context 'when "if" option is a method that returns true' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :if => :check_true) + end + + it 'invokes the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :verify_before, :endpoint ] + end + end + + context 'when "if" option is a callable that returns true' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :if => lambda { |service| true }) + end + + it 'invokes the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :verify_before, :endpoint ] + end + end + + context 'when "if" option is a method that returns false' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :if => :check_false) + end + + it 'skips the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :endpoint ] + end + end + + context 'when "if" option is a callable that returns false' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :if => lambda { |service| false }) + end + + it 'skips the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :endpoint ] + end + end + end + + context 'when filter is configured with "unless"' do + before(:all) do + class FilterTest + private + def check_true; return true; end + def check_false; return false; end + def verify_before; @called << :verify_before; end + end + end + + context 'when "unless" option is a method that returns false' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :unless => :check_false) + end + + it 'invokes the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :verify_before, :endpoint ] + end + end + + context 'when "unless" option is a callable that returns true' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :unless => lambda { |service| false }) + end + + it 'invokes the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :verify_before, :endpoint ] + end + end + + context 'when "unless" option is a method that returns false' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :unless => :check_true) + end + + it 'skips the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :endpoint ] + end + end + + context 'when "unless" option is a callable that returns false' do + before do + FilterTest.clear_filters! + FilterTest.before_filter(:verify_before, :unless => lambda { |service| true }) + end + + it 'skips the filter' do + subject.__send__(:run_filters, :endpoint) + subject.called.should eq [ :endpoint ] + end + end + end + context 'when filter returns false' do before(:all) do class FilterTest + private def short_circuit_filter @called << :short_circuit_filter return false @@ -144,6 +266,7 @@ def short_circuit_filter before(:all) do class FilterTest + private def verify_after @called << :verify_after @after_filter_calls += 1 @@ -173,6 +296,7 @@ def foo before(:all) do class FilterTest + private def outer_around @called << :outer_around_top yield @@ -206,6 +330,7 @@ def inner_around context 'when around_filter does not yield' do before do class FilterTest + private def inner_around @called << :inner_around end @@ -217,7 +342,7 @@ def inner_around FilterTest.around_filter(:inner_around) end - it 'calls filters in the order they were defined' do + it 'cancels calling the rest of the filters and the endpoint' do subject.should_not_receive(:endpoint) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :outer_around_top, From 7c0ea6d6e0a52c10b2def0cdaf77955db814ac69 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 5 Nov 2012 15:26:50 -0700 Subject: [PATCH 0173/1191] Bump version 2.1.0. Add support for service filters. --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1cede2ab..732bb86b 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,69 @@ end This means that the client's `on_failure` callback will be invoked instead of the `on_success` callback. Read more below on client callbacks. One drawback to the `rpc_failed` approach is that it does not short-circuit the rest of the method. This means that you must explicitly return from the method if you do not wish the remainder to be executed. +### Service Filters + +Service Filters provides ActionController-style filter support to service instances, specifically adding `before_filter`, `after_filter`, and `around_filter`. + +```ruby +class Foo::UserService < ::Protobuf::Rpc::Service + before_filter :start_request_timer + after_filter :end_request_timer + around_filter :benchmark_request + + # Provide a list of rpc methods to call (or exclude calling) for the given filter(s). + # The following two filters are essentially equivalent. + before_filter :verify_user_present, :only => [ :update, :delete ] + before_filter :verify_user_present, :except => [ :find, :create ] + + # Using if/unless filters options to achieve the same goal, reporting a login after the login has been processed. + # Note that you can provide a method name or lambda, but you must return a boolean value. + after_filter :report_login, :only => :login, :if => :user_found? + after_filter :report_login, :only => :login, :if => lambda { |service| service.response.user_guid.present? } + after_filter :report_login, :only => :login, :unless => :user_missing? + after_filter :report_login, :only => :login, :unless => lambda { |service| service.response.user_guid.empty? } + + #... rpc instance methods + + private + + def start_request_timer + @time_start = Time.now + end + + def end_request_timer + @time_end = Time.now + log_info { ... } + end + + def benchmark_request + Benchmark.benchmark do + yield + end + end +end +``` + +#### Halting execution of rpc request inside a filter + +__Around Filters__ – Inside of an around filter, if you wish to halt request processing and return, simply do not `yield` the block. Since the filter is implemented as an instance method, you can use `rpc_failed` or `respond_with` just like you can in the endpoint methods. + +__Before Filters__ – Returning `false` from a before filter will cancel any other filter calls which would run afterwards, as well as canceling invocation of the service method. Note: You must actually return false, not just a "falsey" value such as nil. + +__After Filters__ – There is no request shortcutting since the after filter runs after the request. Duh. + +#### Filter options + +The following options can be applied to any of the filters as the final argument in the filter configuration. (See example above). + +__:if__ – The object supplied to `:if` can either be a symbol/string indicating the instance method to call, or, an object that responds to `call`. The method or callable should return true or false indicating if the filter should be invoked or not. Akin to the `if` keyword. + +__:unless__ – The opposite of the `:if` option is `:unless`. Accepts the same object types. The method or callable should return true or false indicating if the filter should be invoked or not. Akin to the `unless` keyword. + +__:only__ – A string/symbol or Array of strings/symbols values that reference instance methods. The names of these methods should be the rpc method you wish to invoke the filter for. Methods not identified in this list would not have the filter applied. + +__:except__ – The opposite of the `:only` option. A string/symbol or Array of strings/symbols values that reference instance methods. The names of these methods should be the rpc method you wish to skip invokation of the given filter. Methods not identified in this list would have the filter applied. + ### Servers A service is nothing without being hooked up to a socket. It's the nerdy kid waiting by the telephone for someone to call without knowing that the phone company disconnected their house. Sad and pathetic. So hook the phone lines! diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b2d23adc..89d89763 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.0.3' + VERSION = '2.1.0' PROTOC_VERSION = '2.4.1' end From e0d6b70d632426f859256972e1f5bc3d9035b806 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 6 Nov 2012 12:11:17 -0700 Subject: [PATCH 0174/1191] Cleanup trap registration in cli --- lib/protobuf/cli.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 1ba409c3..d3168348 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -107,19 +107,15 @@ def configure_server_mode # TODO add signal handling for hot-reloading the application. def configure_traps debug_say 'Configuring traps' - trap_block = proc { - ::Protobuf::Logger.info { 'RPC Server shutting down...' } - @start_aborted = true - @runner.stop - ::Protobuf::Logger.info { 'Shutdown complete' } - } - - debug_say 'Registering INT', :blue - trap(:INT, &trap_block) - debug_say 'Registering QUIT', :blue - trap(:QUIT, &trap_block) - debug_say 'Registering TERM', :blue - trap(:TERM, &trap_block) + [:INT, :QUIT, :TERM].each do |signal| + debug_say "Registering signal trap for #{signal}", :blue + trap(signal) do + ::Protobuf::Logger.info { 'RPC Server shutting down...' } + @start_aborted = true + @runner.stop + ::Protobuf::Logger.info { 'Shutdown complete' } + end + end end # Say something if we're in debug mode. From d4619e646bbc1c5c52c0d6acadc4f23ec9bbf9f6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 6 Nov 2012 15:08:15 -0700 Subject: [PATCH 0175/1191] Fix format for default hash parameters --- lib/protobuf/field.rb | 2 +- lib/protobuf/message.rb | 8 ++++---- lib/protobuf/rpc/client.rb | 8 ++++---- lib/protobuf/rpc/connectors/em_client.rb | 4 ++-- lib/protobuf/rpc/servers/evented_runner.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/base_spec.rb | 8 ++++---- spec/support/server.rb | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index 5f27f9b2..f54b137d 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -41,7 +41,7 @@ module Field ::Protobuf::Field::BoolField ].freeze - def self.build(message_class, rule, type, name, tag, options={}) + def self.build(message_class, rule, type, name, tag, options = {}) field_class = type_message_or_enum(type) field_class.new(message_class, rule, type, name, tag, options) end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6945d9d9..9a393275 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -29,17 +29,17 @@ def self.extensions(range) end # Define a required field. Don't use this method directly. - def self.required(type, name, tag, options={}) + def self.required(type, name, tag, options = {}) define_field(:required, type, name, tag, options) end # Define a optional field. Don't use this method directly. - def self.optional(type, name, tag, options={}) + def self.optional(type, name, tag, options = {}) define_field(:optional, type, name, tag, options) end # Define a repeated field. Don't use this method directly. - def self.repeated(type, name, tag, options={}) + def self.repeated(type, name, tag, options = {}) define_field(:repeated, type, name, tag, options) end @@ -111,7 +111,7 @@ def self.get_ext_field_by_tag(tag) ## # Constructor # - def initialize(values={}) + def initialize(values = {}) values = values.to_hash @values = {} diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 8e71472e..5c463d2a 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -26,10 +26,10 @@ class Client # :request => request # }) # - def initialize(opts={}) - raise "Invalid client configuration. Service must be defined." if opts[:service].nil? - @connector = Connector.connector_for_client.new(opts) - log_debug { sign_message("Initialized with options: #{opts.inspect}") } + def initialize(options = {}) + raise "Invalid client configuration. Service must be defined." if options[:service].nil? + @connector = Connector.connector_for_client.new(options) + log_debug { sign_message("Initialized with options: #{options.inspect}") } end def log_signature diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index f785c72c..f69115fa 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -13,7 +13,7 @@ class EMClient < EM::Connection ## # Constructor # - def initialize(options={}, &failure_cb) + def initialize(options = {}, &failure_cb) @failure_cb = failure_cb @options = DEFAULT_OPTIONS.merge(options) @response_buffer = ::Protobuf::Rpc::Buffer.new(:read) @@ -27,7 +27,7 @@ def initialize(options={}, &failure_cb) ## # Class Methods # - def self.connect(options={}) + def self.connect(options = {}) options = DEFAULT_OPTIONS.merge(options) log_debug { sign_message("Connecting to server: #{options.inspect}") } EM.connect(options[:host], options[:port], self, options) diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index 34c8e3af..c1e2fe0d 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -6,10 +6,10 @@ def self.stop ::EventMachine.stop_event_loop if ::EventMachine.reactor_running? end - def self.run(server) + def self.run(options) # Startup and run the rpc server ::EventMachine.schedule do - ::EventMachine.start_server(server.host, server.port, ::Protobuf::Rpc::Evented::Server) + ::EventMachine.start_server(options[:host], options[:port], ::Protobuf::Rpc::Evented::Server) end # Join or start the reactor diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 693899fe..5dae92f6 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -2,11 +2,11 @@ describe Protobuf::Rpc::Connectors::Base do - let(:opts) do + let(:options) do { :timeout => 60 } end - subject { Protobuf::Rpc::Connectors::Base.new(opts) } + subject { Protobuf::Rpc::Connectors::Base.new(options) } describe "#send_request" do it "raising an error when 'send_request' is not overridden" do @@ -14,14 +14,14 @@ end it "does not raise error when 'send_request' is overridden" do - new_sub = Class.new(subject.class){ def send_request; end }.new(opts) + new_sub = Class.new(subject.class){ def send_request; end }.new(options) expect{ new_sub.send_request }.to_not raise_error end end describe '.new' do it 'assigns passed options and initializes success/failure callbacks' do - subject.options.should eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(opts)) + subject.options.should eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(options)) subject.success_cb.should be_nil subject.failure_cb.should be_nil end diff --git a/spec/support/server.rb b/spec/support/server.rb index 364b1df2..4530d14f 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -37,12 +37,12 @@ class StubServer attr_accessor :options - def initialize(opts = {}) + def initialize(options = {}) @running = true @options = OpenStruct.new({ :host => "127.0.0.1", :port => 9399, :delay => 0, - :server => Protobuf::Rpc::Evented::Server }.merge(opts)) + :server => Protobuf::Rpc::Evented::Server }.merge(options)) start yield self From 5e15f296cc3e358bb77dcb356a1b6960c6d4de04 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 6 Nov 2012 15:11:54 -0700 Subject: [PATCH 0176/1191] Normalize server options hash The CLI class is the only class knowledgeable about the default values for server options. Before this commit defaults were spread throughout the various rpc server classes. Now we just rely on direct hash access to get the values provided by the CLI. Removed some option hash lookups entirely since we are not going to be providing rpc_server arguments to change those options. Where appropriate turned those values into constants (e.g. socket server auto_collect_timeout), or simply turned the option extract into a method (e.g. zmq worker/broker protocol values). --- lib/protobuf/cli.rb | 2 +- lib/protobuf/rpc/servers/socket/server.rb | 21 ++++++------ lib/protobuf/rpc/servers/zmq/broker.rb | 32 ++++++++++--------- lib/protobuf/rpc/servers/zmq/server.rb | 8 ++--- lib/protobuf/rpc/servers/zmq/worker.rb | 10 +++--- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/broker_spec.rb | 8 +++-- .../protobuf/rpc/servers/zmq/worker_spec.rb | 4 +++ 9 files changed, 49 insertions(+), 40 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index d3168348..9ea47192 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -16,7 +16,7 @@ class CLI < ::Thor desc 'start APP_FILE', 'Run the RPC server in the given mode, preloading the given APP_FILE. This is the default task.' option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-o), :desc => 'Host to bind.' - option :port, :type => :numeric, :default => 9595, :aliases => %w(-p), :desc => 'Port to bind.' + option :port, :type => :numeric, :default => 9399, :aliases => %w(-p), :desc => 'Master Port to bind.' option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.' option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index eadf709f..684961e1 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -9,9 +9,11 @@ class Server include ::Protobuf::Rpc::Server include ::Protobuf::Logger::LogMethods + AUTO_COLLECT_TIMEOUT = 20 # seconds + def self.cleanup? # every 10 connections run a cleanup routine after closing the response - @threads.size > (@thread_threshold - 1) && (@threads.size % @thread_threshold) == 0 + @threads.size > (@threshold - 1) && (@threads.size % @threshold) == 0 end def self.cleanup_threads @@ -42,18 +44,17 @@ def self.new_worker(socket) end end - def self.run(opts = {}) + def self.run(options = {}) log_debug { sign_message("Run") } - host = opts.fetch(:host, "127.0.0.1") - port = opts.fetch(:port, 9399) - backlog = opts.fetch(:backlog, 100) - thread_threshold = opts.fetch(:thread_threshold, 100) - auto_collect_timeout = opts.fetch(:auto_collect_timeout, 20) + host = options[:host] + port = options[:port] + backlog = options[:backlog] + @threshold = options[:threshold] @threads = [] - @thread_threshold = thread_threshold @server = ::TCPServer.new(host, port) - raise "blah" if @server.closed? + raise "The server was unable to start properly." if @server.closed? + @server.listen(backlog) @working = [] @listen_fds = [@server] @@ -62,7 +63,7 @@ def self.run(opts = {}) while running? log_debug { sign_message("Waiting for connections") } - if ready_cnxns = IO.select(@listen_fds, [], [], auto_collect_timeout) + if ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) cnxns = ready_cnxns.first cnxns.each do |client| case diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 3fc79413..fa8facbf 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -8,13 +8,13 @@ class Broker include ::Protobuf::Rpc::Zmq::Util attr_reader :frontend, :backend, :poller, :context - ## + ## # Constructor # - def initialize(opts={}) + def initialize(options = {}) @context = ::ZMQ::Context.new - @frontend = setup_frontend(opts) - @backend = setup_backend(opts) + @frontend = setup_frontend(options) + @backend = setup_backend(options) @poller = setup_poller end @@ -52,27 +52,29 @@ def move_to(frontend_or_backend, socket) end end - def setup_backend(opts={}) - dealer_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) - host = dealer_options.fetch(:host, "127.0.0.1") - port = dealer_options.fetch(:port, 9400) - protocol = dealer_options.fetch(:protocol, "tcp") + def setup_backend(options = {}) + dealer_options = options.merge(:port => options[:port] + 1) + host = dealer_options[:host] + port = dealer_options[:port] zmq_backend = context.socket(::ZMQ::DEALER) - zmq_error_check(zmq_backend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) + zmq_error_check(zmq_backend.bind(bind_address(host, port))) zmq_backend end - def setup_frontend(opts={}) - host = opts.fetch(:host, "127.0.0.1") - port = opts.fetch(:port, 9399) - protocol = opts.fetch(:protocol, "tcp") + def setup_frontend(options = {}) + host = options[:host] + port = options[:port] zmq_frontend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_frontend.bind("#{protocol}://#{resolve_ip(host)}:#{port}")) + zmq_error_check(zmq_frontend.bind(bind_address(host, port))) zmq_frontend end + def bind_address(host, port) + "tcp://#{resolve_ip(host)}:#{port}" + end + def setup_poller zmq_poller = ::ZMQ::Poller.new zmq_poller.register(frontend, ::ZMQ::POLLIN) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 817d80af..8c9d423c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -11,12 +11,12 @@ class Server ## # Class Methods # - def self.run(opts = {}) + def self.run(options = {}) log_debug { sign_message("initializing broker") } - @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts) - local_worker_threads = opts.fetch(:threads, 5) + @broker = ::Protobuf::Rpc::Zmq::Broker.new(options) + local_worker_threads = options[:threads] - worker_options = opts.merge(:port => opts.fetch(:port, 9399) + 1) + worker_options = options.merge(:port => options[:port] + 1) log_debug { sign_message("starting server workers") } local_worker_threads.times do @threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run } diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 475221b5..c8d50e65 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -11,15 +11,13 @@ class Worker ## # Constructor # - def initialize(opts={}) - @options = opts - host = @options.fetch(:host) { "127.0.0.1" } - port = @options.fetch(:port) { 9400 } - protocol = @options.fetch(:protocol) { "tcp" } + def initialize(options = {}) + host = options[:host] + port = options[:port] @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REP) - zmq_error_check(@socket.connect("#{protocol}://#{resolve_ip(host)}:#{port}")) + zmq_error_check(@socket.connect("tcp://#{resolve_ip(host)}:#{port}")) @poller = ::ZMQ::Poller.new @poller.register(@socket, ::ZMQ::POLLIN) diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index a7b5aa5f..ed1d21ba 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -6,7 +6,7 @@ load "protobuf/socket.rb" ::Protobuf::Rpc::Connector.connector_for_client(true) Thread.abort_on_exception = true - server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) + server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } Thread.pass until Protobuf::Rpc::Socket::Server.running? end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index a8ef3f24..2a204074 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -6,7 +6,7 @@ load "protobuf/zmq.rb" ::Protobuf::Rpc::Connector.connector_for_client(true) Thread.abort_on_exception = true - server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) + server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100, :threads => 5) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } Thread.pass until Protobuf::Rpc::Zmq::Server.running? end diff --git a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb index 01301d06..a54e8d93 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe ::Protobuf::Rpc::Zmq::Broker do - before(:each) do - load 'protobuf/zmq.rb' + before(:each) do + load 'protobuf/zmq.rb' ::Protobuf::Rpc::Connector.connector_for_client(true) end @@ -10,6 +10,10 @@ subject.teardown end + subject do + described_class.new({ :host => '127.0.0.1', :port => 9399 }) + end + it 'sets up a context' do subject.context.should be_a(::ZMQ::Context) end diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index cbc47d46..4129e817 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -11,6 +11,10 @@ subject.instance_variable_get(:@zmq_context).terminate end + subject do + described_class.new({ :host => '127.0.0.1', :port => 9400 }) + end + it 'sets the context' do subject.instance_variable_get(:@zmq_context).should be_a(::ZMQ::Context) end From b7c4fae122897f5b25b6cca6135cb2832dba4cad Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 6 Nov 2012 15:40:01 -0700 Subject: [PATCH 0177/1191] De-memoize the connector_for_client Memoization of this value likely provides a very minute performance benefit while actually making it much more difficult to be flexible in configuring clients after a connector type has been chosen. --- lib/protobuf/rpc/connector.rb | 20 ++++++-------- spec/benchmark/tasks.rb | 3 --- spec/functional/evented_server_spec.rb | 1 - spec/functional/socket_server_spec.rb | 1 - spec/functional/zmq_server_spec.rb | 1 - spec/lib/protobuf/rpc/client_spec.rb | 1 - spec/lib/protobuf/rpc/connector_spec.rb | 27 +++++++------------ .../rpc/servers/socket_server_spec.rb | 8 +++--- .../protobuf/rpc/servers/zmq/broker_spec.rb | 1 - .../protobuf/rpc/servers/zmq/server_spec.rb | 1 - .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 3 +-- .../protobuf/rpc/servers/zmq/worker_spec.rb | 1 - 12 files changed, 21 insertions(+), 47 deletions(-) diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb index 4b96fb25..a19184ba 100644 --- a/lib/protobuf/rpc/connector.rb +++ b/lib/protobuf/rpc/connector.rb @@ -3,19 +3,15 @@ module Rpc class Connector # Returns a connector class for the pre-defined connector_type. - def self.connector_for_client(reload = false) - if reload || @_connector.nil? - @_connector = case ::Protobuf.connector_type - when :evented then - ::Protobuf::Rpc::Connectors::EventMachine - when :zmq then - ::Protobuf::Rpc::Connectors::Zmq - else - ::Protobuf::Rpc::Connectors::Socket - end + def self.connector_for_client + case ::Protobuf.connector_type + when :evented then + ::Protobuf::Rpc::Connectors::EventMachine + when :zmq then + ::Protobuf::Rpc::Connectors::Zmq + else + ::Protobuf::Rpc::Connectors::Socket end - - return @_connector end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 3b3017ea..56193af5 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -60,7 +60,6 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - ::Protobuf::Rpc::Connector.connector_for_client(true) EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| @@ -76,7 +75,6 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) def sock_client_em_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - ::Protobuf::Rpc::Connector.connector_for_client(true) EM.stop if EM.reactor_running? em_thread = Thread.new { EM.run } Thread.pass until EM.reactor_running? @@ -97,7 +95,6 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" - ::Protobuf::Rpc::Connector.connector_for_client(true) StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| client = ::Test::ResourceService.client(:port => 9399) diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 81309c87..657c0415 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -4,7 +4,6 @@ describe 'Functional EventMachine Client' do before(:each) do load 'protobuf/evented.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) end it 'runs fine when required fields are set' do diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index ed1d21ba..7a5a9528 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -4,7 +4,6 @@ describe 'Functional Socket Client' do before(:all) do load "protobuf/socket.rb" - ::Protobuf::Rpc::Connector.connector_for_client(true) Thread.abort_on_exception = true server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 2a204074..e69254ef 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -4,7 +4,6 @@ describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" - ::Protobuf::Rpc::Connector.connector_for_client(true) Thread.abort_on_exception = true server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100, :threads => 5) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 57cdfb24..e2239460 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -4,7 +4,6 @@ describe Protobuf::Rpc::Client do before(:each) do load 'protobuf/evented.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) end context "when using fiber based calls" do diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index 0f485482..e2dfa389 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -6,36 +6,27 @@ describe ::Protobuf::Rpc::Connector do describe '.connector_for_client(true)' do - after { described_class.instance_variable_set(:@_connector, nil) } + subject { described_class.connector_for_client } context 'Protobuf.connector_type is socket' do - it 'returns a socket connector class' do - ::Protobuf.connector_type = :socket - described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket - end + before { ::Protobuf.connector_type = :socket } + it { should eq ::Protobuf::Rpc::Connectors::Socket } end context 'Protobuf.connector_type is not a known value' do - it 'returns a socket connector class' do - ::Protobuf.stub(:connector_type).and_return('some value') - described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket - end + before { ::Protobuf.connector_type = :socket } + it { should eq ::Protobuf::Rpc::Connectors::Socket } end context 'Protobuf.connector_type is evented' do - it 'returns an eventmachine connector class' do - ::Protobuf.connector_type = :evented - described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::EventMachine - end + before { ::Protobuf.connector_type = :evented } + it { should eq ::Protobuf::Rpc::Connectors::EventMachine } end context 'Protobuf.connector_type is zmq' do - it 'returns a zmq connector class' do - ::Protobuf.connector_type = :zmq - described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Zmq - end + before { ::Protobuf.connector_type = :zmq } + it { should eq ::Protobuf::Rpc::Connectors::Zmq } end - end end diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index d70cf6a9..7f7e1d5e 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -5,14 +5,12 @@ require 'protobuf/socket' describe Protobuf::Rpc::Socket::Server do - before(:each) do - load 'protobuf/socket.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) + before(:each) do + load 'protobuf/socket.rb' end before(:all) do - load 'protobuf/socket.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) + load 'protobuf/socket.rb' Thread.abort_on_exception = true server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } diff --git a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb index a54e8d93..71f8d026 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb @@ -3,7 +3,6 @@ describe ::Protobuf::Rpc::Zmq::Broker do before(:each) do load 'protobuf/zmq.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) end after(:each) do diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 3d3f32c8..b0128ded 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -4,7 +4,6 @@ describe Protobuf::Rpc::Zmq::Server do before(:each) do load 'protobuf/zmq.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) end describe '.running?' do diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index f4f87cf2..90a2ef7c 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -6,8 +6,7 @@ class UtilTest describe ::Protobuf::Rpc::Zmq::Util do before(:each) do - load 'protobuf/zmq.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) + load 'protobuf/zmq.rb' end subject { UtilTest.new } diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 4129e817..962cff87 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -3,7 +3,6 @@ describe ::Protobuf::Rpc::Zmq::Worker do before(:each) do load 'protobuf/zmq.rb' - ::Protobuf::Rpc::Connector.connector_for_client(true) end after(:each) do From ae6ee39e7de80c3829a137593a9582e879fc9af0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 6 Nov 2012 15:42:05 -0700 Subject: [PATCH 0178/1191] Support PB_CLIENT_TYPE environment var to configure connector type Provided values can be socket, zmq, or evented. Values are case-insensitive. If a value is provided outside of this range the default type will be loaded instead (socket) while printing a warning. --- lib/protobuf.rb | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 0738dc09..897920d4 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -7,10 +7,10 @@ module Protobuf # See Protobuf#connector_type documentation. - VALID_CONNECTOR_TYPES = [ :socket, :zmq, :evented ].freeze + CONNECTORS = [ :socket, :zmq, :evented ].freeze # Default is Socket as it has no external dependencies. - DEFAULT_CONNECTOR_TYPE = :socket + DEFAULT_CONNECTOR = :socket module_function @@ -21,15 +21,14 @@ module Protobuf # Symbol value which denotes the type of connector to use # during client requests to an RPC server. def self.connector_type - @_connector_type ||= DEFAULT_CONNECTOR_TYPE + @_connector_type ||= DEFAULT_CONNECTOR end def self.connector_type=(type) - raise ArgumentError, 'Invalid connector type given' unless VALID_CONNECTOR_TYPES.include?(type) + raise ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) @_connector_type = type end - # GC Pause during server requests # # Default: false @@ -70,4 +69,18 @@ def self.print_deprecation_warnings=(value) require 'protobuf/rpc/client' require 'protobuf/rpc/service' -require 'protobuf/socket' + +env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') { + ::Protobuf::DEFAULT_CONNECTOR +}.to_s.downcase.strip.to_sym + +if ::Protobuf::CONNECTORS.include?(env_connector_type) + require "protobuf/#{env_connector_type}" +else + $stderr.puts <<-WARN + [WARNING] Require attempted on an invalid connector type '#{env_connector_type}'. + Falling back to default '#{::Protobuf::DEFAULT_CONNECTOR}' connector. + WARN + + require "protobuf/#{::Protobuf::DEFAULT_CONNECTOR}" +end From 9369f4833788481e28df2d22d6d3f9af50a6c946 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 6 Nov 2012 16:52:52 -0700 Subject: [PATCH 0179/1191] Bump version 2.1.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 89d89763..c6272d1a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.1.0' + VERSION = '2.1.1' PROTOC_VERSION = '2.4.1' end From 93a481de11f08d6df48445a192798e9eef2373e5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 5 Nov 2012 12:49:02 -0700 Subject: [PATCH 0180/1191] Use == on false evaluation, rename rv to return_value --- lib/protobuf/rpc/service_filters.rb | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index d41a6682..f3c92fd6 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -152,8 +152,8 @@ def invoke_via_unless?(rpc_method, filter) def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = false) unwrapped_filters.each do |filter| if invoke_filter?(rpc_method, filter) - rv = call_or_send(filter[:callable]) - return false if stop_on_false_return && rv === false + return_value = call_or_send(filter[:callable]) + return false if stop_on_false_return && return_value == false end end @@ -216,24 +216,24 @@ def run_filters(rpc_method) # __send__ assuming that we respond_to it. Return the call's return value. # def call_or_send(callable, &block) - rv = case - when callable.respond_to?(:call) then - if callable.arity == 1 - callable.call(self, &block) - else - callable.call(&block) - end - when respond_to?(callable, true) then - if method(callable).arity == 1 - __send__(callable, self, &block) - else - __send__(callable, &block) - end - else - raise "Object #{callable} is not callable" - end - - return rv + return_value = case + when callable.respond_to?(:call) then + if callable.arity == 1 + callable.call(self, &block) + else + callable.call(&block) + end + when respond_to?(callable, true) then + if method(callable).arity == 1 + __send__(callable, self, &block) + else + __send__(callable, &block) + end + else + raise "Object #{callable} is not callable" + end + + return return_value end end From c8aa32b0adc4d0da2d7e2279c43625f626ebb2b0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 7 Nov 2012 16:28:32 -0700 Subject: [PATCH 0181/1191] do not set in initializer any of the fields which have a nil value (and specs) --- lib/protobuf/message.rb | 5 ++--- spec/lib/protobuf/message_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 9a393275..5be18ac6 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -112,10 +112,9 @@ def self.get_ext_field_by_tag(tag) # Constructor # def initialize(values = {}) - values = values.to_hash @values = {} - - values.each { |name, val| self[name] = val} + values = values.to_hash + values.each { |name, val| self[name] = val unless val.nil? } end def initialized? diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 8a9a4586..880d7cd6 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -2,6 +2,24 @@ describe Protobuf::Message do + describe '#initialize' do + it "does not try to set attributes which have nil values" do + Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=") + test_enum = Test::EnumTestMessage.new(:non_default_enum => nil) + end + + it "takes a hash as an initialization argument" do + test_enum = Test::EnumTestMessage.new(:non_default_enum => 2) + test_enum.non_default_enum.should eq(2) + end + + it "initializes with an object that responds to #to_hash" do + hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) + test_enum = Test::EnumTestMessage.new(hashie_object) + test_enum.non_default_enum.should eq(2) + end + end + describe '#to_hash' do context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do From b7ce98c9ba1b25aa736c636432848d1dd818e4d0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 7 Nov 2012 16:28:53 -0700 Subject: [PATCH 0182/1191] bump to 2.1.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c6272d1a..62269e95 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.1.1' + VERSION = '2.1.2' PROTOC_VERSION = '2.4.1' end From b49855b4da63d42198c47e6041a3f4d7911e3189 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 7 Nov 2012 18:40:25 -0700 Subject: [PATCH 0183/1191] make Protobuf::EnumValue look like a Fixnum so arel visitor will treat it as a Fixnum --- lib/protobuf/enum_value.rb | 9 +++++++-- spec/lib/protobuf/enum_value_spec.rb | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index 82de1aa9..dafc1388 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -6,6 +6,11 @@ class EnumValue < SimpleDelegator attr_reader :parent_class, :name, :value + # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum + def class + Fixnum + end + def initialize(parent_class, name, value) @parent_class = parent_class @name = name @@ -14,7 +19,7 @@ def initialize(parent_class, name, value) end def inspect - "\#<#{self.class} #{@parent_class}::#{@name}=#{@value}>" + "\#" end def to_hash_value @@ -22,7 +27,7 @@ def to_hash_value end def to_s - @name.to_s + to_hash_value.to_s end end end diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb index 6676b222..a50c301d 100644 --- a/spec/lib/protobuf/enum_value_spec.rb +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -3,11 +3,12 @@ describe Protobuf::EnumValue do subject { Test::EnumTestType::ONE } + its(:class) { should eq Fixnum } its(:parent_class) { should eq Test::EnumTestType } its(:name) { should eq :ONE } its(:value) { should eq 1 } its(:to_hash_value) { should eq 1 } - its(:to_s) { should eq "ONE" } + its(:to_s) { should eq "1" } its(:inspect) { should eq '#' } end From 8eea06486ed83fa56bf4a775c8cc73ead6d48d03 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 8 Nov 2012 13:56:23 -0700 Subject: [PATCH 0184/1191] bump version for visitor enum --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 62269e95..ece4f0bd 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.1.2' + VERSION = '2.1.3' PROTOC_VERSION = '2.4.1' end From f035a6775692cf7e07f04e10f40e75a27a618a26 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 8 Nov 2012 15:03:02 -0700 Subject: [PATCH 0185/1191] Add rescue_from support to service filters --- lib/protobuf/rpc/service_filters.rb | 54 ++++++++--- spec/lib/protobuf/rpc/service_filters_spec.rb | 95 +++++++++++++++++++ 2 files changed, 134 insertions(+), 15 deletions(-) diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index f3c92fd6..b851ea0a 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -26,6 +26,20 @@ def filters @filters ||= Hash.new { |h,k| h[k] = [] } end + # Filters hash keyed based on filter type (e.g. :before, :after, :around), + # whose values are Sets. + # + def rescue_filters + @rescue_filters ||= {} + end + + def rescue_from(*ex_klasses, &block) + options = ex_klasses.last.is_a?(Hash) ? ex_klasses.pop : {} + callable = options.delete(:with) { block } + raise ArgumentError, 'Option :with missing from rescue_from options' if callable.nil? + ex_klasses.each { |ex_klass| rescue_filters[ex_klass] = callable } + end + private def define_filter(type, filter, options = {}) @@ -146,6 +160,10 @@ def invoke_via_unless?(rpc_method, filter) return ! skip_invoke end + def rescue_filters + self.class.rescue_filters + end + # Loop over the unwrapped filters and invoke them. An unwrapped filter # is either a before or after filter, not an around filter. # @@ -205,30 +223,36 @@ def run_around_filters(rpc_method) # be used instead of the other run methods directly. # def run_filters(rpc_method) - continue = run_unwrapped_filters(filters[:before], rpc_method, true) - if continue - run_around_filters(rpc_method) - run_unwrapped_filters(filters[:after], rpc_method) + run_rescue_filters do + continue = run_unwrapped_filters(filters[:before], rpc_method, true) + if continue + run_around_filters(rpc_method) + run_unwrapped_filters(filters[:after], rpc_method) + end + end + end + + def run_rescue_filters + if rescue_filters.keys.empty? + yield + else + begin + yield + rescue *rescue_filters.keys => ex + call_or_send(rescue_filters[ex.class], ex) + end end end # Call the object if it is callable, otherwise invoke the method using # __send__ assuming that we respond_to it. Return the call's return value. # - def call_or_send(callable, &block) + def call_or_send(callable, *args, &block) return_value = case when callable.respond_to?(:call) then - if callable.arity == 1 - callable.call(self, &block) - else - callable.call(&block) - end + callable.call(self, *args, &block) when respond_to?(callable, true) then - if method(callable).arity == 1 - __send__(callable, self, &block) - else - __send__(callable, &block) - end + __send__(callable, *args, &block) else raise "Object #{callable} is not callable" end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 72e9c994..29a47572 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -23,10 +23,12 @@ def endpoint def self.clear_filters! @defined_filters = nil @filters = nil + @rescue_filters = nil end end describe Protobuf::Rpc::ServiceFilters do + let(:params) { {} } subject { FilterTest.new(params) } after(:each) { FilterTest.clear_filters! } @@ -353,4 +355,97 @@ def inner_around end end + describe '#rescue_from' do + before do + class CustomError1 < StandardError; end + class CustomError2 < StandardError; end + class CustomError3 < StandardError; end + end + + before do + class FilterTest + private + + def filter_with_error1 + @called << :filter_with_error1 + raise CustomError1, 'Filter 1 failed' + end + + def filter_with_error2 + @called << :filter_with_error2 + raise CustomError1, 'Filter 2 failed' + end + + def filter_with_error3 + @called << :filter_with_error3 + raise CustomError3, 'Filter 3 failed' + end + + def custom_error_occurred(ex) + @ex_class = ex.class + @called << :custom_error_occurred + end + end + end + + let(:params) { { :ex_class => nil } } + + context 'when defining multiple errors with a given callback' do + before do + FilterTest.rescue_from(CustomError1, CustomError2, CustomError3, :with => :custom_error_occurred) + end + before { FilterTest.before_filter(:filter_with_error3) } + + it 'short-circuits the call stack' do + expect { + subject.should_not_receive(:endpoint) + subject.__send__(:run_filters, :endpoint) + subject.called.should eq([ :filter_with_error3, :custom_error_occurred ]) + subject.ex_class.should eq CustomError3 + }.to_not raise_error(CustomError3) + end + end + + context 'when defined with options' do + context 'when :with option is not given' do + specify do + expect { FilterTest.rescue_from(CustomError1) }.to raise_error(ArgumentError, /with/) + end + end + + context 'when error occurs inside filter' do + before { FilterTest.rescue_from(CustomError1, :with => :custom_error_occurred) } + before { FilterTest.before_filter(:filter_with_error1) } + + it 'short-circuits the call stack' do + expect { + subject.should_not_receive(:endpoint) + subject.__send__(:run_filters, :endpoint) + subject.called.should eq([ :filter_with_error1, :custom_error_occurred ]) + subject.ex_class.should eq CustomError1 + }.to_not raise_error(CustomError1) + end + end + end + + context 'when defined with block' do + before do + FilterTest.rescue_from(CustomError1) do |service, ex| + service.ex_class = ex.class + service.called << :block_rescue_handler + end + end + before { FilterTest.before_filter(:filter_with_error1) } + + it 'short-circuits the call stack' do + expect { + subject.should_not_receive(:endpoint) + subject.__send__(:run_filters, :endpoint) + subject.called.should eq([ :filter_with_error1, :block_rescue_handler ]) + subject.ex_class.should eq CustomError1 + }.to_not raise_error(CustomError1) + end + end + end + end From 4940ed0a5aca07c860f654fe62546bdd76b47168 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 10 Nov 2012 18:10:54 -0700 Subject: [PATCH 0186/1191] clean up structure of message and move respond_to_has_and_present? into core --- lib/protobuf/message.rb | 286 +++++++++++++++++------------- spec/lib/protobuf/message_spec.rb | 52 ++++++ 2 files changed, 213 insertions(+), 125 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 5be18ac6..d74d78bf 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -6,11 +6,19 @@ module Protobuf class Message - + ## + # Error Classes + # class FieldNotDefinedError < StandardError; end + ## + # Constants + # STRING_ENCODING = "ASCII-8BIT".freeze + ## + # Class Methods + # def self.all_fields @all_fields ||= begin all_fields_array = [] @@ -23,26 +31,6 @@ def self.all_fields end end - # Reserve field numbers for extensions. Don't use this method directly. - def self.extensions(range) - extension_fields.add_range(range) - end - - # Define a required field. Don't use this method directly. - def self.required(type, name, tag, options = {}) - define_field(:required, type, name, tag, options) - end - - # Define a optional field. Don't use this method directly. - def self.optional(type, name, tag, options = {}) - define_field(:optional, type, name, tag, options) - end - - # Define a repeated field. Don't use this method directly. - def self.repeated(type, name, tag, options = {}) - define_field(:repeated, type, name, tag, options) - end - # Define a field. Don't use this method directly. def self.define_field(rule, type, fname, tag, options) field_array = options[:extension] ? extension_fields : fields @@ -57,8 +45,13 @@ def self.define_field(rule, type, fname, tag, options) field_array[tag] = field_definition end - def self.extension_tag?(tag) - extension_fields.include_tag?(tag) + # Reserve field numbers for extensions. Don't use this method directly. + def self.extensions(range) + extension_fields.add_range(range) + end + + def self.extension_field_name_to_tag + @extension_fields_by_name ||= {} end # An extension field object. @@ -66,8 +59,8 @@ def self.extension_fields @extension_fields ||= ::Protobuf::Field::ExtensionFields.new end - def self.extension_field_name_to_tag - @extension_fields_by_name ||= {} + def self.extension_tag?(tag) + extension_fields.include_tag?(tag) end # A collection of field object. @@ -79,6 +72,18 @@ def self.field_name_to_tag @field_name_to_tag ||= {} end + def self.get_ext_field_by_name(name) + # Check if the name has been used before, if not then set it to the sym value + extension_fields[extension_field_name_to_tag[name.to_sym]] + rescue TypeError, NoMethodError => e + name = 'nil' if name.nil? + raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") + end + + def self.get_ext_field_by_tag(tag) + extension_fields[tag] + end + # Find a field object by +name+. def self.get_field_by_name(name) # Check if the name has been used before, if not then set it to the sym value @@ -96,16 +101,19 @@ def self.get_field_by_tag(tag) raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") end - def self.get_ext_field_by_name(name) - # Check if the name has been used before, if not then set it to the sym value - extension_fields[extension_field_name_to_tag[name.to_sym]] - rescue TypeError, NoMethodError => e - name = 'nil' if name.nil? - raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") + # Define a optional field. Don't use this method directly. + def self.optional(type, name, tag, options = {}) + define_field(:optional, type, name, tag, options) end - def self.get_ext_field_by_tag(tag) - extension_fields[tag] + # Define a repeated field. Don't use this method directly. + def self.repeated(type, name, tag, options = {}) + define_field(:repeated, type, name, tag, options) + end + + # Define a required field. Don't use this method directly. + def self.required(type, name, tag, options = {}) + define_field(:required, type, name, tag, options) end ## @@ -117,20 +125,11 @@ def initialize(values = {}) values.each { |name, val| self[name] = val unless val.nil? } end - def initialized? - all_fields.all? { |field| field.initialized?(self) } - end - - def has_field?(name) - @values.has_key?(name) - end - - def ==(obj) - return false unless obj.is_a?(self.class) - each_field do |field, value| - return false unless value == obj.__send__(field.name) - end - true + ## + # Public Instance Methods + # + def all_fields + self.class.all_fields end def clear! @@ -145,121 +144,96 @@ def clear! self end - def dup - copy_to(super, :dup) - end - def clone copy_to(super, :clone) end - def copy_to(object, method) - duplicate = proc { |obj| - case obj - when Message, String then obj.__send__(method) - else obj - end - } + def dup + copy_to(super, :dup) + end - object.__send__(:initialize) - @values.each do |name, value| - if value.is_a?(Field::FieldArray) - object.__send__(name).replace(value.map {|v| duplicate.call(v)}) - else - object.__send__("#{name}=", duplicate.call(value)) - end + # Iterate over a field collection. + # message.each_field do |field_object, value| + # # do something + # end + def each_field + all_fields.each do |field| + value = __send__(field.name) + yield(field, value) end - object end - private :copy_to - def inspect - to_hash.inspect + # Returns extension fields. See Message#fields method. + def extension_fields + self.class.extension_fields end - def parse_from_string(string) - parse_from(StringIO.new(string)) + def fields + self.class.fields end - def parse_from(stream) - Decoder.decode(stream, self) + def get_ext_field_by_name(name) # :nodoc: + self.class.get_ext_field_by_name(name) end - def serialize_to_string(string='') - io = StringIO.new(string) - serialize_to(io) - result = io.string - result.force_encoding(::Protobuf::Message::STRING_ENCODING) if result.respond_to?(:force_encoding) - result + def get_ext_field_by_tag(tag) # :nodoc: + self.class.get_ext_field_by_tag(tag) end - alias to_s serialize_to_string - def serialize_to(stream) - Encoder.encode(stream, self) + # Returns field object or +nil+. + def get_field_by_name(name) + self.class.get_field_by_name(name) end - def set_field(tag, bytes) - field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) - field.set(self, bytes) if field + # Returns field object or +nil+. + def get_field_by_tag(tag) + self.class.get_field_by_tag(tag) end - def [](name) - if field = get_field_by_name(name) || get_ext_field_by_name(name) - __send__(field.name) - else - raise NoMethodError, "No such field: #{name.inspect}" - end + def has_field?(name) + @values.has_key?(name) end - def []=(name, value) - if field = get_field_by_name(name) || get_ext_field_by_name(name) - __send__(field.setter_method_name, value) - else - raise NoMethodError, "No such field: #{name.inspect}" - end + def initialized? + all_fields.all? { |field| field.initialized?(self) } end - # Returns a hash; which key is a tag number, and value is a field object. - def all_fields - self.class.all_fields + def inspect + to_hash.inspect end - def fields - self.class.fields + def parse_from_string(string) + parse_from(StringIO.new(string)) end - # Returns field object or +nil+. - def get_field_by_name(name) - self.class.get_field_by_name(name) + def parse_from(stream) + Decoder.decode(stream, self) end - # Returns field object or +nil+. - def get_field_by_tag(tag) - self.class.get_field_by_tag(tag) + def respond_to_has?(key) + self.respond_to?(key) && self.has_field?(key) end - # Returns extension fields. See Message#fields method. - def extension_fields - self.class.extension_fields + def respond_to_has_and_present?(key) + self.respond_to_has?(key) && + (self.__send__(key).present? || [true, false].include?(self.__send__(key))) end - def get_ext_field_by_name(name) # :nodoc: - self.class.get_ext_field_by_name(name) + def serialize_to(stream) + Encoder.encode(stream, self) end - def get_ext_field_by_tag(tag) # :nodoc: - self.class.get_ext_field_by_tag(tag) + def serialize_to_string(string='') + io = StringIO.new(string) + serialize_to(io) + result = io.string + result.force_encoding(::Protobuf::Message::STRING_ENCODING) if result.respond_to?(:force_encoding) + result end - # Iterate over a field collection. - # message.each_field do |field_object, value| - # # do something - # end - def each_field - all_fields.each do |field| - value = __send__(field.name) - yield(field, value) - end + def set_field(tag, bytes) + field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) + field.set(self, bytes) if field end # Return a hash-representation of the given fields for this message type. @@ -274,11 +248,73 @@ def to_hash return result end - alias_method :to_hash_value, :to_hash def to_json to_hash.to_json end + def ==(obj) + return false unless obj.is_a?(self.class) + each_field do |field, value| + return false unless value == obj.__send__(field.name) + end + true + end + + def [](name) + if field = get_field_by_name(name) || get_ext_field_by_name(name) + __send__(field.name) + else + raise NoMethodError, "No such field: #{name.inspect}" + end + end + + def []=(name, value) + if field = get_field_by_name(name) || get_ext_field_by_name(name) + __send__(field.setter_method_name, value) + else + raise NoMethodError, "No such field: #{name.inspect}" + end + end + + ## + # Instance Aliases + # + alias_method :to_hash_value, :to_hash + alias_method :to_s, :serialize_to_string + alias_method :responds_to_has?, :respond_to_has? + alias_method :respond_to_and_has?, :respond_to_has? + alias_method :responds_to_and_has?, :respond_to_has? + alias_method :respond_to_has_present?, :respond_to_has_and_present? + alias_method :respond_to_and_has_present?, :respond_to_has_and_present? + alias_method :respond_to_and_has_and_present?, :respond_to_has_and_present? + alias_method :responds_to_has_present?, :respond_to_has_and_present? + alias_method :responds_to_and_has_present?, :respond_to_has_and_present? + alias_method :responds_to_and_has_and_present?, :respond_to_has_and_present? + + ## + # Private Instance Methods + # + private + + def copy_to(object, method) + duplicate = proc { |obj| + case obj + when Message, String then obj.__send__(method) + else obj + end + } + + object.__send__(:initialize) + @values.each do |name, value| + if value.is_a?(Field::FieldArray) + object.__send__(name).replace(value.map {|v| duplicate.call(v)}) + else + object.__send__("#{name}=", duplicate.call(value)) + end + end + object + end + end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 880d7cd6..5d77e60f 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -20,6 +20,58 @@ end end + describe "#respond_to_and_has?" do + subject { Test::EnumTestMessage.new(:non_default_enum => 2) } + + it "is false when the message does not have the field" do + subject.respond_to_and_has?(:other_field).should be_false + end + + it "is true when the message has the field" do + subject.respond_to_and_has?(:non_default_enum).should be_true + end + end + + describe "#respond_to_has_and_present?" do + subject { Test::EnumTestMessage.new(:non_default_enum => 2) } + + it "is false when the message does not have the field" do + subject.respond_to_and_has_and_present?(:other_field).should be_false + end + + it "is false when the field is repeated and a value is not present" do + subject.respond_to_and_has_and_present?(:repeated_enums).should be_false + end + + it "is false when the field is repeated and the value is empty array" do + subject.repeated_enums = [] + subject.respond_to_and_has_and_present?(:repeated_enums).should be_false + end + + it "is true when the field is repeated and a value is present" do + subject.repeated_enums = [2] + subject.respond_to_and_has_and_present?(:repeated_enums).should be_true + end + + it "is true when the message has the field" do + subject.respond_to_and_has_and_present?(:non_default_enum).should be_true + end + + context "#API" do + subject { Test::EnumTestMessage.new(:non_default_enum => 2) } + + it { should respond_to(:respond_to_and_has_and_present?) } + it { should respond_to(:responds_to_and_has_and_present?) } + it { should respond_to(:responds_to_has?) } + it { should respond_to(:respond_to_has?) } + it { should respond_to(:respond_to_has_present?) } + it { should respond_to(:responds_to_has_present?) } + it { should respond_to(:respond_to_and_has_present?) } + it { should respond_to(:responds_to_and_has_present?) } + end + + end + describe '#to_hash' do context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do From 787c218b2ff983c9c5df8eefb5567e85092c8f69 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 10 Nov 2012 18:28:53 -0700 Subject: [PATCH 0187/1191] add predicate methods to boolean fields --- lib/protobuf/field/bool_field.rb | 12 ++++++++++++ spec/lib/protobuf/message_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 2cf7d93b..63f1d691 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -16,6 +16,18 @@ def decode(value) value == 1 end + def define_getter + super + + field = self + @message_class.class_eval do + define_method("#{field.getter_method_name}?") do + field.warn_if_deprecated + @values.fetch(field.name, field.default_value) + end + end + end + def encode(value) [value ? 1 : 0].pack('C') end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 5d77e60f..b3b33269 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -20,6 +20,26 @@ end end + describe "boolean predicate methods" do + subject { Test::ResourceFindRequest.new(:name => "resource") } + + it { should respond_to(:active?) } + + it "sets the predicate to true when the boolean value is true" do + subject.active = true + subject.active?.should be_true + end + + it "sets the predicate to false when the boolean value is false" do + subject.active = false + subject.active?.should be_false + end + + it "does not put predicate methods on non-boolean fields" do + Test::ResourceFindRequest.new(:name => "resource").should_not respond_to(:name?) + end + end + describe "#respond_to_and_has?" do subject { Test::EnumTestMessage.new(:non_default_enum => 2) } From 6c254b291b41c7868276842eb162fe951274398f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 12 Nov 2012 09:22:40 -0700 Subject: [PATCH 0188/1191] run GC start when GC enable is called --- lib/protobuf/rpc/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 9fefe550..ab44fcc6 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -22,7 +22,7 @@ def disable_gc! end def enable_gc! - ::GC.enable if ::Protobuf.gc_pause_server_request? + ::GC.enable && ::GC.start if ::Protobuf.gc_pause_server_request? end # no-op, implemented by including class if desired. From e197fb9e62d5570bfe8f7a2c37ed796f26fbb34b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 12 Nov 2012 09:29:45 -0700 Subject: [PATCH 0189/1191] bump to 2.2.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index ece4f0bd..7e6df42a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.1.3' + VERSION = '2.2.0' PROTOC_VERSION = '2.4.1' end From a75c2c278320b83f7406d3978a1f82e79567c9c1 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 12 Nov 2012 16:25:00 -0700 Subject: [PATCH 0190/1191] fix jruby bug with fixnum/integer responding to to_sym --- lib/protobuf/enum.rb | 11 ++++++----- lib/protobuf/logger.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 97a073e5..1642f581 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -16,12 +16,13 @@ def self.define(name, value) # mechanisms. This is useful for the enum field setters # as well as repeated enum field construction. def self.fetch(value) - if value.is_a?(::Protobuf::EnumValue) + case value + when ::Protobuf::EnumValue then value - elsif value.respond_to?(:to_sym) - value_by_name(value.to_sym) rescue nil - elsif value.respond_to?(:to_i) - enum_by_value(value.to_i) rescue nil + when Numeric then + enum_by_value(value.to_i) + when String, Symbol then + value_by_name(value.to_sym) else nil end diff --git a/lib/protobuf/logger.rb b/lib/protobuf/logger.rb index 5fe42a47..30397c27 100644 --- a/lib/protobuf/logger.rb +++ b/lib/protobuf/logger.rb @@ -54,7 +54,7 @@ module LogMethods [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| define_method("log_#{m}") do |*params, &block| params.map! { |message| sign_message(message) } - Protobuf::Logger.__send__(m, *params, &block) + ::Protobuf::Logger.__send__(m, *params, &block) end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 24f07554..0dc88041 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -25,12 +25,14 @@ context 'when value can be coerced to a symbol' do it 'fetches based on the symbol name value' do Test::EnumTestType.fetch("http://github.com/ONE").should eq Test::EnumTestType::ONE + Test::EnumTestType.fetch(:ONE).should eq Test::EnumTestType::ONE end end context 'when value can be coerced to an integer' do it 'fetches based on the integer tag value' do Test::EnumTestType.fetch(3.0).should eq Test::EnumTestType::THREE + Test::EnumTestType.fetch(3).should eq Test::EnumTestType::THREE end end From 0dfdd176622536609e324e2ac8621887396f882e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 12 Nov 2012 16:25:18 -0700 Subject: [PATCH 0191/1191] bump to 2.2.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 7e6df42a..14d342c2 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.0' + VERSION = '2.2.1' PROTOC_VERSION = '2.4.1' end From 9ef0d9fac9da13579b007090574d50d0e66d7b11 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 12 Nov 2012 16:42:09 -0700 Subject: [PATCH 0192/1191] Add travis yml --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..01844aaa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: ruby +rvm: + - "1.9.2" + - "1.9.3" + - jruby-19mode + - rbx-19mode + - ruby-head + - jruby-head +script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec From 7501994e5f3b6021f6a423aee588a7ceb2eefe1d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 12 Nov 2012 16:46:00 -0700 Subject: [PATCH 0193/1191] Minor readme change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 732bb86b..1035fa6b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # protobuf -***IMPORTANT: Those upgrading from version 1.4.2 to 2.0 should read the [UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes*** +***IMPORTANT: Those upgrading from version 1.4.2 to 2.X should read the [UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes*** Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. We currently support version 2.4.0. It's a gem for managing 3 things: From b40f2c4cffd0e1cc52ec317422b18903418bbaa5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 12 Nov 2012 16:50:42 -0700 Subject: [PATCH 0194/1191] Add travis badge to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1035fa6b..e4308485 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # protobuf +[![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) + ***IMPORTANT: Those upgrading from version 1.4.2 to 2.X should read the [UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes*** Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. We currently support version 2.4.0. It's a gem for managing 3 things: From 42e8b1fe043c9808cb2a0cecb9cee69d52df3a96 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 12 Nov 2012 17:02:53 -0700 Subject: [PATCH 0195/1191] Comment out perftools, add warning in benchmark script --- protobuf.gemspec | 4 ++-- spec/benchmark/tasks.rb | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index acd4c1b3..7421bbb2 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -29,11 +29,11 @@ Gem::Specification.new do |s| s.add_development_dependency 'eventmachine' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'perftools.rb' + # s.add_development_dependency 'perftools.rb' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' - s.add_development_dependency 'rake-compiler' + # s.add_development_dependency 'rake-compiler' s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 56193af5..4507666c 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,7 +1,13 @@ require 'benchmark' require 'support/all' require 'support/test/resource_service' -require 'perftools' + +begin + require 'perftools' +rescue LoadError + $stderr.puts 'perftools must be uncommented in the gemspec before you can run this benchmark task' + exit(1) +end # Including a way to turn on debug logger for spec runs if ENV["DEBUG"] From 1aa7a98e3af2c35ab6a9678b4812b871f3bc9ea5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 12 Nov 2012 17:05:28 -0700 Subject: [PATCH 0196/1191] Un-require benchmark task from rakefile --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 67c1a92d..6af33f25 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ $:.push File.expand_path("./", File.dirname(__FILE__)) $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "bundler/gem_tasks" -require "benchmark/tasks" +# require "benchmark/tasks" require 'rspec/core/rake_task' From 2ef5cffefdcf4ab3dd8321af2f2f34fa601bb50b Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 12 Nov 2012 17:07:29 -0700 Subject: [PATCH 0197/1191] Comment out rake compiler task from Rakefile --- Rakefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 6af33f25..0b6cb21b 100644 --- a/Rakefile +++ b/Rakefile @@ -12,9 +12,9 @@ task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new(:spec) -## +## # Rake-compiler # -require 'rake/extensiontask' - -Rake::ExtensionTask.new("ruby_generator") +# require 'rake/extensiontask' +# +# Rake::ExtensionTask.new("ruby_generator") From 21e7d1166f867bf4249360d0fd518d2dfc4b960c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 12 Nov 2012 20:18:47 -0700 Subject: [PATCH 0198/1191] add to_s format to enum_value --- lib/protobuf/enum_value.rb | 11 +++++++++-- spec/lib/protobuf/enum_value_spec.rb | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index dafc1388..93972dca 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -26,8 +26,15 @@ def to_hash_value self.to_i end - def to_s - to_hash_value.to_s + def to_s(format = :value_string) + case format + when :value_string then + self.to_i.to_s + when :name then + name.to_s + else + self.to_i.to_s + end end end end diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb index a50c301d..c4b50b1f 100644 --- a/spec/lib/protobuf/enum_value_spec.rb +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -10,5 +10,6 @@ its(:to_hash_value) { should eq 1 } its(:to_s) { should eq "1" } its(:inspect) { should eq '#' } + specify { subject.to_s(:name).should eq("ONE") } end From 7e8038eb7c76a985d3a9aeffa26aa57f5574340a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 12 Nov 2012 20:19:43 -0700 Subject: [PATCH 0199/1191] bump to 2.2.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 14d342c2..c540935b 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.1' + VERSION = '2.2.2' PROTOC_VERSION = '2.4.1' end From a262f719f6ae40b0ae28a9f4770f50e200abef54 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 09:59:33 -0700 Subject: [PATCH 0200/1191] remove SimpleDelegator in EnumValue --- lib/protobuf/enum_value.rb | 33 ++++++++++++++++++++++------ spec/lib/protobuf/enum_value_spec.rb | 14 ++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index 93972dca..c98004ba 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -1,16 +1,14 @@ -require 'delegate' require 'protobuf/enum' module Protobuf - class EnumValue < SimpleDelegator + class EnumValue + include Comparable attr_reader :parent_class, :name, :value - # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum - def class - Fixnum - end - + ## + # Constructor + # def initialize(parent_class, name, value) @parent_class = parent_class @name = name @@ -18,6 +16,23 @@ def initialize(parent_class, name, value) super(@value) end + ## + # Public Instance Methods + # + def <=>(compared_value) + case compared_value + when ::Protobuf::EnumValue then + value <=> compared_value.value + when Numeric then + value <=> compared_value.to_i + end + end + + # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum + def class + Fixnum + end + def inspect "\#" end @@ -26,6 +41,10 @@ def to_hash_value self.to_i end + def to_i + @value.to_i + end + def to_s(format = :value_string) case format when :value_string then diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb index c4b50b1f..8fba8058 100644 --- a/spec/lib/protobuf/enum_value_spec.rb +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -3,13 +3,13 @@ describe Protobuf::EnumValue do subject { Test::EnumTestType::ONE } - its(:class) { should eq Fixnum } - its(:parent_class) { should eq Test::EnumTestType } - its(:name) { should eq :ONE } - its(:value) { should eq 1 } - its(:to_hash_value) { should eq 1 } - its(:to_s) { should eq "1" } - its(:inspect) { should eq '#' } + its(:class) { should eq(Fixnum) } + its(:parent_class) { should eq(Test::EnumTestType) } + its(:name) { should eq(:ONE) } + its(:value) { should eq(1) } + its(:to_hash_value) { should eq(1) } + its(:to_s) { should eq("1") } + its(:inspect) { should eq('#') } specify { subject.to_s(:name).should eq("ONE") } end From 2ca089855be3c85f0582abdfd49c7c379fa5f36e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 09:59:56 -0700 Subject: [PATCH 0201/1191] bump to 2.2.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c540935b..7afccf25 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.2' + VERSION = '2.2.3' PROTOC_VERSION = '2.4.1' end From 129873db4ef0a7956b44041459a22be35ade9576 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 10:31:42 -0700 Subject: [PATCH 0202/1191] build a java platform version and remove super call in enum_value now that SimpleDelegator is gone --- ext/ruby_generator/extconf.rb | 32 ++++++++++++++++++++++---------- lib/protobuf/enum_value.rb | 1 - lib/protobuf/version.rb | 2 +- protobuf.gemspec | 6 +++++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ext/ruby_generator/extconf.rb b/ext/ruby_generator/extconf.rb index a50886f0..800cd33a 100644 --- a/ext/ruby_generator/extconf.rb +++ b/ext/ruby_generator/extconf.rb @@ -1,17 +1,29 @@ -begin - require 'mkmf' +unless defined?(JRUBY_VERSION) + begin + require 'mkmf' - include_directory = File.expand_path(File.join(File.dirname(__FILE__), "..", "protobuf-2.4.1", "src")) + include_directory = File.expand_path(File.join(File.dirname(__FILE__), "..", "protobuf-2.4.1", "src")) - $CPPFLAGS << " -I#{include_directory}" - $CPPFLAGS << " -Wall " + $CPPFLAGS << " -I#{include_directory}" + $CPPFLAGS << " -Wall " - have_library("pthread") - have_library("protoc") - have_library("protobuf") + have_library("pthread") + have_library("protoc") + have_library("protobuf") - create_makefile('ruby_generator') -rescue + create_makefile('ruby_generator') + rescue ::Gem::Installer::ExtensionBuildError => ex + $stdout << <<-WARNING + Cannot compile native extension. + + If you are running on Jruby or Windows you should compile protocol buffer + definitions on another computer and then use those definitions locally. + + Only the compiler is restricted by this. The definitions should work without issue. + WARNING + $stdout << $/ + end +else $stdout << <<-WARNING Cannot compile native extension. diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index c98004ba..80f30811 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -13,7 +13,6 @@ def initialize(parent_class, name, value) @parent_class = parent_class @name = name @value = value - super(@value) end ## diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 7afccf25..ffb2d1b0 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.3' + VERSION = '2.2.4' PROTOC_VERSION = '2.4.1' end diff --git a/protobuf.gemspec b/protobuf.gemspec index 7421bbb2..2bbf27ca 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -19,7 +19,11 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] unless ENV['WITHOUT_PROTO_COMPILER'] - s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') + unless defined?(JRUBY_VERSION) + s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') + else + s.platform = 'java' + end end s.add_dependency 'activesupport' From f5a530faa0bfb172741122695b78a2ece4eef560 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 10:47:03 -0700 Subject: [PATCH 0203/1191] update gemspec to publish java native gem --- Rakefile | 22 ++++++++++++++++------ protobuf.gemspec | 8 ++++---- spec/support/test/resource.pb.rb | 1 - 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Rakefile b/Rakefile index 0b6cb21b..e306bfec 100644 --- a/Rakefile +++ b/Rakefile @@ -1,20 +1,30 @@ $:.push File.expand_path("./", File.dirname(__FILE__)) $:.push File.expand_path("./spec", File.dirname(__FILE__)) +require "rubygems" +require "rubygems/package_task" require "bundler/gem_tasks" # require "benchmark/tasks" -require 'rspec/core/rake_task' +require "rspec/core/rake_task" -desc 'Default: run specs.' +desc "Default: run specs." task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new(:spec) ## -# Rake-compiler +# rake-compiler # -# require 'rake/extensiontask' -# -# Rake::ExtensionTask.new("ruby_generator") +spec = Gem::Specification.load("protobuf.gemspec") + +Gem::PackageTask.new(spec) do |pkg| +end + +if RUBY_PLATFORM =~ /java/ + require "rake/javaextensiontask" +else + require "rake/extensiontask" + Rake::ExtensionTask.new("ruby_generator", spec) +end diff --git a/protobuf.gemspec b/protobuf.gemspec index 2bbf27ca..d40fbefa 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -19,10 +19,10 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] unless ENV['WITHOUT_PROTO_COMPILER'] - unless defined?(JRUBY_VERSION) - s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') - else + if defined?(JRUBY_VERSION) s.platform = 'java' + else + s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') end end @@ -37,7 +37,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' - # s.add_development_dependency 'rake-compiler' + s.add_development_dependency 'rake-compiler' s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 7e68dcf2..356fb47d 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -15,7 +15,6 @@ class StatusType < ::Protobuf::Enum; end # class ResourceFindRequest < ::Protobuf::Message; end class Resource < ::Protobuf::Message; end - class Extended < ::Protobuf::Message; end class Nested < ::Protobuf::Message; end ## From 4e3d01ded4431fa6e54da691294de1cef5752209 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 11:01:14 -0700 Subject: [PATCH 0204/1191] bump to 2.2.5 and remove rake-compilers version of native ext --- Rakefile | 1 - lib/protobuf/version.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index e306bfec..15f786bc 100644 --- a/Rakefile +++ b/Rakefile @@ -26,5 +26,4 @@ if RUBY_PLATFORM =~ /java/ require "rake/javaextensiontask" else require "rake/extensiontask" - Rake::ExtensionTask.new("ruby_generator", spec) end diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index ffb2d1b0..e60badf4 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.4' + VERSION = '2.2.5' PROTOC_VERSION = '2.4.1' end From 93737ce40c7fe51113684af78be9eca6570e859d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 13 Nov 2012 11:06:58 -0700 Subject: [PATCH 0205/1191] Add brackets to log sig on client and common connector --- lib/protobuf/rpc/client.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 5c463d2a..3566795e 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -33,7 +33,7 @@ def initialize(options = {}) end def log_signature - @_log_signature ||= "client-#{self.class}" + @_log_signature ||= "[client-#{self.class}]" end # Set a complete callback on the client to return the object (self). diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index d24ef775..e1ebb312 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -58,7 +58,7 @@ def initialize_stats end def log_signature - @_log_signature ||= "client-#{self.class}" + @_log_signature ||= "[client-#{self.class}]" end def parse_response From 0fb1ea63f1fecded330e48921eed02591da5579f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 11:21:00 -0700 Subject: [PATCH 0206/1191] should not run compile tests on jruby --- spec/spec_helper.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 57e3d6b3..8d663ddf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,12 +23,14 @@ c.mock_with :rspec c.before(:suite) do - unless ENV['NO_COMPILE_TEST_PROTOS'] - $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - proto_path = File.expand_path("../support/", __FILE__) - cmd = %Q{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } - puts cmd - %x{#{cmd}} + unless defined?(JRUBY_VERSION) + unless ENV['NO_COMPILE_TEST_PROTOS'] + $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' + proto_path = File.expand_path("../support/", __FILE__) + cmd = %Q{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } + puts cmd + %x{#{cmd}} + end end end end From dee00833994ae0f4fa91421f5f1206a2b2f82e6a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 14:11:03 -0700 Subject: [PATCH 0207/1191] add the #to_int method to allow enum values to use them as indexes to an array --- lib/protobuf/enum.rb | 2 +- lib/protobuf/enum_value.rb | 6 +++++- spec/lib/protobuf/enum_value_spec.rb | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 1642f581..c1a52642 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -18,7 +18,7 @@ def self.define(name, value) def self.fetch(value) case value when ::Protobuf::EnumValue then - value + value.value when Numeric then enum_by_value(value.to_i) when String, Symbol then diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index 80f30811..eee1e5a5 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -41,7 +41,11 @@ def to_hash_value end def to_i - @value.to_i + @value + end + + def to_int + @value.to_int end def to_s(format = :value_string) diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb index 8fba8058..776cea67 100644 --- a/spec/lib/protobuf/enum_value_spec.rb +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -12,4 +12,8 @@ its(:inspect) { should eq('#') } specify { subject.to_s(:name).should eq("ONE") } + it "can be used as the index to an array" do + array = [0, 1, 2, 3] + array[::Test::EnumTestType::ONE].should eq(1) + end end From 10b3062b866ed7f2a362c6140cd431171ab078e5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 14:11:57 -0700 Subject: [PATCH 0208/1191] bump to 2.2.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index e60badf4..1806fff6 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.5' + VERSION = '2.2.6' PROTOC_VERSION = '2.4.1' end From 4f0edf33b8d59a30687421ada826ef3c484eeb0a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 14:49:10 -0700 Subject: [PATCH 0209/1191] add #value to Numeric and deprecated calling #value on EnumValue --- lib/protobuf/enum.rb | 2 +- lib/protobuf/enum_value.rb | 33 +++++++++++++++++++++++----- spec/lib/protobuf/enum_value_spec.rb | 17 ++++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index c1a52642..062db071 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -18,7 +18,7 @@ def self.define(name, value) def self.fetch(value) case value when ::Protobuf::EnumValue then - value.value + value.to_i when Numeric then enum_by_value(value.to_i) when String, Symbol then diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index eee1e5a5..6abfca6f 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -1,10 +1,22 @@ require 'protobuf/enum' +## +# Adding extension to Numeric until +# we can get people to stop calling #value +# on EnumValue +class Numeric + unless method_defined?(:value) + def value + self + end + end +end + module Protobuf class EnumValue include Comparable - attr_reader :parent_class, :name, :value + attr_reader :parent_class, :name ## # Constructor @@ -21,7 +33,7 @@ def initialize(parent_class, name, value) def <=>(compared_value) case compared_value when ::Protobuf::EnumValue then - value <=> compared_value.value + value <=> compared_value.to_i when Numeric then value <=> compared_value.to_i end @@ -36,10 +48,6 @@ def inspect "\#" end - def to_hash_value - self.to_i - end - def to_i @value end @@ -58,6 +66,19 @@ def to_s(format = :value_string) self.to_i.to_s end end + + def value + if ::Protobuf.print_deprecation_warnings? + $stderr.puts("[WARNING] Calling #value on an EnumValue is deprecated and no longer needed.") + end + + @value + end + + ## + # Instance Aliases + # + alias_method :to_hash_value, :to_i end end diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb index 776cea67..aa2b0f25 100644 --- a/spec/lib/protobuf/enum_value_spec.rb +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -2,6 +2,15 @@ describe Protobuf::EnumValue do + def capture_stderr(&required_block) + real_stderr = $stderr + $stderr = StringIO.new + yield + $stderr.string + ensure + $stderr = real_stderr + end + subject { Test::EnumTestType::ONE } its(:class) { should eq(Fixnum) } its(:parent_class) { should eq(Test::EnumTestType) } @@ -16,4 +25,12 @@ array = [0, 1, 2, 3] array[::Test::EnumTestType::ONE].should eq(1) end + + it "prints a Warning to $stderr when #value is called" do + local_warning = capture_stderr do + ::Test::EnumTestType::ONE.value + end + + local_warning.should match(/deprecated/i) + end end From 83315b81753d74d0c91c0817d667b8ec941cea90 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 13 Nov 2012 14:49:38 -0700 Subject: [PATCH 0210/1191] bump to 2.2.7 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 1806fff6..6a085950 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.6' + VERSION = '2.2.7' PROTOC_VERSION = '2.4.1' end From 07b26b6414b22cb88c48ca267b4e2f3426b6bf6b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Nov 2012 13:25:25 -0700 Subject: [PATCH 0211/1191] return from whence we came with simpledelegator, not a good experiment (bump to 2.2.8) --- lib/protobuf/enum_value.rb | 21 +++------------------ lib/protobuf/version.rb | 2 +- spec/lib/protobuf/enum_value_spec.rb | 16 ---------------- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index 6abfca6f..9b110c7c 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -1,3 +1,4 @@ +require 'delegate' require 'protobuf/enum' ## @@ -13,8 +14,7 @@ def value end module Protobuf - class EnumValue - include Comparable + class EnumValue < SimpleDelegator attr_reader :parent_class, :name @@ -25,18 +25,7 @@ def initialize(parent_class, name, value) @parent_class = parent_class @name = name @value = value - end - - ## - # Public Instance Methods - # - def <=>(compared_value) - case compared_value - when ::Protobuf::EnumValue then - value <=> compared_value.to_i - when Numeric then - value <=> compared_value.to_i - end + super(@value) end # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum @@ -68,10 +57,6 @@ def to_s(format = :value_string) end def value - if ::Protobuf.print_deprecation_warnings? - $stderr.puts("[WARNING] Calling #value on an EnumValue is deprecated and no longer needed.") - end - @value end diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6a085950..f9016867 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.2.7' + VERSION = '2.3.0' PROTOC_VERSION = '2.4.1' end diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb index aa2b0f25..fb2398fe 100644 --- a/spec/lib/protobuf/enum_value_spec.rb +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -2,15 +2,6 @@ describe Protobuf::EnumValue do - def capture_stderr(&required_block) - real_stderr = $stderr - $stderr = StringIO.new - yield - $stderr.string - ensure - $stderr = real_stderr - end - subject { Test::EnumTestType::ONE } its(:class) { should eq(Fixnum) } its(:parent_class) { should eq(Test::EnumTestType) } @@ -26,11 +17,4 @@ def capture_stderr(&required_block) array[::Test::EnumTestType::ONE].should eq(1) end - it "prints a Warning to $stderr when #value is called" do - local_warning = capture_stderr do - ::Test::EnumTestType::ONE.value - end - - local_warning.should match(/deprecated/i) - end end From 6272b873cb0b6b786f6161e27c42e24d31cf9c7d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Nov 2012 18:46:16 -0700 Subject: [PATCH 0212/1191] allow nil in bytes_fields and string_fields --- lib/protobuf/field/bytes_field.rb | 4 ++-- lib/protobuf/version.rb | 2 +- spec/lib/protobuf/message_spec.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 153b124e..139564c0 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -10,11 +10,11 @@ def wire_type end def acceptable?(val) - if val.is_a?(::Protobuf::Message) || val.instance_of?(String) + if val.nil? || val.is_a?(::Protobuf::Message) || val.instance_of?(String) return true end - raise TypeError + raise TypeError, "Cannot set field : #{name} to value : #{val}" end def decode(bytes) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f9016867..9438b89c 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.3.0' + VERSION = '2.3.1' PROTOC_VERSION = '2.4.1' end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index b3b33269..d136fb8c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -169,6 +169,17 @@ end end + describe "#define_setter" do + subject { ::Test::Resource.new } + it "allows string fields to be set to nil" do + expect { subject.name = nil }.to_not raise_error + end + + it "does not allow string fields to be set to Numeric" do + expect { subject.name = 1}.to raise_error(/name/) + end + end + describe '#get_ext_field_by_name' do pending 'Need to get a proto compiled with extensions first' end From 80a33c20a2a6cdadcc490ba4832dec38319a45bd Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Nov 2012 19:52:05 -0700 Subject: [PATCH 0213/1191] allow nil values in bytes_field and string_fields --- lib/protobuf/message.rb | 16 +++++++++++++++- lib/protobuf/message/encoder.rb | 4 +--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index d74d78bf..f641af6d 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -159,7 +159,21 @@ def dup def each_field all_fields.each do |field| value = __send__(field.name) - yield(field, value) + yield(field, value) + end + end + + def each_field_for_serialization + all_fields.each do |field| + next unless has_field?(field.name) + + value = __send__(field.name) + + if value.present? || [true, false].include?(value) + yield(field, value) + else + raise "#{field.name} is required on #{field.message_class}" if field.required? + end end end diff --git a/lib/protobuf/message/encoder.rb b/lib/protobuf/message/encoder.rb index bb570111..c45040a3 100644 --- a/lib/protobuf/message/encoder.rb +++ b/lib/protobuf/message/encoder.rb @@ -14,9 +14,7 @@ def encode(stream, message) raise NotInitializedError, "Message #{message.class.name} is not initialized (one or more fields is improperly set): #{JSON.parse(message.to_json)}" end - message.each_field do |field, value| - next unless message.has_field?(field.name) - + message.each_field_for_serialization do |field, value| if field.repeated? if field.packed? key = (field.tag << 3) | WireType::LENGTH_DELIMITED From 7e367688795e67cae8b14a7f3db4ef82567ebfdb Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Nov 2012 19:52:32 -0700 Subject: [PATCH 0214/1191] bump to 2.3.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9438b89c..693aa055 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.3.1' + VERSION = '2.3.2' PROTOC_VERSION = '2.4.1' end From 06dbe27eec02a7fd71b16296669e2a7aea236778 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Nov 2012 23:31:27 -0700 Subject: [PATCH 0215/1191] move encoding into the message and allow any field to be unset by setting it to nil --- lib/protobuf/field/base_field.rb | 21 +++++++---- lib/protobuf/field/bool_field.rb | 3 +- lib/protobuf/field/bytes_field.rb | 4 +- lib/protobuf/field/field_array.rb | 10 ++--- lib/protobuf/field/float_field.rb | 4 +- lib/protobuf/message.rb | 31 ++++++++++++++- lib/protobuf/message/decoder.rb | 26 ++++--------- lib/protobuf/message/encoder.rb | 46 ----------------------- spec/lib/protobuf/message/encoder_spec.rb | 19 ---------- spec/lib/protobuf/message_spec.rb | 13 +++++++ 10 files changed, 73 insertions(+), 104 deletions(-) delete mode 100644 lib/protobuf/message/encoder.rb delete mode 100644 spec/lib/protobuf/message/encoder_spec.rb diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index bb7a57a5..980509b4 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -40,7 +40,7 @@ def initialize(message_class, rule, type, name, tag, options) @default_value = \ case @rule when :repeated then - FieldArray.new(self).freeze + ::Protobuf::Field::FieldArray.new(self).freeze when :required then nil when :optional then @@ -85,13 +85,14 @@ def set(message_instance, bytes) array = message_instance.__send__(getter_method_name) method = \ case wire_type - when WireType::FIXED32 then :read_fixed32 - when WireType::FIXED64 then :read_fixed64 - when WireType::VARINT then :read_varint + when ::Protobuf::WireType::FIXED32 then :read_fixed32 + when ::Protobuf::WireType::FIXED64 then :read_fixed64 + when ::Protobuf::WireType::VARINT then :read_varint end stream = StringIO.new(bytes) + until stream.eof? - array << decode(Decoder.__send__(method, stream)) + array << decode(::Protobuf::Decoder.__send__(method, stream)) end else value = decode(bytes) @@ -195,8 +196,13 @@ def define_array_setter @message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated - @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) - @values[field.name].replace(val) + + if val.nil? + @values.delete(field.name) + else + @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) + @values[field.name].replace(val) + end end end end @@ -216,6 +222,7 @@ def define_setter @message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated + if val.nil? @values.delete(field.name) elsif field.acceptable?(val) diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 63f1d691..8d16a112 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -8,8 +8,7 @@ def self.default end def acceptable?(val) - raise TypeError unless [true, false].include?(val) - true + [true, false].include?(val) end def decode(value) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 139564c0..bc7c6afe 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -12,9 +12,9 @@ def wire_type def acceptable?(val) if val.nil? || val.is_a?(::Protobuf::Message) || val.instance_of?(String) return true + else + raise TypeError, "Cannot set field : #{name} to value : #{val}" end - - raise TypeError, "Cannot set field : #{name} to value : #{val}" end def decode(bytes) diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index d6f16a29..e5ad5456 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -12,24 +12,24 @@ def initialize(field) # Public Instance Methods # def []=(nth, val) - super(nth, normalize(val)) + super(nth, normalize(val)) unless val.nil? end def <<(val) - super(normalize(val)) + super(normalize(val)) unless val.nil? end def push(val) - super(normalize(val)) + super(normalize(val)) unless val.nil? end def unshift(val) - super(normalize(val)) + super(normalize(val)) unless val.nil? end def replace(val) raise TypeError unless val.is_a?(Array) - val = val.map { |v| normalize(v)} + val = val.map { |v| normalize(v) } super(val) end diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 8c475eb4..c075b0a9 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -22,9 +22,7 @@ def encode(value) end def acceptable?(val) - raise TypeError, val.class.name unless val.is_a?(Numeric) - raise RangeError if val < min || max < val - true + (val > min || val < max) rescue false end end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index f641af6d..de60b134 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -2,7 +2,6 @@ require 'protobuf/field' require 'protobuf/enum' require 'protobuf/message/decoder' -require 'protobuf/message/encoder' module Protobuf class Message @@ -168,6 +167,7 @@ def each_field_for_serialization next unless has_field?(field.name) value = __send__(field.name) + value.compact! if field.repeated? if value.present? || [true, false].include?(value) yield(field, value) @@ -234,7 +234,26 @@ def respond_to_has_and_present?(key) end def serialize_to(stream) - Encoder.encode(stream, self) + # FIXME make this not as ghetto + unless initialized? + raise NotInitializedError, "Message #{self.class.name} is not initialized (one or more fields is improperly set): #{JSON.parse(self.to_json)}" + end + + each_field_for_serialization do |field, value| + if field.repeated? + if field.packed? + key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED + packed_value = value.map { |val| field.encode(val) }.join + stream.write(::Protobuf::Field::VarintField.encode(key)) + stream.write(::Protobuf::Field::VarintField.encode(packed_value.size)) + stream.write(packed_value) + else + value.each { |val| write_pair(stream, field, val) } + end + else + write_pair(stream, field, value) + end + end end def serialize_to_string(string='') @@ -329,6 +348,14 @@ def copy_to(object, method) end object end + # Encode key and value, and write to +stream+. + def write_pair(stream, field, value) + key = (field.tag << 3) | field.wire_type + key_bytes = ::Protobuf::Field::VarintField.encode(key) + stream.write(key_bytes) + bytes = field.encode(value) + stream.write(bytes) + end end end diff --git a/lib/protobuf/message/decoder.rb b/lib/protobuf/message/decoder.rb index 6a1562c9..5884d947 100644 --- a/lib/protobuf/message/decoder.rb +++ b/lib/protobuf/message/decoder.rb @@ -13,18 +13,18 @@ def decode(stream, message) tag, wire_type = read_key(stream) bytes = case wire_type - when WireType::VARINT then + when ::Protobuf::WireType::VARINT then read_varint(stream) - when WireType::FIXED64 then + when ::Protobuf::WireType::FIXED64 then read_fixed64(stream) - when WireType::LENGTH_DELIMITED then + when ::Protobuf::WireType::LENGTH_DELIMITED then read_length_delimited(stream) - when WireType::START_GROUP then - read_start_group(stream) - when WireType::END_GROUP then - read_end_group(stream) - when WireType::FIXED32 then + when ::Protobuf::WireType::FIXED32 then read_fixed32(stream) + when ::Protobuf::WireType::START_GROUP then + raise NotImplementedError, 'Group is deprecated.' + when ::Protobuf::WireType::END_GROUP then + raise NotImplementedError, 'Group is deprecated.' else raise InvalidWireType, wire_type end @@ -69,15 +69,5 @@ def read_length_delimited(stream) stream.read(value_length) end - # Not implemented. - def read_start_group(stream) - raise NotImplementedError, 'Group is deprecated.' - end - - # Not implemented. - def read_end_group(stream) - raise NotImplementedError, 'Group is deprecated.' - end - end end diff --git a/lib/protobuf/message/encoder.rb b/lib/protobuf/message/encoder.rb deleted file mode 100644 index c45040a3..00000000 --- a/lib/protobuf/message/encoder.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'protobuf/wire_type' -require 'protobuf/exceptions' - -module Protobuf - - module Encoder - - module_function - - # Encode +message+ and write to +stream+. - def encode(stream, message) - # FIXME make this not as ghetto - unless message.initialized? - raise NotInitializedError, "Message #{message.class.name} is not initialized (one or more fields is improperly set): #{JSON.parse(message.to_json)}" - end - - message.each_field_for_serialization do |field, value| - if field.repeated? - if field.packed? - key = (field.tag << 3) | WireType::LENGTH_DELIMITED - packed_value = value.map {|val| field.encode(val) }.join - stream.write(Field::VarintField.encode(key)) - stream.write(Field::VarintField.encode(packed_value.size)) - stream.write(packed_value) - else - value.each do |val| - write_pair(stream, field, val) - end - end - else - write_pair(stream, field, value) - end - end - end - - # Encode key and value, and write to +stream+. - def write_pair(stream, field, value) - key = (field.tag << 3) | field.wire_type - key_bytes = Field::VarintField.encode(key) - stream.write(key_bytes) - bytes = field.encode(value) - stream.write(bytes) - end - - end -end diff --git a/spec/lib/protobuf/message/encoder_spec.rb b/spec/lib/protobuf/message/encoder_spec.rb deleted file mode 100644 index 47e93b17..00000000 --- a/spec/lib/protobuf/message/encoder_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -class EncoderTest - extend ::Protobuf::Encoder -end - -describe Protobuf::Encoder do - describe '#encode' do - context "when there's no value for a required field" do - let(:message) { ::Test::Resource.new } - let(:stream) { StringIO.new } - it "raises a 'message not initialized' error" do - expect { - EncoderTest.__send__(:encode, stream, message) - }.to raise_error(Protobuf::NotInitializedError, /message.*not initialized/i) - end - end - end -end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index d136fb8c..d63b1bc7 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -20,6 +20,19 @@ end end + describe '#encode' do + context "when there's no value for a required field" do + let(:message) { ::Test::Resource.new } + let(:stream) { StringIO.new } + + it "raises a 'message not initialized' error" do + expect { + message.serialize_to(stream) + }.to raise_error(Protobuf::NotInitializedError, /message.*not initialized/i) + end + end + end + describe "boolean predicate methods" do subject { Test::ResourceFindRequest.new(:name => "resource") } From 198a733e275fa30ccc1f64670e2bcf085013bf5c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Nov 2012 23:52:10 -0700 Subject: [PATCH 0216/1191] remove need for initialization as it has moved to the serialization layer --- lib/protobuf/exceptions.rb | 7 ++----- lib/protobuf/field/base_field.rb | 12 ------------ lib/protobuf/message.rb | 25 +++++++++---------------- spec/functional/evented_server_spec.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/message_spec.rb | 12 ++++++------ 7 files changed, 20 insertions(+), 42 deletions(-) diff --git a/lib/protobuf/exceptions.rb b/lib/protobuf/exceptions.rb index 77b633ff..842c689a 100644 --- a/lib/protobuf/exceptions.rb +++ b/lib/protobuf/exceptions.rb @@ -1,11 +1,8 @@ module Protobuf - class Error < StandardError; end - class InvalidWireType < Error; end - class NotInitializedError < Error; end - class TagCollisionError < Error; end - + class SerializationError < StandardError; end + class FieldNotDefinedError < StandardError; end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 980509b4..acd2a136 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -67,18 +67,6 @@ def message? @_message = (self.class < ::Protobuf::Field::MessageField) end - def initialized?(message_instance) - value = message_instance.__send__(getter_method_name) - case @rule - when :required then - ! value.nil? && (! kind_of?(MessageField) || value.initialized?) - when :repeated then - value.all? {|msg| ! kind_of?(MessageField) || msg.initialized? } - when :optional then - value.nil? || ! kind_of?(MessageField) || value.initialized? - end - end - # Decode +bytes+ and pass to +message_instance+. def set(message_instance, bytes) if packed? diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index de60b134..8a22a36c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,15 +1,11 @@ require 'set' require 'protobuf/field' require 'protobuf/enum' +require 'protobuf/exceptions' require 'protobuf/message/decoder' module Protobuf class Message - ## - # Error Classes - # - class FieldNotDefinedError < StandardError; end - ## # Constants # @@ -164,7 +160,7 @@ def each_field def each_field_for_serialization all_fields.each do |field| - next unless has_field?(field.name) + next unless has_field_or_required_field?(field) value = __send__(field.name) value.compact! if field.repeated? @@ -172,7 +168,8 @@ def each_field_for_serialization if value.present? || [true, false].include?(value) yield(field, value) else - raise "#{field.name} is required on #{field.message_class}" if field.required? + # Only way you can get here is if you are required and not present + raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" end end end @@ -208,10 +205,6 @@ def has_field?(name) @values.has_key?(name) end - def initialized? - all_fields.all? { |field| field.initialized?(self) } - end - def inspect to_hash.inspect end @@ -234,11 +227,6 @@ def respond_to_has_and_present?(key) end def serialize_to(stream) - # FIXME make this not as ghetto - unless initialized? - raise NotInitializedError, "Message #{self.class.name} is not initialized (one or more fields is improperly set): #{JSON.parse(self.to_json)}" - end - each_field_for_serialization do |field, value| if field.repeated? if field.packed? @@ -348,6 +336,11 @@ def copy_to(object, method) end object end + + def has_field_or_required_field?(field) + has_field?(field.name) || field.required? + end + # Encode key and value, and write to +stream+. def write_pair(stream, field, value) key = (field.tag << 3) | field.wire_type diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 657c0415..121203bf 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -42,7 +42,7 @@ end EM.stop end - error.message.should =~ /ResourceFindRequest.*fields.*improperly set/ + error.message.should =~ /name.*required/ end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 7a5a9528..02ce00aa 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -41,7 +41,7 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /ResourceFindRequest.*fields.*improperly set/ + error.message.should =~ /name.*required/ end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index e69254ef..fa476c17 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -41,7 +41,7 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /ResourceFindRequest.*fields.*improperly set/ + error.message.should =~ /name.*required/ end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index d63b1bc7..bfc55f73 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -28,7 +28,7 @@ it "raises a 'message not initialized' error" do expect { message.serialize_to(stream) - }.to raise_error(Protobuf::NotInitializedError, /message.*not initialized/i) + }.to raise_error(Protobuf::SerializationError, /required/i) end end end @@ -165,19 +165,19 @@ specify do expect { subject.get_field_by_name(1) - }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*1.*#{subject.class.name}/) + }.to raise_error(::Protobuf::FieldNotDefinedError, /.*1.*#{subject.class.name}/) end specify do expect { subject.get_field_by_name(:nothere) - }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*nothere.*#{subject.class.name}/) + }.to raise_error(::Protobuf::FieldNotDefinedError, /.*nothere.*#{subject.class.name}/) end specify do expect { subject.get_field_by_name(nil) - }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) + }.to raise_error(::Protobuf::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) end end end @@ -219,13 +219,13 @@ specify do expect { subject.get_field_by_tag("not a number") - }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*not a number.*#{subject.class.name}/) + }.to raise_error(::Protobuf::FieldNotDefinedError, /.*not a number.*#{subject.class.name}/) end specify do expect { subject.get_field_by_tag(nil) - }.to raise_error(::Protobuf::Message::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) + }.to raise_error(::Protobuf::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) end end end From 2e396016a5d726d086453197fc773b728fef31c0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 09:31:19 -0700 Subject: [PATCH 0217/1191] add bytes/serialize aliases to message --- lib/protobuf/field/bytes_field.rb | 1 - lib/protobuf/message.rb | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index bc7c6afe..c0c4d3cb 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -26,7 +26,6 @@ def encode(value) if value.is_a?(::Protobuf::Message) value = value.serialize_to_string else - value = value.dup value.force_encoding(::Protobuf::Message::STRING_ENCODING) if value.respond_to?(:force_encoding) end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 8a22a36c..61b9059f 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -209,14 +209,14 @@ def inspect to_hash.inspect end - def parse_from_string(string) - parse_from(StringIO.new(string)) - end - def parse_from(stream) Decoder.decode(stream, self) end + def parse_from_string(string) + parse_from(StringIO.new(string)) + end + def respond_to_has?(key) self.respond_to?(key) && self.has_field?(key) end @@ -244,7 +244,7 @@ def serialize_to(stream) end end - def serialize_to_string(string='') + def serialize_to_string(string = '') io = StringIO.new(string) serialize_to(io) result = io.string @@ -303,6 +303,8 @@ def []=(name, value) # alias_method :to_hash_value, :to_hash alias_method :to_s, :serialize_to_string + alias_method :bytes, :serialize_to_string + alias_method :serialize, :serialize_to_string alias_method :responds_to_has?, :respond_to_has? alias_method :respond_to_and_has?, :respond_to_has? alias_method :responds_to_and_has?, :respond_to_has? From 7c7fbcd9f0d52ace20827c99c81c9f6f7831e42e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 09:31:55 -0700 Subject: [PATCH 0218/1191] bump to 2.4.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 693aa055..63786f02 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.3.2' + VERSION = '2.4.0' PROTOC_VERSION = '2.4.1' end From 92ae127c6ceeccc24b1935cc07817095a8619a72 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 09:55:22 -0700 Subject: [PATCH 0219/1191] fix issue with repeated fields looking as if they are present --- lib/protobuf/message.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 61b9059f..ebe749f4 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -160,16 +160,24 @@ def each_field def each_field_for_serialization all_fields.each do |field| - next unless has_field_or_required_field?(field) + next unless has_field?(field.name) || field.required? - value = __send__(field.name) - value.compact! if field.repeated? + value = @values[field.name] - if value.present? || [true, false].include?(value) - yield(field, value) - else - # Only way you can get here is if you are required and not present - raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" + if field.repeated? + if !value.nil? + value.compact! + @values[field.name] = nil if value.empty? + end + end + + if has_field?(field.name) || field.required? + if value.present? || [true, false].include?(value) + yield(field, value) + else + # Only way you can get here is if you are required and not present + raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" + end end end end @@ -339,10 +347,6 @@ def copy_to(object, method) object end - def has_field_or_required_field?(field) - has_field?(field.name) || field.required? - end - # Encode key and value, and write to +stream+. def write_pair(stream, field, value) key = (field.tag << 3) | field.wire_type From 02546b89987701785a85ee01f44a6d80864de14b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 09:55:37 -0700 Subject: [PATCH 0220/1191] bump to 2.4.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 63786f02..f6894352 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.0' + VERSION = '2.4.1' PROTOC_VERSION = '2.4.1' end From 9d421f76f6591e2c74db095ca178012595b33a0a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 10:13:53 -0700 Subject: [PATCH 0221/1191] add specs for field serialization of array that is empty --- lib/protobuf/message.rb | 34 ++++++++++++++++--------------- spec/lib/protobuf/message_spec.rb | 12 +++++++++++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index ebe749f4..6f4ed928 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -35,7 +35,7 @@ def self.define_field(rule, type, fname, tag, options) raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! end - field_definition = Field.build(self, rule, type, fname, tag, options) + field_definition = ::Protobuf::Field.build(self, rule, type, fname, tag, options) field_name_hash[fname] = tag field_array[tag] = field_definition end @@ -160,24 +160,15 @@ def each_field def each_field_for_serialization all_fields.each do |field| - next unless has_field?(field.name) || field.required? + next unless _field_must_be_serialized?(field) value = @values[field.name] - if field.repeated? - if !value.nil? - value.compact! - @values[field.name] = nil if value.empty? - end - end - - if has_field?(field.name) || field.required? - if value.present? || [true, false].include?(value) - yield(field, value) - else - # Only way you can get here is if you are required and not present - raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" - end + if value.present? || [true, false].include?(value) + yield(field, value) + else + # Only way you can get here is if you are required and not present + raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" end end end @@ -347,6 +338,17 @@ def copy_to(object, method) object end + def _field_must_be_serialized?(field) + return true if field.required? + + if field.repeated? && has_field?(field.name) + @values[field.name].compact! + @values.delete(field.name) if @values[field.name].empty? + end + + return has_field?(field.name) + end + # Encode key and value, and write to +stream+. def write_pair(stream, field, value) key = (field.tag << 3) | field.wire_type diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index bfc55f73..8ca62f7c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -31,6 +31,18 @@ }.to raise_error(Protobuf::SerializationError, /required/i) end end + + context "repeated fields" do + let(:message) { ::Test::Resource.new(:name => "something") } + let(:stream) { StringIO.new } + + it "does not raise an error when repeated fields are []" do + expect { + message.repeated_enum = [] + message.serialize_to(stream) + }.to_not raise_error + end + end end describe "boolean predicate methods" do From 9489fc11a4abcd0895f7566dcf5a2d76e01e7c5b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 10:14:10 -0700 Subject: [PATCH 0222/1191] 2.4.2 bump --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f6894352..742c0325 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.1' + VERSION = '2.4.2' PROTOC_VERSION = '2.4.1' end From e868ae520a853ea645eccc85fda031d2d62593b9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 15:50:17 -0700 Subject: [PATCH 0223/1191] move encoding to working only on strings --- lib/protobuf/message.rb | 28 ++++++++++---------------- lib/protobuf/message/decoder.rb | 3 +-- lib/protobuf/message/extend.rb | 8 -------- lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 4 ++-- lib/protobuf/rpc/server.rb | 1 - lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- spec/benchmark/tasks.rb | 11 ++++++++++ spec/lib/protobuf/message_spec.rb | 6 ++---- 9 files changed, 29 insertions(+), 36 deletions(-) delete mode 100644 lib/protobuf/message/extend.rb diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6f4ed928..f4e67021 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -129,7 +129,7 @@ def all_fields def clear! @values.delete_if do |_, value| - if value.is_a?(Field::FieldArray) + if value.is_a?(::Protobuf::Field::FieldArray) value.clear false else @@ -225,15 +225,17 @@ def respond_to_has_and_present?(key) (self.__send__(key).present? || [true, false].include?(self.__send__(key))) end - def serialize_to(stream) + def serialize_to_string + stream = "" + each_field_for_serialization do |field, value| if field.repeated? if field.packed? key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED packed_value = value.map { |val| field.encode(val) }.join - stream.write(::Protobuf::Field::VarintField.encode(key)) - stream.write(::Protobuf::Field::VarintField.encode(packed_value.size)) - stream.write(packed_value) + stream << ::Protobuf::Field::VarintField.encode(key) + stream << ::Protobuf::Field::VarintField.encode(packed_value.size) + stream << packed_value else value.each { |val| write_pair(stream, field, val) } end @@ -241,14 +243,8 @@ def serialize_to(stream) write_pair(stream, field, value) end end - end - def serialize_to_string(string = '') - io = StringIO.new(string) - serialize_to(io) - result = io.string - result.force_encoding(::Protobuf::Message::STRING_ENCODING) if result.respond_to?(:force_encoding) - result + return stream end def set_field(tag, bytes) @@ -329,7 +325,7 @@ def copy_to(object, method) object.__send__(:initialize) @values.each do |name, value| - if value.is_a?(Field::FieldArray) + if value.is_a?(::Protobuf::Field::FieldArray) object.__send__(name).replace(value.map {|v| duplicate.call(v)}) else object.__send__("#{name}=", duplicate.call(value)) @@ -352,10 +348,8 @@ def _field_must_be_serialized?(field) # Encode key and value, and write to +stream+. def write_pair(stream, field, value) key = (field.tag << 3) | field.wire_type - key_bytes = ::Protobuf::Field::VarintField.encode(key) - stream.write(key_bytes) - bytes = field.encode(value) - stream.write(bytes) + stream << ::Protobuf::Field::VarintField.encode(key) + stream << field.encode(value) end end diff --git a/lib/protobuf/message/decoder.rb b/lib/protobuf/message/decoder.rb index 5884d947..ff21d284 100644 --- a/lib/protobuf/message/decoder.rb +++ b/lib/protobuf/message/decoder.rb @@ -43,10 +43,9 @@ def read_key(stream) # Read varint integer value from +stream+. def read_varint(stream) - read_method = stream.respond_to?(:readbyte) ? :readbyte : :readchar value = index = 0 begin - byte = stream.__send__(read_method) + byte = stream.readbyte value |= (byte & 0x7f) << (7 * index) index += 1 end while (byte & 0x80).nonzero? diff --git a/lib/protobuf/message/extend.rb b/lib/protobuf/message/extend.rb deleted file mode 100644 index 3cc52181..00000000 --- a/lib/protobuf/message/extend.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'protobuf/message/message' - -module Protobuf - class Extend < Message - MIN = -1.0/0 - MAX = 1.0/0 - end -end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index f91d9a23..1281e697 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -44,7 +44,7 @@ def <<(data) end def set_data(data) - @data = data.is_a?(::Protobuf::Message) ? data.serialize_to_string : data.to_s + @data = data.to_s @size = @data.size end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index e1ebb312..feb3745d 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -104,10 +104,10 @@ def post_init def rpc_request_data validate_request_type - return Protobuf::Socketrpc::Request.new( + return ::Protobuf::Socketrpc::Request.new( :service_name => @options[:service].name, :method_name => @options[:method].to_s, - :request_proto => @options[:request].serialize_to_string + :request_proto => @options[:request] ).serialize_to_string rescue => e fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index ab44fcc6..64b1fcbb 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -86,4 +86,3 @@ def send_response end end end - diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index c8d50e65..4322130c 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -49,7 +49,7 @@ def run end def send_data - response_data = @response.is_a?(::Protobuf::Message) ? @response.serialize_to_string : @response.to_s + response_data = @response.to_s # to_s is aliases as serialize_to_string in Message @stats.response_size = response_data.size zmq_error_check(@socket.send_string(response_data)) end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 4507666c..e573b2ca 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -140,6 +140,17 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) puts args[:profile_output] end + desc "benchmark Protobuf Message #serialize" + task :profile_protobuf_serialize, [:number, :profile_output] do |t, args| + args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") + create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } + ::PerfTools::CpuProfiler.start(args[:profile_output]) do + args[:number].to_i.times { Test::Resource.new(create_params).serialize } + end + + puts args[:profile_output] + end + desc "benchmark EventMachine client with EventMachine server" task :em_client_em_server, [:number, :length] do |t, args| args.with_defaults(:number => 1000, :length => 100) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 8ca62f7c..5c92c0d1 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -23,23 +23,21 @@ describe '#encode' do context "when there's no value for a required field" do let(:message) { ::Test::Resource.new } - let(:stream) { StringIO.new } it "raises a 'message not initialized' error" do expect { - message.serialize_to(stream) + message.serialize_to_string }.to raise_error(Protobuf::SerializationError, /required/i) end end context "repeated fields" do let(:message) { ::Test::Resource.new(:name => "something") } - let(:stream) { StringIO.new } it "does not raise an error when repeated fields are []" do expect { message.repeated_enum = [] - message.serialize_to(stream) + message.serialize_to_string }.to_not raise_error end end From b6d825d62506a7c6a8a8a9daced7f4f025671869 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Nov 2012 15:51:33 -0700 Subject: [PATCH 0224/1191] 2.4.3.rc1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 742c0325..acba6187 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.2' + VERSION = '2.4.3.rc1' PROTOC_VERSION = '2.4.1' end From 7ab303398cfa0fb387800c6f1fadb758a187a98f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 13:26:20 -0700 Subject: [PATCH 0225/1191] correct string encoding issues with UTF8/ASCII-8bit --- lib/protobuf/field/base_field.rb | 42 ++++++++++++++++++----------- lib/protobuf/field/bytes_field.rb | 23 ++++++++-------- lib/protobuf/field/field_array.rb | 11 +++++++- lib/protobuf/field/message_field.rb | 2 +- lib/protobuf/field/string_field.rb | 8 +++++- lib/protobuf/field/varint_field.rb | 10 ++++++- lib/protobuf/message.rb | 4 --- lib/protobuf/rpc/client.rb | 2 +- spec/lib/protobuf/message_spec.rb | 11 ++++++++ 9 files changed, 77 insertions(+), 36 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index acd2a136..b4f40c1c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -4,6 +4,15 @@ module Protobuf module Field class BaseField + ## + # Constants + # + PACKED_TYPES = [ + ::Protobuf::WireType::VARINT, + ::Protobuf::WireType::FIXED32, + ::Protobuf::WireType::FIXED64 + ].freeze + ## # Attributes # @@ -29,24 +38,15 @@ def initialize(message_class, rule, type, name, tag, options) @extension = options.delete(:extension) @packed = repeated? && options.delete(:packed) @deprecated = options.delete(:deprecated) - unless options.empty? - warn "WARNING: Invalid options: #{options.inspect} (in #{@message_class.name.split('::').last}.#{@name})" - end - - if packed? && ! [WireType::VARINT, WireType::FIXED32, WireType::FIXED64].include?(wire_type) - raise "Can't use packed encoding for `#{@type}' type" - end - @default_value = \ case @rule - when :repeated then - ::Protobuf::Field::FieldArray.new(self).freeze - when :required then - nil - when :optional then - typed_default_value + when :repeated then ::Protobuf::Field::FieldArray.new(self).freeze + when :required then nil + when :optional then typed_default_value end + warn_excess_options(options) unless options.empty? + validate_packed_field if packed? define_accessor end @@ -185,7 +185,7 @@ def define_array_setter define_method(field.setter_method_name) do |val| field.warn_if_deprecated - if val.nil? + if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) else @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) @@ -211,7 +211,7 @@ def define_setter define_method(field.setter_method_name) do |val| field.warn_if_deprecated - if val.nil? + if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) @values[field.name] = val @@ -230,6 +230,16 @@ def typed_default_value end end + def validate_packed_field + if packed? && ! ::Protobuf::Field::BaseField::PACKED_TYPES.include?(wire_type) + raise "Can't use packed encoding for `#{@type}' type" + end + end + + def warn_excess_options(options) + warn "WARNING: Invalid options: #{options.inspect} (in #{@message_class.name.split('::').last}.#{@name})" + end + end end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index c0c4d3cb..bd407689 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -1,14 +1,14 @@ +require 'protobuf/wire_type' + module Protobuf module Field class BytesField < BaseField + BYTES_ENCODING = "ASCII-8BIT".freeze + def self.default '' end - def wire_type - WireType::LENGTH_DELIMITED - end - def acceptable?(val) if val.nil? || val.is_a?(::Protobuf::Message) || val.instance_of?(String) return true @@ -18,20 +18,21 @@ def acceptable?(val) end def decode(bytes) - bytes.force_encoding(::Protobuf::Message::STRING_ENCODING) if bytes.respond_to?(:force_encoding) + bytes.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) bytes end def encode(value) - if value.is_a?(::Protobuf::Message) - value = value.serialize_to_string - else - value.force_encoding(::Protobuf::Message::STRING_ENCODING) if value.respond_to?(:force_encoding) - end + value = value.serialize_to_string if value.is_a?(::Protobuf::Message) + value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - string_size = VarintField.encode(value.size) + string_size = ::Protobuf::Field::VarintField.encode(value.size) string_size << value end + + def wire_type + ::Protobuf::WireType::LENGTH_DELIMITED + end end end end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index e5ad5456..dd41b92b 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -28,7 +28,7 @@ def unshift(val) end def replace(val) - raise TypeError unless val.is_a?(Array) + raise_type_error(val) unless val.is_a?(Array) val = val.map { |v| normalize(v) } super(val) end @@ -60,6 +60,15 @@ def normalize(value) value end end + + def raise_type_error(val) + error_text = <<-TYPE_ERROR + Expected value of type '#{@field.type}' + Got '#{val.class}' for protobuf field #{@field.name} + TYPE_ERROR + + raise TypeError, error_text + end end end end diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index b5c7f83a..17929ea0 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -21,7 +21,7 @@ def decode(bytes) def encode(value) bytes = value.serialize_to_string - result = VarintField.encode(bytes.size) + result = ::Protobuf::Field::VarintField.encode(bytes.size) result << bytes end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index fac8c5af..05e06359 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -6,9 +6,15 @@ class StringField < BytesField ENCODING = 'UTF-8'.freeze def decode(bytes) - bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) if bytes.respond_to?(:force_encoding) + bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) bytes end + + def encode(value) + value.force_encoding(::Protobuf::Field::StringField::ENCODING) + string_size = ::Protobuf::Field::VarintField.encode(value.size) + string_size << value + end end end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index b0070287..fce10667 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -49,7 +49,15 @@ def decode(value) end def encode(value) - self.class.encode(value) + return [value].pack('C') if value < 128 + + bytes = [] + until value == 0 + bytes << (0x80 | (value & 0x7f)) + value >>= 7 + end + bytes[-1] &= 0x7f + bytes.pack('C*') end def wire_type diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index f4e67021..d52b029e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -6,10 +6,6 @@ module Protobuf class Message - ## - # Constants - # - STRING_ENCODING = "ASCII-8BIT".freeze ## # Class Methods diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 3566795e..be88bf80 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -10,7 +10,7 @@ class Client extend Forwardable include Protobuf::Logger::LogMethods - delegate [:options, :complete_cb, :success_cb, :failure_cb] => :@connector + def_delegators :@connector, :options, :complete_cb, :success_cb, :failure_cb attr_reader :connector # Create a new client with default options (defined in ClientConnection) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 5c92c0d1..40ab93f7 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -40,6 +40,17 @@ message.serialize_to_string }.to_not raise_error end + + it "sets the value to nil when empty array is passed" do + message.repeated_enum = [] + message.instance_variable_get("@values")[:repeated_enum].should be_nil + end + + it "raises TypeError when a non-array replaces it" do + expect { + message.repeated_enum = 2 + }.to raise_error(/value of type/) + end end end From b75d21127ead42a1856c07f24f6559226919fe99 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 13:39:14 -0700 Subject: [PATCH 0226/1191] move predicates with type data into respective classes --- lib/protobuf/field/base_field.rb | 6 ++---- lib/protobuf/field/enum_field.rb | 4 ++++ lib/protobuf/field/message_field.rb | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index b4f40c1c..d11efefe 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -58,13 +58,11 @@ def acceptable?(value) end def enum? - return @_enum unless @_enum.nil? - @_enum = (self.class < ::Protobuf::Field::EnumField) + false end def message? - return @_message unless @_message.nil? - @_message = (self.class < ::Protobuf::Field::MessageField) + false end # Decode +bytes+ and pass to +message_instance+. diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 364b1238..857b410b 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -19,6 +19,10 @@ def encode(value) super(value.to_i) end + def enum? + true + end + private def typed_default_value diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 17929ea0..cca2ae2a 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -25,6 +25,10 @@ def encode(value) result << bytes end + def message? + true + end + def wire_type ::Protobuf::WireType::LENGTH_DELIMITED end From a8f2f5846c35e3331dec200b7dc7e05a74f35869 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 13:52:42 -0700 Subject: [PATCH 0227/1191] move predicate setting to initialization --- lib/protobuf/field/base_field.rb | 41 ++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d11efefe..7338e98b 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -38,13 +38,9 @@ def initialize(message_class, rule, type, name, tag, options) @extension = options.delete(:extension) @packed = repeated? && options.delete(:packed) @deprecated = options.delete(:deprecated) - @default_value = \ - case @rule - when :repeated then ::Protobuf::Field::FieldArray.new(self).freeze - when :required then nil - when :optional then typed_default_value - end + set_rule_predicates + set_default_value warn_excess_options(options) unless options.empty? validate_packed_field if packed? define_accessor @@ -101,25 +97,22 @@ def encode(value) end def extension? - !!@extension + !! @extension end # Is this a repeated field? def repeated? - return @_repeated unless @_repeated.nil? - @_repeated = (@rule == :repeated) + !! @repeated end # Is this a required field? def required? - return @_required unless @_required.nil? - @_required = (@rule == :required) + !! @required end # Is this a optional field? def optional? - return @_optional unless @_optional.nil? - @_optional = (@rule == :optional) + !! @optional end # Is this a deprecated field? @@ -220,6 +213,28 @@ def define_setter end end + def set_default_value + @default_value = case + when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze + when required? then nil + when optional? then typed_default_value + end + end + + def set_rule_predicates + case @rule + when :repeated then + @required = @optional = false + @repeated = true + when :required then + @repeated = @optional = false + @required = true + when :optional then + @repeated = @required = false + @optional = true + end + end + def typed_default_value if @default.nil? self.class.default From 80ccdc9d606ed6a584922b9991ec317eae21ad0e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 17:00:19 -0700 Subject: [PATCH 0228/1191] only lookup the value once for field_must_be_serialized --- lib/protobuf/field/base_field.rb | 1 + lib/protobuf/message.rb | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 7338e98b..2835b573 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -175,6 +175,7 @@ def define_array_setter @message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated + val.compact! if val.respond_to?(:compact!) if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index d52b029e..7317fa1c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -156,7 +156,7 @@ def each_field def each_field_for_serialization all_fields.each do |field| - next unless _field_must_be_serialized?(field) + next unless __field_must_be_serialized__?(field) value = @values[field.name] @@ -265,6 +265,14 @@ def to_json to_hash.to_json end + def to_proto + self + end + + def to_proto_hash + self.to_hash + end + def ==(obj) return false unless obj.is_a?(self.class) each_field do |field, value| @@ -330,15 +338,13 @@ def copy_to(object, method) object end - def _field_must_be_serialized?(field) - return true if field.required? - - if field.repeated? && has_field?(field.name) - @values[field.name].compact! - @values.delete(field.name) if @values[field.name].empty? - end + def __field_must_be_serialized__?(field) + field.required? || __field_value_is_present__?(field) + end - return has_field?(field.name) + def __field_value_is_present__?(field) + value = @values[field.name] + !value.nil? && (value.present? || [true, false].include?(value)) end # Encode key and value, and write to +stream+. From 1e1d6c3a3c635078382f68a95c8fa345a97a00db Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 17:19:29 -0700 Subject: [PATCH 0229/1191] speed up specs and set a lower auto collect timout --- lib/protobuf/rpc/servers/socket/server.rb | 2 +- spec/lib/protobuf/rpc/client_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 684961e1..76121140 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -9,7 +9,7 @@ class Server include ::Protobuf::Rpc::Server include ::Protobuf::Logger::LogMethods - AUTO_COLLECT_TIMEOUT = 20 # seconds + AUTO_COLLECT_TIMEOUT = 5 # seconds def self.cleanup? # every 10 connections run a cleanup routine after closing the response diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index e2239460..5a89d41d 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -9,7 +9,7 @@ context "when using fiber based calls" do it "waits for response" do EventMachine.fiber_run do - StubServer.new(:delay => 3) do |server| + StubServer.new(:delay => 1) do |server| client = Test::ResourceService.client start = now From 74e6a3a4ed11e7c20b23ad42d387d7d7f01e4f97 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 17:42:04 -0700 Subject: [PATCH 0230/1191] add to_proto_hash alias --- lib/protobuf/message.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 7317fa1c..a67d89c9 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -269,10 +269,6 @@ def to_proto self end - def to_proto_hash - self.to_hash - end - def ==(obj) return false unless obj.is_a?(self.class) each_field do |field, value| @@ -301,6 +297,7 @@ def []=(name, value) # Instance Aliases # alias_method :to_hash_value, :to_hash + alias_method :to_proto_hash, :to_hash alias_method :to_s, :serialize_to_string alias_method :bytes, :serialize_to_string alias_method :serialize, :serialize_to_string From 857f58f94015adc29a7000990c11be2e70e0d4ac Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 17:49:29 -0700 Subject: [PATCH 0231/1191] go full on 2.4.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index acba6187..512d0568 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.3.rc1' + VERSION = '2.4.3' PROTOC_VERSION = '2.4.1' end From 755363b3331a9ae3762604d37cddd853ecf997c4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 18:43:58 -0700 Subject: [PATCH 0232/1191] update array setter to deal with frozen arrays and constant array contructs --- lib/protobuf/field/base_field.rb | 13 ++++++++++++- lib/protobuf/field/field_array.rb | 3 ++- spec/lib/protobuf/message_spec.rb | 12 ++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 2835b573..ab551efb 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -175,7 +175,18 @@ def define_array_setter @message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated - val.compact! if val.respond_to?(:compact!) + + if val.is_a?(Array) + val = val.dup + val.compact! + else + error_text = <<-TYPE_ERROR + Expected value of type '#{field.type}' + Got '#{val.class}' for protobuf field #{field.name} + TYPE_ERROR + + raise TypeError, error_text + end if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index dd41b92b..f0fd6dcf 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -29,7 +29,7 @@ def unshift(val) def replace(val) raise_type_error(val) unless val.is_a?(Array) - val = val.map { |v| normalize(v) } + val = val.map! { |v| normalize(v) } super(val) end @@ -52,6 +52,7 @@ def to_s # def normalize(value) raise TypeError unless @field.acceptable?(value) + if @field.is_a?(::Protobuf::Field::EnumField) @field.type.fetch(value) elsif @field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 40ab93f7..49d2953a 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -46,6 +46,18 @@ message.instance_variable_get("@values")[:repeated_enum].should be_nil end + it "does not compact the edit original array" do + a = [nil].freeze + message.repeated_enum = a + message.repeated_enum.should eq([]) + a.should eq([nil].freeze) + end + + it "compacts the set array" do + message.repeated_enum = [nil] + message.repeated_enum.should eq([]) + end + it "raises TypeError when a non-array replaces it" do expect { message.repeated_enum = 2 From f0043ffa07443ae1f977cbc003b4a38eec162af6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 18:46:14 -0700 Subject: [PATCH 0233/1191] bump to 2.4.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 512d0568..ae2ab7b1 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.3' + VERSION = '2.4.4' PROTOC_VERSION = '2.4.1' end From c57c75ba9eaa02989f336f778596dd1046810a00 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 19:15:54 -0700 Subject: [PATCH 0234/1191] allow message fields and array field to be set to values that respond_to to_proto --- lib/protobuf/field/field_array.rb | 1 + lib/protobuf/field/message_field.rb | 2 ++ lib/protobuf/rpc/service.rb | 5 ++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index f0fd6dcf..41232559 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -51,6 +51,7 @@ def to_s # Private Instance Methods # def normalize(value) + value = value.to_proto if value.respond_to?(:to_proto) raise TypeError unless @field.acceptable?(value) if @field.is_a?(::Protobuf::Field::EnumField) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index cca2ae2a..090be9df 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -44,6 +44,8 @@ def define_setter @values.delete(field.name) when val.is_a?(field.type) then @values[field.name] = val + when val.respond_to?(:to_proto) then + @values[field.name] = val.to_proto when val.respond_to?(:to_hash) then @values[field.name] = field.type.new(val.to_hash) else diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index cf89e0e3..3d557f8e 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -11,8 +11,8 @@ module Rpc RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) class Service - include Protobuf::Rpc::ServiceFilters - include Protobuf::Logger::LogMethods + include ::Protobuf::Rpc::ServiceFilters + include ::Protobuf::Logger::LogMethods attr_reader :response, :rpc @@ -98,7 +98,6 @@ def self.rpc_method?(name) rpcs.key?(name) end - ## # Instance Methods # From 9381afe499e1254471bf7f17cdc64a9dccf343a4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 19:16:43 -0700 Subject: [PATCH 0235/1191] bump to 2.4.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index ae2ab7b1..169248b2 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.4' + VERSION = '2.4.5' PROTOC_VERSION = '2.4.1' end From 07264f2146ca050e41b7119e9c3d12b902fa0160 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 17 Nov 2012 20:15:31 -0700 Subject: [PATCH 0236/1191] fix decoding issue with enum --- lib/protobuf/enum.rb | 2 +- lib/protobuf/version.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 062db071..1642f581 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -18,7 +18,7 @@ def self.define(name, value) def self.fetch(value) case value when ::Protobuf::EnumValue then - value.to_i + value when Numeric then enum_by_value(value.to_i) when String, Symbol then diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 169248b2..5c81fa62 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.5' + VERSION = '2.4.6' PROTOC_VERSION = '2.4.1' end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 0dc88041..d1c10146 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -18,7 +18,7 @@ describe '.fetch' do context 'when value is an EnumValue' do it 'responds with that object' do - Test::EnumTestType.fetch(Test::EnumTestType::THREE).should eq Test::EnumTestType::THREE + Test::EnumTestType.fetch(Test::EnumTestType::THREE).name.should eq Test::EnumTestType::THREE.name end end From 38d656554e8f91bc849d2ad31db38dbc89a790be Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 18 Nov 2012 11:54:26 -0700 Subject: [PATCH 0237/1191] correct the last day of encoding change with string and keep encoding backwards compat --- lib/protobuf/field/base_field.rb | 10 ---------- lib/protobuf/field/string_field.rb | 22 +++++++++++++++++++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index ab551efb..d9a2efa9 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -125,16 +125,6 @@ def packed? !! @packed end - # Upper limit for this field. - def max - self.class.max - end - - # Lower limit for this field. - def min - self.class.min - end - def to_s "#{@rule} #{@type} #{@name} = #{@tag} #{@default ? "[default=#{@default.inspect}]" : ''}" end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 05e06359..16c1cb0d 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -5,9 +5,25 @@ module Field class StringField < BytesField ENCODING = 'UTF-8'.freeze - def decode(bytes) - bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) - bytes + def define_setter + field = self + @message_class.class_eval do + define_method(field.setter_method_name) do |val| + begin + field.warn_if_deprecated + + if val.nil? || val.empty? + @values.delete(field.name) + elsif field.acceptable?(val) + @values[field.name] = val.dup + else + raise TypeError, "unacceptable value #{val} for type #{field.type}" + end + rescue NoMethodError => ex + raise TypeError, "unacceptable value #{val} for type #{field.type} field #{field.name}" + end + end + end end def encode(value) From a06ce697bed447d32a0cbaf3648df7e2e637d117 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 18 Nov 2012 11:54:46 -0700 Subject: [PATCH 0238/1191] bump to 2.4.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5c81fa62..97518b5e 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.6' + VERSION = '2.4.7' PROTOC_VERSION = '2.4.1' end From d029dcd218cf3fe23a31883dfdfe4698ab9f29ba Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 19 Nov 2012 14:44:30 -0700 Subject: [PATCH 0239/1191] strings/bytes can be "" but cannot be nil and laxing the requirement on request_proto in a service call --- lib/protobuf/field/bytes_field.rb | 21 +++++++++++++++++++++ lib/protobuf/field/string_field.rb | 21 --------------------- lib/protobuf/message.rb | 15 +++++---------- lib/protobuf/rpc/service.rb | 6 +++++- lib/protobuf/rpc/service_dispatcher.rb | 4 +++- proto/rpc.pb.rb | 2 +- proto/rpc.proto | 2 +- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index bd407689..98f84aca 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -22,6 +22,27 @@ def decode(bytes) bytes end + def define_setter + field = self + @message_class.class_eval do + define_method(field.setter_method_name) do |val| + begin + field.warn_if_deprecated + + if val.nil? + @values.delete(field.name) + elsif field.acceptable?(val) + @values[field.name] = val.dup + else + raise TypeError, "unacceptable value #{val} for type #{field.type}" + end + rescue NoMethodError => ex + raise TypeError, "unacceptable value #{val} for type #{field.type} field #{field.name}" + end + end + end + end + def encode(value) value = value.serialize_to_string if value.is_a?(::Protobuf::Message) value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 16c1cb0d..20d9536b 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -5,27 +5,6 @@ module Field class StringField < BytesField ENCODING = 'UTF-8'.freeze - def define_setter - field = self - @message_class.class_eval do - define_method(field.setter_method_name) do |val| - begin - field.warn_if_deprecated - - if val.nil? || val.empty? - @values.delete(field.name) - elsif field.acceptable?(val) - @values[field.name] = val.dup - else - raise TypeError, "unacceptable value #{val} for type #{field.type}" - end - rescue NoMethodError => ex - raise TypeError, "unacceptable value #{val} for type #{field.type} field #{field.name}" - end - end - end - end - def encode(value) value.force_encoding(::Protobuf::Field::StringField::ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value.size) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a67d89c9..36415ffd 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -160,11 +160,11 @@ def each_field_for_serialization value = @values[field.name] - if value.present? || [true, false].include?(value) - yield(field, value) - else - # Only way you can get here is if you are required and not present + if value.nil? + # Only way you can get here is if you are required and nil raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" + else + yield(field, value) end end end @@ -336,12 +336,7 @@ def copy_to(object, method) end def __field_must_be_serialized__?(field) - field.required? || __field_value_is_present__?(field) - end - - def __field_value_is_present__?(field) - value = @values[field.name] - !value.nil? && (value.present? || [true, false].include?(value)) + field.required? || !@values[field.name].nil? end # Encode key and value, and write to +stream+. diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 3d557f8e..d5272344 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -147,7 +147,11 @@ def callable_rpc_method(method_name) # Request object for this rpc cycle. Not assignable. # def request - @_request ||= rpcs[@rpc].request_type.new.parse_from_string(@request_bytes) + @_request ||= if @request_bytes.present? + rpcs[@rpc].request_type.new.parse_from_string(@request_bytes) + else + rpcs[@rpc].request_type.new + end rescue => e raise BadRequestProto, "Unable to parse request: #{e.message}" end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index e82f8f06..f26ef90b 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -71,8 +71,10 @@ def coerced_response # def init_method method_name = outer_request.method_name.underscore.to_sym + request_proto = outer_request.has_field?(:request_proto) ? outer_request.request_proto : nil + if service_klass.rpc_method?(method_name) - self.service = service_klass.new(method_name, outer_request.request_proto) + self.service = service_klass.new(method_name, request_proto) self.callable_method = service.callable_rpc_method(method_name) self.definition = service.rpcs[method_name] else diff --git a/proto/rpc.pb.rb b/proto/rpc.pb.rb index eca46619..a885eb4b 100644 --- a/proto/rpc.pb.rb +++ b/proto/rpc.pb.rb @@ -36,7 +36,7 @@ class Response < ::Protobuf::Message; end # ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1) ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2) - ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::BytesField, :request_proto, 3) + ::Protobuf::Socketrpc::Request.optional(::Protobuf::Field::BytesField, :request_proto, 3) ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1) ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2) diff --git a/proto/rpc.proto b/proto/rpc.proto index 1ab035dc..591b2f32 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -33,7 +33,7 @@ message Request { required string method_name = 2; // RPC request proto - required bytes request_proto = 3; + optional bytes request_proto = 3; } message Response { From 61a90ecdccbb981065e31e2002a782888e211bb6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 19 Nov 2012 14:44:51 -0700 Subject: [PATCH 0240/1191] bump to 2.4.8 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 97518b5e..f750eb1a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.7' + VERSION = '2.4.8' PROTOC_VERSION = '2.4.1' end From 0863a1665e3102edbca8483c1f58b3fe7190769b Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 15 Nov 2012 08:44:39 -0700 Subject: [PATCH 0241/1191] make corrections --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e4308485..ad3574fb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Let's say you have a `defs.proto` file that defines a User message. package foo; message User { required string first_name = 1; - required string last_name = 1; + required string last_name = 2; } Now let's compile that definition to ruby: @@ -147,7 +147,7 @@ module Foo end ``` -Simply implement the instance method for the defined rpc. You can provide any other methods in this class as helpers, but only those defined in the proto file will be callable by remote clients. Every request made by a client will provide a non-empty request of the defined type. The server creates a new service instance based on the request, so you should not be constrained to just the endpoint method. This is similar to rails controllers where only methods defined by the routes file are hooked up to HTTP requests, but it's very common to implement private methods the aid in code quality and simpilicity. +Simply implement the instance method for the defined rpc. You can provide any other methods in this class as helpers, but only those defined in the proto file will be callable by remote clients. Every request made by a client will provide a non-empty request of the defined type. The server creates a new service instance based on the request, so you should not be constrained to just the endpoint method. This is similar to rails controllers where only methods defined by the routes file are hooked up to HTTP requests, but it's very common to implement private methods to aid in code quality and simpilicity. Every instance has a `request` and `response` object used for fulfilling the call, again, similar to a rails controller action. You should never attempt to modify the `request` object. The `response` object however should be modified or replaced entirely. If you need to create your own response object (a valid case), simply use `respond_with(new_response)`. The returned object should conform to one of three properties: @@ -176,7 +176,9 @@ This means that the client's `on_failure` callback will be invoked instead of th Service Filters provides ActionController-style filter support to service instances, specifically adding `before_filter`, `after_filter`, and `around_filter`. ```ruby -class Foo::UserService < ::Protobuf::Rpc::Service +require lib/foo/user.pb + +class Foo::UserService before_filter :start_request_timer after_filter :end_request_timer around_filter :benchmark_request @@ -236,13 +238,13 @@ __:except__ – The opposite of the `:only` option. A string/symbol or Array of ### Servers -A service is nothing without being hooked up to a socket. It's the nerdy kid waiting by the telephone for someone to call without knowing that the phone company disconnected their house. Sad and pathetic. So hook the phone lines! +A service is nothing without being hooked up to a socket. It's the nerdy kid waiting by the telephone for someone to call without knowing that the phone company disconnected their house. Sad and pathetic. So hook up the phone lines! ``` $ rpc_server -o myserver.com -p 9939 -l ./log/protobuf.log ./config/environment.rb ``` -The previous call will start an Socket server running on the given host and port which will load your application into memory. You certainly don't have to run rails or any other framework, just make sure you have some kind of file that will load your services all into memory. The server doesn't know where you put your code, so tell it. +The previous call will start a Socket server running on the given host and port which will load your application into memory. You certainly don't have to run rails or any other framework, just make sure you have some kind of file that will load your services all into memory. The server doesn't know where you put your code, so tell it. Be aware that the server needs to be able to translate the socket stream of bytes into an actual protobuf request object. If the definition for that request object aren't known to the server, you're going to have a long day getting this going. It's necessary to store all your definitions and their generated classes in a shared repository (read: gem) so that both client and server have access to the ruby classes in their respective load paths. @@ -287,7 +289,7 @@ Foo::UserService.client.find(req) do |c| # Register a block for execution when the response # is deemed a failure. This can be either a client-side - # or server-side failure. The object passed the to the + # or server-side failure. The object passed to the # block has a `message` and a `code` attribute # to aid in logging/diagnosing the failure. c.on_failure do |err| From e3fdb81af47be11502e4257f71b8ec6d7402d38f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 19 Nov 2012 16:15:25 -0700 Subject: [PATCH 0242/1191] Update README.md More readme fixes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad3574fb..5f12ed14 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ This means that the client's `on_failure` callback will be invoked instead of th Service Filters provides ActionController-style filter support to service instances, specifically adding `before_filter`, `after_filter`, and `around_filter`. ```ruby -require lib/foo/user.pb +require 'lib/foo/user.pb' class Foo::UserService before_filter :start_request_timer From 7a796fde3626f3d31c42884ae4408aa83604dace Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Nov 2012 14:08:42 -0700 Subject: [PATCH 0243/1191] Add 'caller' field to outer request proto for client hostname/address --- lib/protobuf/rpc/rpc.pb.rb | 119 +++++++++---------------------------- proto/rpc.pb.rb | 48 --------------- proto/rpc.proto | 65 +++++++++----------- 3 files changed, 54 insertions(+), 178 deletions(-) delete mode 100644 proto/rpc.pb.rb diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index f7ac8f8e..d7b12fca 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -1,78 +1,6 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# // Copyright (c) 2009 Shardul Deo -# // -# // Permission is hereby granted, free of charge, to any person obtaining a copy -# // of this software and associated documentation files (the "Software"), to deal -# // in the Software without restriction, including without limitation the rights -# // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# // copies of the Software, and to permit persons to whom the Software is -# // furnished to do so, subject to the following conditions: -# // -# // The above copyright notice and this permission notice shall be included in -# // all copies or substantial portions of the Software. -# // -# // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# // THE SOFTWARE. -# -# // Author: Shardul Deo -# // -# // Protobufs needed for socket rpcs. -# -# package protobuf.socketrpc; -# -# message Request { -# -# // RPC service full name -# required string service_name = 1; -# -# // RPC method name -# required string method_name = 2; -# -# // RPC request proto -# required bytes request_proto = 3; -# } -# -# message Response { -# -# // RPC response proto -# optional bytes response_proto = 1; -# -# // Error, if any -# optional string error = 2; -# -# // Was callback invoked -# optional bool callback = 3 [default = false]; -# -# // Error Reason -# optional ErrorReason error_reason = 4; -# } -# -# // Possible error reasons -# // The server-side errors are returned in the response from the server. -# // The client-side errors are returned by the client-side code when it doesn't -# // have a response from the server. -# enum ErrorReason { -# -# // Server-side errors -# BAD_REQUEST_DATA = 0; // Server received bad request data -# BAD_REQUEST_PROTO = 1; // Server received bad request proto -# SERVICE_NOT_FOUND = 2; // Service not found on server -# METHOD_NOT_FOUND = 3; // Method not found on server -# RPC_ERROR = 4; // Rpc threw exception on server -# RPC_FAILED = 5; // Rpc failed on server -# -# // Client-side errors (these are returned by the client-side code) -# INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto -# BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto -# UNKNOWN_HOST = 8; // Could not find supplied host -# IO_ERROR = 9; // I/O error while communicating with server -# } +## +# This file is auto-generated. DO NOT EDIT! +# require 'protobuf/message' module Protobuf @@ -91,28 +19,35 @@ class Response < ::Protobuf::Message; end ## # Enum Values # - ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_DATA, 0 - ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_PROTO, 1 - ::Protobuf::Socketrpc::ErrorReason.define :SERVICE_NOT_FOUND, 2 - ::Protobuf::Socketrpc::ErrorReason.define :METHOD_NOT_FOUND, 3 - ::Protobuf::Socketrpc::ErrorReason.define :RPC_ERROR, 4 - ::Protobuf::Socketrpc::ErrorReason.define :RPC_FAILED, 5 - ::Protobuf::Socketrpc::ErrorReason.define :INVALID_REQUEST_PROTO, 6 - ::Protobuf::Socketrpc::ErrorReason.define :BAD_RESPONSE_PROTO, 7 - ::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8 - ::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9 + class ErrorReason + define :BAD_REQUEST_DATA, 0 + define :BAD_REQUEST_PROTO, 1 + define :SERVICE_NOT_FOUND, 2 + define :METHOD_NOT_FOUND, 3 + define :RPC_ERROR, 4 + define :RPC_FAILED, 5 + define :INVALID_REQUEST_PROTO, 6 + define :BAD_RESPONSE_PROTO, 7 + define :UNKNOWN_HOST, 8 + define :IO_ERROR, 9 + end ## # Message Fields # - ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1) - ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2) - ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::BytesField, :request_proto, 3) + class Request + required ::Protobuf::Field::StringField, :service_name, 1 + required ::Protobuf::Field::StringField, :method_name, 2 + optional ::Protobuf::Field::BytesField, :request_proto, 3 + optional ::Protobuf::Field::StringField, :caller, 4 + end - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1) - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2) - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false) - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4) + class Response + optional ::Protobuf::Field::BytesField, :response_proto, 1 + optional ::Protobuf::Field::StringField, :error, 2 + optional ::Protobuf::Field::BoolField, :callback, 3, :default => false + optional ::Protobuf::Socketrpc::ErrorReason, :error_reason, 4 + end end end diff --git a/proto/rpc.pb.rb b/proto/rpc.pb.rb deleted file mode 100644 index a885eb4b..00000000 --- a/proto/rpc.pb.rb +++ /dev/null @@ -1,48 +0,0 @@ -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' - -module Protobuf - module Socketrpc - ## - # Enum Classes - # - class ErrorReason < ::Protobuf::Enum; end - - ## - # Message Classes - # - class Request < ::Protobuf::Message; end - class Response < ::Protobuf::Message; end - - ## - # Enum Values - # - ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_DATA, 0 - ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_PROTO, 1 - ::Protobuf::Socketrpc::ErrorReason.define :SERVICE_NOT_FOUND, 2 - ::Protobuf::Socketrpc::ErrorReason.define :METHOD_NOT_FOUND, 3 - ::Protobuf::Socketrpc::ErrorReason.define :RPC_ERROR, 4 - ::Protobuf::Socketrpc::ErrorReason.define :RPC_FAILED, 5 - ::Protobuf::Socketrpc::ErrorReason.define :INVALID_REQUEST_PROTO, 6 - ::Protobuf::Socketrpc::ErrorReason.define :BAD_RESPONSE_PROTO, 7 - ::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8 - ::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9 - - - ## - # Message Fields - # - ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1) - ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2) - ::Protobuf::Socketrpc::Request.optional(::Protobuf::Field::BytesField, :request_proto, 3) - - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1) - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2) - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false) - ::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4) - - - end -end diff --git a/proto/rpc.proto b/proto/rpc.proto index 591b2f32..c786d24c 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -18,56 +18,45 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// Author: Shardul Deo +// Authors: Shardul Deo, BJ Neilsen // // Protobufs needed for socket rpcs. package protobuf.socketrpc; -message Request { - - // RPC service full name - required string service_name = 1; - - // RPC method name - required string method_name = 2; - - // RPC request proto - optional bytes request_proto = 3; +message Request +{ + required string service_name = 1; // Fully- qualified Service class name + required string method_name = 2; // Service method to invoke + optional bytes request_proto = 3; // Serialized request bytes + optional string caller = 4; // Calling hostname or address } -message Response { - - // RPC response proto - optional bytes response_proto = 1; - - // Error, if any - optional string error = 2; - - // Was callback invoked - optional bool callback = 3 [default = false]; - - // Error Reason - optional ErrorReason error_reason = 4; +message Response +{ + optional bytes response_proto = 1; // Serialized response + optional string error = 2; // Error message, if any + optional bool callback = 3 [default = false]; // Was callback invoked (not sure what this is for) + optional ErrorReason error_reason = 4; // Error Reason } // Possible error reasons // The server-side errors are returned in the response from the server. -// The client-side errors are returned by the client-side code when it doesn't +// The client-side errors are returned by the client-side code when it doesn't // have a response from the server. -enum ErrorReason { - +enum ErrorReason +{ // Server-side errors - BAD_REQUEST_DATA = 0; // Server received bad request data - BAD_REQUEST_PROTO = 1; // Server received bad request proto - SERVICE_NOT_FOUND = 2; // Service not found on server - METHOD_NOT_FOUND = 3; // Method not found on server - RPC_ERROR = 4; // Rpc threw exception on server - RPC_FAILED = 5; // Rpc failed on server - + BAD_REQUEST_DATA = 0; // Server received bad request data + BAD_REQUEST_PROTO = 1; // Server received bad request proto + SERVICE_NOT_FOUND = 2; // Service not found on server + METHOD_NOT_FOUND = 3; // Method not found on server + RPC_ERROR = 4; // Rpc threw exception on server + RPC_FAILED = 5; // Rpc failed on server + // Client-side errors (these are returned by the client-side code) - INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto - BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto - UNKNOWN_HOST = 8; // Could not find supplied host - IO_ERROR = 9; // I/O error while communicating with server + INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto + BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto + UNKNOWN_HOST = 8; // Could not find supplied host + IO_ERROR = 9; // I/O error while communicating with server } From d58919e6a58737777179128ff04e254ec98e6942 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Nov 2012 15:01:43 -0700 Subject: [PATCH 0244/1191] Add client_host config method to Protobuf module Calls to Protobuf.client_host to return the host or address of the machine making client RPC calls (default value is the `hostname` of the machine). Also provided is a setter to override this value and memoize for future client calls within the running process. --- lib/protobuf.rb | 13 +++++++++++++ spec/lib/protobuf_spec.rb | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 897920d4..702babe1 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -14,6 +14,19 @@ module Protobuf module_function + # Client Host + # + # Default: `hostname` of the system + # + # The name or address of the host to use during client RPC calls. + def self.client_host + @_client_host ||= `hostname`.chomp + end + + def self.client_host=(host) + @_client_host = host + end + # Connector Type # # Default: socket diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index ee35e9e8..4d5f24be 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -3,6 +3,22 @@ describe ::Protobuf do + describe '.client_host' do + after { ::Protobuf.instance_variable_set(:@_client_host, nil) } + + subject { ::Protobuf.client_host } + + context 'when client_host is not pre-configured' do + it { should eq `hostname`.chomp } + end + + context 'when client_host is pre-configured' do + let(:hostname) { 'override.myhost.com' } + before { ::Protobuf.client_host = hostname } + it { should eq hostname } + end + end + describe '.connector_type' do before { described_class.instance_variable_set(:@_connector_type, nil) } From c83953c9f7e612462b564c9e5902c449ab2afa0f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Nov 2012 15:03:44 -0700 Subject: [PATCH 0245/1191] Set client_host on wrapper request :caller field For client RPC calls, set the :caller field with the value returned by the :client_host client option or the Protobuf.client_host configured value. Added the :client_host option to default options hash used by the client common base. --- lib/protobuf/rpc/connectors/base.rb | 11 ++-- lib/protobuf/rpc/connectors/common.rb | 26 ++++---- .../protobuf/rpc/connectors/common_spec.rb | 60 +++++++++++++++---- 3 files changed, 69 insertions(+), 28 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index e47b55ff..d2650c37 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -9,14 +9,15 @@ module Protobuf module Rpc module Connectors DEFAULT_OPTIONS = { - :service => nil, # Service to invoke - :method => nil, # Service method to call - :host => '127.0.0.1', # A default host (usually overridden) - :port => '9399', # A default port (usually overridden) + :service => nil, # Fully-qualified Service class + :method => nil, # Service method to invoke + :host => '127.0.0.1', # The hostname or address of the service (usually overridden or pre-configured) + :port => '9399', # The port of the service (usually overridden or pre-configured) :request => nil, # The request object sent by the client :request_type => nil, # The request type expected by the client :response_type => nil, # The response type expected by the client - :timeout => 30 # The default timeout for the request, also handled by client.rb + :timeout => 30, # The default timeout for the request, also handled by client.rb + :client_host => nil # The hostname or address of this client } class Base diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index feb3745d..4128efbc 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -11,6 +11,10 @@ def any_callbacks? end end + def request_caller + @options[:client_host] || ::Protobuf.client_host + end + def complete @stats.stop log_info { @stats.to_s } @@ -101,21 +105,21 @@ def post_init fail(:RPC_ERROR, "Connection error: #{e.message}") end - def rpc_request_data - validate_request_type + def request_bytes + validate_request_type! + fields = { :service_name => @options[:service].name, + :method_name => @options[:method].to_s, + :request_proto => @options[:request], + :caller => request_caller } - return ::Protobuf::Socketrpc::Request.new( - :service_name => @options[:service].name, - :method_name => @options[:method].to_s, - :request_proto => @options[:request] - ).serialize_to_string + return ::Protobuf::Socketrpc::Request.new(fields).serialize_to_string rescue => e fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") end def setup_connection initialize_stats - @request_data = rpc_request_data + @request_data = request_bytes end def succeed(response) @@ -129,7 +133,7 @@ def succeed(response) complete end - def validate_request_type + def validate_request_type! unless @options[:request].class == @options[:request_type] expected = @options[:request_type].name actual = @options[:request].class.name @@ -138,13 +142,13 @@ def validate_request_type end def verify_callbacks - if !any_callbacks? + unless any_callbacks? log_debug { sign_message("No callbacks set, using data_callback") } @success_cb = @failure_cb = self.method(:data_callback) end end - def verify_options + def verify_options! # Verify the options that are necessary and merge them in [:service, :method, :host, :port].each do |opt| fail(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 216d977e..bf4df29e 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -10,20 +10,23 @@ end end - subject{ @subject ||= common_class.new({}) } + let(:subject_options) { {} } + + subject { @subject ||= common_class.new(subject_options) } context "API" do - specify{ subject.respond_to?(:any_callbacks?).should be_true } - specify{ subject.respond_to?(:data_callback).should be_true } - specify{ subject.respond_to?(:error).should be_true } - specify{ subject.respond_to?(:fail).should be_true } - specify{ subject.respond_to?(:complete).should be_true } - specify{ subject.respond_to?(:parse_response).should be_true } - specify{ subject.respond_to?(:verify_options).should be_true } - specify{ subject.respond_to?(:verify_callbacks).should be_true } + specify { subject.respond_to?(:any_callbacks?).should be_true } + specify { subject.respond_to?(:request_caller).should be_true } + specify { subject.respond_to?(:data_callback).should be_true } + specify { subject.respond_to?(:error).should be_true } + specify { subject.respond_to?(:fail).should be_true } + specify { subject.respond_to?(:complete).should be_true } + specify { subject.respond_to?(:parse_response).should be_true } + specify { subject.respond_to?(:verify_options!).should be_true } + specify { subject.respond_to?(:verify_callbacks).should be_true } end - context "#any_callbacks?" do + describe "#any_callbacks?" do [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| it "returns true if #{cb} is provided" do @@ -42,7 +45,19 @@ end - context "#data_callback" do + describe '#request_caller' do + its(:request_caller) { should eq ::Protobuf.client_host } + + context 'when "client_host" option is given to initializer' do + let(:hostname) { 'myhost.myserver.com' } + let(:subject_options) { { :client_host => hostname } } + + its(:request_caller) { should_not eq ::Protobuf.client_host } + its(:request_caller) { should eq hostname } + end + end + + describe "#data_callback" do it "changes state to use the data callback" do subject.data_callback("data") subject.instance_variable_get(:@used_data_callback).should be_true @@ -54,7 +69,28 @@ end end - context "#verify_callbacks" do + describe '#request_bytes' do + let(:service) { Test::ResourceService } + let(:method) { :find } + let(:request) { '' } + let(:client_host) { 'myhost.myservice.com' } + let(:subject_options) { { :service => service, + :method => method, + :request => request, + :client_host => client_host } } + + let(:expected) { ::Protobuf::Socketrpc::Request.new({ :service_name => service.name, + :method_name => 'find', + :request_proto => '', + :caller => client_host }) } + + before { subject.stub(:validate_request_type!).and_return(true) } + before { subject.should_not_receive(:fail) } + + its(:request_bytes) { should eq expected.serialize_to_string } + end + + describe "#verify_callbacks" do it "sets @failure_cb to #data_callback when no callbacks are defined" do subject.verify_callbacks From 31cc7592bba366b990f4b2ed94117f94f5717de1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Nov 2012 15:05:09 -0700 Subject: [PATCH 0246/1191] Method name cleanup --- lib/protobuf/rpc/connectors/em_client.rb | 2 +- lib/protobuf/rpc/servers/socket/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- lib/protobuf/rpc/stat.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb index f69115fa..e5c202e4 100644 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ b/lib/protobuf/rpc/connectors/em_client.rb @@ -17,7 +17,7 @@ def initialize(options = {}, &failure_cb) @failure_cb = failure_cb @options = DEFAULT_OPTIONS.merge(options) @response_buffer = ::Protobuf::Rpc::Buffer.new(:read) - verify_options + verify_options! log_debug { sign_message("Client Initialized: #{options.inspect}") } rescue => e diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 76121140..1d67f4ee 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -74,7 +74,7 @@ def self.run(options = {}) client, sockaddr = @server.accept @listen_fds << client else - if !@working.include?(client) + unless @working.include?(client) @working << @listen_fds.delete(client) log_debug { sign_message("Working") } @threads << { :thread => new_worker(client), :socket => client } diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 4322130c..b0597609 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -29,7 +29,7 @@ def initialize(options = {}) def handle_request(socket) @request_data = '' zmq_error_check(socket.recv_string(@request_data)) - log_debug { sign_message("handling request") } if !@request_data.nil? + log_debug { sign_message("handling request") } unless @request_data.nil? end def run diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index d6c06b9f..3d9310e4 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -47,7 +47,7 @@ def start end def stop - start if !@start_time + start unless @start_time @end_time ||= Time.now end From 3329dabadd214091a75cf79bef1b979188968bd6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Nov 2012 15:44:33 -0700 Subject: [PATCH 0247/1191] Server provides client_host (caller) to stat for logging --- lib/protobuf/rpc/server.rb | 6 ++---- lib/protobuf/rpc/servers/evented/server.rb | 4 ---- lib/protobuf/rpc/servers/socket/worker.rb | 4 ---- lib/protobuf/rpc/stat.rb | 6 +++--- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 64b1fcbb..bfaf335d 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -14,7 +14,6 @@ def initialize_request! @request = ::Protobuf::Socketrpc::Request.new @response = ::Protobuf::Socketrpc::Response.new @stats = Protobuf::Rpc::Stat.new(:SERVER) - set_peer end def disable_gc! @@ -25,12 +24,11 @@ def enable_gc! ::GC.enable && ::GC.start if ::Protobuf.gc_pause_server_request? end - # no-op, implemented by including class if desired. - def set_peer; end - # Invoke the service method dictated by the proto wrapper request object def handle_client parse_request_from_buffer + @stats.client = @request.caller + @dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(@request) @stats.dispatcher = @dispatcher diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb index 2f508acd..e36c5107 100644 --- a/lib/protobuf/rpc/servers/evented/server.rb +++ b/lib/protobuf/rpc/servers/evented/server.rb @@ -31,10 +31,6 @@ def send_data log_debug { sign_message("sending data: #{response_buffer.inspect}") } super(response_buffer.write) end - - def set_peer - @stats.client = ::Socket.unpack_sockaddr_in(get_peername) - end end end end diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 6f4bf0db..c788211c 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -52,10 +52,6 @@ def log_signature @_log_signature ||= "server-#{self.class}-#{object_id}" end - def set_peer - @stats.client = ::Socket.unpack_sockaddr_in(@socket.getpeername) - end - def socket_writable? ! @socket.nil? && ! @socket.closed? end diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 3d9310e4..47d1d431 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -14,12 +14,12 @@ def initialize(mode = :SERVER) start end - def client=(peer) - @client = {:port => peer[0], :ip => peer[1]} + def client=(client_host) + @client = client_host end def client - @client ? "#{@client[:ip]}:#{@client[:port]}" : nil + @client || nil end def method_name From 2b639abd2e4b238112e906169fd1358e19921d95 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Nov 2012 16:00:00 -0700 Subject: [PATCH 0248/1191] Provide client_host (caller) to service instance Provide client_host attribute to the service instance so that service instances can utilize that information if necessary. Added request_type and response_type instance methods to service for general purpose use. Internalized service instance var names for protection from implementation instance variables. --- lib/protobuf/rpc/service.rb | 43 +++++++++++++++++++------- lib/protobuf/rpc/service_dispatcher.rb | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index d5272344..ba4fc99b 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -15,8 +15,6 @@ class Service include ::Protobuf::Logger::LogMethods - attr_reader :response, :rpc - DEFAULT_HOST = '127.0.0.1'.freeze DEFAULT_PORT = 9399 @@ -102,23 +100,26 @@ def self.rpc_method?(name) # Instance Methods # + attr_reader :response, :method_name, :client_host + # Initialize a service with the rpc endpoint name and the bytes # for the request. - def initialize(rpc, request_bytes) - @rpc = rpc - @request_bytes = request_bytes + def initialize(method_name, request_bytes, client_host = nil) + @method_name = method_name + @client_host = client_host + @_request_bytes = request_bytes end # Register a failure callback for use when rpc_failed is invoked. # def on_rpc_failed(callable) - @rpc_failed_callback ||= callable + @_rpc_failed_callback ||= callable end # Response object for this rpc cycle. Not assignable. # def response - @_response ||= rpcs[@rpc].response_type.new + @_response ||= response_type.new end # Convenience method to get back to class method. @@ -144,18 +145,26 @@ def callable_rpc_method(method_name) private + def response_type + @_response_type ||= rpcs[@method_name].response_type + end + # Request object for this rpc cycle. Not assignable. # def request - @_request ||= if @request_bytes.present? - rpcs[@rpc].request_type.new.parse_from_string(@request_bytes) + @_request ||= if @_request_bytes.present? + request_type.new.parse_from_string(@_request_bytes) else - rpcs[@rpc].request_type.new + request_type.new end rescue => e raise BadRequestProto, "Unable to parse request: #{e.message}" end + def request_type + @_request_type ||= rpcs[@method_name].request_type + end + # Sugar to make an rpc method feel like a controller method. # If this method is not called, the response will be the memoized # object returned by the response reader. @@ -165,10 +174,22 @@ def respond_with(candidate) end alias_method :return_from_whence_you_came, :respond_with + # Renamed attribute from prior implementaiton due to lack of clarity + # in what the variable contained. DEPRECATED. + def rpc + if ::Protobuf.print_deprecation_warnings? + $stderr.puts <<-ERROR + [WARNING] Service#rpc method has been deprecated + and will be removed in a future version of protobuf. + ERROR + end + @method_name + end + # Automatically fail a service method. # def rpc_failed(message) - @rpc_failed_callback.call(message) + @_rpc_failed_callback.call(message) end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index f26ef90b..269563f1 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -74,7 +74,7 @@ def init_method request_proto = outer_request.has_field?(:request_proto) ? outer_request.request_proto : nil if service_klass.rpc_method?(method_name) - self.service = service_klass.new(method_name, request_proto) + self.service = service_klass.new(method_name, request_proto, outer_request.caller) self.callable_method = service.callable_rpc_method(method_name) self.definition = service.rpcs[method_name] else From 48ed22b9a4fc7d89909d088f6de7e95e5262ce58 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 28 Nov 2012 20:30:51 -0700 Subject: [PATCH 0249/1191] fix encode/decode issues with strings that fall outside of ascii range, spec says string are UTF-8 --- lib/protobuf/field/string_field.rb | 10 +++++++++- spec/lib/protobuf/message_spec.rb | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 20d9536b..7e9fcd24 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -5,8 +5,16 @@ module Field class StringField < BytesField ENCODING = 'UTF-8'.freeze + def decode(bytes) + bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) + bytes + end + def encode(value) - value.force_encoding(::Protobuf::Field::StringField::ENCODING) + # TODO: make replace character configurable? + value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + string_size = ::Protobuf::Field::VarintField.encode(value.size) string_size << value end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 49d2953a..87ebf6f2 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -21,6 +21,21 @@ end describe '#encode' do + context "encoding" do + it "accepts UTF-8 strings into string fields" do + message = ::Test::Resource.new(:name => "Kyle Redfearn\u0060s iPad") + + expect { message.serialize_to_string }.to_not raise_error + end + + it "trims unicode characters from string fields" do + message = ::Test::Resource.new(:name => "my name\xc3") + new_message = ::Test::Resource.new + new_message.parse_from_string(message.serialize_to_string) + new_message.name.should eq("my name") + end + end + context "when there's no value for a required field" do let(:message) { ::Test::Resource.new } From c7393a279bbf744356f502e0c36c76b7a6e1b553 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 28 Nov 2012 20:33:01 -0700 Subject: [PATCH 0250/1191] bump to 2.5.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f750eb1a..eafeac11 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.4.8' + VERSION = '2.5.0' PROTOC_VERSION = '2.4.1' end From f1449525efaa24b8b75709ec0f77df0b757baa77 Mon Sep 17 00:00:00 2001 From: JohnnyT Date: Thu, 29 Nov 2012 15:50:38 -0700 Subject: [PATCH 0251/1191] Install info for the protobuf package (mac/ubuntu) --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5f12ed14..01646fdc 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ So let's dive in and see how to work with all three. ## 1. Generating ruby classes from `.proto` files +_The `protobuf` package is required for compilation. Mac: `brew install protobuf`, Ubuntu: `sudo apt-get install -y protobuf`_ + Protocol Buffers are great because they allow you to clearly define data storage or data transfer packets. Google officially supports Java, C++, and Python for compilation and usage. Let's make it ruby aware! Let's say you have a `defs.proto` file that defines a User message. @@ -24,9 +26,11 @@ message User { required string first_name = 1; required string last_name = 2; } +``` Now let's compile that definition to ruby: +``` $ rprotoc defs.proto --ruby_out ./lib ``` From 59508cdf13fc97202c0c747d1fa32e3c9f75a3fb Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 29 Nov 2012 17:10:43 -0700 Subject: [PATCH 0252/1191] Bump version 2.5.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index eafeac11..e8d34efb 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.5.0' + VERSION = '2.5.1' PROTOC_VERSION = '2.4.1' end From 1a1bd164da2f61809a27b0fe2c5967e85a747438 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 5 Dec 2012 10:22:57 -0700 Subject: [PATCH 0253/1191] add back the PB_SERVER_TYPE configuration for rpc_server" --- lib/protobuf/cli.rb | 36 +++- spec/lib/protobuf/cli_spec.rb | 349 ++++++++++++++++++---------------- 2 files changed, 215 insertions(+), 170 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 9ea47192..c4e0a5ae 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -91,15 +91,24 @@ def configure_process_name(app_file) def configure_server_mode debug_say 'Configuring runner mode' if options.zmq? && ! options.evented? && ! options.socket? - @mode = :zmq - @runner = ::Protobuf::Rpc::ZmqRunner + server_zmq! elsif options.evented? && ! options.zmq? && ! options.socket? - @mode = :evented - @runner = ::Protobuf::Rpc::EventedRunner + server_evented! + elsif (env_server_type = ENV["PB_SERVER_TYPE"]) + case + when env_server_type =~ /zmq/i then + server_zmq! + when env_server_type =~ /socket/i then + server_socket! + when env_server_type =~ /evented/i then + server_evented! + else + say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{env_server_type}'. Defaulting to socket mode.", :yellow + server_socket! + end else say 'WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow if multi_mode? - @mode = :socket - @runner = ::Protobuf::Rpc::SocketRunner + server_socket! end end @@ -173,6 +182,21 @@ def say_and_exit!(message, exception = nil) exit(1) end + def server_evented! + @mode = :evented + @runner = ::Protobuf::Rpc::EventedRunner + end + + def server_socket! + @mode = :socket + @runner = ::Protobuf::Rpc::SocketRunner + end + + def server_zmq! + @mode = :zmq + @runner = ::Protobuf::Rpc::ZmqRunner + end + # Start the runner and log the relevant options. def start_server! debug_say 'Invoking server start' diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 61671c63..8b723dd9 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -3,127 +3,127 @@ describe ::Protobuf::CLI do - let(:app_file) do - File.expand_path('../../../support/test_app_file.rb', __FILE__) - end - - before do - ::Protobuf::Rpc::SocketRunner.stub(:run) - ::Protobuf::Rpc::ZmqRunner.stub(:run) - ::Protobuf::Rpc::EventedRunner.stub(:run) - end - - describe '#start' do - let(:base_args) { [ 'start', app_file ] } - let(:test_args) { [] } - let(:args) { base_args + test_args } - - context 'host option' do - let(:test_args) { [ '--host=123.123.123.123' ] } - - it 'sends the host option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:host].should eq '123.123.123.123' - end - described_class.start(args) - end - end - - context 'port option' do - let(:test_args) { [ '--port=12345' ] } - - it 'sends the port option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:port].should eq 12345 - end - described_class.start(args) - end - end - - context 'threads option' do - let(:test_args) { [ '--threads=500' ] } - - it 'sends the threads option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:threads].should eq 500 - end - described_class.start(args) - end - end - - context 'backlog option' do - let(:test_args) { [ '--backlog=500' ] } - - it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:backlog].should eq 500 - end - described_class.start(args) - end - end - - context 'threshold option' do - let(:test_args) { [ '--threshold=500' ] } - - it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:threshold].should eq 500 - end - described_class.start(args) - end - end - - context 'log options' do - let(:test_args) { [ '--log=mylog.log', '--level=0' ] } - - it 'sends the log file and level options to the runner' do - ::Protobuf::Logger.should_receive(:configure) do |options| - options[:file].should eq 'mylog.log' - options[:level].should eq 0 - end - described_class.start(args) - end - - context 'when debugging' do - let(:test_args) { [ '--level=3', '--debug' ] } - - it 'overrides the log-level to DEBUG' do - ::Protobuf::Logger.should_receive(:configure) do |options| - options[:level].should eq ::Logger::DEBUG - end - described_class.start(args) - end - end - end - - context 'gc options' do - - context 'when gc options are not present' do - let(:test_args) { [] } - - it 'sets both request and serialization pausing to false' do - described_class.start(args) - ::Protobuf.gc_pause_server_request?.should be_false - end - end - - context 'request pausing' do - let(:test_args) { [ '--gc_pause_request' ] } - - it 'sets the configuration option to GC pause server request' do - described_class.start(args) - ::Protobuf.gc_pause_server_request?.should be_true - end - end - end - - context 'deprecation options' do + let(:app_file) do + File.expand_path('../../../support/test_app_file.rb', __FILE__) + end + + before do + ::Protobuf::Rpc::SocketRunner.stub(:run) + ::Protobuf::Rpc::ZmqRunner.stub(:run) + ::Protobuf::Rpc::EventedRunner.stub(:run) + end + + describe '#start' do + let(:base_args) { [ 'start', app_file ] } + let(:test_args) { [] } + let(:args) { base_args + test_args } + + context 'host option' do + let(:test_args) { [ '--host=123.123.123.123' ] } + + it 'sends the host option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:host].should eq '123.123.123.123' + end + described_class.start(args) + end + end + + context 'port option' do + let(:test_args) { [ '--port=12345' ] } + + it 'sends the port option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:port].should eq 12345 + end + described_class.start(args) + end + end + + context 'threads option' do + let(:test_args) { [ '--threads=500' ] } + + it 'sends the threads option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:threads].should eq 500 + end + described_class.start(args) + end + end + + context 'backlog option' do + let(:test_args) { [ '--backlog=500' ] } + + it 'sends the backlog option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:backlog].should eq 500 + end + described_class.start(args) + end + end + + context 'threshold option' do + let(:test_args) { [ '--threshold=500' ] } + + it 'sends the backlog option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:threshold].should eq 500 + end + described_class.start(args) + end + end + + context 'log options' do + let(:test_args) { [ '--log=mylog.log', '--level=0' ] } + + it 'sends the log file and level options to the runner' do + ::Protobuf::Logger.should_receive(:configure) do |options| + options[:file].should eq 'mylog.log' + options[:level].should eq 0 + end + described_class.start(args) + end + + context 'when debugging' do + let(:test_args) { [ '--level=3', '--debug' ] } + + it 'overrides the log-level to DEBUG' do + ::Protobuf::Logger.should_receive(:configure) do |options| + options[:level].should eq ::Logger::DEBUG + end + described_class.start(args) + end + end + end + + context 'gc options' do + + context 'when gc options are not present' do + let(:test_args) { [] } + + it 'sets both request and serialization pausing to false' do + described_class.start(args) + ::Protobuf.gc_pause_server_request?.should be_false + end + end + + context 'request pausing' do + let(:test_args) { [ '--gc_pause_request' ] } + + it 'sets the configuration option to GC pause server request' do + described_class.start(args) + ::Protobuf.gc_pause_server_request?.should be_true + end + end + end + + context 'deprecation options' do context 'when not given' do let(:test_args) { [] } it 'sets the deprecation warning flag to its default value' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + ::Protobuf.print_deprecation_warnings?.should be_true end end @@ -132,7 +132,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + ::Protobuf.print_deprecation_warnings?.should be_true end end @@ -141,72 +141,93 @@ it 'sets the deprecation warning flag to false' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_false + ::Protobuf.print_deprecation_warnings?.should be_false end end - end + end - context 'run modes' do + context 'run modes' do - context 'socket' do - let(:test_args) { [ '--socket' ] } + context 'socket' do + let(:test_args) { [ '--socket' ] } + let(:runner) { ::Protobuf::Rpc::SocketRunner } - before do - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) - end + before do + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + end + + it 'is activated by the --socket switch' do + runner.should_receive(:run) + described_class.start(args) + end - it 'is activated by the --socket switch' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) - described_class.start(args) - end + it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do + ENV['PB_SERVER_TYPE'] = "Socket" + runner.should_receive(:run) + described_class.start(args) + end - it 'configures the connector type to be socket' do + it 'configures the connector type to be socket' do load "protobuf/socket.rb" - ::Protobuf.connector_type.should == :socket - end - end + ::Protobuf.connector_type.should == :socket + end + end - context 'evented' do - let(:test_args) { [ '--evented' ] } + context 'evented' do + let(:test_args) { [ '--evented' ] } + let(:runner) { ::Protobuf::Rpc::EventedRunner } - before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) - end + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + end + + it 'is activated by the --evented switch' do + runner.should_receive(:run) + described_class.start(args) + end - it 'is activated by the --evented switch' do - ::Protobuf::Rpc::EventedRunner.should_receive(:run) - described_class.start(args) - end + it 'is activated by PB_SERVER_TYPE=Evented ENV variable' do + ENV['PB_SERVER_TYPE'] = "Evented" + runner.should_receive(:run) + described_class.start(args) + end - it 'configures the connector type to be evented' do + it 'configures the connector type to be evented' do load "protobuf/evented.rb" - ::Protobuf.connector_type.should == :evented - end - end + ::Protobuf.connector_type.should == :evented + end + end - context 'zmq' do - let(:test_args) { [ '--zmq' ] } + context 'zmq' do + let(:test_args) { [ '--zmq' ] } + let(:runner) { ::Protobuf::Rpc::ZmqRunner } - before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) - end + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + end + + it 'is activated by the --zmq switch' do + runner.should_receive(:run) + described_class.start(args) + end - it 'is activated by the --zmq switch' do - ::Protobuf::Rpc::ZmqRunner.should_receive(:run) - described_class.start(args) - end + it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do + ENV['PB_SERVER_TYPE'] = "Zmq" + runner.should_receive(:run) + described_class.start(args) + end - it 'configures the connector type to be zmq' do + it 'configures the connector type to be zmq' do load "protobuf/zmq.rb" - ::Protobuf.connector_type.should == :zmq - end - end + ::Protobuf.connector_type.should == :zmq + end + end - end + end - end + end end From b978edfbf77109dd5eaa0ec47e74f1d28f0db779 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 5 Dec 2012 10:48:54 -0700 Subject: [PATCH 0254/1191] fix env ignore_deprecations when running rpc_server with env var set --- lib/protobuf/cli.rb | 8 +- spec/lib/protobuf/cli_spec.rb | 335 +++++++++++++++++----------------- 2 files changed, 177 insertions(+), 166 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 9ea47192..606b1e0b 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -31,7 +31,7 @@ class CLI < ::Thor option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' - option :print_deprecation_warnings, :type => :boolean, :default => true, :desc => 'Cause use of deprecated fields to be printed or ignored.' + option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' def start(app_file) debug_say 'Configuring the rpc_server process' @@ -61,7 +61,11 @@ def version # Tell protobuf how to handle the printing of deprecated field usage. def configure_deprecation_warnings - ::Protobuf.print_deprecation_warnings = options.print_deprecation_warnings? + if options.print_deprecation_warnings.nil? + ::Protobuf.print_deprecation_warnings = !ENV.key?("PB_IGNORE_DEPRECATIONS") + else + ::Protobuf.print_deprecation_warnings = options.print_deprecation_warnings? + end end # If we pause during request we don't need to pause in serialization diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 61671c63..69dbffb2 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -3,127 +3,134 @@ describe ::Protobuf::CLI do - let(:app_file) do - File.expand_path('../../../support/test_app_file.rb', __FILE__) - end - - before do - ::Protobuf::Rpc::SocketRunner.stub(:run) - ::Protobuf::Rpc::ZmqRunner.stub(:run) - ::Protobuf::Rpc::EventedRunner.stub(:run) - end - - describe '#start' do - let(:base_args) { [ 'start', app_file ] } - let(:test_args) { [] } - let(:args) { base_args + test_args } - - context 'host option' do - let(:test_args) { [ '--host=123.123.123.123' ] } - - it 'sends the host option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:host].should eq '123.123.123.123' - end - described_class.start(args) - end - end - - context 'port option' do - let(:test_args) { [ '--port=12345' ] } - - it 'sends the port option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:port].should eq 12345 - end - described_class.start(args) - end - end - - context 'threads option' do - let(:test_args) { [ '--threads=500' ] } - - it 'sends the threads option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:threads].should eq 500 - end - described_class.start(args) - end - end - - context 'backlog option' do - let(:test_args) { [ '--backlog=500' ] } - - it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:backlog].should eq 500 - end - described_class.start(args) - end - end - - context 'threshold option' do - let(:test_args) { [ '--threshold=500' ] } - - it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| - options[:threshold].should eq 500 - end - described_class.start(args) - end - end - - context 'log options' do - let(:test_args) { [ '--log=mylog.log', '--level=0' ] } - - it 'sends the log file and level options to the runner' do - ::Protobuf::Logger.should_receive(:configure) do |options| - options[:file].should eq 'mylog.log' - options[:level].should eq 0 - end - described_class.start(args) - end - - context 'when debugging' do - let(:test_args) { [ '--level=3', '--debug' ] } - - it 'overrides the log-level to DEBUG' do - ::Protobuf::Logger.should_receive(:configure) do |options| - options[:level].should eq ::Logger::DEBUG - end - described_class.start(args) - end - end - end - - context 'gc options' do - - context 'when gc options are not present' do - let(:test_args) { [] } - - it 'sets both request and serialization pausing to false' do - described_class.start(args) - ::Protobuf.gc_pause_server_request?.should be_false - end - end - - context 'request pausing' do - let(:test_args) { [ '--gc_pause_request' ] } - - it 'sets the configuration option to GC pause server request' do - described_class.start(args) - ::Protobuf.gc_pause_server_request?.should be_true - end - end - end - - context 'deprecation options' do + let(:app_file) do + File.expand_path('../../../support/test_app_file.rb', __FILE__) + end + + before do + ::Protobuf::Rpc::SocketRunner.stub(:run) + ::Protobuf::Rpc::ZmqRunner.stub(:run) + ::Protobuf::Rpc::EventedRunner.stub(:run) + end + + describe '#start' do + let(:base_args) { [ 'start', app_file ] } + let(:test_args) { [] } + let(:args) { base_args + test_args } + + context 'host option' do + let(:test_args) { [ '--host=123.123.123.123' ] } + + it 'sends the host option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:host].should eq '123.123.123.123' + end + described_class.start(args) + end + end + + context 'port option' do + let(:test_args) { [ '--port=12345' ] } + + it 'sends the port option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:port].should eq 12345 + end + described_class.start(args) + end + end + + context 'threads option' do + let(:test_args) { [ '--threads=500' ] } + + it 'sends the threads option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:threads].should eq 500 + end + described_class.start(args) + end + end + + context 'backlog option' do + let(:test_args) { [ '--backlog=500' ] } + + it 'sends the backlog option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:backlog].should eq 500 + end + described_class.start(args) + end + end + + context 'threshold option' do + let(:test_args) { [ '--threshold=500' ] } + + it 'sends the backlog option to the runner' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + options[:threshold].should eq 500 + end + described_class.start(args) + end + end + + context 'log options' do + let(:test_args) { [ '--log=mylog.log', '--level=0' ] } + + it 'sends the log file and level options to the runner' do + ::Protobuf::Logger.should_receive(:configure) do |options| + options[:file].should eq 'mylog.log' + options[:level].should eq 0 + end + described_class.start(args) + end + + context 'when debugging' do + let(:test_args) { [ '--level=3', '--debug' ] } + + it 'overrides the log-level to DEBUG' do + ::Protobuf::Logger.should_receive(:configure) do |options| + options[:level].should eq ::Logger::DEBUG + end + described_class.start(args) + end + end + end + + context 'gc options' do + + context 'when gc options are not present' do + let(:test_args) { [] } + + it 'sets both request and serialization pausing to false' do + described_class.start(args) + ::Protobuf.gc_pause_server_request?.should be_false + end + end + + context 'request pausing' do + let(:test_args) { [ '--gc_pause_request' ] } + + it 'sets the configuration option to GC pause server request' do + described_class.start(args) + ::Protobuf.gc_pause_server_request?.should be_true + end + end + end + + context 'deprecation options' do context 'when not given' do let(:test_args) { [] } it 'sets the deprecation warning flag to its default value' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + ::Protobuf.print_deprecation_warnings?.should be_true + end + + it 'sets the deprecation warning flag to false if ENV["PB_IGNORE_DEPRECATIONS"] is present' do + ENV["PB_IGNORE_DEPRECATIONS"] = "1" + described_class.start(args) + ::Protobuf.print_deprecation_warnings?.should be_false + ENV.delete("PB_IGNORE_DEPRECATIONS") end end @@ -132,7 +139,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + ::Protobuf.print_deprecation_warnings?.should be_true end end @@ -141,72 +148,72 @@ it 'sets the deprecation warning flag to false' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_false + ::Protobuf.print_deprecation_warnings?.should be_false end end - end + end - context 'run modes' do + context 'run modes' do - context 'socket' do - let(:test_args) { [ '--socket' ] } + context 'socket' do + let(:test_args) { [ '--socket' ] } - before do - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) - end + before do + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + end - it 'is activated by the --socket switch' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) - described_class.start(args) - end + it 'is activated by the --socket switch' do + ::Protobuf::Rpc::SocketRunner.should_receive(:run) + described_class.start(args) + end - it 'configures the connector type to be socket' do + it 'configures the connector type to be socket' do load "protobuf/socket.rb" - ::Protobuf.connector_type.should == :socket - end - end + ::Protobuf.connector_type.should == :socket + end + end - context 'evented' do - let(:test_args) { [ '--evented' ] } + context 'evented' do + let(:test_args) { [ '--evented' ] } - before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) - end + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + end - it 'is activated by the --evented switch' do - ::Protobuf::Rpc::EventedRunner.should_receive(:run) - described_class.start(args) - end + it 'is activated by the --evented switch' do + ::Protobuf::Rpc::EventedRunner.should_receive(:run) + described_class.start(args) + end - it 'configures the connector type to be evented' do + it 'configures the connector type to be evented' do load "protobuf/evented.rb" - ::Protobuf.connector_type.should == :evented - end - end + ::Protobuf.connector_type.should == :evented + end + end - context 'zmq' do - let(:test_args) { [ '--zmq' ] } + context 'zmq' do + let(:test_args) { [ '--zmq' ] } - before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) - end + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + end - it 'is activated by the --zmq switch' do - ::Protobuf::Rpc::ZmqRunner.should_receive(:run) - described_class.start(args) - end + it 'is activated by the --zmq switch' do + ::Protobuf::Rpc::ZmqRunner.should_receive(:run) + described_class.start(args) + end - it 'configures the connector type to be zmq' do + it 'configures the connector type to be zmq' do load "protobuf/zmq.rb" - ::Protobuf.connector_type.should == :zmq - end - end + ::Protobuf.connector_type.should == :zmq + end + end - end + end - end + end end From f701b15e12f3d58693b9be8ec7366080f68651a4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 5 Dec 2012 10:51:03 -0700 Subject: [PATCH 0255/1191] fixes #42 running rpc_server with ENV IGNORE_DEPRECATIONS --- spec/lib/protobuf/cli_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 69dbffb2..17893fb8 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -121,7 +121,7 @@ context 'when not given' do let(:test_args) { [] } - it 'sets the deprecation warning flag to its default value' do + it 'sets the deprecation warning flag to true when no ENV is present and no command line option' do described_class.start(args) ::Protobuf.print_deprecation_warnings?.should be_true end From f1f3fdc0d266d8b12fd378232530c88a96b50b4b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 5 Dec 2012 11:13:52 -0700 Subject: [PATCH 0256/1191] do not need gc_pause on jruby as GC.enable/disable are noops --- lib/protobuf/cli.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 9ea47192..4be99f02 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -67,7 +67,13 @@ def configure_deprecation_warnings # If we pause during request we don't need to pause in serialization def configure_gc debug_say 'Configuring gc' - ::Protobuf.gc_pause_server_request = options.gc_pause_request? + + if defined?(JRUBY_VERSION) + # GC.enable/disable are noop's on Jruby + ::Protobuf.gc_pause_server_request = false + else + ::Protobuf.gc_pause_server_request = options.gc_pause_request? + end end # Setup the protobuf logger. From 80bf64f0eddd58fdc031999687cecda8712444a3 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 5 Dec 2012 13:03:41 -0700 Subject: [PATCH 0257/1191] bump to 2.5.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index e8d34efb..fef68df9 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.5.1' + VERSION = '2.5.2' PROTOC_VERSION = '2.4.1' end From d4f444fed8eea8fff3a99eb1de93910087d61d9c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 7 Dec 2012 14:58:23 -0700 Subject: [PATCH 0258/1191] Alias *_filter with *_action methods. In preparation for rails 4 (see https://github.com/rails/rails/commit/9d62e04838f01f5589fa50b0baa480d60c815e2c) --- lib/protobuf/rpc/service_filters.rb | 1 + spec/lib/protobuf/rpc/service_filters_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index b851ea0a..13578471 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -17,6 +17,7 @@ module ClassMethods define_method "#{type}_filter" do |*args| set_filters(type, *args) end + alias_method "#{type}_action", "#{type}_filter" end # Filters hash keyed based on filter type (e.g. :before, :after, :around), diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 29a47572..33a79ca5 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -55,6 +55,9 @@ def foo FilterTest.before_filter(:foo) end + specify { subject.class.should respond_to(:before_filter) } + specify { subject.class.should respond_to(:before_action) } + it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) subject.called.should eq [ :verify_before, :foo, :endpoint ] @@ -286,6 +289,9 @@ def foo FilterTest.after_filter(:foo) end + specify { subject.class.should respond_to(:after_filter) } + specify { subject.class.should respond_to(:after_action) } + it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) subject.called.should eq [ :endpoint, :verify_after, :foo ] @@ -320,6 +326,9 @@ def inner_around FilterTest.around_filter(:inner_around) end + specify { subject.class.should respond_to(:around_filter) } + specify { subject.class.should respond_to(:around_action) } + it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :outer_around_top, From 3227576f8f929ce042a680b1ec359b9ca9abf175 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 11 Dec 2012 14:31:30 -0700 Subject: [PATCH 0259/1191] Add jruby, rbx and ruby-head to allowable failures matrix for travis --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 01844aaa..10497c66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,10 @@ rvm: - ruby-head - jruby-head script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec +matrix: + allow_failures: + - rvm: + - jruby-19mode + - rbx-19mode + - jruby-head + - ruby-head From 0de96d924cdbfc671fad8ca788a040c15641e8bd Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Dec 2012 10:07:30 -0700 Subject: [PATCH 0260/1191] Changing the arity of to_json for compatibility with the standard to_json interface. --- lib/protobuf/message.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 36415ffd..e107fbb3 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -40,7 +40,7 @@ def self.define_field(rule, type, fname, tag, options) def self.extensions(range) extension_fields.add_range(range) end - + def self.extension_field_name_to_tag @extension_fields_by_name ||= {} end @@ -150,7 +150,7 @@ def dup def each_field all_fields.each do |field| value = __send__(field.name) - yield(field, value) + yield(field, value) end end @@ -164,7 +164,7 @@ def each_field_for_serialization # Only way you can get here is if you are required and nil raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" else - yield(field, value) + yield(field, value) end end end @@ -217,7 +217,7 @@ def respond_to_has?(key) end def respond_to_has_and_present?(key) - self.respond_to_has?(key) && + self.respond_to_has?(key) && (self.__send__(key).present? || [true, false].include?(self.__send__(key))) end @@ -261,8 +261,8 @@ def to_hash return result end - def to_json - to_hash.to_json + def to_json(options = {}) + to_hash.to_json(options) end def to_proto From efce72bb38ce5adc1c4c37f3c227c786df3931cc Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Dec 2012 10:34:45 -0700 Subject: [PATCH 0261/1191] Remove rbx from travis config since it was always timing out in travis --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10497c66..f0415f1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,6 @@ rvm: - "1.9.2" - "1.9.3" - jruby-19mode - - rbx-19mode - ruby-head - jruby-head script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec -matrix: - allow_failures: - - rvm: - - jruby-19mode - - rbx-19mode - - jruby-head - - ruby-head From 4d9ce7f1d9fdb1337627b66d50b38145a057a1b3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Dec 2012 10:37:50 -0700 Subject: [PATCH 0262/1191] Bump version 2.5.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index fef68df9..71014d06 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.5.2' + VERSION = '2.5.3' PROTOC_VERSION = '2.4.1' end From 5ff5567f1d38afc5231e54214f72fd302194e040 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Dec 2012 16:35:42 -0700 Subject: [PATCH 0263/1191] Packed fields now set correctly. Fixes #49 --- lib/protobuf/field/base_field.rb | 7 +-- spec/lib/protobuf/field/int32_field_spec.rb | 7 +++ spec/lib/protobuf/message_spec.rb | 60 ++++++++++----------- spec/support/all.rb | 1 + spec/support/packed_field.rb | 21 ++++++++ 5 files changed, 63 insertions(+), 33 deletions(-) create mode 100644 spec/lib/protobuf/field/int32_field_spec.rb create mode 100644 spec/support/packed_field.rb diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d9a2efa9..6787a734 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -32,6 +32,8 @@ def initialize(message_class, rule, type, name, tag, options) @message_class, @rule, @type, @name, @tag = \ message_class, rule, type, name, tag + set_rule_predicates + @getter_method_name = name @setter_method_name = "#{name}=".to_sym @default = options.delete(:default) @@ -39,7 +41,6 @@ def initialize(message_class, rule, type, name, tag, options) @packed = repeated? && options.delete(:packed) @deprecated = options.delete(:deprecated) - set_rule_predicates set_default_value warn_excess_options(options) unless options.empty? validate_packed_field if packed? @@ -165,7 +166,7 @@ def define_array_setter @message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated - + if val.is_a?(Array) val = val.dup val.compact! @@ -216,7 +217,7 @@ def define_setter end def set_default_value - @default_value = case + @default_value = case when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze when required? then nil when optional? then typed_default_value diff --git a/spec/lib/protobuf/field/int32_field_spec.rb b/spec/lib/protobuf/field/int32_field_spec.rb new file mode 100644 index 00000000..53281e23 --- /dev/null +++ b/spec/lib/protobuf/field/int32_field_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Protobuf::Field::Int32Field do + + it_behaves_like :packable_field, described_class + +end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 87ebf6f2..57851216 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -2,26 +2,26 @@ describe Protobuf::Message do - describe '#initialize' do - it "does not try to set attributes which have nil values" do + describe '#initialize' do + it "does not try to set attributes which have nil values" do Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=") test_enum = Test::EnumTestMessage.new(:non_default_enum => nil) end - it "takes a hash as an initialization argument" do + it "takes a hash as an initialization argument" do test_enum = Test::EnumTestMessage.new(:non_default_enum => 2) test_enum.non_default_enum.should eq(2) end - it "initializes with an object that responds to #to_hash" do - hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) + it "initializes with an object that responds to #to_hash" do + hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) test_enum = Test::EnumTestMessage.new(hashie_object) test_enum.non_default_enum.should eq(2) end end describe '#encode' do - context "encoding" do + context "encoding" do it "accepts UTF-8 strings into string fields" do message = ::Test::Resource.new(:name => "Kyle Redfearn\u0060s iPad") @@ -46,7 +46,7 @@ end end - context "repeated fields" do + context "repeated fields" do let(:message) { ::Test::Resource.new(:name => "something") } it "does not raise an error when repeated fields are []" do @@ -56,24 +56,24 @@ }.to_not raise_error end - it "sets the value to nil when empty array is passed" do + it "sets the value to nil when empty array is passed" do message.repeated_enum = [] message.instance_variable_get("@values")[:repeated_enum].should be_nil end - it "does not compact the edit original array" do + it "does not compact the edit original array" do a = [nil].freeze message.repeated_enum = a message.repeated_enum.should eq([]) a.should eq([nil].freeze) end - it "compacts the set array" do + it "compacts the set array" do message.repeated_enum = [nil] message.repeated_enum.should eq([]) end - it "raises TypeError when a non-array replaces it" do + it "raises TypeError when a non-array replaces it" do expect { message.repeated_enum = 2 }.to raise_error(/value of type/) @@ -81,66 +81,66 @@ end end - describe "boolean predicate methods" do + describe "boolean predicate methods" do subject { Test::ResourceFindRequest.new(:name => "resource") } it { should respond_to(:active?) } - it "sets the predicate to true when the boolean value is true" do + it "sets the predicate to true when the boolean value is true" do subject.active = true subject.active?.should be_true end - it "sets the predicate to false when the boolean value is false" do + it "sets the predicate to false when the boolean value is false" do subject.active = false subject.active?.should be_false end - it "does not put predicate methods on non-boolean fields" do + it "does not put predicate methods on non-boolean fields" do Test::ResourceFindRequest.new(:name => "resource").should_not respond_to(:name?) end end - describe "#respond_to_and_has?" do + describe "#respond_to_and_has?" do subject { Test::EnumTestMessage.new(:non_default_enum => 2) } - it "is false when the message does not have the field" do + it "is false when the message does not have the field" do subject.respond_to_and_has?(:other_field).should be_false end - it "is true when the message has the field" do + it "is true when the message has the field" do subject.respond_to_and_has?(:non_default_enum).should be_true end end - describe "#respond_to_has_and_present?" do + describe "#respond_to_has_and_present?" do subject { Test::EnumTestMessage.new(:non_default_enum => 2) } - it "is false when the message does not have the field" do + it "is false when the message does not have the field" do subject.respond_to_and_has_and_present?(:other_field).should be_false end - it "is false when the field is repeated and a value is not present" do + it "is false when the field is repeated and a value is not present" do subject.respond_to_and_has_and_present?(:repeated_enums).should be_false end - it "is false when the field is repeated and the value is empty array" do + it "is false when the field is repeated and the value is empty array" do subject.repeated_enums = [] subject.respond_to_and_has_and_present?(:repeated_enums).should be_false end - it "is true when the field is repeated and a value is present" do + it "is true when the field is repeated and a value is present" do subject.repeated_enums = [2] subject.respond_to_and_has_and_present?(:repeated_enums).should be_true end - it "is true when the message has the field" do + it "is true when the message has the field" do subject.respond_to_and_has_and_present?(:non_default_enum).should be_true end - context "#API" do + context "#API" do subject { Test::EnumTestMessage.new(:non_default_enum => 2) } - + it { should respond_to(:respond_to_and_has_and_present?) } it { should respond_to(:responds_to_and_has_and_present?) } it { should respond_to(:responds_to_has?) } @@ -150,7 +150,7 @@ it { should respond_to(:respond_to_and_has_present?) } it { should respond_to(:responds_to_and_has_present?) } end - + end describe '#to_hash' do @@ -230,13 +230,13 @@ end end - describe "#define_setter" do + describe "#define_setter" do subject { ::Test::Resource.new } - it "allows string fields to be set to nil" do + it "allows string fields to be set to nil" do expect { subject.name = nil }.to_not raise_error end - it "does not allow string fields to be set to Numeric" do + it "does not allow string fields to be set to Numeric" do expect { subject.name = 1}.to raise_error(/name/) end end diff --git a/spec/support/all.rb b/spec/support/all.rb index 874f31bf..8cde33a9 100644 --- a/spec/support/all.rb +++ b/spec/support/all.rb @@ -1,3 +1,4 @@ +require 'support/packed_field' require 'support/tolerance_matcher' require 'support/server' diff --git a/spec/support/packed_field.rb b/spec/support/packed_field.rb new file mode 100644 index 00000000..7f731503 --- /dev/null +++ b/spec/support/packed_field.rb @@ -0,0 +1,21 @@ +shared_examples_for :packable_field do |klass| + + before(:all) do + unless defined?(PackableFieldTest) + class PackableFieldTest < ::Protobuf::Message; end + end + + field_klass = klass + field_name = "#{klass.name.split('::').last.underscore}_packed_field".to_sym + tag_num = PackableFieldTest.fields.size + 1 + PackableFieldTest.repeated(field_klass, field_name, tag_num, :packed => true) + end + + let(:field_name) { "#{klass.name.split('::').last.underscore}_packed_field" } + let(:message_instance) { PackableFieldTest.new(field_name => [100, 200, 300]) } + + subject { message_instance.fields.last } + + it { should be_packed } + +end From bedad81186ef56856985f876eb4845b14db92e35 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Dec 2012 17:00:42 -0700 Subject: [PATCH 0264/1191] Bump version 2.5.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 71014d06..4d4386cd 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.5.3' + VERSION = '2.5.4' PROTOC_VERSION = '2.4.1' end From ea8f0186dce708b741e33e6dc7d739d94d854b2b Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Dec 2012 18:31:41 -0700 Subject: [PATCH 0265/1191] Add more specs to Enum.fetch --- spec/lib/protobuf/enum_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index d1c10146..d5c4c98c 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -39,6 +39,8 @@ context 'when value is not an applicable type' do it 'returns a nil' do Test::EnumTestType.fetch(Test::Resource.new).should be_nil + Test::EnumTestType.fetch(nil).should be_nil + Test::EnumTestType.fetch(false).should be_nil end end end From 77b8a25c495fdb6418bf67215e9718f5bbba8064 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Dec 2012 10:19:40 -0700 Subject: [PATCH 0266/1191] Re-implement EnumValue#try to fix delegation issue --- lib/protobuf/enum_value.rb | 16 ++++++++++++++++ spec/lib/protobuf/enum_value_spec.rb | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index 9b110c7c..4499f332 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -56,6 +56,22 @@ def to_s(format = :value_string) end end + # Re-implement `try` in order to fix the problem where + # the underlying fixnum doesn't respond to all methods (e.g. name or value). + # If we respond to the first argument, `__send__` the args. Otherwise, + # delegate the `try` call to the underlying vlaue fixnum. + # + def try(*args, &block) + case + when args.empty? && block_given? + yield self + when respond_to?(args.first) + __send__(*args) + else + @value.try(*args, &block) + end + end + def value @value end diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb index fb2398fe..63d590cb 100644 --- a/spec/lib/protobuf/enum_value_spec.rb +++ b/spec/lib/protobuf/enum_value_spec.rb @@ -12,9 +12,18 @@ its(:inspect) { should eq('#') } specify { subject.to_s(:name).should eq("ONE") } - it "can be used as the index to an array" do + it "can be used as the index to an array" do array = [0, 1, 2, 3] array[::Test::EnumTestType::ONE].should eq(1) end + describe '#try' do + specify { subject.try(:class).should eq subject.class } + specify { subject.try(:name).should eq subject.name } + specify { subject.try(:value).should eq subject.value } + specify { subject.try(:to_i).should eq subject.to_i } + specify { subject.try(:to_int).should eq subject.to_int } + specify { subject.try { |yielded| yielded.should eq subject } } + end + end From dd4c6a7e89574f39bcd71190193810d5e4eb1799 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Dec 2012 10:21:42 -0700 Subject: [PATCH 0267/1191] Pass block when sending to self in EnumValue#try --- lib/protobuf/enum_value.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb index 4499f332..8196034d 100644 --- a/lib/protobuf/enum_value.rb +++ b/lib/protobuf/enum_value.rb @@ -66,7 +66,7 @@ def try(*args, &block) when args.empty? && block_given? yield self when respond_to?(args.first) - __send__(*args) + __send__(*args, &block) else @value.try(*args, &block) end From 086da8cf2ed0e695b01cdd3ae91b980800dcfba3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Dec 2012 11:15:27 -0700 Subject: [PATCH 0268/1191] Bump version 2.5.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 4d4386cd..02f72316 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.5.4' + VERSION = '2.5.5' PROTOC_VERSION = '2.4.1' end From f9f34e8cbc545990ed9a1ff3a72e63f2a44117c4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 2 Jan 2013 10:48:18 -0700 Subject: [PATCH 0269/1191] add zmq server restart for workers on uncaught exception --- lib/protobuf/rpc/servers/zmq/server.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 8c9d423c..5908824b 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -16,13 +16,14 @@ def self.run(options = {}) @broker = ::Protobuf::Rpc::Zmq::Broker.new(options) local_worker_threads = options[:threads] - worker_options = options.merge(:port => options[:port] + 1) + @worker_options = options.merge(:port => options[:port] + 1) log_debug { sign_message("starting server workers") } + local_worker_threads.times do - @threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run } + self.start_worker end - @running = true + @running = true log_debug { sign_message("server started") } while self.running? do @broker.poll @@ -35,6 +36,21 @@ def self.running? !!@running end + def self.start_worker(failed_worker = false) + @threads.select! { |t| t.alive? } if failed_worker + + @threads << Thread.new(self, @worker_options) { |parent_server, worker_options| + begin + ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run + rescue => e + if parent_server.running? + log_error { parent_server.sign_message("Restart Worker on Exception: #{e.inspect}\n #{e.backtrace}") } + parent_server.start_worker(true) + end + end + } + end + def self.stop @running = false From d501979aa14471ba6b745757e3b4f9390b34db88 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 2 Jan 2013 16:57:34 -0700 Subject: [PATCH 0270/1191] bump to 2.6.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 02f72316..3b69e92c 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.5.5' + VERSION = '2.6.0' PROTOC_VERSION = '2.4.1' end From 72edb57ec17322c24a11b2afe52696790eed588a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 3 Jan 2013 15:28:49 -0700 Subject: [PATCH 0271/1191] Fix Stat to print client info on server, server info on client --- lib/protobuf/rpc/stat.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 47d1d431..b4f3f5e6 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -70,10 +70,10 @@ def client? def to_s [ server? ? "[SRV]" : "[CLT]", + server? ? client : server, rpc, elapsed_time, - sizes, - server? ? server : client + sizes ].compact.join(' - ') end From d3adfbd34fbc341cddc80b55d878fe51550ca032 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 3 Jan 2013 15:29:18 -0700 Subject: [PATCH 0272/1191] Bump version 2.6.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 3b69e92c..f44bb380 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.6.0' + VERSION = '2.6.1' PROTOC_VERSION = '2.4.1' end From 161c9733663cc9bf796c42dfdfab72c696a5ecc5 Mon Sep 17 00:00:00 2001 From: Daniel Neighman Date: Wed, 9 Jan 2013 19:09:33 -0800 Subject: [PATCH 0273/1191] Updates the enum to accept -ve values When using enum values, a value of a -ve number is not allowed because it is implemented as an array. Changes the implementation to a hash to accept -ve numbers --- lib/protobuf/enum.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 1642f581..02a8ea6a 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -7,7 +7,7 @@ def self.define(name, value) enum_value = ::Protobuf::EnumValue.new(self, name, value) const_set(name, enum_value) @values ||= {} - @names ||= [] + @names ||= {} @values[name] = enum_value @names[value] = name end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index d5c4c98c..0f4ae9f9 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -2,9 +2,10 @@ describe Protobuf::Enum do let(:name) { :THREE } - let(:tag) { 3 } + let(:tag) { 3 } before(:all) do + Test::EnumTestType.define(:MINUS_ONE, -1) Test::EnumTestType.define(name, tag) end @@ -47,7 +48,7 @@ describe '.enum_by_value' do it 'gets the EnumValue corresponding to the given value (tag)' do - Test::EnumTestType.enum_by_value(tag).should eq Test::EnumTestType::THREE + Test::EnumTestType.enum_by_value(tag).should eq Test::EnumTestType.const_get(name) end end @@ -82,6 +83,7 @@ describe '.values' do it 'provides a hash of defined EnumValues' do Test::EnumTestType.values.should eq({ + :MINUS_ONE => Test::EnumTestType::MINUS_ONE, :ONE => Test::EnumTestType::ONE, :TWO => Test::EnumTestType::TWO, :THREE => Test::EnumTestType::THREE From 32eebfb41d8b06736dc747641b66380ee9a0442c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 10 Jan 2013 17:43:57 -0700 Subject: [PATCH 0274/1191] Fix ServiceFilters#rescue_from inherited exceptions An issue was discovered where rescuing from a parent error class would cause a TypeError exception to be thrown when attempting to find the callable method/block registered to that exception. This is due to ruby's capability to rescue from inherited exceptions. The following example produced a TypeError. Internally the exception classes are mapped to their callables, so `StandardError` would point to the `handle_error` method. class UserService rescue_from StandardError, :handle_error def create raise RuntimeError, "oh noes!" end private def handle_error(ex) # ex is the thrown exception, which may # not be a StandardError but one of its # subclasses. end end A simplified example of this call stack would look like: service = UserService.new begin service.create rescue StandardError => e # e.class is RuntimeError, but we haven't # explicitly mapped RuntimeError to a callable error_handler = rescue_filters[e.class] error_handler.call(e) # error_handler is nil here end The failure is that in attempting to find the error handling callable from the defined rescue handlers, it would fail because we are statically mapping StandardError -> :handle_error method. The solution is to simply do a comparison of the thrown exception's class with that of any mapped classes: begin service.create rescue StandardError => e key = rescue_filters.keys.detect { |mapped| e.class < mapped } error_handler = rescue_filters[key] error_handler.call(e) end --- lib/protobuf/rpc/service_filters.rb | 7 +++++- spec/lib/protobuf/rpc/service_filters_spec.rb | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 13578471..6eab5654 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -240,7 +240,12 @@ def run_rescue_filters begin yield rescue *rescue_filters.keys => ex - call_or_send(rescue_filters[ex.class], ex) + callable = rescue_filters.fetch(ex.class) { + mapped_klass = rescue_filters.keys.detect { |child_klass| ex.class < child_klass } + rescue_filters[mapped_klass] + } + + call_or_send(callable, ex) end end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 33a79ca5..43ccbcbf 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -390,6 +390,11 @@ def filter_with_error3 raise CustomError3, 'Filter 3 failed' end + def filter_with_runtime_error + @called << :filter_with_runtime_error + raise RuntimeError, 'Filter with runtime error failed' + end + def custom_error_occurred(ex) @ex_class = ex.class @called << :custom_error_occurred @@ -455,6 +460,25 @@ def custom_error_occurred(ex) }.to_not raise_error(CustomError1) end end + + context 'when thrown exception inherits from a mapped exception' do + before do + FilterTest.rescue_from(StandardError) do |service, ex| + service.ex_class = ex.class + service.called << :standard_error_rescue_handler + end + end + before { FilterTest.before_filter(:filter_with_runtime_error) } + + it 'rescues with the given callable' do + expect { + subject.should_not_receive(:endpoint) + subject.__send__(:run_filters, :endpoint) + subject.called.should eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) + subject.ex_class.should eq RuntimeError + }.to_not raise_error + end + end end end From a831702b62d90f1c8668b628e4592731fac3b917 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 10 Jan 2013 17:44:44 -0700 Subject: [PATCH 0275/1191] Bump version 2.6.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f44bb380..5b88366a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.6.1' + VERSION = '2.6.2' PROTOC_VERSION = '2.4.1' end From 06fa5f6826162dbb5991a89bf687c26a3568e7bd Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 14 Jan 2013 23:48:07 -0700 Subject: [PATCH 0276/1191] Add requires to classes referencing base module --- lib/protobuf/field/base_field.rb | 1 + lib/protobuf/rpc/connector.rb | 2 ++ lib/protobuf/rpc/connectors/common.rb | 2 ++ lib/protobuf/rpc/server.rb | 1 + 4 files changed, 6 insertions(+) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 6787a734..65dc1723 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,3 +1,4 @@ +require 'protobuf' require 'protobuf/wire_type' require 'protobuf/field/field_array' diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb index a19184ba..99a61af8 100644 --- a/lib/protobuf/rpc/connector.rb +++ b/lib/protobuf/rpc/connector.rb @@ -1,3 +1,5 @@ +require 'protobuf' + module Protobuf module Rpc class Connector diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 4128efbc..8ff077a4 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -1,3 +1,5 @@ +require 'protobuf' + module Protobuf module Rpc module Connectors diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index bfaf335d..8dded997 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -1,3 +1,4 @@ +require 'protobuf' require 'protobuf/logger' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' From d60033009bdc2e21d7ed4848401098319e1be3db Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 14 Jan 2013 23:49:07 -0700 Subject: [PATCH 0277/1191] Be specific in TypeError messages Also, do not mask NoMethodError in BytesField#define_setter. --- lib/protobuf/field/base_field.rb | 6 +++--- lib/protobuf/field/bytes_field.rb | 10 ++++++---- lib/protobuf/field/enum_field.rb | 8 ++++---- lib/protobuf/field/field_array.rb | 6 +++--- lib/protobuf/field/message_field.rb | 6 +++--- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 65dc1723..9cd34535 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -173,8 +173,8 @@ def define_array_setter val.compact! else error_text = <<-TYPE_ERROR - Expected value of type '#{field.type}' - Got '#{val.class}' for protobuf field #{field.name} + Expected repeated value of type '#{field.type}' + Got '#{val.class}' for repeated protobuf field #{field.name} TYPE_ERROR raise TypeError, error_text @@ -211,7 +211,7 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = val else - raise TypeError, "unacceptable value #{val} for type #{field.type}" + raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type}" end end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 98f84aca..e9725da6 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -18,7 +18,7 @@ def acceptable?(val) end def decode(bytes) - bytes.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + bytes.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) bytes end @@ -34,10 +34,12 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = val.dup else - raise TypeError, "unacceptable value #{val} for type #{field.type}" + raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type}" end rescue NoMethodError => ex - raise TypeError, "unacceptable value #{val} for type #{field.type} field #{field.name}" + ::Protobuf::Logger.error { ex.message } + ::Protobuf::Logger.error { ex.backtrace.join("\n") } + raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type}: #{ex.message}" end end end @@ -45,7 +47,7 @@ def define_setter def encode(value) value = value.serialize_to_string if value.is_a?(::Protobuf::Message) - value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value.size) string_size << value diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 857b410b..a2999f35 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -6,11 +6,11 @@ class EnumField < VarintField def acceptable?(val) case val when Symbol then - raise TypeError unless @type.const_defined?(val) + raise TypeError, "Enum #{val} is not known for type #{@type}" unless @type.const_defined?(val) when EnumValue then - raise TypeError if val.parent_class != @type + raise TypeError, "Enum #{val} is not owned by #{@type}" if val.parent_class != @type else - raise TypeError unless @type.valid_tag?(val) + raise TypeError, "Tag #{val} is not valid for Enum #{@type}" unless @type.valid_tag?(val) end true end @@ -42,7 +42,7 @@ def define_setter @values.delete(field.name) else value = field.type.fetch(value) - raise TypeError, "Invalid ENUM value: #{orig_value.inspect} for #{field.name}" unless value + raise TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value @values[field.name] = value end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 41232559..cfb161c2 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -52,7 +52,7 @@ def to_s # def normalize(value) value = value.to_proto if value.respond_to?(:to_proto) - raise TypeError unless @field.acceptable?(value) + raise TypeError, "Unacceptable value #{value} for field #{@field.name} of type #{@field.type}" unless @field.acceptable?(value) if @field.is_a?(::Protobuf::Field::EnumField) @field.type.fetch(value) @@ -65,8 +65,8 @@ def normalize(value) def raise_type_error(val) error_text = <<-TYPE_ERROR - Expected value of type '#{@field.type}' - Got '#{val.class}' for protobuf field #{@field.name} + Expected repeated value of type '#{@field.type}' + Got '#{val.class}' for repeated protobuf field #{@field.name} TYPE_ERROR raise TypeError, error_text diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 090be9df..2e2e2466 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -3,7 +3,7 @@ module Protobuf module Field class MessageField < BaseField - RAISE_TYPE = lambda { |field, val| raise TypeError, "Expected value of type '#{field.type}', but got '#{val.class}'" } + RAISE_TYPE = lambda { |field, val| raise TypeError, "Expected value of type '#{field.type}' for field #{field.name}, but got '#{val.class}'" } ## # Public Instance Methods @@ -18,7 +18,7 @@ def decode(bytes) message.parse_from_string(bytes) message end - + def encode(value) bytes = value.serialize_to_string result = ::Protobuf::Field::VarintField.encode(bytes.size) @@ -39,7 +39,7 @@ def define_setter field = self @message_class.class_eval do define_method("#{field.name}=") do |val| - case + case when val.nil? then @values.delete(field.name) when val.is_a?(field.type) then From f832dfdcfbe0fc7f0fab2f50e1fe9628a8dc0929 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 15 Jan 2013 10:12:11 -0700 Subject: [PATCH 0278/1191] Bump version 2.6.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5b88366a..fdeb54c2 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.6.2' + VERSION = '2.6.3' PROTOC_VERSION = '2.4.1' end From 4c3a68d6a18c3cebd0cf04681ab3bb4bbd5434e3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 17 Jan 2013 11:27:23 -0700 Subject: [PATCH 0279/1191] Add version badge from badge.fury.io --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 01646fdc..6bafad08 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # protobuf +[![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) ***IMPORTANT: Those upgrading from version 1.4.2 to 2.X should read the [UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes*** From c1382a6b044265940bd27dd64121cf97b68ba256 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 17 Jan 2013 11:29:34 -0700 Subject: [PATCH 0280/1191] Add comment about protobuf 2.5 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bafad08..ec163013 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ***IMPORTANT: Those upgrading from version 1.4.2 to 2.X should read the [UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes*** -Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. We currently support version 2.4.0. It's a gem for managing 3 things: +Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. We currently support version 2.4.1 with support for the new 2.5 coming shortly after it becomes final. It's a gem for managing 3 things: 1. Generating ruby classes from `.proto` files. 2. Provide an RPC mechanism for calling remote services. From 1b38aeda0f673c4c562c34a74889b01b70c62f97 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jan 2013 11:49:23 -0700 Subject: [PATCH 0281/1191] Do not reopen class bodies if no fields defined --- ext/ruby_generator/RubyGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ruby_generator/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp index e42f6280..a7299c27 100644 --- a/ext/ruby_generator/RubyGenerator.cpp +++ b/ext/ruby_generator/RubyGenerator.cpp @@ -114,7 +114,7 @@ void RubyGenerator::PrintMessage(const Descriptor* descriptor, bool print_fields map data; data["class_name"] = descriptor->name(); - if (print_fields) { + if (print_fields && (descriptor->field_count() > 0 || descriptor->extension_count() > 0)) { printer_->Print(data, "class $class_name$"); PrintNewLine(); printer_->Indent(); From 1f25ea5aa5c03a38f4ce136335edea317cbfa5e9 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jan 2013 11:50:16 -0700 Subject: [PATCH 0282/1191] Preserve underscores in Constantize function Fixes #56. --- ext/ruby_generator/RubyGenerator.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/ruby_generator/RubyGenerator.h b/ext/ruby_generator/RubyGenerator.h index 8582ea14..f620360b 100644 --- a/ext/ruby_generator/RubyGenerator.h +++ b/ext/ruby_generator/RubyGenerator.h @@ -118,7 +118,6 @@ class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { } else if (c == 95) { // underscore char segment_end = true; - continue; } else if (segment_end) { if (c >= 97 && c <= 122) { // a-z chars From c9a3c120171a2768eda83f31f6d1592a4f413d92 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jan 2013 14:15:10 -0700 Subject: [PATCH 0283/1191] Add before_install task to travis for libzmq --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f0415f1d..2e411f79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,5 @@ rvm: - ruby-head - jruby-head script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec +before_install: + - sudo apt-get install -qq libzmq-dev From 3153d9d6b80e184d2617bc2970e84cad1023cb97 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jan 2013 14:19:07 -0700 Subject: [PATCH 0284/1191] Only build for 1.9.2 and 1.9.3 for now I need to take the time to get specs passing for jruby and ruby head. --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e411f79..bdca3adf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,6 @@ language: ruby rvm: - "1.9.2" - "1.9.3" - - jruby-19mode - - ruby-head - - jruby-head script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec before_install: - sudo apt-get install -qq libzmq-dev From f97321182568c58b237fdb7814301439f5ecab25 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jan 2013 14:34:06 -0700 Subject: [PATCH 0285/1191] Fix deprecation env specs --- spec/lib/protobuf/cli_spec.rb | 23 +++++++++++++++-------- spec/spec_helper.rb | 3 +++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 34cdd8a1..6e5289df 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -121,16 +121,23 @@ context 'when not given' do let(:test_args) { [] } - it 'sets the deprecation warning flag to true when no ENV is present and no command line option' do - described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + context 'when no ENV is present and no command line option' do + before { ENV.delete("PB_IGNORE_DEPRECATIONS") } + + it 'sets the deprecation warning flag to true' do + described_class.start(args) + ::Protobuf.print_deprecation_warnings?.should be_true + end end - it 'sets the deprecation warning flag to false if ENV["PB_IGNORE_DEPRECATIONS"] is present' do - ENV["PB_IGNORE_DEPRECATIONS"] = "1" - described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_false - ENV.delete("PB_IGNORE_DEPRECATIONS") + context 'if ENV["PB_IGNORE_DEPRECATIONS"] is present' do + before { ENV["PB_IGNORE_DEPRECATIONS"] = "1" } + after { ENV.delete("PB_IGNORE_DEPRECATIONS") } + + it 'sets the deprecation warning flag to false ' do + described_class.start(args) + ::Protobuf.print_deprecation_warnings?.should be_false + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8d663ddf..a5abad04 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,9 @@ ::Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) end +# Get rid of the deprecation env var if present (messes with specs). +ENV.delete("PB_IGNORE_DEPRECATIONS") + ::RSpec.configure do |c| c.include(::Sander6::CustomMatchers) c.mock_with :rspec From f56a416c7b37d28890c1b782262bfb5e67ae2bc4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jan 2013 14:40:05 -0700 Subject: [PATCH 0286/1191] Bump version 2.6.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index fdeb54c2..c9673c2a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.6.3' + VERSION = '2.6.4' PROTOC_VERSION = '2.4.1' end From 0d9c5f9b20f82d6e5e9d1f9ea0bc3e7ebb9189d2 Mon Sep 17 00:00:00 2001 From: Daniel Neighman Date: Mon, 28 Jan 2013 19:09:52 -0800 Subject: [PATCH 0287/1191] Allow setting protoc source as an environment variable when compiling --- ext/ruby_generator/extconf.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/ruby_generator/extconf.rb b/ext/ruby_generator/extconf.rb index 800cd33a..0a4efd0d 100644 --- a/ext/ruby_generator/extconf.rb +++ b/ext/ruby_generator/extconf.rb @@ -1,8 +1,7 @@ unless defined?(JRUBY_VERSION) begin require 'mkmf' - - include_directory = File.expand_path(File.join(File.dirname(__FILE__), "..", "protobuf-2.4.1", "src")) + include_directory = File.expand_path(ENV['PROTOC_SRC'] || File.join(File.dirname(__FILE__), "..", "protobuf-2.4.1", "src")) $CPPFLAGS << " -I#{include_directory}" $CPPFLAGS << " -Wall " From c5635cdd8186b832214b2ec563f2e8f12b67da42 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jan 2013 21:31:09 -0700 Subject: [PATCH 0288/1191] Add Install section, PROTOC_SRC env on gem install Extended cleanup of the README formatting and clarifying/removing some sections. --- README.md | 212 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 168 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index ec163013..9c6a19fe 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,53 @@ [![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) -***IMPORTANT: Those upgrading from version 1.4.2 to 2.X should read the [UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes*** +___IMPORTANT: Those upgrading from version 1.4.2 to 2.X should read the +[UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes___ -Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. We currently support version 2.4.1 with support for the new 2.5 coming shortly after it becomes final. It's a gem for managing 3 things: +Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. +We currently support version 2.4.1 with support for the new 2.5 coming shortly after +it becomes final. -1. Generating ruby classes from `.proto` files. -2. Provide an RPC mechanism for calling remote services. -3. Provide RPC interop between ruby and other protobuf-rpc aware implementations for different languages (e.g. [protobuf-socket-rpc][]). +--- -So let's dive in and see how to work with all three. +## Install -## 1. Generating ruby classes from `.proto` files +You will likely need to install protobuf from your favorite package manager +or from source. This gem currently supports protobuf 2.4.1. You may alternatively +specify a `PROTOC_SRC` when installing with rubygems (see below). + +### OSX Install + +```shell +$ brew install protobuf +``` + +### Ubuntu +```shell +$ sudo apt-get install -y protobuf +``` + +### Gem Install + +Once the protobuf package is installed, go ahead and install with rubygems. +If you'd like to skip installing the protobuf package (above) and specify an +alternate location for the protobuf package, for instance if you have a custom +protoc package, then specify it with `PROTOC_SRC=/path/to/src`. +_Please note that this will void your warranty as it were. If you compiled with +a custom protobuf package and are having issues it may be difficult to troubleshoot._ -_The `protobuf` package is required for compilation. Mac: `brew install protobuf`, Ubuntu: `sudo apt-get install -y protobuf`_ +```shell +$ gem install protobuf -Protocol Buffers are great because they allow you to clearly define data storage or data transfer packets. Google officially supports Java, C++, and Python for compilation and usage. Let's make it ruby aware! +# Provide an alternative protoc source directory to build from. +$ PROTOC_SRC=/path/to/protobuf/src gem install protobuf +``` + +## 1. Generating ruby classes from `.proto` files + +Protocol Buffers are great because they allow you to clearly define data storage +or data transfer packets. Google officially supports Java, C++, and Python for +compilation and usage. Let's make it ruby aware! Let's say you have a `defs.proto` file that defines a User message. @@ -35,7 +67,10 @@ Now let's compile that definition to ruby: $ rprotoc defs.proto --ruby_out ./lib ``` -The previous line will take whatever is defined in `defs.proto` and output ruby classes to the `./lib` directory, obeying the package directive. Assuming that's all `defs.proto` had defined, `./lib` should now look like this: +The previous line will take whatever is defined in `defs.proto` and +output ruby classes to the `./lib` directory, obeying the package +directive. Assuming that's all `defs.proto` had defined, `./lib` +should now look like this: ``` - lib @@ -56,9 +91,12 @@ module Foo end ``` -_Note: The generator will pre-define all the classes empty and then re-open to apply the defined fields. This is an optomization to prevent recursive field errors._ +___Note:__ The generator will pre-define all the classes empty and then +re-open to apply the defined fields. This is an optomization to prevent +recursive field errors._ -The generated class is now just a plain old ruby object and you can use it however you wish. +The generated class is now just a plain old ruby object and you +can use it however you wish. ```ruby require 'lib/foo/user.pb' @@ -77,7 +115,10 @@ user.last_name # => Christmas ### Message (de)serialization -Every message object comes ready for serialization or deserialization. Use `serialize_to_string` to write out the byte-string for the message. Use `parse_from_string` on a new message instance to inflate the byte-string back to a message in ruby. +Every message object comes ready for serialization or deserialization. +Use `serialize_to_string` to write out the byte-string for the message. +Use `parse_from_string` on a new message instance to inflate the +byte-string back to a message in ruby. ```ruby user = Foo::User.new(:first_name => 'Bob') @@ -90,13 +131,21 @@ inflated_user == user #=> true ## 2. RPC -RPC is one of many technologies that tries to solve the problem of getting smaller pieces of data from one place to another. Many will argue for or against RPC and its usefulness, but I'm not going to do that here. Google's Protocol Buffers provides support for Services with RPC and that's why you're here. +RPC is one of many technologies that tries to solve the problem of getting +smaller pieces of data from one place to another. Many will argue for or +against RPC and its usefulness, but I'm not going to do that here. Google's +Protocol Buffers provides support for Services with RPC and that's why you're here. -Any discussion about RPC leads to a discussion about clients and servers and the remote procedures themselves. For our purposes, we'll talk about a `Client` (process that is calling the server/service), a `Service` (the remote procedure), and a `Server` (the process that manages one or more services). We'll start with the Service first. +Any discussion about RPC leads to a discussion about clients and servers +and the remote procedures themselves. For our purposes, we'll talk about +a `Client` (process that is calling the server/service), a `Service` +(the remote procedure), and a `Server` (the process that manages one or more +services). We'll start with the Service first. ### Services -Services are simply classes that have endpoint methods defined. Here's what one looks like in protobuf: +Services are simply classes that have endpoint methods defined. Here's what +one looks like in protobuf: ``` package foo; @@ -124,11 +173,15 @@ module Foo end ``` -**Important Note: The UserService class here is a *stub*. You should not provide your implementation in this generated file as subsequent generations will wipe out your implmentation. Read on to learn how to use this stub.** +__Important Note: The UserService class here is a *stub*. You should not +provide your implementation in this generated file as subsequent generations +will wipe out your implmentation. Read on to learn how to use this stub.__ Did you read the note above? Go read it. I'll wait. -Ok, now that you have a generated service stub, you'll want to require it from `lib` and implement the methods. Create a service implementation file in your project. In rails I'd put this in `app/services/user_service.rb`. +Ok, now that you have a generated service stub, you'll want to require it +from `lib` and implement the methods. Create a service implementation file +in your project. In rails I'd put this in `app/services/user_service.rb`. ```ruby # app/services/user_service.rb @@ -152,15 +205,27 @@ module Foo end ``` -Simply implement the instance method for the defined rpc. You can provide any other methods in this class as helpers, but only those defined in the proto file will be callable by remote clients. Every request made by a client will provide a non-empty request of the defined type. The server creates a new service instance based on the request, so you should not be constrained to just the endpoint method. This is similar to rails controllers where only methods defined by the routes file are hooked up to HTTP requests, but it's very common to implement private methods to aid in code quality and simpilicity. - -Every instance has a `request` and `response` object used for fulfilling the call, again, similar to a rails controller action. You should never attempt to modify the `request` object. The `response` object however should be modified or replaced entirely. If you need to create your own response object (a valid case), simply use `respond_with(new_response)`. The returned object should conform to one of three properties: +Simply implement the instance method for the defined rpc. You can provide +any other methods in this class as helpers, but only those defined in the +proto file will be callable by remote clients. Every request made by a client +will provide a non-empty request of the defined type. The server creates a new +service instance based on the request, so you should not be constrained to just +the endpoint method. This is similar to rails controllers where only methods +defined by the routes file are hooked up to HTTP requests, but it's very common +to implement private methods to aid in code quality and simpilicity. + +Every instance has a `request` and `response` object used for fulfilling the call, +again, similar to a rails controller action. You should never attempt to modify the +`request` object. The `response` object however should be modified or replaced +entirely. If you need to create your own response object (a valid case), simply use +`respond_with(new_response)`. The returned object should conform to one of three properties: 1. Response should be of same type as defined by the rpc definition (in this case, `Foo::UserList`), or 2. Response should be a hash. This hash will be used to construct an instance of the defined type and should therefore conform to the appropriate fields for that type. 3. Response should respond to the `to_proto` method. The object returned by `to_proto` should be an instance of the defined response type. -If at any time the implementation encounters an error, the client can be instructed of the error using `rpc_failed`: +If at any time the implementation encounters an error, the client can be +instructed of the error using `rpc_failed`: ```ruby #... @@ -174,11 +239,16 @@ end #... ``` -This means that the client's `on_failure` callback will be invoked instead of the `on_success` callback. Read more below on client callbacks. One drawback to the `rpc_failed` approach is that it does not short-circuit the rest of the method. This means that you must explicitly return from the method if you do not wish the remainder to be executed. +This means that the client's `on_failure` callback will be invoked instead +of the `on_success` callback. Read more below on client callbacks. One drawback +to the `rpc_failed` approach is that it does not short-circuit the rest of +the method. This means that you must explicitly return from the method if +you do not wish the remainder to be executed. ### Service Filters -Service Filters provides ActionController-style filter support to service instances, specifically adding `before_filter`, `after_filter`, and `around_filter`. +Service Filters provides ActionController-style filter support to service +instances, specifically adding `before_filter`, `after_filter`, and `around_filter`. ```ruby require 'lib/foo/user.pb' @@ -223,37 +293,74 @@ end #### Halting execution of rpc request inside a filter -__Around Filters__ – Inside of an around filter, if you wish to halt request processing and return, simply do not `yield` the block. Since the filter is implemented as an instance method, you can use `rpc_failed` or `respond_with` just like you can in the endpoint methods. +__Around Filters__ – Inside of an around filter, if you wish to halt +request processing and return, simply do not `yield` the block. Since the +filter is implemented as an instance method, you can use `rpc_failed` +or `respond_with` just like you can in the endpoint methods. -__Before Filters__ – Returning `false` from a before filter will cancel any other filter calls which would run afterwards, as well as canceling invocation of the service method. Note: You must actually return false, not just a "falsey" value such as nil. +__Before Filters__ – Returning `false` from a before filter will cancel +any other filter calls which would run afterwards, as well as canceling +invocation of the service method. Note: You must actually return false, +not just a "falsey" value such as nil. -__After Filters__ – There is no request shortcutting since the after filter runs after the request. Duh. +__After Filters__ – There is no request shortcutting since the after +filter runs after the request. Duh. #### Filter options -The following options can be applied to any of the filters as the final argument in the filter configuration. (See example above). +The following options can be applied to any of the filters as the final +argument in the filter configuration. (See example above). -__:if__ – The object supplied to `:if` can either be a symbol/string indicating the instance method to call, or, an object that responds to `call`. The method or callable should return true or false indicating if the filter should be invoked or not. Akin to the `if` keyword. +__:if__ – The object supplied to `:if` can either be a symbol/string +indicating the instance method to call, or, an object that responds to `call`. +The method or callable should return true or false indicating if the +filter should be invoked or not. Akin to the `if` keyword. -__:unless__ – The opposite of the `:if` option is `:unless`. Accepts the same object types. The method or callable should return true or false indicating if the filter should be invoked or not. Akin to the `unless` keyword. +__:unless__ – The opposite of the `:if` option is `:unless`. Accepts +the same object types. The method or callable should return true or +false indicating if the filter should be invoked or not. Akin to the +`unless` keyword. -__:only__ – A string/symbol or Array of strings/symbols values that reference instance methods. The names of these methods should be the rpc method you wish to invoke the filter for. Methods not identified in this list would not have the filter applied. +__:only__ – A string/symbol or Array of strings/symbols values that +reference instance methods. The names of these methods should be the +rpc method you wish to invoke the filter for. Methods not identified +in this list would not have the filter applied. -__:except__ – The opposite of the `:only` option. A string/symbol or Array of strings/symbols values that reference instance methods. The names of these methods should be the rpc method you wish to skip invokation of the given filter. Methods not identified in this list would have the filter applied. +__:except__ – The opposite of the `:only` option. A string/symbol or +Array of strings/symbols values that reference instance methods. The +names of these methods should be the rpc method you wish to skip +invokation of the given filter. Methods not identified in this list +would have the filter applied. ### Servers -A service is nothing without being hooked up to a socket. It's the nerdy kid waiting by the telephone for someone to call without knowing that the phone company disconnected their house. Sad and pathetic. So hook up the phone lines! +A service is nothing without being hooked up to a socket. It's the +nerdy kid waiting by the telephone for someone to call without knowing +that the phone company disconnected their house. Sad and pathetic. +So hook up the phone lines! ``` $ rpc_server -o myserver.com -p 9939 -l ./log/protobuf.log ./config/environment.rb ``` -The previous call will start a Socket server running on the given host and port which will load your application into memory. You certainly don't have to run rails or any other framework, just make sure you have some kind of file that will load your services all into memory. The server doesn't know where you put your code, so tell it. - -Be aware that the server needs to be able to translate the socket stream of bytes into an actual protobuf request object. If the definition for that request object aren't known to the server, you're going to have a long day getting this going. It's necessary to store all your definitions and their generated classes in a shared repository (read: gem) so that both client and server have access to the ruby classes in their respective load paths. - -Once the server starts, you should see it as a running process with `ps`. Sending a KILL, QUIT, or TERM signal to the pid will result in shutting the server down gracefully. +The previous call will start a Socket server running on the given +host and port which will load your application into memory. You +certainly don't have to run rails or any other framework, just +make sure you have some kind of file that will load your services +all into memory. The server doesn't know where you put your code, +so tell it. + +Be aware that the server needs to be able to translate the socket +stream of bytes into an actual protobuf request object. If the +definition for that request object aren't known to the server, +you're going to have a long day getting this going. It's necessary +to store all your definitions and their generated classes in a +shared repository (read: gem) so that both client and server have +access to the ruby classes in their respective load paths. + +Once the server starts, you should see it as a running process +with `ps`. Sending a KILL, QUIT, or TERM signal to the pid will +result in shutting the server down gracefully. ``` $ ps aux | grep rpc_server @@ -265,7 +372,8 @@ rpc_server shutdown ### Clients -A lot of work has gone into making the client calls simple and easy to use yet still powerful. Clients have a DSL that feels very ajaxy. +A lot of work has gone into making the client calls simple and easy +to use yet still powerful. Clients have a DSL that feels very ajaxy. ```ruby # require the defs from the shared gem/repo @@ -303,17 +411,33 @@ Foo::UserService.client.find(req) do |c| end ``` -Many different options can be passed to the `.client` call above (such as `:timeout => 600`). See the `lib/protobuf/rpc/client.rb` and `lib/protobuf/rpc/service.rb` files for more documentation. +Many different options can be passed to the `.client` call above +(such as `:timeout => 600`). See the `lib/protobuf/rpc/client.rb` +and `lib/protobuf/rpc/service.rb` files for more documentation. ## 3. RPC Interop -The main reason I wrote this gem was to provide a ruby implementation to google's protobuf that worked on the RPC layer with a Java Service layer that was already running [protobuf-socket-rpc][], the supported socket rpc library for protobuf from Google. Other ruby protobuf implementations I've used did not provide this kind of support. +The main reason I wrote this gem was to provide a ruby implementation +to google's protobuf that worked on the RPC layer with a Java Service +layer that was already running [protobuf-socket-rpc][], the supported +socket rpc library for protobuf from Google. Other ruby protobuf +implementations I've used did not provide this kind of support. ## Accreditation & Caveats -It must be noted that this gem was started originally as a fork of the [ruby-protobuf][old gem] gem. Its authors and I were unable to reach a communication point to be able to merge all of my RPC updates in with their master. Unfortunately I just simply couldn't use their RPC code and so I forked the code. Myself and others have significantly changed the internals of the gem, including the rpc implementation, the message/field implementation, and the compiler implementation. These changes were made to address glaring performance and quality issues in the code. The code was initially diverged at their 0.4.0 version. - -It should also be noted that there are many more features I haven't really shown here, so please let me know if you have any questions on usage or support for various features. Happy protobufing. +It must be noted that this gem was started originally as a fork of +the [ruby-protobuf][old gem] gem. Its authors and I were unable to +reach a communication point to be able to merge all of my RPC updates +in with their master. Unfortunately I just simply couldn't use their +RPC code and so I forked the code. Myself and others have significantly +changed the internals of the gem, including the rpc implementation, the +message/field implementation, and the compiler implementation. These +changes were made to address glaring performance and quality issues +in the code. The code was initially diverged at their 0.4.0 version. + +It should also be noted that there are many more features I haven't +really shown here, so please let me know if you have any questions +on usage or support for various features. Happy protobufing. -- BJ Neilsen, [@localshred][] From 8e6e92973774833b259d6ee53b8c977a203a6e9b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 9 Feb 2013 12:57:43 -0700 Subject: [PATCH 0289/1191] check to_i when mapping name_by_value --- lib/protobuf/enum.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 02a8ea6a..ab8fded2 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -33,7 +33,7 @@ def self.enum_by_value(value) end def self.name_by_value(value) - value.nil? ? nil : @names[value] + (!value.nil? && value.respond_to?(:to_i)) ? @names[value.to_i] : nil end def self.valid_tag?(tag) From 773a089ff116932e32bd4b1d4c73ba12203033d3 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 9 Feb 2013 16:58:21 -0700 Subject: [PATCH 0290/1191] add spec for referencing name_by_value with enum --- spec/lib/protobuf/enum_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 0f4ae9f9..daa16dc0 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -53,6 +53,10 @@ end describe '.name_by_value' do + it 'get the name by value of the enum given the enum' do + Test::EnumTestType.name_by_value(::Test::EnumTestType::THREE).should eq name + end + it 'gets the name of the enum corresponding to the given value (tag)' do Test::EnumTestType.name_by_value(tag).should eq name end From 066a036110931e7ab4183d72fe55afe169f5b864 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 9 Feb 2013 16:58:48 -0700 Subject: [PATCH 0291/1191] bump to 2.6.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c9673c2a..51d4196d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.6.4' + VERSION = '2.6.5' PROTOC_VERSION = '2.4.1' end From 13f474f5c958ea2f7d12696029312e0a4f3c7c6e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 15 Feb 2013 14:22:11 -0700 Subject: [PATCH 0292/1191] Add timeout blocks to Socket/ZMQ send_request Bump the default timeout to 300 seconds since we haven't been operating with timeouts in the socket and zmq layers. --- lib/protobuf/rpc/connectors/base.rb | 3 ++- lib/protobuf/rpc/connectors/socket.rb | 10 ++++++---- lib/protobuf/rpc/connectors/zmq.rb | 10 ++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index d2650c37..e00c3889 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -1,3 +1,4 @@ +require 'timeout' require 'protobuf/logger' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' @@ -16,7 +17,7 @@ module Connectors :request => nil, # The request object sent by the client :request_type => nil, # The request type expected by the client :response_type => nil, # The response type expected by the client - :timeout => 30, # The default timeout for the request, also handled by client.rb + :timeout => 300, # The default timeout for the request, also handled by client.rb :client_host => nil # The hostname or address of this client } diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index d613c37c..8ae36f51 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -8,10 +8,12 @@ class Socket < Base include Protobuf::Logger::LogMethods def send_request - setup_connection - connect_to_rpc_server - post_init - read_response + ::Timeout.timeout(options[:timeout]) do + setup_connection + connect_to_rpc_server + post_init + read_response + end end def log_signature diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 63bb8fbf..075b27b7 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -8,10 +8,12 @@ class Zmq < Base include Protobuf::Logger::LogMethods def send_request - setup_connection - connect_to_rpc_server - post_init - read_response + ::Timeout.timeout(options[:timeout]) do + setup_connection + connect_to_rpc_server + post_init + read_response + end ensure @socket.close if @socket @zmq_context.terminate if @zmq_context From cfa271ace2b89d27aa7b50579c9abed2da2fd9c4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 15 Feb 2013 14:44:51 -0700 Subject: [PATCH 0293/1191] Add timeout_wrap to rpc connectors common module Use timeout_wrap in socket/zmq connectors to get the same behavior and error handling regarding timeouts. --- lib/protobuf/rpc/connectors/common.rb | 8 ++++++++ lib/protobuf/rpc/connectors/socket.rb | 4 +++- lib/protobuf/rpc/connectors/zmq.rb | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 8ff077a4..e3ed8e62 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -135,6 +135,14 @@ def succeed(response) complete end + # Wrap the given block in a timeout of the configured number of seconds. + # + def timeout_wrap(&block) + ::Timeout.timeout(options[:timeout], &block) + rescue ::Timeout::Error => e + fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond") + end + def validate_request_type! unless @options[:request].class == @options[:request_type] expected = @options[:request_type].name diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 8ae36f51..f47f2237 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -8,12 +8,14 @@ class Socket < Base include Protobuf::Logger::LogMethods def send_request - ::Timeout.timeout(options[:timeout]) do + timeout_wrap do setup_connection connect_to_rpc_server post_init read_response end + ensure + @socket.close unless @socket.closed? end def log_signature diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 075b27b7..993ac3e1 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -8,7 +8,7 @@ class Zmq < Base include Protobuf::Logger::LogMethods def send_request - ::Timeout.timeout(options[:timeout]) do + timeout_wrap do setup_connection connect_to_rpc_server post_init From c146404c9ac49c609331f6b62d787db3fd7c0ef9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 16 Feb 2013 17:28:29 -0700 Subject: [PATCH 0294/1191] update zmq server to use router-router for true parallel execution --- bin/rpc_server | 1 - lib/protobuf/rpc/servers/zmq/broker.rb | 63 +++++++++++++------ lib/protobuf/rpc/servers/zmq/util.rb | 2 + lib/protobuf/rpc/servers/zmq/worker.rb | 21 +++++-- .../protobuf/rpc/servers/zmq/worker_spec.rb | 23 +++---- 5 files changed, 70 insertions(+), 40 deletions(-) diff --git a/bin/rpc_server b/bin/rpc_server index cf396cf4..18d8724b 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -2,4 +2,3 @@ require 'protobuf/cli' ::Protobuf::CLI.start(ARGV) - diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index fa8facbf..01de8c8f 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -6,29 +6,38 @@ module Rpc module Zmq class Broker include ::Protobuf::Rpc::Zmq::Util - attr_reader :frontend, :backend, :poller, :context + attr_reader :frontend, :backend, :poller, :context, :available_workers ## # Constructor # def initialize(options = {}) + @available_workers = [] @context = ::ZMQ::Context.new @frontend = setup_frontend(options) @backend = setup_backend(options) - @poller = setup_poller + @poller = ::ZMQ::Poller.new + @poller.register(frontend, ::ZMQ::POLLIN) + @poller.register(backend, ::ZMQ::POLLIN) end ## # Instance Methods # def poll + if available_workers.size > 0 + poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2 + else + poller.delete(frontend) + end + poller.poll(1000) poller.readables.each do |socket| case socket when frontend then - move_to(backend, socket) + move_to_backend(socket) when backend then - move_to(frontend, socket) + move_to_frontend(socket) end end end @@ -41,14 +50,37 @@ def teardown private - def move_to(frontend_or_backend, socket) - more_data = true + def move_to_backend(socket) + message_array = [] + zmq_error_check(socket.recv_strings(message_array)) + + backend_message_set = [ + available_workers.shift, # Worker UUID for router + "", + message_array[0], # Client UUID for return value + "", + message_array[2] # Client Message payload (request) + ] + + zmq_error_check(backend.send_strings(backend_message_set)) + end + + def move_to_frontend(socket) + message_array = [] + zmq_error_check(socket.recv_strings(message_array)) + + # Push UUID of socket on the available workers queue + available_workers << message_array[0] + + # messages should be [ "uuid of socket", "", "READY_MESSAGE || uuid of client socket"] + unless message_array[2] == ::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE + frontend_message_set = [ + message_array[2], # client UUID + "", + message_array[4] # Reply payload + ] - while more_data do - socket.recv_string(data = "") - more_data = socket.more_parts? - more_data_flag = (more_data ? ::ZMQ::SNDMORE : 0) - frontend_or_backend.send_string(data, more_data_flag) + zmq_error_check(frontend.send_strings(frontend_message_set)) end end @@ -57,7 +89,7 @@ def setup_backend(options = {}) host = dealer_options[:host] port = dealer_options[:port] - zmq_backend = context.socket(::ZMQ::DEALER) + zmq_backend = context.socket(::ZMQ::ROUTER) zmq_error_check(zmq_backend.bind(bind_address(host, port))) zmq_backend end @@ -74,13 +106,6 @@ def setup_frontend(options = {}) def bind_address(host, port) "tcp://#{resolve_ip(host)}:#{port}" end - - def setup_poller - zmq_poller = ::ZMQ::Poller.new - zmq_poller.register(frontend, ::ZMQ::POLLIN) - zmq_poller.register(backend, ::ZMQ::POLLIN) - zmq_poller - end end end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index dfee6029..d8ff4508 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -2,6 +2,8 @@ module Protobuf module Rpc module Zmq + WORKER_READY_MESSAGE = "WORKER_READY" + module Util include ::Protobuf::Logger::LogMethods def self.included(base) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index b0597609..0e969ee4 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -16,19 +16,25 @@ def initialize(options = {}) port = options[:port] @zmq_context = ::ZMQ::Context.new - @socket = @zmq_context.socket(::ZMQ::REP) + @socket = @zmq_context.socket(::ZMQ::REQ) zmq_error_check(@socket.connect("tcp://#{resolve_ip(host)}:#{port}")) @poller = ::ZMQ::Poller.new @poller.register(@socket, ::ZMQ::POLLIN) + + # Send request to broker telling it we are ready + zmq_error_check(@socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) end ## # Instance Methods # def handle_request(socket) - @request_data = '' - zmq_error_check(socket.recv_string(@request_data)) + message_array = [] + zmq_error_check(socket.recv_strings(message_array)) + + @request_data = message_array[2] + @client_address = message_array[0] log_debug { sign_message("handling request") } unless @request_data.nil? end @@ -50,8 +56,15 @@ def run def send_data response_data = @response.to_s # to_s is aliases as serialize_to_string in Message + + response_message_set = [ + @client_address, # client uuid address + "", + response_data + ] + @stats.response_size = response_data.size - zmq_error_check(@socket.send_string(response_data)) + zmq_error_check(@socket.send_strings(response_message_set)) end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 962cff87..ada0adfc 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -3,29 +3,20 @@ describe ::Protobuf::Rpc::Zmq::Worker do before(:each) do load 'protobuf/zmq.rb' - end - after(:each) do - subject.instance_variable_get(:@socket).close - subject.instance_variable_get(:@zmq_context).terminate + fake_socket = double + fake_socket.should_receive(:connect).and_return(0) + fake_socket.should_receive(:send_string).and_return(0) + + fake_context = double + fake_context.should_receive(:socket).and_return( fake_socket ) + ::ZMQ::Context.should_receive(:new).and_return( fake_context ) end subject do described_class.new({ :host => '127.0.0.1', :port => 9400 }) end - it 'sets the context' do - subject.instance_variable_get(:@zmq_context).should be_a(::ZMQ::Context) - end - - it 'sets the poller' do - subject.instance_variable_get(:@socket).should be_a(::ZMQ::Socket) - end - - it 'sets the socket' do - subject.instance_variable_get(:@poller).should be_a(::ZMQ::Poller) - end - describe '#run' do # not tested via unit tests end From 0c65e355454e23002dab210b0453e6b85e5405e8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Feb 2013 09:38:26 -0700 Subject: [PATCH 0295/1191] Bump version 2.6.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 51d4196d..39fbdf91 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.6.5' + VERSION = '2.6.6' PROTOC_VERSION = '2.4.1' end From 1cf56c5df12eda613b0b985cbc6e1285a4500b83 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Feb 2013 10:16:58 -0700 Subject: [PATCH 0296/1191] Remove socket close ensure in socket connector --- lib/protobuf/rpc/connectors/socket.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index f47f2237..7ded22b5 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -14,8 +14,6 @@ def send_request post_init read_response end - ensure - @socket.close unless @socket.closed? end def log_signature From a4488d741a48b915d1228b2a6137d20456e150de Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Feb 2013 10:17:59 -0700 Subject: [PATCH 0297/1191] Bump version 2.7.0.rc1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 39fbdf91..b7bff649 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.6.6' + VERSION = '2.7.0.rc1' PROTOC_VERSION = '2.4.1' end From c51f40a67e9ab985706738f0290a203cd588a6e5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Feb 2013 17:43:52 -0700 Subject: [PATCH 0298/1191] Bump version 2.7.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b7bff649..df831c9d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.0.rc1' + VERSION = '2.7.0' PROTOC_VERSION = '2.4.1' end From 4fdd033c76ba6e1dcd0941c60e69926afed71ecf Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Feb 2013 18:06:33 -0700 Subject: [PATCH 0299/1191] Start new work on worker exception for zmq --- lib/protobuf/rpc/servers/zmq/server.rb | 17 ++++++++--------- spec/functional/zmq_server_spec.rb | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 5908824b..c6af7f55 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -36,17 +36,16 @@ def self.running? !!@running end - def self.start_worker(failed_worker = false) - @threads.select! { |t| t.alive? } if failed_worker - - @threads << Thread.new(self, @worker_options) { |parent_server, worker_options| + def self.start_worker + @threads << Thread.new(@worker_options) { |worker_options| begin - ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run + ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run rescue => e - if parent_server.running? - log_error { parent_server.sign_message("Restart Worker on Exception: #{e.inspect}\n #{e.backtrace}") } - parent_server.start_worker(true) - end + message = "Worker Failed, spawning new worker: #{e.inspect}\n #{e.backtrace.join("\n")}" + $stderr.puts message + log_error { message } + + retry if ::Protobuf::Rpc::Zmq::Server.running? end } end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index fa476c17..e91bbaf2 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -12,7 +12,7 @@ after(:all) do ::Protobuf::Rpc::Zmq::Server.stop - @server_thread.join + @server_thread.try(:join) end it 'runs fine when required fields are set' do From 005f56996d5e66a01a8a72be39360b1c527ce231 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Feb 2013 18:11:10 -0700 Subject: [PATCH 0300/1191] Bump version 2.7.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index df831c9d..fa1975c5 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.0' + VERSION = '2.7.1' PROTOC_VERSION = '2.4.1' end From 92b38b738f645df5e95f89d33ffd7ec07f23a02f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Feb 2013 14:10:34 -0700 Subject: [PATCH 0301/1191] Log stats before and after request dispatching. Add trace_id to stat output for pairing pre/post request logs. --- lib/protobuf/rpc/server.rb | 1 + lib/protobuf/rpc/stat.rb | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 8dded997..1e2958d5 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -32,6 +32,7 @@ def handle_client @dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(@request) @stats.dispatcher = @dispatcher + log_info { @stats.to_s } disable_gc! @dispatcher.invoke! diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index b4f3f5e6..558f28f7 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -22,6 +22,10 @@ def client @client || nil end + def elapsed_time + (start_time && end_time ? "#{(end_time - start_time).round(4)}s" : nil) + end + def method_name @method_name ||= @dispatcher.try(:service).try(:rpc) end @@ -39,7 +43,7 @@ def service end def sizes - "#{@request_size || 0}B/#{@response_size || 0}B" + "#{@request_size || 0}B/#{@response_size || 0}B" if stopped? end def start @@ -51,12 +55,12 @@ def stop @end_time ||= Time.now end - def rpc - service && method_name ? "#{service}##{method_name}" : nil + def stopped? + ! end_time.nil? end - def elapsed_time - (start_time && end_time ? "#{(end_time - start_time).round(4)}s" : nil) + def rpc + service && method_name ? "#{service}##{method_name}" : nil end def server? @@ -71,12 +75,17 @@ def to_s [ server? ? "[SRV]" : "[CLT]", server? ? client : server, + trace_id, rpc, elapsed_time, sizes ].compact.join(' - ') end + def trace_id + Thread.current.object_id.to_s(16) + end + end end end From 26724d253838029953ddbfefd4d9a58a139f305f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Feb 2013 14:14:06 -0700 Subject: [PATCH 0302/1191] Bump version 2.7.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index fa1975c5..527dbfbd 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.1' + VERSION = '2.7.2' PROTOC_VERSION = '2.4.1' end From fa220d14dc97129c7545ce3132d1d09a7321b94e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Feb 2013 15:31:11 -0700 Subject: [PATCH 0303/1191] First cut of the Lazy Pirate client pattern The ZMQ client connector implements the Lazy Pirate pattern as laid out in the [ZMQ Guide - Chapter 4][lpp]. The essence is that we attempt to be more stable in our client requests as we assume the server may not be available for fulfilling responses. A connection will be created to the server and data sent with a timeout on the socket. If the socket becomes readable inside the timeout, we read the data and go on our way. If the socket does not become readable in the timeout, we will close and reopen the socket, send the data again, and again wait for a valid response or timeout. If we exceed the number of tries we do not attempt the connection anymore and we fail with a timeout message to the calling code. [lpp]: http://zguide.zeromq.org/php:chapter4#Client-side-Reliability-Lazy-Pirate-Pattern --- lib/protobuf/rpc/connectors/zmq.rb | 154 ++++++++++++++++++++----- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 2 files changed, 127 insertions(+), 29 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 993ac3e1..0e5fcceb 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -4,20 +4,35 @@ module Protobuf module Rpc module Connectors class Zmq < Base + + ## + # Included Modules + # + include Protobuf::Rpc::Connectors::Common include Protobuf::Logger::LogMethods + ## + # Class Constants + # + + LAZY_RETRIES = 3 + + ## + # Instance methods + # + + # Start the request/response cycle. We implement the Lazy Pirate + # req/reply reliability pattern as laid out in the ZMQ Guide, Chapter 4. + # + # @see http://zguide.zeromq.org/php:chapter4#Client-side-Reliability-Lazy-Pirate-Pattern + # def send_request - timeout_wrap do - setup_connection - connect_to_rpc_server - post_init - read_response - end + setup_connection + connect_to_rpc_server + poll_send_data ensure - @socket.close if @socket - @zmq_context.terminate if @zmq_context - @zmq_context = nil + close_connection end def log_signature @@ -26,45 +41,128 @@ def log_signature private + ## + # Private Instance methods + # + def close_connection - return if @error - zmq_error_check(@socket.close) - zmq_error_check(@zmq_context.terminate) - log_debug { sign_message("Connector closed") } + socket_close + zmq_context_terminate end + # Establish a request socket connection to the remote rpc_server. + # Set the socket option LINGER to 0 so that we don't wait + # for queued messages to be accepted when the socket/context are + # asked to close/terminate. + # def connect_to_rpc_server - return if @error - log_debug { sign_message("Establishing connection: #{options[:host]}:#{options[:port]}") } - @zmq_context = ::ZMQ::Context.new - @socket = @zmq_context.socket(::ZMQ::REQ) - zmq_error_check(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) - log_debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } + return if error? + + location = "#{options[:host]}:#{options[:port]}" + log_debug { sign_message("Establishing connection: #{location}") } + socket.setsockopt(::ZMQ::LINGER, 0) + zmq_error_check(socket.connect("tcp://#{location}"), :socket_connect) + zmq_error_check(poller.register_readable(socket), :poller_register_socket) + log_debug { sign_message("Connection established to #{location}") } end - # Method to determine error state, must be used with Connector api + # Method to determine error state, must be used with Connector API. + # def error? - !!@error + !! @error + end + + # Trying a number of times, attempt to get a response from the server. + # If we haven't received a legitimate response in the LAZY_RETRIES number + # of retries, fail the request. + def poll_send_data + poll_timeout = (options[:timeout] / LAZY_RETRIES) * 1000 + + LAZY_RETRIES.times do |n| + send_data + + if poller.poll(poll_timeout) == 1 + read_response + return + else + socket_close + connect_to_rpc_server + end + end + + fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond") + end + + def poller + @poller ||= ::ZMQ::Poller.new end + # Read the string response from the available readable. This will be + # the current @socket. Calls `parse_response` to invoke the success or + # failed callbacks, depending on the state of the communication + # and response data. + # def read_response - return if @error - @response_data = '' - zmq_error_check(@socket.recv_string(@response_data)) + return if error? + + poller.readables.each do |readable| + @response_data = '' + zmq_error_check(readable.recv_string(@response_data), :socket_recv_string) + end + parse_response end + # Send the request data to the remote rpc_server. + # def send_data - return if @error log_debug { sign_message("Sending Request: #{@request_data}") } @stats.request_size = @request_data.size - zmq_error_check(@socket.send_string(@request_data)) + zmq_error_check(socket.send_string(@request_data), :socket_send_string) log_debug { sign_message("write closed") } end - def zmq_error_check(return_code) - raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + # Setup a ZMQ request socket in the current zmq context. + # + def socket + @socket ||= zmq_context.socket(::ZMQ::REQ) + end + + def socket_close + if socket + log_debug { sign_message("Closing Socket") } + zmq_error_check(poller.deregister_readable(socket), :poller_deregister_socket) + zmq_error_check(socket.close, :socket_close) + log_debug { sign_message("Socket closed") } + @socket = nil + end + end + + def zmq_context + self.class.zmq_context end + + # Return the ZMQ Context to use for this process. + # If the context does not exist, create it, then register + # an exit block to ensure the context is terminated correctly. + # + def zmq_context + @zmq_context ||= ::ZMQ::Context.new + end + + # Terminate the zmq_context (if any). + # + def zmq_context_terminate + log_debug { sign_message("Terminating ZMQ Context") } + @zmq_context.try(:terminate) + @zmq_context = nil + log_debug { sign_message("ZMQ Context terminated") } + end + + def zmq_error_check(return_code, message) + raise "Last ZMQ API call (#{message}) failed at #{caller(1)}" unless return_code >= 0 + end + end end end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 01de8c8f..f048ef87 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -28,7 +28,7 @@ def poll if available_workers.size > 0 poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2 else - poller.delete(frontend) + poller.delete(frontend) end poller.poll(1000) From c1fe9ca6a67e5c0bb9d74ec64a8bb842639a7bb5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Feb 2013 15:54:07 -0700 Subject: [PATCH 0304/1191] Remove overdefined zmq_context method --- lib/protobuf/rpc/connectors/zmq.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 0e5fcceb..553629ff 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -75,6 +75,7 @@ def error? # Trying a number of times, attempt to get a response from the server. # If we haven't received a legitimate response in the LAZY_RETRIES number # of retries, fail the request. + # def poll_send_data poll_timeout = (options[:timeout] / LAZY_RETRIES) * 1000 @@ -138,10 +139,6 @@ def socket_close end end - def zmq_context - self.class.zmq_context - end - # Return the ZMQ Context to use for this process. # If the context does not exist, create it, then register # an exit block to ensure the context is terminated correctly. From c49ed10cb4a0d3221a3c999e47124de31b77c320 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Feb 2013 16:11:04 -0700 Subject: [PATCH 0305/1191] Add PB_CLIENT_RETRIES env var for client lpp --- lib/protobuf/rpc/connectors/zmq.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 553629ff..246f76b4 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -16,7 +16,7 @@ class Zmq < Base # Class Constants # - LAZY_RETRIES = 3 + CLIENT_RETRIES = ENV['PB_CLIENT_RETRIES'] || 3 ## # Instance methods @@ -62,7 +62,7 @@ def connect_to_rpc_server log_debug { sign_message("Establishing connection: #{location}") } socket.setsockopt(::ZMQ::LINGER, 0) zmq_error_check(socket.connect("tcp://#{location}"), :socket_connect) - zmq_error_check(poller.register_readable(socket), :poller_register_socket) + zmq_error_check(poller.register_readable(socket), :poller_register_readable) log_debug { sign_message("Connection established to #{location}") } end @@ -73,13 +73,13 @@ def error? end # Trying a number of times, attempt to get a response from the server. - # If we haven't received a legitimate response in the LAZY_RETRIES number + # If we haven't received a legitimate response in the CLIENT_RETRIES number # of retries, fail the request. # def poll_send_data - poll_timeout = (options[:timeout] / LAZY_RETRIES) * 1000 + poll_timeout = (options[:timeout] / CLIENT_RETRIES) * 1000 - LAZY_RETRIES.times do |n| + CLIENT_RETRIES.times do |n| send_data if poller.poll(poll_timeout) == 1 @@ -132,7 +132,7 @@ def socket def socket_close if socket log_debug { sign_message("Closing Socket") } - zmq_error_check(poller.deregister_readable(socket), :poller_deregister_socket) + zmq_error_check(poller.deregister_readable(socket), :poller_deregister_readable) zmq_error_check(socket.close, :socket_close) log_debug { sign_message("Socket closed") } @socket = nil From 8f4d3b2928c5ca930081cd643192e3d831234785 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Feb 2013 16:35:21 -0700 Subject: [PATCH 0306/1191] Synchronize zmq_error_check function to include source --- lib/protobuf/rpc/connectors/zmq.rb | 10 ++++++++-- lib/protobuf/rpc/servers/zmq/broker.rb | 12 ++++++------ lib/protobuf/rpc/servers/zmq/util.rb | 10 ++++++++-- lib/protobuf/rpc/servers/zmq/worker.rb | 10 +++++----- spec/lib/protobuf/rpc/servers/zmq/util_spec.rb | 10 +++++----- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 246f76b4..0040b5d2 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -156,8 +156,14 @@ def zmq_context_terminate log_debug { sign_message("ZMQ Context terminated") } end - def zmq_error_check(return_code, message) - raise "Last ZMQ API call (#{message}) failed at #{caller(1)}" unless return_code >= 0 + def zmq_error_check(return_code, source) + unless ::ZMQ::Util.resultcode_ok?(return_code) + raise <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + end end end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index f048ef87..905f2722 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -52,7 +52,7 @@ def teardown def move_to_backend(socket) message_array = [] - zmq_error_check(socket.recv_strings(message_array)) + zmq_error_check(socket.recv_strings(message_array), :socket_recv_strings) backend_message_set = [ available_workers.shift, # Worker UUID for router @@ -62,12 +62,12 @@ def move_to_backend(socket) message_array[2] # Client Message payload (request) ] - zmq_error_check(backend.send_strings(backend_message_set)) + zmq_error_check(backend.send_strings(backend_message_set), :backend_send_strings) end def move_to_frontend(socket) message_array = [] - zmq_error_check(socket.recv_strings(message_array)) + zmq_error_check(socket.recv_strings(message_array), :socked_recv_strings) # Push UUID of socket on the available workers queue available_workers << message_array[0] @@ -80,7 +80,7 @@ def move_to_frontend(socket) message_array[4] # Reply payload ] - zmq_error_check(frontend.send_strings(frontend_message_set)) + zmq_error_check(frontend.send_strings(frontend_message_set), :frontend_send_strings) end end @@ -90,7 +90,7 @@ def setup_backend(options = {}) port = dealer_options[:port] zmq_backend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_backend.bind(bind_address(host, port))) + zmq_error_check(zmq_backend.bind(bind_address(host, port)), :zmq_backend_bind) zmq_backend end @@ -99,7 +99,7 @@ def setup_frontend(options = {}) port = options[:port] zmq_frontend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_frontend.bind(bind_address(host, port))) + zmq_error_check(zmq_frontend.bind(bind_address(host, port)), :zmq_frontend_bind) zmq_frontend end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index d8ff4508..2209c409 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -10,8 +10,14 @@ def self.included(base) base.extend(::Protobuf::Rpc::Zmq::Util) end - def zmq_error_check(return_code) - raise "Last API call failed with \"#{::ZMQ::Util.error_string}\"#{$/}#{$/}#{caller(1)}" unless return_code >= 0 + def zmq_error_check(return_code, source) + unless ::ZMQ::Util.resultcode_ok?(return_code) + raise <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + end end def log_signature diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 0e969ee4..f3a16204 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -17,13 +17,13 @@ def initialize(options = {}) @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) - zmq_error_check(@socket.connect("tcp://#{resolve_ip(host)}:#{port}")) + zmq_error_check(@socket.connect("tcp://#{resolve_ip(host)}:#{port}"), :socket_connect) @poller = ::ZMQ::Poller.new @poller.register(@socket, ::ZMQ::POLLIN) # Send request to broker telling it we are ready - zmq_error_check(@socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) + zmq_error_check(@socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE), :socket_send_string) end ## @@ -31,7 +31,7 @@ def initialize(options = {}) # def handle_request(socket) message_array = [] - zmq_error_check(socket.recv_strings(message_array)) + zmq_error_check(socket.recv_strings(message_array), :socket_recv_strings) @request_data = message_array[2] @client_address = message_array[0] @@ -55,7 +55,7 @@ def run end def send_data - response_data = @response.to_s # to_s is aliases as serialize_to_string in Message + response_data = @response.serialize_to_string response_message_set = [ @client_address, # client uuid address @@ -64,7 +64,7 @@ def send_data ] @stats.response_size = response_data.size - zmq_error_check(@socket.send_strings(response_message_set)) + zmq_error_check(@socket.send_strings(response_message_set), :socket_send_strings) end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index 90a2ef7c..dad46a46 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -13,26 +13,26 @@ class UtilTest describe '#zmq_error_check' do it 'raises when the error code is less than 0' do expect { - subject.zmq_error_check(-1) - }.to raise_error + subject.zmq_error_check(-1, :test) + }.to raise_error(/test/) end it 'retrieves the error string from ZeroMQ' do ZMQ::Util.stub(:error_string).and_return('an error from zmq') expect { - subject.zmq_error_check(-1) + subject.zmq_error_check(-1, :test) }.to raise_error(RuntimeError, /an error from zmq/i) end it 'does nothing if the error code is > 0' do expect { - subject.zmq_error_check(1) + subject.zmq_error_check(1, :test) }.to_not raise_error end it 'does nothing if the error code is == 0' do expect { - subject.zmq_error_check(0) + subject.zmq_error_check(0, :test) }.to_not raise_error end end From e6af31970b753d4460d338a7ab8a6334daae445f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 14:58:40 -0700 Subject: [PATCH 0307/1191] Fix the benchmark rake tasks --- Rakefile | 2 +- protobuf.gemspec | 2 +- spec/benchmark/tasks.rb | 38 ++++++++++++++++++-------------- spec/support/server.rb | 49 +++++++++++++++++++++++++++-------------- 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/Rakefile b/Rakefile index 15f786bc..f41d3f4c 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "rubygems" require "rubygems/package_task" require "bundler/gem_tasks" -# require "benchmark/tasks" +require "benchmark/tasks" require "rspec/core/rake_task" diff --git a/protobuf.gemspec b/protobuf.gemspec index d40fbefa..30e1c799 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'eventmachine' s.add_development_dependency 'ffi-rzmq' - # s.add_development_dependency 'perftools.rb' + s.add_development_dependency 'perftools.rb' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index e573b2ca..726a6ff1 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,5 +1,6 @@ require 'benchmark' -require 'support/all' +require 'protobuf' +require 'support/server' require 'support/test/resource_service' begin @@ -33,11 +34,12 @@ def em_client_em_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new do |server| - client = ::Test::ResourceService.client - benchmark_wrapper(global_bench) do |bench| bench.report("ES / EC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -51,11 +53,12 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("SS / EC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -69,11 +72,12 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -86,11 +90,12 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) Thread.pass until EM.reactor_running? StubServer.new(:port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("ES / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -102,11 +107,12 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do |i| + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end server.stop diff --git a/spec/support/server.rb b/spec/support/server.rb index 4530d14f..0982258b 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -41,19 +41,28 @@ def initialize(options = {}) @running = true @options = OpenStruct.new({ :host => "127.0.0.1", :port => 9399, - :delay => 0, - :server => Protobuf::Rpc::Evented::Server }.merge(options)) + :backlog => 100, + :threshold => 100, + :threads => 5, + :server => Protobuf::Rpc::Zmq::Server }.merge(options)) start yield self + rescue => e + puts <<-EXC + Exception occurred #{e.message} + #{e.backtrace.join($/)} + EXC ensure stop if @running end def start - case - when @options.server == Protobuf::Rpc::Evented::Server then start_em_server - when @options.server == Protobuf::Rpc::Zmq::Server then start_zmq_server + case @options.server.name + when "Protobuf::Rpc::Evented::Server" then + start_em_server + when "Protobuf::Rpc::Zmq::Server" then + start_zmq_server else start_socket_server end @@ -65,26 +74,32 @@ def start end end - def start_em_server - @server_handle = EventMachine.start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) + if defined?(EventMachine) + def start_em_server + @server_handle = EventMachine.start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) + end end - def start_socket_server - @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } - @sock_server.abort_on_exception = true # Set for testing purposes - Thread.pass until Protobuf::Rpc::Socket::Server.running? + if defined?(Protobuf::Rpc::Socket::Server) + def start_socket_server + @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } + @sock_server.abort_on_exception = true # Set for testing purposes + Thread.pass until Protobuf::Rpc::Socket::Server.running? + end end - def start_zmq_server - @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } - Thread.pass until Protobuf::Rpc::Zmq::Server.running? + if defined?(Protobuf::Rpc::Zmq::Server) + def start_zmq_server + @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } + Thread.pass until Protobuf::Rpc::Zmq::Server.running? + end end def stop - case - when @options.server == Protobuf::Rpc::Evented::Server then + case @options.server.name + when "Protobuf::Rpc::Evented::Server" then EventMachine.stop_server(@server_handle) if @server_handle - when @options.server == Protobuf::Rpc::Zmq::Server then + when "Protobuf::Rpc::Zmq::Server" then Protobuf::Rpc::ZmqRunner.stop @zmq_server.join if @zmq_server else From f41b640f25a9e950c7d2c025058c8885ca0c3934 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 15:03:41 -0700 Subject: [PATCH 0308/1191] Fix poller timeout on client zmq socket cnxns --- lib/protobuf/rpc/connectors/zmq.rb | 14 ++++++-------- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- lib/protobuf/rpc/servers/zmq/util.rb | 7 ++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 0040b5d2..34c9488a 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -16,7 +16,7 @@ class Zmq < Base # Class Constants # - CLIENT_RETRIES = ENV['PB_CLIENT_RETRIES'] || 3 + CLIENT_RETRIES = (ENV['PB_CLIENT_RETRIES'] || 3) ## # Instance methods @@ -29,7 +29,6 @@ class Zmq < Base # def send_request setup_connection - connect_to_rpc_server poll_send_data ensure close_connection @@ -77,17 +76,19 @@ def error? # of retries, fail the request. # def poll_send_data - poll_timeout = (options[:timeout] / CLIENT_RETRIES) * 1000 + poll_timeout = (options[:timeout].to_f / CLIENT_RETRIES.to_f) * 1000 CLIENT_RETRIES.times do |n| + connect_to_rpc_server + log_debug { sign_message("Sending Request (attempt #{n + 1}, #{socket})") } send_data + log_debug { sign_message("Request sending complete (attempt #{n + 1}, #{socket})") } if poller.poll(poll_timeout) == 1 read_response return else socket_close - connect_to_rpc_server end end @@ -117,10 +118,8 @@ def read_response # Send the request data to the remote rpc_server. # def send_data - log_debug { sign_message("Sending Request: #{@request_data}") } @stats.request_size = @request_data.size zmq_error_check(socket.send_string(@request_data), :socket_send_string) - log_debug { sign_message("write closed") } end # Setup a ZMQ request socket in the current zmq context. @@ -132,7 +131,6 @@ def socket def socket_close if socket log_debug { sign_message("Closing Socket") } - zmq_error_check(poller.deregister_readable(socket), :poller_deregister_readable) zmq_error_check(socket.close, :socket_close) log_debug { sign_message("Socket closed") } @socket = nil @@ -157,7 +155,7 @@ def zmq_context_terminate end def zmq_error_check(return_code, source) - unless ::ZMQ::Util.resultcode_ok?(return_code) + unless ::ZMQ::Util.resultcode_ok?(return_code || -1) raise <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 905f2722..df7cab97 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -67,7 +67,7 @@ def move_to_backend(socket) def move_to_frontend(socket) message_array = [] - zmq_error_check(socket.recv_strings(message_array), :socked_recv_strings) + zmq_error_check(socket.recv_strings(message_array), :socket_recv_strings) # Push UUID of socket on the available workers queue available_workers << message_array[0] diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 2209c409..d724c730 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -21,7 +21,12 @@ def zmq_error_check(return_code, source) end def log_signature - @_log_signature ||= "server-#{self.class}-#{object_id}" + unless @_log_signature + name = (self.class == Class ? self.name : self.class.name) + @_log_signature = "[server-#{name}-#{object_id}]" + end + + @_log_signature end def resolve_ip(hostname) From db7ea1822da01501873912aef0a928dcf91a2d93 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 15:05:38 -0700 Subject: [PATCH 0309/1191] Fix rubygems source to use https in Gemfile --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index a1b93f3e..fa75df15 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source :rubygems +source 'https://rubygems.org/' gemspec From be05b097962c187ca6fdc46ae4ecf057a496564c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 15:06:09 -0700 Subject: [PATCH 0310/1191] Use service#method_name instead of deprecated #rpc --- lib/protobuf/rpc/stat.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 558f28f7..6b9ef085 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -27,7 +27,7 @@ def elapsed_time end def method_name - @method_name ||= @dispatcher.try(:service).try(:rpc) + @method_name ||= @dispatcher.try(:service).try(:method_name) end def server=(peer) From d4e1a855b8e03c217e64a0289642c59113495dde Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 15:06:29 -0700 Subject: [PATCH 0311/1191] Make Service#request a public method for respondability --- lib/protobuf/rpc/service.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index ba4fc99b..86320a4c 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -122,6 +122,18 @@ def response @_response ||= response_type.new end + # Request object for this rpc cycle. Not assignable. + # + def request + @_request ||= if @_request_bytes.present? + request_type.new.parse_from_string(@_request_bytes) + else + request_type.new + end + rescue => e + raise BadRequestProto, "Unable to parse request: #{e.message}" + end + # Convenience method to get back to class method. # def rpc_method?(name) @@ -149,18 +161,6 @@ def response_type @_response_type ||= rpcs[@method_name].response_type end - # Request object for this rpc cycle. Not assignable. - # - def request - @_request ||= if @_request_bytes.present? - request_type.new.parse_from_string(@_request_bytes) - else - request_type.new - end - rescue => e - raise BadRequestProto, "Unable to parse request: #{e.message}" - end - def request_type @_request_type ||= rpcs[@method_name].request_type end From c7e2daee804971d48f5289cb5a5b8dad1739ef36 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 16:38:46 -0700 Subject: [PATCH 0312/1191] Do not send data from zmq connector when in error --- lib/protobuf/rpc/connectors/zmq.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 34c9488a..c5185d77 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -76,6 +76,8 @@ def error? # of retries, fail the request. # def poll_send_data + return if error? + poll_timeout = (options[:timeout].to_f / CLIENT_RETRIES.to_f) * 1000 CLIENT_RETRIES.times do |n| @@ -118,6 +120,8 @@ def read_response # Send the request data to the remote rpc_server. # def send_data + return if error? + @stats.request_size = @request_data.size zmq_error_check(socket.send_string(@request_data), :socket_send_string) end From c164ef9d89c7eb85303f122d4fd4a3ec4875655d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 14:58:40 -0700 Subject: [PATCH 0313/1191] Fix the benchmark rake tasks --- Rakefile | 2 +- protobuf.gemspec | 2 +- spec/benchmark/tasks.rb | 38 ++++++++++++++++++-------------- spec/support/server.rb | 49 +++++++++++++++++++++++++++-------------- 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/Rakefile b/Rakefile index 15f786bc..f41d3f4c 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "rubygems" require "rubygems/package_task" require "bundler/gem_tasks" -# require "benchmark/tasks" +require "benchmark/tasks" require "rspec/core/rake_task" diff --git a/protobuf.gemspec b/protobuf.gemspec index d40fbefa..30e1c799 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'eventmachine' s.add_development_dependency 'ffi-rzmq' - # s.add_development_dependency 'perftools.rb' + s.add_development_dependency 'perftools.rb' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index e573b2ca..726a6ff1 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,5 +1,6 @@ require 'benchmark' -require 'support/all' +require 'protobuf' +require 'support/server' require 'support/test/resource_service' begin @@ -33,11 +34,12 @@ def em_client_em_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new do |server| - client = ::Test::ResourceService.client - benchmark_wrapper(global_bench) do |bench| bench.report("ES / EC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -51,11 +53,12 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("SS / EC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -69,11 +72,12 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -86,11 +90,12 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) Thread.pass until EM.reactor_running? StubServer.new(:port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("ES / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end end @@ -102,11 +107,12 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - client = ::Test::ResourceService.client(:port => 9399) - benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + (1..number_tests.to_i).each do |i| + client = ::Test::ResourceService.client(:port => 9399) + client.find(:name => "Test Name" * test_length.to_i, :active => true) + end end end server.stop diff --git a/spec/support/server.rb b/spec/support/server.rb index 4530d14f..0982258b 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -41,19 +41,28 @@ def initialize(options = {}) @running = true @options = OpenStruct.new({ :host => "127.0.0.1", :port => 9399, - :delay => 0, - :server => Protobuf::Rpc::Evented::Server }.merge(options)) + :backlog => 100, + :threshold => 100, + :threads => 5, + :server => Protobuf::Rpc::Zmq::Server }.merge(options)) start yield self + rescue => e + puts <<-EXC + Exception occurred #{e.message} + #{e.backtrace.join($/)} + EXC ensure stop if @running end def start - case - when @options.server == Protobuf::Rpc::Evented::Server then start_em_server - when @options.server == Protobuf::Rpc::Zmq::Server then start_zmq_server + case @options.server.name + when "Protobuf::Rpc::Evented::Server" then + start_em_server + when "Protobuf::Rpc::Zmq::Server" then + start_zmq_server else start_socket_server end @@ -65,26 +74,32 @@ def start end end - def start_em_server - @server_handle = EventMachine.start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) + if defined?(EventMachine) + def start_em_server + @server_handle = EventMachine.start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) + end end - def start_socket_server - @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } - @sock_server.abort_on_exception = true # Set for testing purposes - Thread.pass until Protobuf::Rpc::Socket::Server.running? + if defined?(Protobuf::Rpc::Socket::Server) + def start_socket_server + @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } + @sock_server.abort_on_exception = true # Set for testing purposes + Thread.pass until Protobuf::Rpc::Socket::Server.running? + end end - def start_zmq_server - @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } - Thread.pass until Protobuf::Rpc::Zmq::Server.running? + if defined?(Protobuf::Rpc::Zmq::Server) + def start_zmq_server + @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } + Thread.pass until Protobuf::Rpc::Zmq::Server.running? + end end def stop - case - when @options.server == Protobuf::Rpc::Evented::Server then + case @options.server.name + when "Protobuf::Rpc::Evented::Server" then EventMachine.stop_server(@server_handle) if @server_handle - when @options.server == Protobuf::Rpc::Zmq::Server then + when "Protobuf::Rpc::Zmq::Server" then Protobuf::Rpc::ZmqRunner.stop @zmq_server.join if @zmq_server else From bc07a9aeaf3949c25b6d76b7cda2e87cecea033e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 17:00:06 -0700 Subject: [PATCH 0314/1191] Fix zmq/socket stub server usage --- lib/protobuf/rpc/servers/socket/server.rb | 2 +- spec/benchmark/tasks.rb | 2 +- spec/functional/embedded_service_spec.rb | 7 --- spec/functional/evented_server_spec.rb | 8 ++-- spec/functional/socket_server_spec.rb | 55 +++++++++++------------ spec/functional/zmq_server_spec.rb | 55 +++++++++++------------ spec/lib/protobuf/rpc/client_spec.rb | 23 ++++++---- 7 files changed, 73 insertions(+), 79 deletions(-) delete mode 100644 spec/functional/embedded_service_spec.rb diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 1d67f4ee..01fa3e77 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -93,7 +93,7 @@ def self.run(options = {}) raise rescue # Closing the server causes the loop to raise an exception here - raise #if running? + raise if running? end def self.running? diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 726a6ff1..2db4450a 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -69,7 +69,7 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - EM.stop if EM.reactor_running? + EM.stop if defined?(EM) && EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| benchmark_wrapper(global_bench) do |bench| diff --git a/spec/functional/embedded_service_spec.rb b/spec/functional/embedded_service_spec.rb deleted file mode 100644 index e2a5c529..00000000 --- a/spec/functional/embedded_service_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe 'An Embedded Service Call Hierarchy' do - - - -end \ No newline at end of file diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 121203bf..d2f6ab54 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -9,8 +9,8 @@ it 'runs fine when required fields are set' do expect { EventMachine.fiber_run do - StubServer.new do |server| - client = ::Test::ResourceService.client(:timeout => 5) + StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| + client = ::Test::ResourceService.client(:timeout => 15) client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| @@ -31,7 +31,7 @@ it 'calls the on_failure callback when a message is malformed' do error = nil EventMachine.fiber_run do - StubServer.new do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| request = ::Test::ResourceFindRequest.new(:active => true) client = ::Test::ResourceService.client @@ -48,7 +48,7 @@ it 'calls the on_failure callback when the request type is wrong' do error = nil EventMachine.fiber_run do - StubServer.new do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| request = ::Test::Resource.new(:name => 'Test Name') client = ::Test::ResourceService.client diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 02ce00aa..aaf90fd7 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -4,29 +4,22 @@ describe 'Functional Socket Client' do before(:all) do load "protobuf/socket.rb" - Thread.abort_on_exception = true - server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) - @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } - Thread.pass until Protobuf::Rpc::Socket::Server.running? - end - - after(:all) do - Protobuf::Rpc::SocketRunner.stop - @server_thread.join end it 'runs fine when required fields are set' do expect { - client = ::Test::ResourceService.client - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect + StubServer.new(:server => Protobuf::Rpc::Socket::Server) do + client = ::Test::ResourceService.client + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Test::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect + end end end }.to_not raise_error @@ -34,24 +27,28 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client + StubServer.new(:server => Protobuf::Rpc::Socket::Server) do + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end end error.message.should =~ /name.*required/ end it 'calls the on_failure callback when the request type is wrong' do error = nil - request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client + StubServer.new(:server => Protobuf::Rpc::Socket::Server) do + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} + end end error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index e91bbaf2..80a1195d 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -4,29 +4,22 @@ describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" - Thread.abort_on_exception = true - server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100, :threads => 5) - @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } - Thread.pass until Protobuf::Rpc::Zmq::Server.running? - end - - after(:all) do - ::Protobuf::Rpc::Zmq::Server.stop - @server_thread.try(:join) end it 'runs fine when required fields are set' do expect { - client = ::Test::ResourceService.client - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect + StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do + client = ::Test::ResourceService.client + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Test::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect + end end end }.to_not raise_error @@ -34,24 +27,28 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client + StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + client.find(request) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure {|e| error = e } + end end error.message.should =~ /name.*required/ end it 'calls the on_failure callback when the request type is wrong' do error = nil - request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client + StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + client.find(request) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure {|e| error = e} + end end error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 5a89d41d..78ff3778 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -9,7 +9,7 @@ context "when using fiber based calls" do it "waits for response" do EventMachine.fiber_run do - StubServer.new(:delay => 1) do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 1) do |server| client = Test::ResourceService.client start = now @@ -31,24 +31,31 @@ end end - it "throws and error when call is attempted without 'EventMachine.fiber_run'" do + it "throws an error when call is attempted without 'EventMachine.fiber_run'" do + error = nil subject = Proc.new do EventMachine.run do - StubServer.new(:delay => 1) do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 1) do |server| client = Test::ResourceService.client - client.find(:name => "Test Name", :active => true) + client.find(:name => "Test Name", :active => true) do |c| + c.on_failure do |err| + error = err + EM.add_timer(1) { EM.stop_event_loop } + end + end end end end - subject.should raise_error(RuntimeError, /EM.fiber_run/) + subject.call + error.message.should match(/EM.fiber_run/) end it "throws a timeout when client timeout is exceeded" do error = nil test_proc = Proc.new do EventMachine.fiber_run do - StubServer.new(:delay => 2) do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 2) do |server| client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) do |cl| cl.on_success {} @@ -67,7 +74,7 @@ it "throws a timeout when client timeout is exceeded" do subject = Proc.new do - StubServer.new(:delay => 2) do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 2) do |server| client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) end @@ -80,7 +87,7 @@ failure_message = nil subject = Proc.new do - StubServer.new(:delay => 2) do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 2) do |server| client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) do |c| c.on_failure do |f| From 39074b0021edff9eeff008742f5d1a721cc98c55 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 20 Feb 2013 17:10:12 -0700 Subject: [PATCH 0315/1191] Remove cli log debug test (stdout pollution in specs) --- spec/lib/protobuf/cli_spec.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 6e5289df..15574edb 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -83,17 +83,6 @@ end described_class.start(args) end - - context 'when debugging' do - let(:test_args) { [ '--level=3', '--debug' ] } - - it 'overrides the log-level to DEBUG' do - ::Protobuf::Logger.should_receive(:configure) do |options| - options[:level].should eq ::Logger::DEBUG - end - described_class.start(args) - end - end end context 'gc options' do From 247368c8a08f66b7dbda18c2919a0261ba65bef6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 21 Feb 2013 09:59:25 -0700 Subject: [PATCH 0316/1191] Specify server type in benchmark task --- spec/benchmark/tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 2db4450a..c46b1f38 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -33,7 +33,7 @@ def em_client_em_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? EventMachine.fiber_run do - StubServer.new do |server| + StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| benchmark_wrapper(global_bench) do |bench| bench.report("ES / EC") do (1..number_tests.to_i).each do From 40bfb760e4c5a79ecbab9744c8f489c76291cdfa Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 21 Feb 2013 10:24:36 -0700 Subject: [PATCH 0317/1191] Add zmq test (failing) to test client timeouts --- spec/functional/zmq_server_spec.rb | 58 ++++++++++++++++++--------- spec/support/test/resource.pb.rb | 6 +++ spec/support/test/resource.proto | 5 +++ spec/support/test/resource_service.rb | 7 ++++ 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 80a1195d..469a7425 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -25,31 +25,51 @@ }.to_not raise_error end - it 'calls the on_failure callback when a message is malformed' do - error = nil - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client - - client.find(request) do |c| - c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e } + context 'when a message is malformed' do + it 'calls the on_failure callback' do + error = nil + StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client + + client.find(request) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure {|e| error = e } + end end + error.message.should match(/name.*required/) end - error.message.should =~ /name.*required/ end - it 'calls the on_failure callback when the request type is wrong' do - error = nil - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client + context 'when the request type is wrong' do + it 'calls the on_failure callback' do + error = nil + StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e} + client.find(request) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure {|e| error = e} + end end + error.message.should match(/expected request.*ResourceFindRequest.*Resource instead/i) end - error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end + + context 'when the server takes too long to respond' do + it 'responds with a timeout error' do + error = nil + StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do + client = ::Test::ResourceService.client(:timeout => 1) + + client.find_with_sleep(:sleep => 2) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure { |e| error = e } + end + end + error.message.should match(/The server took longer than 1 seconds to respond/i) + end + end + end diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 356fb47d..e6abae55 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -14,6 +14,7 @@ class StatusType < ::Protobuf::Enum; end # Message Classes # class ResourceFindRequest < ::Protobuf::Message; end + class ResourceSleepRequest < ::Protobuf::Message; end class Resource < ::Protobuf::Message; end class Nested < ::Protobuf::Message; end @@ -35,6 +36,10 @@ class ResourceFindRequest optional ::Protobuf::Field::BoolField, :active, 2 end + class ResourceSleepRequest + optional ::Protobuf::Field::Int32Field, :sleep, 1 + end + class Resource required ::Protobuf::Field::StringField, :name, 1 optional ::Protobuf::Field::Int64Field, :date_created, 2 @@ -54,5 +59,6 @@ class Nested # class ResourceService < ::Protobuf::Rpc::Service rpc :find, ::Test::ResourceFindRequest, ::Test::Resource + rpc :find_with_sleep, ::Test::ResourceSleepRequest, ::Test::Resource end end diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index 202df04d..ba9f502d 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -12,6 +12,10 @@ message ResourceFindRequest { optional bool active = 2; } +message ResourceSleepRequest { + optional int32 sleep = 1; +} + message Resource { required string name = 1; optional int64 date_created = 2; @@ -28,4 +32,5 @@ message Nested { service ResourceService { rpc Find (ResourceFindRequest) returns (Resource); + rpc FindWithSleep (ResourceSleepRequest) returns (Resource); } diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index f1dab010..33072ba4 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -10,5 +10,12 @@ def find response.status = request.active ? 1 : 0 end + # request -> Test::ResourceSleepRequest + # response -> Test::Resource + def find_with_sleep + sleep (request.sleep || 1) + response.name = 'Request should have timed out' + end + end end From bac64bdd3188bfc8242f4e6fb4e8811695a4c85c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 2 Mar 2013 12:57:08 -0700 Subject: [PATCH 0318/1191] add workers_only mode for zmq server where workers can be started on remote machines and attach to current running server --- lib/protobuf/cli.rb | 9 ++++++--- lib/protobuf/rpc/servers/zmq/server.rb | 15 +++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 7a82ae6f..6edc9074 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -32,6 +32,7 @@ class CLI < ::Thor option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' + option :workers_only, :type => :boolean, :default => false, :desc => "Starts process with only workers (no broker/frontend is started) only relevant for Zmq Server" def start(app_file) debug_say 'Configuring the rpc_server process' @@ -47,7 +48,6 @@ def start(app_file) run_if_no_abort { require_application!(app_file) } run_if_no_abort { configure_process_name(app_file) } run_if_no_abort { start_server! } - rescue => e say_and_exit!('ERROR: RPC Server failed to start.', e) end @@ -170,11 +170,14 @@ def run_if_no_abort end def runner_options - { :host => options.host, + { + :host => options.host, :port => options.port, :backlog => options.backlog, :threshold => options.threshold, - :threads => options.threads } + :threads => options.threads, + :workers_only => options.workers_only + } end def say_and_exit!(message, exception = nil) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c6af7f55..04197931 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -12,10 +12,12 @@ class Server # Class Methods # def self.run(options = {}) - log_debug { sign_message("initializing broker") } - @broker = ::Protobuf::Rpc::Zmq::Broker.new(options) - local_worker_threads = options[:threads] + unless options[:workers_only] + log_debug { sign_message("initializing broker") } + @broker = ::Protobuf::Rpc::Zmq::Broker.new(options) + end + local_worker_threads = options[:threads] @worker_options = options.merge(:port => options[:port] + 1) log_debug { sign_message("starting server workers") } @@ -26,7 +28,12 @@ def self.run(options = {}) @running = true log_debug { sign_message("server started") } while self.running? do - @broker.poll + if options[:workers_only] + sleep 5 + Thread.pass + else + @broker.poll + end end ensure @broker.teardown if @broker From 9392523c15c6980e6e8e26b215829be7e77c1688 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 2 Mar 2013 15:13:46 -0700 Subject: [PATCH 0319/1191] add a :worker_port option for backend of zmq broker and no longer editing the port/options as it is passed through runner/server/broker/worker --- lib/protobuf/cli.rb | 2 ++ lib/protobuf/rpc/servers/zmq/broker.rb | 5 ++--- lib/protobuf/rpc/servers/zmq/server.rb | 7 ++++--- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- spec/functional/zmq_server_spec.rb | 8 +++++++- spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb | 2 +- spec/support/server.rb | 1 + 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 6edc9074..c0a2ab0d 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -33,6 +33,7 @@ class CLI < ::Thor option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' option :workers_only, :type => :boolean, :default => false, :desc => "Starts process with only workers (no broker/frontend is started) only relevant for Zmq Server" + option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)" def start(app_file) debug_say 'Configuring the rpc_server process' @@ -176,6 +177,7 @@ def runner_options :backlog => options.backlog, :threshold => options.threshold, :threads => options.threads, + :worker_port => options.worker_port || (options.port + 1), :workers_only => options.workers_only } end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 01de8c8f..eec4ea0c 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -85,9 +85,8 @@ def move_to_frontend(socket) end def setup_backend(options = {}) - dealer_options = options.merge(:port => options[:port] + 1) - host = dealer_options[:host] - port = dealer_options[:port] + host = options[:host] + port = options[:worker_port] zmq_backend = context.socket(::ZMQ::ROUTER) zmq_error_check(zmq_backend.bind(bind_address(host, port))) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 04197931..e5e4f631 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -12,13 +12,14 @@ class Server # Class Methods # def self.run(options = {}) + @options = options + unless options[:workers_only] log_debug { sign_message("initializing broker") } @broker = ::Protobuf::Rpc::Zmq::Broker.new(options) end local_worker_threads = options[:threads] - @worker_options = options.merge(:port => options[:port] + 1) log_debug { sign_message("starting server workers") } local_worker_threads.times do @@ -44,9 +45,9 @@ def self.running? end def self.start_worker - @threads << Thread.new(@worker_options) { |worker_options| + @threads << Thread.new(@options) { |options| begin - ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run + ::Protobuf::Rpc::Zmq::Worker.new(options).run rescue => e message = "Worker Failed, spawning new worker: #{e.inspect}\n #{e.backtrace.join("\n")}" $stderr.puts message diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 0e969ee4..c0c69053 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -13,7 +13,7 @@ class Worker # def initialize(options = {}) host = options[:host] - port = options[:port] + port = options[:worker_port] @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index e91bbaf2..ef02c16c 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -5,7 +5,13 @@ before(:all) do load "protobuf/zmq.rb" Thread.abort_on_exception = true - server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100, :threads => 5) + server = OpenStruct.new(:host => "127.0.0.1", + :port => 9399, + :worker_port => 9400, + :backlog => 100, + :threshold => 100, + :threads => 5) + @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } Thread.pass until Protobuf::Rpc::Zmq::Server.running? end diff --git a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb index 71f8d026..21af27a1 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb @@ -10,7 +10,7 @@ end subject do - described_class.new({ :host => '127.0.0.1', :port => 9399 }) + described_class.new({ :host => '127.0.0.1', :port => 9399, :worker_port => 9400 }) end it 'sets up a context' do diff --git a/spec/support/server.rb b/spec/support/server.rb index 4530d14f..d961a0c9 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -41,6 +41,7 @@ def initialize(options = {}) @running = true @options = OpenStruct.new({ :host => "127.0.0.1", :port => 9399, + :worker_port => 9400, :delay => 0, :server => Protobuf::Rpc::Evented::Server }.merge(options)) From 8ded141878aed5dccf34e1e502766a421268da5d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 2 Mar 2013 17:26:45 -0700 Subject: [PATCH 0320/1191] add specs for workers_only/worker_port and PB_WORKERS_ONLY through ENV --- lib/protobuf/cli.rb | 2 +- spec/lib/protobuf/cli_spec.rb | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index c0a2ab0d..3c4dfab8 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -178,7 +178,7 @@ def runner_options :threshold => options.threshold, :threads => options.threads, :worker_port => options.worker_port || (options.port + 1), - :workers_only => options.workers_only + :workers_only => !!ENV['PB_WORKERS_ONLY'] || options.workers_only } end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 6e5289df..c5664746 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -215,6 +215,52 @@ ::Protobuf.connector_type.should == :evented end end + + context 'zmq workers only' do + let(:test_args) { [ '--workers_only', '--zmq' ] } + let(:runner) { ::Protobuf::Rpc::ZmqRunner } + + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + end + + it 'is activated by the --workers_only switch' do + runner.should_receive(:run) do |options| + options[:workers_only].should be_true + end + + described_class.start(args) + end + + it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do + ENV['PB_WORKERS_ONLY'] = "1" + runner.should_receive(:run) do |options| + options[:workers_only].should be_true + end + + described_class.start(args) + ENV.delete('PB_WORKERS_ONLY') + end + end + + context 'zmq worker port' do + let(:test_args) { [ '--worker_port=1234', '--zmq' ] } + let(:runner) { ::Protobuf::Rpc::ZmqRunner } + + before do + ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + end + + it 'is activated by the --worker_port switch' do + runner.should_receive(:run) do |options| + options[:worker_port].should eq(1234) + end + + described_class.start(args) + end + end context 'zmq' do let(:test_args) { [ '--zmq' ] } From fb300209d545102af5cd706d97b9f06a1d4f7754 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 3 Mar 2013 12:58:11 -0700 Subject: [PATCH 0321/1191] add register_signals to each server runner and TTIN to zmq to start new workers --- lib/protobuf/cli.rb | 6 +++++- lib/protobuf/rpc/servers/evented_runner.rb | 9 +++++++-- lib/protobuf/rpc/servers/socket_runner.rb | 8 ++++++-- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++++- lib/protobuf/rpc/servers/zmq_runner.rb | 15 ++++++++++++--- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3c4dfab8..af4e2060 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -214,9 +214,13 @@ def server_zmq! # Start the runner and log the relevant options. def start_server! + @runner.register_signals + debug_say 'Invoking server start' @runner.run(runner_options) do - Protobuf::Logger.info { "pid #{::Process.pid} -- #{@mode} RPC Server listening at #{options.host}:#{options.port}" } + ::Protobuf::Logger.info { + "pid #{::Process.pid} -- #{@mode} RPC Server listening at #{options.host}:#{options.port}" + } end end diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index c1e2fe0d..0825647d 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -2,8 +2,8 @@ module Protobuf module Rpc class EventedRunner - def self.stop - ::EventMachine.stop_event_loop if ::EventMachine.reactor_running? + def self.register_signals + # Noop end def self.run(options) @@ -16,6 +16,11 @@ def self.run(options) yield if block_given? ::EM.reactor_running? ? ::EM.reactor_thread.join : ::EM.run end + + def self.stop + ::EventMachine.stop_event_loop if ::EventMachine.reactor_running? + end + end end end diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 35da4218..d35cdcbb 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -2,8 +2,8 @@ module Protobuf module Rpc class SocketRunner - def self.stop - ::Protobuf::Rpc::Socket::Server.stop + def self.register_signals + # noop end def self.run(server) @@ -22,6 +22,10 @@ def self.run(server) ::Protobuf::Rpc::Socket::Server.run(server_config) end + def self.stop + ::Protobuf::Rpc::Socket::Server.stop + end + end end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index e5e4f631..38bbae61 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -49,7 +49,7 @@ def self.start_worker begin ::Protobuf::Rpc::Zmq::Worker.new(options).run rescue => e - message = "Worker Failed, spawning new worker: #{e.inspect}\n #{e.backtrace.join("\n")}" + message = "Worker Failed, spawning new worker: #{e.inspect}\n #{e.backtrace.join($/)}" $stderr.puts message log_error { message } @@ -66,6 +66,10 @@ def self.stop end end + def self.threads + @threads + end + @threads ||= [] end end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 0d372d29..b34e3d23 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -2,8 +2,12 @@ module Protobuf module Rpc class ZmqRunner - def self.stop - Protobuf::Rpc::Zmq::Server.stop + def self.register_signals + trap(:TTIN) do + log_info { "TTIN received: Starting new worker" } + ::Protobuf::Rpc::Zmq::Server.start_worker + log_info { "Worker count : #{::Protobuf::Rpc::Zmq::Server.threads.size}" } + end end def self.run(server) @@ -17,9 +21,14 @@ def self.run(server) end yield if block_given? + Protobuf::Rpc::Zmq::Server.run(server_config) end - end + def self.stop + Protobuf::Rpc::Zmq::Server.stop + end + + end end end From bb9aa51725731902d812b13d778e0559fbed7564 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 3 Mar 2013 13:01:25 -0700 Subject: [PATCH 0322/1191] documentation update --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9c6a19fe..93e94a05 100644 --- a/README.md +++ b/README.md @@ -92,11 +92,11 @@ end ``` ___Note:__ The generator will pre-define all the classes empty and then -re-open to apply the defined fields. This is an optomization to prevent +re-open to apply the defined fields. This is an optimization to prevent recursive field errors._ -The generated class is now just a plain old ruby object and you -can use it however you wish. +The generated class is now just a plain old ruby object. +You can use it however you wish. ```ruby require 'lib/foo/user.pb' @@ -340,7 +340,7 @@ that the phone company disconnected their house. Sad and pathetic. So hook up the phone lines! ``` -$ rpc_server -o myserver.com -p 9939 -l ./log/protobuf.log ./config/environment.rb +$ rpc_server -o myserver.com -p 9399 -l ./log/protobuf.log ./config/environment.rb ``` The previous call will start a Socket server running on the given @@ -364,7 +364,7 @@ result in shutting the server down gracefully. ``` $ ps aux | grep rpc_server -1234 ... rpc_server myservice.com:9939 +1234 ... rpc_server myservice.com:9399 $ kill -QUIT 1234 rpc_server shutdown From aefa286140b2ccd5443bf176e029fde46031a50a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 3 Mar 2013 21:13:59 -0700 Subject: [PATCH 0323/1191] add logger methods to runner --- lib/protobuf/rpc/servers/zmq_runner.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index b34e3d23..b2f4db20 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -1,6 +1,7 @@ module Protobuf module Rpc class ZmqRunner + include ::Protobuf::Logger::LogMethods def self.register_signals trap(:TTIN) do @@ -22,11 +23,11 @@ def self.run(server) yield if block_given? - Protobuf::Rpc::Zmq::Server.run(server_config) + ::Protobuf::Rpc::Zmq::Server.run(server_config) end def self.stop - Protobuf::Rpc::Zmq::Server.stop + ::Protobuf::Rpc::Zmq::Server.stop end end From 13a45595ed7adf58a8f6a65f1bca87bd24b12ec8 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 4 Mar 2013 10:03:43 -0700 Subject: [PATCH 0324/1191] bump to 2.7.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 527dbfbd..f0a5f593 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.2' + VERSION = '2.7.3' PROTOC_VERSION = '2.4.1' end From 1d7375272692f8f1a1cdee7d6ff9029cc667ab19 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sat, 9 Mar 2013 21:54:13 -0700 Subject: [PATCH 0325/1191] Revert "Fix zmq/socket stub server usage" This reverts commit bc07a9aeaf3949c25b6d76b7cda2e87cecea033e. --- lib/protobuf/rpc/servers/socket/server.rb | 2 +- spec/benchmark/tasks.rb | 2 +- spec/functional/embedded_service_spec.rb | 7 +++ spec/functional/evented_server_spec.rb | 8 ++-- spec/functional/socket_server_spec.rb | 55 ++++++++++++----------- spec/functional/zmq_server_spec.rb | 55 ++++++++++++----------- spec/lib/protobuf/rpc/client_spec.rb | 23 ++++------ 7 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 spec/functional/embedded_service_spec.rb diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 01fa3e77..1d67f4ee 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -93,7 +93,7 @@ def self.run(options = {}) raise rescue # Closing the server causes the loop to raise an exception here - raise if running? + raise #if running? end def self.running? diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 2db4450a..726a6ff1 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -69,7 +69,7 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - EM.stop if defined?(EM) && EM.reactor_running? + EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| benchmark_wrapper(global_bench) do |bench| diff --git a/spec/functional/embedded_service_spec.rb b/spec/functional/embedded_service_spec.rb new file mode 100644 index 00000000..e2a5c529 --- /dev/null +++ b/spec/functional/embedded_service_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe 'An Embedded Service Call Hierarchy' do + + + +end \ No newline at end of file diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index d2f6ab54..121203bf 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -9,8 +9,8 @@ it 'runs fine when required fields are set' do expect { EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| - client = ::Test::ResourceService.client(:timeout => 15) + StubServer.new do |server| + client = ::Test::ResourceService.client(:timeout => 5) client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| @@ -31,7 +31,7 @@ it 'calls the on_failure callback when a message is malformed' do error = nil EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| + StubServer.new do |server| request = ::Test::ResourceFindRequest.new(:active => true) client = ::Test::ResourceService.client @@ -48,7 +48,7 @@ it 'calls the on_failure callback when the request type is wrong' do error = nil EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| + StubServer.new do |server| request = ::Test::Resource.new(:name => 'Test Name') client = ::Test::ResourceService.client diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index aaf90fd7..02ce00aa 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -4,22 +4,29 @@ describe 'Functional Socket Client' do before(:all) do load "protobuf/socket.rb" + Thread.abort_on_exception = true + server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) + @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } + Thread.pass until Protobuf::Rpc::Socket::Server.running? + end + + after(:all) do + Protobuf::Rpc::SocketRunner.stop + @server_thread.join end it 'runs fine when required fields are set' do expect { - StubServer.new(:server => Protobuf::Rpc::Socket::Server) do - client = ::Test::ResourceService.client - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end + client = ::Test::ResourceService.client + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Test::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect end end }.to_not raise_error @@ -27,28 +34,24 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - StubServer.new(:server => Protobuf::Rpc::Socket::Server) do - request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /name.*required/ end it 'calls the on_failure callback when the request type is wrong' do error = nil - StubServer.new(:server => Protobuf::Rpc::Socket::Server) do - request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 80a1195d..e91bbaf2 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -4,22 +4,29 @@ describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" + Thread.abort_on_exception = true + server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100, :threads => 5) + @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } + Thread.pass until Protobuf::Rpc::Zmq::Server.running? + end + + after(:all) do + ::Protobuf::Rpc::Zmq::Server.stop + @server_thread.try(:join) end it 'runs fine when required fields are set' do expect { - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - client = ::Test::ResourceService.client - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end + client = ::Test::ResourceService.client + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Test::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect end end }.to_not raise_error @@ -27,28 +34,24 @@ it 'calls the on_failure callback when a message is malformed' do error = nil - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e } - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /name.*required/ end it 'calls the on_failure callback when the request type is wrong' do error = nil - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass"} + c.on_failure {|e| error = e} end error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 78ff3778..5a89d41d 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -9,7 +9,7 @@ context "when using fiber based calls" do it "waits for response" do EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 1) do |server| + StubServer.new(:delay => 1) do |server| client = Test::ResourceService.client start = now @@ -31,31 +31,24 @@ end end - it "throws an error when call is attempted without 'EventMachine.fiber_run'" do - error = nil + it "throws and error when call is attempted without 'EventMachine.fiber_run'" do subject = Proc.new do EventMachine.run do - StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 1) do |server| + StubServer.new(:delay => 1) do |server| client = Test::ResourceService.client - client.find(:name => "Test Name", :active => true) do |c| - c.on_failure do |err| - error = err - EM.add_timer(1) { EM.stop_event_loop } - end - end + client.find(:name => "Test Name", :active => true) end end end - subject.call - error.message.should match(/EM.fiber_run/) + subject.should raise_error(RuntimeError, /EM.fiber_run/) end it "throws a timeout when client timeout is exceeded" do error = nil test_proc = Proc.new do EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 2) do |server| + StubServer.new(:delay => 2) do |server| client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) do |cl| cl.on_success {} @@ -74,7 +67,7 @@ it "throws a timeout when client timeout is exceeded" do subject = Proc.new do - StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 2) do |server| + StubServer.new(:delay => 2) do |server| client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) end @@ -87,7 +80,7 @@ failure_message = nil subject = Proc.new do - StubServer.new(:server => Protobuf::Rpc::Evented::Server, :delay => 2) do |server| + StubServer.new(:delay => 2) do |server| client = Test::ResourceService.client(:timeout => 1) client.find(:name => "Test Name", :active => true) do |c| c.on_failure do |f| From ff5e02a6e8cba0cfb7a99e09c45f86ea85524fc4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sat, 9 Mar 2013 21:54:24 -0700 Subject: [PATCH 0326/1191] Revert "Fix the benchmark rake tasks" This reverts commit c164ef9d89c7eb85303f122d4fd4a3ec4875655d. --- Rakefile | 2 +- protobuf.gemspec | 2 +- spec/benchmark/tasks.rb | 38 ++++++++++++++------------------ spec/support/server.rb | 49 ++++++++++++++--------------------------- 4 files changed, 35 insertions(+), 56 deletions(-) diff --git a/Rakefile b/Rakefile index f41d3f4c..15f786bc 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ $:.push File.expand_path("./spec", File.dirname(__FILE__)) require "rubygems" require "rubygems/package_task" require "bundler/gem_tasks" -require "benchmark/tasks" +# require "benchmark/tasks" require "rspec/core/rake_task" diff --git a/protobuf.gemspec b/protobuf.gemspec index 30e1c799..d40fbefa 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'eventmachine' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'perftools.rb' + # s.add_development_dependency 'perftools.rb' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 726a6ff1..e573b2ca 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,6 +1,5 @@ require 'benchmark' -require 'protobuf' -require 'support/server' +require 'support/all' require 'support/test/resource_service' begin @@ -34,12 +33,11 @@ def em_client_em_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new do |server| + client = ::Test::ResourceService.client + benchmark_wrapper(global_bench) do |bench| bench.report("ES / EC") do - (1..number_tests.to_i).each do - client = ::Test::ResourceService.client - client.find(:name => "Test Name" * test_length.to_i, :active => true) - end + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end end @@ -53,12 +51,11 @@ def em_client_sock_server(number_tests, test_length, global_bench = nil) EventMachine.fiber_run do StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| + client = ::Test::ResourceService.client(:port => 9399) + benchmark_wrapper(global_bench) do |bench| bench.report("SS / EC") do - (1..number_tests.to_i).each do - client = ::Test::ResourceService.client(:port => 9399) - client.find(:name => "Test Name" * test_length.to_i, :active => true) - end + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end end @@ -72,12 +69,11 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| + client = ::Test::ResourceService.client(:port => 9399) + benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do - (1..number_tests.to_i).each do - client = ::Test::ResourceService.client(:port => 9399) - client.find(:name => "Test Name" * test_length.to_i, :active => true) - end + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end end @@ -90,12 +86,11 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) Thread.pass until EM.reactor_running? StubServer.new(:port => 9399) do |server| + client = ::Test::ResourceService.client(:port => 9399) + benchmark_wrapper(global_bench) do |bench| bench.report("ES / SC") do - (1..number_tests.to_i).each do - client = ::Test::ResourceService.client(:port => 9399) - client.find(:name => "Test Name" * test_length.to_i, :active => true) - end + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end end @@ -107,12 +102,11 @@ def sock_client_em_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| + client = ::Test::ResourceService.client(:port => 9399) + benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do - (1..number_tests.to_i).each do |i| - client = ::Test::ResourceService.client(:port => 9399) - client.find(:name => "Test Name" * test_length.to_i, :active => true) - end + (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } end end server.stop diff --git a/spec/support/server.rb b/spec/support/server.rb index 0982258b..4530d14f 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -41,28 +41,19 @@ def initialize(options = {}) @running = true @options = OpenStruct.new({ :host => "127.0.0.1", :port => 9399, - :backlog => 100, - :threshold => 100, - :threads => 5, - :server => Protobuf::Rpc::Zmq::Server }.merge(options)) + :delay => 0, + :server => Protobuf::Rpc::Evented::Server }.merge(options)) start yield self - rescue => e - puts <<-EXC - Exception occurred #{e.message} - #{e.backtrace.join($/)} - EXC ensure stop if @running end def start - case @options.server.name - when "Protobuf::Rpc::Evented::Server" then - start_em_server - when "Protobuf::Rpc::Zmq::Server" then - start_zmq_server + case + when @options.server == Protobuf::Rpc::Evented::Server then start_em_server + when @options.server == Protobuf::Rpc::Zmq::Server then start_zmq_server else start_socket_server end @@ -74,32 +65,26 @@ def start end end - if defined?(EventMachine) - def start_em_server - @server_handle = EventMachine.start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) - end + def start_em_server + @server_handle = EventMachine.start_server(@options.host, @options.port, StubProtobufServerFactory.build(@options.delay)) end - if defined?(Protobuf::Rpc::Socket::Server) - def start_socket_server - @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } - @sock_server.abort_on_exception = true # Set for testing purposes - Thread.pass until Protobuf::Rpc::Socket::Server.running? - end + def start_socket_server + @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } + @sock_server.abort_on_exception = true # Set for testing purposes + Thread.pass until Protobuf::Rpc::Socket::Server.running? end - if defined?(Protobuf::Rpc::Zmq::Server) - def start_zmq_server - @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } - Thread.pass until Protobuf::Rpc::Zmq::Server.running? - end + def start_zmq_server + @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } + Thread.pass until Protobuf::Rpc::Zmq::Server.running? end def stop - case @options.server.name - when "Protobuf::Rpc::Evented::Server" then + case + when @options.server == Protobuf::Rpc::Evented::Server then EventMachine.stop_server(@server_handle) if @server_handle - when "Protobuf::Rpc::Zmq::Server" then + when @options.server == Protobuf::Rpc::Zmq::Server then Protobuf::Rpc::ZmqRunner.stop @zmq_server.join if @zmq_server else From 0fce1013d99ff4ce5aaa9e595fe894a8ceea95d2 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 11 Mar 2013 15:27:40 -0600 Subject: [PATCH 0327/1191] update broker in zmq to wait to open the frontend socket to take in requests until workers are ready --- lib/protobuf/rpc/servers/zmq/broker.rb | 82 +++++++++++-------- .../protobuf/rpc/servers/zmq/broker_spec.rb | 4 - 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index eec4ea0c..e001ee23 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -6,50 +6,84 @@ module Rpc module Zmq class Broker include ::Protobuf::Rpc::Zmq::Util - attr_reader :frontend, :backend, :poller, :context, :available_workers + attr_reader :frontend, :backend, :poller, :context, :available_workers, :options, :expected_worker_count ## # Constructor # def initialize(options = {}) @available_workers = [] + @options = options.deep_dup + @expected_worker_count = @options[:threads] @context = ::ZMQ::Context.new - @frontend = setup_frontend(options) - @backend = setup_backend(options) @poller = ::ZMQ::Poller.new - @poller.register(frontend, ::ZMQ::POLLIN) - @poller.register(backend, ::ZMQ::POLLIN) + setup_backend end ## # Instance Methods # def poll - if available_workers.size > 0 - poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2 + if frontend.nil? + if local_workers_have_started? + # only open the front end when the workers are done booting + log_info { "Starting frontend socket in broker, all workers ready!" } + setup_frontend + end else - poller.delete(frontend) + # Start checking the poller after startup + if available_workers.size > 0 + poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2 + else + poller.delete(frontend) + end end poller.poll(1000) poller.readables.each do |socket| case socket - when frontend then - move_to_backend(socket) when backend then move_to_frontend(socket) + when frontend then + move_to_backend(socket) end end end + def setup_backend + host = options[:host] + port = options[:worker_port] + + zmq_backend = context.socket(::ZMQ::ROUTER) + zmq_error_check(zmq_backend.bind(bind_address(host, port))) + + @backend = zmq_backend + @poller.register(@backend, ::ZMQ::POLLIN) + end + + def setup_frontend + host = options[:host] + port = options[:port] + + zmq_frontend = context.socket(::ZMQ::ROUTER) + zmq_error_check(zmq_frontend.bind(bind_address(host, port))) + + @frontend = zmq_frontend + @poller.register(@frontend, ::ZMQ::POLLIN) + end + def teardown - frontend.close - backend.close - context.terminate + frontend.try(:close) + backend.try(:close) + context.try(:terminate) end private + def local_workers_have_started? + @local_workers_have_started ||= available_workers.size >= expected_worker_count + end + def move_to_backend(socket) message_array = [] zmq_error_check(socket.recv_strings(message_array)) @@ -73,7 +107,9 @@ def move_to_frontend(socket) available_workers << message_array[0] # messages should be [ "uuid of socket", "", "READY_MESSAGE || uuid of client socket"] - unless message_array[2] == ::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE + if message_array[2] == ::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE + log_info { "Worker #{available_workers.size} of #{expected_worker_count} ready!" } + else frontend_message_set = [ message_array[2], # client UUID "", @@ -84,24 +120,6 @@ def move_to_frontend(socket) end end - def setup_backend(options = {}) - host = options[:host] - port = options[:worker_port] - - zmq_backend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_backend.bind(bind_address(host, port))) - zmq_backend - end - - def setup_frontend(options = {}) - host = options[:host] - port = options[:port] - - zmq_frontend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_frontend.bind(bind_address(host, port))) - zmq_frontend - end - def bind_address(host, port) "tcp://#{resolve_ip(host)}:#{port}" end diff --git a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb index 21af27a1..6aef8433 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb @@ -17,10 +17,6 @@ subject.context.should be_a(::ZMQ::Context) end - it 'sets up a frontend socket' do - subject.frontend.should be_a(::ZMQ::Socket) - end - it 'sets up a backend socket' do subject.backend.should be_a(::ZMQ::Socket) end From 4af256ac9fd11edfca44db59f9c62dbb0c4ce16f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 11 Mar 2013 15:41:22 -0600 Subject: [PATCH 0328/1191] bump to 2.7.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f0a5f593..219f6a22 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.3' + VERSION = '2.7.4' PROTOC_VERSION = '2.4.1' end From 9da0c3c5eff61a866b202bd7872e8c6a60ffa614 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 11 Mar 2013 15:50:10 -0600 Subject: [PATCH 0329/1191] have zmq workers die or kill them after 5 seconds --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- spec/lib/protobuf/rpc/servers/zmq/server_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 38bbae61..1d9ab259 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -62,7 +62,7 @@ def self.stop @running = false @threads.each do |t| - t.join + t.join(5) || t.kill end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index b0128ded..33937a30 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -27,7 +27,7 @@ it 'lets all threads stop' do thread_mock = double(Thread) - thread_mock.should_receive(:join) + thread_mock.should_receive(:join).and_return(thread_mock) described_class.instance_variable_set(:@threads, [thread_mock]) described_class.stop end From a197a2dadb730e07e2166e4bc88ec10938b765e4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 13 Mar 2013 14:07:51 -0600 Subject: [PATCH 0330/1191] add ! method to get raw value from protobuf message --- lib/protobuf/message.rb | 4 ++++ spec/lib/protobuf/message_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index e107fbb3..c6b0beb3 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -34,6 +34,10 @@ def self.define_field(rule, type, fname, tag, options) field_definition = ::Protobuf::Field.build(self, rule, type, fname, tag, options) field_name_hash[fname] = tag field_array[tag] = field_definition + + define_method("#{fname}!") do + @values[fname] + end end # Reserve field numbers for extensions. Don't use this method directly. diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 57851216..3c726a38 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -3,6 +3,22 @@ describe Protobuf::Message do describe '#initialize' do + it "initializes the enum getter to 0" do + test_enum = Test::EnumTestMessage.new + test_enum.non_default_enum.should eq(0) + end + + it "exposes the enum getter raw value through ! method" do + test_enum = Test::EnumTestMessage.new + test_enum.non_default_enum!.should be_nil + end + + it "exposes the enum getter raw value through ! method (when set)" do + test_enum = Test::EnumTestMessage.new + test_enum.non_default_enum = 1 + test_enum.non_default_enum!.should eq(1) + end + it "does not try to set attributes which have nil values" do Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=") test_enum = Test::EnumTestMessage.new(:non_default_enum => nil) From 8b847c96ee437b870e19688f090f80ba58c241cf Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 13 Mar 2013 14:08:12 -0600 Subject: [PATCH 0331/1191] bump to 2.7.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 219f6a22..5350b2d8 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.4' + VERSION = '2.7.5' PROTOC_VERSION = '2.4.1' end From 6d1ecb478f284ed71ddaa4ffeaf26ffdf6552882 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 8 Mar 2013 16:16:55 -0700 Subject: [PATCH 0332/1191] Compile Extension Fields to correct message class The libprotoc Generator provides extension fields to a FileDescriptor or Descriptor object. I misunderstood that the descriptor extension fields are not the fields that belong to the corresponding message proto/class. The fix is to store the extension fields by their containing type name when we initially parse through the messages in the file descriptor. Then when we go to print each message's fields we print out the previously extracted extension fields. Fixes #69. --- ext/ruby_generator/RubyGenerator.cpp | 222 +++++++++++++++++++-------- ext/ruby_generator/RubyGenerator.h | 14 +- ext/ruby_generator/protoc-ruby | Bin 137316 -> 232308 bytes spec/spec_helper.rb | 1 + spec/support/test/enum.pb.rb | 26 ++-- spec/support/test/enum.proto | 5 + spec/support/test/resource.pb.rb | 58 +++++-- spec/support/test/resource.proto | 45 ++++++ 8 files changed, 285 insertions(+), 86 deletions(-) diff --git a/ext/ruby_generator/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp index a7299c27..70e6bda6 100644 --- a/ext/ruby_generator/RubyGenerator.cpp +++ b/ext/ruby_generator/RubyGenerator.cpp @@ -18,6 +18,7 @@ bool RubyGenerator::Generate(const FileDescriptor* file, filename = CreateRubyFileName(file_->name()); ns_vector.clear(); + extended_messages.clear(); SplitStringUsing(file_->package(), ".", &ns_vector); // Get a ZeroCopyOutputStream object of the data. @@ -41,9 +42,10 @@ bool RubyGenerator::Generate(const FileDescriptor* file, PrintMessagesForFileDescriptor(file_, false); PrintNewLine(); - PrintEnumsForFileDescriptor(file_, true); PrintMessagesForFileDescriptor(file_, true); + PrintDanglingExtendedMessages(); + PrintServices(); PrintEnclosingNamespaceModuleEnds(); @@ -88,6 +90,9 @@ void RubyGenerator::PrintEnclosingNamespaceModuleEnds() const { ///////////////////////////////////////////////// [ messages ] //////////////// // +// Print a comment and then iteratively PrintMessage for each message +// type defined by in this FileDescriptor scope. +// void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const { if (descriptor->message_type_count() > 0) { if (print_fields) { @@ -95,6 +100,7 @@ void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descrip } else { PrintComment("Message Classes", true); + StoreExtensionFields(descriptor); } for (int i = 0; i < descriptor->message_type_count(); i++) { @@ -103,76 +109,102 @@ void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descrip } } +// Iterates the nested types of a message descriptor and calls PrintMessage for each. +// void RubyGenerator::PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const { for (int i = 0; i < descriptor->nested_type_count(); i++) { PrintMessage(descriptor->nested_type(i), print_fields); } } -// + // Print out the given descriptor message as a Ruby class. +// void RubyGenerator::PrintMessage(const Descriptor* descriptor, bool print_fields) const { map data; data["class_name"] = descriptor->name(); - if (print_fields && (descriptor->field_count() > 0 || descriptor->extension_count() > 0)) { - printer_->Print(data, "class $class_name$"); - PrintNewLine(); - printer_->Indent(); + switch (print_fields) { + case false: - if (descriptor->enum_type_count() > 0) { - PrintEnumsForDescriptor(descriptor, true); - } + if (DescriptorHasNestedTypes(descriptor)) { + printer_->Print(data, "class $class_name$ < ::Protobuf::Message"); + PrintNewLine(); + printer_->Indent(); - if (descriptor->nested_type_count() > 0) { - PrintMessagesForDescriptor(descriptor, true); - } + if (descriptor->enum_type_count() > 0) { + PrintEnumsForDescriptor(descriptor, true); + } - PrintExtensionRangesForDescriptor(descriptor); + if (descriptor->nested_type_count() > 0) { + PrintMessagesForDescriptor(descriptor, false); + } - // Print Fields - if (descriptor->field_count() > 0) { - for (int i = 0; i < descriptor->field_count(); i++) { - PrintMessageField(descriptor->field(i)); + printer_->Outdent(); + printer_->Print(data, "end"); } - } - - // Print Extension Fields - if (descriptor->extension_count() > 0) { - for (int i = 0; i < descriptor->extension_count(); i++) { - PrintMessageField(descriptor->extension(i)); + else { + printer_->Print(data, "class $class_name$ < ::Protobuf::Message; end"); } - } - printer_->Outdent(); - printer_->Print(data, "end"); - PrintNewLine(); - } - else if (DescriptorHasNestedTypes(descriptor)) { - printer_->Print(data, "class $class_name$ < ::Protobuf::Message"); - PrintNewLine(); - printer_->Indent(); + PrintNewLine(); + StoreExtensionFields(descriptor); - if (descriptor->enum_type_count() > 0) { - PrintEnumsForDescriptor(descriptor, false); - } + break; - if (descriptor->nested_type_count() > 0) { - PrintMessagesForDescriptor(descriptor, false); - } + case true: - printer_->Outdent(); - printer_->Print(data, "end"); - PrintNewLine(); - } - else { - printer_->Print(data, "class $class_name$ < ::Protobuf::Message; end"); - } + if (descriptor->field_count() > 0 || DescriptorHasExtensions(descriptor)) { + printer_->Print(data, "class $class_name$"); + PrintNewLine(); + printer_->Indent(); - PrintNewLine(); + if (descriptor->nested_type_count() > 0) { + PrintMessagesForDescriptor(descriptor, true); + } + + // Print Fields + if (descriptor->field_count() > 0) { + for (int i = 0; i < descriptor->field_count(); i++) { + PrintMessageField(descriptor->field(i)); + } + } + + PrintExtensionRangesForDescriptor(descriptor); + + // Print Extension Fields + if (DescriptorHasExtensions(descriptor)) { + PrintMessageExtensionFields(descriptor->full_name()); + } + + printer_->Outdent(); + printer_->Print(data, "end"); + PrintNewLine(); + PrintNewLine(); + } + else if (descriptor->nested_type_count() > 0) { + printer_->Print(data, "class $class_name$"); + PrintNewLine(); + printer_->Indent(); + + if (descriptor->nested_type_count() > 0) { + PrintMessagesForDescriptor(descriptor, true); + } + + printer_->Outdent(); + printer_->Print(data, "end"); + PrintNewLine(); + PrintNewLine(); + } + + break; + } } void RubyGenerator::PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const { if (descriptor->extension_range_count() > 0) { + PrintNewLine(); + PrintComment("Extension Fields", false); + for (int i = 0; i < descriptor->extension_range_count(); i++) { const Descriptor::ExtensionRange* range = descriptor->extension_range(i); map data; @@ -281,6 +313,20 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { PrintNewLine(); } +// Print out each extension field previously mapped to the full name of +// the descriptor message. +// +// After printign the fields, erase the fields from the map so that we know +// which fields are dangling and to print wrapped in a re-opened class block. +// +void RubyGenerator::PrintMessageExtensionFields(const string full_name) const { + vector message_extensions = extended_messages[full_name]; + vector::iterator it; + for (it = message_extensions.begin(); it != message_extensions.end(); ++it) { + PrintMessageField(*it); + } + extended_messages.erase(full_name); +} // ///////////////////////////////////////////////// [ enums ] /////////////////// @@ -288,7 +334,7 @@ void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { void RubyGenerator::PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const { for (int i = 0; i < descriptor->enum_type_count(); i++) { - PrintEnum(descriptor->enum_type(i), print_values); + PrintEnum(descriptor->enum_type(i)); } } @@ -302,33 +348,28 @@ void RubyGenerator::PrintEnumsForFileDescriptor(const FileDescriptor* descriptor } for (int i = 0; i < descriptor->enum_type_count(); i++) { - PrintEnum(descriptor->enum_type(i), print_values); + PrintEnum(descriptor->enum_type(i)); } } } // Print the given enum descriptor as a Ruby class. -void RubyGenerator::PrintEnum(const EnumDescriptor* descriptor, bool print_values) const { +void RubyGenerator::PrintEnum(const EnumDescriptor* descriptor) const { map data; data["class_name"] = descriptor->name(); - if (print_values) { - printer_->Print(data, "class $class_name$"); - printer_->Indent(); - PrintNewLine(); - - for (int i = 0; i < descriptor->value_count(); i++) { - PrintEnumValue(descriptor->value(i)); - } + printer_->Print(data, "class $class_name$ < ::Protobuf::Enum"); + printer_->Indent(); + PrintNewLine(); - printer_->Outdent(); - printer_->Print(data, "end"); - PrintNewLine(); - } - else { - printer_->Print(data, "class $class_name$ < ::Protobuf::Enum; end"); + for (int i = 0; i < descriptor->value_count(); i++) { + PrintEnumValue(descriptor->value(i)); } + printer_->Outdent(); + printer_->Print(data, "end"); + PrintNewLine(); + PrintNewLine(); } @@ -387,6 +428,42 @@ void RubyGenerator::PrintServiceMethod(const MethodDescriptor* descriptor) const ///////////////////////////////////////////////// [ general ] //////////////// // +void RubyGenerator::PrintDanglingExtendedMessages() const { + if (extended_messages.size() > 0) { + PrintComment("Extended Messages", true); + + tr1::unordered_map >::iterator it; + for (it = extended_messages.begin(); it != extended_messages.end(); ++it ) { + map data; + data["class_name"] = Constantize(it->first); + + printer_->Print(data, "class $class_name$"); + printer_->Indent(); + PrintNewLine(); + + PrintMessageExtensionFields(it->first); + + printer_->Outdent(); + printer_->Print(data, "end"); + PrintNewLine(); + PrintNewLine(); + } + } +} + +// Explicitly check for the key with `count` so that we don't create +// empty vectors for classes simply using bracket access. +// +bool RubyGenerator::DescriptorHasExtensions(const Descriptor* descriptor) const { + const string full_name = descriptor->full_name(); + if (extended_messages.count(full_name) > 0) { + return (extended_messages[full_name].size()); + } + else { + return 0; + } +} + // Print a header or one-line comment (as indicated by the as_header bool). void RubyGenerator::PrintComment(string comment, bool as_header) const { char format[] = "# $comment$\n"; @@ -444,6 +521,25 @@ void RubyGenerator::PrintNewLine() const { printer_->Print("\n"); } +// We need to store any extension fields defined in the scope of this +// descriptor message by the field's containing type. +void RubyGenerator::StoreExtensionFields(const FileDescriptor* descriptor) const { + for (int i = 0; i < descriptor->extension_count(); i++) { + const FieldDescriptor* extension_field = descriptor->extension(i); + const Descriptor* containing = extension_field->containing_type(); + extended_messages[containing->full_name()].push_back(extension_field); + } +} + +// Same as above, only accept the Descriptor type instead of FileDescriptor. +void RubyGenerator::StoreExtensionFields(const Descriptor* descriptor) const { + for (int i = 0; i < descriptor->extension_count(); i++) { + const FieldDescriptor* extension_field = descriptor->extension(i); + const Descriptor* containing = extension_field->containing_type(); + extended_messages[containing->full_name()].push_back(extension_field); + } +} + } // namespace ruby } // namespace compiler } // namespace protobuf diff --git a/ext/ruby_generator/RubyGenerator.h b/ext/ruby_generator/RubyGenerator.h index f620360b..dc0b7e7c 100644 --- a/ext/ruby_generator/RubyGenerator.h +++ b/ext/ruby_generator/RubyGenerator.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -31,28 +32,32 @@ class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { GeneratorContext* context, string* error) const; - private: mutable GeneratorContext* context_; mutable io::Printer* printer_; mutable const FileDescriptor* file_; mutable string filename; mutable vector ns_vector; + mutable tr1::unordered_map > extended_messages; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RubyGenerator); + bool DescriptorHasExtensions(const Descriptor* descriptor) const; + void PrintDanglingExtendedMessages() const; + void PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const; + void PrintEnclosingNamespaceModules() const; void PrintEnclosingNamespaceModuleEnds() const; void PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const; void PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const; void PrintMessage(const Descriptor* descriptor, bool print_fields) const; - void PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const; void PrintMessageField(const FieldDescriptor* descriptor) const; + void PrintMessageExtensionFields(const string full_name) const; void PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const; void PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const; - void PrintEnum(const EnumDescriptor* descriptor, bool print_values) const; + void PrintEnum(const EnumDescriptor* descriptor) const; void PrintEnumValue(const EnumValueDescriptor* descriptor) const; void PrintServices() const; @@ -67,6 +72,9 @@ class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { void PrintRequire(string lib_name) const; void PrintNewLine() const; + void StoreExtensionFields(const FileDescriptor* descriptor) const; + void StoreExtensionFields(const Descriptor* descriptor) const; + // Take the proto file name, strip ".proto" // from the end and add ".pb.rb" static string CreateRubyFileName(const string proto_filename) { diff --git a/ext/ruby_generator/protoc-ruby b/ext/ruby_generator/protoc-ruby index 7a53215cfbd97f17bccb89edeacdb23e6944d095..6557bef834c619e40ac9802e9a6215339cf7c937 100755 GIT binary patch literal 232308 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 Lp+|sZM)Cguv9Mmu literal 137316 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 true + end + end diff --git a/spec/support/test/enum.proto b/spec/support/test/enum.proto index 5bc64226..3476d35f 100644 --- a/spec/support/test/enum.proto +++ b/spec/support/test/enum.proto @@ -1,4 +1,5 @@ package test; +import 'test/resource.proto'; enum EnumTestType { ONE = 1; @@ -10,3 +11,7 @@ message EnumTestMessage { optional EnumTestType default_enum = 2 [default=ONE]; repeated EnumTestType repeated_enums = 3; } + +extend test.Resource { + optional int32 ext_other_file_defined_field = 200; +} diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 356fb47d..007ead1e 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -8,23 +8,31 @@ module Test ## # Enum Classes # - class StatusType < ::Protobuf::Enum; end + class StatusType < ::Protobuf::Enum + define :PENDING, 0 + define :ENABLED, 1 + define :DISABLED, 2 + define :DELETED, 3 + end + ## # Message Classes # class ResourceFindRequest < ::Protobuf::Message; end class Resource < ::Protobuf::Message; end - class Nested < ::Protobuf::Message; end - - ## - # Enum Values - # - class StatusType - define :PENDING, 0 - define :ENABLED, 1 - define :DISABLED, 2 - define :DELETED, 3 + class Searchable < ::Protobuf::Message + class SearchType < ::Protobuf::Enum + define :FLAT, 1 + define :NESTED, 2 + end + + end + class MessageParent < ::Protobuf::Message + class MessageChild < ::Protobuf::Message; end + end + class Nested < ::Protobuf::Message + class NestedLevelOne < ::Protobuf::Message; end end ## @@ -40,13 +48,41 @@ class Resource optional ::Protobuf::Field::Int64Field, :date_created, 2 optional ::Test::StatusType, :status, 3 repeated ::Test::StatusType, :repeated_enum, 4 + + # Extension Fields + extensions 100...536870912 + optional ::Protobuf::Field::BoolField, :ext_is_searchable, 100, :extension => true + optional ::Protobuf::Field::BoolField, :ext_is_hidden, 101, :extension => true + optional ::Test::Searchable::SearchType, :ext_search_type, 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true + optional ::Protobuf::Field::BoolField, :ext_nested_in_level_one, 105, :extension => true + end + + class MessageParent + class MessageChild + optional ::Protobuf::Field::StringField, :child1, 1 + end + end class Nested + class NestedLevelOne + optional ::Protobuf::Field::BoolField, :level_one, 1, :default => true + + # Extension Fields + extensions 100...102 + optional ::Protobuf::Field::BoolField, :ext_nested_level_one_outer, 101, :extension => true + optional ::Protobuf::Field::BoolField, :ext_nested_level_one, 100, :extension => true + end + optional ::Protobuf::Field::StringField, :name, 1 optional ::Test::Resource, :resource, 2 repeated ::Test::Resource, :multiple_resources, 3 optional ::Test::StatusType, :status, 4 + + # Extension Fields + extensions 100...111 + optional ::Protobuf::Field::StringField, :foo, 100, :extension => true + optional ::Protobuf::Field::Int64Field, :bar, 101, :extension => true end ## diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index 202df04d..ef4439ac 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -13,17 +13,62 @@ message ResourceFindRequest { } message Resource { + extensions 100 to max; + required string name = 1; optional int64 date_created = 2; optional StatusType status = 3; repeated StatusType repeated_enum = 4; } +message Searchable { + enum SearchType { + FLAT = 1; + NESTED = 2; + } + + extend test.Resource { + optional bool ext_is_searchable = 100; + optional bool ext_is_hidden = 101; + optional Searchable.SearchType ext_search_type = 102 [default=FLAT]; + } +} + +message MessageParent { + message MessageChild { + optional string child1 = 1; + } +} + message Nested { + extensions 100 to 110; + optional string name = 1; optional Resource resource = 2; repeated Resource multiple_resources = 3; optional StatusType status = 4; + + message NestedLevelOne { + extensions 100 to 101; + optional bool level_one = 1 [default=true]; + + extend Resource { + optional bool ext_nested_in_level_one = 105; + } + } + + extend NestedLevelOne { + optional bool ext_nested_level_one = 100; + } +} + +extend Nested { + optional string foo = 100; + optional int64 bar = 101; +} + +extend Nested.NestedLevelOne { + optional bool ext_nested_level_one_outer = 101; } service ResourceService { From 202cb7467ca5b2241af996544b48b1fc3fff4ae9 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 8 Mar 2013 16:59:20 -0700 Subject: [PATCH 0333/1191] Ignore value assignment on unknown fields --- lib/protobuf/message.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c6b0beb3..87c4354e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -68,11 +68,8 @@ def self.field_name_to_tag end def self.get_ext_field_by_name(name) - # Check if the name has been used before, if not then set it to the sym value - extension_fields[extension_field_name_to_tag[name.to_sym]] - rescue TypeError, NoMethodError => e - name = 'nil' if name.nil? - raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") + tag = extension_field_name_to_tag[name.to_sym] + extension_fields[tag] unless tag.nil? end def self.get_ext_field_by_tag(tag) @@ -81,11 +78,8 @@ def self.get_ext_field_by_tag(tag) # Find a field object by +name+. def self.get_field_by_name(name) - # Check if the name has been used before, if not then set it to the sym value - fields[field_name_to_tag[name.to_sym]] - rescue TypeError, NoMethodError => e - name = 'nil' if name.nil? - raise FieldNotDefinedError.new("Field '#{name}' is not defined on message '#{self.name}'") + tag = field_name_to_tag[name.to_sym] + fields[tag] unless tag.nil? end # Find a field object by +tag+ number. @@ -93,6 +87,7 @@ def self.get_field_by_tag(tag) fields[tag] rescue TypeError => e tag = tag.nil? ? 'nil' : tag.to_s + raise raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") end @@ -284,16 +279,12 @@ def ==(obj) def [](name) if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.name) - else - raise NoMethodError, "No such field: #{name.inspect}" end end def []=(name, value) if field = get_field_by_name(name) || get_ext_field_by_name(name) __send__(field.setter_method_name, value) - else - raise NoMethodError, "No such field: #{name.inspect}" end end From 4acc17b9e192eef705fc4d586f2b4b0988bb749b Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 17 Mar 2013 21:22:05 -0600 Subject: [PATCH 0334/1191] Bump version 2.7.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5350b2d8..c4cab9ca 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.5' + VERSION = '2.7.6' PROTOC_VERSION = '2.4.1' end From 00c48b85545a662cf7090355c54d4568cefa6d9e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Mar 2013 17:10:15 -0600 Subject: [PATCH 0335/1191] Symbolize name only if it responds to to_sym --- lib/protobuf/message.rb | 4 ++-- spec/lib/protobuf/message_spec.rb | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 87c4354e..0f404647 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -78,7 +78,8 @@ def self.get_ext_field_by_tag(tag) # Find a field object by +name+. def self.get_field_by_name(name) - tag = field_name_to_tag[name.to_sym] + name = name.to_sym if name.respond_to?(:to_sym) + tag = field_name_to_tag[name] fields[tag] unless tag.nil? end @@ -87,7 +88,6 @@ def self.get_field_by_tag(tag) fields[tag] rescue TypeError => e tag = tag.nil? ? 'nil' : tag.to_s - raise raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 3c726a38..d72a2d41 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -8,12 +8,12 @@ test_enum.non_default_enum.should eq(0) end - it "exposes the enum getter raw value through ! method" do + it "exposes the enum getter raw value through ! method" do test_enum = Test::EnumTestMessage.new test_enum.non_default_enum!.should be_nil end - it "exposes the enum getter raw value through ! method (when set)" do + it "exposes the enum getter raw value through ! method (when set)" do test_enum = Test::EnumTestMessage.new test_enum.non_default_enum = 1 test_enum.non_default_enum!.should eq(1) @@ -227,21 +227,15 @@ context 'when name is not a valid field' do specify do - expect { - subject.get_field_by_name(1) - }.to raise_error(::Protobuf::FieldNotDefinedError, /.*1.*#{subject.class.name}/) + subject.get_field_by_name(1).should be_nil end specify do - expect { - subject.get_field_by_name(:nothere) - }.to raise_error(::Protobuf::FieldNotDefinedError, /.*nothere.*#{subject.class.name}/) + subject.get_field_by_name(:nothere).should be_nil end specify do - expect { - subject.get_field_by_name(nil) - }.to raise_error(::Protobuf::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) + subject.get_field_by_name(nil).should be_nil end end end From 2402ba2a4f16c1580675a649501fcdfdf58a65a0 Mon Sep 17 00:00:00 2001 From: Shane Hanna Date: Tue, 19 Mar 2013 11:31:20 +1100 Subject: [PATCH 0336/1191] Only require used active_support extensions. Libraries should never modify core classes indirectly. Explicitly require only used active_support extensions rather than loading (or autoloading) everything. --- lib/protobuf.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 702babe1..c269b42f 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -2,7 +2,16 @@ require 'socket' require 'pp' require 'stringio' -require 'active_support/all' +require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/object/try' +require 'active_support/inflector' +require 'active_support/json' + +begin # master +require 'active_support/core_ext/object/deep_dup' +rescue LoadError # 3.2.x +require 'active_support/core_ext/hash/deep_dup' +end module Protobuf From c0e8c48c2bbca0b489ddc2f9ef8ce5f81fe29f1c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 18 Mar 2013 18:52:19 -0600 Subject: [PATCH 0337/1191] Bump version 2.7.7 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c4cab9ca..697dd8d2 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.6' + VERSION = '2.7.7' PROTOC_VERSION = '2.4.1' end From a25abdaebcf432977ecaaa04f7a716e5208148fe Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 11:17:26 -0600 Subject: [PATCH 0338/1191] Create CONTRIBUTING.md --- CONTRIBUTING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..72ec4dc7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,16 @@ +# Contributing + +I love accepting issues and pull requests. I only ask for a few guidelines to +be followed that will make it much easier for me to solve your issue or get +your code merged. + +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. +2. For _compiler issues_, please provide both a gist for the _source definition(s)_ as well as the _generated output_ (if any). +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`. +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. +5. Be patient with me as I work on your issue. + +Following these simple guidelines really will help me help you. And really, +that's what we're here for. :) + +## Happy Contributing! From e45498159f7cd64b288add1574b7d1f84dc30e87 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 11:19:32 -0600 Subject: [PATCH 0339/1191] Update CONTRIBUTING.md --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 72ec4dc7..1a8af7d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,9 +5,9 @@ be followed that will make it much easier for me to solve your issue or get your code merged. 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. -2. For _compiler issues_, please provide both a gist for the _source definition(s)_ as well as the _generated output_ (if any). -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`. -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. +2. For __compiler issues__, please provide both a gist for the __source definition(s)__ as well as the __generated output__ (if any). +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`. +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. 5. Be patient with me as I work on your issue. Following these simple guidelines really will help me help you. And really, From 83f6c233a272517b15cc59716d746d7ec79ac4f6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 11:20:39 -0600 Subject: [PATCH 0340/1191] Create CONTRIBUTING.md --- CONTRIBUTING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..1a8af7d8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,16 @@ +# Contributing + +I love accepting issues and pull requests. I only ask for a few guidelines to +be followed that will make it much easier for me to solve your issue or get +your code merged. + +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. +2. For __compiler issues__, please provide both a gist for the __source definition(s)__ as well as the __generated output__ (if any). +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`. +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. +5. Be patient with me as I work on your issue. + +Following these simple guidelines really will help me help you. And really, +that's what we're here for. :) + +## Happy Contributing! From 9afa08af5c6b0dc25263b1985f5e382994d04110 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 11:34:05 -0600 Subject: [PATCH 0341/1191] Fix travis zmq install, add ruby 2.0 build --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bdca3adf..9bf46467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby rvm: - "1.9.2" - "1.9.3" + - "2.0.0" script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec before_install: - - sudo apt-get install -qq libzmq-dev + - sudo apt-get install -qq libzmq3-dev From 78bf3744499a1b9809080fa712aa132a6a250e81 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 11:34:35 -0600 Subject: [PATCH 0342/1191] Fix travis zmq install, add ruby 2.0 build --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bdca3adf..9bf46467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby rvm: - "1.9.2" - "1.9.3" + - "2.0.0" script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec before_install: - - sudo apt-get install -qq libzmq-dev + - sudo apt-get install -qq libzmq3-dev From 825662525ab8aad78814928196b9b725ba8db893 Mon Sep 17 00:00:00 2001 From: Shane Hanna Date: Tue, 19 Mar 2013 11:31:20 +1100 Subject: [PATCH 0343/1191] Only require used active_support extensions. Libraries should never modify core classes indirectly. Explicitly require only used active_support extensions rather than loading (or autoloading) everything. --- lib/protobuf.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 702babe1..c269b42f 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -2,7 +2,16 @@ require 'socket' require 'pp' require 'stringio' -require 'active_support/all' +require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/object/try' +require 'active_support/inflector' +require 'active_support/json' + +begin # master +require 'active_support/core_ext/object/deep_dup' +rescue LoadError # 3.2.x +require 'active_support/core_ext/hash/deep_dup' +end module Protobuf From 7e33a09f5dc3f4c9e470c3fe841004eaba4f0287 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 15:05:03 -0600 Subject: [PATCH 0344/1191] Print dangling messages from FileDescriptor Previously we were only printing dangling messages if the FileDescriptor had other messages or enums defined. Now we store/print them regardless. This should have been the behavior before I just didn't have a valid test case. Fixes #58. --- ext/ruby_generator/RubyGenerator.cpp | 12 +++++------- ext/ruby_generator/protoc-ruby | Bin 232308 -> 232308 bytes spec/support/test/enum.pb.rb | 3 +++ spec/support/test/enum.proto | 2 ++ spec/support/test/extended.pb.rb | 20 ++++++++++++++++++++ spec/support/test/extended.proto | 10 ++++++++++ spec/support/test/resource.pb.rb | 5 +++++ spec/support/test/resource.proto | 5 +++++ spec/support/test/resource_service.rb | 14 -------------- 9 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 spec/support/test/extended.pb.rb create mode 100644 spec/support/test/extended.proto delete mode 100644 spec/support/test/resource_service.rb diff --git a/ext/ruby_generator/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp index 70e6bda6..c5e0475e 100644 --- a/ext/ruby_generator/RubyGenerator.cpp +++ b/ext/ruby_generator/RubyGenerator.cpp @@ -36,16 +36,12 @@ bool RubyGenerator::Generate(const FileDescriptor* file, PrintImportRequires(); PrintEnclosingNamespaceModules(); + StoreExtensionFields(file_); PrintEnumsForFileDescriptor(file_, false); - PrintNewLine(); PrintMessagesForFileDescriptor(file_, false); - PrintNewLine(); - PrintMessagesForFileDescriptor(file_, true); - PrintDanglingExtendedMessages(); - PrintServices(); PrintEnclosingNamespaceModuleEnds(); @@ -72,6 +68,7 @@ void RubyGenerator::PrintEnclosingNamespaceModules() const { printer_->Print(data, "module $ns$"); PrintNewLine(); + PrintNewLine(); printer_->Indent(); } } @@ -82,6 +79,7 @@ void RubyGenerator::PrintEnclosingNamespaceModuleEnds() const { printer_->Outdent(); printer_->Print("end"); PrintNewLine(); + PrintNewLine(); } } @@ -100,12 +98,12 @@ void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descrip } else { PrintComment("Message Classes", true); - StoreExtensionFields(descriptor); } for (int i = 0; i < descriptor->message_type_count(); i++) { PrintMessage(descriptor->message_type(i), print_fields); } + PrintNewLine(); } } @@ -350,6 +348,7 @@ void RubyGenerator::PrintEnumsForFileDescriptor(const FileDescriptor* descriptor for (int i = 0; i < descriptor->enum_type_count(); i++) { PrintEnum(descriptor->enum_type(i)); } + PrintNewLine(); } } @@ -369,7 +368,6 @@ void RubyGenerator::PrintEnum(const EnumDescriptor* descriptor) const { printer_->Outdent(); printer_->Print(data, "end"); PrintNewLine(); - PrintNewLine(); } diff --git a/ext/ruby_generator/protoc-ruby b/ext/ruby_generator/protoc-ruby index 6557bef834c619e40ac9802e9a6215339cf7c937..40417eeb4e0636a0c205e087d80d14a6e704e150 100755 GIT binary patch delta 17168 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 delta 17138 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 diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index f3d389f3..8e4039c9 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -9,6 +9,7 @@ require 'test/resource.pb' module Test + ## # Enum Classes # @@ -32,6 +33,7 @@ class EnumTestMessage repeated ::Test::EnumTestType, :repeated_enums, 3 end + ## # Extended Messages # @@ -40,3 +42,4 @@ class ::Test::Resource end end + diff --git a/spec/support/test/enum.proto b/spec/support/test/enum.proto index 3476d35f..35a11531 100644 --- a/spec/support/test/enum.proto +++ b/spec/support/test/enum.proto @@ -1,6 +1,8 @@ package test; import 'test/resource.proto'; +// Test extending another message from an imported file. + enum EnumTestType { ONE = 1; TWO = 2; diff --git a/spec/support/test/extended.pb.rb b/spec/support/test/extended.pb.rb new file mode 100644 index 00000000..2977c0e6 --- /dev/null +++ b/spec/support/test/extended.pb.rb @@ -0,0 +1,20 @@ +## +# This file is auto-generated. DO NOT EDIT! +# + +## +# Imports +# +require 'test/resource.pb' + +module Test + + ## + # Extended Messages + # + class ::Test::Resource + optional ::Protobuf::Field::Int64Field, :deleted_at, 300, :extension => true + end + +end + diff --git a/spec/support/test/extended.proto b/spec/support/test/extended.proto new file mode 100644 index 00000000..f12e60cb --- /dev/null +++ b/spec/support/test/extended.proto @@ -0,0 +1,10 @@ +package test; +import 'test/resource.proto'; + +// Test that we will re-open a class and add +// extension fields to it even if there are no +// message or enum definitions in this FileDescriptor. + +extend test.Resource { + optional int64 deleted_at = 300; +} diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 007ead1e..a3dd55bc 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -5,6 +5,7 @@ require 'protobuf/rpc/service' module Test + ## # Enum Classes # @@ -55,6 +56,8 @@ class Resource optional ::Protobuf::Field::BoolField, :ext_is_hidden, 101, :extension => true optional ::Test::Searchable::SearchType, :ext_search_type, 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true optional ::Protobuf::Field::BoolField, :ext_nested_in_level_one, 105, :extension => true + optional ::Protobuf::Field::BoolField, :ext_dup_field, 106, :extension => true + optional ::Protobuf::Field::BoolField, :ext_dup_field, 107, :extension => true end class MessageParent @@ -85,6 +88,7 @@ class NestedLevelOne optional ::Protobuf::Field::Int64Field, :bar, 101, :extension => true end + ## # Services # @@ -92,3 +96,4 @@ class ResourceService < ::Protobuf::Rpc::Service rpc :find, ::Test::ResourceFindRequest, ::Test::Resource end end + diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index ef4439ac..2e78f005 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -54,12 +54,17 @@ message Nested { extend Resource { optional bool ext_nested_in_level_one = 105; + optional bool ext_dup_field = 106; } } extend NestedLevelOne { optional bool ext_nested_level_one = 100; } + + extend Resource { + optional bool ext_dup_field = 107; + } } extend Nested { diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb deleted file mode 100644 index f1dab010..00000000 --- a/spec/support/test/resource_service.rb +++ /dev/null @@ -1,14 +0,0 @@ -require ::File.expand_path('../resource.pb', __FILE__) - -module Test - class ResourceService - - # request -> Test::ResourceFindRequest - # response -> Test::Resource - def find - response.name = request.name - response.status = request.active ? 1 : 0 - end - - end -end From 78356c52ee3a3b4a9183492d564e9a6e86c08db2 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 15:51:23 -0600 Subject: [PATCH 0345/1191] Check for dup field tags/names in define_field The rprotoc generator is duped by duplicate field names when you extend the same message from within different scopes: message Foo { ... } message Bar { extend Foo { optional Protobuf::Field::Int32Field, :foo, 100 } } message Baz { extend Foo { optional Protobuf::Field::Int32Field, :foo, 101 } } The fix is simply to check on each Message.define_field call for fields that already exist with the same name (regular or extension fields). Fixes #70 --- lib/protobuf/exceptions.rb | 1 + lib/protobuf/message.rb | 10 +++- spec/lib/protobuf/message_spec.rb | 48 +++++++++++++++++++ .../support/test/multi_field_extensions.pb.rb | 36 ++++++++++++++ .../support/test/multi_field_extensions.proto | 23 +++++++++ 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 spec/support/test/multi_field_extensions.pb.rb create mode 100644 spec/support/test/multi_field_extensions.proto diff --git a/lib/protobuf/exceptions.rb b/lib/protobuf/exceptions.rb index 842c689a..223b2fb9 100644 --- a/lib/protobuf/exceptions.rb +++ b/lib/protobuf/exceptions.rb @@ -5,4 +5,5 @@ class NotInitializedError < Error; end class TagCollisionError < Error; end class SerializationError < StandardError; end class FieldNotDefinedError < StandardError; end + class DuplicateFieldNameError < StandardError; end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 0f404647..eda4f330 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -27,8 +27,14 @@ def self.define_field(rule, type, fname, tag, options) field_array = options[:extension] ? extension_fields : fields field_name_hash = options[:extension] ? extension_field_name_to_tag : field_name_to_tag - if field_array[tag] - raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! + previous_tag_field = get_field_by_tag(tag) || get_ext_field_by_tag(tag) + if previous_tag_field + raise TagCollisionError, %!Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! + end + + previous_name_field = get_field_by_name(fname) || get_ext_field_by_name(fname) + if previous_name_field + raise DuplicateFieldNameError, %!Field name #{fname} has already been used in "#{self.name}".! end field_definition = ::Protobuf::Field.build(self, rule, type, fname, tag, options) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index d72a2d41..7a066b92 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -2,6 +2,54 @@ describe Protobuf::Message do + describe '.define_field' do + context 'when defining a field with a tag that has already been used' do + it 'raises a TagCollisionError' do + expect { + Class.new(Protobuf::Message) do + define_field :optional, ::Protobuf::Field::Int32Field, :foo, 1, {} + define_field :optional, ::Protobuf::Field::Int32Field, :bar, 1, {} + end + }.to raise_error(Protobuf::TagCollisionError, /Field number 1 has already been used/) + end + end + + context 'when defining an extension field with a tag that has already been used' do + it 'raises a TagCollisionError' do + expect { + Class.new(Protobuf::Message) do + extensions 100...110 + define_field :optional, ::Protobuf::Field::Int32Field, :foo, 100, {} + define_field :optional, ::Protobuf::Field::Int32Field, :bar, 100, :extension => true + end + }.to raise_error(Protobuf::TagCollisionError, /Field number 100 has already been used/) + end + end + + context 'when defining a field with a name that has already been used' do + it 'raises a DuplicateFieldNameError' do + expect { + Class.new(Protobuf::Message) do + define_field :optional, ::Protobuf::Field::Int32Field, :foo, 1, {} + define_field :optional, ::Protobuf::Field::Int32Field, :foo, 2, {} + end + }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) + end + end + + context 'when defining an extension field with a name that has already been used' do + it 'raises a DuplicateFieldNameError' do + expect { + Class.new(Protobuf::Message) do + extensions 100...110 + define_field :optional, ::Protobuf::Field::Int32Field, :foo, 1, {} + define_field :optional, ::Protobuf::Field::Int32Field, :foo, 100, :extension => true + end + }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) + end + end + end + describe '#initialize' do it "initializes the enum getter to 0" do test_enum = Test::EnumTestMessage.new diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/test/multi_field_extensions.pb.rb new file mode 100644 index 00000000..7e629c57 --- /dev/null +++ b/spec/support/test/multi_field_extensions.pb.rb @@ -0,0 +1,36 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Test + + ## + # Message Classes + # + class Header < ::Protobuf::Message + class Type < ::Protobuf::Enum + define :PayloadTypeA, 1 + define :PayloadTypeB, 2 + end + + end + class PayloadA < ::Protobuf::Message; end + class PayloadB < ::Protobuf::Message; end + + ## + # Message Fields + # + class Header + required ::Test::Header::Type, :type, 1 + + # Extension Fields + extensions 100...536870912 + optional ::Test::PayloadA, :payload, 100, :extension => true + # UNCOMMENT TO TEST FAILING WITH MULTIPLE FIELDS + # optional ::Test::PayloadB, :payload, 101, :extension => true + end + + +end + diff --git a/spec/support/test/multi_field_extensions.proto b/spec/support/test/multi_field_extensions.proto new file mode 100644 index 00000000..90d81a4b --- /dev/null +++ b/spec/support/test/multi_field_extensions.proto @@ -0,0 +1,23 @@ +package test; + +message Header { + extensions 100 to max; + enum Type { + PayloadTypeA = 1; + PayloadTypeB = 2; + } + required Type type = 1; +} + +message PayloadA { + extend Header { + optional PayloadA payload = 100; + } +} + +message PayloadB { + extend Header { + // UNCOMMENT TO TEST FAILING WITH MULTIPLE FIELDS + // optional PayloadB payload = 101; + } +} From 7ad277cf6a476ae6b8746de7667d4da274acfd13 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 19 Mar 2013 22:17:32 -0600 Subject: [PATCH 0346/1191] Fix StringField#encode to specify from/to encodings for ruby 2.0 --- Gemfile | 2 +- lib/protobuf/field/string_field.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index a1b93f3e..fa75df15 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source :rubygems +source 'https://rubygems.org/' gemspec diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 7e9fcd24..1ff359ac 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -12,8 +12,8 @@ def decode(bytes) def encode(value) # TODO: make replace character configurable? - value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") - value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + value.encode!(::Protobuf::Field::StringField::ENCODING, ::Protobuf::Field::BytesField::BYTES_ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value.size) string_size << value From f540ab691d2530a8efcb64425af9491e93911e4e Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 25 Mar 2013 17:18:14 -0600 Subject: [PATCH 0347/1191] Make runners and servers instance based --- lib/protobuf/cli.rb | 17 ++-- lib/protobuf/rpc/servers/evented_runner.rb | 19 +++-- lib/protobuf/rpc/servers/socket/server.rb | 27 ++++--- lib/protobuf/rpc/servers/socket_runner.rb | 41 ++++++---- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 40 +++++----- lib/protobuf/rpc/servers/zmq/worker.rb | 9 ++- lib/protobuf/rpc/servers/zmq_runner.rb | 42 +++++----- spec/functional/socket_server_spec.rb | 11 +-- spec/functional/zmq_server_spec.rb | 20 ++--- spec/lib/protobuf/cli_spec.rb | 78 ++++++++++--------- .../rpc/servers/evented_server_spec.rb | 3 +- .../rpc/servers/socket_server_spec.rb | 17 ++-- .../protobuf/rpc/servers/zmq/server_spec.rb | 25 +++--- spec/support/server.rb | 21 ++--- 15 files changed, 208 insertions(+), 164 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index af4e2060..791d27ff 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -171,7 +171,7 @@ def run_if_no_abort end def runner_options - { + { :host => options.host, :port => options.port, :backlog => options.backlog, @@ -187,7 +187,7 @@ def say_and_exit!(message, exception = nil) ::Protobuf::Logger.error { message } if exception - $stderr.puts "[#{exception.class.name}] #{exception.message}" + $stderr.puts "[#{exception.class.name}] #{exception.message}" $stderr.puts exception.backtrace.join("\n") ::Protobuf::Logger.error { "[#{exception.class.name}] #{exception.message}" } @@ -199,17 +199,17 @@ def say_and_exit!(message, exception = nil) def server_evented! @mode = :evented - @runner = ::Protobuf::Rpc::EventedRunner + @runner = ::Protobuf::Rpc::EventedRunner.new(runner_options) end def server_socket! @mode = :socket - @runner = ::Protobuf::Rpc::SocketRunner + @runner = ::Protobuf::Rpc::SocketRunner.new(runner_options) end def server_zmq! @mode = :zmq - @runner = ::Protobuf::Rpc::ZmqRunner + @runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) end # Start the runner and log the relevant options. @@ -217,15 +217,14 @@ def start_server! @runner.register_signals debug_say 'Invoking server start' - @runner.run(runner_options) do - ::Protobuf::Logger.info { + + @runner.run do + ::Protobuf::Logger.info { "pid #{::Process.pid} -- #{@mode} RPC Server listening at #{options.host}:#{options.port}" } end end - end - end end diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index 0825647d..f932f92f 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -2,22 +2,31 @@ module Protobuf module Rpc class EventedRunner - def self.register_signals + def initialize(options) + @options = options + end + + def register_signals # Noop end - def self.run(options) + def run # Startup and run the rpc server ::EventMachine.schedule do - ::EventMachine.start_server(options[:host], options[:port], ::Protobuf::Rpc::Evented::Server) + ::EventMachine.start_server( + @options[:host], + @options[:port], + ::Protobuf::Rpc::Evented::Server + ) end # Join or start the reactor - yield if block_given? + yield if block_given? + ::EM.reactor_running? ? ::EM.reactor_thread.join : ::EM.run end - def self.stop + def stop ::EventMachine.stop_event_loop if ::EventMachine.reactor_running? end diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 1d67f4ee..ed9ae980 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -11,12 +11,16 @@ class Server AUTO_COLLECT_TIMEOUT = 5 # seconds - def self.cleanup? + def initialize(options) + @options = options + end + + def cleanup? # every 10 connections run a cleanup routine after closing the response @threads.size > (@threshold - 1) && (@threads.size % @threshold) == 0 end - def self.cleanup_threads + def cleanup_threads log_debug { sign_message("Thread cleanup - #{@threads.size} - start") } @threads = @threads.select do |t| @@ -32,11 +36,11 @@ def self.cleanup_threads log_debug { sign_message("Thread cleanup - #{@threads.size} - complete") } end - def self.log_signature + def log_signature @_log_signature ||= "server-#{self.class.name}" end - def self.new_worker(socket) + def new_worker(socket) Thread.new(socket) do |sock| ::Protobuf::Rpc::Socket::Worker.new(sock) do |s| s.close @@ -44,12 +48,12 @@ def self.new_worker(socket) end end - def self.run(options = {}) + def run log_debug { sign_message("Run") } - host = options[:host] - port = options[:port] - backlog = options[:backlog] - @threshold = options[:threshold] + host = @options[:host] + port = @options[:port] + backlog = @options[:backlog] + @threshold = @options[:threshold] @threads = [] @server = ::TCPServer.new(host, port) @@ -96,16 +100,15 @@ def self.run(options = {}) raise #if running? end - def self.running? + def running? @running end - def self.stop + def stop @running = false @server.close if @server end end - end end end diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index d35cdcbb..9b376961 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -2,30 +2,37 @@ module Protobuf module Rpc class SocketRunner - def self.register_signals - # noop + def initialize(options) + @options = case + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.is_a?(Hash) then + options + when options.respond_to?(:to_hash) then + options.to_hash + else + raise "Cannot parser Socket Server - server options" + end + + @server = ::Protobuf::Rpc::Socket::Server.new(@options) end - def self.run(server) - server_config = case - when server.is_a?(OpenStruct) then - server.marshal_dump - when server.is_a?(Hash) then - server - when server.respond_to?(:to_hash) then - server.to_hash - else - raise "Cannot parser Socket Server - server options" - end + def register_signals + # noop + end - yield if block_given? - ::Protobuf::Rpc::Socket::Server.run(server_config) + def run + yield if block_given? + @server.run end - def self.stop - ::Protobuf::Rpc::Socket::Server.stop + def running? + @server.running? end + def stop + @server.stop + end end end end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index e001ee23..f6604bec 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -25,7 +25,7 @@ def initialize(options = {}) # def poll if frontend.nil? - if local_workers_have_started? + if local_workers_have_started? # only open the front end when the workers are done booting log_info { "Starting frontend socket in broker, all workers ready!" } setup_frontend diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 1d9ab259..30d4f6b5 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -8,18 +8,24 @@ module Zmq class Server include ::Protobuf::Rpc::Zmq::Util - ## - # Class Methods - # - def self.run(options = {}) + attr_accessor :threads, :options + + def initialize(options) @options = options + @threads = [] + end - unless options[:workers_only] + def host + @options[:host] + end + + def run + unless @options[:workers_only] log_debug { sign_message("initializing broker") } - @broker = ::Protobuf::Rpc::Zmq::Broker.new(options) + @broker = ::Protobuf::Rpc::Zmq::Broker.new(@options) end - local_worker_threads = options[:threads] + local_worker_threads = @options[:threads] log_debug { sign_message("starting server workers") } local_worker_threads.times do @@ -29,7 +35,7 @@ def self.run(options = {}) @running = true log_debug { sign_message("server started") } while self.running? do - if options[:workers_only] + if @options[:workers_only] sleep 5 Thread.pass else @@ -40,25 +46,25 @@ def self.run(options = {}) @broker.teardown if @broker end - def self.running? + def running? !!@running end - def self.start_worker - @threads << Thread.new(@options) { |options| + def start_worker + @threads << Thread.new(self) { |server| begin - ::Protobuf::Rpc::Zmq::Worker.new(options).run + ::Protobuf::Rpc::Zmq::Worker.new(server).run rescue => e message = "Worker Failed, spawning new worker: #{e.inspect}\n #{e.backtrace.join($/)}" $stderr.puts message log_error { message } - retry if ::Protobuf::Rpc::Zmq::Server.running? + retry if self.running? end } end - def self.stop + def stop @running = false @threads.each do |t| @@ -66,11 +72,9 @@ def self.stop end end - def self.threads - @threads + def worker_port + @options[:worker_port] end - - @threads ||= [] end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index c0c69053..f2b50eb8 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -11,9 +11,10 @@ class Worker ## # Constructor # - def initialize(options = {}) - host = options[:host] - port = options[:worker_port] + def initialize(server) + @server = server + host = server.host + port = server.worker_port @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) @@ -39,7 +40,7 @@ def handle_request(socket) end def run - while ::Protobuf::Rpc::Zmq::Server.running? do + while @server.running? do # poll for 1_000 milliseconds then continue looping # This lets us see whether we need to die @poller.poll(1_000) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index b2f4db20..b3d63cb5 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -3,33 +3,39 @@ module Rpc class ZmqRunner include ::Protobuf::Logger::LogMethods - def self.register_signals - trap(:TTIN) do + def initialize(options) + @options = case + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash + else + raise "Cannot parser Zmq Server - server options" + end + + @server = ::Protobuf::Rpc::Zmq::Server.new(@options) + end + + def register_signals + trap(:TTIN) do log_info { "TTIN received: Starting new worker" } - ::Protobuf::Rpc::Zmq::Server.start_worker + @server.start_worker log_info { "Worker count : #{::Protobuf::Rpc::Zmq::Server.threads.size}" } end end - def self.run(server) - server_config = case - when server.is_a?(OpenStruct) then - server.marshal_dump - when server.respond_to?(:to_hash) then - server.to_hash - else - raise "Cannot parser Zmq Server - server options" - end - - yield if block_given? - - ::Protobuf::Rpc::Zmq::Server.run(server_config) + def run + yield if block_given? + @server.run end - def self.stop - ::Protobuf::Rpc::Zmq::Server.stop + def running? + @server.running? end + def stop + @server.stop + end end end end diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 02ce00aa..2af158d1 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -4,14 +4,14 @@ describe 'Functional Socket Client' do before(:all) do load "protobuf/socket.rb" - Thread.abort_on_exception = true - server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) - @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } - Thread.pass until Protobuf::Rpc::Socket::Server.running? + @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) + @runner = ::Protobuf::Rpc::SocketRunner.new(@options) + @server_thread = Thread.new(@runner) { |runner| runner.run } + Thread.pass until @runner.running? end after(:all) do - Protobuf::Rpc::SocketRunner.stop + @runner.stop @server_thread.join end @@ -56,3 +56,4 @@ error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i end end + diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index ef02c16c..302e3eda 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -5,19 +5,21 @@ before(:all) do load "protobuf/zmq.rb" Thread.abort_on_exception = true - server = OpenStruct.new(:host => "127.0.0.1", - :port => 9399, - :worker_port => 9400, - :backlog => 100, - :threshold => 100, - :threads => 5) + options = OpenStruct.new(:host => "127.0.0.1", + :port => 9399, + :worker_port => 9400, + :backlog => 100, + :threshold => 100, + :threads => 5) - @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) } - Thread.pass until Protobuf::Rpc::Zmq::Server.running? + @runner = ::Protobuf::Rpc::ZmqRunner.new(options) + @server_thread = Thread.new(@runner) { |runner| runner.run } + + Thread.pass until @runner.running? end after(:all) do - ::Protobuf::Rpc::Zmq::Server.stop + @runner.stop @server_thread.try(:join) end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 2bfef524..0de5e5ed 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -7,10 +7,14 @@ File.expand_path('../../../support/test_app_file.rb', __FILE__) end - before do - ::Protobuf::Rpc::SocketRunner.stub(:run) - ::Protobuf::Rpc::ZmqRunner.stub(:run) - ::Protobuf::Rpc::EventedRunner.stub(:run) + let(:sock_runner) { double "SocketRunner", run: nil, register_signals: nil } + let(:zmq_runner) { double "ZmqRunner", run: nil, register_signals: nil } + let(:evented_runner) { double "EventedRunner", run: nil, register_signals: nil } + + before(:each) do + ::Protobuf::Rpc::SocketRunner.stub(:new) { sock_runner } + ::Protobuf::Rpc::ZmqRunner.stub(:new) { zmq_runner } + ::Protobuf::Rpc::EventedRunner.stub(:new) { evented_runner } end describe '#start' do @@ -22,9 +26,9 @@ let(:test_args) { [ '--host=123.123.123.123' ] } it 'sends the host option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| options[:host].should eq '123.123.123.123' - end + end.and_return(sock_runner) described_class.start(args) end end @@ -33,9 +37,9 @@ let(:test_args) { [ '--port=12345' ] } it 'sends the port option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| options[:port].should eq 12345 - end + end.and_return(sock_runner) described_class.start(args) end end @@ -44,9 +48,9 @@ let(:test_args) { [ '--threads=500' ] } it 'sends the threads option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| options[:threads].should eq 500 - end + end.and_return(sock_runner) described_class.start(args) end end @@ -55,9 +59,9 @@ let(:test_args) { [ '--backlog=500' ] } it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| options[:backlog].should eq 500 - end + end.and_return(sock_runner) described_class.start(args) end end @@ -66,9 +70,9 @@ let(:test_args) { [ '--threshold=500' ] } it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options| + ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| options[:threshold].should eq 500 - end + end.and_return(sock_runner) described_class.start(args) end end @@ -156,18 +160,18 @@ let(:runner) { ::Protobuf::Rpc::SocketRunner } before do - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:new) end it 'is activated by the --socket switch' do - runner.should_receive(:run) + runner.should_receive(:new) described_class.start(args) end it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do ENV['PB_SERVER_TYPE'] = "Socket" - runner.should_receive(:run) + runner.should_receive(:new).and_return(sock_runner) described_class.start(args) ENV.delete('PB_SERVER_TYPE') end @@ -183,18 +187,18 @@ let(:runner) { ::Protobuf::Rpc::EventedRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run) + ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + ::Protobuf::Rpc::ZmqRunner.should_not_receive(:new) end it 'is activated by the --evented switch' do - runner.should_receive(:run) + runner.should_receive(:new).and_return(evented_runner) described_class.start(args) end it 'is activated by PB_SERVER_TYPE=Evented ENV variable' do ENV['PB_SERVER_TYPE'] = "Evented" - runner.should_receive(:run) + runner.should_receive(:new).and_return(evented_runner) described_class.start(args) ENV.delete('PB_SERVER_TYPE') end @@ -204,29 +208,29 @@ ::Protobuf.connector_type.should == :evented end end - + context 'zmq workers only' do let(:test_args) { [ '--workers_only', '--zmq' ] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) end it 'is activated by the --workers_only switch' do - runner.should_receive(:run) do |options| + runner.should_receive(:new) do |options| options[:workers_only].should be_true - end + end.and_return(zmq_runner) described_class.start(args) end it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do ENV['PB_WORKERS_ONLY'] = "1" - runner.should_receive(:run) do |options| + runner.should_receive(:new) do |options| options[:workers_only].should be_true - end + end.and_return(zmq_runner) described_class.start(args) ENV.delete('PB_WORKERS_ONLY') @@ -238,14 +242,14 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) end it 'is activated by the --worker_port switch' do - runner.should_receive(:run) do |options| + runner.should_receive(:new) do |options| options[:worker_port].should eq(1234) - end + end.and_return(zmq_runner) described_class.start(args) end @@ -256,18 +260,18 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:run) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:run) + ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) end it 'is activated by the --zmq switch' do - runner.should_receive(:run) + runner.should_receive(:new) described_class.start(args) end it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do ENV['PB_SERVER_TYPE'] = "Zmq" - runner.should_receive(:run) + runner.should_receive(:new) described_class.start(args) ENV.delete('PB_SERVER_TYPE') end diff --git a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb index 9ed8b546..558044ce 100644 --- a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb @@ -12,7 +12,8 @@ it "Runner provides a stop method" do runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner").constantize - runner_class.respond_to?(:stop).should be_true + runner = runner_class.new({}) + runner.respond_to?(:stop).should be_true end end diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 7f7e1d5e..a0be83b7 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -12,23 +12,24 @@ before(:all) do load 'protobuf/socket.rb' Thread.abort_on_exception = true - server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) - @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) } - Thread.pass until Protobuf::Rpc::Socket::Server.running? + @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) + @runner = ::Protobuf::Rpc::SocketRunner.new(@options) + @server = @runner.instance_variable_get(:@server) + @server_thread = Thread.new(@runner) { |runner| runner.run } + Thread.pass until @server.running? end after(:all) do - Protobuf::Rpc::SocketRunner.stop + @server.stop @server_thread.join end it "Runner provides a stop method" do - runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner").constantize - runner_class.respond_to?(:stop).should be_true + @runner.respond_to?(:stop).should be_true end it "provides a stop method" do - described_class.respond_to?(:stop).should be_true + @runner.respond_to?(:stop).should be_true end it "provides a Runner class" do @@ -37,7 +38,7 @@ end it "signals the Server is running" do - described_class.running?.should be_true + @server.running?.should be_true end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 33937a30..bf93393a 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -2,19 +2,22 @@ require 'protobuf/rpc/servers/zmq/server' describe Protobuf::Rpc::Zmq::Server do - before(:each) do + subject { described_class.new({}) } + + before(:each) do load 'protobuf/zmq.rb' end describe '.running?' do + it 'returns true if running' do - described_class.instance_variable_set(:@running, true) - described_class.running?.should be_true + subject.instance_variable_set(:@running, true) + subject.running?.should be_true end it 'returns false if not running' do - described_class.instance_variable_set(:@running, false) - described_class.running?.should be_false + subject.instance_variable_set(:@running, false) + subject.running?.should be_false end end @@ -22,20 +25,20 @@ # keep threads instance variable from retaining any thread mocks we've # created (breaks tests down the line, otherwise) after(:each) do - described_class.instance_variable_set(:@threads, []) + subject.instance_variable_set(:@threads, []) end it 'lets all threads stop' do thread_mock = double(Thread) thread_mock.should_receive(:join).and_return(thread_mock) - described_class.instance_variable_set(:@threads, [thread_mock]) - described_class.stop + subject.instance_variable_set(:@threads, [thread_mock]) + subject.stop end it 'sets running to false' do - described_class.instance_variable_set(:@threads, []) - described_class.stop - described_class.instance_variable_get(:@running).should be_false + subject.instance_variable_set(:@threads, []) + subject.stop + subject.instance_variable_get(:@running).should be_false end end end diff --git a/spec/support/server.rb b/spec/support/server.rb index d961a0c9..6095a311 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -71,14 +71,17 @@ def start_em_server end def start_socket_server - @sock_server = Thread.new(@options) { |opt| Protobuf::Rpc::SocketRunner.run(opt) } - @sock_server.abort_on_exception = true # Set for testing purposes - Thread.pass until Protobuf::Rpc::Socket::Server.running? + @sock_runner = ::Protobuf::Rpc::SocketRunner.new(opt) + @sock_thread = Thread.new(@sock_runner) { |runner| runner.run } + @sock_thread.abort_on_exception = true # Set for testing purposes + Thread.pass until @sock_runner.running? end def start_zmq_server - @zmq_server = Thread.new(@options) { |opt| Protobuf::Rpc::ZmqRunner.run(opt) } - Thread.pass until Protobuf::Rpc::Zmq::Server.running? + @zmq_runnger = ::Protobuf::Rpc::ZmqRunner.new(opt) + @zmq_thread = Thread.new(@zmq_runner) { |runner| runner.run } + @zmq_thread.abort_on_exception = true # Set for testing purposes + Thread.pass until @zmq_runner.running? end def stop @@ -86,11 +89,11 @@ def stop when @options.server == Protobuf::Rpc::Evented::Server then EventMachine.stop_server(@server_handle) if @server_handle when @options.server == Protobuf::Rpc::Zmq::Server then - Protobuf::Rpc::ZmqRunner.stop - @zmq_server.join if @zmq_server + @zmq_runner.stop + @zmq_thread.join if @zmq_thread else - Protobuf::Rpc::SocketRunner.stop - @sock_server.join if @sock_server + @sock_runner.stop + @sock_thread.join if @sock_thread end @running = false From 4d6db0edaf5ff178b4839bc2eb2abdd49ad69f8a Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 27 Mar 2013 09:23:57 -0600 Subject: [PATCH 0348/1191] Prevent pre-mature worker shutdown By setting @running to true after the workers are started, it is possible that the worker could check the servers running status before it has been set, causing the worker to shutdown. --- lib/protobuf/rpc/servers/zmq/server.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 30d4f6b5..095ad08d 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -20,6 +20,8 @@ def host end def run + @running = true + unless @options[:workers_only] log_debug { sign_message("initializing broker") } @broker = ::Protobuf::Rpc::Zmq::Broker.new(@options) @@ -28,12 +30,13 @@ def run local_worker_threads = @options[:threads] log_debug { sign_message("starting server workers") } + local_worker_threads.times do self.start_worker end - @running = true log_debug { sign_message("server started") } + while self.running? do if @options[:workers_only] sleep 5 From 8b159d091b9f627655860704bc17ce221ecf37b0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 27 Mar 2013 11:23:10 -0600 Subject: [PATCH 0349/1191] move running up to avoid race condition of starting multiple workers and they die before server is "running" --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 1d9ab259..b8d11ee6 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -22,11 +22,11 @@ def self.run(options = {}) local_worker_threads = options[:threads] log_debug { sign_message("starting server workers") } + @running = true local_worker_threads.times do self.start_worker end - @running = true log_debug { sign_message("server started") } while self.running? do if options[:workers_only] From 1fc3f3930a4c3ea9b6218e54b3f73ad9e7e15e5f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 27 Mar 2013 11:23:26 -0600 Subject: [PATCH 0350/1191] bump to 2.7.8 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 697dd8d2..0d1db0cf 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.7' + VERSION = '2.7.8' PROTOC_VERSION = '2.4.1' end From 4003d1fddcb45c1a88175e2400d8441d06a17f37 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Apr 2013 15:24:31 -0600 Subject: [PATCH 0351/1191] add specs for binary encoding in strings and checking utf-8 keeps chars --- lib/protobuf/field/string_field.rb | 2 +- spec/lib/protobuf/message_spec.rb | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 1ff359ac..01630d11 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -12,7 +12,7 @@ def decode(bytes) def encode(value) # TODO: make replace character configurable? - value.encode!(::Protobuf::Field::StringField::ENCODING, ::Protobuf::Field::BytesField::BYTES_ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value.size) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index d72a2d41..39698898 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -44,11 +44,24 @@ expect { message.serialize_to_string }.to_not raise_error end - it "trims unicode characters from string fields" do - message = ::Test::Resource.new(:name => "my name\xc3") + it "keeps utf-8 when utf-8 is input for string fields" do + name = "my name\xC3" + name.force_encoding("UTF-8") + + message = ::Test::Resource.new(:name => name) + new_message = ::Test::Resource.new + new_message.parse_from_string(message.serialize_to_string) + (new_message.name == name).should be_true + end + + it "trims binary when binary is input for string fields" do + name = "my name\xC3" + name.force_encoding("ASCII-8BIT") + + message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.new new_message.parse_from_string(message.serialize_to_string) - new_message.name.should eq("my name") + (new_message.name == "my name").should be_true end end From 9b7b1be910e2f2d63a593e23f9c2dfff03dbaa66 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Apr 2013 15:31:01 -0600 Subject: [PATCH 0352/1191] bump to 2.7.9 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 0d1db0cf..1fd1f83f 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.8' + VERSION = '2.7.9' PROTOC_VERSION = '2.4.1' end From d18d60087dd651e5a32c572e7821a9c582fe7e68 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 16 Apr 2013 13:19:09 -0600 Subject: [PATCH 0353/1191] Add back in ResourceService implementation for spec --- spec/support/test/resource_service.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/support/test/resource_service.rb diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb new file mode 100644 index 00000000..f1dab010 --- /dev/null +++ b/spec/support/test/resource_service.rb @@ -0,0 +1,14 @@ +require ::File.expand_path('../resource.pb', __FILE__) + +module Test + class ResourceService + + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find + response.name = request.name + response.status = request.active ? 1 : 0 + end + + end +end From 2bdbdc2450f09e7ba13db4d6ac83820ebd1eaf66 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 16 Apr 2013 13:34:28 -0600 Subject: [PATCH 0354/1191] Use dup instead of deep_dup --- lib/protobuf.rb | 6 ------ lib/protobuf/rpc/servers/zmq/broker.rb | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index c269b42f..3c8edc90 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -7,12 +7,6 @@ require 'active_support/inflector' require 'active_support/json' -begin # master -require 'active_support/core_ext/object/deep_dup' -rescue LoadError # 3.2.x -require 'active_support/core_ext/hash/deep_dup' -end - module Protobuf # See Protobuf#connector_type documentation. diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index e001ee23..3b005861 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -13,7 +13,7 @@ class Broker # def initialize(options = {}) @available_workers = [] - @options = options.deep_dup + @options = options.dup @expected_worker_count = @options[:threads] @context = ::ZMQ::Context.new @poller = ::ZMQ::Poller.new @@ -25,10 +25,10 @@ def initialize(options = {}) # def poll if frontend.nil? - if local_workers_have_started? + if local_workers_have_started? # only open the front end when the workers are done booting log_info { "Starting frontend socket in broker, all workers ready!" } - setup_frontend + setup_frontend end else # Start checking the poller after startup From 18b0db4c05f5397d56295e2183b60ad0998ffdda Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 16 Apr 2013 13:19:09 -0600 Subject: [PATCH 0355/1191] Add back in ResourceService implementation for spec --- spec/support/test/resource_service.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/support/test/resource_service.rb diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb new file mode 100644 index 00000000..f1dab010 --- /dev/null +++ b/spec/support/test/resource_service.rb @@ -0,0 +1,14 @@ +require ::File.expand_path('../resource.pb', __FILE__) + +module Test + class ResourceService + + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find + response.name = request.name + response.status = request.active ? 1 : 0 + end + + end +end From d19dfa351bd629ea551553dcfd3dca9df3ab69e3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 16 Apr 2013 13:49:08 -0600 Subject: [PATCH 0356/1191] Update gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9ab897a8..1a65e74b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,8 @@ Gemfile.lock tmp/* ext/defs ext/out -ext/ruby_generator/protoc-ruby \ No newline at end of file +ext/ruby_generator/protoc-ruby +.ruby-gemset +.ruby-version +ext/ruby_generator/gdb.run +ext/ruby_generator/protoc-ruby.dSYM From f2ead598f0ae0f24f5625e93444fa76b31f6ae93 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 16 Apr 2013 13:52:07 -0600 Subject: [PATCH 0357/1191] Bump version 2.7.10 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 1fd1f83f..5ab89636 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.9' + VERSION = '2.7.10' PROTOC_VERSION = '2.4.1' end From ae0e2675805e49141d7ef6dd5abd70104910ddb4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 16 Apr 2013 14:06:33 -0600 Subject: [PATCH 0358/1191] Remove multi-field definitions for specs to pass --- spec/support/test/multi_field_extensions.pb.rb | 2 -- spec/support/test/multi_field_extensions.proto | 4 ++-- spec/support/test/resource.pb.rb | 1 - spec/support/test/resource.proto | 6 +++--- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/test/multi_field_extensions.pb.rb index 7e629c57..db70f1e2 100644 --- a/spec/support/test/multi_field_extensions.pb.rb +++ b/spec/support/test/multi_field_extensions.pb.rb @@ -27,8 +27,6 @@ class Header # Extension Fields extensions 100...536870912 optional ::Test::PayloadA, :payload, 100, :extension => true - # UNCOMMENT TO TEST FAILING WITH MULTIPLE FIELDS - # optional ::Test::PayloadB, :payload, 101, :extension => true end diff --git a/spec/support/test/multi_field_extensions.proto b/spec/support/test/multi_field_extensions.proto index 90d81a4b..2a28c844 100644 --- a/spec/support/test/multi_field_extensions.proto +++ b/spec/support/test/multi_field_extensions.proto @@ -16,8 +16,8 @@ message PayloadA { } message PayloadB { - extend Header { + //extend Header { // UNCOMMENT TO TEST FAILING WITH MULTIPLE FIELDS // optional PayloadB payload = 101; - } + //} } diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index a3dd55bc..1582721f 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -57,7 +57,6 @@ class Resource optional ::Test::Searchable::SearchType, :ext_search_type, 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true optional ::Protobuf::Field::BoolField, :ext_nested_in_level_one, 105, :extension => true optional ::Protobuf::Field::BoolField, :ext_dup_field, 106, :extension => true - optional ::Protobuf::Field::BoolField, :ext_dup_field, 107, :extension => true end class MessageParent diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index 2e78f005..c7b1a420 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -62,9 +62,9 @@ message Nested { optional bool ext_nested_level_one = 100; } - extend Resource { - optional bool ext_dup_field = 107; - } +// extend Resource { +// optional bool ext_dup_field = 107; +// } } extend Nested { From ad7a3e1e38bb10993c6db0e8b361bc7d295e3395 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 23 May 2013 13:45:29 -0600 Subject: [PATCH 0359/1191] Cleanup --- lib/protobuf/cli.rb | 2 -- lib/protobuf/rpc/servers/evented_runner.rb | 4 --- lib/protobuf/rpc/servers/socket_runner.rb | 4 --- lib/protobuf/rpc/servers/zmq/broker.rb | 35 +++++++--------------- lib/protobuf/rpc/servers/zmq/worker.rb | 13 ++++---- lib/protobuf/rpc/servers/zmq_runner.rb | 19 +++++++----- 6 files changed, 28 insertions(+), 49 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 791d27ff..59582d32 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -214,8 +214,6 @@ def server_zmq! # Start the runner and log the relevant options. def start_server! - @runner.register_signals - debug_say 'Invoking server start' @runner.run do diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb index f932f92f..38acade0 100644 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ b/lib/protobuf/rpc/servers/evented_runner.rb @@ -6,10 +6,6 @@ def initialize(options) @options = options end - def register_signals - # Noop - end - def run # Startup and run the rpc server ::EventMachine.schedule do diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 9b376961..bd70aad2 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -17,10 +17,6 @@ def initialize(options) @server = ::Protobuf::Rpc::Socket::Server.new(@options) end - def register_signals - # noop - end - def run yield if block_given? @server.run diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 3b005861..b4bf1e16 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -85,38 +85,23 @@ def local_workers_have_started? end def move_to_backend(socket) - message_array = [] - zmq_error_check(socket.recv_strings(message_array)) - - backend_message_set = [ - available_workers.shift, # Worker UUID for router - "", - message_array[0], # Client UUID for return value - "", - message_array[2] # Client Message payload (request) - ] - - zmq_error_check(backend.send_strings(backend_message_set)) + # frames = [CLIENT_ID, "", REQUEST_DATA] + + zmq_error_check(socket.recv_strings(frames = [])) + frames = [available_workers.shift, ""] + frames + zmq_error_check(backend.send_strings(frames)) end def move_to_frontend(socket) - message_array = [] - zmq_error_check(socket.recv_strings(message_array)) + # frames = [WORKER_ID, "", READY_MESSAGE | (CLIENT_ID, "", RESPONSE_DATA)] - # Push UUID of socket on the available workers queue - available_workers << message_array[0] + zmq_error_check(socket.recv_strings(frames = [])) + available_workers << frames.shift(2)[0] - # messages should be [ "uuid of socket", "", "READY_MESSAGE || uuid of client socket"] - if message_array[2] == ::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE + if frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] log_info { "Worker #{available_workers.size} of #{expected_worker_count} ready!" } else - frontend_message_set = [ - message_array[2], # client UUID - "", - message_array[4] # Reply payload - ] - - zmq_error_check(frontend.send_strings(frontend_message_set)) + zmq_error_check(frontend.send_strings(frames)) end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index f2b50eb8..8ad18b18 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -31,12 +31,14 @@ def initialize(server) # Instance Methods # def handle_request(socket) - message_array = [] - zmq_error_check(socket.recv_strings(message_array)) + zmq_error_check(socket.recv_strings(frames = [])) - @request_data = message_array[2] - @client_address = message_array[0] - log_debug { sign_message("handling request") } unless @request_data.nil? + @client_address, empty, @request_data = *frames + + unless @request_data.nil? + log_debug { sign_message("handling request") } + handle_client + end end def run @@ -47,7 +49,6 @@ def run @poller.readables.each do |socket| initialize_request! handle_request(socket) - handle_client unless @request_data.nil? end end ensure diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index b3d63cb5..f1219d9e 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -16,15 +16,8 @@ def initialize(options) @server = ::Protobuf::Rpc::Zmq::Server.new(@options) end - def register_signals - trap(:TTIN) do - log_info { "TTIN received: Starting new worker" } - @server.start_worker - log_info { "Worker count : #{::Protobuf::Rpc::Zmq::Server.threads.size}" } - end - end - def run + register_signals yield if block_given? @server.run end @@ -36,6 +29,16 @@ def running? def stop @server.stop end + + private + + def register_signals + trap(:TTIN) do + log_info { "TTIN received: Starting new worker" } + @server.start_worker + log_info { "Worker count : #{::Protobuf::Rpc::Zmq::Server.threads.size}" } + end + end end end end From 0097af1d1dfe5da6640a8690f23fb96932652260 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 24 May 2013 13:57:25 -0600 Subject: [PATCH 0360/1191] Add dynamic discovery option for ZMQ server --- lib/protobuf/cli.rb | 34 +-- lib/protobuf/rpc/servers/zmq/broker.rb | 114 -------- lib/protobuf/rpc/servers/zmq/server.rb | 245 +++++++++++++++--- lib/protobuf/rpc/servers/zmq/util.rb | 3 +- lib/protobuf/rpc/servers/zmq/worker.rb | 43 +-- proto/dynamic_discovery.proto | 40 +++ .../protobuf/rpc/servers/zmq/broker_spec.rb | 31 --- .../protobuf/rpc/servers/zmq/server_spec.rb | 38 ++- 8 files changed, 317 insertions(+), 231 deletions(-) delete mode 100644 lib/protobuf/rpc/servers/zmq/broker.rb create mode 100644 proto/dynamic_discovery.proto delete mode 100644 spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 59582d32..809b0ffe 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -29,6 +29,7 @@ class CLI < ::Thor option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' + option :dynamic_discovery, :type => :boolean, :default => false, :aliases => %w(-y), :desc => 'Enable dynamic discovery (Currently only available with ZeroMQ).' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' @@ -101,25 +102,26 @@ def configure_process_name(app_file) # Configure the mode of the server and the runner class. def configure_server_mode debug_say 'Configuring runner mode' - if options.zmq? && ! options.evented? && ! options.socket? + + if multi_mode? + say 'WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow + server_socket! + elsif options.zmq? server_zmq! - elsif options.evented? && ! options.zmq? && ! options.socket? + elsif options.evented? server_evented! - elsif (env_server_type = ENV["PB_SERVER_TYPE"]) - case - when env_server_type =~ /zmq/i then - server_zmq! - when env_server_type =~ /socket/i then + else + case server_type = ENV["PB_SERVER_TYPE"] + when nil, /socket/i server_socket! - when env_server_type =~ /evented/i then + when /zmq/i + server_zmq! + when /evented/i server_evented! else - say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{env_server_type}'. Defaulting to socket mode.", :yellow + say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow server_socket! end - else - say 'WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow if multi_mode? - server_socket! end end @@ -145,9 +147,11 @@ def debug_say(message, color = :yellow) # Internal helper to determine if the modes are multi-set which is not valid. def multi_mode? - (options.zmq? && (options.evented? || options.socket?)) \ - && (options.evented? && (options.evented? || options.socket?)) \ - && (options.zmq? && (options.evented? || options.socket?)) \ + [ + options.zmq?, + options.evented?, + options.socket?, + ].count(true) > 1 end # Require the application file given, exiting if the file doesn't exist. diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb deleted file mode 100644 index b4bf1e16..00000000 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ /dev/null @@ -1,114 +0,0 @@ -require 'resolv' -require 'protobuf/rpc/servers/zmq/util' - -module Protobuf - module Rpc - module Zmq - class Broker - include ::Protobuf::Rpc::Zmq::Util - attr_reader :frontend, :backend, :poller, :context, :available_workers, :options, :expected_worker_count - - ## - # Constructor - # - def initialize(options = {}) - @available_workers = [] - @options = options.dup - @expected_worker_count = @options[:threads] - @context = ::ZMQ::Context.new - @poller = ::ZMQ::Poller.new - setup_backend - end - - ## - # Instance Methods - # - def poll - if frontend.nil? - if local_workers_have_started? - # only open the front end when the workers are done booting - log_info { "Starting frontend socket in broker, all workers ready!" } - setup_frontend - end - else - # Start checking the poller after startup - if available_workers.size > 0 - poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2 - else - poller.delete(frontend) - end - end - - poller.poll(1000) - poller.readables.each do |socket| - case socket - when backend then - move_to_frontend(socket) - when frontend then - move_to_backend(socket) - end - end - end - - def setup_backend - host = options[:host] - port = options[:worker_port] - - zmq_backend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_backend.bind(bind_address(host, port))) - - @backend = zmq_backend - @poller.register(@backend, ::ZMQ::POLLIN) - end - - def setup_frontend - host = options[:host] - port = options[:port] - - zmq_frontend = context.socket(::ZMQ::ROUTER) - zmq_error_check(zmq_frontend.bind(bind_address(host, port))) - - @frontend = zmq_frontend - @poller.register(@frontend, ::ZMQ::POLLIN) - end - - def teardown - frontend.try(:close) - backend.try(:close) - context.try(:terminate) - end - - private - - def local_workers_have_started? - @local_workers_have_started ||= available_workers.size >= expected_worker_count - end - - def move_to_backend(socket) - # frames = [CLIENT_ID, "", REQUEST_DATA] - - zmq_error_check(socket.recv_strings(frames = [])) - frames = [available_workers.shift, ""] + frames - zmq_error_check(backend.send_strings(frames)) - end - - def move_to_frontend(socket) - # frames = [WORKER_ID, "", READY_MESSAGE | (CLIENT_ID, "", RESPONSE_DATA)] - - zmq_error_check(socket.recv_strings(frames = [])) - available_workers << frames.shift(2)[0] - - if frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] - log_info { "Worker #{available_workers.size} of #{expected_worker_count} ready!" } - else - zmq_error_check(frontend.send_strings(frames)) - end - end - - def bind_address(host, port) - "tcp://#{resolve_ip(host)}:#{port}" - end - end - end - end -end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 5fbf0e63..c410e90c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -1,4 +1,3 @@ -require 'protobuf/rpc/servers/zmq/broker' require 'protobuf/rpc/servers/zmq/worker' require 'protobuf/rpc/servers/zmq/util' @@ -8,74 +7,248 @@ module Zmq class Server include ::Protobuf::Rpc::Zmq::Util - attr_accessor :threads, :options + attr_accessor :options, :workers, :zmq_context def initialize(options) - @options = options - @threads = [] + @options = default_options.merge(options) + @workers = [] + + init_zmq_context + init_backend_socket + init_frontend_socket unless brokerless? + init_shutdown_socket + init_beacon_socket if broadcast_beacons? end - def host - @options[:host] + def alive_workers + @workers.count { |worker| worker.alive? } end - def run - unless @options[:workers_only] - log_debug { sign_message("initializing broker") } - @broker = ::Protobuf::Rpc::Zmq::Broker.new(@options) + def backend_ip + frontend_ip + end + + def backend_port + options[:worker_port] + end + + def backend_uri + "tcp://#{backend_ip}:#{backend_port}" + end + + def beacon_interval + [options[:beacon_interval].to_i, 1].max + end + + def beacon_ip + "255.255.255.255" + end + + def beacon_port + options[:beacon_port].to_i + end + + def broadcast_beacons? + !brokerless? && options[:dynamic_discovery] + end + + def broadcast_flatline + # TODO: create a flatline beacon from the proto + flatline = "flatline" + + @beacon_socket.send flatline, 0 + end + + def broadcast_heartbeat + # TODO: create a heartbeat beacon from the proto + heartbeat = "heartbeat" + + @beacon_socket.send heartbeat, 0 + end + + def brokerless? + !!options[:workers_only] + end + + def frontend_ip + @frontend_ip ||= resolve_ip(options[:host]) + end + + def frontend_port + options[:port] + end + + def frontend_uri + "tcp://#{frontend_ip}:#{frontend_port}" + end + + def maintenance_interval + [reaping_interval, beacon_interval].min + end + + def minimum_timeout + 100 + end + + def reap_dead_workers + @workers.keep_if do |worker| + worker.alive? end + end - local_worker_threads = @options[:threads] - log_debug { sign_message("starting server workers") } + def reaping_interval + 5 + end + def run @running = true - local_worker_threads.times do - self.start_worker - end + start_missing_workers - log_debug { sign_message("server started") } + brokerless? ? wait_for_shutdown_signal : run_broker - while self.running? do - if @options[:workers_only] - sleep 5 - Thread.pass - else - @broker.poll - end + @workers.each do |t| + t.join(5) || t.kill end - ensure - @broker.teardown if @broker + + teardown end def running? !!@running end + def run_broker + log_debug { sign_message("initializing broker") } + + timeout = 0 + next_beacon = 0 + next_reaping = 0 + next_cycle = Time.now.to_i + maintenance_interval + poller = ZMQ::Poller.new + available_workers = [] + + poller.register_readable @frontend_socket + poller.register_readable @backend_socket + poller.register_readable @shutdown_socket + + while running? || @workers.any? + poller.poll(timeout) + poller.readables.each do |readable| + if readable === @frontend_socket && available_workers.any? + @frontend_socket.recv_strings frames = [] + @backend_socket.send_strings [available_workers.shift, ""] + frames + elsif readable === @backend_socket + @backend_socket.recv_strings frames = [] + available_workers << frames.shift(2)[0] + unless frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] + @frontend_socket.send_strings frames + end + elsif readable === @shutdown_socket + broadcast_flatline if broadcast_beacons? + poller.deregister_readable @frontend_socket + end + end + + if (time = Time.now.to_i) >= next_reaping + reap_dead_workers + start_missing_workers if running? + next_reaping = time + reaping_interval + next_cycle = [next_cycle, next_reaping].min + end + + if broadcast_beacons? && time >= next_beacon + running? ? broadcast_heartbeat : broadcast_flatline + next_beacon = time + beacon_interval + next_cycle = [next_cycle, next_beacon].min + end + + timeout = [minimum_timeout, 1_000 * (next_cycle - time)].max + end + end + + def signal_shutdown + @running = false + socket = zmq_context.socket ZMQ::PAIR + zmq_error_check(socket.connect shutdown_uri) + zmq_error_check(socket.send_string "shutdown") + zmq_error_check(socket.close) + end + + def start_missing_workers + missing_workers = total_workers - @workers.size + + if missing_workers > 0 + missing_workers.times { start_worker } + log_debug { sign_message("#{total_workers} workers started") } + end + end + def start_worker - @threads << Thread.new(self) { |server| + @workers << Thread.new(self) do |server| begin ::Protobuf::Rpc::Zmq::Worker.new(server).run rescue => e - message = "Worker Failed, spawning new worker: #{e.inspect}\n #{e.backtrace.join($/)}" + message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" $stderr.puts message log_error { message } - - retry if self.running? end - } + end + end + + def shutdown_uri + "inproc://#{object_id}" end def stop - @running = false + signal_shutdown + end - @threads.each do |t| - t.join(5) || t.kill - end + def teardown + @frontend_socket.try :close + @backend_socket.try :close + @shutdown_socket.try :close + @beacon_socket.try :close + @zmq_context.terminate + end + + def total_workers + @total_workers ||= @options[:threads] + end + + def wait_for_shutdown_signal + @shutdown_socket.recv_string shutdown = "" + end + + private + + def default_options + { :beacon_interval => 5 } + end + + def init_backend_socket + @backend_socket = @zmq_context.socket ZMQ::ROUTER + zmq_error_check(@backend_socket.bind backend_uri) + end + + def init_beacon_socket + @beacon_socket = UDPSocket.new + @beacon_socket.setsockopt Socket::SOL_SOCKET, Socket::SO_BROADCAST, true + @beacon_socket.connect beacon_ip, beacon_port + end + + def init_frontend_socket + @frontend_socket = @zmq_context.socket ZMQ::ROUTER + zmq_error_check(@frontend_socket.bind frontend_uri) + end + + def init_shutdown_socket + @shutdown_socket = @zmq_context.socket ZMQ::PAIR + @shutdown_socket.bind shutdown_uri end - def worker_port - @options[:worker_port] + def init_zmq_context + @zmq_context = ZMQ::Context.new end end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index d8ff4508..0eba01f7 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -6,6 +6,7 @@ module Zmq module Util include ::Protobuf::Logger::LogMethods + def self.included(base) base.extend(::Protobuf::Rpc::Zmq::Util) end @@ -21,9 +22,7 @@ def log_signature def resolve_ip(hostname) ::Resolv.getaddress(hostname) end - end - end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 8ad18b18..c0eb7a42 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -1,9 +1,9 @@ require 'protobuf/rpc/server' require 'protobuf/rpc/servers/zmq/util' + module Protobuf module Rpc module Zmq - class Worker include ::Protobuf::Rpc::Server include ::Protobuf::Rpc::Zmq::Util @@ -13,18 +13,8 @@ class Worker # def initialize(server) @server = server - host = server.host - port = server.worker_port - - @zmq_context = ::ZMQ::Context.new - @socket = @zmq_context.socket(::ZMQ::REQ) - zmq_error_check(@socket.connect("tcp://#{resolve_ip(host)}:#{port}")) - - @poller = ::ZMQ::Poller.new - @poller.register(@socket, ::ZMQ::POLLIN) - - # Send request to broker telling it we are ready - zmq_error_check(@socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) + init_zmq_context + init_socket end ## @@ -42,11 +32,16 @@ def handle_request(socket) end def run - while @server.running? do - # poll for 1_000 milliseconds then continue looping - # This lets us see whether we need to die - @poller.poll(1_000) - @poller.readables.each do |socket| + poller = ::ZMQ::Poller.new + poller.register(@socket, ::ZMQ::POLLIN) + + # Send request to broker telling it we are ready + zmq_error_check(@socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) + + # poll for 1 second then continue looping + # This lets us see whether we need to die + while @server.running? && poller.poll(1_000) >= 0 + poller.readables.each do |socket| initialize_request! handle_request(socket) end @@ -68,8 +63,18 @@ def send_data @stats.response_size = response_data.size zmq_error_check(@socket.send_strings(response_message_set)) end - end + private + + def init_zmq_context + @zmq_context = ZMQ::Context.new + end + + def init_socket + @socket = @zmq_context.socket ZMQ::REQ + zmq_error_check(@socket.connect @server.backend_uri) + end + end end end end diff --git a/proto/dynamic_discovery.proto b/proto/dynamic_discovery.proto new file mode 100644 index 00000000..81eb0fee --- /dev/null +++ b/proto/dynamic_discovery.proto @@ -0,0 +1,40 @@ +// Copyright (c) 2013 MoneyDesktop, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Authors: Devin Christensen +// +// Protobufs needed for dynamic discovery zmq server and client. + +package protobuf.dynamic_discovery; + +enum BeaconType { + HEARTBEAT = 1; + FLATLINE = 2; +} + +message Beacon { + optional BeaconType beacon_type = 1; + optional string uuid = 2; + optional string hostname = 3; + optional string port = 4; + optional int32 ttl = 5; + repeated string service_classes = 5; +} + diff --git a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb deleted file mode 100644 index 6aef8433..00000000 --- a/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'spec_helper' - -describe ::Protobuf::Rpc::Zmq::Broker do - before(:each) do - load 'protobuf/zmq.rb' - end - - after(:each) do - subject.teardown - end - - subject do - described_class.new({ :host => '127.0.0.1', :port => 9399, :worker_port => 9400 }) - end - - it 'sets up a context' do - subject.context.should be_a(::ZMQ::Context) - end - - it 'sets up a backend socket' do - subject.backend.should be_a(::ZMQ::Socket) - end - - it 'sets up a polling object' do - subject.poller.should be_a(::ZMQ::Poller) - end - - describe '#poll' do - # no unit tests for this method - end -end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index bf93393a..51db32d7 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -2,14 +2,32 @@ require 'protobuf/rpc/servers/zmq/server' describe Protobuf::Rpc::Zmq::Server do - subject { described_class.new({}) } + subject { described_class.new(options) } - before(:each) do + let(:options) {{ + :host => '127.0.0.1', + :port => 9399, + :worker_port => 9400, + :workers_only => true + }} + + before do load 'protobuf/zmq.rb' end - describe '.running?' do + after do + subject.teardown + end + + it 'sets up a ZMQ context' do + subject.instance_variable_get(:@zmq_context).should be_a(::ZMQ::Context) + end + it 'sets up a backend socket' do + subject.instance_variable_get(:@backend_socket).should be_a(::ZMQ::Socket) + end + + describe '.running?' do it 'returns true if running' do subject.instance_variable_set(:@running, true) subject.running?.should be_true @@ -22,21 +40,13 @@ end describe '.stop' do - # keep threads instance variable from retaining any thread mocks we've - # created (breaks tests down the line, otherwise) - after(:each) do - subject.instance_variable_set(:@threads, []) - end - - it 'lets all threads stop' do - thread_mock = double(Thread) - thread_mock.should_receive(:join).and_return(thread_mock) - subject.instance_variable_set(:@threads, [thread_mock]) + it 'signals shutdown' do + subject.should_receive(:signal_shutdown) subject.stop end it 'sets running to false' do - subject.instance_variable_set(:@threads, []) + subject.instance_variable_set(:@workers, []) subject.stop subject.instance_variable_get(:@running).should be_false end From 496d96ce37058635abc1830d5f1abc11e9053d3a Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 24 May 2013 16:21:32 -0600 Subject: [PATCH 0361/1191] Improve JRuby compatability and cleanup CLI --- lib/protobuf/cli.rb | 40 +++++++++++-------- lib/protobuf/rpc/servers/socket/server.rb | 4 +- spec/lib/protobuf/cli_spec.rb | 14 ++++--- spec/lib/protobuf/enum_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 6 +-- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 809b0ffe..391be744 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -7,9 +7,7 @@ module Protobuf class CLI < ::Thor - include ::Thor::Actions - - attr_accessor :runner, :mode, :start_aborted + attr_accessor :runner, :mode default_task :start @@ -38,7 +36,6 @@ class CLI < ::Thor def start(app_file) debug_say 'Configuring the rpc_server process' - @start_aborted = false configure_logger configure_traps @@ -47,9 +44,9 @@ def start(app_file) configure_gc configure_deprecation_warnings - run_if_no_abort { require_application!(app_file) } - run_if_no_abort { configure_process_name(app_file) } - run_if_no_abort { start_server! } + require_application!(app_file) unless exit_requested? + configure_process_name(app_file) unless exit_requested? + start_server! unless exit_requested? rescue => e say_and_exit!('ERROR: RPC Server failed to start.', e) end @@ -129,13 +126,16 @@ def configure_server_mode # TODO add signal handling for hot-reloading the application. def configure_traps debug_say 'Configuring traps' - [:INT, :QUIT, :TERM].each do |signal| - debug_say "Registering signal trap for #{signal}", :blue + + exit_signals = [:INT, :TERM] + exit_signals << :QUIT unless defined?(JRUBY_VERSION) + + exit_signals.each do |signal| + debug_say "Registering trap for exit signal #{signal}", :blue + trap(signal) do - ::Protobuf::Logger.info { 'RPC Server shutting down...' } - @start_aborted = true - @runner.stop - ::Protobuf::Logger.info { 'Shutdown complete' } + @exit_requested = true + shutdown_server end end end @@ -145,6 +145,10 @@ def debug_say(message, color = :yellow) say(message, color) if options.debug? end + def exit_requested? + !!@exit_requested + end + # Internal helper to determine if the modes are multi-set which is not valid. def multi_mode? [ @@ -170,10 +174,6 @@ def require_protobuf! say_and_exit!("Failed to load protobuf runner #{@mode}", e) end - def run_if_no_abort - yield unless @start_aborted - end - def runner_options { :host => options.host, @@ -216,6 +216,12 @@ def server_zmq! @runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) end + def shutdown_server! + ::Protobuf::Logger.info { 'RPC Server shutting down...' } + @runner.try :stop + ::Protobuf::Logger.info { 'Shutdown complete' } + end + # Start the runner and log the relevant options. def start_server! debug_say 'Invoking server start' diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index ed9ae980..b837a815 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -101,12 +101,12 @@ def run end def running? - @running + !!@running end def stop @running = false - @server.close if @server + @server.try :close end end end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 0de5e5ed..dd6d404d 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -96,16 +96,18 @@ it 'sets both request and serialization pausing to false' do described_class.start(args) - ::Protobuf.gc_pause_server_request?.should be_false + ::Protobuf.should_not be_gc_pause_server_request end end - context 'request pausing' do - let(:test_args) { [ '--gc_pause_request' ] } + unless defined?(JRUBY_VERSION) + context 'request pausing' do + let(:test_args) { [ '--gc_pause_request' ] } - it 'sets the configuration option to GC pause server request' do - described_class.start(args) - ::Protobuf.gc_pause_server_request?.should be_true + it 'sets the configuration option to GC pause server request' do + described_class.start(args) + ::Protobuf.should be_gc_pause_server_request + end end end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index daa16dc0..afacc4ee 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -6,7 +6,7 @@ before(:all) do Test::EnumTestType.define(:MINUS_ONE, -1) - Test::EnumTestType.define(name, tag) + Test::EnumTestType.define(:THREE, 3) end describe '.define' do diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index a0be83b7..84de8c13 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -25,11 +25,11 @@ end it "Runner provides a stop method" do - @runner.respond_to?(:stop).should be_true + @runner.should respond_to(:stop) end it "provides a stop method" do - @runner.respond_to?(:stop).should be_true + @server.should respond_to(:stop) end it "provides a Runner class" do @@ -38,7 +38,7 @@ end it "signals the Server is running" do - @server.running?.should be_true + @server.should be_running end end From e4950c868fdb2cea08faa288d5e6cb2ee53ca71f Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 24 May 2013 18:03:33 -0600 Subject: [PATCH 0362/1191] Integrate the beacon proto into the zmq server --- lib/protobuf/rpc/dynamic_discovery.pb.rb | 40 ++++++++++++++++++++ lib/protobuf/rpc/rpc.pb.rb | 25 +++++++------ lib/protobuf/rpc/servers/zmq/server.rb | 47 ++++++++++++++++-------- lib/protobuf/rpc/servers/zmq/util.rb | 2 + proto/dynamic_discovery.proto | 10 ++--- spec/functional/zmq_server_spec.rb | 34 +++++++++-------- 6 files changed, 110 insertions(+), 48 deletions(-) create mode 100644 lib/protobuf/rpc/dynamic_discovery.pb.rb diff --git a/lib/protobuf/rpc/dynamic_discovery.pb.rb b/lib/protobuf/rpc/dynamic_discovery.pb.rb new file mode 100644 index 00000000..056ec020 --- /dev/null +++ b/lib/protobuf/rpc/dynamic_discovery.pb.rb @@ -0,0 +1,40 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Protobuf + + module DynamicDiscovery + + ## + # Enum Classes + # + class BeaconType < ::Protobuf::Enum + define :HEARTBEAT, 0 + define :FLATLINE, 1 + end + + + ## + # Message Classes + # + class Beacon < ::Protobuf::Message; end + + ## + # Message Fields + # + class Beacon + optional ::Protobuf::DynamicDiscovery::BeaconType, :beacon_type, 1 + optional ::Protobuf::Field::StringField, :uuid, 2 + optional ::Protobuf::Field::StringField, :address, 3 + optional ::Protobuf::Field::StringField, :port, 4 + optional ::Protobuf::Field::Int32Field, :ttl, 5 + repeated ::Protobuf::Field::StringField, :service_classes, 6 + end + + + end + +end + diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index d7b12fca..fc3d69bb 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -4,22 +4,13 @@ require 'protobuf/message' module Protobuf + module Socketrpc + ## # Enum Classes # - class ErrorReason < ::Protobuf::Enum; end - - ## - # Message Classes - # - class Request < ::Protobuf::Message; end - class Response < ::Protobuf::Message; end - - ## - # Enum Values - # - class ErrorReason + class ErrorReason < ::Protobuf::Enum define :BAD_REQUEST_DATA, 0 define :BAD_REQUEST_PROTO, 1 define :SERVICE_NOT_FOUND, 2 @@ -32,6 +23,13 @@ class ErrorReason define :IO_ERROR, 9 end + + ## + # Message Classes + # + class Request < ::Protobuf::Message; end + class Response < ::Protobuf::Message; end + ## # Message Fields # @@ -49,5 +47,8 @@ class Response optional ::Protobuf::Socketrpc::ErrorReason, :error_reason, 4 end + end + end + diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c410e90c..d15da2c4 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -1,5 +1,7 @@ require 'protobuf/rpc/servers/zmq/worker' require 'protobuf/rpc/servers/zmq/util' +require 'protobuf/rpc/dynamic_discovery.pb' +require 'securerandom' module Protobuf module Rpc @@ -20,10 +22,6 @@ def initialize(options) init_beacon_socket if broadcast_beacons? end - def alive_workers - @workers.count { |worker| worker.alive? } - end - def backend_ip frontend_ip end @@ -53,17 +51,27 @@ def broadcast_beacons? end def broadcast_flatline - # TODO: create a flatline beacon from the proto - flatline = "flatline" + flatline = ::Protobuf::DynamicDiscovery::Beacon.new( + :beacon_type => ::Protobuf::DynamicDiscovery::BeaconType::FLATLINE, + :uuid => uuid, + :address => frontend_ip, + :port => frontend_port.to_s + ) - @beacon_socket.send flatline, 0 + @beacon_socket.send flatline.to_s, 0 end def broadcast_heartbeat - # TODO: create a heartbeat beacon from the proto - heartbeat = "heartbeat" + heartbeat = ::Protobuf::DynamicDiscovery::Beacon.new( + :beacon_type => ::Protobuf::DynamicDiscovery::BeaconType::HEARTBEAT, + :uuid => uuid, + :address => frontend_ip, + :port => frontend_port.to_s, + :ttl => beacon_interval * 3, + :service_classes => ["not sure"] # TODO: Figure out what goes here + ) - @beacon_socket.send heartbeat, 0 + @beacon_socket.send heartbeat.to_s, 0 end def brokerless? @@ -110,7 +118,7 @@ def run @workers.each do |t| t.join(5) || t.kill end - + ensure teardown end @@ -135,9 +143,11 @@ def run_broker while running? || @workers.any? poller.poll(timeout) poller.readables.each do |readable| - if readable === @frontend_socket && available_workers.any? - @frontend_socket.recv_strings frames = [] - @backend_socket.send_strings [available_workers.shift, ""] + frames + if readable === @frontend_socket + if available_workers.any? + @frontend_socket.recv_strings frames = [] + @backend_socket.send_strings [available_workers.shift, ""] + frames + end elsif readable === @backend_socket @backend_socket.recv_strings frames = [] available_workers << frames.shift(2)[0] @@ -147,6 +157,7 @@ def run_broker elsif readable === @shutdown_socket broadcast_flatline if broadcast_beacons? poller.deregister_readable @frontend_socket + poller.deregister_readable @shutdown_socket end end @@ -216,6 +227,10 @@ def total_workers @total_workers ||= @options[:threads] end + def uuid + @uuid ||= SecureRandom.uuid + end + def wait_for_shutdown_signal @shutdown_socket.recv_string shutdown = "" end @@ -223,7 +238,7 @@ def wait_for_shutdown_signal private def default_options - { :beacon_interval => 5 } + { :beacon_interval => 5 } end def init_backend_socket @@ -233,7 +248,7 @@ def init_backend_socket def init_beacon_socket @beacon_socket = UDPSocket.new - @beacon_socket.setsockopt Socket::SOL_SOCKET, Socket::SO_BROADCAST, true + @beacon_socket.setsockopt :SOCKET, :BROADCAST, true @beacon_socket.connect beacon_ip, beacon_port end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 0eba01f7..078de305 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -1,3 +1,5 @@ +require 'resolv' + module Protobuf module Rpc module Zmq diff --git a/proto/dynamic_discovery.proto b/proto/dynamic_discovery.proto index 81eb0fee..3854a105 100644 --- a/proto/dynamic_discovery.proto +++ b/proto/dynamic_discovery.proto @@ -22,19 +22,19 @@ // // Protobufs needed for dynamic discovery zmq server and client. -package protobuf.dynamic_discovery; +package protobuf.dynamicDiscovery; enum BeaconType { - HEARTBEAT = 1; - FLATLINE = 2; + HEARTBEAT = 0; + FLATLINE = 1; } message Beacon { optional BeaconType beacon_type = 1; optional string uuid = 2; - optional string hostname = 3; + optional string address = 3; optional string port = 4; optional int32 ttl = 5; - repeated string service_classes = 5; + repeated string service_classes = 6; } diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 302e3eda..752fd4b6 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -2,25 +2,29 @@ require 'spec/support/test/resource_service' describe 'Functional ZMQ Client' do - before(:all) do - load "protobuf/zmq.rb" - Thread.abort_on_exception = true - options = OpenStruct.new(:host => "127.0.0.1", - :port => 9399, - :worker_port => 9400, - :backlog => 100, - :threshold => 100, - :threads => 5) + let(:options) {{ + :host => "127.0.0.1", + :port => 9399, + :worker_port => 9400, + :backlog => 100, + :threshold => 100, + :threads => 5, + :dynamic_discovery => true, + :beacon_port => 9398 + }} - @runner = ::Protobuf::Rpc::ZmqRunner.new(options) - @server_thread = Thread.new(@runner) { |runner| runner.run } + let(:server) { ::Protobuf::Rpc::Zmq::Server.new(options) } + let(:server_thread) { Thread.new(server) { |server| server.run } } - Thread.pass until @runner.running? + before do + load "protobuf/zmq.rb" + server_thread.abort_on_exception = true + Thread.pass until server.running? end - after(:all) do - @runner.stop - @server_thread.try(:join) + after do + server.stop + server_thread.join end it 'runs fine when required fields are set' do From acaade92098d7d42c3506581f00fcc18774b1a16 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 28 May 2013 16:33:57 -0600 Subject: [PATCH 0363/1191] Separate the broker concern --- lib/protobuf/rpc/servers/zmq/broker.rb | 114 +++++++++++++ lib/protobuf/rpc/servers/zmq/server.rb | 153 +++++++----------- lib/protobuf/rpc/servers/zmq/util.rb | 3 +- lib/protobuf/rpc/servers/zmq/worker.rb | 84 +++++++--- .../protobuf/rpc/servers/zmq/server_spec.rb | 8 - 5 files changed, 241 insertions(+), 121 deletions(-) create mode 100644 lib/protobuf/rpc/servers/zmq/broker.rb diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb new file mode 100644 index 00000000..3b5d1e27 --- /dev/null +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -0,0 +1,114 @@ + +module Protobuf + module Rpc + module Zmq + class Broker + include ::Protobuf::Rpc::Zmq::Util + + attr_reader :server + + def initialize(server) + @server = server + + init_zmq_context + init_backend_socket + init_frontend_socket + init_shutdown_socket + init_poller + end + + def join + @thread.try :join + end + + def minimum_timeout + 100 + end + + def run + idle_workers = [] + + catch(:shutdown) do + while @poller.poll > 0 + @poller.readables.each do |readable| + case readable + when @frontend_socket + if idle_workers.any? + @frontend_socket.recv_strings frames = [] + @backend_socket.send_strings [idle_workers.shift, ""] + frames + end + when @backend_socket + @backend_socket.recv_strings frames = [] + idle_workers << frames.shift(2)[0] + unless frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] + @frontend_socket.send_strings frames + end + when @shutdown_socket + throw :shutdown + end + end + end + end + + teardown + end + + def start + log_debug { sign_message("starting broker") } + + @thread = Thread.new do + self.run + end + + self + end + + def shutdown_uri + "inproc://#{object_id}" + end + + def signal_shutdown + socket = @zmq_context.socket ZMQ::PAIR + zmq_error_check(socket.connect shutdown_uri) + zmq_error_check(socket.send_string "") + zmq_error_check(socket.close) + end + + def teardown + @frontend_socket.close + @backend_socket.close + @shutdown_socket.close + @zmq_context.terminate + end + + private + + def init_backend_socket + @backend_socket = @zmq_context.socket ZMQ::ROUTER + zmq_error_check(@backend_socket.bind server.backend_uri) + end + + def init_frontend_socket + @frontend_socket = @zmq_context.socket ZMQ::ROUTER + zmq_error_check(@frontend_socket.bind server.frontend_uri) + end + + def init_poller + @poller = ZMQ::Poller.new + @poller.register_readable @frontend_socket + @poller.register_readable @backend_socket + @poller.register_readable @shutdown_socket + end + + def init_shutdown_socket + @shutdown_socket = @zmq_context.socket ZMQ::PAIR + zmq_error_check(@shutdown_socket.bind shutdown_uri) + end + + def init_zmq_context + @zmq_context = ZMQ::Context.new + end + end + end + end +end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index d15da2c4..a7fc3b32 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -1,8 +1,11 @@ -require 'protobuf/rpc/servers/zmq/worker' require 'protobuf/rpc/servers/zmq/util' +require 'protobuf/rpc/servers/zmq/worker' +require 'protobuf/rpc/servers/zmq/broker' require 'protobuf/rpc/dynamic_discovery.pb' require 'securerandom' +STDOUT.sync = true + module Protobuf module Rpc module Zmq @@ -16,10 +19,11 @@ def initialize(options) @workers = [] init_zmq_context - init_backend_socket - init_frontend_socket unless brokerless? - init_shutdown_socket init_beacon_socket if broadcast_beacons? + init_shutdown_socket + rescue + teardown + raise end def backend_ip @@ -100,7 +104,7 @@ def minimum_timeout def reap_dead_workers @workers.keep_if do |worker| - worker.alive? + worker.thread.alive? or worker.thread.join && false end end @@ -111,14 +115,13 @@ def reaping_interval def run @running = true + start_broker unless brokerless? start_missing_workers - - brokerless? ? wait_for_shutdown_signal : run_broker - - @workers.each do |t| - t.join(5) || t.kill - end + wait_for_shutdown_signal + stop_workers + stop_broker unless brokerless? ensure + @running = false teardown end @@ -126,66 +129,21 @@ def running? !!@running end - def run_broker - log_debug { sign_message("initializing broker") } - - timeout = 0 - next_beacon = 0 - next_reaping = 0 - next_cycle = Time.now.to_i + maintenance_interval - poller = ZMQ::Poller.new - available_workers = [] - - poller.register_readable @frontend_socket - poller.register_readable @backend_socket - poller.register_readable @shutdown_socket - - while running? || @workers.any? - poller.poll(timeout) - poller.readables.each do |readable| - if readable === @frontend_socket - if available_workers.any? - @frontend_socket.recv_strings frames = [] - @backend_socket.send_strings [available_workers.shift, ""] + frames - end - elsif readable === @backend_socket - @backend_socket.recv_strings frames = [] - available_workers << frames.shift(2)[0] - unless frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] - @frontend_socket.send_strings frames - end - elsif readable === @shutdown_socket - broadcast_flatline if broadcast_beacons? - poller.deregister_readable @frontend_socket - poller.deregister_readable @shutdown_socket - end - end - - if (time = Time.now.to_i) >= next_reaping - reap_dead_workers - start_missing_workers if running? - next_reaping = time + reaping_interval - next_cycle = [next_cycle, next_reaping].min - end - - if broadcast_beacons? && time >= next_beacon - running? ? broadcast_heartbeat : broadcast_flatline - next_beacon = time + beacon_interval - next_cycle = [next_cycle, next_beacon].min - end - - timeout = [minimum_timeout, 1_000 * (next_cycle - time)].max - end + def shutdown_uri + "inproc://#{object_id}" end def signal_shutdown - @running = false - socket = zmq_context.socket ZMQ::PAIR + socket = @zmq_context.socket ZMQ::PAIR zmq_error_check(socket.connect shutdown_uri) - zmq_error_check(socket.send_string "shutdown") + zmq_error_check(socket.send_string "blargh!") zmq_error_check(socket.close) end + def start_broker + @broker = ::Protobuf::Rpc::Zmq::Broker.new(self).start + end + def start_missing_workers missing_workers = total_workers - @workers.size @@ -196,31 +154,27 @@ def start_missing_workers end def start_worker - @workers << Thread.new(self) do |server| - begin - ::Protobuf::Rpc::Zmq::Worker.new(server).run - rescue => e - message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" - $stderr.puts message - log_error { message } - end - end - end - - def shutdown_uri - "inproc://#{object_id}" + @workers << ::Protobuf::Rpc::Zmq::Worker.new(self).start end def stop signal_shutdown end + def stop_broker + @broker.signal_shutdown + @broker.join + end + + def stop_workers + @workers.each &:signal_shutdown + Thread.pass until reap_dead_workers.empty? + end + def teardown - @frontend_socket.try :close - @backend_socket.try :close @shutdown_socket.try :close @beacon_socket.try :close - @zmq_context.terminate + @zmq_context.try :terminate end def total_workers @@ -232,7 +186,34 @@ def uuid end def wait_for_shutdown_signal - @shutdown_socket.recv_string shutdown = "" + timeout = 0 + next_beacon = 0 + next_reaping = 0 + next_cycle = Time.now.to_i + maintenance_interval + poller = ZMQ::Poller.new + + poller.register_readable @shutdown_socket + + while poller.poll(timeout) >= 0 + break if poller.readables.any? + + time = Time.now.to_i + + if time >= next_reaping + reap_dead_workers + start_missing_workers + next_reaping = time + reaping_interval + next_cycle = [next_cycle, next_reaping].min + end + + if broadcast_beacons? && time >= next_beacon + broadcast_heartbeat + next_beacon = time + beacon_interval + next_cycle = [next_cycle, next_beacon].min + end + + timeout = [minimum_timeout, 1000 * (next_cycle - time)].max + end end private @@ -241,22 +222,12 @@ def default_options { :beacon_interval => 5 } end - def init_backend_socket - @backend_socket = @zmq_context.socket ZMQ::ROUTER - zmq_error_check(@backend_socket.bind backend_uri) - end - def init_beacon_socket @beacon_socket = UDPSocket.new @beacon_socket.setsockopt :SOCKET, :BROADCAST, true @beacon_socket.connect beacon_ip, beacon_port end - def init_frontend_socket - @frontend_socket = @zmq_context.socket ZMQ::ROUTER - zmq_error_check(@frontend_socket.bind frontend_uri) - end - def init_shutdown_socket @shutdown_socket = @zmq_context.socket ZMQ::PAIR @shutdown_socket.bind shutdown_uri diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 078de305..513eaa45 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -4,7 +4,8 @@ module Protobuf module Rpc module Zmq - WORKER_READY_MESSAGE = "WORKER_READY" + WORKER_READY_MESSAGE = "\1" + WORKER_SHUTDOWN_MESSAGE = "\2" module Util include ::Protobuf::Logger::LogMethods diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index c0eb7a42..88f0e133 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -8,13 +8,16 @@ class Worker include ::Protobuf::Rpc::Server include ::Protobuf::Rpc::Zmq::Util + attr_reader :thread + ## # Constructor # def initialize(server) @server = server init_zmq_context - init_socket + init_backend_socket + init_shutdown_socket end ## @@ -32,36 +35,70 @@ def handle_request(socket) end def run + running = true poller = ::ZMQ::Poller.new - poller.register(@socket, ::ZMQ::POLLIN) + + poller.register_readable(@backend_socket) + poller.register_readable(@shutdown_socket) # Send request to broker telling it we are ready - zmq_error_check(@socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) - - # poll for 1 second then continue looping - # This lets us see whether we need to die - while @server.running? && poller.poll(1_000) >= 0 - poller.readables.each do |socket| - initialize_request! - handle_request(socket) + zmq_error_check(@backend_socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) + + while poller.poll > 0 + poller.readables.each do |readable| + if readable === @backend_socket + initialize_request! + handle_request(@backend_socket) + elsif readable === @shutdown_socket + running = false + end end + + break unless running end ensure - @socket.close - @zmq_context.terminate + teardown end def send_data response_data = @response.to_s # to_s is aliases as serialize_to_string in Message - response_message_set = [ - @client_address, # client uuid address - "", - response_data - ] + frames = [@client_address, "", response_data] @stats.response_size = response_data.size - zmq_error_check(@socket.send_strings(response_message_set)) + + zmq_error_check(@backend_socket.send_strings(frames)) + end + + def shutdown_uri + "inproc://#{object_id}" + end + + def signal_shutdown + socket = @zmq_context.socket ZMQ::PAIR + zmq_error_check(socket.connect shutdown_uri) + zmq_error_check(socket.send_string "shutdown") + zmq_error_check(socket.close) + end + + def start + @thread = Thread.new do + begin + self.run + rescue => e + message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" + $stderr.puts message + log_error { message } + end + end + + self + end + + def teardown + @backend_socket.try :close + @shutdown_socket.try :close + @zmq_context.try :terminate end private @@ -70,9 +107,14 @@ def init_zmq_context @zmq_context = ZMQ::Context.new end - def init_socket - @socket = @zmq_context.socket ZMQ::REQ - zmq_error_check(@socket.connect @server.backend_uri) + def init_backend_socket + @backend_socket = @zmq_context.socket ZMQ::REQ + zmq_error_check(@backend_socket.connect @server.backend_uri) + end + + def init_shutdown_socket + @shutdown_socket = @zmq_context.socket ZMQ::PAIR + zmq_error_check(@shutdown_socket.bind shutdown_uri) end end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 51db32d7..80ab752e 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -19,14 +19,6 @@ subject.teardown end - it 'sets up a ZMQ context' do - subject.instance_variable_get(:@zmq_context).should be_a(::ZMQ::Context) - end - - it 'sets up a backend socket' do - subject.instance_variable_get(:@backend_socket).should be_a(::ZMQ::Socket) - end - describe '.running?' do it 'returns true if running' do subject.instance_variable_set(:@running, true) From 1a3eb490b3b93e18d801647607e2ed2e012de944 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 11:20:42 -0600 Subject: [PATCH 0364/1191] Track subclasses and services --- lib/protobuf/rpc/service.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 86320a4c..4246fbd0 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -54,6 +54,11 @@ def self.host=(new_host) @_host = new_host end + def self.inherited(subclass) + @_subclasses ||= [] + @_subclasses << subclass + end + # Shorthand call to configure, passing a string formatted as hostname:port # e.g. 127.0.0.1:9933 # e.g. localhost:0 @@ -96,6 +101,15 @@ def self.rpc_method?(name) rpcs.key?(name) end + # An array of defined service classes + def self.services + @_subclasses.select do |subclass| + subclass.rpcs.any? do |(name, method)| + subclass.method_defined? name + end + end + end + ## # Instance Methods # From a4dc84b681538c8d94f2eee30404f012c2a97448 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 11:21:45 -0600 Subject: [PATCH 0365/1191] Add services to the heartbeat beacon --- lib/protobuf/rpc/servers/zmq/server.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index a7fc3b32..ba004967 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -66,13 +66,14 @@ def broadcast_flatline end def broadcast_heartbeat + services = ::Protobuf::Rpc::Service.services heartbeat = ::Protobuf::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::DynamicDiscovery::BeaconType::HEARTBEAT, :uuid => uuid, :address => frontend_ip, :port => frontend_port.to_s, :ttl => beacon_interval * 3, - :service_classes => ["not sure"] # TODO: Figure out what goes here + :service_classes => services.map(&:name) ) @beacon_socket.send heartbeat.to_s, 0 From cc22b9cf318e79205f59d40a8afd669c97ab8651 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 11:22:43 -0600 Subject: [PATCH 0366/1191] Delegate alive? and join to the worker's thread --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/worker.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index ba004967..c85f991e 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -105,7 +105,7 @@ def minimum_timeout def reap_dead_workers @workers.keep_if do |worker| - worker.thread.alive? or worker.thread.join && false + worker.alive? or worker.join && false end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 88f0e133..34c5f52f 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -23,6 +23,10 @@ def initialize(server) ## # Instance Methods # + def alive? + @thread.try(:alive?) || false + end + def handle_request(socket) zmq_error_check(socket.recv_strings(frames = [])) @@ -34,6 +38,10 @@ def handle_request(socket) end end + def join + @thread.try :join + end + def run running = true poller = ::ZMQ::Poller.new From 23fb0a11936d55ef8a62099c876c7a7226ca026a Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 11:23:32 -0600 Subject: [PATCH 0367/1191] Broadcast the flatline beacon after shutdown --- lib/protobuf/rpc/servers/zmq/server.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c85f991e..583e5968 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -119,6 +119,7 @@ def run start_broker unless brokerless? start_missing_workers wait_for_shutdown_signal + broadcast_flatline if broadcast_beacons? stop_workers stop_broker unless brokerless? ensure From 78f979107bad910e20d25fc829f89eee76d973ef Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 11:24:23 -0600 Subject: [PATCH 0368/1191] Avoid reaping workers immediately after startup --- lib/protobuf/rpc/servers/zmq/server.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 583e5968..4f83dd2b 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -188,10 +188,11 @@ def uuid end def wait_for_shutdown_signal + time = Time.now.to_i timeout = 0 next_beacon = 0 - next_reaping = 0 - next_cycle = Time.now.to_i + maintenance_interval + next_reaping = time + reaping_interval + next_cycle = time + maintenance_interval poller = ZMQ::Poller.new poller.register_readable @shutdown_socket From 11d93e719d51cd5ac59fe5e1252903a8a51937da Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 11:37:39 -0600 Subject: [PATCH 0369/1191] Tweak the poller loop to be a bit more concise --- lib/protobuf/rpc/servers/zmq/server.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 4f83dd2b..1f80985c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -194,15 +194,12 @@ def wait_for_shutdown_signal next_reaping = time + reaping_interval next_cycle = time + maintenance_interval poller = ZMQ::Poller.new - poller.register_readable @shutdown_socket - while poller.poll(timeout) >= 0 - break if poller.readables.any? - - time = Time.now.to_i - - if time >= next_reaping + # If the poller returns 1, a shutdown signal has been received. + # If the poller returns -1, something went wrong. + while poller.poll(timeout) === 0 + if (time = Time.now.to_i) >= next_reaping reap_dead_workers start_missing_workers next_reaping = time + reaping_interval From 6b94e796661c43c9b3bcce5ed4ad3c855e2de21f Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 11:43:54 -0600 Subject: [PATCH 0370/1191] Remove unused method in broker --- lib/protobuf/rpc/servers/zmq/broker.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 3b5d1e27..337d2c6e 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -21,10 +21,6 @@ def join @thread.try :join end - def minimum_timeout - 100 - end - def run idle_workers = [] From 3f90238798fc4542c6a4b518f99b0e3a7aa2b31f Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 13:48:58 -0600 Subject: [PATCH 0371/1191] Review and improve code --- lib/protobuf/rpc/servers/zmq/broker.rb | 30 ++++++++++--------- lib/protobuf/rpc/servers/zmq/server.rb | 10 +++---- lib/protobuf/rpc/servers/zmq/util.rb | 1 - lib/protobuf/rpc/servers/zmq/worker.rb | 40 +++++++++++++------------- lib/protobuf/rpc/service.rb | 2 +- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 337d2c6e..2aae9006 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -5,8 +5,6 @@ module Zmq class Broker include ::Protobuf::Rpc::Zmq::Util - attr_reader :server - def initialize(server) @server = server @@ -15,6 +13,9 @@ def initialize(server) init_frontend_socket init_shutdown_socket init_poller + rescue + teardown + raise end def join @@ -30,14 +31,15 @@ def run case readable when @frontend_socket if idle_workers.any? - @frontend_socket.recv_strings frames = [] - @backend_socket.send_strings [idle_workers.shift, ""] + frames + zmq_error_check(@frontend_socket.recv_strings frames = []) + frames.unshift(idle_workers.shift, "") + zmq_error_check(@backend_socket.send_strings frames) end when @backend_socket - @backend_socket.recv_strings frames = [] + zmq_error_check(@backend_socket.recv_strings frames = []) idle_workers << frames.shift(2)[0] unless frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] - @frontend_socket.send_strings frames + zmq_error_check(@frontend_socket.send_strings frames) end when @shutdown_socket throw :shutdown @@ -45,7 +47,7 @@ def run end end end - + ensure teardown end @@ -66,27 +68,27 @@ def shutdown_uri def signal_shutdown socket = @zmq_context.socket ZMQ::PAIR zmq_error_check(socket.connect shutdown_uri) - zmq_error_check(socket.send_string "") + zmq_error_check(socket.send_string ".") zmq_error_check(socket.close) end def teardown - @frontend_socket.close - @backend_socket.close - @shutdown_socket.close - @zmq_context.terminate + @frontend_socket.try :close + @backend_socket.try :close + @shutdown_socket.try :close + @zmq_context.try :terminate end private def init_backend_socket @backend_socket = @zmq_context.socket ZMQ::ROUTER - zmq_error_check(@backend_socket.bind server.backend_uri) + zmq_error_check(@backend_socket.bind @server.backend_uri) end def init_frontend_socket @frontend_socket = @zmq_context.socket ZMQ::ROUTER - zmq_error_check(@frontend_socket.bind server.frontend_uri) + zmq_error_check(@frontend_socket.bind @server.frontend_uri) end def init_poller diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 1f80985c..6c773692 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -4,15 +4,13 @@ require 'protobuf/rpc/dynamic_discovery.pb' require 'securerandom' -STDOUT.sync = true - module Protobuf module Rpc module Zmq class Server include ::Protobuf::Rpc::Zmq::Util - attr_accessor :options, :workers, :zmq_context + attr_accessor :options def initialize(options) @options = default_options.merge(options) @@ -138,7 +136,7 @@ def shutdown_uri def signal_shutdown socket = @zmq_context.socket ZMQ::PAIR zmq_error_check(socket.connect shutdown_uri) - zmq_error_check(socket.send_string "blargh!") + zmq_error_check(socket.send_string ".") zmq_error_check(socket.close) end @@ -180,7 +178,7 @@ def teardown end def total_workers - @total_workers ||= @options[:threads] + @total_workers ||= [@options[:threads].to_i, 1].max end def uuid @@ -230,7 +228,7 @@ def init_beacon_socket def init_shutdown_socket @shutdown_socket = @zmq_context.socket ZMQ::PAIR - @shutdown_socket.bind shutdown_uri + zmq_error_check(@shutdown_socket.bind shutdown_uri) end def init_zmq_context diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 513eaa45..6da90ac4 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -5,7 +5,6 @@ module Rpc module Zmq WORKER_READY_MESSAGE = "\1" - WORKER_SHUTDOWN_MESSAGE = "\2" module Util include ::Protobuf::Logger::LogMethods diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 34c5f52f..89ac5f46 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -8,8 +8,6 @@ class Worker include ::Protobuf::Rpc::Server include ::Protobuf::Rpc::Zmq::Util - attr_reader :thread - ## # Constructor # @@ -18,6 +16,9 @@ def initialize(server) init_zmq_context init_backend_socket init_shutdown_socket + rescue + teardown + raise end ## @@ -27,8 +28,12 @@ def alive? @thread.try(:alive?) || false end - def handle_request(socket) - zmq_error_check(socket.recv_strings(frames = [])) + def join + @thread.try :join + end + + def process_request + zmq_error_check(@backend_socket.recv_strings(frames = [])) @client_address, empty, @request_data = *frames @@ -38,31 +43,26 @@ def handle_request(socket) end end - def join - @thread.try :join - end - def run - running = true poller = ::ZMQ::Poller.new - poller.register_readable(@backend_socket) poller.register_readable(@shutdown_socket) # Send request to broker telling it we are ready zmq_error_check(@backend_socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) - while poller.poll > 0 - poller.readables.each do |readable| - if readable === @backend_socket - initialize_request! - handle_request(@backend_socket) - elsif readable === @shutdown_socket - running = false + catch(:shutdown) do + while poller.poll > 0 + poller.readables.each do |readable| + case readable + when @backend_socket + initialize_request! + process_request + when @shutdown_socket + throw :shutdown + end end end - - break unless running end ensure teardown @@ -85,7 +85,7 @@ def shutdown_uri def signal_shutdown socket = @zmq_context.socket ZMQ::PAIR zmq_error_check(socket.connect shutdown_uri) - zmq_error_check(socket.send_string "shutdown") + zmq_error_check(socket.send_string ".") zmq_error_check(socket.close) end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 4246fbd0..aeea555f 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -103,7 +103,7 @@ def self.rpc_method?(name) # An array of defined service classes def self.services - @_subclasses.select do |subclass| + (@_subclasses ||[]).select do |subclass| subclass.rpcs.any? do |(name, method)| subclass.method_defined? name end From 8f1300640661fe090668e106ced9be8163da2af5 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 13:56:57 -0600 Subject: [PATCH 0372/1191] Improve readability --- lib/protobuf/rpc/service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index aeea555f..d3c98625 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -103,7 +103,7 @@ def self.rpc_method?(name) # An array of defined service classes def self.services - (@_subclasses ||[]).select do |subclass| + (@_subclasses || []).select do |subclass| subclass.rpcs.any? do |(name, method)| subclass.method_defined? name end From b29765919da2ef1c722099bb68f1759849423d08 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 15:23:46 -0600 Subject: [PATCH 0373/1191] Rename the beacon command line option --- lib/protobuf/cli.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 391be744..c1810fce 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -27,7 +27,7 @@ class CLI < ::Thor option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' - option :dynamic_discovery, :type => :boolean, :default => false, :aliases => %w(-y), :desc => 'Enable dynamic discovery (Currently only available with ZeroMQ).' + option :broadcast_beacons, :type => :boolean, :default => false, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 6c773692..c7d9c5e3 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -49,7 +49,7 @@ def beacon_port end def broadcast_beacons? - !brokerless? && options[:dynamic_discovery] + !brokerless? && options[:broadcast_beacons] end def broadcast_flatline diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 752fd4b6..506720d8 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -9,7 +9,7 @@ :backlog => 100, :threshold => 100, :threads => 5, - :dynamic_discovery => true, + :broadcast_beacons => true, :beacon_port => 9398 }} From 0daf17ff980f6d4dc16a056dbd387f00b7dedb61 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 17:09:18 -0600 Subject: [PATCH 0374/1191] Use a constant for default options --- lib/protobuf/rpc/servers/zmq/server.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c7d9c5e3..7864a8ad 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -10,10 +10,12 @@ module Zmq class Server include ::Protobuf::Rpc::Zmq::Util + DEFAULT_OPTIONS = { :beacon_interval => 5 } + attr_accessor :options def initialize(options) - @options = default_options.merge(options) + @options = DEFAULT_OPTIONS.merge(options) @workers = [] init_zmq_context @@ -216,10 +218,6 @@ def wait_for_shutdown_signal private - def default_options - { :beacon_interval => 5 } - end - def init_beacon_socket @beacon_socket = UDPSocket.new @beacon_socket.setsockopt :SOCKET, :BROADCAST, true From 46fcea0eb69f7d78bdf67c4f8b8c6dfef6190644 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 29 May 2013 17:09:43 -0600 Subject: [PATCH 0375/1191] Cleanup whitespace --- lib/protobuf.rb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 3c8edc90..24523879 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -15,7 +15,7 @@ module Protobuf # Default is Socket as it has no external dependencies. DEFAULT_CONNECTOR = :socket - module_function + module_function # Client Host # @@ -53,14 +53,14 @@ def self.connector_type=(type) # the Garbage Collector when handling an rpc request. # Once the request is completed, the GC is enabled again. # This optomization provides a huge boost in speed to rpc requests. - def self.gc_pause_server_request? - return @_gc_pause_server_request unless @_gc_pause_server_request.nil? - gc_pause_server_request = false - end + def self.gc_pause_server_request? + return @_gc_pause_server_request unless @_gc_pause_server_request.nil? + gc_pause_server_request = false + end - def self.gc_pause_server_request=(value) - @_gc_pause_server_request = !!value - end + def self.gc_pause_server_request=(value) + @_gc_pause_server_request = !!value + end # Print Deprecation Warnings # @@ -72,14 +72,14 @@ def self.gc_pause_server_request=(value) # ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value. # # The rpc_server option will override the ENV setting. - def self.print_deprecation_warnings? - return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil? - print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true - end - - def self.print_deprecation_warnings=(value) - @_print_deprecation_warnings = !!value - end + def self.print_deprecation_warnings? + return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil? + print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true + end + + def self.print_deprecation_warnings=(value) + @_print_deprecation_warnings = !!value + end end From 9f02740d357239f4a1db6af8740c7bb575f59a28 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 30 May 2013 10:18:48 -0600 Subject: [PATCH 0376/1191] Don't shutdown the broker pre-maturely --- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c6af7f55..f393cc9c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -25,7 +25,7 @@ def self.run(options = {}) @running = true log_debug { sign_message("server started") } - while self.running? do + while @threads.any? do @broker.poll end ensure @@ -53,8 +53,8 @@ def self.start_worker def self.stop @running = false - @threads.each do |t| - t.join + @threads.delete_if do |t| + t.join || true end end From bbcd4b163616e459a8e485efb232d2b38fd6ea94 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 31 May 2013 13:59:33 -0600 Subject: [PATCH 0377/1191] Add the service directory class --- lib/protobuf/rpc/connectors/zmq.rb | 25 +++- lib/protobuf/rpc/dynamic_discovery.pb.rb | 59 +++++---- lib/protobuf/rpc/servers/zmq/server.rb | 31 +++-- lib/protobuf/rpc/service.rb | 9 +- lib/protobuf/rpc/service_directory.rb | 156 +++++++++++++++++++++++ proto/dynamic_discovery.proto | 16 ++- 6 files changed, 243 insertions(+), 53 deletions(-) create mode 100644 lib/protobuf/rpc/service_directory.rb diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 993ac3e1..bc511b81 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -1,4 +1,5 @@ require 'protobuf/rpc/connectors/base' +require 'protobuf/rpc/service_directory' module Protobuf module Rpc @@ -15,8 +16,8 @@ def send_request read_response end ensure - @socket.close if @socket - @zmq_context.terminate if @zmq_context + @socket.try :close + @zmq_context.try :terminate @zmq_context = nil end @@ -24,6 +25,20 @@ def log_signature @_log_signature ||= "[client-#{self.class}]" end + def service_directory + ::Protobuf::Rpc::ServiceDirectory.instance + end + + def service_uri + if service_directory.running? + host, port = service_directory.find options[:service] + else + host, port = options[:host], options[:port] + end + + "tcp://#{host}:#{port}" + end + private def close_connection @@ -35,11 +50,11 @@ def close_connection def connect_to_rpc_server return if @error - log_debug { sign_message("Establishing connection: #{options[:host]}:#{options[:port]}") } + log_debug { sign_message("Establishing connection: #{service_uri}") } @zmq_context = ::ZMQ::Context.new @socket = @zmq_context.socket(::ZMQ::REQ) - zmq_error_check(@socket.connect("tcp://#{options[:host]}:#{options[:port]}")) - log_debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } + zmq_error_check(@socket.connect(service_uri)) + log_debug { sign_message("Connection established #{service_uri}") } end # Method to determine error state, must be used with Connector api diff --git a/lib/protobuf/rpc/dynamic_discovery.pb.rb b/lib/protobuf/rpc/dynamic_discovery.pb.rb index 056ec020..51d0d79e 100644 --- a/lib/protobuf/rpc/dynamic_discovery.pb.rb +++ b/lib/protobuf/rpc/dynamic_discovery.pb.rb @@ -5,35 +5,44 @@ module Protobuf - module DynamicDiscovery + module Rpc - ## - # Enum Classes - # - class BeaconType < ::Protobuf::Enum - define :HEARTBEAT, 0 - define :FLATLINE, 1 - end - + module DynamicDiscovery - ## - # Message Classes - # - class Beacon < ::Protobuf::Message; end - - ## - # Message Fields - # - class Beacon - optional ::Protobuf::DynamicDiscovery::BeaconType, :beacon_type, 1 - optional ::Protobuf::Field::StringField, :uuid, 2 - optional ::Protobuf::Field::StringField, :address, 3 - optional ::Protobuf::Field::StringField, :port, 4 - optional ::Protobuf::Field::Int32Field, :ttl, 5 - repeated ::Protobuf::Field::StringField, :service_classes, 6 + ## + # Enum Classes + # + class BeaconType < ::Protobuf::Enum + define :HEARTBEAT, 0 + define :FLATLINE, 1 + end + + + ## + # Message Classes + # + class Server < ::Protobuf::Message; end + class Beacon < ::Protobuf::Message; end + + ## + # Message Fields + # + class Server + optional ::Protobuf::Field::StringField, :uuid, 1 + optional ::Protobuf::Field::StringField, :address, 2 + optional ::Protobuf::Field::StringField, :port, 3 + optional ::Protobuf::Field::Int32Field, :ttl, 4 + repeated ::Protobuf::Field::StringField, :services, 5 + end + + class Beacon + optional ::Protobuf::Rpc::DynamicDiscovery::BeaconType, :beacon_type, 1 + optional ::Protobuf::Rpc::DynamicDiscovery::Server, :server, 2 + end + + end - end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 7864a8ad..09e99f70 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -55,28 +55,21 @@ def broadcast_beacons? end def broadcast_flatline - flatline = ::Protobuf::DynamicDiscovery::Beacon.new( - :beacon_type => ::Protobuf::DynamicDiscovery::BeaconType::FLATLINE, - :uuid => uuid, - :address => frontend_ip, - :port => frontend_port.to_s + flatline = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( + :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE, + :server => self.to_proto ) @beacon_socket.send flatline.to_s, 0 end def broadcast_heartbeat - services = ::Protobuf::Rpc::Service.services - heartbeat = ::Protobuf::DynamicDiscovery::Beacon.new( - :beacon_type => ::Protobuf::DynamicDiscovery::BeaconType::HEARTBEAT, - :uuid => uuid, - :address => frontend_ip, - :port => frontend_port.to_s, - :ttl => beacon_interval * 3, - :service_classes => services.map(&:name) + heartbeat = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( + :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT, + :server => self.to_proto ) - @beacon_socket.send heartbeat.to_s, 0 + @beacon_socket.send heartbeat.serialize_to_string, 0 end def brokerless? @@ -183,6 +176,16 @@ def total_workers @total_workers ||= [@options[:threads].to_i, 1].max end + def to_proto + @proto ||= ::Protobuf::Rpc::DynamicDiscovery::Server.new( + :uuid => uuid, + :address => frontend_ip, + :port => frontend_port.to_s, + :ttl => beacon_interval * 3, + :services => ::Protobuf::Rpc::Service.implemented_services + ) + end + def uuid @uuid ||= SecureRandom.uuid end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index d3c98625..50b221a6 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -101,13 +101,16 @@ def self.rpc_method?(name) rpcs.key?(name) end - # An array of defined service classes - def self.services - (@_subclasses || []).select do |subclass| + # An array of defined service classes that contain implementation + # code + def self.implemented_services + classes = (@_subclasses || []).select do |subclass| subclass.rpcs.any? do |(name, method)| subclass.method_defined? name end end + + classes.map &:name end ## diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb new file mode 100644 index 00000000..cb373490 --- /dev/null +++ b/lib/protobuf/rpc/service_directory.rb @@ -0,0 +1,156 @@ +require 'delegate' +require 'singleton' +require 'socket' +require 'thread' +require 'protobuf/rpc/dynamic_discovery.pb' + +module Protobuf + module Rpc + class ServiceDirectory + include ::Singleton + include ::Protobuf::Logger::LogMethods + + DEFAULT_ADDRESS = "0.0.0.0" + DEFAULT_PORT = 9398 + + class Server < Delegator + attr_reader :expires_at + + def initialize(server) + @server = server + @expires_at = Time.now.to_i + ttl + end + + def current? + !expired? + end + + def expired? + Time.now.to_i >= @expires_at + end + + def __getobj__ + @server + end + end + + # Class Methods + # + def self.address + @address ||= DEFAULT_ADDRESS + end + + def self.address=(value) + @address ||= value + end + + def self.port + @port ||= DEFAULT_PORT + end + + def self.port=(value) + @port ||= value.to_i + end + + def self.start + self.instance.start + end + + # Instance Methods + # + def initialize + @servers = {} + @mutex = Mutex.new + end + + def add_server(server) + @mutex.synchronize do + @servers[server.uuid] = Server.new(server) + end + end + + def find(service) + log_debug { sign_message("searching for #{service}") } + Thread.pass until server = random_server_for(service) + log_debug { sign_message("found #{service} at #{server}") } + + [server.address, server.port] + end + + def random_server_for(service) + @mutex.synchronize do + servers = @servers.values.select do |server| + server.services.any? do |service_class| + server.current? && service_class.to_s == service.to_s + end + end + + servers.sample + end + end + + def reap_expired_servers + @mutex.synchronize do + @servers.delete_if do |uuid, server| + server.expired? + end + end + end + + def remove_server(server) + @mutex.synchronize do + @servers.delete server.uuid + end + end + + def run + loop do + data, addr = @socket.recvfrom(1024) + beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new + beacon.parse_from_string(data) rescue nil + + log_debug { sign_message("received beacon: #{beacon.inspect}") } + + case beacon.beacon_type + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT + add_server(beacon.server) + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE + remove_server(beacon.server) + end + + reap_expired_servers + end + end + + def running? + @thread.try(:alive?) + end + + def start + unless running? + log_debug { sign_message("starting service directory") } + + init_socket + + @thread = Thread.new do + begin + self.run + rescue => e + log_debug { sign_message("service directory failed: (#{e.class}) #{e.message}") } + raise + end + end + end + + self + end + + private + + def init_socket + @socket = UDPSocket.new + @socket.bind(self.class.address, self.class.port) + end + end + end +end diff --git a/proto/dynamic_discovery.proto b/proto/dynamic_discovery.proto index 3854a105..dcecca5f 100644 --- a/proto/dynamic_discovery.proto +++ b/proto/dynamic_discovery.proto @@ -22,19 +22,23 @@ // // Protobufs needed for dynamic discovery zmq server and client. -package protobuf.dynamicDiscovery; +package protobuf.rpc.dynamicDiscovery; enum BeaconType { HEARTBEAT = 0; FLATLINE = 1; } +message Server { + optional string uuid = 1; + optional string address = 2; + optional string port = 3; + optional int32 ttl = 4; + repeated string services = 5; +} + message Beacon { optional BeaconType beacon_type = 1; - optional string uuid = 2; - optional string address = 3; - optional string port = 4; - optional int32 ttl = 5; - repeated string service_classes = 6; + optional Server server = 2; } From 115b32804f3bed19dde89631dd42f3c4519138fa Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 31 May 2013 17:05:08 -0600 Subject: [PATCH 0378/1191] Begin writing the directory service spec --- lib/protobuf/rpc/service_directory.rb | 90 ++++++++++++++------- spec/functional/zmq_server_spec.rb | 5 +- spec/lib/protobuf/service_directory_spec.rb | 53 ++++++++++++ 3 files changed, 115 insertions(+), 33 deletions(-) create mode 100644 spec/lib/protobuf/service_directory_spec.rb diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index cb373490..c9c781d4 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -2,6 +2,8 @@ require 'singleton' require 'socket' require 'thread' +require 'timeout' + require 'protobuf/rpc/dynamic_discovery.pb' module Protobuf @@ -12,8 +14,11 @@ class ServiceDirectory DEFAULT_ADDRESS = "0.0.0.0" DEFAULT_PORT = 9398 + DEFAULT_TIMEOUT = 5 + + ServiceNotFound = Class.new(RuntimeError) - class Server < Delegator + class Listing < Delegator attr_reader :expires_at def initialize(server) @@ -36,70 +41,86 @@ def __getobj__ # Class Methods # - def self.address - @address ||= DEFAULT_ADDRESS + class << self + attr_writer :address, :port, :timeout end - def self.address=(value) - @address ||= value + def self.address + @address ||= DEFAULT_ADDRESS end def self.port @port ||= DEFAULT_PORT end - def self.port=(value) - @port ||= value.to_i - end - def self.start + yield(self) if block_given? self.instance.start end + def self.stop + self.instance.stop + end + + def self.timeout + @timeout ||= DEFAULT_TIMEOUT + end + # Instance Methods # def initialize - @servers = {} + @listings = {} @mutex = Mutex.new end - def add_server(server) + def add_listing_for(server) @mutex.synchronize do - @servers[server.uuid] = Server.new(server) + @listings[server.uuid] = Listing.new(server) end end def find(service) + listing = nil log_debug { sign_message("searching for #{service}") } - Thread.pass until server = random_server_for(service) - log_debug { sign_message("found #{service} at #{server}") } - [server.address, server.port] + Timeout.timeout(self.class.timeout, ServiceNotFound) do + Thread.pass until listing = random_listing_for(service) + end + + log_debug { sign_message("found #{service} at #{listing.inspect}") } + + [listing.address, listing.port] + end + + def listing_count + @mutex.synchronize do + @listings.count + end end - def random_server_for(service) + def random_listing_for(service) @mutex.synchronize do - servers = @servers.values.select do |server| - server.services.any? do |service_class| - server.current? && service_class.to_s == service.to_s + listings = @listings.values.select do |listing| + listing.services.any? do |listed_service| + listing.current? && listed_service.to_s == service.to_s end end - servers.sample + listings.sample end end - def reap_expired_servers + def remove_expired_listings @mutex.synchronize do - @servers.delete_if do |uuid, server| - server.expired? + @listings.delete_if do |uuid, listing| + listing.expired? end end end - def remove_server(server) + def remove_listing_for(server) @mutex.synchronize do - @servers.delete server.uuid + @listings.delete(server.uuid) end end @@ -113,17 +134,17 @@ def run case beacon.beacon_type when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT - add_server(beacon.server) + add_listing_for(beacon.server) when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE - remove_server(beacon.server) + remove_listing_for(beacon.server) end - reap_expired_servers + remove_expired_listings end end def running? - @thread.try(:alive?) + !!@thread.try(:alive?) end def start @@ -136,7 +157,7 @@ def start begin self.run rescue => e - log_debug { sign_message("service directory failed: (#{e.class}) #{e.message}") } + log_debug { sign_message("error: (#{e.class}) #{e.message}") } raise end end @@ -145,6 +166,15 @@ def start self end + def stop + @mutex.synchronize do + @thread.try(:kill) + @listings = {} + end + + @socket.try(:close) + end + private def init_socket diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 506720d8..28455db3 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' require 'spec/support/test/resource_service' +require 'protobuf/rpc/service_directory' describe 'Functional ZMQ Client' do let(:options) {{ @@ -8,9 +9,7 @@ :worker_port => 9400, :backlog => 100, :threshold => 100, - :threads => 5, - :broadcast_beacons => true, - :beacon_port => 9398 + :threads => 5 }} let(:server) { ::Protobuf::Rpc::Zmq::Server.new(options) } diff --git a/spec/lib/protobuf/service_directory_spec.rb b/spec/lib/protobuf/service_directory_spec.rb new file mode 100644 index 00000000..e0cae3e9 --- /dev/null +++ b/spec/lib/protobuf/service_directory_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +require 'protobuf/rpc/service_directory' + +describe ::Protobuf::Rpc::ServiceDirectory do + let(:instance) { ::Protobuf::Rpc::ServiceDirectory.instance } + let(:server) { double('server', :uuid => '123', + :services => ['Known::Service'], + :address => "0.0.0.0", + :port => 9999, + :ttl => 15) } + + before(:all) do + ::Protobuf::Rpc::ServiceDirectory.timeout = 0.5 + end + + after do + instance.stop + end + + it "is a singleton" do + instance.should be_a_kind_of(Singleton) + end + + describe "#find" do + it "times out when nothing is found" do + expect { + instance.find("Unknown::Service") + }.to raise_error(::Protobuf::Rpc::ServiceDirectory::ServiceNotFound) + end + + it "returns a listing for the given service" do + instance.add_listing_for(server) + instance.find("Known::Service").should eq [server.address, server.port] + end + end + + describe "#remove_expired_listings" do + before do + instance.instance_variable_set(:@listings, { + '1' => double(:expired? => true), + '2' => double(:expired? => true), + '3' => double(:expired? => false), + }) + end + + it "removes expired listings" do + expect { + instance.remove_expired_listings + }.to change(instance, :listing_count).from(3).to(1) + end + end +end From 0f4b3c85d7d357a683b746260755ec65408a4dce Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 3 Jun 2013 10:54:03 -0600 Subject: [PATCH 0379/1191] Move spec to the correct folder --- spec/lib/protobuf/{ => rpc}/service_directory_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/lib/protobuf/{ => rpc}/service_directory_spec.rb (100%) diff --git a/spec/lib/protobuf/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb similarity index 100% rename from spec/lib/protobuf/service_directory_spec.rb rename to spec/lib/protobuf/rpc/service_directory_spec.rb From fccf0150b0602204701b3e911b05aa9077a8f0e9 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 3 Jun 2013 15:27:53 -0600 Subject: [PATCH 0380/1191] Test and improve directory service --- lib/protobuf/rpc/connectors/zmq.rb | 6 +- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 83 +++++++------ .../protobuf/rpc/service_directory_spec.rb | 116 ++++++++++++++++-- 4 files changed, 159 insertions(+), 48 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index bc511b81..0180dee9 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -31,12 +31,12 @@ def service_directory def service_uri if service_directory.running? - host, port = service_directory.find options[:service] + address, port = service_directory.find options[:service] else - host, port = options[:host], options[:port] + address, port = options[:host], options[:port] end - "tcp://#{host}:#{port}" + "tcp://#{address}:#{port}" end private diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 09e99f70..fff03713 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -60,7 +60,7 @@ def broadcast_flatline :server => self.to_proto ) - @beacon_socket.send flatline.to_s, 0 + @beacon_socket.send flatline.serialize_to_string, 0 end def broadcast_heartbeat diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index c9c781d4..f51c1a8c 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -26,6 +26,10 @@ def initialize(server) @expires_at = Time.now.to_i + ttl end + def <=>(other) + other.expires_at <=> self.expires_at + end + def current? !expired? end @@ -74,8 +78,15 @@ def initialize end def add_listing_for(server) - @mutex.synchronize do - @listings[server.uuid] = Listing.new(server) + if server && server.uuid + log_debug { sign_message("Adding listing for server: #{server.inspect}") } + + @mutex.synchronize do + @listings[server.uuid] = Listing.new(server) + end + + else + log_debug { sign_message("Cannot add server without uuid: #{server.inspect}") } end end @@ -84,7 +95,7 @@ def find(service) log_debug { sign_message("searching for #{service}") } Timeout.timeout(self.class.timeout, ServiceNotFound) do - Thread.pass until listing = random_listing_for(service) + Thread.pass until listing = youngest_listing_for(service) end log_debug { sign_message("found #{service} at #{listing.inspect}") } @@ -92,24 +103,6 @@ def find(service) [listing.address, listing.port] end - def listing_count - @mutex.synchronize do - @listings.count - end - end - - def random_listing_for(service) - @mutex.synchronize do - listings = @listings.values.select do |listing| - listing.services.any? do |listed_service| - listing.current? && listed_service.to_s == service.to_s - end - end - - listings.sample - end - end - def remove_expired_listings @mutex.synchronize do @listings.delete_if do |uuid, listing| @@ -119,18 +112,25 @@ def remove_expired_listings end def remove_listing_for(server) - @mutex.synchronize do - @listings.delete(server.uuid) + if server && server.uuid + log_debug { sign_message("Removing server: #{server.inspect}") } + + @mutex.synchronize do + @listings.delete(server.uuid) + end + + else + log_debug { sign_message("Cannot remove server without uuid: #{server.inspect}") } end end def run - loop do + begin data, addr = @socket.recvfrom(1024) beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new beacon.parse_from_string(data) rescue nil - log_debug { sign_message("received beacon: #{beacon.inspect}") } + log_debug { sign_message("received beacon: #{beacon.inspect} from #{addr}") } case beacon.beacon_type when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT @@ -140,7 +140,9 @@ def run end remove_expired_listings - end + rescue => e + log_debug { sign_message("error: (#{e.class}) #{e.message}") } + end while true end def running? @@ -149,30 +151,37 @@ def running? def start unless running? - log_debug { sign_message("starting service directory") } - + log_debug { sign_message("starting") } init_socket - - @thread = Thread.new do - begin - self.run - rescue => e - log_debug { sign_message("error: (#{e.class}) #{e.message}") } - raise - end - end + @thread = Thread.new { self.run } end self end def stop + log_debug { sign_message("stopping") } + @mutex.synchronize do @thread.try(:kill) + @thread = nil @listings = {} end @socket.try(:close) + @socket = nil + end + + def youngest_listing_for(service) + @mutex.synchronize do + listings = @listings.values.select do |listing| + listing.services.any? do |listed_service| + listing.current? && listed_service.to_s == service.to_s + end + end + + listings.sort.first + end end private diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index e0cae3e9..6a31dfc2 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -4,14 +4,13 @@ describe ::Protobuf::Rpc::ServiceDirectory do let(:instance) { ::Protobuf::Rpc::ServiceDirectory.instance } - let(:server) { double('server', :uuid => '123', - :services => ['Known::Service'], - :address => "0.0.0.0", - :port => 9999, - :ttl => 15) } + + def listings + instance.instance_variable_get(:@listings) + end before(:all) do - ::Protobuf::Rpc::ServiceDirectory.timeout = 0.5 + ::Protobuf::Rpc::ServiceDirectory.timeout = 0.1 end after do @@ -23,6 +22,12 @@ end describe "#find" do + let(:server) { double('server', :uuid => '123', + :services => ['Known::Service'], + :address => "0.0.0.0", + :port => 9999, + :ttl => 15) } + it "times out when nothing is found" do expect { instance.find("Unknown::Service") @@ -33,6 +38,20 @@ instance.add_listing_for(server) instance.find("Known::Service").should eq [server.address, server.port] end + + it "does not return expired listings" do + server.stub(:ttl => 0) + instance.add_listing_for(server) + expect { + instance.find("Known::Service") + }.to raise_error(::Protobuf::Rpc::ServiceDirectory::ServiceNotFound) + end + + it "delegates to #youngest_listing_for" do + instance.should_receive(:youngest_listing_for).with("Known::Service") { double(:address => '0.0.0.0', :port => 9398) } + instance.add_listing_for(server) + instance.find("Known::Service") + end end describe "#remove_expired_listings" do @@ -47,7 +66,90 @@ it "removes expired listings" do expect { instance.remove_expired_listings - }.to change(instance, :listing_count).from(3).to(1) + }.to change(listings, :size).from(3).to(1) + listings.keys.should eq ['3'] + end + end + + describe "#start" do + it "creates a thread" do + Thread.should_receive(:new) + instance.start + end + + it "initializes the socket" do + instance.should_receive :init_socket + instance.start + end + + it "calls #run" do + instance.should_receive(:run) + instance.start + sleep 0.01 + end + + it "changes the running state" do + expect { + instance.start + }.to change(instance, :running?).from(false).to(true) + end + end + + describe "#youngest_listing_for" do + it "returns the youngest listing" do + instance.add_listing_for double(:uuid => 1, :ttl => 5, :services => ["Test"]) + instance.add_listing_for double(:uuid => 2, :ttl => 15, :services => ["Test"]) + instance.add_listing_for double(:uuid => 3, :ttl => 10, :services => ["Test"]) + instance.youngest_listing_for("Test").uuid.should eq 2 + end + end + + describe "a running service directory" do + let(:socket) { UDPSocket.new } + + def thread + instance.instance_variable_get(:@thread) + end + + before do + described_class.start do |config| + config.address = "127.0.0.1" + config.port = 33333 + end + + socket.connect described_class.address, described_class.port + end + + context "receiving a heartbeat" do + let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'heartbeat') } + let(:beacon) { ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( + :server => server, + :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT + )} + let(:payload) { beacon.serialize_to_string } + + it "adds a listing" do + instance.should_receive(:add_listing_for).with(server) + instance.should_receive(:remove_expired_listings) + socket.send(payload, 0) + sleep 0.01 + end + end + + context "receiving a flatline" do + let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'flatline') } + let(:beacon) { ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( + :server => server, + :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE + )} + let(:payload) { beacon.serialize_to_string } + + it "removes a listing" do + instance.should_receive(:remove_listing_for).with(server) + instance.should_receive(:remove_expired_listings) + socket.send(payload, 0) + sleep 0.01 + end end end end From 69fb457c3edbea16166a2efccac116bda5ba7d7d Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 3 Jun 2013 16:08:36 -0600 Subject: [PATCH 0381/1191] Incorporate the lazy pirate from @localshred --- lib/protobuf/rpc/connectors/zmq.rb | 202 ++++++++++++++++++++++------- 1 file changed, 158 insertions(+), 44 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 0180dee9..b55403a6 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -5,81 +5,195 @@ module Protobuf module Rpc module Connectors class Zmq < Base + + ## + # Included Modules + # + include Protobuf::Rpc::Connectors::Common include Protobuf::Logger::LogMethods + ## + # Class Constants + # + + CLIENT_RETRIES = (ENV['PB_CLIENT_RETRIES'] || 3) + + ## + # Instance methods + # + + # Start the request/response cycle. We implement the Lazy Pirate + # req/reply reliability pattern as laid out in the ZMQ Guide, Chapter 4. + # + # @see http://zguide.zeromq.org/php:chapter4#Client-side-Reliability-Lazy-Pirate-Pattern + # def send_request - timeout_wrap do - setup_connection - connect_to_rpc_server - post_init - read_response - end + setup_connection + poll_send_data ensure - @socket.try :close - @zmq_context.try :terminate - @zmq_context = nil + close_connection end def log_signature @_log_signature ||= "[client-#{self.class}]" end - def service_directory - ::Protobuf::Rpc::ServiceDirectory.instance - end - - def service_uri - if service_directory.running? - address, port = service_directory.find options[:service] - else - address, port = options[:host], options[:port] - end - - "tcp://#{address}:#{port}" - end - private + ## + # Private Instance methods + # + def close_connection - return if @error - zmq_error_check(@socket.close) - zmq_error_check(@zmq_context.terminate) - log_debug { sign_message("Connector closed") } + socket_close + zmq_context_terminate end + # Establish a request socket connection to the remote rpc_server. + # Set the socket option LINGER to 0 so that we don't wait + # for queued messages to be accepted when the socket/context are + # asked to close/terminate. + # def connect_to_rpc_server - return if @error - log_debug { sign_message("Establishing connection: #{service_uri}") } - @zmq_context = ::ZMQ::Context.new - @socket = @zmq_context.socket(::ZMQ::REQ) - zmq_error_check(@socket.connect(service_uri)) - log_debug { sign_message("Connection established #{service_uri}") } + return if error? + + log_debug { sign_message("Establishing connection: #{server_uri}") } + socket.setsockopt(::ZMQ::LINGER, 0) + zmq_error_check(socket.connect(server_uri), :socket_connect) + zmq_error_check(poller.register_readable(socket), :poller_register_readable) + log_debug { sign_message("Connection established to #{server_uri}") } end - # Method to determine error state, must be used with Connector api + # Method to determine error state, must be used with Connector API. + # def error? - !!@error + !! @error + end + + # Trying a number of times, attempt to get a response from the server. + # If we haven't received a legitimate response in the CLIENT_RETRIES number + # of retries, fail the request. + # + def poll_send_data + return if error? + + poll_timeout = (options[:timeout].to_f / CLIENT_RETRIES.to_f) * 1000 + + CLIENT_RETRIES.times do |n| + connect_to_rpc_server + log_debug { sign_message("Sending Request (attempt #{n + 1}, #{socket})") } + send_data + log_debug { sign_message("Request sending complete (attempt #{n + 1}, #{socket})") } + + if poller.poll(poll_timeout) == 1 + read_response + return + else + close_connection + end + end + + fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond") + end + + def poller + @poller ||= ::ZMQ::Poller.new end + # Read the string response from the available readable. This will be + # the current @socket. Calls `parse_response` to invoke the success or + # failed callbacks, depending on the state of the communication + # and response data. + # def read_response - return if @error - @response_data = '' - zmq_error_check(@socket.recv_string(@response_data)) + return if error? + + poller.readables.each do |readable| + @response_data = '' + zmq_error_check(readable.recv_string(@response_data), :socket_recv_string) + end + parse_response end + # Send the request data to the remote rpc_server. + # def send_data - return if @error - log_debug { sign_message("Sending Request: #{@request_data}") } + return if error? + @stats.request_size = @request_data.size - zmq_error_check(@socket.send_string(@request_data)) - log_debug { sign_message("write closed") } + zmq_error_check(socket.send_string(@request_data), :socket_send_string) end - def zmq_error_check(return_code) - raise "Last API call failed at #{caller(1)}" unless return_code >= 0 + # The location of the server. If the ServiceDirectory is running then + # we ask it for a server that hosts the requested service. If it is + # not running, or it cannot be found, we fallback to the options. + # + def server_uri + if service_directory.running? + listing = service_directory.find(service) rescue nil + host, port = listing.address, listing.port if listing + end + + host, port = options[:host], options[:port] unless host && port + + "tcp://#{host}:#{port}" end + + # The service we're attempting to connect to + # + def service + options[:service] + end + + # Alias for ::Protobuf::Rpc::ServiceDirectory.instance + def service_directory + ::Protobuf::Rpc::ServiceDirectory.instance + end + + # Setup a ZMQ request socket in the current zmq context. + # + def socket + @socket ||= zmq_context.socket(::ZMQ::REQ) + end + + def socket_close + if socket + log_debug { sign_message("Closing Socket") } + zmq_error_check(socket.close, :socket_close) + log_debug { sign_message("Socket closed") } + @socket = nil + end + end + + # Return the ZMQ Context to use for this process. + # If the context does not exist, create it, then register + # an exit block to ensure the context is terminated correctly. + # + def zmq_context + @zmq_context ||= ::ZMQ::Context.new + end + + # Terminate the zmq_context (if any). + # + def zmq_context_terminate + log_debug { sign_message("Terminating ZMQ Context") } + @zmq_context.try(:terminate) + @zmq_context = nil + log_debug { sign_message("ZMQ Context terminated") } + end + + def zmq_error_check(return_code, source) + unless ::ZMQ::Util.resultcode_ok?(return_code || -1) + raise <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + end + end + end end end From a489cbc98a2320b19a4bd76b658c57b663ac5791 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Jun 2013 10:26:02 -0600 Subject: [PATCH 0382/1191] Add tests around the service directory --- lib/protobuf/rpc/servers/socket/server.rb | 3 +- lib/protobuf/rpc/service_directory.rb | 6 ++- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 44 ++++++++++++++++++- .../protobuf/rpc/service_directory_spec.rb | 23 +++++----- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index b837a815..94a38dfa 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -66,8 +66,9 @@ def run while running? log_debug { sign_message("Waiting for connections") } + ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) rescue nil - if ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) + if ready_cnxns cnxns = ready_cnxns.first cnxns.each do |client| case diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index f51c1a8c..09019c90 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -38,6 +38,10 @@ def expired? Time.now.to_i >= @expires_at end + def ttl + [super.to_i, 3].max + end + def __getobj__ @server end @@ -100,7 +104,7 @@ def find(service) log_debug { sign_message("found #{service} at #{listing.inspect}") } - [listing.address, listing.port] + listing end def remove_expired_listings diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index eeca9fc8..8151f752 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -2,6 +2,16 @@ require 'protobuf/zmq' describe ::Protobuf::Rpc::Connectors::Zmq do + subject { described_class.new(options) } + + let(:options) {{ + :service => "Test::Service", + :method => "find", + :timeout => 3, + :host => "127.0.0.1", + :port => "9400" + }} + let(:socket_mock) do sm = mock(::ZMQ::Socket) sm.stub(:connect).and_return(0) @@ -14,9 +24,41 @@ zc end - before(:each) do + before do ::ZMQ::Context.stub(:new).and_return(zmq_context_mock) end + describe "#server_uri" do + let(:service_directory) { double('ServiceDirectory', :running? => running? ) } + let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) } + let(:running?) { true } + + before do + subject.stub(:service_directory) { service_directory } + end + + context "when the service directory is running" do + it "searches the service directory" do + service_directory.should_receive(:find).and_return(listing) + subject.send(:server_uri).should eq "tcp://127.0.0.2:9399" + end + + it "defaults to the options" do + service_directory.should_receive(:find).and_raise(RuntimeError) + subject.send(:server_uri).should eq "tcp://127.0.0.1:9400" + end + end + + context "when the service directory is not running" do + let(:running?) { false } + + it "does not search the directory" do + service_directory.should_not_receive(:find) + subject.send(:server_uri).should eq "tcp://127.0.0.1:9400" + end + end + + end + pending end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 6a31dfc2..c7e597bd 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -27,6 +27,7 @@ def listings :address => "0.0.0.0", :port => 9999, :ttl => 15) } + let(:listing) { ::Protobuf::Rpc::ServiceDirectory::Listing.new(server) } it "times out when nothing is found" do expect { @@ -36,20 +37,12 @@ def listings it "returns a listing for the given service" do instance.add_listing_for(server) - instance.find("Known::Service").should eq [server.address, server.port] - end - - it "does not return expired listings" do - server.stub(:ttl => 0) - instance.add_listing_for(server) - expect { - instance.find("Known::Service") - }.to raise_error(::Protobuf::Rpc::ServiceDirectory::ServiceNotFound) + instance.find("Known::Service").should eq listing end it "delegates to #youngest_listing_for" do - instance.should_receive(:youngest_listing_for).with("Known::Service") { double(:address => '0.0.0.0', :port => 9398) } - instance.add_listing_for(server) + instance.should_receive(:youngest_listing_for) + .with("Known::Service") { double('listing') } instance.find("Known::Service") end end @@ -102,6 +95,14 @@ def listings instance.add_listing_for double(:uuid => 3, :ttl => 10, :services => ["Test"]) instance.youngest_listing_for("Test").uuid.should eq 2 end + + it "does not return expired listings" do + instance.instance_variable_set(:@listings, { + '1' => double(:current? => false, :services => ["Test"]), + }) + + instance.youngest_listing_for("Test").should be_nil + end end describe "a running service directory" do From 93831dc99b81ef07f4b4164b10c60a6e2e3456fd Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Jun 2013 12:34:54 -0600 Subject: [PATCH 0383/1191] Add additional options for the zmq server --- lib/protobuf/rpc/servers/zmq/server.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index fff03713..90f0b7c2 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -10,7 +10,12 @@ module Zmq class Server include ::Protobuf::Rpc::Zmq::Util - DEFAULT_OPTIONS = { :beacon_interval => 5 } + DEFAULT_OPTIONS = { + :beacon_address => "255.255.255.255", + :beacon_interval => 5, + :beacon_port => 9398, + :broadcast_beacons => false + } attr_accessor :options @@ -43,7 +48,7 @@ def beacon_interval end def beacon_ip - "255.255.255.255" + @beacon_ip ||= resolve_ip(options[:beacon_address]) end def beacon_port From eab132d0e4ceef78a9b02c57fcfc81a76c1c8618 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Jun 2013 16:07:55 -0600 Subject: [PATCH 0384/1191] Refactor DirectoryService#find --- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 93 ++++++++----------- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 6 +- .../protobuf/rpc/service_directory_spec.rb | 77 ++++++++++----- 4 files changed, 97 insertions(+), 81 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b55403a6..863f8bb5 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -132,7 +132,7 @@ def send_data # def server_uri if service_directory.running? - listing = service_directory.find(service) rescue nil + listing = service_directory.lookup(service) host, port = listing.address, listing.port if listing end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 09019c90..66383827 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -14,9 +14,7 @@ class ServiceDirectory DEFAULT_ADDRESS = "0.0.0.0" DEFAULT_PORT = 9398 - DEFAULT_TIMEOUT = 5 - - ServiceNotFound = Class.new(RuntimeError) + DEFAULT_TIMEOUT = 1 class Listing < Delegator attr_reader :expires_at @@ -26,10 +24,6 @@ def initialize(server) @expires_at = Time.now.to_i + ttl end - def <=>(other) - other.expires_at <=> self.expires_at - end - def current? !expired? end @@ -50,7 +44,7 @@ def __getobj__ # Class Methods # class << self - attr_writer :address, :port, :timeout + attr_writer :address, :port end def self.address @@ -70,10 +64,6 @@ def self.stop self.instance.stop end - def self.timeout - @timeout ||= DEFAULT_TIMEOUT - end - # Instance Methods # def initialize @@ -94,17 +84,18 @@ def add_listing_for(server) end end - def find(service) - listing = nil - log_debug { sign_message("searching for #{service}") } - - Timeout.timeout(self.class.timeout, ServiceNotFound) do - Thread.pass until listing = youngest_listing_for(service) - end + def lookup(service) + log_debug { sign_message("lookup #{service}") } - log_debug { sign_message("found #{service} at #{listing.inspect}") } + @mutex.synchronize do + listings = @listings.values.select do |listing| + listing.services.any? do |listed_service| + listing.current? && listed_service == service.to_s + end + end - listing + listings.sample + end end def remove_expired_listings @@ -128,27 +119,6 @@ def remove_listing_for(server) end end - def run - begin - data, addr = @socket.recvfrom(1024) - beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new - beacon.parse_from_string(data) rescue nil - - log_debug { sign_message("received beacon: #{beacon.inspect} from #{addr}") } - - case beacon.beacon_type - when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT - add_listing_for(beacon.server) - when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE - remove_listing_for(beacon.server) - end - - remove_expired_listings - rescue => e - log_debug { sign_message("error: (#{e.class}) #{e.message}") } - end while true - end - def running? !!@thread.try(:alive?) end @@ -157,7 +127,7 @@ def start unless running? log_debug { sign_message("starting") } init_socket - @thread = Thread.new { self.run } + @thread = Thread.new { self.send(:run) } end self @@ -176,16 +146,14 @@ def stop @socket = nil end - def youngest_listing_for(service) - @mutex.synchronize do - listings = @listings.values.select do |listing| - listing.services.any? do |listed_service| - listing.current? && listed_service.to_s == service.to_s - end - end - - listings.sort.first + def wait_for(service, timeout = DEFAULT_TIMEOUT) + log_debug { sign_message("waiting for #{service}") } + Timeout.timeout(timeout) do + sleep(timeout / 10.0) until listing = lookup(service) + listing end + rescue + nil end private @@ -194,6 +162,27 @@ def init_socket @socket = UDPSocket.new @socket.bind(self.class.address, self.class.port) end + + def run + begin + data, addr = @socket.recvfrom(2048) + beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new + beacon.parse_from_string(data) rescue nil + + log_debug { sign_message("received beacon: #{beacon.inspect} from #{addr}") } + + case beacon.beacon_type + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT + add_listing_for(beacon.server) + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE + remove_listing_for(beacon.server) + end + + remove_expired_listings + rescue => e + log_debug { sign_message("error: (#{e.class}) #{e.message}") } + end while true + end end end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 8151f752..7e32c41e 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -39,12 +39,12 @@ context "when the service directory is running" do it "searches the service directory" do - service_directory.should_receive(:find).and_return(listing) + service_directory.should_receive(:lookup).and_return(listing) subject.send(:server_uri).should eq "tcp://127.0.0.2:9399" end it "defaults to the options" do - service_directory.should_receive(:find).and_raise(RuntimeError) + service_directory.should_receive(:lookup) { nil } subject.send(:server_uri).should eq "tcp://127.0.0.1:9400" end end @@ -53,7 +53,7 @@ let(:running?) { false } it "does not search the directory" do - service_directory.should_not_receive(:find) + service_directory.should_not_receive(:lookup) subject.send(:server_uri).should eq "tcp://127.0.0.1:9400" end end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index c7e597bd..31d41e49 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -9,8 +9,10 @@ def listings instance.instance_variable_get(:@listings) end - before(:all) do - ::Protobuf::Rpc::ServiceDirectory.timeout = 0.1 + def duration + start = Time.now.to_f + yield + Time.now.to_f - start end after do @@ -21,7 +23,7 @@ def listings instance.should be_a_kind_of(Singleton) end - describe "#find" do + describe "#lookup" do let(:server) { double('server', :uuid => '123', :services => ['Known::Service'], :address => "0.0.0.0", @@ -29,21 +31,26 @@ def listings :ttl => 15) } let(:listing) { ::Protobuf::Rpc::ServiceDirectory::Listing.new(server) } - it "times out when nothing is found" do - expect { - instance.find("Unknown::Service") - }.to raise_error(::Protobuf::Rpc::ServiceDirectory::ServiceNotFound) - end - it "returns a listing for the given service" do instance.add_listing_for(server) - instance.find("Known::Service").should eq listing + instance.lookup("Known::Service").should eq listing + end + + it "returns random listings" do + instance.add_listing_for double(:uuid => 1, :ttl => 5, :services => ["Test"]) + instance.add_listing_for double(:uuid => 2, :ttl => 5, :services => ["Test"]) + + uuids = 100.times.map { instance.lookup("Test").uuid } + uuids.count(1).should be_within(25).of(50) + uuids.count(2).should be_within(25).of(50) end - it "delegates to #youngest_listing_for" do - instance.should_receive(:youngest_listing_for) - .with("Known::Service") { double('listing') } - instance.find("Known::Service") + it "does not return expired listings" do + instance.instance_variable_set(:@listings, { + '1' => double(:current? => false, :services => ["Test"]), + }) + + instance.lookup("Test").should be_nil end end @@ -88,20 +95,40 @@ def listings end end - describe "#youngest_listing_for" do - it "returns the youngest listing" do - instance.add_listing_for double(:uuid => 1, :ttl => 5, :services => ["Test"]) - instance.add_listing_for double(:uuid => 2, :ttl => 15, :services => ["Test"]) - instance.add_listing_for double(:uuid => 3, :ttl => 10, :services => ["Test"]) - instance.youngest_listing_for("Test").uuid.should eq 2 + describe "#wait_for" do + it "returns a listing for the given service" do + server = double(:uuid => 1, :ttl => 5, :services => ["Test"]) + instance.add_listing_for server + instance.lookup("Test").should eq server end - it "does not return expired listings" do - instance.instance_variable_set(:@listings, { - '1' => double(:current? => false, :services => ["Test"]), - }) + it "depends on #lookup" do + instance.stub(:lookup).with("Hayoob!") { "yup" } + instance.wait_for("Hayoob!").should eq "yup" + end + + it "waits for the service to appear" do + server = double(:uuid => 1, :ttl => 5, :services => ["Test"]) + + t = Thread.new do + sleep 0.5 + instance.add_listing_for server + end + + duration { instance.wait_for("Test") }.should be_within(0.01).of(0.5) + t.join + end + + it "returns nil if the service doesn't appear withint the timeout period" do + server = double(:uuid => 1, :ttl => 5, :services => ["Test"]) + + t = Thread.new do + sleep 0.5 + instance.add_listing_for server + end - instance.youngest_listing_for("Test").should be_nil + instance.wait_for("Test", 0.1).should be_nil + t.join end end From 44857e626ec403837b51bb3c31d962bc03752439 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 5 Jun 2013 10:27:01 -0600 Subject: [PATCH 0385/1191] Require 'ostruct' before using it --- lib/protobuf/rpc/servers/zmq_runner.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index f1219d9e..9911cc3c 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -1,3 +1,5 @@ +require 'ostruct' + module Protobuf module Rpc class ZmqRunner From b4b431d4d6eb0b564cfd66411e35df29425a54ec Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 5 Jun 2013 11:20:12 -0600 Subject: [PATCH 0386/1191] Include Thor::Actions in the CLI --- lib/protobuf/cli.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index c1810fce..2a0ae23d 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -7,6 +7,8 @@ module Protobuf class CLI < ::Thor + include ::Thor::Actions + attr_accessor :runner, :mode default_task :start @@ -168,7 +170,7 @@ def require_application!(app_file) # Loads protobuf in the given mode, exiting if somehow the mode is wrong. def require_protobuf! - require "protobuf/#{@mode}.rb" + require "protobuf/#{@mode}" rescue LoadError => e puts e.message, *(e.backtrace) say_and_exit!("Failed to load protobuf runner #{@mode}", e) From 3f58484200c4d04ed449e3534eb5a8d7bff54f9f Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 5 Jun 2013 11:24:26 -0600 Subject: [PATCH 0387/1191] Require the server before creating the runner --- lib/protobuf/cli.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 2a0ae23d..5f634823 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -42,7 +42,6 @@ def start(app_file) configure_logger configure_traps configure_server_mode - require_protobuf! configure_gc configure_deprecation_warnings @@ -168,14 +167,6 @@ def require_application!(app_file) say_and_exit!("Failed to load application file #{app_file}", e) end - # Loads protobuf in the given mode, exiting if somehow the mode is wrong. - def require_protobuf! - require "protobuf/#{@mode}" - rescue LoadError => e - puts e.message, *(e.backtrace) - say_and_exit!("Failed to load protobuf runner #{@mode}", e) - end - def runner_options { :host => options.host, @@ -204,16 +195,22 @@ def say_and_exit!(message, exception = nil) end def server_evented! + require 'protobuf/evented' + @mode = :evented @runner = ::Protobuf::Rpc::EventedRunner.new(runner_options) end def server_socket! + require 'protobuf/socket' + @mode = :socket @runner = ::Protobuf::Rpc::SocketRunner.new(runner_options) end def server_zmq! + require 'protobuf/zmq' + @mode = :zmq @runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) end From 914f5c59517cc399445a7e33d75a97ad72b84e4e Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 5 Jun 2013 11:39:53 -0600 Subject: [PATCH 0388/1191] Add CLI configuration for beacon address and port --- lib/protobuf/cli.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 5f634823..a1aec37c 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -30,6 +30,8 @@ class CLI < ::Thor option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' option :broadcast_beacons, :type => :boolean, :default => false, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' + option :beacon_address, :type => :string, :desc => 'Broadcast beacons to this address' + option :beacon_port, :type => :string, :desc => 'Broadcast beacons to this port' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' @@ -37,6 +39,8 @@ class CLI < ::Thor option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)" def start(app_file) + $rpc_server = true + debug_say 'Configuring the rpc_server process' configure_logger From b5e378af4cc7fa3783f1687b6d9ccccd7792e6db Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 5 Jun 2013 11:48:57 -0600 Subject: [PATCH 0389/1191] Log heartbeat beacons --- lib/protobuf/rpc/servers/zmq/server.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 90f0b7c2..99956a53 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -55,6 +55,10 @@ def beacon_port options[:beacon_port].to_i end + def beacon_uri + "udp://#{beacon_ip}:#{beacon_port}" + end + def broadcast_beacons? !brokerless? && options[:broadcast_beacons] end @@ -75,6 +79,8 @@ def broadcast_heartbeat ) @beacon_socket.send heartbeat.serialize_to_string, 0 + + log_debug { sign_message("sent heartbeat to #{beacon_uri}") } end def brokerless? From 6db51982d239bda053a52d126e10281fc43dd379 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 5 Jun 2013 11:52:57 -0600 Subject: [PATCH 0390/1191] Symbolize option keys in zmq server --- lib/protobuf/rpc/servers/zmq/server.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 99956a53..cf1dbd48 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -20,6 +20,9 @@ class Server attr_accessor :options def initialize(options) + # Symbolize keys + options.inject({}) {|h,(k,v)| h[k.to_sym] = v; h} + @options = DEFAULT_OPTIONS.merge(options) @workers = [] From 7618f4d99ca6c6347cb40eceb53241b64bd0d3d8 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 6 Jun 2013 13:34:58 -0600 Subject: [PATCH 0391/1191] Fixes and improvements --- lib/protobuf/cli.rb | 19 +++++++------------ lib/protobuf/rpc/connectors/zmq.rb | 6 ++---- lib/protobuf/rpc/servers/zmq/server.rb | 5 +---- lib/protobuf/rpc/service.rb | 7 +------ lib/protobuf/rpc/service_directory.rb | 2 -- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index a1aec37c..819dd2f4 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -29,9 +29,9 @@ class CLI < ::Thor option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' - option :broadcast_beacons, :type => :boolean, :default => false, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' + option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' option :beacon_address, :type => :string, :desc => 'Broadcast beacons to this address' - option :beacon_port, :type => :string, :desc => 'Broadcast beacons to this port' + option :beacon_port, :type => :numeric, :desc => 'Broadcast beacons to this port' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' @@ -140,7 +140,7 @@ def configure_traps trap(signal) do @exit_requested = true - shutdown_server + shutdown_server! end end end @@ -172,15 +172,10 @@ def require_application!(app_file) end def runner_options - { - :host => options.host, - :port => options.port, - :backlog => options.backlog, - :threshold => options.threshold, - :threads => options.threads, - :worker_port => options.worker_port || (options.port + 1), - :workers_only => !!ENV['PB_WORKERS_ONLY'] || options.workers_only - } + opt = options.inject({}){|h,(k,v)|h[k.to_sym]=v;h} # Symbolize keys + opt[:workers_only] = !!ENV['PB_WORKERS_ONLY'] || options.workers_only + + opt end def say_and_exit!(message, exception = nil) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 863f8bb5..004635c0 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -109,10 +109,8 @@ def poller def read_response return if error? - poller.readables.each do |readable| - @response_data = '' - zmq_error_check(readable.recv_string(@response_data), :socket_recv_string) - end + @response_data = '' + zmq_error_check(socket.recv_string(@response_data), :socket_recv_string) parse_response end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index cf1dbd48..acfcfd6e 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -20,9 +20,6 @@ class Server attr_accessor :options def initialize(options) - # Symbolize keys - options.inject({}) {|h,(k,v)| h[k.to_sym] = v; h} - @options = DEFAULT_OPTIONS.merge(options) @workers = [] @@ -39,7 +36,7 @@ def backend_ip end def backend_port - options[:worker_port] + options[:worker_port] || frontend_port + 1 end def backend_uri diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 50b221a6..c708de58 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -54,11 +54,6 @@ def self.host=(new_host) @_host = new_host end - def self.inherited(subclass) - @_subclasses ||= [] - @_subclasses << subclass - end - # Shorthand call to configure, passing a string formatted as hostname:port # e.g. 127.0.0.1:9933 # e.g. localhost:0 @@ -104,7 +99,7 @@ def self.rpc_method?(name) # An array of defined service classes that contain implementation # code def self.implemented_services - classes = (@_subclasses || []).select do |subclass| + classes = (self.subclasses || []).select do |subclass| subclass.rpcs.any? do |(name, method)| subclass.method_defined? name end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 66383827..346839ac 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -73,8 +73,6 @@ def initialize def add_listing_for(server) if server && server.uuid - log_debug { sign_message("Adding listing for server: #{server.inspect}") } - @mutex.synchronize do @listings[server.uuid] = Listing.new(server) end From 0e59c5dc4c1205c8720b485c46b183d52824ecb0 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 6 Jun 2013 13:59:11 -0600 Subject: [PATCH 0392/1191] Remove global --- lib/protobuf/cli.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 819dd2f4..fe8b0ca9 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -39,8 +39,6 @@ class CLI < ::Thor option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)" def start(app_file) - $rpc_server = true - debug_say 'Configuring the rpc_server process' configure_logger From c4117ea47a4779c46f794d35cb3128f6256ce038 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 6 Jun 2013 14:23:12 -0600 Subject: [PATCH 0393/1191] Allow multiple service directories per machine --- lib/protobuf/rpc/service_directory.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 346839ac..20ae6fd2 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -158,6 +158,7 @@ def wait_for(service, timeout = DEFAULT_TIMEOUT) def init_socket @socket = UDPSocket.new + @socket.setsockopt(:SOCKET, :REUSEADDR, true) @socket.bind(self.class.address, self.class.port) end From b4cdec76d75fd94f5879bc08c6be9d10bdccafe3 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 6 Jun 2013 16:44:59 -0600 Subject: [PATCH 0394/1191] JRuby does not support shorthand sockopts --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index acfcfd6e..70de2b83 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -234,7 +234,7 @@ def wait_for_shutdown_signal def init_beacon_socket @beacon_socket = UDPSocket.new - @beacon_socket.setsockopt :SOCKET, :BROADCAST, true + @beacon_socket.setsockopt Socket::SOL_SOCKET, Socket::SO_BROADCAST, true @beacon_socket.connect beacon_ip, beacon_port end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 20ae6fd2..8b5f8bb6 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -158,7 +158,7 @@ def wait_for(service, timeout = DEFAULT_TIMEOUT) def init_socket @socket = UDPSocket.new - @socket.setsockopt(:SOCKET, :REUSEADDR, true) + @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) @socket.bind(self.class.address, self.class.port) end From 208cc78c4b0fd6eaac32ea348e994601c66a994b Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 6 Jun 2013 16:52:08 -0600 Subject: [PATCH 0395/1191] Fix specs --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 70de2b83..0b22467f 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -234,7 +234,7 @@ def wait_for_shutdown_signal def init_beacon_socket @beacon_socket = UDPSocket.new - @beacon_socket.setsockopt Socket::SOL_SOCKET, Socket::SO_BROADCAST, true + @beacon_socket.setsockopt ::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true @beacon_socket.connect beacon_ip, beacon_port end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 8b5f8bb6..fad13791 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -158,7 +158,7 @@ def wait_for(service, timeout = DEFAULT_TIMEOUT) def init_socket @socket = UDPSocket.new - @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) + @socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true) @socket.bind(self.class.address, self.class.port) end From 598b39b575dcbf536c0ebcd7575157a2a6f06c2f Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 14:13:23 -0600 Subject: [PATCH 0396/1191] Default beacons to directories port and address --- lib/protobuf/cli.rb | 5 +++-- lib/protobuf/rpc/servers/zmq/server.rb | 22 +++++++++++++++++----- lib/protobuf/rpc/service_directory.rb | 6 +++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index fe8b0ca9..4d96f7e3 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -29,9 +29,10 @@ class CLI < ::Thor option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' + option :beacon_address, :type => :string, :desc => 'Broadcast beacons to this address (defaul: value of ServiceDirectory.address)' + option :beacon_interval, :type => :numeric, :desc => 'Broadcast beacons every N seconds. (default: 5)' + option :beacon_port, :type => :numeric, :desc => 'Broadcast beacons to this port (default: value of ServiceDirectory.port)' option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' - option :beacon_address, :type => :string, :desc => 'Broadcast beacons to this address' - option :beacon_port, :type => :numeric, :desc => 'Broadcast beacons to this port' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 0b22467f..bd2bf23e 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -11,9 +11,7 @@ class Server include ::Protobuf::Rpc::Zmq::Util DEFAULT_OPTIONS = { - :beacon_address => "255.255.255.255", :beacon_interval => 5, - :beacon_port => 9398, :broadcast_beacons => false } @@ -48,11 +46,25 @@ def beacon_interval end def beacon_ip - @beacon_ip ||= resolve_ip(options[:beacon_address]) + unless @beacon_ip + unless address = options[:beacon_address] + address = ::Protobuf::Rpc::ServiceDirectory.address + end + + @beacon_ip = resolve_ip(address) + end + + @beacon_ip end def beacon_port - options[:beacon_port].to_i + unless @beacon_port + unless port = options[:beacon_port] + port = ::Protobuf::Rpc::ServiceDirectory.port + end + + @beacon_port = port.to_i + end end def beacon_uri @@ -192,7 +204,7 @@ def to_proto :uuid => uuid, :address => frontend_ip, :port => frontend_port.to_s, - :ttl => beacon_interval * 3, + :ttl => (beacon_interval * 1.5).ceil, :services => ::Protobuf::Rpc::Service.implemented_services ) end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index fad13791..178bf5b7 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -12,8 +12,8 @@ class ServiceDirectory include ::Singleton include ::Protobuf::Logger::LogMethods - DEFAULT_ADDRESS = "0.0.0.0" - DEFAULT_PORT = 9398 + DEFAULT_ADDRESS = "255.255.255.255" + DEFAULT_PORT = 53000 DEFAULT_TIMEOUT = 1 class Listing < Delegator @@ -52,7 +52,7 @@ def self.address end def self.port - @port ||= DEFAULT_PORT + (@port ||= DEFAULT_PORT).to_i end def self.start From 13699c39d0bc9d6fec2075c4d528c7e530e464cc Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 14:48:12 -0600 Subject: [PATCH 0397/1191] It helps to return stuffs --- lib/protobuf/rpc/servers/zmq/server.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index bd2bf23e..8aed3e6b 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -65,6 +65,8 @@ def beacon_port @beacon_port = port.to_i end + + @beacon_port end def beacon_uri From 38e773fbe22ffd67308595d571a52cb6961bcb0b Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 15:21:28 -0600 Subject: [PATCH 0398/1191] Shutdown the service directory if it's running --- lib/protobuf/cli.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 4d96f7e3..87d639ee 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -216,6 +216,7 @@ def server_zmq! def shutdown_server! ::Protobuf::Logger.info { 'RPC Server shutting down...' } @runner.try :stop + ::Protobuf::Rpc::ServiceDirectory.instance.stop ::Protobuf::Logger.info { 'Shutdown complete' } end From 84094c0ca3f517c3e2a85c501caf3f9bff4fa754 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 15:57:02 -0600 Subject: [PATCH 0399/1191] Defer server creation This gives the application time to load and make any needed configuration changes. --- lib/protobuf/rpc/servers/zmq_runner.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 9911cc3c..656c634a 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -15,21 +15,21 @@ def initialize(options) raise "Cannot parser Zmq Server - server options" end - @server = ::Protobuf::Rpc::Zmq::Server.new(@options) end def run + @server = ::Protobuf::Rpc::Zmq::Server.new(@options) register_signals yield if block_given? @server.run end def running? - @server.running? + @server.try :running? end def stop - @server.stop + @server.try :stop end private From c9ca7e31952b13668372dfaff5794a032a577856 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 15:59:23 -0600 Subject: [PATCH 0400/1191] Make the caller responsible for casting --- lib/protobuf/rpc/service_directory.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 178bf5b7..44222e5f 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -52,7 +52,7 @@ def self.address end def self.port - (@port ||= DEFAULT_PORT).to_i + @port ||= DEFAULT_PORT end def self.start @@ -159,7 +159,7 @@ def wait_for(service, timeout = DEFAULT_TIMEOUT) def init_socket @socket = UDPSocket.new @socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true) - @socket.bind(self.class.address, self.class.port) + @socket.bind(self.class.address, self.class.port.to_i) end def run From 6b365f1ccbf170ae030bf8d7e687154e7ff1f84f Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 16:00:32 -0600 Subject: [PATCH 0401/1191] Improve service directory logging --- lib/protobuf/rpc/service_directory.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 44222e5f..e1c7576d 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -73,6 +73,12 @@ def initialize def add_listing_for(server) if server && server.uuid + + log_debug do + action = @listings[server.uuid] ? "Updating" : "Adding"; + sign_message("#{action} server: #{server.inspect}") + end + @mutex.synchronize do @listings[server.uuid] = Listing.new(server) end @@ -123,8 +129,8 @@ def running? def start unless running? - log_debug { sign_message("starting") } init_socket + log_debug { sign_message("listining at udp://#{self.class.address}:#{self.class.port}") } @thread = Thread.new { self.send(:run) } end @@ -168,8 +174,6 @@ def run beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new beacon.parse_from_string(data) rescue nil - log_debug { sign_message("received beacon: #{beacon.inspect} from #{addr}") } - case beacon.beacon_type when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT add_listing_for(beacon.server) From 135fae42e292b8f1e01c4d0486839f584c4836e7 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 17:51:53 -0600 Subject: [PATCH 0402/1191] Fix typo --- lib/protobuf/rpc/service_directory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index e1c7576d..ab0c6f0b 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -130,7 +130,7 @@ def running? def start unless running? init_socket - log_debug { sign_message("listining at udp://#{self.class.address}:#{self.class.port}") } + log_debug { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } @thread = Thread.new { self.send(:run) } end From a2956b3b23489e2762602b245a67565086531001 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 18:11:39 -0600 Subject: [PATCH 0403/1191] Only lookup the server_uri once per connection --- lib/protobuf/rpc/connectors/zmq.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 004635c0..0bb6a4ea 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -58,11 +58,12 @@ def close_connection def connect_to_rpc_server return if error? - log_debug { sign_message("Establishing connection: #{server_uri}") } + uri = server_uri + log_debug { sign_message("Establishing connection: #{uri}") } socket.setsockopt(::ZMQ::LINGER, 0) - zmq_error_check(socket.connect(server_uri), :socket_connect) + zmq_error_check(socket.connect(uri), :socket_connect) zmq_error_check(poller.register_readable(socket), :poller_register_readable) - log_debug { sign_message("Connection established to #{server_uri}") } + log_debug { sign_message("Connection established to #{uri}") } end # Method to determine error state, must be used with Connector API. From 2161263f811ac68ac34bad6b330860559b7f8998 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 18:18:26 -0600 Subject: [PATCH 0404/1191] Add a restart method to the service directory This is useful for apps running unicorn. Call restart in the after_fork callback. --- lib/protobuf/rpc/service_directory.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index ab0c6f0b..5b957679 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -123,6 +123,11 @@ def remove_listing_for(server) end end + def restart + stop + start + end + def running? !!@thread.try(:alive?) end From 60c17aee23b6ab3fa25dfcccc45cb1ce2e85d967 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 7 Jun 2013 18:23:40 -0600 Subject: [PATCH 0405/1191] Favor the address captured by the socket --- lib/protobuf/rpc/service_directory.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 5b957679..a63041be 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -179,6 +179,9 @@ def run beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new beacon.parse_from_string(data) rescue nil + # Favor the address captured by the socket + beacon.try(:server).try(:address=, addr[3]) + case beacon.beacon_type when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT add_listing_for(beacon.server) From cff848089d6a2e8cf6243353099edfd6d70c47f5 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 10 Jun 2013 11:28:19 -0600 Subject: [PATCH 0406/1191] Rename server_uri to lookup_server_uri --- lib/protobuf/rpc/connectors/zmq.rb | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 0bb6a4ea..ac221164 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -58,12 +58,12 @@ def close_connection def connect_to_rpc_server return if error? - uri = server_uri - log_debug { sign_message("Establishing connection: #{uri}") } + server_uri = lookup_server_uri + log_debug { sign_message("Establishing connection: #{server_uri}") } socket.setsockopt(::ZMQ::LINGER, 0) - zmq_error_check(socket.connect(uri), :socket_connect) + zmq_error_check(socket.connect(server_uri), :socket_connect) zmq_error_check(poller.register_readable(socket), :poller_register_readable) - log_debug { sign_message("Connection established to #{uri}") } + log_debug { sign_message("Connection established to #{server_uri}") } end # Method to determine error state, must be used with Connector API. @@ -72,6 +72,21 @@ def error? !! @error end + # Lookup a server uri for the requested service in the service + # directory. If the service directory is not running, default + # to the host and port in the options + # + def lookup_server_uri + if service_directory.running? + listing = service_directory.lookup(service) + host, port = listing.address, listing.port if listing + end + + host, port = options[:host], options[:port] unless host && port + + "tcp://#{host}:#{port}" + end + # Trying a number of times, attempt to get a response from the server. # If we haven't received a legitimate response in the CLIENT_RETRIES number # of retries, fail the request. @@ -125,21 +140,6 @@ def send_data zmq_error_check(socket.send_string(@request_data), :socket_send_string) end - # The location of the server. If the ServiceDirectory is running then - # we ask it for a server that hosts the requested service. If it is - # not running, or it cannot be found, we fallback to the options. - # - def server_uri - if service_directory.running? - listing = service_directory.lookup(service) - host, port = listing.address, listing.port if listing - end - - host, port = options[:host], options[:port] unless host && port - - "tcp://#{host}:#{port}" - end - # The service we're attempting to connect to # def service From 7eb00e06dcd1b77cdf8da884c71d2ae7f6e8c4cd Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 10 Jun 2013 11:29:37 -0600 Subject: [PATCH 0407/1191] Reduce default timeout from 5 min to 15 sec --- lib/protobuf/rpc/connectors/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index e00c3889..eb7a2f52 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -17,7 +17,7 @@ module Connectors :request => nil, # The request object sent by the client :request_type => nil, # The request type expected by the client :response_type => nil, # The response type expected by the client - :timeout => 300, # The default timeout for the request, also handled by client.rb + :timeout => 15, # The default timeout for the request, also handled by client.rb :client_host => nil # The hostname or address of this client } From 8c1d1e29927121a7a5dd20ad33b87b8dd4d16849 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 10 Jun 2013 11:34:15 -0600 Subject: [PATCH 0408/1191] Update logging --- lib/protobuf/rpc/service_directory.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index a63041be..0a36d804 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -84,13 +84,11 @@ def add_listing_for(server) end else - log_debug { sign_message("Cannot add server without uuid: #{server.inspect}") } + log_info { sign_message("Cannot add server without uuid: #{server.inspect}") } end end def lookup(service) - log_debug { sign_message("lookup #{service}") } - @mutex.synchronize do listings = @listings.values.select do |listing| listing.services.any? do |listed_service| @@ -119,7 +117,7 @@ def remove_listing_for(server) end else - log_debug { sign_message("Cannot remove server without uuid: #{server.inspect}") } + log_info { sign_message("Cannot remove server without uuid: #{server.inspect}") } end end @@ -135,7 +133,7 @@ def running? def start unless running? init_socket - log_debug { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } + log_info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } @thread = Thread.new { self.send(:run) } end @@ -143,7 +141,7 @@ def start end def stop - log_debug { sign_message("stopping") } + log_info { sign_message("Stopping directory") } @mutex.synchronize do @thread.try(:kill) @@ -162,6 +160,7 @@ def wait_for(service, timeout = DEFAULT_TIMEOUT) listing end rescue + log_info { sign_message("no listing found for #{service}") } nil end From 09154fd9ec0429a2a170f5a461ab8e629ad1650e Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 10 Jun 2013 17:36:45 -0600 Subject: [PATCH 0409/1191] Fix whitespace --- lib/protobuf/rpc/error/client_error.rb | 10 +++++----- lib/protobuf/rpc/error/server_error.rb | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/rpc/error/client_error.rb b/lib/protobuf/rpc/error/client_error.rb index 5b65ed3b..19d161af 100644 --- a/lib/protobuf/rpc/error/client_error.rb +++ b/lib/protobuf/rpc/error/client_error.rb @@ -2,30 +2,30 @@ module Protobuf module Rpc - + class InvalidRequestProto < PbError def initialize(message='Invalid request type given') super message, 'INVALID_REQUEST_PROTO' end end - + class BadResponseProto < PbError def initialize(message='Bad response type from server') super message, 'BAD_RESPONSE_PROTO' end end - + class UnkownHost < PbError def initialize(message='Unknown host or port') super message, 'UNKNOWN_HOST' end end - + class IOError < PbError def initialize(message='IO Error occurred') super message, 'IO_ERROR' end end - + end end diff --git a/lib/protobuf/rpc/error/server_error.rb b/lib/protobuf/rpc/error/server_error.rb index f0191776..a37f0a37 100644 --- a/lib/protobuf/rpc/error/server_error.rb +++ b/lib/protobuf/rpc/error/server_error.rb @@ -2,42 +2,42 @@ module Protobuf module Rpc - + class BadRequestData < PbError def initialize message='Unable to parse request' super message, 'BAD_REQUEST_DATA' end end - + class BadRequestProto < PbError def initialize message='Request is of wrong type' super message, 'BAD_REQUEST_PROTO' end end - + class ServiceNotFound < PbError def initialize message='Service class not found' super message, 'SERVICE_NOT_FOUND' end end - + class MethodNotFound < PbError def initialize message='Service method not found' super message, 'METHOD_NOT_FOUND' end end - + class RpcError < PbError def initialize message='RPC exception occurred' super message, 'RPC_ERROR' end end - + class RpcFailed < PbError def initialize message='RPC failed' super message, 'RPC_FAILED' end end - + end end From 18f71258e13c90b1c71033a643d468171fa4d9a8 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 11 Jun 2013 10:21:10 -0600 Subject: [PATCH 0410/1191] Reconcile with comments from the pull request --- lib/protobuf/rpc/servers/zmq/broker.rb | 63 ++++++++++++------- lib/protobuf/rpc/servers/zmq/server.rb | 18 +++--- lib/protobuf/rpc/servers/zmq/worker.rb | 46 ++++++++------ spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 8 +-- .../protobuf/rpc/service_directory_spec.rb | 4 +- 5 files changed, 82 insertions(+), 57 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 2aae9006..0e339722 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -19,7 +19,19 @@ def initialize(server) end def join - @thread.try :join + @thread.try(:join) + end + + def read_from_backend + [].tap do |frames| + zmq_error_check(@backend_socket.recv_strings(frames)) + end + end + + def read_from_frontend + [].tap do |frames| + zmq_error_check(@frontend_socket.recv_strings(frames)) + end end def run @@ -31,15 +43,14 @@ def run case readable when @frontend_socket if idle_workers.any? - zmq_error_check(@frontend_socket.recv_strings frames = []) - frames.unshift(idle_workers.shift, "") - zmq_error_check(@backend_socket.send_strings frames) + frames = read_from_frontend + write_to_backend([idle_workers.shift, ""] + frames) end when @backend_socket - zmq_error_check(@backend_socket.recv_strings frames = []) - idle_workers << frames.shift(2)[0] + worker, ignore, *frames = read_from_backend + idle_workers << worker unless frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] - zmq_error_check(@frontend_socket.send_strings frames) + write_to_frontend(frames) end when @shutdown_socket throw :shutdown @@ -51,6 +62,14 @@ def run teardown end + def write_to_backend(frames) + zmq_error_check(@backend_socket.send_strings(frames)) + end + + def write_to_frontend(frames) + zmq_error_check(@frontend_socket.send_strings(frames)) + end + def start log_debug { sign_message("starting broker") } @@ -66,41 +85,41 @@ def shutdown_uri end def signal_shutdown - socket = @zmq_context.socket ZMQ::PAIR - zmq_error_check(socket.connect shutdown_uri) + socket = @zmq_context.socket(ZMQ::PAIR) + zmq_error_check(socket.connect(shutdown_uri)) zmq_error_check(socket.send_string ".") zmq_error_check(socket.close) end def teardown - @frontend_socket.try :close - @backend_socket.try :close - @shutdown_socket.try :close - @zmq_context.try :terminate + @frontend_socket.try(:close) + @backend_socket.try(:close) + @shutdown_socket.try(:close) + @zmq_context.try(:terminate) end private def init_backend_socket - @backend_socket = @zmq_context.socket ZMQ::ROUTER - zmq_error_check(@backend_socket.bind @server.backend_uri) + @backend_socket = @zmq_context.socket(ZMQ::ROUTER) + zmq_error_check(@backend_socket.bind(@server.backend_uri)) end def init_frontend_socket - @frontend_socket = @zmq_context.socket ZMQ::ROUTER - zmq_error_check(@frontend_socket.bind @server.frontend_uri) + @frontend_socket = @zmq_context.socket(ZMQ::ROUTER) + zmq_error_check(@frontend_socket.bind(@server.frontend_uri)) end def init_poller @poller = ZMQ::Poller.new - @poller.register_readable @frontend_socket - @poller.register_readable @backend_socket - @poller.register_readable @shutdown_socket + @poller.register_readable(@frontend_socket) + @poller.register_readable(@backend_socket) + @poller.register_readable(@shutdown_socket) end def init_shutdown_socket - @shutdown_socket = @zmq_context.socket ZMQ::PAIR - zmq_error_check(@shutdown_socket.bind shutdown_uri) + @shutdown_socket = @zmq_context.socket(ZMQ::PAIR) + zmq_error_check(@shutdown_socket.bind(shutdown_uri)) end def init_zmq_context diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 8aed3e6b..16638847 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -92,7 +92,7 @@ def broadcast_heartbeat :server => self.to_proto ) - @beacon_socket.send heartbeat.serialize_to_string, 0 + @beacon_socket.send(heartbeat.serialize_to_string, 0) log_debug { sign_message("sent heartbeat to #{beacon_uri}") } end @@ -187,14 +187,14 @@ def stop_broker end def stop_workers - @workers.each &:signal_shutdown + @workers.each(&:signal_shutdown) Thread.pass until reap_dead_workers.empty? end def teardown - @shutdown_socket.try :close - @beacon_socket.try :close - @zmq_context.try :terminate + @shutdown_socket.try(:close) + @beacon_socket.try(:close) + @zmq_context.try(:terminate) end def total_workers @@ -222,7 +222,7 @@ def wait_for_shutdown_signal next_reaping = time + reaping_interval next_cycle = time + maintenance_interval poller = ZMQ::Poller.new - poller.register_readable @shutdown_socket + poller.register_readable(@shutdown_socket) # If the poller returns 1, a shutdown signal has been received. # If the poller returns -1, something went wrong. @@ -248,12 +248,12 @@ def wait_for_shutdown_signal def init_beacon_socket @beacon_socket = UDPSocket.new - @beacon_socket.setsockopt ::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true - @beacon_socket.connect beacon_ip, beacon_port + @beacon_socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true) + @beacon_socket.connect(beacon_ip, beacon_port) end def init_shutdown_socket - @shutdown_socket = @zmq_context.socket ZMQ::PAIR + @shutdown_socket = @zmq_context.socket(ZMQ::PAIR) zmq_error_check(@shutdown_socket.bind shutdown_uri) end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 89ac5f46..b648e4fe 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -29,13 +29,11 @@ def alive? end def join - @thread.try :join + @thread.try(:join) end def process_request - zmq_error_check(@backend_socket.recv_strings(frames = [])) - - @client_address, empty, @request_data = *frames + @client_address, empty, @request_data = read_from_backend unless @request_data.nil? log_debug { sign_message("handling request") } @@ -43,13 +41,19 @@ def process_request end end + def read_from_backend + [].tap do |frames| + zmq_error_check(@backend_socket.recv_strings(frames)) + end + end + def run poller = ::ZMQ::Poller.new poller.register_readable(@backend_socket) poller.register_readable(@shutdown_socket) # Send request to broker telling it we are ready - zmq_error_check(@backend_socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE)) + write_to_backend([::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE]) catch(:shutdown) do while poller.poll > 0 @@ -69,13 +73,11 @@ def run end def send_data - response_data = @response.to_s # to_s is aliases as serialize_to_string in Message - - frames = [@client_address, "", response_data] + data = @response.serialize_to_string - @stats.response_size = response_data.size + @stats.response_size = data.size - zmq_error_check(@backend_socket.send_strings(frames)) + write_to_backend([@client_address, "", data]) end def shutdown_uri @@ -84,8 +86,8 @@ def shutdown_uri def signal_shutdown socket = @zmq_context.socket ZMQ::PAIR - zmq_error_check(socket.connect shutdown_uri) - zmq_error_check(socket.send_string ".") + zmq_error_check(socket.connect(shutdown_uri)) + zmq_error_check(socket.send_string(".")) zmq_error_check(socket.close) end @@ -95,7 +97,7 @@ def start self.run rescue => e message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" - $stderr.puts message + $stderr.puts(message) log_error { message } end end @@ -104,9 +106,13 @@ def start end def teardown - @backend_socket.try :close - @shutdown_socket.try :close - @zmq_context.try :terminate + @backend_socket.try(:close) + @shutdown_socket.try(:close) + @zmq_context.try(:terminate) + end + + def write_to_backend(frames) + zmq_error_check(@backend_socket.send_strings(frames)) end private @@ -116,13 +122,13 @@ def init_zmq_context end def init_backend_socket - @backend_socket = @zmq_context.socket ZMQ::REQ - zmq_error_check(@backend_socket.connect @server.backend_uri) + @backend_socket = @zmq_context.socket(ZMQ::REQ) + zmq_error_check(@backend_socket.connect(@server.backend_uri)) end def init_shutdown_socket - @shutdown_socket = @zmq_context.socket ZMQ::PAIR - zmq_error_check(@shutdown_socket.bind shutdown_uri) + @shutdown_socket = @zmq_context.socket(ZMQ::PAIR) + zmq_error_check(@shutdown_socket.bind(shutdown_uri)) end end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 7e32c41e..2fd0afb9 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -28,7 +28,7 @@ ::ZMQ::Context.stub(:new).and_return(zmq_context_mock) end - describe "#server_uri" do + describe "#lookup_server_uri" do let(:service_directory) { double('ServiceDirectory', :running? => running? ) } let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) } let(:running?) { true } @@ -40,12 +40,12 @@ context "when the service directory is running" do it "searches the service directory" do service_directory.should_receive(:lookup).and_return(listing) - subject.send(:server_uri).should eq "tcp://127.0.0.2:9399" + subject.send(:lookup_server_uri).should eq "tcp://127.0.0.2:9399" end it "defaults to the options" do service_directory.should_receive(:lookup) { nil } - subject.send(:server_uri).should eq "tcp://127.0.0.1:9400" + subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end @@ -54,7 +54,7 @@ it "does not search the directory" do service_directory.should_not_receive(:lookup) - subject.send(:server_uri).should eq "tcp://127.0.0.1:9400" + subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 31d41e49..e4c858d8 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -149,7 +149,7 @@ def thread end context "receiving a heartbeat" do - let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'heartbeat') } + let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'heartbeat', :address => '127.0.0.1') } let(:beacon) { ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :server => server, :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT @@ -165,7 +165,7 @@ def thread end context "receiving a flatline" do - let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'flatline') } + let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'flatline', :address => '127.0.0.1') } let(:beacon) { ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :server => server, :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE From 949eef66eb74e38b4d1908dae205f1a8790a17e7 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 11 Jun 2013 10:30:02 -0600 Subject: [PATCH 0411/1191] Reconcile with comments from the pull request --- lib/protobuf/rpc/servers/socket/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 94a38dfa..50298ad3 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -107,7 +107,7 @@ def running? def stop @running = false - @server.try :close + @server.try(:close) end end end From bbab1cb143ed5c139c83fc75083d3fa8c800b15c Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 11 Jun 2013 12:24:51 -0600 Subject: [PATCH 0412/1191] Cleanup --- lib/protobuf/cli.rb | 95 ++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 87d639ee..3ef067c9 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -40,24 +40,25 @@ class CLI < ::Thor option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)" def start(app_file) - debug_say 'Configuring the rpc_server process' + debug_say('Configuring the rpc_server process') configure_logger configure_traps - configure_server_mode + configure_runner_mode + create_runner + configure_process_name(app_file) configure_gc configure_deprecation_warnings - require_application!(app_file) unless exit_requested? - configure_process_name(app_file) unless exit_requested? - start_server! unless exit_requested? + require_application(app_file) unless exit_requested? + start_server unless exit_requested? rescue => e - say_and_exit!('ERROR: RPC Server failed to start.', e) + say_and_exit('ERROR: RPC Server failed to start.', e) end desc 'version', 'Print ruby and protoc versions and exit.' def version - say "Ruby Protobuf v#{::Protobuf::VERSION}, protoc v#{::Protobuf::PROTOC_VERSION}" + say("Ruby Protobuf v#{::Protobuf::VERSION}, protoc v#{::Protobuf::PROTOC_VERSION}") end no_tasks do @@ -73,7 +74,7 @@ def configure_deprecation_warnings # If we pause during request we don't need to pause in serialization def configure_gc - debug_say 'Configuring gc' + debug_say('Configuring gc') if defined?(JRUBY_VERSION) # GC.enable/disable are noop's on Jruby @@ -85,7 +86,7 @@ def configure_gc # Setup the protobuf logger. def configure_logger - debug_say 'Configuring logger' + debug_say('Configuring logger') ::Protobuf::Logger.configure({ :file => options.log || STDOUT, :level => options.debug? ? ::Logger::DEBUG : options.level }) @@ -96,32 +97,32 @@ def configure_logger # Re-write the $0 var to have a nice process name in ps. def configure_process_name(app_file) - debug_say 'Configuring process name' - $0 = "rpc_server --#{@mode} #{options.host}:#{options.port} #{app_file}" + debug_say('Configuring process name') + $0 = "rpc_server --#{@runner_mode} #{options.host}:#{options.port} #{app_file}" end # Configure the mode of the server and the runner class. - def configure_server_mode - debug_say 'Configuring runner mode' + def configure_runner_mode + debug_say('Configuring runner mode') if multi_mode? - say 'WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow - server_socket! + say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) + @runner_mode = :socket elsif options.zmq? - server_zmq! + @runner_mode = :zmq elsif options.evented? - server_evented! + @runner_mode = :evented else case server_type = ENV["PB_SERVER_TYPE"] when nil, /socket/i - server_socket! + @runner_mode = :socket when /zmq/i - server_zmq! + @runner_mode = :zmq when /evented/i - server_evented! + @runner_mode = :evented else say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow - server_socket! + @runner_mode = :socket end end end @@ -129,21 +130,36 @@ def configure_server_mode # Configure signal traps. # TODO add signal handling for hot-reloading the application. def configure_traps - debug_say 'Configuring traps' + debug_say('Configuring traps') exit_signals = [:INT, :TERM] exit_signals << :QUIT unless defined?(JRUBY_VERSION) exit_signals.each do |signal| - debug_say "Registering trap for exit signal #{signal}", :blue + debug_say("Registering trap for exit signal #{signal}", :blue) trap(signal) do @exit_requested = true - shutdown_server! + shutdown_server end end end + # Create the runner for the configured mode + def create_runner + debug_say("Creating #{@runner_mode} runner") + @runner = case @runner_mode + when :evented + create_evented_runner + when :zmq + create_zmq_runner + when :socket + create_socket_runner + else + say_and_exit("Unknown runner mode: #{@runner_mode}") + end + end + # Say something if we're in debug mode. def debug_say(message, color = :yellow) say(message, color) if options.debug? @@ -163,21 +179,23 @@ def multi_mode? end # Require the application file given, exiting if the file doesn't exist. - def require_application!(app_file) - debug_say 'Requiring app file' + def require_application(app_file) + debug_say('Requiring app file') require app_file rescue LoadError => e - say_and_exit!("Failed to load application file #{app_file}", e) + say_and_exit("Failed to load application file #{app_file}", e) end def runner_options - opt = options.inject({}){|h,(k,v)|h[k.to_sym]=v;h} # Symbolize keys + # Symbolize keys + opt = options.inject({}) { |h, (k, v)| h[k.to_sym] = v; h } + opt[:workers_only] = !!ENV['PB_WORKERS_ONLY'] || options.workers_only opt end - def say_and_exit!(message, exception = nil) + def say_and_exit(message, exception = nil) message = set_color(message, :red) if ::Protobuf::Logger.file == STDOUT ::Protobuf::Logger.error { message } @@ -192,41 +210,38 @@ def say_and_exit!(message, exception = nil) exit(1) end - def server_evented! + def create_evented_runner require 'protobuf/evented' - @mode = :evented @runner = ::Protobuf::Rpc::EventedRunner.new(runner_options) end - def server_socket! + def create_socket_runner require 'protobuf/socket' - @mode = :socket @runner = ::Protobuf::Rpc::SocketRunner.new(runner_options) end - def server_zmq! + def create_zmq_runner require 'protobuf/zmq' - @mode = :zmq @runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) end - def shutdown_server! + def shutdown_server ::Protobuf::Logger.info { 'RPC Server shutting down...' } - @runner.try :stop + @runner.try(:stop) ::Protobuf::Rpc::ServiceDirectory.instance.stop ::Protobuf::Logger.info { 'Shutdown complete' } end # Start the runner and log the relevant options. - def start_server! - debug_say 'Invoking server start' + def start_server + debug_say('Running server') @runner.run do ::Protobuf::Logger.info { - "pid #{::Process.pid} -- #{@mode} RPC Server listening at #{options.host}:#{options.port}" + "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" } end end From b8c611694205b07bdb131511aa73098d79c15900 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 11 Jun 2013 13:55:00 -0600 Subject: [PATCH 0413/1191] Update README --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 93e94a05..fe0650a8 100644 --- a/README.md +++ b/README.md @@ -303,8 +303,7 @@ any other filter calls which would run afterwards, as well as canceling invocation of the service method. Note: You must actually return false, not just a "falsey" value such as nil. -__After Filters__ – There is no request shortcutting since the after -filter runs after the request. Duh. +__After Filters__ – No request shortcutting. #### Filter options @@ -415,6 +414,29 @@ Many different options can be passed to the `.client` call above (such as `:timeout => 600`). See the `lib/protobuf/rpc/client.rb` and `lib/protobuf/rpc/service.rb` files for more documentation. +### Dynamic Discovery (ZMQ Only) +It is possible to setup the RPC server and client in a way that +allows servers to be dynamically discovered by the client. + +#### In the client +```ruby +ServiceDirectory.start do |config| + config.port = 53000 +end +``` + +#### Starting the server +``` +$ rpc_server -o myserver.com --broadcast-beacons ./config/environment.rb +``` + +The client will listen on the specified port for beacons broadcast +by servers. Each beacon includes a list of services provided by the +broadcasting server. The client randomly selects a server for the +desired service each time a request is made. + +Check out the {Protobuf::ServiceDirectory} class for more details. + ## 3. RPC Interop The main reason I wrote this gem was to provide a ruby implementation From a25ba7aaf8883091c603a340e512cf6fe2a81c20 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 11 Jun 2013 13:59:19 -0600 Subject: [PATCH 0414/1191] Add caution about cross-environment beacons --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fe0650a8..8b9665d6 100644 --- a/README.md +++ b/README.md @@ -435,7 +435,12 @@ by servers. Each beacon includes a list of services provided by the broadcasting server. The client randomly selects a server for the desired service each time a request is made. -Check out the {Protobuf::ServiceDirectory} class for more details. +*CAUTION:* When running multiple environments on a single network, +e.g., qa and staging, be sure that each environment is setup with +a unique broadcast port; otherwise, clients in one environment will +make requests to servers in another environment. + +Check out {Protobuf::ServiceDirectory} for more details. ## 3. RPC Interop From 67d9b0e3cedd8a58d69584973d09434312a0c3ed Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 11 Jun 2013 15:13:20 -0500 Subject: [PATCH 0415/1191] Update README.md --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b9665d6..00fa0fde 100644 --- a/README.md +++ b/README.md @@ -423,11 +423,21 @@ allows servers to be dynamically discovered by the client. ServiceDirectory.start do |config| config.port = 53000 end + +# If your server also runs this code, it will default to the +# given port when sending beacons and have its own service +# directory. You can prevent this code from running on the +# server if needed: +unless defined? ::Protobuf::CLI + ServiceDirectory.start do |config| + config.port = 53000 + end +end ``` #### Starting the server ``` -$ rpc_server -o myserver.com --broadcast-beacons ./config/environment.rb +$ rpc_server --broadcast-beacons --beacon-port 53000 ... ``` The client will listen on the specified port for beacons broadcast @@ -435,10 +445,10 @@ by servers. Each beacon includes a list of services provided by the broadcasting server. The client randomly selects a server for the desired service each time a request is made. -*CAUTION:* When running multiple environments on a single network, +__CAUTION:__ When running multiple environments on a single network, e.g., qa and staging, be sure that each environment is setup with -a unique broadcast port; otherwise, clients in one environment will -make requests to servers in another environment. +a unique beacon port; otherwise, clients in one environment _will_ +make requests to servers in the other environment. Check out {Protobuf::ServiceDirectory} for more details. From 9e15a0bda037a2eecf92526e6f7a8a013f792b21 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 12 Jun 2013 11:42:44 -0600 Subject: [PATCH 0416/1191] Reconcile with pull-request feedback --- lib/protobuf/cli.rb | 2 +- lib/protobuf/rpc/servers/zmq/broker.rb | 88 ++++++++++++++------------ lib/protobuf/rpc/servers/zmq/server.rb | 61 +++++++++++++----- lib/protobuf/rpc/service_directory.rb | 38 ++++++----- 4 files changed, 116 insertions(+), 73 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3ef067c9..6dc0b909 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -190,7 +190,7 @@ def runner_options # Symbolize keys opt = options.inject({}) { |h, (k, v)| h[k.to_sym] = v; h } - opt[:workers_only] = !!ENV['PB_WORKERS_ONLY'] || options.workers_only + opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only opt end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 0e339722..430d12d0 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -22,36 +22,17 @@ def join @thread.try(:join) end - def read_from_backend - [].tap do |frames| - zmq_error_check(@backend_socket.recv_strings(frames)) - end - end - - def read_from_frontend - [].tap do |frames| - zmq_error_check(@frontend_socket.recv_strings(frames)) - end - end - def run - idle_workers = [] + @idle_workers = [] catch(:shutdown) do while @poller.poll > 0 @poller.readables.each do |readable| case readable when @frontend_socket - if idle_workers.any? - frames = read_from_frontend - write_to_backend([idle_workers.shift, ""] + frames) - end + process_frontend when @backend_socket - worker, ignore, *frames = read_from_backend - idle_workers << worker - unless frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] - write_to_frontend(frames) - end + process_backend when @shutdown_socket throw :shutdown end @@ -62,20 +43,10 @@ def run teardown end - def write_to_backend(frames) - zmq_error_check(@backend_socket.send_strings(frames)) - end - - def write_to_frontend(frames) - zmq_error_check(@frontend_socket.send_strings(frames)) - end - def start log_debug { sign_message("starting broker") } - @thread = Thread.new do - self.run - end + @thread = Thread.new { self.run } self end @@ -91,13 +62,6 @@ def signal_shutdown zmq_error_check(socket.close) end - def teardown - @frontend_socket.try(:close) - @backend_socket.try(:close) - @shutdown_socket.try(:close) - @zmq_context.try(:terminate) - end - private def init_backend_socket @@ -125,6 +89,50 @@ def init_shutdown_socket def init_zmq_context @zmq_context = ZMQ::Context.new end + + def process_backend + worker, ignore, *frames = read_from_backend + + @idle_workers << worker + + unless frames == [::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE] + write_to_frontend(frames) + end + end + + def process_frontend + if @idle_workers.any? + frames = read_from_frontend + write_to_backend([@idle_workers.shift, ""] + frames) + end + end + + def read_from_backend + [].tap do |frames| + zmq_error_check(@backend_socket.recv_strings(frames)) + end + end + + def read_from_frontend + [].tap do |frames| + zmq_error_check(@frontend_socket.recv_strings(frames)) + end + end + + def teardown + @frontend_socket.try(:close) + @backend_socket.try(:close) + @shutdown_socket.try(:close) + @zmq_context.try(:terminate) + end + + def write_to_backend(frames) + zmq_error_check(@backend_socket.send_strings(frames)) + end + + def write_to_frontend(frames) + zmq_error_check(@frontend_socket.send_strings(frames)) + end end end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 16638847..7ca31458 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -87,6 +87,8 @@ def broadcast_flatline end def broadcast_heartbeat + @last_beacon = Time.now.to_i + heartbeat = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT, :server => self.to_proto @@ -97,6 +99,10 @@ def broadcast_heartbeat log_debug { sign_message("sent heartbeat to #{beacon_uri}") } end + def broadcast_heartbeat? + Time.now.to_i >= next_beacon && broadcast_beacons? + end + def brokerless? !!options[:workers_only] end @@ -113,20 +119,45 @@ def frontend_uri "tcp://#{frontend_ip}:#{frontend_port}" end - def maintenance_interval - [reaping_interval, beacon_interval].min + def next_maintenance + cycles = [next_reaping] + cycles << next_beacon if broadcast_beacons? + + cycles.min end def minimum_timeout 100 end + def next_beacon + if @last_beacon.nil? + 0 + else + Time.now.to_i + beacon_interval + end + end + + def next_reaping + if @last_reaping.nil? + 0 + else + Time.now.to_i + reaping_interval + end + end + def reap_dead_workers + @last_reaping = Time.now.to_i + @workers.keep_if do |worker| worker.alive? or worker.join && false end end + def reap_dead_workers? + Time.now.to_i >= next_reaping + end + def reaping_interval 5 end @@ -195,12 +226,21 @@ def teardown @shutdown_socket.try(:close) @beacon_socket.try(:close) @zmq_context.try(:terminate) + @last_reaping = @last_beacon = @timeout = nil end def total_workers @total_workers ||= [@options[:threads].to_i, 1].max end + def timeout + if @timeout.nil? + 0 + else + @timeout = [minimum_timeout, 1_000 * next_maintenance].max + end + end + def to_proto @proto ||= ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => uuid, @@ -216,31 +256,18 @@ def uuid end def wait_for_shutdown_signal - time = Time.now.to_i - timeout = 0 - next_beacon = 0 - next_reaping = time + reaping_interval - next_cycle = time + maintenance_interval poller = ZMQ::Poller.new poller.register_readable(@shutdown_socket) # If the poller returns 1, a shutdown signal has been received. # If the poller returns -1, something went wrong. while poller.poll(timeout) === 0 - if (time = Time.now.to_i) >= next_reaping + if reap_dead_workers? reap_dead_workers start_missing_workers - next_reaping = time + reaping_interval - next_cycle = [next_cycle, next_reaping].min - end - - if broadcast_beacons? && time >= next_beacon - broadcast_heartbeat - next_beacon = time + beacon_interval - next_cycle = [next_cycle, next_beacon].min end - timeout = [minimum_timeout, 1000 * (next_cycle - time)].max + broadcast_heartbeat if broadcast_heartbeat? end end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 0a36d804..7ef89197 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -172,26 +172,34 @@ def init_socket @socket.bind(self.class.address, self.class.port.to_i) end + def process_beacon(beacon) + case beacon.beacon_type + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT + add_listing_for(beacon.server) + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE + remove_listing_for(beacon.server) + end + end + def run - begin - data, addr = @socket.recvfrom(2048) - beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new + loop do + process_beacon(wait_for_beacon) + remove_expired_listings + end + rescue => e + log_debug { sign_message("error: (#{e.class}) #{e.message}") } + retry + end + + def wait_for_beacon + data, addr = @socket.recvfrom(2048) + + ::Protobuf::Rpc::DynamicDiscovery::Beacon.new.tap do |beacon| beacon.parse_from_string(data) rescue nil # Favor the address captured by the socket beacon.try(:server).try(:address=, addr[3]) - - case beacon.beacon_type - when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT - add_listing_for(beacon.server) - when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE - remove_listing_for(beacon.server) - end - - remove_expired_listings - rescue => e - log_debug { sign_message("error: (#{e.class}) #{e.message}") } - end while true + end end end end From 05fd332dfe205eb4c4ca14ea5be425ac481bd9d4 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 12 Jun 2013 13:40:45 -0600 Subject: [PATCH 0417/1191] Fix some bugs introduced during refactor --- lib/protobuf/rpc/servers/zmq/server.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 7ca31458..39736683 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -119,6 +119,10 @@ def frontend_uri "tcp://#{frontend_ip}:#{frontend_port}" end + def maintenance_timeout + 1_000 * (next_maintenance - Time.now.to_i) + end + def next_maintenance cycles = [next_reaping] cycles << next_beacon if broadcast_beacons? @@ -134,7 +138,7 @@ def next_beacon if @last_beacon.nil? 0 else - Time.now.to_i + beacon_interval + @last_beacon + beacon_interval end end @@ -142,7 +146,7 @@ def next_reaping if @last_reaping.nil? 0 else - Time.now.to_i + reaping_interval + @last_reaping + reaping_interval end end @@ -235,9 +239,9 @@ def total_workers def timeout if @timeout.nil? - 0 + @timeout = 0 else - @timeout = [minimum_timeout, 1_000 * next_maintenance].max + @timeout = [minimum_timeout, maintenance_timeout].max end end From 505fa5c973ede0c3bfc27aae9d502cca4ea66533 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Jun 2013 14:39:42 -0600 Subject: [PATCH 0418/1191] Bump version 2.8.0.beta1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5ab89636..0fd896c1 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.10' + VERSION = '2.8.0.beta1' PROTOC_VERSION = '2.4.1' end From e963c7ea109516fe7b36da2dfbaf748fdc6f5e18 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Fri, 14 Jun 2013 16:11:32 -0600 Subject: [PATCH 0419/1191] Accept values that respond to `to_f` in FloatField. The checking for acceptable FloatField values was verifying that values fell between -Infinity and Infinity. This worked for any number object, including BigDecimal in MRI 1.9.2 <= & JRuby. In MRI 1.9.3 >=, setting a BigDecimal raised a type error. Since BigDecimal values pack the same way as Float values and their aren't min/max values for double/float fields in Protocol Buffers, a simple `respond_to?(:to_f)` call will suffice when checking for acceptable values. Closes #90. --- lib/protobuf/field/float_field.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index c075b0a9..71bd6c33 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -4,10 +4,6 @@ module Protobuf module Field class FloatField < BaseField def self.default; 0.0; end - def self.max; 1.0/0; end - def self.min; -1.0/0; end - def max; 1.0/0; end - def min; -1.0/0; end def wire_type WireType::FIXED32 @@ -22,7 +18,7 @@ def encode(value) end def acceptable?(val) - (val > min || val < max) rescue false + val.respond_to?(:to_f) end end end From 86ab017e7642350bebf7e2f2200941f812ce71ea Mon Sep 17 00:00:00 2001 From: Michael Xavier Date: Fri, 14 Jun 2013 15:21:24 -0700 Subject: [PATCH 0420/1191] Add fallback support for activesupport 2 --- lib/protobuf.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 3c8edc90..a9677a2b 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -3,7 +3,16 @@ require 'pp' require 'stringio' require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/object/try' +require 'active_support/version' + +if ActiveSupport::VERSION::MAJOR > 2 + require 'active_support/core_ext/object/try' +else + require 'active_support/core_ext/module/delegation' + require 'active_support/core_ext/kernel/reporting' + require 'active_support/core_ext/try' +end + require 'active_support/inflector' require 'active_support/json' From 1a76628ff0441aaec98ec7cc56c00a087ad85113 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Jun 2013 11:59:44 -0600 Subject: [PATCH 0421/1191] Bump version 2.7.11 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5ab89636..b6650147 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.10' + VERSION = '2.7.11' PROTOC_VERSION = '2.4.1' end From 63d0b16e9f30249bf88c053c41161c0265803107 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 18 Jun 2013 13:38:56 -0600 Subject: [PATCH 0422/1191] Fix default service directory address Using 255.255.255.255 does not work on osx. --- lib/protobuf/rpc/service_directory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 7ef89197..52d853ed 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -12,7 +12,7 @@ class ServiceDirectory include ::Singleton include ::Protobuf::Logger::LogMethods - DEFAULT_ADDRESS = "255.255.255.255" + DEFAULT_ADDRESS = "0.0.0.0" DEFAULT_PORT = 53000 DEFAULT_TIMEOUT = 1 From 28224552764b9520f5da77593e8a07394c0dde29 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Jun 2013 16:14:54 -0600 Subject: [PATCH 0423/1191] Bump version 2.8.0.beta2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 0fd896c1..4cfbd96b 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta1' + VERSION = '2.8.0.beta2' PROTOC_VERSION = '2.4.1' end From 985d567f1b5582239972e2d8dbc60653498fb8da Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 19 Jun 2013 13:31:02 -0600 Subject: [PATCH 0424/1191] Fix spec --- spec/functional/zmq_server_spec.rb | 43 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index e45345cb..297dca4a 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' + require 'spec/support/test/resource_service' require 'protobuf/rpc/service_directory' @@ -13,11 +14,13 @@ }} let(:server) { ::Protobuf::Rpc::Zmq::Server.new(options) } - let(:server_thread) { Thread.new(server) { |server| server.run } } + let!(:server_thread) { Thread.new(server) { |server| server.run } } - before do + before(:all) do load "protobuf/zmq.rb" - server_thread.abort_on_exception = true + end + + before do Thread.pass until server.running? end @@ -46,14 +49,12 @@ context 'when a message is malformed' do it 'calls the on_failure callback' do error = nil - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client + request = ::Test::ResourceFindRequest.new(:active => true) + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e } - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure {|e| error = e } end error.message.should match(/name.*required/) end @@ -62,14 +63,12 @@ context 'when the request type is wrong' do it 'calls the on_failure callback' do error = nil - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client + request = ::Test::Resource.new(:name => 'Test Name') + client = ::Test::ResourceService.client - client.find(request) do |c| - c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e} - end + client.find(request) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure {|e| error = e} end error.message.should match(/expected request.*ResourceFindRequest.*Resource instead/i) end @@ -78,13 +77,11 @@ context 'when the server takes too long to respond' do it 'responds with a timeout error' do error = nil - StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do - client = ::Test::ResourceService.client(:timeout => 1) + client = ::Test::ResourceService.client(:timeout => 1) - client.find_with_sleep(:sleep => 2) do |c| - c.on_success { raise "shouldn't pass" } - c.on_failure { |e| error = e } - end + client.find_with_sleep(:sleep => 2) do |c| + c.on_success { raise "shouldn't pass" } + c.on_failure { |e| error = e } end error.message.should match(/The server took longer than 1 seconds to respond/i) end From 52466654da9f8921b17fcc9f66345b6c44e25d17 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 19 Jun 2013 13:48:31 -0600 Subject: [PATCH 0425/1191] Remove usage of tap --- lib/protobuf/rpc/servers/zmq/broker.rb | 12 ++++++------ lib/protobuf/rpc/servers/zmq/worker.rb | 6 +++--- lib/protobuf/rpc/service_directory.rb | 11 ++++++----- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 430d12d0..e223c1da 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -108,15 +108,15 @@ def process_frontend end def read_from_backend - [].tap do |frames| - zmq_error_check(@backend_socket.recv_strings(frames)) - end + frames = [] + zmq_error_check(@backend_socket.recv_strings(frames)) + frames end def read_from_frontend - [].tap do |frames| - zmq_error_check(@frontend_socket.recv_strings(frames)) - end + frames = [] + zmq_error_check(@frontend_socket.recv_strings(frames)) + frames end def teardown diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index b648e4fe..06511d89 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -42,9 +42,9 @@ def process_request end def read_from_backend - [].tap do |frames| - zmq_error_check(@backend_socket.recv_strings(frames)) - end + frames = [] + zmq_error_check(@backend_socket.recv_strings(frames)) + frames end def run diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 7ef89197..5712cb42 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -194,12 +194,13 @@ def run def wait_for_beacon data, addr = @socket.recvfrom(2048) - ::Protobuf::Rpc::DynamicDiscovery::Beacon.new.tap do |beacon| - beacon.parse_from_string(data) rescue nil + beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new + beacon.parse_from_string(data) rescue nil - # Favor the address captured by the socket - beacon.try(:server).try(:address=, addr[3]) - end + # Favor the address captured by the socket + beacon.try(:server).try(:address=, addr[3]) + + beacon end end end From 04633f39da662ca42d85d94fb9db51278b6f88c3 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 19 Jun 2013 13:50:02 -0600 Subject: [PATCH 0426/1191] Remove usage of throw --- lib/protobuf/rpc/servers/zmq/broker.rb | 21 ++++++++++----------- lib/protobuf/rpc/servers/zmq/worker.rb | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index e223c1da..6895373b 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -23,19 +23,18 @@ def join end def run + running = true @idle_workers = [] - catch(:shutdown) do - while @poller.poll > 0 - @poller.readables.each do |readable| - case readable - when @frontend_socket - process_frontend - when @backend_socket - process_backend - when @shutdown_socket - throw :shutdown - end + while running && @poller.poll > 0 + @poller.readables.each do |readable| + case readable + when @frontend_socket + process_frontend + when @backend_socket + process_backend + when @shutdown_socket + running = false end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 06511d89..67234be2 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -48,6 +48,8 @@ def read_from_backend end def run + running = true + poller = ::ZMQ::Poller.new poller.register_readable(@backend_socket) poller.register_readable(@shutdown_socket) @@ -55,16 +57,14 @@ def run # Send request to broker telling it we are ready write_to_backend([::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE]) - catch(:shutdown) do - while poller.poll > 0 - poller.readables.each do |readable| - case readable - when @backend_socket - initialize_request! - process_request - when @shutdown_socket - throw :shutdown - end + while running && poller.poll > 0 + poller.readables.each do |readable| + case readable + when @backend_socket + initialize_request! + process_request + when @shutdown_socket + running = false end end end From be2d1ea2ae6cc300df27d57385ec2aeb2a1dcb39 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 19 Jun 2013 13:54:21 -0600 Subject: [PATCH 0427/1191] Fix TTIN signal --- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++++- lib/protobuf/rpc/servers/zmq_runner.rb | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 39736683..f6c14a4c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -15,7 +15,7 @@ class Server :broadcast_beacons => false } - attr_accessor :options + attr_accessor :options, :workers def initialize(options) @options = DEFAULT_OPTIONS.merge(options) @@ -29,6 +29,10 @@ def initialize(options) raise end + def add_worker + @total_workers = total_workers + 1 + end + def backend_ip frontend_ip end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 656c634a..de5bed33 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -36,9 +36,8 @@ def stop def register_signals trap(:TTIN) do - log_info { "TTIN received: Starting new worker" } - @server.start_worker - log_info { "Worker count : #{::Protobuf::Rpc::Zmq::Server.threads.size}" } + @server.add_worker + log_info { "Increased worker size to: #{@server.total_workers}" } end end end From c8fb474a82f00a607ef259b0e2e3580d8f9595e8 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 19 Jun 2013 14:56:23 -0600 Subject: [PATCH 0428/1191] Fix threading model --- lib/protobuf/rpc/servers/zmq/broker.rb | 39 ++------- lib/protobuf/rpc/servers/zmq/server.rb | 57 ++++++------- lib/protobuf/rpc/servers/zmq/worker.rb | 84 +++++-------------- .../protobuf/rpc/servers/zmq/server_spec.rb | 2 +- 4 files changed, 57 insertions(+), 125 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 6895373b..fb31c326 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -1,4 +1,3 @@ - module Protobuf module Rpc module Zmq @@ -11,30 +10,24 @@ def initialize(server) init_zmq_context init_backend_socket init_frontend_socket - init_shutdown_socket init_poller rescue teardown raise end - def join - @thread.try(:join) - end - def run - running = true @idle_workers = [] - while running && @poller.poll > 0 + while running? + break if @poller.poll(500) < 0 + @poller.readables.each do |readable| case readable when @frontend_socket process_frontend when @backend_socket process_backend - when @shutdown_socket - running = false end end end @@ -42,23 +35,8 @@ def run teardown end - def start - log_debug { sign_message("starting broker") } - - @thread = Thread.new { self.run } - - self - end - - def shutdown_uri - "inproc://#{object_id}" - end - - def signal_shutdown - socket = @zmq_context.socket(ZMQ::PAIR) - zmq_error_check(socket.connect(shutdown_uri)) - zmq_error_check(socket.send_string ".") - zmq_error_check(socket.close) + def running? + @server.running? || @server.workers.any? end private @@ -77,12 +55,6 @@ def init_poller @poller = ZMQ::Poller.new @poller.register_readable(@frontend_socket) @poller.register_readable(@backend_socket) - @poller.register_readable(@shutdown_socket) - end - - def init_shutdown_socket - @shutdown_socket = @zmq_context.socket(ZMQ::PAIR) - zmq_error_check(@shutdown_socket.bind(shutdown_uri)) end def init_zmq_context @@ -121,7 +93,6 @@ def read_from_frontend def teardown @frontend_socket.try(:close) @backend_socket.try(:close) - @shutdown_socket.try(:close) @zmq_context.try(:terminate) end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index f6c14a4c..a511c0bd 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -177,8 +177,8 @@ def run start_missing_workers wait_for_shutdown_signal broadcast_flatline if broadcast_beacons? - stop_workers - stop_broker unless brokerless? + Thread.pass until reap_dead_workers.empty? + @broker.join unless brokerless? ensure @running = false teardown @@ -192,17 +192,6 @@ def shutdown_uri "inproc://#{object_id}" end - def signal_shutdown - socket = @zmq_context.socket ZMQ::PAIR - zmq_error_check(socket.connect shutdown_uri) - zmq_error_check(socket.send_string ".") - zmq_error_check(socket.close) - end - - def start_broker - @broker = ::Protobuf::Rpc::Zmq::Broker.new(self).start - end - def start_missing_workers missing_workers = total_workers - @workers.size @@ -212,22 +201,9 @@ def start_missing_workers end end - def start_worker - @workers << ::Protobuf::Rpc::Zmq::Worker.new(self).start - end - def stop - signal_shutdown - end - - def stop_broker - @broker.signal_shutdown - @broker.join - end - - def stop_workers - @workers.each(&:signal_shutdown) - Thread.pass until reap_dead_workers.empty? + @running = false + send_shutdown_signal end def teardown @@ -295,6 +271,31 @@ def init_shutdown_socket def init_zmq_context @zmq_context = ZMQ::Context.new end + + def send_shutdown_signal + socket = @zmq_context.socket ZMQ::PAIR + zmq_error_check(socket.connect shutdown_uri) + zmq_error_check(socket.send_string ".") + zmq_error_check(socket.close) + end + + def start_broker + @broker = Thread.new do + ::Protobuf::Rpc::Zmq::Broker.new(self).run + end + end + + def start_worker + @workers << Thread.new(self) do |server| + begin + ::Protobuf::Rpc::Zmq::Worker.new(server).run + rescue => e + message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" + $stderr.puts(message) + log_error { message } + end + end + end end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 67234be2..d6bd4ffe 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -13,9 +13,9 @@ class Worker # def initialize(server) @server = server + init_zmq_context init_backend_socket - init_shutdown_socket rescue teardown raise @@ -24,14 +24,6 @@ def initialize(server) ## # Instance Methods # - def alive? - @thread.try(:alive?) || false - end - - def join - @thread.try(:join) - end - def process_request @client_address, empty, @request_data = read_from_backend @@ -41,15 +33,7 @@ def process_request end end - def read_from_backend - frames = [] - zmq_error_check(@backend_socket.recv_strings(frames)) - frames - end - def run - running = true - poller = ::ZMQ::Poller.new poller.register_readable(@backend_socket) poller.register_readable(@shutdown_socket) @@ -57,21 +41,22 @@ def run # Send request to broker telling it we are ready write_to_backend([::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE]) - while running && poller.poll > 0 - poller.readables.each do |readable| - case readable - when @backend_socket - initialize_request! - process_request - when @shutdown_socket - running = false - end + while running? + break if poller.poll(500) < 0 + + if poller.readables.any? + initialize_request! + process_request end end ensure teardown end + def running? + @server.running? + end + def send_data data = @response.serialize_to_string @@ -80,56 +65,31 @@ def send_data write_to_backend([@client_address, "", data]) end - def shutdown_uri - "inproc://#{object_id}" - end + private - def signal_shutdown - socket = @zmq_context.socket ZMQ::PAIR - zmq_error_check(socket.connect(shutdown_uri)) - zmq_error_check(socket.send_string(".")) - zmq_error_check(socket.close) + def init_zmq_context + @zmq_context = ZMQ::Context.new end - def start - @thread = Thread.new do - begin - self.run - rescue => e - message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" - $stderr.puts(message) - log_error { message } - end - end + def init_backend_socket + @backend_socket = @zmq_context.socket(ZMQ::REQ) + zmq_error_check(@backend_socket.connect(@server.backend_uri)) + end - self + def read_from_backend + frames = [] + zmq_error_check(@backend_socket.recv_strings(frames)) + frames end def teardown @backend_socket.try(:close) - @shutdown_socket.try(:close) @zmq_context.try(:terminate) end def write_to_backend(frames) zmq_error_check(@backend_socket.send_strings(frames)) end - - private - - def init_zmq_context - @zmq_context = ZMQ::Context.new - end - - def init_backend_socket - @backend_socket = @zmq_context.socket(ZMQ::REQ) - zmq_error_check(@backend_socket.connect(@server.backend_uri)) - end - - def init_shutdown_socket - @shutdown_socket = @zmq_context.socket(ZMQ::PAIR) - zmq_error_check(@shutdown_socket.bind(shutdown_uri)) - end end end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 80ab752e..81281a31 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -33,7 +33,7 @@ describe '.stop' do it 'signals shutdown' do - subject.should_receive(:signal_shutdown) + subject.should_receive(:send_shutdown_signal) subject.stop end From e32c09d2e8d8bdbfdc2243ee8997a6430a7131f6 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 19 Jun 2013 15:05:14 -0600 Subject: [PATCH 0429/1191] Remove last inproc socket in favor of IO pipe --- lib/protobuf/rpc/servers/zmq/server.rb | 32 ++++++++------------------ 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index a511c0bd..f3864490 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -23,7 +23,7 @@ def initialize(options) init_zmq_context init_beacon_socket if broadcast_beacons? - init_shutdown_socket + init_shutdown_pipe rescue teardown raise @@ -188,10 +188,6 @@ def running? !!@running end - def shutdown_uri - "inproc://#{object_id}" - end - def start_missing_workers missing_workers = total_workers - @workers.size @@ -203,11 +199,12 @@ def start_missing_workers def stop @running = false - send_shutdown_signal + @shutdown_w.write('.') end def teardown - @shutdown_socket.try(:close) + @shutdown_r.try(:close) + @shutdown_w.try(:close) @beacon_socket.try(:close) @zmq_context.try(:terminate) @last_reaping = @last_beacon = @timeout = nil @@ -223,6 +220,8 @@ def timeout else @timeout = [minimum_timeout, maintenance_timeout].max end + + @timeout / 1000.0 end def to_proto @@ -240,12 +239,9 @@ def uuid end def wait_for_shutdown_signal - poller = ZMQ::Poller.new - poller.register_readable(@shutdown_socket) + loop do + break if IO.select([@shutdown_r], nil, nil, timeout) - # If the poller returns 1, a shutdown signal has been received. - # If the poller returns -1, something went wrong. - while poller.poll(timeout) === 0 if reap_dead_workers? reap_dead_workers start_missing_workers @@ -263,22 +259,14 @@ def init_beacon_socket @beacon_socket.connect(beacon_ip, beacon_port) end - def init_shutdown_socket - @shutdown_socket = @zmq_context.socket(ZMQ::PAIR) - zmq_error_check(@shutdown_socket.bind shutdown_uri) + def init_shutdown_pipe + @shutdown_r, @shutdown_w = IO.pipe end def init_zmq_context @zmq_context = ZMQ::Context.new end - def send_shutdown_signal - socket = @zmq_context.socket ZMQ::PAIR - zmq_error_check(socket.connect shutdown_uri) - zmq_error_check(socket.send_string ".") - zmq_error_check(socket.close) - end - def start_broker @broker = Thread.new do ::Protobuf::Rpc::Zmq::Broker.new(self).run From c57b33945d94f87dc5caa79d1119571f380de3d1 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 19 Jun 2013 16:39:45 -0600 Subject: [PATCH 0430/1191] Cleanup --- lib/protobuf/rpc/servers/zmq/server.rb | 10 ++++------ spec/lib/protobuf/rpc/servers/zmq/server_spec.rb | 5 ----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index f3864490..28027c86 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -124,7 +124,7 @@ def frontend_uri end def maintenance_timeout - 1_000 * (next_maintenance - Time.now.to_i) + next_maintenance - Time.now.to_i end def next_maintenance @@ -135,7 +135,7 @@ def next_maintenance end def minimum_timeout - 100 + 1 end def next_beacon @@ -220,8 +220,6 @@ def timeout else @timeout = [minimum_timeout, maintenance_timeout].max end - - @timeout / 1000.0 end def to_proto @@ -268,8 +266,8 @@ def init_zmq_context end def start_broker - @broker = Thread.new do - ::Protobuf::Rpc::Zmq::Broker.new(self).run + @broker = Thread.new(self) do |server| + ::Protobuf::Rpc::Zmq::Broker.new(server).run end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 81281a31..17d6aaf9 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -32,11 +32,6 @@ end describe '.stop' do - it 'signals shutdown' do - subject.should_receive(:send_shutdown_signal) - subject.stop - end - it 'sets running to false' do subject.instance_variable_set(:@workers, []) subject.stop From 701f8fdbfb91b3c2ca4ac10824e5b5c8ad1a3e7d Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 20 Jun 2013 08:52:49 -0600 Subject: [PATCH 0431/1191] Try to reproduce the bad file descriptor error --- spec/functional/zmq_server_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 297dca4a..433ccae6 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -46,6 +46,27 @@ }.to_not raise_error end + it 'runs under heavy load' do + 100.times do |x| + 50.times.map do |y| + Thread.new do + client = ::Test::ResourceService.client + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Test::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect + end + end + end + end.each(&:join) + end + end + context 'when a message is malformed' do it 'calls the on_failure callback' do error = nil From 60664432871e6b581b88c61c64f5c6cdf9c4dd65 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 20 Jun 2013 10:14:22 -0600 Subject: [PATCH 0432/1191] Fix bad file descriptor error ZMQ was throwing a "Bad file descriptor" error when many requests are made in a small time frame. This happened because each request creates a new zmq context and a new socket within that context. By using a single ZMQ context for all requests, the error dissappears. --- lib/protobuf/rpc/connectors/zmq.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index ac221164..369b89ba 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -19,6 +19,13 @@ class Zmq < Base CLIENT_RETRIES = (ENV['PB_CLIENT_RETRIES'] || 3) + ## + # Class Methods + # + def self.zmq_context + @zmq_context ||= ZMQ::Context.new + end + ## # Instance methods # @@ -47,7 +54,6 @@ def log_signature def close_connection socket_close - zmq_context_terminate end # Establish a request socket connection to the remote rpc_server. @@ -106,7 +112,7 @@ def poll_send_data read_response return else - close_connection + socket_close end end @@ -171,16 +177,7 @@ def socket_close # an exit block to ensure the context is terminated correctly. # def zmq_context - @zmq_context ||= ::ZMQ::Context.new - end - - # Terminate the zmq_context (if any). - # - def zmq_context_terminate - log_debug { sign_message("Terminating ZMQ Context") } - @zmq_context.try(:terminate) - @zmq_context = nil - log_debug { sign_message("ZMQ Context terminated") } + self.class.zmq_context end def zmq_error_check(return_code, source) From b3e86013129a1881a1de041c9e6f6f4325a06009 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 20 Jun 2013 14:08:54 -0600 Subject: [PATCH 0433/1191] Reconcile with feedback --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 28027c86..3d3fb0da 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -135,7 +135,7 @@ def next_maintenance end def minimum_timeout - 1 + 0.1 end def next_beacon diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 85cfcbfd..1690dc29 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -183,7 +183,8 @@ def process_beacon(beacon) def run loop do - process_beacon(wait_for_beacon) + beacon = wait_for_beacon + process_beacon(beacon) remove_expired_listings end rescue => e @@ -195,7 +196,7 @@ def wait_for_beacon data, addr = @socket.recvfrom(2048) beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new - beacon.parse_from_string(data) rescue nil + beacon.parse_from_string(data) # Favor the address captured by the socket beacon.try(:server).try(:address=, addr[3]) From f5a1fadd0b521a40d3eb8ae9bda643fc1a8232af Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 20 Jun 2013 14:19:24 -0600 Subject: [PATCH 0434/1191] Bump version 2.8.0.beta3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 4cfbd96b..11c7d27f 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta2' + VERSION = '2.8.0.beta3' PROTOC_VERSION = '2.4.1' end From fa5f554277cabb3d9669609bd4da3b37c58a1e63 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 21 Jun 2013 15:17:02 -0600 Subject: [PATCH 0435/1191] Revert the change to the default timeout --- lib/protobuf/rpc/connectors/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index eb7a2f52..e00c3889 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -17,7 +17,7 @@ module Connectors :request => nil, # The request object sent by the client :request_type => nil, # The request type expected by the client :response_type => nil, # The response type expected by the client - :timeout => 15, # The default timeout for the request, also handled by client.rb + :timeout => 300, # The default timeout for the request, also handled by client.rb :client_host => nil # The hostname or address of this client } From ec918e200201969bd79ac10c8ec01170b1f3b99c Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Fri, 14 Jun 2013 16:11:32 -0600 Subject: [PATCH 0436/1191] Accept values that respond to `to_f` in FloatField. The checking for acceptable FloatField values was verifying that values fell between -Infinity and Infinity. This worked for any number object, including BigDecimal in MRI 1.9.2 <= & JRuby. In MRI 1.9.3 >=, setting a BigDecimal raised a type error. Since BigDecimal values pack the same way as Float values and their aren't min/max values for double/float fields in Protocol Buffers, a simple `respond_to?(:to_f)` call will suffice when checking for acceptable values. Closes #90. --- lib/protobuf/field/float_field.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index c075b0a9..71bd6c33 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -4,10 +4,6 @@ module Protobuf module Field class FloatField < BaseField def self.default; 0.0; end - def self.max; 1.0/0; end - def self.min; -1.0/0; end - def max; 1.0/0; end - def min; -1.0/0; end def wire_type WireType::FIXED32 @@ -22,7 +18,7 @@ def encode(value) end def acceptable?(val) - (val > min || val < max) rescue false + val.respond_to?(:to_f) end end end From ffbc1a5b75aa5758375416cba8cd2ab2534fb7d5 Mon Sep 17 00:00:00 2001 From: Michael Xavier Date: Fri, 14 Jun 2013 15:21:24 -0700 Subject: [PATCH 0437/1191] Add fallback support for activesupport 2 --- lib/protobuf.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 24523879..f2d87f60 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -3,7 +3,16 @@ require 'pp' require 'stringio' require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/object/try' +require 'active_support/version' + +if ActiveSupport::VERSION::MAJOR > 2 + require 'active_support/core_ext/object/try' +else + require 'active_support/core_ext/module/delegation' + require 'active_support/core_ext/kernel/reporting' + require 'active_support/core_ext/try' +end + require 'active_support/inflector' require 'active_support/json' From 2163c1c266d50ea8c37bc5a44b5c4d401522766d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Jun 2013 11:59:44 -0600 Subject: [PATCH 0438/1191] Bump version 2.7.11 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5ab89636..b6650147 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.10' + VERSION = '2.7.11' PROTOC_VERSION = '2.4.1' end From da33287119d12d0dc075f1c9f6b37fabc4bb1aa6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 21 Jun 2013 15:35:50 -0600 Subject: [PATCH 0439/1191] Bump version 2.8.0.beta4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 11c7d27f..e0948a88 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta3' + VERSION = '2.8.0.beta4' PROTOC_VERSION = '2.4.1' end From 6f566298d1b6678911d96fbb942793d74099a784 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 25 Jun 2013 16:51:01 -0600 Subject: [PATCH 0440/1191] Fix address in use errors on osx OSX users were getting failures when trying to bind more than one client to the broadcast port. This change sets the REUSEPORT socket option on platforms where it is available. --- lib/protobuf/rpc/service_directory.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 1690dc29..04ed874b 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -169,6 +169,11 @@ def wait_for(service, timeout = DEFAULT_TIMEOUT) def init_socket @socket = UDPSocket.new @socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true) + + if defined?(::Socket::SO_REUSEPORT) + @socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, true) + end + @socket.bind(self.class.address, self.class.port.to_i) end From 4f0535a2460ff65996b9ad6ba156ac73494b4056 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 26 Jun 2013 09:26:52 -0600 Subject: [PATCH 0441/1191] Bump version 2.8.0.beta5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index e0948a88..2a95b4af 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta4' + VERSION = '2.8.0.beta5' PROTOC_VERSION = '2.4.1' end From b726708380ec080d63f9f65b51ad7d8d5d8423d0 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 1 Jul 2013 16:47:32 -0600 Subject: [PATCH 0442/1191] Respond to TTOU signal Prints the number of running workers --- lib/protobuf/rpc/servers/zmq_runner.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index de5bed33..0aefba4d 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -39,6 +39,10 @@ def register_signals @server.add_worker log_info { "Increased worker size to: #{@server.total_workers}" } end + + trap(:TTOU) do + log_info { "Current worker size: #{@server.workers.size}" } + end end end end From 112039fe6df325911ebd15f905b694a8aba1f8c8 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 2 Jul 2013 14:24:18 -0600 Subject: [PATCH 0443/1191] Do not allow the beacon address to be configured Broadcasts should always occur on 255.255.255.255 --- lib/protobuf/cli.rb | 1 - lib/protobuf/rpc/servers/zmq/server.rb | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 6dc0b909..4a12e2fa 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -29,7 +29,6 @@ class CLI < ::Thor option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' - option :beacon_address, :type => :string, :desc => 'Broadcast beacons to this address (defaul: value of ServiceDirectory.address)' option :beacon_interval, :type => :numeric, :desc => 'Broadcast beacons every N seconds. (default: 5)' option :beacon_port, :type => :numeric, :desc => 'Broadcast beacons to this port (default: value of ServiceDirectory.port)' option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 3d3fb0da..ea1f3d2c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -49,18 +49,6 @@ def beacon_interval [options[:beacon_interval].to_i, 1].max end - def beacon_ip - unless @beacon_ip - unless address = options[:beacon_address] - address = ::Protobuf::Rpc::ServiceDirectory.address - end - - @beacon_ip = resolve_ip(address) - end - - @beacon_ip - end - def beacon_port unless @beacon_port unless port = options[:beacon_port] @@ -74,7 +62,7 @@ def beacon_port end def beacon_uri - "udp://#{beacon_ip}:#{beacon_port}" + "udp://255.255.255.255:#{beacon_port}" end def broadcast_beacons? From 20bea942a03f75dcab21f0130b6811dd387930c7 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 2 Jul 2013 14:33:28 -0600 Subject: [PATCH 0444/1191] Restore the beacon_ip method I didn't realize this was being used --- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index ea1f3d2c..7b0438bb 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -49,6 +49,10 @@ def beacon_interval [options[:beacon_interval].to_i, 1].max end + def beacon_ip + "255.255.255.255" + end + def beacon_port unless @beacon_port unless port = options[:beacon_port] @@ -62,7 +66,7 @@ def beacon_port end def beacon_uri - "udp://255.255.255.255:#{beacon_port}" + "udp://#{beacon_ip}:#{beacon_port}" end def broadcast_beacons? From 9d5eec1a6b8030966e12c122d6e877c94b46d22e Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 3 Jul 2013 12:17:59 -0600 Subject: [PATCH 0445/1191] Cleanup the implementation of lazy pirate Removed excess moving parts. The socket is opened and closed in the same place, making the execution path more explicit. --- lib/protobuf/rpc/connectors/zmq.rb | 117 ++++++++++++----------------- 1 file changed, 46 insertions(+), 71 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 369b89ba..768ca356 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -6,6 +6,8 @@ module Rpc module Connectors class Zmq < Base + RequestTimeout = Class.new(RuntimeError) + ## # Included Modules # @@ -37,9 +39,7 @@ def self.zmq_context # def send_request setup_connection - poll_send_data - ensure - close_connection + send_request_with_lazy_pirate end def log_signature @@ -53,23 +53,23 @@ def log_signature # def close_connection - socket_close + # The socket is automatically closed after every request. end - # Establish a request socket connection to the remote rpc_server. - # Set the socket option LINGER to 0 so that we don't wait - # for queued messages to be accepted when the socket/context are - # asked to close/terminate. - # - def connect_to_rpc_server - return if error? - + # Create a socket connected to a server that can handle the current + # service. The LINGER is set to 0 so we can close immediately in + # the event of a timeout + def create_socket server_uri = lookup_server_uri - log_debug { sign_message("Establishing connection: #{server_uri}") } + + socket = zmq_context.socket(::ZMQ::REQ) socket.setsockopt(::ZMQ::LINGER, 0) + + log_debug { sign_message("Establishing connection: #{server_uri}") } zmq_error_check(socket.connect(server_uri), :socket_connect) - zmq_error_check(poller.register_readable(socket), :poller_register_readable) log_debug { sign_message("Connection established to #{server_uri}") } + + socket end # Method to determine error state, must be used with Connector API. @@ -97,53 +97,44 @@ def lookup_server_uri # If we haven't received a legitimate response in the CLIENT_RETRIES number # of retries, fail the request. # - def poll_send_data - return if error? - - poll_timeout = (options[:timeout].to_f / CLIENT_RETRIES.to_f) * 1000 - - CLIENT_RETRIES.times do |n| - connect_to_rpc_server - log_debug { sign_message("Sending Request (attempt #{n + 1}, #{socket})") } - send_data - log_debug { sign_message("Request sending complete (attempt #{n + 1}, #{socket})") } - - if poller.poll(poll_timeout) == 1 - read_response - return - else - socket_close - end - end - - fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond") - end + def send_request_with_lazy_pirate + attempt = 0 + timeout = options[:timeout].to_f + @stats.request_size = @request_data.size - def poller - @poller ||= ::ZMQ::Poller.new + begin + attempt += 1 + send_request_with_timeout(timeout, attempt) + parse_response + rescue RequestTimeout + retry if attempt < CLIENT_RETRIES + fail(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds") + rescue => e + fail(:RPC_FAILED, "Unexpected error sending request: #{e}") + end end - # Read the string response from the available readable. This will be - # the current @socket. Calls `parse_response` to invoke the success or - # failed callbacks, depending on the state of the communication - # and response data. - # - def read_response - return if error? + def send_request_with_timeout(timeout, attempt = 0) + socket = create_socket - @response_data = '' - zmq_error_check(socket.recv_string(@response_data), :socket_recv_string) + poller = ::ZMQ::Poller.new + poller.register_readable(socket) - parse_response - end - - # Send the request data to the remote rpc_server. - # - def send_data - return if error? - - @stats.request_size = @request_data.size + log_debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } zmq_error_check(socket.send_string(@request_data), :socket_send_string) + log_debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } + + if poller.poll(timeout * 1000) == 1 + zmq_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) + log_debug { sign_message("Response received (attempt #{attempt}, #{socket})") } + else + log_debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } + raise RequestTimeout + end + ensure + log_debug { sign_message("Closing Socket") } + zmq_error_check(socket.close, :socket_close) + log_debug { sign_message("Socket closed") } end # The service we're attempting to connect to @@ -157,21 +148,6 @@ def service_directory ::Protobuf::Rpc::ServiceDirectory.instance end - # Setup a ZMQ request socket in the current zmq context. - # - def socket - @socket ||= zmq_context.socket(::ZMQ::REQ) - end - - def socket_close - if socket - log_debug { sign_message("Closing Socket") } - zmq_error_check(socket.close, :socket_close) - log_debug { sign_message("Socket closed") } - @socket = nil - end - end - # Return the ZMQ Context to use for this process. # If the context does not exist, create it, then register # an exit block to ensure the context is terminated correctly. @@ -189,7 +165,6 @@ def zmq_error_check(return_code, source) ERROR end end - end end end From 42a623cff546101108b6a82f839b33f9f7718414 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 3 Jul 2013 15:40:12 -0600 Subject: [PATCH 0446/1191] Avoid context collisions from forked processes --- lib/protobuf/rpc/connectors/socket.rb | 1 - lib/protobuf/rpc/connectors/zmq.rb | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 7ded22b5..1694c201 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -68,7 +68,6 @@ def send_data @socket.flush log_debug { sign_message("write closed") } end - end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 768ca356..08e34be0 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -25,7 +25,11 @@ class Zmq < Base # Class Methods # def self.zmq_context - @zmq_context ||= ZMQ::Context.new + @zmq_contexts ||= Hash.new { |hash, key| + hash[key] = ZMQ::Context.new + } + + @zmq_contexts[Process.pid] end ## From c6832196caf0d20a2030814c411ec88f7745fa15 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 3 Jul 2013 17:51:07 -0600 Subject: [PATCH 0447/1191] Bump version 2.8.0.beta6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 2a95b4af..c62caee7 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta5' + VERSION = '2.8.0.beta6' PROTOC_VERSION = '2.4.1' end From c47683c108d2985d24124d151f8551470e8a6347 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 Jul 2013 12:57:40 -0600 Subject: [PATCH 0448/1191] Add a ping mechanism --- lib/protobuf/rpc/connectors/base.rb | 8 +++++ lib/protobuf/rpc/connectors/zmq.rb | 41 +++++++++++++++++++++----- lib/protobuf/rpc/servers/zmq/broker.rb | 7 +++-- lib/protobuf/rpc/servers/zmq/worker.rb | 9 ++++-- spec/functional/zmq_server_spec.rb | 2 +- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index e00c3889..9b78ec25 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -34,6 +34,14 @@ def initialize(options) def send_request raise 'If you inherit a Connector from Base you must implement send_request' end + + def ping_port + @ping_port ||= ENV["PB_RPC_PING_PORT"] + end + + def ping_port_enabled? + ENV.has_key?("PB_RPC_PING_PORT") + end end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 08e34be0..1f05223e 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -43,7 +43,7 @@ def self.zmq_context # def send_request setup_connection - send_request_with_lazy_pirate + send_request_with_lazy_pirate unless error? end def log_signature @@ -87,14 +87,41 @@ def error? # to the host and port in the options # def lookup_server_uri - if service_directory.running? - listing = service_directory.lookup(service) - host, port = listing.address, listing.port if listing + server_host = server_port = nil + + loop do + if service_directory.running? + listing = service_directory.lookup(service) + + if listing + server_host, server_port = listing.address, listing.port + end + end + + unless server_host && server_port + server_host, server_port = options[:host], options[:port] + end + + # TODO: Wonky double break is wonky. fix it. + if ping_port_enabled? + break if server_running?(server_host) + else + break + end end - host, port = options[:host], options[:port] unless host && port + "tcp://#{server_host}:#{server_port}" + end - "tcp://#{host}:#{port}" + def server_running?(host) + begin + socket = TCPSocket.new(host, ping_port) + true + rescue + false + ensure + socket.close rescue nil + end end # Trying a number of times, attempt to get a response from the server. @@ -113,8 +140,6 @@ def send_request_with_lazy_pirate rescue RequestTimeout retry if attempt < CLIENT_RETRIES fail(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds") - rescue => e - fail(:RPC_FAILED, "Unexpected error sending request: #{e}") end end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index fb31c326..b2a2451d 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -19,8 +19,11 @@ def initialize(server) def run @idle_workers = [] - while running? - break if @poller.poll(500) < 0 + loop do + rc = @poller.poll(500) + + # Break unless we're running or a request was received. + break unless running? || rc > 0 @poller.readables.each do |readable| case readable diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index d6bd4ffe..1c6752d9 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -41,10 +41,13 @@ def run # Send request to broker telling it we are ready write_to_backend([::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE]) - while running? - break if poller.poll(500) < 0 + loop do + rc = poller.poll(500) - if poller.readables.any? + # Break unless we're running or a request was received. + break unless running? || rc > 0 + + if rc > 0 initialize_request! process_request end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 433ccae6..29c3e0e5 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -104,7 +104,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure { |e| error = e } end - error.message.should match(/The server took longer than 1 seconds to respond/i) + error.message.should match(/The server repeatedly failed to respond/) end end From 4106bf135f7af2c0ea31c6412df666bc16074460 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 Jul 2013 13:42:17 -0600 Subject: [PATCH 0449/1191] Fix the wonky lookup_server_uri implementation Credit: @abrondoned --- lib/protobuf/rpc/connectors/zmq.rb | 30 +++++++++------------------ lib/protobuf/rpc/service_directory.rb | 4 ++++ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 1f05223e..7eec0326 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -87,33 +87,23 @@ def error? # to the host and port in the options # def lookup_server_uri - server_host = server_port = nil - - loop do + begin if service_directory.running? listing = service_directory.lookup(service) - - if listing - server_host, server_port = listing.address, listing.port - end - end - - unless server_host && server_port - server_host, server_port = options[:host], options[:port] + host = listing.try(:address) + port = listing.try(:port) end - # TODO: Wonky double break is wonky. fix it. - if ping_port_enabled? - break if server_running?(server_host) - else - break - end - end + host ||= options[:host] + port ||= options[:port] + end until usable_server?( host ) - "tcp://#{server_host}:#{server_port}" + "tcp://#{host}:#{port}" end - def server_running?(host) + def usable_server?(host) + return true unless ping_port_enabled? + begin socket = TCPSocket.new(host, ping_port) true diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 04ed874b..69562820 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -36,6 +36,10 @@ def ttl [super.to_i, 3].max end + def uri + "tcp://#{address}:#{port}" + end + def __getobj__ @server end From a4970ab9ecb006e9a444e13c9e5dc8641dbdf784 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 Jul 2013 14:05:28 -0600 Subject: [PATCH 0450/1191] Improve code readability --- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- lib/protobuf/rpc/servers/zmq/broker.rb | 7 +++++-- lib/protobuf/rpc/servers/zmq/worker.rb | 7 +++++-- lib/protobuf/rpc/service_directory.rb | 4 ---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 7eec0326..a6214f81 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -96,12 +96,12 @@ def lookup_server_uri host ||= options[:host] port ||= options[:port] - end until usable_server?( host ) + end until host_alive?( host ) "tcp://#{host}:#{port}" end - def usable_server?(host) + def host_alive?(host) return true unless ping_port_enabled? begin diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index b2a2451d..492ef44d 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -22,8 +22,11 @@ def run loop do rc = @poller.poll(500) - # Break unless we're running or a request was received. - break unless running? || rc > 0 + # The server was shutdown and no requests are pending + break if rc == 0 && !running? + + # Something went wrong + break if rc == -1 @poller.readables.each do |readable| case readable diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 1c6752d9..bdf7cee0 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -44,8 +44,11 @@ def run loop do rc = poller.poll(500) - # Break unless we're running or a request was received. - break unless running? || rc > 0 + # The server was shutdown and no requests are pending + break if rc == 0 && !running? + + # Something went wrong + break if rc == -1 if rc > 0 initialize_request! diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 69562820..04ed874b 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -36,10 +36,6 @@ def ttl [super.to_i, 3].max end - def uri - "tcp://#{address}:#{port}" - end - def __getobj__ @server end From ef8281d1dfa4198b69c16260f0ca743e929ae809 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 Jul 2013 14:21:23 -0600 Subject: [PATCH 0451/1191] Remove unneccessary begin/end block --- lib/protobuf/rpc/connectors/zmq.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a6214f81..a178a703 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -104,14 +104,11 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? - begin - socket = TCPSocket.new(host, ping_port) - true - rescue - false - ensure - socket.close rescue nil - end + TCPSocket.new(host, ping_port) && true + rescue + false + ensure + socket.close rescue nil end # Trying a number of times, attempt to get a response from the server. From 61c10ca468b9d02f23368224708abc646d947dcb Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 Jul 2013 14:34:26 -0600 Subject: [PATCH 0452/1191] Reconcile with feedback from pull request --- lib/protobuf/rpc/connectors/zmq.rb | 15 +++---- lib/protobuf/rpc/service_directory.rb | 25 ++++------- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 4 +- .../protobuf/rpc/service_directory_spec.rb | 41 ++----------------- 4 files changed, 20 insertions(+), 65 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a178a703..1a4e8fc2 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -88,14 +88,9 @@ def error? # def lookup_server_uri begin - if service_directory.running? - listing = service_directory.lookup(service) - host = listing.try(:address) - port = listing.try(:port) - end - - host ||= options[:host] - port ||= options[:port] + listing = service_directory.lookup(service) + host = listing.try(:address) || options[:host] + port = listing.try(:port) || options[:port] end until host_alive?( host ) "tcp://#{host}:#{port}" @@ -104,7 +99,9 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? - TCPSocket.new(host, ping_port) && true + socket = TCPSocket.new(host, ping_port) + + true rescue false ensure diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 04ed874b..59aa8524 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -89,14 +89,16 @@ def add_listing_for(server) end def lookup(service) - @mutex.synchronize do - listings = @listings.values.select do |listing| - listing.services.any? do |listed_service| - listing.current? && listed_service == service.to_s + if running? + @mutex.synchronize do + listings = @listings.values.select do |listing| + listing.services.any? do |listed_service| + listing.current? && listed_service == service.to_s + end end - end - listings.sample + listings.sample + end end end @@ -153,17 +155,6 @@ def stop @socket = nil end - def wait_for(service, timeout = DEFAULT_TIMEOUT) - log_debug { sign_message("waiting for #{service}") } - Timeout.timeout(timeout) do - sleep(timeout / 10.0) until listing = lookup(service) - listing - end - rescue - log_info { sign_message("no listing found for #{service}") } - nil - end - private def init_socket diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 2fd0afb9..30db3af8 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -52,8 +52,8 @@ context "when the service directory is not running" do let(:running?) { false } - it "does not search the directory" do - service_directory.should_not_receive(:lookup) + it "defaults to the options" do + service_directory.should_receive(:lookup) { nil } subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index e4c858d8..0f950adf 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -31,6 +31,10 @@ def duration :ttl => 15) } let(:listing) { ::Protobuf::Rpc::ServiceDirectory::Listing.new(server) } + before do + instance.stub(:running?) { true } + end + it "returns a listing for the given service" do instance.add_listing_for(server) instance.lookup("Known::Service").should eq listing @@ -95,43 +99,6 @@ def duration end end - describe "#wait_for" do - it "returns a listing for the given service" do - server = double(:uuid => 1, :ttl => 5, :services => ["Test"]) - instance.add_listing_for server - instance.lookup("Test").should eq server - end - - it "depends on #lookup" do - instance.stub(:lookup).with("Hayoob!") { "yup" } - instance.wait_for("Hayoob!").should eq "yup" - end - - it "waits for the service to appear" do - server = double(:uuid => 1, :ttl => 5, :services => ["Test"]) - - t = Thread.new do - sleep 0.5 - instance.add_listing_for server - end - - duration { instance.wait_for("Test") }.should be_within(0.01).of(0.5) - t.join - end - - it "returns nil if the service doesn't appear withint the timeout period" do - server = double(:uuid => 1, :ttl => 5, :services => ["Test"]) - - t = Thread.new do - sleep 0.5 - instance.add_listing_for server - end - - instance.wait_for("Test", 0.1).should be_nil - t.join - end - end - describe "a running service directory" do let(:socket) { UDPSocket.new } From 6da9afd7ed5b49fbb9eb5015273f57631b00bcfc Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 Jul 2013 14:52:59 -0600 Subject: [PATCH 0453/1191] Write some specs --- lib/protobuf/rpc/connectors/zmq.rb | 2 +- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 46 +++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 1a4e8fc2..b1028b9c 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -99,7 +99,7 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? - socket = TCPSocket.new(host, ping_port) + socket = TCPSocket.new(host, ping_port.to_i) true rescue diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 30db3af8..f8e48991 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -58,7 +58,51 @@ end end + it "checks if the server is alive" do + service_directory.should_receive(:lookup) { nil } + subject.should_receive(:host_alive?).with("127.0.0.1") { true } + subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" + end + end - pending + describe "#host_alive?" do + context "when the PB_RPC_PING_PORT is not set" do + before do + ENV.delete("PB_RPC_PING_PORT") + end + + it "returns true" do + subject.send(:host_alive?, "yip.yip").should be_true + end + + it "does not attempt a connection" do + TCPSocket.should_not_receive(:new) + subject.send(:host_alive?, "blargh.com") + end + end + + context "when the PB_RPC_PING_PORT is set" do + before do + ENV["PB_RPC_PING_PORT"] = "3307" + end + + it "returns true when the connection succeeds" do + TCPSocket.should_receive(:new).with("huzzah.com", 3307) { double(:close => nil) } + subject.send(:host_alive?, "huzzah.com").should be_true + end + + it "returns false when the connection fails" do + TCPSocket.should_receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) + subject.send(:host_alive?, "hayoob.com").should be_false + end + + it "closes the socket" do + socket = double("TCPSocket") + socket.should_receive(:close) + TCPSocket.should_receive(:new).with("absorbalof.com", 3307) { socket } + subject.send(:host_alive?, "absorbalof.com").should be_true + end + end + end end From 712d31daaf55f2be6c4aa394b5f78e7239a7f152 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Jul 2013 15:39:20 -0600 Subject: [PATCH 0454/1191] bump to beta8 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c62caee7..250b5b14 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta6' + VERSION = '2.8.0.beta8' PROTOC_VERSION = '2.4.1' end From 8451d5aa7fa357e123a5927105b927ab32b18c86 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 17 Jul 2013 14:20:35 -0600 Subject: [PATCH 0455/1191] Remove protobuf-2.4.1 source --- .../google/protobuf/compiler/code_generator.h | 142 - .../compiler/command_line_interface.h | 318 - .../google/protobuf/compiler/cpp/cpp_enum.h | 99 - .../protobuf/compiler/cpp/cpp_enum_field.h | 103 - .../protobuf/compiler/cpp/cpp_extension.h | 85 - .../google/protobuf/compiler/cpp/cpp_field.h | 167 - .../google/protobuf/compiler/cpp/cpp_file.h | 98 - .../protobuf/compiler/cpp/cpp_generator.h | 72 - .../protobuf/compiler/cpp/cpp_helpers.h | 159 - .../protobuf/compiler/cpp/cpp_message.h | 170 - .../protobuf/compiler/cpp/cpp_message_field.h | 102 - .../compiler/cpp/cpp_primitive_field.h | 103 - .../protobuf/compiler/cpp/cpp_service.h | 118 - .../protobuf/compiler/cpp/cpp_string_field.h | 104 - .../cpp/cpp_test_bad_identifiers.pb.h | 2721 ---- .../src/google/protobuf/compiler/importer.h | 303 - .../google/protobuf/compiler/java/java_enum.h | 84 - .../protobuf/compiler/java/java_enum_field.h | 121 - .../protobuf/compiler/java/java_extension.h | 77 - .../protobuf/compiler/java/java_field.h | 108 - .../google/protobuf/compiler/java/java_file.h | 101 - .../protobuf/compiler/java/java_generator.h | 72 - .../protobuf/compiler/java/java_helpers.h | 213 - .../protobuf/compiler/java/java_message.h | 109 - .../compiler/java/java_message_field.h | 134 - .../compiler/java/java_primitive_field.h | 121 - .../protobuf/compiler/java/java_service.h | 113 - .../compiler/java/java_string_field.h | 120 - .../protobuf/compiler/mock_code_generator.h | 113 - .../google/protobuf/compiler/package_info.h | 64 - .../src/google/protobuf/compiler/parser.h | 434 - .../src/google/protobuf/compiler/plugin.h | 73 - .../src/google/protobuf/compiler/plugin.pb.h | 790 - .../compiler/python/python_generator.h | 156 - .../src/google/protobuf/compiler/subprocess.h | 108 - .../src/google/protobuf/compiler/zip_writer.h | 93 - .../src/google/protobuf/descriptor.h | 1367 -- .../src/google/protobuf/descriptor.pb.h | 5223 ------- .../src/google/protobuf/descriptor_database.h | 366 - .../src/google/protobuf/dynamic_message.h | 136 - .../src/google/protobuf/extension_set.h | 904 -- .../protobuf/generated_message_reflection.h | 424 - .../google/protobuf/generated_message_util.h | 82 - .../src/google/protobuf/io/coded_stream.h | 1102 -- .../src/google/protobuf/io/coded_stream_inl.h | 64 - .../src/google/protobuf/io/gzip_stream.h | 207 - .../src/google/protobuf/io/package_info.h | 54 - .../src/google/protobuf/io/printer.h | 136 - .../src/google/protobuf/io/tokenizer.h | 313 - .../src/google/protobuf/io/zero_copy_stream.h | 238 - .../protobuf/io/zero_copy_stream_impl.h | 357 - .../protobuf/io/zero_copy_stream_impl_lite.h | 340 - .../src/google/protobuf/message.h | 692 - .../src/google/protobuf/message_lite.h | 239 - .../src/google/protobuf/package_info.h | 64 - .../src/google/protobuf/reflection_ops.h | 80 - .../src/google/protobuf/repeated_field.h | 1295 -- .../src/google/protobuf/service.h | 291 - .../src/google/protobuf/stubs/common.h | 1211 -- .../src/google/protobuf/stubs/hash.h | 220 - .../src/google/protobuf/stubs/map-util.h | 119 - .../src/google/protobuf/stubs/once.h | 123 - .../src/google/protobuf/stubs/stl_util-inl.h | 121 - .../src/google/protobuf/stubs/strutil.h | 457 - .../src/google/protobuf/stubs/substitute.h | 170 - .../src/google/protobuf/test_util.h | 174 - .../src/google/protobuf/test_util_lite.h | 101 - .../src/google/protobuf/testing/file.h | 83 - .../src/google/protobuf/testing/googletest.h | 98 - .../src/google/protobuf/text_format.h | 285 - .../src/google/protobuf/unittest.pb.h | 11915 ---------------- .../protobuf/unittest_custom_options.pb.h | 2895 ---- .../protobuf/unittest_embed_optimize_for.pb.h | 211 - .../src/google/protobuf/unittest_empty.pb.h | 56 - .../src/google/protobuf/unittest_import.pb.h | 188 - .../google/protobuf/unittest_import_lite.pb.h | 151 - .../src/google/protobuf/unittest_lite.pb.h | 4752 ------ .../unittest_lite_imports_nonlite.pb.h | 150 - .../src/google/protobuf/unittest_mset.pb.h | 816 -- .../unittest_no_generic_services.pb.h | 197 - .../protobuf/unittest_optimize_for.pb.h | 403 - .../src/google/protobuf/unknown_field_set.h | 268 - .../src/google/protobuf/wire_format.h | 304 - .../src/google/protobuf/wire_format_lite.h | 620 - .../google/protobuf/wire_format_lite_inl.h | 774 - 85 files changed, 48904 deletions(-) delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/descriptor.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/extension_set.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/printer.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/message.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/message_lite.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/package_info.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/service.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/test_util.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/testing/file.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/text_format.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/wire_format.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h delete mode 100644 ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h deleted file mode 100644 index 252f68d1..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +++ /dev/null @@ -1,142 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines the abstract interface implemented by each of the language-specific -// code generators. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ - -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -namespace io { class ZeroCopyOutputStream; } -class FileDescriptor; - -namespace compiler { - -// Defined in this file. -class CodeGenerator; -class GeneratorContext; - -// The abstract interface to a class which generates code implementing a -// particular proto file in a particular language. A number of these may -// be registered with CommandLineInterface to support various languages. -class LIBPROTOC_EXPORT CodeGenerator { - public: - inline CodeGenerator() {} - virtual ~CodeGenerator(); - - // Generates code for the given proto file, generating one or more files in - // the given output directory. - // - // A parameter to be passed to the generator can be specified on the - // command line. This is intended to be used by Java and similar languages - // to specify which specific class from the proto file is to be generated, - // though it could have other uses as well. It is empty if no parameter was - // given. - // - // Returns true if successful. Otherwise, sets *error to a description of - // the problem (e.g. "invalid parameter") and returns false. - virtual bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); -}; - -// CodeGenerators generate one or more files in a given directory. This -// abstract interface represents the directory to which the CodeGenerator is -// to write and other information about the context in which the Generator -// runs. -class LIBPROTOC_EXPORT GeneratorContext { - public: - inline GeneratorContext() {} - virtual ~GeneratorContext(); - - // Opens the given file, truncating it if it exists, and returns a - // ZeroCopyOutputStream that writes to the file. The caller takes ownership - // of the returned object. This method never fails (a dummy stream will be - // returned instead). - // - // The filename given should be relative to the root of the source tree. - // E.g. the C++ generator, when generating code for "foo/bar.proto", will - // generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that - // "foo/" is included in these filenames. The filename is not allowed to - // contain "." or ".." components. - virtual io::ZeroCopyOutputStream* Open(const string& filename) = 0; - - // Creates a ZeroCopyOutputStream which will insert code into the given file - // at the given insertion point. See plugin.proto (plugin.pb.h) for more - // information on insertion points. The default implementation - // assert-fails -- it exists only for backwards-compatibility. - // - // WARNING: This feature is currently EXPERIMENTAL and is subject to change. - virtual io::ZeroCopyOutputStream* OpenForInsert( - const string& filename, const string& insertion_point); - - // Returns a vector of FileDescriptors for all the files being compiled - // in this run. Useful for languages, such as Go, that treat files - // differently when compiled as a set rather than individually. - virtual void ListParsedFiles(vector* output); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext); -}; - -// The type GeneratorContext was once called OutputDirectory. This typedef -// provides backward compatibility. -typedef GeneratorContext OutputDirectory; - -// Several code generators treat the parameter argument as holding a -// list of options separated by commas. This helper function parses -// a set of comma-delimited name/value pairs: e.g., -// "foo=bar,baz,qux=corge" -// parses to the pairs: -// ("foo", "bar"), ("baz", ""), ("qux", "corge") -extern void ParseGeneratorParameter(const string&, - vector >*); - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h deleted file mode 100644 index 0b507d80..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +++ /dev/null @@ -1,318 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Implements the Protocol Compiler front-end such that it may be reused by -// custom compilers written to support other languages. - -#ifndef GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ -#define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ - -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -class FileDescriptor; // descriptor.h -class DescriptorPool; // descriptor.h -class FileDescriptorProto; // descriptor.pb.h -template class RepeatedPtrField; // repeated_field.h - -namespace compiler { - -class CodeGenerator; // code_generator.h -class GeneratorContext; // code_generator.h -class DiskSourceTree; // importer.h - -// This class implements the command-line interface to the protocol compiler. -// It is designed to make it very easy to create a custom protocol compiler -// supporting the languages of your choice. For example, if you wanted to -// create a custom protocol compiler binary which includes both the regular -// C++ support plus support for your own custom output "Foo", you would -// write a class "FooGenerator" which implements the CodeGenerator interface, -// then write a main() procedure like this: -// -// int main(int argc, char* argv[]) { -// google::protobuf::compiler::CommandLineInterface cli; -// -// // Support generation of C++ source and headers. -// google::protobuf::compiler::cpp::CppGenerator cpp_generator; -// cli.RegisterGenerator("--cpp_out", &cpp_generator, -// "Generate C++ source and header."); -// -// // Support generation of Foo code. -// FooGenerator foo_generator; -// cli.RegisterGenerator("--foo_out", &foo_generator, -// "Generate Foo file."); -// -// return cli.Run(argc, argv); -// } -// -// The compiler is invoked with syntax like: -// protoc --cpp_out=outdir --foo_out=outdir --proto_path=src src/foo.proto -// -// For a full description of the command-line syntax, invoke it with --help. -class LIBPROTOC_EXPORT CommandLineInterface { - public: - CommandLineInterface(); - ~CommandLineInterface(); - - // Register a code generator for a language. - // - // Parameters: - // * flag_name: The command-line flag used to specify an output file of - // this type. The name must start with a '-'. If the name is longer - // than one letter, it must start with two '-'s. - // * generator: The CodeGenerator which will be called to generate files - // of this type. - // * help_text: Text describing this flag in the --help output. - // - // Some generators accept extra parameters. You can specify this parameter - // on the command-line by placing it before the output directory, separated - // by a colon: - // protoc --foo_out=enable_bar:outdir - // The text before the colon is passed to CodeGenerator::Generate() as the - // "parameter". - void RegisterGenerator(const string& flag_name, - CodeGenerator* generator, - const string& help_text); - - // Enables "plugins". In this mode, if a command-line flag ends with "_out" - // but does not match any registered generator, the compiler will attempt to - // find a "plugin" to implement the generator. Plugins are just executables. - // They should live somewhere in the PATH. - // - // The compiler determines the executable name to search for by concatenating - // exe_name_prefix with the unrecognized flag name, removing "_out". So, for - // example, if exe_name_prefix is "protoc-" and you pass the flag --foo_out, - // the compiler will try to run the program "protoc-foo". - // - // The plugin program should implement the following usage: - // plugin [--out=OUTDIR] [--parameter=PARAMETER] PROTO_FILES < DESCRIPTORS - // --out indicates the output directory (as passed to the --foo_out - // parameter); if omitted, the current directory should be used. --parameter - // gives the generator parameter, if any was provided. The PROTO_FILES list - // the .proto files which were given on the compiler command-line; these are - // the files for which the plugin is expected to generate output code. - // Finally, DESCRIPTORS is an encoded FileDescriptorSet (as defined in - // descriptor.proto). This is piped to the plugin's stdin. The set will - // include descriptors for all the files listed in PROTO_FILES as well as - // all files that they import. The plugin MUST NOT attempt to read the - // PROTO_FILES directly -- it must use the FileDescriptorSet. - // - // The plugin should generate whatever files are necessary, as code generators - // normally do. It should write the names of all files it generates to - // stdout. The names should be relative to the output directory, NOT absolute - // names or relative to the current directory. If any errors occur, error - // messages should be written to stderr. If an error is fatal, the plugin - // should exit with a non-zero exit code. - void AllowPlugins(const string& exe_name_prefix); - - // Run the Protocol Compiler with the given command-line parameters. - // Returns the error code which should be returned by main(). - // - // It may not be safe to call Run() in a multi-threaded environment because - // it calls strerror(). I'm not sure why you'd want to do this anyway. - int Run(int argc, const char* const argv[]); - - // Call SetInputsAreCwdRelative(true) if the input files given on the command - // line should be interpreted relative to the proto import path specified - // using --proto_path or -I flags. Otherwise, input file names will be - // interpreted relative to the current working directory (or as absolute - // paths if they start with '/'), though they must still reside inside - // a directory given by --proto_path or the compiler will fail. The latter - // mode is generally more intuitive and easier to use, especially e.g. when - // defining implicit rules in Makefiles. - void SetInputsAreProtoPathRelative(bool enable) { - inputs_are_proto_path_relative_ = enable; - } - - // Provides some text which will be printed when the --version flag is - // used. The version of libprotoc will also be printed on the next line - // after this text. - void SetVersionInfo(const string& text) { - version_info_ = text; - } - - - private: - // ----------------------------------------------------------------- - - class ErrorPrinter; - class GeneratorContextImpl; - class MemoryOutputStream; - - // Clear state from previous Run(). - void Clear(); - - // Remaps each file in input_files_ so that it is relative to one of the - // directories in proto_path_. Returns false if an error occurred. This - // is only used if inputs_are_proto_path_relative_ is false. - bool MakeInputsBeProtoPathRelative( - DiskSourceTree* source_tree); - - // Parse all command-line arguments. - bool ParseArguments(int argc, const char* const argv[]); - - // Parses a command-line argument into a name/value pair. Returns - // true if the next argument in the argv should be used as the value, - // false otherwise. - // - // Exmaples: - // "-Isrc/protos" -> - // name = "-I", value = "src/protos" - // "--cpp_out=src/foo.pb2.cc" -> - // name = "--cpp_out", value = "src/foo.pb2.cc" - // "foo.proto" -> - // name = "", value = "foo.proto" - bool ParseArgument(const char* arg, string* name, string* value); - - // Interprets arguments parsed with ParseArgument. - bool InterpretArgument(const string& name, const string& value); - - // Print the --help text to stderr. - void PrintHelpText(); - - // Generate the given output file from the given input. - struct OutputDirective; // see below - bool GenerateOutput(const vector& parsed_files, - const OutputDirective& output_directive, - GeneratorContext* generator_context); - bool GeneratePluginOutput(const vector& parsed_files, - const string& plugin_name, - const string& parameter, - GeneratorContext* generator_context, - string* error); - - // Implements --encode and --decode. - bool EncodeOrDecode(const DescriptorPool* pool); - - // Implements the --descriptor_set_out option. - bool WriteDescriptorSet(const vector parsed_files); - - // Get all transitive dependencies of the given file (including the file - // itself), adding them to the given list of FileDescriptorProtos. The - // protos will be ordered such that every file is listed before any file that - // depends on it, so that you can call DescriptorPool::BuildFile() on them - // in order. Any files in *already_seen will not be added, and each file - // added will be inserted into *already_seen. - static void GetTransitiveDependencies( - const FileDescriptor* file, - set* already_seen, - RepeatedPtrField* output); - - // ----------------------------------------------------------------- - - // The name of the executable as invoked (i.e. argv[0]). - string executable_name_; - - // Version info set with SetVersionInfo(). - string version_info_; - - // Map from flag names to registered generators. - struct GeneratorInfo { - CodeGenerator* generator; - string help_text; - }; - typedef map GeneratorMap; - GeneratorMap generators_; - - // See AllowPlugins(). If this is empty, plugins aren't allowed. - string plugin_prefix_; - - // Maps specific plugin names to files. When executing a plugin, this map - // is searched first to find the plugin executable. If not found here, the - // PATH (or other OS-specific search strategy) is searched. - map plugins_; - - // Stuff parsed from command line. - enum Mode { - MODE_COMPILE, // Normal mode: parse .proto files and compile them. - MODE_ENCODE, // --encode: read text from stdin, write binary to stdout. - MODE_DECODE // --decode: read binary from stdin, write text to stdout. - }; - - Mode mode_; - - enum ErrorFormat { - ERROR_FORMAT_GCC, // GCC error output format (default). - ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs). - }; - - ErrorFormat error_format_; - - vector > proto_path_; // Search path for proto files. - vector input_files_; // Names of the input proto files. - - // output_directives_ lists all the files we are supposed to output and what - // generator to use for each. - struct OutputDirective { - string name; // E.g. "--foo_out" - CodeGenerator* generator; // NULL for plugins - string parameter; - string output_location; - }; - vector output_directives_; - - // When using --encode or --decode, this names the type we are encoding or - // decoding. (Empty string indicates --decode_raw.) - string codec_type_; - - // If --descriptor_set_out was given, this is the filename to which the - // FileDescriptorSet should be written. Otherwise, empty. - string descriptor_set_name_; - - // True if --include_imports was given, meaning that we should - // write all transitive dependencies to the DescriptorSet. Otherwise, only - // the .proto files listed on the command-line are added. - bool imports_in_descriptor_set_; - - // Was the --disallow_services flag used? - bool disallow_services_; - - // See SetInputsAreProtoPathRelative(). - bool inputs_are_proto_path_relative_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface); -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h deleted file mode 100644 index 58f7721e..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +++ /dev/null @@ -1,99 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ - -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace cpp { - -class EnumGenerator { - public: - // See generator.cc for the meaning of dllexport_decl. - explicit EnumGenerator(const EnumDescriptor* descriptor, - const string& dllexport_decl); - ~EnumGenerator(); - - // Header stuff. - - // Generate header code defining the enum. This code should be placed - // within the enum's package namespace, but NOT within any class, even for - // nested enums. - void GenerateDefinition(io::Printer* printer); - - // Generate specialization of GetEnumDescriptor(). - // Precondition: in ::google::protobuf namespace. - void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); - - // For enums nested within a message, generate code to import all the enum's - // symbols (e.g. the enum type name, all its values, etc.) into the class's - // namespace. This should be placed inside the class definition in the - // header. - void GenerateSymbolImports(io::Printer* printer); - - // Source file stuff. - - // Generate code that initializes the global variable storing the enum's - // descriptor. - void GenerateDescriptorInitializer(io::Printer* printer, int index); - - // Generate non-inline methods related to the enum, such as IsValidValue(). - // Goes in the .cc file. - void GenerateMethods(io::Printer* printer); - - private: - const EnumDescriptor* descriptor_; - string classname_; - string dllexport_decl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h deleted file mode 100644 index 0793430c..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +++ /dev/null @@ -1,103 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace cpp { - -class EnumFieldGenerator : public FieldGenerator { - public: - explicit EnumFieldGenerator(const FieldDescriptor* descriptor); - ~EnumFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); -}; - -class RepeatedEnumFieldGenerator : public FieldGenerator { - public: - explicit RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor); - ~RepeatedEnumFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h deleted file mode 100644 index 3068b091..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +++ /dev/null @@ -1,85 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__ - -#include -#include - -namespace google { -namespace protobuf { - class FieldDescriptor; // descriptor.h - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace cpp { - -// Generates code for an extension, which may be within the scope of some -// message or may be at file scope. This is much simpler than FieldGenerator -// since extensions are just simple identifiers with interesting types. -class ExtensionGenerator { - public: - // See generator.cc for the meaning of dllexport_decl. - explicit ExtensionGenerator(const FieldDescriptor* descriptor, - const string& dllexport_decl); - ~ExtensionGenerator(); - - // Header stuff. - void GenerateDeclaration(io::Printer* printer); - - // Source file stuff. - void GenerateDefinition(io::Printer* printer); - - // Generate code to register the extension. - void GenerateRegistration(io::Printer* printer); - - private: - const FieldDescriptor* descriptor_; - string type_traits_; - string dllexport_decl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h deleted file mode 100644 index c303a337..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +++ /dev/null @@ -1,167 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ - -#include -#include - -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace cpp { - -// Helper function: set variables in the map that are the same for all -// field code generators. -// ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', -// 'deprecation']. -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - map* variables); - -class FieldGenerator { - public: - FieldGenerator() {} - virtual ~FieldGenerator(); - - // Generate lines of code declaring members fields of the message class - // needed to represent this field. These are placed inside the message - // class. - virtual void GeneratePrivateMembers(io::Printer* printer) const = 0; - - // Generate prototypes for all of the accessor functions related to this - // field. These are placed inside the class definition. - virtual void GenerateAccessorDeclarations(io::Printer* printer) const = 0; - - // Generate inline definitions of accessor functions for this field. - // These are placed inside the header after all class definitions. - virtual void GenerateInlineAccessorDefinitions( - io::Printer* printer) const = 0; - - // Generate definitions of accessors that aren't inlined. These are - // placed somewhere in the .cc file. - // Most field types don't need this, so the default implementation is empty. - virtual void GenerateNonInlineAccessorDefinitions( - io::Printer* printer) const {} - - // Generate lines of code (statements, not declarations) which clear the - // field. This is used to define the clear_$name$() method as well as - // the Clear() method for the whole message. - virtual void GenerateClearingCode(io::Printer* printer) const = 0; - - // Generate lines of code (statements, not declarations) which merges the - // contents of the field from the current message to the target message, - // which is stored in the generated code variable "from". - // This is used to fill in the MergeFrom method for the whole message. - // Details of this usage can be found in message.cc under the - // GenerateMergeFrom method. - virtual void GenerateMergingCode(io::Printer* printer) const = 0; - - // Generate lines of code (statements, not declarations) which swaps - // this field and the corresponding field of another message, which - // is stored in the generated code variable "other". This is used to - // define the Swap method. Details of usage can be found in - // message.cc under the GenerateSwap method. - virtual void GenerateSwappingCode(io::Printer* printer) const = 0; - - // Generate initialization code for private members declared by - // GeneratePrivateMembers(). These go into the message class's SharedCtor() - // method, invoked by each of the generated constructors. - virtual void GenerateConstructorCode(io::Printer* printer) const = 0; - - // Generate any code that needs to go in the class's SharedDtor() method, - // invoked by the destructor. - // Most field types don't need this, so the default implementation is empty. - virtual void GenerateDestructorCode(io::Printer* printer) const {} - - // Generate lines to decode this field, which will be placed inside the - // message's MergeFromCodedStream() method. - virtual void GenerateMergeFromCodedStream(io::Printer* printer) const = 0; - - // Generate lines to decode this field from a packed value, which will be - // placed inside the message's MergeFromCodedStream() method. - virtual void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) - const; - - // Generate lines to serialize this field, which are placed within the - // message's SerializeWithCachedSizes() method. - virtual void GenerateSerializeWithCachedSizes(io::Printer* printer) const = 0; - - // Generate lines to serialize this field directly to the array "target", - // which are placed within the message's SerializeWithCachedSizesToArray() - // method. This must also advance "target" past the written bytes. - virtual void GenerateSerializeWithCachedSizesToArray( - io::Printer* printer) const = 0; - - // Generate lines to compute the serialized size of this field, which - // are placed in the message's ByteSize() method. - virtual void GenerateByteSize(io::Printer* printer) const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); -}; - -// Convenience class which constructs FieldGenerators for a Descriptor. -class FieldGeneratorMap { - public: - explicit FieldGeneratorMap(const Descriptor* descriptor); - ~FieldGeneratorMap(); - - const FieldGenerator& get(const FieldDescriptor* field) const; - - private: - const Descriptor* descriptor_; - scoped_array > field_generators_; - - static FieldGenerator* MakeGenerator(const FieldDescriptor* field); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); -}; - - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h deleted file mode 100644 index b4e01285..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +++ /dev/null @@ -1,98 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ - -#include -#include -#include -#include - -namespace google { -namespace protobuf { - class FileDescriptor; // descriptor.h - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace cpp { - -class EnumGenerator; // enum.h -class MessageGenerator; // message.h -class ServiceGenerator; // service.h -class ExtensionGenerator; // extension.h - -class FileGenerator { - public: - // See generator.cc for the meaning of dllexport_decl. - explicit FileGenerator(const FileDescriptor* file, - const string& dllexport_decl); - ~FileGenerator(); - - void GenerateHeader(io::Printer* printer); - void GenerateSource(io::Printer* printer); - - private: - // Generate the BuildDescriptors() procedure, which builds all descriptors - // for types defined in the file. - void GenerateBuildDescriptors(io::Printer* printer); - - void GenerateNamespaceOpeners(io::Printer* printer); - void GenerateNamespaceClosers(io::Printer* printer); - - const FileDescriptor* file_; - - scoped_array > message_generators_; - scoped_array > enum_generators_; - scoped_array > service_generators_; - scoped_array > extension_generators_; - - // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}. - vector package_parts_; - - string dllexport_decl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h deleted file mode 100644 index a90e84d7..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Generates C++ code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace cpp { - -// CodeGenerator implementation which generates a C++ source file and -// header. If you create your own protocol compiler binary and you want -// it to support C++ output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT CppGenerator : public CodeGenerator { - public: - CppGenerator(); - ~CppGenerator(); - - // implements CodeGenerator ---------------------------------------- - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CppGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h deleted file mode 100644 index b13d53be..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ /dev/null @@ -1,159 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace cpp { - -// Commonly-used separator comments. Thick is a line of '=', thin is a line -// of '-'. -extern const char kThickSeparator[]; -extern const char kThinSeparator[]; - -// Returns the non-nested type name for the given type. If "qualified" is -// true, prefix the type with the full namespace. For example, if you had: -// package foo.bar; -// message Baz { message Qux {} } -// Then the qualified ClassName for Qux would be: -// ::foo::bar::Baz_Qux -// While the non-qualified version would be: -// Baz_Qux -string ClassName(const Descriptor* descriptor, bool qualified); -string ClassName(const EnumDescriptor* enum_descriptor, bool qualified); - -string SuperClassName(const Descriptor* descriptor); - -// Get the (unqualified) name that should be used for this field in C++ code. -// The name is coerced to lower-case to emulate proto1 behavior. People -// should be using lowercase-with-underscores style for proto field names -// anyway, so normally this just returns field->name(). -string FieldName(const FieldDescriptor* field); - -// Get the unqualified name that should be used for a field's field -// number constant. -string FieldConstantName(const FieldDescriptor *field); - -// Returns the scope where the field was defined (for extensions, this is -// different from the message type to which the field applies). -inline const Descriptor* FieldScope(const FieldDescriptor* field) { - return field->is_extension() ? - field->extension_scope() : field->containing_type(); -} - -// Returns the fully-qualified type name field->message_type(). Usually this -// is just ClassName(field->message_type(), true); -string FieldMessageTypeName(const FieldDescriptor* field); - -// Strips ".proto" or ".protodevel" from the end of a filename. -string StripProto(const string& filename); - -// Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.). -// Note: non-built-in type names will be qualified, meaning they will start -// with a ::. If you are using the type as a template parameter, you will -// need to insure there is a space between the < and the ::, because the -// ridiculous C++ standard defines "<:" to be a synonym for "[". -const char* PrimitiveTypeName(FieldDescriptor::CppType type); - -// Get the declared type name in CamelCase format, as is used e.g. for the -// methods of WireFormat. For example, TYPE_INT32 becomes "Int32". -const char* DeclaredTypeMethodName(FieldDescriptor::Type type); - -// Get code that evaluates to the field's default value. -string DefaultValue(const FieldDescriptor* field); - -// Convert a file name into a valid identifier. -string FilenameIdentifier(const string& filename); - -// Return the name of the AddDescriptors() function for a given file. -string GlobalAddDescriptorsName(const string& filename); - -// Return the name of the AssignDescriptors() function for a given file. -string GlobalAssignDescriptorsName(const string& filename); - -// Return the name of the ShutdownFile() function for a given file. -string GlobalShutdownFileName(const string& filename); - -// Escape C++ trigraphs by escaping question marks to \? -string EscapeTrigraphs(const string& to_escape); - -// Do message classes in this file keep track of unknown fields? -inline bool HasUnknownFields(const FileDescriptor *file) { - return file->options().optimize_for() != FileOptions::LITE_RUNTIME; -} - -// Does this file have generated parsing, serialization, and other -// standard methods for which reflection-based fallback implementations exist? -inline bool HasGeneratedMethods(const FileDescriptor *file) { - return file->options().optimize_for() != FileOptions::CODE_SIZE; -} - -// Do message classes in this file have descriptor and refelction methods? -inline bool HasDescriptorMethods(const FileDescriptor *file) { - return file->options().optimize_for() != FileOptions::LITE_RUNTIME; -} - -// Should we generate generic services for this file? -inline bool HasGenericServices(const FileDescriptor *file) { - return file->service_count() > 0 && - file->options().optimize_for() != FileOptions::LITE_RUNTIME && - file->options().cc_generic_services(); -} - -// Should string fields in this file verify that their contents are UTF-8? -inline bool HasUtf8Verification(const FileDescriptor* file) { - return file->options().optimize_for() != FileOptions::LITE_RUNTIME; -} - -// Should we generate a separate, super-optimized code path for serializing to -// flat arrays? We don't do this in Lite mode because we'd rather reduce code -// size. -inline bool HasFastArraySerialization(const FileDescriptor* file) { - return file->options().optimize_for() == FileOptions::SPEED; -} - - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h deleted file mode 100644 index 04778f6d..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +++ /dev/null @@ -1,170 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace cpp { - -class EnumGenerator; // enum.h -class ExtensionGenerator; // extension.h - -class MessageGenerator { - public: - // See generator.cc for the meaning of dllexport_decl. - explicit MessageGenerator(const Descriptor* descriptor, - const string& dllexport_decl); - ~MessageGenerator(); - - // Header stuff. - - // Generate foward declarations for this class and all its nested types. - void GenerateForwardDeclaration(io::Printer* printer); - - // Generate definitions of all nested enums (must come before class - // definitions because those classes use the enums definitions). - void GenerateEnumDefinitions(io::Printer* printer); - - // Generate specializations of GetEnumDescriptor(). - // Precondition: in ::google::protobuf namespace. - void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); - - // Generate definitions for this class and all its nested types. - void GenerateClassDefinition(io::Printer* printer); - - // Generate definitions of inline methods (placed at the end of the header - // file). - void GenerateInlineMethods(io::Printer* printer); - - // Source file stuff. - - // Generate code which declares all the global descriptor pointers which - // will be initialized by the methods below. - void GenerateDescriptorDeclarations(io::Printer* printer); - - // Generate code that initializes the global variable storing the message's - // descriptor. - void GenerateDescriptorInitializer(io::Printer* printer, int index); - - // Generate code that calls MessageFactory::InternalRegisterGeneratedMessage() - // for all types. - void GenerateTypeRegistrations(io::Printer* printer); - - // Generates code that allocates the message's default instance. - void GenerateDefaultInstanceAllocator(io::Printer* printer); - - // Generates code that initializes the message's default instance. This - // is separate from allocating because all default instances must be - // allocated before any can be initialized. - void GenerateDefaultInstanceInitializer(io::Printer* printer); - - // Generates code that should be run when ShutdownProtobufLibrary() is called, - // to delete all dynamically-allocated objects. - void GenerateShutdownCode(io::Printer* printer); - - // Generate all non-inline methods for this class. - void GenerateClassMethods(io::Printer* printer); - - private: - // Generate declarations and definitions of accessors for fields. - void GenerateFieldAccessorDeclarations(io::Printer* printer); - void GenerateFieldAccessorDefinitions(io::Printer* printer); - - // Generate the field offsets array. - void GenerateOffsets(io::Printer* printer); - - // Generate constructors and destructor. - void GenerateStructors(io::Printer* printer); - - // The compiler typically generates multiple copies of each constructor and - // destructor: http://gcc.gnu.org/bugs.html#nonbugs_cxx - // Placing common code in a separate method reduces the generated code size. - // - // Generate the shared constructor code. - void GenerateSharedConstructorCode(io::Printer* printer); - // Generate the shared destructor code. - void GenerateSharedDestructorCode(io::Printer* printer); - - // Generate standard Message methods. - void GenerateClear(io::Printer* printer); - void GenerateMergeFromCodedStream(io::Printer* printer); - void GenerateSerializeWithCachedSizes(io::Printer* printer); - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer); - void GenerateSerializeWithCachedSizesBody(io::Printer* printer, - bool to_array); - void GenerateByteSize(io::Printer* printer); - void GenerateMergeFrom(io::Printer* printer); - void GenerateCopyFrom(io::Printer* printer); - void GenerateSwap(io::Printer* printer); - void GenerateIsInitialized(io::Printer* printer); - - // Helpers for GenerateSerializeWithCachedSizes(). - void GenerateSerializeOneField(io::Printer* printer, - const FieldDescriptor* field, - bool unbounded); - void GenerateSerializeOneExtensionRange( - io::Printer* printer, const Descriptor::ExtensionRange* range, - bool unbounded); - - - const Descriptor* descriptor_; - string classname_; - string dllexport_decl_; - FieldGeneratorMap field_generators_; - scoped_array > nested_generators_; - scoped_array > enum_generators_; - scoped_array > extension_generators_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h deleted file mode 100644 index f5147278..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +++ /dev/null @@ -1,102 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace cpp { - -class MessageFieldGenerator : public FieldGenerator { - public: - explicit MessageFieldGenerator(const FieldDescriptor* descriptor); - ~MessageFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); -}; - -class RepeatedMessageFieldGenerator : public FieldGenerator { - public: - explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor); - ~RepeatedMessageFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h deleted file mode 100644 index 8fcd74ae..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +++ /dev/null @@ -1,103 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace cpp { - -class PrimitiveFieldGenerator : public FieldGenerator { - public: - explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor); - ~PrimitiveFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); -}; - -class RepeatedPrimitiveFieldGenerator : public FieldGenerator { - public: - explicit RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor); - ~RepeatedPrimitiveFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h deleted file mode 100644 index 10e9dd3c..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +++ /dev/null @@ -1,118 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ - -#include -#include -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace cpp { - -class ServiceGenerator { - public: - // See generator.cc for the meaning of dllexport_decl. - explicit ServiceGenerator(const ServiceDescriptor* descriptor, - const string& dllexport_decl); - ~ServiceGenerator(); - - // Header stuff. - - // Generate the class definitions for the service's interface and the - // stub implementation. - void GenerateDeclarations(io::Printer* printer); - - // Source file stuff. - - // Generate code that initializes the global variable storing the service's - // descriptor. - void GenerateDescriptorInitializer(io::Printer* printer, int index); - - // Generate implementations of everything declared by GenerateDeclarations(). - void GenerateImplementation(io::Printer* printer); - - private: - enum RequestOrResponse { REQUEST, RESPONSE }; - enum VirtualOrNon { VIRTUAL, NON_VIRTUAL }; - - // Header stuff. - - // Generate the service abstract interface. - void GenerateInterface(io::Printer* printer); - - // Generate the stub class definition. - void GenerateStubDefinition(io::Printer* printer); - - // Prints signatures for all methods in the - void GenerateMethodSignatures(VirtualOrNon virtual_or_non, - io::Printer* printer); - - // Source file stuff. - - // Generate the default implementations of the service methods, which - // produce a "not implemented" error. - void GenerateNotImplementedMethods(io::Printer* printer); - - // Generate the CallMethod() method of the service. - void GenerateCallMethod(io::Printer* printer); - - // Generate the Get{Request,Response}Prototype() methods. - void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); - - // Generate the stub's implementations of the service methods. - void GenerateStubMethods(io::Printer* printer); - - const ServiceDescriptor* descriptor_; - map vars_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h deleted file mode 100644 index 7f45107d..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +++ /dev/null @@ -1,104 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace cpp { - -class StringFieldGenerator : public FieldGenerator { - public: - explicit StringFieldGenerator(const FieldDescriptor* descriptor); - ~StringFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateDestructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator); -}; - -class RepeatedStringFieldGenerator : public FieldGenerator { - public: - explicit RepeatedStringFieldGenerator(const FieldDescriptor* descriptor); - ~RepeatedStringFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GeneratePrivateMembers(io::Printer* printer) const; - void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateClearingCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; - void GenerateMergeFromCodedStream(io::Printer* printer) const; - void GenerateSerializeWithCachedSizes(io::Printer* printer) const; - void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; - void GenerateByteSize(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h deleted file mode 100644 index bd467602..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +++ /dev/null @@ -1,2721 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - -class TestConflictingSymbolNames; -class TestConflictingSymbolNames_BuildDescriptors; -class TestConflictingSymbolNames_TypeTraits; -class TestConflictingSymbolNames_Data1; -class TestConflictingSymbolNames_Data2; -class TestConflictingSymbolNames_Data3; -class TestConflictingSymbolNames_Data4; -class TestConflictingSymbolNames_Data5; -class TestConflictingSymbolNames_Data6; -class TestConflictingSymbolNames_Cord; -class TestConflictingSymbolNames_StringPiece; -class TestConflictingSymbolNames_DO; -class DummyMessage; - -enum TestConflictingSymbolNames_TestEnum { - TestConflictingSymbolNames_TestEnum_FOO = 1 -}; -bool TestConflictingSymbolNames_TestEnum_IsValid(int value); -const TestConflictingSymbolNames_TestEnum TestConflictingSymbolNames_TestEnum_TestEnum_MIN = TestConflictingSymbolNames_TestEnum_FOO; -const TestConflictingSymbolNames_TestEnum TestConflictingSymbolNames_TestEnum_TestEnum_MAX = TestConflictingSymbolNames_TestEnum_FOO; -const int TestConflictingSymbolNames_TestEnum_TestEnum_ARRAYSIZE = TestConflictingSymbolNames_TestEnum_TestEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TestConflictingSymbolNames_TestEnum_descriptor(); -inline const ::std::string& TestConflictingSymbolNames_TestEnum_Name(TestConflictingSymbolNames_TestEnum value) { - return ::google::protobuf::internal::NameOfEnum( - TestConflictingSymbolNames_TestEnum_descriptor(), value); -} -inline bool TestConflictingSymbolNames_TestEnum_Parse( - const ::std::string& name, TestConflictingSymbolNames_TestEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TestConflictingSymbolNames_TestEnum_descriptor(), name, value); -} -// =================================================================== - -class TestConflictingSymbolNames_BuildDescriptors : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_BuildDescriptors(); - virtual ~TestConflictingSymbolNames_BuildDescriptors(); - - TestConflictingSymbolNames_BuildDescriptors(const TestConflictingSymbolNames_BuildDescriptors& from); - - inline TestConflictingSymbolNames_BuildDescriptors& operator=(const TestConflictingSymbolNames_BuildDescriptors& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_BuildDescriptors& default_instance(); - - void Swap(TestConflictingSymbolNames_BuildDescriptors* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_BuildDescriptors* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_BuildDescriptors& from); - void MergeFrom(const TestConflictingSymbolNames_BuildDescriptors& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.BuildDescriptors) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_BuildDescriptors* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_TypeTraits : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_TypeTraits(); - virtual ~TestConflictingSymbolNames_TypeTraits(); - - TestConflictingSymbolNames_TypeTraits(const TestConflictingSymbolNames_TypeTraits& from); - - inline TestConflictingSymbolNames_TypeTraits& operator=(const TestConflictingSymbolNames_TypeTraits& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_TypeTraits& default_instance(); - - void Swap(TestConflictingSymbolNames_TypeTraits* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_TypeTraits* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_TypeTraits& from); - void MergeFrom(const TestConflictingSymbolNames_TypeTraits& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.TypeTraits) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_TypeTraits* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_Data1 : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_Data1(); - virtual ~TestConflictingSymbolNames_Data1(); - - TestConflictingSymbolNames_Data1(const TestConflictingSymbolNames_Data1& from); - - inline TestConflictingSymbolNames_Data1& operator=(const TestConflictingSymbolNames_Data1& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_Data1& default_instance(); - - void Swap(TestConflictingSymbolNames_Data1* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_Data1* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_Data1& from); - void MergeFrom(const TestConflictingSymbolNames_Data1& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 data = 1; - inline int data_size() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - inline ::google::protobuf::int32 data(int index) const; - inline void set_data(int index, ::google::protobuf::int32 value); - inline void add_data(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - data() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_data(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data1) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_Data1* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_Data2 : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_Data2(); - virtual ~TestConflictingSymbolNames_Data2(); - - TestConflictingSymbolNames_Data2(const TestConflictingSymbolNames_Data2& from); - - inline TestConflictingSymbolNames_Data2& operator=(const TestConflictingSymbolNames_Data2& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_Data2& default_instance(); - - void Swap(TestConflictingSymbolNames_Data2* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_Data2* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_Data2& from); - void MergeFrom(const TestConflictingSymbolNames_Data2& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .protobuf_unittest.TestConflictingSymbolNames.TestEnum data = 1; - inline int data_size() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - inline ::protobuf_unittest::TestConflictingSymbolNames_TestEnum data(int index) const; - inline void set_data(int index, ::protobuf_unittest::TestConflictingSymbolNames_TestEnum value); - inline void add_data(::protobuf_unittest::TestConflictingSymbolNames_TestEnum value); - inline const ::google::protobuf::RepeatedField& data() const; - inline ::google::protobuf::RepeatedField* mutable_data(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data2) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedField data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_Data2* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_Data3 : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_Data3(); - virtual ~TestConflictingSymbolNames_Data3(); - - TestConflictingSymbolNames_Data3(const TestConflictingSymbolNames_Data3& from); - - inline TestConflictingSymbolNames_Data3& operator=(const TestConflictingSymbolNames_Data3& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_Data3& default_instance(); - - void Swap(TestConflictingSymbolNames_Data3* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_Data3* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_Data3& from); - void MergeFrom(const TestConflictingSymbolNames_Data3& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated string data = 1; - inline int data_size() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - inline const ::std::string& data(int index) const; - inline ::std::string* mutable_data(int index); - inline void set_data(int index, const ::std::string& value); - inline void set_data(int index, const char* value); - inline void set_data(int index, const char* value, size_t size); - inline ::std::string* add_data(); - inline void add_data(const ::std::string& value); - inline void add_data(const char* value); - inline void add_data(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& data() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_data(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data3) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::std::string> data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_Data3* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_Data4 : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_Data4(); - virtual ~TestConflictingSymbolNames_Data4(); - - TestConflictingSymbolNames_Data4(const TestConflictingSymbolNames_Data4& from); - - inline TestConflictingSymbolNames_Data4& operator=(const TestConflictingSymbolNames_Data4& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_Data4& default_instance(); - - void Swap(TestConflictingSymbolNames_Data4* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_Data4* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_Data4& from); - void MergeFrom(const TestConflictingSymbolNames_Data4& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .protobuf_unittest.TestConflictingSymbolNames.Data4 data = 1; - inline int data_size() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - inline const ::protobuf_unittest::TestConflictingSymbolNames_Data4& data(int index) const; - inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* mutable_data(int index); - inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* add_data(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >& - data() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >* - mutable_data(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data4) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 > data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_Data4* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_Data5 : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_Data5(); - virtual ~TestConflictingSymbolNames_Data5(); - - TestConflictingSymbolNames_Data5(const TestConflictingSymbolNames_Data5& from); - - inline TestConflictingSymbolNames_Data5& operator=(const TestConflictingSymbolNames_Data5& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_Data5& default_instance(); - - void Swap(TestConflictingSymbolNames_Data5* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_Data5* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_Data5& from); - void MergeFrom(const TestConflictingSymbolNames_Data5& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated string data = 1 [ctype = STRING_PIECE]; - inline int data_size() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& data(int index) const; - inline ::std::string* mutable_data(int index); - inline void set_data(int index, const ::std::string& value); - inline void set_data(int index, const char* value); - inline void set_data(int index, const char* value, size_t size); - inline ::std::string* add_data(); - inline void add_data(const ::std::string& value); - inline void add_data(const char* value); - inline void add_data(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& data() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_data(); - public: - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data5) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::std::string> data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_Data5* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_Data6 : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_Data6(); - virtual ~TestConflictingSymbolNames_Data6(); - - TestConflictingSymbolNames_Data6(const TestConflictingSymbolNames_Data6& from); - - inline TestConflictingSymbolNames_Data6& operator=(const TestConflictingSymbolNames_Data6& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_Data6& default_instance(); - - void Swap(TestConflictingSymbolNames_Data6* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_Data6* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_Data6& from); - void MergeFrom(const TestConflictingSymbolNames_Data6& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated string data = 1 [ctype = CORD]; - inline int data_size() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& data(int index) const; - inline ::std::string* mutable_data(int index); - inline void set_data(int index, const ::std::string& value); - inline void set_data(int index, const char* value); - inline void set_data(int index, const char* value, size_t size); - inline ::std::string* add_data(); - inline void add_data(const ::std::string& value); - inline void add_data(const char* value); - inline void add_data(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& data() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_data(); - public: - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Data6) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::std::string> data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_Data6* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_Cord : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_Cord(); - virtual ~TestConflictingSymbolNames_Cord(); - - TestConflictingSymbolNames_Cord(const TestConflictingSymbolNames_Cord& from); - - inline TestConflictingSymbolNames_Cord& operator=(const TestConflictingSymbolNames_Cord& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_Cord& default_instance(); - - void Swap(TestConflictingSymbolNames_Cord* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_Cord* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_Cord& from); - void MergeFrom(const TestConflictingSymbolNames_Cord& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.Cord) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_Cord* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_StringPiece : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_StringPiece(); - virtual ~TestConflictingSymbolNames_StringPiece(); - - TestConflictingSymbolNames_StringPiece(const TestConflictingSymbolNames_StringPiece& from); - - inline TestConflictingSymbolNames_StringPiece& operator=(const TestConflictingSymbolNames_StringPiece& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_StringPiece& default_instance(); - - void Swap(TestConflictingSymbolNames_StringPiece* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_StringPiece* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_StringPiece& from); - void MergeFrom(const TestConflictingSymbolNames_StringPiece& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.StringPiece) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_StringPiece* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames_DO : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames_DO(); - virtual ~TestConflictingSymbolNames_DO(); - - TestConflictingSymbolNames_DO(const TestConflictingSymbolNames_DO& from); - - inline TestConflictingSymbolNames_DO& operator=(const TestConflictingSymbolNames_DO& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames_DO& default_instance(); - - void Swap(TestConflictingSymbolNames_DO* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames_DO* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames_DO& from); - void MergeFrom(const TestConflictingSymbolNames_DO& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames.DO) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames_DO* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestConflictingSymbolNames : public ::google::protobuf::Message { - public: - TestConflictingSymbolNames(); - virtual ~TestConflictingSymbolNames(); - - TestConflictingSymbolNames(const TestConflictingSymbolNames& from); - - inline TestConflictingSymbolNames& operator=(const TestConflictingSymbolNames& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestConflictingSymbolNames& default_instance(); - - void Swap(TestConflictingSymbolNames* other); - - // implements Message ---------------------------------------------- - - TestConflictingSymbolNames* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestConflictingSymbolNames& from); - void MergeFrom(const TestConflictingSymbolNames& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef TestConflictingSymbolNames_BuildDescriptors BuildDescriptors; - typedef TestConflictingSymbolNames_TypeTraits TypeTraits; - typedef TestConflictingSymbolNames_Data1 Data1; - typedef TestConflictingSymbolNames_Data2 Data2; - typedef TestConflictingSymbolNames_Data3 Data3; - typedef TestConflictingSymbolNames_Data4 Data4; - typedef TestConflictingSymbolNames_Data5 Data5; - typedef TestConflictingSymbolNames_Data6 Data6; - typedef TestConflictingSymbolNames_Cord Cord; - typedef TestConflictingSymbolNames_StringPiece StringPiece; - typedef TestConflictingSymbolNames_DO DO; - - typedef TestConflictingSymbolNames_TestEnum TestEnum; - static const TestEnum FOO = TestConflictingSymbolNames_TestEnum_FOO; - static inline bool TestEnum_IsValid(int value) { - return TestConflictingSymbolNames_TestEnum_IsValid(value); - } - static const TestEnum TestEnum_MIN = - TestConflictingSymbolNames_TestEnum_TestEnum_MIN; - static const TestEnum TestEnum_MAX = - TestConflictingSymbolNames_TestEnum_TestEnum_MAX; - static const int TestEnum_ARRAYSIZE = - TestConflictingSymbolNames_TestEnum_TestEnum_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - TestEnum_descriptor() { - return TestConflictingSymbolNames_TestEnum_descriptor(); - } - static inline const ::std::string& TestEnum_Name(TestEnum value) { - return TestConflictingSymbolNames_TestEnum_Name(value); - } - static inline bool TestEnum_Parse(const ::std::string& name, - TestEnum* value) { - return TestConflictingSymbolNames_TestEnum_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional int32 input = 1; - inline bool has_input() const; - inline void clear_input(); - static const int kInputFieldNumber = 1; - inline ::google::protobuf::int32 input() const; - inline void set_input(::google::protobuf::int32 value); - - // optional int32 output = 2; - inline bool has_output() const; - inline void clear_output(); - static const int kOutputFieldNumber = 2; - inline ::google::protobuf::int32 output() const; - inline void set_output(::google::protobuf::int32 value); - - // optional string length = 3; - inline bool has_length() const; - inline void clear_length(); - static const int kLengthFieldNumber = 3; - inline const ::std::string& length() const; - inline void set_length(const ::std::string& value); - inline void set_length(const char* value); - inline void set_length(const char* value, size_t size); - inline ::std::string* mutable_length(); - inline ::std::string* release_length(); - - // repeated int32 i = 4; - inline int i_size() const; - inline void clear_i(); - static const int kIFieldNumber = 4; - inline ::google::protobuf::int32 i(int index) const; - inline void set_i(int index, ::google::protobuf::int32 value); - inline void add_i(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - i() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_i(); - - // repeated string new_element = 5 [ctype = STRING_PIECE]; - inline int new_element_size() const; - inline void clear_new_element(); - static const int kNewElementFieldNumber = 5; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& new_element(int index) const; - inline ::std::string* mutable_new_element(int index); - inline void set_new_element(int index, const ::std::string& value); - inline void set_new_element(int index, const char* value); - inline void set_new_element(int index, const char* value, size_t size); - inline ::std::string* add_new_element(); - inline void add_new_element(const ::std::string& value); - inline void add_new_element(const char* value); - inline void add_new_element(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& new_element() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_new_element(); - public: - - // optional int32 total_size = 6; - inline bool has_total_size() const; - inline void clear_total_size(); - static const int kTotalSizeFieldNumber = 6; - inline ::google::protobuf::int32 total_size() const; - inline void set_total_size(::google::protobuf::int32 value); - - // optional int32 tag = 7; - inline bool has_tag() const; - inline void clear_tag(); - static const int kTagFieldNumber = 7; - inline ::google::protobuf::int32 tag() const; - inline void set_tag(::google::protobuf::int32 value); - - // optional int32 source = 8; - inline bool has_source() const; - inline void clear_source(); - static const int kSourceFieldNumber = 8; - inline ::google::protobuf::int32 source() const; - inline void set_source(::google::protobuf::int32 value); - - // optional int32 value = 9; - inline bool has_value() const; - inline void clear_value(); - static const int kValueFieldNumber = 9; - inline ::google::protobuf::int32 value() const; - inline void set_value(::google::protobuf::int32 value); - - // optional int32 file = 10; - inline bool has_file() const; - inline void clear_file(); - static const int kFileFieldNumber = 10; - inline ::google::protobuf::int32 file() const; - inline void set_file(::google::protobuf::int32 value); - - // optional int32 from = 11; - inline bool has_from() const; - inline void clear_from(); - static const int kFromFieldNumber = 11; - inline ::google::protobuf::int32 from() const; - inline void set_from(::google::protobuf::int32 value); - - // optional int32 handle_uninterpreted = 12; - inline bool has_handle_uninterpreted() const; - inline void clear_handle_uninterpreted(); - static const int kHandleUninterpretedFieldNumber = 12; - inline ::google::protobuf::int32 handle_uninterpreted() const; - inline void set_handle_uninterpreted(::google::protobuf::int32 value); - - // repeated int32 index = 13; - inline int index_size() const; - inline void clear_index(); - static const int kIndexFieldNumber = 13; - inline ::google::protobuf::int32 index(int index) const; - inline void set_index(int index, ::google::protobuf::int32 value); - inline void add_index(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - index() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_index(); - - // optional int32 controller = 14; - inline bool has_controller() const; - inline void clear_controller(); - static const int kControllerFieldNumber = 14; - inline ::google::protobuf::int32 controller() const; - inline void set_controller(::google::protobuf::int32 value); - - // optional int32 already_here = 15; - inline bool has_already_here() const; - inline void clear_already_here(); - static const int kAlreadyHereFieldNumber = 15; - inline ::google::protobuf::int32 already_here() const; - inline void set_already_here(::google::protobuf::int32 value); - - // optional uint32 uint32 = 16; - inline bool has_uint32() const; - inline void clear_uint32(); - static const int kUint32FieldNumber = 16; - inline ::google::protobuf::uint32 uint32() const; - inline void set_uint32(::google::protobuf::uint32 value); - - // optional uint64 uint64 = 17; - inline bool has_uint64() const; - inline void clear_uint64(); - static const int kUint64FieldNumber = 17; - inline ::google::protobuf::uint64 uint64() const; - inline void set_uint64(::google::protobuf::uint64 value); - - // optional string string = 18; - inline bool has_string() const; - inline void clear_string(); - static const int kStringFieldNumber = 18; - inline const ::std::string& string() const; - inline void set_string(const ::std::string& value); - inline void set_string(const char* value); - inline void set_string(const char* value, size_t size); - inline ::std::string* mutable_string(); - inline ::std::string* release_string(); - - // optional int32 memset = 19; - inline bool has_memset() const; - inline void clear_memset(); - static const int kMemsetFieldNumber = 19; - inline ::google::protobuf::int32 memset() const; - inline void set_memset(::google::protobuf::int32 value); - - // optional int32 int32 = 20; - inline bool has_int32() const; - inline void clear_int32(); - static const int kInt32FieldNumber = 20; - inline ::google::protobuf::int32 int32() const; - inline void set_int32(::google::protobuf::int32 value); - - // optional int64 int64 = 21; - inline bool has_int64() const; - inline void clear_int64(); - static const int kInt64FieldNumber = 21; - inline ::google::protobuf::int64 int64() const; - inline void set_int64(::google::protobuf::int64 value); - - // optional uint32 cached_size = 22; - inline bool has_cached_size() const; - inline void clear_cached_size(); - static const int kCachedSizeFieldNumber = 22; - inline ::google::protobuf::uint32 cached_size() const; - inline void set_cached_size(::google::protobuf::uint32 value); - - // optional uint32 extensions = 23; - inline bool has_extensions() const; - inline void clear_extensions(); - static const int kExtensionsFieldNumber = 23; - inline ::google::protobuf::uint32 extensions() const; - inline void set_extensions(::google::protobuf::uint32 value); - - // optional uint32 bit = 24; - inline bool has_bit() const; - inline void clear_bit(); - static const int kBitFieldNumber = 24; - inline ::google::protobuf::uint32 bit() const; - inline void set_bit(::google::protobuf::uint32 value); - - // optional uint32 bits = 25; - inline bool has_bits() const; - inline void clear_bits(); - static const int kBitsFieldNumber = 25; - inline ::google::protobuf::uint32 bits() const; - inline void set_bits(::google::protobuf::uint32 value); - - // optional uint32 offsets = 26; - inline bool has_offsets() const; - inline void clear_offsets(); - static const int kOffsetsFieldNumber = 26; - inline ::google::protobuf::uint32 offsets() const; - inline void set_offsets(::google::protobuf::uint32 value); - - // optional uint32 reflection = 27; - inline bool has_reflection() const; - inline void clear_reflection(); - static const int kReflectionFieldNumber = 27; - inline ::google::protobuf::uint32 reflection() const; - inline void set_reflection(::google::protobuf::uint32 value); - - // optional string some_cord = 28 [ctype = CORD]; - inline bool has_some_cord() const; - inline void clear_some_cord(); - static const int kSomeCordFieldNumber = 28; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& some_cord() const; - inline void set_some_cord(const ::std::string& value); - inline void set_some_cord(const char* value); - inline void set_some_cord(const char* value, size_t size); - inline ::std::string* mutable_some_cord(); - inline ::std::string* release_some_cord(); - public: - - // optional string some_string_piece = 29 [ctype = STRING_PIECE]; - inline bool has_some_string_piece() const; - inline void clear_some_string_piece(); - static const int kSomeStringPieceFieldNumber = 29; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& some_string_piece() const; - inline void set_some_string_piece(const ::std::string& value); - inline void set_some_string_piece(const char* value); - inline void set_some_string_piece(const char* value, size_t size); - inline ::std::string* mutable_some_string_piece(); - inline ::std::string* release_some_string_piece(); - public: - - // optional uint32 int = 30; - inline bool has_int_() const; - inline void clear_int_(); - static const int kIntFieldNumber = 30; - inline ::google::protobuf::uint32 int_() const; - inline void set_int_(::google::protobuf::uint32 value); - - // optional uint32 friend = 31; - inline bool has_friend_() const; - inline void clear_friend_(); - static const int kFriendFieldNumber = 31; - inline ::google::protobuf::uint32 friend_() const; - inline void set_friend_(::google::protobuf::uint32 value); - - // optional .protobuf_unittest.TestConflictingSymbolNames.DO do = 32; - inline bool has_do_() const; - inline void clear_do_(); - static const int kDoFieldNumber = 32; - inline const ::protobuf_unittest::TestConflictingSymbolNames_DO& do_() const; - inline ::protobuf_unittest::TestConflictingSymbolNames_DO* mutable_do_(); - inline ::protobuf_unittest::TestConflictingSymbolNames_DO* release_do_(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestConflictingSymbolNames) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestConflictingSymbolNames) - private: - inline void set_has_input(); - inline void clear_has_input(); - inline void set_has_output(); - inline void clear_has_output(); - inline void set_has_length(); - inline void clear_has_length(); - inline void set_has_total_size(); - inline void clear_has_total_size(); - inline void set_has_tag(); - inline void clear_has_tag(); - inline void set_has_source(); - inline void clear_has_source(); - inline void set_has_value(); - inline void clear_has_value(); - inline void set_has_file(); - inline void clear_has_file(); - inline void set_has_from(); - inline void clear_has_from(); - inline void set_has_handle_uninterpreted(); - inline void clear_has_handle_uninterpreted(); - inline void set_has_controller(); - inline void clear_has_controller(); - inline void set_has_already_here(); - inline void clear_has_already_here(); - inline void set_has_uint32(); - inline void clear_has_uint32(); - inline void set_has_uint64(); - inline void clear_has_uint64(); - inline void set_has_string(); - inline void clear_has_string(); - inline void set_has_memset(); - inline void clear_has_memset(); - inline void set_has_int32(); - inline void clear_has_int32(); - inline void set_has_int64(); - inline void clear_has_int64(); - inline void set_has_cached_size(); - inline void clear_has_cached_size(); - inline void set_has_extensions(); - inline void clear_has_extensions(); - inline void set_has_bit(); - inline void clear_has_bit(); - inline void set_has_bits(); - inline void clear_has_bits(); - inline void set_has_offsets(); - inline void clear_has_offsets(); - inline void set_has_reflection(); - inline void clear_has_reflection(); - inline void set_has_some_cord(); - inline void clear_has_some_cord(); - inline void set_has_some_string_piece(); - inline void clear_has_some_string_piece(); - inline void set_has_int_(); - inline void clear_has_int_(); - inline void set_has_friend_(); - inline void clear_has_friend_(); - inline void set_has_do_(); - inline void clear_has_do_(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 input_; - ::google::protobuf::int32 output_; - ::std::string* length_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > i_; - ::google::protobuf::RepeatedPtrField< ::std::string> new_element_; - ::google::protobuf::int32 total_size_; - ::google::protobuf::int32 tag_; - ::google::protobuf::int32 source_; - ::google::protobuf::int32 value_; - ::google::protobuf::int32 file_; - ::google::protobuf::int32 from_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > index_; - ::google::protobuf::int32 handle_uninterpreted_; - ::google::protobuf::int32 controller_; - ::google::protobuf::int32 already_here_; - ::google::protobuf::uint32 uint32_; - ::google::protobuf::uint64 uint64_; - ::std::string* string_; - ::google::protobuf::int32 memset_; - ::google::protobuf::int32 int32_; - ::google::protobuf::int64 int64_; - ::google::protobuf::uint32 cached_size_; - ::google::protobuf::uint32 extensions_; - ::google::protobuf::uint32 bit_; - ::google::protobuf::uint32 bits_; - ::google::protobuf::uint32 offsets_; - ::google::protobuf::uint32 reflection_; - ::std::string* some_cord_; - ::std::string* some_string_piece_; - ::google::protobuf::uint32 int__; - ::google::protobuf::uint32 friend__; - ::protobuf_unittest::TestConflictingSymbolNames_DO* do__; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(32 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static TestConflictingSymbolNames* default_instance_; -}; -// ------------------------------------------------------------------- - -class DummyMessage : public ::google::protobuf::Message { - public: - DummyMessage(); - virtual ~DummyMessage(); - - DummyMessage(const DummyMessage& from); - - inline DummyMessage& operator=(const DummyMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DummyMessage& default_instance(); - - void Swap(DummyMessage* other); - - // implements Message ---------------------------------------------- - - DummyMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DummyMessage& from); - void MergeFrom(const DummyMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.DummyMessage) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto(); - - void InitAsDefaultInstance(); - static DummyMessage* default_instance_; -}; -// =================================================================== - -class TestConflictingMethodNames_Stub; - -class TestConflictingMethodNames : public ::google::protobuf::Service { - protected: - // This class should be treated as an abstract interface. - inline TestConflictingMethodNames() {}; - public: - virtual ~TestConflictingMethodNames(); - - typedef TestConflictingMethodNames_Stub Stub; - - static const ::google::protobuf::ServiceDescriptor* descriptor(); - - virtual void Closure(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::DummyMessage* request, - ::protobuf_unittest::DummyMessage* response, - ::google::protobuf::Closure* done); - - // implements Service ---------------------------------------------- - - const ::google::protobuf::ServiceDescriptor* GetDescriptor(); - void CallMethod(const ::google::protobuf::MethodDescriptor* method, - ::google::protobuf::RpcController* controller, - const ::google::protobuf::Message* request, - ::google::protobuf::Message* response, - ::google::protobuf::Closure* done); - const ::google::protobuf::Message& GetRequestPrototype( - const ::google::protobuf::MethodDescriptor* method) const; - const ::google::protobuf::Message& GetResponsePrototype( - const ::google::protobuf::MethodDescriptor* method) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestConflictingMethodNames); -}; - -class TestConflictingMethodNames_Stub : public TestConflictingMethodNames { - public: - TestConflictingMethodNames_Stub(::google::protobuf::RpcChannel* channel); - TestConflictingMethodNames_Stub(::google::protobuf::RpcChannel* channel, - ::google::protobuf::Service::ChannelOwnership ownership); - ~TestConflictingMethodNames_Stub(); - - inline ::google::protobuf::RpcChannel* channel() { return channel_; } - - // implements TestConflictingMethodNames ------------------------------------------ - - void Closure(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::DummyMessage* request, - ::protobuf_unittest::DummyMessage* response, - ::google::protobuf::Closure* done); - private: - ::google::protobuf::RpcChannel* channel_; - bool owns_channel_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestConflictingMethodNames_Stub); -}; - - -// =================================================================== - - -// =================================================================== - -// TestConflictingSymbolNames_BuildDescriptors - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_TypeTraits - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_Data1 - -// repeated int32 data = 1; -inline int TestConflictingSymbolNames_Data1::data_size() const { - return data_.size(); -} -inline void TestConflictingSymbolNames_Data1::clear_data() { - data_.Clear(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames_Data1::data(int index) const { - return data_.Get(index); -} -inline void TestConflictingSymbolNames_Data1::set_data(int index, ::google::protobuf::int32 value) { - data_.Set(index, value); -} -inline void TestConflictingSymbolNames_Data1::add_data(::google::protobuf::int32 value) { - data_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestConflictingSymbolNames_Data1::data() const { - return data_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestConflictingSymbolNames_Data1::mutable_data() { - return &data_; -} - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_Data2 - -// repeated .protobuf_unittest.TestConflictingSymbolNames.TestEnum data = 1; -inline int TestConflictingSymbolNames_Data2::data_size() const { - return data_.size(); -} -inline void TestConflictingSymbolNames_Data2::clear_data() { - data_.Clear(); -} -inline ::protobuf_unittest::TestConflictingSymbolNames_TestEnum TestConflictingSymbolNames_Data2::data(int index) const { - return static_cast< ::protobuf_unittest::TestConflictingSymbolNames_TestEnum >(data_.Get(index)); -} -inline void TestConflictingSymbolNames_Data2::set_data(int index, ::protobuf_unittest::TestConflictingSymbolNames_TestEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestConflictingSymbolNames_TestEnum_IsValid(value)); - data_.Set(index, value); -} -inline void TestConflictingSymbolNames_Data2::add_data(::protobuf_unittest::TestConflictingSymbolNames_TestEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestConflictingSymbolNames_TestEnum_IsValid(value)); - data_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestConflictingSymbolNames_Data2::data() const { - return data_; -} -inline ::google::protobuf::RepeatedField* -TestConflictingSymbolNames_Data2::mutable_data() { - return &data_; -} - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_Data3 - -// repeated string data = 1; -inline int TestConflictingSymbolNames_Data3::data_size() const { - return data_.size(); -} -inline void TestConflictingSymbolNames_Data3::clear_data() { - data_.Clear(); -} -inline const ::std::string& TestConflictingSymbolNames_Data3::data(int index) const { - return data_.Get(index); -} -inline ::std::string* TestConflictingSymbolNames_Data3::mutable_data(int index) { - return data_.Mutable(index); -} -inline void TestConflictingSymbolNames_Data3::set_data(int index, const ::std::string& value) { - data_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames_Data3::set_data(int index, const char* value) { - data_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames_Data3::set_data(int index, const char* value, size_t size) { - data_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames_Data3::add_data() { - return data_.Add(); -} -inline void TestConflictingSymbolNames_Data3::add_data(const ::std::string& value) { - data_.Add()->assign(value); -} -inline void TestConflictingSymbolNames_Data3::add_data(const char* value) { - data_.Add()->assign(value); -} -inline void TestConflictingSymbolNames_Data3::add_data(const char* value, size_t size) { - data_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestConflictingSymbolNames_Data3::data() const { - return data_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestConflictingSymbolNames_Data3::mutable_data() { - return &data_; -} - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_Data4 - -// repeated .protobuf_unittest.TestConflictingSymbolNames.Data4 data = 1; -inline int TestConflictingSymbolNames_Data4::data_size() const { - return data_.size(); -} -inline void TestConflictingSymbolNames_Data4::clear_data() { - data_.Clear(); -} -inline const ::protobuf_unittest::TestConflictingSymbolNames_Data4& TestConflictingSymbolNames_Data4::data(int index) const { - return data_.Get(index); -} -inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* TestConflictingSymbolNames_Data4::mutable_data(int index) { - return data_.Mutable(index); -} -inline ::protobuf_unittest::TestConflictingSymbolNames_Data4* TestConflictingSymbolNames_Data4::add_data() { - return data_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >& -TestConflictingSymbolNames_Data4::data() const { - return data_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestConflictingSymbolNames_Data4 >* -TestConflictingSymbolNames_Data4::mutable_data() { - return &data_; -} - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_Data5 - -// repeated string data = 1 [ctype = STRING_PIECE]; -inline int TestConflictingSymbolNames_Data5::data_size() const { - return data_.size(); -} -inline void TestConflictingSymbolNames_Data5::clear_data() { - data_.Clear(); -} -inline const ::std::string& TestConflictingSymbolNames_Data5::data(int index) const { - return data_.Get(index); -} -inline ::std::string* TestConflictingSymbolNames_Data5::mutable_data(int index) { - return data_.Mutable(index); -} -inline void TestConflictingSymbolNames_Data5::set_data(int index, const ::std::string& value) { - data_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames_Data5::set_data(int index, const char* value) { - data_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames_Data5::set_data(int index, const char* value, size_t size) { - data_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames_Data5::add_data() { - return data_.Add(); -} -inline void TestConflictingSymbolNames_Data5::add_data(const ::std::string& value) { - data_.Add()->assign(value); -} -inline void TestConflictingSymbolNames_Data5::add_data(const char* value) { - data_.Add()->assign(value); -} -inline void TestConflictingSymbolNames_Data5::add_data(const char* value, size_t size) { - data_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestConflictingSymbolNames_Data5::data() const { - return data_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestConflictingSymbolNames_Data5::mutable_data() { - return &data_; -} - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_Data6 - -// repeated string data = 1 [ctype = CORD]; -inline int TestConflictingSymbolNames_Data6::data_size() const { - return data_.size(); -} -inline void TestConflictingSymbolNames_Data6::clear_data() { - data_.Clear(); -} -inline const ::std::string& TestConflictingSymbolNames_Data6::data(int index) const { - return data_.Get(index); -} -inline ::std::string* TestConflictingSymbolNames_Data6::mutable_data(int index) { - return data_.Mutable(index); -} -inline void TestConflictingSymbolNames_Data6::set_data(int index, const ::std::string& value) { - data_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames_Data6::set_data(int index, const char* value) { - data_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames_Data6::set_data(int index, const char* value, size_t size) { - data_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames_Data6::add_data() { - return data_.Add(); -} -inline void TestConflictingSymbolNames_Data6::add_data(const ::std::string& value) { - data_.Add()->assign(value); -} -inline void TestConflictingSymbolNames_Data6::add_data(const char* value) { - data_.Add()->assign(value); -} -inline void TestConflictingSymbolNames_Data6::add_data(const char* value, size_t size) { - data_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestConflictingSymbolNames_Data6::data() const { - return data_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestConflictingSymbolNames_Data6::mutable_data() { - return &data_; -} - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_Cord - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_StringPiece - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames_DO - -// ------------------------------------------------------------------- - -// TestConflictingSymbolNames - -// optional int32 input = 1; -inline bool TestConflictingSymbolNames::has_input() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestConflictingSymbolNames::set_has_input() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestConflictingSymbolNames::clear_has_input() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestConflictingSymbolNames::clear_input() { - input_ = 0; - clear_has_input(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::input() const { - return input_; -} -inline void TestConflictingSymbolNames::set_input(::google::protobuf::int32 value) { - set_has_input(); - input_ = value; -} - -// optional int32 output = 2; -inline bool TestConflictingSymbolNames::has_output() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestConflictingSymbolNames::set_has_output() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestConflictingSymbolNames::clear_has_output() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestConflictingSymbolNames::clear_output() { - output_ = 0; - clear_has_output(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::output() const { - return output_; -} -inline void TestConflictingSymbolNames::set_output(::google::protobuf::int32 value) { - set_has_output(); - output_ = value; -} - -// optional string length = 3; -inline bool TestConflictingSymbolNames::has_length() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestConflictingSymbolNames::set_has_length() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestConflictingSymbolNames::clear_has_length() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestConflictingSymbolNames::clear_length() { - if (length_ != &::google::protobuf::internal::kEmptyString) { - length_->clear(); - } - clear_has_length(); -} -inline const ::std::string& TestConflictingSymbolNames::length() const { - return *length_; -} -inline void TestConflictingSymbolNames::set_length(const ::std::string& value) { - set_has_length(); - if (length_ == &::google::protobuf::internal::kEmptyString) { - length_ = new ::std::string; - } - length_->assign(value); -} -inline void TestConflictingSymbolNames::set_length(const char* value) { - set_has_length(); - if (length_ == &::google::protobuf::internal::kEmptyString) { - length_ = new ::std::string; - } - length_->assign(value); -} -inline void TestConflictingSymbolNames::set_length(const char* value, size_t size) { - set_has_length(); - if (length_ == &::google::protobuf::internal::kEmptyString) { - length_ = new ::std::string; - } - length_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames::mutable_length() { - set_has_length(); - if (length_ == &::google::protobuf::internal::kEmptyString) { - length_ = new ::std::string; - } - return length_; -} -inline ::std::string* TestConflictingSymbolNames::release_length() { - clear_has_length(); - if (length_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = length_; - length_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated int32 i = 4; -inline int TestConflictingSymbolNames::i_size() const { - return i_.size(); -} -inline void TestConflictingSymbolNames::clear_i() { - i_.Clear(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::i(int index) const { - return i_.Get(index); -} -inline void TestConflictingSymbolNames::set_i(int index, ::google::protobuf::int32 value) { - i_.Set(index, value); -} -inline void TestConflictingSymbolNames::add_i(::google::protobuf::int32 value) { - i_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestConflictingSymbolNames::i() const { - return i_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestConflictingSymbolNames::mutable_i() { - return &i_; -} - -// repeated string new_element = 5 [ctype = STRING_PIECE]; -inline int TestConflictingSymbolNames::new_element_size() const { - return new_element_.size(); -} -inline void TestConflictingSymbolNames::clear_new_element() { - new_element_.Clear(); -} -inline const ::std::string& TestConflictingSymbolNames::new_element(int index) const { - return new_element_.Get(index); -} -inline ::std::string* TestConflictingSymbolNames::mutable_new_element(int index) { - return new_element_.Mutable(index); -} -inline void TestConflictingSymbolNames::set_new_element(int index, const ::std::string& value) { - new_element_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames::set_new_element(int index, const char* value) { - new_element_.Mutable(index)->assign(value); -} -inline void TestConflictingSymbolNames::set_new_element(int index, const char* value, size_t size) { - new_element_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames::add_new_element() { - return new_element_.Add(); -} -inline void TestConflictingSymbolNames::add_new_element(const ::std::string& value) { - new_element_.Add()->assign(value); -} -inline void TestConflictingSymbolNames::add_new_element(const char* value) { - new_element_.Add()->assign(value); -} -inline void TestConflictingSymbolNames::add_new_element(const char* value, size_t size) { - new_element_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestConflictingSymbolNames::new_element() const { - return new_element_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestConflictingSymbolNames::mutable_new_element() { - return &new_element_; -} - -// optional int32 total_size = 6; -inline bool TestConflictingSymbolNames::has_total_size() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void TestConflictingSymbolNames::set_has_total_size() { - _has_bits_[0] |= 0x00000020u; -} -inline void TestConflictingSymbolNames::clear_has_total_size() { - _has_bits_[0] &= ~0x00000020u; -} -inline void TestConflictingSymbolNames::clear_total_size() { - total_size_ = 0; - clear_has_total_size(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::total_size() const { - return total_size_; -} -inline void TestConflictingSymbolNames::set_total_size(::google::protobuf::int32 value) { - set_has_total_size(); - total_size_ = value; -} - -// optional int32 tag = 7; -inline bool TestConflictingSymbolNames::has_tag() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void TestConflictingSymbolNames::set_has_tag() { - _has_bits_[0] |= 0x00000040u; -} -inline void TestConflictingSymbolNames::clear_has_tag() { - _has_bits_[0] &= ~0x00000040u; -} -inline void TestConflictingSymbolNames::clear_tag() { - tag_ = 0; - clear_has_tag(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::tag() const { - return tag_; -} -inline void TestConflictingSymbolNames::set_tag(::google::protobuf::int32 value) { - set_has_tag(); - tag_ = value; -} - -// optional int32 source = 8; -inline bool TestConflictingSymbolNames::has_source() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void TestConflictingSymbolNames::set_has_source() { - _has_bits_[0] |= 0x00000080u; -} -inline void TestConflictingSymbolNames::clear_has_source() { - _has_bits_[0] &= ~0x00000080u; -} -inline void TestConflictingSymbolNames::clear_source() { - source_ = 0; - clear_has_source(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::source() const { - return source_; -} -inline void TestConflictingSymbolNames::set_source(::google::protobuf::int32 value) { - set_has_source(); - source_ = value; -} - -// optional int32 value = 9; -inline bool TestConflictingSymbolNames::has_value() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void TestConflictingSymbolNames::set_has_value() { - _has_bits_[0] |= 0x00000100u; -} -inline void TestConflictingSymbolNames::clear_has_value() { - _has_bits_[0] &= ~0x00000100u; -} -inline void TestConflictingSymbolNames::clear_value() { - value_ = 0; - clear_has_value(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::value() const { - return value_; -} -inline void TestConflictingSymbolNames::set_value(::google::protobuf::int32 value) { - set_has_value(); - value_ = value; -} - -// optional int32 file = 10; -inline bool TestConflictingSymbolNames::has_file() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void TestConflictingSymbolNames::set_has_file() { - _has_bits_[0] |= 0x00000200u; -} -inline void TestConflictingSymbolNames::clear_has_file() { - _has_bits_[0] &= ~0x00000200u; -} -inline void TestConflictingSymbolNames::clear_file() { - file_ = 0; - clear_has_file(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::file() const { - return file_; -} -inline void TestConflictingSymbolNames::set_file(::google::protobuf::int32 value) { - set_has_file(); - file_ = value; -} - -// optional int32 from = 11; -inline bool TestConflictingSymbolNames::has_from() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void TestConflictingSymbolNames::set_has_from() { - _has_bits_[0] |= 0x00000400u; -} -inline void TestConflictingSymbolNames::clear_has_from() { - _has_bits_[0] &= ~0x00000400u; -} -inline void TestConflictingSymbolNames::clear_from() { - from_ = 0; - clear_has_from(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::from() const { - return from_; -} -inline void TestConflictingSymbolNames::set_from(::google::protobuf::int32 value) { - set_has_from(); - from_ = value; -} - -// optional int32 handle_uninterpreted = 12; -inline bool TestConflictingSymbolNames::has_handle_uninterpreted() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void TestConflictingSymbolNames::set_has_handle_uninterpreted() { - _has_bits_[0] |= 0x00000800u; -} -inline void TestConflictingSymbolNames::clear_has_handle_uninterpreted() { - _has_bits_[0] &= ~0x00000800u; -} -inline void TestConflictingSymbolNames::clear_handle_uninterpreted() { - handle_uninterpreted_ = 0; - clear_has_handle_uninterpreted(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::handle_uninterpreted() const { - return handle_uninterpreted_; -} -inline void TestConflictingSymbolNames::set_handle_uninterpreted(::google::protobuf::int32 value) { - set_has_handle_uninterpreted(); - handle_uninterpreted_ = value; -} - -// repeated int32 index = 13; -inline int TestConflictingSymbolNames::index_size() const { - return index_.size(); -} -inline void TestConflictingSymbolNames::clear_index() { - index_.Clear(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::index(int index) const { - return index_.Get(index); -} -inline void TestConflictingSymbolNames::set_index(int index, ::google::protobuf::int32 value) { - index_.Set(index, value); -} -inline void TestConflictingSymbolNames::add_index(::google::protobuf::int32 value) { - index_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestConflictingSymbolNames::index() const { - return index_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestConflictingSymbolNames::mutable_index() { - return &index_; -} - -// optional int32 controller = 14; -inline bool TestConflictingSymbolNames::has_controller() const { - return (_has_bits_[0] & 0x00002000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_controller() { - _has_bits_[0] |= 0x00002000u; -} -inline void TestConflictingSymbolNames::clear_has_controller() { - _has_bits_[0] &= ~0x00002000u; -} -inline void TestConflictingSymbolNames::clear_controller() { - controller_ = 0; - clear_has_controller(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::controller() const { - return controller_; -} -inline void TestConflictingSymbolNames::set_controller(::google::protobuf::int32 value) { - set_has_controller(); - controller_ = value; -} - -// optional int32 already_here = 15; -inline bool TestConflictingSymbolNames::has_already_here() const { - return (_has_bits_[0] & 0x00004000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_already_here() { - _has_bits_[0] |= 0x00004000u; -} -inline void TestConflictingSymbolNames::clear_has_already_here() { - _has_bits_[0] &= ~0x00004000u; -} -inline void TestConflictingSymbolNames::clear_already_here() { - already_here_ = 0; - clear_has_already_here(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::already_here() const { - return already_here_; -} -inline void TestConflictingSymbolNames::set_already_here(::google::protobuf::int32 value) { - set_has_already_here(); - already_here_ = value; -} - -// optional uint32 uint32 = 16; -inline bool TestConflictingSymbolNames::has_uint32() const { - return (_has_bits_[0] & 0x00008000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_uint32() { - _has_bits_[0] |= 0x00008000u; -} -inline void TestConflictingSymbolNames::clear_has_uint32() { - _has_bits_[0] &= ~0x00008000u; -} -inline void TestConflictingSymbolNames::clear_uint32() { - uint32_ = 0u; - clear_has_uint32(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::uint32() const { - return uint32_; -} -inline void TestConflictingSymbolNames::set_uint32(::google::protobuf::uint32 value) { - set_has_uint32(); - uint32_ = value; -} - -// optional uint64 uint64 = 17; -inline bool TestConflictingSymbolNames::has_uint64() const { - return (_has_bits_[0] & 0x00010000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_uint64() { - _has_bits_[0] |= 0x00010000u; -} -inline void TestConflictingSymbolNames::clear_has_uint64() { - _has_bits_[0] &= ~0x00010000u; -} -inline void TestConflictingSymbolNames::clear_uint64() { - uint64_ = GOOGLE_ULONGLONG(0); - clear_has_uint64(); -} -inline ::google::protobuf::uint64 TestConflictingSymbolNames::uint64() const { - return uint64_; -} -inline void TestConflictingSymbolNames::set_uint64(::google::protobuf::uint64 value) { - set_has_uint64(); - uint64_ = value; -} - -// optional string string = 18; -inline bool TestConflictingSymbolNames::has_string() const { - return (_has_bits_[0] & 0x00020000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_string() { - _has_bits_[0] |= 0x00020000u; -} -inline void TestConflictingSymbolNames::clear_has_string() { - _has_bits_[0] &= ~0x00020000u; -} -inline void TestConflictingSymbolNames::clear_string() { - if (string_ != &::google::protobuf::internal::kEmptyString) { - string_->clear(); - } - clear_has_string(); -} -inline const ::std::string& TestConflictingSymbolNames::string() const { - return *string_; -} -inline void TestConflictingSymbolNames::set_string(const ::std::string& value) { - set_has_string(); - if (string_ == &::google::protobuf::internal::kEmptyString) { - string_ = new ::std::string; - } - string_->assign(value); -} -inline void TestConflictingSymbolNames::set_string(const char* value) { - set_has_string(); - if (string_ == &::google::protobuf::internal::kEmptyString) { - string_ = new ::std::string; - } - string_->assign(value); -} -inline void TestConflictingSymbolNames::set_string(const char* value, size_t size) { - set_has_string(); - if (string_ == &::google::protobuf::internal::kEmptyString) { - string_ = new ::std::string; - } - string_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames::mutable_string() { - set_has_string(); - if (string_ == &::google::protobuf::internal::kEmptyString) { - string_ = new ::std::string; - } - return string_; -} -inline ::std::string* TestConflictingSymbolNames::release_string() { - clear_has_string(); - if (string_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = string_; - string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional int32 memset = 19; -inline bool TestConflictingSymbolNames::has_memset() const { - return (_has_bits_[0] & 0x00040000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_memset() { - _has_bits_[0] |= 0x00040000u; -} -inline void TestConflictingSymbolNames::clear_has_memset() { - _has_bits_[0] &= ~0x00040000u; -} -inline void TestConflictingSymbolNames::clear_memset() { - memset_ = 0; - clear_has_memset(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::memset() const { - return memset_; -} -inline void TestConflictingSymbolNames::set_memset(::google::protobuf::int32 value) { - set_has_memset(); - memset_ = value; -} - -// optional int32 int32 = 20; -inline bool TestConflictingSymbolNames::has_int32() const { - return (_has_bits_[0] & 0x00080000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_int32() { - _has_bits_[0] |= 0x00080000u; -} -inline void TestConflictingSymbolNames::clear_has_int32() { - _has_bits_[0] &= ~0x00080000u; -} -inline void TestConflictingSymbolNames::clear_int32() { - int32_ = 0; - clear_has_int32(); -} -inline ::google::protobuf::int32 TestConflictingSymbolNames::int32() const { - return int32_; -} -inline void TestConflictingSymbolNames::set_int32(::google::protobuf::int32 value) { - set_has_int32(); - int32_ = value; -} - -// optional int64 int64 = 21; -inline bool TestConflictingSymbolNames::has_int64() const { - return (_has_bits_[0] & 0x00100000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_int64() { - _has_bits_[0] |= 0x00100000u; -} -inline void TestConflictingSymbolNames::clear_has_int64() { - _has_bits_[0] &= ~0x00100000u; -} -inline void TestConflictingSymbolNames::clear_int64() { - int64_ = GOOGLE_LONGLONG(0); - clear_has_int64(); -} -inline ::google::protobuf::int64 TestConflictingSymbolNames::int64() const { - return int64_; -} -inline void TestConflictingSymbolNames::set_int64(::google::protobuf::int64 value) { - set_has_int64(); - int64_ = value; -} - -// optional uint32 cached_size = 22; -inline bool TestConflictingSymbolNames::has_cached_size() const { - return (_has_bits_[0] & 0x00200000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_cached_size() { - _has_bits_[0] |= 0x00200000u; -} -inline void TestConflictingSymbolNames::clear_has_cached_size() { - _has_bits_[0] &= ~0x00200000u; -} -inline void TestConflictingSymbolNames::clear_cached_size() { - cached_size_ = 0u; - clear_has_cached_size(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::cached_size() const { - return cached_size_; -} -inline void TestConflictingSymbolNames::set_cached_size(::google::protobuf::uint32 value) { - set_has_cached_size(); - cached_size_ = value; -} - -// optional uint32 extensions = 23; -inline bool TestConflictingSymbolNames::has_extensions() const { - return (_has_bits_[0] & 0x00400000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_extensions() { - _has_bits_[0] |= 0x00400000u; -} -inline void TestConflictingSymbolNames::clear_has_extensions() { - _has_bits_[0] &= ~0x00400000u; -} -inline void TestConflictingSymbolNames::clear_extensions() { - extensions_ = 0u; - clear_has_extensions(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::extensions() const { - return extensions_; -} -inline void TestConflictingSymbolNames::set_extensions(::google::protobuf::uint32 value) { - set_has_extensions(); - extensions_ = value; -} - -// optional uint32 bit = 24; -inline bool TestConflictingSymbolNames::has_bit() const { - return (_has_bits_[0] & 0x00800000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_bit() { - _has_bits_[0] |= 0x00800000u; -} -inline void TestConflictingSymbolNames::clear_has_bit() { - _has_bits_[0] &= ~0x00800000u; -} -inline void TestConflictingSymbolNames::clear_bit() { - bit_ = 0u; - clear_has_bit(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::bit() const { - return bit_; -} -inline void TestConflictingSymbolNames::set_bit(::google::protobuf::uint32 value) { - set_has_bit(); - bit_ = value; -} - -// optional uint32 bits = 25; -inline bool TestConflictingSymbolNames::has_bits() const { - return (_has_bits_[0] & 0x01000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_bits() { - _has_bits_[0] |= 0x01000000u; -} -inline void TestConflictingSymbolNames::clear_has_bits() { - _has_bits_[0] &= ~0x01000000u; -} -inline void TestConflictingSymbolNames::clear_bits() { - bits_ = 0u; - clear_has_bits(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::bits() const { - return bits_; -} -inline void TestConflictingSymbolNames::set_bits(::google::protobuf::uint32 value) { - set_has_bits(); - bits_ = value; -} - -// optional uint32 offsets = 26; -inline bool TestConflictingSymbolNames::has_offsets() const { - return (_has_bits_[0] & 0x02000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_offsets() { - _has_bits_[0] |= 0x02000000u; -} -inline void TestConflictingSymbolNames::clear_has_offsets() { - _has_bits_[0] &= ~0x02000000u; -} -inline void TestConflictingSymbolNames::clear_offsets() { - offsets_ = 0u; - clear_has_offsets(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::offsets() const { - return offsets_; -} -inline void TestConflictingSymbolNames::set_offsets(::google::protobuf::uint32 value) { - set_has_offsets(); - offsets_ = value; -} - -// optional uint32 reflection = 27; -inline bool TestConflictingSymbolNames::has_reflection() const { - return (_has_bits_[0] & 0x04000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_reflection() { - _has_bits_[0] |= 0x04000000u; -} -inline void TestConflictingSymbolNames::clear_has_reflection() { - _has_bits_[0] &= ~0x04000000u; -} -inline void TestConflictingSymbolNames::clear_reflection() { - reflection_ = 0u; - clear_has_reflection(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::reflection() const { - return reflection_; -} -inline void TestConflictingSymbolNames::set_reflection(::google::protobuf::uint32 value) { - set_has_reflection(); - reflection_ = value; -} - -// optional string some_cord = 28 [ctype = CORD]; -inline bool TestConflictingSymbolNames::has_some_cord() const { - return (_has_bits_[0] & 0x08000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_some_cord() { - _has_bits_[0] |= 0x08000000u; -} -inline void TestConflictingSymbolNames::clear_has_some_cord() { - _has_bits_[0] &= ~0x08000000u; -} -inline void TestConflictingSymbolNames::clear_some_cord() { - if (some_cord_ != &::google::protobuf::internal::kEmptyString) { - some_cord_->clear(); - } - clear_has_some_cord(); -} -inline const ::std::string& TestConflictingSymbolNames::some_cord() const { - return *some_cord_; -} -inline void TestConflictingSymbolNames::set_some_cord(const ::std::string& value) { - set_has_some_cord(); - if (some_cord_ == &::google::protobuf::internal::kEmptyString) { - some_cord_ = new ::std::string; - } - some_cord_->assign(value); -} -inline void TestConflictingSymbolNames::set_some_cord(const char* value) { - set_has_some_cord(); - if (some_cord_ == &::google::protobuf::internal::kEmptyString) { - some_cord_ = new ::std::string; - } - some_cord_->assign(value); -} -inline void TestConflictingSymbolNames::set_some_cord(const char* value, size_t size) { - set_has_some_cord(); - if (some_cord_ == &::google::protobuf::internal::kEmptyString) { - some_cord_ = new ::std::string; - } - some_cord_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames::mutable_some_cord() { - set_has_some_cord(); - if (some_cord_ == &::google::protobuf::internal::kEmptyString) { - some_cord_ = new ::std::string; - } - return some_cord_; -} -inline ::std::string* TestConflictingSymbolNames::release_some_cord() { - clear_has_some_cord(); - if (some_cord_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = some_cord_; - some_cord_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string some_string_piece = 29 [ctype = STRING_PIECE]; -inline bool TestConflictingSymbolNames::has_some_string_piece() const { - return (_has_bits_[0] & 0x10000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_some_string_piece() { - _has_bits_[0] |= 0x10000000u; -} -inline void TestConflictingSymbolNames::clear_has_some_string_piece() { - _has_bits_[0] &= ~0x10000000u; -} -inline void TestConflictingSymbolNames::clear_some_string_piece() { - if (some_string_piece_ != &::google::protobuf::internal::kEmptyString) { - some_string_piece_->clear(); - } - clear_has_some_string_piece(); -} -inline const ::std::string& TestConflictingSymbolNames::some_string_piece() const { - return *some_string_piece_; -} -inline void TestConflictingSymbolNames::set_some_string_piece(const ::std::string& value) { - set_has_some_string_piece(); - if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { - some_string_piece_ = new ::std::string; - } - some_string_piece_->assign(value); -} -inline void TestConflictingSymbolNames::set_some_string_piece(const char* value) { - set_has_some_string_piece(); - if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { - some_string_piece_ = new ::std::string; - } - some_string_piece_->assign(value); -} -inline void TestConflictingSymbolNames::set_some_string_piece(const char* value, size_t size) { - set_has_some_string_piece(); - if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { - some_string_piece_ = new ::std::string; - } - some_string_piece_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestConflictingSymbolNames::mutable_some_string_piece() { - set_has_some_string_piece(); - if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { - some_string_piece_ = new ::std::string; - } - return some_string_piece_; -} -inline ::std::string* TestConflictingSymbolNames::release_some_string_piece() { - clear_has_some_string_piece(); - if (some_string_piece_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = some_string_piece_; - some_string_piece_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional uint32 int = 30; -inline bool TestConflictingSymbolNames::has_int_() const { - return (_has_bits_[0] & 0x20000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_int_() { - _has_bits_[0] |= 0x20000000u; -} -inline void TestConflictingSymbolNames::clear_has_int_() { - _has_bits_[0] &= ~0x20000000u; -} -inline void TestConflictingSymbolNames::clear_int_() { - int__ = 0u; - clear_has_int_(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::int_() const { - return int__; -} -inline void TestConflictingSymbolNames::set_int_(::google::protobuf::uint32 value) { - set_has_int_(); - int__ = value; -} - -// optional uint32 friend = 31; -inline bool TestConflictingSymbolNames::has_friend_() const { - return (_has_bits_[0] & 0x40000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_friend_() { - _has_bits_[0] |= 0x40000000u; -} -inline void TestConflictingSymbolNames::clear_has_friend_() { - _has_bits_[0] &= ~0x40000000u; -} -inline void TestConflictingSymbolNames::clear_friend_() { - friend__ = 0u; - clear_has_friend_(); -} -inline ::google::protobuf::uint32 TestConflictingSymbolNames::friend_() const { - return friend__; -} -inline void TestConflictingSymbolNames::set_friend_(::google::protobuf::uint32 value) { - set_has_friend_(); - friend__ = value; -} - -// optional .protobuf_unittest.TestConflictingSymbolNames.DO do = 32; -inline bool TestConflictingSymbolNames::has_do_() const { - return (_has_bits_[0] & 0x80000000u) != 0; -} -inline void TestConflictingSymbolNames::set_has_do_() { - _has_bits_[0] |= 0x80000000u; -} -inline void TestConflictingSymbolNames::clear_has_do_() { - _has_bits_[0] &= ~0x80000000u; -} -inline void TestConflictingSymbolNames::clear_do_() { - if (do__ != NULL) do__->::protobuf_unittest::TestConflictingSymbolNames_DO::Clear(); - clear_has_do_(); -} -inline const ::protobuf_unittest::TestConflictingSymbolNames_DO& TestConflictingSymbolNames::do_() const { - return do__ != NULL ? *do__ : *default_instance_->do__; -} -inline ::protobuf_unittest::TestConflictingSymbolNames_DO* TestConflictingSymbolNames::mutable_do_() { - set_has_do_(); - if (do__ == NULL) do__ = new ::protobuf_unittest::TestConflictingSymbolNames_DO; - return do__; -} -inline ::protobuf_unittest::TestConflictingSymbolNames_DO* TestConflictingSymbolNames::release_do_() { - clear_has_do_(); - ::protobuf_unittest::TestConflictingSymbolNames_DO* temp = do__; - do__ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// DummyMessage - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestConflictingSymbolNames_TestEnum>() { - return ::protobuf_unittest::TestConflictingSymbolNames_TestEnum_descriptor(); -} - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fcompiler_2fcpp_2fcpp_5ftest_5fbad_5fidentifiers_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h deleted file mode 100644 index 7a2efc29..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +++ /dev/null @@ -1,303 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file is the public interface to the .proto file parser. - -#ifndef GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ -#define GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ - -#include -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -namespace io { class ZeroCopyInputStream; } - -namespace compiler { - -// Defined in this file. -class Importer; -class MultiFileErrorCollector; -class SourceTree; -class DiskSourceTree; - -// TODO(kenton): Move all SourceTree stuff to a separate file? - -// An implementation of DescriptorDatabase which loads files from a SourceTree -// and parses them. -// -// Note: This class is not thread-safe since it maintains a table of source -// code locations for error reporting. However, when a DescriptorPool wraps -// a DescriptorDatabase, it uses mutex locking to make sure only one method -// of the database is called at a time, even if the DescriptorPool is used -// from multiple threads. Therefore, there is only a problem if you create -// multiple DescriptorPools wrapping the same SourceTreeDescriptorDatabase -// and use them from multiple threads. -// -// Note: This class does not implement FindFileContainingSymbol() or -// FindFileContainingExtension(); these will always return false. -class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase { - public: - SourceTreeDescriptorDatabase(SourceTree* source_tree); - ~SourceTreeDescriptorDatabase(); - - // Instructs the SourceTreeDescriptorDatabase to report any parse errors - // to the given MultiFileErrorCollector. This should be called before - // parsing. error_collector must remain valid until either this method - // is called again or the SourceTreeDescriptorDatabase is destroyed. - void RecordErrorsTo(MultiFileErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Gets a DescriptorPool::ErrorCollector which records errors to the - // MultiFileErrorCollector specified with RecordErrorsTo(). This collector - // has the ability to determine exact line and column numbers of errors - // from the information given to it by the DescriptorPool. - DescriptorPool::ErrorCollector* GetValidationErrorCollector() { - using_validation_error_collector_ = true; - return &validation_error_collector_; - } - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - - private: - class SingleFileErrorCollector; - - SourceTree* source_tree_; - MultiFileErrorCollector* error_collector_; - - class LIBPROTOBUF_EXPORT ValidationErrorCollector : public DescriptorPool::ErrorCollector { - public: - ValidationErrorCollector(SourceTreeDescriptorDatabase* owner); - ~ValidationErrorCollector(); - - // implements ErrorCollector --------------------------------------- - void AddError(const string& filename, - const string& element_name, - const Message* descriptor, - ErrorLocation location, - const string& message); - - private: - SourceTreeDescriptorDatabase* owner_; - }; - friend class ValidationErrorCollector; - - bool using_validation_error_collector_; - SourceLocationTable source_locations_; - ValidationErrorCollector validation_error_collector_; -}; - -// Simple interface for parsing .proto files. This wraps the process -// of opening the file, parsing it with a Parser, recursively parsing all its -// imports, and then cross-linking the results to produce a FileDescriptor. -// -// This is really just a thin wrapper around SourceTreeDescriptorDatabase. -// You may find that SourceTreeDescriptorDatabase is more flexible. -// -// TODO(kenton): I feel like this class is not well-named. -class LIBPROTOBUF_EXPORT Importer { - public: - Importer(SourceTree* source_tree, - MultiFileErrorCollector* error_collector); - ~Importer(); - - // Import the given file and build a FileDescriptor representing it. If - // the file is already in the DescriptorPool, the existing FileDescriptor - // will be returned. The FileDescriptor is property of the DescriptorPool, - // and will remain valid until it is destroyed. If any errors occur, they - // will be reported using the error collector and Import() will return NULL. - // - // A particular Importer object will only report errors for a particular - // file once. All future attempts to import the same file will return NULL - // without reporting any errors. The idea is that you might want to import - // a lot of files without seeing the same errors over and over again. If - // you want to see errors for the same files repeatedly, you can use a - // separate Importer object to import each one (but use the same - // DescriptorPool so that they can be cross-linked). - const FileDescriptor* Import(const string& filename); - - // The DescriptorPool in which all imported FileDescriptors and their - // contents are stored. - inline const DescriptorPool* pool() const { - return &pool_; - } - - private: - SourceTreeDescriptorDatabase database_; - DescriptorPool pool_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); -}; - -// If the importer encounters problems while trying to import the proto files, -// it reports them to a MultiFileErrorCollector. -class LIBPROTOBUF_EXPORT MultiFileErrorCollector { - public: - inline MultiFileErrorCollector() {} - virtual ~MultiFileErrorCollector(); - - // Line and column numbers are zero-based. A line number of -1 indicates - // an error with the entire file (e.g. "not found"). - virtual void AddError(const string& filename, int line, int column, - const string& message) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); -}; - -// Abstract interface which represents a directory tree containing proto files. -// Used by the default implementation of Importer to resolve import statements -// Most users will probably want to use the DiskSourceTree implementation, -// below. -class LIBPROTOBUF_EXPORT SourceTree { - public: - inline SourceTree() {} - virtual ~SourceTree(); - - // Open the given file and return a stream that reads it, or NULL if not - // found. The caller takes ownership of the returned object. The filename - // must be a path relative to the root of the source tree and must not - // contain "." or ".." components. - virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); -}; - -// An implementation of SourceTree which loads files from locations on disk. -// Multiple mappings can be set up to map locations in the DiskSourceTree to -// locations in the physical filesystem. -class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { - public: - DiskSourceTree(); - ~DiskSourceTree(); - - // Map a path on disk to a location in the SourceTree. The path may be - // either a file or a directory. If it is a directory, the entire tree - // under it will be mapped to the given virtual location. To map a directory - // to the root of the source tree, pass an empty string for virtual_path. - // - // If multiple mapped paths apply when opening a file, they will be searched - // in order. For example, if you do: - // MapPath("bar", "foo/bar"); - // MapPath("", "baz"); - // and then you do: - // Open("bar/qux"); - // the DiskSourceTree will first try to open foo/bar/qux, then baz/bar/qux, - // returning the first one that opens successfuly. - // - // disk_path may be an absolute path or relative to the current directory, - // just like a path you'd pass to open(). - void MapPath(const string& virtual_path, const string& disk_path); - - // Return type for DiskFileToVirtualFile(). - enum DiskFileToVirtualFileResult { - SUCCESS, - SHADOWED, - CANNOT_OPEN, - NO_MAPPING - }; - - // Given a path to a file on disk, find a virtual path mapping to that - // file. The first mapping created with MapPath() whose disk_path contains - // the filename is used. However, that virtual path may not actually be - // usable to open the given file. Possible return values are: - // * SUCCESS: The mapping was found. *virtual_file is filled in so that - // calling Open(*virtual_file) will open the file named by disk_file. - // * SHADOWED: A mapping was found, but using Open() to open this virtual - // path will end up returning some different file. This is because some - // other mapping with a higher precedence also matches this virtual path - // and maps it to a different file that exists on disk. *virtual_file - // is filled in as it would be in the SUCCESS case. *shadowing_disk_file - // is filled in with the disk path of the file which would be opened if - // you were to call Open(*virtual_file). - // * CANNOT_OPEN: The mapping was found and was not shadowed, but the - // file specified cannot be opened. When this value is returned, - // errno will indicate the reason the file cannot be opened. *virtual_file - // will be set to the virtual path as in the SUCCESS case, even though - // it is not useful. - // * NO_MAPPING: Indicates that no mapping was found which contains this - // file. - DiskFileToVirtualFileResult - DiskFileToVirtualFile(const string& disk_file, - string* virtual_file, - string* shadowing_disk_file); - - // Given a virtual path, find the path to the file on disk. - // Return true and update disk_file with the on-disk path if the file exists. - // Return false and leave disk_file untouched if the file doesn't exist. - bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); - - // implements SourceTree ------------------------------------------- - io::ZeroCopyInputStream* Open(const string& filename); - - private: - struct Mapping { - string virtual_path; - string disk_path; - - inline Mapping(const string& virtual_path, const string& disk_path) - : virtual_path(virtual_path), disk_path(disk_path) {} - }; - vector mappings_; - - // Like Open(), but returns the on-disk path in disk_file if disk_file is - // non-NULL and the file could be successfully opened. - io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, - string* disk_file); - - // Like Open() but given the actual on-disk path. - io::ZeroCopyInputStream* OpenDiskFile(const string& filename); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h deleted file mode 100644 index 05ece1f1..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +++ /dev/null @@ -1,84 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace java { - -class EnumGenerator { - public: - explicit EnumGenerator(const EnumDescriptor* descriptor); - ~EnumGenerator(); - - void Generate(io::Printer* printer); - - private: - const EnumDescriptor* descriptor_; - - // The proto language allows multiple enum constants to have the same numeric - // value. Java, however, does not allow multiple enum constants to be - // considered equivalent. We treat the first defined constant for any - // given numeric value as "canonical" and the rest as aliases of that - // canonical value. - vector canonical_values_; - - struct Alias { - const EnumValueDescriptor* value; - const EnumValueDescriptor* canonical_value; - }; - vector aliases_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h deleted file mode 100644 index 0cad6be0..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +++ /dev/null @@ -1,121 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class EnumFieldGenerator : public FieldGenerator { - public: - explicit EnumFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~EnumFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); -}; - -class RepeatedEnumFieldGenerator : public FieldGenerator { - public: - explicit RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~RepeatedEnumFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateParsingCodeFromPacked(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h deleted file mode 100644 index 009ed9ff..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +++ /dev/null @@ -1,77 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ - -#include - -#include - -namespace google { -namespace protobuf { - class FieldDescriptor; // descriptor.h - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace java { - -// Generates code for an extension, which may be within the scope of some -// message or may be at file scope. This is much simpler than FieldGenerator -// since extensions are just simple identifiers with interesting types. -class ExtensionGenerator { - public: - explicit ExtensionGenerator(const FieldDescriptor* descriptor); - ~ExtensionGenerator(); - - void Generate(io::Printer* printer); - void GenerateNonNestedInitializationCode(io::Printer* printer); - void GenerateRegistrationCode(io::Printer* printer); - - private: - const FieldDescriptor* descriptor_; - string scope_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h deleted file mode 100644 index 6097f357..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +++ /dev/null @@ -1,108 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace java { - -class FieldGenerator { - public: - FieldGenerator() {} - virtual ~FieldGenerator(); - - virtual int GetNumBitsForMessage() const = 0; - virtual int GetNumBitsForBuilder() const = 0; - virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; - virtual void GenerateMembers(io::Printer* printer) const = 0; - virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; - virtual void GenerateInitializationCode(io::Printer* printer) const = 0; - virtual void GenerateBuilderClearCode(io::Printer* printer) const = 0; - virtual void GenerateMergingCode(io::Printer* printer) const = 0; - virtual void GenerateBuildingCode(io::Printer* printer) const = 0; - virtual void GenerateParsingCode(io::Printer* printer) const = 0; - virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const; - virtual void GenerateSerializationCode(io::Printer* printer) const = 0; - virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0; - virtual void GenerateFieldBuilderInitializationCode(io::Printer* printer) - const = 0; - - virtual void GenerateEqualsCode(io::Printer* printer) const = 0; - virtual void GenerateHashCode(io::Printer* printer) const = 0; - - virtual string GetBoxedType() const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); -}; - -// Convenience class which constructs FieldGenerators for a Descriptor. -class FieldGeneratorMap { - public: - explicit FieldGeneratorMap(const Descriptor* descriptor); - ~FieldGeneratorMap(); - - const FieldGenerator& get(const FieldDescriptor* field) const; - const FieldGenerator& get_extension(int index) const; - - private: - const Descriptor* descriptor_; - scoped_array > field_generators_; - scoped_array > extension_generators_; - - static FieldGenerator* MakeGenerator(const FieldDescriptor* field, - int messageBitIndex, int builderBitIndex); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h deleted file mode 100644 index 59911462..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +++ /dev/null @@ -1,101 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - class FileDescriptor; // descriptor.h - namespace io { - class Printer; // printer.h - } - namespace compiler { - class GeneratorContext; // code_generator.h - } -} - -namespace protobuf { -namespace compiler { -namespace java { - -class FileGenerator { - public: - explicit FileGenerator(const FileDescriptor* file); - ~FileGenerator(); - - // Checks for problems that would otherwise lead to cryptic compile errors. - // Returns true if there are no problems, or writes an error description to - // the given string and returns false otherwise. - bool Validate(string* error); - - void Generate(io::Printer* printer); - - // If we aren't putting everything into one file, this will write all the - // files other than the outer file (i.e. one for each message, enum, and - // service type). - void GenerateSiblings(const string& package_dir, - GeneratorContext* generator_context, - vector* file_list); - - const string& java_package() { return java_package_; } - const string& classname() { return classname_; } - - - private: - // Returns whether the dependency should be included in the output file. - // Always returns true for opensource, but used internally at Google to help - // improve compatibility with version 1 of protocol buffers. - bool ShouldIncludeDependency(const FileDescriptor* descriptor); - - const FileDescriptor* file_; - string java_package_; - string classname_; - - - void GenerateEmbeddedDescriptor(io::Printer* printer); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h deleted file mode 100644 index 888b8d85..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Generates Java code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// CodeGenerator implementation which generates Java code. If you create your -// own protocol compiler binary and you want it to support Java output, you -// can do so by registering an instance of this CodeGenerator with the -// CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT JavaGenerator : public CodeGenerator { - public: - JavaGenerator(); - ~JavaGenerator(); - - // implements CodeGenerator ---------------------------------------- - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h deleted file mode 100644 index 4ae07f15..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +++ /dev/null @@ -1,213 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// Commonly-used separator comments. Thick is a line of '=', thin is a line -// of '-'. -extern const char kThickSeparator[]; -extern const char kThinSeparator[]; - -// Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes -// "fooBarBaz" or "FooBarBaz", respectively. -string UnderscoresToCamelCase(const FieldDescriptor* field); -string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field); - -// Similar, but for method names. (Typically, this merely has the effect -// of lower-casing the first letter of the name.) -string UnderscoresToCamelCase(const MethodDescriptor* method); - -// Strips ".proto" or ".protodevel" from the end of a filename. -string StripProto(const string& filename); - -// Gets the unqualified class name for the file. Each .proto file becomes a -// single Java class, with all its contents nested in that class. -string FileClassName(const FileDescriptor* file); - -// Returns the file's Java package name. -string FileJavaPackage(const FileDescriptor* file); - -// Returns output directory for the given package name. -string JavaPackageToDir(string package_name); - -// Converts the given fully-qualified name in the proto namespace to its -// fully-qualified name in the Java namespace, given that it is in the given -// file. -string ToJavaName(const string& full_name, const FileDescriptor* file); - -// These return the fully-qualified class name corresponding to the given -// descriptor. -inline string ClassName(const Descriptor* descriptor) { - return ToJavaName(descriptor->full_name(), descriptor->file()); -} -inline string ClassName(const EnumDescriptor* descriptor) { - return ToJavaName(descriptor->full_name(), descriptor->file()); -} -inline string ClassName(const ServiceDescriptor* descriptor) { - return ToJavaName(descriptor->full_name(), descriptor->file()); -} -inline string ExtensionIdentifierName(const FieldDescriptor* descriptor) { - return ToJavaName(descriptor->full_name(), descriptor->file()); -} -string ClassName(const FileDescriptor* descriptor); - -// Get the unqualified name that should be used for a field's field -// number constant. -string FieldConstantName(const FieldDescriptor *field); - -// Returns the type of the FieldDescriptor. -// This does nothing interesting for the open source release, but is used for -// hacks that improve compatability with version 1 protocol buffers at Google. -FieldDescriptor::Type GetType(const FieldDescriptor* field); - -enum JavaType { - JAVATYPE_INT, - JAVATYPE_LONG, - JAVATYPE_FLOAT, - JAVATYPE_DOUBLE, - JAVATYPE_BOOLEAN, - JAVATYPE_STRING, - JAVATYPE_BYTES, - JAVATYPE_ENUM, - JAVATYPE_MESSAGE -}; - -JavaType GetJavaType(const FieldDescriptor* field); - -// Get the fully-qualified class name for a boxed primitive type, e.g. -// "java.lang.Integer" for JAVATYPE_INT. Returns NULL for enum and message -// types. -const char* BoxedPrimitiveTypeName(JavaType type); - -string DefaultValue(const FieldDescriptor* field); -bool IsDefaultValueJavaDefault(const FieldDescriptor* field); - -// Does this message class keep track of unknown fields? -inline bool HasUnknownFields(const Descriptor* descriptor) { - return descriptor->file()->options().optimize_for() != - FileOptions::LITE_RUNTIME; -} - -// Does this message class have generated parsing, serialization, and other -// standard methods for which reflection-based fallback implementations exist? -inline bool HasGeneratedMethods(const Descriptor* descriptor) { - return descriptor->file()->options().optimize_for() != - FileOptions::CODE_SIZE; -} - -// Does this message have specialized equals() and hashCode() methods? -inline bool HasEqualsAndHashCode(const Descriptor* descriptor) { - return descriptor->file()->options().java_generate_equals_and_hash(); -} - -// Does this message class have descriptor and reflection methods? -inline bool HasDescriptorMethods(const Descriptor* descriptor) { - return descriptor->file()->options().optimize_for() != - FileOptions::LITE_RUNTIME; -} -inline bool HasDescriptorMethods(const EnumDescriptor* descriptor) { - return descriptor->file()->options().optimize_for() != - FileOptions::LITE_RUNTIME; -} -inline bool HasDescriptorMethods(const FileDescriptor* descriptor) { - return descriptor->options().optimize_for() != - FileOptions::LITE_RUNTIME; -} - -inline bool HasNestedBuilders(const Descriptor* descriptor) { - // The proto-lite version doesn't support nested builders. - return descriptor->file()->options().optimize_for() != - FileOptions::LITE_RUNTIME; -} - -// Should we generate generic services for this file? -inline bool HasGenericServices(const FileDescriptor *file) { - return file->service_count() > 0 && - file->options().optimize_for() != FileOptions::LITE_RUNTIME && - file->options().java_generic_services(); -} - - -// Methods for shared bitfields. - -// Gets the name of the shared bitfield for the given index. -string GetBitFieldName(int index); - -// Gets the name of the shared bitfield for the given bit index. -// Effectively, GetBitFieldName(bitIndex / 32) -string GetBitFieldNameForBit(int bitIndex); - -// Generates the java code for the expression that returns the boolean value -// of the bit of the shared bitfields for the given bit index. -// Example: "((bitField1_ & 0x04) == 0x04)" -string GenerateGetBit(int bitIndex); - -// Generates the java code for the expression that sets the bit of the shared -// bitfields for the given bit index. -// Example: "bitField1_ = (bitField1_ | 0x04)" -string GenerateSetBit(int bitIndex); - -// Generates the java code for the expression that clears the bit of the shared -// bitfields for the given bit index. -// Example: "bitField1_ = (bitField1_ & ~0x04)" -string GenerateClearBit(int bitIndex); - -// Does the same as GenerateGetBit but operates on the bit field on a local -// variable. This is used by the builder to copy the value in the builder to -// the message. -// Example: "((from_bitField1_ & 0x04) == 0x04)" -string GenerateGetBitFromLocal(int bitIndex); - -// Does the same as GenerateSetBit but operates on the bit field on a local -// variable. This is used by the builder to copy the value in the builder to -// the message. -// Example: "to_bitField1_ = (to_bitField1_ | 0x04)" -string GenerateSetBitToLocal(int bitIndex); - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h deleted file mode 100644 index 4c6fbbe5..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +++ /dev/null @@ -1,109 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace java { - -class MessageGenerator { - public: - explicit MessageGenerator(const Descriptor* descriptor); - ~MessageGenerator(); - - // All static variables have to be declared at the top-level of the file - // so that we can control initialization order, which is important for - // DescriptorProto bootstrapping to work. - void GenerateStaticVariables(io::Printer* printer); - - // Output code which initializes the static variables generated by - // GenerateStaticVariables(). - void GenerateStaticVariableInitializers(io::Printer* printer); - - // Generate the class itself. - void Generate(io::Printer* printer); - - // Generates the base interface that both the class and its builder implement - void GenerateInterface(io::Printer* printer); - - // Generate code to register all contained extensions with an - // ExtensionRegistry. - void GenerateExtensionRegistrationCode(io::Printer* printer); - - private: - enum UseMemoization { - MEMOIZE, - DONT_MEMOIZE - }; - - void GenerateMessageSerializationMethods(io::Printer* printer); - void GenerateParseFromMethods(io::Printer* printer); - void GenerateSerializeOneField(io::Printer* printer, - const FieldDescriptor* field); - void GenerateSerializeOneExtensionRange( - io::Printer* printer, const Descriptor::ExtensionRange* range); - - void GenerateBuilder(io::Printer* printer); - void GenerateCommonBuilderMethods(io::Printer* printer); - void GenerateDescriptorMethods(io::Printer* printer); - void GenerateBuilderParsingMethods(io::Printer* printer); - void GenerateIsInitialized(io::Printer* printer, - UseMemoization useMemoization); - void GenerateEqualsAndHashCode(io::Printer* printer); - - const Descriptor* descriptor_; - FieldGeneratorMap field_generators_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h deleted file mode 100644 index 2efbcd97..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +++ /dev/null @@ -1,134 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class MessageFieldGenerator : public FieldGenerator { - public: - explicit MessageFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~MessageFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); - - void PrintNestedBuilderCondition(io::Printer* printer, - const char* regular_case, const char* nested_builder_case) const; - void PrintNestedBuilderFunction(io::Printer* printer, - const char* method_prototype, const char* regular_case, - const char* nested_builder_case, - const char* trailing_code) const; -}; - -class RepeatedMessageFieldGenerator : public FieldGenerator { - public: - explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~RepeatedMessageFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); - - void PrintNestedBuilderCondition(io::Printer* printer, - const char* regular_case, const char* nested_builder_case) const; - void PrintNestedBuilderFunction(io::Printer* printer, - const char* method_prototype, const char* regular_case, - const char* nested_builder_case, - const char* trailing_code) const; -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h deleted file mode 100644 index 7900fac5..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +++ /dev/null @@ -1,121 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class PrimitiveFieldGenerator : public FieldGenerator { - public: - explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~PrimitiveFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); -}; - -class RepeatedPrimitiveFieldGenerator : public FieldGenerator { - public: - explicit RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~RepeatedPrimitiveFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateParsingCodeFromPacked(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h deleted file mode 100644 index e07eebf7..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +++ /dev/null @@ -1,113 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ - -#include -#include - -namespace google { -namespace protobuf { - namespace io { - class Printer; // printer.h - } -} - -namespace protobuf { -namespace compiler { -namespace java { - -class ServiceGenerator { - public: - explicit ServiceGenerator(const ServiceDescriptor* descriptor); - ~ServiceGenerator(); - - void Generate(io::Printer* printer); - - private: - - // Generate the getDescriptorForType() method. - void GenerateGetDescriptorForType(io::Printer* printer); - - // Generate a Java interface for the service. - void GenerateInterface(io::Printer* printer); - - // Generate newReflectiveService() method. - void GenerateNewReflectiveServiceMethod(io::Printer* printer); - - // Generate newReflectiveBlockingService() method. - void GenerateNewReflectiveBlockingServiceMethod(io::Printer* printer); - - // Generate abstract method declarations for all methods. - void GenerateAbstractMethods(io::Printer* printer); - - // Generate the implementation of Service.callMethod(). - void GenerateCallMethod(io::Printer* printer); - - // Generate the implementation of BlockingService.callBlockingMethod(). - void GenerateCallBlockingMethod(io::Printer* printer); - - // Generate the implementations of Service.get{Request,Response}Prototype(). - enum RequestOrResponse { REQUEST, RESPONSE }; - void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); - - // Generate a stub implementation of the service. - void GenerateStub(io::Printer* printer); - - // Generate a method signature, possibly abstract, without body or trailing - // semicolon. - enum IsAbstract { IS_ABSTRACT, IS_CONCRETE }; - void GenerateMethodSignature(io::Printer* printer, - const MethodDescriptor* method, - IsAbstract is_abstract); - - // Generate a blocking stub interface and implementation of the service. - void GenerateBlockingStub(io::Printer* printer); - - // Generate the method signature for one method of a blocking stub. - void GenerateBlockingMethodSignature(io::Printer* printer, - const MethodDescriptor* method); - - const ServiceDescriptor* descriptor_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -#endif // NET_PROTO2_COMPILER_JAVA_SERVICE_H__ -} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h deleted file mode 100644 index 8cb41469..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +++ /dev/null @@ -1,120 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Author: jonp@google.com (Jon Perlow) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -class StringFieldGenerator : public FieldGenerator { - public: - explicit StringFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~StringFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator); -}; - -class RepeatedStringFieldGenerator : public FieldGenerator { - public: - explicit RepeatedStringFieldGenerator(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex); - ~RepeatedStringFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - int GetNumBitsForMessage() const; - int GetNumBitsForBuilder() const; - void GenerateInterfaceMembers(io::Printer* printer) const; - void GenerateMembers(io::Printer* printer) const; - void GenerateBuilderMembers(io::Printer* printer) const; - void GenerateInitializationCode(io::Printer* printer) const; - void GenerateBuilderClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateBuildingCode(io::Printer* printer) const; - void GenerateParsingCode(io::Printer* printer) const; - void GenerateParsingCodeFromPacked(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateFieldBuilderInitializationCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; - - private: - const FieldDescriptor* descriptor_; - map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h deleted file mode 100644 index 5c7942bd..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +++ /dev/null @@ -1,113 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) - -#ifndef GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { - -// A mock CodeGenerator, used by command_line_interface_unittest. This is in -// its own file so that it can be used both directly and as a plugin. -// -// Generate() produces some output which can be checked by ExpectCalled(). The -// generator can run in a different process (e.g. a plugin). -// -// If the parameter is "insert=NAMES", the MockCodeGenerator will insert lines -// into the files generated by other MockCodeGenerators instead of creating -// its own file. NAMES is a comma-separated list of the names of those other -// MockCodeGenerators. -// -// MockCodeGenerator will also modify its behavior slightly if the input file -// contains a message type with one of the following names: -// MockCodeGenerator_Error: Causes Generate() to return false and set the -// error message to "Saw message type MockCodeGenerator_Error." -// MockCodeGenerator_Exit: Generate() prints "Saw message type -// MockCodeGenerator_Exit." to stderr and then calls exit(123). -// MockCodeGenerator_Abort: Generate() prints "Saw message type -// MockCodeGenerator_Abort." to stderr and then calls abort(). -class MockCodeGenerator : public CodeGenerator { - public: - MockCodeGenerator(const string& name); - virtual ~MockCodeGenerator(); - - // Expect (via gTest) that a MockCodeGenerator with the given name was called - // with the given parameters by inspecting the output location. - // - // |insertions| is a comma-separated list of names of MockCodeGenerators which - // should have inserted lines into this file. - // |parsed_file_list| is a comma-separated list of names of the files - // that are being compiled together in this run. - static void ExpectGenerated(const string& name, - const string& parameter, - const string& insertions, - const string& file, - const string& first_message_name, - const string& parsed_file_list, - const string& output_directory); - - // Get the name of the file which would be written by the given generator. - static string GetOutputFileName(const string& generator_name, - const FileDescriptor* file); - static string GetOutputFileName(const string& generator_name, - const string& file); - - // implements CodeGenerator ---------------------------------------- - - virtual bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const; - - private: - string name_; - - static string GetOutputFileContent(const string& generator_name, - const string& parameter, - const FileDescriptor* file, - GeneratorContext *context); - static string GetOutputFileContent(const string& generator_name, - const string& parameter, - const string& file, - const string& parsed_file_list, - const string& first_message_name); -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h deleted file mode 100644 index b8971267..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +++ /dev/null @@ -1,64 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file exists solely to document the google::protobuf::compiler namespace. -// It is not compiled into anything, but it may be read by an automated -// documentation generator. - -namespace google { - -namespace protobuf { - -// Implementation of the Protocol Buffer compiler. -// -// This package contains code for parsing .proto files and generating code -// based on them. There are two reasons you might be interested in this -// package: -// - You want to parse .proto files at runtime. In this case, you should -// look at importer.h. Since this functionality is widely useful, it is -// included in the libprotobuf base library; you do not have to link against -// libprotoc. -// - You want to write a custom protocol compiler which generates different -// kinds of code, e.g. code in a different language which is not supported -// by the official compiler. For this purpose, command_line_interface.h -// provides you with a complete compiler front-end, so all you need to do -// is write a custom implementation of CodeGenerator and a trivial main() -// function. You can even make your compiler support the official languages -// in addition to your own. Since this functionality is only useful to those -// writing custom compilers, it is in a separate library called "libprotoc" -// which you will have to link against. -namespace compiler {} - -} // namespace protobuf -} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h deleted file mode 100644 index 4cc90a29..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +++ /dev/null @@ -1,434 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Implements parsing of .proto files to FileDescriptorProtos. - -#ifndef GOOGLE_PROTOBUF_COMPILER_PARSER_H__ -#define GOOGLE_PROTOBUF_COMPILER_PARSER_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { class Message; } - -namespace protobuf { -namespace compiler { - -// Defined in this file. -class Parser; -class SourceLocationTable; - -// Implements parsing of protocol definitions (such as .proto files). -// -// Note that most users will be more interested in the Importer class. -// Parser is a lower-level class which simply converts a single .proto file -// to a FileDescriptorProto. It does not resolve import directives or perform -// many other kinds of validation needed to construct a complete -// FileDescriptor. -class LIBPROTOBUF_EXPORT Parser { - public: - Parser(); - ~Parser(); - - // Parse the entire input and construct a FileDescriptorProto representing - // it. Returns true if no errors occurred, false otherwise. - bool Parse(io::Tokenizer* input, FileDescriptorProto* file); - - // Optional fetaures: - - // DEPRECATED: New code should use the SourceCodeInfo embedded in the - // FileDescriptorProto. - // - // Requests that locations of certain definitions be recorded to the given - // SourceLocationTable while parsing. This can be used to look up exact line - // and column numbers for errors reported by DescriptorPool during validation. - // Set to NULL (the default) to discard source location information. - void RecordSourceLocationsTo(SourceLocationTable* location_table) { - source_location_table_ = location_table; - } - - // Requests that errors be recorded to the given ErrorCollector while - // parsing. Set to NULL (the default) to discard error messages. - void RecordErrorsTo(io::ErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Returns the identifier used in the "syntax = " declaration, if one was - // seen during the last call to Parse(), or the empty string otherwise. - const string& GetSyntaxIdentifier() { return syntax_identifier_; } - - // If set true, input files will be required to begin with a syntax - // identifier. Otherwise, files may omit this. If a syntax identifier - // is provided, it must be 'syntax = "proto2";' and must appear at the - // top of this file regardless of whether or not it was required. - void SetRequireSyntaxIdentifier(bool value) { - require_syntax_identifier_ = value; - } - - // Call SetStopAfterSyntaxIdentifier(true) to tell the parser to stop - // parsing as soon as it has seen the syntax identifier, or lack thereof. - // This is useful for quickly identifying the syntax of the file without - // parsing the whole thing. If this is enabled, no error will be recorded - // if the syntax identifier is something other than "proto2" (since - // presumably the caller intends to deal with that), but other kinds of - // errors (e.g. parse errors) will still be reported. When this is enabled, - // you may pass a NULL FileDescriptorProto to Parse(). - void SetStopAfterSyntaxIdentifier(bool value) { - stop_after_syntax_identifier_ = value; - } - - private: - // ================================================================= - // Error recovery helpers - - // Consume the rest of the current statement. This consumes tokens - // until it sees one of: - // ';' Consumes the token and returns. - // '{' Consumes the brace then calls SkipRestOfBlock(). - // '}' Returns without consuming. - // EOF Returns (can't consume). - // The Parser often calls SkipStatement() after encountering a syntax - // error. This allows it to go on parsing the following lines, allowing - // it to report more than just one error in the file. - void SkipStatement(); - - // Consume the rest of the current block, including nested blocks, - // ending after the closing '}' is encountered and consumed, or at EOF. - void SkipRestOfBlock(); - - // ----------------------------------------------------------------- - // Single-token consuming helpers - // - // These make parsing code more readable. - - // True if the current token is TYPE_END. - inline bool AtEnd(); - - // True if the next token matches the given text. - inline bool LookingAt(const char* text); - // True if the next token is of the given type. - inline bool LookingAtType(io::Tokenizer::TokenType token_type); - - // If the next token exactly matches the text given, consume it and return - // true. Otherwise, return false without logging an error. - bool TryConsume(const char* text); - - // These attempt to read some kind of token from the input. If successful, - // they return true. Otherwise they return false and add the given error - // to the error list. - - // Consume a token with the exact text given. - bool Consume(const char* text, const char* error); - // Same as above, but automatically generates the error "Expected \"text\".", - // where "text" is the expected token text. - bool Consume(const char* text); - // Consume a token of type IDENTIFIER and store its text in "output". - bool ConsumeIdentifier(string* output, const char* error); - // Consume an integer and store its value in "output". - bool ConsumeInteger(int* output, const char* error); - // Consume a 64-bit integer and store its value in "output". If the value - // is greater than max_value, an error will be reported. - bool ConsumeInteger64(uint64 max_value, uint64* output, const char* error); - // Consume a number and store its value in "output". This will accept - // tokens of either INTEGER or FLOAT type. - bool ConsumeNumber(double* output, const char* error); - // Consume a string literal and store its (unescaped) value in "output". - bool ConsumeString(string* output, const char* error); - - // ----------------------------------------------------------------- - // Error logging helpers - - // Invokes error_collector_->AddError(), if error_collector_ is not NULL. - void AddError(int line, int column, const string& error); - - // Invokes error_collector_->AddError() with the line and column number - // of the current token. - void AddError(const string& error); - - // Records a location in the SourceCodeInfo.location table (see - // descriptor.proto). We use RAII to ensure that the start and end locations - // are recorded -- the constructor records the start location and the - // destructor records the end location. Since the parser is - // recursive-descent, this works out beautifully. - class LIBPROTOBUF_EXPORT LocationRecorder { - public: - // Construct the file's "root" location. - LocationRecorder(Parser* parser); - - // Construct a location that represents a declaration nested within the - // given parent. E.g. a field's location is nested within the location - // for a message type. The parent's path will be copied, so you should - // call AddPath() only to add the path components leading from the parent - // to the child (as opposed to leading from the root to the child). - LocationRecorder(const LocationRecorder& parent); - - // Convenience constructors that call AddPath() one or two times. - LocationRecorder(const LocationRecorder& parent, int path1); - LocationRecorder(const LocationRecorder& parent, int path1, int path2); - - ~LocationRecorder(); - - // Add a path component. See SourceCodeInfo.Location.path in - // descriptor.proto. - void AddPath(int path_component); - - // By default the location is considered to start at the current token at - // the time the LocationRecorder is created. StartAt() sets the start - // location to the given token instead. - void StartAt(const io::Tokenizer::Token& token); - - // By default the location is considered to end at the previous token at - // the time the LocationRecorder is destroyed. EndAt() sets the end - // location to the given token instead. - void EndAt(const io::Tokenizer::Token& token); - - // Records the start point of this location to the SourceLocationTable that - // was passed to RecordSourceLocationsTo(), if any. SourceLocationTable - // is an older way of keeping track of source locations which is still - // used in some places. - void RecordLegacyLocation(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location); - - private: - Parser* parser_; - SourceCodeInfo::Location* location_; - - void Init(const LocationRecorder& parent); - }; - - // ================================================================= - // Parsers for various language constructs - - // Parses the "syntax = \"proto2\";" line at the top of the file. Returns - // false if it failed to parse or if the syntax identifier was not - // recognized. - bool ParseSyntaxIdentifier(); - - // These methods parse various individual bits of code. They return - // false if they completely fail to parse the construct. In this case, - // it is probably necessary to skip the rest of the statement to recover. - // However, if these methods return true, it does NOT mean that there - // were no errors; only that there were no *syntax* errors. For instance, - // if a service method is defined using proper syntax but uses a primitive - // type as its input or output, ParseMethodField() still returns true - // and only reports the error by calling AddError(). In practice, this - // makes logic much simpler for the caller. - - // Parse a top-level message, enum, service, etc. - bool ParseTopLevelStatement(FileDescriptorProto* file, - const LocationRecorder& root_location); - - // Parse various language high-level language construrcts. - bool ParseMessageDefinition(DescriptorProto* message, - const LocationRecorder& message_location); - bool ParseEnumDefinition(EnumDescriptorProto* enum_type, - const LocationRecorder& enum_location); - bool ParseServiceDefinition(ServiceDescriptorProto* service, - const LocationRecorder& service_location); - bool ParsePackage(FileDescriptorProto* file, - const LocationRecorder& root_location); - bool ParseImport(string* import_filename, - const LocationRecorder& root_location, - int index); - bool ParseOption(Message* options, - const LocationRecorder& options_location); - - // These methods parse the contents of a message, enum, or service type and - // add them to the given object. They consume the entire block including - // the beginning and ending brace. - bool ParseMessageBlock(DescriptorProto* message, - const LocationRecorder& message_location); - bool ParseEnumBlock(EnumDescriptorProto* enum_type, - const LocationRecorder& enum_location); - bool ParseServiceBlock(ServiceDescriptorProto* service, - const LocationRecorder& service_location); - - // Parse one statement within a message, enum, or service block, inclunding - // final semicolon. - bool ParseMessageStatement(DescriptorProto* message, - const LocationRecorder& message_location); - bool ParseEnumStatement(EnumDescriptorProto* message, - const LocationRecorder& enum_location); - bool ParseServiceStatement(ServiceDescriptorProto* message, - const LocationRecorder& service_location); - - // Parse a field of a message. If the field is a group, its type will be - // added to "messages". - // - // parent_location and location_field_number_for_nested_type are needed when - // parsing groups -- we need to generate a nested message type within the - // parent and record its location accordingly. Since the parent could be - // either a FileDescriptorProto or a DescriptorProto, we must pass in the - // correct field number to use. - bool ParseMessageField(FieldDescriptorProto* field, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& field_location); - - // Parse an "extensions" declaration. - bool ParseExtensions(DescriptorProto* message, - const LocationRecorder& extensions_location); - - // Parse an "extend" declaration. (See also comments for - // ParseMessageField().) - bool ParseExtend(RepeatedPtrField* extensions, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& extend_location); - - // Parse a single enum value within an enum block. - bool ParseEnumConstant(EnumValueDescriptorProto* enum_value, - const LocationRecorder& enum_value_location); - - // Parse enum constant options, i.e. the list in square brackets at the end - // of the enum constant value definition. - bool ParseEnumConstantOptions(EnumValueDescriptorProto* value, - const LocationRecorder& enum_value_location); - - // Parse a single method within a service definition. - bool ParseServiceMethod(MethodDescriptorProto* method, - const LocationRecorder& method_location); - - // Parse "required", "optional", or "repeated" and fill in "label" - // with the value. - bool ParseLabel(FieldDescriptorProto::Label* label); - - // Parse a type name and fill in "type" (if it is a primitive) or - // "type_name" (if it is not) with the type parsed. - bool ParseType(FieldDescriptorProto::Type* type, - string* type_name); - // Parse a user-defined type and fill in "type_name" with the name. - // If a primitive type is named, it is treated as an error. - bool ParseUserDefinedType(string* type_name); - - // Parses field options, i.e. the stuff in square brackets at the end - // of a field definition. Also parses default value. - bool ParseFieldOptions(FieldDescriptorProto* field, - const LocationRecorder& field_location); - - // Parse the "default" option. This needs special handling because its - // type is the field's type. - bool ParseDefaultAssignment(FieldDescriptorProto* field, - const LocationRecorder& field_location); - - // Parse a single option name/value pair, e.g. "ctype = CORD". The name - // identifies a field of the given Message, and the value of that field - // is set to the parsed value. - bool ParseOptionAssignment(Message* options, - const LocationRecorder& options_location); - - // Parses a single part of a multipart option name. A multipart name consists - // of names separated by dots. Each name is either an identifier or a series - // of identifiers separated by dots and enclosed in parentheses. E.g., - // "foo.(bar.baz).qux". - bool ParseOptionNamePart(UninterpretedOption* uninterpreted_option, - const LocationRecorder& part_location); - - // Parses a string surrounded by balanced braces. Strips off the outer - // braces and stores the enclosed string in *value. - // E.g., - // { foo } *value gets 'foo' - // { foo { bar: box } } *value gets 'foo { bar: box }' - // {} *value gets '' - // - // REQUIRES: LookingAt("{") - // When finished successfully, we are looking at the first token past - // the ending brace. - bool ParseUninterpretedBlock(string* value); - - // ================================================================= - - io::Tokenizer* input_; - io::ErrorCollector* error_collector_; - SourceCodeInfo* source_code_info_; - SourceLocationTable* source_location_table_; // legacy - bool had_errors_; - bool require_syntax_identifier_; - bool stop_after_syntax_identifier_; - string syntax_identifier_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser); -}; - -// A table mapping (descriptor, ErrorLocation) pairs -- as reported by -// DescriptorPool when validating descriptors -- to line and column numbers -// within the original source code. -// -// This is semi-obsolete: FileDescriptorProto.source_code_info now contains -// far more complete information about source locations. However, as of this -// writing you still need to use SourceLocationTable when integrating with -// DescriptorPool. -class LIBPROTOBUF_EXPORT SourceLocationTable { - public: - SourceLocationTable(); - ~SourceLocationTable(); - - // Finds the precise location of the given error and fills in *line and - // *column with the line and column numbers. If not found, sets *line to - // -1 and *column to 0 (since line = -1 is used to mean "error has no exact - // location" in the ErrorCollector interface). Returns true if found, false - // otherwise. - bool Find(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location, - int* line, int* column) const; - - // Adds a location to the table. - void Add(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location, - int line, int column); - - // Clears the contents of the table. - void Clear(); - - private: - typedef map< - pair, - pair > LocationMap; - LocationMap location_map_; -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_PARSER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h deleted file mode 100644 index 64dfb1d2..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +++ /dev/null @@ -1,73 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// -// Front-end for protoc code generator plugins written in C++. -// -// To implement a protoc plugin in C++, simply write an implementation of -// CodeGenerator, then create a main() function like: -// int main(int argc, char* argv[]) { -// MyCodeGenerator generator; -// return google::protobuf::compiler::PluginMain(argc, argv, &generator); -// } -// You must link your plugin against libprotobuf and libprotoc. -// -// To get protoc to use the plugin, do one of the following: -// * Place the plugin binary somewhere in the PATH and give it the name -// "protoc-gen-NAME" (replacing "NAME" with the name of your plugin). If you -// then invoke protoc with the parameter --NAME_out=OUT_DIR (again, replace -// "NAME" with your plugin's name), protoc will invoke your plugin to generate -// the output, which will be placed in OUT_DIR. -// * Place the plugin binary anywhere, with any name, and pass the --plugin -// parameter to protoc to direct it to your plugin like so: -// protoc --plugin=protoc-gen-NAME=path/to/mybinary --NAME_out=OUT_DIR -// On Windows, make sure to include the .exe suffix: -// protoc --plugin=protoc-gen-NAME=path/to/mybinary.exe --NAME_out=OUT_DIR - -#ifndef GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ -#define GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ - -#include - -namespace google { -namespace protobuf { -namespace compiler { - -class CodeGenerator; // code_generator.h - -// Implements main() for a protoc plugin exposing the given code generator. -int PluginMain(int argc, char* argv[], const CodeGenerator* generator); - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h deleted file mode 100644 index 14216c2a..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +++ /dev/null @@ -1,790 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/compiler/plugin.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include "google/protobuf/descriptor.pb.h" -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { -namespace compiler { - -// Internal implementation detail -- do not call these. -void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - -class CodeGeneratorRequest; -class CodeGeneratorResponse; -class CodeGeneratorResponse_File; - -// =================================================================== - -class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message { - public: - CodeGeneratorRequest(); - virtual ~CodeGeneratorRequest(); - - CodeGeneratorRequest(const CodeGeneratorRequest& from); - - inline CodeGeneratorRequest& operator=(const CodeGeneratorRequest& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CodeGeneratorRequest& default_instance(); - - void Swap(CodeGeneratorRequest* other); - - // implements Message ---------------------------------------------- - - CodeGeneratorRequest* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CodeGeneratorRequest& from); - void MergeFrom(const CodeGeneratorRequest& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated string file_to_generate = 1; - inline int file_to_generate_size() const; - inline void clear_file_to_generate(); - static const int kFileToGenerateFieldNumber = 1; - inline const ::std::string& file_to_generate(int index) const; - inline ::std::string* mutable_file_to_generate(int index); - inline void set_file_to_generate(int index, const ::std::string& value); - inline void set_file_to_generate(int index, const char* value); - inline void set_file_to_generate(int index, const char* value, size_t size); - inline ::std::string* add_file_to_generate(); - inline void add_file_to_generate(const ::std::string& value); - inline void add_file_to_generate(const char* value); - inline void add_file_to_generate(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& file_to_generate() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_file_to_generate(); - - // optional string parameter = 2; - inline bool has_parameter() const; - inline void clear_parameter(); - static const int kParameterFieldNumber = 2; - inline const ::std::string& parameter() const; - inline void set_parameter(const ::std::string& value); - inline void set_parameter(const char* value); - inline void set_parameter(const char* value, size_t size); - inline ::std::string* mutable_parameter(); - inline ::std::string* release_parameter(); - - // repeated .google.protobuf.FileDescriptorProto proto_file = 15; - inline int proto_file_size() const; - inline void clear_proto_file(); - static const int kProtoFileFieldNumber = 15; - inline const ::google::protobuf::FileDescriptorProto& proto_file(int index) const; - inline ::google::protobuf::FileDescriptorProto* mutable_proto_file(int index); - inline ::google::protobuf::FileDescriptorProto* add_proto_file(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& - proto_file() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* - mutable_proto_file(); - - // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorRequest) - private: - inline void set_has_parameter(); - inline void clear_has_parameter(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::std::string> file_to_generate_; - ::std::string* parameter_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > proto_file_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - - void InitAsDefaultInstance(); - static CodeGeneratorRequest* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Message { - public: - CodeGeneratorResponse_File(); - virtual ~CodeGeneratorResponse_File(); - - CodeGeneratorResponse_File(const CodeGeneratorResponse_File& from); - - inline CodeGeneratorResponse_File& operator=(const CodeGeneratorResponse_File& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CodeGeneratorResponse_File& default_instance(); - - void Swap(CodeGeneratorResponse_File* other); - - // implements Message ---------------------------------------------- - - CodeGeneratorResponse_File* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CodeGeneratorResponse_File& from); - void MergeFrom(const CodeGeneratorResponse_File& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // optional string insertion_point = 2; - inline bool has_insertion_point() const; - inline void clear_insertion_point(); - static const int kInsertionPointFieldNumber = 2; - inline const ::std::string& insertion_point() const; - inline void set_insertion_point(const ::std::string& value); - inline void set_insertion_point(const char* value); - inline void set_insertion_point(const char* value, size_t size); - inline ::std::string* mutable_insertion_point(); - inline ::std::string* release_insertion_point(); - - // optional string content = 15; - inline bool has_content() const; - inline void clear_content(); - static const int kContentFieldNumber = 15; - inline const ::std::string& content() const; - inline void set_content(const ::std::string& value); - inline void set_content(const char* value); - inline void set_content(const char* value, size_t size); - inline ::std::string* mutable_content(); - inline ::std::string* release_content(); - - // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse.File) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_insertion_point(); - inline void clear_has_insertion_point(); - inline void set_has_content(); - inline void clear_has_content(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::std::string* insertion_point_; - ::std::string* content_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - - void InitAsDefaultInstance(); - static CodeGeneratorResponse_File* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Message { - public: - CodeGeneratorResponse(); - virtual ~CodeGeneratorResponse(); - - CodeGeneratorResponse(const CodeGeneratorResponse& from); - - inline CodeGeneratorResponse& operator=(const CodeGeneratorResponse& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CodeGeneratorResponse& default_instance(); - - void Swap(CodeGeneratorResponse* other); - - // implements Message ---------------------------------------------- - - CodeGeneratorResponse* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CodeGeneratorResponse& from); - void MergeFrom(const CodeGeneratorResponse& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef CodeGeneratorResponse_File File; - - // accessors ------------------------------------------------------- - - // optional string error = 1; - inline bool has_error() const; - inline void clear_error(); - static const int kErrorFieldNumber = 1; - inline const ::std::string& error() const; - inline void set_error(const ::std::string& value); - inline void set_error(const char* value); - inline void set_error(const char* value, size_t size); - inline ::std::string* mutable_error(); - inline ::std::string* release_error(); - - // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; - inline int file_size() const; - inline void clear_file(); - static const int kFileFieldNumber = 15; - inline const ::google::protobuf::compiler::CodeGeneratorResponse_File& file(int index) const; - inline ::google::protobuf::compiler::CodeGeneratorResponse_File* mutable_file(int index); - inline ::google::protobuf::compiler::CodeGeneratorResponse_File* add_file(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >& - file() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >* - mutable_file(); - - // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse) - private: - inline void set_has_error(); - inline void clear_has_error(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* error_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File > file_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - - void InitAsDefaultInstance(); - static CodeGeneratorResponse* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// CodeGeneratorRequest - -// repeated string file_to_generate = 1; -inline int CodeGeneratorRequest::file_to_generate_size() const { - return file_to_generate_.size(); -} -inline void CodeGeneratorRequest::clear_file_to_generate() { - file_to_generate_.Clear(); -} -inline const ::std::string& CodeGeneratorRequest::file_to_generate(int index) const { - return file_to_generate_.Get(index); -} -inline ::std::string* CodeGeneratorRequest::mutable_file_to_generate(int index) { - return file_to_generate_.Mutable(index); -} -inline void CodeGeneratorRequest::set_file_to_generate(int index, const ::std::string& value) { - file_to_generate_.Mutable(index)->assign(value); -} -inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { - file_to_generate_.Mutable(index)->assign(value); -} -inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, size_t size) { - file_to_generate_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* CodeGeneratorRequest::add_file_to_generate() { - return file_to_generate_.Add(); -} -inline void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) { - file_to_generate_.Add()->assign(value); -} -inline void CodeGeneratorRequest::add_file_to_generate(const char* value) { - file_to_generate_.Add()->assign(value); -} -inline void CodeGeneratorRequest::add_file_to_generate(const char* value, size_t size) { - file_to_generate_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -CodeGeneratorRequest::file_to_generate() const { - return file_to_generate_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -CodeGeneratorRequest::mutable_file_to_generate() { - return &file_to_generate_; -} - -// optional string parameter = 2; -inline bool CodeGeneratorRequest::has_parameter() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void CodeGeneratorRequest::set_has_parameter() { - _has_bits_[0] |= 0x00000002u; -} -inline void CodeGeneratorRequest::clear_has_parameter() { - _has_bits_[0] &= ~0x00000002u; -} -inline void CodeGeneratorRequest::clear_parameter() { - if (parameter_ != &::google::protobuf::internal::kEmptyString) { - parameter_->clear(); - } - clear_has_parameter(); -} -inline const ::std::string& CodeGeneratorRequest::parameter() const { - return *parameter_; -} -inline void CodeGeneratorRequest::set_parameter(const ::std::string& value) { - set_has_parameter(); - if (parameter_ == &::google::protobuf::internal::kEmptyString) { - parameter_ = new ::std::string; - } - parameter_->assign(value); -} -inline void CodeGeneratorRequest::set_parameter(const char* value) { - set_has_parameter(); - if (parameter_ == &::google::protobuf::internal::kEmptyString) { - parameter_ = new ::std::string; - } - parameter_->assign(value); -} -inline void CodeGeneratorRequest::set_parameter(const char* value, size_t size) { - set_has_parameter(); - if (parameter_ == &::google::protobuf::internal::kEmptyString) { - parameter_ = new ::std::string; - } - parameter_->assign(reinterpret_cast(value), size); -} -inline ::std::string* CodeGeneratorRequest::mutable_parameter() { - set_has_parameter(); - if (parameter_ == &::google::protobuf::internal::kEmptyString) { - parameter_ = new ::std::string; - } - return parameter_; -} -inline ::std::string* CodeGeneratorRequest::release_parameter() { - clear_has_parameter(); - if (parameter_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = parameter_; - parameter_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated .google.protobuf.FileDescriptorProto proto_file = 15; -inline int CodeGeneratorRequest::proto_file_size() const { - return proto_file_.size(); -} -inline void CodeGeneratorRequest::clear_proto_file() { - proto_file_.Clear(); -} -inline const ::google::protobuf::FileDescriptorProto& CodeGeneratorRequest::proto_file(int index) const { - return proto_file_.Get(index); -} -inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::mutable_proto_file(int index) { - return proto_file_.Mutable(index); -} -inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::add_proto_file() { - return proto_file_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& -CodeGeneratorRequest::proto_file() const { - return proto_file_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* -CodeGeneratorRequest::mutable_proto_file() { - return &proto_file_; -} - -// ------------------------------------------------------------------- - -// CodeGeneratorResponse_File - -// optional string name = 1; -inline bool CodeGeneratorResponse_File::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void CodeGeneratorResponse_File::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void CodeGeneratorResponse_File::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void CodeGeneratorResponse_File::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& CodeGeneratorResponse_File::name() const { - return *name_; -} -inline void CodeGeneratorResponse_File::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void CodeGeneratorResponse_File::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void CodeGeneratorResponse_File::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* CodeGeneratorResponse_File::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* CodeGeneratorResponse_File::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string insertion_point = 2; -inline bool CodeGeneratorResponse_File::has_insertion_point() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void CodeGeneratorResponse_File::set_has_insertion_point() { - _has_bits_[0] |= 0x00000002u; -} -inline void CodeGeneratorResponse_File::clear_has_insertion_point() { - _has_bits_[0] &= ~0x00000002u; -} -inline void CodeGeneratorResponse_File::clear_insertion_point() { - if (insertion_point_ != &::google::protobuf::internal::kEmptyString) { - insertion_point_->clear(); - } - clear_has_insertion_point(); -} -inline const ::std::string& CodeGeneratorResponse_File::insertion_point() const { - return *insertion_point_; -} -inline void CodeGeneratorResponse_File::set_insertion_point(const ::std::string& value) { - set_has_insertion_point(); - if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { - insertion_point_ = new ::std::string; - } - insertion_point_->assign(value); -} -inline void CodeGeneratorResponse_File::set_insertion_point(const char* value) { - set_has_insertion_point(); - if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { - insertion_point_ = new ::std::string; - } - insertion_point_->assign(value); -} -inline void CodeGeneratorResponse_File::set_insertion_point(const char* value, size_t size) { - set_has_insertion_point(); - if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { - insertion_point_ = new ::std::string; - } - insertion_point_->assign(reinterpret_cast(value), size); -} -inline ::std::string* CodeGeneratorResponse_File::mutable_insertion_point() { - set_has_insertion_point(); - if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { - insertion_point_ = new ::std::string; - } - return insertion_point_; -} -inline ::std::string* CodeGeneratorResponse_File::release_insertion_point() { - clear_has_insertion_point(); - if (insertion_point_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = insertion_point_; - insertion_point_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string content = 15; -inline bool CodeGeneratorResponse_File::has_content() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void CodeGeneratorResponse_File::set_has_content() { - _has_bits_[0] |= 0x00000004u; -} -inline void CodeGeneratorResponse_File::clear_has_content() { - _has_bits_[0] &= ~0x00000004u; -} -inline void CodeGeneratorResponse_File::clear_content() { - if (content_ != &::google::protobuf::internal::kEmptyString) { - content_->clear(); - } - clear_has_content(); -} -inline const ::std::string& CodeGeneratorResponse_File::content() const { - return *content_; -} -inline void CodeGeneratorResponse_File::set_content(const ::std::string& value) { - set_has_content(); - if (content_ == &::google::protobuf::internal::kEmptyString) { - content_ = new ::std::string; - } - content_->assign(value); -} -inline void CodeGeneratorResponse_File::set_content(const char* value) { - set_has_content(); - if (content_ == &::google::protobuf::internal::kEmptyString) { - content_ = new ::std::string; - } - content_->assign(value); -} -inline void CodeGeneratorResponse_File::set_content(const char* value, size_t size) { - set_has_content(); - if (content_ == &::google::protobuf::internal::kEmptyString) { - content_ = new ::std::string; - } - content_->assign(reinterpret_cast(value), size); -} -inline ::std::string* CodeGeneratorResponse_File::mutable_content() { - set_has_content(); - if (content_ == &::google::protobuf::internal::kEmptyString) { - content_ = new ::std::string; - } - return content_; -} -inline ::std::string* CodeGeneratorResponse_File::release_content() { - clear_has_content(); - if (content_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = content_; - content_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// CodeGeneratorResponse - -// optional string error = 1; -inline bool CodeGeneratorResponse::has_error() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void CodeGeneratorResponse::set_has_error() { - _has_bits_[0] |= 0x00000001u; -} -inline void CodeGeneratorResponse::clear_has_error() { - _has_bits_[0] &= ~0x00000001u; -} -inline void CodeGeneratorResponse::clear_error() { - if (error_ != &::google::protobuf::internal::kEmptyString) { - error_->clear(); - } - clear_has_error(); -} -inline const ::std::string& CodeGeneratorResponse::error() const { - return *error_; -} -inline void CodeGeneratorResponse::set_error(const ::std::string& value) { - set_has_error(); - if (error_ == &::google::protobuf::internal::kEmptyString) { - error_ = new ::std::string; - } - error_->assign(value); -} -inline void CodeGeneratorResponse::set_error(const char* value) { - set_has_error(); - if (error_ == &::google::protobuf::internal::kEmptyString) { - error_ = new ::std::string; - } - error_->assign(value); -} -inline void CodeGeneratorResponse::set_error(const char* value, size_t size) { - set_has_error(); - if (error_ == &::google::protobuf::internal::kEmptyString) { - error_ = new ::std::string; - } - error_->assign(reinterpret_cast(value), size); -} -inline ::std::string* CodeGeneratorResponse::mutable_error() { - set_has_error(); - if (error_ == &::google::protobuf::internal::kEmptyString) { - error_ = new ::std::string; - } - return error_; -} -inline ::std::string* CodeGeneratorResponse::release_error() { - clear_has_error(); - if (error_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = error_; - error_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; -inline int CodeGeneratorResponse::file_size() const { - return file_.size(); -} -inline void CodeGeneratorResponse::clear_file() { - file_.Clear(); -} -inline const ::google::protobuf::compiler::CodeGeneratorResponse_File& CodeGeneratorResponse::file(int index) const { - return file_.Get(index); -} -inline ::google::protobuf::compiler::CodeGeneratorResponse_File* CodeGeneratorResponse::mutable_file(int index) { - return file_.Mutable(index); -} -inline ::google::protobuf::compiler::CodeGeneratorResponse_File* CodeGeneratorResponse::add_file() { - return file_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >& -CodeGeneratorResponse::file() const { - return file_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >* -CodeGeneratorResponse::mutable_file() { - return &file_; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace compiler -} // namespace protobuf -} // namespace google - -#ifndef SWIG -namespace google { -namespace protobuf { - - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h deleted file mode 100644 index 84eaf8ab..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +++ /dev/null @@ -1,156 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: robinson@google.com (Will Robinson) -// -// Generates Python code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ - -#include - -#include -#include - -namespace google { -namespace protobuf { - -class Descriptor; -class EnumDescriptor; -class EnumValueDescriptor; -class FieldDescriptor; -class ServiceDescriptor; - -namespace io { class Printer; } - -namespace compiler { -namespace python { - -// CodeGenerator implementation for generated Python protocol buffer classes. -// If you create your own protocol compiler binary and you want it to support -// Python output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator : public CodeGenerator { - public: - Generator(); - virtual ~Generator(); - - // CodeGenerator methods. - virtual bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; - - private: - void PrintImports() const; - void PrintFileDescriptor() const; - void PrintTopLevelEnums() const; - void PrintAllNestedEnumsInFile() const; - void PrintNestedEnums(const Descriptor& descriptor) const; - void PrintEnum(const EnumDescriptor& enum_descriptor) const; - - void PrintTopLevelExtensions() const; - - void PrintFieldDescriptor( - const FieldDescriptor& field, bool is_extension) const; - void PrintFieldDescriptorsInDescriptor( - const Descriptor& message_descriptor, - bool is_extension, - const string& list_variable_name, - int (Descriptor::*CountFn)() const, - const FieldDescriptor* (Descriptor::*GetterFn)(int) const) const; - void PrintFieldsInDescriptor(const Descriptor& message_descriptor) const; - void PrintExtensionsInDescriptor(const Descriptor& message_descriptor) const; - void PrintMessageDescriptors() const; - void PrintDescriptor(const Descriptor& message_descriptor) const; - void PrintNestedDescriptors(const Descriptor& containing_descriptor) const; - - void PrintMessages() const; - void PrintMessage(const Descriptor& message_descriptor) const; - void PrintNestedMessages(const Descriptor& containing_descriptor) const; - - void FixForeignFieldsInDescriptors() const; - void FixForeignFieldsInDescriptor( - const Descriptor& descriptor, - const Descriptor* containing_descriptor) const; - void FixForeignFieldsInField(const Descriptor* containing_type, - const FieldDescriptor& field, - const string& python_dict_name) const; - void AddMessageToFileDescriptor(const Descriptor& descriptor) const; - string FieldReferencingExpression(const Descriptor* containing_type, - const FieldDescriptor& field, - const string& python_dict_name) const; - template - void FixContainingTypeInDescriptor( - const DescriptorT& descriptor, - const Descriptor* containing_descriptor) const; - - void FixForeignFieldsInExtensions() const; - void FixForeignFieldsInExtension( - const FieldDescriptor& extension_field) const; - void FixForeignFieldsInNestedExtensions(const Descriptor& descriptor) const; - - void PrintServices() const; - void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; - void PrintServiceClass(const ServiceDescriptor& descriptor) const; - void PrintServiceStub(const ServiceDescriptor& descriptor) const; - - void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; - string OptionsValue(const string& class_name, - const string& serialized_options) const; - bool GeneratingDescriptorProto() const; - - template - string ModuleLevelDescriptorName(const DescriptorT& descriptor) const; - string ModuleLevelMessageName(const Descriptor& descriptor) const; - string ModuleLevelServiceDescriptorName( - const ServiceDescriptor& descriptor) const; - - template - void PrintSerializedPbInterval( - const DescriptorT& descriptor, DescriptorProtoT& proto) const; - - // Very coarse-grained lock to ensure that Generate() is reentrant. - // Guards file_, printer_ and file_descriptor_serialized_. - mutable Mutex mutex_; - mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. - mutable string file_descriptor_serialized_; - mutable io::Printer* printer_; // Set in Generate(). Under mutex_. - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator); -}; - -} // namespace python -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h deleted file mode 100644 index de9fce9e..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +++ /dev/null @@ -1,108 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) - -#ifndef GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ -#define GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ - -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN // right... -#include -#else // _WIN32 -#include -#include -#endif // !_WIN32 -#include - -#include - - -namespace google { -namespace protobuf { - -class Message; - -namespace compiler { - -// Utility class for launching sub-processes. -class Subprocess { - public: - Subprocess(); - ~Subprocess(); - - enum SearchMode { - SEARCH_PATH, // Use PATH environment variable. - EXACT_NAME // Program is an exact file name; don't use the PATH. - }; - - // Start the subprocess. Currently we don't provide a way to specify - // arguments as protoc plugins don't have any. - void Start(const string& program, SearchMode search_mode); - - // Serialize the input message and pipe it to the subprocess's stdin, then - // close the pipe. Meanwhile, read from the subprocess's stdout and parse - // the data into *output. All this is done carefully to avoid deadlocks. - // Returns true if successful. On any sort of error, returns false and sets - // *error to a description of the problem. - bool Communicate(const Message& input, Message* output, string* error); - -#ifdef _WIN32 - // Given an error code, returns a human-readable error message. This is - // defined here so that CommandLineInterface can share it. - static string Win32ErrorMessage(DWORD error_code); -#endif - - private: -#ifdef _WIN32 - DWORD process_start_error_; - HANDLE child_handle_; - - // The file handles for our end of the child's pipes. We close each and - // set it to NULL when no longer needed. - HANDLE child_stdin_; - HANDLE child_stdout_; - -#else // _WIN32 - pid_t child_pid_; - - // The file descriptors for our end of the child's pipes. We close each and - // set it to -1 when no longer needed. - int child_stdin_; - int child_stdout_; - -#endif // !_WIN32 -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h b/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h deleted file mode 100644 index be73972a..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +++ /dev/null @@ -1,93 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { - -class ZipWriter { - public: - ZipWriter(io::ZeroCopyOutputStream* raw_output); - ~ZipWriter(); - - bool Write(const string& filename, const string& contents); - bool WriteDirectory(); - - private: - struct FileInfo { - string name; - uint32 offset; - uint32 size; - uint32 crc32; - }; - - io::ZeroCopyOutputStream* raw_output_; - vector files_; -}; - -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h b/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h deleted file mode 100644 index 7f87dd80..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +++ /dev/null @@ -1,1367 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains classes which describe a type of protocol message. -// You can use a message's descriptor to learn at runtime what fields -// it contains and what the types of those fields are. The Message -// interface also allows you to dynamically access and modify individual -// fields by passing the FieldDescriptor of the field you are interested -// in. -// -// Most users will not care about descriptors, because they will write -// code specific to certain protocol types and will simply use the classes -// generated by the protocol compiler directly. Advanced users who want -// to operate on arbitrary types (not known at compile time) may want to -// read descriptors in order to learn about the contents of a message. -// A very small number of users will want to construct their own -// Descriptors, either because they are implementing Message manually or -// because they are writing something like the protocol compiler. -// -// For an example of how you might use descriptors, see the code example -// at the top of message.h. - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_H__ -#define GOOGLE_PROTOBUF_DESCRIPTOR_H__ - -#include -#include -#include - - -namespace google { -namespace protobuf { - -// Defined in this file. -class Descriptor; -class FieldDescriptor; -class EnumDescriptor; -class EnumValueDescriptor; -class ServiceDescriptor; -class MethodDescriptor; -class FileDescriptor; -class DescriptorDatabase; -class DescriptorPool; - -// Defined in descriptor.proto -class DescriptorProto; -class FieldDescriptorProto; -class EnumDescriptorProto; -class EnumValueDescriptorProto; -class ServiceDescriptorProto; -class MethodDescriptorProto; -class FileDescriptorProto; -class MessageOptions; -class FieldOptions; -class EnumOptions; -class EnumValueOptions; -class ServiceOptions; -class MethodOptions; -class FileOptions; -class UninterpretedOption; - -// Defined in message.h -class Message; - -// Defined in descriptor.cc -class DescriptorBuilder; -class FileDescriptorTables; - -// Defined in unknown_field_set.h. -class UnknownField; - -// Describes a type of protocol message, or a particular group within a -// message. To obtain the Descriptor for a given message object, call -// Message::GetDescriptor(). Generated message classes also have a -// static method called descriptor() which returns the type's descriptor. -// Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT Descriptor { - public: - // The name of the message type, not including its scope. - const string& name() const; - - // The fully-qualified name of the message type, scope delimited by - // periods. For example, message type "Foo" which is declared in package - // "bar" has full name "bar.Foo". If a type "Baz" is nested within - // Foo, Baz's full_name is "bar.Foo.Baz". To get only the part that - // comes after the last '.', use name(). - const string& full_name() const; - - // Index of this descriptor within the file or containing type's message - // type array. - int index() const; - - // The .proto file in which this message type was defined. Never NULL. - const FileDescriptor* file() const; - - // If this Descriptor describes a nested type, this returns the type - // in which it is nested. Otherwise, returns NULL. - const Descriptor* containing_type() const; - - // Get options for this message type. These are specified in the .proto file - // by placing lines like "option foo = 1234;" in the message definition. - // Allowed options are defined by MessageOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const MessageOptions& options() const; - - // Write the contents of this Descriptor into the given DescriptorProto. - // The target DescriptorProto must be clear before calling this; if it - // isn't, the result may be garbage. - void CopyTo(DescriptorProto* proto) const; - - // Write the contents of this decriptor in a human-readable form. Output - // will be suitable for re-parsing. - string DebugString() const; - - // Field stuff ----------------------------------------------------- - - // The number of fields in this message type. - int field_count() const; - // Gets a field by index, where 0 <= index < field_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* field(int index) const; - - // Looks up a field by declared tag number. Returns NULL if no such field - // exists. - const FieldDescriptor* FindFieldByNumber(int number) const; - // Looks up a field by name. Returns NULL if no such field exists. - const FieldDescriptor* FindFieldByName(const string& name) const; - - // Looks up a field by lowercased name (as returned by lowercase_name()). - // This lookup may be ambiguous if multiple field names differ only by case, - // in which case the field returned is chosen arbitrarily from the matches. - const FieldDescriptor* FindFieldByLowercaseName( - const string& lowercase_name) const; - - // Looks up a field by camel-case name (as returned by camelcase_name()). - // This lookup may be ambiguous if multiple field names differ in a way that - // leads them to have identical camel-case names, in which case the field - // returned is chosen arbitrarily from the matches. - const FieldDescriptor* FindFieldByCamelcaseName( - const string& camelcase_name) const; - - // Nested type stuff ----------------------------------------------- - - // The number of nested types in this message type. - int nested_type_count() const; - // Gets a nested type by index, where 0 <= index < nested_type_count(). - // These are returned in the order they were defined in the .proto file. - const Descriptor* nested_type(int index) const; - - // Looks up a nested type by name. Returns NULL if no such nested type - // exists. - const Descriptor* FindNestedTypeByName(const string& name) const; - - // Enum stuff ------------------------------------------------------ - - // The number of enum types in this message type. - int enum_type_count() const; - // Gets an enum type by index, where 0 <= index < enum_type_count(). - // These are returned in the order they were defined in the .proto file. - const EnumDescriptor* enum_type(int index) const; - - // Looks up an enum type by name. Returns NULL if no such enum type exists. - const EnumDescriptor* FindEnumTypeByName(const string& name) const; - - // Looks up an enum value by name, among all enum types in this message. - // Returns NULL if no such value exists. - const EnumValueDescriptor* FindEnumValueByName(const string& name) const; - - // Extensions ------------------------------------------------------ - - // A range of field numbers which are designated for third-party - // extensions. - struct ExtensionRange { - int start; // inclusive - int end; // exclusive - }; - - // The number of extension ranges in this message type. - int extension_range_count() const; - // Gets an extension range by index, where 0 <= index < - // extension_range_count(). These are returned in the order they were defined - // in the .proto file. - const ExtensionRange* extension_range(int index) const; - - // Returns true if the number is in one of the extension ranges. - bool IsExtensionNumber(int number) const; - - // The number of extensions -- extending *other* messages -- that were - // defined nested within this message type's scope. - int extension_count() const; - // Get an extension by index, where 0 <= index < extension_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* extension(int index) const; - - // Looks up a named extension (which extends some *other* message type) - // defined within this message type's scope. - const FieldDescriptor* FindExtensionByName(const string& name) const; - - // Similar to FindFieldByLowercaseName(), but finds extensions defined within - // this message type's scope. - const FieldDescriptor* FindExtensionByLowercaseName(const string& name) const; - - // Similar to FindFieldByCamelcaseName(), but finds extensions defined within - // this message type's scope. - const FieldDescriptor* FindExtensionByCamelcaseName(const string& name) const; - - private: - typedef MessageOptions OptionsType; - - // Internal version of DebugString; controls the level of indenting for - // correct depth - void DebugString(int depth, string *contents) const; - - const string* name_; - const string* full_name_; - const FileDescriptor* file_; - const Descriptor* containing_type_; - const MessageOptions* options_; - - // True if this is a placeholder for an unknown type. - bool is_placeholder_; - // True if this is a placeholder and the type name wasn't fully-qualified. - bool is_unqualified_placeholder_; - - int field_count_; - FieldDescriptor* fields_; - int nested_type_count_; - Descriptor* nested_types_; - int enum_type_count_; - EnumDescriptor* enum_types_; - int extension_range_count_; - ExtensionRange* extension_ranges_; - int extension_count_; - FieldDescriptor* extensions_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in descriptor.cc - // and update them to initialize the field. - - // Must be constructed using DescriptorPool. - Descriptor() {} - friend class DescriptorBuilder; - friend class EnumDescriptor; - friend class FieldDescriptor; - friend class MethodDescriptor; - friend class FileDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor); -}; - -// Describes a single field of a message. To get the descriptor for a given -// field, first get the Descriptor for the message in which it is defined, -// then call Descriptor::FindFieldByName(). To get a FieldDescriptor for -// an extension, do one of the following: -// - Get the Descriptor or FileDescriptor for its containing scope, then -// call Descriptor::FindExtensionByName() or -// FileDescriptor::FindExtensionByName(). -// - Given a DescriptorPool, call DescriptorPool::FindExtensionByNumber(). -// - Given a Reflection for a message object, call -// Reflection::FindKnownExtensionByName() or -// Reflection::FindKnownExtensionByNumber(). -// Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT FieldDescriptor { - public: - // Identifies a field type. 0 is reserved for errors. The order is weird - // for historical reasons. Types 12 and up are new in proto2. - enum Type { - TYPE_DOUBLE = 1, // double, exactly eight bytes on the wire. - TYPE_FLOAT = 2, // float, exactly four bytes on the wire. - TYPE_INT64 = 3, // int64, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT64 if negative - // values are likely. - TYPE_UINT64 = 4, // uint64, varint on the wire. - TYPE_INT32 = 5, // int32, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT32 if negative - // values are likely. - TYPE_FIXED64 = 6, // uint64, exactly eight bytes on the wire. - TYPE_FIXED32 = 7, // uint32, exactly four bytes on the wire. - TYPE_BOOL = 8, // bool, varint on the wire. - TYPE_STRING = 9, // UTF-8 text. - TYPE_GROUP = 10, // Tag-delimited message. Deprecated. - TYPE_MESSAGE = 11, // Length-delimited message. - - TYPE_BYTES = 12, // Arbitrary byte array. - TYPE_UINT32 = 13, // uint32, varint on the wire - TYPE_ENUM = 14, // Enum, varint on the wire - TYPE_SFIXED32 = 15, // int32, exactly four bytes on the wire - TYPE_SFIXED64 = 16, // int64, exactly eight bytes on the wire - TYPE_SINT32 = 17, // int32, ZigZag-encoded varint on the wire - TYPE_SINT64 = 18, // int64, ZigZag-encoded varint on the wire - - MAX_TYPE = 18, // Constant useful for defining lookup tables - // indexed by Type. - }; - - // Specifies the C++ data type used to represent the field. There is a - // fixed mapping from Type to CppType where each Type maps to exactly one - // CppType. 0 is reserved for errors. - enum CppType { - CPPTYPE_INT32 = 1, // TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32 - CPPTYPE_INT64 = 2, // TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64 - CPPTYPE_UINT32 = 3, // TYPE_UINT32, TYPE_FIXED32 - CPPTYPE_UINT64 = 4, // TYPE_UINT64, TYPE_FIXED64 - CPPTYPE_DOUBLE = 5, // TYPE_DOUBLE - CPPTYPE_FLOAT = 6, // TYPE_FLOAT - CPPTYPE_BOOL = 7, // TYPE_BOOL - CPPTYPE_ENUM = 8, // TYPE_ENUM - CPPTYPE_STRING = 9, // TYPE_STRING, TYPE_BYTES - CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP - - MAX_CPPTYPE = 10, // Constant useful for defining lookup tables - // indexed by CppType. - }; - - // Identifies whether the field is optional, required, or repeated. 0 is - // reserved for errors. - enum Label { - LABEL_OPTIONAL = 1, // optional - LABEL_REQUIRED = 2, // required - LABEL_REPEATED = 3, // repeated - - MAX_LABEL = 3, // Constant useful for defining lookup tables - // indexed by Label. - }; - - // Valid field numbers are positive integers up to kMaxNumber. - static const int kMaxNumber = (1 << 29) - 1; - - // First field number reserved for the protocol buffer library implementation. - // Users may not declare fields that use reserved numbers. - static const int kFirstReservedNumber = 19000; - // Last field number reserved for the protocol buffer library implementation. - // Users may not declare fields that use reserved numbers. - static const int kLastReservedNumber = 19999; - - const string& name() const; // Name of this field within the message. - const string& full_name() const; // Fully-qualified name of the field. - const FileDescriptor* file() const;// File in which this field was defined. - bool is_extension() const; // Is this an extension field? - int number() const; // Declared tag number. - - // Same as name() except converted to lower-case. This (and especially the - // FindFieldByLowercaseName() method) can be useful when parsing formats - // which prefer to use lowercase naming style. (Although, technically - // field names should be lowercased anyway according to the protobuf style - // guide, so this only makes a difference when dealing with old .proto files - // which do not follow the guide.) - const string& lowercase_name() const; - - // Same as name() except converted to camel-case. In this conversion, any - // time an underscore appears in the name, it is removed and the next - // letter is capitalized. Furthermore, the first letter of the name is - // lower-cased. Examples: - // FooBar -> fooBar - // foo_bar -> fooBar - // fooBar -> fooBar - // This (and especially the FindFieldByCamelcaseName() method) can be useful - // when parsing formats which prefer to use camel-case naming style. - const string& camelcase_name() const; - - Type type() const; // Declared type of this field. - CppType cpp_type() const; // C++ type of this field. - Label label() const; // optional/required/repeated - - bool is_required() const; // shorthand for label() == LABEL_REQUIRED - bool is_optional() const; // shorthand for label() == LABEL_OPTIONAL - bool is_repeated() const; // shorthand for label() == LABEL_REPEATED - bool is_packable() const; // shorthand for is_repeated() && - // IsTypePackable(type()) - - // Index of this field within the message's field array, or the file or - // extension scope's extensions array. - int index() const; - - // Does this field have an explicitly-declared default value? - bool has_default_value() const; - - // Get the field default value if cpp_type() == CPPTYPE_INT32. If no - // explicit default was defined, the default is 0. - int32 default_value_int32() const; - // Get the field default value if cpp_type() == CPPTYPE_INT64. If no - // explicit default was defined, the default is 0. - int64 default_value_int64() const; - // Get the field default value if cpp_type() == CPPTYPE_UINT32. If no - // explicit default was defined, the default is 0. - uint32 default_value_uint32() const; - // Get the field default value if cpp_type() == CPPTYPE_UINT64. If no - // explicit default was defined, the default is 0. - uint64 default_value_uint64() const; - // Get the field default value if cpp_type() == CPPTYPE_FLOAT. If no - // explicit default was defined, the default is 0.0. - float default_value_float() const; - // Get the field default value if cpp_type() == CPPTYPE_DOUBLE. If no - // explicit default was defined, the default is 0.0. - double default_value_double() const; - // Get the field default value if cpp_type() == CPPTYPE_BOOL. If no - // explicit default was defined, the default is false. - bool default_value_bool() const; - // Get the field default value if cpp_type() == CPPTYPE_ENUM. If no - // explicit default was defined, the default is the first value defined - // in the enum type (all enum types are required to have at least one value). - // This never returns NULL. - const EnumValueDescriptor* default_value_enum() const; - // Get the field default value if cpp_type() == CPPTYPE_STRING. If no - // explicit default was defined, the default is the empty string. - const string& default_value_string() const; - - // The Descriptor for the message of which this is a field. For extensions, - // this is the extended type. Never NULL. - const Descriptor* containing_type() const; - - // An extension may be declared within the scope of another message. If this - // field is an extension (is_extension() is true), then extension_scope() - // returns that message, or NULL if the extension was declared at global - // scope. If this is not an extension, extension_scope() is undefined (may - // assert-fail). - const Descriptor* extension_scope() const; - - // If type is TYPE_MESSAGE or TYPE_GROUP, returns a descriptor for the - // message or the group type. Otherwise, undefined. - const Descriptor* message_type() const; - // If type is TYPE_ENUM, returns a descriptor for the enum. Otherwise, - // undefined. - const EnumDescriptor* enum_type() const; - - // EXPERIMENTAL; DO NOT USE. - // If this field is a map field, experimental_map_key() is the field - // that is the key for this map. - // experimental_map_key()->containing_type() is the same as message_type(). - const FieldDescriptor* experimental_map_key() const; - - // Get the FieldOptions for this field. This includes things listed in - // square brackets after the field definition. E.g., the field: - // optional string text = 1 [ctype=CORD]; - // has the "ctype" option set. Allowed options are defined by FieldOptions - // in google/protobuf/descriptor.proto, and any available extensions of that - // message. - const FieldOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(FieldDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // Helper method to get the CppType for a particular Type. - static CppType TypeToCppType(Type type); - - // Return true iff [packed = true] is valid for fields of this type. - static inline bool IsTypePackable(Type field_type); - - private: - typedef FieldOptions OptionsType; - - // See Descriptor::DebugString(). - void DebugString(int depth, string *contents) const; - - // formats the default value appropriately and returns it as a string. - // Must have a default value to call this. If quote_string_type is true, then - // types of CPPTYPE_STRING whill be surrounded by quotes and CEscaped. - string DefaultValueAsString(bool quote_string_type) const; - - const string* name_; - const string* full_name_; - const string* lowercase_name_; - const string* camelcase_name_; - const FileDescriptor* file_; - int number_; - Type type_; - Label label_; - bool is_extension_; - const Descriptor* containing_type_; - const Descriptor* extension_scope_; - const Descriptor* message_type_; - const EnumDescriptor* enum_type_; - const FieldDescriptor* experimental_map_key_; - const FieldOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - bool has_default_value_; - union { - int32 default_value_int32_; - int64 default_value_int64_; - uint32 default_value_uint32_; - uint64 default_value_uint64_; - float default_value_float_; - double default_value_double_; - bool default_value_bool_; - - const EnumValueDescriptor* default_value_enum_; - const string* default_value_string_; - }; - - static const CppType kTypeToCppTypeMap[MAX_TYPE + 1]; - - static const char * const kTypeToName[MAX_TYPE + 1]; - - static const char * const kLabelToName[MAX_LABEL + 1]; - - // Must be constructed using DescriptorPool. - FieldDescriptor() {} - friend class DescriptorBuilder; - friend class FileDescriptor; - friend class Descriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor); -}; - -// Describes an enum type defined in a .proto file. To get the EnumDescriptor -// for a generated enum type, call TypeName_descriptor(). Use DescriptorPool -// to construct your own descriptors. -class LIBPROTOBUF_EXPORT EnumDescriptor { - public: - // The name of this enum type in the containing scope. - const string& name() const; - - // The fully-qualified name of the enum type, scope delimited by periods. - const string& full_name() const; - - // Index of this enum within the file or containing message's enum array. - int index() const; - - // The .proto file in which this enum type was defined. Never NULL. - const FileDescriptor* file() const; - - // The number of values for this EnumDescriptor. Guaranteed to be greater - // than zero. - int value_count() const; - // Gets a value by index, where 0 <= index < value_count(). - // These are returned in the order they were defined in the .proto file. - const EnumValueDescriptor* value(int index) const; - - // Looks up a value by name. Returns NULL if no such value exists. - const EnumValueDescriptor* FindValueByName(const string& name) const; - // Looks up a value by number. Returns NULL if no such value exists. If - // multiple values have this number, the first one defined is returned. - const EnumValueDescriptor* FindValueByNumber(int number) const; - - // If this enum type is nested in a message type, this is that message type. - // Otherwise, NULL. - const Descriptor* containing_type() const; - - // Get options for this enum type. These are specified in the .proto file by - // placing lines like "option foo = 1234;" in the enum definition. Allowed - // options are defined by EnumOptions in google/protobuf/descriptor.proto, - // and any available extensions of that message. - const EnumOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(EnumDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - private: - typedef EnumOptions OptionsType; - - // See Descriptor::DebugString(). - void DebugString(int depth, string *contents) const; - - const string* name_; - const string* full_name_; - const FileDescriptor* file_; - const Descriptor* containing_type_; - const EnumOptions* options_; - - // True if this is a placeholder for an unknown type. - bool is_placeholder_; - // True if this is a placeholder and the type name wasn't fully-qualified. - bool is_unqualified_placeholder_; - - int value_count_; - EnumValueDescriptor* values_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - EnumDescriptor() {} - friend class DescriptorBuilder; - friend class Descriptor; - friend class FieldDescriptor; - friend class EnumValueDescriptor; - friend class FileDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor); -}; - -// Describes an individual enum constant of a particular type. To get the -// EnumValueDescriptor for a given enum value, first get the EnumDescriptor -// for its type, then use EnumDescriptor::FindValueByName() or -// EnumDescriptor::FindValueByNumber(). Use DescriptorPool to construct -// your own descriptors. -class LIBPROTOBUF_EXPORT EnumValueDescriptor { - public: - const string& name() const; // Name of this enum constant. - int index() const; // Index within the enums's Descriptor. - int number() const; // Numeric value of this enum constant. - - // The full_name of an enum value is a sibling symbol of the enum type. - // e.g. the full name of FieldDescriptorProto::TYPE_INT32 is actually - // "google.protobuf.FieldDescriptorProto.TYPE_INT32", NOT - // "google.protobuf.FieldDescriptorProto.Type.TYPE_INT32". This is to conform - // with C++ scoping rules for enums. - const string& full_name() const; - - // The type of this value. Never NULL. - const EnumDescriptor* type() const; - - // Get options for this enum value. These are specified in the .proto file - // by adding text like "[foo = 1234]" after an enum value definition. - // Allowed options are defined by EnumValueOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const EnumValueOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(EnumValueDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - private: - typedef EnumValueOptions OptionsType; - - // See Descriptor::DebugString(). - void DebugString(int depth, string *contents) const; - - const string* name_; - const string* full_name_; - int number_; - const EnumDescriptor* type_; - const EnumValueOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() - // in descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - EnumValueDescriptor() {} - friend class DescriptorBuilder; - friend class EnumDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor); -}; - -// Describes an RPC service. To get the ServiceDescriptor for a service, -// call Service::GetDescriptor(). Generated service classes also have a -// static method called descriptor() which returns the type's -// ServiceDescriptor. Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT ServiceDescriptor { - public: - // The name of the service, not including its containing scope. - const string& name() const; - // The fully-qualified name of the service, scope delimited by periods. - const string& full_name() const; - // Index of this service within the file's services array. - int index() const; - - // The .proto file in which this service was defined. Never NULL. - const FileDescriptor* file() const; - - // Get options for this service type. These are specified in the .proto file - // by placing lines like "option foo = 1234;" in the service definition. - // Allowed options are defined by ServiceOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const ServiceOptions& options() const; - - // The number of methods this service defines. - int method_count() const; - // Gets a MethodDescriptor by index, where 0 <= index < method_count(). - // These are returned in the order they were defined in the .proto file. - const MethodDescriptor* method(int index) const; - - // Look up a MethodDescriptor by name. - const MethodDescriptor* FindMethodByName(const string& name) const; - - // See Descriptor::CopyTo(). - void CopyTo(ServiceDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - private: - typedef ServiceOptions OptionsType; - - // See Descriptor::DebugString(). - void DebugString(string *contents) const; - - const string* name_; - const string* full_name_; - const FileDescriptor* file_; - const ServiceOptions* options_; - int method_count_; - MethodDescriptor* methods_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - ServiceDescriptor() {} - friend class DescriptorBuilder; - friend class FileDescriptor; - friend class MethodDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor); -}; - -// Describes an individual service method. To obtain a MethodDescriptor given -// a service, first get its ServiceDescriptor, then call -// ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your -// own descriptors. -class LIBPROTOBUF_EXPORT MethodDescriptor { - public: - // Name of this method, not including containing scope. - const string& name() const; - // The fully-qualified name of the method, scope delimited by periods. - const string& full_name() const; - // Index within the service's Descriptor. - int index() const; - - // Gets the service to which this method belongs. Never NULL. - const ServiceDescriptor* service() const; - - // Gets the type of protocol message which this method accepts as input. - const Descriptor* input_type() const; - // Gets the type of protocol message which this message produces as output. - const Descriptor* output_type() const; - - // Get options for this method. These are specified in the .proto file by - // placing lines like "option foo = 1234;" in curly-braces after a method - // declaration. Allowed options are defined by MethodOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const MethodOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(MethodDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - private: - typedef MethodOptions OptionsType; - - // See Descriptor::DebugString(). - void DebugString(int depth, string *contents) const; - - const string* name_; - const string* full_name_; - const ServiceDescriptor* service_; - const Descriptor* input_type_; - const Descriptor* output_type_; - const MethodOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - MethodDescriptor() {} - friend class DescriptorBuilder; - friend class ServiceDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MethodDescriptor); -}; - -// Describes a whole .proto file. To get the FileDescriptor for a compiled-in -// file, get the descriptor for something defined in that file and call -// descriptor->file(). Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT FileDescriptor { - public: - // The filename, relative to the source tree. - // e.g. "google/protobuf/descriptor.proto" - const string& name() const; - - // The package, e.g. "google.protobuf.compiler". - const string& package() const; - - // The DescriptorPool in which this FileDescriptor and all its contents were - // allocated. Never NULL. - const DescriptorPool* pool() const; - - // The number of files imported by this one. - int dependency_count() const; - // Gets an imported file by index, where 0 <= index < dependency_count(). - // These are returned in the order they were defined in the .proto file. - const FileDescriptor* dependency(int index) const; - - // Number of top-level message types defined in this file. (This does not - // include nested types.) - int message_type_count() const; - // Gets a top-level message type, where 0 <= index < message_type_count(). - // These are returned in the order they were defined in the .proto file. - const Descriptor* message_type(int index) const; - - // Number of top-level enum types defined in this file. (This does not - // include nested types.) - int enum_type_count() const; - // Gets a top-level enum type, where 0 <= index < enum_type_count(). - // These are returned in the order they were defined in the .proto file. - const EnumDescriptor* enum_type(int index) const; - - // Number of services defined in this file. - int service_count() const; - // Gets a service, where 0 <= index < service_count(). - // These are returned in the order they were defined in the .proto file. - const ServiceDescriptor* service(int index) const; - - // Number of extensions defined at file scope. (This does not include - // extensions nested within message types.) - int extension_count() const; - // Gets an extension's descriptor, where 0 <= index < extension_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* extension(int index) const; - - // Get options for this file. These are specified in the .proto file by - // placing lines like "option foo = 1234;" at the top level, outside of any - // other definitions. Allowed options are defined by FileOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const FileOptions& options() const; - - // Find a top-level message type by name. Returns NULL if not found. - const Descriptor* FindMessageTypeByName(const string& name) const; - // Find a top-level enum type by name. Returns NULL if not found. - const EnumDescriptor* FindEnumTypeByName(const string& name) const; - // Find an enum value defined in any top-level enum by name. Returns NULL if - // not found. - const EnumValueDescriptor* FindEnumValueByName(const string& name) const; - // Find a service definition by name. Returns NULL if not found. - const ServiceDescriptor* FindServiceByName(const string& name) const; - // Find a top-level extension definition by name. Returns NULL if not found. - const FieldDescriptor* FindExtensionByName(const string& name) const; - // Similar to FindExtensionByName(), but searches by lowercased-name. See - // Descriptor::FindFieldByLowercaseName(). - const FieldDescriptor* FindExtensionByLowercaseName(const string& name) const; - // Similar to FindExtensionByName(), but searches by camelcased-name. See - // Descriptor::FindFieldByCamelcaseName(). - const FieldDescriptor* FindExtensionByCamelcaseName(const string& name) const; - - // See Descriptor::CopyTo(). - void CopyTo(FileDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - private: - typedef FileOptions OptionsType; - - const string* name_; - const string* package_; - const DescriptorPool* pool_; - int dependency_count_; - const FileDescriptor** dependencies_; - int message_type_count_; - Descriptor* message_types_; - int enum_type_count_; - EnumDescriptor* enum_types_; - int service_count_; - ServiceDescriptor* services_; - int extension_count_; - FieldDescriptor* extensions_; - const FileOptions* options_; - - const FileDescriptorTables* tables_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - FileDescriptor() {} - friend class DescriptorBuilder; - friend class Descriptor; - friend class FieldDescriptor; - friend class EnumDescriptor; - friend class ServiceDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor); -}; - -// =================================================================== - -// Used to construct descriptors. -// -// Normally you won't want to build your own descriptors. Message classes -// constructed by the protocol compiler will provide them for you. However, -// if you are implementing Message on your own, or if you are writing a -// program which can operate on totally arbitrary types and needs to load -// them from some sort of database, you might need to. -// -// Since Descriptors are composed of a whole lot of cross-linked bits of -// data that would be a pain to put together manually, the -// DescriptorPool class is provided to make the process easier. It can -// take a FileDescriptorProto (defined in descriptor.proto), validate it, -// and convert it to a set of nicely cross-linked Descriptors. -// -// DescriptorPool also helps with memory management. Descriptors are -// composed of many objects containing static data and pointers to each -// other. In all likelihood, when it comes time to delete this data, -// you'll want to delete it all at once. In fact, it is not uncommon to -// have a whole pool of descriptors all cross-linked with each other which -// you wish to delete all at once. This class represents such a pool, and -// handles the memory management for you. -// -// You can also search for descriptors within a DescriptorPool by name, and -// extensions by number. -class LIBPROTOBUF_EXPORT DescriptorPool { - public: - // Create a normal, empty DescriptorPool. - DescriptorPool(); - - // Constructs a DescriptorPool that, when it can't find something among the - // descriptors already in the pool, looks for it in the given - // DescriptorDatabase. - // Notes: - // - If a DescriptorPool is constructed this way, its BuildFile*() methods - // must not be called (they will assert-fail). The only way to populate - // the pool with descriptors is to call the Find*By*() methods. - // - The Find*By*() methods may block the calling thread if the - // DescriptorDatabase blocks. This in turn means that parsing messages - // may block if they need to look up extensions. - // - The Find*By*() methods will use mutexes for thread-safety, thus making - // them slower even when they don't have to fall back to the database. - // In fact, even the Find*By*() methods of descriptor objects owned by - // this pool will be slower, since they will have to obtain locks too. - // - An ErrorCollector may optionally be given to collect validation errors - // in files loaded from the database. If not given, errors will be printed - // to GOOGLE_LOG(ERROR). Remember that files are built on-demand, so this - // ErrorCollector may be called from any thread that calls one of the - // Find*By*() methods. - class ErrorCollector; - explicit DescriptorPool(DescriptorDatabase* fallback_database, - ErrorCollector* error_collector = NULL); - - ~DescriptorPool(); - - // Get a pointer to the generated pool. Generated protocol message classes - // which are compiled into the binary will allocate their descriptors in - // this pool. Do not add your own descriptors to this pool. - static const DescriptorPool* generated_pool(); - - // Find a FileDescriptor in the pool by file name. Returns NULL if not - // found. - const FileDescriptor* FindFileByName(const string& name) const; - - // Find the FileDescriptor in the pool which defines the given symbol. - // If any of the Find*ByName() methods below would succeed, then this is - // equivalent to calling that method and calling the result's file() method. - // Otherwise this returns NULL. - const FileDescriptor* FindFileContainingSymbol( - const string& symbol_name) const; - - // Looking up descriptors ------------------------------------------ - // These find descriptors by fully-qualified name. These will find both - // top-level descriptors and nested descriptors. They return NULL if not - // found. - - const Descriptor* FindMessageTypeByName(const string& name) const; - const FieldDescriptor* FindFieldByName(const string& name) const; - const FieldDescriptor* FindExtensionByName(const string& name) const; - const EnumDescriptor* FindEnumTypeByName(const string& name) const; - const EnumValueDescriptor* FindEnumValueByName(const string& name) const; - const ServiceDescriptor* FindServiceByName(const string& name) const; - const MethodDescriptor* FindMethodByName(const string& name) const; - - // Finds an extension of the given type by number. The extendee must be - // a member of this DescriptorPool or one of its underlays. - const FieldDescriptor* FindExtensionByNumber(const Descriptor* extendee, - int number) const; - - // Finds extensions of extendee. The extensions will be appended to - // out in an undefined order. Only extensions defined directly in - // this DescriptorPool or one of its underlays are guaranteed to be - // found: extensions defined in the fallback database might not be found - // depending on the database implementation. - void FindAllExtensions(const Descriptor* extendee, - vector* out) const; - - // Building descriptors -------------------------------------------- - - // When converting a FileDescriptorProto to a FileDescriptor, various - // errors might be detected in the input. The caller may handle these - // programmatically by implementing an ErrorCollector. - class LIBPROTOBUF_EXPORT ErrorCollector { - public: - inline ErrorCollector() {} - virtual ~ErrorCollector(); - - // These constants specify what exact part of the construct is broken. - // This is useful e.g. for mapping the error back to an exact location - // in a .proto file. - enum ErrorLocation { - NAME, // the symbol name, or the package name for files - NUMBER, // field or extension range number - TYPE, // field type - EXTENDEE, // field extendee - DEFAULT_VALUE, // field default value - INPUT_TYPE, // method input type - OUTPUT_TYPE, // method output type - OPTION_NAME, // name in assignment - OPTION_VALUE, // value in option assignment - OTHER // some other problem - }; - - // Reports an error in the FileDescriptorProto. - virtual void AddError( - const string& filename, // File name in which the error occurred. - const string& element_name, // Full name of the erroneous element. - const Message* descriptor, // Descriptor of the erroneous element. - ErrorLocation location, // One of the location constants, above. - const string& message // Human-readable error message. - ) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); - }; - - // Convert the FileDescriptorProto to real descriptors and place them in - // this DescriptorPool. All dependencies of the file must already be in - // the pool. Returns the resulting FileDescriptor, or NULL if there were - // problems with the input (e.g. the message was invalid, or dependencies - // were missing). Details about the errors are written to GOOGLE_LOG(ERROR). - const FileDescriptor* BuildFile(const FileDescriptorProto& proto); - - // Same as BuildFile() except errors are sent to the given ErrorCollector. - const FileDescriptor* BuildFileCollectingErrors( - const FileDescriptorProto& proto, - ErrorCollector* error_collector); - - // By default, it is an error if a FileDescriptorProto contains references - // to types or other files that are not found in the DescriptorPool (or its - // backing DescriptorDatabase, if any). If you call - // AllowUnknownDependencies(), however, then unknown types and files - // will be replaced by placeholder descriptors. This can allow you to - // perform some useful operations with a .proto file even if you do not - // have access to other .proto files on which it depends. However, some - // heuristics must be used to fill in the gaps in information, and these - // can lead to descriptors which are inaccurate. For example, the - // DescriptorPool may be forced to guess whether an unknown type is a message - // or an enum, as well as what package it resides in. Furthermore, - // placeholder types will not be discoverable via FindMessageTypeByName() - // and similar methods, which could confuse some descriptor-based algorithms. - // Generally, the results of this option should only be relied upon for - // debugging purposes. - void AllowUnknownDependencies() { allow_unknown_ = true; } - - // Internal stuff -------------------------------------------------- - // These methods MUST NOT be called from outside the proto2 library. - // These methods may contain hidden pitfalls and may be removed in a - // future library version. - - // Create a DescriptorPool which is overlaid on top of some other pool. - // If you search for a descriptor in the overlay and it is not found, the - // underlay will be searched as a backup. If the underlay has its own - // underlay, that will be searched next, and so on. This also means that - // files built in the overlay will be cross-linked with the underlay's - // descriptors if necessary. The underlay remains property of the caller; - // it must remain valid for the lifetime of the newly-constructed pool. - // - // Example: Say you want to parse a .proto file at runtime in order to use - // its type with a DynamicMessage. Say this .proto file has dependencies, - // but you know that all the dependencies will be things that are already - // compiled into the binary. For ease of use, you'd like to load the types - // right out of generated_pool() rather than have to parse redundant copies - // of all these .protos and runtime. But, you don't want to add the parsed - // types directly into generated_pool(): this is not allowed, and would be - // bad design anyway. So, instead, you could use generated_pool() as an - // underlay for a new DescriptorPool in which you add only the new file. - // - // WARNING: Use of underlays can lead to many subtle gotchas. Instead, - // try to formulate what you want to do in terms of DescriptorDatabases. - explicit DescriptorPool(const DescriptorPool* underlay); - - // Called by generated classes at init time to add their descriptors to - // generated_pool. Do NOT call this in your own code! filename must be a - // permanent string (e.g. a string literal). - static void InternalAddGeneratedFile( - const void* encoded_file_descriptor, int size); - - - // For internal use only: Gets a non-const pointer to the generated pool. - // This is called at static-initialization time only, so thread-safety is - // not a concern. If both an underlay and a fallback database are present, - // the fallback database takes precedence. - static DescriptorPool* internal_generated_pool(); - - // For internal use only: Changes the behavior of BuildFile() such that it - // allows the file to make reference to message types declared in other files - // which it did not officially declare as dependencies. - void InternalDontEnforceDependencies(); - - // For internal use only. - void internal_set_underlay(const DescriptorPool* underlay) { - underlay_ = underlay; - } - - // For internal (unit test) use only: Returns true if a FileDescriptor has - // been constructed for the given file, false otherwise. Useful for testing - // lazy descriptor initialization behavior. - bool InternalIsFileLoaded(const string& filename) const; - - private: - friend class Descriptor; - friend class FieldDescriptor; - friend class EnumDescriptor; - friend class ServiceDescriptor; - friend class FileDescriptor; - friend class DescriptorBuilder; - - // Tries to find something in the fallback database and link in the - // corresponding proto file. Returns true if successful, in which case - // the caller should search for the thing again. These are declared - // const because they are called by (semantically) const methods. - bool TryFindFileInFallbackDatabase(const string& name) const; - bool TryFindSymbolInFallbackDatabase(const string& name) const; - bool TryFindExtensionInFallbackDatabase(const Descriptor* containing_type, - int field_number) const; - - // Like BuildFile() but called internally when the file has been loaded from - // fallback_database_. Declared const because it is called by (semantically) - // const methods. - const FileDescriptor* BuildFileFromDatabase( - const FileDescriptorProto& proto) const; - - // If fallback_database_ is NULL, this is NULL. Otherwise, this is a mutex - // which must be locked while accessing tables_. - Mutex* mutex_; - - // See constructor. - DescriptorDatabase* fallback_database_; - ErrorCollector* default_error_collector_; - const DescriptorPool* underlay_; - - // This class contains a lot of hash maps with complicated types that - // we'd like to keep out of the header. - class Tables; - scoped_ptr tables_; - - bool enforce_dependencies_; - bool allow_unknown_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool); -}; - -// inline methods ==================================================== - -// These macros makes this repetitive code more readable. -#define PROTOBUF_DEFINE_ACCESSOR(CLASS, FIELD, TYPE) \ - inline TYPE CLASS::FIELD() const { return FIELD##_; } - -// Strings fields are stored as pointers but returned as const references. -#define PROTOBUF_DEFINE_STRING_ACCESSOR(CLASS, FIELD) \ - inline const string& CLASS::FIELD() const { return *FIELD##_; } - -// Arrays take an index parameter, obviously. -#define PROTOBUF_DEFINE_ARRAY_ACCESSOR(CLASS, FIELD, TYPE) \ - inline TYPE CLASS::FIELD(int index) const { return FIELD##s_ + index; } - -#define PROTOBUF_DEFINE_OPTIONS_ACCESSOR(CLASS, TYPE) \ - inline const TYPE& CLASS::options() const { return *options_; } - -PROTOBUF_DEFINE_STRING_ACCESSOR(Descriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(Descriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, containing_type, const Descriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, field_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, nested_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, enum_type_count, int) - -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, field, const FieldDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, nested_type, const Descriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, enum_type, const EnumDescriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_range_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension_range, - const Descriptor::ExtensionRange*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension, - const FieldDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(Descriptor, MessageOptions); - -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, full_name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, lowercase_name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, camelcase_name) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, type, FieldDescriptor::Type) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, label, FieldDescriptor::Label) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, experimental_map_key, - const FieldDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions); -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32 , int32 ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64 , int64 ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32, uint32) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64, uint64) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float , float ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool , bool ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_enum, - const EnumValueDescriptor*) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string) - -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, value_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value, - const EnumValueDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions); - -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, number, int) -PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, type, const EnumDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumValueDescriptor, EnumValueOptions); - -PROTOBUF_DEFINE_STRING_ACCESSOR(ServiceDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(ServiceDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, method_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(ServiceDescriptor, method, - const MethodDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(ServiceDescriptor, ServiceOptions); - -PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, service, const ServiceDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, input_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, output_type, const Descriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(MethodDescriptor, MethodOptions); - -PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, package) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, pool, const DescriptorPool*) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, dependency_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, message_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, enum_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, service_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, extension_count, int) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FileDescriptor, FileOptions); - -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, message_type, const Descriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, enum_type, const EnumDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, service, - const ServiceDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, extension, - const FieldDescriptor*) - -#undef PROTOBUF_DEFINE_ACCESSOR -#undef PROTOBUF_DEFINE_STRING_ACCESSOR -#undef PROTOBUF_DEFINE_ARRAY_ACCESSOR - -// A few accessors differ from the macros... - -inline bool FieldDescriptor::is_required() const { - return label() == LABEL_REQUIRED; -} - -inline bool FieldDescriptor::is_optional() const { - return label() == LABEL_OPTIONAL; -} - -inline bool FieldDescriptor::is_repeated() const { - return label() == LABEL_REPEATED; -} - -inline bool FieldDescriptor::is_packable() const { - return is_repeated() && IsTypePackable(type()); -} - -// To save space, index() is computed by looking at the descriptor's position -// in the parent's array of children. -inline int FieldDescriptor::index() const { - if (!is_extension_) { - return this - containing_type_->fields_; - } else if (extension_scope_ != NULL) { - return this - extension_scope_->extensions_; - } else { - return this - file_->extensions_; - } -} - -inline int Descriptor::index() const { - if (containing_type_ == NULL) { - return this - file_->message_types_; - } else { - return this - containing_type_->nested_types_; - } -} - -inline int EnumDescriptor::index() const { - if (containing_type_ == NULL) { - return this - file_->enum_types_; - } else { - return this - containing_type_->enum_types_; - } -} - -inline int EnumValueDescriptor::index() const { - return this - type_->values_; -} - -inline int ServiceDescriptor::index() const { - return this - file_->services_; -} - -inline int MethodDescriptor::index() const { - return this - service_->methods_; -} - -inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const { - return kTypeToCppTypeMap[type_]; -} - -inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) { - return kTypeToCppTypeMap[type]; -} - -inline bool FieldDescriptor::IsTypePackable(Type field_type) { - return (field_type != FieldDescriptor::TYPE_STRING && - field_type != FieldDescriptor::TYPE_GROUP && - field_type != FieldDescriptor::TYPE_MESSAGE && - field_type != FieldDescriptor::TYPE_BYTES); -} - -inline const FileDescriptor* FileDescriptor::dependency(int index) const { - return dependencies_[index]; -} - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_DESCRIPTOR_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h deleted file mode 100644 index 95febb81..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +++ /dev/null @@ -1,5223 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/descriptor.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - -class FileDescriptorSet; -class FileDescriptorProto; -class DescriptorProto; -class DescriptorProto_ExtensionRange; -class FieldDescriptorProto; -class EnumDescriptorProto; -class EnumValueDescriptorProto; -class ServiceDescriptorProto; -class MethodDescriptorProto; -class FileOptions; -class MessageOptions; -class FieldOptions; -class EnumOptions; -class EnumValueOptions; -class ServiceOptions; -class MethodOptions; -class UninterpretedOption; -class UninterpretedOption_NamePart; -class SourceCodeInfo; -class SourceCodeInfo_Location; - -enum FieldDescriptorProto_Type { - FieldDescriptorProto_Type_TYPE_DOUBLE = 1, - FieldDescriptorProto_Type_TYPE_FLOAT = 2, - FieldDescriptorProto_Type_TYPE_INT64 = 3, - FieldDescriptorProto_Type_TYPE_UINT64 = 4, - FieldDescriptorProto_Type_TYPE_INT32 = 5, - FieldDescriptorProto_Type_TYPE_FIXED64 = 6, - FieldDescriptorProto_Type_TYPE_FIXED32 = 7, - FieldDescriptorProto_Type_TYPE_BOOL = 8, - FieldDescriptorProto_Type_TYPE_STRING = 9, - FieldDescriptorProto_Type_TYPE_GROUP = 10, - FieldDescriptorProto_Type_TYPE_MESSAGE = 11, - FieldDescriptorProto_Type_TYPE_BYTES = 12, - FieldDescriptorProto_Type_TYPE_UINT32 = 13, - FieldDescriptorProto_Type_TYPE_ENUM = 14, - FieldDescriptorProto_Type_TYPE_SFIXED32 = 15, - FieldDescriptorProto_Type_TYPE_SFIXED64 = 16, - FieldDescriptorProto_Type_TYPE_SINT32 = 17, - FieldDescriptorProto_Type_TYPE_SINT64 = 18 -}; -LIBPROTOBUF_EXPORT bool FieldDescriptorProto_Type_IsValid(int value); -const FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MIN = FieldDescriptorProto_Type_TYPE_DOUBLE; -const FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MAX = FieldDescriptorProto_Type_TYPE_SINT64; -const int FieldDescriptorProto_Type_Type_ARRAYSIZE = FieldDescriptorProto_Type_Type_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Type_descriptor(); -inline const ::std::string& FieldDescriptorProto_Type_Name(FieldDescriptorProto_Type value) { - return ::google::protobuf::internal::NameOfEnum( - FieldDescriptorProto_Type_descriptor(), value); -} -inline bool FieldDescriptorProto_Type_Parse( - const ::std::string& name, FieldDescriptorProto_Type* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FieldDescriptorProto_Type_descriptor(), name, value); -} -enum FieldDescriptorProto_Label { - FieldDescriptorProto_Label_LABEL_OPTIONAL = 1, - FieldDescriptorProto_Label_LABEL_REQUIRED = 2, - FieldDescriptorProto_Label_LABEL_REPEATED = 3 -}; -LIBPROTOBUF_EXPORT bool FieldDescriptorProto_Label_IsValid(int value); -const FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MIN = FieldDescriptorProto_Label_LABEL_OPTIONAL; -const FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MAX = FieldDescriptorProto_Label_LABEL_REPEATED; -const int FieldDescriptorProto_Label_Label_ARRAYSIZE = FieldDescriptorProto_Label_Label_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Label_descriptor(); -inline const ::std::string& FieldDescriptorProto_Label_Name(FieldDescriptorProto_Label value) { - return ::google::protobuf::internal::NameOfEnum( - FieldDescriptorProto_Label_descriptor(), value); -} -inline bool FieldDescriptorProto_Label_Parse( - const ::std::string& name, FieldDescriptorProto_Label* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FieldDescriptorProto_Label_descriptor(), name, value); -} -enum FileOptions_OptimizeMode { - FileOptions_OptimizeMode_SPEED = 1, - FileOptions_OptimizeMode_CODE_SIZE = 2, - FileOptions_OptimizeMode_LITE_RUNTIME = 3 -}; -LIBPROTOBUF_EXPORT bool FileOptions_OptimizeMode_IsValid(int value); -const FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MIN = FileOptions_OptimizeMode_SPEED; -const FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MAX = FileOptions_OptimizeMode_LITE_RUNTIME; -const int FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE = FileOptions_OptimizeMode_OptimizeMode_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FileOptions_OptimizeMode_descriptor(); -inline const ::std::string& FileOptions_OptimizeMode_Name(FileOptions_OptimizeMode value) { - return ::google::protobuf::internal::NameOfEnum( - FileOptions_OptimizeMode_descriptor(), value); -} -inline bool FileOptions_OptimizeMode_Parse( - const ::std::string& name, FileOptions_OptimizeMode* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FileOptions_OptimizeMode_descriptor(), name, value); -} -enum FieldOptions_CType { - FieldOptions_CType_STRING = 0, - FieldOptions_CType_CORD = 1, - FieldOptions_CType_STRING_PIECE = 2 -}; -LIBPROTOBUF_EXPORT bool FieldOptions_CType_IsValid(int value); -const FieldOptions_CType FieldOptions_CType_CType_MIN = FieldOptions_CType_STRING; -const FieldOptions_CType FieldOptions_CType_CType_MAX = FieldOptions_CType_STRING_PIECE; -const int FieldOptions_CType_CType_ARRAYSIZE = FieldOptions_CType_CType_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldOptions_CType_descriptor(); -inline const ::std::string& FieldOptions_CType_Name(FieldOptions_CType value) { - return ::google::protobuf::internal::NameOfEnum( - FieldOptions_CType_descriptor(), value); -} -inline bool FieldOptions_CType_Parse( - const ::std::string& name, FieldOptions_CType* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FieldOptions_CType_descriptor(), name, value); -} -// =================================================================== - -class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message { - public: - FileDescriptorSet(); - virtual ~FileDescriptorSet(); - - FileDescriptorSet(const FileDescriptorSet& from); - - inline FileDescriptorSet& operator=(const FileDescriptorSet& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FileDescriptorSet& default_instance(); - - void Swap(FileDescriptorSet* other); - - // implements Message ---------------------------------------------- - - FileDescriptorSet* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FileDescriptorSet& from); - void MergeFrom(const FileDescriptorSet& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.FileDescriptorProto file = 1; - inline int file_size() const; - inline void clear_file(); - static const int kFileFieldNumber = 1; - inline const ::google::protobuf::FileDescriptorProto& file(int index) const; - inline ::google::protobuf::FileDescriptorProto* mutable_file(int index); - inline ::google::protobuf::FileDescriptorProto* add_file(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& - file() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* - mutable_file(); - - // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorSet) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > file_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static FileDescriptorSet* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Message { - public: - FileDescriptorProto(); - virtual ~FileDescriptorProto(); - - FileDescriptorProto(const FileDescriptorProto& from); - - inline FileDescriptorProto& operator=(const FileDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FileDescriptorProto& default_instance(); - - void Swap(FileDescriptorProto* other); - - // implements Message ---------------------------------------------- - - FileDescriptorProto* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FileDescriptorProto& from); - void MergeFrom(const FileDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // optional string package = 2; - inline bool has_package() const; - inline void clear_package(); - static const int kPackageFieldNumber = 2; - inline const ::std::string& package() const; - inline void set_package(const ::std::string& value); - inline void set_package(const char* value); - inline void set_package(const char* value, size_t size); - inline ::std::string* mutable_package(); - inline ::std::string* release_package(); - - // repeated string dependency = 3; - inline int dependency_size() const; - inline void clear_dependency(); - static const int kDependencyFieldNumber = 3; - inline const ::std::string& dependency(int index) const; - inline ::std::string* mutable_dependency(int index); - inline void set_dependency(int index, const ::std::string& value); - inline void set_dependency(int index, const char* value); - inline void set_dependency(int index, const char* value, size_t size); - inline ::std::string* add_dependency(); - inline void add_dependency(const ::std::string& value); - inline void add_dependency(const char* value); - inline void add_dependency(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& dependency() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_dependency(); - - // repeated .google.protobuf.DescriptorProto message_type = 4; - inline int message_type_size() const; - inline void clear_message_type(); - static const int kMessageTypeFieldNumber = 4; - inline const ::google::protobuf::DescriptorProto& message_type(int index) const; - inline ::google::protobuf::DescriptorProto* mutable_message_type(int index); - inline ::google::protobuf::DescriptorProto* add_message_type(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& - message_type() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* - mutable_message_type(); - - // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; - inline int enum_type_size() const; - inline void clear_enum_type(); - static const int kEnumTypeFieldNumber = 5; - inline const ::google::protobuf::EnumDescriptorProto& enum_type(int index) const; - inline ::google::protobuf::EnumDescriptorProto* mutable_enum_type(int index); - inline ::google::protobuf::EnumDescriptorProto* add_enum_type(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& - enum_type() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* - mutable_enum_type(); - - // repeated .google.protobuf.ServiceDescriptorProto service = 6; - inline int service_size() const; - inline void clear_service(); - static const int kServiceFieldNumber = 6; - inline const ::google::protobuf::ServiceDescriptorProto& service(int index) const; - inline ::google::protobuf::ServiceDescriptorProto* mutable_service(int index); - inline ::google::protobuf::ServiceDescriptorProto* add_service(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >& - service() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >* - mutable_service(); - - // repeated .google.protobuf.FieldDescriptorProto extension = 7; - inline int extension_size() const; - inline void clear_extension(); - static const int kExtensionFieldNumber = 7; - inline const ::google::protobuf::FieldDescriptorProto& extension(int index) const; - inline ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); - inline ::google::protobuf::FieldDescriptorProto* add_extension(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& - extension() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* - mutable_extension(); - - // optional .google.protobuf.FileOptions options = 8; - inline bool has_options() const; - inline void clear_options(); - static const int kOptionsFieldNumber = 8; - inline const ::google::protobuf::FileOptions& options() const; - inline ::google::protobuf::FileOptions* mutable_options(); - inline ::google::protobuf::FileOptions* release_options(); - - // optional .google.protobuf.SourceCodeInfo source_code_info = 9; - inline bool has_source_code_info() const; - inline void clear_source_code_info(); - static const int kSourceCodeInfoFieldNumber = 9; - inline const ::google::protobuf::SourceCodeInfo& source_code_info() const; - inline ::google::protobuf::SourceCodeInfo* mutable_source_code_info(); - inline ::google::protobuf::SourceCodeInfo* release_source_code_info(); - - // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_package(); - inline void clear_has_package(); - inline void set_has_options(); - inline void clear_has_options(); - inline void set_has_source_code_info(); - inline void clear_has_source_code_info(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::std::string* package_; - ::google::protobuf::RepeatedPtrField< ::std::string> dependency_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > message_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto > service_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; - ::google::protobuf::FileOptions* options_; - ::google::protobuf::SourceCodeInfo* source_code_info_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(9 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static FileDescriptorProto* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::protobuf::Message { - public: - DescriptorProto_ExtensionRange(); - virtual ~DescriptorProto_ExtensionRange(); - - DescriptorProto_ExtensionRange(const DescriptorProto_ExtensionRange& from); - - inline DescriptorProto_ExtensionRange& operator=(const DescriptorProto_ExtensionRange& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DescriptorProto_ExtensionRange& default_instance(); - - void Swap(DescriptorProto_ExtensionRange* other); - - // implements Message ---------------------------------------------- - - DescriptorProto_ExtensionRange* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DescriptorProto_ExtensionRange& from); - void MergeFrom(const DescriptorProto_ExtensionRange& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 start = 1; - inline bool has_start() const; - inline void clear_start(); - static const int kStartFieldNumber = 1; - inline ::google::protobuf::int32 start() const; - inline void set_start(::google::protobuf::int32 value); - - // optional int32 end = 2; - inline bool has_end() const; - inline void clear_end(); - static const int kEndFieldNumber = 2; - inline ::google::protobuf::int32 end() const; - inline void set_end(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto.ExtensionRange) - private: - inline void set_has_start(); - inline void clear_has_start(); - inline void set_has_end(); - inline void clear_has_end(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 start_; - ::google::protobuf::int32 end_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static DescriptorProto_ExtensionRange* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message { - public: - DescriptorProto(); - virtual ~DescriptorProto(); - - DescriptorProto(const DescriptorProto& from); - - inline DescriptorProto& operator=(const DescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DescriptorProto& default_instance(); - - void Swap(DescriptorProto* other); - - // implements Message ---------------------------------------------- - - DescriptorProto* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DescriptorProto& from); - void MergeFrom(const DescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef DescriptorProto_ExtensionRange ExtensionRange; - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // repeated .google.protobuf.FieldDescriptorProto field = 2; - inline int field_size() const; - inline void clear_field(); - static const int kFieldFieldNumber = 2; - inline const ::google::protobuf::FieldDescriptorProto& field(int index) const; - inline ::google::protobuf::FieldDescriptorProto* mutable_field(int index); - inline ::google::protobuf::FieldDescriptorProto* add_field(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& - field() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* - mutable_field(); - - // repeated .google.protobuf.FieldDescriptorProto extension = 6; - inline int extension_size() const; - inline void clear_extension(); - static const int kExtensionFieldNumber = 6; - inline const ::google::protobuf::FieldDescriptorProto& extension(int index) const; - inline ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); - inline ::google::protobuf::FieldDescriptorProto* add_extension(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& - extension() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* - mutable_extension(); - - // repeated .google.protobuf.DescriptorProto nested_type = 3; - inline int nested_type_size() const; - inline void clear_nested_type(); - static const int kNestedTypeFieldNumber = 3; - inline const ::google::protobuf::DescriptorProto& nested_type(int index) const; - inline ::google::protobuf::DescriptorProto* mutable_nested_type(int index); - inline ::google::protobuf::DescriptorProto* add_nested_type(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& - nested_type() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* - mutable_nested_type(); - - // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; - inline int enum_type_size() const; - inline void clear_enum_type(); - static const int kEnumTypeFieldNumber = 4; - inline const ::google::protobuf::EnumDescriptorProto& enum_type(int index) const; - inline ::google::protobuf::EnumDescriptorProto* mutable_enum_type(int index); - inline ::google::protobuf::EnumDescriptorProto* add_enum_type(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& - enum_type() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* - mutable_enum_type(); - - // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; - inline int extension_range_size() const; - inline void clear_extension_range(); - static const int kExtensionRangeFieldNumber = 5; - inline const ::google::protobuf::DescriptorProto_ExtensionRange& extension_range(int index) const; - inline ::google::protobuf::DescriptorProto_ExtensionRange* mutable_extension_range(int index); - inline ::google::protobuf::DescriptorProto_ExtensionRange* add_extension_range(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >& - extension_range() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >* - mutable_extension_range(); - - // optional .google.protobuf.MessageOptions options = 7; - inline bool has_options() const; - inline void clear_options(); - static const int kOptionsFieldNumber = 7; - inline const ::google::protobuf::MessageOptions& options() const; - inline ::google::protobuf::MessageOptions* mutable_options(); - inline ::google::protobuf::MessageOptions* release_options(); - - // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > field_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > nested_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange > extension_range_; - ::google::protobuf::MessageOptions* options_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(7 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static DescriptorProto* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Message { - public: - FieldDescriptorProto(); - virtual ~FieldDescriptorProto(); - - FieldDescriptorProto(const FieldDescriptorProto& from); - - inline FieldDescriptorProto& operator=(const FieldDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FieldDescriptorProto& default_instance(); - - void Swap(FieldDescriptorProto* other); - - // implements Message ---------------------------------------------- - - FieldDescriptorProto* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FieldDescriptorProto& from); - void MergeFrom(const FieldDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef FieldDescriptorProto_Type Type; - static const Type TYPE_DOUBLE = FieldDescriptorProto_Type_TYPE_DOUBLE; - static const Type TYPE_FLOAT = FieldDescriptorProto_Type_TYPE_FLOAT; - static const Type TYPE_INT64 = FieldDescriptorProto_Type_TYPE_INT64; - static const Type TYPE_UINT64 = FieldDescriptorProto_Type_TYPE_UINT64; - static const Type TYPE_INT32 = FieldDescriptorProto_Type_TYPE_INT32; - static const Type TYPE_FIXED64 = FieldDescriptorProto_Type_TYPE_FIXED64; - static const Type TYPE_FIXED32 = FieldDescriptorProto_Type_TYPE_FIXED32; - static const Type TYPE_BOOL = FieldDescriptorProto_Type_TYPE_BOOL; - static const Type TYPE_STRING = FieldDescriptorProto_Type_TYPE_STRING; - static const Type TYPE_GROUP = FieldDescriptorProto_Type_TYPE_GROUP; - static const Type TYPE_MESSAGE = FieldDescriptorProto_Type_TYPE_MESSAGE; - static const Type TYPE_BYTES = FieldDescriptorProto_Type_TYPE_BYTES; - static const Type TYPE_UINT32 = FieldDescriptorProto_Type_TYPE_UINT32; - static const Type TYPE_ENUM = FieldDescriptorProto_Type_TYPE_ENUM; - static const Type TYPE_SFIXED32 = FieldDescriptorProto_Type_TYPE_SFIXED32; - static const Type TYPE_SFIXED64 = FieldDescriptorProto_Type_TYPE_SFIXED64; - static const Type TYPE_SINT32 = FieldDescriptorProto_Type_TYPE_SINT32; - static const Type TYPE_SINT64 = FieldDescriptorProto_Type_TYPE_SINT64; - static inline bool Type_IsValid(int value) { - return FieldDescriptorProto_Type_IsValid(value); - } - static const Type Type_MIN = - FieldDescriptorProto_Type_Type_MIN; - static const Type Type_MAX = - FieldDescriptorProto_Type_Type_MAX; - static const int Type_ARRAYSIZE = - FieldDescriptorProto_Type_Type_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - Type_descriptor() { - return FieldDescriptorProto_Type_descriptor(); - } - static inline const ::std::string& Type_Name(Type value) { - return FieldDescriptorProto_Type_Name(value); - } - static inline bool Type_Parse(const ::std::string& name, - Type* value) { - return FieldDescriptorProto_Type_Parse(name, value); - } - - typedef FieldDescriptorProto_Label Label; - static const Label LABEL_OPTIONAL = FieldDescriptorProto_Label_LABEL_OPTIONAL; - static const Label LABEL_REQUIRED = FieldDescriptorProto_Label_LABEL_REQUIRED; - static const Label LABEL_REPEATED = FieldDescriptorProto_Label_LABEL_REPEATED; - static inline bool Label_IsValid(int value) { - return FieldDescriptorProto_Label_IsValid(value); - } - static const Label Label_MIN = - FieldDescriptorProto_Label_Label_MIN; - static const Label Label_MAX = - FieldDescriptorProto_Label_Label_MAX; - static const int Label_ARRAYSIZE = - FieldDescriptorProto_Label_Label_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - Label_descriptor() { - return FieldDescriptorProto_Label_descriptor(); - } - static inline const ::std::string& Label_Name(Label value) { - return FieldDescriptorProto_Label_Name(value); - } - static inline bool Label_Parse(const ::std::string& name, - Label* value) { - return FieldDescriptorProto_Label_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // optional int32 number = 3; - inline bool has_number() const; - inline void clear_number(); - static const int kNumberFieldNumber = 3; - inline ::google::protobuf::int32 number() const; - inline void set_number(::google::protobuf::int32 value); - - // optional .google.protobuf.FieldDescriptorProto.Label label = 4; - inline bool has_label() const; - inline void clear_label(); - static const int kLabelFieldNumber = 4; - inline ::google::protobuf::FieldDescriptorProto_Label label() const; - inline void set_label(::google::protobuf::FieldDescriptorProto_Label value); - - // optional .google.protobuf.FieldDescriptorProto.Type type = 5; - inline bool has_type() const; - inline void clear_type(); - static const int kTypeFieldNumber = 5; - inline ::google::protobuf::FieldDescriptorProto_Type type() const; - inline void set_type(::google::protobuf::FieldDescriptorProto_Type value); - - // optional string type_name = 6; - inline bool has_type_name() const; - inline void clear_type_name(); - static const int kTypeNameFieldNumber = 6; - inline const ::std::string& type_name() const; - inline void set_type_name(const ::std::string& value); - inline void set_type_name(const char* value); - inline void set_type_name(const char* value, size_t size); - inline ::std::string* mutable_type_name(); - inline ::std::string* release_type_name(); - - // optional string extendee = 2; - inline bool has_extendee() const; - inline void clear_extendee(); - static const int kExtendeeFieldNumber = 2; - inline const ::std::string& extendee() const; - inline void set_extendee(const ::std::string& value); - inline void set_extendee(const char* value); - inline void set_extendee(const char* value, size_t size); - inline ::std::string* mutable_extendee(); - inline ::std::string* release_extendee(); - - // optional string default_value = 7; - inline bool has_default_value() const; - inline void clear_default_value(); - static const int kDefaultValueFieldNumber = 7; - inline const ::std::string& default_value() const; - inline void set_default_value(const ::std::string& value); - inline void set_default_value(const char* value); - inline void set_default_value(const char* value, size_t size); - inline ::std::string* mutable_default_value(); - inline ::std::string* release_default_value(); - - // optional .google.protobuf.FieldOptions options = 8; - inline bool has_options() const; - inline void clear_options(); - static const int kOptionsFieldNumber = 8; - inline const ::google::protobuf::FieldOptions& options() const; - inline ::google::protobuf::FieldOptions* mutable_options(); - inline ::google::protobuf::FieldOptions* release_options(); - - // @@protoc_insertion_point(class_scope:google.protobuf.FieldDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_number(); - inline void clear_has_number(); - inline void set_has_label(); - inline void clear_has_label(); - inline void set_has_type(); - inline void clear_has_type(); - inline void set_has_type_name(); - inline void clear_has_type_name(); - inline void set_has_extendee(); - inline void clear_has_extendee(); - inline void set_has_default_value(); - inline void clear_has_default_value(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::google::protobuf::int32 number_; - int label_; - ::std::string* type_name_; - ::std::string* extendee_; - ::std::string* default_value_; - ::google::protobuf::FieldOptions* options_; - int type_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(8 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static FieldDescriptorProto* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Message { - public: - EnumDescriptorProto(); - virtual ~EnumDescriptorProto(); - - EnumDescriptorProto(const EnumDescriptorProto& from); - - inline EnumDescriptorProto& operator=(const EnumDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumDescriptorProto& default_instance(); - - void Swap(EnumDescriptorProto* other); - - // implements Message ---------------------------------------------- - - EnumDescriptorProto* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumDescriptorProto& from); - void MergeFrom(const EnumDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // repeated .google.protobuf.EnumValueDescriptorProto value = 2; - inline int value_size() const; - inline void clear_value(); - static const int kValueFieldNumber = 2; - inline const ::google::protobuf::EnumValueDescriptorProto& value(int index) const; - inline ::google::protobuf::EnumValueDescriptorProto* mutable_value(int index); - inline ::google::protobuf::EnumValueDescriptorProto* add_value(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >& - value() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >* - mutable_value(); - - // optional .google.protobuf.EnumOptions options = 3; - inline bool has_options() const; - inline void clear_options(); - static const int kOptionsFieldNumber = 3; - inline const ::google::protobuf::EnumOptions& options() const; - inline ::google::protobuf::EnumOptions* mutable_options(); - inline ::google::protobuf::EnumOptions* release_options(); - - // @@protoc_insertion_point(class_scope:google.protobuf.EnumDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto > value_; - ::google::protobuf::EnumOptions* options_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static EnumDescriptorProto* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::Message { - public: - EnumValueDescriptorProto(); - virtual ~EnumValueDescriptorProto(); - - EnumValueDescriptorProto(const EnumValueDescriptorProto& from); - - inline EnumValueDescriptorProto& operator=(const EnumValueDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumValueDescriptorProto& default_instance(); - - void Swap(EnumValueDescriptorProto* other); - - // implements Message ---------------------------------------------- - - EnumValueDescriptorProto* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumValueDescriptorProto& from); - void MergeFrom(const EnumValueDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // optional int32 number = 2; - inline bool has_number() const; - inline void clear_number(); - static const int kNumberFieldNumber = 2; - inline ::google::protobuf::int32 number() const; - inline void set_number(::google::protobuf::int32 value); - - // optional .google.protobuf.EnumValueOptions options = 3; - inline bool has_options() const; - inline void clear_options(); - static const int kOptionsFieldNumber = 3; - inline const ::google::protobuf::EnumValueOptions& options() const; - inline ::google::protobuf::EnumValueOptions* mutable_options(); - inline ::google::protobuf::EnumValueOptions* release_options(); - - // @@protoc_insertion_point(class_scope:google.protobuf.EnumValueDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_number(); - inline void clear_has_number(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::google::protobuf::EnumValueOptions* options_; - ::google::protobuf::int32 number_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static EnumValueDescriptorProto* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Message { - public: - ServiceDescriptorProto(); - virtual ~ServiceDescriptorProto(); - - ServiceDescriptorProto(const ServiceDescriptorProto& from); - - inline ServiceDescriptorProto& operator=(const ServiceDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ServiceDescriptorProto& default_instance(); - - void Swap(ServiceDescriptorProto* other); - - // implements Message ---------------------------------------------- - - ServiceDescriptorProto* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ServiceDescriptorProto& from); - void MergeFrom(const ServiceDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // repeated .google.protobuf.MethodDescriptorProto method = 2; - inline int method_size() const; - inline void clear_method(); - static const int kMethodFieldNumber = 2; - inline const ::google::protobuf::MethodDescriptorProto& method(int index) const; - inline ::google::protobuf::MethodDescriptorProto* mutable_method(int index); - inline ::google::protobuf::MethodDescriptorProto* add_method(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >& - method() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >* - mutable_method(); - - // optional .google.protobuf.ServiceOptions options = 3; - inline bool has_options() const; - inline void clear_options(); - static const int kOptionsFieldNumber = 3; - inline const ::google::protobuf::ServiceOptions& options() const; - inline ::google::protobuf::ServiceOptions* mutable_options(); - inline ::google::protobuf::ServiceOptions* release_options(); - - // @@protoc_insertion_point(class_scope:google.protobuf.ServiceDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto > method_; - ::google::protobuf::ServiceOptions* options_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static ServiceDescriptorProto* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Message { - public: - MethodDescriptorProto(); - virtual ~MethodDescriptorProto(); - - MethodDescriptorProto(const MethodDescriptorProto& from); - - inline MethodDescriptorProto& operator=(const MethodDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const MethodDescriptorProto& default_instance(); - - void Swap(MethodDescriptorProto* other); - - // implements Message ---------------------------------------------- - - MethodDescriptorProto* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const MethodDescriptorProto& from); - void MergeFrom(const MethodDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline bool has_name() const; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - - // optional string input_type = 2; - inline bool has_input_type() const; - inline void clear_input_type(); - static const int kInputTypeFieldNumber = 2; - inline const ::std::string& input_type() const; - inline void set_input_type(const ::std::string& value); - inline void set_input_type(const char* value); - inline void set_input_type(const char* value, size_t size); - inline ::std::string* mutable_input_type(); - inline ::std::string* release_input_type(); - - // optional string output_type = 3; - inline bool has_output_type() const; - inline void clear_output_type(); - static const int kOutputTypeFieldNumber = 3; - inline const ::std::string& output_type() const; - inline void set_output_type(const ::std::string& value); - inline void set_output_type(const char* value); - inline void set_output_type(const char* value, size_t size); - inline ::std::string* mutable_output_type(); - inline ::std::string* release_output_type(); - - // optional .google.protobuf.MethodOptions options = 4; - inline bool has_options() const; - inline void clear_options(); - static const int kOptionsFieldNumber = 4; - inline const ::google::protobuf::MethodOptions& options() const; - inline ::google::protobuf::MethodOptions* mutable_options(); - inline ::google::protobuf::MethodOptions* release_options(); - - // @@protoc_insertion_point(class_scope:google.protobuf.MethodDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_input_type(); - inline void clear_has_input_type(); - inline void set_has_output_type(); - inline void clear_has_output_type(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_; - ::std::string* input_type_; - ::std::string* output_type_; - ::google::protobuf::MethodOptions* options_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(4 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static MethodDescriptorProto* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message { - public: - FileOptions(); - virtual ~FileOptions(); - - FileOptions(const FileOptions& from); - - inline FileOptions& operator=(const FileOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FileOptions& default_instance(); - - void Swap(FileOptions* other); - - // implements Message ---------------------------------------------- - - FileOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FileOptions& from); - void MergeFrom(const FileOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef FileOptions_OptimizeMode OptimizeMode; - static const OptimizeMode SPEED = FileOptions_OptimizeMode_SPEED; - static const OptimizeMode CODE_SIZE = FileOptions_OptimizeMode_CODE_SIZE; - static const OptimizeMode LITE_RUNTIME = FileOptions_OptimizeMode_LITE_RUNTIME; - static inline bool OptimizeMode_IsValid(int value) { - return FileOptions_OptimizeMode_IsValid(value); - } - static const OptimizeMode OptimizeMode_MIN = - FileOptions_OptimizeMode_OptimizeMode_MIN; - static const OptimizeMode OptimizeMode_MAX = - FileOptions_OptimizeMode_OptimizeMode_MAX; - static const int OptimizeMode_ARRAYSIZE = - FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - OptimizeMode_descriptor() { - return FileOptions_OptimizeMode_descriptor(); - } - static inline const ::std::string& OptimizeMode_Name(OptimizeMode value) { - return FileOptions_OptimizeMode_Name(value); - } - static inline bool OptimizeMode_Parse(const ::std::string& name, - OptimizeMode* value) { - return FileOptions_OptimizeMode_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional string java_package = 1; - inline bool has_java_package() const; - inline void clear_java_package(); - static const int kJavaPackageFieldNumber = 1; - inline const ::std::string& java_package() const; - inline void set_java_package(const ::std::string& value); - inline void set_java_package(const char* value); - inline void set_java_package(const char* value, size_t size); - inline ::std::string* mutable_java_package(); - inline ::std::string* release_java_package(); - - // optional string java_outer_classname = 8; - inline bool has_java_outer_classname() const; - inline void clear_java_outer_classname(); - static const int kJavaOuterClassnameFieldNumber = 8; - inline const ::std::string& java_outer_classname() const; - inline void set_java_outer_classname(const ::std::string& value); - inline void set_java_outer_classname(const char* value); - inline void set_java_outer_classname(const char* value, size_t size); - inline ::std::string* mutable_java_outer_classname(); - inline ::std::string* release_java_outer_classname(); - - // optional bool java_multiple_files = 10 [default = false]; - inline bool has_java_multiple_files() const; - inline void clear_java_multiple_files(); - static const int kJavaMultipleFilesFieldNumber = 10; - inline bool java_multiple_files() const; - inline void set_java_multiple_files(bool value); - - // optional bool java_generate_equals_and_hash = 20 [default = false]; - inline bool has_java_generate_equals_and_hash() const; - inline void clear_java_generate_equals_and_hash(); - static const int kJavaGenerateEqualsAndHashFieldNumber = 20; - inline bool java_generate_equals_and_hash() const; - inline void set_java_generate_equals_and_hash(bool value); - - // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - inline bool has_optimize_for() const; - inline void clear_optimize_for(); - static const int kOptimizeForFieldNumber = 9; - inline ::google::protobuf::FileOptions_OptimizeMode optimize_for() const; - inline void set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value); - - // optional bool cc_generic_services = 16 [default = false]; - inline bool has_cc_generic_services() const; - inline void clear_cc_generic_services(); - static const int kCcGenericServicesFieldNumber = 16; - inline bool cc_generic_services() const; - inline void set_cc_generic_services(bool value); - - // optional bool java_generic_services = 17 [default = false]; - inline bool has_java_generic_services() const; - inline void clear_java_generic_services(); - static const int kJavaGenericServicesFieldNumber = 17; - inline bool java_generic_services() const; - inline void set_java_generic_services(bool value); - - // optional bool py_generic_services = 18 [default = false]; - inline bool has_py_generic_services() const; - inline void clear_py_generic_services(); - static const int kPyGenericServicesFieldNumber = 18; - inline bool py_generic_services() const; - inline void set_py_generic_services(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - inline int uninterpreted_option_size() const; - inline void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FileOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.FileOptions) - private: - inline void set_has_java_package(); - inline void clear_has_java_package(); - inline void set_has_java_outer_classname(); - inline void clear_has_java_outer_classname(); - inline void set_has_java_multiple_files(); - inline void clear_has_java_multiple_files(); - inline void set_has_java_generate_equals_and_hash(); - inline void clear_has_java_generate_equals_and_hash(); - inline void set_has_optimize_for(); - inline void clear_has_optimize_for(); - inline void set_has_cc_generic_services(); - inline void clear_has_cc_generic_services(); - inline void set_has_java_generic_services(); - inline void clear_has_java_generic_services(); - inline void set_has_py_generic_services(); - inline void clear_has_py_generic_services(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* java_package_; - ::std::string* java_outer_classname_; - int optimize_for_; - bool java_multiple_files_; - bool java_generate_equals_and_hash_; - bool cc_generic_services_; - bool java_generic_services_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - bool py_generic_services_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(9 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static FileOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message { - public: - MessageOptions(); - virtual ~MessageOptions(); - - MessageOptions(const MessageOptions& from); - - inline MessageOptions& operator=(const MessageOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const MessageOptions& default_instance(); - - void Swap(MessageOptions* other); - - // implements Message ---------------------------------------------- - - MessageOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const MessageOptions& from); - void MergeFrom(const MessageOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bool message_set_wire_format = 1 [default = false]; - inline bool has_message_set_wire_format() const; - inline void clear_message_set_wire_format(); - static const int kMessageSetWireFormatFieldNumber = 1; - inline bool message_set_wire_format() const; - inline void set_message_set_wire_format(bool value); - - // optional bool no_standard_descriptor_accessor = 2 [default = false]; - inline bool has_no_standard_descriptor_accessor() const; - inline void clear_no_standard_descriptor_accessor(); - static const int kNoStandardDescriptorAccessorFieldNumber = 2; - inline bool no_standard_descriptor_accessor() const; - inline void set_no_standard_descriptor_accessor(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - inline int uninterpreted_option_size() const; - inline void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MessageOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.MessageOptions) - private: - inline void set_has_message_set_wire_format(); - inline void clear_has_message_set_wire_format(); - inline void set_has_no_standard_descriptor_accessor(); - inline void clear_has_no_standard_descriptor_accessor(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - bool message_set_wire_format_; - bool no_standard_descriptor_accessor_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static MessageOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message { - public: - FieldOptions(); - virtual ~FieldOptions(); - - FieldOptions(const FieldOptions& from); - - inline FieldOptions& operator=(const FieldOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FieldOptions& default_instance(); - - void Swap(FieldOptions* other); - - // implements Message ---------------------------------------------- - - FieldOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FieldOptions& from); - void MergeFrom(const FieldOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef FieldOptions_CType CType; - static const CType STRING = FieldOptions_CType_STRING; - static const CType CORD = FieldOptions_CType_CORD; - static const CType STRING_PIECE = FieldOptions_CType_STRING_PIECE; - static inline bool CType_IsValid(int value) { - return FieldOptions_CType_IsValid(value); - } - static const CType CType_MIN = - FieldOptions_CType_CType_MIN; - static const CType CType_MAX = - FieldOptions_CType_CType_MAX; - static const int CType_ARRAYSIZE = - FieldOptions_CType_CType_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - CType_descriptor() { - return FieldOptions_CType_descriptor(); - } - static inline const ::std::string& CType_Name(CType value) { - return FieldOptions_CType_Name(value); - } - static inline bool CType_Parse(const ::std::string& name, - CType* value) { - return FieldOptions_CType_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; - inline bool has_ctype() const; - inline void clear_ctype(); - static const int kCtypeFieldNumber = 1; - inline ::google::protobuf::FieldOptions_CType ctype() const; - inline void set_ctype(::google::protobuf::FieldOptions_CType value); - - // optional bool packed = 2; - inline bool has_packed() const; - inline void clear_packed(); - static const int kPackedFieldNumber = 2; - inline bool packed() const; - inline void set_packed(bool value); - - // optional bool deprecated = 3 [default = false]; - inline bool has_deprecated() const; - inline void clear_deprecated(); - static const int kDeprecatedFieldNumber = 3; - inline bool deprecated() const; - inline void set_deprecated(bool value); - - // optional string experimental_map_key = 9; - inline bool has_experimental_map_key() const; - inline void clear_experimental_map_key(); - static const int kExperimentalMapKeyFieldNumber = 9; - inline const ::std::string& experimental_map_key() const; - inline void set_experimental_map_key(const ::std::string& value); - inline void set_experimental_map_key(const char* value); - inline void set_experimental_map_key(const char* value, size_t size); - inline ::std::string* mutable_experimental_map_key(); - inline ::std::string* release_experimental_map_key(); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - inline int uninterpreted_option_size() const; - inline void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FieldOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.FieldOptions) - private: - inline void set_has_ctype(); - inline void clear_has_ctype(); - inline void set_has_packed(); - inline void clear_has_packed(); - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - inline void set_has_experimental_map_key(); - inline void clear_has_experimental_map_key(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - int ctype_; - bool packed_; - bool deprecated_; - ::std::string* experimental_map_key_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(5 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static FieldOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message { - public: - EnumOptions(); - virtual ~EnumOptions(); - - EnumOptions(const EnumOptions& from); - - inline EnumOptions& operator=(const EnumOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumOptions& default_instance(); - - void Swap(EnumOptions* other); - - // implements Message ---------------------------------------------- - - EnumOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumOptions& from); - void MergeFrom(const EnumOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - inline int uninterpreted_option_size() const; - inline void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.EnumOptions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static EnumOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message { - public: - EnumValueOptions(); - virtual ~EnumValueOptions(); - - EnumValueOptions(const EnumValueOptions& from); - - inline EnumValueOptions& operator=(const EnumValueOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumValueOptions& default_instance(); - - void Swap(EnumValueOptions* other); - - // implements Message ---------------------------------------------- - - EnumValueOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumValueOptions& from); - void MergeFrom(const EnumValueOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - inline int uninterpreted_option_size() const; - inline void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumValueOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.EnumValueOptions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static EnumValueOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message { - public: - ServiceOptions(); - virtual ~ServiceOptions(); - - ServiceOptions(const ServiceOptions& from); - - inline ServiceOptions& operator=(const ServiceOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ServiceOptions& default_instance(); - - void Swap(ServiceOptions* other); - - // implements Message ---------------------------------------------- - - ServiceOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ServiceOptions& from); - void MergeFrom(const ServiceOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - inline int uninterpreted_option_size() const; - inline void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ServiceOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.ServiceOptions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static ServiceOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message { - public: - MethodOptions(); - virtual ~MethodOptions(); - - MethodOptions(const MethodOptions& from); - - inline MethodOptions& operator=(const MethodOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const MethodOptions& default_instance(); - - void Swap(MethodOptions* other); - - // implements Message ---------------------------------------------- - - MethodOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const MethodOptions& from); - void MergeFrom(const MethodOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - inline int uninterpreted_option_size() const; - inline void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - inline const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - inline ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - inline ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MethodOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.MethodOptions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static MethodOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobuf::Message { - public: - UninterpretedOption_NamePart(); - virtual ~UninterpretedOption_NamePart(); - - UninterpretedOption_NamePart(const UninterpretedOption_NamePart& from); - - inline UninterpretedOption_NamePart& operator=(const UninterpretedOption_NamePart& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const UninterpretedOption_NamePart& default_instance(); - - void Swap(UninterpretedOption_NamePart* other); - - // implements Message ---------------------------------------------- - - UninterpretedOption_NamePart* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const UninterpretedOption_NamePart& from); - void MergeFrom(const UninterpretedOption_NamePart& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required string name_part = 1; - inline bool has_name_part() const; - inline void clear_name_part(); - static const int kNamePartFieldNumber = 1; - inline const ::std::string& name_part() const; - inline void set_name_part(const ::std::string& value); - inline void set_name_part(const char* value); - inline void set_name_part(const char* value, size_t size); - inline ::std::string* mutable_name_part(); - inline ::std::string* release_name_part(); - - // required bool is_extension = 2; - inline bool has_is_extension() const; - inline void clear_is_extension(); - static const int kIsExtensionFieldNumber = 2; - inline bool is_extension() const; - inline void set_is_extension(bool value); - - // @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption.NamePart) - private: - inline void set_has_name_part(); - inline void clear_has_name_part(); - inline void set_has_is_extension(); - inline void clear_has_is_extension(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* name_part_; - bool is_extension_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static UninterpretedOption_NamePart* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Message { - public: - UninterpretedOption(); - virtual ~UninterpretedOption(); - - UninterpretedOption(const UninterpretedOption& from); - - inline UninterpretedOption& operator=(const UninterpretedOption& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const UninterpretedOption& default_instance(); - - void Swap(UninterpretedOption* other); - - // implements Message ---------------------------------------------- - - UninterpretedOption* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const UninterpretedOption& from); - void MergeFrom(const UninterpretedOption& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef UninterpretedOption_NamePart NamePart; - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; - inline int name_size() const; - inline void clear_name(); - static const int kNameFieldNumber = 2; - inline const ::google::protobuf::UninterpretedOption_NamePart& name(int index) const; - inline ::google::protobuf::UninterpretedOption_NamePart* mutable_name(int index); - inline ::google::protobuf::UninterpretedOption_NamePart* add_name(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >& - name() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >* - mutable_name(); - - // optional string identifier_value = 3; - inline bool has_identifier_value() const; - inline void clear_identifier_value(); - static const int kIdentifierValueFieldNumber = 3; - inline const ::std::string& identifier_value() const; - inline void set_identifier_value(const ::std::string& value); - inline void set_identifier_value(const char* value); - inline void set_identifier_value(const char* value, size_t size); - inline ::std::string* mutable_identifier_value(); - inline ::std::string* release_identifier_value(); - - // optional uint64 positive_int_value = 4; - inline bool has_positive_int_value() const; - inline void clear_positive_int_value(); - static const int kPositiveIntValueFieldNumber = 4; - inline ::google::protobuf::uint64 positive_int_value() const; - inline void set_positive_int_value(::google::protobuf::uint64 value); - - // optional int64 negative_int_value = 5; - inline bool has_negative_int_value() const; - inline void clear_negative_int_value(); - static const int kNegativeIntValueFieldNumber = 5; - inline ::google::protobuf::int64 negative_int_value() const; - inline void set_negative_int_value(::google::protobuf::int64 value); - - // optional double double_value = 6; - inline bool has_double_value() const; - inline void clear_double_value(); - static const int kDoubleValueFieldNumber = 6; - inline double double_value() const; - inline void set_double_value(double value); - - // optional bytes string_value = 7; - inline bool has_string_value() const; - inline void clear_string_value(); - static const int kStringValueFieldNumber = 7; - inline const ::std::string& string_value() const; - inline void set_string_value(const ::std::string& value); - inline void set_string_value(const char* value); - inline void set_string_value(const void* value, size_t size); - inline ::std::string* mutable_string_value(); - inline ::std::string* release_string_value(); - - // optional string aggregate_value = 8; - inline bool has_aggregate_value() const; - inline void clear_aggregate_value(); - static const int kAggregateValueFieldNumber = 8; - inline const ::std::string& aggregate_value() const; - inline void set_aggregate_value(const ::std::string& value); - inline void set_aggregate_value(const char* value); - inline void set_aggregate_value(const char* value, size_t size); - inline ::std::string* mutable_aggregate_value(); - inline ::std::string* release_aggregate_value(); - - // @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption) - private: - inline void set_has_identifier_value(); - inline void clear_has_identifier_value(); - inline void set_has_positive_int_value(); - inline void clear_has_positive_int_value(); - inline void set_has_negative_int_value(); - inline void clear_has_negative_int_value(); - inline void set_has_double_value(); - inline void clear_has_double_value(); - inline void set_has_string_value(); - inline void clear_has_string_value(); - inline void set_has_aggregate_value(); - inline void clear_has_aggregate_value(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart > name_; - ::std::string* identifier_value_; - ::google::protobuf::uint64 positive_int_value_; - ::google::protobuf::int64 negative_int_value_; - double double_value_; - ::std::string* string_value_; - ::std::string* aggregate_value_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(7 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static UninterpretedOption* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Message { - public: - SourceCodeInfo_Location(); - virtual ~SourceCodeInfo_Location(); - - SourceCodeInfo_Location(const SourceCodeInfo_Location& from); - - inline SourceCodeInfo_Location& operator=(const SourceCodeInfo_Location& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SourceCodeInfo_Location& default_instance(); - - void Swap(SourceCodeInfo_Location* other); - - // implements Message ---------------------------------------------- - - SourceCodeInfo_Location* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SourceCodeInfo_Location& from); - void MergeFrom(const SourceCodeInfo_Location& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 path = 1 [packed = true]; - inline int path_size() const; - inline void clear_path(); - static const int kPathFieldNumber = 1; - inline ::google::protobuf::int32 path(int index) const; - inline void set_path(int index, ::google::protobuf::int32 value); - inline void add_path(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - path() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_path(); - - // repeated int32 span = 2 [packed = true]; - inline int span_size() const; - inline void clear_span(); - static const int kSpanFieldNumber = 2; - inline ::google::protobuf::int32 span(int index) const; - inline void set_span(int index, ::google::protobuf::int32 value); - inline void add_span(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - span() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_span(); - - // @@protoc_insertion_point(class_scope:google.protobuf.SourceCodeInfo.Location) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > path_; - mutable int _path_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > span_; - mutable int _span_cached_byte_size_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static SourceCodeInfo_Location* default_instance_; -}; -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message { - public: - SourceCodeInfo(); - virtual ~SourceCodeInfo(); - - SourceCodeInfo(const SourceCodeInfo& from); - - inline SourceCodeInfo& operator=(const SourceCodeInfo& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SourceCodeInfo& default_instance(); - - void Swap(SourceCodeInfo* other); - - // implements Message ---------------------------------------------- - - SourceCodeInfo* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SourceCodeInfo& from); - void MergeFrom(const SourceCodeInfo& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef SourceCodeInfo_Location Location; - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.SourceCodeInfo.Location location = 1; - inline int location_size() const; - inline void clear_location(); - static const int kLocationFieldNumber = 1; - inline const ::google::protobuf::SourceCodeInfo_Location& location(int index) const; - inline ::google::protobuf::SourceCodeInfo_Location* mutable_location(int index); - inline ::google::protobuf::SourceCodeInfo_Location* add_location(); - inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >& - location() const; - inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >* - mutable_location(); - - // @@protoc_insertion_point(class_scope:google.protobuf.SourceCodeInfo) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location > location_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); - static SourceCodeInfo* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// FileDescriptorSet - -// repeated .google.protobuf.FileDescriptorProto file = 1; -inline int FileDescriptorSet::file_size() const { - return file_.size(); -} -inline void FileDescriptorSet::clear_file() { - file_.Clear(); -} -inline const ::google::protobuf::FileDescriptorProto& FileDescriptorSet::file(int index) const { - return file_.Get(index); -} -inline ::google::protobuf::FileDescriptorProto* FileDescriptorSet::mutable_file(int index) { - return file_.Mutable(index); -} -inline ::google::protobuf::FileDescriptorProto* FileDescriptorSet::add_file() { - return file_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& -FileDescriptorSet::file() const { - return file_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* -FileDescriptorSet::mutable_file() { - return &file_; -} - -// ------------------------------------------------------------------- - -// FileDescriptorProto - -// optional string name = 1; -inline bool FileDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FileDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void FileDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FileDescriptorProto::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& FileDescriptorProto::name() const { - return *name_; -} -inline void FileDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void FileDescriptorProto::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void FileDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FileDescriptorProto::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* FileDescriptorProto::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string package = 2; -inline bool FileDescriptorProto::has_package() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FileDescriptorProto::set_has_package() { - _has_bits_[0] |= 0x00000002u; -} -inline void FileDescriptorProto::clear_has_package() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FileDescriptorProto::clear_package() { - if (package_ != &::google::protobuf::internal::kEmptyString) { - package_->clear(); - } - clear_has_package(); -} -inline const ::std::string& FileDescriptorProto::package() const { - return *package_; -} -inline void FileDescriptorProto::set_package(const ::std::string& value) { - set_has_package(); - if (package_ == &::google::protobuf::internal::kEmptyString) { - package_ = new ::std::string; - } - package_->assign(value); -} -inline void FileDescriptorProto::set_package(const char* value) { - set_has_package(); - if (package_ == &::google::protobuf::internal::kEmptyString) { - package_ = new ::std::string; - } - package_->assign(value); -} -inline void FileDescriptorProto::set_package(const char* value, size_t size) { - set_has_package(); - if (package_ == &::google::protobuf::internal::kEmptyString) { - package_ = new ::std::string; - } - package_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FileDescriptorProto::mutable_package() { - set_has_package(); - if (package_ == &::google::protobuf::internal::kEmptyString) { - package_ = new ::std::string; - } - return package_; -} -inline ::std::string* FileDescriptorProto::release_package() { - clear_has_package(); - if (package_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = package_; - package_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated string dependency = 3; -inline int FileDescriptorProto::dependency_size() const { - return dependency_.size(); -} -inline void FileDescriptorProto::clear_dependency() { - dependency_.Clear(); -} -inline const ::std::string& FileDescriptorProto::dependency(int index) const { - return dependency_.Get(index); -} -inline ::std::string* FileDescriptorProto::mutable_dependency(int index) { - return dependency_.Mutable(index); -} -inline void FileDescriptorProto::set_dependency(int index, const ::std::string& value) { - dependency_.Mutable(index)->assign(value); -} -inline void FileDescriptorProto::set_dependency(int index, const char* value) { - dependency_.Mutable(index)->assign(value); -} -inline void FileDescriptorProto::set_dependency(int index, const char* value, size_t size) { - dependency_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* FileDescriptorProto::add_dependency() { - return dependency_.Add(); -} -inline void FileDescriptorProto::add_dependency(const ::std::string& value) { - dependency_.Add()->assign(value); -} -inline void FileDescriptorProto::add_dependency(const char* value) { - dependency_.Add()->assign(value); -} -inline void FileDescriptorProto::add_dependency(const char* value, size_t size) { - dependency_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -FileDescriptorProto::dependency() const { - return dependency_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -FileDescriptorProto::mutable_dependency() { - return &dependency_; -} - -// repeated .google.protobuf.DescriptorProto message_type = 4; -inline int FileDescriptorProto::message_type_size() const { - return message_type_.size(); -} -inline void FileDescriptorProto::clear_message_type() { - message_type_.Clear(); -} -inline const ::google::protobuf::DescriptorProto& FileDescriptorProto::message_type(int index) const { - return message_type_.Get(index); -} -inline ::google::protobuf::DescriptorProto* FileDescriptorProto::mutable_message_type(int index) { - return message_type_.Mutable(index); -} -inline ::google::protobuf::DescriptorProto* FileDescriptorProto::add_message_type() { - return message_type_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& -FileDescriptorProto::message_type() const { - return message_type_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* -FileDescriptorProto::mutable_message_type() { - return &message_type_; -} - -// repeated .google.protobuf.EnumDescriptorProto enum_type = 5; -inline int FileDescriptorProto::enum_type_size() const { - return enum_type_.size(); -} -inline void FileDescriptorProto::clear_enum_type() { - enum_type_.Clear(); -} -inline const ::google::protobuf::EnumDescriptorProto& FileDescriptorProto::enum_type(int index) const { - return enum_type_.Get(index); -} -inline ::google::protobuf::EnumDescriptorProto* FileDescriptorProto::mutable_enum_type(int index) { - return enum_type_.Mutable(index); -} -inline ::google::protobuf::EnumDescriptorProto* FileDescriptorProto::add_enum_type() { - return enum_type_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& -FileDescriptorProto::enum_type() const { - return enum_type_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* -FileDescriptorProto::mutable_enum_type() { - return &enum_type_; -} - -// repeated .google.protobuf.ServiceDescriptorProto service = 6; -inline int FileDescriptorProto::service_size() const { - return service_.size(); -} -inline void FileDescriptorProto::clear_service() { - service_.Clear(); -} -inline const ::google::protobuf::ServiceDescriptorProto& FileDescriptorProto::service(int index) const { - return service_.Get(index); -} -inline ::google::protobuf::ServiceDescriptorProto* FileDescriptorProto::mutable_service(int index) { - return service_.Mutable(index); -} -inline ::google::protobuf::ServiceDescriptorProto* FileDescriptorProto::add_service() { - return service_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >& -FileDescriptorProto::service() const { - return service_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >* -FileDescriptorProto::mutable_service() { - return &service_; -} - -// repeated .google.protobuf.FieldDescriptorProto extension = 7; -inline int FileDescriptorProto::extension_size() const { - return extension_.size(); -} -inline void FileDescriptorProto::clear_extension() { - extension_.Clear(); -} -inline const ::google::protobuf::FieldDescriptorProto& FileDescriptorProto::extension(int index) const { - return extension_.Get(index); -} -inline ::google::protobuf::FieldDescriptorProto* FileDescriptorProto::mutable_extension(int index) { - return extension_.Mutable(index); -} -inline ::google::protobuf::FieldDescriptorProto* FileDescriptorProto::add_extension() { - return extension_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& -FileDescriptorProto::extension() const { - return extension_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* -FileDescriptorProto::mutable_extension() { - return &extension_; -} - -// optional .google.protobuf.FileOptions options = 8; -inline bool FileDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void FileDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000080u; -} -inline void FileDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000080u; -} -inline void FileDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::FileOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { - return options_ != NULL ? *options_ : *default_instance_->options_; -} -inline ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) options_ = new ::google::protobuf::FileOptions; - return options_; -} -inline ::google::protobuf::FileOptions* FileDescriptorProto::release_options() { - clear_has_options(); - ::google::protobuf::FileOptions* temp = options_; - options_ = NULL; - return temp; -} - -// optional .google.protobuf.SourceCodeInfo source_code_info = 9; -inline bool FileDescriptorProto::has_source_code_info() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void FileDescriptorProto::set_has_source_code_info() { - _has_bits_[0] |= 0x00000100u; -} -inline void FileDescriptorProto::clear_has_source_code_info() { - _has_bits_[0] &= ~0x00000100u; -} -inline void FileDescriptorProto::clear_source_code_info() { - if (source_code_info_ != NULL) source_code_info_->::google::protobuf::SourceCodeInfo::Clear(); - clear_has_source_code_info(); -} -inline const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { - return source_code_info_ != NULL ? *source_code_info_ : *default_instance_->source_code_info_; -} -inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { - set_has_source_code_info(); - if (source_code_info_ == NULL) source_code_info_ = new ::google::protobuf::SourceCodeInfo; - return source_code_info_; -} -inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::release_source_code_info() { - clear_has_source_code_info(); - ::google::protobuf::SourceCodeInfo* temp = source_code_info_; - source_code_info_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// DescriptorProto_ExtensionRange - -// optional int32 start = 1; -inline bool DescriptorProto_ExtensionRange::has_start() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void DescriptorProto_ExtensionRange::set_has_start() { - _has_bits_[0] |= 0x00000001u; -} -inline void DescriptorProto_ExtensionRange::clear_has_start() { - _has_bits_[0] &= ~0x00000001u; -} -inline void DescriptorProto_ExtensionRange::clear_start() { - start_ = 0; - clear_has_start(); -} -inline ::google::protobuf::int32 DescriptorProto_ExtensionRange::start() const { - return start_; -} -inline void DescriptorProto_ExtensionRange::set_start(::google::protobuf::int32 value) { - set_has_start(); - start_ = value; -} - -// optional int32 end = 2; -inline bool DescriptorProto_ExtensionRange::has_end() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void DescriptorProto_ExtensionRange::set_has_end() { - _has_bits_[0] |= 0x00000002u; -} -inline void DescriptorProto_ExtensionRange::clear_has_end() { - _has_bits_[0] &= ~0x00000002u; -} -inline void DescriptorProto_ExtensionRange::clear_end() { - end_ = 0; - clear_has_end(); -} -inline ::google::protobuf::int32 DescriptorProto_ExtensionRange::end() const { - return end_; -} -inline void DescriptorProto_ExtensionRange::set_end(::google::protobuf::int32 value) { - set_has_end(); - end_ = value; -} - -// ------------------------------------------------------------------- - -// DescriptorProto - -// optional string name = 1; -inline bool DescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void DescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void DescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void DescriptorProto::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& DescriptorProto::name() const { - return *name_; -} -inline void DescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void DescriptorProto::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void DescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* DescriptorProto::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* DescriptorProto::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated .google.protobuf.FieldDescriptorProto field = 2; -inline int DescriptorProto::field_size() const { - return field_.size(); -} -inline void DescriptorProto::clear_field() { - field_.Clear(); -} -inline const ::google::protobuf::FieldDescriptorProto& DescriptorProto::field(int index) const { - return field_.Get(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::mutable_field(int index) { - return field_.Mutable(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::add_field() { - return field_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& -DescriptorProto::field() const { - return field_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* -DescriptorProto::mutable_field() { - return &field_; -} - -// repeated .google.protobuf.FieldDescriptorProto extension = 6; -inline int DescriptorProto::extension_size() const { - return extension_.size(); -} -inline void DescriptorProto::clear_extension() { - extension_.Clear(); -} -inline const ::google::protobuf::FieldDescriptorProto& DescriptorProto::extension(int index) const { - return extension_.Get(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::mutable_extension(int index) { - return extension_.Mutable(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::add_extension() { - return extension_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& -DescriptorProto::extension() const { - return extension_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* -DescriptorProto::mutable_extension() { - return &extension_; -} - -// repeated .google.protobuf.DescriptorProto nested_type = 3; -inline int DescriptorProto::nested_type_size() const { - return nested_type_.size(); -} -inline void DescriptorProto::clear_nested_type() { - nested_type_.Clear(); -} -inline const ::google::protobuf::DescriptorProto& DescriptorProto::nested_type(int index) const { - return nested_type_.Get(index); -} -inline ::google::protobuf::DescriptorProto* DescriptorProto::mutable_nested_type(int index) { - return nested_type_.Mutable(index); -} -inline ::google::protobuf::DescriptorProto* DescriptorProto::add_nested_type() { - return nested_type_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& -DescriptorProto::nested_type() const { - return nested_type_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* -DescriptorProto::mutable_nested_type() { - return &nested_type_; -} - -// repeated .google.protobuf.EnumDescriptorProto enum_type = 4; -inline int DescriptorProto::enum_type_size() const { - return enum_type_.size(); -} -inline void DescriptorProto::clear_enum_type() { - enum_type_.Clear(); -} -inline const ::google::protobuf::EnumDescriptorProto& DescriptorProto::enum_type(int index) const { - return enum_type_.Get(index); -} -inline ::google::protobuf::EnumDescriptorProto* DescriptorProto::mutable_enum_type(int index) { - return enum_type_.Mutable(index); -} -inline ::google::protobuf::EnumDescriptorProto* DescriptorProto::add_enum_type() { - return enum_type_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& -DescriptorProto::enum_type() const { - return enum_type_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* -DescriptorProto::mutable_enum_type() { - return &enum_type_; -} - -// repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; -inline int DescriptorProto::extension_range_size() const { - return extension_range_.size(); -} -inline void DescriptorProto::clear_extension_range() { - extension_range_.Clear(); -} -inline const ::google::protobuf::DescriptorProto_ExtensionRange& DescriptorProto::extension_range(int index) const { - return extension_range_.Get(index); -} -inline ::google::protobuf::DescriptorProto_ExtensionRange* DescriptorProto::mutable_extension_range(int index) { - return extension_range_.Mutable(index); -} -inline ::google::protobuf::DescriptorProto_ExtensionRange* DescriptorProto::add_extension_range() { - return extension_range_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >& -DescriptorProto::extension_range() const { - return extension_range_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >* -DescriptorProto::mutable_extension_range() { - return &extension_range_; -} - -// optional .google.protobuf.MessageOptions options = 7; -inline bool DescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void DescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000040u; -} -inline void DescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000040u; -} -inline void DescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::MessageOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::MessageOptions& DescriptorProto::options() const { - return options_ != NULL ? *options_ : *default_instance_->options_; -} -inline ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) options_ = new ::google::protobuf::MessageOptions; - return options_; -} -inline ::google::protobuf::MessageOptions* DescriptorProto::release_options() { - clear_has_options(); - ::google::protobuf::MessageOptions* temp = options_; - options_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// FieldDescriptorProto - -// optional string name = 1; -inline bool FieldDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FieldDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void FieldDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FieldDescriptorProto::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& FieldDescriptorProto::name() const { - return *name_; -} -inline void FieldDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void FieldDescriptorProto::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void FieldDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FieldDescriptorProto::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* FieldDescriptorProto::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional int32 number = 3; -inline bool FieldDescriptorProto::has_number() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FieldDescriptorProto::set_has_number() { - _has_bits_[0] |= 0x00000002u; -} -inline void FieldDescriptorProto::clear_has_number() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FieldDescriptorProto::clear_number() { - number_ = 0; - clear_has_number(); -} -inline ::google::protobuf::int32 FieldDescriptorProto::number() const { - return number_; -} -inline void FieldDescriptorProto::set_number(::google::protobuf::int32 value) { - set_has_number(); - number_ = value; -} - -// optional .google.protobuf.FieldDescriptorProto.Label label = 4; -inline bool FieldDescriptorProto::has_label() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void FieldDescriptorProto::set_has_label() { - _has_bits_[0] |= 0x00000004u; -} -inline void FieldDescriptorProto::clear_has_label() { - _has_bits_[0] &= ~0x00000004u; -} -inline void FieldDescriptorProto::clear_label() { - label_ = 1; - clear_has_label(); -} -inline ::google::protobuf::FieldDescriptorProto_Label FieldDescriptorProto::label() const { - return static_cast< ::google::protobuf::FieldDescriptorProto_Label >(label_); -} -inline void FieldDescriptorProto::set_label(::google::protobuf::FieldDescriptorProto_Label value) { - GOOGLE_DCHECK(::google::protobuf::FieldDescriptorProto_Label_IsValid(value)); - set_has_label(); - label_ = value; -} - -// optional .google.protobuf.FieldDescriptorProto.Type type = 5; -inline bool FieldDescriptorProto::has_type() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void FieldDescriptorProto::set_has_type() { - _has_bits_[0] |= 0x00000008u; -} -inline void FieldDescriptorProto::clear_has_type() { - _has_bits_[0] &= ~0x00000008u; -} -inline void FieldDescriptorProto::clear_type() { - type_ = 1; - clear_has_type(); -} -inline ::google::protobuf::FieldDescriptorProto_Type FieldDescriptorProto::type() const { - return static_cast< ::google::protobuf::FieldDescriptorProto_Type >(type_); -} -inline void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorProto_Type value) { - GOOGLE_DCHECK(::google::protobuf::FieldDescriptorProto_Type_IsValid(value)); - set_has_type(); - type_ = value; -} - -// optional string type_name = 6; -inline bool FieldDescriptorProto::has_type_name() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void FieldDescriptorProto::set_has_type_name() { - _has_bits_[0] |= 0x00000010u; -} -inline void FieldDescriptorProto::clear_has_type_name() { - _has_bits_[0] &= ~0x00000010u; -} -inline void FieldDescriptorProto::clear_type_name() { - if (type_name_ != &::google::protobuf::internal::kEmptyString) { - type_name_->clear(); - } - clear_has_type_name(); -} -inline const ::std::string& FieldDescriptorProto::type_name() const { - return *type_name_; -} -inline void FieldDescriptorProto::set_type_name(const ::std::string& value) { - set_has_type_name(); - if (type_name_ == &::google::protobuf::internal::kEmptyString) { - type_name_ = new ::std::string; - } - type_name_->assign(value); -} -inline void FieldDescriptorProto::set_type_name(const char* value) { - set_has_type_name(); - if (type_name_ == &::google::protobuf::internal::kEmptyString) { - type_name_ = new ::std::string; - } - type_name_->assign(value); -} -inline void FieldDescriptorProto::set_type_name(const char* value, size_t size) { - set_has_type_name(); - if (type_name_ == &::google::protobuf::internal::kEmptyString) { - type_name_ = new ::std::string; - } - type_name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FieldDescriptorProto::mutable_type_name() { - set_has_type_name(); - if (type_name_ == &::google::protobuf::internal::kEmptyString) { - type_name_ = new ::std::string; - } - return type_name_; -} -inline ::std::string* FieldDescriptorProto::release_type_name() { - clear_has_type_name(); - if (type_name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = type_name_; - type_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string extendee = 2; -inline bool FieldDescriptorProto::has_extendee() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void FieldDescriptorProto::set_has_extendee() { - _has_bits_[0] |= 0x00000020u; -} -inline void FieldDescriptorProto::clear_has_extendee() { - _has_bits_[0] &= ~0x00000020u; -} -inline void FieldDescriptorProto::clear_extendee() { - if (extendee_ != &::google::protobuf::internal::kEmptyString) { - extendee_->clear(); - } - clear_has_extendee(); -} -inline const ::std::string& FieldDescriptorProto::extendee() const { - return *extendee_; -} -inline void FieldDescriptorProto::set_extendee(const ::std::string& value) { - set_has_extendee(); - if (extendee_ == &::google::protobuf::internal::kEmptyString) { - extendee_ = new ::std::string; - } - extendee_->assign(value); -} -inline void FieldDescriptorProto::set_extendee(const char* value) { - set_has_extendee(); - if (extendee_ == &::google::protobuf::internal::kEmptyString) { - extendee_ = new ::std::string; - } - extendee_->assign(value); -} -inline void FieldDescriptorProto::set_extendee(const char* value, size_t size) { - set_has_extendee(); - if (extendee_ == &::google::protobuf::internal::kEmptyString) { - extendee_ = new ::std::string; - } - extendee_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FieldDescriptorProto::mutable_extendee() { - set_has_extendee(); - if (extendee_ == &::google::protobuf::internal::kEmptyString) { - extendee_ = new ::std::string; - } - return extendee_; -} -inline ::std::string* FieldDescriptorProto::release_extendee() { - clear_has_extendee(); - if (extendee_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = extendee_; - extendee_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string default_value = 7; -inline bool FieldDescriptorProto::has_default_value() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void FieldDescriptorProto::set_has_default_value() { - _has_bits_[0] |= 0x00000040u; -} -inline void FieldDescriptorProto::clear_has_default_value() { - _has_bits_[0] &= ~0x00000040u; -} -inline void FieldDescriptorProto::clear_default_value() { - if (default_value_ != &::google::protobuf::internal::kEmptyString) { - default_value_->clear(); - } - clear_has_default_value(); -} -inline const ::std::string& FieldDescriptorProto::default_value() const { - return *default_value_; -} -inline void FieldDescriptorProto::set_default_value(const ::std::string& value) { - set_has_default_value(); - if (default_value_ == &::google::protobuf::internal::kEmptyString) { - default_value_ = new ::std::string; - } - default_value_->assign(value); -} -inline void FieldDescriptorProto::set_default_value(const char* value) { - set_has_default_value(); - if (default_value_ == &::google::protobuf::internal::kEmptyString) { - default_value_ = new ::std::string; - } - default_value_->assign(value); -} -inline void FieldDescriptorProto::set_default_value(const char* value, size_t size) { - set_has_default_value(); - if (default_value_ == &::google::protobuf::internal::kEmptyString) { - default_value_ = new ::std::string; - } - default_value_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FieldDescriptorProto::mutable_default_value() { - set_has_default_value(); - if (default_value_ == &::google::protobuf::internal::kEmptyString) { - default_value_ = new ::std::string; - } - return default_value_; -} -inline ::std::string* FieldDescriptorProto::release_default_value() { - clear_has_default_value(); - if (default_value_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = default_value_; - default_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional .google.protobuf.FieldOptions options = 8; -inline bool FieldDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void FieldDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000080u; -} -inline void FieldDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000080u; -} -inline void FieldDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { - return options_ != NULL ? *options_ : *default_instance_->options_; -} -inline ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) options_ = new ::google::protobuf::FieldOptions; - return options_; -} -inline ::google::protobuf::FieldOptions* FieldDescriptorProto::release_options() { - clear_has_options(); - ::google::protobuf::FieldOptions* temp = options_; - options_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// EnumDescriptorProto - -// optional string name = 1; -inline bool EnumDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void EnumDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void EnumDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void EnumDescriptorProto::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& EnumDescriptorProto::name() const { - return *name_; -} -inline void EnumDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void EnumDescriptorProto::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void EnumDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* EnumDescriptorProto::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* EnumDescriptorProto::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated .google.protobuf.EnumValueDescriptorProto value = 2; -inline int EnumDescriptorProto::value_size() const { - return value_.size(); -} -inline void EnumDescriptorProto::clear_value() { - value_.Clear(); -} -inline const ::google::protobuf::EnumValueDescriptorProto& EnumDescriptorProto::value(int index) const { - return value_.Get(index); -} -inline ::google::protobuf::EnumValueDescriptorProto* EnumDescriptorProto::mutable_value(int index) { - return value_.Mutable(index); -} -inline ::google::protobuf::EnumValueDescriptorProto* EnumDescriptorProto::add_value() { - return value_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >& -EnumDescriptorProto::value() const { - return value_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >* -EnumDescriptorProto::mutable_value() { - return &value_; -} - -// optional .google.protobuf.EnumOptions options = 3; -inline bool EnumDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void EnumDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000004u; -} -inline void EnumDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000004u; -} -inline void EnumDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::EnumOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { - return options_ != NULL ? *options_ : *default_instance_->options_; -} -inline ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) options_ = new ::google::protobuf::EnumOptions; - return options_; -} -inline ::google::protobuf::EnumOptions* EnumDescriptorProto::release_options() { - clear_has_options(); - ::google::protobuf::EnumOptions* temp = options_; - options_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// EnumValueDescriptorProto - -// optional string name = 1; -inline bool EnumValueDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void EnumValueDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void EnumValueDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void EnumValueDescriptorProto::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& EnumValueDescriptorProto::name() const { - return *name_; -} -inline void EnumValueDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void EnumValueDescriptorProto::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void EnumValueDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* EnumValueDescriptorProto::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* EnumValueDescriptorProto::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional int32 number = 2; -inline bool EnumValueDescriptorProto::has_number() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void EnumValueDescriptorProto::set_has_number() { - _has_bits_[0] |= 0x00000002u; -} -inline void EnumValueDescriptorProto::clear_has_number() { - _has_bits_[0] &= ~0x00000002u; -} -inline void EnumValueDescriptorProto::clear_number() { - number_ = 0; - clear_has_number(); -} -inline ::google::protobuf::int32 EnumValueDescriptorProto::number() const { - return number_; -} -inline void EnumValueDescriptorProto::set_number(::google::protobuf::int32 value) { - set_has_number(); - number_ = value; -} - -// optional .google.protobuf.EnumValueOptions options = 3; -inline bool EnumValueDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void EnumValueDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000004u; -} -inline void EnumValueDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000004u; -} -inline void EnumValueDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { - return options_ != NULL ? *options_ : *default_instance_->options_; -} -inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) options_ = new ::google::protobuf::EnumValueOptions; - return options_; -} -inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::release_options() { - clear_has_options(); - ::google::protobuf::EnumValueOptions* temp = options_; - options_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// ServiceDescriptorProto - -// optional string name = 1; -inline bool ServiceDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ServiceDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void ServiceDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ServiceDescriptorProto::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& ServiceDescriptorProto::name() const { - return *name_; -} -inline void ServiceDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void ServiceDescriptorProto::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void ServiceDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* ServiceDescriptorProto::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* ServiceDescriptorProto::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated .google.protobuf.MethodDescriptorProto method = 2; -inline int ServiceDescriptorProto::method_size() const { - return method_.size(); -} -inline void ServiceDescriptorProto::clear_method() { - method_.Clear(); -} -inline const ::google::protobuf::MethodDescriptorProto& ServiceDescriptorProto::method(int index) const { - return method_.Get(index); -} -inline ::google::protobuf::MethodDescriptorProto* ServiceDescriptorProto::mutable_method(int index) { - return method_.Mutable(index); -} -inline ::google::protobuf::MethodDescriptorProto* ServiceDescriptorProto::add_method() { - return method_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >& -ServiceDescriptorProto::method() const { - return method_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >* -ServiceDescriptorProto::mutable_method() { - return &method_; -} - -// optional .google.protobuf.ServiceOptions options = 3; -inline bool ServiceDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void ServiceDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000004u; -} -inline void ServiceDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000004u; -} -inline void ServiceDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::ServiceOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { - return options_ != NULL ? *options_ : *default_instance_->options_; -} -inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) options_ = new ::google::protobuf::ServiceOptions; - return options_; -} -inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::release_options() { - clear_has_options(); - ::google::protobuf::ServiceOptions* temp = options_; - options_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// MethodDescriptorProto - -// optional string name = 1; -inline bool MethodDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void MethodDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void MethodDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void MethodDescriptorProto::clear_name() { - if (name_ != &::google::protobuf::internal::kEmptyString) { - name_->clear(); - } - clear_has_name(); -} -inline const ::std::string& MethodDescriptorProto::name() const { - return *name_; -} -inline void MethodDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void MethodDescriptorProto::set_name(const char* value) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(value); -} -inline void MethodDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - name_->assign(reinterpret_cast(value), size); -} -inline ::std::string* MethodDescriptorProto::mutable_name() { - set_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - name_ = new ::std::string; - } - return name_; -} -inline ::std::string* MethodDescriptorProto::release_name() { - clear_has_name(); - if (name_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_; - name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string input_type = 2; -inline bool MethodDescriptorProto::has_input_type() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void MethodDescriptorProto::set_has_input_type() { - _has_bits_[0] |= 0x00000002u; -} -inline void MethodDescriptorProto::clear_has_input_type() { - _has_bits_[0] &= ~0x00000002u; -} -inline void MethodDescriptorProto::clear_input_type() { - if (input_type_ != &::google::protobuf::internal::kEmptyString) { - input_type_->clear(); - } - clear_has_input_type(); -} -inline const ::std::string& MethodDescriptorProto::input_type() const { - return *input_type_; -} -inline void MethodDescriptorProto::set_input_type(const ::std::string& value) { - set_has_input_type(); - if (input_type_ == &::google::protobuf::internal::kEmptyString) { - input_type_ = new ::std::string; - } - input_type_->assign(value); -} -inline void MethodDescriptorProto::set_input_type(const char* value) { - set_has_input_type(); - if (input_type_ == &::google::protobuf::internal::kEmptyString) { - input_type_ = new ::std::string; - } - input_type_->assign(value); -} -inline void MethodDescriptorProto::set_input_type(const char* value, size_t size) { - set_has_input_type(); - if (input_type_ == &::google::protobuf::internal::kEmptyString) { - input_type_ = new ::std::string; - } - input_type_->assign(reinterpret_cast(value), size); -} -inline ::std::string* MethodDescriptorProto::mutable_input_type() { - set_has_input_type(); - if (input_type_ == &::google::protobuf::internal::kEmptyString) { - input_type_ = new ::std::string; - } - return input_type_; -} -inline ::std::string* MethodDescriptorProto::release_input_type() { - clear_has_input_type(); - if (input_type_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = input_type_; - input_type_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string output_type = 3; -inline bool MethodDescriptorProto::has_output_type() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void MethodDescriptorProto::set_has_output_type() { - _has_bits_[0] |= 0x00000004u; -} -inline void MethodDescriptorProto::clear_has_output_type() { - _has_bits_[0] &= ~0x00000004u; -} -inline void MethodDescriptorProto::clear_output_type() { - if (output_type_ != &::google::protobuf::internal::kEmptyString) { - output_type_->clear(); - } - clear_has_output_type(); -} -inline const ::std::string& MethodDescriptorProto::output_type() const { - return *output_type_; -} -inline void MethodDescriptorProto::set_output_type(const ::std::string& value) { - set_has_output_type(); - if (output_type_ == &::google::protobuf::internal::kEmptyString) { - output_type_ = new ::std::string; - } - output_type_->assign(value); -} -inline void MethodDescriptorProto::set_output_type(const char* value) { - set_has_output_type(); - if (output_type_ == &::google::protobuf::internal::kEmptyString) { - output_type_ = new ::std::string; - } - output_type_->assign(value); -} -inline void MethodDescriptorProto::set_output_type(const char* value, size_t size) { - set_has_output_type(); - if (output_type_ == &::google::protobuf::internal::kEmptyString) { - output_type_ = new ::std::string; - } - output_type_->assign(reinterpret_cast(value), size); -} -inline ::std::string* MethodDescriptorProto::mutable_output_type() { - set_has_output_type(); - if (output_type_ == &::google::protobuf::internal::kEmptyString) { - output_type_ = new ::std::string; - } - return output_type_; -} -inline ::std::string* MethodDescriptorProto::release_output_type() { - clear_has_output_type(); - if (output_type_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = output_type_; - output_type_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional .google.protobuf.MethodOptions options = 4; -inline bool MethodDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void MethodDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000008u; -} -inline void MethodDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000008u; -} -inline void MethodDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::MethodOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { - return options_ != NULL ? *options_ : *default_instance_->options_; -} -inline ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) options_ = new ::google::protobuf::MethodOptions; - return options_; -} -inline ::google::protobuf::MethodOptions* MethodDescriptorProto::release_options() { - clear_has_options(); - ::google::protobuf::MethodOptions* temp = options_; - options_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// FileOptions - -// optional string java_package = 1; -inline bool FileOptions::has_java_package() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FileOptions::set_has_java_package() { - _has_bits_[0] |= 0x00000001u; -} -inline void FileOptions::clear_has_java_package() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FileOptions::clear_java_package() { - if (java_package_ != &::google::protobuf::internal::kEmptyString) { - java_package_->clear(); - } - clear_has_java_package(); -} -inline const ::std::string& FileOptions::java_package() const { - return *java_package_; -} -inline void FileOptions::set_java_package(const ::std::string& value) { - set_has_java_package(); - if (java_package_ == &::google::protobuf::internal::kEmptyString) { - java_package_ = new ::std::string; - } - java_package_->assign(value); -} -inline void FileOptions::set_java_package(const char* value) { - set_has_java_package(); - if (java_package_ == &::google::protobuf::internal::kEmptyString) { - java_package_ = new ::std::string; - } - java_package_->assign(value); -} -inline void FileOptions::set_java_package(const char* value, size_t size) { - set_has_java_package(); - if (java_package_ == &::google::protobuf::internal::kEmptyString) { - java_package_ = new ::std::string; - } - java_package_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FileOptions::mutable_java_package() { - set_has_java_package(); - if (java_package_ == &::google::protobuf::internal::kEmptyString) { - java_package_ = new ::std::string; - } - return java_package_; -} -inline ::std::string* FileOptions::release_java_package() { - clear_has_java_package(); - if (java_package_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = java_package_; - java_package_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string java_outer_classname = 8; -inline bool FileOptions::has_java_outer_classname() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FileOptions::set_has_java_outer_classname() { - _has_bits_[0] |= 0x00000002u; -} -inline void FileOptions::clear_has_java_outer_classname() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FileOptions::clear_java_outer_classname() { - if (java_outer_classname_ != &::google::protobuf::internal::kEmptyString) { - java_outer_classname_->clear(); - } - clear_has_java_outer_classname(); -} -inline const ::std::string& FileOptions::java_outer_classname() const { - return *java_outer_classname_; -} -inline void FileOptions::set_java_outer_classname(const ::std::string& value) { - set_has_java_outer_classname(); - if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { - java_outer_classname_ = new ::std::string; - } - java_outer_classname_->assign(value); -} -inline void FileOptions::set_java_outer_classname(const char* value) { - set_has_java_outer_classname(); - if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { - java_outer_classname_ = new ::std::string; - } - java_outer_classname_->assign(value); -} -inline void FileOptions::set_java_outer_classname(const char* value, size_t size) { - set_has_java_outer_classname(); - if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { - java_outer_classname_ = new ::std::string; - } - java_outer_classname_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FileOptions::mutable_java_outer_classname() { - set_has_java_outer_classname(); - if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { - java_outer_classname_ = new ::std::string; - } - return java_outer_classname_; -} -inline ::std::string* FileOptions::release_java_outer_classname() { - clear_has_java_outer_classname(); - if (java_outer_classname_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = java_outer_classname_; - java_outer_classname_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional bool java_multiple_files = 10 [default = false]; -inline bool FileOptions::has_java_multiple_files() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void FileOptions::set_has_java_multiple_files() { - _has_bits_[0] |= 0x00000004u; -} -inline void FileOptions::clear_has_java_multiple_files() { - _has_bits_[0] &= ~0x00000004u; -} -inline void FileOptions::clear_java_multiple_files() { - java_multiple_files_ = false; - clear_has_java_multiple_files(); -} -inline bool FileOptions::java_multiple_files() const { - return java_multiple_files_; -} -inline void FileOptions::set_java_multiple_files(bool value) { - set_has_java_multiple_files(); - java_multiple_files_ = value; -} - -// optional bool java_generate_equals_and_hash = 20 [default = false]; -inline bool FileOptions::has_java_generate_equals_and_hash() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void FileOptions::set_has_java_generate_equals_and_hash() { - _has_bits_[0] |= 0x00000008u; -} -inline void FileOptions::clear_has_java_generate_equals_and_hash() { - _has_bits_[0] &= ~0x00000008u; -} -inline void FileOptions::clear_java_generate_equals_and_hash() { - java_generate_equals_and_hash_ = false; - clear_has_java_generate_equals_and_hash(); -} -inline bool FileOptions::java_generate_equals_and_hash() const { - return java_generate_equals_and_hash_; -} -inline void FileOptions::set_java_generate_equals_and_hash(bool value) { - set_has_java_generate_equals_and_hash(); - java_generate_equals_and_hash_ = value; -} - -// optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; -inline bool FileOptions::has_optimize_for() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void FileOptions::set_has_optimize_for() { - _has_bits_[0] |= 0x00000010u; -} -inline void FileOptions::clear_has_optimize_for() { - _has_bits_[0] &= ~0x00000010u; -} -inline void FileOptions::clear_optimize_for() { - optimize_for_ = 1; - clear_has_optimize_for(); -} -inline ::google::protobuf::FileOptions_OptimizeMode FileOptions::optimize_for() const { - return static_cast< ::google::protobuf::FileOptions_OptimizeMode >(optimize_for_); -} -inline void FileOptions::set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value) { - GOOGLE_DCHECK(::google::protobuf::FileOptions_OptimizeMode_IsValid(value)); - set_has_optimize_for(); - optimize_for_ = value; -} - -// optional bool cc_generic_services = 16 [default = false]; -inline bool FileOptions::has_cc_generic_services() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void FileOptions::set_has_cc_generic_services() { - _has_bits_[0] |= 0x00000020u; -} -inline void FileOptions::clear_has_cc_generic_services() { - _has_bits_[0] &= ~0x00000020u; -} -inline void FileOptions::clear_cc_generic_services() { - cc_generic_services_ = false; - clear_has_cc_generic_services(); -} -inline bool FileOptions::cc_generic_services() const { - return cc_generic_services_; -} -inline void FileOptions::set_cc_generic_services(bool value) { - set_has_cc_generic_services(); - cc_generic_services_ = value; -} - -// optional bool java_generic_services = 17 [default = false]; -inline bool FileOptions::has_java_generic_services() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void FileOptions::set_has_java_generic_services() { - _has_bits_[0] |= 0x00000040u; -} -inline void FileOptions::clear_has_java_generic_services() { - _has_bits_[0] &= ~0x00000040u; -} -inline void FileOptions::clear_java_generic_services() { - java_generic_services_ = false; - clear_has_java_generic_services(); -} -inline bool FileOptions::java_generic_services() const { - return java_generic_services_; -} -inline void FileOptions::set_java_generic_services(bool value) { - set_has_java_generic_services(); - java_generic_services_ = value; -} - -// optional bool py_generic_services = 18 [default = false]; -inline bool FileOptions::has_py_generic_services() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void FileOptions::set_has_py_generic_services() { - _has_bits_[0] |= 0x00000080u; -} -inline void FileOptions::clear_has_py_generic_services() { - _has_bits_[0] &= ~0x00000080u; -} -inline void FileOptions::clear_py_generic_services() { - py_generic_services_ = false; - clear_has_py_generic_services(); -} -inline bool FileOptions::py_generic_services() const { - return py_generic_services_; -} -inline void FileOptions::set_py_generic_services(bool value) { - set_has_py_generic_services(); - py_generic_services_ = value; -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int FileOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void FileOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& FileOptions::uninterpreted_option(int index) const { - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* FileOptions::mutable_uninterpreted_option(int index) { - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* FileOptions::add_uninterpreted_option() { - return uninterpreted_option_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -FileOptions::uninterpreted_option() const { - return uninterpreted_option_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -FileOptions::mutable_uninterpreted_option() { - return &uninterpreted_option_; -} - -// ------------------------------------------------------------------- - -// MessageOptions - -// optional bool message_set_wire_format = 1 [default = false]; -inline bool MessageOptions::has_message_set_wire_format() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void MessageOptions::set_has_message_set_wire_format() { - _has_bits_[0] |= 0x00000001u; -} -inline void MessageOptions::clear_has_message_set_wire_format() { - _has_bits_[0] &= ~0x00000001u; -} -inline void MessageOptions::clear_message_set_wire_format() { - message_set_wire_format_ = false; - clear_has_message_set_wire_format(); -} -inline bool MessageOptions::message_set_wire_format() const { - return message_set_wire_format_; -} -inline void MessageOptions::set_message_set_wire_format(bool value) { - set_has_message_set_wire_format(); - message_set_wire_format_ = value; -} - -// optional bool no_standard_descriptor_accessor = 2 [default = false]; -inline bool MessageOptions::has_no_standard_descriptor_accessor() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void MessageOptions::set_has_no_standard_descriptor_accessor() { - _has_bits_[0] |= 0x00000002u; -} -inline void MessageOptions::clear_has_no_standard_descriptor_accessor() { - _has_bits_[0] &= ~0x00000002u; -} -inline void MessageOptions::clear_no_standard_descriptor_accessor() { - no_standard_descriptor_accessor_ = false; - clear_has_no_standard_descriptor_accessor(); -} -inline bool MessageOptions::no_standard_descriptor_accessor() const { - return no_standard_descriptor_accessor_; -} -inline void MessageOptions::set_no_standard_descriptor_accessor(bool value) { - set_has_no_standard_descriptor_accessor(); - no_standard_descriptor_accessor_ = value; -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int MessageOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void MessageOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& MessageOptions::uninterpreted_option(int index) const { - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* MessageOptions::mutable_uninterpreted_option(int index) { - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* MessageOptions::add_uninterpreted_option() { - return uninterpreted_option_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -MessageOptions::uninterpreted_option() const { - return uninterpreted_option_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -MessageOptions::mutable_uninterpreted_option() { - return &uninterpreted_option_; -} - -// ------------------------------------------------------------------- - -// FieldOptions - -// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; -inline bool FieldOptions::has_ctype() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FieldOptions::set_has_ctype() { - _has_bits_[0] |= 0x00000001u; -} -inline void FieldOptions::clear_has_ctype() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FieldOptions::clear_ctype() { - ctype_ = 0; - clear_has_ctype(); -} -inline ::google::protobuf::FieldOptions_CType FieldOptions::ctype() const { - return static_cast< ::google::protobuf::FieldOptions_CType >(ctype_); -} -inline void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value) { - GOOGLE_DCHECK(::google::protobuf::FieldOptions_CType_IsValid(value)); - set_has_ctype(); - ctype_ = value; -} - -// optional bool packed = 2; -inline bool FieldOptions::has_packed() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FieldOptions::set_has_packed() { - _has_bits_[0] |= 0x00000002u; -} -inline void FieldOptions::clear_has_packed() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FieldOptions::clear_packed() { - packed_ = false; - clear_has_packed(); -} -inline bool FieldOptions::packed() const { - return packed_; -} -inline void FieldOptions::set_packed(bool value) { - set_has_packed(); - packed_ = value; -} - -// optional bool deprecated = 3 [default = false]; -inline bool FieldOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void FieldOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000004u; -} -inline void FieldOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000004u; -} -inline void FieldOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool FieldOptions::deprecated() const { - return deprecated_; -} -inline void FieldOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; -} - -// optional string experimental_map_key = 9; -inline bool FieldOptions::has_experimental_map_key() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void FieldOptions::set_has_experimental_map_key() { - _has_bits_[0] |= 0x00000008u; -} -inline void FieldOptions::clear_has_experimental_map_key() { - _has_bits_[0] &= ~0x00000008u; -} -inline void FieldOptions::clear_experimental_map_key() { - if (experimental_map_key_ != &::google::protobuf::internal::kEmptyString) { - experimental_map_key_->clear(); - } - clear_has_experimental_map_key(); -} -inline const ::std::string& FieldOptions::experimental_map_key() const { - return *experimental_map_key_; -} -inline void FieldOptions::set_experimental_map_key(const ::std::string& value) { - set_has_experimental_map_key(); - if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { - experimental_map_key_ = new ::std::string; - } - experimental_map_key_->assign(value); -} -inline void FieldOptions::set_experimental_map_key(const char* value) { - set_has_experimental_map_key(); - if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { - experimental_map_key_ = new ::std::string; - } - experimental_map_key_->assign(value); -} -inline void FieldOptions::set_experimental_map_key(const char* value, size_t size) { - set_has_experimental_map_key(); - if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { - experimental_map_key_ = new ::std::string; - } - experimental_map_key_->assign(reinterpret_cast(value), size); -} -inline ::std::string* FieldOptions::mutable_experimental_map_key() { - set_has_experimental_map_key(); - if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { - experimental_map_key_ = new ::std::string; - } - return experimental_map_key_; -} -inline ::std::string* FieldOptions::release_experimental_map_key() { - clear_has_experimental_map_key(); - if (experimental_map_key_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = experimental_map_key_; - experimental_map_key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int FieldOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void FieldOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& FieldOptions::uninterpreted_option(int index) const { - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* FieldOptions::mutable_uninterpreted_option(int index) { - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* FieldOptions::add_uninterpreted_option() { - return uninterpreted_option_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -FieldOptions::uninterpreted_option() const { - return uninterpreted_option_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -FieldOptions::mutable_uninterpreted_option() { - return &uninterpreted_option_; -} - -// ------------------------------------------------------------------- - -// EnumOptions - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int EnumOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void EnumOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& EnumOptions::uninterpreted_option(int index) const { - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* EnumOptions::mutable_uninterpreted_option(int index) { - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* EnumOptions::add_uninterpreted_option() { - return uninterpreted_option_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -EnumOptions::uninterpreted_option() const { - return uninterpreted_option_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -EnumOptions::mutable_uninterpreted_option() { - return &uninterpreted_option_; -} - -// ------------------------------------------------------------------- - -// EnumValueOptions - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int EnumValueOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void EnumValueOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& EnumValueOptions::uninterpreted_option(int index) const { - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* EnumValueOptions::mutable_uninterpreted_option(int index) { - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* EnumValueOptions::add_uninterpreted_option() { - return uninterpreted_option_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -EnumValueOptions::uninterpreted_option() const { - return uninterpreted_option_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -EnumValueOptions::mutable_uninterpreted_option() { - return &uninterpreted_option_; -} - -// ------------------------------------------------------------------- - -// ServiceOptions - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int ServiceOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void ServiceOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& ServiceOptions::uninterpreted_option(int index) const { - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* ServiceOptions::mutable_uninterpreted_option(int index) { - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* ServiceOptions::add_uninterpreted_option() { - return uninterpreted_option_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -ServiceOptions::uninterpreted_option() const { - return uninterpreted_option_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -ServiceOptions::mutable_uninterpreted_option() { - return &uninterpreted_option_; -} - -// ------------------------------------------------------------------- - -// MethodOptions - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int MethodOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void MethodOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& MethodOptions::uninterpreted_option(int index) const { - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* MethodOptions::mutable_uninterpreted_option(int index) { - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* MethodOptions::add_uninterpreted_option() { - return uninterpreted_option_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -MethodOptions::uninterpreted_option() const { - return uninterpreted_option_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -MethodOptions::mutable_uninterpreted_option() { - return &uninterpreted_option_; -} - -// ------------------------------------------------------------------- - -// UninterpretedOption_NamePart - -// required string name_part = 1; -inline bool UninterpretedOption_NamePart::has_name_part() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void UninterpretedOption_NamePart::set_has_name_part() { - _has_bits_[0] |= 0x00000001u; -} -inline void UninterpretedOption_NamePart::clear_has_name_part() { - _has_bits_[0] &= ~0x00000001u; -} -inline void UninterpretedOption_NamePart::clear_name_part() { - if (name_part_ != &::google::protobuf::internal::kEmptyString) { - name_part_->clear(); - } - clear_has_name_part(); -} -inline const ::std::string& UninterpretedOption_NamePart::name_part() const { - return *name_part_; -} -inline void UninterpretedOption_NamePart::set_name_part(const ::std::string& value) { - set_has_name_part(); - if (name_part_ == &::google::protobuf::internal::kEmptyString) { - name_part_ = new ::std::string; - } - name_part_->assign(value); -} -inline void UninterpretedOption_NamePart::set_name_part(const char* value) { - set_has_name_part(); - if (name_part_ == &::google::protobuf::internal::kEmptyString) { - name_part_ = new ::std::string; - } - name_part_->assign(value); -} -inline void UninterpretedOption_NamePart::set_name_part(const char* value, size_t size) { - set_has_name_part(); - if (name_part_ == &::google::protobuf::internal::kEmptyString) { - name_part_ = new ::std::string; - } - name_part_->assign(reinterpret_cast(value), size); -} -inline ::std::string* UninterpretedOption_NamePart::mutable_name_part() { - set_has_name_part(); - if (name_part_ == &::google::protobuf::internal::kEmptyString) { - name_part_ = new ::std::string; - } - return name_part_; -} -inline ::std::string* UninterpretedOption_NamePart::release_name_part() { - clear_has_name_part(); - if (name_part_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = name_part_; - name_part_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// required bool is_extension = 2; -inline bool UninterpretedOption_NamePart::has_is_extension() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void UninterpretedOption_NamePart::set_has_is_extension() { - _has_bits_[0] |= 0x00000002u; -} -inline void UninterpretedOption_NamePart::clear_has_is_extension() { - _has_bits_[0] &= ~0x00000002u; -} -inline void UninterpretedOption_NamePart::clear_is_extension() { - is_extension_ = false; - clear_has_is_extension(); -} -inline bool UninterpretedOption_NamePart::is_extension() const { - return is_extension_; -} -inline void UninterpretedOption_NamePart::set_is_extension(bool value) { - set_has_is_extension(); - is_extension_ = value; -} - -// ------------------------------------------------------------------- - -// UninterpretedOption - -// repeated .google.protobuf.UninterpretedOption.NamePart name = 2; -inline int UninterpretedOption::name_size() const { - return name_.size(); -} -inline void UninterpretedOption::clear_name() { - name_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption_NamePart& UninterpretedOption::name(int index) const { - return name_.Get(index); -} -inline ::google::protobuf::UninterpretedOption_NamePart* UninterpretedOption::mutable_name(int index) { - return name_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption_NamePart* UninterpretedOption::add_name() { - return name_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >& -UninterpretedOption::name() const { - return name_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >* -UninterpretedOption::mutable_name() { - return &name_; -} - -// optional string identifier_value = 3; -inline bool UninterpretedOption::has_identifier_value() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void UninterpretedOption::set_has_identifier_value() { - _has_bits_[0] |= 0x00000002u; -} -inline void UninterpretedOption::clear_has_identifier_value() { - _has_bits_[0] &= ~0x00000002u; -} -inline void UninterpretedOption::clear_identifier_value() { - if (identifier_value_ != &::google::protobuf::internal::kEmptyString) { - identifier_value_->clear(); - } - clear_has_identifier_value(); -} -inline const ::std::string& UninterpretedOption::identifier_value() const { - return *identifier_value_; -} -inline void UninterpretedOption::set_identifier_value(const ::std::string& value) { - set_has_identifier_value(); - if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { - identifier_value_ = new ::std::string; - } - identifier_value_->assign(value); -} -inline void UninterpretedOption::set_identifier_value(const char* value) { - set_has_identifier_value(); - if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { - identifier_value_ = new ::std::string; - } - identifier_value_->assign(value); -} -inline void UninterpretedOption::set_identifier_value(const char* value, size_t size) { - set_has_identifier_value(); - if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { - identifier_value_ = new ::std::string; - } - identifier_value_->assign(reinterpret_cast(value), size); -} -inline ::std::string* UninterpretedOption::mutable_identifier_value() { - set_has_identifier_value(); - if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { - identifier_value_ = new ::std::string; - } - return identifier_value_; -} -inline ::std::string* UninterpretedOption::release_identifier_value() { - clear_has_identifier_value(); - if (identifier_value_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = identifier_value_; - identifier_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional uint64 positive_int_value = 4; -inline bool UninterpretedOption::has_positive_int_value() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void UninterpretedOption::set_has_positive_int_value() { - _has_bits_[0] |= 0x00000004u; -} -inline void UninterpretedOption::clear_has_positive_int_value() { - _has_bits_[0] &= ~0x00000004u; -} -inline void UninterpretedOption::clear_positive_int_value() { - positive_int_value_ = GOOGLE_ULONGLONG(0); - clear_has_positive_int_value(); -} -inline ::google::protobuf::uint64 UninterpretedOption::positive_int_value() const { - return positive_int_value_; -} -inline void UninterpretedOption::set_positive_int_value(::google::protobuf::uint64 value) { - set_has_positive_int_value(); - positive_int_value_ = value; -} - -// optional int64 negative_int_value = 5; -inline bool UninterpretedOption::has_negative_int_value() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void UninterpretedOption::set_has_negative_int_value() { - _has_bits_[0] |= 0x00000008u; -} -inline void UninterpretedOption::clear_has_negative_int_value() { - _has_bits_[0] &= ~0x00000008u; -} -inline void UninterpretedOption::clear_negative_int_value() { - negative_int_value_ = GOOGLE_LONGLONG(0); - clear_has_negative_int_value(); -} -inline ::google::protobuf::int64 UninterpretedOption::negative_int_value() const { - return negative_int_value_; -} -inline void UninterpretedOption::set_negative_int_value(::google::protobuf::int64 value) { - set_has_negative_int_value(); - negative_int_value_ = value; -} - -// optional double double_value = 6; -inline bool UninterpretedOption::has_double_value() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void UninterpretedOption::set_has_double_value() { - _has_bits_[0] |= 0x00000010u; -} -inline void UninterpretedOption::clear_has_double_value() { - _has_bits_[0] &= ~0x00000010u; -} -inline void UninterpretedOption::clear_double_value() { - double_value_ = 0; - clear_has_double_value(); -} -inline double UninterpretedOption::double_value() const { - return double_value_; -} -inline void UninterpretedOption::set_double_value(double value) { - set_has_double_value(); - double_value_ = value; -} - -// optional bytes string_value = 7; -inline bool UninterpretedOption::has_string_value() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void UninterpretedOption::set_has_string_value() { - _has_bits_[0] |= 0x00000020u; -} -inline void UninterpretedOption::clear_has_string_value() { - _has_bits_[0] &= ~0x00000020u; -} -inline void UninterpretedOption::clear_string_value() { - if (string_value_ != &::google::protobuf::internal::kEmptyString) { - string_value_->clear(); - } - clear_has_string_value(); -} -inline const ::std::string& UninterpretedOption::string_value() const { - return *string_value_; -} -inline void UninterpretedOption::set_string_value(const ::std::string& value) { - set_has_string_value(); - if (string_value_ == &::google::protobuf::internal::kEmptyString) { - string_value_ = new ::std::string; - } - string_value_->assign(value); -} -inline void UninterpretedOption::set_string_value(const char* value) { - set_has_string_value(); - if (string_value_ == &::google::protobuf::internal::kEmptyString) { - string_value_ = new ::std::string; - } - string_value_->assign(value); -} -inline void UninterpretedOption::set_string_value(const void* value, size_t size) { - set_has_string_value(); - if (string_value_ == &::google::protobuf::internal::kEmptyString) { - string_value_ = new ::std::string; - } - string_value_->assign(reinterpret_cast(value), size); -} -inline ::std::string* UninterpretedOption::mutable_string_value() { - set_has_string_value(); - if (string_value_ == &::google::protobuf::internal::kEmptyString) { - string_value_ = new ::std::string; - } - return string_value_; -} -inline ::std::string* UninterpretedOption::release_string_value() { - clear_has_string_value(); - if (string_value_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = string_value_; - string_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string aggregate_value = 8; -inline bool UninterpretedOption::has_aggregate_value() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void UninterpretedOption::set_has_aggregate_value() { - _has_bits_[0] |= 0x00000040u; -} -inline void UninterpretedOption::clear_has_aggregate_value() { - _has_bits_[0] &= ~0x00000040u; -} -inline void UninterpretedOption::clear_aggregate_value() { - if (aggregate_value_ != &::google::protobuf::internal::kEmptyString) { - aggregate_value_->clear(); - } - clear_has_aggregate_value(); -} -inline const ::std::string& UninterpretedOption::aggregate_value() const { - return *aggregate_value_; -} -inline void UninterpretedOption::set_aggregate_value(const ::std::string& value) { - set_has_aggregate_value(); - if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { - aggregate_value_ = new ::std::string; - } - aggregate_value_->assign(value); -} -inline void UninterpretedOption::set_aggregate_value(const char* value) { - set_has_aggregate_value(); - if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { - aggregate_value_ = new ::std::string; - } - aggregate_value_->assign(value); -} -inline void UninterpretedOption::set_aggregate_value(const char* value, size_t size) { - set_has_aggregate_value(); - if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { - aggregate_value_ = new ::std::string; - } - aggregate_value_->assign(reinterpret_cast(value), size); -} -inline ::std::string* UninterpretedOption::mutable_aggregate_value() { - set_has_aggregate_value(); - if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { - aggregate_value_ = new ::std::string; - } - return aggregate_value_; -} -inline ::std::string* UninterpretedOption::release_aggregate_value() { - clear_has_aggregate_value(); - if (aggregate_value_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = aggregate_value_; - aggregate_value_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// SourceCodeInfo_Location - -// repeated int32 path = 1 [packed = true]; -inline int SourceCodeInfo_Location::path_size() const { - return path_.size(); -} -inline void SourceCodeInfo_Location::clear_path() { - path_.Clear(); -} -inline ::google::protobuf::int32 SourceCodeInfo_Location::path(int index) const { - return path_.Get(index); -} -inline void SourceCodeInfo_Location::set_path(int index, ::google::protobuf::int32 value) { - path_.Set(index, value); -} -inline void SourceCodeInfo_Location::add_path(::google::protobuf::int32 value) { - path_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -SourceCodeInfo_Location::path() const { - return path_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -SourceCodeInfo_Location::mutable_path() { - return &path_; -} - -// repeated int32 span = 2 [packed = true]; -inline int SourceCodeInfo_Location::span_size() const { - return span_.size(); -} -inline void SourceCodeInfo_Location::clear_span() { - span_.Clear(); -} -inline ::google::protobuf::int32 SourceCodeInfo_Location::span(int index) const { - return span_.Get(index); -} -inline void SourceCodeInfo_Location::set_span(int index, ::google::protobuf::int32 value) { - span_.Set(index, value); -} -inline void SourceCodeInfo_Location::add_span(::google::protobuf::int32 value) { - span_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -SourceCodeInfo_Location::span() const { - return span_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -SourceCodeInfo_Location::mutable_span() { - return &span_; -} - -// ------------------------------------------------------------------- - -// SourceCodeInfo - -// repeated .google.protobuf.SourceCodeInfo.Location location = 1; -inline int SourceCodeInfo::location_size() const { - return location_.size(); -} -inline void SourceCodeInfo::clear_location() { - location_.Clear(); -} -inline const ::google::protobuf::SourceCodeInfo_Location& SourceCodeInfo::location(int index) const { - return location_.Get(index); -} -inline ::google::protobuf::SourceCodeInfo_Location* SourceCodeInfo::mutable_location(int index) { - return location_.Mutable(index); -} -inline ::google::protobuf::SourceCodeInfo_Location* SourceCodeInfo::add_location() { - return location_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >& -SourceCodeInfo::location() const { - return location_; -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >* -SourceCodeInfo::mutable_location() { - return &location_; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldDescriptorProto_Type>() { - return ::google::protobuf::FieldDescriptorProto_Type_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldDescriptorProto_Label>() { - return ::google::protobuf::FieldDescriptorProto_Label_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FileOptions_OptimizeMode>() { - return ::google::protobuf::FileOptions_OptimizeMode_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldOptions_CType>() { - return ::google::protobuf::FieldOptions_CType_descriptor(); -} - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h b/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h deleted file mode 100644 index f32b1db9..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +++ /dev/null @@ -1,366 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Interface for manipulating databases of descriptors. - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ -#define GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ - -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -// Defined in this file. -class DescriptorDatabase; -class SimpleDescriptorDatabase; -class EncodedDescriptorDatabase; -class DescriptorPoolDatabase; -class MergedDescriptorDatabase; - -// Abstract interface for a database of descriptors. -// -// This is useful if you want to create a DescriptorPool which loads -// descriptors on-demand from some sort of large database. If the database -// is large, it may be inefficient to enumerate every .proto file inside it -// calling DescriptorPool::BuildFile() for each one. Instead, a DescriptorPool -// can be created which wraps a DescriptorDatabase and only builds particular -// descriptors when they are needed. -class LIBPROTOBUF_EXPORT DescriptorDatabase { - public: - inline DescriptorDatabase() {} - virtual ~DescriptorDatabase(); - - // Find a file by file name. Fills in in *output and returns true if found. - // Otherwise, returns false, leaving the contents of *output undefined. - virtual bool FindFileByName(const string& filename, - FileDescriptorProto* output) = 0; - - // Find the file that declares the given fully-qualified symbol name. - // If found, fills in *output and returns true, otherwise returns false - // and leaves *output undefined. - virtual bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output) = 0; - - // Find the file which defines an extension extending the given message type - // with the given field number. If found, fills in *output and returns true, - // otherwise returns false and leaves *output undefined. containing_type - // must be a fully-qualified type name. - virtual bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output) = 0; - - // Finds the tag numbers used by all known extensions of - // extendee_type, and appends them to output in an undefined - // order. This method is best-effort: it's not guaranteed that the - // database will find all extensions, and it's not guaranteed that - // FindFileContainingExtension will return true on all of the found - // numbers. Returns true if the search was successful, otherwise - // returns false and leaves output unchanged. - // - // This method has a default implementation that always returns - // false. - virtual bool FindAllExtensionNumbers(const string& extendee_type, - vector* output) { - return false; - } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase); -}; - -// A DescriptorDatabase into which you can insert files manually. -// -// FindFileContainingSymbol() is fully-implemented. When you add a file, its -// symbols will be indexed for this purpose. Note that the implementation -// may return false positives, but only if it isn't possible for the symbol -// to be defined in any other file. In particular, if a file defines a symbol -// "Foo", then searching for "Foo.[anything]" will match that file. This way, -// the database does not need to aggressively index all children of a symbol. -// -// FindFileContainingExtension() is mostly-implemented. It works if and only -// if the original FieldDescriptorProto defining the extension has a -// fully-qualified type name in its "extendee" field (i.e. starts with a '.'). -// If the extendee is a relative name, SimpleDescriptorDatabase will not -// attempt to resolve the type, so it will not know what type the extension is -// extending. Therefore, calling FindFileContainingExtension() with the -// extension's containing type will never actually find that extension. Note -// that this is an unlikely problem, as all FileDescriptorProtos created by the -// protocol compiler (as well as ones created by calling -// FileDescriptor::CopyTo()) will always use fully-qualified names for all -// types. You only need to worry if you are constructing FileDescriptorProtos -// yourself, or are calling compiler::Parser directly. -class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { - public: - SimpleDescriptorDatabase(); - ~SimpleDescriptorDatabase(); - - // Adds the FileDescriptorProto to the database, making a copy. The object - // can be deleted after Add() returns. Returns false if the file conflicted - // with a file already in the database, in which case an error will have - // been written to GOOGLE_LOG(ERROR). - bool Add(const FileDescriptorProto& file); - - // Adds the FileDescriptorProto to the database and takes ownership of it. - bool AddAndOwn(const FileDescriptorProto* file); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - private: - // So that it can use DescriptorIndex. - friend class EncodedDescriptorDatabase; - - // An index mapping file names, symbol names, and extension numbers to - // some sort of values. - template - class DescriptorIndex { - public: - // Helpers to recursively add particular descriptors and all their contents - // to the index. - bool AddFile(const FileDescriptorProto& file, - Value value); - bool AddSymbol(const string& name, Value value); - bool AddNestedExtensions(const DescriptorProto& message_type, - Value value); - bool AddExtension(const FieldDescriptorProto& field, - Value value); - - Value FindFile(const string& filename); - Value FindSymbol(const string& name); - Value FindExtension(const string& containing_type, int field_number); - bool FindAllExtensionNumbers(const string& containing_type, - vector* output); - - private: - map by_name_; - map by_symbol_; - map, Value> by_extension_; - - // Invariant: The by_symbol_ map does not contain any symbols which are - // prefixes of other symbols in the map. For example, "foo.bar" is a - // prefix of "foo.bar.baz" (but is not a prefix of "foo.barbaz"). - // - // This invariant is important because it means that given a symbol name, - // we can find a key in the map which is a prefix of the symbol in O(lg n) - // time, and we know that there is at most one such key. - // - // The prefix lookup algorithm works like so: - // 1) Find the last key in the map which is less than or equal to the - // search key. - // 2) If the found key is a prefix of the search key, then return it. - // Otherwise, there is no match. - // - // I am sure this algorithm has been described elsewhere, but since I - // wasn't able to find it quickly I will instead prove that it works - // myself. The key to the algorithm is that if a match exists, step (1) - // will find it. Proof: - // 1) Define the "search key" to be the key we are looking for, the "found - // key" to be the key found in step (1), and the "match key" to be the - // key which actually matches the serach key (i.e. the key we're trying - // to find). - // 2) The found key must be less than or equal to the search key by - // definition. - // 3) The match key must also be less than or equal to the search key - // (because it is a prefix). - // 4) The match key cannot be greater than the found key, because if it - // were, then step (1) of the algorithm would have returned the match - // key instead (since it finds the *greatest* key which is less than or - // equal to the search key). - // 5) Therefore, the found key must be between the match key and the search - // key, inclusive. - // 6) Since the search key must be a sub-symbol of the match key, if it is - // not equal to the match key, then search_key[match_key.size()] must - // be '.'. - // 7) Since '.' sorts before any other character that is valid in a symbol - // name, then if the found key is not equal to the match key, then - // found_key[match_key.size()] must also be '.', because any other value - // would make it sort after the search key. - // 8) Therefore, if the found key is not equal to the match key, then the - // found key must be a sub-symbol of the match key. However, this would - // contradict our map invariant which says that no symbol in the map is - // a sub-symbol of any other. - // 9) Therefore, the found key must match the match key. - // - // The above proof assumes the match key exists. In the case that the - // match key does not exist, then step (1) will return some other symbol. - // That symbol cannot be a super-symbol of the search key since if it were, - // then it would be a match, and we're assuming the match key doesn't exist. - // Therefore, step 2 will correctly return no match. - - // Find the last entry in the by_symbol_ map whose key is less than or - // equal to the given name. - typename map::iterator FindLastLessOrEqual( - const string& name); - - // True if either the arguments are equal or super_symbol identifies a - // parent symbol of sub_symbol (e.g. "foo.bar" is a parent of - // "foo.bar.baz", but not a parent of "foo.barbaz"). - bool IsSubSymbol(const string& sub_symbol, const string& super_symbol); - - // Returns true if and only if all characters in the name are alphanumerics, - // underscores, or periods. - bool ValidateSymbolName(const string& name); - }; - - - DescriptorIndex index_; - vector files_to_delete_; - - // If file is non-NULL, copy it into *output and return true, otherwise - // return false. - bool MaybeCopy(const FileDescriptorProto* file, - FileDescriptorProto* output); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase); -}; - -// Very similar to SimpleDescriptorDatabase, but stores all the descriptors -// as raw bytes and generally tries to use as little memory as possible. -// -// The same caveats regarding FindFileContainingExtension() apply as with -// SimpleDescriptorDatabase. -class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { - public: - EncodedDescriptorDatabase(); - ~EncodedDescriptorDatabase(); - - // Adds the FileDescriptorProto to the database. The descriptor is provided - // in encoded form. The database does not make a copy of the bytes, nor - // does it take ownership; it's up to the caller to make sure the bytes - // remain valid for the life of the database. Returns false and logs an error - // if the bytes are not a valid FileDescriptorProto or if the file conflicted - // with a file already in the database. - bool Add(const void* encoded_file_descriptor, int size); - - // Like Add(), but makes a copy of the data, so that the caller does not - // need to keep it around. - bool AddCopy(const void* encoded_file_descriptor, int size); - - // Like FindFileContainingSymbol but returns only the name of the file. - bool FindNameOfFileContainingSymbol(const string& symbol_name, - string* output); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - private: - SimpleDescriptorDatabase::DescriptorIndex > index_; - vector files_to_delete_; - - // If encoded_file.first is non-NULL, parse the data into *output and return - // true, otherwise return false. - bool MaybeParse(pair encoded_file, - FileDescriptorProto* output); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase); -}; - -// A DescriptorDatabase that fetches files from a given pool. -class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { - public: - DescriptorPoolDatabase(const DescriptorPool& pool); - ~DescriptorPoolDatabase(); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - private: - const DescriptorPool& pool_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase); -}; - -// A DescriptorDatabase that wraps two or more others. It first searches the -// first database and, if that fails, tries the second, and so on. -class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { - public: - // Merge just two databases. The sources remain property of the caller. - MergedDescriptorDatabase(DescriptorDatabase* source1, - DescriptorDatabase* source2); - // Merge more than two databases. The sources remain property of the caller. - // The vector may be deleted after the constructor returns but the - // DescriptorDatabases need to stick around. - MergedDescriptorDatabase(const vector& sources); - ~MergedDescriptorDatabase(); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - // Merges the results of calling all databases. Returns true iff any - // of the databases returned true. - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - private: - vector sources_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h b/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h deleted file mode 100644 index 81dd2c63..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +++ /dev/null @@ -1,136 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines an implementation of Message which can emulate types which are not -// known at compile-time. - -#ifndef GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ -#define GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ - -#include -#include - -namespace google { -namespace protobuf { - -// Defined in other files. -class Descriptor; // descriptor.h -class DescriptorPool; // descriptor.h - -// Constructs implementations of Message which can emulate types which are not -// known at compile-time. -// -// Sometimes you want to be able to manipulate protocol types that you don't -// know about at compile time. It would be nice to be able to construct -// a Message object which implements the message type given by any arbitrary -// Descriptor. DynamicMessage provides this. -// -// As it turns out, a DynamicMessage needs to construct extra -// information about its type in order to operate. Most of this information -// can be shared between all DynamicMessages of the same type. But, caching -// this information in some sort of global map would be a bad idea, since -// the cached information for a particular descriptor could outlive the -// descriptor itself. To avoid this problem, DynamicMessageFactory -// encapsulates this "cache". All DynamicMessages of the same type created -// from the same factory will share the same support data. Any Descriptors -// used with a particular factory must outlive the factory. -class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { - public: - // Construct a DynamicMessageFactory that will search for extensions in - // the DescriptorPool in which the exendee is defined. - DynamicMessageFactory(); - - // Construct a DynamicMessageFactory that will search for extensions in - // the given DescriptorPool. - // - // DEPRECATED: Use CodedInputStream::SetExtensionRegistry() to tell the - // parser to look for extensions in an alternate pool. However, note that - // this is almost never what you want to do. Almost all users should use - // the zero-arg constructor. - DynamicMessageFactory(const DescriptorPool* pool); - - ~DynamicMessageFactory(); - - // Call this to tell the DynamicMessageFactory that if it is given a - // Descriptor d for which: - // d->file()->pool() == DescriptorPool::generated_pool(), - // then it should delegate to MessageFactory::generated_factory() instead - // of constructing a dynamic implementation of the message. In theory there - // is no down side to doing this, so it may become the default in the future. - void SetDelegateToGeneratedFactory(bool enable) { - delegate_to_generated_factory_ = enable; - } - - // implements MessageFactory --------------------------------------- - - // Given a Descriptor, constructs the default (prototype) Message of that - // type. You can then call that message's New() method to construct a - // mutable message of that type. - // - // Calling this method twice with the same Descriptor returns the same - // object. The returned object remains property of the factory and will - // be destroyed when the factory is destroyed. Also, any objects created - // by calling the prototype's New() method share some data with the - // prototype, so these must be destoyed before the DynamicMessageFactory - // is destroyed. - // - // The given descriptor must outlive the returned message, and hence must - // outlive the DynamicMessageFactory. - // - // The method is thread-safe. - const Message* GetPrototype(const Descriptor* type); - - private: - const DescriptorPool* pool_; - bool delegate_to_generated_factory_; - - // This struct just contains a hash_map. We can't #include from - // this header due to hacks needed for hash_map portability in the open source - // release. Namely, stubs/hash.h, which defines hash_map portably, is not a - // public header (for good reason), but dynamic_message.h is, and public - // headers may only #include other public headers. - struct PrototypeMap; - scoped_ptr prototypes_; - mutable Mutex prototypes_mutex_; - - friend class DynamicMessage; - const Message* GetPrototypeNoLock(const Descriptor* type); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h b/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h deleted file mode 100644 index ac1ada02..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +++ /dev/null @@ -1,904 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_EXTENSION_SET_H__ -#define GOOGLE_PROTOBUF_EXTENSION_SET_H__ - -#include -#include -#include -#include - - -#include - -namespace google { - -namespace protobuf { - class Descriptor; // descriptor.h - class FieldDescriptor; // descriptor.h - class DescriptorPool; // descriptor.h - class MessageLite; // message_lite.h - class Message; // message.h - class MessageFactory; // message.h - class UnknownFieldSet; // unknown_field_set.h - namespace io { - class CodedInputStream; // coded_stream.h - class CodedOutputStream; // coded_stream.h - } - namespace internal { - class FieldSkipper; // wire_format_lite.h - class RepeatedPtrFieldBase; // repeated_field.h - } - template class RepeatedField; // repeated_field.h - template class RepeatedPtrField; // repeated_field.h -} - -namespace protobuf { -namespace internal { - -// Used to store values of type WireFormatLite::FieldType without having to -// #include wire_format_lite.h. Also, ensures that we use only one byte to -// store these values, which is important to keep the layout of -// ExtensionSet::Extension small. -typedef uint8 FieldType; - -// A function which, given an integer value, returns true if the number -// matches one of the defined values for the corresponding enum type. This -// is used with RegisterEnumExtension, below. -typedef bool EnumValidityFunc(int number); - -// Version of the above which takes an argument. This is needed to deal with -// extensions that are not compiled in. -typedef bool EnumValidityFuncWithArg(const void* arg, int number); - -// Information about a registered extension. -struct ExtensionInfo { - inline ExtensionInfo() {} - inline ExtensionInfo(FieldType type, bool is_repeated, bool is_packed) - : type(type), is_repeated(is_repeated), is_packed(is_packed), - descriptor(NULL) {} - - FieldType type; - bool is_repeated; - bool is_packed; - - struct EnumValidityCheck { - EnumValidityFuncWithArg* func; - const void* arg; - }; - - union { - EnumValidityCheck enum_validity_check; - const MessageLite* message_prototype; - }; - - // The descriptor for this extension, if one exists and is known. May be - // NULL. Must not be NULL if the descriptor for the extension does not - // live in the same pool as the descriptor for the containing type. - const FieldDescriptor* descriptor; -}; - -// Abstract interface for an object which looks up extension definitions. Used -// when parsing. -class LIBPROTOBUF_EXPORT ExtensionFinder { - public: - virtual ~ExtensionFinder(); - - // Find the extension with the given containing type and number. - virtual bool Find(int number, ExtensionInfo* output) = 0; -}; - -// Implementation of ExtensionFinder which finds extensions defined in .proto -// files which have been compiled into the binary. -class LIBPROTOBUF_EXPORT GeneratedExtensionFinder : public ExtensionFinder { - public: - GeneratedExtensionFinder(const MessageLite* containing_type) - : containing_type_(containing_type) {} - virtual ~GeneratedExtensionFinder() {} - - // Returns true and fills in *output if found, otherwise returns false. - virtual bool Find(int number, ExtensionInfo* output); - - private: - const MessageLite* containing_type_; -}; - -// Note: extension_set_heavy.cc defines DescriptorPoolExtensionFinder for -// finding extensions from a DescriptorPool. - -// This is an internal helper class intended for use within the protocol buffer -// library and generated classes. Clients should not use it directly. Instead, -// use the generated accessors such as GetExtension() of the class being -// extended. -// -// This class manages extensions for a protocol message object. The -// message's HasExtension(), GetExtension(), MutableExtension(), and -// ClearExtension() methods are just thin wrappers around the embedded -// ExtensionSet. When parsing, if a tag number is encountered which is -// inside one of the message type's extension ranges, the tag is passed -// off to the ExtensionSet for parsing. Etc. -class LIBPROTOBUF_EXPORT ExtensionSet { - public: - ExtensionSet(); - ~ExtensionSet(); - - // These are called at startup by protocol-compiler-generated code to - // register known extensions. The registrations are used by ParseField() - // to look up extensions for parsed field numbers. Note that dynamic parsing - // does not use ParseField(); only protocol-compiler-generated parsing - // methods do. - static void RegisterExtension(const MessageLite* containing_type, - int number, FieldType type, - bool is_repeated, bool is_packed); - static void RegisterEnumExtension(const MessageLite* containing_type, - int number, FieldType type, - bool is_repeated, bool is_packed, - EnumValidityFunc* is_valid); - static void RegisterMessageExtension(const MessageLite* containing_type, - int number, FieldType type, - bool is_repeated, bool is_packed, - const MessageLite* prototype); - - // ================================================================= - - // Add all fields which are currently present to the given vector. This - // is useful to implement Reflection::ListFields(). - void AppendToList(const Descriptor* containing_type, - const DescriptorPool* pool, - vector* output) const; - - // ================================================================= - // Accessors - // - // Generated message classes include type-safe templated wrappers around - // these methods. Generally you should use those rather than call these - // directly, unless you are doing low-level memory management. - // - // When calling any of these accessors, the extension number requested - // MUST exist in the DescriptorPool provided to the constructor. Otheriwse, - // the method will fail an assert. Normally, though, you would not call - // these directly; you would either call the generated accessors of your - // message class (e.g. GetExtension()) or you would call the accessors - // of the reflection interface. In both cases, it is impossible to - // trigger this assert failure: the generated accessors only accept - // linked-in extension types as parameters, while the Reflection interface - // requires you to provide the FieldDescriptor describing the extension. - // - // When calling any of these accessors, a protocol-compiler-generated - // implementation of the extension corresponding to the number MUST - // be linked in, and the FieldDescriptor used to refer to it MUST be - // the one generated by that linked-in code. Otherwise, the method will - // die on an assert failure. The message objects returned by the message - // accessors are guaranteed to be of the correct linked-in type. - // - // These methods pretty much match Reflection except that: - // - They're not virtual. - // - They identify fields by number rather than FieldDescriptors. - // - They identify enum values using integers rather than descriptors. - // - Strings provide Mutable() in addition to Set() accessors. - - bool Has(int number) const; - int ExtensionSize(int number) const; // Size of a repeated extension. - FieldType ExtensionType(int number) const; - void ClearExtension(int number); - - // singular fields ------------------------------------------------- - - int32 GetInt32 (int number, int32 default_value) const; - int64 GetInt64 (int number, int64 default_value) const; - uint32 GetUInt32(int number, uint32 default_value) const; - uint64 GetUInt64(int number, uint64 default_value) const; - float GetFloat (int number, float default_value) const; - double GetDouble(int number, double default_value) const; - bool GetBool (int number, bool default_value) const; - int GetEnum (int number, int default_value) const; - const string & GetString (int number, const string& default_value) const; - const MessageLite& GetMessage(int number, - const MessageLite& default_value) const; - const MessageLite& GetMessage(int number, const Descriptor* message_type, - MessageFactory* factory) const; - - // |descriptor| may be NULL so long as it is known that the descriptor for - // the extension lives in the same pool as the descriptor for the containing - // type. -#define desc const FieldDescriptor* descriptor // avoid line wrapping - void SetInt32 (int number, FieldType type, int32 value, desc); - void SetInt64 (int number, FieldType type, int64 value, desc); - void SetUInt32(int number, FieldType type, uint32 value, desc); - void SetUInt64(int number, FieldType type, uint64 value, desc); - void SetFloat (int number, FieldType type, float value, desc); - void SetDouble(int number, FieldType type, double value, desc); - void SetBool (int number, FieldType type, bool value, desc); - void SetEnum (int number, FieldType type, int value, desc); - void SetString(int number, FieldType type, const string& value, desc); - string * MutableString (int number, FieldType type, desc); - MessageLite* MutableMessage(int number, FieldType type, - const MessageLite& prototype, desc); - MessageLite* MutableMessage(const FieldDescriptor* decsriptor, - MessageFactory* factory); -#undef desc - - // repeated fields ------------------------------------------------- - - int32 GetRepeatedInt32 (int number, int index) const; - int64 GetRepeatedInt64 (int number, int index) const; - uint32 GetRepeatedUInt32(int number, int index) const; - uint64 GetRepeatedUInt64(int number, int index) const; - float GetRepeatedFloat (int number, int index) const; - double GetRepeatedDouble(int number, int index) const; - bool GetRepeatedBool (int number, int index) const; - int GetRepeatedEnum (int number, int index) const; - const string & GetRepeatedString (int number, int index) const; - const MessageLite& GetRepeatedMessage(int number, int index) const; - - void SetRepeatedInt32 (int number, int index, int32 value); - void SetRepeatedInt64 (int number, int index, int64 value); - void SetRepeatedUInt32(int number, int index, uint32 value); - void SetRepeatedUInt64(int number, int index, uint64 value); - void SetRepeatedFloat (int number, int index, float value); - void SetRepeatedDouble(int number, int index, double value); - void SetRepeatedBool (int number, int index, bool value); - void SetRepeatedEnum (int number, int index, int value); - void SetRepeatedString(int number, int index, const string& value); - string * MutableRepeatedString (int number, int index); - MessageLite* MutableRepeatedMessage(int number, int index); - -#define desc const FieldDescriptor* descriptor // avoid line wrapping - void AddInt32 (int number, FieldType type, bool packed, int32 value, desc); - void AddInt64 (int number, FieldType type, bool packed, int64 value, desc); - void AddUInt32(int number, FieldType type, bool packed, uint32 value, desc); - void AddUInt64(int number, FieldType type, bool packed, uint64 value, desc); - void AddFloat (int number, FieldType type, bool packed, float value, desc); - void AddDouble(int number, FieldType type, bool packed, double value, desc); - void AddBool (int number, FieldType type, bool packed, bool value, desc); - void AddEnum (int number, FieldType type, bool packed, int value, desc); - void AddString(int number, FieldType type, const string& value, desc); - string * AddString (int number, FieldType type, desc); - MessageLite* AddMessage(int number, FieldType type, - const MessageLite& prototype, desc); - MessageLite* AddMessage(const FieldDescriptor* descriptor, - MessageFactory* factory); -#undef desc - - void RemoveLast(int number); - void SwapElements(int number, int index1, int index2); - - // ----------------------------------------------------------------- - // TODO(kenton): Hardcore memory management accessors - - // ================================================================= - // convenience methods for implementing methods of Message - // - // These could all be implemented in terms of the other methods of this - // class, but providing them here helps keep the generated code size down. - - void Clear(); - void MergeFrom(const ExtensionSet& other); - void Swap(ExtensionSet* other); - bool IsInitialized() const; - - // Parses a single extension from the input. The input should start out - // positioned immediately after the tag. |containing_type| is the default - // instance for the containing message; it is used only to look up the - // extension by number. See RegisterExtension(), above. Unlike the other - // methods of ExtensionSet, this only works for generated message types -- - // it looks up extensions registered using RegisterExtension(). - bool ParseField(uint32 tag, io::CodedInputStream* input, - ExtensionFinder* extension_finder, - FieldSkipper* field_skipper); - - // Specific versions for lite or full messages (constructs the appropriate - // FieldSkipper automatically). - bool ParseField(uint32 tag, io::CodedInputStream* input, - const MessageLite* containing_type); - bool ParseField(uint32 tag, io::CodedInputStream* input, - const Message* containing_type, - UnknownFieldSet* unknown_fields); - - // Parse an entire message in MessageSet format. Such messages have no - // fields, only extensions. - bool ParseMessageSet(io::CodedInputStream* input, - ExtensionFinder* extension_finder, - FieldSkipper* field_skipper); - - // Specific versions for lite or full messages (constructs the appropriate - // FieldSkipper automatically). - bool ParseMessageSet(io::CodedInputStream* input, - const MessageLite* containing_type); - bool ParseMessageSet(io::CodedInputStream* input, - const Message* containing_type, - UnknownFieldSet* unknown_fields); - - // Write all extension fields with field numbers in the range - // [start_field_number, end_field_number) - // to the output stream, using the cached sizes computed when ByteSize() was - // last called. Note that the range bounds are inclusive-exclusive. - void SerializeWithCachedSizes(int start_field_number, - int end_field_number, - io::CodedOutputStream* output) const; - - // Same as SerializeWithCachedSizes, but without any bounds checking. - // The caller must ensure that target has sufficient capacity for the - // serialized extensions. - // - // Returns a pointer past the last written byte. - uint8* SerializeWithCachedSizesToArray(int start_field_number, - int end_field_number, - uint8* target) const; - - // Like above but serializes in MessageSet format. - void SerializeMessageSetWithCachedSizes(io::CodedOutputStream* output) const; - uint8* SerializeMessageSetWithCachedSizesToArray(uint8* target) const; - - // Returns the total serialized size of all the extensions. - int ByteSize() const; - - // Like ByteSize() but uses MessageSet format. - int MessageSetByteSize() const; - - // Returns (an estimate of) the total number of bytes used for storing the - // extensions in memory, excluding sizeof(*this). If the ExtensionSet is - // for a lite message (and thus possibly contains lite messages), the results - // are undefined (might work, might crash, might corrupt data, might not even - // be linked in). It's up to the protocol compiler to avoid calling this on - // such ExtensionSets (easy enough since lite messages don't implement - // SpaceUsed()). - int SpaceUsedExcludingSelf() const; - - private: - - struct Extension { - union { - int32 int32_value; - int64 int64_value; - uint32 uint32_value; - uint64 uint64_value; - float float_value; - double double_value; - bool bool_value; - int enum_value; - string* string_value; - MessageLite* message_value; - - RepeatedField * repeated_int32_value; - RepeatedField * repeated_int64_value; - RepeatedField * repeated_uint32_value; - RepeatedField * repeated_uint64_value; - RepeatedField * repeated_float_value; - RepeatedField * repeated_double_value; - RepeatedField * repeated_bool_value; - RepeatedField * repeated_enum_value; - RepeatedPtrField* repeated_string_value; - RepeatedPtrField* repeated_message_value; - }; - - FieldType type; - bool is_repeated; - - // For singular types, indicates if the extension is "cleared". This - // happens when an extension is set and then later cleared by the caller. - // We want to keep the Extension object around for reuse, so instead of - // removing it from the map, we just set is_cleared = true. This has no - // meaning for repeated types; for those, the size of the RepeatedField - // simply becomes zero when cleared. - bool is_cleared; - - // For repeated types, this indicates if the [packed=true] option is set. - bool is_packed; - - // The descriptor for this extension, if one exists and is known. May be - // NULL. Must not be NULL if the descriptor for the extension does not - // live in the same pool as the descriptor for the containing type. - const FieldDescriptor* descriptor; - - // For packed fields, the size of the packed data is recorded here when - // ByteSize() is called then used during serialization. - // TODO(kenton): Use atomic when C++ supports it. - mutable int cached_size; - - // Some helper methods for operations on a single Extension. - void SerializeFieldWithCachedSizes( - int number, - io::CodedOutputStream* output) const; - uint8* SerializeFieldWithCachedSizesToArray( - int number, - uint8* target) const; - void SerializeMessageSetItemWithCachedSizes( - int number, - io::CodedOutputStream* output) const; - uint8* SerializeMessageSetItemWithCachedSizesToArray( - int number, - uint8* target) const; - int ByteSize(int number) const; - int MessageSetItemByteSize(int number) const; - void Clear(); - int GetSize() const; - void Free(); - int SpaceUsedExcludingSelf() const; - }; - - - // Gets the extension with the given number, creating it if it does not - // already exist. Returns true if the extension did not already exist. - bool MaybeNewExtension(int number, const FieldDescriptor* descriptor, - Extension** result); - - // Parse a single MessageSet item -- called just after the item group start - // tag has been read. - bool ParseMessageSetItem(io::CodedInputStream* input, - ExtensionFinder* extension_finder, - FieldSkipper* field_skipper); - - - // Hack: RepeatedPtrFieldBase declares ExtensionSet as a friend. This - // friendship should automatically extend to ExtensionSet::Extension, but - // unfortunately some older compilers (e.g. GCC 3.4.4) do not implement this - // correctly. So, we must provide helpers for calling methods of that - // class. - - // Defined in extension_set_heavy.cc. - static inline int RepeatedMessage_SpaceUsedExcludingSelf( - RepeatedPtrFieldBase* field); - - // The Extension struct is small enough to be passed by value, so we use it - // directly as the value type in the map rather than use pointers. We use - // a map rather than hash_map here because we expect most ExtensionSets will - // only contain a small number of extensions whereas hash_map is optimized - // for 100 elements or more. Also, we want AppendToList() to order fields - // by field number. - map extensions_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionSet); -}; - -// These are just for convenience... -inline void ExtensionSet::SetString(int number, FieldType type, - const string& value, - const FieldDescriptor* descriptor) { - MutableString(number, type, descriptor)->assign(value); -} -inline void ExtensionSet::SetRepeatedString(int number, int index, - const string& value) { - MutableRepeatedString(number, index)->assign(value); -} -inline void ExtensionSet::AddString(int number, FieldType type, - const string& value, - const FieldDescriptor* descriptor) { - AddString(number, type, descriptor)->assign(value); -} - -// =================================================================== -// Glue for generated extension accessors - -// ------------------------------------------------------------------- -// Template magic - -// First we have a set of classes representing "type traits" for different -// field types. A type traits class knows how to implement basic accessors -// for extensions of a particular type given an ExtensionSet. The signature -// for a type traits class looks like this: -// -// class TypeTraits { -// public: -// typedef ? ConstType; -// typedef ? MutableType; -// -// static inline ConstType Get(int number, const ExtensionSet& set); -// static inline void Set(int number, ConstType value, ExtensionSet* set); -// static inline MutableType Mutable(int number, ExtensionSet* set); -// -// // Variants for repeated fields. -// static inline ConstType Get(int number, const ExtensionSet& set, -// int index); -// static inline void Set(int number, int index, -// ConstType value, ExtensionSet* set); -// static inline MutableType Mutable(int number, int index, -// ExtensionSet* set); -// static inline void Add(int number, ConstType value, ExtensionSet* set); -// static inline MutableType Add(int number, ExtensionSet* set); -// }; -// -// Not all of these methods make sense for all field types. For example, the -// "Mutable" methods only make sense for strings and messages, and the -// repeated methods only make sense for repeated types. So, each type -// traits class implements only the set of methods from this signature that it -// actually supports. This will cause a compiler error if the user tries to -// access an extension using a method that doesn't make sense for its type. -// For example, if "foo" is an extension of type "optional int32", then if you -// try to write code like: -// my_message.MutableExtension(foo) -// you will get a compile error because PrimitiveTypeTraits does not -// have a "Mutable()" method. - -// ------------------------------------------------------------------- -// PrimitiveTypeTraits - -// Since the ExtensionSet has different methods for each primitive type, -// we must explicitly define the methods of the type traits class for each -// known type. -template -class PrimitiveTypeTraits { - public: - typedef Type ConstType; - - static inline ConstType Get(int number, const ExtensionSet& set, - ConstType default_value); - static inline void Set(int number, FieldType field_type, - ConstType value, ExtensionSet* set); -}; - -template -class RepeatedPrimitiveTypeTraits { - public: - typedef Type ConstType; - - static inline Type Get(int number, const ExtensionSet& set, int index); - static inline void Set(int number, int index, Type value, ExtensionSet* set); - static inline void Add(int number, FieldType field_type, - bool is_packed, Type value, ExtensionSet* set); -}; - -#define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \ -template<> inline TYPE PrimitiveTypeTraits::Get( \ - int number, const ExtensionSet& set, TYPE default_value) { \ - return set.Get##METHOD(number, default_value); \ -} \ -template<> inline void PrimitiveTypeTraits::Set( \ - int number, FieldType field_type, TYPE value, ExtensionSet* set) { \ - set->Set##METHOD(number, field_type, value, NULL); \ -} \ - \ -template<> inline TYPE RepeatedPrimitiveTypeTraits::Get( \ - int number, const ExtensionSet& set, int index) { \ - return set.GetRepeated##METHOD(number, index); \ -} \ -template<> inline void RepeatedPrimitiveTypeTraits::Set( \ - int number, int index, TYPE value, ExtensionSet* set) { \ - set->SetRepeated##METHOD(number, index, value); \ -} \ -template<> inline void RepeatedPrimitiveTypeTraits::Add( \ - int number, FieldType field_type, bool is_packed, \ - TYPE value, ExtensionSet* set) { \ - set->Add##METHOD(number, field_type, is_packed, value, NULL); \ -} - -PROTOBUF_DEFINE_PRIMITIVE_TYPE( int32, Int32) -PROTOBUF_DEFINE_PRIMITIVE_TYPE( int64, Int64) -PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint32, UInt32) -PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint64, UInt64) -PROTOBUF_DEFINE_PRIMITIVE_TYPE( float, Float) -PROTOBUF_DEFINE_PRIMITIVE_TYPE(double, Double) -PROTOBUF_DEFINE_PRIMITIVE_TYPE( bool, Bool) - -#undef PROTOBUF_DEFINE_PRIMITIVE_TYPE - -// ------------------------------------------------------------------- -// StringTypeTraits - -// Strings support both Set() and Mutable(). -class LIBPROTOBUF_EXPORT StringTypeTraits { - public: - typedef const string& ConstType; - typedef string* MutableType; - - static inline const string& Get(int number, const ExtensionSet& set, - ConstType default_value) { - return set.GetString(number, default_value); - } - static inline void Set(int number, FieldType field_type, - const string& value, ExtensionSet* set) { - set->SetString(number, field_type, value, NULL); - } - static inline string* Mutable(int number, FieldType field_type, - ExtensionSet* set) { - return set->MutableString(number, field_type, NULL); - } -}; - -class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { - public: - typedef const string& ConstType; - typedef string* MutableType; - - static inline const string& Get(int number, const ExtensionSet& set, - int index) { - return set.GetRepeatedString(number, index); - } - static inline void Set(int number, int index, - const string& value, ExtensionSet* set) { - set->SetRepeatedString(number, index, value); - } - static inline string* Mutable(int number, int index, ExtensionSet* set) { - return set->MutableRepeatedString(number, index); - } - static inline void Add(int number, FieldType field_type, - bool /*is_packed*/, const string& value, - ExtensionSet* set) { - set->AddString(number, field_type, value, NULL); - } - static inline string* Add(int number, FieldType field_type, - ExtensionSet* set) { - return set->AddString(number, field_type, NULL); - } -}; - -// ------------------------------------------------------------------- -// EnumTypeTraits - -// ExtensionSet represents enums using integers internally, so we have to -// static_cast around. -template -class EnumTypeTraits { - public: - typedef Type ConstType; - - static inline ConstType Get(int number, const ExtensionSet& set, - ConstType default_value) { - return static_cast(set.GetEnum(number, default_value)); - } - static inline void Set(int number, FieldType field_type, - ConstType value, ExtensionSet* set) { - GOOGLE_DCHECK(IsValid(value)); - set->SetEnum(number, field_type, value, NULL); - } -}; - -template -class RepeatedEnumTypeTraits { - public: - typedef Type ConstType; - - static inline ConstType Get(int number, const ExtensionSet& set, int index) { - return static_cast(set.GetRepeatedEnum(number, index)); - } - static inline void Set(int number, int index, - ConstType value, ExtensionSet* set) { - GOOGLE_DCHECK(IsValid(value)); - set->SetRepeatedEnum(number, index, value); - } - static inline void Add(int number, FieldType field_type, - bool is_packed, ConstType value, ExtensionSet* set) { - GOOGLE_DCHECK(IsValid(value)); - set->AddEnum(number, field_type, is_packed, value, NULL); - } -}; - -// ------------------------------------------------------------------- -// MessageTypeTraits - -// ExtensionSet guarantees that when manipulating extensions with message -// types, the implementation used will be the compiled-in class representing -// that type. So, we can static_cast down to the exact type we expect. -template -class MessageTypeTraits { - public: - typedef const Type& ConstType; - typedef Type* MutableType; - - static inline ConstType Get(int number, const ExtensionSet& set, - ConstType default_value) { - return static_cast( - set.GetMessage(number, default_value)); - } - static inline MutableType Mutable(int number, FieldType field_type, - ExtensionSet* set) { - return static_cast( - set->MutableMessage(number, field_type, Type::default_instance(), NULL)); - } -}; - -template -class RepeatedMessageTypeTraits { - public: - typedef const Type& ConstType; - typedef Type* MutableType; - - static inline ConstType Get(int number, const ExtensionSet& set, int index) { - return static_cast(set.GetRepeatedMessage(number, index)); - } - static inline MutableType Mutable(int number, int index, ExtensionSet* set) { - return static_cast(set->MutableRepeatedMessage(number, index)); - } - static inline MutableType Add(int number, FieldType field_type, - ExtensionSet* set) { - return static_cast( - set->AddMessage(number, field_type, Type::default_instance(), NULL)); - } -}; - -// ------------------------------------------------------------------- -// ExtensionIdentifier - -// This is the type of actual extension objects. E.g. if you have: -// extends Foo with optional int32 bar = 1234; -// then "bar" will be defined in C++ as: -// ExtensionIdentifier, 1, false> bar(1234); -// -// Note that we could, in theory, supply the field number as a template -// parameter, and thus make an instance of ExtensionIdentifier have no -// actual contents. However, if we did that, then using at extension -// identifier would not necessarily cause the compiler to output any sort -// of reference to any simple defined in the extension's .pb.o file. Some -// linkers will actually drop object files that are not explicitly referenced, -// but that would be bad because it would cause this extension to not be -// registered at static initialization, and therefore using it would crash. - -template -class ExtensionIdentifier { - public: - typedef TypeTraitsType TypeTraits; - typedef ExtendeeType Extendee; - - ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value) - : number_(number), default_value_(default_value) {} - inline int number() const { return number_; } - typename TypeTraits::ConstType default_value() const { - return default_value_; - } - - private: - const int number_; - typename TypeTraits::ConstType default_value_; -}; - -// ------------------------------------------------------------------- -// Generated accessors - -// This macro should be expanded in the context of a generated type which -// has extensions. -// -// We use "_proto_TypeTraits" as a type name below because "TypeTraits" -// causes problems if the class has a nested message or enum type with that -// name and "_TypeTraits" is technically reserved for the C++ library since -// it starts with an underscore followed by a capital letter. -#define GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(CLASSNAME) \ - /* Has, Size, Clear */ \ - template \ - inline bool HasExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) const { \ - return _extensions_.Has(id.number()); \ - } \ - \ - template \ - inline void ClearExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) { \ - _extensions_.ClearExtension(id.number()); \ - } \ - \ - template \ - inline int ExtensionSize( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) const { \ - return _extensions_.ExtensionSize(id.number()); \ - } \ - \ - /* Singular accessors */ \ - template \ - inline typename _proto_TypeTraits::ConstType GetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) const { \ - return _proto_TypeTraits::Get(id.number(), _extensions_, \ - id.default_value()); \ - } \ - \ - template \ - inline typename _proto_TypeTraits::MutableType MutableExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) { \ - return _proto_TypeTraits::Mutable(id.number(), field_type, &_extensions_);\ - } \ - \ - template \ - inline void SetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ - typename _proto_TypeTraits::ConstType value) { \ - _proto_TypeTraits::Set(id.number(), field_type, value, &_extensions_); \ - } \ - \ - /* Repeated accessors */ \ - template \ - inline typename _proto_TypeTraits::ConstType GetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ - int index) const { \ - return _proto_TypeTraits::Get(id.number(), _extensions_, index); \ - } \ - \ - template \ - inline typename _proto_TypeTraits::MutableType MutableExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ - int index) { \ - return _proto_TypeTraits::Mutable(id.number(), index, &_extensions_); \ - } \ - \ - template \ - inline void SetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ - int index, typename _proto_TypeTraits::ConstType value) { \ - _proto_TypeTraits::Set(id.number(), index, value, &_extensions_); \ - } \ - \ - template \ - inline typename _proto_TypeTraits::MutableType AddExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id) { \ - return _proto_TypeTraits::Add(id.number(), field_type, &_extensions_); \ - } \ - \ - template \ - inline void AddExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, field_type, is_packed>& id, \ - typename _proto_TypeTraits::ConstType value) { \ - _proto_TypeTraits::Add(id.number(), field_type, is_packed, \ - value, &_extensions_); \ - } - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h b/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h deleted file mode 100644 index b545fa1a..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +++ /dev/null @@ -1,424 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ - -#include -#include -#include -#include - - -namespace google { -namespace protobuf { - class DescriptorPool; - // Generated code needs these to have been forward-declared. Easier to do it - // here than to print them inside every .pb.h file. - class FileDescriptor; - class EnumDescriptor; -} - -namespace protobuf { -namespace internal { - -// Defined in this file. -class GeneratedMessageReflection; - -// Defined in other files. -class ExtensionSet; // extension_set.h - -// THIS CLASS IS NOT INTENDED FOR DIRECT USE. It is intended for use -// by generated code. This class is just a big hack that reduces code -// size. -// -// A GeneratedMessageReflection is an implementation of Reflection -// which expects all fields to be backed by simple variables located in -// memory. The locations are given using a base pointer and a set of -// offsets. -// -// It is required that the user represents fields of each type in a standard -// way, so that GeneratedMessageReflection can cast the void* pointer to -// the appropriate type. For primitive fields and string fields, each field -// should be represented using the obvious C++ primitive type. Enums and -// Messages are different: -// - Singular Message fields are stored as a pointer to a Message. These -// should start out NULL, except for in the default instance where they -// should start out pointing to other default instances. -// - Enum fields are stored as an int. This int must always contain -// a valid value, such that EnumDescriptor::FindValueByNumber() would -// not return NULL. -// - Repeated fields are stored as RepeatedFields or RepeatedPtrFields -// of whatever type the individual field would be. Strings and -// Messages use RepeatedPtrFields while everything else uses -// RepeatedFields. -class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection { - public: - // Constructs a GeneratedMessageReflection. - // Parameters: - // descriptor: The descriptor for the message type being implemented. - // default_instance: The default instance of the message. This is only - // used to obtain pointers to default instances of embedded - // messages, which GetMessage() will return if the particular - // sub-message has not been initialized yet. (Thus, all - // embedded message fields *must* have non-NULL pointers - // in the default instance.) - // offsets: An array of ints giving the byte offsets, relative to - // the start of the message object, of each field. These can - // be computed at compile time using the - // GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro, defined - // below. - // has_bits_offset: Offset in the message of an array of uint32s of size - // descriptor->field_count()/32, rounded up. This is a - // bitfield where each bit indicates whether or not the - // corresponding field of the message has been initialized. - // The bit for field index i is obtained by the expression: - // has_bits[i / 32] & (1 << (i % 32)) - // unknown_fields_offset: Offset in the message of the UnknownFieldSet for - // the message. - // extensions_offset: Offset in the message of the ExtensionSet for the - // message, or -1 if the message type has no extension - // ranges. - // pool: DescriptorPool to search for extension definitions. Only - // used by FindKnownExtensionByName() and - // FindKnownExtensionByNumber(). - // factory: MessageFactory to use to construct extension messages. - // object_size: The size of a message object of this type, as measured - // by sizeof(). - GeneratedMessageReflection(const Descriptor* descriptor, - const Message* default_instance, - const int offsets[], - int has_bits_offset, - int unknown_fields_offset, - int extensions_offset, - const DescriptorPool* pool, - MessageFactory* factory, - int object_size); - ~GeneratedMessageReflection(); - - // implements Reflection ------------------------------------------- - - const UnknownFieldSet& GetUnknownFields(const Message& message) const; - UnknownFieldSet* MutableUnknownFields(Message* message) const; - - int SpaceUsed(const Message& message) const; - - bool HasField(const Message& message, const FieldDescriptor* field) const; - int FieldSize(const Message& message, const FieldDescriptor* field) const; - void ClearField(Message* message, const FieldDescriptor* field) const; - void RemoveLast(Message* message, const FieldDescriptor* field) const; - void Swap(Message* message1, Message* message2) const; - void SwapElements(Message* message, const FieldDescriptor* field, - int index1, int index2) const; - void ListFields(const Message& message, - vector* output) const; - - int32 GetInt32 (const Message& message, - const FieldDescriptor* field) const; - int64 GetInt64 (const Message& message, - const FieldDescriptor* field) const; - uint32 GetUInt32(const Message& message, - const FieldDescriptor* field) const; - uint64 GetUInt64(const Message& message, - const FieldDescriptor* field) const; - float GetFloat (const Message& message, - const FieldDescriptor* field) const; - double GetDouble(const Message& message, - const FieldDescriptor* field) const; - bool GetBool (const Message& message, - const FieldDescriptor* field) const; - string GetString(const Message& message, - const FieldDescriptor* field) const; - const string& GetStringReference(const Message& message, - const FieldDescriptor* field, - string* scratch) const; - const EnumValueDescriptor* GetEnum(const Message& message, - const FieldDescriptor* field) const; - const Message& GetMessage(const Message& message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - - void SetInt32 (Message* message, - const FieldDescriptor* field, int32 value) const; - void SetInt64 (Message* message, - const FieldDescriptor* field, int64 value) const; - void SetUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const; - void SetUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const; - void SetFloat (Message* message, - const FieldDescriptor* field, float value) const; - void SetDouble(Message* message, - const FieldDescriptor* field, double value) const; - void SetBool (Message* message, - const FieldDescriptor* field, bool value) const; - void SetString(Message* message, - const FieldDescriptor* field, - const string& value) const; - void SetEnum (Message* message, const FieldDescriptor* field, - const EnumValueDescriptor* value) const; - Message* MutableMessage(Message* message, const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - - int32 GetRepeatedInt32 (const Message& message, - const FieldDescriptor* field, int index) const; - int64 GetRepeatedInt64 (const Message& message, - const FieldDescriptor* field, int index) const; - uint32 GetRepeatedUInt32(const Message& message, - const FieldDescriptor* field, int index) const; - uint64 GetRepeatedUInt64(const Message& message, - const FieldDescriptor* field, int index) const; - float GetRepeatedFloat (const Message& message, - const FieldDescriptor* field, int index) const; - double GetRepeatedDouble(const Message& message, - const FieldDescriptor* field, int index) const; - bool GetRepeatedBool (const Message& message, - const FieldDescriptor* field, int index) const; - string GetRepeatedString(const Message& message, - const FieldDescriptor* field, int index) const; - const string& GetRepeatedStringReference(const Message& message, - const FieldDescriptor* field, - int index, string* scratch) const; - const EnumValueDescriptor* GetRepeatedEnum(const Message& message, - const FieldDescriptor* field, - int index) const; - const Message& GetRepeatedMessage(const Message& message, - const FieldDescriptor* field, - int index) const; - - // Set the value of a field. - void SetRepeatedInt32 (Message* message, - const FieldDescriptor* field, int index, int32 value) const; - void SetRepeatedInt64 (Message* message, - const FieldDescriptor* field, int index, int64 value) const; - void SetRepeatedUInt32(Message* message, - const FieldDescriptor* field, int index, uint32 value) const; - void SetRepeatedUInt64(Message* message, - const FieldDescriptor* field, int index, uint64 value) const; - void SetRepeatedFloat (Message* message, - const FieldDescriptor* field, int index, float value) const; - void SetRepeatedDouble(Message* message, - const FieldDescriptor* field, int index, double value) const; - void SetRepeatedBool (Message* message, - const FieldDescriptor* field, int index, bool value) const; - void SetRepeatedString(Message* message, - const FieldDescriptor* field, int index, - const string& value) const; - void SetRepeatedEnum(Message* message, const FieldDescriptor* field, - int index, const EnumValueDescriptor* value) const; - // Get a mutable pointer to a field with a message type. - Message* MutableRepeatedMessage(Message* message, - const FieldDescriptor* field, - int index) const; - - void AddInt32 (Message* message, - const FieldDescriptor* field, int32 value) const; - void AddInt64 (Message* message, - const FieldDescriptor* field, int64 value) const; - void AddUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const; - void AddUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const; - void AddFloat (Message* message, - const FieldDescriptor* field, float value) const; - void AddDouble(Message* message, - const FieldDescriptor* field, double value) const; - void AddBool (Message* message, - const FieldDescriptor* field, bool value) const; - void AddString(Message* message, - const FieldDescriptor* field, const string& value) const; - void AddEnum(Message* message, - const FieldDescriptor* field, - const EnumValueDescriptor* value) const; - Message* AddMessage(Message* message, const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - - const FieldDescriptor* FindKnownExtensionByName(const string& name) const; - const FieldDescriptor* FindKnownExtensionByNumber(int number) const; - - private: - friend class GeneratedMessage; - - const Descriptor* descriptor_; - const Message* default_instance_; - const int* offsets_; - - int has_bits_offset_; - int unknown_fields_offset_; - int extensions_offset_; - int object_size_; - - const DescriptorPool* descriptor_pool_; - MessageFactory* message_factory_; - - template - inline const Type& GetRaw(const Message& message, - const FieldDescriptor* field) const; - template - inline Type* MutableRaw(Message* message, - const FieldDescriptor* field) const; - template - inline const Type& DefaultRaw(const FieldDescriptor* field) const; - inline const Message* GetMessagePrototype(const FieldDescriptor* field) const; - - inline const uint32* GetHasBits(const Message& message) const; - inline uint32* MutableHasBits(Message* message) const; - inline const ExtensionSet& GetExtensionSet(const Message& message) const; - inline ExtensionSet* MutableExtensionSet(Message* message) const; - - inline bool HasBit(const Message& message, - const FieldDescriptor* field) const; - inline void SetBit(Message* message, - const FieldDescriptor* field) const; - inline void ClearBit(Message* message, - const FieldDescriptor* field) const; - - template - inline const Type& GetField(const Message& message, - const FieldDescriptor* field) const; - template - inline void SetField(Message* message, - const FieldDescriptor* field, const Type& value) const; - template - inline Type* MutableField(Message* message, - const FieldDescriptor* field) const; - template - inline const Type& GetRepeatedField(const Message& message, - const FieldDescriptor* field, - int index) const; - template - inline const Type& GetRepeatedPtrField(const Message& message, - const FieldDescriptor* field, - int index) const; - template - inline void SetRepeatedField(Message* message, - const FieldDescriptor* field, int index, - Type value) const; - template - inline Type* MutableRepeatedField(Message* message, - const FieldDescriptor* field, - int index) const; - template - inline void AddField(Message* message, - const FieldDescriptor* field, const Type& value) const; - template - inline Type* AddField(Message* message, - const FieldDescriptor* field) const; - - int GetExtensionNumberOrDie(const Descriptor* type) const; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratedMessageReflection); -}; - -// Returns the offset of the given field within the given aggregate type. -// This is equivalent to the ANSI C offsetof() macro. However, according -// to the C++ standard, offsetof() only works on POD types, and GCC -// enforces this requirement with a warning. In practice, this rule is -// unnecessarily strict; there is probably no compiler or platform on -// which the offsets of the direct fields of a class are non-constant. -// Fields inherited from superclasses *can* have non-constant offsets, -// but that's not what this macro will be used for. -// -// Note that we calculate relative to the pointer value 16 here since if we -// just use zero, GCC complains about dereferencing a NULL pointer. We -// choose 16 rather than some other number just in case the compiler would -// be confused by an unaligned pointer. -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ - static_cast( \ - reinterpret_cast( \ - &reinterpret_cast(16)->FIELD) - \ - reinterpret_cast(16)) - -// There are some places in proto2 where dynamic_cast would be useful as an -// optimization. For example, take Message::MergeFrom(const Message& other). -// For a given generated message FooMessage, we generate these two methods: -// void MergeFrom(const FooMessage& other); -// void MergeFrom(const Message& other); -// The former method can be implemented directly in terms of FooMessage's -// inline accessors, but the latter method must work with the reflection -// interface. However, if the parameter to the latter method is actually of -// type FooMessage, then we'd like to be able to just call the other method -// as an optimization. So, we use dynamic_cast to check this. -// -// That said, dynamic_cast requires RTTI, which many people like to disable -// for performance and code size reasons. When RTTI is not available, we -// still need to produce correct results. So, in this case we have to fall -// back to using reflection, which is what we would have done anyway if the -// objects were not of the exact same class. -// -// dynamic_cast_if_available() implements this logic. If RTTI is -// enabled, it does a dynamic_cast. If RTTI is disabled, it just returns -// NULL. -// -// If you need to compile without RTTI, simply #define GOOGLE_PROTOBUF_NO_RTTI. -// On MSVC, this should be detected automatically. -template -inline To dynamic_cast_if_available(From from) { -#if defined(GOOGLE_PROTOBUF_NO_RTTI) || (defined(_MSC_VER)&&!defined(_CPPRTTI)) - return NULL; -#else - return dynamic_cast(from); -#endif -} - -// Helper for EnumType_Parse functions: try to parse the string 'name' as an -// enum name of the given type, returning true and filling in value on success, -// or returning false and leaving value unchanged on failure. -LIBPROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor, - const string& name, - int* value); - -template -bool ParseNamedEnum(const EnumDescriptor* descriptor, - const string& name, - EnumType* value) { - int tmp; - if (!ParseNamedEnum(descriptor, name, &tmp)) return false; - *value = static_cast(tmp); - return true; -} - -// Just a wrapper around printing the name of a value. The main point of this -// function is not to be inlined, so that you can do this without including -// descriptor.h. -LIBPROTOBUF_EXPORT const string& NameOfEnum(const EnumDescriptor* descriptor, int value); - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h b/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h deleted file mode 100644 index 1a2343d4..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +++ /dev/null @@ -1,82 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains miscellaneous helper code used by generated code -- -// including lite types -- but which should not be used directly by users. - -#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ - -#include - -#include - - -namespace google { -namespace protobuf { - namespace io { - class CodedInputStream; // coded_stream.h - } -} - -namespace protobuf { -namespace internal { - -// Annotation for the compiler to emit a deprecation message if a field marked -// with option 'deprecated=true' is used in the code, or for other things in -// generated code which are deprecated. -// -// For internal use in the pb.cc files, deprecation warnings are suppressed -// there. -#undef DEPRECATED_PROTOBUF_FIELD -#if !defined(INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION) -# define PROTOBUF_DEPRECATED GOOGLE_ATTRIBUTE_DEPRECATED -#else -# define PROTOBUF_DEPRECATED -#endif - - -// Constants for special floating point values. -double Infinity(); -double NaN(); - -// Constant used for empty default strings. -extern const ::std::string kEmptyString; - - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h b/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h deleted file mode 100644 index 1b6b4e18..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +++ /dev/null @@ -1,1102 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains the CodedInputStream and CodedOutputStream classes, -// which wrap a ZeroCopyInputStream or ZeroCopyOutputStream, respectively, -// and allow you to read or write individual pieces of data in various -// formats. In particular, these implement the varint encoding for -// integers, a simple variable-length encoding in which smaller numbers -// take fewer bytes. -// -// Typically these classes will only be used internally by the protocol -// buffer library in order to encode and decode protocol buffers. Clients -// of the library only need to know about this class if they wish to write -// custom message parsing or serialization procedures. -// -// CodedOutputStream example: -// // Write some data to "myfile". First we write a 4-byte "magic number" -// // to identify the file type, then write a length-delimited string. The -// // string is composed of a varint giving the length followed by the raw -// // bytes. -// int fd = open("myfile", O_WRONLY); -// ZeroCopyOutputStream* raw_output = new FileOutputStream(fd); -// CodedOutputStream* coded_output = new CodedOutputStream(raw_output); -// -// int magic_number = 1234; -// char text[] = "Hello world!"; -// coded_output->WriteLittleEndian32(magic_number); -// coded_output->WriteVarint32(strlen(text)); -// coded_output->WriteRaw(text, strlen(text)); -// -// delete coded_output; -// delete raw_output; -// close(fd); -// -// CodedInputStream example: -// // Read a file created by the above code. -// int fd = open("myfile", O_RDONLY); -// ZeroCopyInputStream* raw_input = new FileInputStream(fd); -// CodedInputStream coded_input = new CodedInputStream(raw_input); -// -// coded_input->ReadLittleEndian32(&magic_number); -// if (magic_number != 1234) { -// cerr << "File not in expected format." << endl; -// return; -// } -// -// uint32 size; -// coded_input->ReadVarint32(&size); -// -// char* text = new char[size + 1]; -// coded_input->ReadRaw(buffer, size); -// text[size] = '\0'; -// -// delete coded_input; -// delete raw_input; -// close(fd); -// -// cout << "Text is: " << text << endl; -// delete [] text; -// -// For those who are interested, varint encoding is defined as follows: -// -// The encoding operates on unsigned integers of up to 64 bits in length. -// Each byte of the encoded value has the format: -// * bits 0-6: Seven bits of the number being encoded. -// * bit 7: Zero if this is the last byte in the encoding (in which -// case all remaining bits of the number are zero) or 1 if -// more bytes follow. -// The first byte contains the least-significant 7 bits of the number, the -// second byte (if present) contains the next-least-significant 7 bits, -// and so on. So, the binary number 1011000101011 would be encoded in two -// bytes as "10101011 00101100". -// -// In theory, varint could be used to encode integers of any length. -// However, for practicality we set a limit at 64 bits. The maximum encoded -// length of a number is thus 10 bytes. - -#ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ -#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ - -#include -#ifdef _MSC_VER - #if defined(_M_IX86) && \ - !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) - #define PROTOBUF_LITTLE_ENDIAN 1 - #endif - #if _MSC_VER >= 1300 - // If MSVC has "/RTCc" set, it will complain about truncating casts at - // runtime. This file contains some intentional truncating casts. - #pragma runtime_checks("c", off) - #endif -#else - #include // __BYTE_ORDER - #if defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN && \ - !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) - #define PROTOBUF_LITTLE_ENDIAN 1 - #endif -#endif -#include - - -namespace google { -namespace protobuf { - -class DescriptorPool; -class MessageFactory; - -namespace io { - -// Defined in this file. -class CodedInputStream; -class CodedOutputStream; - -// Defined in other files. -class ZeroCopyInputStream; // zero_copy_stream.h -class ZeroCopyOutputStream; // zero_copy_stream.h - -// Class which reads and decodes binary data which is composed of varint- -// encoded integers and fixed-width pieces. Wraps a ZeroCopyInputStream. -// Most users will not need to deal with CodedInputStream. -// -// Most methods of CodedInputStream that return a bool return false if an -// underlying I/O error occurs or if the data is malformed. Once such a -// failure occurs, the CodedInputStream is broken and is no longer useful. -class LIBPROTOBUF_EXPORT CodedInputStream { - public: - // Create a CodedInputStream that reads from the given ZeroCopyInputStream. - explicit CodedInputStream(ZeroCopyInputStream* input); - - // Create a CodedInputStream that reads from the given flat array. This is - // faster than using an ArrayInputStream. PushLimit(size) is implied by - // this constructor. - explicit CodedInputStream(const uint8* buffer, int size); - - // Destroy the CodedInputStream and position the underlying - // ZeroCopyInputStream at the first unread byte. If an error occurred while - // reading (causing a method to return false), then the exact position of - // the input stream may be anywhere between the last value that was read - // successfully and the stream's byte limit. - ~CodedInputStream(); - - - // Skips a number of bytes. Returns false if an underlying read error - // occurs. - bool Skip(int count); - - // Sets *data to point directly at the unread part of the CodedInputStream's - // underlying buffer, and *size to the size of that buffer, but does not - // advance the stream's current position. This will always either produce - // a non-empty buffer or return false. If the caller consumes any of - // this data, it should then call Skip() to skip over the consumed bytes. - // This may be useful for implementing external fast parsing routines for - // types of data not covered by the CodedInputStream interface. - bool GetDirectBufferPointer(const void** data, int* size); - - // Like GetDirectBufferPointer, but this method is inlined, and does not - // attempt to Refresh() if the buffer is currently empty. - inline void GetDirectBufferPointerInline(const void** data, - int* size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - // Read raw bytes, copying them into the given buffer. - bool ReadRaw(void* buffer, int size); - - // Like ReadRaw, but reads into a string. - // - // Implementation Note: ReadString() grows the string gradually as it - // reads in the data, rather than allocating the entire requested size - // upfront. This prevents denial-of-service attacks in which a client - // could claim that a string is going to be MAX_INT bytes long in order to - // crash the server because it can't allocate this much space at once. - bool ReadString(string* buffer, int size); - // Like the above, with inlined optimizations. This should only be used - // by the protobuf implementation. - inline bool InternalReadStringInline(string* buffer, - int size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - - // Read a 32-bit little-endian integer. - bool ReadLittleEndian32(uint32* value); - // Read a 64-bit little-endian integer. - bool ReadLittleEndian64(uint64* value); - - // These methods read from an externally provided buffer. The caller is - // responsible for ensuring that the buffer has sufficient space. - // Read a 32-bit little-endian integer. - static const uint8* ReadLittleEndian32FromArray(const uint8* buffer, - uint32* value); - // Read a 64-bit little-endian integer. - static const uint8* ReadLittleEndian64FromArray(const uint8* buffer, - uint64* value); - - // Read an unsigned integer with Varint encoding, truncating to 32 bits. - // Reading a 32-bit value is equivalent to reading a 64-bit one and casting - // it to uint32, but may be more efficient. - bool ReadVarint32(uint32* value); - // Read an unsigned integer with Varint encoding. - bool ReadVarint64(uint64* value); - - // Read a tag. This calls ReadVarint32() and returns the result, or returns - // zero (which is not a valid tag) if ReadVarint32() fails. Also, it updates - // the last tag value, which can be checked with LastTagWas(). - // Always inline because this is only called in once place per parse loop - // but it is called for every iteration of said loop, so it should be fast. - // GCC doesn't want to inline this by default. - uint32 ReadTag() GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - // Usually returns true if calling ReadVarint32() now would produce the given - // value. Will always return false if ReadVarint32() would not return the - // given value. If ExpectTag() returns true, it also advances past - // the varint. For best performance, use a compile-time constant as the - // parameter. - // Always inline because this collapses to a small number of instructions - // when given a constant parameter, but GCC doesn't want to inline by default. - bool ExpectTag(uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - // Like above, except this reads from the specified buffer. The caller is - // responsible for ensuring that the buffer is large enough to read a varint - // of the expected size. For best performance, use a compile-time constant as - // the expected tag parameter. - // - // Returns a pointer beyond the expected tag if it was found, or NULL if it - // was not. - static const uint8* ExpectTagFromArray( - const uint8* buffer, - uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - // Usually returns true if no more bytes can be read. Always returns false - // if more bytes can be read. If ExpectAtEnd() returns true, a subsequent - // call to LastTagWas() will act as if ReadTag() had been called and returned - // zero, and ConsumedEntireMessage() will return true. - bool ExpectAtEnd(); - - // If the last call to ReadTag() returned the given value, returns true. - // Otherwise, returns false; - // - // This is needed because parsers for some types of embedded messages - // (with field type TYPE_GROUP) don't actually know that they've reached the - // end of a message until they see an ENDGROUP tag, which was actually part - // of the enclosing message. The enclosing message would like to check that - // tag to make sure it had the right number, so it calls LastTagWas() on - // return from the embedded parser to check. - bool LastTagWas(uint32 expected); - - // When parsing message (but NOT a group), this method must be called - // immediately after MergeFromCodedStream() returns (if it returns true) - // to further verify that the message ended in a legitimate way. For - // example, this verifies that parsing did not end on an end-group tag. - // It also checks for some cases where, due to optimizations, - // MergeFromCodedStream() can incorrectly return true. - bool ConsumedEntireMessage(); - - // Limits ---------------------------------------------------------- - // Limits are used when parsing length-delimited embedded messages. - // After the message's length is read, PushLimit() is used to prevent - // the CodedInputStream from reading beyond that length. Once the - // embedded message has been parsed, PopLimit() is called to undo the - // limit. - - // Opaque type used with PushLimit() and PopLimit(). Do not modify - // values of this type yourself. The only reason that this isn't a - // struct with private internals is for efficiency. - typedef int Limit; - - // Places a limit on the number of bytes that the stream may read, - // starting from the current position. Once the stream hits this limit, - // it will act like the end of the input has been reached until PopLimit() - // is called. - // - // As the names imply, the stream conceptually has a stack of limits. The - // shortest limit on the stack is always enforced, even if it is not the - // top limit. - // - // The value returned by PushLimit() is opaque to the caller, and must - // be passed unchanged to the corresponding call to PopLimit(). - Limit PushLimit(int byte_limit); - - // Pops the last limit pushed by PushLimit(). The input must be the value - // returned by that call to PushLimit(). - void PopLimit(Limit limit); - - // Returns the number of bytes left until the nearest limit on the - // stack is hit, or -1 if no limits are in place. - int BytesUntilLimit(); - - // Total Bytes Limit ----------------------------------------------- - // To prevent malicious users from sending excessively large messages - // and causing integer overflows or memory exhaustion, CodedInputStream - // imposes a hard limit on the total number of bytes it will read. - - // Sets the maximum number of bytes that this CodedInputStream will read - // before refusing to continue. To prevent integer overflows in the - // protocol buffers implementation, as well as to prevent servers from - // allocating enormous amounts of memory to hold parsed messages, the - // maximum message length should be limited to the shortest length that - // will not harm usability. The theoretical shortest message that could - // cause integer overflows is 512MB. The default limit is 64MB. Apps - // should set shorter limits if possible. If warning_threshold is not -1, - // a warning will be printed to stderr after warning_threshold bytes are - // read. An error will always be printed to stderr if the limit is - // reached. - // - // This is unrelated to PushLimit()/PopLimit(). - // - // Hint: If you are reading this because your program is printing a - // warning about dangerously large protocol messages, you may be - // confused about what to do next. The best option is to change your - // design such that excessively large messages are not necessary. - // For example, try to design file formats to consist of many small - // messages rather than a single large one. If this is infeasible, - // you will need to increase the limit. Chances are, though, that - // your code never constructs a CodedInputStream on which the limit - // can be set. You probably parse messages by calling things like - // Message::ParseFromString(). In this case, you will need to change - // your code to instead construct some sort of ZeroCopyInputStream - // (e.g. an ArrayInputStream), construct a CodedInputStream around - // that, then call Message::ParseFromCodedStream() instead. Then - // you can adjust the limit. Yes, it's more work, but you're doing - // something unusual. - void SetTotalBytesLimit(int total_bytes_limit, int warning_threshold); - - // Recursion Limit ------------------------------------------------- - // To prevent corrupt or malicious messages from causing stack overflows, - // we must keep track of the depth of recursion when parsing embedded - // messages and groups. CodedInputStream keeps track of this because it - // is the only object that is passed down the stack during parsing. - - // Sets the maximum recursion depth. The default is 64. - void SetRecursionLimit(int limit); - - // Increments the current recursion depth. Returns true if the depth is - // under the limit, false if it has gone over. - bool IncrementRecursionDepth(); - - // Decrements the recursion depth. - void DecrementRecursionDepth(); - - // Extension Registry ---------------------------------------------- - // ADVANCED USAGE: 99.9% of people can ignore this section. - // - // By default, when parsing extensions, the parser looks for extension - // definitions in the pool which owns the outer message's Descriptor. - // However, you may call SetExtensionRegistry() to provide an alternative - // pool instead. This makes it possible, for example, to parse a message - // using a generated class, but represent some extensions using - // DynamicMessage. - - // Set the pool used to look up extensions. Most users do not need to call - // this as the correct pool will be chosen automatically. - // - // WARNING: It is very easy to misuse this. Carefully read the requirements - // below. Do not use this unless you are sure you need it. Almost no one - // does. - // - // Let's say you are parsing a message into message object m, and you want - // to take advantage of SetExtensionRegistry(). You must follow these - // requirements: - // - // The given DescriptorPool must contain m->GetDescriptor(). It is not - // sufficient for it to simply contain a descriptor that has the same name - // and content -- it must be the *exact object*. In other words: - // assert(pool->FindMessageTypeByName(m->GetDescriptor()->full_name()) == - // m->GetDescriptor()); - // There are two ways to satisfy this requirement: - // 1) Use m->GetDescriptor()->pool() as the pool. This is generally useless - // because this is the pool that would be used anyway if you didn't call - // SetExtensionRegistry() at all. - // 2) Use a DescriptorPool which has m->GetDescriptor()->pool() as an - // "underlay". Read the documentation for DescriptorPool for more - // information about underlays. - // - // You must also provide a MessageFactory. This factory will be used to - // construct Message objects representing extensions. The factory's - // GetPrototype() MUST return non-NULL for any Descriptor which can be found - // through the provided pool. - // - // If the provided factory might return instances of protocol-compiler- - // generated (i.e. compiled-in) types, or if the outer message object m is - // a generated type, then the given factory MUST have this property: If - // GetPrototype() is given a Descriptor which resides in - // DescriptorPool::generated_pool(), the factory MUST return the same - // prototype which MessageFactory::generated_factory() would return. That - // is, given a descriptor for a generated type, the factory must return an - // instance of the generated class (NOT DynamicMessage). However, when - // given a descriptor for a type that is NOT in generated_pool, the factory - // is free to return any implementation. - // - // The reason for this requirement is that generated sub-objects may be - // accessed via the standard (non-reflection) extension accessor methods, - // and these methods will down-cast the object to the generated class type. - // If the object is not actually of that type, the results would be undefined. - // On the other hand, if an extension is not compiled in, then there is no - // way the code could end up accessing it via the standard accessors -- the - // only way to access the extension is via reflection. When using reflection, - // DynamicMessage and generated messages are indistinguishable, so it's fine - // if these objects are represented using DynamicMessage. - // - // Using DynamicMessageFactory on which you have called - // SetDelegateToGeneratedFactory(true) should be sufficient to satisfy the - // above requirement. - // - // If either pool or factory is NULL, both must be NULL. - // - // Note that this feature is ignored when parsing "lite" messages as they do - // not have descriptors. - void SetExtensionRegistry(DescriptorPool* pool, MessageFactory* factory); - - // Get the DescriptorPool set via SetExtensionRegistry(), or NULL if no pool - // has been provided. - const DescriptorPool* GetExtensionPool(); - - // Get the MessageFactory set via SetExtensionRegistry(), or NULL if no - // factory has been provided. - MessageFactory* GetExtensionFactory(); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream); - - ZeroCopyInputStream* input_; - const uint8* buffer_; - const uint8* buffer_end_; // pointer to the end of the buffer. - int total_bytes_read_; // total bytes read from input_, including - // the current buffer - - // If total_bytes_read_ surpasses INT_MAX, we record the extra bytes here - // so that we can BackUp() on destruction. - int overflow_bytes_; - - // LastTagWas() stuff. - uint32 last_tag_; // result of last ReadTag(). - - // This is set true by ReadTag{Fallback/Slow}() if it is called when exactly - // at EOF, or by ExpectAtEnd() when it returns true. This happens when we - // reach the end of a message and attempt to read another tag. - bool legitimate_message_end_; - - // See EnableAliasing(). - bool aliasing_enabled_; - - // Limits - Limit current_limit_; // if position = -1, no limit is applied - - // For simplicity, if the current buffer crosses a limit (either a normal - // limit created by PushLimit() or the total bytes limit), buffer_size_ - // only tracks the number of bytes before that limit. This field - // contains the number of bytes after it. Note that this implies that if - // buffer_size_ == 0 and buffer_size_after_limit_ > 0, we know we've - // hit a limit. However, if both are zero, it doesn't necessarily mean - // we aren't at a limit -- the buffer may have ended exactly at the limit. - int buffer_size_after_limit_; - - // Maximum number of bytes to read, period. This is unrelated to - // current_limit_. Set using SetTotalBytesLimit(). - int total_bytes_limit_; - int total_bytes_warning_threshold_; - - // Current recursion depth, controlled by IncrementRecursionDepth() and - // DecrementRecursionDepth(). - int recursion_depth_; - // Recursion depth limit, set by SetRecursionLimit(). - int recursion_limit_; - - // See SetExtensionRegistry(). - const DescriptorPool* extension_pool_; - MessageFactory* extension_factory_; - - // Private member functions. - - // Advance the buffer by a given number of bytes. - void Advance(int amount); - - // Back up input_ to the current buffer position. - void BackUpInputToCurrentPosition(); - - // Recomputes the value of buffer_size_after_limit_. Must be called after - // current_limit_ or total_bytes_limit_ changes. - void RecomputeBufferLimits(); - - // Writes an error message saying that we hit total_bytes_limit_. - void PrintTotalBytesLimitError(); - - // Called when the buffer runs out to request more data. Implies an - // Advance(BufferSize()). - bool Refresh(); - - // When parsing varints, we optimize for the common case of small values, and - // then optimize for the case when the varint fits within the current buffer - // piece. The Fallback method is used when we can't use the one-byte - // optimization. The Slow method is yet another fallback when the buffer is - // not large enough. Making the slow path out-of-line speeds up the common - // case by 10-15%. The slow path is fairly uncommon: it only triggers when a - // message crosses multiple buffers. - bool ReadVarint32Fallback(uint32* value); - bool ReadVarint64Fallback(uint64* value); - bool ReadVarint32Slow(uint32* value); - bool ReadVarint64Slow(uint64* value); - bool ReadLittleEndian32Fallback(uint32* value); - bool ReadLittleEndian64Fallback(uint64* value); - // Fallback/slow methods for reading tags. These do not update last_tag_, - // but will set legitimate_message_end_ if we are at the end of the input - // stream. - uint32 ReadTagFallback(); - uint32 ReadTagSlow(); - bool ReadStringFallback(string* buffer, int size); - - // Return the size of the buffer. - int BufferSize() const; - - static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB - - static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB - static const int kDefaultRecursionLimit = 64; -}; - -// Class which encodes and writes binary data which is composed of varint- -// encoded integers and fixed-width pieces. Wraps a ZeroCopyOutputStream. -// Most users will not need to deal with CodedOutputStream. -// -// Most methods of CodedOutputStream which return a bool return false if an -// underlying I/O error occurs. Once such a failure occurs, the -// CodedOutputStream is broken and is no longer useful. The Write* methods do -// not return the stream status, but will invalidate the stream if an error -// occurs. The client can probe HadError() to determine the status. -// -// Note that every method of CodedOutputStream which writes some data has -// a corresponding static "ToArray" version. These versions write directly -// to the provided buffer, returning a pointer past the last written byte. -// They require that the buffer has sufficient capacity for the encoded data. -// This allows an optimization where we check if an output stream has enough -// space for an entire message before we start writing and, if there is, we -// call only the ToArray methods to avoid doing bound checks for each -// individual value. -// i.e., in the example above: -// -// CodedOutputStream coded_output = new CodedOutputStream(raw_output); -// int magic_number = 1234; -// char text[] = "Hello world!"; -// -// int coded_size = sizeof(magic_number) + -// CodedOutputStream::VarintSize32(strlen(text)) + -// strlen(text); -// -// uint8* buffer = -// coded_output->GetDirectBufferForNBytesAndAdvance(coded_size); -// if (buffer != NULL) { -// // The output stream has enough space in the buffer: write directly to -// // the array. -// buffer = CodedOutputStream::WriteLittleEndian32ToArray(magic_number, -// buffer); -// buffer = CodedOutputStream::WriteVarint32ToArray(strlen(text), buffer); -// buffer = CodedOutputStream::WriteRawToArray(text, strlen(text), buffer); -// } else { -// // Make bound-checked writes, which will ask the underlying stream for -// // more space as needed. -// coded_output->WriteLittleEndian32(magic_number); -// coded_output->WriteVarint32(strlen(text)); -// coded_output->WriteRaw(text, strlen(text)); -// } -// -// delete coded_output; -class LIBPROTOBUF_EXPORT CodedOutputStream { - public: - // Create an CodedOutputStream that writes to the given ZeroCopyOutputStream. - explicit CodedOutputStream(ZeroCopyOutputStream* output); - - // Destroy the CodedOutputStream and position the underlying - // ZeroCopyOutputStream immediately after the last byte written. - ~CodedOutputStream(); - - // Skips a number of bytes, leaving the bytes unmodified in the underlying - // buffer. Returns false if an underlying write error occurs. This is - // mainly useful with GetDirectBufferPointer(). - bool Skip(int count); - - // Sets *data to point directly at the unwritten part of the - // CodedOutputStream's underlying buffer, and *size to the size of that - // buffer, but does not advance the stream's current position. This will - // always either produce a non-empty buffer or return false. If the caller - // writes any data to this buffer, it should then call Skip() to skip over - // the consumed bytes. This may be useful for implementing external fast - // serialization routines for types of data not covered by the - // CodedOutputStream interface. - bool GetDirectBufferPointer(void** data, int* size); - - // If there are at least "size" bytes available in the current buffer, - // returns a pointer directly into the buffer and advances over these bytes. - // The caller may then write directly into this buffer (e.g. using the - // *ToArray static methods) rather than go through CodedOutputStream. If - // there are not enough bytes available, returns NULL. The return pointer is - // invalidated as soon as any other non-const method of CodedOutputStream - // is called. - inline uint8* GetDirectBufferForNBytesAndAdvance(int size); - - // Write raw bytes, copying them from the given buffer. - void WriteRaw(const void* buffer, int size); - // Like WriteRaw() but writing directly to the target array. - // This is _not_ inlined, as the compiler often optimizes memcpy into inline - // copy loops. Since this gets called by every field with string or bytes - // type, inlining may lead to a significant amount of code bloat, with only a - // minor performance gain. - static uint8* WriteRawToArray(const void* buffer, int size, uint8* target); - - // Equivalent to WriteRaw(str.data(), str.size()). - void WriteString(const string& str); - // Like WriteString() but writing directly to the target array. - static uint8* WriteStringToArray(const string& str, uint8* target); - - - // Write a 32-bit little-endian integer. - void WriteLittleEndian32(uint32 value); - // Like WriteLittleEndian32() but writing directly to the target array. - static uint8* WriteLittleEndian32ToArray(uint32 value, uint8* target); - // Write a 64-bit little-endian integer. - void WriteLittleEndian64(uint64 value); - // Like WriteLittleEndian64() but writing directly to the target array. - static uint8* WriteLittleEndian64ToArray(uint64 value, uint8* target); - - // Write an unsigned integer with Varint encoding. Writing a 32-bit value - // is equivalent to casting it to uint64 and writing it as a 64-bit value, - // but may be more efficient. - void WriteVarint32(uint32 value); - // Like WriteVarint32() but writing directly to the target array. - static uint8* WriteVarint32ToArray(uint32 value, uint8* target); - // Write an unsigned integer with Varint encoding. - void WriteVarint64(uint64 value); - // Like WriteVarint64() but writing directly to the target array. - static uint8* WriteVarint64ToArray(uint64 value, uint8* target); - - // Equivalent to WriteVarint32() except when the value is negative, - // in which case it must be sign-extended to a full 10 bytes. - void WriteVarint32SignExtended(int32 value); - // Like WriteVarint32SignExtended() but writing directly to the target array. - static uint8* WriteVarint32SignExtendedToArray(int32 value, uint8* target); - - // This is identical to WriteVarint32(), but optimized for writing tags. - // In particular, if the input is a compile-time constant, this method - // compiles down to a couple instructions. - // Always inline because otherwise the aformentioned optimization can't work, - // but GCC by default doesn't want to inline this. - void WriteTag(uint32 value); - // Like WriteTag() but writing directly to the target array. - static uint8* WriteTagToArray( - uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - // Returns the number of bytes needed to encode the given value as a varint. - static int VarintSize32(uint32 value); - // Returns the number of bytes needed to encode the given value as a varint. - static int VarintSize64(uint64 value); - - // If negative, 10 bytes. Otheriwse, same as VarintSize32(). - static int VarintSize32SignExtended(int32 value); - - // Returns the total number of bytes written since this object was created. - inline int ByteCount() const; - - // Returns true if there was an underlying I/O error since this object was - // created. - bool HadError() const { return had_error_; } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); - - ZeroCopyOutputStream* output_; - uint8* buffer_; - int buffer_size_; - int total_bytes_; // Sum of sizes of all buffers seen so far. - bool had_error_; // Whether an error occurred during output. - - // Advance the buffer by a given number of bytes. - void Advance(int amount); - - // Called when the buffer runs out to request more data. Implies an - // Advance(buffer_size_). - bool Refresh(); - - static uint8* WriteVarint32FallbackToArray(uint32 value, uint8* target); - - // Always-inlined versions of WriteVarint* functions so that code can be - // reused, while still controlling size. For instance, WriteVarint32ToArray() - // should not directly call this: since it is inlined itself, doing so - // would greatly increase the size of generated code. Instead, it should call - // WriteVarint32FallbackToArray. Meanwhile, WriteVarint32() is already - // out-of-line, so it should just invoke this directly to avoid any extra - // function call overhead. - static uint8* WriteVarint32FallbackToArrayInline( - uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - static uint8* WriteVarint64ToArrayInline( - uint64 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - static int VarintSize32Fallback(uint32 value); -}; - -// inline methods ==================================================== -// The vast majority of varints are only one byte. These inline -// methods optimize for that case. - -inline bool CodedInputStream::ReadVarint32(uint32* value) { - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) { - *value = *buffer_; - Advance(1); - return true; - } else { - return ReadVarint32Fallback(value); - } -} - -inline bool CodedInputStream::ReadVarint64(uint64* value) { - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) { - *value = *buffer_; - Advance(1); - return true; - } else { - return ReadVarint64Fallback(value); - } -} - -// static -inline const uint8* CodedInputStream::ReadLittleEndian32FromArray( - const uint8* buffer, - uint32* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(value, buffer, sizeof(*value)); - return buffer + sizeof(*value); -#else - *value = (static_cast(buffer[0]) ) | - (static_cast(buffer[1]) << 8) | - (static_cast(buffer[2]) << 16) | - (static_cast(buffer[3]) << 24); - return buffer + sizeof(*value); -#endif -} -// static -inline const uint8* CodedInputStream::ReadLittleEndian64FromArray( - const uint8* buffer, - uint64* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(value, buffer, sizeof(*value)); - return buffer + sizeof(*value); -#else - uint32 part0 = (static_cast(buffer[0]) ) | - (static_cast(buffer[1]) << 8) | - (static_cast(buffer[2]) << 16) | - (static_cast(buffer[3]) << 24); - uint32 part1 = (static_cast(buffer[4]) ) | - (static_cast(buffer[5]) << 8) | - (static_cast(buffer[6]) << 16) | - (static_cast(buffer[7]) << 24); - *value = static_cast(part0) | - (static_cast(part1) << 32); - return buffer + sizeof(*value); -#endif -} - -inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { - memcpy(value, buffer_, sizeof(*value)); - Advance(sizeof(*value)); - return true; - } else { - return ReadLittleEndian32Fallback(value); - } -#else - return ReadLittleEndian32Fallback(value); -#endif -} - -inline bool CodedInputStream::ReadLittleEndian64(uint64* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { - memcpy(value, buffer_, sizeof(*value)); - Advance(sizeof(*value)); - return true; - } else { - return ReadLittleEndian64Fallback(value); - } -#else - return ReadLittleEndian64Fallback(value); -#endif -} - -inline uint32 CodedInputStream::ReadTag() { - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] < 0x80) { - last_tag_ = buffer_[0]; - Advance(1); - return last_tag_; - } else { - last_tag_ = ReadTagFallback(); - return last_tag_; - } -} - -inline bool CodedInputStream::LastTagWas(uint32 expected) { - return last_tag_ == expected; -} - -inline bool CodedInputStream::ConsumedEntireMessage() { - return legitimate_message_end_; -} - -inline bool CodedInputStream::ExpectTag(uint32 expected) { - if (expected < (1 << 7)) { - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] == expected) { - Advance(1); - return true; - } else { - return false; - } - } else if (expected < (1 << 14)) { - if (GOOGLE_PREDICT_TRUE(BufferSize() >= 2) && - buffer_[0] == static_cast(expected | 0x80) && - buffer_[1] == static_cast(expected >> 7)) { - Advance(2); - return true; - } else { - return false; - } - } else { - // Don't bother optimizing for larger values. - return false; - } -} - -inline const uint8* CodedInputStream::ExpectTagFromArray( - const uint8* buffer, uint32 expected) { - if (expected < (1 << 7)) { - if (buffer[0] == expected) { - return buffer + 1; - } - } else if (expected < (1 << 14)) { - if (buffer[0] == static_cast(expected | 0x80) && - buffer[1] == static_cast(expected >> 7)) { - return buffer + 2; - } - } - return NULL; -} - -inline void CodedInputStream::GetDirectBufferPointerInline(const void** data, - int* size) { - *data = buffer_; - *size = buffer_end_ - buffer_; -} - -inline bool CodedInputStream::ExpectAtEnd() { - // If we are at a limit we know no more bytes can be read. Otherwise, it's - // hard to say without calling Refresh(), and we'd rather not do that. - - if (buffer_ == buffer_end_ && buffer_size_after_limit_ != 0) { - last_tag_ = 0; // Pretend we called ReadTag()... - legitimate_message_end_ = true; // ... and it hit EOF. - return true; - } else { - return false; - } -} - -inline uint8* CodedOutputStream::GetDirectBufferForNBytesAndAdvance(int size) { - if (buffer_size_ < size) { - return NULL; - } else { - uint8* result = buffer_; - Advance(size); - return result; - } -} - -inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value, - uint8* target) { - if (value < 0x80) { - *target = value; - return target + 1; - } else { - return WriteVarint32FallbackToArray(value, target); - } -} - -inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) { - if (value < 0) { - WriteVarint64(static_cast(value)); - } else { - WriteVarint32(static_cast(value)); - } -} - -inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray( - int32 value, uint8* target) { - if (value < 0) { - return WriteVarint64ToArray(static_cast(value), target); - } else { - return WriteVarint32ToArray(static_cast(value), target); - } -} - -inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value, - uint8* target) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(target, &value, sizeof(value)); -#else - target[0] = static_cast(value); - target[1] = static_cast(value >> 8); - target[2] = static_cast(value >> 16); - target[3] = static_cast(value >> 24); -#endif - return target + sizeof(value); -} - -inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value, - uint8* target) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(target, &value, sizeof(value)); -#else - uint32 part0 = static_cast(value); - uint32 part1 = static_cast(value >> 32); - - target[0] = static_cast(part0); - target[1] = static_cast(part0 >> 8); - target[2] = static_cast(part0 >> 16); - target[3] = static_cast(part0 >> 24); - target[4] = static_cast(part1); - target[5] = static_cast(part1 >> 8); - target[6] = static_cast(part1 >> 16); - target[7] = static_cast(part1 >> 24); -#endif - return target + sizeof(value); -} - -inline void CodedOutputStream::WriteTag(uint32 value) { - WriteVarint32(value); -} - -inline uint8* CodedOutputStream::WriteTagToArray( - uint32 value, uint8* target) { - if (value < (1 << 7)) { - target[0] = value; - return target + 1; - } else if (value < (1 << 14)) { - target[0] = static_cast(value | 0x80); - target[1] = static_cast(value >> 7); - return target + 2; - } else { - return WriteVarint32FallbackToArray(value, target); - } -} - -inline int CodedOutputStream::VarintSize32(uint32 value) { - if (value < (1 << 7)) { - return 1; - } else { - return VarintSize32Fallback(value); - } -} - -inline int CodedOutputStream::VarintSize32SignExtended(int32 value) { - if (value < 0) { - return 10; // TODO(kenton): Make this a symbolic constant. - } else { - return VarintSize32(static_cast(value)); - } -} - -inline void CodedOutputStream::WriteString(const string& str) { - WriteRaw(str.data(), static_cast(str.size())); -} - -inline uint8* CodedOutputStream::WriteStringToArray( - const string& str, uint8* target) { - return WriteRawToArray(str.data(), static_cast(str.size()), target); -} - -inline int CodedOutputStream::ByteCount() const { - return total_bytes_ - buffer_size_; -} - -inline void CodedInputStream::Advance(int amount) { - buffer_ += amount; -} - -inline void CodedOutputStream::Advance(int amount) { - buffer_ += amount; - buffer_size_ -= amount; -} - -inline void CodedInputStream::SetRecursionLimit(int limit) { - recursion_limit_ = limit; -} - -inline bool CodedInputStream::IncrementRecursionDepth() { - ++recursion_depth_; - return recursion_depth_ <= recursion_limit_; -} - -inline void CodedInputStream::DecrementRecursionDepth() { - if (recursion_depth_ > 0) --recursion_depth_; -} - -inline void CodedInputStream::SetExtensionRegistry(DescriptorPool* pool, - MessageFactory* factory) { - extension_pool_ = pool; - extension_factory_ = factory; -} - -inline const DescriptorPool* CodedInputStream::GetExtensionPool() { - return extension_pool_; -} - -inline MessageFactory* CodedInputStream::GetExtensionFactory() { - return extension_factory_; -} - -inline int CodedInputStream::BufferSize() const { - return buffer_end_ - buffer_; -} - -inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input) - : input_(input), - buffer_(NULL), - buffer_end_(NULL), - total_bytes_read_(0), - overflow_bytes_(0), - last_tag_(0), - legitimate_message_end_(false), - aliasing_enabled_(false), - current_limit_(kint32max), - buffer_size_after_limit_(0), - total_bytes_limit_(kDefaultTotalBytesLimit), - total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), - recursion_depth_(0), - recursion_limit_(kDefaultRecursionLimit), - extension_pool_(NULL), - extension_factory_(NULL) { - // Eagerly Refresh() so buffer space is immediately available. - Refresh(); -} - -inline CodedInputStream::CodedInputStream(const uint8* buffer, int size) - : input_(NULL), - buffer_(buffer), - buffer_end_(buffer + size), - total_bytes_read_(size), - overflow_bytes_(0), - last_tag_(0), - legitimate_message_end_(false), - aliasing_enabled_(false), - current_limit_(size), - buffer_size_after_limit_(0), - total_bytes_limit_(kDefaultTotalBytesLimit), - total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), - recursion_depth_(0), - recursion_limit_(kDefaultRecursionLimit), - extension_pool_(NULL), - extension_factory_(NULL) { - // Note that setting current_limit_ == size is important to prevent some - // code paths from trying to access input_ and segfaulting. -} - -inline CodedInputStream::~CodedInputStream() { - if (input_ != NULL) { - BackUpInputToCurrentPosition(); - } -} - -} // namespace io -} // namespace protobuf - - -#if defined(_MSC_VER) && _MSC_VER >= 1300 - #pragma runtime_checks("c", restore) -#endif // _MSC_VER - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h b/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h deleted file mode 100644 index e9799d47..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +++ /dev/null @@ -1,64 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: jasonh@google.com (Jason Hsueh) -// -// Implements methods of coded_stream.h that need to be inlined for performance -// reasons, but should not be defined in a public header. - -#ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ -#define GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace io { - -inline bool CodedInputStream::InternalReadStringInline(string* buffer, - int size) { - if (size < 0) return false; // security: size is often user-supplied - - if (BufferSize() >= size) { - STLStringResizeUninitialized(buffer, size); - memcpy(string_as_array(buffer), buffer_, size); - Advance(size); - return true; - } - - return ReadStringFallback(buffer, size); -} - -} // namespace io -} // namespace protobuf -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h b/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h deleted file mode 100644 index 65dbc5b5..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +++ /dev/null @@ -1,207 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: brianolson@google.com (Brian Olson) -// -// This file contains the definition for classes GzipInputStream and -// GzipOutputStream. -// -// GzipInputStream decompresses data from an underlying -// ZeroCopyInputStream and provides the decompressed data as a -// ZeroCopyInputStream. -// -// GzipOutputStream is an ZeroCopyOutputStream that compresses data to -// an underlying ZeroCopyOutputStream. - -#ifndef GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ -#define GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ - -#include - -#include - -namespace google { -namespace protobuf { -namespace io { - -// A ZeroCopyInputStream that reads compressed data through zlib -class LIBPROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream { - public: - // Format key for constructor - enum Format { - // zlib will autodetect gzip header or deflate stream - AUTO = 0, - - // GZIP streams have some extra header data for file attributes. - GZIP = 1, - - // Simpler zlib stream format. - ZLIB = 2, - }; - - // buffer_size and format may be -1 for default of 64kB and GZIP format - explicit GzipInputStream( - ZeroCopyInputStream* sub_stream, - Format format = AUTO, - int buffer_size = -1); - virtual ~GzipInputStream(); - - // Return last error message or NULL if no error. - inline const char* ZlibErrorMessage() const { - return zcontext_.msg; - } - inline int ZlibErrorCode() const { - return zerror_; - } - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - Format format_; - - ZeroCopyInputStream* sub_stream_; - - z_stream zcontext_; - int zerror_; - - void* output_buffer_; - void* output_position_; - size_t output_buffer_length_; - - int Inflate(int flush); - void DoNextOutput(const void** data, int* size); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipInputStream); -}; - - -class LIBPROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { - public: - // Format key for constructor - enum Format { - // GZIP streams have some extra header data for file attributes. - GZIP = 1, - - // Simpler zlib stream format. - ZLIB = 2, - }; - - struct Options { - // Defaults to GZIP. - Format format; - - // What size buffer to use internally. Defaults to 64kB. - int buffer_size; - - // A number between 0 and 9, where 0 is no compression and 9 is best - // compression. Defaults to Z_DEFAULT_COMPRESSION (see zlib.h). - int compression_level; - - // Defaults to Z_DEFAULT_STRATEGY. Can also be set to Z_FILTERED, - // Z_HUFFMAN_ONLY, or Z_RLE. See the documentation for deflateInit2 in - // zlib.h for definitions of these constants. - int compression_strategy; - - Options(); // Initializes with default values. - }; - - // Create a GzipOutputStream with default options. - explicit GzipOutputStream(ZeroCopyOutputStream* sub_stream); - - // Create a GzipOutputStream with the given options. - GzipOutputStream( - ZeroCopyOutputStream* sub_stream, - const Options& options); - - // DEPRECATED: Use one of the above constructors instead. - GzipOutputStream( - ZeroCopyOutputStream* sub_stream, - Format format, - int buffer_size = -1) GOOGLE_ATTRIBUTE_DEPRECATED; - - virtual ~GzipOutputStream(); - - // Return last error message or NULL if no error. - inline const char* ZlibErrorMessage() const { - return zcontext_.msg; - } - inline int ZlibErrorCode() const { - return zerror_; - } - - // Flushes data written so far to zipped data in the underlying stream. - // It is the caller's responsibility to flush the underlying stream if - // necessary. - // Compression may be less efficient stopping and starting around flushes. - // Returns true if no error. - bool Flush(); - - // Writes out all data and closes the gzip stream. - // It is the caller's responsibility to close the underlying stream if - // necessary. - // Returns true if no error. - bool Close(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - ZeroCopyOutputStream* sub_stream_; - // Result from calling Next() on sub_stream_ - void* sub_data_; - int sub_data_size_; - - z_stream zcontext_; - int zerror_; - void* input_buffer_; - size_t input_buffer_length_; - - // Shared constructor code. - void Init(ZeroCopyOutputStream* sub_stream, const Options& options); - - // Do some compression. - // Takes zlib flush mode. - // Returns zlib error code. - int Deflate(int flush); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipOutputStream); -}; - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h b/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h deleted file mode 100644 index 7a7a4e77..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +++ /dev/null @@ -1,54 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file exists solely to document the google::protobuf::io namespace. -// It is not compiled into anything, but it may be read by an automated -// documentation generator. - -namespace google { - -namespace protobuf { - -// Auxiliary classes used for I/O. -// -// The Protocol Buffer library uses the classes in this package to deal with -// I/O and encoding/decoding raw bytes. Most users will not need to -// deal with this package. However, users who want to adapt the system to -// work with their own I/O abstractions -- e.g., to allow Protocol Buffers -// to be read from a different kind of input stream without the need for a -// temporary buffer -- should take a closer look. -namespace io {} - -} // namespace protobuf -} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h b/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h deleted file mode 100644 index 5be48543..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +++ /dev/null @@ -1,136 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Utility class for writing text to a ZeroCopyOutputStream. - -#ifndef GOOGLE_PROTOBUF_IO_PRINTER_H__ -#define GOOGLE_PROTOBUF_IO_PRINTER_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace io { - -class ZeroCopyOutputStream; // zero_copy_stream.h - -// This simple utility class assists in code generation. It basically -// allows the caller to define a set of variables and then output some -// text with variable substitutions. Example usage: -// -// Printer printer(output, '$'); -// map vars; -// vars["name"] = "Bob"; -// printer.Print(vars, "My name is $name$."); -// -// The above writes "My name is Bob." to the output stream. -// -// Printer aggressively enforces correct usage, crashing (with assert failures) -// in the case of undefined variables in debug builds. This helps greatly in -// debugging code which uses it. -class LIBPROTOBUF_EXPORT Printer { - public: - // Create a printer that writes text to the given output stream. Use the - // given character as the delimiter for variables. - Printer(ZeroCopyOutputStream* output, char variable_delimiter); - ~Printer(); - - // Print some text after applying variable substitutions. If a particular - // variable in the text is not defined, this will crash. Variables to be - // substituted are identified by their names surrounded by delimiter - // characters (as given to the constructor). The variable bindings are - // defined by the given map. - void Print(const map& variables, const char* text); - - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable, const string& value); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2, - const char* variable3, const string& value3); - // TODO(kenton): Overloaded versions with more variables? Three seems - // to be enough. - - // Indent text by two spaces. After calling Indent(), two spaces will be - // inserted at the beginning of each line of text. Indent() may be called - // multiple times to produce deeper indents. - void Indent(); - - // Reduces the current indent level by two spaces, or crashes if the indent - // level is zero. - void Outdent(); - - // Write a string to the output buffer. - // This method does not look for newlines to add indentation. - void PrintRaw(const string& data); - - // Write a zero-delimited string to output buffer. - // This method does not look for newlines to add indentation. - void PrintRaw(const char* data); - - // Write some bytes to the output buffer. - // This method does not look for newlines to add indentation. - void WriteRaw(const char* data, int size); - - // True if any write to the underlying stream failed. (We don't just - // crash in this case because this is an I/O failure, not a programming - // error.) - bool failed() const { return failed_; } - - private: - const char variable_delimiter_; - - ZeroCopyOutputStream* const output_; - char* buffer_; - int buffer_size_; - - string indent_; - bool at_start_of_line_; - bool failed_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Printer); -}; - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_PRINTER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h b/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h deleted file mode 100644 index 8f759abb..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +++ /dev/null @@ -1,313 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Class for parsing tokenized text from a ZeroCopyInputStream. - -#ifndef GOOGLE_PROTOBUF_IO_TOKENIZER_H__ -#define GOOGLE_PROTOBUF_IO_TOKENIZER_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace io { - -class ZeroCopyInputStream; // zero_copy_stream.h - -// Defined in this file. -class ErrorCollector; -class Tokenizer; - -// Abstract interface for an object which collects the errors that occur -// during parsing. A typical implementation might simply print the errors -// to stdout. -class LIBPROTOBUF_EXPORT ErrorCollector { - public: - inline ErrorCollector() {} - virtual ~ErrorCollector(); - - // Indicates that there was an error in the input at the given line and - // column numbers. The numbers are zero-based, so you may want to add - // 1 to each before printing them. - virtual void AddError(int line, int column, const string& message) = 0; - - // Indicates that there was a warning in the input at the given line and - // column numbers. The numbers are zero-based, so you may want to add - // 1 to each before printing them. - virtual void AddWarning(int line, int column, const string& message) { } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); -}; - -// This class converts a stream of raw text into a stream of tokens for -// the protocol definition parser to parse. The tokens recognized are -// similar to those that make up the C language; see the TokenType enum for -// precise descriptions. Whitespace and comments are skipped. By default, -// C- and C++-style comments are recognized, but other styles can be used by -// calling set_comment_style(). -class LIBPROTOBUF_EXPORT Tokenizer { - public: - // Construct a Tokenizer that reads and tokenizes text from the given - // input stream and writes errors to the given error_collector. - // The caller keeps ownership of input and error_collector. - Tokenizer(ZeroCopyInputStream* input, ErrorCollector* error_collector); - ~Tokenizer(); - - enum TokenType { - TYPE_START, // Next() has not yet been called. - TYPE_END, // End of input reached. "text" is empty. - - TYPE_IDENTIFIER, // A sequence of letters, digits, and underscores, not - // starting with a digit. It is an error for a number - // to be followed by an identifier with no space in - // between. - TYPE_INTEGER, // A sequence of digits representing an integer. Normally - // the digits are decimal, but a prefix of "0x" indicates - // a hex number and a leading zero indicates octal, just - // like with C numeric literals. A leading negative sign - // is NOT included in the token; it's up to the parser to - // interpret the unary minus operator on its own. - TYPE_FLOAT, // A floating point literal, with a fractional part and/or - // an exponent. Always in decimal. Again, never - // negative. - TYPE_STRING, // A quoted sequence of escaped characters. Either single - // or double quotes can be used, but they must match. - // A string literal cannot cross a line break. - TYPE_SYMBOL, // Any other printable character, like '!' or '+'. - // Symbols are always a single character, so "!+$%" is - // four tokens. - }; - - // Structure representing a token read from the token stream. - struct Token { - TokenType type; - string text; // The exact text of the token as it appeared in - // the input. e.g. tokens of TYPE_STRING will still - // be escaped and in quotes. - - // "line" and "column" specify the position of the first character of - // the token within the input stream. They are zero-based. - int line; - int column; - int end_column; - }; - - // Get the current token. This is updated when Next() is called. Before - // the first call to Next(), current() has type TYPE_START and no contents. - const Token& current(); - - // Return the previous token -- i.e. what current() returned before the - // previous call to Next(). - const Token& previous(); - - // Advance to the next token. Returns false if the end of the input is - // reached. - bool Next(); - - // Parse helpers --------------------------------------------------- - - // Parses a TYPE_FLOAT token. This never fails, so long as the text actually - // comes from a TYPE_FLOAT token parsed by Tokenizer. If it doesn't, the - // result is undefined (possibly an assert failure). - static double ParseFloat(const string& text); - - // Parses a TYPE_STRING token. This never fails, so long as the text actually - // comes from a TYPE_STRING token parsed by Tokenizer. If it doesn't, the - // result is undefined (possibly an assert failure). - static void ParseString(const string& text, string* output); - - // Identical to ParseString, but appends to output. - static void ParseStringAppend(const string& text, string* output); - - // Parses a TYPE_INTEGER token. Returns false if the result would be - // greater than max_value. Otherwise, returns true and sets *output to the - // result. If the text is not from a Token of type TYPE_INTEGER originally - // parsed by a Tokenizer, the result is undefined (possibly an assert - // failure). - static bool ParseInteger(const string& text, uint64 max_value, - uint64* output); - - // Options --------------------------------------------------------- - - // Set true to allow floats to be suffixed with the letter 'f'. Tokens - // which would otherwise be integers but which have the 'f' suffix will be - // forced to be interpreted as floats. For all other purposes, the 'f' is - // ignored. - void set_allow_f_after_float(bool value) { allow_f_after_float_ = value; } - - // Valid values for set_comment_style(). - enum CommentStyle { - // Line comments begin with "//", block comments are delimited by "/*" and - // "*/". - CPP_COMMENT_STYLE, - // Line comments begin with "#". No way to write block comments. - SH_COMMENT_STYLE - }; - - // Sets the comment style. - void set_comment_style(CommentStyle style) { comment_style_ = style; } - - // ----------------------------------------------------------------- - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Tokenizer); - - Token current_; // Returned by current(). - Token previous_; // Returned by previous(). - - ZeroCopyInputStream* input_; - ErrorCollector* error_collector_; - - char current_char_; // == buffer_[buffer_pos_], updated by NextChar(). - const char* buffer_; // Current buffer returned from input_. - int buffer_size_; // Size of buffer_. - int buffer_pos_; // Current position within the buffer. - bool read_error_; // Did we previously encounter a read error? - - // Line and column number of current_char_ within the whole input stream. - int line_; - int column_; - - // Position in buffer_ where StartToken() was called. If the token - // started in the previous buffer, this is zero, and current_.text already - // contains the part of the token from the previous buffer. If not - // currently parsing a token, this is -1. - int token_start_; - - // Options. - bool allow_f_after_float_; - CommentStyle comment_style_; - - // Since we count columns we need to interpret tabs somehow. We'll take - // the standard 8-character definition for lack of any way to do better. - static const int kTabWidth = 8; - - // ----------------------------------------------------------------- - // Helper methods. - - // Consume this character and advance to the next one. - void NextChar(); - - // Read a new buffer from the input. - void Refresh(); - - // Called when the current character is the first character of a new - // token (not including whitespace or comments). - inline void StartToken(); - // Called when the current character is the first character after the - // end of the last token. After this returns, current_.text will - // contain all text consumed since StartToken() was called. - inline void EndToken(); - - // Convenience method to add an error at the current line and column. - void AddError(const string& message) { - error_collector_->AddError(line_, column_, message); - } - - // ----------------------------------------------------------------- - // The following four methods are used to consume tokens of specific - // types. They are actually used to consume all characters *after* - // the first, since the calling function consumes the first character - // in order to decide what kind of token is being read. - - // Read and consume a string, ending when the given delimiter is - // consumed. - void ConsumeString(char delimiter); - - // Read and consume a number, returning TYPE_FLOAT or TYPE_INTEGER - // depending on what was read. This needs to know if the first - // character was a zero in order to correctly recognize hex and octal - // numbers. - // It also needs to know if the first characted was a . to parse floating - // point correctly. - TokenType ConsumeNumber(bool started_with_zero, bool started_with_dot); - - // Consume the rest of a line. - void ConsumeLineComment(); - // Consume until "*/". - void ConsumeBlockComment(); - - // ----------------------------------------------------------------- - // These helper methods make the parsing code more readable. The - // "character classes" refered to are defined at the top of the .cc file. - // Basically it is a C++ class with one method: - // static bool InClass(char c); - // The method returns true if c is a member of this "class", like "Letter" - // or "Digit". - - // Returns true if the current character is of the given character - // class, but does not consume anything. - template - inline bool LookingAt(); - - // If the current character is in the given class, consume it and return - // true. Otherwise return false. - // e.g. TryConsumeOne() - template - inline bool TryConsumeOne(); - - // Like above, but try to consume the specific character indicated. - inline bool TryConsume(char c); - - // Consume zero or more of the given character class. - template - inline void ConsumeZeroOrMore(); - - // Consume one or more of the given character class or log the given - // error message. - // e.g. ConsumeOneOrMore("Expected digits."); - template - inline void ConsumeOneOrMore(const char* error); -}; - -// inline methods ==================================================== -inline const Tokenizer::Token& Tokenizer::current() { - return current_; -} - -inline const Tokenizer::Token& Tokenizer::previous() { - return previous_; -} - -inline void Tokenizer::ParseString(const string& text, string* output) { - output->clear(); - ParseStringAppend(text, output); -} - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_TOKENIZER_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h deleted file mode 100644 index db5326f7..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +++ /dev/null @@ -1,238 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains the ZeroCopyInputStream and ZeroCopyOutputStream -// interfaces, which represent abstract I/O streams to and from which -// protocol buffers can be read and written. For a few simple -// implementations of these interfaces, see zero_copy_stream_impl.h. -// -// These interfaces are different from classic I/O streams in that they -// try to minimize the amount of data copying that needs to be done. -// To accomplish this, responsibility for allocating buffers is moved to -// the stream object, rather than being the responsibility of the caller. -// So, the stream can return a buffer which actually points directly into -// the final data structure where the bytes are to be stored, and the caller -// can interact directly with that buffer, eliminating an intermediate copy -// operation. -// -// As an example, consider the common case in which you are reading bytes -// from an array that is already in memory (or perhaps an mmap()ed file). -// With classic I/O streams, you would do something like: -// char buffer[BUFFER_SIZE]; -// input->Read(buffer, BUFFER_SIZE); -// DoSomething(buffer, BUFFER_SIZE); -// Then, the stream basically just calls memcpy() to copy the data from -// the array into your buffer. With a ZeroCopyInputStream, you would do -// this instead: -// const void* buffer; -// int size; -// input->Next(&buffer, &size); -// DoSomething(buffer, size); -// Here, no copy is performed. The input stream returns a pointer directly -// into the backing array, and the caller ends up reading directly from it. -// -// If you want to be able to read the old-fashion way, you can create -// a CodedInputStream or CodedOutputStream wrapping these objects and use -// their ReadRaw()/WriteRaw() methods. These will, of course, add a copy -// step, but Coded*Stream will handle buffering so at least it will be -// reasonably efficient. -// -// ZeroCopyInputStream example: -// // Read in a file and print its contents to stdout. -// int fd = open("myfile", O_RDONLY); -// ZeroCopyInputStream* input = new FileInputStream(fd); -// -// const void* buffer; -// int size; -// while (input->Next(&buffer, &size)) { -// cout.write(buffer, size); -// } -// -// delete input; -// close(fd); -// -// ZeroCopyOutputStream example: -// // Copy the contents of "infile" to "outfile", using plain read() for -// // "infile" but a ZeroCopyOutputStream for "outfile". -// int infd = open("infile", O_RDONLY); -// int outfd = open("outfile", O_WRONLY); -// ZeroCopyOutputStream* output = new FileOutputStream(outfd); -// -// void* buffer; -// int size; -// while (output->Next(&buffer, &size)) { -// int bytes = read(infd, buffer, size); -// if (bytes < size) { -// // Reached EOF. -// output->BackUp(size - bytes); -// break; -// } -// } -// -// delete output; -// close(infd); -// close(outfd); - -#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ -#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ - -#include -#include - -namespace google { - -namespace protobuf { -namespace io { - -// Defined in this file. -class ZeroCopyInputStream; -class ZeroCopyOutputStream; - -// Abstract interface similar to an input stream but designed to minimize -// copying. -class LIBPROTOBUF_EXPORT ZeroCopyInputStream { - public: - inline ZeroCopyInputStream() {} - virtual ~ZeroCopyInputStream(); - - // Obtains a chunk of data from the stream. - // - // Preconditions: - // * "size" and "data" are not NULL. - // - // Postconditions: - // * If the returned value is false, there is no more data to return or - // an error occurred. All errors are permanent. - // * Otherwise, "size" points to the actual number of bytes read and "data" - // points to a pointer to a buffer containing these bytes. - // * Ownership of this buffer remains with the stream, and the buffer - // remains valid only until some other method of the stream is called - // or the stream is destroyed. - // * It is legal for the returned buffer to have zero size, as long - // as repeatedly calling Next() eventually yields a buffer with non-zero - // size. - virtual bool Next(const void** data, int* size) = 0; - - // Backs up a number of bytes, so that the next call to Next() returns - // data again that was already returned by the last call to Next(). This - // is useful when writing procedures that are only supposed to read up - // to a certain point in the input, then return. If Next() returns a - // buffer that goes beyond what you wanted to read, you can use BackUp() - // to return to the point where you intended to finish. - // - // Preconditions: - // * The last method called must have been Next(). - // * count must be less than or equal to the size of the last buffer - // returned by Next(). - // - // Postconditions: - // * The last "count" bytes of the last buffer returned by Next() will be - // pushed back into the stream. Subsequent calls to Next() will return - // the same data again before producing new data. - virtual void BackUp(int count) = 0; - - // Skips a number of bytes. Returns false if the end of the stream is - // reached or some input error occurred. In the end-of-stream case, the - // stream is advanced to the end of the stream (so ByteCount() will return - // the total size of the stream). - virtual bool Skip(int count) = 0; - - // Returns the total number of bytes read since this object was created. - virtual int64 ByteCount() const = 0; - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyInputStream); -}; - -// Abstract interface similar to an output stream but designed to minimize -// copying. -class LIBPROTOBUF_EXPORT ZeroCopyOutputStream { - public: - inline ZeroCopyOutputStream() {} - virtual ~ZeroCopyOutputStream(); - - // Obtains a buffer into which data can be written. Any data written - // into this buffer will eventually (maybe instantly, maybe later on) - // be written to the output. - // - // Preconditions: - // * "size" and "data" are not NULL. - // - // Postconditions: - // * If the returned value is false, an error occurred. All errors are - // permanent. - // * Otherwise, "size" points to the actual number of bytes in the buffer - // and "data" points to the buffer. - // * Ownership of this buffer remains with the stream, and the buffer - // remains valid only until some other method of the stream is called - // or the stream is destroyed. - // * Any data which the caller stores in this buffer will eventually be - // written to the output (unless BackUp() is called). - // * It is legal for the returned buffer to have zero size, as long - // as repeatedly calling Next() eventually yields a buffer with non-zero - // size. - virtual bool Next(void** data, int* size) = 0; - - // Backs up a number of bytes, so that the end of the last buffer returned - // by Next() is not actually written. This is needed when you finish - // writing all the data you want to write, but the last buffer was bigger - // than you needed. You don't want to write a bunch of garbage after the - // end of your data, so you use BackUp() to back up. - // - // Preconditions: - // * The last method called must have been Next(). - // * count must be less than or equal to the size of the last buffer - // returned by Next(). - // * The caller must not have written anything to the last "count" bytes - // of that buffer. - // - // Postconditions: - // * The last "count" bytes of the last buffer returned by Next() will be - // ignored. - virtual void BackUp(int count) = 0; - - // Returns the total number of bytes written since this object was created. - virtual int64 ByteCount() const = 0; - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyOutputStream); -}; - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h deleted file mode 100644 index 9fedb005..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +++ /dev/null @@ -1,357 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains common implementations of the interfaces defined in -// zero_copy_stream.h which are only included in the full (non-lite) -// protobuf library. These implementations include Unix file descriptors -// and C++ iostreams. See also: zero_copy_stream_impl_lite.h - -#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ -#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ - -#include -#include -#include -#include -#include - - -namespace google { -namespace protobuf { -namespace io { - - -// =================================================================== - -// A ZeroCopyInputStream which reads from a file descriptor. -// -// FileInputStream is preferred over using an ifstream with IstreamInputStream. -// The latter will introduce an extra layer of buffering, harming performance. -// Also, it's conceivable that FileInputStream could someday be enhanced -// to use zero-copy file descriptors on OSs which support them. -class LIBPROTOBUF_EXPORT FileInputStream : public ZeroCopyInputStream { - public: - // Creates a stream that reads from the given Unix file descriptor. - // If a block_size is given, it specifies the number of bytes that - // should be read and returned with each call to Next(). Otherwise, - // a reasonable default is used. - explicit FileInputStream(int file_descriptor, int block_size = -1); - ~FileInputStream(); - - // Flushes any buffers and closes the underlying file. Returns false if - // an error occurs during the process; use GetErrno() to examine the error. - // Even if an error occurs, the file descriptor is closed when this returns. - bool Close(); - - // By default, the file descriptor is not closed when the stream is - // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: - // This leaves no way for the caller to detect if close() fails. If - // detecting close() errors is important to you, you should arrange - // to close the descriptor yourself. - void SetCloseOnDelete(bool value) { copying_input_.SetCloseOnDelete(value); } - - // If an I/O error has occurred on this file descriptor, this is the - // errno from that error. Otherwise, this is zero. Once an error - // occurs, the stream is broken and all subsequent operations will - // fail. - int GetErrno() { return copying_input_.GetErrno(); } - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingFileInputStream : public CopyingInputStream { - public: - CopyingFileInputStream(int file_descriptor); - ~CopyingFileInputStream(); - - bool Close(); - void SetCloseOnDelete(bool value) { close_on_delete_ = value; } - int GetErrno() { return errno_; } - - // implements CopyingInputStream --------------------------------- - int Read(void* buffer, int size); - int Skip(int count); - - private: - // The file descriptor. - const int file_; - bool close_on_delete_; - bool is_closed_; - - // The errno of the I/O error, if one has occurred. Otherwise, zero. - int errno_; - - // Did we try to seek once and fail? If so, we assume this file descriptor - // doesn't support seeking and won't try again. - bool previous_seek_failed_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileInputStream); - }; - - CopyingFileInputStream copying_input_; - CopyingInputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileInputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream which writes to a file descriptor. -// -// FileOutputStream is preferred over using an ofstream with -// OstreamOutputStream. The latter will introduce an extra layer of buffering, -// harming performance. Also, it's conceivable that FileOutputStream could -// someday be enhanced to use zero-copy file descriptors on OSs which -// support them. -class LIBPROTOBUF_EXPORT FileOutputStream : public ZeroCopyOutputStream { - public: - // Creates a stream that writes to the given Unix file descriptor. - // If a block_size is given, it specifies the size of the buffers - // that should be returned by Next(). Otherwise, a reasonable default - // is used. - explicit FileOutputStream(int file_descriptor, int block_size = -1); - ~FileOutputStream(); - - // Flushes any buffers and closes the underlying file. Returns false if - // an error occurs during the process; use GetErrno() to examine the error. - // Even if an error occurs, the file descriptor is closed when this returns. - bool Close(); - - // Flushes FileOutputStream's buffers but does not close the - // underlying file. No special measures are taken to ensure that - // underlying operating system file object is synchronized to disk. - bool Flush(); - - // By default, the file descriptor is not closed when the stream is - // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: - // This leaves no way for the caller to detect if close() fails. If - // detecting close() errors is important to you, you should arrange - // to close the descriptor yourself. - void SetCloseOnDelete(bool value) { copying_output_.SetCloseOnDelete(value); } - - // If an I/O error has occurred on this file descriptor, this is the - // errno from that error. Otherwise, this is zero. Once an error - // occurs, the stream is broken and all subsequent operations will - // fail. - int GetErrno() { return copying_output_.GetErrno(); } - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingFileOutputStream : public CopyingOutputStream { - public: - CopyingFileOutputStream(int file_descriptor); - ~CopyingFileOutputStream(); - - bool Close(); - void SetCloseOnDelete(bool value) { close_on_delete_ = value; } - int GetErrno() { return errno_; } - - // implements CopyingOutputStream -------------------------------- - bool Write(const void* buffer, int size); - - private: - // The file descriptor. - const int file_; - bool close_on_delete_; - bool is_closed_; - - // The errno of the I/O error, if one has occurred. Otherwise, zero. - int errno_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileOutputStream); - }; - - CopyingFileOutputStream copying_output_; - CopyingOutputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileOutputStream); -}; - -// =================================================================== - -// A ZeroCopyInputStream which reads from a C++ istream. -// -// Note that for reading files (or anything represented by a file descriptor), -// FileInputStream is more efficient. -class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { - public: - // Creates a stream that reads from the given C++ istream. - // If a block_size is given, it specifies the number of bytes that - // should be read and returned with each call to Next(). Otherwise, - // a reasonable default is used. - explicit IstreamInputStream(istream* stream, int block_size = -1); - ~IstreamInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream { - public: - CopyingIstreamInputStream(istream* input); - ~CopyingIstreamInputStream(); - - // implements CopyingInputStream --------------------------------- - int Read(void* buffer, int size); - // (We use the default implementation of Skip().) - - private: - // The stream. - istream* input_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); - }; - - CopyingIstreamInputStream copying_input_; - CopyingInputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream which writes to a C++ ostream. -// -// Note that for writing files (or anything represented by a file descriptor), -// FileOutputStream is more efficient. -class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { - public: - // Creates a stream that writes to the given C++ ostream. - // If a block_size is given, it specifies the size of the buffers - // that should be returned by Next(). Otherwise, a reasonable default - // is used. - explicit OstreamOutputStream(ostream* stream, int block_size = -1); - ~OstreamOutputStream(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStream { - public: - CopyingOstreamOutputStream(ostream* output); - ~CopyingOstreamOutputStream(); - - // implements CopyingOutputStream -------------------------------- - bool Write(const void* buffer, int size); - - private: - // The stream. - ostream* output_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); - }; - - CopyingOstreamOutputStream copying_output_; - CopyingOutputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream); -}; - -// =================================================================== - -// A ZeroCopyInputStream which reads from several other streams in sequence. -// ConcatenatingInputStream is unable to distinguish between end-of-stream -// and read errors in the underlying streams, so it assumes any errors mean -// end-of-stream. So, if the underlying streams fail for any other reason, -// ConcatenatingInputStream may do odd things. It is suggested that you do -// not use ConcatenatingInputStream on streams that might produce read errors -// other than end-of-stream. -class LIBPROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream { - public: - // All streams passed in as well as the array itself must remain valid - // until the ConcatenatingInputStream is destroyed. - ConcatenatingInputStream(ZeroCopyInputStream* const streams[], int count); - ~ConcatenatingInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - - private: - // As streams are retired, streams_ is incremented and count_ is - // decremented. - ZeroCopyInputStream* const* streams_; - int stream_count_; - int64 bytes_retired_; // Bytes read from previous streams. - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ConcatenatingInputStream); -}; - -// =================================================================== - -// A ZeroCopyInputStream which wraps some other stream and limits it to -// a particular byte count. -class LIBPROTOBUF_EXPORT LimitingInputStream : public ZeroCopyInputStream { - public: - LimitingInputStream(ZeroCopyInputStream* input, int64 limit); - ~LimitingInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - - private: - ZeroCopyInputStream* input_; - int64 limit_; // Decreases as we go, becomes negative if we overshoot. - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); -}; - -// =================================================================== - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h deleted file mode 100644 index 153f543e..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +++ /dev/null @@ -1,340 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains common implementations of the interfaces defined in -// zero_copy_stream.h which are included in the "lite" protobuf library. -// These implementations cover I/O on raw arrays and strings, as well as -// adaptors which make it easy to implement streams based on traditional -// streams. Of course, many users will probably want to write their own -// implementations of these interfaces specific to the particular I/O -// abstractions they prefer to use, but these should cover the most common -// cases. - -#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ -#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ - -#include -#include -#include -#include - - -namespace google { -namespace protobuf { -namespace io { - -// =================================================================== - -// A ZeroCopyInputStream backed by an in-memory array of bytes. -class LIBPROTOBUF_EXPORT ArrayInputStream : public ZeroCopyInputStream { - public: - // Create an InputStream that returns the bytes pointed to by "data". - // "data" remains the property of the caller but must remain valid until - // the stream is destroyed. If a block_size is given, calls to Next() - // will return data blocks no larger than the given size. Otherwise, the - // first call to Next() returns the entire array. block_size is mainly - // useful for testing; in production you would probably never want to set - // it. - ArrayInputStream(const void* data, int size, int block_size = -1); - ~ArrayInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - - private: - const uint8* const data_; // The byte array. - const int size_; // Total size of the array. - const int block_size_; // How many bytes to return at a time. - - int position_; - int last_returned_size_; // How many bytes we returned last time Next() - // was called (used for error checking only). - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayInputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream backed by an in-memory array of bytes. -class LIBPROTOBUF_EXPORT ArrayOutputStream : public ZeroCopyOutputStream { - public: - // Create an OutputStream that writes to the bytes pointed to by "data". - // "data" remains the property of the caller but must remain valid until - // the stream is destroyed. If a block_size is given, calls to Next() - // will return data blocks no larger than the given size. Otherwise, the - // first call to Next() returns the entire array. block_size is mainly - // useful for testing; in production you would probably never want to set - // it. - ArrayOutputStream(void* data, int size, int block_size = -1); - ~ArrayOutputStream(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - uint8* const data_; // The byte array. - const int size_; // Total size of the array. - const int block_size_; // How many bytes to return at a time. - - int position_; - int last_returned_size_; // How many bytes we returned last time Next() - // was called (used for error checking only). - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayOutputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream which appends bytes to a string. -class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream { - public: - // Create a StringOutputStream which appends bytes to the given string. - // The string remains property of the caller, but it MUST NOT be accessed - // in any way until the stream is destroyed. - // - // Hint: If you call target->reserve(n) before creating the stream, - // the first call to Next() will return at least n bytes of buffer - // space. - explicit StringOutputStream(string* target); - ~StringOutputStream(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - static const int kMinimumSize = 16; - - string* target_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream); -}; - -// Note: There is no StringInputStream. Instead, just create an -// ArrayInputStream as follows: -// ArrayInputStream input(str.data(), str.size()); - -// =================================================================== - -// A generic traditional input stream interface. -// -// Lots of traditional input streams (e.g. file descriptors, C stdio -// streams, and C++ iostreams) expose an interface where every read -// involves copying bytes into a buffer. If you want to take such an -// interface and make a ZeroCopyInputStream based on it, simply implement -// CopyingInputStream and then use CopyingInputStreamAdaptor. -// -// CopyingInputStream implementations should avoid buffering if possible. -// CopyingInputStreamAdaptor does its own buffering and will read data -// in large blocks. -class LIBPROTOBUF_EXPORT CopyingInputStream { - public: - virtual ~CopyingInputStream(); - - // Reads up to "size" bytes into the given buffer. Returns the number of - // bytes read. Read() waits until at least one byte is available, or - // returns zero if no bytes will ever become available (EOF), or -1 if a - // permanent read error occurred. - virtual int Read(void* buffer, int size) = 0; - - // Skips the next "count" bytes of input. Returns the number of bytes - // actually skipped. This will always be exactly equal to "count" unless - // EOF was reached or a permanent read error occurred. - // - // The default implementation just repeatedly calls Read() into a scratch - // buffer. - virtual int Skip(int count); -}; - -// A ZeroCopyInputStream which reads from a CopyingInputStream. This is -// useful for implementing ZeroCopyInputStreams that read from traditional -// streams. Note that this class is not really zero-copy. -// -// If you want to read from file descriptors or C++ istreams, this is -// already implemented for you: use FileInputStream or IstreamInputStream -// respectively. -class LIBPROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream { - public: - // Creates a stream that reads from the given CopyingInputStream. - // If a block_size is given, it specifies the number of bytes that - // should be read and returned with each call to Next(). Otherwise, - // a reasonable default is used. The caller retains ownership of - // copying_stream unless SetOwnsCopyingStream(true) is called. - explicit CopyingInputStreamAdaptor(CopyingInputStream* copying_stream, - int block_size = -1); - ~CopyingInputStreamAdaptor(); - - // Call SetOwnsCopyingStream(true) to tell the CopyingInputStreamAdaptor to - // delete the underlying CopyingInputStream when it is destroyed. - void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; } - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - // Insures that buffer_ is not NULL. - void AllocateBufferIfNeeded(); - // Frees the buffer and resets buffer_used_. - void FreeBuffer(); - - // The underlying copying stream. - CopyingInputStream* copying_stream_; - bool owns_copying_stream_; - - // True if we have seen a permenant error from the underlying stream. - bool failed_; - - // The current position of copying_stream_, relative to the point where - // we started reading. - int64 position_; - - // Data is read into this buffer. It may be NULL if no buffer is currently - // in use. Otherwise, it points to an array of size buffer_size_. - scoped_array buffer_; - const int buffer_size_; - - // Number of valid bytes currently in the buffer (i.e. the size last - // returned by Next()). 0 <= buffer_used_ <= buffer_size_. - int buffer_used_; - - // Number of bytes in the buffer which were backed up over by a call to - // BackUp(). These need to be returned again. - // 0 <= backup_bytes_ <= buffer_used_ - int backup_bytes_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingInputStreamAdaptor); -}; - -// =================================================================== - -// A generic traditional output stream interface. -// -// Lots of traditional output streams (e.g. file descriptors, C stdio -// streams, and C++ iostreams) expose an interface where every write -// involves copying bytes from a buffer. If you want to take such an -// interface and make a ZeroCopyOutputStream based on it, simply implement -// CopyingOutputStream and then use CopyingOutputStreamAdaptor. -// -// CopyingOutputStream implementations should avoid buffering if possible. -// CopyingOutputStreamAdaptor does its own buffering and will write data -// in large blocks. -class LIBPROTOBUF_EXPORT CopyingOutputStream { - public: - virtual ~CopyingOutputStream(); - - // Writes "size" bytes from the given buffer to the output. Returns true - // if successful, false on a write error. - virtual bool Write(const void* buffer, int size) = 0; -}; - -// A ZeroCopyOutputStream which writes to a CopyingOutputStream. This is -// useful for implementing ZeroCopyOutputStreams that write to traditional -// streams. Note that this class is not really zero-copy. -// -// If you want to write to file descriptors or C++ ostreams, this is -// already implemented for you: use FileOutputStream or OstreamOutputStream -// respectively. -class LIBPROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStream { - public: - // Creates a stream that writes to the given Unix file descriptor. - // If a block_size is given, it specifies the size of the buffers - // that should be returned by Next(). Otherwise, a reasonable default - // is used. - explicit CopyingOutputStreamAdaptor(CopyingOutputStream* copying_stream, - int block_size = -1); - ~CopyingOutputStreamAdaptor(); - - // Writes all pending data to the underlying stream. Returns false if a - // write error occurred on the underlying stream. (The underlying - // stream itself is not necessarily flushed.) - bool Flush(); - - // Call SetOwnsCopyingStream(true) to tell the CopyingOutputStreamAdaptor to - // delete the underlying CopyingOutputStream when it is destroyed. - void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; } - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - // Write the current buffer, if it is present. - bool WriteBuffer(); - // Insures that buffer_ is not NULL. - void AllocateBufferIfNeeded(); - // Frees the buffer. - void FreeBuffer(); - - // The underlying copying stream. - CopyingOutputStream* copying_stream_; - bool owns_copying_stream_; - - // True if we have seen a permenant error from the underlying stream. - bool failed_; - - // The current position of copying_stream_, relative to the point where - // we started writing. - int64 position_; - - // Data is written from this buffer. It may be NULL if no buffer is - // currently in use. Otherwise, it points to an array of size buffer_size_. - scoped_array buffer_; - const int buffer_size_; - - // Number of valid bytes currently in the buffer (i.e. the size last - // returned by Next()). When BackUp() is called, we just reduce this. - // 0 <= buffer_used_ <= buffer_size_. - int buffer_used_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOutputStreamAdaptor); -}; - -// =================================================================== - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/message.h b/ext/protobuf-2.4.1/src/google/protobuf/message.h deleted file mode 100644 index 4bbc6418..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/message.h +++ /dev/null @@ -1,692 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines Message, the abstract interface implemented by non-lite -// protocol message objects. Although it's possible to implement this -// interface manually, most users will use the protocol compiler to -// generate implementations. -// -// Example usage: -// -// Say you have a message defined as: -// -// message Foo { -// optional string text = 1; -// repeated int32 numbers = 2; -// } -// -// Then, if you used the protocol compiler to generate a class from the above -// definition, you could use it like so: -// -// string data; // Will store a serialized version of the message. -// -// { -// // Create a message and serialize it. -// Foo foo; -// foo.set_text("Hello World!"); -// foo.add_numbers(1); -// foo.add_numbers(5); -// foo.add_numbers(42); -// -// foo.SerializeToString(&data); -// } -// -// { -// // Parse the serialized message and check that it contains the -// // correct data. -// Foo foo; -// foo.ParseFromString(data); -// -// assert(foo.text() == "Hello World!"); -// assert(foo.numbers_size() == 3); -// assert(foo.numbers(0) == 1); -// assert(foo.numbers(1) == 5); -// assert(foo.numbers(2) == 42); -// } -// -// { -// // Same as the last block, but do it dynamically via the Message -// // reflection interface. -// Message* foo = new Foo; -// Descriptor* descriptor = foo->GetDescriptor(); -// -// // Get the descriptors for the fields we're interested in and verify -// // their types. -// FieldDescriptor* text_field = descriptor->FindFieldByName("text"); -// assert(text_field != NULL); -// assert(text_field->type() == FieldDescriptor::TYPE_STRING); -// assert(text_field->label() == FieldDescriptor::TYPE_OPTIONAL); -// FieldDescriptor* numbers_field = descriptor->FindFieldByName("numbers"); -// assert(numbers_field != NULL); -// assert(numbers_field->type() == FieldDescriptor::TYPE_INT32); -// assert(numbers_field->label() == FieldDescriptor::TYPE_REPEATED); -// -// // Parse the message. -// foo->ParseFromString(data); -// -// // Use the reflection interface to examine the contents. -// const Reflection* reflection = foo->GetReflection(); -// assert(reflection->GetString(foo, text_field) == "Hello World!"); -// assert(reflection->FieldSize(foo, numbers_field) == 3); -// assert(reflection->GetRepeatedInt32(foo, numbers_field, 0) == 1); -// assert(reflection->GetRepeatedInt32(foo, numbers_field, 1) == 5); -// assert(reflection->GetRepeatedInt32(foo, numbers_field, 2) == 42); -// -// delete foo; -// } - -#ifndef GOOGLE_PROTOBUF_MESSAGE_H__ -#define GOOGLE_PROTOBUF_MESSAGE_H__ - -#include -#include - -#ifdef __DECCXX -// HP C++'s iosfwd doesn't work. -#include -#else -#include -#endif - -#include - -#include - - -namespace google { -namespace protobuf { - -// Defined in this file. -class Message; -class Reflection; -class MessageFactory; - -// Defined in other files. -class Descriptor; // descriptor.h -class FieldDescriptor; // descriptor.h -class EnumDescriptor; // descriptor.h -class EnumValueDescriptor; // descriptor.h -namespace io { - class ZeroCopyInputStream; // zero_copy_stream.h - class ZeroCopyOutputStream; // zero_copy_stream.h - class CodedInputStream; // coded_stream.h - class CodedOutputStream; // coded_stream.h -} -class UnknownFieldSet; // unknown_field_set.h - -// A container to hold message metadata. -struct Metadata { - const Descriptor* descriptor; - const Reflection* reflection; -}; - -// Returns the EnumDescriptor for enum type E, which must be a -// proto-declared enum type. Code generated by the protocol compiler -// will include specializations of this template for each enum type declared. -template -const EnumDescriptor* GetEnumDescriptor(); - -// Abstract interface for protocol messages. -// -// See also MessageLite, which contains most every-day operations. Message -// adds descriptors and reflection on top of that. -// -// The methods of this class that are virtual but not pure-virtual have -// default implementations based on reflection. Message classes which are -// optimized for speed will want to override these with faster implementations, -// but classes optimized for code size may be happy with keeping them. See -// the optimize_for option in descriptor.proto. -class LIBPROTOBUF_EXPORT Message : public MessageLite { - public: - inline Message() {} - virtual ~Message(); - - // Basic Operations ------------------------------------------------ - - // Construct a new instance of the same type. Ownership is passed to the - // caller. (This is also defined in MessageLite, but is defined again here - // for return-type covariance.) - virtual Message* New() const = 0; - - // Make this message into a copy of the given message. The given message - // must have the same descriptor, but need not necessarily be the same class. - // By default this is just implemented as "Clear(); MergeFrom(from);". - virtual void CopyFrom(const Message& from); - - // Merge the fields from the given message into this message. Singular - // fields will be overwritten, except for embedded messages which will - // be merged. Repeated fields will be concatenated. The given message - // must be of the same type as this message (i.e. the exact same class). - virtual void MergeFrom(const Message& from); - - // Verifies that IsInitialized() returns true. GOOGLE_CHECK-fails otherwise, with - // a nice error message. - void CheckInitialized() const; - - // Slowly build a list of all required fields that are not set. - // This is much, much slower than IsInitialized() as it is implemented - // purely via reflection. Generally, you should not call this unless you - // have already determined that an error exists by calling IsInitialized(). - void FindInitializationErrors(vector* errors) const; - - // Like FindInitializationErrors, but joins all the strings, delimited by - // commas, and returns them. - string InitializationErrorString() const; - - // Clears all unknown fields from this message and all embedded messages. - // Normally, if unknown tag numbers are encountered when parsing a message, - // the tag and value are stored in the message's UnknownFieldSet and - // then written back out when the message is serialized. This allows servers - // which simply route messages to other servers to pass through messages - // that have new field definitions which they don't yet know about. However, - // this behavior can have security implications. To avoid it, call this - // method after parsing. - // - // See Reflection::GetUnknownFields() for more on unknown fields. - virtual void DiscardUnknownFields(); - - // Computes (an estimate of) the total number of bytes currently used for - // storing the message in memory. The default implementation calls the - // Reflection object's SpaceUsed() method. - virtual int SpaceUsed() const; - - // Debugging & Testing---------------------------------------------- - - // Generates a human readable form of this message, useful for debugging - // and other purposes. - string DebugString() const; - // Like DebugString(), but with less whitespace. - string ShortDebugString() const; - // Like DebugString(), but do not escape UTF-8 byte sequences. - string Utf8DebugString() const; - // Convenience function useful in GDB. Prints DebugString() to stdout. - void PrintDebugString() const; - - // Heavy I/O ------------------------------------------------------- - // Additional parsing and serialization methods not implemented by - // MessageLite because they are not supported by the lite library. - - // Parse a protocol buffer from a file descriptor. If successful, the entire - // input will be consumed. - bool ParseFromFileDescriptor(int file_descriptor); - // Like ParseFromFileDescriptor(), but accepts messages that are missing - // required fields. - bool ParsePartialFromFileDescriptor(int file_descriptor); - // Parse a protocol buffer from a C++ istream. If successful, the entire - // input will be consumed. - bool ParseFromIstream(istream* input); - // Like ParseFromIstream(), but accepts messages that are missing - // required fields. - bool ParsePartialFromIstream(istream* input); - - // Serialize the message and write it to the given file descriptor. All - // required fields must be set. - bool SerializeToFileDescriptor(int file_descriptor) const; - // Like SerializeToFileDescriptor(), but allows missing required fields. - bool SerializePartialToFileDescriptor(int file_descriptor) const; - // Serialize the message and write it to the given C++ ostream. All - // required fields must be set. - bool SerializeToOstream(ostream* output) const; - // Like SerializeToOstream(), but allows missing required fields. - bool SerializePartialToOstream(ostream* output) const; - - - // Reflection-based methods ---------------------------------------- - // These methods are pure-virtual in MessageLite, but Message provides - // reflection-based default implementations. - - virtual string GetTypeName() const; - virtual void Clear(); - virtual bool IsInitialized() const; - virtual void CheckTypeAndMergeFrom(const MessageLite& other); - virtual bool MergePartialFromCodedStream(io::CodedInputStream* input); - virtual int ByteSize() const; - virtual void SerializeWithCachedSizes(io::CodedOutputStream* output) const; - - private: - // This is called only by the default implementation of ByteSize(), to - // update the cached size. If you override ByteSize(), you do not need - // to override this. If you do not override ByteSize(), you MUST override - // this; the default implementation will crash. - // - // The method is private because subclasses should never call it; only - // override it. Yes, C++ lets you do that. Crazy, huh? - virtual void SetCachedSize(int size) const; - - public: - - // Introspection --------------------------------------------------- - - // Typedef for backwards-compatibility. - typedef google::protobuf::Reflection Reflection; - - // Get a Descriptor for this message's type. This describes what - // fields the message contains, the types of those fields, etc. - const Descriptor* GetDescriptor() const { return GetMetadata().descriptor; } - - // Get the Reflection interface for this Message, which can be used to - // read and modify the fields of the Message dynamically (in other words, - // without knowing the message type at compile time). This object remains - // property of the Message. - // - // This method remains virtual in case a subclass does not implement - // reflection and wants to override the default behavior. - virtual const Reflection* GetReflection() const { - return GetMetadata().reflection; - } - - protected: - // Get a struct containing the metadata for the Message. Most subclasses only - // need to implement this method, rather than the GetDescriptor() and - // GetReflection() wrappers. - virtual Metadata GetMetadata() const = 0; - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Message); -}; - -// This interface contains methods that can be used to dynamically access -// and modify the fields of a protocol message. Their semantics are -// similar to the accessors the protocol compiler generates. -// -// To get the Reflection for a given Message, call Message::GetReflection(). -// -// This interface is separate from Message only for efficiency reasons; -// the vast majority of implementations of Message will share the same -// implementation of Reflection (GeneratedMessageReflection, -// defined in generated_message.h), and all Messages of a particular class -// should share the same Reflection object (though you should not rely on -// the latter fact). -// -// There are several ways that these methods can be used incorrectly. For -// example, any of the following conditions will lead to undefined -// results (probably assertion failures): -// - The FieldDescriptor is not a field of this message type. -// - The method called is not appropriate for the field's type. For -// each field type in FieldDescriptor::TYPE_*, there is only one -// Get*() method, one Set*() method, and one Add*() method that is -// valid for that type. It should be obvious which (except maybe -// for TYPE_BYTES, which are represented using strings in C++). -// - A Get*() or Set*() method for singular fields is called on a repeated -// field. -// - GetRepeated*(), SetRepeated*(), or Add*() is called on a non-repeated -// field. -// - The Message object passed to any method is not of the right type for -// this Reflection object (i.e. message.GetReflection() != reflection). -// -// You might wonder why there is not any abstract representation for a field -// of arbitrary type. E.g., why isn't there just a "GetField()" method that -// returns "const Field&", where "Field" is some class with accessors like -// "GetInt32Value()". The problem is that someone would have to deal with -// allocating these Field objects. For generated message classes, having to -// allocate space for an additional object to wrap every field would at least -// double the message's memory footprint, probably worse. Allocating the -// objects on-demand, on the other hand, would be expensive and prone to -// memory leaks. So, instead we ended up with this flat interface. -// -// TODO(kenton): Create a utility class which callers can use to read and -// write fields from a Reflection without paying attention to the type. -class LIBPROTOBUF_EXPORT Reflection { - public: - // TODO(kenton): Remove parameter. - inline Reflection() {} - virtual ~Reflection(); - - // Get the UnknownFieldSet for the message. This contains fields which - // were seen when the Message was parsed but were not recognized according - // to the Message's definition. - virtual const UnknownFieldSet& GetUnknownFields( - const Message& message) const = 0; - // Get a mutable pointer to the UnknownFieldSet for the message. This - // contains fields which were seen when the Message was parsed but were not - // recognized according to the Message's definition. - virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0; - - // Estimate the amount of memory used by the message object. - virtual int SpaceUsed(const Message& message) const = 0; - - // Check if the given non-repeated field is set. - virtual bool HasField(const Message& message, - const FieldDescriptor* field) const = 0; - - // Get the number of elements of a repeated field. - virtual int FieldSize(const Message& message, - const FieldDescriptor* field) const = 0; - - // Clear the value of a field, so that HasField() returns false or - // FieldSize() returns zero. - virtual void ClearField(Message* message, - const FieldDescriptor* field) const = 0; - - // Remove the last element of a repeated field. - // We don't provide a way to remove any element other than the last - // because it invites inefficient use, such as O(n^2) filtering loops - // that should have been O(n). If you want to remove an element other - // than the last, the best way to do it is to re-arrange the elements - // (using Swap()) so that the one you want removed is at the end, then - // call RemoveLast(). - virtual void RemoveLast(Message* message, - const FieldDescriptor* field) const = 0; - - // Swap the complete contents of two messages. - virtual void Swap(Message* message1, Message* message2) const = 0; - - // Swap two elements of a repeated field. - virtual void SwapElements(Message* message, - const FieldDescriptor* field, - int index1, - int index2) const = 0; - - // List all fields of the message which are currently set. This includes - // extensions. Singular fields will only be listed if HasField(field) would - // return true and repeated fields will only be listed if FieldSize(field) - // would return non-zero. Fields (both normal fields and extension fields) - // will be listed ordered by field number. - virtual void ListFields(const Message& message, - vector* output) const = 0; - - // Singular field getters ------------------------------------------ - // These get the value of a non-repeated field. They return the default - // value for fields that aren't set. - - virtual int32 GetInt32 (const Message& message, - const FieldDescriptor* field) const = 0; - virtual int64 GetInt64 (const Message& message, - const FieldDescriptor* field) const = 0; - virtual uint32 GetUInt32(const Message& message, - const FieldDescriptor* field) const = 0; - virtual uint64 GetUInt64(const Message& message, - const FieldDescriptor* field) const = 0; - virtual float GetFloat (const Message& message, - const FieldDescriptor* field) const = 0; - virtual double GetDouble(const Message& message, - const FieldDescriptor* field) const = 0; - virtual bool GetBool (const Message& message, - const FieldDescriptor* field) const = 0; - virtual string GetString(const Message& message, - const FieldDescriptor* field) const = 0; - virtual const EnumValueDescriptor* GetEnum( - const Message& message, const FieldDescriptor* field) const = 0; - // See MutableMessage() for the meaning of the "factory" parameter. - virtual const Message& GetMessage(const Message& message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const = 0; - - // Get a string value without copying, if possible. - // - // GetString() necessarily returns a copy of the string. This can be - // inefficient when the string is already stored in a string object in the - // underlying message. GetStringReference() will return a reference to the - // underlying string in this case. Otherwise, it will copy the string into - // *scratch and return that. - // - // Note: It is perfectly reasonable and useful to write code like: - // str = reflection->GetStringReference(field, &str); - // This line would ensure that only one copy of the string is made - // regardless of the field's underlying representation. When initializing - // a newly-constructed string, though, it's just as fast and more readable - // to use code like: - // string str = reflection->GetString(field); - virtual const string& GetStringReference(const Message& message, - const FieldDescriptor* field, - string* scratch) const = 0; - - - // Singular field mutators ----------------------------------------- - // These mutate the value of a non-repeated field. - - virtual void SetInt32 (Message* message, - const FieldDescriptor* field, int32 value) const = 0; - virtual void SetInt64 (Message* message, - const FieldDescriptor* field, int64 value) const = 0; - virtual void SetUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const = 0; - virtual void SetUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const = 0; - virtual void SetFloat (Message* message, - const FieldDescriptor* field, float value) const = 0; - virtual void SetDouble(Message* message, - const FieldDescriptor* field, double value) const = 0; - virtual void SetBool (Message* message, - const FieldDescriptor* field, bool value) const = 0; - virtual void SetString(Message* message, - const FieldDescriptor* field, - const string& value) const = 0; - virtual void SetEnum (Message* message, - const FieldDescriptor* field, - const EnumValueDescriptor* value) const = 0; - // Get a mutable pointer to a field with a message type. If a MessageFactory - // is provided, it will be used to construct instances of the sub-message; - // otherwise, the default factory is used. If the field is an extension that - // does not live in the same pool as the containing message's descriptor (e.g. - // it lives in an overlay pool), then a MessageFactory must be provided. - // If you have no idea what that meant, then you probably don't need to worry - // about it (don't provide a MessageFactory). WARNING: If the - // FieldDescriptor is for a compiled-in extension, then - // factory->GetPrototype(field->message_type() MUST return an instance of the - // compiled-in class for this type, NOT DynamicMessage. - virtual Message* MutableMessage(Message* message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const = 0; - - - // Repeated field getters ------------------------------------------ - // These get the value of one element of a repeated field. - - virtual int32 GetRepeatedInt32 (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual int64 GetRepeatedInt64 (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual uint32 GetRepeatedUInt32(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual uint64 GetRepeatedUInt64(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual float GetRepeatedFloat (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual double GetRepeatedDouble(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual bool GetRepeatedBool (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual string GetRepeatedString(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual const EnumValueDescriptor* GetRepeatedEnum( - const Message& message, - const FieldDescriptor* field, int index) const = 0; - virtual const Message& GetRepeatedMessage( - const Message& message, - const FieldDescriptor* field, int index) const = 0; - - // See GetStringReference(), above. - virtual const string& GetRepeatedStringReference( - const Message& message, const FieldDescriptor* field, - int index, string* scratch) const = 0; - - - // Repeated field mutators ----------------------------------------- - // These mutate the value of one element of a repeated field. - - virtual void SetRepeatedInt32 (Message* message, - const FieldDescriptor* field, - int index, int32 value) const = 0; - virtual void SetRepeatedInt64 (Message* message, - const FieldDescriptor* field, - int index, int64 value) const = 0; - virtual void SetRepeatedUInt32(Message* message, - const FieldDescriptor* field, - int index, uint32 value) const = 0; - virtual void SetRepeatedUInt64(Message* message, - const FieldDescriptor* field, - int index, uint64 value) const = 0; - virtual void SetRepeatedFloat (Message* message, - const FieldDescriptor* field, - int index, float value) const = 0; - virtual void SetRepeatedDouble(Message* message, - const FieldDescriptor* field, - int index, double value) const = 0; - virtual void SetRepeatedBool (Message* message, - const FieldDescriptor* field, - int index, bool value) const = 0; - virtual void SetRepeatedString(Message* message, - const FieldDescriptor* field, - int index, const string& value) const = 0; - virtual void SetRepeatedEnum(Message* message, - const FieldDescriptor* field, int index, - const EnumValueDescriptor* value) const = 0; - // Get a mutable pointer to an element of a repeated field with a message - // type. - virtual Message* MutableRepeatedMessage( - Message* message, const FieldDescriptor* field, int index) const = 0; - - - // Repeated field adders ------------------------------------------- - // These add an element to a repeated field. - - virtual void AddInt32 (Message* message, - const FieldDescriptor* field, int32 value) const = 0; - virtual void AddInt64 (Message* message, - const FieldDescriptor* field, int64 value) const = 0; - virtual void AddUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const = 0; - virtual void AddUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const = 0; - virtual void AddFloat (Message* message, - const FieldDescriptor* field, float value) const = 0; - virtual void AddDouble(Message* message, - const FieldDescriptor* field, double value) const = 0; - virtual void AddBool (Message* message, - const FieldDescriptor* field, bool value) const = 0; - virtual void AddString(Message* message, - const FieldDescriptor* field, - const string& value) const = 0; - virtual void AddEnum (Message* message, - const FieldDescriptor* field, - const EnumValueDescriptor* value) const = 0; - // See MutableMessage() for comments on the "factory" parameter. - virtual Message* AddMessage(Message* message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const = 0; - - - // Extensions ------------------------------------------------------ - - // Try to find an extension of this message type by fully-qualified field - // name. Returns NULL if no extension is known for this name or number. - virtual const FieldDescriptor* FindKnownExtensionByName( - const string& name) const = 0; - - // Try to find an extension of this message type by field number. - // Returns NULL if no extension is known for this name or number. - virtual const FieldDescriptor* FindKnownExtensionByNumber( - int number) const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reflection); -}; - -// Abstract interface for a factory for message objects. -class LIBPROTOBUF_EXPORT MessageFactory { - public: - inline MessageFactory() {} - virtual ~MessageFactory(); - - // Given a Descriptor, gets or constructs the default (prototype) Message - // of that type. You can then call that message's New() method to construct - // a mutable message of that type. - // - // Calling this method twice with the same Descriptor returns the same - // object. The returned object remains property of the factory. Also, any - // objects created by calling the prototype's New() method share some data - // with the prototype, so these must be destoyed before the MessageFactory - // is destroyed. - // - // The given descriptor must outlive the returned message, and hence must - // outlive the MessageFactory. - // - // Some implementations do not support all types. GetPrototype() will - // return NULL if the descriptor passed in is not supported. - // - // This method may or may not be thread-safe depending on the implementation. - // Each implementation should document its own degree thread-safety. - virtual const Message* GetPrototype(const Descriptor* type) = 0; - - // Gets a MessageFactory which supports all generated, compiled-in messages. - // In other words, for any compiled-in type FooMessage, the following is true: - // MessageFactory::generated_factory()->GetPrototype( - // FooMessage::descriptor()) == FooMessage::default_instance() - // This factory supports all types which are found in - // DescriptorPool::generated_pool(). If given a descriptor from any other - // pool, GetPrototype() will return NULL. (You can also check if a - // descriptor is for a generated message by checking if - // descriptor->file()->pool() == DescriptorPool::generated_pool().) - // - // This factory is 100% thread-safe; calling GetPrototype() does not modify - // any shared data. - // - // This factory is a singleton. The caller must not delete the object. - static MessageFactory* generated_factory(); - - // For internal use only: Registers a .proto file at static initialization - // time, to be placed in generated_factory. The first time GetPrototype() - // is called with a descriptor from this file, |register_messages| will be - // called, with the file name as the parameter. It must call - // InternalRegisterGeneratedMessage() (below) to register each message type - // in the file. This strange mechanism is necessary because descriptors are - // built lazily, so we can't register types by their descriptor until we - // know that the descriptor exists. |filename| must be a permanent string. - static void InternalRegisterGeneratedFile( - const char* filename, void (*register_messages)(const string&)); - - // For internal use only: Registers a message type. Called only by the - // functions which are registered with InternalRegisterGeneratedFile(), - // above. - static void InternalRegisterGeneratedMessage(const Descriptor* descriptor, - const Message* prototype); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFactory); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MESSAGE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h deleted file mode 100644 index ebf4ba3c..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +++ /dev/null @@ -1,239 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Authors: wink@google.com (Wink Saville), -// kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines MessageLite, the abstract interface implemented by all (lite -// and non-lite) protocol message objects. - -#ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ -#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ - -#include -#include - -namespace google { -namespace protobuf { - -// Interface to light weight protocol messages. -// -// This interface is implemented by all protocol message objects. Non-lite -// messages additionally implement the Message interface, which is a -// subclass of MessageLite. Use MessageLite instead when you only need -// the subset of features which it supports -- namely, nothing that uses -// descriptors or reflection. You can instruct the protocol compiler -// to generate classes which implement only MessageLite, not the full -// Message interface, by adding the following line to the .proto file: -// -// option optimize_for = LITE_RUNTIME; -// -// This is particularly useful on resource-constrained systems where -// the full protocol buffers runtime library is too big. -// -// Note that on non-constrained systems (e.g. servers) when you need -// to link in lots of protocol definitions, a better way to reduce -// total code footprint is to use optimize_for = CODE_SIZE. This -// will make the generated code smaller while still supporting all the -// same features (at the expense of speed). optimize_for = LITE_RUNTIME -// is best when you only have a small number of message types linked -// into your binary, in which case the size of the protocol buffers -// runtime itself is the biggest problem. -class LIBPROTOBUF_EXPORT MessageLite { - public: - inline MessageLite() {} - virtual ~MessageLite(); - - // Basic Operations ------------------------------------------------ - - // Get the name of this message type, e.g. "foo.bar.BazProto". - virtual string GetTypeName() const = 0; - - // Construct a new instance of the same type. Ownership is passed to the - // caller. - virtual MessageLite* New() const = 0; - - // Clear all fields of the message and set them to their default values. - // Clear() avoids freeing memory, assuming that any memory allocated - // to hold parts of the message will be needed again to hold the next - // message. If you actually want to free the memory used by a Message, - // you must delete it. - virtual void Clear() = 0; - - // Quickly check if all required fields have values set. - virtual bool IsInitialized() const = 0; - - // This is not implemented for Lite messages -- it just returns "(cannot - // determine missing fields for lite message)". However, it is implemented - // for full messages. See message.h. - virtual string InitializationErrorString() const; - - // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, - // results are undefined (probably crash). - virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; - - // Parsing --------------------------------------------------------- - // Methods for parsing in protocol buffer format. Most of these are - // just simple wrappers around MergeFromCodedStream(). - - // Fill the message with a protocol buffer parsed from the given input - // stream. Returns false on a read error or if the input is in the - // wrong format. - bool ParseFromCodedStream(io::CodedInputStream* input); - // Like ParseFromCodedStream(), but accepts messages that are missing - // required fields. - bool ParsePartialFromCodedStream(io::CodedInputStream* input); - // Read a protocol buffer from the given zero-copy input stream. If - // successful, the entire input will be consumed. - bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); - // Like ParseFromZeroCopyStream(), but accepts messages that are missing - // required fields. - bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input); - // Read a protocol buffer from the given zero-copy input stream, expecting - // the message to be exactly "size" bytes long. If successful, exactly - // this many bytes will have been consumed from the input. - bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size); - // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are - // missing required fields. - bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, - int size); - // Parse a protocol buffer contained in a string. - bool ParseFromString(const string& data); - // Like ParseFromString(), but accepts messages that are missing - // required fields. - bool ParsePartialFromString(const string& data); - // Parse a protocol buffer contained in an array of bytes. - bool ParseFromArray(const void* data, int size); - // Like ParseFromArray(), but accepts messages that are missing - // required fields. - bool ParsePartialFromArray(const void* data, int size); - - - // Reads a protocol buffer from the stream and merges it into this - // Message. Singular fields read from the input overwrite what is - // already in the Message and repeated fields are appended to those - // already present. - // - // It is the responsibility of the caller to call input->LastTagWas() - // (for groups) or input->ConsumedEntireMessage() (for non-groups) after - // this returns to verify that the message's end was delimited correctly. - // - // ParsefromCodedStream() is implemented as Clear() followed by - // MergeFromCodedStream(). - bool MergeFromCodedStream(io::CodedInputStream* input); - - // Like MergeFromCodedStream(), but succeeds even if required fields are - // missing in the input. - // - // MergeFromCodedStream() is just implemented as MergePartialFromCodedStream() - // followed by IsInitialized(). - virtual bool MergePartialFromCodedStream(io::CodedInputStream* input) = 0; - - // Serialization --------------------------------------------------- - // Methods for serializing in protocol buffer format. Most of these - // are just simple wrappers around ByteSize() and SerializeWithCachedSizes(). - - // Write a protocol buffer of this message to the given output. Returns - // false on a write error. If the message is missing required fields, - // this may GOOGLE_CHECK-fail. - bool SerializeToCodedStream(io::CodedOutputStream* output) const; - // Like SerializeToCodedStream(), but allows missing required fields. - bool SerializePartialToCodedStream(io::CodedOutputStream* output) const; - // Write the message to the given zero-copy output stream. All required - // fields must be set. - bool SerializeToZeroCopyStream(io::ZeroCopyOutputStream* output) const; - // Like SerializeToZeroCopyStream(), but allows missing required fields. - bool SerializePartialToZeroCopyStream(io::ZeroCopyOutputStream* output) const; - // Serialize the message and store it in the given string. All required - // fields must be set. - bool SerializeToString(string* output) const; - // Like SerializeToString(), but allows missing required fields. - bool SerializePartialToString(string* output) const; - // Serialize the message and store it in the given byte array. All required - // fields must be set. - bool SerializeToArray(void* data, int size) const; - // Like SerializeToArray(), but allows missing required fields. - bool SerializePartialToArray(void* data, int size) const; - - // Make a string encoding the message. Is equivalent to calling - // SerializeToString() on a string and using that. Returns the empty - // string if SerializeToString() would have returned an error. - // Note: If you intend to generate many such strings, you may - // reduce heap fragmentation by instead re-using the same string - // object with calls to SerializeToString(). - string SerializeAsString() const; - // Like SerializeAsString(), but allows missing required fields. - string SerializePartialAsString() const; - - // Like SerializeToString(), but appends to the data to the string's existing - // contents. All required fields must be set. - bool AppendToString(string* output) const; - // Like AppendToString(), but allows missing required fields. - bool AppendPartialToString(string* output) const; - - // Computes the serialized size of the message. This recursively calls - // ByteSize() on all embedded messages. If a subclass does not override - // this, it MUST override SetCachedSize(). - virtual int ByteSize() const = 0; - - // Serializes the message without recomputing the size. The message must - // not have changed since the last call to ByteSize(); if it has, the results - // are undefined. - virtual void SerializeWithCachedSizes( - io::CodedOutputStream* output) const = 0; - - // Like SerializeWithCachedSizes, but writes directly to *target, returning - // a pointer to the byte immediately after the last byte written. "target" - // must point at a byte array of at least ByteSize() bytes. - virtual uint8* SerializeWithCachedSizesToArray(uint8* target) const; - - // Returns the result of the last call to ByteSize(). An embedded message's - // size is needed both to serialize it (because embedded messages are - // length-delimited) and to compute the outer message's size. Caching - // the size avoids computing it multiple times. - // - // ByteSize() does not automatically use the cached size when available - // because this would require invalidating it every time the message was - // modified, which would be too hard and expensive. (E.g. if a deeply-nested - // sub-message is changed, all of its parents' cached sizes would need to be - // invalidated, which is too much work for an otherwise inlined setter - // method.) - virtual int GetCachedSize() const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/package_info.h b/ext/protobuf-2.4.1/src/google/protobuf/package_info.h deleted file mode 100644 index 60cd3994..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +++ /dev/null @@ -1,64 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file exists solely to document the google::protobuf namespace. -// It is not compiled into anything, but it may be read by an automated -// documentation generator. - -namespace google { - -// Core components of the Protocol Buffers runtime library. -// -// The files in this package represent the core of the Protocol Buffer -// system. All of them are part of the libprotobuf library. -// -// A note on thread-safety: -// -// Thread-safety in the Protocol Buffer library follows a simple rule: -// unless explicitly noted otherwise, it is always safe to use an object -// from multiple threads simultaneously as long as the object is declared -// const in all threads (or, it is only used in ways that would be allowed -// if it were declared const). However, if an object is accessed in one -// thread in a way that would not be allowed if it were const, then it is -// not safe to access that object in any other thread simultaneously. -// -// Put simply, read-only access to an object can happen in multiple threads -// simultaneously, but write access can only happen in a single thread at -// a time. -// -// The implementation does contain some "const" methods which actually modify -// the object behind the scenes -- e.g., to cache results -- but in these cases -// mutex locking is used to make the access thread-safe. -namespace protobuf {} -} // namespace google diff --git a/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h b/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h deleted file mode 100644 index 355a0a5d..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +++ /dev/null @@ -1,80 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_REFLECTION_OPS_H__ -#define GOOGLE_PROTOBUF_REFLECTION_OPS_H__ - -#include - -namespace google { -namespace protobuf { -namespace internal { - -// Basic operations that can be performed using reflection. -// These can be used as a cheap way to implement the corresponding -// methods of the Message interface, though they are likely to be -// slower than implementations tailored for the specific message type. -// -// This class should stay limited to operations needed to implement -// the Message interface. -// -// This class is really a namespace that contains only static methods. -class LIBPROTOBUF_EXPORT ReflectionOps { - public: - static void Copy(const Message& from, Message* to); - static void Merge(const Message& from, Message* to); - static void Clear(Message* message); - static bool IsInitialized(const Message& message); - static void DiscardUnknownFields(Message* message); - - // Finds all unset required fields in the message and adds their full - // paths (e.g. "foo.bar[5].baz") to *names. "prefix" will be attached to - // the front of each name. - static void FindInitializationErrors(const Message& message, - const string& prefix, - vector* errors); - - private: - // All methods are static. No need to construct. - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionOps); -}; - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_REFLECTION_OPS_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h b/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h deleted file mode 100644 index 6080ddcc..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +++ /dev/null @@ -1,1295 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// RepeatedField and RepeatedPtrField are used by generated protocol message -// classes to manipulate repeated fields. These classes are very similar to -// STL's vector, but include a number of optimizations found to be useful -// specifically in the case of Protocol Buffers. RepeatedPtrField is -// particularly different from STL vector as it manages ownership of the -// pointers that it contains. -// -// Typically, clients should not need to access RepeatedField objects directly, -// but should instead use the accessor functions generated automatically by the -// protocol compiler. - -#ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_H__ -#define GOOGLE_PROTOBUF_REPEATED_FIELD_H__ - -#include -#include -#include -#include - -namespace google { - -namespace protobuf { - -class Message; - -namespace internal { - -// We need this (from generated_message_reflection.cc). -LIBPROTOBUF_EXPORT int StringSpaceUsedExcludingSelf(const string& str); - -} // namespace internal - -// RepeatedField is used to represent repeated fields of a primitive type (in -// other words, everything except strings and nested Messages). Most users will -// not ever use a RepeatedField directly; they will use the get-by-index, -// set-by-index, and add accessors that are generated for all repeated fields. -template -class RepeatedField { - public: - RepeatedField(); - RepeatedField(const RepeatedField& other); - ~RepeatedField(); - - RepeatedField& operator=(const RepeatedField& other); - - int size() const; - - const Element& Get(int index) const; - Element* Mutable(int index); - void Set(int index, const Element& value); - void Add(const Element& value); - Element* Add(); - // Remove the last element in the array. - // We don't provide a way to remove any element other than the last - // because it invites inefficient use, such as O(n^2) filtering loops - // that should have been O(n). If you want to remove an element other - // than the last, the best way to do it is to re-arrange the elements - // so that the one you want removed is at the end, then call RemoveLast(). - void RemoveLast(); - void Clear(); - void MergeFrom(const RepeatedField& other); - void CopyFrom(const RepeatedField& other); - - // Reserve space to expand the field to at least the given size. If the - // array is grown, it will always be at least doubled in size. - void Reserve(int new_size); - - // Resize the RepeatedField to a new, smaller size. This is O(1). - void Truncate(int new_size); - - void AddAlreadyReserved(const Element& value); - Element* AddAlreadyReserved(); - int Capacity() const; - - // Gets the underlying array. This pointer is possibly invalidated by - // any add or remove operation. - Element* mutable_data(); - const Element* data() const; - - // Swap entire contents with "other". - void Swap(RepeatedField* other); - - // Swap two elements. - void SwapElements(int index1, int index2); - - // STL-like iterator support - typedef Element* iterator; - typedef const Element* const_iterator; - typedef Element value_type; - - iterator begin(); - const_iterator begin() const; - iterator end(); - const_iterator end() const; - - // Returns the number of bytes used by the repeated field, excluding - // sizeof(*this) - int SpaceUsedExcludingSelf() const; - - private: - static const int kInitialSize = 4; - - Element* elements_; - int current_size_; - int total_size_; - - Element initial_space_[kInitialSize]; - - // Move the contents of |from| into |to|, possibly clobbering |from| in the - // process. For primitive types this is just a memcpy(), but it could be - // specialized for non-primitive types to, say, swap each element instead. - void MoveArray(Element to[], Element from[], int size); - - // Copy the elements of |from| into |to|. - void CopyArray(Element to[], const Element from[], int size); -}; - -namespace internal { -template class RepeatedPtrIterator; -template class RepeatedPtrOverPtrsIterator; -} // namespace internal - -namespace internal { - -// This is the common base class for RepeatedPtrFields. It deals only in void* -// pointers. Users should not use this interface directly. -// -// The methods of this interface correspond to the methods of RepeatedPtrField, -// but may have a template argument called TypeHandler. Its signature is: -// class TypeHandler { -// public: -// typedef MyType Type; -// static Type* New(); -// static void Delete(Type*); -// static void Clear(Type*); -// static void Merge(const Type& from, Type* to); -// -// // Only needs to be implemented if SpaceUsedExcludingSelf() is called. -// static int SpaceUsed(const Type&); -// }; -class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { - protected: - // The reflection implementation needs to call protected methods directly, - // reinterpreting pointers as being to Message instead of a specific Message - // subclass. - friend class GeneratedMessageReflection; - - // ExtensionSet stores repeated message extensions as - // RepeatedPtrField, but non-lite ExtensionSets need to - // implement SpaceUsed(), and thus need to call SpaceUsedExcludingSelf() - // reinterpreting MessageLite as Message. ExtensionSet also needs to make - // use of AddFromCleared(), which is not part of the public interface. - friend class ExtensionSet; - - RepeatedPtrFieldBase(); - - // Must be called from destructor. - template - void Destroy(); - - int size() const; - - template - const typename TypeHandler::Type& Get(int index) const; - template - typename TypeHandler::Type* Mutable(int index); - template - typename TypeHandler::Type* Add(); - template - void RemoveLast(); - template - void Clear(); - template - void MergeFrom(const RepeatedPtrFieldBase& other); - template - void CopyFrom(const RepeatedPtrFieldBase& other); - - void Reserve(int new_size); - - int Capacity() const; - - // Used for constructing iterators. - void* const* raw_data() const; - void** raw_mutable_data() const; - - template - typename TypeHandler::Type** mutable_data(); - template - const typename TypeHandler::Type* const* data() const; - - void Swap(RepeatedPtrFieldBase* other); - - void SwapElements(int index1, int index2); - - template - int SpaceUsedExcludingSelf() const; - - - // Advanced memory management -------------------------------------- - - // Like Add(), but if there are no cleared objects to use, returns NULL. - template - typename TypeHandler::Type* AddFromCleared(); - - template - void AddAllocated(typename TypeHandler::Type* value); - template - typename TypeHandler::Type* ReleaseLast(); - - int ClearedCount() const; - template - void AddCleared(typename TypeHandler::Type* value); - template - typename TypeHandler::Type* ReleaseCleared(); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPtrFieldBase); - - static const int kInitialSize = 4; - - void** elements_; - int current_size_; - int allocated_size_; - int total_size_; - - void* initial_space_[kInitialSize]; - - template - static inline typename TypeHandler::Type* cast(void* element) { - return reinterpret_cast(element); - } - template - static inline const typename TypeHandler::Type* cast(const void* element) { - return reinterpret_cast(element); - } -}; - -template -class GenericTypeHandler { - public: - typedef GenericType Type; - static GenericType* New() { return new GenericType; } - static void Delete(GenericType* value) { delete value; } - static void Clear(GenericType* value) { value->Clear(); } - static void Merge(const GenericType& from, GenericType* to) { - to->MergeFrom(from); - } - static int SpaceUsed(const GenericType& value) { return value.SpaceUsed(); } -}; - -template <> -inline void GenericTypeHandler::Merge( - const MessageLite& from, MessageLite* to) { - to->CheckTypeAndMergeFrom(from); -} - -// HACK: If a class is declared as DLL-exported in MSVC, it insists on -// generating copies of all its methods -- even inline ones -- to include -// in the DLL. But SpaceUsed() calls StringSpaceUsedExcludingSelf() which -// isn't in the lite library, therefore the lite library cannot link if -// StringTypeHandler is exported. So, we factor out StringTypeHandlerBase, -// export that, then make StringTypeHandler be a subclass which is NOT -// exported. -// TODO(kenton): There has to be a better way. -class LIBPROTOBUF_EXPORT StringTypeHandlerBase { - public: - typedef string Type; - static string* New(); - static void Delete(string* value); - static void Clear(string* value) { value->clear(); } - static void Merge(const string& from, string* to) { *to = from; } -}; - -class LIBPROTOBUF_EXPORT StringTypeHandler : public StringTypeHandlerBase { - public: - static int SpaceUsed(const string& value) { - return sizeof(value) + StringSpaceUsedExcludingSelf(value); - } -}; - - -} // namespace internal - -// RepeatedPtrField is like RepeatedField, but used for repeated strings or -// Messages. -template -class RepeatedPtrField : public internal::RepeatedPtrFieldBase { - public: - RepeatedPtrField(); - RepeatedPtrField(const RepeatedPtrField& other); - ~RepeatedPtrField(); - - RepeatedPtrField& operator=(const RepeatedPtrField& other); - - int size() const; - - const Element& Get(int index) const; - Element* Mutable(int index); - Element* Add(); - void RemoveLast(); // Remove the last element in the array. - void Clear(); - void MergeFrom(const RepeatedPtrField& other); - void CopyFrom(const RepeatedPtrField& other); - - // Reserve space to expand the field to at least the given size. This only - // resizes the pointer array; it doesn't allocate any objects. If the - // array is grown, it will always be at least doubled in size. - void Reserve(int new_size); - - int Capacity() const; - - // Gets the underlying array. This pointer is possibly invalidated by - // any add or remove operation. - Element** mutable_data(); - const Element* const* data() const; - - // Swap entire contents with "other". - void Swap(RepeatedPtrField* other); - - // Swap two elements. - void SwapElements(int index1, int index2); - - // STL-like iterator support - typedef internal::RepeatedPtrIterator iterator; - typedef internal::RepeatedPtrIterator const_iterator; - typedef Element value_type; - - iterator begin(); - const_iterator begin() const; - iterator end(); - const_iterator end() const; - - // Custom STL-like iterator that iterates over and returns the underlying - // pointers to Element rather than Element itself. - typedef internal::RepeatedPtrOverPtrsIterator pointer_iterator; - pointer_iterator pointer_begin(); - pointer_iterator pointer_end(); - - // Returns (an estimate of) the number of bytes used by the repeated field, - // excluding sizeof(*this). - int SpaceUsedExcludingSelf() const; - - // Advanced memory management -------------------------------------- - // When hardcore memory management becomes necessary -- as it often - // does here at Google -- the following methods may be useful. - - // Add an already-allocated object, passing ownership to the - // RepeatedPtrField. - void AddAllocated(Element* value); - // Remove the last element and return it, passing ownership to the - // caller. - // Requires: size() > 0 - Element* ReleaseLast(); - - // When elements are removed by calls to RemoveLast() or Clear(), they - // are not actually freed. Instead, they are cleared and kept so that - // they can be reused later. This can save lots of CPU time when - // repeatedly reusing a protocol message for similar purposes. - // - // Really, extremely hardcore programs may actually want to manipulate - // these objects to better-optimize memory management. These methods - // allow that. - - // Get the number of cleared objects that are currently being kept - // around for reuse. - int ClearedCount() const; - // Add an element to the pool of cleared objects, passing ownership to - // the RepeatedPtrField. The element must be cleared prior to calling - // this method. - void AddCleared(Element* value); - // Remove a single element from the cleared pool and return it, passing - // ownership to the caller. The element is guaranteed to be cleared. - // Requires: ClearedCount() > 0 - Element* ReleaseCleared(); - - protected: - // Note: RepeatedPtrField SHOULD NOT be subclassed by users. We only - // subclass it in one place as a hack for compatibility with proto1. The - // subclass needs to know about TypeHandler in order to call protected - // methods on RepeatedPtrFieldBase. - class TypeHandler; - -}; - -// implementation ==================================================== - -template -inline RepeatedField::RepeatedField() - : elements_(initial_space_), - current_size_(0), - total_size_(kInitialSize) { -} - -template -inline RepeatedField::RepeatedField(const RepeatedField& other) - : elements_(initial_space_), - current_size_(0), - total_size_(kInitialSize) { - CopyFrom(other); -} - -template -RepeatedField::~RepeatedField() { - if (elements_ != initial_space_) { - delete [] elements_; - } -} - -template -inline RepeatedField& -RepeatedField::operator=(const RepeatedField& other) { - CopyFrom(other); - return *this; -} - -template -inline int RepeatedField::size() const { - return current_size_; -} - -template -inline int RepeatedField::Capacity() const { - return total_size_; -} - -template -inline void RepeatedField::AddAlreadyReserved(const Element& value) { - GOOGLE_DCHECK_LT(size(), Capacity()); - elements_[current_size_++] = value; -} - -template -inline Element* RepeatedField::AddAlreadyReserved() { - GOOGLE_DCHECK_LT(size(), Capacity()); - return &elements_[current_size_++]; -} - -template -inline const Element& RepeatedField::Get(int index) const { - GOOGLE_DCHECK_LT(index, size()); - return elements_[index]; -} - -template -inline Element* RepeatedField::Mutable(int index) { - GOOGLE_DCHECK_LT(index, size()); - return elements_ + index; -} - -template -inline void RepeatedField::Set(int index, const Element& value) { - GOOGLE_DCHECK_LT(index, size()); - elements_[index] = value; -} - -template -inline void RepeatedField::Add(const Element& value) { - if (current_size_ == total_size_) Reserve(total_size_ + 1); - elements_[current_size_++] = value; -} - -template -inline Element* RepeatedField::Add() { - if (current_size_ == total_size_) Reserve(total_size_ + 1); - return &elements_[current_size_++]; -} - -template -inline void RepeatedField::RemoveLast() { - GOOGLE_DCHECK_GT(current_size_, 0); - --current_size_; -} - -template -inline void RepeatedField::Clear() { - current_size_ = 0; -} - -template -inline void RepeatedField::MergeFrom(const RepeatedField& other) { - Reserve(current_size_ + other.current_size_); - CopyArray(elements_ + current_size_, other.elements_, other.current_size_); - current_size_ += other.current_size_; -} - -template -inline void RepeatedField::CopyFrom(const RepeatedField& other) { - Clear(); - MergeFrom(other); -} - -template -inline Element* RepeatedField::mutable_data() { - return elements_; -} - -template -inline const Element* RepeatedField::data() const { - return elements_; -} - - -template -void RepeatedField::Swap(RepeatedField* other) { - Element* swap_elements = elements_; - int swap_current_size = current_size_; - int swap_total_size = total_size_; - // We may not be using initial_space_ but it's not worth checking. Just - // copy it anyway. - Element swap_initial_space[kInitialSize]; - MoveArray(swap_initial_space, initial_space_, kInitialSize); - - elements_ = other->elements_; - current_size_ = other->current_size_; - total_size_ = other->total_size_; - MoveArray(initial_space_, other->initial_space_, kInitialSize); - - other->elements_ = swap_elements; - other->current_size_ = swap_current_size; - other->total_size_ = swap_total_size; - MoveArray(other->initial_space_, swap_initial_space, kInitialSize); - - if (elements_ == other->initial_space_) { - elements_ = initial_space_; - } - if (other->elements_ == initial_space_) { - other->elements_ = other->initial_space_; - } -} - -template -void RepeatedField::SwapElements(int index1, int index2) { - std::swap(elements_[index1], elements_[index2]); -} - -template -inline typename RepeatedField::iterator -RepeatedField::begin() { - return elements_; -} -template -inline typename RepeatedField::const_iterator -RepeatedField::begin() const { - return elements_; -} -template -inline typename RepeatedField::iterator -RepeatedField::end() { - return elements_ + current_size_; -} -template -inline typename RepeatedField::const_iterator -RepeatedField::end() const { - return elements_ + current_size_; -} - -template -inline int RepeatedField::SpaceUsedExcludingSelf() const { - return (elements_ != initial_space_) ? total_size_ * sizeof(elements_[0]) : 0; -} - -// Avoid inlining of Reserve(): new, memcpy, and delete[] lead to a significant -// amount of code bloat. -template -void RepeatedField::Reserve(int new_size) { - if (total_size_ >= new_size) return; - - Element* old_elements = elements_; - total_size_ = max(total_size_ * 2, new_size); - elements_ = new Element[total_size_]; - MoveArray(elements_, old_elements, current_size_); - if (old_elements != initial_space_) { - delete [] old_elements; - } -} - -template -inline void RepeatedField::Truncate(int new_size) { - GOOGLE_DCHECK_LE(new_size, current_size_); - current_size_ = new_size; -} - -template -inline void RepeatedField::MoveArray( - Element to[], Element from[], int array_size) { - memcpy(to, from, array_size * sizeof(Element)); -} - -template -inline void RepeatedField::CopyArray( - Element to[], const Element from[], int array_size) { - memcpy(to, from, array_size * sizeof(Element)); -} - - -// ------------------------------------------------------------------- - -namespace internal { - -inline RepeatedPtrFieldBase::RepeatedPtrFieldBase() - : elements_(initial_space_), - current_size_(0), - allocated_size_(0), - total_size_(kInitialSize) { -} - -template -void RepeatedPtrFieldBase::Destroy() { - for (int i = 0; i < allocated_size_; i++) { - TypeHandler::Delete(cast(elements_[i])); - } - if (elements_ != initial_space_) { - delete [] elements_; - } -} - -inline int RepeatedPtrFieldBase::size() const { - return current_size_; -} - - -template -inline const typename TypeHandler::Type& -RepeatedPtrFieldBase::Get(int index) const { - GOOGLE_DCHECK_LT(index, size()); - return *cast(elements_[index]); -} - -template -inline typename TypeHandler::Type* -RepeatedPtrFieldBase::Mutable(int index) { - GOOGLE_DCHECK_LT(index, size()); - return cast(elements_[index]); -} - -template -inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add() { - if (current_size_ < allocated_size_) { - return cast(elements_[current_size_++]); - } - if (allocated_size_ == total_size_) Reserve(total_size_ + 1); - ++allocated_size_; - typename TypeHandler::Type* result = TypeHandler::New(); - elements_[current_size_++] = result; - return result; -} - -template -inline void RepeatedPtrFieldBase::RemoveLast() { - GOOGLE_DCHECK_GT(current_size_, 0); - TypeHandler::Clear(cast(elements_[--current_size_])); -} - -template -void RepeatedPtrFieldBase::Clear() { - for (int i = 0; i < current_size_; i++) { - TypeHandler::Clear(cast(elements_[i])); - } - current_size_ = 0; -} - -template -inline void RepeatedPtrFieldBase::MergeFrom(const RepeatedPtrFieldBase& other) { - Reserve(current_size_ + other.current_size_); - for (int i = 0; i < other.current_size_; i++) { - TypeHandler::Merge(other.template Get(i), Add()); - } -} - -template -inline void RepeatedPtrFieldBase::CopyFrom(const RepeatedPtrFieldBase& other) { - RepeatedPtrFieldBase::Clear(); - RepeatedPtrFieldBase::MergeFrom(other); -} - -inline int RepeatedPtrFieldBase::Capacity() const { - return total_size_; -} - -inline void* const* RepeatedPtrFieldBase::raw_data() const { - return elements_; -} - -inline void** RepeatedPtrFieldBase::raw_mutable_data() const { - return elements_; -} - -template -inline typename TypeHandler::Type** RepeatedPtrFieldBase::mutable_data() { - // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this - // method entirely. - return reinterpret_cast(elements_); -} - -template -inline const typename TypeHandler::Type* const* -RepeatedPtrFieldBase::data() const { - // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this - // method entirely. - return reinterpret_cast(elements_); -} - -inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) { - std::swap(elements_[index1], elements_[index2]); -} - -template -inline int RepeatedPtrFieldBase::SpaceUsedExcludingSelf() const { - int allocated_bytes = - (elements_ != initial_space_) ? total_size_ * sizeof(elements_[0]) : 0; - for (int i = 0; i < allocated_size_; ++i) { - allocated_bytes += TypeHandler::SpaceUsed(*cast(elements_[i])); - } - return allocated_bytes; -} - -template -inline typename TypeHandler::Type* RepeatedPtrFieldBase::AddFromCleared() { - if (current_size_ < allocated_size_) { - return cast(elements_[current_size_++]); - } else { - return NULL; - } -} - -template -void RepeatedPtrFieldBase::AddAllocated( - typename TypeHandler::Type* value) { - // Make room for the new pointer. - if (current_size_ == total_size_) { - // The array is completely full with no cleared objects, so grow it. - Reserve(total_size_ + 1); - ++allocated_size_; - } else if (allocated_size_ == total_size_) { - // There is no more space in the pointer array because it contains some - // cleared objects awaiting reuse. We don't want to grow the array in this - // case because otherwise a loop calling AddAllocated() followed by Clear() - // would leak memory. - TypeHandler::Delete(cast(elements_[current_size_])); - } else if (current_size_ < allocated_size_) { - // We have some cleared objects. We don't care about their order, so we - // can just move the first one to the end to make space. - elements_[allocated_size_] = elements_[current_size_]; - ++allocated_size_; - } else { - // There are no cleared objects. - ++allocated_size_; - } - - elements_[current_size_++] = value; -} - -template -inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseLast() { - GOOGLE_DCHECK_GT(current_size_, 0); - typename TypeHandler::Type* result = - cast(elements_[--current_size_]); - --allocated_size_; - if (current_size_ < allocated_size_) { - // There are cleared elements on the end; replace the removed element - // with the last allocated element. - elements_[current_size_] = elements_[allocated_size_]; - } - return result; -} - - -inline int RepeatedPtrFieldBase::ClearedCount() const { - return allocated_size_ - current_size_; -} - -template -inline void RepeatedPtrFieldBase::AddCleared( - typename TypeHandler::Type* value) { - if (allocated_size_ == total_size_) Reserve(total_size_ + 1); - elements_[allocated_size_++] = value; -} - -template -inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseCleared() { - GOOGLE_DCHECK_GT(allocated_size_, current_size_); - return cast(elements_[--allocated_size_]); -} - -} // namespace internal - -// ------------------------------------------------------------------- - -template -class RepeatedPtrField::TypeHandler - : public internal::GenericTypeHandler {}; - -template <> -class RepeatedPtrField::TypeHandler - : public internal::StringTypeHandler {}; - - -template -inline RepeatedPtrField::RepeatedPtrField() {} - -template -inline RepeatedPtrField::RepeatedPtrField( - const RepeatedPtrField& other) { - CopyFrom(other); -} - -template -RepeatedPtrField::~RepeatedPtrField() { - Destroy(); -} - -template -inline RepeatedPtrField& RepeatedPtrField::operator=( - const RepeatedPtrField& other) { - CopyFrom(other); - return *this; -} - -template -inline int RepeatedPtrField::size() const { - return RepeatedPtrFieldBase::size(); -} - -template -inline const Element& RepeatedPtrField::Get(int index) const { - return RepeatedPtrFieldBase::Get(index); -} - -template -inline Element* RepeatedPtrField::Mutable(int index) { - return RepeatedPtrFieldBase::Mutable(index); -} - -template -inline Element* RepeatedPtrField::Add() { - return RepeatedPtrFieldBase::Add(); -} - -template -inline void RepeatedPtrField::RemoveLast() { - RepeatedPtrFieldBase::RemoveLast(); -} - -template -inline void RepeatedPtrField::Clear() { - RepeatedPtrFieldBase::Clear(); -} - -template -inline void RepeatedPtrField::MergeFrom( - const RepeatedPtrField& other) { - RepeatedPtrFieldBase::MergeFrom(other); -} - -template -inline void RepeatedPtrField::CopyFrom( - const RepeatedPtrField& other) { - RepeatedPtrFieldBase::CopyFrom(other); -} - -template -inline Element** RepeatedPtrField::mutable_data() { - return RepeatedPtrFieldBase::mutable_data(); -} - -template -inline const Element* const* RepeatedPtrField::data() const { - return RepeatedPtrFieldBase::data(); -} - -template -void RepeatedPtrField::Swap(RepeatedPtrField* other) { - RepeatedPtrFieldBase::Swap(other); -} - -template -void RepeatedPtrField::SwapElements(int index1, int index2) { - RepeatedPtrFieldBase::SwapElements(index1, index2); -} - -template -inline int RepeatedPtrField::SpaceUsedExcludingSelf() const { - return RepeatedPtrFieldBase::SpaceUsedExcludingSelf(); -} - -template -inline void RepeatedPtrField::AddAllocated(Element* value) { - RepeatedPtrFieldBase::AddAllocated(value); -} - -template -inline Element* RepeatedPtrField::ReleaseLast() { - return RepeatedPtrFieldBase::ReleaseLast(); -} - - -template -inline int RepeatedPtrField::ClearedCount() const { - return RepeatedPtrFieldBase::ClearedCount(); -} - -template -inline void RepeatedPtrField::AddCleared(Element* value) { - return RepeatedPtrFieldBase::AddCleared(value); -} - -template -inline Element* RepeatedPtrField::ReleaseCleared() { - return RepeatedPtrFieldBase::ReleaseCleared(); -} - -template -inline void RepeatedPtrField::Reserve(int new_size) { - return RepeatedPtrFieldBase::Reserve(new_size); -} - -template -inline int RepeatedPtrField::Capacity() const { - return RepeatedPtrFieldBase::Capacity(); -} - -// ------------------------------------------------------------------- - -namespace internal { - -// STL-like iterator implementation for RepeatedPtrField. You should not -// refer to this class directly; use RepeatedPtrField::iterator instead. -// -// The iterator for RepeatedPtrField, RepeatedPtrIterator, is -// very similar to iterator_ptr in util/gtl/iterator_adaptors-inl.h, -// but adds random-access operators and is modified to wrap a void** base -// iterator (since RepeatedPtrField stores its array as a void* array and -// casting void** to T** would violate C++ aliasing rules). -// -// This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin -// (jyasskin@google.com). -template -class RepeatedPtrIterator - : public std::iterator< - std::random_access_iterator_tag, Element> { - public: - typedef RepeatedPtrIterator iterator; - typedef std::iterator< - std::random_access_iterator_tag, Element> superclass; - - // Let the compiler know that these are type names, so we don't have to - // write "typename" in front of them everywhere. - typedef typename superclass::reference reference; - typedef typename superclass::pointer pointer; - typedef typename superclass::difference_type difference_type; - - RepeatedPtrIterator() : it_(NULL) {} - explicit RepeatedPtrIterator(void* const* it) : it_(it) {} - - // Allow "upcasting" from RepeatedPtrIterator to - // RepeatedPtrIterator. - template - RepeatedPtrIterator(const RepeatedPtrIterator& other) - : it_(other.it_) { - // Force a compiler error if the other type is not convertible to ours. - if (false) { - implicit_cast(0); - } - } - - // dereferenceable - reference operator*() const { return *reinterpret_cast(*it_); } - pointer operator->() const { return &(operator*()); } - - // {inc,dec}rementable - iterator& operator++() { ++it_; return *this; } - iterator operator++(int) { return iterator(it_++); } - iterator& operator--() { --it_; return *this; } - iterator operator--(int) { return iterator(it_--); } - - // equality_comparable - bool operator==(const iterator& x) const { return it_ == x.it_; } - bool operator!=(const iterator& x) const { return it_ != x.it_; } - - // less_than_comparable - bool operator<(const iterator& x) const { return it_ < x.it_; } - bool operator<=(const iterator& x) const { return it_ <= x.it_; } - bool operator>(const iterator& x) const { return it_ > x.it_; } - bool operator>=(const iterator& x) const { return it_ >= x.it_; } - - // addable, subtractable - iterator& operator+=(difference_type d) { - it_ += d; - return *this; - } - friend iterator operator+(iterator it, difference_type d) { - it += d; - return it; - } - friend iterator operator+(difference_type d, iterator it) { - it += d; - return it; - } - iterator& operator-=(difference_type d) { - it_ -= d; - return *this; - } - friend iterator operator-(iterator it, difference_type d) { - it -= d; - return it; - } - - // indexable - reference operator[](difference_type d) const { return *(*this + d); } - - // random access iterator - difference_type operator-(const iterator& x) const { return it_ - x.it_; } - - private: - template - friend class RepeatedPtrIterator; - - // The internal iterator. - void* const* it_; -}; - -// Provide an iterator that operates on pointers to the underlying objects -// rather than the objects themselves as RepeatedPtrIterator does. -// Consider using this when working with stl algorithms that change -// the array. -template -class RepeatedPtrOverPtrsIterator - : public std::iterator { - public: - typedef RepeatedPtrOverPtrsIterator iterator; - typedef std::iterator< - std::random_access_iterator_tag, Element*> superclass; - - // Let the compiler know that these are type names, so we don't have to - // write "typename" in front of them everywhere. - typedef typename superclass::reference reference; - typedef typename superclass::pointer pointer; - typedef typename superclass::difference_type difference_type; - - RepeatedPtrOverPtrsIterator() : it_(NULL) {} - explicit RepeatedPtrOverPtrsIterator(void** it) : it_(it) {} - - // dereferenceable - reference operator*() const { return *reinterpret_cast(it_); } - pointer operator->() const { return &(operator*()); } - - // {inc,dec}rementable - iterator& operator++() { ++it_; return *this; } - iterator operator++(int) { return iterator(it_++); } - iterator& operator--() { --it_; return *this; } - iterator operator--(int) { return iterator(it_--); } - - // equality_comparable - bool operator==(const iterator& x) const { return it_ == x.it_; } - bool operator!=(const iterator& x) const { return it_ != x.it_; } - - // less_than_comparable - bool operator<(const iterator& x) const { return it_ < x.it_; } - bool operator<=(const iterator& x) const { return it_ <= x.it_; } - bool operator>(const iterator& x) const { return it_ > x.it_; } - bool operator>=(const iterator& x) const { return it_ >= x.it_; } - - // addable, subtractable - iterator& operator+=(difference_type d) { - it_ += d; - return *this; - } - friend iterator operator+(iterator it, difference_type d) { - it += d; - return it; - } - friend iterator operator+(difference_type d, iterator it) { - it += d; - return it; - } - iterator& operator-=(difference_type d) { - it_ -= d; - return *this; - } - friend iterator operator-(iterator it, difference_type d) { - it -= d; - return it; - } - - // indexable - reference operator[](difference_type d) const { return *(*this + d); } - - // random access iterator - difference_type operator-(const iterator& x) const { return it_ - x.it_; } - - private: - template - friend class RepeatedPtrIterator; - - // The internal iterator. - void** it_; -}; - - -} // namespace internal - -template -inline typename RepeatedPtrField::iterator -RepeatedPtrField::begin() { - return iterator(raw_data()); -} -template -inline typename RepeatedPtrField::const_iterator -RepeatedPtrField::begin() const { - return iterator(raw_data()); -} -template -inline typename RepeatedPtrField::iterator -RepeatedPtrField::end() { - return iterator(raw_data() + size()); -} -template -inline typename RepeatedPtrField::const_iterator -RepeatedPtrField::end() const { - return iterator(raw_data() + size()); -} - -template -inline typename RepeatedPtrField::pointer_iterator -RepeatedPtrField::pointer_begin() { - return pointer_iterator(raw_mutable_data()); -} -template -inline typename RepeatedPtrField::pointer_iterator -RepeatedPtrField::pointer_end() { - return pointer_iterator(raw_mutable_data() + size()); -} - - -// Iterators and helper functions that follow the spirit of the STL -// std::back_insert_iterator and std::back_inserter but are tailor-made -// for RepeatedField and RepatedPtrField. Typical usage would be: -// -// std::copy(some_sequence.begin(), some_sequence.end(), -// google::protobuf::RepeatedFieldBackInserter(proto.mutable_sequence())); -// -// Ported by johannes from util/gtl/proto-array-iterators-inl.h - -namespace internal { -// A back inserter for RepeatedField objects. -template class RepeatedFieldBackInsertIterator - : public std::iterator { - public: - explicit RepeatedFieldBackInsertIterator( - RepeatedField* const mutable_field) - : field_(mutable_field) { - } - RepeatedFieldBackInsertIterator& operator=(const T& value) { - field_->Add(value); - return *this; - } - RepeatedFieldBackInsertIterator& operator*() { - return *this; - } - RepeatedFieldBackInsertIterator& operator++() { - return *this; - } - RepeatedFieldBackInsertIterator& operator++(int ignores_parameter) { - return *this; - } - - private: - RepeatedField* field_; -}; - -// A back inserter for RepeatedPtrField objects. -template class RepeatedPtrFieldBackInsertIterator - : public std::iterator { - public: - RepeatedPtrFieldBackInsertIterator( - RepeatedPtrField* const mutable_field) - : field_(mutable_field) { - } - RepeatedPtrFieldBackInsertIterator& operator=(const T& value) { - *field_->Add() = value; - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator=( - const T* const ptr_to_value) { - *field_->Add() = *ptr_to_value; - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator*() { - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator++() { - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator++(int ignores_parameter) { - return *this; - } - - private: - RepeatedPtrField* field_; -}; - -// A back inserter for RepeatedPtrFields that inserts by transfering ownership -// of a pointer. -template class AllocatedRepeatedPtrFieldBackInsertIterator - : public std::iterator { - public: - explicit AllocatedRepeatedPtrFieldBackInsertIterator( - RepeatedPtrField* const mutable_field) - : field_(mutable_field) { - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator=( - T* const ptr_to_value) { - field_->AddAllocated(ptr_to_value); - return *this; - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator*() { - return *this; - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator++() { - return *this; - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator++( - int ignores_parameter) { - return *this; - } - - private: - RepeatedPtrField* field_; -}; -} // namespace internal - -// Provides a back insert iterator for RepeatedField instances, -// similar to std::back_inserter(). Note the identically named -// function for RepeatedPtrField instances. -template internal::RepeatedFieldBackInsertIterator -RepeatedFieldBackInserter(RepeatedField* const mutable_field) { - return internal::RepeatedFieldBackInsertIterator(mutable_field); -} - -// Provides a back insert iterator for RepeatedPtrField instances, -// similar to std::back_inserter(). Note the identically named -// function for RepeatedField instances. -template internal::RepeatedPtrFieldBackInsertIterator -RepeatedFieldBackInserter(RepeatedPtrField* const mutable_field) { - return internal::RepeatedPtrFieldBackInsertIterator(mutable_field); -} - -// Provides a back insert iterator for RepeatedPtrField instances -// similar to std::back_inserter() which transfers the ownership while -// copying elements. -template internal::AllocatedRepeatedPtrFieldBackInsertIterator -AllocatedRepeatedPtrFieldBackInserter( - RepeatedPtrField* const mutable_field) { - return internal::AllocatedRepeatedPtrFieldBackInsertIterator( - mutable_field); -} - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_REPEATED_FIELD_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/service.h b/ext/protobuf-2.4.1/src/google/protobuf/service.h deleted file mode 100644 index a6a7d16d..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/service.h +++ /dev/null @@ -1,291 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// DEPRECATED: This module declares the abstract interfaces underlying proto2 -// RPC services. These are intented to be independent of any particular RPC -// implementation, so that proto2 services can be used on top of a variety -// of implementations. Starting with version 2.3.0, RPC implementations should -// not try to build on these, but should instead provide code generator plugins -// which generate code specific to the particular RPC implementation. This way -// the generated code can be more appropriate for the implementation in use -// and can avoid unnecessary layers of indirection. -// -// -// When you use the protocol compiler to compile a service definition, it -// generates two classes: An abstract interface for the service (with -// methods matching the service definition) and a "stub" implementation. -// A stub is just a type-safe wrapper around an RpcChannel which emulates a -// local implementation of the service. -// -// For example, the service definition: -// service MyService { -// rpc Foo(MyRequest) returns(MyResponse); -// } -// will generate abstract interface "MyService" and class "MyService::Stub". -// You could implement a MyService as follows: -// class MyServiceImpl : public MyService { -// public: -// MyServiceImpl() {} -// ~MyServiceImpl() {} -// -// // implements MyService --------------------------------------- -// -// void Foo(google::protobuf::RpcController* controller, -// const MyRequest* request, -// MyResponse* response, -// Closure* done) { -// // ... read request and fill in response ... -// done->Run(); -// } -// }; -// You would then register an instance of MyServiceImpl with your RPC server -// implementation. (How to do that depends on the implementation.) -// -// To call a remote MyServiceImpl, first you need an RpcChannel connected to it. -// How to construct a channel depends, again, on your RPC implementation. -// Here we use a hypothentical "MyRpcChannel" as an example: -// MyRpcChannel channel("rpc:hostname:1234/myservice"); -// MyRpcController controller; -// MyServiceImpl::Stub stub(&channel); -// FooRequest request; -// FooRespnose response; -// -// // ... fill in request ... -// -// stub.Foo(&controller, request, &response, NewCallback(HandleResponse)); -// -// On Thread-Safety: -// -// Different RPC implementations may make different guarantees about what -// threads they may run callbacks on, and what threads the application is -// allowed to use to call the RPC system. Portable software should be ready -// for callbacks to be called on any thread, but should not try to call the -// RPC system from any thread except for the ones on which it received the -// callbacks. Realistically, though, simple software will probably want to -// use a single-threaded RPC system while high-end software will want to -// use multiple threads. RPC implementations should provide multiple -// choices. - -#ifndef GOOGLE_PROTOBUF_SERVICE_H__ -#define GOOGLE_PROTOBUF_SERVICE_H__ - -#include -#include - -namespace google { -namespace protobuf { - -// Defined in this file. -class Service; -class RpcController; -class RpcChannel; - -// Defined in other files. -class Descriptor; // descriptor.h -class ServiceDescriptor; // descriptor.h -class MethodDescriptor; // descriptor.h -class Message; // message.h - -// Abstract base interface for protocol-buffer-based RPC services. Services -// themselves are abstract interfaces (implemented either by servers or as -// stubs), but they subclass this base interface. The methods of this -// interface can be used to call the methods of the Service without knowing -// its exact type at compile time (analogous to Reflection). -class LIBPROTOBUF_EXPORT Service { - public: - inline Service() {} - virtual ~Service(); - - // When constructing a stub, you may pass STUB_OWNS_CHANNEL as the second - // parameter to the constructor to tell it to delete its RpcChannel when - // destroyed. - enum ChannelOwnership { - STUB_OWNS_CHANNEL, - STUB_DOESNT_OWN_CHANNEL - }; - - // Get the ServiceDescriptor describing this service and its methods. - virtual const ServiceDescriptor* GetDescriptor() = 0; - - // Call a method of the service specified by MethodDescriptor. This is - // normally implemented as a simple switch() that calls the standard - // definitions of the service's methods. - // - // Preconditions: - // * method->service() == GetDescriptor() - // * request and response are of the exact same classes as the objects - // returned by GetRequestPrototype(method) and - // GetResponsePrototype(method). - // * After the call has started, the request must not be modified and the - // response must not be accessed at all until "done" is called. - // * "controller" is of the correct type for the RPC implementation being - // used by this Service. For stubs, the "correct type" depends on the - // RpcChannel which the stub is using. Server-side Service - // implementations are expected to accept whatever type of RpcController - // the server-side RPC implementation uses. - // - // Postconditions: - // * "done" will be called when the method is complete. This may be - // before CallMethod() returns or it may be at some point in the future. - // * If the RPC succeeded, "response" contains the response returned by - // the server. - // * If the RPC failed, "response"'s contents are undefined. The - // RpcController can be queried to determine if an error occurred and - // possibly to get more information about the error. - virtual void CallMethod(const MethodDescriptor* method, - RpcController* controller, - const Message* request, - Message* response, - Closure* done) = 0; - - // CallMethod() requires that the request and response passed in are of a - // particular subclass of Message. GetRequestPrototype() and - // GetResponsePrototype() get the default instances of these required types. - // You can then call Message::New() on these instances to construct mutable - // objects which you can then pass to CallMethod(). - // - // Example: - // const MethodDescriptor* method = - // service->GetDescriptor()->FindMethodByName("Foo"); - // Message* request = stub->GetRequestPrototype (method)->New(); - // Message* response = stub->GetResponsePrototype(method)->New(); - // request->ParseFromString(input); - // service->CallMethod(method, *request, response, callback); - virtual const Message& GetRequestPrototype( - const MethodDescriptor* method) const = 0; - virtual const Message& GetResponsePrototype( - const MethodDescriptor* method) const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Service); -}; - -// An RpcController mediates a single method call. The primary purpose of -// the controller is to provide a way to manipulate settings specific to the -// RPC implementation and to find out about RPC-level errors. -// -// The methods provided by the RpcController interface are intended to be a -// "least common denominator" set of features which we expect all -// implementations to support. Specific implementations may provide more -// advanced features (e.g. deadline propagation). -class LIBPROTOBUF_EXPORT RpcController { - public: - inline RpcController() {} - virtual ~RpcController(); - - // Client-side methods --------------------------------------------- - // These calls may be made from the client side only. Their results - // are undefined on the server side (may crash). - - // Resets the RpcController to its initial state so that it may be reused in - // a new call. Must not be called while an RPC is in progress. - virtual void Reset() = 0; - - // After a call has finished, returns true if the call failed. The possible - // reasons for failure depend on the RPC implementation. Failed() must not - // be called before a call has finished. If Failed() returns true, the - // contents of the response message are undefined. - virtual bool Failed() const = 0; - - // If Failed() is true, returns a human-readable description of the error. - virtual string ErrorText() const = 0; - - // Advises the RPC system that the caller desires that the RPC call be - // canceled. The RPC system may cancel it immediately, may wait awhile and - // then cancel it, or may not even cancel the call at all. If the call is - // canceled, the "done" callback will still be called and the RpcController - // will indicate that the call failed at that time. - virtual void StartCancel() = 0; - - // Server-side methods --------------------------------------------- - // These calls may be made from the server side only. Their results - // are undefined on the client side (may crash). - - // Causes Failed() to return true on the client side. "reason" will be - // incorporated into the message returned by ErrorText(). If you find - // you need to return machine-readable information about failures, you - // should incorporate it into your response protocol buffer and should - // NOT call SetFailed(). - virtual void SetFailed(const string& reason) = 0; - - // If true, indicates that the client canceled the RPC, so the server may - // as well give up on replying to it. The server should still call the - // final "done" callback. - virtual bool IsCanceled() const = 0; - - // Asks that the given callback be called when the RPC is canceled. The - // callback will always be called exactly once. If the RPC completes without - // being canceled, the callback will be called after completion. If the RPC - // has already been canceled when NotifyOnCancel() is called, the callback - // will be called immediately. - // - // NotifyOnCancel() must be called no more than once per request. - virtual void NotifyOnCancel(Closure* callback) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcController); -}; - -// Abstract interface for an RPC channel. An RpcChannel represents a -// communication line to a Service which can be used to call that Service's -// methods. The Service may be running on another machine. Normally, you -// should not call an RpcChannel directly, but instead construct a stub Service -// wrapping it. Example: -// RpcChannel* channel = new MyRpcChannel("remotehost.example.com:1234"); -// MyService* service = new MyService::Stub(channel); -// service->MyMethod(request, &response, callback); -class LIBPROTOBUF_EXPORT RpcChannel { - public: - inline RpcChannel() {} - virtual ~RpcChannel(); - - // Call the given method of the remote service. The signature of this - // procedure looks the same as Service::CallMethod(), but the requirements - // are less strict in one important way: the request and response objects - // need not be of any specific class as long as their descriptors are - // method->input_type() and method->output_type(). - virtual void CallMethod(const MethodDescriptor* method, - RpcController* controller, - const Message* request, - Message* response, - Closure* done) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcChannel); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_SERVICE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h deleted file mode 100644 index 7173a84d..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +++ /dev/null @@ -1,1211 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) and others -// -// Contains basic types and utilities used by the rest of the library. - -#ifndef GOOGLE_PROTOBUF_COMMON_H__ -#define GOOGLE_PROTOBUF_COMMON_H__ - -#include -#include -#include -#include -#include -#if defined(__osf__) -// Tru64 lacks stdint.h, but has inttypes.h which defines a superset of -// what stdint.h would define. -#include -#elif !defined(_MSC_VER) -#include -#endif - -#if defined(_MSC_VER) && defined(_CPPUNWIND) - #define PROTOBUF_USE_EXCEPTIONS -#elif defined(__EXCEPTIONS) - #define PROTOBUF_USE_EXCEPTIONS -#endif -#ifdef PROTOBUF_USE_EXCEPTIONS -#include -#endif - -#if defined(_WIN32) && defined(GetMessage) -// Allow GetMessage to be used as a valid method name in protobuf classes. -// windows.h defines GetMessage() as a macro. Let's re-define it as an inline -// function. The inline function should be equivalent for C++ users. -inline BOOL GetMessage_Win32( - LPMSG lpMsg, HWND hWnd, - UINT wMsgFilterMin, UINT wMsgFilterMax) { - return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); -} -#undef GetMessage -inline BOOL GetMessage( - LPMSG lpMsg, HWND hWnd, - UINT wMsgFilterMin, UINT wMsgFilterMax) { - return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); -} -#endif - - -namespace std {} - -namespace google { -namespace protobuf { - -#undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS -#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - -#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS) - #ifdef LIBPROTOBUF_EXPORTS - #define LIBPROTOBUF_EXPORT __declspec(dllexport) - #else - #define LIBPROTOBUF_EXPORT __declspec(dllimport) - #endif - #ifdef LIBPROTOC_EXPORTS - #define LIBPROTOC_EXPORT __declspec(dllexport) - #else - #define LIBPROTOC_EXPORT __declspec(dllimport) - #endif -#else - #define LIBPROTOBUF_EXPORT - #define LIBPROTOC_EXPORT -#endif - -namespace internal { - -// Some of these constants are macros rather than const ints so that they can -// be used in #if directives. - -// The current version, represented as a single integer to make comparison -// easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 2004001 - -// The minimum library version which works with the current version of the -// headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2004000 - -// The minimum header version which works with the current version of -// the library. This constant should only be used by protoc's C++ code -// generator. -static const int kMinHeaderVersionForLibrary = 2004000; - -// The minimum protoc version which works with the current version of the -// headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2004000 - -// The minimum header version which works with the current version of -// protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 2004000; - -// Verifies that the headers and libraries are compatible. Use the macro -// below to call this. -void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, - const char* filename); - -// Converts a numeric version number to a string. -std::string LIBPROTOBUF_EXPORT VersionString(int version); - -} // namespace internal - -// Place this macro in your main() function (or somewhere before you attempt -// to use the protobuf library) to verify that the version you link against -// matches the headers you compiled against. If a version mismatch is -// detected, the process will abort. -#define GOOGLE_PROTOBUF_VERIFY_VERSION \ - ::google::protobuf::internal::VerifyVersion( \ - GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION, \ - __FILE__) - -// =================================================================== -// from google3/base/port.h - -typedef unsigned int uint; - -#ifdef _MSC_VER -typedef __int8 int8; -typedef __int16 int16; -typedef __int32 int32; -typedef __int64 int64; - -typedef unsigned __int8 uint8; -typedef unsigned __int16 uint16; -typedef unsigned __int32 uint32; -typedef unsigned __int64 uint64; -#else -typedef int8_t int8; -typedef int16_t int16; -typedef int32_t int32; -typedef int64_t int64; - -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; -typedef uint64_t uint64; -#endif - -// long long macros to be used because gcc and vc++ use different suffixes, -// and different size specifiers in format strings -#undef GOOGLE_LONGLONG -#undef GOOGLE_ULONGLONG -#undef GOOGLE_LL_FORMAT - -#ifdef _MSC_VER -#define GOOGLE_LONGLONG(x) x##I64 -#define GOOGLE_ULONGLONG(x) x##UI64 -#define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...) -#else -#define GOOGLE_LONGLONG(x) x##LL -#define GOOGLE_ULONGLONG(x) x##ULL -#define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also. -#endif - -static const int32 kint32max = 0x7FFFFFFF; -static const int32 kint32min = -kint32max - 1; -static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF); -static const int64 kint64min = -kint64max - 1; -static const uint32 kuint32max = 0xFFFFFFFFu; -static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF); - -// ------------------------------------------------------------------- -// Annotations: Some parts of the code have been annotated in ways that might -// be useful to some compilers or tools, but are not supported universally. -// You can #define these annotations yourself if the default implementation -// is not right for you. - -#ifndef GOOGLE_ATTRIBUTE_ALWAYS_INLINE -#if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) -// For functions we want to force inline. -// Introduced in gcc 3.1. -#define GOOGLE_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) -#else -// Other compilers will have to figure it out for themselves. -#define GOOGLE_ATTRIBUTE_ALWAYS_INLINE -#endif -#endif - -#ifndef GOOGLE_ATTRIBUTE_DEPRECATED -#ifdef __GNUC__ -// If the method/variable/type is used anywhere, produce a warning. -#define GOOGLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated)) -#else -#define GOOGLE_ATTRIBUTE_DEPRECATED -#endif -#endif - -#ifndef GOOGLE_PREDICT_TRUE -#ifdef __GNUC__ -// Provided at least since GCC 3.0. -#define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) -#else -#define GOOGLE_PREDICT_TRUE -#endif -#endif - -// Delimits a block of code which may write to memory which is simultaneously -// written by other threads, but which has been determined to be thread-safe -// (e.g. because it is an idempotent write). -#ifndef GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN -#define GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN() -#endif -#ifndef GOOGLE_SAFE_CONCURRENT_WRITES_END -#define GOOGLE_SAFE_CONCURRENT_WRITES_END() -#endif - -// =================================================================== -// from google3/base/basictypes.h - -// The GOOGLE_ARRAYSIZE(arr) macro returns the # of elements in an array arr. -// The expression is a compile-time constant, and therefore can be -// used in defining new arrays, for example. -// -// GOOGLE_ARRAYSIZE catches a few type errors. If you see a compiler error -// -// "warning: division by zero in ..." -// -// when using GOOGLE_ARRAYSIZE, you are (wrongfully) giving it a pointer. -// You should only use GOOGLE_ARRAYSIZE on statically allocated arrays. -// -// The following comments are on the implementation details, and can -// be ignored by the users. -// -// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in -// the array) and sizeof(*(arr)) (the # of bytes in one array -// element). If the former is divisible by the latter, perhaps arr is -// indeed an array, in which case the division result is the # of -// elements in the array. Otherwise, arr cannot possibly be an array, -// and we generate a compiler error to prevent the code from -// compiling. -// -// Since the size of bool is implementation-defined, we need to cast -// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final -// result has type size_t. -// -// This macro is not perfect as it wrongfully accepts certain -// pointers, namely where the pointer size is divisible by the pointee -// size. Since all our code has to go through a 32-bit compiler, -// where a pointer is 4 bytes, this means all pointers to a type whose -// size is 3 or greater than 4 will be (righteously) rejected. -// -// Kudos to Jorg Brown for this simple and elegant implementation. - -#undef GOOGLE_ARRAYSIZE -#define GOOGLE_ARRAYSIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast(!(sizeof(a) % sizeof(*(a))))) - -namespace internal { - -// Use implicit_cast as a safe version of static_cast or const_cast -// for upcasting in the type hierarchy (i.e. casting a pointer to Foo -// to a pointer to SuperclassOfFoo or casting a pointer to Foo to -// a const pointer to Foo). -// When you use implicit_cast, the compiler checks that the cast is safe. -// Such explicit implicit_casts are necessary in surprisingly many -// situations where C++ demands an exact type match instead of an -// argument type convertable to a target type. -// -// The From type can be inferred, so the preferred syntax for using -// implicit_cast is the same as for static_cast etc.: -// -// implicit_cast(expr) -// -// implicit_cast would have been part of the C++ standard library, -// but the proposal was submitted too late. It will probably make -// its way into the language in the future. -template -inline To implicit_cast(From const &f) { - return f; -} - -// When you upcast (that is, cast a pointer from type Foo to type -// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts -// always succeed. When you downcast (that is, cast a pointer from -// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because -// how do you know the pointer is really of type SubclassOfFoo? It -// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, -// when you downcast, you should use this macro. In debug mode, we -// use dynamic_cast<> to double-check the downcast is legal (we die -// if it's not). In normal mode, we do the efficient static_cast<> -// instead. Thus, it's important to test in debug mode to make sure -// the cast is legal! -// This is the only place in the code we should use dynamic_cast<>. -// In particular, you SHOULDN'T be using dynamic_cast<> in order to -// do RTTI (eg code like this: -// if (dynamic_cast(foo)) HandleASubclass1Object(foo); -// if (dynamic_cast(foo)) HandleASubclass2Object(foo); -// You should design the code some other way not to need this. - -template // use like this: down_cast(foo); -inline To down_cast(From* f) { // so we only accept pointers - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away - // completely. - if (false) { - implicit_cast(0); - } - -#if !defined(NDEBUG) && !defined(GOOGLE_PROTOBUF_NO_RTTI) - assert(f == NULL || dynamic_cast(f) != NULL); // RTTI: debug mode only! -#endif - return static_cast(f); -} - -} // namespace internal - -// We made these internal so that they would show up as such in the docs, -// but we don't want to stick "internal::" in front of them everywhere. -using internal::implicit_cast; -using internal::down_cast; - -// The COMPILE_ASSERT macro can be used to verify that a compile time -// expression is true. For example, you could use it to verify the -// size of a static array: -// -// COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES, -// content_type_names_incorrect_size); -// -// or to make sure a struct is smaller than a certain size: -// -// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); -// -// The second argument to the macro is the name of the variable. If -// the expression is false, most compilers will issue a warning/error -// containing the name of the variable. - -namespace internal { - -template -struct CompileAssert { -}; - -} // namespace internal - -#undef GOOGLE_COMPILE_ASSERT -#define GOOGLE_COMPILE_ASSERT(expr, msg) \ - typedef ::google::protobuf::internal::CompileAssert<(bool(expr))> \ - msg[bool(expr) ? 1 : -1] - - -// Implementation details of COMPILE_ASSERT: -// -// - COMPILE_ASSERT works by defining an array type that has -1 -// elements (and thus is invalid) when the expression is false. -// -// - The simpler definition -// -// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] -// -// does not work, as gcc supports variable-length arrays whose sizes -// are determined at run-time (this is gcc's extension and not part -// of the C++ standard). As a result, gcc fails to reject the -// following code with the simple definition: -// -// int foo; -// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is -// // not a compile-time constant. -// -// - By using the type CompileAssert<(bool(expr))>, we ensures that -// expr is a compile-time constant. (Template arguments must be -// determined at compile-time.) -// -// - The outter parentheses in CompileAssert<(bool(expr))> are necessary -// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written -// -// CompileAssert -// -// instead, these compilers will refuse to compile -// -// COMPILE_ASSERT(5 > 0, some_message); -// -// (They seem to think the ">" in "5 > 0" marks the end of the -// template argument list.) -// -// - The array size is (bool(expr) ? 1 : -1), instead of simply -// -// ((expr) ? 1 : -1). -// -// This is to avoid running into a bug in MS VC 7.1, which -// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. - -// =================================================================== -// from google3/base/scoped_ptr.h - -namespace internal { - -// This is an implementation designed to match the anticipated future TR2 -// implementation of the scoped_ptr class, and its closely-related brethren, -// scoped_array, scoped_ptr_malloc, and make_scoped_ptr. - -template class scoped_ptr; -template class scoped_array; - -// A scoped_ptr is like a T*, except that the destructor of scoped_ptr -// automatically deletes the pointer it holds (if any). -// That is, scoped_ptr owns the T object that it points to. -// Like a T*, a scoped_ptr may hold either NULL or a pointer to a T object. -// -// The size of a scoped_ptr is small: -// sizeof(scoped_ptr) == sizeof(C*) -template -class scoped_ptr { - public: - - // The element type - typedef C element_type; - - // Constructor. Defaults to intializing with NULL. - // There is no way to create an uninitialized scoped_ptr. - // The input parameter must be allocated with new. - explicit scoped_ptr(C* p = NULL) : ptr_(p) { } - - // Destructor. If there is a C object, delete it. - // We don't need to test ptr_ == NULL because C++ does that for us. - ~scoped_ptr() { - enum { type_must_be_complete = sizeof(C) }; - delete ptr_; - } - - // Reset. Deletes the current owned object, if any. - // Then takes ownership of a new object, if given. - // this->reset(this->get()) works. - void reset(C* p = NULL) { - if (p != ptr_) { - enum { type_must_be_complete = sizeof(C) }; - delete ptr_; - ptr_ = p; - } - } - - // Accessors to get the owned object. - // operator* and operator-> will assert() if there is no current object. - C& operator*() const { - assert(ptr_ != NULL); - return *ptr_; - } - C* operator->() const { - assert(ptr_ != NULL); - return ptr_; - } - C* get() const { return ptr_; } - - // Comparison operators. - // These return whether two scoped_ptr refer to the same object, not just to - // two different but equal objects. - bool operator==(C* p) const { return ptr_ == p; } - bool operator!=(C* p) const { return ptr_ != p; } - - // Swap two scoped pointers. - void swap(scoped_ptr& p2) { - C* tmp = ptr_; - ptr_ = p2.ptr_; - p2.ptr_ = tmp; - } - - // Release a pointer. - // The return value is the current pointer held by this object. - // If this object holds a NULL pointer, the return value is NULL. - // After this operation, this object will hold a NULL pointer, - // and will not own the object any more. - C* release() { - C* retVal = ptr_; - ptr_ = NULL; - return retVal; - } - - private: - C* ptr_; - - // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't - // make sense, and if C2 == C, it still doesn't make sense because you should - // never have the same object owned by two different scoped_ptrs. - template bool operator==(scoped_ptr const& p2) const; - template bool operator!=(scoped_ptr const& p2) const; - - // Disallow evil constructors - scoped_ptr(const scoped_ptr&); - void operator=(const scoped_ptr&); -}; - -// scoped_array is like scoped_ptr, except that the caller must allocate -// with new [] and the destructor deletes objects with delete []. -// -// As with scoped_ptr, a scoped_array either points to an object -// or is NULL. A scoped_array owns the object that it points to. -// -// Size: sizeof(scoped_array) == sizeof(C*) -template -class scoped_array { - public: - - // The element type - typedef C element_type; - - // Constructor. Defaults to intializing with NULL. - // There is no way to create an uninitialized scoped_array. - // The input parameter must be allocated with new []. - explicit scoped_array(C* p = NULL) : array_(p) { } - - // Destructor. If there is a C object, delete it. - // We don't need to test ptr_ == NULL because C++ does that for us. - ~scoped_array() { - enum { type_must_be_complete = sizeof(C) }; - delete[] array_; - } - - // Reset. Deletes the current owned object, if any. - // Then takes ownership of a new object, if given. - // this->reset(this->get()) works. - void reset(C* p = NULL) { - if (p != array_) { - enum { type_must_be_complete = sizeof(C) }; - delete[] array_; - array_ = p; - } - } - - // Get one element of the current object. - // Will assert() if there is no current object, or index i is negative. - C& operator[](std::ptrdiff_t i) const { - assert(i >= 0); - assert(array_ != NULL); - return array_[i]; - } - - // Get a pointer to the zeroth element of the current object. - // If there is no current object, return NULL. - C* get() const { - return array_; - } - - // Comparison operators. - // These return whether two scoped_array refer to the same object, not just to - // two different but equal objects. - bool operator==(C* p) const { return array_ == p; } - bool operator!=(C* p) const { return array_ != p; } - - // Swap two scoped arrays. - void swap(scoped_array& p2) { - C* tmp = array_; - array_ = p2.array_; - p2.array_ = tmp; - } - - // Release an array. - // The return value is the current pointer held by this object. - // If this object holds a NULL pointer, the return value is NULL. - // After this operation, this object will hold a NULL pointer, - // and will not own the object any more. - C* release() { - C* retVal = array_; - array_ = NULL; - return retVal; - } - - private: - C* array_; - - // Forbid comparison of different scoped_array types. - template bool operator==(scoped_array const& p2) const; - template bool operator!=(scoped_array const& p2) const; - - // Disallow evil constructors - scoped_array(const scoped_array&); - void operator=(const scoped_array&); -}; - -} // namespace internal - -// We made these internal so that they would show up as such in the docs, -// but we don't want to stick "internal::" in front of them everywhere. -using internal::scoped_ptr; -using internal::scoped_array; - -// =================================================================== -// emulates google3/base/logging.h - -enum LogLevel { - LOGLEVEL_INFO, // Informational. This is never actually used by - // libprotobuf. - LOGLEVEL_WARNING, // Warns about issues that, although not technically a - // problem now, could cause problems in the future. For - // example, a // warning will be printed when parsing a - // message that is near the message size limit. - LOGLEVEL_ERROR, // An error occurred which should never happen during - // normal use. - LOGLEVEL_FATAL, // An error occurred from which the library cannot - // recover. This usually indicates a programming error - // in the code which calls the library, especially when - // compiled in debug mode. - -#ifdef NDEBUG - LOGLEVEL_DFATAL = LOGLEVEL_ERROR -#else - LOGLEVEL_DFATAL = LOGLEVEL_FATAL -#endif -}; - -namespace internal { - -class LogFinisher; - -class LIBPROTOBUF_EXPORT LogMessage { - public: - LogMessage(LogLevel level, const char* filename, int line); - ~LogMessage(); - - LogMessage& operator<<(const std::string& value); - LogMessage& operator<<(const char* value); - LogMessage& operator<<(char value); - LogMessage& operator<<(int value); - LogMessage& operator<<(uint value); - LogMessage& operator<<(long value); - LogMessage& operator<<(unsigned long value); - LogMessage& operator<<(double value); - - private: - friend class LogFinisher; - void Finish(); - - LogLevel level_; - const char* filename_; - int line_; - std::string message_; -}; - -// Used to make the entire "LOG(BLAH) << etc." expression have a void return -// type and print a newline after each message. -class LIBPROTOBUF_EXPORT LogFinisher { - public: - void operator=(LogMessage& other); -}; - -} // namespace internal - -// Undef everything in case we're being mixed with some other Google library -// which already defined them itself. Presumably all Google libraries will -// support the same syntax for these so it should not be a big deal if they -// end up using our definitions instead. -#undef GOOGLE_LOG -#undef GOOGLE_LOG_IF - -#undef GOOGLE_CHECK -#undef GOOGLE_CHECK_EQ -#undef GOOGLE_CHECK_NE -#undef GOOGLE_CHECK_LT -#undef GOOGLE_CHECK_LE -#undef GOOGLE_CHECK_GT -#undef GOOGLE_CHECK_GE - -#undef GOOGLE_DLOG -#undef GOOGLE_DCHECK -#undef GOOGLE_DCHECK_EQ -#undef GOOGLE_DCHECK_NE -#undef GOOGLE_DCHECK_LT -#undef GOOGLE_DCHECK_LE -#undef GOOGLE_DCHECK_GT -#undef GOOGLE_DCHECK_GE - -#define GOOGLE_LOG(LEVEL) \ - ::google::protobuf::internal::LogFinisher() = \ - ::google::protobuf::internal::LogMessage( \ - ::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__) -#define GOOGLE_LOG_IF(LEVEL, CONDITION) \ - !(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL) - -#define GOOGLE_CHECK(EXPRESSION) \ - GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": " -#define GOOGLE_CHECK_EQ(A, B) GOOGLE_CHECK((A) == (B)) -#define GOOGLE_CHECK_NE(A, B) GOOGLE_CHECK((A) != (B)) -#define GOOGLE_CHECK_LT(A, B) GOOGLE_CHECK((A) < (B)) -#define GOOGLE_CHECK_LE(A, B) GOOGLE_CHECK((A) <= (B)) -#define GOOGLE_CHECK_GT(A, B) GOOGLE_CHECK((A) > (B)) -#define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B)) - -#ifdef NDEBUG - -#define GOOGLE_DLOG GOOGLE_LOG_IF(INFO, false) - -#define GOOGLE_DCHECK(EXPRESSION) while(false) GOOGLE_CHECK(EXPRESSION) -#define GOOGLE_DCHECK_EQ(A, B) GOOGLE_DCHECK((A) == (B)) -#define GOOGLE_DCHECK_NE(A, B) GOOGLE_DCHECK((A) != (B)) -#define GOOGLE_DCHECK_LT(A, B) GOOGLE_DCHECK((A) < (B)) -#define GOOGLE_DCHECK_LE(A, B) GOOGLE_DCHECK((A) <= (B)) -#define GOOGLE_DCHECK_GT(A, B) GOOGLE_DCHECK((A) > (B)) -#define GOOGLE_DCHECK_GE(A, B) GOOGLE_DCHECK((A) >= (B)) - -#else // NDEBUG - -#define GOOGLE_DLOG GOOGLE_LOG - -#define GOOGLE_DCHECK GOOGLE_CHECK -#define GOOGLE_DCHECK_EQ GOOGLE_CHECK_EQ -#define GOOGLE_DCHECK_NE GOOGLE_CHECK_NE -#define GOOGLE_DCHECK_LT GOOGLE_CHECK_LT -#define GOOGLE_DCHECK_LE GOOGLE_CHECK_LE -#define GOOGLE_DCHECK_GT GOOGLE_CHECK_GT -#define GOOGLE_DCHECK_GE GOOGLE_CHECK_GE - -#endif // !NDEBUG - -typedef void LogHandler(LogLevel level, const char* filename, int line, - const std::string& message); - -// The protobuf library sometimes writes warning and error messages to -// stderr. These messages are primarily useful for developers, but may -// also help end users figure out a problem. If you would prefer that -// these messages be sent somewhere other than stderr, call SetLogHandler() -// to set your own handler. This returns the old handler. Set the handler -// to NULL to ignore log messages (but see also LogSilencer, below). -// -// Obviously, SetLogHandler is not thread-safe. You should only call it -// at initialization time, and probably not from library code. If you -// simply want to suppress log messages temporarily (e.g. because you -// have some code that tends to trigger them frequently and you know -// the warnings are not important to you), use the LogSilencer class -// below. -LIBPROTOBUF_EXPORT LogHandler* SetLogHandler(LogHandler* new_func); - -// Create a LogSilencer if you want to temporarily suppress all log -// messages. As long as any LogSilencer objects exist, non-fatal -// log messages will be discarded (the current LogHandler will *not* -// be called). Constructing a LogSilencer is thread-safe. You may -// accidentally suppress log messages occurring in another thread, but -// since messages are generally for debugging purposes only, this isn't -// a big deal. If you want to intercept log messages, use SetLogHandler(). -class LIBPROTOBUF_EXPORT LogSilencer { - public: - LogSilencer(); - ~LogSilencer(); -}; - -// =================================================================== -// emulates google3/base/callback.h - -// Abstract interface for a callback. When calling an RPC, you must provide -// a Closure to call when the procedure completes. See the Service interface -// in service.h. -// -// To automatically construct a Closure which calls a particular function or -// method with a particular set of parameters, use the NewCallback() function. -// Example: -// void FooDone(const FooResponse* response) { -// ... -// } -// -// void CallFoo() { -// ... -// // When done, call FooDone() and pass it a pointer to the response. -// Closure* callback = NewCallback(&FooDone, response); -// // Make the call. -// service->Foo(controller, request, response, callback); -// } -// -// Example that calls a method: -// class Handler { -// public: -// ... -// -// void FooDone(const FooResponse* response) { -// ... -// } -// -// void CallFoo() { -// ... -// // When done, call FooDone() and pass it a pointer to the response. -// Closure* callback = NewCallback(this, &Handler::FooDone, response); -// // Make the call. -// service->Foo(controller, request, response, callback); -// } -// }; -// -// Currently NewCallback() supports binding zero, one, or two arguments. -// -// Callbacks created with NewCallback() automatically delete themselves when -// executed. They should be used when a callback is to be called exactly -// once (usually the case with RPC callbacks). If a callback may be called -// a different number of times (including zero), create it with -// NewPermanentCallback() instead. You are then responsible for deleting the -// callback (using the "delete" keyword as normal). -// -// Note that NewCallback() is a bit touchy regarding argument types. Generally, -// the values you provide for the parameter bindings must exactly match the -// types accepted by the callback function. For example: -// void Foo(string s); -// NewCallback(&Foo, "foo"); // WON'T WORK: const char* != string -// NewCallback(&Foo, string("foo")); // WORKS -// Also note that the arguments cannot be references: -// void Foo(const string& s); -// string my_str; -// NewCallback(&Foo, my_str); // WON'T WORK: Can't use referecnes. -// However, correctly-typed pointers will work just fine. -class LIBPROTOBUF_EXPORT Closure { - public: - Closure() {} - virtual ~Closure(); - - virtual void Run() = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Closure); -}; - -namespace internal { - -class LIBPROTOBUF_EXPORT FunctionClosure0 : public Closure { - public: - typedef void (*FunctionType)(); - - FunctionClosure0(FunctionType function, bool self_deleting) - : function_(function), self_deleting_(self_deleting) {} - ~FunctionClosure0(); - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - function_(); - if (needs_delete) delete this; - } - - private: - FunctionType function_; - bool self_deleting_; -}; - -template -class MethodClosure0 : public Closure { - public: - typedef void (Class::*MethodType)(); - - MethodClosure0(Class* object, MethodType method, bool self_deleting) - : object_(object), method_(method), self_deleting_(self_deleting) {} - ~MethodClosure0() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - (object_->*method_)(); - if (needs_delete) delete this; - } - - private: - Class* object_; - MethodType method_; - bool self_deleting_; -}; - -template -class FunctionClosure1 : public Closure { - public: - typedef void (*FunctionType)(Arg1 arg1); - - FunctionClosure1(FunctionType function, bool self_deleting, - Arg1 arg1) - : function_(function), self_deleting_(self_deleting), - arg1_(arg1) {} - ~FunctionClosure1() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - function_(arg1_); - if (needs_delete) delete this; - } - - private: - FunctionType function_; - bool self_deleting_; - Arg1 arg1_; -}; - -template -class MethodClosure1 : public Closure { - public: - typedef void (Class::*MethodType)(Arg1 arg1); - - MethodClosure1(Class* object, MethodType method, bool self_deleting, - Arg1 arg1) - : object_(object), method_(method), self_deleting_(self_deleting), - arg1_(arg1) {} - ~MethodClosure1() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - (object_->*method_)(arg1_); - if (needs_delete) delete this; - } - - private: - Class* object_; - MethodType method_; - bool self_deleting_; - Arg1 arg1_; -}; - -template -class FunctionClosure2 : public Closure { - public: - typedef void (*FunctionType)(Arg1 arg1, Arg2 arg2); - - FunctionClosure2(FunctionType function, bool self_deleting, - Arg1 arg1, Arg2 arg2) - : function_(function), self_deleting_(self_deleting), - arg1_(arg1), arg2_(arg2) {} - ~FunctionClosure2() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - function_(arg1_, arg2_); - if (needs_delete) delete this; - } - - private: - FunctionType function_; - bool self_deleting_; - Arg1 arg1_; - Arg2 arg2_; -}; - -template -class MethodClosure2 : public Closure { - public: - typedef void (Class::*MethodType)(Arg1 arg1, Arg2 arg2); - - MethodClosure2(Class* object, MethodType method, bool self_deleting, - Arg1 arg1, Arg2 arg2) - : object_(object), method_(method), self_deleting_(self_deleting), - arg1_(arg1), arg2_(arg2) {} - ~MethodClosure2() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - (object_->*method_)(arg1_, arg2_); - if (needs_delete) delete this; - } - - private: - Class* object_; - MethodType method_; - bool self_deleting_; - Arg1 arg1_; - Arg2 arg2_; -}; - -} // namespace internal - -// See Closure. -inline Closure* NewCallback(void (*function)()) { - return new internal::FunctionClosure0(function, true); -} - -// See Closure. -inline Closure* NewPermanentCallback(void (*function)()) { - return new internal::FunctionClosure0(function, false); -} - -// See Closure. -template -inline Closure* NewCallback(Class* object, void (Class::*method)()) { - return new internal::MethodClosure0(object, method, true); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(Class* object, void (Class::*method)()) { - return new internal::MethodClosure0(object, method, false); -} - -// See Closure. -template -inline Closure* NewCallback(void (*function)(Arg1), - Arg1 arg1) { - return new internal::FunctionClosure1(function, true, arg1); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(void (*function)(Arg1), - Arg1 arg1) { - return new internal::FunctionClosure1(function, false, arg1); -} - -// See Closure. -template -inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1), - Arg1 arg1) { - return new internal::MethodClosure1(object, method, true, arg1); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(Class* object, void (Class::*method)(Arg1), - Arg1 arg1) { - return new internal::MethodClosure1(object, method, false, arg1); -} - -// See Closure. -template -inline Closure* NewCallback(void (*function)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::FunctionClosure2( - function, true, arg1, arg2); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(void (*function)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::FunctionClosure2( - function, false, arg1, arg2); -} - -// See Closure. -template -inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::MethodClosure2( - object, method, true, arg1, arg2); -} - -// See Closure. -template -inline Closure* NewPermanentCallback( - Class* object, void (Class::*method)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::MethodClosure2( - object, method, false, arg1, arg2); -} - -// A function which does nothing. Useful for creating no-op callbacks, e.g.: -// Closure* nothing = NewCallback(&DoNothing); -void LIBPROTOBUF_EXPORT DoNothing(); - -// =================================================================== -// emulates google3/base/mutex.h - -namespace internal { - -// A Mutex is a non-reentrant (aka non-recursive) mutex. At most one thread T -// may hold a mutex at a given time. If T attempts to Lock() the same Mutex -// while holding it, T will deadlock. -class LIBPROTOBUF_EXPORT Mutex { - public: - // Create a Mutex that is not held by anybody. - Mutex(); - - // Destructor - ~Mutex(); - - // Block if necessary until this Mutex is free, then acquire it exclusively. - void Lock(); - - // Release this Mutex. Caller must hold it exclusively. - void Unlock(); - - // Crash if this Mutex is not held exclusively by this thread. - // May fail to crash when it should; will never crash when it should not. - void AssertHeld(); - - private: - struct Internal; - Internal* mInternal; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Mutex); -}; - -// MutexLock(mu) acquires mu when constructed and releases it when destroyed. -class LIBPROTOBUF_EXPORT MutexLock { - public: - explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); } - ~MutexLock() { this->mu_->Unlock(); } - private: - Mutex *const mu_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLock); -}; - -// TODO(kenton): Implement these? Hard to implement portably. -typedef MutexLock ReaderMutexLock; -typedef MutexLock WriterMutexLock; - -// MutexLockMaybe is like MutexLock, but is a no-op when mu is NULL. -class LIBPROTOBUF_EXPORT MutexLockMaybe { - public: - explicit MutexLockMaybe(Mutex *mu) : - mu_(mu) { if (this->mu_ != NULL) { this->mu_->Lock(); } } - ~MutexLockMaybe() { if (this->mu_ != NULL) { this->mu_->Unlock(); } } - private: - Mutex *const mu_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLockMaybe); -}; - -} // namespace internal - -// We made these internal so that they would show up as such in the docs, -// but we don't want to stick "internal::" in front of them everywhere. -using internal::Mutex; -using internal::MutexLock; -using internal::ReaderMutexLock; -using internal::WriterMutexLock; -using internal::MutexLockMaybe; - -// =================================================================== -// from google3/base/type_traits.h - -namespace internal { - -// Specified by TR1 [4.7.4] Pointer modifications. -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { - typedef T type; }; - -// =================================================================== - -// Checks if the buffer contains structurally-valid UTF-8. Implemented in -// structurally_valid.cc. -LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); - -} // namespace internal - -// =================================================================== -// Shutdown support. - -// Shut down the entire protocol buffers library, deleting all static-duration -// objects allocated by the library or by generated .pb.cc files. -// -// There are two reasons you might want to call this: -// * You use a draconian definition of "memory leak" in which you expect -// every single malloc() to have a corresponding free(), even for objects -// which live until program exit. -// * You are writing a dynamically-loaded library which needs to clean up -// after itself when the library is unloaded. -// -// It is safe to call this multiple times. However, it is not safe to use -// any other part of the protocol buffers library after -// ShutdownProtobufLibrary() has been called. -LIBPROTOBUF_EXPORT void ShutdownProtobufLibrary(); - -namespace internal { - -// Register a function to be called when ShutdownProtocolBuffers() is called. -LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); - -} // namespace internal - -#ifdef PROTOBUF_USE_EXCEPTIONS -class FatalException : public std::exception { - public: - FatalException(const char* filename, int line, const std::string& message) - : filename_(filename), line_(line), message_(message) {} - virtual ~FatalException() throw(); - - virtual const char* what() const throw(); - - const char* filename() const { return filename_; } - int line() const { return line_; } - const std::string& message() const { return message_; } - - private: - const char* filename_; - const int line_; - const std::string message_; -}; -#endif - -// This is at the end of the file instead of the beginning to work around a bug -// in some versions of MSVC. -using namespace std; // Don't do this at home, kids. - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMMON_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h deleted file mode 100644 index 822d6050..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +++ /dev/null @@ -1,220 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// -// Deals with the fact that hash_map is not defined everywhere. - -#ifndef GOOGLE_PROTOBUF_STUBS_HASH_H__ -#define GOOGLE_PROTOBUF_STUBS_HASH_H__ - -#include -#include -#include "config.h" - -#if defined(HAVE_HASH_MAP) && defined(HAVE_HASH_SET) -#include HASH_MAP_H -#include HASH_SET_H -#else -#define MISSING_HASH -#include -#include -#endif - -namespace google { -namespace protobuf { - -#ifdef MISSING_HASH - -// This system doesn't have hash_map or hash_set. Emulate them using map and -// set. - -// Make hash be the same as less. Note that everywhere where custom -// hash functions are defined in the protobuf code, they are also defined such -// that they can be used as "less" functions, which is required by MSVC anyway. -template -struct hash { - // Dummy, just to make derivative hash functions compile. - int operator()(const Key& key) { - GOOGLE_LOG(FATAL) << "Should never be called."; - return 0; - } - - inline bool operator()(const Key& a, const Key& b) const { - return a < b; - } -}; - -// Make sure char* is compared by value. -template <> -struct hash { - // Dummy, just to make derivative hash functions compile. - int operator()(const char* key) { - GOOGLE_LOG(FATAL) << "Should never be called."; - return 0; - } - - inline bool operator()(const char* a, const char* b) const { - return strcmp(a, b) < 0; - } -}; - -template , - typename EqualKey = int > -class hash_map : public std::map { -}; - -template , - typename EqualKey = int > -class hash_set : public std::set { -}; - -#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) - -template -struct hash : public HASH_NAMESPACE::hash_compare { -}; - -// MSVC's hash_compare hashes based on the string contents but -// compares based on the string pointer. WTF? -class CstringLess { - public: - inline bool operator()(const char* a, const char* b) const { - return strcmp(a, b) < 0; - } -}; - -template <> -struct hash - : public HASH_NAMESPACE::hash_compare { -}; - -template , - typename EqualKey = int > -class hash_map : public HASH_NAMESPACE::hash_map< - Key, Data, HashFcn> { -}; - -template , - typename EqualKey = int > -class hash_set : public HASH_NAMESPACE::hash_set< - Key, HashFcn> { -}; - -#else - -template -struct hash : public HASH_NAMESPACE::hash { -}; - -template -struct hash { - inline size_t operator()(const Key* key) const { - return reinterpret_cast(key); - } -}; - -// Unlike the old SGI version, the TR1 "hash" does not special-case char*. So, -// we go ahead and provide our own implementation. -template <> -struct hash { - inline size_t operator()(const char* str) const { - size_t result = 0; - for (; *str != '\0'; str++) { - result = 5 * result + *str; - } - return result; - } -}; - -template , - typename EqualKey = std::equal_to > -class hash_map : public HASH_NAMESPACE::HASH_MAP_CLASS< - Key, Data, HashFcn, EqualKey> { -}; - -template , - typename EqualKey = std::equal_to > -class hash_set : public HASH_NAMESPACE::HASH_SET_CLASS< - Key, HashFcn, EqualKey> { -}; - -#endif - -template <> -struct hash { - inline size_t operator()(const string& key) const { - return hash()(key.c_str()); - } - - static const size_t bucket_size = 4; - static const size_t min_buckets = 8; - inline size_t operator()(const string& a, const string& b) const { - return a < b; - } -}; - -template -struct hash > { - inline size_t operator()(const pair& key) const { - size_t first_hash = hash()(key.first); - size_t second_hash = hash()(key.second); - - // FIXME(kenton): What is the best way to compute this hash? I have - // no idea! This seems a bit better than an XOR. - return first_hash * ((1 << 16) - 1) + second_hash; - } - - static const size_t bucket_size = 4; - static const size_t min_buckets = 8; - inline size_t operator()(const pair& a, - const pair& b) const { - return a < b; - } -}; - -// Used by GCC/SGI STL only. (Why isn't this provided by the standard -// library? :( ) -struct streq { - inline bool operator()(const char* a, const char* b) const { - return strcmp(a, b) == 0; - } -}; - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_HASH_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h deleted file mode 100644 index f5c9d6b6..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +++ /dev/null @@ -1,119 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// from google3/util/gtl/map-util.h -// Author: Anton Carver - -#ifndef GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ -#define GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ - -#include - -namespace google { -namespace protobuf { - -// Perform a lookup in a map or hash_map. -// If the key is present in the map then the value associated with that -// key is returned, otherwise the value passed as a default is returned. -template -const typename Collection::value_type::second_type& -FindWithDefault(const Collection& collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return value; - } - return it->second; -} - -// Perform a lookup in a map or hash_map. -// If the key is present a const pointer to the associated value is returned, -// otherwise a NULL pointer is returned. -template -const typename Collection::value_type::second_type* -FindOrNull(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return 0; - } - return &it->second; -} - -// Perform a lookup in a map or hash_map whose values are pointers. -// If the key is present a const pointer to the associated value is returned, -// otherwise a NULL pointer is returned. -// This function does not distinguish between a missing key and a key mapped -// to a NULL value. -template -const typename Collection::value_type::second_type -FindPtrOrNull(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return 0; - } - return it->second; -} - -// Change the value associated with a particular key in a map or hash_map. -// If the key is not present in the map the key and value are inserted, -// otherwise the value is updated to be a copy of the value provided. -// True indicates that an insert took place, false indicates an update. -template -bool InsertOrUpdate(Collection * const collection, - const Key& key, const Value& value) { - pair ret = - collection->insert(typename Collection::value_type(key, value)); - if (!ret.second) { - // update - ret.first->second = value; - return false; - } - return true; -} - -// Insert a new key and value into a map or hash_map. -// If the key is not present in the map the key and value are -// inserted, otherwise nothing happens. True indicates that an insert -// took place, false indicates the key was already present. -template -bool InsertIfNotPresent(Collection * const collection, - const Key& key, const Value& value) { - pair ret = - collection->insert(typename Collection::value_type(key, value)); - return ret.second; -} - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h deleted file mode 100644 index 0dee4076..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +++ /dev/null @@ -1,123 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// -// emulates google3/base/once.h -// -// This header is intended to be included only by internal .cc files and -// generated .pb.cc files. Users should not use this directly. -// -// This is basically a portable version of pthread_once(). -// -// This header declares three things: -// * A type called ProtobufOnceType. -// * A macro GOOGLE_PROTOBUF_DECLARE_ONCE() which declares a variable of type -// ProtobufOnceType. This is the only legal way to declare such a variable. -// The macro may only be used at the global scope (you cannot create local -// or class member variables of this type). -// * A function GogoleOnceInit(ProtobufOnceType* once, void (*init_func)()). -// This function, when invoked multiple times given the same ProtobufOnceType -// object, will invoke init_func on the first call only, and will make sure -// none of the calls return before that first call to init_func has finished. -// -// This implements a way to perform lazy initialization. It's more efficient -// than using mutexes as no lock is needed if initialization has already -// happened. -// -// Example usage: -// void Init(); -// GOOGLE_PROTOBUF_DECLARE_ONCE(once_init); -// -// // Calls Init() exactly once. -// void InitOnce() { -// GoogleOnceInit(&once_init, &Init); -// } -// -// Note that if GoogleOnceInit() is called before main() has begun, it must -// only be called by the thread that will eventually call main() -- that is, -// the thread that performs dynamic initialization. In general this is a safe -// assumption since people don't usually construct threads before main() starts, -// but it is technically not guaranteed. Unfortunately, Win32 provides no way -// whatsoever to statically-initialize its synchronization primitives, so our -// only choice is to assume that dynamic initialization is single-threaded. - -#ifndef GOOGLE_PROTOBUF_STUBS_ONCE_H__ -#define GOOGLE_PROTOBUF_STUBS_ONCE_H__ - -#include - -#ifndef _WIN32 -#include -#endif - -namespace google { -namespace protobuf { - -#ifdef _WIN32 - -struct ProtobufOnceInternal; - -struct LIBPROTOBUF_EXPORT ProtobufOnceType { - ProtobufOnceType(); - ~ProtobufOnceType(); - void Init(void (*init_func)()); - - volatile bool initialized_; - ProtobufOnceInternal* internal_; -}; - -#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ - ::google::protobuf::ProtobufOnceType NAME - -inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) { - // Note: Double-checked locking is safe on x86. - if (!once->initialized_) { - once->Init(init_func); - } -} - -#else - -typedef pthread_once_t ProtobufOnceType; - -#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ - pthread_once_t NAME = PTHREAD_ONCE_INIT - -inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) { - pthread_once(once, init_func); -} - -#endif - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_ONCE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h deleted file mode 100644 index a2e671bb..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +++ /dev/null @@ -1,121 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// from google3/util/gtl/stl_util-inl.h - -#ifndef GOOGLE_PROTOBUF_STUBS_STL_UTIL_INL_H__ -#define GOOGLE_PROTOBUF_STUBS_STL_UTIL_INL_H__ - -#include - -namespace google { -namespace protobuf { - -// STLDeleteContainerPointers() -// For a range within a container of pointers, calls delete -// (non-array version) on these pointers. -// NOTE: for these three functions, we could just implement a DeleteObject -// functor and then call for_each() on the range and functor, but this -// requires us to pull in all of algorithm.h, which seems expensive. -// For hash_[multi]set, it is important that this deletes behind the iterator -// because the hash_set may call the hash function on the iterator when it is -// advanced, which could result in the hash function trying to deference a -// stale pointer. -template -void STLDeleteContainerPointers(ForwardIterator begin, - ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete *temp; - } -} - -// Inside Google, this function implements a horrible, disgusting hack in which -// we reach into the string's private implementation and resize it without -// initializing the new bytes. In some cases doing this can significantly -// improve performance. However, since it's totally non-portable it has no -// place in open source code. Feel free to fill this function in with your -// own disgusting hack if you want the perf boost. -inline void STLStringResizeUninitialized(string* s, size_t new_size) { - s->resize(new_size); -} - -// Return a mutable char* pointing to a string's internal buffer, -// which may not be null-terminated. Writing through this pointer will -// modify the string. -// -// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the -// next call to a string method that invalidates iterators. -// -// As of 2006-04, there is no standard-blessed way of getting a -// mutable reference to a string's internal buffer. However, issue 530 -// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) -// proposes this as the method. According to Matt Austern, this should -// already work on all current implementations. -inline char* string_as_array(string* str) { - // DO NOT USE const_cast(str->data())! See the unittest for why. - return str->empty() ? NULL : &*str->begin(); -} - -// STLDeleteElements() deletes all the elements in an STL container and clears -// the container. This function is suitable for use with a vector, set, -// hash_set, or any other STL container which defines sensible begin(), end(), -// and clear() methods. -// -// If container is NULL, this function is a no-op. -// -// As an alternative to calling STLDeleteElements() directly, consider -// ElementDeleter (defined below), which ensures that your container's elements -// are deleted when the ElementDeleter goes out of scope. -template -void STLDeleteElements(T *container) { - if (!container) return; - STLDeleteContainerPointers(container->begin(), container->end()); - container->clear(); -} - -// Given an STL container consisting of (key, value) pairs, STLDeleteValues -// deletes all the "value" components and clears the container. Does nothing -// in the case it's given a NULL pointer. - -template -void STLDeleteValues(T *v) { - if (!v) return; - for (typename T::iterator i = v->begin(); i != v->end(); ++i) { - delete i->second; - } - v->clear(); -} - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_STL_UTIL_INL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h deleted file mode 100644 index 4a79c224..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +++ /dev/null @@ -1,457 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// from google3/strings/strutil.h - -#ifndef GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ -#define GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - -#ifdef _MSC_VER -#define strtoll _strtoi64 -#define strtoull _strtoui64 -#elif defined(__DECCXX) && defined(__osf__) -// HP C++ on Tru64 does not have strtoll, but strtol is already 64-bit. -#define strtoll strtol -#define strtoull strtoul -#endif - -// ---------------------------------------------------------------------- -// ascii_isalnum() -// Check if an ASCII character is alphanumeric. We can't use ctype's -// isalnum() because it is affected by locale. This function is applied -// to identifiers in the protocol buffer language, not to natural-language -// strings, so locale should not be taken into account. -// ascii_isdigit() -// Like above, but only accepts digits. -// ---------------------------------------------------------------------- - -inline bool ascii_isalnum(char c) { - return ('a' <= c && c <= 'z') || - ('A' <= c && c <= 'Z') || - ('0' <= c && c <= '9'); -} - -inline bool ascii_isdigit(char c) { - return ('0' <= c && c <= '9'); -} - -// ---------------------------------------------------------------------- -// HasPrefixString() -// Check if a string begins with a given prefix. -// StripPrefixString() -// Given a string and a putative prefix, returns the string minus the -// prefix string if the prefix matches, otherwise the original -// string. -// ---------------------------------------------------------------------- -inline bool HasPrefixString(const string& str, - const string& prefix) { - return str.size() >= prefix.size() && - str.compare(0, prefix.size(), prefix) == 0; -} - -inline string StripPrefixString(const string& str, const string& prefix) { - if (HasPrefixString(str, prefix)) { - return str.substr(prefix.size()); - } else { - return str; - } -} - -// ---------------------------------------------------------------------- -// HasSuffixString() -// Return true if str ends in suffix. -// StripSuffixString() -// Given a string and a putative suffix, returns the string minus the -// suffix string if the suffix matches, otherwise the original -// string. -// ---------------------------------------------------------------------- -inline bool HasSuffixString(const string& str, - const string& suffix) { - return str.size() >= suffix.size() && - str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; -} - -inline string StripSuffixString(const string& str, const string& suffix) { - if (HasSuffixString(str, suffix)) { - return str.substr(0, str.size() - suffix.size()); - } else { - return str; - } -} - -// ---------------------------------------------------------------------- -// StripString -// Replaces any occurrence of the character 'remove' (or the characters -// in 'remove') with the character 'replacewith'. -// Good for keeping html characters or protocol characters (\t) out -// of places where they might cause a problem. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT void StripString(string* s, const char* remove, - char replacewith); - -// ---------------------------------------------------------------------- -// LowerString() -// UpperString() -// Convert the characters in "s" to lowercase or uppercase. ASCII-only: -// these functions intentionally ignore locale because they are applied to -// identifiers used in the Protocol Buffer language, not to natural-language -// strings. -// ---------------------------------------------------------------------- - -inline void LowerString(string * s) { - string::iterator end = s->end(); - for (string::iterator i = s->begin(); i != end; ++i) { - // tolower() changes based on locale. We don't want this! - if ('A' <= *i && *i <= 'Z') *i += 'a' - 'A'; - } -} - -inline void UpperString(string * s) { - string::iterator end = s->end(); - for (string::iterator i = s->begin(); i != end; ++i) { - // toupper() changes based on locale. We don't want this! - if ('a' <= *i && *i <= 'z') *i += 'A' - 'a'; - } -} - -// ---------------------------------------------------------------------- -// StringReplace() -// Give me a string and two patterns "old" and "new", and I replace -// the first instance of "old" in the string with "new", if it -// exists. RETURN a new string, regardless of whether the replacement -// happened or not. -// ---------------------------------------------------------------------- - -LIBPROTOBUF_EXPORT string StringReplace(const string& s, const string& oldsub, - const string& newsub, bool replace_all); - -// ---------------------------------------------------------------------- -// SplitStringUsing() -// Split a string using a character delimiter. Append the components -// to 'result'. If there are consecutive delimiters, this function skips -// over all of them. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT void SplitStringUsing(const string& full, const char* delim, - vector* res); - -// ---------------------------------------------------------------------- -// JoinStrings() -// These methods concatenate a vector of strings into a C++ string, using -// the C-string "delim" as a separator between components. There are two -// flavors of the function, one flavor returns the concatenated string, -// another takes a pointer to the target string. In the latter case the -// target string is cleared and overwritten. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT void JoinStrings(const vector& components, - const char* delim, string* result); - -inline string JoinStrings(const vector& components, - const char* delim) { - string result; - JoinStrings(components, delim, &result); - return result; -} - -// ---------------------------------------------------------------------- -// UnescapeCEscapeSequences() -// Copies "source" to "dest", rewriting C-style escape sequences -// -- '\n', '\r', '\\', '\ooo', etc -- to their ASCII -// equivalents. "dest" must be sufficiently large to hold all -// the characters in the rewritten string (i.e. at least as large -// as strlen(source) + 1 should be safe, since the replacements -// are always shorter than the original escaped sequences). It's -// safe for source and dest to be the same. RETURNS the length -// of dest. -// -// It allows hex sequences \xhh, or generally \xhhhhh with an -// arbitrary number of hex digits, but all of them together must -// specify a value of a single byte (e.g. \x0045 is equivalent -// to \x45, and \x1234 is erroneous). -// -// It also allows escape sequences of the form \uhhhh (exactly four -// hex digits, upper or lower case) or \Uhhhhhhhh (exactly eight -// hex digits, upper or lower case) to specify a Unicode code -// point. The dest array will contain the UTF8-encoded version of -// that code-point (e.g., if source contains \u2019, then dest will -// contain the three bytes 0xE2, 0x80, and 0x99). -// -// Errors: In the first form of the call, errors are reported with -// LOG(ERROR). The same is true for the second form of the call if -// the pointer to the string vector is NULL; otherwise, error -// messages are stored in the vector. In either case, the effect on -// the dest array is not defined, but rest of the source will be -// processed. -// ---------------------------------------------------------------------- - -LIBPROTOBUF_EXPORT int UnescapeCEscapeSequences(const char* source, char* dest); -LIBPROTOBUF_EXPORT int UnescapeCEscapeSequences(const char* source, char* dest, - vector *errors); - -// ---------------------------------------------------------------------- -// UnescapeCEscapeString() -// This does the same thing as UnescapeCEscapeSequences, but creates -// a new string. The caller does not need to worry about allocating -// a dest buffer. This should be used for non performance critical -// tasks such as printing debug messages. It is safe for src and dest -// to be the same. -// -// The second call stores its errors in a supplied string vector. -// If the string vector pointer is NULL, it reports the errors with LOG(). -// -// In the first and second calls, the length of dest is returned. In the -// the third call, the new string is returned. -// ---------------------------------------------------------------------- - -LIBPROTOBUF_EXPORT int UnescapeCEscapeString(const string& src, string* dest); -LIBPROTOBUF_EXPORT int UnescapeCEscapeString(const string& src, string* dest, - vector *errors); -LIBPROTOBUF_EXPORT string UnescapeCEscapeString(const string& src); - -// ---------------------------------------------------------------------- -// CEscapeString() -// Copies 'src' to 'dest', escaping dangerous characters using -// C-style escape sequences. This is very useful for preparing query -// flags. 'src' and 'dest' should not overlap. -// Returns the number of bytes written to 'dest' (not including the \0) -// or -1 if there was insufficient space. -// -// Currently only \n, \r, \t, ", ', \ and !isprint() chars are escaped. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT int CEscapeString(const char* src, int src_len, - char* dest, int dest_len); - -// ---------------------------------------------------------------------- -// CEscape() -// More convenient form of CEscapeString: returns result as a "string". -// This version is slower than CEscapeString() because it does more -// allocation. However, it is much more convenient to use in -// non-speed-critical code like logging messages etc. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT string CEscape(const string& src); - -namespace strings { -// Like CEscape() but does not escape bytes with the upper bit set. -LIBPROTOBUF_EXPORT string Utf8SafeCEscape(const string& src); - -// Like CEscape() but uses hex (\x) escapes instead of octals. -LIBPROTOBUF_EXPORT string CHexEscape(const string& src); -} // namespace strings - -// ---------------------------------------------------------------------- -// strto32() -// strtou32() -// strto64() -// strtou64() -// Architecture-neutral plug compatible replacements for strtol() and -// strtoul(). Long's have different lengths on ILP-32 and LP-64 -// platforms, so using these is safer, from the point of view of -// overflow behavior, than using the standard libc functions. -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT int32 strto32_adaptor(const char *nptr, char **endptr, - int base); -LIBPROTOBUF_EXPORT uint32 strtou32_adaptor(const char *nptr, char **endptr, - int base); - -inline int32 strto32(const char *nptr, char **endptr, int base) { - if (sizeof(int32) == sizeof(long)) - return strtol(nptr, endptr, base); - else - return strto32_adaptor(nptr, endptr, base); -} - -inline uint32 strtou32(const char *nptr, char **endptr, int base) { - if (sizeof(uint32) == sizeof(unsigned long)) - return strtoul(nptr, endptr, base); - else - return strtou32_adaptor(nptr, endptr, base); -} - -// For now, long long is 64-bit on all the platforms we care about, so these -// functions can simply pass the call to strto[u]ll. -inline int64 strto64(const char *nptr, char **endptr, int base) { - GOOGLE_COMPILE_ASSERT(sizeof(int64) == sizeof(long long), - sizeof_int64_is_not_sizeof_long_long); - return strtoll(nptr, endptr, base); -} - -inline uint64 strtou64(const char *nptr, char **endptr, int base) { - GOOGLE_COMPILE_ASSERT(sizeof(uint64) == sizeof(unsigned long long), - sizeof_uint64_is_not_sizeof_long_long); - return strtoull(nptr, endptr, base); -} - -// ---------------------------------------------------------------------- -// FastIntToBuffer() -// FastHexToBuffer() -// FastHex64ToBuffer() -// FastHex32ToBuffer() -// FastTimeToBuffer() -// These are intended for speed. FastIntToBuffer() assumes the -// integer is non-negative. FastHexToBuffer() puts output in -// hex rather than decimal. FastTimeToBuffer() puts the output -// into RFC822 format. -// -// FastHex64ToBuffer() puts a 64-bit unsigned value in hex-format, -// padded to exactly 16 bytes (plus one byte for '\0') -// -// FastHex32ToBuffer() puts a 32-bit unsigned value in hex-format, -// padded to exactly 8 bytes (plus one byte for '\0') -// -// All functions take the output buffer as an arg. -// They all return a pointer to the beginning of the output, -// which may not be the beginning of the input buffer. -// ---------------------------------------------------------------------- - -// Suggested buffer size for FastToBuffer functions. Also works with -// DoubleToBuffer() and FloatToBuffer(). -static const int kFastToBufferSize = 32; - -LIBPROTOBUF_EXPORT char* FastInt32ToBuffer(int32 i, char* buffer); -LIBPROTOBUF_EXPORT char* FastInt64ToBuffer(int64 i, char* buffer); -char* FastUInt32ToBuffer(uint32 i, char* buffer); // inline below -char* FastUInt64ToBuffer(uint64 i, char* buffer); // inline below -LIBPROTOBUF_EXPORT char* FastHexToBuffer(int i, char* buffer); -LIBPROTOBUF_EXPORT char* FastHex64ToBuffer(uint64 i, char* buffer); -LIBPROTOBUF_EXPORT char* FastHex32ToBuffer(uint32 i, char* buffer); - -// at least 22 bytes long -inline char* FastIntToBuffer(int i, char* buffer) { - return (sizeof(i) == 4 ? - FastInt32ToBuffer(i, buffer) : FastInt64ToBuffer(i, buffer)); -} -inline char* FastUIntToBuffer(unsigned int i, char* buffer) { - return (sizeof(i) == 4 ? - FastUInt32ToBuffer(i, buffer) : FastUInt64ToBuffer(i, buffer)); -} -inline char* FastLongToBuffer(long i, char* buffer) { - return (sizeof(i) == 4 ? - FastInt32ToBuffer(i, buffer) : FastInt64ToBuffer(i, buffer)); -} -inline char* FastULongToBuffer(unsigned long i, char* buffer) { - return (sizeof(i) == 4 ? - FastUInt32ToBuffer(i, buffer) : FastUInt64ToBuffer(i, buffer)); -} - -// ---------------------------------------------------------------------- -// FastInt32ToBufferLeft() -// FastUInt32ToBufferLeft() -// FastInt64ToBufferLeft() -// FastUInt64ToBufferLeft() -// -// Like the Fast*ToBuffer() functions above, these are intended for speed. -// Unlike the Fast*ToBuffer() functions, however, these functions write -// their output to the beginning of the buffer (hence the name, as the -// output is left-aligned). The caller is responsible for ensuring that -// the buffer has enough space to hold the output. -// -// Returns a pointer to the end of the string (i.e. the null character -// terminating the string). -// ---------------------------------------------------------------------- - -LIBPROTOBUF_EXPORT char* FastInt32ToBufferLeft(int32 i, char* buffer); -LIBPROTOBUF_EXPORT char* FastUInt32ToBufferLeft(uint32 i, char* buffer); -LIBPROTOBUF_EXPORT char* FastInt64ToBufferLeft(int64 i, char* buffer); -LIBPROTOBUF_EXPORT char* FastUInt64ToBufferLeft(uint64 i, char* buffer); - -// Just define these in terms of the above. -inline char* FastUInt32ToBuffer(uint32 i, char* buffer) { - FastUInt32ToBufferLeft(i, buffer); - return buffer; -} -inline char* FastUInt64ToBuffer(uint64 i, char* buffer) { - FastUInt64ToBufferLeft(i, buffer); - return buffer; -} - -// ---------------------------------------------------------------------- -// SimpleItoa() -// Description: converts an integer to a string. -// -// Return value: string -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT string SimpleItoa(int i); -LIBPROTOBUF_EXPORT string SimpleItoa(unsigned int i); -LIBPROTOBUF_EXPORT string SimpleItoa(long i); -LIBPROTOBUF_EXPORT string SimpleItoa(unsigned long i); -LIBPROTOBUF_EXPORT string SimpleItoa(long long i); -LIBPROTOBUF_EXPORT string SimpleItoa(unsigned long long i); - -// ---------------------------------------------------------------------- -// SimpleDtoa() -// SimpleFtoa() -// DoubleToBuffer() -// FloatToBuffer() -// Description: converts a double or float to a string which, if -// passed to NoLocaleStrtod(), will produce the exact same original double -// (except in case of NaN; all NaNs are considered the same value). -// We try to keep the string short but it's not guaranteed to be as -// short as possible. -// -// DoubleToBuffer() and FloatToBuffer() write the text to the given -// buffer and return it. The buffer must be at least -// kDoubleToBufferSize bytes for doubles and kFloatToBufferSize -// bytes for floats. kFastToBufferSize is also guaranteed to be large -// enough to hold either. -// -// Return value: string -// ---------------------------------------------------------------------- -LIBPROTOBUF_EXPORT string SimpleDtoa(double value); -LIBPROTOBUF_EXPORT string SimpleFtoa(float value); - -LIBPROTOBUF_EXPORT char* DoubleToBuffer(double i, char* buffer); -LIBPROTOBUF_EXPORT char* FloatToBuffer(float i, char* buffer); - -// In practice, doubles should never need more than 24 bytes and floats -// should never need more than 14 (including null terminators), but we -// overestimate to be safe. -static const int kDoubleToBufferSize = 32; -static const int kFloatToBufferSize = 24; - -// ---------------------------------------------------------------------- -// NoLocaleStrtod() -// Exactly like strtod(), except it always behaves as if in the "C" -// locale (i.e. decimal points must be '.'s). -// ---------------------------------------------------------------------- - -LIBPROTOBUF_EXPORT double NoLocaleStrtod(const char* text, char** endptr); - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ - - diff --git a/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h b/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h deleted file mode 100644 index 2581793b..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +++ /dev/null @@ -1,170 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// from google3/strings/substitute.h - -#include -#include -#include - -#ifndef GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ -#define GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ - -namespace google { -namespace protobuf { -namespace strings { - -// ---------------------------------------------------------------------- -// strings::Substitute() -// strings::SubstituteAndAppend() -// Kind of like StringPrintf, but different. -// -// Example: -// string GetMessage(string first_name, string last_name, int age) { -// return strings::Substitute("My name is $0 $1 and I am $2 years old.", -// first_name, last_name, age); -// } -// -// Differences from StringPrintf: -// * The format string does not identify the types of arguments. -// Instead, the magic of C++ deals with this for us. See below -// for a list of accepted types. -// * Substitutions in the format string are identified by a '$' -// followed by a digit. So, you can use arguments out-of-order and -// use the same argument multiple times. -// * It's much faster than StringPrintf. -// -// Supported types: -// * Strings (const char*, const string&) -// * Note that this means you do not have to add .c_str() to all of -// your strings. In fact, you shouldn't; it will be slower. -// * int32, int64, uint32, uint64: Formatted using SimpleItoa(). -// * float, double: Formatted using SimpleFtoa() and SimpleDtoa(). -// * bool: Printed as "true" or "false". -// -// SubstituteAndAppend() is like Substitute() but appends the result to -// *output. Example: -// -// string str; -// strings::SubstituteAndAppend(&str, -// "My name is $0 $1 and I am $2 years old.", -// first_name, last_name, age); -// -// Substitute() is significantly faster than StringPrintf(). For very -// large strings, it may be orders of magnitude faster. -// ---------------------------------------------------------------------- - -namespace internal { // Implementation details. - -class SubstituteArg { - public: - inline SubstituteArg(const char* value) - : text_(value), size_(strlen(text_)) {} - inline SubstituteArg(const string& value) - : text_(value.data()), size_(value.size()) {} - - // Indicates that no argument was given. - inline explicit SubstituteArg() - : text_(NULL), size_(-1) {} - - // Primitives - // We don't overload for signed and unsigned char because if people are - // explicitly declaring their chars as signed or unsigned then they are - // probably actually using them as 8-bit integers and would probably - // prefer an integer representation. But, we don't really know. So, we - // make the caller decide what to do. - inline SubstituteArg(char value) - : text_(scratch_), size_(1) { scratch_[0] = value; } - inline SubstituteArg(short value) - : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(unsigned short value) - : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(int value) - : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(unsigned int value) - : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(long value) - : text_(FastLongToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(unsigned long value) - : text_(FastULongToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(long long value) - : text_(FastInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(unsigned long long value) - : text_(FastUInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(float value) - : text_(FloatToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(double value) - : text_(DoubleToBuffer(value, scratch_)), size_(strlen(text_)) {} - inline SubstituteArg(bool value) - : text_(value ? "true" : "false"), size_(strlen(text_)) {} - - inline const char* data() const { return text_; } - inline int size() const { return size_; } - - private: - const char* text_; - int size_; - char scratch_[kFastToBufferSize]; -}; - -} // namespace internal - -LIBPROTOBUF_EXPORT string Substitute( - const char* format, - const internal::SubstituteArg& arg0 = internal::SubstituteArg(), - const internal::SubstituteArg& arg1 = internal::SubstituteArg(), - const internal::SubstituteArg& arg2 = internal::SubstituteArg(), - const internal::SubstituteArg& arg3 = internal::SubstituteArg(), - const internal::SubstituteArg& arg4 = internal::SubstituteArg(), - const internal::SubstituteArg& arg5 = internal::SubstituteArg(), - const internal::SubstituteArg& arg6 = internal::SubstituteArg(), - const internal::SubstituteArg& arg7 = internal::SubstituteArg(), - const internal::SubstituteArg& arg8 = internal::SubstituteArg(), - const internal::SubstituteArg& arg9 = internal::SubstituteArg()); - -LIBPROTOBUF_EXPORT void SubstituteAndAppend( - string* output, const char* format, - const internal::SubstituteArg& arg0 = internal::SubstituteArg(), - const internal::SubstituteArg& arg1 = internal::SubstituteArg(), - const internal::SubstituteArg& arg2 = internal::SubstituteArg(), - const internal::SubstituteArg& arg3 = internal::SubstituteArg(), - const internal::SubstituteArg& arg4 = internal::SubstituteArg(), - const internal::SubstituteArg& arg5 = internal::SubstituteArg(), - const internal::SubstituteArg& arg6 = internal::SubstituteArg(), - const internal::SubstituteArg& arg7 = internal::SubstituteArg(), - const internal::SubstituteArg& arg8 = internal::SubstituteArg(), - const internal::SubstituteArg& arg9 = internal::SubstituteArg()); - -} // namespace strings -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/test_util.h b/ext/protobuf-2.4.1/src/google/protobuf/test_util.h deleted file mode 100644 index 25165f3a..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +++ /dev/null @@ -1,174 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_TEST_UTIL_H__ -#define GOOGLE_PROTOBUF_TEST_UTIL_H__ - -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -namespace unittest = protobuf_unittest; -namespace unittest_import = protobuf_unittest_import; - -class TestUtil { - public: - // Set every field in the message to a unique value. - static void SetAllFields(unittest::TestAllTypes* message); - static void SetAllExtensions(unittest::TestAllExtensions* message); - static void SetAllFieldsAndExtensions(unittest::TestFieldOrderings* message); - static void SetPackedFields(unittest::TestPackedTypes* message); - static void SetPackedExtensions(unittest::TestPackedExtensions* message); - static void SetUnpackedFields(unittest::TestUnpackedTypes* message); - - // Use the repeated versions of the set_*() accessors to modify all the - // repeated fields of the messsage (which should already have been - // initialized with Set*Fields()). Set*Fields() itself only tests - // the add_*() accessors. - static void ModifyRepeatedFields(unittest::TestAllTypes* message); - static void ModifyRepeatedExtensions(unittest::TestAllExtensions* message); - static void ModifyPackedFields(unittest::TestPackedTypes* message); - static void ModifyPackedExtensions(unittest::TestPackedExtensions* message); - - // Check that all fields have the values that they should have after - // Set*Fields() is called. - static void ExpectAllFieldsSet(const unittest::TestAllTypes& message); - static void ExpectAllExtensionsSet( - const unittest::TestAllExtensions& message); - static void ExpectPackedFieldsSet(const unittest::TestPackedTypes& message); - static void ExpectPackedExtensionsSet( - const unittest::TestPackedExtensions& message); - static void ExpectUnpackedFieldsSet( - const unittest::TestUnpackedTypes& message); - - // Expect that the message is modified as would be expected from - // Modify*Fields(). - static void ExpectRepeatedFieldsModified( - const unittest::TestAllTypes& message); - static void ExpectRepeatedExtensionsModified( - const unittest::TestAllExtensions& message); - static void ExpectPackedFieldsModified( - const unittest::TestPackedTypes& message); - static void ExpectPackedExtensionsModified( - const unittest::TestPackedExtensions& message); - - // Check that all fields have their default values. - static void ExpectClear(const unittest::TestAllTypes& message); - static void ExpectExtensionsClear(const unittest::TestAllExtensions& message); - static void ExpectPackedClear(const unittest::TestPackedTypes& message); - static void ExpectPackedExtensionsClear( - const unittest::TestPackedExtensions& message); - - // Check that the passed-in serialization is the canonical serialization we - // expect for a TestFieldOrderings message filled in by - // SetAllFieldsAndExtensions(). - static void ExpectAllFieldsAndExtensionsInOrder(const string& serialized); - - // Check that all repeated fields have had their last elements removed. - static void ExpectLastRepeatedsRemoved( - const unittest::TestAllTypes& message); - static void ExpectLastRepeatedExtensionsRemoved( - const unittest::TestAllExtensions& message); - - // Check that all repeated fields have had their first and last elements - // swapped. - static void ExpectRepeatedsSwapped(const unittest::TestAllTypes& message); - static void ExpectRepeatedExtensionsSwapped( - const unittest::TestAllExtensions& message); - - // Like above, but use the reflection interface. - class ReflectionTester { - public: - // base_descriptor must be a descriptor for TestAllTypes or - // TestAllExtensions. In the former case, ReflectionTester fetches from - // it the FieldDescriptors needed to use the reflection interface. In - // the latter case, ReflectionTester searches for extension fields in - // its file. - explicit ReflectionTester(const Descriptor* base_descriptor); - - void SetAllFieldsViaReflection(Message* message); - void ModifyRepeatedFieldsViaReflection(Message* message); - void ExpectAllFieldsSetViaReflection(const Message& message); - void ExpectClearViaReflection(const Message& message); - - void SetPackedFieldsViaReflection(Message* message); - void ModifyPackedFieldsViaReflection(Message* message); - void ExpectPackedFieldsSetViaReflection(const Message& message); - void ExpectPackedClearViaReflection(const Message& message); - - void RemoveLastRepeatedsViaReflection(Message* message); - void SwapRepeatedsViaReflection(Message* message); - - private: - const FieldDescriptor* F(const string& name); - - const Descriptor* base_descriptor_; - - const FieldDescriptor* group_a_; - const FieldDescriptor* repeated_group_a_; - const FieldDescriptor* nested_b_; - const FieldDescriptor* foreign_c_; - const FieldDescriptor* import_d_; - - const EnumValueDescriptor* nested_foo_; - const EnumValueDescriptor* nested_bar_; - const EnumValueDescriptor* nested_baz_; - const EnumValueDescriptor* foreign_foo_; - const EnumValueDescriptor* foreign_bar_; - const EnumValueDescriptor* foreign_baz_; - const EnumValueDescriptor* import_foo_; - const EnumValueDescriptor* import_bar_; - const EnumValueDescriptor* import_baz_; - - // We have to split this into three function otherwise it creates a stack - // frame so large that it triggers a warning. - void ExpectAllFieldsSetViaReflection1(const Message& message); - void ExpectAllFieldsSetViaReflection2(const Message& message); - void ExpectAllFieldsSetViaReflection3(const Message& message); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionTester); - }; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestUtil); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_TEST_UTIL_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h deleted file mode 100644 index ca35aaa4..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +++ /dev/null @@ -1,101 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ -#define GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ - -#include - -namespace google { -namespace protobuf { - -namespace unittest = protobuf_unittest; -namespace unittest_import = protobuf_unittest_import; - -class TestUtilLite { - public: - // Set every field in the message to a unique value. - static void SetAllFields(unittest::TestAllTypesLite* message); - static void SetAllExtensions(unittest::TestAllExtensionsLite* message); - static void SetPackedFields(unittest::TestPackedTypesLite* message); - static void SetPackedExtensions(unittest::TestPackedExtensionsLite* message); - - // Use the repeated versions of the set_*() accessors to modify all the - // repeated fields of the messsage (which should already have been - // initialized with Set*Fields()). Set*Fields() itself only tests - // the add_*() accessors. - static void ModifyRepeatedFields(unittest::TestAllTypesLite* message); - static void ModifyRepeatedExtensions( - unittest::TestAllExtensionsLite* message); - static void ModifyPackedFields(unittest::TestPackedTypesLite* message); - static void ModifyPackedExtensions( - unittest::TestPackedExtensionsLite* message); - - // Check that all fields have the values that they should have after - // Set*Fields() is called. - static void ExpectAllFieldsSet(const unittest::TestAllTypesLite& message); - static void ExpectAllExtensionsSet( - const unittest::TestAllExtensionsLite& message); - static void ExpectPackedFieldsSet( - const unittest::TestPackedTypesLite& message); - static void ExpectPackedExtensionsSet( - const unittest::TestPackedExtensionsLite& message); - - // Expect that the message is modified as would be expected from - // Modify*Fields(). - static void ExpectRepeatedFieldsModified( - const unittest::TestAllTypesLite& message); - static void ExpectRepeatedExtensionsModified( - const unittest::TestAllExtensionsLite& message); - static void ExpectPackedFieldsModified( - const unittest::TestPackedTypesLite& message); - static void ExpectPackedExtensionsModified( - const unittest::TestPackedExtensionsLite& message); - - // Check that all fields have their default values. - static void ExpectClear(const unittest::TestAllTypesLite& message); - static void ExpectExtensionsClear( - const unittest::TestAllExtensionsLite& message); - static void ExpectPackedClear(const unittest::TestPackedTypesLite& message); - static void ExpectPackedExtensionsClear( - const unittest::TestPackedExtensionsLite& message); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestUtilLite); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h b/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h deleted file mode 100644 index a6b1c764..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +++ /dev/null @@ -1,83 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// emulates google3/file/base/file.h - -#ifndef GOOGLE_PROTOBUF_TESTING_FILE_H__ -#define GOOGLE_PROTOBUF_TESTING_FILE_H__ - -#include - -namespace google { -namespace protobuf { - -const int DEFAULT_FILE_MODE = 0777; - -// Protocol buffer code only uses a couple static methods of File, and only -// in tests. -class File { - public: - // Check if the file exists. - static bool Exists(const string& name); - - // Read an entire file to a string. Return true if successful, false - // otherwise. - static bool ReadFileToString(const string& name, string* output); - - // Same as above, but crash on failure. - static void ReadFileToStringOrDie(const string& name, string* output); - - // Create a file and write a string to it. - static void WriteStringToFileOrDie(const string& contents, - const string& name); - - // Create a directory. - static bool CreateDir(const string& name, int mode); - - // Create a directory and all parent directories if necessary. - static bool RecursivelyCreateDir(const string& path, int mode); - - // If "name" is a file, we delete it. If it is a directory, we - // call DeleteRecursively() for each file or directory (other than - // dot and double-dot) within it, and then delete the directory itself. - // The "dummy" parameters have a meaning in the original version of this - // method but they are not used anywhere in protocol buffers. - static void DeleteRecursively(const string& name, - void* dummy1, void* dummy2); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(File); -}; - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_TESTING_FILE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h b/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h deleted file mode 100644 index 71444c96..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +++ /dev/null @@ -1,98 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// emulates google3/testing/base/public/googletest.h - -#ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__ -#define GOOGLE_PROTOBUF_GOOGLETEST_H__ - -#include -#include - -namespace google { -namespace protobuf { - -// When running unittests, get the directory containing the source code. -string TestSourceDir(); - -// When running unittests, get a directory where temporary files may be -// placed. -string TestTempDir(); - -// Capture all text written to stdout or stderr. -void CaptureTestStdout(); -void CaptureTestStderr(); - -// Stop capturing stdout or stderr and return the text captured. -string GetCapturedTestStdout(); -string GetCapturedTestStderr(); - -// For use with ScopedMemoryLog::GetMessages(). Inside Google the LogLevel -// constants don't have the LOGLEVEL_ prefix, so the code that used -// ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR. -#undef ERROR // defend against promiscuous windows.h -static const LogLevel ERROR = LOGLEVEL_ERROR; - -// Receives copies of all LOG(ERROR) messages while in scope. Sample usage: -// { -// ScopedMemoryLog log; // constructor registers object as a log sink -// SomeRoutineThatMayLogMessages(); -// const vector& warnings = log.GetMessages(ERROR); -// } // destructor unregisters object as a log sink -// This is a dummy implementation which covers only what is used by protocol -// buffer unit tests. -class ScopedMemoryLog { - public: - ScopedMemoryLog(); - virtual ~ScopedMemoryLog(); - - // Fetches all messages logged. The internal version of this class - // would only fetch messages at the given security level, but the protobuf - // open source version ignores the argument since we always pass ERROR - // anyway. - const vector& GetMessages(LogLevel dummy) const; - - private: - vector messages_; - LogHandler* old_handler_; - - static void HandleLog(LogLevel level, const char* filename, int line, - const string& message); - - static ScopedMemoryLog* active_log_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog); -}; - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_GOOGLETEST_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/text_format.h b/ext/protobuf-2.4.1/src/google/protobuf/text_format.h deleted file mode 100644 index 03c04910..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +++ /dev/null @@ -1,285 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: jschorr@google.com (Joseph Schorr) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Utilities for printing and parsing protocol messages in a human-readable, -// text-based format. - -#ifndef GOOGLE_PROTOBUF_TEXT_FORMAT_H__ -#define GOOGLE_PROTOBUF_TEXT_FORMAT_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - -namespace io { - class ErrorCollector; // tokenizer.h -} - -// This class implements protocol buffer text format. Printing and parsing -// protocol messages in text format is useful for debugging and human editing -// of messages. -// -// This class is really a namespace that contains only static methods. -class LIBPROTOBUF_EXPORT TextFormat { - public: - // Outputs a textual representation of the given message to the given - // output stream. - static bool Print(const Message& message, io::ZeroCopyOutputStream* output); - - // Print the fields in an UnknownFieldSet. They are printed by tag number - // only. Embedded messages are heuristically identified by attempting to - // parse them. - static bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, - io::ZeroCopyOutputStream* output); - - // Like Print(), but outputs directly to a string. - static bool PrintToString(const Message& message, string* output); - - // Like PrintUnknownFields(), but outputs directly to a string. - static bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, - string* output); - - // Outputs a textual representation of the value of the field supplied on - // the message supplied. For non-repeated fields, an index of -1 must - // be supplied. Note that this method will print the default value for a - // field if it is not set. - static void PrintFieldValueToString(const Message& message, - const FieldDescriptor* field, - int index, - string* output); - - // Class for those users which require more fine-grained control over how - // a protobuffer message is printed out. - class LIBPROTOBUF_EXPORT Printer { - public: - Printer(); - ~Printer(); - - // Like TextFormat::Print - bool Print(const Message& message, io::ZeroCopyOutputStream* output) const; - // Like TextFormat::PrintUnknownFields - bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, - io::ZeroCopyOutputStream* output) const; - // Like TextFormat::PrintToString - bool PrintToString(const Message& message, string* output) const; - // Like TextFormat::PrintUnknownFieldsToString - bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, - string* output) const; - // Like TextFormat::PrintFieldValueToString - void PrintFieldValueToString(const Message& message, - const FieldDescriptor* field, - int index, - string* output) const; - - // Adjust the initial indent level of all output. Each indent level is - // equal to two spaces. - void SetInitialIndentLevel(int indent_level) { - initial_indent_level_ = indent_level; - } - - // If printing in single line mode, then the entire message will be output - // on a single line with no line breaks. - void SetSingleLineMode(bool single_line_mode) { - single_line_mode_ = single_line_mode; - } - - // Set true to print repeated primitives in a format like: - // field_name: [1, 2, 3, 4] - // instead of printing each value on its own line. Short format applies - // only to primitive values -- i.e. everything except strings and - // sub-messages/groups. - void SetUseShortRepeatedPrimitives(bool use_short_repeated_primitives) { - use_short_repeated_primitives_ = use_short_repeated_primitives; - } - - // Set true to output UTF-8 instead of ASCII. The only difference - // is that bytes >= 0x80 in string fields will not be escaped, - // because they are assumed to be part of UTF-8 multi-byte - // sequences. - void SetUseUtf8StringEscaping(bool as_utf8) { - utf8_string_escaping_ = as_utf8; - } - - private: - // Forward declaration of an internal class used to print the text - // output to the OutputStream (see text_format.cc for implementation). - class TextGenerator; - - // Internal Print method, used for writing to the OutputStream via - // the TextGenerator class. - void Print(const Message& message, - TextGenerator& generator) const; - - // Print a single field. - void PrintField(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - TextGenerator& generator) const; - - // Print a repeated primitive field in short form. - void PrintShortRepeatedField(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - TextGenerator& generator) const; - - // Print the name of a field -- i.e. everything that comes before the - // ':' for a single name/value pair. - void PrintFieldName(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - TextGenerator& generator) const; - - // Outputs a textual representation of the value of the field supplied on - // the message supplied or the default value if not set. - void PrintFieldValue(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - int index, - TextGenerator& generator) const; - - // Print the fields in an UnknownFieldSet. They are printed by tag number - // only. Embedded messages are heuristically identified by attempting to - // parse them. - void PrintUnknownFields(const UnknownFieldSet& unknown_fields, - TextGenerator& generator) const; - - int initial_indent_level_; - - bool single_line_mode_; - - bool use_short_repeated_primitives_; - - bool utf8_string_escaping_; - }; - - // Parses a text-format protocol message from the given input stream to - // the given message object. This function parses the format written - // by Print(). - static bool Parse(io::ZeroCopyInputStream* input, Message* output); - // Like Parse(), but reads directly from a string. - static bool ParseFromString(const string& input, Message* output); - - // Like Parse(), but the data is merged into the given message, as if - // using Message::MergeFrom(). - static bool Merge(io::ZeroCopyInputStream* input, Message* output); - // Like Merge(), but reads directly from a string. - static bool MergeFromString(const string& input, Message* output); - - // Parse the given text as a single field value and store it into the - // given field of the given message. If the field is a repeated field, - // the new value will be added to the end - static bool ParseFieldValueFromString(const string& input, - const FieldDescriptor* field, - Message* message); - - // Interface that TextFormat::Parser can use to find extensions. - // This class may be extended in the future to find more information - // like fields, etc. - class LIBPROTOBUF_EXPORT Finder { - public: - virtual ~Finder(); - - // Try to find an extension of *message by fully-qualified field - // name. Returns NULL if no extension is known for this name or number. - virtual const FieldDescriptor* FindExtension( - Message* message, - const string& name) const = 0; - }; - - // For more control over parsing, use this class. - class LIBPROTOBUF_EXPORT Parser { - public: - Parser(); - ~Parser(); - - // Like TextFormat::Parse(). - bool Parse(io::ZeroCopyInputStream* input, Message* output); - // Like TextFormat::ParseFromString(). - bool ParseFromString(const string& input, Message* output); - // Like TextFormat::Merge(). - bool Merge(io::ZeroCopyInputStream* input, Message* output); - // Like TextFormat::MergeFromString(). - bool MergeFromString(const string& input, Message* output); - - // Set where to report parse errors. If NULL (the default), errors will - // be printed to stderr. - void RecordErrorsTo(io::ErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Set how parser finds extensions. If NULL (the default), the - // parser will use the standard Reflection object associated with - // the message being parsed. - void SetFinder(Finder* finder) { - finder_ = finder; - } - - // Normally parsing fails if, after parsing, output->IsInitialized() - // returns false. Call AllowPartialMessage(true) to skip this check. - void AllowPartialMessage(bool allow) { - allow_partial_ = allow; - } - - // Like TextFormat::ParseFieldValueFromString - bool ParseFieldValueFromString(const string& input, - const FieldDescriptor* field, - Message* output); - - private: - // Forward declaration of an internal class used to parse text - // representations (see text_format.cc for implementation). - class ParserImpl; - - // Like TextFormat::Merge(). The provided implementation is used - // to do the parsing. - bool MergeUsingImpl(io::ZeroCopyInputStream* input, - Message* output, - ParserImpl* parser_impl); - - io::ErrorCollector* error_collector_; - Finder* finder_; - bool allow_partial_; - }; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormat); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h deleted file mode 100644 index e294cf39..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +++ /dev/null @@ -1,11915 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include "google/protobuf/unittest_import.pb.h" -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - -class TestAllTypes; -class TestAllTypes_NestedMessage; -class TestAllTypes_OptionalGroup; -class TestAllTypes_RepeatedGroup; -class TestDeprecatedFields; -class ForeignMessage; -class TestAllExtensions; -class OptionalGroup_extension; -class RepeatedGroup_extension; -class TestNestedExtension; -class TestRequired; -class TestRequiredForeign; -class TestForeignNested; -class TestEmptyMessage; -class TestEmptyMessageWithExtensions; -class TestMultipleExtensionRanges; -class TestReallyLargeTagNumber; -class TestRecursiveMessage; -class TestMutualRecursionA; -class TestMutualRecursionB; -class TestDupFieldNumber; -class TestDupFieldNumber_Foo; -class TestDupFieldNumber_Bar; -class TestNestedMessageHasBits; -class TestNestedMessageHasBits_NestedMessage; -class TestCamelCaseFieldNames; -class TestFieldOrderings; -class TestExtremeDefaultValues; -class SparseEnumMessage; -class OneString; -class OneBytes; -class TestPackedTypes; -class TestUnpackedTypes; -class TestPackedExtensions; -class TestDynamicExtensions; -class TestDynamicExtensions_DynamicMessageType; -class TestRepeatedScalarDifferentTagSizes; -class FooRequest; -class FooResponse; -class BarRequest; -class BarResponse; - -enum TestAllTypes_NestedEnum { - TestAllTypes_NestedEnum_FOO = 1, - TestAllTypes_NestedEnum_BAR = 2, - TestAllTypes_NestedEnum_BAZ = 3 -}; -bool TestAllTypes_NestedEnum_IsValid(int value); -const TestAllTypes_NestedEnum TestAllTypes_NestedEnum_NestedEnum_MIN = TestAllTypes_NestedEnum_FOO; -const TestAllTypes_NestedEnum TestAllTypes_NestedEnum_NestedEnum_MAX = TestAllTypes_NestedEnum_BAZ; -const int TestAllTypes_NestedEnum_NestedEnum_ARRAYSIZE = TestAllTypes_NestedEnum_NestedEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TestAllTypes_NestedEnum_descriptor(); -inline const ::std::string& TestAllTypes_NestedEnum_Name(TestAllTypes_NestedEnum value) { - return ::google::protobuf::internal::NameOfEnum( - TestAllTypes_NestedEnum_descriptor(), value); -} -inline bool TestAllTypes_NestedEnum_Parse( - const ::std::string& name, TestAllTypes_NestedEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TestAllTypes_NestedEnum_descriptor(), name, value); -} -enum TestDynamicExtensions_DynamicEnumType { - TestDynamicExtensions_DynamicEnumType_DYNAMIC_FOO = 2200, - TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAR = 2201, - TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAZ = 2202 -}; -bool TestDynamicExtensions_DynamicEnumType_IsValid(int value); -const TestDynamicExtensions_DynamicEnumType TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MIN = TestDynamicExtensions_DynamicEnumType_DYNAMIC_FOO; -const TestDynamicExtensions_DynamicEnumType TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MAX = TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAZ; -const int TestDynamicExtensions_DynamicEnumType_DynamicEnumType_ARRAYSIZE = TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TestDynamicExtensions_DynamicEnumType_descriptor(); -inline const ::std::string& TestDynamicExtensions_DynamicEnumType_Name(TestDynamicExtensions_DynamicEnumType value) { - return ::google::protobuf::internal::NameOfEnum( - TestDynamicExtensions_DynamicEnumType_descriptor(), value); -} -inline bool TestDynamicExtensions_DynamicEnumType_Parse( - const ::std::string& name, TestDynamicExtensions_DynamicEnumType* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TestDynamicExtensions_DynamicEnumType_descriptor(), name, value); -} -enum ForeignEnum { - FOREIGN_FOO = 4, - FOREIGN_BAR = 5, - FOREIGN_BAZ = 6 -}; -bool ForeignEnum_IsValid(int value); -const ForeignEnum ForeignEnum_MIN = FOREIGN_FOO; -const ForeignEnum ForeignEnum_MAX = FOREIGN_BAZ; -const int ForeignEnum_ARRAYSIZE = ForeignEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* ForeignEnum_descriptor(); -inline const ::std::string& ForeignEnum_Name(ForeignEnum value) { - return ::google::protobuf::internal::NameOfEnum( - ForeignEnum_descriptor(), value); -} -inline bool ForeignEnum_Parse( - const ::std::string& name, ForeignEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - ForeignEnum_descriptor(), name, value); -} -enum TestEnumWithDupValue { - FOO1 = 1, - BAR1 = 2, - BAZ = 3, - FOO2 = 1, - BAR2 = 2 -}; -bool TestEnumWithDupValue_IsValid(int value); -const TestEnumWithDupValue TestEnumWithDupValue_MIN = FOO1; -const TestEnumWithDupValue TestEnumWithDupValue_MAX = BAZ; -const int TestEnumWithDupValue_ARRAYSIZE = TestEnumWithDupValue_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TestEnumWithDupValue_descriptor(); -inline const ::std::string& TestEnumWithDupValue_Name(TestEnumWithDupValue value) { - return ::google::protobuf::internal::NameOfEnum( - TestEnumWithDupValue_descriptor(), value); -} -inline bool TestEnumWithDupValue_Parse( - const ::std::string& name, TestEnumWithDupValue* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TestEnumWithDupValue_descriptor(), name, value); -} -enum TestSparseEnum { - SPARSE_A = 123, - SPARSE_B = 62374, - SPARSE_C = 12589234, - SPARSE_D = -15, - SPARSE_E = -53452, - SPARSE_F = 0, - SPARSE_G = 2 -}; -bool TestSparseEnum_IsValid(int value); -const TestSparseEnum TestSparseEnum_MIN = SPARSE_E; -const TestSparseEnum TestSparseEnum_MAX = SPARSE_C; -const int TestSparseEnum_ARRAYSIZE = TestSparseEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TestSparseEnum_descriptor(); -inline const ::std::string& TestSparseEnum_Name(TestSparseEnum value) { - return ::google::protobuf::internal::NameOfEnum( - TestSparseEnum_descriptor(), value); -} -inline bool TestSparseEnum_Parse( - const ::std::string& name, TestSparseEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TestSparseEnum_descriptor(), name, value); -} -// =================================================================== - -class TestAllTypes_NestedMessage : public ::google::protobuf::Message { - public: - TestAllTypes_NestedMessage(); - virtual ~TestAllTypes_NestedMessage(); - - TestAllTypes_NestedMessage(const TestAllTypes_NestedMessage& from); - - inline TestAllTypes_NestedMessage& operator=(const TestAllTypes_NestedMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestAllTypes_NestedMessage& default_instance(); - - void Swap(TestAllTypes_NestedMessage* other); - - // implements Message ---------------------------------------------- - - TestAllTypes_NestedMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestAllTypes_NestedMessage& from); - void MergeFrom(const TestAllTypes_NestedMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 bb = 1; - inline bool has_bb() const; - inline void clear_bb(); - static const int kBbFieldNumber = 1; - inline ::google::protobuf::int32 bb() const; - inline void set_bb(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes.NestedMessage) - private: - inline void set_has_bb(); - inline void clear_has_bb(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 bb_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypes_NestedMessage* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllTypes_OptionalGroup : public ::google::protobuf::Message { - public: - TestAllTypes_OptionalGroup(); - virtual ~TestAllTypes_OptionalGroup(); - - TestAllTypes_OptionalGroup(const TestAllTypes_OptionalGroup& from); - - inline TestAllTypes_OptionalGroup& operator=(const TestAllTypes_OptionalGroup& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestAllTypes_OptionalGroup& default_instance(); - - void Swap(TestAllTypes_OptionalGroup* other); - - // implements Message ---------------------------------------------- - - TestAllTypes_OptionalGroup* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestAllTypes_OptionalGroup& from); - void MergeFrom(const TestAllTypes_OptionalGroup& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 17; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 17; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes.OptionalGroup) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypes_OptionalGroup* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllTypes_RepeatedGroup : public ::google::protobuf::Message { - public: - TestAllTypes_RepeatedGroup(); - virtual ~TestAllTypes_RepeatedGroup(); - - TestAllTypes_RepeatedGroup(const TestAllTypes_RepeatedGroup& from); - - inline TestAllTypes_RepeatedGroup& operator=(const TestAllTypes_RepeatedGroup& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestAllTypes_RepeatedGroup& default_instance(); - - void Swap(TestAllTypes_RepeatedGroup* other); - - // implements Message ---------------------------------------------- - - TestAllTypes_RepeatedGroup* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestAllTypes_RepeatedGroup& from); - void MergeFrom(const TestAllTypes_RepeatedGroup& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 47; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 47; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes.RepeatedGroup) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypes_RepeatedGroup* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllTypes : public ::google::protobuf::Message { - public: - TestAllTypes(); - virtual ~TestAllTypes(); - - TestAllTypes(const TestAllTypes& from); - - inline TestAllTypes& operator=(const TestAllTypes& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestAllTypes& default_instance(); - - void Swap(TestAllTypes* other); - - // implements Message ---------------------------------------------- - - TestAllTypes* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestAllTypes& from); - void MergeFrom(const TestAllTypes& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef TestAllTypes_NestedMessage NestedMessage; - typedef TestAllTypes_OptionalGroup OptionalGroup; - typedef TestAllTypes_RepeatedGroup RepeatedGroup; - - typedef TestAllTypes_NestedEnum NestedEnum; - static const NestedEnum FOO = TestAllTypes_NestedEnum_FOO; - static const NestedEnum BAR = TestAllTypes_NestedEnum_BAR; - static const NestedEnum BAZ = TestAllTypes_NestedEnum_BAZ; - static inline bool NestedEnum_IsValid(int value) { - return TestAllTypes_NestedEnum_IsValid(value); - } - static const NestedEnum NestedEnum_MIN = - TestAllTypes_NestedEnum_NestedEnum_MIN; - static const NestedEnum NestedEnum_MAX = - TestAllTypes_NestedEnum_NestedEnum_MAX; - static const int NestedEnum_ARRAYSIZE = - TestAllTypes_NestedEnum_NestedEnum_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - NestedEnum_descriptor() { - return TestAllTypes_NestedEnum_descriptor(); - } - static inline const ::std::string& NestedEnum_Name(NestedEnum value) { - return TestAllTypes_NestedEnum_Name(value); - } - static inline bool NestedEnum_Parse(const ::std::string& name, - NestedEnum* value) { - return TestAllTypes_NestedEnum_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional int32 optional_int32 = 1; - inline bool has_optional_int32() const; - inline void clear_optional_int32(); - static const int kOptionalInt32FieldNumber = 1; - inline ::google::protobuf::int32 optional_int32() const; - inline void set_optional_int32(::google::protobuf::int32 value); - - // optional int64 optional_int64 = 2; - inline bool has_optional_int64() const; - inline void clear_optional_int64(); - static const int kOptionalInt64FieldNumber = 2; - inline ::google::protobuf::int64 optional_int64() const; - inline void set_optional_int64(::google::protobuf::int64 value); - - // optional uint32 optional_uint32 = 3; - inline bool has_optional_uint32() const; - inline void clear_optional_uint32(); - static const int kOptionalUint32FieldNumber = 3; - inline ::google::protobuf::uint32 optional_uint32() const; - inline void set_optional_uint32(::google::protobuf::uint32 value); - - // optional uint64 optional_uint64 = 4; - inline bool has_optional_uint64() const; - inline void clear_optional_uint64(); - static const int kOptionalUint64FieldNumber = 4; - inline ::google::protobuf::uint64 optional_uint64() const; - inline void set_optional_uint64(::google::protobuf::uint64 value); - - // optional sint32 optional_sint32 = 5; - inline bool has_optional_sint32() const; - inline void clear_optional_sint32(); - static const int kOptionalSint32FieldNumber = 5; - inline ::google::protobuf::int32 optional_sint32() const; - inline void set_optional_sint32(::google::protobuf::int32 value); - - // optional sint64 optional_sint64 = 6; - inline bool has_optional_sint64() const; - inline void clear_optional_sint64(); - static const int kOptionalSint64FieldNumber = 6; - inline ::google::protobuf::int64 optional_sint64() const; - inline void set_optional_sint64(::google::protobuf::int64 value); - - // optional fixed32 optional_fixed32 = 7; - inline bool has_optional_fixed32() const; - inline void clear_optional_fixed32(); - static const int kOptionalFixed32FieldNumber = 7; - inline ::google::protobuf::uint32 optional_fixed32() const; - inline void set_optional_fixed32(::google::protobuf::uint32 value); - - // optional fixed64 optional_fixed64 = 8; - inline bool has_optional_fixed64() const; - inline void clear_optional_fixed64(); - static const int kOptionalFixed64FieldNumber = 8; - inline ::google::protobuf::uint64 optional_fixed64() const; - inline void set_optional_fixed64(::google::protobuf::uint64 value); - - // optional sfixed32 optional_sfixed32 = 9; - inline bool has_optional_sfixed32() const; - inline void clear_optional_sfixed32(); - static const int kOptionalSfixed32FieldNumber = 9; - inline ::google::protobuf::int32 optional_sfixed32() const; - inline void set_optional_sfixed32(::google::protobuf::int32 value); - - // optional sfixed64 optional_sfixed64 = 10; - inline bool has_optional_sfixed64() const; - inline void clear_optional_sfixed64(); - static const int kOptionalSfixed64FieldNumber = 10; - inline ::google::protobuf::int64 optional_sfixed64() const; - inline void set_optional_sfixed64(::google::protobuf::int64 value); - - // optional float optional_float = 11; - inline bool has_optional_float() const; - inline void clear_optional_float(); - static const int kOptionalFloatFieldNumber = 11; - inline float optional_float() const; - inline void set_optional_float(float value); - - // optional double optional_double = 12; - inline bool has_optional_double() const; - inline void clear_optional_double(); - static const int kOptionalDoubleFieldNumber = 12; - inline double optional_double() const; - inline void set_optional_double(double value); - - // optional bool optional_bool = 13; - inline bool has_optional_bool() const; - inline void clear_optional_bool(); - static const int kOptionalBoolFieldNumber = 13; - inline bool optional_bool() const; - inline void set_optional_bool(bool value); - - // optional string optional_string = 14; - inline bool has_optional_string() const; - inline void clear_optional_string(); - static const int kOptionalStringFieldNumber = 14; - inline const ::std::string& optional_string() const; - inline void set_optional_string(const ::std::string& value); - inline void set_optional_string(const char* value); - inline void set_optional_string(const char* value, size_t size); - inline ::std::string* mutable_optional_string(); - inline ::std::string* release_optional_string(); - - // optional bytes optional_bytes = 15; - inline bool has_optional_bytes() const; - inline void clear_optional_bytes(); - static const int kOptionalBytesFieldNumber = 15; - inline const ::std::string& optional_bytes() const; - inline void set_optional_bytes(const ::std::string& value); - inline void set_optional_bytes(const char* value); - inline void set_optional_bytes(const void* value, size_t size); - inline ::std::string* mutable_optional_bytes(); - inline ::std::string* release_optional_bytes(); - - // optional group OptionalGroup = 16 { - inline bool has_optionalgroup() const; - inline void clear_optionalgroup(); - static const int kOptionalgroupFieldNumber = 16; - inline const ::protobuf_unittest::TestAllTypes_OptionalGroup& optionalgroup() const; - inline ::protobuf_unittest::TestAllTypes_OptionalGroup* mutable_optionalgroup(); - inline ::protobuf_unittest::TestAllTypes_OptionalGroup* release_optionalgroup(); - - // optional .protobuf_unittest.TestAllTypes.NestedMessage optional_nested_message = 18; - inline bool has_optional_nested_message() const; - inline void clear_optional_nested_message(); - static const int kOptionalNestedMessageFieldNumber = 18; - inline const ::protobuf_unittest::TestAllTypes_NestedMessage& optional_nested_message() const; - inline ::protobuf_unittest::TestAllTypes_NestedMessage* mutable_optional_nested_message(); - inline ::protobuf_unittest::TestAllTypes_NestedMessage* release_optional_nested_message(); - - // optional .protobuf_unittest.ForeignMessage optional_foreign_message = 19; - inline bool has_optional_foreign_message() const; - inline void clear_optional_foreign_message(); - static const int kOptionalForeignMessageFieldNumber = 19; - inline const ::protobuf_unittest::ForeignMessage& optional_foreign_message() const; - inline ::protobuf_unittest::ForeignMessage* mutable_optional_foreign_message(); - inline ::protobuf_unittest::ForeignMessage* release_optional_foreign_message(); - - // optional .protobuf_unittest_import.ImportMessage optional_import_message = 20; - inline bool has_optional_import_message() const; - inline void clear_optional_import_message(); - static const int kOptionalImportMessageFieldNumber = 20; - inline const ::protobuf_unittest_import::ImportMessage& optional_import_message() const; - inline ::protobuf_unittest_import::ImportMessage* mutable_optional_import_message(); - inline ::protobuf_unittest_import::ImportMessage* release_optional_import_message(); - - // optional .protobuf_unittest.TestAllTypes.NestedEnum optional_nested_enum = 21; - inline bool has_optional_nested_enum() const; - inline void clear_optional_nested_enum(); - static const int kOptionalNestedEnumFieldNumber = 21; - inline ::protobuf_unittest::TestAllTypes_NestedEnum optional_nested_enum() const; - inline void set_optional_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value); - - // optional .protobuf_unittest.ForeignEnum optional_foreign_enum = 22; - inline bool has_optional_foreign_enum() const; - inline void clear_optional_foreign_enum(); - static const int kOptionalForeignEnumFieldNumber = 22; - inline protobuf_unittest::ForeignEnum optional_foreign_enum() const; - inline void set_optional_foreign_enum(protobuf_unittest::ForeignEnum value); - - // optional .protobuf_unittest_import.ImportEnum optional_import_enum = 23; - inline bool has_optional_import_enum() const; - inline void clear_optional_import_enum(); - static const int kOptionalImportEnumFieldNumber = 23; - inline protobuf_unittest_import::ImportEnum optional_import_enum() const; - inline void set_optional_import_enum(protobuf_unittest_import::ImportEnum value); - - // optional string optional_string_piece = 24 [ctype = STRING_PIECE]; - inline bool has_optional_string_piece() const; - inline void clear_optional_string_piece(); - static const int kOptionalStringPieceFieldNumber = 24; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& optional_string_piece() const; - inline void set_optional_string_piece(const ::std::string& value); - inline void set_optional_string_piece(const char* value); - inline void set_optional_string_piece(const char* value, size_t size); - inline ::std::string* mutable_optional_string_piece(); - inline ::std::string* release_optional_string_piece(); - public: - - // optional string optional_cord = 25 [ctype = CORD]; - inline bool has_optional_cord() const; - inline void clear_optional_cord(); - static const int kOptionalCordFieldNumber = 25; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& optional_cord() const; - inline void set_optional_cord(const ::std::string& value); - inline void set_optional_cord(const char* value); - inline void set_optional_cord(const char* value, size_t size); - inline ::std::string* mutable_optional_cord(); - inline ::std::string* release_optional_cord(); - public: - - // repeated int32 repeated_int32 = 31; - inline int repeated_int32_size() const; - inline void clear_repeated_int32(); - static const int kRepeatedInt32FieldNumber = 31; - inline ::google::protobuf::int32 repeated_int32(int index) const; - inline void set_repeated_int32(int index, ::google::protobuf::int32 value); - inline void add_repeated_int32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeated_int32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeated_int32(); - - // repeated int64 repeated_int64 = 32; - inline int repeated_int64_size() const; - inline void clear_repeated_int64(); - static const int kRepeatedInt64FieldNumber = 32; - inline ::google::protobuf::int64 repeated_int64(int index) const; - inline void set_repeated_int64(int index, ::google::protobuf::int64 value); - inline void add_repeated_int64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - repeated_int64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_repeated_int64(); - - // repeated uint32 repeated_uint32 = 33; - inline int repeated_uint32_size() const; - inline void clear_repeated_uint32(); - static const int kRepeatedUint32FieldNumber = 33; - inline ::google::protobuf::uint32 repeated_uint32(int index) const; - inline void set_repeated_uint32(int index, ::google::protobuf::uint32 value); - inline void add_repeated_uint32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - repeated_uint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_repeated_uint32(); - - // repeated uint64 repeated_uint64 = 34; - inline int repeated_uint64_size() const; - inline void clear_repeated_uint64(); - static const int kRepeatedUint64FieldNumber = 34; - inline ::google::protobuf::uint64 repeated_uint64(int index) const; - inline void set_repeated_uint64(int index, ::google::protobuf::uint64 value); - inline void add_repeated_uint64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - repeated_uint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_repeated_uint64(); - - // repeated sint32 repeated_sint32 = 35; - inline int repeated_sint32_size() const; - inline void clear_repeated_sint32(); - static const int kRepeatedSint32FieldNumber = 35; - inline ::google::protobuf::int32 repeated_sint32(int index) const; - inline void set_repeated_sint32(int index, ::google::protobuf::int32 value); - inline void add_repeated_sint32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeated_sint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeated_sint32(); - - // repeated sint64 repeated_sint64 = 36; - inline int repeated_sint64_size() const; - inline void clear_repeated_sint64(); - static const int kRepeatedSint64FieldNumber = 36; - inline ::google::protobuf::int64 repeated_sint64(int index) const; - inline void set_repeated_sint64(int index, ::google::protobuf::int64 value); - inline void add_repeated_sint64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - repeated_sint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_repeated_sint64(); - - // repeated fixed32 repeated_fixed32 = 37; - inline int repeated_fixed32_size() const; - inline void clear_repeated_fixed32(); - static const int kRepeatedFixed32FieldNumber = 37; - inline ::google::protobuf::uint32 repeated_fixed32(int index) const; - inline void set_repeated_fixed32(int index, ::google::protobuf::uint32 value); - inline void add_repeated_fixed32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - repeated_fixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_repeated_fixed32(); - - // repeated fixed64 repeated_fixed64 = 38; - inline int repeated_fixed64_size() const; - inline void clear_repeated_fixed64(); - static const int kRepeatedFixed64FieldNumber = 38; - inline ::google::protobuf::uint64 repeated_fixed64(int index) const; - inline void set_repeated_fixed64(int index, ::google::protobuf::uint64 value); - inline void add_repeated_fixed64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - repeated_fixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_repeated_fixed64(); - - // repeated sfixed32 repeated_sfixed32 = 39; - inline int repeated_sfixed32_size() const; - inline void clear_repeated_sfixed32(); - static const int kRepeatedSfixed32FieldNumber = 39; - inline ::google::protobuf::int32 repeated_sfixed32(int index) const; - inline void set_repeated_sfixed32(int index, ::google::protobuf::int32 value); - inline void add_repeated_sfixed32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeated_sfixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeated_sfixed32(); - - // repeated sfixed64 repeated_sfixed64 = 40; - inline int repeated_sfixed64_size() const; - inline void clear_repeated_sfixed64(); - static const int kRepeatedSfixed64FieldNumber = 40; - inline ::google::protobuf::int64 repeated_sfixed64(int index) const; - inline void set_repeated_sfixed64(int index, ::google::protobuf::int64 value); - inline void add_repeated_sfixed64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - repeated_sfixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_repeated_sfixed64(); - - // repeated float repeated_float = 41; - inline int repeated_float_size() const; - inline void clear_repeated_float(); - static const int kRepeatedFloatFieldNumber = 41; - inline float repeated_float(int index) const; - inline void set_repeated_float(int index, float value); - inline void add_repeated_float(float value); - inline const ::google::protobuf::RepeatedField< float >& - repeated_float() const; - inline ::google::protobuf::RepeatedField< float >* - mutable_repeated_float(); - - // repeated double repeated_double = 42; - inline int repeated_double_size() const; - inline void clear_repeated_double(); - static const int kRepeatedDoubleFieldNumber = 42; - inline double repeated_double(int index) const; - inline void set_repeated_double(int index, double value); - inline void add_repeated_double(double value); - inline const ::google::protobuf::RepeatedField< double >& - repeated_double() const; - inline ::google::protobuf::RepeatedField< double >* - mutable_repeated_double(); - - // repeated bool repeated_bool = 43; - inline int repeated_bool_size() const; - inline void clear_repeated_bool(); - static const int kRepeatedBoolFieldNumber = 43; - inline bool repeated_bool(int index) const; - inline void set_repeated_bool(int index, bool value); - inline void add_repeated_bool(bool value); - inline const ::google::protobuf::RepeatedField< bool >& - repeated_bool() const; - inline ::google::protobuf::RepeatedField< bool >* - mutable_repeated_bool(); - - // repeated string repeated_string = 44; - inline int repeated_string_size() const; - inline void clear_repeated_string(); - static const int kRepeatedStringFieldNumber = 44; - inline const ::std::string& repeated_string(int index) const; - inline ::std::string* mutable_repeated_string(int index); - inline void set_repeated_string(int index, const ::std::string& value); - inline void set_repeated_string(int index, const char* value); - inline void set_repeated_string(int index, const char* value, size_t size); - inline ::std::string* add_repeated_string(); - inline void add_repeated_string(const ::std::string& value); - inline void add_repeated_string(const char* value); - inline void add_repeated_string(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string(); - - // repeated bytes repeated_bytes = 45; - inline int repeated_bytes_size() const; - inline void clear_repeated_bytes(); - static const int kRepeatedBytesFieldNumber = 45; - inline const ::std::string& repeated_bytes(int index) const; - inline ::std::string* mutable_repeated_bytes(int index); - inline void set_repeated_bytes(int index, const ::std::string& value); - inline void set_repeated_bytes(int index, const char* value); - inline void set_repeated_bytes(int index, const void* value, size_t size); - inline ::std::string* add_repeated_bytes(); - inline void add_repeated_bytes(const ::std::string& value); - inline void add_repeated_bytes(const char* value); - inline void add_repeated_bytes(const void* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_bytes() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_bytes(); - - // repeated group RepeatedGroup = 46 { - inline int repeatedgroup_size() const; - inline void clear_repeatedgroup(); - static const int kRepeatedgroupFieldNumber = 46; - inline const ::protobuf_unittest::TestAllTypes_RepeatedGroup& repeatedgroup(int index) const; - inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* mutable_repeatedgroup(int index); - inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* add_repeatedgroup(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >& - repeatedgroup() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >* - mutable_repeatedgroup(); - - // repeated .protobuf_unittest.TestAllTypes.NestedMessage repeated_nested_message = 48; - inline int repeated_nested_message_size() const; - inline void clear_repeated_nested_message(); - static const int kRepeatedNestedMessageFieldNumber = 48; - inline const ::protobuf_unittest::TestAllTypes_NestedMessage& repeated_nested_message(int index) const; - inline ::protobuf_unittest::TestAllTypes_NestedMessage* mutable_repeated_nested_message(int index); - inline ::protobuf_unittest::TestAllTypes_NestedMessage* add_repeated_nested_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >& - repeated_nested_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >* - mutable_repeated_nested_message(); - - // repeated .protobuf_unittest.ForeignMessage repeated_foreign_message = 49; - inline int repeated_foreign_message_size() const; - inline void clear_repeated_foreign_message(); - static const int kRepeatedForeignMessageFieldNumber = 49; - inline const ::protobuf_unittest::ForeignMessage& repeated_foreign_message(int index) const; - inline ::protobuf_unittest::ForeignMessage* mutable_repeated_foreign_message(int index); - inline ::protobuf_unittest::ForeignMessage* add_repeated_foreign_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& - repeated_foreign_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* - mutable_repeated_foreign_message(); - - // repeated .protobuf_unittest_import.ImportMessage repeated_import_message = 50; - inline int repeated_import_message_size() const; - inline void clear_repeated_import_message(); - static const int kRepeatedImportMessageFieldNumber = 50; - inline const ::protobuf_unittest_import::ImportMessage& repeated_import_message(int index) const; - inline ::protobuf_unittest_import::ImportMessage* mutable_repeated_import_message(int index); - inline ::protobuf_unittest_import::ImportMessage* add_repeated_import_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >& - repeated_import_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >* - mutable_repeated_import_message(); - - // repeated .protobuf_unittest.TestAllTypes.NestedEnum repeated_nested_enum = 51; - inline int repeated_nested_enum_size() const; - inline void clear_repeated_nested_enum(); - static const int kRepeatedNestedEnumFieldNumber = 51; - inline ::protobuf_unittest::TestAllTypes_NestedEnum repeated_nested_enum(int index) const; - inline void set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypes_NestedEnum value); - inline void add_repeated_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value); - inline const ::google::protobuf::RepeatedField& repeated_nested_enum() const; - inline ::google::protobuf::RepeatedField* mutable_repeated_nested_enum(); - - // repeated .protobuf_unittest.ForeignEnum repeated_foreign_enum = 52; - inline int repeated_foreign_enum_size() const; - inline void clear_repeated_foreign_enum(); - static const int kRepeatedForeignEnumFieldNumber = 52; - inline protobuf_unittest::ForeignEnum repeated_foreign_enum(int index) const; - inline void set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnum value); - inline void add_repeated_foreign_enum(protobuf_unittest::ForeignEnum value); - inline const ::google::protobuf::RepeatedField& repeated_foreign_enum() const; - inline ::google::protobuf::RepeatedField* mutable_repeated_foreign_enum(); - - // repeated .protobuf_unittest_import.ImportEnum repeated_import_enum = 53; - inline int repeated_import_enum_size() const; - inline void clear_repeated_import_enum(); - static const int kRepeatedImportEnumFieldNumber = 53; - inline protobuf_unittest_import::ImportEnum repeated_import_enum(int index) const; - inline void set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnum value); - inline void add_repeated_import_enum(protobuf_unittest_import::ImportEnum value); - inline const ::google::protobuf::RepeatedField& repeated_import_enum() const; - inline ::google::protobuf::RepeatedField* mutable_repeated_import_enum(); - - // repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; - inline int repeated_string_piece_size() const; - inline void clear_repeated_string_piece(); - static const int kRepeatedStringPieceFieldNumber = 54; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& repeated_string_piece(int index) const; - inline ::std::string* mutable_repeated_string_piece(int index); - inline void set_repeated_string_piece(int index, const ::std::string& value); - inline void set_repeated_string_piece(int index, const char* value); - inline void set_repeated_string_piece(int index, const char* value, size_t size); - inline ::std::string* add_repeated_string_piece(); - inline void add_repeated_string_piece(const ::std::string& value); - inline void add_repeated_string_piece(const char* value); - inline void add_repeated_string_piece(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string_piece() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string_piece(); - public: - - // repeated string repeated_cord = 55 [ctype = CORD]; - inline int repeated_cord_size() const; - inline void clear_repeated_cord(); - static const int kRepeatedCordFieldNumber = 55; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& repeated_cord(int index) const; - inline ::std::string* mutable_repeated_cord(int index); - inline void set_repeated_cord(int index, const ::std::string& value); - inline void set_repeated_cord(int index, const char* value); - inline void set_repeated_cord(int index, const char* value, size_t size); - inline ::std::string* add_repeated_cord(); - inline void add_repeated_cord(const ::std::string& value); - inline void add_repeated_cord(const char* value); - inline void add_repeated_cord(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_cord() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_cord(); - public: - - // optional int32 default_int32 = 61 [default = 41]; - inline bool has_default_int32() const; - inline void clear_default_int32(); - static const int kDefaultInt32FieldNumber = 61; - inline ::google::protobuf::int32 default_int32() const; - inline void set_default_int32(::google::protobuf::int32 value); - - // optional int64 default_int64 = 62 [default = 42]; - inline bool has_default_int64() const; - inline void clear_default_int64(); - static const int kDefaultInt64FieldNumber = 62; - inline ::google::protobuf::int64 default_int64() const; - inline void set_default_int64(::google::protobuf::int64 value); - - // optional uint32 default_uint32 = 63 [default = 43]; - inline bool has_default_uint32() const; - inline void clear_default_uint32(); - static const int kDefaultUint32FieldNumber = 63; - inline ::google::protobuf::uint32 default_uint32() const; - inline void set_default_uint32(::google::protobuf::uint32 value); - - // optional uint64 default_uint64 = 64 [default = 44]; - inline bool has_default_uint64() const; - inline void clear_default_uint64(); - static const int kDefaultUint64FieldNumber = 64; - inline ::google::protobuf::uint64 default_uint64() const; - inline void set_default_uint64(::google::protobuf::uint64 value); - - // optional sint32 default_sint32 = 65 [default = -45]; - inline bool has_default_sint32() const; - inline void clear_default_sint32(); - static const int kDefaultSint32FieldNumber = 65; - inline ::google::protobuf::int32 default_sint32() const; - inline void set_default_sint32(::google::protobuf::int32 value); - - // optional sint64 default_sint64 = 66 [default = 46]; - inline bool has_default_sint64() const; - inline void clear_default_sint64(); - static const int kDefaultSint64FieldNumber = 66; - inline ::google::protobuf::int64 default_sint64() const; - inline void set_default_sint64(::google::protobuf::int64 value); - - // optional fixed32 default_fixed32 = 67 [default = 47]; - inline bool has_default_fixed32() const; - inline void clear_default_fixed32(); - static const int kDefaultFixed32FieldNumber = 67; - inline ::google::protobuf::uint32 default_fixed32() const; - inline void set_default_fixed32(::google::protobuf::uint32 value); - - // optional fixed64 default_fixed64 = 68 [default = 48]; - inline bool has_default_fixed64() const; - inline void clear_default_fixed64(); - static const int kDefaultFixed64FieldNumber = 68; - inline ::google::protobuf::uint64 default_fixed64() const; - inline void set_default_fixed64(::google::protobuf::uint64 value); - - // optional sfixed32 default_sfixed32 = 69 [default = 49]; - inline bool has_default_sfixed32() const; - inline void clear_default_sfixed32(); - static const int kDefaultSfixed32FieldNumber = 69; - inline ::google::protobuf::int32 default_sfixed32() const; - inline void set_default_sfixed32(::google::protobuf::int32 value); - - // optional sfixed64 default_sfixed64 = 70 [default = -50]; - inline bool has_default_sfixed64() const; - inline void clear_default_sfixed64(); - static const int kDefaultSfixed64FieldNumber = 70; - inline ::google::protobuf::int64 default_sfixed64() const; - inline void set_default_sfixed64(::google::protobuf::int64 value); - - // optional float default_float = 71 [default = 51.5]; - inline bool has_default_float() const; - inline void clear_default_float(); - static const int kDefaultFloatFieldNumber = 71; - inline float default_float() const; - inline void set_default_float(float value); - - // optional double default_double = 72 [default = 52000]; - inline bool has_default_double() const; - inline void clear_default_double(); - static const int kDefaultDoubleFieldNumber = 72; - inline double default_double() const; - inline void set_default_double(double value); - - // optional bool default_bool = 73 [default = true]; - inline bool has_default_bool() const; - inline void clear_default_bool(); - static const int kDefaultBoolFieldNumber = 73; - inline bool default_bool() const; - inline void set_default_bool(bool value); - - // optional string default_string = 74 [default = "hello"]; - inline bool has_default_string() const; - inline void clear_default_string(); - static const int kDefaultStringFieldNumber = 74; - inline const ::std::string& default_string() const; - inline void set_default_string(const ::std::string& value); - inline void set_default_string(const char* value); - inline void set_default_string(const char* value, size_t size); - inline ::std::string* mutable_default_string(); - inline ::std::string* release_default_string(); - - // optional bytes default_bytes = 75 [default = "world"]; - inline bool has_default_bytes() const; - inline void clear_default_bytes(); - static const int kDefaultBytesFieldNumber = 75; - inline const ::std::string& default_bytes() const; - inline void set_default_bytes(const ::std::string& value); - inline void set_default_bytes(const char* value); - inline void set_default_bytes(const void* value, size_t size); - inline ::std::string* mutable_default_bytes(); - inline ::std::string* release_default_bytes(); - - // optional .protobuf_unittest.TestAllTypes.NestedEnum default_nested_enum = 81 [default = BAR]; - inline bool has_default_nested_enum() const; - inline void clear_default_nested_enum(); - static const int kDefaultNestedEnumFieldNumber = 81; - inline ::protobuf_unittest::TestAllTypes_NestedEnum default_nested_enum() const; - inline void set_default_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value); - - // optional .protobuf_unittest.ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; - inline bool has_default_foreign_enum() const; - inline void clear_default_foreign_enum(); - static const int kDefaultForeignEnumFieldNumber = 82; - inline protobuf_unittest::ForeignEnum default_foreign_enum() const; - inline void set_default_foreign_enum(protobuf_unittest::ForeignEnum value); - - // optional .protobuf_unittest_import.ImportEnum default_import_enum = 83 [default = IMPORT_BAR]; - inline bool has_default_import_enum() const; - inline void clear_default_import_enum(); - static const int kDefaultImportEnumFieldNumber = 83; - inline protobuf_unittest_import::ImportEnum default_import_enum() const; - inline void set_default_import_enum(protobuf_unittest_import::ImportEnum value); - - // optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; - inline bool has_default_string_piece() const; - inline void clear_default_string_piece(); - static const int kDefaultStringPieceFieldNumber = 84; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& default_string_piece() const; - inline void set_default_string_piece(const ::std::string& value); - inline void set_default_string_piece(const char* value); - inline void set_default_string_piece(const char* value, size_t size); - inline ::std::string* mutable_default_string_piece(); - inline ::std::string* release_default_string_piece(); - public: - - // optional string default_cord = 85 [default = "123", ctype = CORD]; - inline bool has_default_cord() const; - inline void clear_default_cord(); - static const int kDefaultCordFieldNumber = 85; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& default_cord() const; - inline void set_default_cord(const ::std::string& value); - inline void set_default_cord(const char* value); - inline void set_default_cord(const char* value, size_t size); - inline ::std::string* mutable_default_cord(); - inline ::std::string* release_default_cord(); - public: - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypes) - private: - inline void set_has_optional_int32(); - inline void clear_has_optional_int32(); - inline void set_has_optional_int64(); - inline void clear_has_optional_int64(); - inline void set_has_optional_uint32(); - inline void clear_has_optional_uint32(); - inline void set_has_optional_uint64(); - inline void clear_has_optional_uint64(); - inline void set_has_optional_sint32(); - inline void clear_has_optional_sint32(); - inline void set_has_optional_sint64(); - inline void clear_has_optional_sint64(); - inline void set_has_optional_fixed32(); - inline void clear_has_optional_fixed32(); - inline void set_has_optional_fixed64(); - inline void clear_has_optional_fixed64(); - inline void set_has_optional_sfixed32(); - inline void clear_has_optional_sfixed32(); - inline void set_has_optional_sfixed64(); - inline void clear_has_optional_sfixed64(); - inline void set_has_optional_float(); - inline void clear_has_optional_float(); - inline void set_has_optional_double(); - inline void clear_has_optional_double(); - inline void set_has_optional_bool(); - inline void clear_has_optional_bool(); - inline void set_has_optional_string(); - inline void clear_has_optional_string(); - inline void set_has_optional_bytes(); - inline void clear_has_optional_bytes(); - inline void set_has_optionalgroup(); - inline void clear_has_optionalgroup(); - inline void set_has_optional_nested_message(); - inline void clear_has_optional_nested_message(); - inline void set_has_optional_foreign_message(); - inline void clear_has_optional_foreign_message(); - inline void set_has_optional_import_message(); - inline void clear_has_optional_import_message(); - inline void set_has_optional_nested_enum(); - inline void clear_has_optional_nested_enum(); - inline void set_has_optional_foreign_enum(); - inline void clear_has_optional_foreign_enum(); - inline void set_has_optional_import_enum(); - inline void clear_has_optional_import_enum(); - inline void set_has_optional_string_piece(); - inline void clear_has_optional_string_piece(); - inline void set_has_optional_cord(); - inline void clear_has_optional_cord(); - inline void set_has_default_int32(); - inline void clear_has_default_int32(); - inline void set_has_default_int64(); - inline void clear_has_default_int64(); - inline void set_has_default_uint32(); - inline void clear_has_default_uint32(); - inline void set_has_default_uint64(); - inline void clear_has_default_uint64(); - inline void set_has_default_sint32(); - inline void clear_has_default_sint32(); - inline void set_has_default_sint64(); - inline void clear_has_default_sint64(); - inline void set_has_default_fixed32(); - inline void clear_has_default_fixed32(); - inline void set_has_default_fixed64(); - inline void clear_has_default_fixed64(); - inline void set_has_default_sfixed32(); - inline void clear_has_default_sfixed32(); - inline void set_has_default_sfixed64(); - inline void clear_has_default_sfixed64(); - inline void set_has_default_float(); - inline void clear_has_default_float(); - inline void set_has_default_double(); - inline void clear_has_default_double(); - inline void set_has_default_bool(); - inline void clear_has_default_bool(); - inline void set_has_default_string(); - inline void clear_has_default_string(); - inline void set_has_default_bytes(); - inline void clear_has_default_bytes(); - inline void set_has_default_nested_enum(); - inline void clear_has_default_nested_enum(); - inline void set_has_default_foreign_enum(); - inline void clear_has_default_foreign_enum(); - inline void set_has_default_import_enum(); - inline void clear_has_default_import_enum(); - inline void set_has_default_string_piece(); - inline void clear_has_default_string_piece(); - inline void set_has_default_cord(); - inline void clear_has_default_cord(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 optional_int32_; - ::google::protobuf::uint32 optional_uint32_; - ::google::protobuf::int64 optional_int64_; - ::google::protobuf::uint64 optional_uint64_; - ::google::protobuf::int32 optional_sint32_; - ::google::protobuf::uint32 optional_fixed32_; - ::google::protobuf::int64 optional_sint64_; - ::google::protobuf::uint64 optional_fixed64_; - ::google::protobuf::int32 optional_sfixed32_; - float optional_float_; - ::google::protobuf::int64 optional_sfixed64_; - double optional_double_; - ::std::string* optional_string_; - ::std::string* optional_bytes_; - ::protobuf_unittest::TestAllTypes_OptionalGroup* optionalgroup_; - ::protobuf_unittest::TestAllTypes_NestedMessage* optional_nested_message_; - ::protobuf_unittest::ForeignMessage* optional_foreign_message_; - ::protobuf_unittest_import::ImportMessage* optional_import_message_; - int optional_nested_enum_; - int optional_foreign_enum_; - ::std::string* optional_string_piece_; - ::std::string* optional_cord_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_int32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_int64_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_uint32_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_uint64_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sint32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sint64_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_fixed32_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_fixed64_; - int optional_import_enum_; - bool optional_bool_; - bool default_bool_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sfixed32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sfixed64_; - ::google::protobuf::RepeatedField< float > repeated_float_; - ::google::protobuf::RepeatedField< double > repeated_double_; - ::google::protobuf::RepeatedField< bool > repeated_bool_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_bytes_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup > repeatedgroup_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage > repeated_nested_message_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage > repeated_foreign_message_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage > repeated_import_message_; - ::google::protobuf::RepeatedField repeated_nested_enum_; - ::google::protobuf::RepeatedField repeated_foreign_enum_; - ::google::protobuf::RepeatedField repeated_import_enum_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_piece_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_cord_; - ::google::protobuf::int64 default_int64_; - ::google::protobuf::int32 default_int32_; - ::google::protobuf::uint32 default_uint32_; - ::google::protobuf::uint64 default_uint64_; - ::google::protobuf::int32 default_sint32_; - ::google::protobuf::uint32 default_fixed32_; - ::google::protobuf::int64 default_sint64_; - ::google::protobuf::uint64 default_fixed64_; - ::google::protobuf::int32 default_sfixed32_; - float default_float_; - ::google::protobuf::int64 default_sfixed64_; - double default_double_; - ::std::string* default_string_; - static const ::std::string _default_default_string_; - ::std::string* default_bytes_; - static const ::std::string _default_default_bytes_; - int default_nested_enum_; - int default_foreign_enum_; - ::std::string* default_string_piece_; - static const ::std::string _default_default_string_piece_; - ::std::string* default_cord_; - static const ::std::string _default_default_cord_; - int default_import_enum_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(68 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypes* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestDeprecatedFields : public ::google::protobuf::Message { - public: - TestDeprecatedFields(); - virtual ~TestDeprecatedFields(); - - TestDeprecatedFields(const TestDeprecatedFields& from); - - inline TestDeprecatedFields& operator=(const TestDeprecatedFields& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestDeprecatedFields& default_instance(); - - void Swap(TestDeprecatedFields* other); - - // implements Message ---------------------------------------------- - - TestDeprecatedFields* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestDeprecatedFields& from); - void MergeFrom(const TestDeprecatedFields& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 deprecated_int32 = 1 [deprecated = true]; - inline bool has_deprecated_int32() const PROTOBUF_DEPRECATED; - inline void clear_deprecated_int32() PROTOBUF_DEPRECATED; - static const int kDeprecatedInt32FieldNumber = 1; - inline ::google::protobuf::int32 deprecated_int32() const PROTOBUF_DEPRECATED; - inline void set_deprecated_int32(::google::protobuf::int32 value) PROTOBUF_DEPRECATED; - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDeprecatedFields) - private: - inline void set_has_deprecated_int32(); - inline void clear_has_deprecated_int32(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 deprecated_int32_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestDeprecatedFields* default_instance_; -}; -// ------------------------------------------------------------------- - -class ForeignMessage : public ::google::protobuf::Message { - public: - ForeignMessage(); - virtual ~ForeignMessage(); - - ForeignMessage(const ForeignMessage& from); - - inline ForeignMessage& operator=(const ForeignMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ForeignMessage& default_instance(); - - void Swap(ForeignMessage* other); - - // implements Message ---------------------------------------------- - - ForeignMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ForeignMessage& from); - void MergeFrom(const ForeignMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 c = 1; - inline bool has_c() const; - inline void clear_c(); - static const int kCFieldNumber = 1; - inline ::google::protobuf::int32 c() const; - inline void set_c(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.ForeignMessage) - private: - inline void set_has_c(); - inline void clear_has_c(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 c_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static ForeignMessage* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllExtensions : public ::google::protobuf::Message { - public: - TestAllExtensions(); - virtual ~TestAllExtensions(); - - TestAllExtensions(const TestAllExtensions& from); - - inline TestAllExtensions& operator=(const TestAllExtensions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestAllExtensions& default_instance(); - - void Swap(TestAllExtensions* other); - - // implements Message ---------------------------------------------- - - TestAllExtensions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestAllExtensions& from); - void MergeFrom(const TestAllExtensions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestAllExtensions) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllExtensions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestAllExtensions* default_instance_; -}; -// ------------------------------------------------------------------- - -class OptionalGroup_extension : public ::google::protobuf::Message { - public: - OptionalGroup_extension(); - virtual ~OptionalGroup_extension(); - - OptionalGroup_extension(const OptionalGroup_extension& from); - - inline OptionalGroup_extension& operator=(const OptionalGroup_extension& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const OptionalGroup_extension& default_instance(); - - void Swap(OptionalGroup_extension* other); - - // implements Message ---------------------------------------------- - - OptionalGroup_extension* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const OptionalGroup_extension& from); - void MergeFrom(const OptionalGroup_extension& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 17; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 17; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.OptionalGroup_extension) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static OptionalGroup_extension* default_instance_; -}; -// ------------------------------------------------------------------- - -class RepeatedGroup_extension : public ::google::protobuf::Message { - public: - RepeatedGroup_extension(); - virtual ~RepeatedGroup_extension(); - - RepeatedGroup_extension(const RepeatedGroup_extension& from); - - inline RepeatedGroup_extension& operator=(const RepeatedGroup_extension& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const RepeatedGroup_extension& default_instance(); - - void Swap(RepeatedGroup_extension* other); - - // implements Message ---------------------------------------------- - - RepeatedGroup_extension* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const RepeatedGroup_extension& from); - void MergeFrom(const RepeatedGroup_extension& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 47; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 47; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.RepeatedGroup_extension) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static RepeatedGroup_extension* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestNestedExtension : public ::google::protobuf::Message { - public: - TestNestedExtension(); - virtual ~TestNestedExtension(); - - TestNestedExtension(const TestNestedExtension& from); - - inline TestNestedExtension& operator=(const TestNestedExtension& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestNestedExtension& default_instance(); - - void Swap(TestNestedExtension* other); - - // implements Message ---------------------------------------------- - - TestNestedExtension* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestNestedExtension& from); - void MergeFrom(const TestNestedExtension& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - static const int kTestFieldNumber = 1002; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - test; - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedExtension) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestNestedExtension* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestRequired : public ::google::protobuf::Message { - public: - TestRequired(); - virtual ~TestRequired(); - - TestRequired(const TestRequired& from); - - inline TestRequired& operator=(const TestRequired& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestRequired& default_instance(); - - void Swap(TestRequired* other); - - // implements Message ---------------------------------------------- - - TestRequired* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestRequired& from); - void MergeFrom(const TestRequired& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required int32 a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // optional int32 dummy2 = 2; - inline bool has_dummy2() const; - inline void clear_dummy2(); - static const int kDummy2FieldNumber = 2; - inline ::google::protobuf::int32 dummy2() const; - inline void set_dummy2(::google::protobuf::int32 value); - - // required int32 b = 3; - inline bool has_b() const; - inline void clear_b(); - static const int kBFieldNumber = 3; - inline ::google::protobuf::int32 b() const; - inline void set_b(::google::protobuf::int32 value); - - // optional int32 dummy4 = 4; - inline bool has_dummy4() const; - inline void clear_dummy4(); - static const int kDummy4FieldNumber = 4; - inline ::google::protobuf::int32 dummy4() const; - inline void set_dummy4(::google::protobuf::int32 value); - - // optional int32 dummy5 = 5; - inline bool has_dummy5() const; - inline void clear_dummy5(); - static const int kDummy5FieldNumber = 5; - inline ::google::protobuf::int32 dummy5() const; - inline void set_dummy5(::google::protobuf::int32 value); - - // optional int32 dummy6 = 6; - inline bool has_dummy6() const; - inline void clear_dummy6(); - static const int kDummy6FieldNumber = 6; - inline ::google::protobuf::int32 dummy6() const; - inline void set_dummy6(::google::protobuf::int32 value); - - // optional int32 dummy7 = 7; - inline bool has_dummy7() const; - inline void clear_dummy7(); - static const int kDummy7FieldNumber = 7; - inline ::google::protobuf::int32 dummy7() const; - inline void set_dummy7(::google::protobuf::int32 value); - - // optional int32 dummy8 = 8; - inline bool has_dummy8() const; - inline void clear_dummy8(); - static const int kDummy8FieldNumber = 8; - inline ::google::protobuf::int32 dummy8() const; - inline void set_dummy8(::google::protobuf::int32 value); - - // optional int32 dummy9 = 9; - inline bool has_dummy9() const; - inline void clear_dummy9(); - static const int kDummy9FieldNumber = 9; - inline ::google::protobuf::int32 dummy9() const; - inline void set_dummy9(::google::protobuf::int32 value); - - // optional int32 dummy10 = 10; - inline bool has_dummy10() const; - inline void clear_dummy10(); - static const int kDummy10FieldNumber = 10; - inline ::google::protobuf::int32 dummy10() const; - inline void set_dummy10(::google::protobuf::int32 value); - - // optional int32 dummy11 = 11; - inline bool has_dummy11() const; - inline void clear_dummy11(); - static const int kDummy11FieldNumber = 11; - inline ::google::protobuf::int32 dummy11() const; - inline void set_dummy11(::google::protobuf::int32 value); - - // optional int32 dummy12 = 12; - inline bool has_dummy12() const; - inline void clear_dummy12(); - static const int kDummy12FieldNumber = 12; - inline ::google::protobuf::int32 dummy12() const; - inline void set_dummy12(::google::protobuf::int32 value); - - // optional int32 dummy13 = 13; - inline bool has_dummy13() const; - inline void clear_dummy13(); - static const int kDummy13FieldNumber = 13; - inline ::google::protobuf::int32 dummy13() const; - inline void set_dummy13(::google::protobuf::int32 value); - - // optional int32 dummy14 = 14; - inline bool has_dummy14() const; - inline void clear_dummy14(); - static const int kDummy14FieldNumber = 14; - inline ::google::protobuf::int32 dummy14() const; - inline void set_dummy14(::google::protobuf::int32 value); - - // optional int32 dummy15 = 15; - inline bool has_dummy15() const; - inline void clear_dummy15(); - static const int kDummy15FieldNumber = 15; - inline ::google::protobuf::int32 dummy15() const; - inline void set_dummy15(::google::protobuf::int32 value); - - // optional int32 dummy16 = 16; - inline bool has_dummy16() const; - inline void clear_dummy16(); - static const int kDummy16FieldNumber = 16; - inline ::google::protobuf::int32 dummy16() const; - inline void set_dummy16(::google::protobuf::int32 value); - - // optional int32 dummy17 = 17; - inline bool has_dummy17() const; - inline void clear_dummy17(); - static const int kDummy17FieldNumber = 17; - inline ::google::protobuf::int32 dummy17() const; - inline void set_dummy17(::google::protobuf::int32 value); - - // optional int32 dummy18 = 18; - inline bool has_dummy18() const; - inline void clear_dummy18(); - static const int kDummy18FieldNumber = 18; - inline ::google::protobuf::int32 dummy18() const; - inline void set_dummy18(::google::protobuf::int32 value); - - // optional int32 dummy19 = 19; - inline bool has_dummy19() const; - inline void clear_dummy19(); - static const int kDummy19FieldNumber = 19; - inline ::google::protobuf::int32 dummy19() const; - inline void set_dummy19(::google::protobuf::int32 value); - - // optional int32 dummy20 = 20; - inline bool has_dummy20() const; - inline void clear_dummy20(); - static const int kDummy20FieldNumber = 20; - inline ::google::protobuf::int32 dummy20() const; - inline void set_dummy20(::google::protobuf::int32 value); - - // optional int32 dummy21 = 21; - inline bool has_dummy21() const; - inline void clear_dummy21(); - static const int kDummy21FieldNumber = 21; - inline ::google::protobuf::int32 dummy21() const; - inline void set_dummy21(::google::protobuf::int32 value); - - // optional int32 dummy22 = 22; - inline bool has_dummy22() const; - inline void clear_dummy22(); - static const int kDummy22FieldNumber = 22; - inline ::google::protobuf::int32 dummy22() const; - inline void set_dummy22(::google::protobuf::int32 value); - - // optional int32 dummy23 = 23; - inline bool has_dummy23() const; - inline void clear_dummy23(); - static const int kDummy23FieldNumber = 23; - inline ::google::protobuf::int32 dummy23() const; - inline void set_dummy23(::google::protobuf::int32 value); - - // optional int32 dummy24 = 24; - inline bool has_dummy24() const; - inline void clear_dummy24(); - static const int kDummy24FieldNumber = 24; - inline ::google::protobuf::int32 dummy24() const; - inline void set_dummy24(::google::protobuf::int32 value); - - // optional int32 dummy25 = 25; - inline bool has_dummy25() const; - inline void clear_dummy25(); - static const int kDummy25FieldNumber = 25; - inline ::google::protobuf::int32 dummy25() const; - inline void set_dummy25(::google::protobuf::int32 value); - - // optional int32 dummy26 = 26; - inline bool has_dummy26() const; - inline void clear_dummy26(); - static const int kDummy26FieldNumber = 26; - inline ::google::protobuf::int32 dummy26() const; - inline void set_dummy26(::google::protobuf::int32 value); - - // optional int32 dummy27 = 27; - inline bool has_dummy27() const; - inline void clear_dummy27(); - static const int kDummy27FieldNumber = 27; - inline ::google::protobuf::int32 dummy27() const; - inline void set_dummy27(::google::protobuf::int32 value); - - // optional int32 dummy28 = 28; - inline bool has_dummy28() const; - inline void clear_dummy28(); - static const int kDummy28FieldNumber = 28; - inline ::google::protobuf::int32 dummy28() const; - inline void set_dummy28(::google::protobuf::int32 value); - - // optional int32 dummy29 = 29; - inline bool has_dummy29() const; - inline void clear_dummy29(); - static const int kDummy29FieldNumber = 29; - inline ::google::protobuf::int32 dummy29() const; - inline void set_dummy29(::google::protobuf::int32 value); - - // optional int32 dummy30 = 30; - inline bool has_dummy30() const; - inline void clear_dummy30(); - static const int kDummy30FieldNumber = 30; - inline ::google::protobuf::int32 dummy30() const; - inline void set_dummy30(::google::protobuf::int32 value); - - // optional int32 dummy31 = 31; - inline bool has_dummy31() const; - inline void clear_dummy31(); - static const int kDummy31FieldNumber = 31; - inline ::google::protobuf::int32 dummy31() const; - inline void set_dummy31(::google::protobuf::int32 value); - - // optional int32 dummy32 = 32; - inline bool has_dummy32() const; - inline void clear_dummy32(); - static const int kDummy32FieldNumber = 32; - inline ::google::protobuf::int32 dummy32() const; - inline void set_dummy32(::google::protobuf::int32 value); - - // required int32 c = 33; - inline bool has_c() const; - inline void clear_c(); - static const int kCFieldNumber = 33; - inline ::google::protobuf::int32 c() const; - inline void set_c(::google::protobuf::int32 value); - - static const int kSingleFieldNumber = 1000; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestRequired >, 11, false > - single; - static const int kMultiFieldNumber = 1001; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::TestRequired >, 11, false > - multi; - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRequired) - private: - inline void set_has_a(); - inline void clear_has_a(); - inline void set_has_dummy2(); - inline void clear_has_dummy2(); - inline void set_has_b(); - inline void clear_has_b(); - inline void set_has_dummy4(); - inline void clear_has_dummy4(); - inline void set_has_dummy5(); - inline void clear_has_dummy5(); - inline void set_has_dummy6(); - inline void clear_has_dummy6(); - inline void set_has_dummy7(); - inline void clear_has_dummy7(); - inline void set_has_dummy8(); - inline void clear_has_dummy8(); - inline void set_has_dummy9(); - inline void clear_has_dummy9(); - inline void set_has_dummy10(); - inline void clear_has_dummy10(); - inline void set_has_dummy11(); - inline void clear_has_dummy11(); - inline void set_has_dummy12(); - inline void clear_has_dummy12(); - inline void set_has_dummy13(); - inline void clear_has_dummy13(); - inline void set_has_dummy14(); - inline void clear_has_dummy14(); - inline void set_has_dummy15(); - inline void clear_has_dummy15(); - inline void set_has_dummy16(); - inline void clear_has_dummy16(); - inline void set_has_dummy17(); - inline void clear_has_dummy17(); - inline void set_has_dummy18(); - inline void clear_has_dummy18(); - inline void set_has_dummy19(); - inline void clear_has_dummy19(); - inline void set_has_dummy20(); - inline void clear_has_dummy20(); - inline void set_has_dummy21(); - inline void clear_has_dummy21(); - inline void set_has_dummy22(); - inline void clear_has_dummy22(); - inline void set_has_dummy23(); - inline void clear_has_dummy23(); - inline void set_has_dummy24(); - inline void clear_has_dummy24(); - inline void set_has_dummy25(); - inline void clear_has_dummy25(); - inline void set_has_dummy26(); - inline void clear_has_dummy26(); - inline void set_has_dummy27(); - inline void clear_has_dummy27(); - inline void set_has_dummy28(); - inline void clear_has_dummy28(); - inline void set_has_dummy29(); - inline void clear_has_dummy29(); - inline void set_has_dummy30(); - inline void clear_has_dummy30(); - inline void set_has_dummy31(); - inline void clear_has_dummy31(); - inline void set_has_dummy32(); - inline void clear_has_dummy32(); - inline void set_has_c(); - inline void clear_has_c(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - ::google::protobuf::int32 dummy2_; - ::google::protobuf::int32 b_; - ::google::protobuf::int32 dummy4_; - ::google::protobuf::int32 dummy5_; - ::google::protobuf::int32 dummy6_; - ::google::protobuf::int32 dummy7_; - ::google::protobuf::int32 dummy8_; - ::google::protobuf::int32 dummy9_; - ::google::protobuf::int32 dummy10_; - ::google::protobuf::int32 dummy11_; - ::google::protobuf::int32 dummy12_; - ::google::protobuf::int32 dummy13_; - ::google::protobuf::int32 dummy14_; - ::google::protobuf::int32 dummy15_; - ::google::protobuf::int32 dummy16_; - ::google::protobuf::int32 dummy17_; - ::google::protobuf::int32 dummy18_; - ::google::protobuf::int32 dummy19_; - ::google::protobuf::int32 dummy20_; - ::google::protobuf::int32 dummy21_; - ::google::protobuf::int32 dummy22_; - ::google::protobuf::int32 dummy23_; - ::google::protobuf::int32 dummy24_; - ::google::protobuf::int32 dummy25_; - ::google::protobuf::int32 dummy26_; - ::google::protobuf::int32 dummy27_; - ::google::protobuf::int32 dummy28_; - ::google::protobuf::int32 dummy29_; - ::google::protobuf::int32 dummy30_; - ::google::protobuf::int32 dummy31_; - ::google::protobuf::int32 dummy32_; - ::google::protobuf::int32 c_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(33 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestRequired* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestRequiredForeign : public ::google::protobuf::Message { - public: - TestRequiredForeign(); - virtual ~TestRequiredForeign(); - - TestRequiredForeign(const TestRequiredForeign& from); - - inline TestRequiredForeign& operator=(const TestRequiredForeign& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestRequiredForeign& default_instance(); - - void Swap(TestRequiredForeign* other); - - // implements Message ---------------------------------------------- - - TestRequiredForeign* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestRequiredForeign& from); - void MergeFrom(const TestRequiredForeign& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestRequired optional_message = 1; - inline bool has_optional_message() const; - inline void clear_optional_message(); - static const int kOptionalMessageFieldNumber = 1; - inline const ::protobuf_unittest::TestRequired& optional_message() const; - inline ::protobuf_unittest::TestRequired* mutable_optional_message(); - inline ::protobuf_unittest::TestRequired* release_optional_message(); - - // repeated .protobuf_unittest.TestRequired repeated_message = 2; - inline int repeated_message_size() const; - inline void clear_repeated_message(); - static const int kRepeatedMessageFieldNumber = 2; - inline const ::protobuf_unittest::TestRequired& repeated_message(int index) const; - inline ::protobuf_unittest::TestRequired* mutable_repeated_message(int index); - inline ::protobuf_unittest::TestRequired* add_repeated_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >& - repeated_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >* - mutable_repeated_message(); - - // optional int32 dummy = 3; - inline bool has_dummy() const; - inline void clear_dummy(); - static const int kDummyFieldNumber = 3; - inline ::google::protobuf::int32 dummy() const; - inline void set_dummy(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRequiredForeign) - private: - inline void set_has_optional_message(); - inline void clear_has_optional_message(); - inline void set_has_dummy(); - inline void clear_has_dummy(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestRequired* optional_message_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired > repeated_message_; - ::google::protobuf::int32 dummy_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestRequiredForeign* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestForeignNested : public ::google::protobuf::Message { - public: - TestForeignNested(); - virtual ~TestForeignNested(); - - TestForeignNested(const TestForeignNested& from); - - inline TestForeignNested& operator=(const TestForeignNested& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestForeignNested& default_instance(); - - void Swap(TestForeignNested* other); - - // implements Message ---------------------------------------------- - - TestForeignNested* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestForeignNested& from); - void MergeFrom(const TestForeignNested& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestAllTypes.NestedMessage foreign_nested = 1; - inline bool has_foreign_nested() const; - inline void clear_foreign_nested(); - static const int kForeignNestedFieldNumber = 1; - inline const ::protobuf_unittest::TestAllTypes_NestedMessage& foreign_nested() const; - inline ::protobuf_unittest::TestAllTypes_NestedMessage* mutable_foreign_nested(); - inline ::protobuf_unittest::TestAllTypes_NestedMessage* release_foreign_nested(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestForeignNested) - private: - inline void set_has_foreign_nested(); - inline void clear_has_foreign_nested(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestAllTypes_NestedMessage* foreign_nested_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestForeignNested* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestEmptyMessage : public ::google::protobuf::Message { - public: - TestEmptyMessage(); - virtual ~TestEmptyMessage(); - - TestEmptyMessage(const TestEmptyMessage& from); - - inline TestEmptyMessage& operator=(const TestEmptyMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestEmptyMessage& default_instance(); - - void Swap(TestEmptyMessage* other); - - // implements Message ---------------------------------------------- - - TestEmptyMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestEmptyMessage& from); - void MergeFrom(const TestEmptyMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestEmptyMessage) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestEmptyMessage* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestEmptyMessageWithExtensions : public ::google::protobuf::Message { - public: - TestEmptyMessageWithExtensions(); - virtual ~TestEmptyMessageWithExtensions(); - - TestEmptyMessageWithExtensions(const TestEmptyMessageWithExtensions& from); - - inline TestEmptyMessageWithExtensions& operator=(const TestEmptyMessageWithExtensions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestEmptyMessageWithExtensions& default_instance(); - - void Swap(TestEmptyMessageWithExtensions* other); - - // implements Message ---------------------------------------------- - - TestEmptyMessageWithExtensions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestEmptyMessageWithExtensions& from); - void MergeFrom(const TestEmptyMessageWithExtensions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestEmptyMessageWithExtensions) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestEmptyMessageWithExtensions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestEmptyMessageWithExtensions* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestMultipleExtensionRanges : public ::google::protobuf::Message { - public: - TestMultipleExtensionRanges(); - virtual ~TestMultipleExtensionRanges(); - - TestMultipleExtensionRanges(const TestMultipleExtensionRanges& from); - - inline TestMultipleExtensionRanges& operator=(const TestMultipleExtensionRanges& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMultipleExtensionRanges& default_instance(); - - void Swap(TestMultipleExtensionRanges* other); - - // implements Message ---------------------------------------------- - - TestMultipleExtensionRanges* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMultipleExtensionRanges& from); - void MergeFrom(const TestMultipleExtensionRanges& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestMultipleExtensionRanges) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMultipleExtensionRanges) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestMultipleExtensionRanges* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestReallyLargeTagNumber : public ::google::protobuf::Message { - public: - TestReallyLargeTagNumber(); - virtual ~TestReallyLargeTagNumber(); - - TestReallyLargeTagNumber(const TestReallyLargeTagNumber& from); - - inline TestReallyLargeTagNumber& operator=(const TestReallyLargeTagNumber& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestReallyLargeTagNumber& default_instance(); - - void Swap(TestReallyLargeTagNumber* other); - - // implements Message ---------------------------------------------- - - TestReallyLargeTagNumber* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestReallyLargeTagNumber& from); - void MergeFrom(const TestReallyLargeTagNumber& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // optional int32 bb = 268435455; - inline bool has_bb() const; - inline void clear_bb(); - static const int kBbFieldNumber = 268435455; - inline ::google::protobuf::int32 bb() const; - inline void set_bb(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestReallyLargeTagNumber) - private: - inline void set_has_a(); - inline void clear_has_a(); - inline void set_has_bb(); - inline void clear_has_bb(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - ::google::protobuf::int32 bb_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestReallyLargeTagNumber* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestRecursiveMessage : public ::google::protobuf::Message { - public: - TestRecursiveMessage(); - virtual ~TestRecursiveMessage(); - - TestRecursiveMessage(const TestRecursiveMessage& from); - - inline TestRecursiveMessage& operator=(const TestRecursiveMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestRecursiveMessage& default_instance(); - - void Swap(TestRecursiveMessage* other); - - // implements Message ---------------------------------------------- - - TestRecursiveMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestRecursiveMessage& from); - void MergeFrom(const TestRecursiveMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestRecursiveMessage a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline const ::protobuf_unittest::TestRecursiveMessage& a() const; - inline ::protobuf_unittest::TestRecursiveMessage* mutable_a(); - inline ::protobuf_unittest::TestRecursiveMessage* release_a(); - - // optional int32 i = 2; - inline bool has_i() const; - inline void clear_i(); - static const int kIFieldNumber = 2; - inline ::google::protobuf::int32 i() const; - inline void set_i(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRecursiveMessage) - private: - inline void set_has_a(); - inline void clear_has_a(); - inline void set_has_i(); - inline void clear_has_i(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestRecursiveMessage* a_; - ::google::protobuf::int32 i_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestRecursiveMessage* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestMutualRecursionA : public ::google::protobuf::Message { - public: - TestMutualRecursionA(); - virtual ~TestMutualRecursionA(); - - TestMutualRecursionA(const TestMutualRecursionA& from); - - inline TestMutualRecursionA& operator=(const TestMutualRecursionA& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMutualRecursionA& default_instance(); - - void Swap(TestMutualRecursionA* other); - - // implements Message ---------------------------------------------- - - TestMutualRecursionA* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMutualRecursionA& from); - void MergeFrom(const TestMutualRecursionA& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestMutualRecursionB bb = 1; - inline bool has_bb() const; - inline void clear_bb(); - static const int kBbFieldNumber = 1; - inline const ::protobuf_unittest::TestMutualRecursionB& bb() const; - inline ::protobuf_unittest::TestMutualRecursionB* mutable_bb(); - inline ::protobuf_unittest::TestMutualRecursionB* release_bb(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMutualRecursionA) - private: - inline void set_has_bb(); - inline void clear_has_bb(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestMutualRecursionB* bb_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestMutualRecursionA* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestMutualRecursionB : public ::google::protobuf::Message { - public: - TestMutualRecursionB(); - virtual ~TestMutualRecursionB(); - - TestMutualRecursionB(const TestMutualRecursionB& from); - - inline TestMutualRecursionB& operator=(const TestMutualRecursionB& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMutualRecursionB& default_instance(); - - void Swap(TestMutualRecursionB* other); - - // implements Message ---------------------------------------------- - - TestMutualRecursionB* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMutualRecursionB& from); - void MergeFrom(const TestMutualRecursionB& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestMutualRecursionA a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline const ::protobuf_unittest::TestMutualRecursionA& a() const; - inline ::protobuf_unittest::TestMutualRecursionA* mutable_a(); - inline ::protobuf_unittest::TestMutualRecursionA* release_a(); - - // optional int32 optional_int32 = 2; - inline bool has_optional_int32() const; - inline void clear_optional_int32(); - static const int kOptionalInt32FieldNumber = 2; - inline ::google::protobuf::int32 optional_int32() const; - inline void set_optional_int32(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMutualRecursionB) - private: - inline void set_has_a(); - inline void clear_has_a(); - inline void set_has_optional_int32(); - inline void clear_has_optional_int32(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestMutualRecursionA* a_; - ::google::protobuf::int32 optional_int32_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestMutualRecursionB* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestDupFieldNumber_Foo : public ::google::protobuf::Message { - public: - TestDupFieldNumber_Foo(); - virtual ~TestDupFieldNumber_Foo(); - - TestDupFieldNumber_Foo(const TestDupFieldNumber_Foo& from); - - inline TestDupFieldNumber_Foo& operator=(const TestDupFieldNumber_Foo& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestDupFieldNumber_Foo& default_instance(); - - void Swap(TestDupFieldNumber_Foo* other); - - // implements Message ---------------------------------------------- - - TestDupFieldNumber_Foo* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestDupFieldNumber_Foo& from); - void MergeFrom(const TestDupFieldNumber_Foo& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDupFieldNumber.Foo) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestDupFieldNumber_Foo* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestDupFieldNumber_Bar : public ::google::protobuf::Message { - public: - TestDupFieldNumber_Bar(); - virtual ~TestDupFieldNumber_Bar(); - - TestDupFieldNumber_Bar(const TestDupFieldNumber_Bar& from); - - inline TestDupFieldNumber_Bar& operator=(const TestDupFieldNumber_Bar& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestDupFieldNumber_Bar& default_instance(); - - void Swap(TestDupFieldNumber_Bar* other); - - // implements Message ---------------------------------------------- - - TestDupFieldNumber_Bar* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestDupFieldNumber_Bar& from); - void MergeFrom(const TestDupFieldNumber_Bar& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDupFieldNumber.Bar) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestDupFieldNumber_Bar* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestDupFieldNumber : public ::google::protobuf::Message { - public: - TestDupFieldNumber(); - virtual ~TestDupFieldNumber(); - - TestDupFieldNumber(const TestDupFieldNumber& from); - - inline TestDupFieldNumber& operator=(const TestDupFieldNumber& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestDupFieldNumber& default_instance(); - - void Swap(TestDupFieldNumber* other); - - // implements Message ---------------------------------------------- - - TestDupFieldNumber* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestDupFieldNumber& from); - void MergeFrom(const TestDupFieldNumber& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef TestDupFieldNumber_Foo Foo; - typedef TestDupFieldNumber_Bar Bar; - - // accessors ------------------------------------------------------- - - // optional int32 a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // optional group Foo = 2 { - inline bool has_foo() const; - inline void clear_foo(); - static const int kFooFieldNumber = 2; - inline const ::protobuf_unittest::TestDupFieldNumber_Foo& foo() const; - inline ::protobuf_unittest::TestDupFieldNumber_Foo* mutable_foo(); - inline ::protobuf_unittest::TestDupFieldNumber_Foo* release_foo(); - - // optional group Bar = 3 { - inline bool has_bar() const; - inline void clear_bar(); - static const int kBarFieldNumber = 3; - inline const ::protobuf_unittest::TestDupFieldNumber_Bar& bar() const; - inline ::protobuf_unittest::TestDupFieldNumber_Bar* mutable_bar(); - inline ::protobuf_unittest::TestDupFieldNumber_Bar* release_bar(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDupFieldNumber) - private: - inline void set_has_a(); - inline void clear_has_a(); - inline void set_has_foo(); - inline void clear_has_foo(); - inline void set_has_bar(); - inline void clear_has_bar(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestDupFieldNumber_Foo* foo_; - ::protobuf_unittest::TestDupFieldNumber_Bar* bar_; - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestDupFieldNumber* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestNestedMessageHasBits_NestedMessage : public ::google::protobuf::Message { - public: - TestNestedMessageHasBits_NestedMessage(); - virtual ~TestNestedMessageHasBits_NestedMessage(); - - TestNestedMessageHasBits_NestedMessage(const TestNestedMessageHasBits_NestedMessage& from); - - inline TestNestedMessageHasBits_NestedMessage& operator=(const TestNestedMessageHasBits_NestedMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestNestedMessageHasBits_NestedMessage& default_instance(); - - void Swap(TestNestedMessageHasBits_NestedMessage* other); - - // implements Message ---------------------------------------------- - - TestNestedMessageHasBits_NestedMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestNestedMessageHasBits_NestedMessage& from); - void MergeFrom(const TestNestedMessageHasBits_NestedMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 nestedmessage_repeated_int32 = 1; - inline int nestedmessage_repeated_int32_size() const; - inline void clear_nestedmessage_repeated_int32(); - static const int kNestedmessageRepeatedInt32FieldNumber = 1; - inline ::google::protobuf::int32 nestedmessage_repeated_int32(int index) const; - inline void set_nestedmessage_repeated_int32(int index, ::google::protobuf::int32 value); - inline void add_nestedmessage_repeated_int32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - nestedmessage_repeated_int32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_nestedmessage_repeated_int32(); - - // repeated .protobuf_unittest.ForeignMessage nestedmessage_repeated_foreignmessage = 2; - inline int nestedmessage_repeated_foreignmessage_size() const; - inline void clear_nestedmessage_repeated_foreignmessage(); - static const int kNestedmessageRepeatedForeignmessageFieldNumber = 2; - inline const ::protobuf_unittest::ForeignMessage& nestedmessage_repeated_foreignmessage(int index) const; - inline ::protobuf_unittest::ForeignMessage* mutable_nestedmessage_repeated_foreignmessage(int index); - inline ::protobuf_unittest::ForeignMessage* add_nestedmessage_repeated_foreignmessage(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& - nestedmessage_repeated_foreignmessage() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* - mutable_nestedmessage_repeated_foreignmessage(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedMessageHasBits.NestedMessage) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > nestedmessage_repeated_int32_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage > nestedmessage_repeated_foreignmessage_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestNestedMessageHasBits_NestedMessage* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestNestedMessageHasBits : public ::google::protobuf::Message { - public: - TestNestedMessageHasBits(); - virtual ~TestNestedMessageHasBits(); - - TestNestedMessageHasBits(const TestNestedMessageHasBits& from); - - inline TestNestedMessageHasBits& operator=(const TestNestedMessageHasBits& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestNestedMessageHasBits& default_instance(); - - void Swap(TestNestedMessageHasBits* other); - - // implements Message ---------------------------------------------- - - TestNestedMessageHasBits* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestNestedMessageHasBits& from); - void MergeFrom(const TestNestedMessageHasBits& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef TestNestedMessageHasBits_NestedMessage NestedMessage; - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestNestedMessageHasBits.NestedMessage optional_nested_message = 1; - inline bool has_optional_nested_message() const; - inline void clear_optional_nested_message(); - static const int kOptionalNestedMessageFieldNumber = 1; - inline const ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage& optional_nested_message() const; - inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* mutable_optional_nested_message(); - inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* release_optional_nested_message(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedMessageHasBits) - private: - inline void set_has_optional_nested_message(); - inline void clear_has_optional_nested_message(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* optional_nested_message_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestNestedMessageHasBits* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestCamelCaseFieldNames : public ::google::protobuf::Message { - public: - TestCamelCaseFieldNames(); - virtual ~TestCamelCaseFieldNames(); - - TestCamelCaseFieldNames(const TestCamelCaseFieldNames& from); - - inline TestCamelCaseFieldNames& operator=(const TestCamelCaseFieldNames& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestCamelCaseFieldNames& default_instance(); - - void Swap(TestCamelCaseFieldNames* other); - - // implements Message ---------------------------------------------- - - TestCamelCaseFieldNames* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestCamelCaseFieldNames& from); - void MergeFrom(const TestCamelCaseFieldNames& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 PrimitiveField = 1; - inline bool has_primitivefield() const; - inline void clear_primitivefield(); - static const int kPrimitiveFieldFieldNumber = 1; - inline ::google::protobuf::int32 primitivefield() const; - inline void set_primitivefield(::google::protobuf::int32 value); - - // optional string StringField = 2; - inline bool has_stringfield() const; - inline void clear_stringfield(); - static const int kStringFieldFieldNumber = 2; - inline const ::std::string& stringfield() const; - inline void set_stringfield(const ::std::string& value); - inline void set_stringfield(const char* value); - inline void set_stringfield(const char* value, size_t size); - inline ::std::string* mutable_stringfield(); - inline ::std::string* release_stringfield(); - - // optional .protobuf_unittest.ForeignEnum EnumField = 3; - inline bool has_enumfield() const; - inline void clear_enumfield(); - static const int kEnumFieldFieldNumber = 3; - inline protobuf_unittest::ForeignEnum enumfield() const; - inline void set_enumfield(protobuf_unittest::ForeignEnum value); - - // optional .protobuf_unittest.ForeignMessage MessageField = 4; - inline bool has_messagefield() const; - inline void clear_messagefield(); - static const int kMessageFieldFieldNumber = 4; - inline const ::protobuf_unittest::ForeignMessage& messagefield() const; - inline ::protobuf_unittest::ForeignMessage* mutable_messagefield(); - inline ::protobuf_unittest::ForeignMessage* release_messagefield(); - - // optional string StringPieceField = 5 [ctype = STRING_PIECE]; - inline bool has_stringpiecefield() const; - inline void clear_stringpiecefield(); - static const int kStringPieceFieldFieldNumber = 5; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& stringpiecefield() const; - inline void set_stringpiecefield(const ::std::string& value); - inline void set_stringpiecefield(const char* value); - inline void set_stringpiecefield(const char* value, size_t size); - inline ::std::string* mutable_stringpiecefield(); - inline ::std::string* release_stringpiecefield(); - public: - - // optional string CordField = 6 [ctype = CORD]; - inline bool has_cordfield() const; - inline void clear_cordfield(); - static const int kCordFieldFieldNumber = 6; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& cordfield() const; - inline void set_cordfield(const ::std::string& value); - inline void set_cordfield(const char* value); - inline void set_cordfield(const char* value, size_t size); - inline ::std::string* mutable_cordfield(); - inline ::std::string* release_cordfield(); - public: - - // repeated int32 RepeatedPrimitiveField = 7; - inline int repeatedprimitivefield_size() const; - inline void clear_repeatedprimitivefield(); - static const int kRepeatedPrimitiveFieldFieldNumber = 7; - inline ::google::protobuf::int32 repeatedprimitivefield(int index) const; - inline void set_repeatedprimitivefield(int index, ::google::protobuf::int32 value); - inline void add_repeatedprimitivefield(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeatedprimitivefield() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeatedprimitivefield(); - - // repeated string RepeatedStringField = 8; - inline int repeatedstringfield_size() const; - inline void clear_repeatedstringfield(); - static const int kRepeatedStringFieldFieldNumber = 8; - inline const ::std::string& repeatedstringfield(int index) const; - inline ::std::string* mutable_repeatedstringfield(int index); - inline void set_repeatedstringfield(int index, const ::std::string& value); - inline void set_repeatedstringfield(int index, const char* value); - inline void set_repeatedstringfield(int index, const char* value, size_t size); - inline ::std::string* add_repeatedstringfield(); - inline void add_repeatedstringfield(const ::std::string& value); - inline void add_repeatedstringfield(const char* value); - inline void add_repeatedstringfield(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeatedstringfield() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeatedstringfield(); - - // repeated .protobuf_unittest.ForeignEnum RepeatedEnumField = 9; - inline int repeatedenumfield_size() const; - inline void clear_repeatedenumfield(); - static const int kRepeatedEnumFieldFieldNumber = 9; - inline protobuf_unittest::ForeignEnum repeatedenumfield(int index) const; - inline void set_repeatedenumfield(int index, protobuf_unittest::ForeignEnum value); - inline void add_repeatedenumfield(protobuf_unittest::ForeignEnum value); - inline const ::google::protobuf::RepeatedField& repeatedenumfield() const; - inline ::google::protobuf::RepeatedField* mutable_repeatedenumfield(); - - // repeated .protobuf_unittest.ForeignMessage RepeatedMessageField = 10; - inline int repeatedmessagefield_size() const; - inline void clear_repeatedmessagefield(); - static const int kRepeatedMessageFieldFieldNumber = 10; - inline const ::protobuf_unittest::ForeignMessage& repeatedmessagefield(int index) const; - inline ::protobuf_unittest::ForeignMessage* mutable_repeatedmessagefield(int index); - inline ::protobuf_unittest::ForeignMessage* add_repeatedmessagefield(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& - repeatedmessagefield() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* - mutable_repeatedmessagefield(); - - // repeated string RepeatedStringPieceField = 11 [ctype = STRING_PIECE]; - inline int repeatedstringpiecefield_size() const; - inline void clear_repeatedstringpiecefield(); - static const int kRepeatedStringPieceFieldFieldNumber = 11; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& repeatedstringpiecefield(int index) const; - inline ::std::string* mutable_repeatedstringpiecefield(int index); - inline void set_repeatedstringpiecefield(int index, const ::std::string& value); - inline void set_repeatedstringpiecefield(int index, const char* value); - inline void set_repeatedstringpiecefield(int index, const char* value, size_t size); - inline ::std::string* add_repeatedstringpiecefield(); - inline void add_repeatedstringpiecefield(const ::std::string& value); - inline void add_repeatedstringpiecefield(const char* value); - inline void add_repeatedstringpiecefield(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeatedstringpiecefield() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeatedstringpiecefield(); - public: - - // repeated string RepeatedCordField = 12 [ctype = CORD]; - inline int repeatedcordfield_size() const; - inline void clear_repeatedcordfield(); - static const int kRepeatedCordFieldFieldNumber = 12; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& repeatedcordfield(int index) const; - inline ::std::string* mutable_repeatedcordfield(int index); - inline void set_repeatedcordfield(int index, const ::std::string& value); - inline void set_repeatedcordfield(int index, const char* value); - inline void set_repeatedcordfield(int index, const char* value, size_t size); - inline ::std::string* add_repeatedcordfield(); - inline void add_repeatedcordfield(const ::std::string& value); - inline void add_repeatedcordfield(const char* value); - inline void add_repeatedcordfield(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeatedcordfield() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeatedcordfield(); - public: - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestCamelCaseFieldNames) - private: - inline void set_has_primitivefield(); - inline void clear_has_primitivefield(); - inline void set_has_stringfield(); - inline void clear_has_stringfield(); - inline void set_has_enumfield(); - inline void clear_has_enumfield(); - inline void set_has_messagefield(); - inline void clear_has_messagefield(); - inline void set_has_stringpiecefield(); - inline void clear_has_stringpiecefield(); - inline void set_has_cordfield(); - inline void clear_has_cordfield(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* stringfield_; - ::google::protobuf::int32 primitivefield_; - int enumfield_; - ::protobuf_unittest::ForeignMessage* messagefield_; - ::std::string* stringpiecefield_; - ::std::string* cordfield_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeatedprimitivefield_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeatedstringfield_; - ::google::protobuf::RepeatedField repeatedenumfield_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage > repeatedmessagefield_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeatedstringpiecefield_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeatedcordfield_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(12 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestCamelCaseFieldNames* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestFieldOrderings : public ::google::protobuf::Message { - public: - TestFieldOrderings(); - virtual ~TestFieldOrderings(); - - TestFieldOrderings(const TestFieldOrderings& from); - - inline TestFieldOrderings& operator=(const TestFieldOrderings& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestFieldOrderings& default_instance(); - - void Swap(TestFieldOrderings* other); - - // implements Message ---------------------------------------------- - - TestFieldOrderings* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestFieldOrderings& from); - void MergeFrom(const TestFieldOrderings& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string my_string = 11; - inline bool has_my_string() const; - inline void clear_my_string(); - static const int kMyStringFieldNumber = 11; - inline const ::std::string& my_string() const; - inline void set_my_string(const ::std::string& value); - inline void set_my_string(const char* value); - inline void set_my_string(const char* value, size_t size); - inline ::std::string* mutable_my_string(); - inline ::std::string* release_my_string(); - - // optional int64 my_int = 1; - inline bool has_my_int() const; - inline void clear_my_int(); - static const int kMyIntFieldNumber = 1; - inline ::google::protobuf::int64 my_int() const; - inline void set_my_int(::google::protobuf::int64 value); - - // optional float my_float = 101; - inline bool has_my_float() const; - inline void clear_my_float(); - static const int kMyFloatFieldNumber = 101; - inline float my_float() const; - inline void set_my_float(float value); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestFieldOrderings) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestFieldOrderings) - private: - inline void set_has_my_string(); - inline void clear_has_my_string(); - inline void set_has_my_int(); - inline void clear_has_my_int(); - inline void set_has_my_float(); - inline void clear_has_my_float(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* my_string_; - ::google::protobuf::int64 my_int_; - float my_float_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestFieldOrderings* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestExtremeDefaultValues : public ::google::protobuf::Message { - public: - TestExtremeDefaultValues(); - virtual ~TestExtremeDefaultValues(); - - TestExtremeDefaultValues(const TestExtremeDefaultValues& from); - - inline TestExtremeDefaultValues& operator=(const TestExtremeDefaultValues& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestExtremeDefaultValues& default_instance(); - - void Swap(TestExtremeDefaultValues* other); - - // implements Message ---------------------------------------------- - - TestExtremeDefaultValues* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestExtremeDefaultValues& from); - void MergeFrom(const TestExtremeDefaultValues& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bytes escaped_bytes = 1 [default = "\000\001\007\010\014\n\r\t\013\\\'\"\376"]; - inline bool has_escaped_bytes() const; - inline void clear_escaped_bytes(); - static const int kEscapedBytesFieldNumber = 1; - inline const ::std::string& escaped_bytes() const; - inline void set_escaped_bytes(const ::std::string& value); - inline void set_escaped_bytes(const char* value); - inline void set_escaped_bytes(const void* value, size_t size); - inline ::std::string* mutable_escaped_bytes(); - inline ::std::string* release_escaped_bytes(); - - // optional uint32 large_uint32 = 2 [default = 4294967295]; - inline bool has_large_uint32() const; - inline void clear_large_uint32(); - static const int kLargeUint32FieldNumber = 2; - inline ::google::protobuf::uint32 large_uint32() const; - inline void set_large_uint32(::google::protobuf::uint32 value); - - // optional uint64 large_uint64 = 3 [default = 18446744073709551615]; - inline bool has_large_uint64() const; - inline void clear_large_uint64(); - static const int kLargeUint64FieldNumber = 3; - inline ::google::protobuf::uint64 large_uint64() const; - inline void set_large_uint64(::google::protobuf::uint64 value); - - // optional int32 small_int32 = 4 [default = -2147483647]; - inline bool has_small_int32() const; - inline void clear_small_int32(); - static const int kSmallInt32FieldNumber = 4; - inline ::google::protobuf::int32 small_int32() const; - inline void set_small_int32(::google::protobuf::int32 value); - - // optional int64 small_int64 = 5 [default = -9223372036854775807]; - inline bool has_small_int64() const; - inline void clear_small_int64(); - static const int kSmallInt64FieldNumber = 5; - inline ::google::protobuf::int64 small_int64() const; - inline void set_small_int64(::google::protobuf::int64 value); - - // optional string utf8_string = 6 [default = "\341\210\264"]; - inline bool has_utf8_string() const; - inline void clear_utf8_string(); - static const int kUtf8StringFieldNumber = 6; - inline const ::std::string& utf8_string() const; - inline void set_utf8_string(const ::std::string& value); - inline void set_utf8_string(const char* value); - inline void set_utf8_string(const char* value, size_t size); - inline ::std::string* mutable_utf8_string(); - inline ::std::string* release_utf8_string(); - - // optional float zero_float = 7 [default = 0]; - inline bool has_zero_float() const; - inline void clear_zero_float(); - static const int kZeroFloatFieldNumber = 7; - inline float zero_float() const; - inline void set_zero_float(float value); - - // optional float one_float = 8 [default = 1]; - inline bool has_one_float() const; - inline void clear_one_float(); - static const int kOneFloatFieldNumber = 8; - inline float one_float() const; - inline void set_one_float(float value); - - // optional float small_float = 9 [default = 1.5]; - inline bool has_small_float() const; - inline void clear_small_float(); - static const int kSmallFloatFieldNumber = 9; - inline float small_float() const; - inline void set_small_float(float value); - - // optional float negative_one_float = 10 [default = -1]; - inline bool has_negative_one_float() const; - inline void clear_negative_one_float(); - static const int kNegativeOneFloatFieldNumber = 10; - inline float negative_one_float() const; - inline void set_negative_one_float(float value); - - // optional float negative_float = 11 [default = -1.5]; - inline bool has_negative_float() const; - inline void clear_negative_float(); - static const int kNegativeFloatFieldNumber = 11; - inline float negative_float() const; - inline void set_negative_float(float value); - - // optional float large_float = 12 [default = 2e+08]; - inline bool has_large_float() const; - inline void clear_large_float(); - static const int kLargeFloatFieldNumber = 12; - inline float large_float() const; - inline void set_large_float(float value); - - // optional float small_negative_float = 13 [default = -8e-28]; - inline bool has_small_negative_float() const; - inline void clear_small_negative_float(); - static const int kSmallNegativeFloatFieldNumber = 13; - inline float small_negative_float() const; - inline void set_small_negative_float(float value); - - // optional double inf_double = 14 [default = inf]; - inline bool has_inf_double() const; - inline void clear_inf_double(); - static const int kInfDoubleFieldNumber = 14; - inline double inf_double() const; - inline void set_inf_double(double value); - - // optional double neg_inf_double = 15 [default = -inf]; - inline bool has_neg_inf_double() const; - inline void clear_neg_inf_double(); - static const int kNegInfDoubleFieldNumber = 15; - inline double neg_inf_double() const; - inline void set_neg_inf_double(double value); - - // optional double nan_double = 16 [default = nan]; - inline bool has_nan_double() const; - inline void clear_nan_double(); - static const int kNanDoubleFieldNumber = 16; - inline double nan_double() const; - inline void set_nan_double(double value); - - // optional float inf_float = 17 [default = inf]; - inline bool has_inf_float() const; - inline void clear_inf_float(); - static const int kInfFloatFieldNumber = 17; - inline float inf_float() const; - inline void set_inf_float(float value); - - // optional float neg_inf_float = 18 [default = -inf]; - inline bool has_neg_inf_float() const; - inline void clear_neg_inf_float(); - static const int kNegInfFloatFieldNumber = 18; - inline float neg_inf_float() const; - inline void set_neg_inf_float(float value); - - // optional float nan_float = 19 [default = nan]; - inline bool has_nan_float() const; - inline void clear_nan_float(); - static const int kNanFloatFieldNumber = 19; - inline float nan_float() const; - inline void set_nan_float(float value); - - // optional string cpp_trigraph = 20 [default = "? ? ?? ?? ??? ??/ ??-"]; - inline bool has_cpp_trigraph() const; - inline void clear_cpp_trigraph(); - static const int kCppTrigraphFieldNumber = 20; - inline const ::std::string& cpp_trigraph() const; - inline void set_cpp_trigraph(const ::std::string& value); - inline void set_cpp_trigraph(const char* value); - inline void set_cpp_trigraph(const char* value, size_t size); - inline ::std::string* mutable_cpp_trigraph(); - inline ::std::string* release_cpp_trigraph(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestExtremeDefaultValues) - private: - inline void set_has_escaped_bytes(); - inline void clear_has_escaped_bytes(); - inline void set_has_large_uint32(); - inline void clear_has_large_uint32(); - inline void set_has_large_uint64(); - inline void clear_has_large_uint64(); - inline void set_has_small_int32(); - inline void clear_has_small_int32(); - inline void set_has_small_int64(); - inline void clear_has_small_int64(); - inline void set_has_utf8_string(); - inline void clear_has_utf8_string(); - inline void set_has_zero_float(); - inline void clear_has_zero_float(); - inline void set_has_one_float(); - inline void clear_has_one_float(); - inline void set_has_small_float(); - inline void clear_has_small_float(); - inline void set_has_negative_one_float(); - inline void clear_has_negative_one_float(); - inline void set_has_negative_float(); - inline void clear_has_negative_float(); - inline void set_has_large_float(); - inline void clear_has_large_float(); - inline void set_has_small_negative_float(); - inline void clear_has_small_negative_float(); - inline void set_has_inf_double(); - inline void clear_has_inf_double(); - inline void set_has_neg_inf_double(); - inline void clear_has_neg_inf_double(); - inline void set_has_nan_double(); - inline void clear_has_nan_double(); - inline void set_has_inf_float(); - inline void clear_has_inf_float(); - inline void set_has_neg_inf_float(); - inline void clear_has_neg_inf_float(); - inline void set_has_nan_float(); - inline void clear_has_nan_float(); - inline void set_has_cpp_trigraph(); - inline void clear_has_cpp_trigraph(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* escaped_bytes_; - static const ::std::string _default_escaped_bytes_; - ::google::protobuf::uint64 large_uint64_; - ::google::protobuf::uint32 large_uint32_; - ::google::protobuf::int32 small_int32_; - ::google::protobuf::int64 small_int64_; - ::std::string* utf8_string_; - static const ::std::string _default_utf8_string_; - float zero_float_; - float one_float_; - float small_float_; - float negative_one_float_; - float negative_float_; - float large_float_; - double inf_double_; - double neg_inf_double_; - float small_negative_float_; - float inf_float_; - double nan_double_; - float neg_inf_float_; - float nan_float_; - ::std::string* cpp_trigraph_; - static const ::std::string _default_cpp_trigraph_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(20 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestExtremeDefaultValues* default_instance_; -}; -// ------------------------------------------------------------------- - -class SparseEnumMessage : public ::google::protobuf::Message { - public: - SparseEnumMessage(); - virtual ~SparseEnumMessage(); - - SparseEnumMessage(const SparseEnumMessage& from); - - inline SparseEnumMessage& operator=(const SparseEnumMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SparseEnumMessage& default_instance(); - - void Swap(SparseEnumMessage* other); - - // implements Message ---------------------------------------------- - - SparseEnumMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SparseEnumMessage& from); - void MergeFrom(const SparseEnumMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestSparseEnum sparse_enum = 1; - inline bool has_sparse_enum() const; - inline void clear_sparse_enum(); - static const int kSparseEnumFieldNumber = 1; - inline protobuf_unittest::TestSparseEnum sparse_enum() const; - inline void set_sparse_enum(protobuf_unittest::TestSparseEnum value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.SparseEnumMessage) - private: - inline void set_has_sparse_enum(); - inline void clear_has_sparse_enum(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - int sparse_enum_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static SparseEnumMessage* default_instance_; -}; -// ------------------------------------------------------------------- - -class OneString : public ::google::protobuf::Message { - public: - OneString(); - virtual ~OneString(); - - OneString(const OneString& from); - - inline OneString& operator=(const OneString& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const OneString& default_instance(); - - void Swap(OneString* other); - - // implements Message ---------------------------------------------- - - OneString* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const OneString& from); - void MergeFrom(const OneString& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string data = 1; - inline bool has_data() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - inline const ::std::string& data() const; - inline void set_data(const ::std::string& value); - inline void set_data(const char* value); - inline void set_data(const char* value, size_t size); - inline ::std::string* mutable_data(); - inline ::std::string* release_data(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.OneString) - private: - inline void set_has_data(); - inline void clear_has_data(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static OneString* default_instance_; -}; -// ------------------------------------------------------------------- - -class OneBytes : public ::google::protobuf::Message { - public: - OneBytes(); - virtual ~OneBytes(); - - OneBytes(const OneBytes& from); - - inline OneBytes& operator=(const OneBytes& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const OneBytes& default_instance(); - - void Swap(OneBytes* other); - - // implements Message ---------------------------------------------- - - OneBytes* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const OneBytes& from); - void MergeFrom(const OneBytes& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bytes data = 1; - inline bool has_data() const; - inline void clear_data(); - static const int kDataFieldNumber = 1; - inline const ::std::string& data() const; - inline void set_data(const ::std::string& value); - inline void set_data(const char* value); - inline void set_data(const void* value, size_t size); - inline ::std::string* mutable_data(); - inline ::std::string* release_data(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.OneBytes) - private: - inline void set_has_data(); - inline void clear_has_data(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* data_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static OneBytes* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestPackedTypes : public ::google::protobuf::Message { - public: - TestPackedTypes(); - virtual ~TestPackedTypes(); - - TestPackedTypes(const TestPackedTypes& from); - - inline TestPackedTypes& operator=(const TestPackedTypes& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestPackedTypes& default_instance(); - - void Swap(TestPackedTypes* other); - - // implements Message ---------------------------------------------- - - TestPackedTypes* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestPackedTypes& from); - void MergeFrom(const TestPackedTypes& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 packed_int32 = 90 [packed = true]; - inline int packed_int32_size() const; - inline void clear_packed_int32(); - static const int kPackedInt32FieldNumber = 90; - inline ::google::protobuf::int32 packed_int32(int index) const; - inline void set_packed_int32(int index, ::google::protobuf::int32 value); - inline void add_packed_int32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - packed_int32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_packed_int32(); - - // repeated int64 packed_int64 = 91 [packed = true]; - inline int packed_int64_size() const; - inline void clear_packed_int64(); - static const int kPackedInt64FieldNumber = 91; - inline ::google::protobuf::int64 packed_int64(int index) const; - inline void set_packed_int64(int index, ::google::protobuf::int64 value); - inline void add_packed_int64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - packed_int64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_packed_int64(); - - // repeated uint32 packed_uint32 = 92 [packed = true]; - inline int packed_uint32_size() const; - inline void clear_packed_uint32(); - static const int kPackedUint32FieldNumber = 92; - inline ::google::protobuf::uint32 packed_uint32(int index) const; - inline void set_packed_uint32(int index, ::google::protobuf::uint32 value); - inline void add_packed_uint32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - packed_uint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_packed_uint32(); - - // repeated uint64 packed_uint64 = 93 [packed = true]; - inline int packed_uint64_size() const; - inline void clear_packed_uint64(); - static const int kPackedUint64FieldNumber = 93; - inline ::google::protobuf::uint64 packed_uint64(int index) const; - inline void set_packed_uint64(int index, ::google::protobuf::uint64 value); - inline void add_packed_uint64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - packed_uint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_packed_uint64(); - - // repeated sint32 packed_sint32 = 94 [packed = true]; - inline int packed_sint32_size() const; - inline void clear_packed_sint32(); - static const int kPackedSint32FieldNumber = 94; - inline ::google::protobuf::int32 packed_sint32(int index) const; - inline void set_packed_sint32(int index, ::google::protobuf::int32 value); - inline void add_packed_sint32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - packed_sint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_packed_sint32(); - - // repeated sint64 packed_sint64 = 95 [packed = true]; - inline int packed_sint64_size() const; - inline void clear_packed_sint64(); - static const int kPackedSint64FieldNumber = 95; - inline ::google::protobuf::int64 packed_sint64(int index) const; - inline void set_packed_sint64(int index, ::google::protobuf::int64 value); - inline void add_packed_sint64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - packed_sint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_packed_sint64(); - - // repeated fixed32 packed_fixed32 = 96 [packed = true]; - inline int packed_fixed32_size() const; - inline void clear_packed_fixed32(); - static const int kPackedFixed32FieldNumber = 96; - inline ::google::protobuf::uint32 packed_fixed32(int index) const; - inline void set_packed_fixed32(int index, ::google::protobuf::uint32 value); - inline void add_packed_fixed32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - packed_fixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_packed_fixed32(); - - // repeated fixed64 packed_fixed64 = 97 [packed = true]; - inline int packed_fixed64_size() const; - inline void clear_packed_fixed64(); - static const int kPackedFixed64FieldNumber = 97; - inline ::google::protobuf::uint64 packed_fixed64(int index) const; - inline void set_packed_fixed64(int index, ::google::protobuf::uint64 value); - inline void add_packed_fixed64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - packed_fixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_packed_fixed64(); - - // repeated sfixed32 packed_sfixed32 = 98 [packed = true]; - inline int packed_sfixed32_size() const; - inline void clear_packed_sfixed32(); - static const int kPackedSfixed32FieldNumber = 98; - inline ::google::protobuf::int32 packed_sfixed32(int index) const; - inline void set_packed_sfixed32(int index, ::google::protobuf::int32 value); - inline void add_packed_sfixed32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - packed_sfixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_packed_sfixed32(); - - // repeated sfixed64 packed_sfixed64 = 99 [packed = true]; - inline int packed_sfixed64_size() const; - inline void clear_packed_sfixed64(); - static const int kPackedSfixed64FieldNumber = 99; - inline ::google::protobuf::int64 packed_sfixed64(int index) const; - inline void set_packed_sfixed64(int index, ::google::protobuf::int64 value); - inline void add_packed_sfixed64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - packed_sfixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_packed_sfixed64(); - - // repeated float packed_float = 100 [packed = true]; - inline int packed_float_size() const; - inline void clear_packed_float(); - static const int kPackedFloatFieldNumber = 100; - inline float packed_float(int index) const; - inline void set_packed_float(int index, float value); - inline void add_packed_float(float value); - inline const ::google::protobuf::RepeatedField< float >& - packed_float() const; - inline ::google::protobuf::RepeatedField< float >* - mutable_packed_float(); - - // repeated double packed_double = 101 [packed = true]; - inline int packed_double_size() const; - inline void clear_packed_double(); - static const int kPackedDoubleFieldNumber = 101; - inline double packed_double(int index) const; - inline void set_packed_double(int index, double value); - inline void add_packed_double(double value); - inline const ::google::protobuf::RepeatedField< double >& - packed_double() const; - inline ::google::protobuf::RepeatedField< double >* - mutable_packed_double(); - - // repeated bool packed_bool = 102 [packed = true]; - inline int packed_bool_size() const; - inline void clear_packed_bool(); - static const int kPackedBoolFieldNumber = 102; - inline bool packed_bool(int index) const; - inline void set_packed_bool(int index, bool value); - inline void add_packed_bool(bool value); - inline const ::google::protobuf::RepeatedField< bool >& - packed_bool() const; - inline ::google::protobuf::RepeatedField< bool >* - mutable_packed_bool(); - - // repeated .protobuf_unittest.ForeignEnum packed_enum = 103 [packed = true]; - inline int packed_enum_size() const; - inline void clear_packed_enum(); - static const int kPackedEnumFieldNumber = 103; - inline protobuf_unittest::ForeignEnum packed_enum(int index) const; - inline void set_packed_enum(int index, protobuf_unittest::ForeignEnum value); - inline void add_packed_enum(protobuf_unittest::ForeignEnum value); - inline const ::google::protobuf::RepeatedField& packed_enum() const; - inline ::google::protobuf::RepeatedField* mutable_packed_enum(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedTypes) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_int32_; - mutable int _packed_int32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_int64_; - mutable int _packed_int64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_uint32_; - mutable int _packed_uint32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_uint64_; - mutable int _packed_uint64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sint32_; - mutable int _packed_sint32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sint64_; - mutable int _packed_sint64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_fixed32_; - mutable int _packed_fixed32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_fixed64_; - mutable int _packed_fixed64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sfixed32_; - mutable int _packed_sfixed32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sfixed64_; - mutable int _packed_sfixed64_cached_byte_size_; - ::google::protobuf::RepeatedField< float > packed_float_; - mutable int _packed_float_cached_byte_size_; - ::google::protobuf::RepeatedField< double > packed_double_; - mutable int _packed_double_cached_byte_size_; - ::google::protobuf::RepeatedField< bool > packed_bool_; - mutable int _packed_bool_cached_byte_size_; - ::google::protobuf::RepeatedField packed_enum_; - mutable int _packed_enum_cached_byte_size_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(14 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestPackedTypes* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestUnpackedTypes : public ::google::protobuf::Message { - public: - TestUnpackedTypes(); - virtual ~TestUnpackedTypes(); - - TestUnpackedTypes(const TestUnpackedTypes& from); - - inline TestUnpackedTypes& operator=(const TestUnpackedTypes& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestUnpackedTypes& default_instance(); - - void Swap(TestUnpackedTypes* other); - - // implements Message ---------------------------------------------- - - TestUnpackedTypes* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestUnpackedTypes& from); - void MergeFrom(const TestUnpackedTypes& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 unpacked_int32 = 90 [packed = false]; - inline int unpacked_int32_size() const; - inline void clear_unpacked_int32(); - static const int kUnpackedInt32FieldNumber = 90; - inline ::google::protobuf::int32 unpacked_int32(int index) const; - inline void set_unpacked_int32(int index, ::google::protobuf::int32 value); - inline void add_unpacked_int32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - unpacked_int32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_unpacked_int32(); - - // repeated int64 unpacked_int64 = 91 [packed = false]; - inline int unpacked_int64_size() const; - inline void clear_unpacked_int64(); - static const int kUnpackedInt64FieldNumber = 91; - inline ::google::protobuf::int64 unpacked_int64(int index) const; - inline void set_unpacked_int64(int index, ::google::protobuf::int64 value); - inline void add_unpacked_int64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - unpacked_int64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_unpacked_int64(); - - // repeated uint32 unpacked_uint32 = 92 [packed = false]; - inline int unpacked_uint32_size() const; - inline void clear_unpacked_uint32(); - static const int kUnpackedUint32FieldNumber = 92; - inline ::google::protobuf::uint32 unpacked_uint32(int index) const; - inline void set_unpacked_uint32(int index, ::google::protobuf::uint32 value); - inline void add_unpacked_uint32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - unpacked_uint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_unpacked_uint32(); - - // repeated uint64 unpacked_uint64 = 93 [packed = false]; - inline int unpacked_uint64_size() const; - inline void clear_unpacked_uint64(); - static const int kUnpackedUint64FieldNumber = 93; - inline ::google::protobuf::uint64 unpacked_uint64(int index) const; - inline void set_unpacked_uint64(int index, ::google::protobuf::uint64 value); - inline void add_unpacked_uint64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - unpacked_uint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_unpacked_uint64(); - - // repeated sint32 unpacked_sint32 = 94 [packed = false]; - inline int unpacked_sint32_size() const; - inline void clear_unpacked_sint32(); - static const int kUnpackedSint32FieldNumber = 94; - inline ::google::protobuf::int32 unpacked_sint32(int index) const; - inline void set_unpacked_sint32(int index, ::google::protobuf::int32 value); - inline void add_unpacked_sint32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - unpacked_sint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_unpacked_sint32(); - - // repeated sint64 unpacked_sint64 = 95 [packed = false]; - inline int unpacked_sint64_size() const; - inline void clear_unpacked_sint64(); - static const int kUnpackedSint64FieldNumber = 95; - inline ::google::protobuf::int64 unpacked_sint64(int index) const; - inline void set_unpacked_sint64(int index, ::google::protobuf::int64 value); - inline void add_unpacked_sint64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - unpacked_sint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_unpacked_sint64(); - - // repeated fixed32 unpacked_fixed32 = 96 [packed = false]; - inline int unpacked_fixed32_size() const; - inline void clear_unpacked_fixed32(); - static const int kUnpackedFixed32FieldNumber = 96; - inline ::google::protobuf::uint32 unpacked_fixed32(int index) const; - inline void set_unpacked_fixed32(int index, ::google::protobuf::uint32 value); - inline void add_unpacked_fixed32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - unpacked_fixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_unpacked_fixed32(); - - // repeated fixed64 unpacked_fixed64 = 97 [packed = false]; - inline int unpacked_fixed64_size() const; - inline void clear_unpacked_fixed64(); - static const int kUnpackedFixed64FieldNumber = 97; - inline ::google::protobuf::uint64 unpacked_fixed64(int index) const; - inline void set_unpacked_fixed64(int index, ::google::protobuf::uint64 value); - inline void add_unpacked_fixed64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - unpacked_fixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_unpacked_fixed64(); - - // repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; - inline int unpacked_sfixed32_size() const; - inline void clear_unpacked_sfixed32(); - static const int kUnpackedSfixed32FieldNumber = 98; - inline ::google::protobuf::int32 unpacked_sfixed32(int index) const; - inline void set_unpacked_sfixed32(int index, ::google::protobuf::int32 value); - inline void add_unpacked_sfixed32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - unpacked_sfixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_unpacked_sfixed32(); - - // repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; - inline int unpacked_sfixed64_size() const; - inline void clear_unpacked_sfixed64(); - static const int kUnpackedSfixed64FieldNumber = 99; - inline ::google::protobuf::int64 unpacked_sfixed64(int index) const; - inline void set_unpacked_sfixed64(int index, ::google::protobuf::int64 value); - inline void add_unpacked_sfixed64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - unpacked_sfixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_unpacked_sfixed64(); - - // repeated float unpacked_float = 100 [packed = false]; - inline int unpacked_float_size() const; - inline void clear_unpacked_float(); - static const int kUnpackedFloatFieldNumber = 100; - inline float unpacked_float(int index) const; - inline void set_unpacked_float(int index, float value); - inline void add_unpacked_float(float value); - inline const ::google::protobuf::RepeatedField< float >& - unpacked_float() const; - inline ::google::protobuf::RepeatedField< float >* - mutable_unpacked_float(); - - // repeated double unpacked_double = 101 [packed = false]; - inline int unpacked_double_size() const; - inline void clear_unpacked_double(); - static const int kUnpackedDoubleFieldNumber = 101; - inline double unpacked_double(int index) const; - inline void set_unpacked_double(int index, double value); - inline void add_unpacked_double(double value); - inline const ::google::protobuf::RepeatedField< double >& - unpacked_double() const; - inline ::google::protobuf::RepeatedField< double >* - mutable_unpacked_double(); - - // repeated bool unpacked_bool = 102 [packed = false]; - inline int unpacked_bool_size() const; - inline void clear_unpacked_bool(); - static const int kUnpackedBoolFieldNumber = 102; - inline bool unpacked_bool(int index) const; - inline void set_unpacked_bool(int index, bool value); - inline void add_unpacked_bool(bool value); - inline const ::google::protobuf::RepeatedField< bool >& - unpacked_bool() const; - inline ::google::protobuf::RepeatedField< bool >* - mutable_unpacked_bool(); - - // repeated .protobuf_unittest.ForeignEnum unpacked_enum = 103 [packed = false]; - inline int unpacked_enum_size() const; - inline void clear_unpacked_enum(); - static const int kUnpackedEnumFieldNumber = 103; - inline protobuf_unittest::ForeignEnum unpacked_enum(int index) const; - inline void set_unpacked_enum(int index, protobuf_unittest::ForeignEnum value); - inline void add_unpacked_enum(protobuf_unittest::ForeignEnum value); - inline const ::google::protobuf::RepeatedField& unpacked_enum() const; - inline ::google::protobuf::RepeatedField* mutable_unpacked_enum(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestUnpackedTypes) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > unpacked_int32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > unpacked_int64_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > unpacked_uint32_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > unpacked_uint64_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > unpacked_sint32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > unpacked_sint64_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > unpacked_fixed32_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > unpacked_fixed64_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > unpacked_sfixed32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > unpacked_sfixed64_; - ::google::protobuf::RepeatedField< float > unpacked_float_; - ::google::protobuf::RepeatedField< double > unpacked_double_; - ::google::protobuf::RepeatedField< bool > unpacked_bool_; - ::google::protobuf::RepeatedField unpacked_enum_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(14 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestUnpackedTypes* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestPackedExtensions : public ::google::protobuf::Message { - public: - TestPackedExtensions(); - virtual ~TestPackedExtensions(); - - TestPackedExtensions(const TestPackedExtensions& from); - - inline TestPackedExtensions& operator=(const TestPackedExtensions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestPackedExtensions& default_instance(); - - void Swap(TestPackedExtensions* other); - - // implements Message ---------------------------------------------- - - TestPackedExtensions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestPackedExtensions& from); - void MergeFrom(const TestPackedExtensions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestPackedExtensions) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedExtensions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestPackedExtensions* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestDynamicExtensions_DynamicMessageType : public ::google::protobuf::Message { - public: - TestDynamicExtensions_DynamicMessageType(); - virtual ~TestDynamicExtensions_DynamicMessageType(); - - TestDynamicExtensions_DynamicMessageType(const TestDynamicExtensions_DynamicMessageType& from); - - inline TestDynamicExtensions_DynamicMessageType& operator=(const TestDynamicExtensions_DynamicMessageType& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestDynamicExtensions_DynamicMessageType& default_instance(); - - void Swap(TestDynamicExtensions_DynamicMessageType* other); - - // implements Message ---------------------------------------------- - - TestDynamicExtensions_DynamicMessageType* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestDynamicExtensions_DynamicMessageType& from); - void MergeFrom(const TestDynamicExtensions_DynamicMessageType& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 dynamic_field = 2100; - inline bool has_dynamic_field() const; - inline void clear_dynamic_field(); - static const int kDynamicFieldFieldNumber = 2100; - inline ::google::protobuf::int32 dynamic_field() const; - inline void set_dynamic_field(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDynamicExtensions.DynamicMessageType) - private: - inline void set_has_dynamic_field(); - inline void clear_has_dynamic_field(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 dynamic_field_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestDynamicExtensions_DynamicMessageType* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestDynamicExtensions : public ::google::protobuf::Message { - public: - TestDynamicExtensions(); - virtual ~TestDynamicExtensions(); - - TestDynamicExtensions(const TestDynamicExtensions& from); - - inline TestDynamicExtensions& operator=(const TestDynamicExtensions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestDynamicExtensions& default_instance(); - - void Swap(TestDynamicExtensions* other); - - // implements Message ---------------------------------------------- - - TestDynamicExtensions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestDynamicExtensions& from); - void MergeFrom(const TestDynamicExtensions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef TestDynamicExtensions_DynamicMessageType DynamicMessageType; - - typedef TestDynamicExtensions_DynamicEnumType DynamicEnumType; - static const DynamicEnumType DYNAMIC_FOO = TestDynamicExtensions_DynamicEnumType_DYNAMIC_FOO; - static const DynamicEnumType DYNAMIC_BAR = TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAR; - static const DynamicEnumType DYNAMIC_BAZ = TestDynamicExtensions_DynamicEnumType_DYNAMIC_BAZ; - static inline bool DynamicEnumType_IsValid(int value) { - return TestDynamicExtensions_DynamicEnumType_IsValid(value); - } - static const DynamicEnumType DynamicEnumType_MIN = - TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MIN; - static const DynamicEnumType DynamicEnumType_MAX = - TestDynamicExtensions_DynamicEnumType_DynamicEnumType_MAX; - static const int DynamicEnumType_ARRAYSIZE = - TestDynamicExtensions_DynamicEnumType_DynamicEnumType_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - DynamicEnumType_descriptor() { - return TestDynamicExtensions_DynamicEnumType_descriptor(); - } - static inline const ::std::string& DynamicEnumType_Name(DynamicEnumType value) { - return TestDynamicExtensions_DynamicEnumType_Name(value); - } - static inline bool DynamicEnumType_Parse(const ::std::string& name, - DynamicEnumType* value) { - return TestDynamicExtensions_DynamicEnumType_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional fixed32 scalar_extension = 2000; - inline bool has_scalar_extension() const; - inline void clear_scalar_extension(); - static const int kScalarExtensionFieldNumber = 2000; - inline ::google::protobuf::uint32 scalar_extension() const; - inline void set_scalar_extension(::google::protobuf::uint32 value); - - // optional .protobuf_unittest.ForeignEnum enum_extension = 2001; - inline bool has_enum_extension() const; - inline void clear_enum_extension(); - static const int kEnumExtensionFieldNumber = 2001; - inline protobuf_unittest::ForeignEnum enum_extension() const; - inline void set_enum_extension(protobuf_unittest::ForeignEnum value); - - // optional .protobuf_unittest.TestDynamicExtensions.DynamicEnumType dynamic_enum_extension = 2002; - inline bool has_dynamic_enum_extension() const; - inline void clear_dynamic_enum_extension(); - static const int kDynamicEnumExtensionFieldNumber = 2002; - inline ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType dynamic_enum_extension() const; - inline void set_dynamic_enum_extension(::protobuf_unittest::TestDynamicExtensions_DynamicEnumType value); - - // optional .protobuf_unittest.ForeignMessage message_extension = 2003; - inline bool has_message_extension() const; - inline void clear_message_extension(); - static const int kMessageExtensionFieldNumber = 2003; - inline const ::protobuf_unittest::ForeignMessage& message_extension() const; - inline ::protobuf_unittest::ForeignMessage* mutable_message_extension(); - inline ::protobuf_unittest::ForeignMessage* release_message_extension(); - - // optional .protobuf_unittest.TestDynamicExtensions.DynamicMessageType dynamic_message_extension = 2004; - inline bool has_dynamic_message_extension() const; - inline void clear_dynamic_message_extension(); - static const int kDynamicMessageExtensionFieldNumber = 2004; - inline const ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType& dynamic_message_extension() const; - inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* mutable_dynamic_message_extension(); - inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* release_dynamic_message_extension(); - - // repeated string repeated_extension = 2005; - inline int repeated_extension_size() const; - inline void clear_repeated_extension(); - static const int kRepeatedExtensionFieldNumber = 2005; - inline const ::std::string& repeated_extension(int index) const; - inline ::std::string* mutable_repeated_extension(int index); - inline void set_repeated_extension(int index, const ::std::string& value); - inline void set_repeated_extension(int index, const char* value); - inline void set_repeated_extension(int index, const char* value, size_t size); - inline ::std::string* add_repeated_extension(); - inline void add_repeated_extension(const ::std::string& value); - inline void add_repeated_extension(const char* value); - inline void add_repeated_extension(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_extension() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_extension(); - - // repeated sint32 packed_extension = 2006 [packed = true]; - inline int packed_extension_size() const; - inline void clear_packed_extension(); - static const int kPackedExtensionFieldNumber = 2006; - inline ::google::protobuf::int32 packed_extension(int index) const; - inline void set_packed_extension(int index, ::google::protobuf::int32 value); - inline void add_packed_extension(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - packed_extension() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_packed_extension(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDynamicExtensions) - private: - inline void set_has_scalar_extension(); - inline void clear_has_scalar_extension(); - inline void set_has_enum_extension(); - inline void clear_has_enum_extension(); - inline void set_has_dynamic_enum_extension(); - inline void clear_has_dynamic_enum_extension(); - inline void set_has_message_extension(); - inline void clear_has_message_extension(); - inline void set_has_dynamic_message_extension(); - inline void clear_has_dynamic_message_extension(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::uint32 scalar_extension_; - int enum_extension_; - ::protobuf_unittest::ForeignMessage* message_extension_; - ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* dynamic_message_extension_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_extension_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_extension_; - mutable int _packed_extension_cached_byte_size_; - int dynamic_enum_extension_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(7 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestDynamicExtensions* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestRepeatedScalarDifferentTagSizes : public ::google::protobuf::Message { - public: - TestRepeatedScalarDifferentTagSizes(); - virtual ~TestRepeatedScalarDifferentTagSizes(); - - TestRepeatedScalarDifferentTagSizes(const TestRepeatedScalarDifferentTagSizes& from); - - inline TestRepeatedScalarDifferentTagSizes& operator=(const TestRepeatedScalarDifferentTagSizes& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestRepeatedScalarDifferentTagSizes& default_instance(); - - void Swap(TestRepeatedScalarDifferentTagSizes* other); - - // implements Message ---------------------------------------------- - - TestRepeatedScalarDifferentTagSizes* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestRepeatedScalarDifferentTagSizes& from); - void MergeFrom(const TestRepeatedScalarDifferentTagSizes& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated fixed32 repeated_fixed32 = 12; - inline int repeated_fixed32_size() const; - inline void clear_repeated_fixed32(); - static const int kRepeatedFixed32FieldNumber = 12; - inline ::google::protobuf::uint32 repeated_fixed32(int index) const; - inline void set_repeated_fixed32(int index, ::google::protobuf::uint32 value); - inline void add_repeated_fixed32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - repeated_fixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_repeated_fixed32(); - - // repeated int32 repeated_int32 = 13; - inline int repeated_int32_size() const; - inline void clear_repeated_int32(); - static const int kRepeatedInt32FieldNumber = 13; - inline ::google::protobuf::int32 repeated_int32(int index) const; - inline void set_repeated_int32(int index, ::google::protobuf::int32 value); - inline void add_repeated_int32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeated_int32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeated_int32(); - - // repeated fixed64 repeated_fixed64 = 2046; - inline int repeated_fixed64_size() const; - inline void clear_repeated_fixed64(); - static const int kRepeatedFixed64FieldNumber = 2046; - inline ::google::protobuf::uint64 repeated_fixed64(int index) const; - inline void set_repeated_fixed64(int index, ::google::protobuf::uint64 value); - inline void add_repeated_fixed64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - repeated_fixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_repeated_fixed64(); - - // repeated int64 repeated_int64 = 2047; - inline int repeated_int64_size() const; - inline void clear_repeated_int64(); - static const int kRepeatedInt64FieldNumber = 2047; - inline ::google::protobuf::int64 repeated_int64(int index) const; - inline void set_repeated_int64(int index, ::google::protobuf::int64 value); - inline void add_repeated_int64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - repeated_int64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_repeated_int64(); - - // repeated float repeated_float = 262142; - inline int repeated_float_size() const; - inline void clear_repeated_float(); - static const int kRepeatedFloatFieldNumber = 262142; - inline float repeated_float(int index) const; - inline void set_repeated_float(int index, float value); - inline void add_repeated_float(float value); - inline const ::google::protobuf::RepeatedField< float >& - repeated_float() const; - inline ::google::protobuf::RepeatedField< float >* - mutable_repeated_float(); - - // repeated uint64 repeated_uint64 = 262143; - inline int repeated_uint64_size() const; - inline void clear_repeated_uint64(); - static const int kRepeatedUint64FieldNumber = 262143; - inline ::google::protobuf::uint64 repeated_uint64(int index) const; - inline void set_repeated_uint64(int index, ::google::protobuf::uint64 value); - inline void add_repeated_uint64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - repeated_uint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_repeated_uint64(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRepeatedScalarDifferentTagSizes) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_fixed32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_int32_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_fixed64_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_int64_; - ::google::protobuf::RepeatedField< float > repeated_float_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_uint64_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(6 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static TestRepeatedScalarDifferentTagSizes* default_instance_; -}; -// ------------------------------------------------------------------- - -class FooRequest : public ::google::protobuf::Message { - public: - FooRequest(); - virtual ~FooRequest(); - - FooRequest(const FooRequest& from); - - inline FooRequest& operator=(const FooRequest& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FooRequest& default_instance(); - - void Swap(FooRequest* other); - - // implements Message ---------------------------------------------- - - FooRequest* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FooRequest& from); - void MergeFrom(const FooRequest& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.FooRequest) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static FooRequest* default_instance_; -}; -// ------------------------------------------------------------------- - -class FooResponse : public ::google::protobuf::Message { - public: - FooResponse(); - virtual ~FooResponse(); - - FooResponse(const FooResponse& from); - - inline FooResponse& operator=(const FooResponse& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FooResponse& default_instance(); - - void Swap(FooResponse* other); - - // implements Message ---------------------------------------------- - - FooResponse* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FooResponse& from); - void MergeFrom(const FooResponse& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.FooResponse) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static FooResponse* default_instance_; -}; -// ------------------------------------------------------------------- - -class BarRequest : public ::google::protobuf::Message { - public: - BarRequest(); - virtual ~BarRequest(); - - BarRequest(const BarRequest& from); - - inline BarRequest& operator=(const BarRequest& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const BarRequest& default_instance(); - - void Swap(BarRequest* other); - - // implements Message ---------------------------------------------- - - BarRequest* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const BarRequest& from); - void MergeFrom(const BarRequest& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.BarRequest) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static BarRequest* default_instance_; -}; -// ------------------------------------------------------------------- - -class BarResponse : public ::google::protobuf::Message { - public: - BarResponse(); - virtual ~BarResponse(); - - BarResponse(const BarResponse& from); - - inline BarResponse& operator=(const BarResponse& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const BarResponse& default_instance(); - - void Swap(BarResponse* other); - - // implements Message ---------------------------------------------- - - BarResponse* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const BarResponse& from); - void MergeFrom(const BarResponse& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.BarResponse) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_2eproto(); - - void InitAsDefaultInstance(); - static BarResponse* default_instance_; -}; -// =================================================================== - -class TestService_Stub; - -class TestService : public ::google::protobuf::Service { - protected: - // This class should be treated as an abstract interface. - inline TestService() {}; - public: - virtual ~TestService(); - - typedef TestService_Stub Stub; - - static const ::google::protobuf::ServiceDescriptor* descriptor(); - - virtual void Foo(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::FooRequest* request, - ::protobuf_unittest::FooResponse* response, - ::google::protobuf::Closure* done); - virtual void Bar(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::BarRequest* request, - ::protobuf_unittest::BarResponse* response, - ::google::protobuf::Closure* done); - - // implements Service ---------------------------------------------- - - const ::google::protobuf::ServiceDescriptor* GetDescriptor(); - void CallMethod(const ::google::protobuf::MethodDescriptor* method, - ::google::protobuf::RpcController* controller, - const ::google::protobuf::Message* request, - ::google::protobuf::Message* response, - ::google::protobuf::Closure* done); - const ::google::protobuf::Message& GetRequestPrototype( - const ::google::protobuf::MethodDescriptor* method) const; - const ::google::protobuf::Message& GetResponsePrototype( - const ::google::protobuf::MethodDescriptor* method) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestService); -}; - -class TestService_Stub : public TestService { - public: - TestService_Stub(::google::protobuf::RpcChannel* channel); - TestService_Stub(::google::protobuf::RpcChannel* channel, - ::google::protobuf::Service::ChannelOwnership ownership); - ~TestService_Stub(); - - inline ::google::protobuf::RpcChannel* channel() { return channel_; } - - // implements TestService ------------------------------------------ - - void Foo(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::FooRequest* request, - ::protobuf_unittest::FooResponse* response, - ::google::protobuf::Closure* done); - void Bar(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::BarRequest* request, - ::protobuf_unittest::BarResponse* response, - ::google::protobuf::Closure* done); - private: - ::google::protobuf::RpcChannel* channel_; - bool owns_channel_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestService_Stub); -}; - - -// =================================================================== - -static const int kOptionalInt32ExtensionFieldNumber = 1; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - optional_int32_extension; -static const int kOptionalInt64ExtensionFieldNumber = 2; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > - optional_int64_extension; -static const int kOptionalUint32ExtensionFieldNumber = 3; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > - optional_uint32_extension; -static const int kOptionalUint64ExtensionFieldNumber = 4; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - optional_uint64_extension; -static const int kOptionalSint32ExtensionFieldNumber = 5; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > - optional_sint32_extension; -static const int kOptionalSint64ExtensionFieldNumber = 6; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - optional_sint64_extension; -static const int kOptionalFixed32ExtensionFieldNumber = 7; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > - optional_fixed32_extension; -static const int kOptionalFixed64ExtensionFieldNumber = 8; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - optional_fixed64_extension; -static const int kOptionalSfixed32ExtensionFieldNumber = 9; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - optional_sfixed32_extension; -static const int kOptionalSfixed64ExtensionFieldNumber = 10; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > - optional_sfixed64_extension; -static const int kOptionalFloatExtensionFieldNumber = 11; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > - optional_float_extension; -static const int kOptionalDoubleExtensionFieldNumber = 12; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > - optional_double_extension; -static const int kOptionalBoolExtensionFieldNumber = 13; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > - optional_bool_extension; -static const int kOptionalStringExtensionFieldNumber = 14; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - optional_string_extension; -static const int kOptionalBytesExtensionFieldNumber = 15; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 12, false > - optional_bytes_extension; -static const int kOptionalgroupExtensionFieldNumber = 16; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::OptionalGroup_extension >, 10, false > - optionalgroup_extension; -static const int kOptionalNestedMessageExtensionFieldNumber = 18; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestAllTypes_NestedMessage >, 11, false > - optional_nested_message_extension; -static const int kOptionalForeignMessageExtensionFieldNumber = 19; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ForeignMessage >, 11, false > - optional_foreign_message_extension; -static const int kOptionalImportMessageExtensionFieldNumber = 20; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest_import::ImportMessage >, 11, false > - optional_import_message_extension; -static const int kOptionalNestedEnumExtensionFieldNumber = 21; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypes_NestedEnum, ::protobuf_unittest::TestAllTypes_NestedEnum_IsValid>, 14, false > - optional_nested_enum_extension; -static const int kOptionalForeignEnumExtensionFieldNumber = 22; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, false > - optional_foreign_enum_extension; -static const int kOptionalImportEnumExtensionFieldNumber = 23; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnum, protobuf_unittest_import::ImportEnum_IsValid>, 14, false > - optional_import_enum_extension; -static const int kOptionalStringPieceExtensionFieldNumber = 24; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - optional_string_piece_extension; -static const int kOptionalCordExtensionFieldNumber = 25; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - optional_cord_extension; -static const int kRepeatedInt32ExtensionFieldNumber = 31; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - repeated_int32_extension; -static const int kRepeatedInt64ExtensionFieldNumber = 32; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > - repeated_int64_extension; -static const int kRepeatedUint32ExtensionFieldNumber = 33; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > - repeated_uint32_extension; -static const int kRepeatedUint64ExtensionFieldNumber = 34; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - repeated_uint64_extension; -static const int kRepeatedSint32ExtensionFieldNumber = 35; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > - repeated_sint32_extension; -static const int kRepeatedSint64ExtensionFieldNumber = 36; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - repeated_sint64_extension; -static const int kRepeatedFixed32ExtensionFieldNumber = 37; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > - repeated_fixed32_extension; -static const int kRepeatedFixed64ExtensionFieldNumber = 38; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - repeated_fixed64_extension; -static const int kRepeatedSfixed32ExtensionFieldNumber = 39; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - repeated_sfixed32_extension; -static const int kRepeatedSfixed64ExtensionFieldNumber = 40; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > - repeated_sfixed64_extension; -static const int kRepeatedFloatExtensionFieldNumber = 41; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, false > - repeated_float_extension; -static const int kRepeatedDoubleExtensionFieldNumber = 42; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, false > - repeated_double_extension; -static const int kRepeatedBoolExtensionFieldNumber = 43; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, false > - repeated_bool_extension; -static const int kRepeatedStringExtensionFieldNumber = 44; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > - repeated_string_extension; -static const int kRepeatedBytesExtensionFieldNumber = 45; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedStringTypeTraits, 12, false > - repeated_bytes_extension; -static const int kRepeatedgroupExtensionFieldNumber = 46; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::RepeatedGroup_extension >, 10, false > - repeatedgroup_extension; -static const int kRepeatedNestedMessageExtensionFieldNumber = 48; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::TestAllTypes_NestedMessage >, 11, false > - repeated_nested_message_extension; -static const int kRepeatedForeignMessageExtensionFieldNumber = 49; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::ForeignMessage >, 11, false > - repeated_foreign_message_extension; -static const int kRepeatedImportMessageExtensionFieldNumber = 50; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest_import::ImportMessage >, 11, false > - repeated_import_message_extension; -static const int kRepeatedNestedEnumExtensionFieldNumber = 51; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedEnumTypeTraits< ::protobuf_unittest::TestAllTypes_NestedEnum, ::protobuf_unittest::TestAllTypes_NestedEnum_IsValid>, 14, false > - repeated_nested_enum_extension; -static const int kRepeatedForeignEnumExtensionFieldNumber = 52; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, false > - repeated_foreign_enum_extension; -static const int kRepeatedImportEnumExtensionFieldNumber = 53; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest_import::ImportEnum, protobuf_unittest_import::ImportEnum_IsValid>, 14, false > - repeated_import_enum_extension; -static const int kRepeatedStringPieceExtensionFieldNumber = 54; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > - repeated_string_piece_extension; -static const int kRepeatedCordExtensionFieldNumber = 55; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > - repeated_cord_extension; -static const int kDefaultInt32ExtensionFieldNumber = 61; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - default_int32_extension; -static const int kDefaultInt64ExtensionFieldNumber = 62; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > - default_int64_extension; -static const int kDefaultUint32ExtensionFieldNumber = 63; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > - default_uint32_extension; -static const int kDefaultUint64ExtensionFieldNumber = 64; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - default_uint64_extension; -static const int kDefaultSint32ExtensionFieldNumber = 65; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > - default_sint32_extension; -static const int kDefaultSint64ExtensionFieldNumber = 66; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - default_sint64_extension; -static const int kDefaultFixed32ExtensionFieldNumber = 67; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > - default_fixed32_extension; -static const int kDefaultFixed64ExtensionFieldNumber = 68; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - default_fixed64_extension; -static const int kDefaultSfixed32ExtensionFieldNumber = 69; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - default_sfixed32_extension; -static const int kDefaultSfixed64ExtensionFieldNumber = 70; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > - default_sfixed64_extension; -static const int kDefaultFloatExtensionFieldNumber = 71; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > - default_float_extension; -static const int kDefaultDoubleExtensionFieldNumber = 72; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > - default_double_extension; -static const int kDefaultBoolExtensionFieldNumber = 73; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > - default_bool_extension; -static const int kDefaultStringExtensionFieldNumber = 74; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - default_string_extension; -static const int kDefaultBytesExtensionFieldNumber = 75; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 12, false > - default_bytes_extension; -static const int kDefaultNestedEnumExtensionFieldNumber = 81; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypes_NestedEnum, ::protobuf_unittest::TestAllTypes_NestedEnum_IsValid>, 14, false > - default_nested_enum_extension; -static const int kDefaultForeignEnumExtensionFieldNumber = 82; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, false > - default_foreign_enum_extension; -static const int kDefaultImportEnumExtensionFieldNumber = 83; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnum, protobuf_unittest_import::ImportEnum_IsValid>, 14, false > - default_import_enum_extension; -static const int kDefaultStringPieceExtensionFieldNumber = 84; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - default_string_piece_extension; -static const int kDefaultCordExtensionFieldNumber = 85; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - default_cord_extension; -static const int kMyExtensionStringFieldNumber = 50; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestFieldOrderings, - ::google::protobuf::internal::StringTypeTraits, 9, false > - my_extension_string; -static const int kMyExtensionIntFieldNumber = 5; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestFieldOrderings, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - my_extension_int; -static const int kPackedInt32ExtensionFieldNumber = 90; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, true > - packed_int32_extension; -static const int kPackedInt64ExtensionFieldNumber = 91; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, true > - packed_int64_extension; -static const int kPackedUint32ExtensionFieldNumber = 92; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, true > - packed_uint32_extension; -static const int kPackedUint64ExtensionFieldNumber = 93; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, true > - packed_uint64_extension; -static const int kPackedSint32ExtensionFieldNumber = 94; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, true > - packed_sint32_extension; -static const int kPackedSint64ExtensionFieldNumber = 95; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, true > - packed_sint64_extension; -static const int kPackedFixed32ExtensionFieldNumber = 96; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, true > - packed_fixed32_extension; -static const int kPackedFixed64ExtensionFieldNumber = 97; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, true > - packed_fixed64_extension; -static const int kPackedSfixed32ExtensionFieldNumber = 98; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, true > - packed_sfixed32_extension; -static const int kPackedSfixed64ExtensionFieldNumber = 99; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, true > - packed_sfixed64_extension; -static const int kPackedFloatExtensionFieldNumber = 100; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, true > - packed_float_extension; -static const int kPackedDoubleExtensionFieldNumber = 101; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, true > - packed_double_extension; -static const int kPackedBoolExtensionFieldNumber = 102; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, true > - packed_bool_extension; -static const int kPackedEnumExtensionFieldNumber = 103; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensions, - ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnum, protobuf_unittest::ForeignEnum_IsValid>, 14, true > - packed_enum_extension; - -// =================================================================== - -// TestAllTypes_NestedMessage - -// optional int32 bb = 1; -inline bool TestAllTypes_NestedMessage::has_bb() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypes_NestedMessage::set_has_bb() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypes_NestedMessage::clear_has_bb() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypes_NestedMessage::clear_bb() { - bb_ = 0; - clear_has_bb(); -} -inline ::google::protobuf::int32 TestAllTypes_NestedMessage::bb() const { - return bb_; -} -inline void TestAllTypes_NestedMessage::set_bb(::google::protobuf::int32 value) { - set_has_bb(); - bb_ = value; -} - -// ------------------------------------------------------------------- - -// TestAllTypes_OptionalGroup - -// optional int32 a = 17; -inline bool TestAllTypes_OptionalGroup::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypes_OptionalGroup::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypes_OptionalGroup::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypes_OptionalGroup::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestAllTypes_OptionalGroup::a() const { - return a_; -} -inline void TestAllTypes_OptionalGroup::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestAllTypes_RepeatedGroup - -// optional int32 a = 47; -inline bool TestAllTypes_RepeatedGroup::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypes_RepeatedGroup::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypes_RepeatedGroup::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypes_RepeatedGroup::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestAllTypes_RepeatedGroup::a() const { - return a_; -} -inline void TestAllTypes_RepeatedGroup::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestAllTypes - -// optional int32 optional_int32 = 1; -inline bool TestAllTypes::has_optional_int32() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypes::set_has_optional_int32() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypes::clear_has_optional_int32() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypes::clear_optional_int32() { - optional_int32_ = 0; - clear_has_optional_int32(); -} -inline ::google::protobuf::int32 TestAllTypes::optional_int32() const { - return optional_int32_; -} -inline void TestAllTypes::set_optional_int32(::google::protobuf::int32 value) { - set_has_optional_int32(); - optional_int32_ = value; -} - -// optional int64 optional_int64 = 2; -inline bool TestAllTypes::has_optional_int64() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestAllTypes::set_has_optional_int64() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestAllTypes::clear_has_optional_int64() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestAllTypes::clear_optional_int64() { - optional_int64_ = GOOGLE_LONGLONG(0); - clear_has_optional_int64(); -} -inline ::google::protobuf::int64 TestAllTypes::optional_int64() const { - return optional_int64_; -} -inline void TestAllTypes::set_optional_int64(::google::protobuf::int64 value) { - set_has_optional_int64(); - optional_int64_ = value; -} - -// optional uint32 optional_uint32 = 3; -inline bool TestAllTypes::has_optional_uint32() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestAllTypes::set_has_optional_uint32() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestAllTypes::clear_has_optional_uint32() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestAllTypes::clear_optional_uint32() { - optional_uint32_ = 0u; - clear_has_optional_uint32(); -} -inline ::google::protobuf::uint32 TestAllTypes::optional_uint32() const { - return optional_uint32_; -} -inline void TestAllTypes::set_optional_uint32(::google::protobuf::uint32 value) { - set_has_optional_uint32(); - optional_uint32_ = value; -} - -// optional uint64 optional_uint64 = 4; -inline bool TestAllTypes::has_optional_uint64() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void TestAllTypes::set_has_optional_uint64() { - _has_bits_[0] |= 0x00000008u; -} -inline void TestAllTypes::clear_has_optional_uint64() { - _has_bits_[0] &= ~0x00000008u; -} -inline void TestAllTypes::clear_optional_uint64() { - optional_uint64_ = GOOGLE_ULONGLONG(0); - clear_has_optional_uint64(); -} -inline ::google::protobuf::uint64 TestAllTypes::optional_uint64() const { - return optional_uint64_; -} -inline void TestAllTypes::set_optional_uint64(::google::protobuf::uint64 value) { - set_has_optional_uint64(); - optional_uint64_ = value; -} - -// optional sint32 optional_sint32 = 5; -inline bool TestAllTypes::has_optional_sint32() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TestAllTypes::set_has_optional_sint32() { - _has_bits_[0] |= 0x00000010u; -} -inline void TestAllTypes::clear_has_optional_sint32() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TestAllTypes::clear_optional_sint32() { - optional_sint32_ = 0; - clear_has_optional_sint32(); -} -inline ::google::protobuf::int32 TestAllTypes::optional_sint32() const { - return optional_sint32_; -} -inline void TestAllTypes::set_optional_sint32(::google::protobuf::int32 value) { - set_has_optional_sint32(); - optional_sint32_ = value; -} - -// optional sint64 optional_sint64 = 6; -inline bool TestAllTypes::has_optional_sint64() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void TestAllTypes::set_has_optional_sint64() { - _has_bits_[0] |= 0x00000020u; -} -inline void TestAllTypes::clear_has_optional_sint64() { - _has_bits_[0] &= ~0x00000020u; -} -inline void TestAllTypes::clear_optional_sint64() { - optional_sint64_ = GOOGLE_LONGLONG(0); - clear_has_optional_sint64(); -} -inline ::google::protobuf::int64 TestAllTypes::optional_sint64() const { - return optional_sint64_; -} -inline void TestAllTypes::set_optional_sint64(::google::protobuf::int64 value) { - set_has_optional_sint64(); - optional_sint64_ = value; -} - -// optional fixed32 optional_fixed32 = 7; -inline bool TestAllTypes::has_optional_fixed32() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void TestAllTypes::set_has_optional_fixed32() { - _has_bits_[0] |= 0x00000040u; -} -inline void TestAllTypes::clear_has_optional_fixed32() { - _has_bits_[0] &= ~0x00000040u; -} -inline void TestAllTypes::clear_optional_fixed32() { - optional_fixed32_ = 0u; - clear_has_optional_fixed32(); -} -inline ::google::protobuf::uint32 TestAllTypes::optional_fixed32() const { - return optional_fixed32_; -} -inline void TestAllTypes::set_optional_fixed32(::google::protobuf::uint32 value) { - set_has_optional_fixed32(); - optional_fixed32_ = value; -} - -// optional fixed64 optional_fixed64 = 8; -inline bool TestAllTypes::has_optional_fixed64() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void TestAllTypes::set_has_optional_fixed64() { - _has_bits_[0] |= 0x00000080u; -} -inline void TestAllTypes::clear_has_optional_fixed64() { - _has_bits_[0] &= ~0x00000080u; -} -inline void TestAllTypes::clear_optional_fixed64() { - optional_fixed64_ = GOOGLE_ULONGLONG(0); - clear_has_optional_fixed64(); -} -inline ::google::protobuf::uint64 TestAllTypes::optional_fixed64() const { - return optional_fixed64_; -} -inline void TestAllTypes::set_optional_fixed64(::google::protobuf::uint64 value) { - set_has_optional_fixed64(); - optional_fixed64_ = value; -} - -// optional sfixed32 optional_sfixed32 = 9; -inline bool TestAllTypes::has_optional_sfixed32() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void TestAllTypes::set_has_optional_sfixed32() { - _has_bits_[0] |= 0x00000100u; -} -inline void TestAllTypes::clear_has_optional_sfixed32() { - _has_bits_[0] &= ~0x00000100u; -} -inline void TestAllTypes::clear_optional_sfixed32() { - optional_sfixed32_ = 0; - clear_has_optional_sfixed32(); -} -inline ::google::protobuf::int32 TestAllTypes::optional_sfixed32() const { - return optional_sfixed32_; -} -inline void TestAllTypes::set_optional_sfixed32(::google::protobuf::int32 value) { - set_has_optional_sfixed32(); - optional_sfixed32_ = value; -} - -// optional sfixed64 optional_sfixed64 = 10; -inline bool TestAllTypes::has_optional_sfixed64() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void TestAllTypes::set_has_optional_sfixed64() { - _has_bits_[0] |= 0x00000200u; -} -inline void TestAllTypes::clear_has_optional_sfixed64() { - _has_bits_[0] &= ~0x00000200u; -} -inline void TestAllTypes::clear_optional_sfixed64() { - optional_sfixed64_ = GOOGLE_LONGLONG(0); - clear_has_optional_sfixed64(); -} -inline ::google::protobuf::int64 TestAllTypes::optional_sfixed64() const { - return optional_sfixed64_; -} -inline void TestAllTypes::set_optional_sfixed64(::google::protobuf::int64 value) { - set_has_optional_sfixed64(); - optional_sfixed64_ = value; -} - -// optional float optional_float = 11; -inline bool TestAllTypes::has_optional_float() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void TestAllTypes::set_has_optional_float() { - _has_bits_[0] |= 0x00000400u; -} -inline void TestAllTypes::clear_has_optional_float() { - _has_bits_[0] &= ~0x00000400u; -} -inline void TestAllTypes::clear_optional_float() { - optional_float_ = 0; - clear_has_optional_float(); -} -inline float TestAllTypes::optional_float() const { - return optional_float_; -} -inline void TestAllTypes::set_optional_float(float value) { - set_has_optional_float(); - optional_float_ = value; -} - -// optional double optional_double = 12; -inline bool TestAllTypes::has_optional_double() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void TestAllTypes::set_has_optional_double() { - _has_bits_[0] |= 0x00000800u; -} -inline void TestAllTypes::clear_has_optional_double() { - _has_bits_[0] &= ~0x00000800u; -} -inline void TestAllTypes::clear_optional_double() { - optional_double_ = 0; - clear_has_optional_double(); -} -inline double TestAllTypes::optional_double() const { - return optional_double_; -} -inline void TestAllTypes::set_optional_double(double value) { - set_has_optional_double(); - optional_double_ = value; -} - -// optional bool optional_bool = 13; -inline bool TestAllTypes::has_optional_bool() const { - return (_has_bits_[0] & 0x00001000u) != 0; -} -inline void TestAllTypes::set_has_optional_bool() { - _has_bits_[0] |= 0x00001000u; -} -inline void TestAllTypes::clear_has_optional_bool() { - _has_bits_[0] &= ~0x00001000u; -} -inline void TestAllTypes::clear_optional_bool() { - optional_bool_ = false; - clear_has_optional_bool(); -} -inline bool TestAllTypes::optional_bool() const { - return optional_bool_; -} -inline void TestAllTypes::set_optional_bool(bool value) { - set_has_optional_bool(); - optional_bool_ = value; -} - -// optional string optional_string = 14; -inline bool TestAllTypes::has_optional_string() const { - return (_has_bits_[0] & 0x00002000u) != 0; -} -inline void TestAllTypes::set_has_optional_string() { - _has_bits_[0] |= 0x00002000u; -} -inline void TestAllTypes::clear_has_optional_string() { - _has_bits_[0] &= ~0x00002000u; -} -inline void TestAllTypes::clear_optional_string() { - if (optional_string_ != &::google::protobuf::internal::kEmptyString) { - optional_string_->clear(); - } - clear_has_optional_string(); -} -inline const ::std::string& TestAllTypes::optional_string() const { - return *optional_string_; -} -inline void TestAllTypes::set_optional_string(const ::std::string& value) { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - optional_string_->assign(value); -} -inline void TestAllTypes::set_optional_string(const char* value) { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - optional_string_->assign(value); -} -inline void TestAllTypes::set_optional_string(const char* value, size_t size) { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - optional_string_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_optional_string() { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - return optional_string_; -} -inline ::std::string* TestAllTypes::release_optional_string() { - clear_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_string_; - optional_string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional bytes optional_bytes = 15; -inline bool TestAllTypes::has_optional_bytes() const { - return (_has_bits_[0] & 0x00004000u) != 0; -} -inline void TestAllTypes::set_has_optional_bytes() { - _has_bits_[0] |= 0x00004000u; -} -inline void TestAllTypes::clear_has_optional_bytes() { - _has_bits_[0] &= ~0x00004000u; -} -inline void TestAllTypes::clear_optional_bytes() { - if (optional_bytes_ != &::google::protobuf::internal::kEmptyString) { - optional_bytes_->clear(); - } - clear_has_optional_bytes(); -} -inline const ::std::string& TestAllTypes::optional_bytes() const { - return *optional_bytes_; -} -inline void TestAllTypes::set_optional_bytes(const ::std::string& value) { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - optional_bytes_->assign(value); -} -inline void TestAllTypes::set_optional_bytes(const char* value) { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - optional_bytes_->assign(value); -} -inline void TestAllTypes::set_optional_bytes(const void* value, size_t size) { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - optional_bytes_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_optional_bytes() { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - return optional_bytes_; -} -inline ::std::string* TestAllTypes::release_optional_bytes() { - clear_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_bytes_; - optional_bytes_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional group OptionalGroup = 16 { -inline bool TestAllTypes::has_optionalgroup() const { - return (_has_bits_[0] & 0x00008000u) != 0; -} -inline void TestAllTypes::set_has_optionalgroup() { - _has_bits_[0] |= 0x00008000u; -} -inline void TestAllTypes::clear_has_optionalgroup() { - _has_bits_[0] &= ~0x00008000u; -} -inline void TestAllTypes::clear_optionalgroup() { - if (optionalgroup_ != NULL) optionalgroup_->::protobuf_unittest::TestAllTypes_OptionalGroup::Clear(); - clear_has_optionalgroup(); -} -inline const ::protobuf_unittest::TestAllTypes_OptionalGroup& TestAllTypes::optionalgroup() const { - return optionalgroup_ != NULL ? *optionalgroup_ : *default_instance_->optionalgroup_; -} -inline ::protobuf_unittest::TestAllTypes_OptionalGroup* TestAllTypes::mutable_optionalgroup() { - set_has_optionalgroup(); - if (optionalgroup_ == NULL) optionalgroup_ = new ::protobuf_unittest::TestAllTypes_OptionalGroup; - return optionalgroup_; -} -inline ::protobuf_unittest::TestAllTypes_OptionalGroup* TestAllTypes::release_optionalgroup() { - clear_has_optionalgroup(); - ::protobuf_unittest::TestAllTypes_OptionalGroup* temp = optionalgroup_; - optionalgroup_ = NULL; - return temp; -} - -// optional .protobuf_unittest.TestAllTypes.NestedMessage optional_nested_message = 18; -inline bool TestAllTypes::has_optional_nested_message() const { - return (_has_bits_[0] & 0x00010000u) != 0; -} -inline void TestAllTypes::set_has_optional_nested_message() { - _has_bits_[0] |= 0x00010000u; -} -inline void TestAllTypes::clear_has_optional_nested_message() { - _has_bits_[0] &= ~0x00010000u; -} -inline void TestAllTypes::clear_optional_nested_message() { - if (optional_nested_message_ != NULL) optional_nested_message_->::protobuf_unittest::TestAllTypes_NestedMessage::Clear(); - clear_has_optional_nested_message(); -} -inline const ::protobuf_unittest::TestAllTypes_NestedMessage& TestAllTypes::optional_nested_message() const { - return optional_nested_message_ != NULL ? *optional_nested_message_ : *default_instance_->optional_nested_message_; -} -inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::mutable_optional_nested_message() { - set_has_optional_nested_message(); - if (optional_nested_message_ == NULL) optional_nested_message_ = new ::protobuf_unittest::TestAllTypes_NestedMessage; - return optional_nested_message_; -} -inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::release_optional_nested_message() { - clear_has_optional_nested_message(); - ::protobuf_unittest::TestAllTypes_NestedMessage* temp = optional_nested_message_; - optional_nested_message_ = NULL; - return temp; -} - -// optional .protobuf_unittest.ForeignMessage optional_foreign_message = 19; -inline bool TestAllTypes::has_optional_foreign_message() const { - return (_has_bits_[0] & 0x00020000u) != 0; -} -inline void TestAllTypes::set_has_optional_foreign_message() { - _has_bits_[0] |= 0x00020000u; -} -inline void TestAllTypes::clear_has_optional_foreign_message() { - _has_bits_[0] &= ~0x00020000u; -} -inline void TestAllTypes::clear_optional_foreign_message() { - if (optional_foreign_message_ != NULL) optional_foreign_message_->::protobuf_unittest::ForeignMessage::Clear(); - clear_has_optional_foreign_message(); -} -inline const ::protobuf_unittest::ForeignMessage& TestAllTypes::optional_foreign_message() const { - return optional_foreign_message_ != NULL ? *optional_foreign_message_ : *default_instance_->optional_foreign_message_; -} -inline ::protobuf_unittest::ForeignMessage* TestAllTypes::mutable_optional_foreign_message() { - set_has_optional_foreign_message(); - if (optional_foreign_message_ == NULL) optional_foreign_message_ = new ::protobuf_unittest::ForeignMessage; - return optional_foreign_message_; -} -inline ::protobuf_unittest::ForeignMessage* TestAllTypes::release_optional_foreign_message() { - clear_has_optional_foreign_message(); - ::protobuf_unittest::ForeignMessage* temp = optional_foreign_message_; - optional_foreign_message_ = NULL; - return temp; -} - -// optional .protobuf_unittest_import.ImportMessage optional_import_message = 20; -inline bool TestAllTypes::has_optional_import_message() const { - return (_has_bits_[0] & 0x00040000u) != 0; -} -inline void TestAllTypes::set_has_optional_import_message() { - _has_bits_[0] |= 0x00040000u; -} -inline void TestAllTypes::clear_has_optional_import_message() { - _has_bits_[0] &= ~0x00040000u; -} -inline void TestAllTypes::clear_optional_import_message() { - if (optional_import_message_ != NULL) optional_import_message_->::protobuf_unittest_import::ImportMessage::Clear(); - clear_has_optional_import_message(); -} -inline const ::protobuf_unittest_import::ImportMessage& TestAllTypes::optional_import_message() const { - return optional_import_message_ != NULL ? *optional_import_message_ : *default_instance_->optional_import_message_; -} -inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::mutable_optional_import_message() { - set_has_optional_import_message(); - if (optional_import_message_ == NULL) optional_import_message_ = new ::protobuf_unittest_import::ImportMessage; - return optional_import_message_; -} -inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::release_optional_import_message() { - clear_has_optional_import_message(); - ::protobuf_unittest_import::ImportMessage* temp = optional_import_message_; - optional_import_message_ = NULL; - return temp; -} - -// optional .protobuf_unittest.TestAllTypes.NestedEnum optional_nested_enum = 21; -inline bool TestAllTypes::has_optional_nested_enum() const { - return (_has_bits_[0] & 0x00080000u) != 0; -} -inline void TestAllTypes::set_has_optional_nested_enum() { - _has_bits_[0] |= 0x00080000u; -} -inline void TestAllTypes::clear_has_optional_nested_enum() { - _has_bits_[0] &= ~0x00080000u; -} -inline void TestAllTypes::clear_optional_nested_enum() { - optional_nested_enum_ = 1; - clear_has_optional_nested_enum(); -} -inline ::protobuf_unittest::TestAllTypes_NestedEnum TestAllTypes::optional_nested_enum() const { - return static_cast< ::protobuf_unittest::TestAllTypes_NestedEnum >(optional_nested_enum_); -} -inline void TestAllTypes::set_optional_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); - set_has_optional_nested_enum(); - optional_nested_enum_ = value; -} - -// optional .protobuf_unittest.ForeignEnum optional_foreign_enum = 22; -inline bool TestAllTypes::has_optional_foreign_enum() const { - return (_has_bits_[0] & 0x00100000u) != 0; -} -inline void TestAllTypes::set_has_optional_foreign_enum() { - _has_bits_[0] |= 0x00100000u; -} -inline void TestAllTypes::clear_has_optional_foreign_enum() { - _has_bits_[0] &= ~0x00100000u; -} -inline void TestAllTypes::clear_optional_foreign_enum() { - optional_foreign_enum_ = 4; - clear_has_optional_foreign_enum(); -} -inline protobuf_unittest::ForeignEnum TestAllTypes::optional_foreign_enum() const { - return static_cast< protobuf_unittest::ForeignEnum >(optional_foreign_enum_); -} -inline void TestAllTypes::set_optional_foreign_enum(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - set_has_optional_foreign_enum(); - optional_foreign_enum_ = value; -} - -// optional .protobuf_unittest_import.ImportEnum optional_import_enum = 23; -inline bool TestAllTypes::has_optional_import_enum() const { - return (_has_bits_[0] & 0x00200000u) != 0; -} -inline void TestAllTypes::set_has_optional_import_enum() { - _has_bits_[0] |= 0x00200000u; -} -inline void TestAllTypes::clear_has_optional_import_enum() { - _has_bits_[0] &= ~0x00200000u; -} -inline void TestAllTypes::clear_optional_import_enum() { - optional_import_enum_ = 7; - clear_has_optional_import_enum(); -} -inline protobuf_unittest_import::ImportEnum TestAllTypes::optional_import_enum() const { - return static_cast< protobuf_unittest_import::ImportEnum >(optional_import_enum_); -} -inline void TestAllTypes::set_optional_import_enum(protobuf_unittest_import::ImportEnum value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); - set_has_optional_import_enum(); - optional_import_enum_ = value; -} - -// optional string optional_string_piece = 24 [ctype = STRING_PIECE]; -inline bool TestAllTypes::has_optional_string_piece() const { - return (_has_bits_[0] & 0x00400000u) != 0; -} -inline void TestAllTypes::set_has_optional_string_piece() { - _has_bits_[0] |= 0x00400000u; -} -inline void TestAllTypes::clear_has_optional_string_piece() { - _has_bits_[0] &= ~0x00400000u; -} -inline void TestAllTypes::clear_optional_string_piece() { - if (optional_string_piece_ != &::google::protobuf::internal::kEmptyString) { - optional_string_piece_->clear(); - } - clear_has_optional_string_piece(); -} -inline const ::std::string& TestAllTypes::optional_string_piece() const { - return *optional_string_piece_; -} -inline void TestAllTypes::set_optional_string_piece(const ::std::string& value) { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - optional_string_piece_->assign(value); -} -inline void TestAllTypes::set_optional_string_piece(const char* value) { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - optional_string_piece_->assign(value); -} -inline void TestAllTypes::set_optional_string_piece(const char* value, size_t size) { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - optional_string_piece_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_optional_string_piece() { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - return optional_string_piece_; -} -inline ::std::string* TestAllTypes::release_optional_string_piece() { - clear_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_string_piece_; - optional_string_piece_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string optional_cord = 25 [ctype = CORD]; -inline bool TestAllTypes::has_optional_cord() const { - return (_has_bits_[0] & 0x00800000u) != 0; -} -inline void TestAllTypes::set_has_optional_cord() { - _has_bits_[0] |= 0x00800000u; -} -inline void TestAllTypes::clear_has_optional_cord() { - _has_bits_[0] &= ~0x00800000u; -} -inline void TestAllTypes::clear_optional_cord() { - if (optional_cord_ != &::google::protobuf::internal::kEmptyString) { - optional_cord_->clear(); - } - clear_has_optional_cord(); -} -inline const ::std::string& TestAllTypes::optional_cord() const { - return *optional_cord_; -} -inline void TestAllTypes::set_optional_cord(const ::std::string& value) { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - optional_cord_->assign(value); -} -inline void TestAllTypes::set_optional_cord(const char* value) { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - optional_cord_->assign(value); -} -inline void TestAllTypes::set_optional_cord(const char* value, size_t size) { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - optional_cord_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_optional_cord() { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - return optional_cord_; -} -inline ::std::string* TestAllTypes::release_optional_cord() { - clear_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_cord_; - optional_cord_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated int32 repeated_int32 = 31; -inline int TestAllTypes::repeated_int32_size() const { - return repeated_int32_.size(); -} -inline void TestAllTypes::clear_repeated_int32() { - repeated_int32_.Clear(); -} -inline ::google::protobuf::int32 TestAllTypes::repeated_int32(int index) const { - return repeated_int32_.Get(index); -} -inline void TestAllTypes::set_repeated_int32(int index, ::google::protobuf::int32 value) { - repeated_int32_.Set(index, value); -} -inline void TestAllTypes::add_repeated_int32(::google::protobuf::int32 value) { - repeated_int32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestAllTypes::repeated_int32() const { - return repeated_int32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestAllTypes::mutable_repeated_int32() { - return &repeated_int32_; -} - -// repeated int64 repeated_int64 = 32; -inline int TestAllTypes::repeated_int64_size() const { - return repeated_int64_.size(); -} -inline void TestAllTypes::clear_repeated_int64() { - repeated_int64_.Clear(); -} -inline ::google::protobuf::int64 TestAllTypes::repeated_int64(int index) const { - return repeated_int64_.Get(index); -} -inline void TestAllTypes::set_repeated_int64(int index, ::google::protobuf::int64 value) { - repeated_int64_.Set(index, value); -} -inline void TestAllTypes::add_repeated_int64(::google::protobuf::int64 value) { - repeated_int64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestAllTypes::repeated_int64() const { - return repeated_int64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestAllTypes::mutable_repeated_int64() { - return &repeated_int64_; -} - -// repeated uint32 repeated_uint32 = 33; -inline int TestAllTypes::repeated_uint32_size() const { - return repeated_uint32_.size(); -} -inline void TestAllTypes::clear_repeated_uint32() { - repeated_uint32_.Clear(); -} -inline ::google::protobuf::uint32 TestAllTypes::repeated_uint32(int index) const { - return repeated_uint32_.Get(index); -} -inline void TestAllTypes::set_repeated_uint32(int index, ::google::protobuf::uint32 value) { - repeated_uint32_.Set(index, value); -} -inline void TestAllTypes::add_repeated_uint32(::google::protobuf::uint32 value) { - repeated_uint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestAllTypes::repeated_uint32() const { - return repeated_uint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestAllTypes::mutable_repeated_uint32() { - return &repeated_uint32_; -} - -// repeated uint64 repeated_uint64 = 34; -inline int TestAllTypes::repeated_uint64_size() const { - return repeated_uint64_.size(); -} -inline void TestAllTypes::clear_repeated_uint64() { - repeated_uint64_.Clear(); -} -inline ::google::protobuf::uint64 TestAllTypes::repeated_uint64(int index) const { - return repeated_uint64_.Get(index); -} -inline void TestAllTypes::set_repeated_uint64(int index, ::google::protobuf::uint64 value) { - repeated_uint64_.Set(index, value); -} -inline void TestAllTypes::add_repeated_uint64(::google::protobuf::uint64 value) { - repeated_uint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestAllTypes::repeated_uint64() const { - return repeated_uint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestAllTypes::mutable_repeated_uint64() { - return &repeated_uint64_; -} - -// repeated sint32 repeated_sint32 = 35; -inline int TestAllTypes::repeated_sint32_size() const { - return repeated_sint32_.size(); -} -inline void TestAllTypes::clear_repeated_sint32() { - repeated_sint32_.Clear(); -} -inline ::google::protobuf::int32 TestAllTypes::repeated_sint32(int index) const { - return repeated_sint32_.Get(index); -} -inline void TestAllTypes::set_repeated_sint32(int index, ::google::protobuf::int32 value) { - repeated_sint32_.Set(index, value); -} -inline void TestAllTypes::add_repeated_sint32(::google::protobuf::int32 value) { - repeated_sint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestAllTypes::repeated_sint32() const { - return repeated_sint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestAllTypes::mutable_repeated_sint32() { - return &repeated_sint32_; -} - -// repeated sint64 repeated_sint64 = 36; -inline int TestAllTypes::repeated_sint64_size() const { - return repeated_sint64_.size(); -} -inline void TestAllTypes::clear_repeated_sint64() { - repeated_sint64_.Clear(); -} -inline ::google::protobuf::int64 TestAllTypes::repeated_sint64(int index) const { - return repeated_sint64_.Get(index); -} -inline void TestAllTypes::set_repeated_sint64(int index, ::google::protobuf::int64 value) { - repeated_sint64_.Set(index, value); -} -inline void TestAllTypes::add_repeated_sint64(::google::protobuf::int64 value) { - repeated_sint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestAllTypes::repeated_sint64() const { - return repeated_sint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestAllTypes::mutable_repeated_sint64() { - return &repeated_sint64_; -} - -// repeated fixed32 repeated_fixed32 = 37; -inline int TestAllTypes::repeated_fixed32_size() const { - return repeated_fixed32_.size(); -} -inline void TestAllTypes::clear_repeated_fixed32() { - repeated_fixed32_.Clear(); -} -inline ::google::protobuf::uint32 TestAllTypes::repeated_fixed32(int index) const { - return repeated_fixed32_.Get(index); -} -inline void TestAllTypes::set_repeated_fixed32(int index, ::google::protobuf::uint32 value) { - repeated_fixed32_.Set(index, value); -} -inline void TestAllTypes::add_repeated_fixed32(::google::protobuf::uint32 value) { - repeated_fixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestAllTypes::repeated_fixed32() const { - return repeated_fixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestAllTypes::mutable_repeated_fixed32() { - return &repeated_fixed32_; -} - -// repeated fixed64 repeated_fixed64 = 38; -inline int TestAllTypes::repeated_fixed64_size() const { - return repeated_fixed64_.size(); -} -inline void TestAllTypes::clear_repeated_fixed64() { - repeated_fixed64_.Clear(); -} -inline ::google::protobuf::uint64 TestAllTypes::repeated_fixed64(int index) const { - return repeated_fixed64_.Get(index); -} -inline void TestAllTypes::set_repeated_fixed64(int index, ::google::protobuf::uint64 value) { - repeated_fixed64_.Set(index, value); -} -inline void TestAllTypes::add_repeated_fixed64(::google::protobuf::uint64 value) { - repeated_fixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestAllTypes::repeated_fixed64() const { - return repeated_fixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestAllTypes::mutable_repeated_fixed64() { - return &repeated_fixed64_; -} - -// repeated sfixed32 repeated_sfixed32 = 39; -inline int TestAllTypes::repeated_sfixed32_size() const { - return repeated_sfixed32_.size(); -} -inline void TestAllTypes::clear_repeated_sfixed32() { - repeated_sfixed32_.Clear(); -} -inline ::google::protobuf::int32 TestAllTypes::repeated_sfixed32(int index) const { - return repeated_sfixed32_.Get(index); -} -inline void TestAllTypes::set_repeated_sfixed32(int index, ::google::protobuf::int32 value) { - repeated_sfixed32_.Set(index, value); -} -inline void TestAllTypes::add_repeated_sfixed32(::google::protobuf::int32 value) { - repeated_sfixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestAllTypes::repeated_sfixed32() const { - return repeated_sfixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestAllTypes::mutable_repeated_sfixed32() { - return &repeated_sfixed32_; -} - -// repeated sfixed64 repeated_sfixed64 = 40; -inline int TestAllTypes::repeated_sfixed64_size() const { - return repeated_sfixed64_.size(); -} -inline void TestAllTypes::clear_repeated_sfixed64() { - repeated_sfixed64_.Clear(); -} -inline ::google::protobuf::int64 TestAllTypes::repeated_sfixed64(int index) const { - return repeated_sfixed64_.Get(index); -} -inline void TestAllTypes::set_repeated_sfixed64(int index, ::google::protobuf::int64 value) { - repeated_sfixed64_.Set(index, value); -} -inline void TestAllTypes::add_repeated_sfixed64(::google::protobuf::int64 value) { - repeated_sfixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestAllTypes::repeated_sfixed64() const { - return repeated_sfixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestAllTypes::mutable_repeated_sfixed64() { - return &repeated_sfixed64_; -} - -// repeated float repeated_float = 41; -inline int TestAllTypes::repeated_float_size() const { - return repeated_float_.size(); -} -inline void TestAllTypes::clear_repeated_float() { - repeated_float_.Clear(); -} -inline float TestAllTypes::repeated_float(int index) const { - return repeated_float_.Get(index); -} -inline void TestAllTypes::set_repeated_float(int index, float value) { - repeated_float_.Set(index, value); -} -inline void TestAllTypes::add_repeated_float(float value) { - repeated_float_.Add(value); -} -inline const ::google::protobuf::RepeatedField< float >& -TestAllTypes::repeated_float() const { - return repeated_float_; -} -inline ::google::protobuf::RepeatedField< float >* -TestAllTypes::mutable_repeated_float() { - return &repeated_float_; -} - -// repeated double repeated_double = 42; -inline int TestAllTypes::repeated_double_size() const { - return repeated_double_.size(); -} -inline void TestAllTypes::clear_repeated_double() { - repeated_double_.Clear(); -} -inline double TestAllTypes::repeated_double(int index) const { - return repeated_double_.Get(index); -} -inline void TestAllTypes::set_repeated_double(int index, double value) { - repeated_double_.Set(index, value); -} -inline void TestAllTypes::add_repeated_double(double value) { - repeated_double_.Add(value); -} -inline const ::google::protobuf::RepeatedField< double >& -TestAllTypes::repeated_double() const { - return repeated_double_; -} -inline ::google::protobuf::RepeatedField< double >* -TestAllTypes::mutable_repeated_double() { - return &repeated_double_; -} - -// repeated bool repeated_bool = 43; -inline int TestAllTypes::repeated_bool_size() const { - return repeated_bool_.size(); -} -inline void TestAllTypes::clear_repeated_bool() { - repeated_bool_.Clear(); -} -inline bool TestAllTypes::repeated_bool(int index) const { - return repeated_bool_.Get(index); -} -inline void TestAllTypes::set_repeated_bool(int index, bool value) { - repeated_bool_.Set(index, value); -} -inline void TestAllTypes::add_repeated_bool(bool value) { - repeated_bool_.Add(value); -} -inline const ::google::protobuf::RepeatedField< bool >& -TestAllTypes::repeated_bool() const { - return repeated_bool_; -} -inline ::google::protobuf::RepeatedField< bool >* -TestAllTypes::mutable_repeated_bool() { - return &repeated_bool_; -} - -// repeated string repeated_string = 44; -inline int TestAllTypes::repeated_string_size() const { - return repeated_string_.size(); -} -inline void TestAllTypes::clear_repeated_string() { - repeated_string_.Clear(); -} -inline const ::std::string& TestAllTypes::repeated_string(int index) const { - return repeated_string_.Get(index); -} -inline ::std::string* TestAllTypes::mutable_repeated_string(int index) { - return repeated_string_.Mutable(index); -} -inline void TestAllTypes::set_repeated_string(int index, const ::std::string& value) { - repeated_string_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_string(int index, const char* value) { - repeated_string_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_string(int index, const char* value, size_t size) { - repeated_string_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::add_repeated_string() { - return repeated_string_.Add(); -} -inline void TestAllTypes::add_repeated_string(const ::std::string& value) { - repeated_string_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_string(const char* value) { - repeated_string_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_string(const char* value, size_t size) { - repeated_string_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypes::repeated_string() const { - return repeated_string_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypes::mutable_repeated_string() { - return &repeated_string_; -} - -// repeated bytes repeated_bytes = 45; -inline int TestAllTypes::repeated_bytes_size() const { - return repeated_bytes_.size(); -} -inline void TestAllTypes::clear_repeated_bytes() { - repeated_bytes_.Clear(); -} -inline const ::std::string& TestAllTypes::repeated_bytes(int index) const { - return repeated_bytes_.Get(index); -} -inline ::std::string* TestAllTypes::mutable_repeated_bytes(int index) { - return repeated_bytes_.Mutable(index); -} -inline void TestAllTypes::set_repeated_bytes(int index, const ::std::string& value) { - repeated_bytes_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_bytes(int index, const char* value) { - repeated_bytes_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_bytes(int index, const void* value, size_t size) { - repeated_bytes_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::add_repeated_bytes() { - return repeated_bytes_.Add(); -} -inline void TestAllTypes::add_repeated_bytes(const ::std::string& value) { - repeated_bytes_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_bytes(const char* value) { - repeated_bytes_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_bytes(const void* value, size_t size) { - repeated_bytes_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypes::repeated_bytes() const { - return repeated_bytes_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypes::mutable_repeated_bytes() { - return &repeated_bytes_; -} - -// repeated group RepeatedGroup = 46 { -inline int TestAllTypes::repeatedgroup_size() const { - return repeatedgroup_.size(); -} -inline void TestAllTypes::clear_repeatedgroup() { - repeatedgroup_.Clear(); -} -inline const ::protobuf_unittest::TestAllTypes_RepeatedGroup& TestAllTypes::repeatedgroup(int index) const { - return repeatedgroup_.Get(index); -} -inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* TestAllTypes::mutable_repeatedgroup(int index) { - return repeatedgroup_.Mutable(index); -} -inline ::protobuf_unittest::TestAllTypes_RepeatedGroup* TestAllTypes::add_repeatedgroup() { - return repeatedgroup_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >& -TestAllTypes::repeatedgroup() const { - return repeatedgroup_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_RepeatedGroup >* -TestAllTypes::mutable_repeatedgroup() { - return &repeatedgroup_; -} - -// repeated .protobuf_unittest.TestAllTypes.NestedMessage repeated_nested_message = 48; -inline int TestAllTypes::repeated_nested_message_size() const { - return repeated_nested_message_.size(); -} -inline void TestAllTypes::clear_repeated_nested_message() { - repeated_nested_message_.Clear(); -} -inline const ::protobuf_unittest::TestAllTypes_NestedMessage& TestAllTypes::repeated_nested_message(int index) const { - return repeated_nested_message_.Get(index); -} -inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::mutable_repeated_nested_message(int index) { - return repeated_nested_message_.Mutable(index); -} -inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestAllTypes::add_repeated_nested_message() { - return repeated_nested_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >& -TestAllTypes::repeated_nested_message() const { - return repeated_nested_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypes_NestedMessage >* -TestAllTypes::mutable_repeated_nested_message() { - return &repeated_nested_message_; -} - -// repeated .protobuf_unittest.ForeignMessage repeated_foreign_message = 49; -inline int TestAllTypes::repeated_foreign_message_size() const { - return repeated_foreign_message_.size(); -} -inline void TestAllTypes::clear_repeated_foreign_message() { - repeated_foreign_message_.Clear(); -} -inline const ::protobuf_unittest::ForeignMessage& TestAllTypes::repeated_foreign_message(int index) const { - return repeated_foreign_message_.Get(index); -} -inline ::protobuf_unittest::ForeignMessage* TestAllTypes::mutable_repeated_foreign_message(int index) { - return repeated_foreign_message_.Mutable(index); -} -inline ::protobuf_unittest::ForeignMessage* TestAllTypes::add_repeated_foreign_message() { - return repeated_foreign_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& -TestAllTypes::repeated_foreign_message() const { - return repeated_foreign_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* -TestAllTypes::mutable_repeated_foreign_message() { - return &repeated_foreign_message_; -} - -// repeated .protobuf_unittest_import.ImportMessage repeated_import_message = 50; -inline int TestAllTypes::repeated_import_message_size() const { - return repeated_import_message_.size(); -} -inline void TestAllTypes::clear_repeated_import_message() { - repeated_import_message_.Clear(); -} -inline const ::protobuf_unittest_import::ImportMessage& TestAllTypes::repeated_import_message(int index) const { - return repeated_import_message_.Get(index); -} -inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::mutable_repeated_import_message(int index) { - return repeated_import_message_.Mutable(index); -} -inline ::protobuf_unittest_import::ImportMessage* TestAllTypes::add_repeated_import_message() { - return repeated_import_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >& -TestAllTypes::repeated_import_message() const { - return repeated_import_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessage >* -TestAllTypes::mutable_repeated_import_message() { - return &repeated_import_message_; -} - -// repeated .protobuf_unittest.TestAllTypes.NestedEnum repeated_nested_enum = 51; -inline int TestAllTypes::repeated_nested_enum_size() const { - return repeated_nested_enum_.size(); -} -inline void TestAllTypes::clear_repeated_nested_enum() { - repeated_nested_enum_.Clear(); -} -inline ::protobuf_unittest::TestAllTypes_NestedEnum TestAllTypes::repeated_nested_enum(int index) const { - return static_cast< ::protobuf_unittest::TestAllTypes_NestedEnum >(repeated_nested_enum_.Get(index)); -} -inline void TestAllTypes::set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypes_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); - repeated_nested_enum_.Set(index, value); -} -inline void TestAllTypes::add_repeated_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); - repeated_nested_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestAllTypes::repeated_nested_enum() const { - return repeated_nested_enum_; -} -inline ::google::protobuf::RepeatedField* -TestAllTypes::mutable_repeated_nested_enum() { - return &repeated_nested_enum_; -} - -// repeated .protobuf_unittest.ForeignEnum repeated_foreign_enum = 52; -inline int TestAllTypes::repeated_foreign_enum_size() const { - return repeated_foreign_enum_.size(); -} -inline void TestAllTypes::clear_repeated_foreign_enum() { - repeated_foreign_enum_.Clear(); -} -inline protobuf_unittest::ForeignEnum TestAllTypes::repeated_foreign_enum(int index) const { - return static_cast< protobuf_unittest::ForeignEnum >(repeated_foreign_enum_.Get(index)); -} -inline void TestAllTypes::set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - repeated_foreign_enum_.Set(index, value); -} -inline void TestAllTypes::add_repeated_foreign_enum(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - repeated_foreign_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestAllTypes::repeated_foreign_enum() const { - return repeated_foreign_enum_; -} -inline ::google::protobuf::RepeatedField* -TestAllTypes::mutable_repeated_foreign_enum() { - return &repeated_foreign_enum_; -} - -// repeated .protobuf_unittest_import.ImportEnum repeated_import_enum = 53; -inline int TestAllTypes::repeated_import_enum_size() const { - return repeated_import_enum_.size(); -} -inline void TestAllTypes::clear_repeated_import_enum() { - repeated_import_enum_.Clear(); -} -inline protobuf_unittest_import::ImportEnum TestAllTypes::repeated_import_enum(int index) const { - return static_cast< protobuf_unittest_import::ImportEnum >(repeated_import_enum_.Get(index)); -} -inline void TestAllTypes::set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnum value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); - repeated_import_enum_.Set(index, value); -} -inline void TestAllTypes::add_repeated_import_enum(protobuf_unittest_import::ImportEnum value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); - repeated_import_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestAllTypes::repeated_import_enum() const { - return repeated_import_enum_; -} -inline ::google::protobuf::RepeatedField* -TestAllTypes::mutable_repeated_import_enum() { - return &repeated_import_enum_; -} - -// repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; -inline int TestAllTypes::repeated_string_piece_size() const { - return repeated_string_piece_.size(); -} -inline void TestAllTypes::clear_repeated_string_piece() { - repeated_string_piece_.Clear(); -} -inline const ::std::string& TestAllTypes::repeated_string_piece(int index) const { - return repeated_string_piece_.Get(index); -} -inline ::std::string* TestAllTypes::mutable_repeated_string_piece(int index) { - return repeated_string_piece_.Mutable(index); -} -inline void TestAllTypes::set_repeated_string_piece(int index, const ::std::string& value) { - repeated_string_piece_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_string_piece(int index, const char* value) { - repeated_string_piece_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_string_piece(int index, const char* value, size_t size) { - repeated_string_piece_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::add_repeated_string_piece() { - return repeated_string_piece_.Add(); -} -inline void TestAllTypes::add_repeated_string_piece(const ::std::string& value) { - repeated_string_piece_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_string_piece(const char* value) { - repeated_string_piece_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_string_piece(const char* value, size_t size) { - repeated_string_piece_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypes::repeated_string_piece() const { - return repeated_string_piece_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypes::mutable_repeated_string_piece() { - return &repeated_string_piece_; -} - -// repeated string repeated_cord = 55 [ctype = CORD]; -inline int TestAllTypes::repeated_cord_size() const { - return repeated_cord_.size(); -} -inline void TestAllTypes::clear_repeated_cord() { - repeated_cord_.Clear(); -} -inline const ::std::string& TestAllTypes::repeated_cord(int index) const { - return repeated_cord_.Get(index); -} -inline ::std::string* TestAllTypes::mutable_repeated_cord(int index) { - return repeated_cord_.Mutable(index); -} -inline void TestAllTypes::set_repeated_cord(int index, const ::std::string& value) { - repeated_cord_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_cord(int index, const char* value) { - repeated_cord_.Mutable(index)->assign(value); -} -inline void TestAllTypes::set_repeated_cord(int index, const char* value, size_t size) { - repeated_cord_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::add_repeated_cord() { - return repeated_cord_.Add(); -} -inline void TestAllTypes::add_repeated_cord(const ::std::string& value) { - repeated_cord_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_cord(const char* value) { - repeated_cord_.Add()->assign(value); -} -inline void TestAllTypes::add_repeated_cord(const char* value, size_t size) { - repeated_cord_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypes::repeated_cord() const { - return repeated_cord_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypes::mutable_repeated_cord() { - return &repeated_cord_; -} - -// optional int32 default_int32 = 61 [default = 41]; -inline bool TestAllTypes::has_default_int32() const { - return (_has_bits_[1] & 0x00010000u) != 0; -} -inline void TestAllTypes::set_has_default_int32() { - _has_bits_[1] |= 0x00010000u; -} -inline void TestAllTypes::clear_has_default_int32() { - _has_bits_[1] &= ~0x00010000u; -} -inline void TestAllTypes::clear_default_int32() { - default_int32_ = 41; - clear_has_default_int32(); -} -inline ::google::protobuf::int32 TestAllTypes::default_int32() const { - return default_int32_; -} -inline void TestAllTypes::set_default_int32(::google::protobuf::int32 value) { - set_has_default_int32(); - default_int32_ = value; -} - -// optional int64 default_int64 = 62 [default = 42]; -inline bool TestAllTypes::has_default_int64() const { - return (_has_bits_[1] & 0x00020000u) != 0; -} -inline void TestAllTypes::set_has_default_int64() { - _has_bits_[1] |= 0x00020000u; -} -inline void TestAllTypes::clear_has_default_int64() { - _has_bits_[1] &= ~0x00020000u; -} -inline void TestAllTypes::clear_default_int64() { - default_int64_ = GOOGLE_LONGLONG(42); - clear_has_default_int64(); -} -inline ::google::protobuf::int64 TestAllTypes::default_int64() const { - return default_int64_; -} -inline void TestAllTypes::set_default_int64(::google::protobuf::int64 value) { - set_has_default_int64(); - default_int64_ = value; -} - -// optional uint32 default_uint32 = 63 [default = 43]; -inline bool TestAllTypes::has_default_uint32() const { - return (_has_bits_[1] & 0x00040000u) != 0; -} -inline void TestAllTypes::set_has_default_uint32() { - _has_bits_[1] |= 0x00040000u; -} -inline void TestAllTypes::clear_has_default_uint32() { - _has_bits_[1] &= ~0x00040000u; -} -inline void TestAllTypes::clear_default_uint32() { - default_uint32_ = 43u; - clear_has_default_uint32(); -} -inline ::google::protobuf::uint32 TestAllTypes::default_uint32() const { - return default_uint32_; -} -inline void TestAllTypes::set_default_uint32(::google::protobuf::uint32 value) { - set_has_default_uint32(); - default_uint32_ = value; -} - -// optional uint64 default_uint64 = 64 [default = 44]; -inline bool TestAllTypes::has_default_uint64() const { - return (_has_bits_[1] & 0x00080000u) != 0; -} -inline void TestAllTypes::set_has_default_uint64() { - _has_bits_[1] |= 0x00080000u; -} -inline void TestAllTypes::clear_has_default_uint64() { - _has_bits_[1] &= ~0x00080000u; -} -inline void TestAllTypes::clear_default_uint64() { - default_uint64_ = GOOGLE_ULONGLONG(44); - clear_has_default_uint64(); -} -inline ::google::protobuf::uint64 TestAllTypes::default_uint64() const { - return default_uint64_; -} -inline void TestAllTypes::set_default_uint64(::google::protobuf::uint64 value) { - set_has_default_uint64(); - default_uint64_ = value; -} - -// optional sint32 default_sint32 = 65 [default = -45]; -inline bool TestAllTypes::has_default_sint32() const { - return (_has_bits_[1] & 0x00100000u) != 0; -} -inline void TestAllTypes::set_has_default_sint32() { - _has_bits_[1] |= 0x00100000u; -} -inline void TestAllTypes::clear_has_default_sint32() { - _has_bits_[1] &= ~0x00100000u; -} -inline void TestAllTypes::clear_default_sint32() { - default_sint32_ = -45; - clear_has_default_sint32(); -} -inline ::google::protobuf::int32 TestAllTypes::default_sint32() const { - return default_sint32_; -} -inline void TestAllTypes::set_default_sint32(::google::protobuf::int32 value) { - set_has_default_sint32(); - default_sint32_ = value; -} - -// optional sint64 default_sint64 = 66 [default = 46]; -inline bool TestAllTypes::has_default_sint64() const { - return (_has_bits_[1] & 0x00200000u) != 0; -} -inline void TestAllTypes::set_has_default_sint64() { - _has_bits_[1] |= 0x00200000u; -} -inline void TestAllTypes::clear_has_default_sint64() { - _has_bits_[1] &= ~0x00200000u; -} -inline void TestAllTypes::clear_default_sint64() { - default_sint64_ = GOOGLE_LONGLONG(46); - clear_has_default_sint64(); -} -inline ::google::protobuf::int64 TestAllTypes::default_sint64() const { - return default_sint64_; -} -inline void TestAllTypes::set_default_sint64(::google::protobuf::int64 value) { - set_has_default_sint64(); - default_sint64_ = value; -} - -// optional fixed32 default_fixed32 = 67 [default = 47]; -inline bool TestAllTypes::has_default_fixed32() const { - return (_has_bits_[1] & 0x00400000u) != 0; -} -inline void TestAllTypes::set_has_default_fixed32() { - _has_bits_[1] |= 0x00400000u; -} -inline void TestAllTypes::clear_has_default_fixed32() { - _has_bits_[1] &= ~0x00400000u; -} -inline void TestAllTypes::clear_default_fixed32() { - default_fixed32_ = 47u; - clear_has_default_fixed32(); -} -inline ::google::protobuf::uint32 TestAllTypes::default_fixed32() const { - return default_fixed32_; -} -inline void TestAllTypes::set_default_fixed32(::google::protobuf::uint32 value) { - set_has_default_fixed32(); - default_fixed32_ = value; -} - -// optional fixed64 default_fixed64 = 68 [default = 48]; -inline bool TestAllTypes::has_default_fixed64() const { - return (_has_bits_[1] & 0x00800000u) != 0; -} -inline void TestAllTypes::set_has_default_fixed64() { - _has_bits_[1] |= 0x00800000u; -} -inline void TestAllTypes::clear_has_default_fixed64() { - _has_bits_[1] &= ~0x00800000u; -} -inline void TestAllTypes::clear_default_fixed64() { - default_fixed64_ = GOOGLE_ULONGLONG(48); - clear_has_default_fixed64(); -} -inline ::google::protobuf::uint64 TestAllTypes::default_fixed64() const { - return default_fixed64_; -} -inline void TestAllTypes::set_default_fixed64(::google::protobuf::uint64 value) { - set_has_default_fixed64(); - default_fixed64_ = value; -} - -// optional sfixed32 default_sfixed32 = 69 [default = 49]; -inline bool TestAllTypes::has_default_sfixed32() const { - return (_has_bits_[1] & 0x01000000u) != 0; -} -inline void TestAllTypes::set_has_default_sfixed32() { - _has_bits_[1] |= 0x01000000u; -} -inline void TestAllTypes::clear_has_default_sfixed32() { - _has_bits_[1] &= ~0x01000000u; -} -inline void TestAllTypes::clear_default_sfixed32() { - default_sfixed32_ = 49; - clear_has_default_sfixed32(); -} -inline ::google::protobuf::int32 TestAllTypes::default_sfixed32() const { - return default_sfixed32_; -} -inline void TestAllTypes::set_default_sfixed32(::google::protobuf::int32 value) { - set_has_default_sfixed32(); - default_sfixed32_ = value; -} - -// optional sfixed64 default_sfixed64 = 70 [default = -50]; -inline bool TestAllTypes::has_default_sfixed64() const { - return (_has_bits_[1] & 0x02000000u) != 0; -} -inline void TestAllTypes::set_has_default_sfixed64() { - _has_bits_[1] |= 0x02000000u; -} -inline void TestAllTypes::clear_has_default_sfixed64() { - _has_bits_[1] &= ~0x02000000u; -} -inline void TestAllTypes::clear_default_sfixed64() { - default_sfixed64_ = GOOGLE_LONGLONG(-50); - clear_has_default_sfixed64(); -} -inline ::google::protobuf::int64 TestAllTypes::default_sfixed64() const { - return default_sfixed64_; -} -inline void TestAllTypes::set_default_sfixed64(::google::protobuf::int64 value) { - set_has_default_sfixed64(); - default_sfixed64_ = value; -} - -// optional float default_float = 71 [default = 51.5]; -inline bool TestAllTypes::has_default_float() const { - return (_has_bits_[1] & 0x04000000u) != 0; -} -inline void TestAllTypes::set_has_default_float() { - _has_bits_[1] |= 0x04000000u; -} -inline void TestAllTypes::clear_has_default_float() { - _has_bits_[1] &= ~0x04000000u; -} -inline void TestAllTypes::clear_default_float() { - default_float_ = 51.5f; - clear_has_default_float(); -} -inline float TestAllTypes::default_float() const { - return default_float_; -} -inline void TestAllTypes::set_default_float(float value) { - set_has_default_float(); - default_float_ = value; -} - -// optional double default_double = 72 [default = 52000]; -inline bool TestAllTypes::has_default_double() const { - return (_has_bits_[1] & 0x08000000u) != 0; -} -inline void TestAllTypes::set_has_default_double() { - _has_bits_[1] |= 0x08000000u; -} -inline void TestAllTypes::clear_has_default_double() { - _has_bits_[1] &= ~0x08000000u; -} -inline void TestAllTypes::clear_default_double() { - default_double_ = 52000; - clear_has_default_double(); -} -inline double TestAllTypes::default_double() const { - return default_double_; -} -inline void TestAllTypes::set_default_double(double value) { - set_has_default_double(); - default_double_ = value; -} - -// optional bool default_bool = 73 [default = true]; -inline bool TestAllTypes::has_default_bool() const { - return (_has_bits_[1] & 0x10000000u) != 0; -} -inline void TestAllTypes::set_has_default_bool() { - _has_bits_[1] |= 0x10000000u; -} -inline void TestAllTypes::clear_has_default_bool() { - _has_bits_[1] &= ~0x10000000u; -} -inline void TestAllTypes::clear_default_bool() { - default_bool_ = true; - clear_has_default_bool(); -} -inline bool TestAllTypes::default_bool() const { - return default_bool_; -} -inline void TestAllTypes::set_default_bool(bool value) { - set_has_default_bool(); - default_bool_ = value; -} - -// optional string default_string = 74 [default = "hello"]; -inline bool TestAllTypes::has_default_string() const { - return (_has_bits_[1] & 0x20000000u) != 0; -} -inline void TestAllTypes::set_has_default_string() { - _has_bits_[1] |= 0x20000000u; -} -inline void TestAllTypes::clear_has_default_string() { - _has_bits_[1] &= ~0x20000000u; -} -inline void TestAllTypes::clear_default_string() { - if (default_string_ != &_default_default_string_) { - default_string_->assign(_default_default_string_); - } - clear_has_default_string(); -} -inline const ::std::string& TestAllTypes::default_string() const { - return *default_string_; -} -inline void TestAllTypes::set_default_string(const ::std::string& value) { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string; - } - default_string_->assign(value); -} -inline void TestAllTypes::set_default_string(const char* value) { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string; - } - default_string_->assign(value); -} -inline void TestAllTypes::set_default_string(const char* value, size_t size) { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string; - } - default_string_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_default_string() { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string(_default_default_string_); - } - return default_string_; -} -inline ::std::string* TestAllTypes::release_default_string() { - clear_has_default_string(); - if (default_string_ == &_default_default_string_) { - return NULL; - } else { - ::std::string* temp = default_string_; - default_string_ = const_cast< ::std::string*>(&_default_default_string_); - return temp; - } -} - -// optional bytes default_bytes = 75 [default = "world"]; -inline bool TestAllTypes::has_default_bytes() const { - return (_has_bits_[1] & 0x40000000u) != 0; -} -inline void TestAllTypes::set_has_default_bytes() { - _has_bits_[1] |= 0x40000000u; -} -inline void TestAllTypes::clear_has_default_bytes() { - _has_bits_[1] &= ~0x40000000u; -} -inline void TestAllTypes::clear_default_bytes() { - if (default_bytes_ != &_default_default_bytes_) { - default_bytes_->assign(_default_default_bytes_); - } - clear_has_default_bytes(); -} -inline const ::std::string& TestAllTypes::default_bytes() const { - return *default_bytes_; -} -inline void TestAllTypes::set_default_bytes(const ::std::string& value) { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string; - } - default_bytes_->assign(value); -} -inline void TestAllTypes::set_default_bytes(const char* value) { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string; - } - default_bytes_->assign(value); -} -inline void TestAllTypes::set_default_bytes(const void* value, size_t size) { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string; - } - default_bytes_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_default_bytes() { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string(_default_default_bytes_); - } - return default_bytes_; -} -inline ::std::string* TestAllTypes::release_default_bytes() { - clear_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - return NULL; - } else { - ::std::string* temp = default_bytes_; - default_bytes_ = const_cast< ::std::string*>(&_default_default_bytes_); - return temp; - } -} - -// optional .protobuf_unittest.TestAllTypes.NestedEnum default_nested_enum = 81 [default = BAR]; -inline bool TestAllTypes::has_default_nested_enum() const { - return (_has_bits_[1] & 0x80000000u) != 0; -} -inline void TestAllTypes::set_has_default_nested_enum() { - _has_bits_[1] |= 0x80000000u; -} -inline void TestAllTypes::clear_has_default_nested_enum() { - _has_bits_[1] &= ~0x80000000u; -} -inline void TestAllTypes::clear_default_nested_enum() { - default_nested_enum_ = 2; - clear_has_default_nested_enum(); -} -inline ::protobuf_unittest::TestAllTypes_NestedEnum TestAllTypes::default_nested_enum() const { - return static_cast< ::protobuf_unittest::TestAllTypes_NestedEnum >(default_nested_enum_); -} -inline void TestAllTypes::set_default_nested_enum(::protobuf_unittest::TestAllTypes_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypes_NestedEnum_IsValid(value)); - set_has_default_nested_enum(); - default_nested_enum_ = value; -} - -// optional .protobuf_unittest.ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; -inline bool TestAllTypes::has_default_foreign_enum() const { - return (_has_bits_[2] & 0x00000001u) != 0; -} -inline void TestAllTypes::set_has_default_foreign_enum() { - _has_bits_[2] |= 0x00000001u; -} -inline void TestAllTypes::clear_has_default_foreign_enum() { - _has_bits_[2] &= ~0x00000001u; -} -inline void TestAllTypes::clear_default_foreign_enum() { - default_foreign_enum_ = 5; - clear_has_default_foreign_enum(); -} -inline protobuf_unittest::ForeignEnum TestAllTypes::default_foreign_enum() const { - return static_cast< protobuf_unittest::ForeignEnum >(default_foreign_enum_); -} -inline void TestAllTypes::set_default_foreign_enum(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - set_has_default_foreign_enum(); - default_foreign_enum_ = value; -} - -// optional .protobuf_unittest_import.ImportEnum default_import_enum = 83 [default = IMPORT_BAR]; -inline bool TestAllTypes::has_default_import_enum() const { - return (_has_bits_[2] & 0x00000002u) != 0; -} -inline void TestAllTypes::set_has_default_import_enum() { - _has_bits_[2] |= 0x00000002u; -} -inline void TestAllTypes::clear_has_default_import_enum() { - _has_bits_[2] &= ~0x00000002u; -} -inline void TestAllTypes::clear_default_import_enum() { - default_import_enum_ = 8; - clear_has_default_import_enum(); -} -inline protobuf_unittest_import::ImportEnum TestAllTypes::default_import_enum() const { - return static_cast< protobuf_unittest_import::ImportEnum >(default_import_enum_); -} -inline void TestAllTypes::set_default_import_enum(protobuf_unittest_import::ImportEnum value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnum_IsValid(value)); - set_has_default_import_enum(); - default_import_enum_ = value; -} - -// optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; -inline bool TestAllTypes::has_default_string_piece() const { - return (_has_bits_[2] & 0x00000004u) != 0; -} -inline void TestAllTypes::set_has_default_string_piece() { - _has_bits_[2] |= 0x00000004u; -} -inline void TestAllTypes::clear_has_default_string_piece() { - _has_bits_[2] &= ~0x00000004u; -} -inline void TestAllTypes::clear_default_string_piece() { - if (default_string_piece_ != &_default_default_string_piece_) { - default_string_piece_->assign(_default_default_string_piece_); - } - clear_has_default_string_piece(); -} -inline const ::std::string& TestAllTypes::default_string_piece() const { - return *default_string_piece_; -} -inline void TestAllTypes::set_default_string_piece(const ::std::string& value) { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string; - } - default_string_piece_->assign(value); -} -inline void TestAllTypes::set_default_string_piece(const char* value) { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string; - } - default_string_piece_->assign(value); -} -inline void TestAllTypes::set_default_string_piece(const char* value, size_t size) { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string; - } - default_string_piece_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_default_string_piece() { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string(_default_default_string_piece_); - } - return default_string_piece_; -} -inline ::std::string* TestAllTypes::release_default_string_piece() { - clear_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - return NULL; - } else { - ::std::string* temp = default_string_piece_; - default_string_piece_ = const_cast< ::std::string*>(&_default_default_string_piece_); - return temp; - } -} - -// optional string default_cord = 85 [default = "123", ctype = CORD]; -inline bool TestAllTypes::has_default_cord() const { - return (_has_bits_[2] & 0x00000008u) != 0; -} -inline void TestAllTypes::set_has_default_cord() { - _has_bits_[2] |= 0x00000008u; -} -inline void TestAllTypes::clear_has_default_cord() { - _has_bits_[2] &= ~0x00000008u; -} -inline void TestAllTypes::clear_default_cord() { - if (default_cord_ != &_default_default_cord_) { - default_cord_->assign(_default_default_cord_); - } - clear_has_default_cord(); -} -inline const ::std::string& TestAllTypes::default_cord() const { - return *default_cord_; -} -inline void TestAllTypes::set_default_cord(const ::std::string& value) { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string; - } - default_cord_->assign(value); -} -inline void TestAllTypes::set_default_cord(const char* value) { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string; - } - default_cord_->assign(value); -} -inline void TestAllTypes::set_default_cord(const char* value, size_t size) { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string; - } - default_cord_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypes::mutable_default_cord() { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string(_default_default_cord_); - } - return default_cord_; -} -inline ::std::string* TestAllTypes::release_default_cord() { - clear_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - return NULL; - } else { - ::std::string* temp = default_cord_; - default_cord_ = const_cast< ::std::string*>(&_default_default_cord_); - return temp; - } -} - -// ------------------------------------------------------------------- - -// TestDeprecatedFields - -// optional int32 deprecated_int32 = 1 [deprecated = true]; -inline bool TestDeprecatedFields::has_deprecated_int32() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestDeprecatedFields::set_has_deprecated_int32() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestDeprecatedFields::clear_has_deprecated_int32() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestDeprecatedFields::clear_deprecated_int32() { - deprecated_int32_ = 0; - clear_has_deprecated_int32(); -} -inline ::google::protobuf::int32 TestDeprecatedFields::deprecated_int32() const { - return deprecated_int32_; -} -inline void TestDeprecatedFields::set_deprecated_int32(::google::protobuf::int32 value) { - set_has_deprecated_int32(); - deprecated_int32_ = value; -} - -// ------------------------------------------------------------------- - -// ForeignMessage - -// optional int32 c = 1; -inline bool ForeignMessage::has_c() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ForeignMessage::set_has_c() { - _has_bits_[0] |= 0x00000001u; -} -inline void ForeignMessage::clear_has_c() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ForeignMessage::clear_c() { - c_ = 0; - clear_has_c(); -} -inline ::google::protobuf::int32 ForeignMessage::c() const { - return c_; -} -inline void ForeignMessage::set_c(::google::protobuf::int32 value) { - set_has_c(); - c_ = value; -} - -// ------------------------------------------------------------------- - -// TestAllExtensions - -// ------------------------------------------------------------------- - -// OptionalGroup_extension - -// optional int32 a = 17; -inline bool OptionalGroup_extension::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void OptionalGroup_extension::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void OptionalGroup_extension::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void OptionalGroup_extension::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 OptionalGroup_extension::a() const { - return a_; -} -inline void OptionalGroup_extension::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// RepeatedGroup_extension - -// optional int32 a = 47; -inline bool RepeatedGroup_extension::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void RepeatedGroup_extension::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void RepeatedGroup_extension::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void RepeatedGroup_extension::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 RepeatedGroup_extension::a() const { - return a_; -} -inline void RepeatedGroup_extension::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestNestedExtension - -// ------------------------------------------------------------------- - -// TestRequired - -// required int32 a = 1; -inline bool TestRequired::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestRequired::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestRequired::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestRequired::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestRequired::a() const { - return a_; -} -inline void TestRequired::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// optional int32 dummy2 = 2; -inline bool TestRequired::has_dummy2() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestRequired::set_has_dummy2() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestRequired::clear_has_dummy2() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestRequired::clear_dummy2() { - dummy2_ = 0; - clear_has_dummy2(); -} -inline ::google::protobuf::int32 TestRequired::dummy2() const { - return dummy2_; -} -inline void TestRequired::set_dummy2(::google::protobuf::int32 value) { - set_has_dummy2(); - dummy2_ = value; -} - -// required int32 b = 3; -inline bool TestRequired::has_b() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestRequired::set_has_b() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestRequired::clear_has_b() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestRequired::clear_b() { - b_ = 0; - clear_has_b(); -} -inline ::google::protobuf::int32 TestRequired::b() const { - return b_; -} -inline void TestRequired::set_b(::google::protobuf::int32 value) { - set_has_b(); - b_ = value; -} - -// optional int32 dummy4 = 4; -inline bool TestRequired::has_dummy4() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void TestRequired::set_has_dummy4() { - _has_bits_[0] |= 0x00000008u; -} -inline void TestRequired::clear_has_dummy4() { - _has_bits_[0] &= ~0x00000008u; -} -inline void TestRequired::clear_dummy4() { - dummy4_ = 0; - clear_has_dummy4(); -} -inline ::google::protobuf::int32 TestRequired::dummy4() const { - return dummy4_; -} -inline void TestRequired::set_dummy4(::google::protobuf::int32 value) { - set_has_dummy4(); - dummy4_ = value; -} - -// optional int32 dummy5 = 5; -inline bool TestRequired::has_dummy5() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TestRequired::set_has_dummy5() { - _has_bits_[0] |= 0x00000010u; -} -inline void TestRequired::clear_has_dummy5() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TestRequired::clear_dummy5() { - dummy5_ = 0; - clear_has_dummy5(); -} -inline ::google::protobuf::int32 TestRequired::dummy5() const { - return dummy5_; -} -inline void TestRequired::set_dummy5(::google::protobuf::int32 value) { - set_has_dummy5(); - dummy5_ = value; -} - -// optional int32 dummy6 = 6; -inline bool TestRequired::has_dummy6() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void TestRequired::set_has_dummy6() { - _has_bits_[0] |= 0x00000020u; -} -inline void TestRequired::clear_has_dummy6() { - _has_bits_[0] &= ~0x00000020u; -} -inline void TestRequired::clear_dummy6() { - dummy6_ = 0; - clear_has_dummy6(); -} -inline ::google::protobuf::int32 TestRequired::dummy6() const { - return dummy6_; -} -inline void TestRequired::set_dummy6(::google::protobuf::int32 value) { - set_has_dummy6(); - dummy6_ = value; -} - -// optional int32 dummy7 = 7; -inline bool TestRequired::has_dummy7() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void TestRequired::set_has_dummy7() { - _has_bits_[0] |= 0x00000040u; -} -inline void TestRequired::clear_has_dummy7() { - _has_bits_[0] &= ~0x00000040u; -} -inline void TestRequired::clear_dummy7() { - dummy7_ = 0; - clear_has_dummy7(); -} -inline ::google::protobuf::int32 TestRequired::dummy7() const { - return dummy7_; -} -inline void TestRequired::set_dummy7(::google::protobuf::int32 value) { - set_has_dummy7(); - dummy7_ = value; -} - -// optional int32 dummy8 = 8; -inline bool TestRequired::has_dummy8() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void TestRequired::set_has_dummy8() { - _has_bits_[0] |= 0x00000080u; -} -inline void TestRequired::clear_has_dummy8() { - _has_bits_[0] &= ~0x00000080u; -} -inline void TestRequired::clear_dummy8() { - dummy8_ = 0; - clear_has_dummy8(); -} -inline ::google::protobuf::int32 TestRequired::dummy8() const { - return dummy8_; -} -inline void TestRequired::set_dummy8(::google::protobuf::int32 value) { - set_has_dummy8(); - dummy8_ = value; -} - -// optional int32 dummy9 = 9; -inline bool TestRequired::has_dummy9() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void TestRequired::set_has_dummy9() { - _has_bits_[0] |= 0x00000100u; -} -inline void TestRequired::clear_has_dummy9() { - _has_bits_[0] &= ~0x00000100u; -} -inline void TestRequired::clear_dummy9() { - dummy9_ = 0; - clear_has_dummy9(); -} -inline ::google::protobuf::int32 TestRequired::dummy9() const { - return dummy9_; -} -inline void TestRequired::set_dummy9(::google::protobuf::int32 value) { - set_has_dummy9(); - dummy9_ = value; -} - -// optional int32 dummy10 = 10; -inline bool TestRequired::has_dummy10() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void TestRequired::set_has_dummy10() { - _has_bits_[0] |= 0x00000200u; -} -inline void TestRequired::clear_has_dummy10() { - _has_bits_[0] &= ~0x00000200u; -} -inline void TestRequired::clear_dummy10() { - dummy10_ = 0; - clear_has_dummy10(); -} -inline ::google::protobuf::int32 TestRequired::dummy10() const { - return dummy10_; -} -inline void TestRequired::set_dummy10(::google::protobuf::int32 value) { - set_has_dummy10(); - dummy10_ = value; -} - -// optional int32 dummy11 = 11; -inline bool TestRequired::has_dummy11() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void TestRequired::set_has_dummy11() { - _has_bits_[0] |= 0x00000400u; -} -inline void TestRequired::clear_has_dummy11() { - _has_bits_[0] &= ~0x00000400u; -} -inline void TestRequired::clear_dummy11() { - dummy11_ = 0; - clear_has_dummy11(); -} -inline ::google::protobuf::int32 TestRequired::dummy11() const { - return dummy11_; -} -inline void TestRequired::set_dummy11(::google::protobuf::int32 value) { - set_has_dummy11(); - dummy11_ = value; -} - -// optional int32 dummy12 = 12; -inline bool TestRequired::has_dummy12() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void TestRequired::set_has_dummy12() { - _has_bits_[0] |= 0x00000800u; -} -inline void TestRequired::clear_has_dummy12() { - _has_bits_[0] &= ~0x00000800u; -} -inline void TestRequired::clear_dummy12() { - dummy12_ = 0; - clear_has_dummy12(); -} -inline ::google::protobuf::int32 TestRequired::dummy12() const { - return dummy12_; -} -inline void TestRequired::set_dummy12(::google::protobuf::int32 value) { - set_has_dummy12(); - dummy12_ = value; -} - -// optional int32 dummy13 = 13; -inline bool TestRequired::has_dummy13() const { - return (_has_bits_[0] & 0x00001000u) != 0; -} -inline void TestRequired::set_has_dummy13() { - _has_bits_[0] |= 0x00001000u; -} -inline void TestRequired::clear_has_dummy13() { - _has_bits_[0] &= ~0x00001000u; -} -inline void TestRequired::clear_dummy13() { - dummy13_ = 0; - clear_has_dummy13(); -} -inline ::google::protobuf::int32 TestRequired::dummy13() const { - return dummy13_; -} -inline void TestRequired::set_dummy13(::google::protobuf::int32 value) { - set_has_dummy13(); - dummy13_ = value; -} - -// optional int32 dummy14 = 14; -inline bool TestRequired::has_dummy14() const { - return (_has_bits_[0] & 0x00002000u) != 0; -} -inline void TestRequired::set_has_dummy14() { - _has_bits_[0] |= 0x00002000u; -} -inline void TestRequired::clear_has_dummy14() { - _has_bits_[0] &= ~0x00002000u; -} -inline void TestRequired::clear_dummy14() { - dummy14_ = 0; - clear_has_dummy14(); -} -inline ::google::protobuf::int32 TestRequired::dummy14() const { - return dummy14_; -} -inline void TestRequired::set_dummy14(::google::protobuf::int32 value) { - set_has_dummy14(); - dummy14_ = value; -} - -// optional int32 dummy15 = 15; -inline bool TestRequired::has_dummy15() const { - return (_has_bits_[0] & 0x00004000u) != 0; -} -inline void TestRequired::set_has_dummy15() { - _has_bits_[0] |= 0x00004000u; -} -inline void TestRequired::clear_has_dummy15() { - _has_bits_[0] &= ~0x00004000u; -} -inline void TestRequired::clear_dummy15() { - dummy15_ = 0; - clear_has_dummy15(); -} -inline ::google::protobuf::int32 TestRequired::dummy15() const { - return dummy15_; -} -inline void TestRequired::set_dummy15(::google::protobuf::int32 value) { - set_has_dummy15(); - dummy15_ = value; -} - -// optional int32 dummy16 = 16; -inline bool TestRequired::has_dummy16() const { - return (_has_bits_[0] & 0x00008000u) != 0; -} -inline void TestRequired::set_has_dummy16() { - _has_bits_[0] |= 0x00008000u; -} -inline void TestRequired::clear_has_dummy16() { - _has_bits_[0] &= ~0x00008000u; -} -inline void TestRequired::clear_dummy16() { - dummy16_ = 0; - clear_has_dummy16(); -} -inline ::google::protobuf::int32 TestRequired::dummy16() const { - return dummy16_; -} -inline void TestRequired::set_dummy16(::google::protobuf::int32 value) { - set_has_dummy16(); - dummy16_ = value; -} - -// optional int32 dummy17 = 17; -inline bool TestRequired::has_dummy17() const { - return (_has_bits_[0] & 0x00010000u) != 0; -} -inline void TestRequired::set_has_dummy17() { - _has_bits_[0] |= 0x00010000u; -} -inline void TestRequired::clear_has_dummy17() { - _has_bits_[0] &= ~0x00010000u; -} -inline void TestRequired::clear_dummy17() { - dummy17_ = 0; - clear_has_dummy17(); -} -inline ::google::protobuf::int32 TestRequired::dummy17() const { - return dummy17_; -} -inline void TestRequired::set_dummy17(::google::protobuf::int32 value) { - set_has_dummy17(); - dummy17_ = value; -} - -// optional int32 dummy18 = 18; -inline bool TestRequired::has_dummy18() const { - return (_has_bits_[0] & 0x00020000u) != 0; -} -inline void TestRequired::set_has_dummy18() { - _has_bits_[0] |= 0x00020000u; -} -inline void TestRequired::clear_has_dummy18() { - _has_bits_[0] &= ~0x00020000u; -} -inline void TestRequired::clear_dummy18() { - dummy18_ = 0; - clear_has_dummy18(); -} -inline ::google::protobuf::int32 TestRequired::dummy18() const { - return dummy18_; -} -inline void TestRequired::set_dummy18(::google::protobuf::int32 value) { - set_has_dummy18(); - dummy18_ = value; -} - -// optional int32 dummy19 = 19; -inline bool TestRequired::has_dummy19() const { - return (_has_bits_[0] & 0x00040000u) != 0; -} -inline void TestRequired::set_has_dummy19() { - _has_bits_[0] |= 0x00040000u; -} -inline void TestRequired::clear_has_dummy19() { - _has_bits_[0] &= ~0x00040000u; -} -inline void TestRequired::clear_dummy19() { - dummy19_ = 0; - clear_has_dummy19(); -} -inline ::google::protobuf::int32 TestRequired::dummy19() const { - return dummy19_; -} -inline void TestRequired::set_dummy19(::google::protobuf::int32 value) { - set_has_dummy19(); - dummy19_ = value; -} - -// optional int32 dummy20 = 20; -inline bool TestRequired::has_dummy20() const { - return (_has_bits_[0] & 0x00080000u) != 0; -} -inline void TestRequired::set_has_dummy20() { - _has_bits_[0] |= 0x00080000u; -} -inline void TestRequired::clear_has_dummy20() { - _has_bits_[0] &= ~0x00080000u; -} -inline void TestRequired::clear_dummy20() { - dummy20_ = 0; - clear_has_dummy20(); -} -inline ::google::protobuf::int32 TestRequired::dummy20() const { - return dummy20_; -} -inline void TestRequired::set_dummy20(::google::protobuf::int32 value) { - set_has_dummy20(); - dummy20_ = value; -} - -// optional int32 dummy21 = 21; -inline bool TestRequired::has_dummy21() const { - return (_has_bits_[0] & 0x00100000u) != 0; -} -inline void TestRequired::set_has_dummy21() { - _has_bits_[0] |= 0x00100000u; -} -inline void TestRequired::clear_has_dummy21() { - _has_bits_[0] &= ~0x00100000u; -} -inline void TestRequired::clear_dummy21() { - dummy21_ = 0; - clear_has_dummy21(); -} -inline ::google::protobuf::int32 TestRequired::dummy21() const { - return dummy21_; -} -inline void TestRequired::set_dummy21(::google::protobuf::int32 value) { - set_has_dummy21(); - dummy21_ = value; -} - -// optional int32 dummy22 = 22; -inline bool TestRequired::has_dummy22() const { - return (_has_bits_[0] & 0x00200000u) != 0; -} -inline void TestRequired::set_has_dummy22() { - _has_bits_[0] |= 0x00200000u; -} -inline void TestRequired::clear_has_dummy22() { - _has_bits_[0] &= ~0x00200000u; -} -inline void TestRequired::clear_dummy22() { - dummy22_ = 0; - clear_has_dummy22(); -} -inline ::google::protobuf::int32 TestRequired::dummy22() const { - return dummy22_; -} -inline void TestRequired::set_dummy22(::google::protobuf::int32 value) { - set_has_dummy22(); - dummy22_ = value; -} - -// optional int32 dummy23 = 23; -inline bool TestRequired::has_dummy23() const { - return (_has_bits_[0] & 0x00400000u) != 0; -} -inline void TestRequired::set_has_dummy23() { - _has_bits_[0] |= 0x00400000u; -} -inline void TestRequired::clear_has_dummy23() { - _has_bits_[0] &= ~0x00400000u; -} -inline void TestRequired::clear_dummy23() { - dummy23_ = 0; - clear_has_dummy23(); -} -inline ::google::protobuf::int32 TestRequired::dummy23() const { - return dummy23_; -} -inline void TestRequired::set_dummy23(::google::protobuf::int32 value) { - set_has_dummy23(); - dummy23_ = value; -} - -// optional int32 dummy24 = 24; -inline bool TestRequired::has_dummy24() const { - return (_has_bits_[0] & 0x00800000u) != 0; -} -inline void TestRequired::set_has_dummy24() { - _has_bits_[0] |= 0x00800000u; -} -inline void TestRequired::clear_has_dummy24() { - _has_bits_[0] &= ~0x00800000u; -} -inline void TestRequired::clear_dummy24() { - dummy24_ = 0; - clear_has_dummy24(); -} -inline ::google::protobuf::int32 TestRequired::dummy24() const { - return dummy24_; -} -inline void TestRequired::set_dummy24(::google::protobuf::int32 value) { - set_has_dummy24(); - dummy24_ = value; -} - -// optional int32 dummy25 = 25; -inline bool TestRequired::has_dummy25() const { - return (_has_bits_[0] & 0x01000000u) != 0; -} -inline void TestRequired::set_has_dummy25() { - _has_bits_[0] |= 0x01000000u; -} -inline void TestRequired::clear_has_dummy25() { - _has_bits_[0] &= ~0x01000000u; -} -inline void TestRequired::clear_dummy25() { - dummy25_ = 0; - clear_has_dummy25(); -} -inline ::google::protobuf::int32 TestRequired::dummy25() const { - return dummy25_; -} -inline void TestRequired::set_dummy25(::google::protobuf::int32 value) { - set_has_dummy25(); - dummy25_ = value; -} - -// optional int32 dummy26 = 26; -inline bool TestRequired::has_dummy26() const { - return (_has_bits_[0] & 0x02000000u) != 0; -} -inline void TestRequired::set_has_dummy26() { - _has_bits_[0] |= 0x02000000u; -} -inline void TestRequired::clear_has_dummy26() { - _has_bits_[0] &= ~0x02000000u; -} -inline void TestRequired::clear_dummy26() { - dummy26_ = 0; - clear_has_dummy26(); -} -inline ::google::protobuf::int32 TestRequired::dummy26() const { - return dummy26_; -} -inline void TestRequired::set_dummy26(::google::protobuf::int32 value) { - set_has_dummy26(); - dummy26_ = value; -} - -// optional int32 dummy27 = 27; -inline bool TestRequired::has_dummy27() const { - return (_has_bits_[0] & 0x04000000u) != 0; -} -inline void TestRequired::set_has_dummy27() { - _has_bits_[0] |= 0x04000000u; -} -inline void TestRequired::clear_has_dummy27() { - _has_bits_[0] &= ~0x04000000u; -} -inline void TestRequired::clear_dummy27() { - dummy27_ = 0; - clear_has_dummy27(); -} -inline ::google::protobuf::int32 TestRequired::dummy27() const { - return dummy27_; -} -inline void TestRequired::set_dummy27(::google::protobuf::int32 value) { - set_has_dummy27(); - dummy27_ = value; -} - -// optional int32 dummy28 = 28; -inline bool TestRequired::has_dummy28() const { - return (_has_bits_[0] & 0x08000000u) != 0; -} -inline void TestRequired::set_has_dummy28() { - _has_bits_[0] |= 0x08000000u; -} -inline void TestRequired::clear_has_dummy28() { - _has_bits_[0] &= ~0x08000000u; -} -inline void TestRequired::clear_dummy28() { - dummy28_ = 0; - clear_has_dummy28(); -} -inline ::google::protobuf::int32 TestRequired::dummy28() const { - return dummy28_; -} -inline void TestRequired::set_dummy28(::google::protobuf::int32 value) { - set_has_dummy28(); - dummy28_ = value; -} - -// optional int32 dummy29 = 29; -inline bool TestRequired::has_dummy29() const { - return (_has_bits_[0] & 0x10000000u) != 0; -} -inline void TestRequired::set_has_dummy29() { - _has_bits_[0] |= 0x10000000u; -} -inline void TestRequired::clear_has_dummy29() { - _has_bits_[0] &= ~0x10000000u; -} -inline void TestRequired::clear_dummy29() { - dummy29_ = 0; - clear_has_dummy29(); -} -inline ::google::protobuf::int32 TestRequired::dummy29() const { - return dummy29_; -} -inline void TestRequired::set_dummy29(::google::protobuf::int32 value) { - set_has_dummy29(); - dummy29_ = value; -} - -// optional int32 dummy30 = 30; -inline bool TestRequired::has_dummy30() const { - return (_has_bits_[0] & 0x20000000u) != 0; -} -inline void TestRequired::set_has_dummy30() { - _has_bits_[0] |= 0x20000000u; -} -inline void TestRequired::clear_has_dummy30() { - _has_bits_[0] &= ~0x20000000u; -} -inline void TestRequired::clear_dummy30() { - dummy30_ = 0; - clear_has_dummy30(); -} -inline ::google::protobuf::int32 TestRequired::dummy30() const { - return dummy30_; -} -inline void TestRequired::set_dummy30(::google::protobuf::int32 value) { - set_has_dummy30(); - dummy30_ = value; -} - -// optional int32 dummy31 = 31; -inline bool TestRequired::has_dummy31() const { - return (_has_bits_[0] & 0x40000000u) != 0; -} -inline void TestRequired::set_has_dummy31() { - _has_bits_[0] |= 0x40000000u; -} -inline void TestRequired::clear_has_dummy31() { - _has_bits_[0] &= ~0x40000000u; -} -inline void TestRequired::clear_dummy31() { - dummy31_ = 0; - clear_has_dummy31(); -} -inline ::google::protobuf::int32 TestRequired::dummy31() const { - return dummy31_; -} -inline void TestRequired::set_dummy31(::google::protobuf::int32 value) { - set_has_dummy31(); - dummy31_ = value; -} - -// optional int32 dummy32 = 32; -inline bool TestRequired::has_dummy32() const { - return (_has_bits_[0] & 0x80000000u) != 0; -} -inline void TestRequired::set_has_dummy32() { - _has_bits_[0] |= 0x80000000u; -} -inline void TestRequired::clear_has_dummy32() { - _has_bits_[0] &= ~0x80000000u; -} -inline void TestRequired::clear_dummy32() { - dummy32_ = 0; - clear_has_dummy32(); -} -inline ::google::protobuf::int32 TestRequired::dummy32() const { - return dummy32_; -} -inline void TestRequired::set_dummy32(::google::protobuf::int32 value) { - set_has_dummy32(); - dummy32_ = value; -} - -// required int32 c = 33; -inline bool TestRequired::has_c() const { - return (_has_bits_[1] & 0x00000001u) != 0; -} -inline void TestRequired::set_has_c() { - _has_bits_[1] |= 0x00000001u; -} -inline void TestRequired::clear_has_c() { - _has_bits_[1] &= ~0x00000001u; -} -inline void TestRequired::clear_c() { - c_ = 0; - clear_has_c(); -} -inline ::google::protobuf::int32 TestRequired::c() const { - return c_; -} -inline void TestRequired::set_c(::google::protobuf::int32 value) { - set_has_c(); - c_ = value; -} - -// ------------------------------------------------------------------- - -// TestRequiredForeign - -// optional .protobuf_unittest.TestRequired optional_message = 1; -inline bool TestRequiredForeign::has_optional_message() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestRequiredForeign::set_has_optional_message() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestRequiredForeign::clear_has_optional_message() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestRequiredForeign::clear_optional_message() { - if (optional_message_ != NULL) optional_message_->::protobuf_unittest::TestRequired::Clear(); - clear_has_optional_message(); -} -inline const ::protobuf_unittest::TestRequired& TestRequiredForeign::optional_message() const { - return optional_message_ != NULL ? *optional_message_ : *default_instance_->optional_message_; -} -inline ::protobuf_unittest::TestRequired* TestRequiredForeign::mutable_optional_message() { - set_has_optional_message(); - if (optional_message_ == NULL) optional_message_ = new ::protobuf_unittest::TestRequired; - return optional_message_; -} -inline ::protobuf_unittest::TestRequired* TestRequiredForeign::release_optional_message() { - clear_has_optional_message(); - ::protobuf_unittest::TestRequired* temp = optional_message_; - optional_message_ = NULL; - return temp; -} - -// repeated .protobuf_unittest.TestRequired repeated_message = 2; -inline int TestRequiredForeign::repeated_message_size() const { - return repeated_message_.size(); -} -inline void TestRequiredForeign::clear_repeated_message() { - repeated_message_.Clear(); -} -inline const ::protobuf_unittest::TestRequired& TestRequiredForeign::repeated_message(int index) const { - return repeated_message_.Get(index); -} -inline ::protobuf_unittest::TestRequired* TestRequiredForeign::mutable_repeated_message(int index) { - return repeated_message_.Mutable(index); -} -inline ::protobuf_unittest::TestRequired* TestRequiredForeign::add_repeated_message() { - return repeated_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >& -TestRequiredForeign::repeated_message() const { - return repeated_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestRequired >* -TestRequiredForeign::mutable_repeated_message() { - return &repeated_message_; -} - -// optional int32 dummy = 3; -inline bool TestRequiredForeign::has_dummy() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestRequiredForeign::set_has_dummy() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestRequiredForeign::clear_has_dummy() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestRequiredForeign::clear_dummy() { - dummy_ = 0; - clear_has_dummy(); -} -inline ::google::protobuf::int32 TestRequiredForeign::dummy() const { - return dummy_; -} -inline void TestRequiredForeign::set_dummy(::google::protobuf::int32 value) { - set_has_dummy(); - dummy_ = value; -} - -// ------------------------------------------------------------------- - -// TestForeignNested - -// optional .protobuf_unittest.TestAllTypes.NestedMessage foreign_nested = 1; -inline bool TestForeignNested::has_foreign_nested() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestForeignNested::set_has_foreign_nested() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestForeignNested::clear_has_foreign_nested() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestForeignNested::clear_foreign_nested() { - if (foreign_nested_ != NULL) foreign_nested_->::protobuf_unittest::TestAllTypes_NestedMessage::Clear(); - clear_has_foreign_nested(); -} -inline const ::protobuf_unittest::TestAllTypes_NestedMessage& TestForeignNested::foreign_nested() const { - return foreign_nested_ != NULL ? *foreign_nested_ : *default_instance_->foreign_nested_; -} -inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestForeignNested::mutable_foreign_nested() { - set_has_foreign_nested(); - if (foreign_nested_ == NULL) foreign_nested_ = new ::protobuf_unittest::TestAllTypes_NestedMessage; - return foreign_nested_; -} -inline ::protobuf_unittest::TestAllTypes_NestedMessage* TestForeignNested::release_foreign_nested() { - clear_has_foreign_nested(); - ::protobuf_unittest::TestAllTypes_NestedMessage* temp = foreign_nested_; - foreign_nested_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// TestEmptyMessage - -// ------------------------------------------------------------------- - -// TestEmptyMessageWithExtensions - -// ------------------------------------------------------------------- - -// TestMultipleExtensionRanges - -// ------------------------------------------------------------------- - -// TestReallyLargeTagNumber - -// optional int32 a = 1; -inline bool TestReallyLargeTagNumber::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestReallyLargeTagNumber::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestReallyLargeTagNumber::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestReallyLargeTagNumber::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestReallyLargeTagNumber::a() const { - return a_; -} -inline void TestReallyLargeTagNumber::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// optional int32 bb = 268435455; -inline bool TestReallyLargeTagNumber::has_bb() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestReallyLargeTagNumber::set_has_bb() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestReallyLargeTagNumber::clear_has_bb() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestReallyLargeTagNumber::clear_bb() { - bb_ = 0; - clear_has_bb(); -} -inline ::google::protobuf::int32 TestReallyLargeTagNumber::bb() const { - return bb_; -} -inline void TestReallyLargeTagNumber::set_bb(::google::protobuf::int32 value) { - set_has_bb(); - bb_ = value; -} - -// ------------------------------------------------------------------- - -// TestRecursiveMessage - -// optional .protobuf_unittest.TestRecursiveMessage a = 1; -inline bool TestRecursiveMessage::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestRecursiveMessage::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestRecursiveMessage::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestRecursiveMessage::clear_a() { - if (a_ != NULL) a_->::protobuf_unittest::TestRecursiveMessage::Clear(); - clear_has_a(); -} -inline const ::protobuf_unittest::TestRecursiveMessage& TestRecursiveMessage::a() const { - return a_ != NULL ? *a_ : *default_instance_->a_; -} -inline ::protobuf_unittest::TestRecursiveMessage* TestRecursiveMessage::mutable_a() { - set_has_a(); - if (a_ == NULL) a_ = new ::protobuf_unittest::TestRecursiveMessage; - return a_; -} -inline ::protobuf_unittest::TestRecursiveMessage* TestRecursiveMessage::release_a() { - clear_has_a(); - ::protobuf_unittest::TestRecursiveMessage* temp = a_; - a_ = NULL; - return temp; -} - -// optional int32 i = 2; -inline bool TestRecursiveMessage::has_i() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestRecursiveMessage::set_has_i() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestRecursiveMessage::clear_has_i() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestRecursiveMessage::clear_i() { - i_ = 0; - clear_has_i(); -} -inline ::google::protobuf::int32 TestRecursiveMessage::i() const { - return i_; -} -inline void TestRecursiveMessage::set_i(::google::protobuf::int32 value) { - set_has_i(); - i_ = value; -} - -// ------------------------------------------------------------------- - -// TestMutualRecursionA - -// optional .protobuf_unittest.TestMutualRecursionB bb = 1; -inline bool TestMutualRecursionA::has_bb() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestMutualRecursionA::set_has_bb() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestMutualRecursionA::clear_has_bb() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestMutualRecursionA::clear_bb() { - if (bb_ != NULL) bb_->::protobuf_unittest::TestMutualRecursionB::Clear(); - clear_has_bb(); -} -inline const ::protobuf_unittest::TestMutualRecursionB& TestMutualRecursionA::bb() const { - return bb_ != NULL ? *bb_ : *default_instance_->bb_; -} -inline ::protobuf_unittest::TestMutualRecursionB* TestMutualRecursionA::mutable_bb() { - set_has_bb(); - if (bb_ == NULL) bb_ = new ::protobuf_unittest::TestMutualRecursionB; - return bb_; -} -inline ::protobuf_unittest::TestMutualRecursionB* TestMutualRecursionA::release_bb() { - clear_has_bb(); - ::protobuf_unittest::TestMutualRecursionB* temp = bb_; - bb_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// TestMutualRecursionB - -// optional .protobuf_unittest.TestMutualRecursionA a = 1; -inline bool TestMutualRecursionB::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestMutualRecursionB::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestMutualRecursionB::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestMutualRecursionB::clear_a() { - if (a_ != NULL) a_->::protobuf_unittest::TestMutualRecursionA::Clear(); - clear_has_a(); -} -inline const ::protobuf_unittest::TestMutualRecursionA& TestMutualRecursionB::a() const { - return a_ != NULL ? *a_ : *default_instance_->a_; -} -inline ::protobuf_unittest::TestMutualRecursionA* TestMutualRecursionB::mutable_a() { - set_has_a(); - if (a_ == NULL) a_ = new ::protobuf_unittest::TestMutualRecursionA; - return a_; -} -inline ::protobuf_unittest::TestMutualRecursionA* TestMutualRecursionB::release_a() { - clear_has_a(); - ::protobuf_unittest::TestMutualRecursionA* temp = a_; - a_ = NULL; - return temp; -} - -// optional int32 optional_int32 = 2; -inline bool TestMutualRecursionB::has_optional_int32() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestMutualRecursionB::set_has_optional_int32() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestMutualRecursionB::clear_has_optional_int32() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestMutualRecursionB::clear_optional_int32() { - optional_int32_ = 0; - clear_has_optional_int32(); -} -inline ::google::protobuf::int32 TestMutualRecursionB::optional_int32() const { - return optional_int32_; -} -inline void TestMutualRecursionB::set_optional_int32(::google::protobuf::int32 value) { - set_has_optional_int32(); - optional_int32_ = value; -} - -// ------------------------------------------------------------------- - -// TestDupFieldNumber_Foo - -// optional int32 a = 1; -inline bool TestDupFieldNumber_Foo::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestDupFieldNumber_Foo::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestDupFieldNumber_Foo::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestDupFieldNumber_Foo::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestDupFieldNumber_Foo::a() const { - return a_; -} -inline void TestDupFieldNumber_Foo::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestDupFieldNumber_Bar - -// optional int32 a = 1; -inline bool TestDupFieldNumber_Bar::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestDupFieldNumber_Bar::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestDupFieldNumber_Bar::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestDupFieldNumber_Bar::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestDupFieldNumber_Bar::a() const { - return a_; -} -inline void TestDupFieldNumber_Bar::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestDupFieldNumber - -// optional int32 a = 1; -inline bool TestDupFieldNumber::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestDupFieldNumber::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestDupFieldNumber::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestDupFieldNumber::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestDupFieldNumber::a() const { - return a_; -} -inline void TestDupFieldNumber::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// optional group Foo = 2 { -inline bool TestDupFieldNumber::has_foo() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestDupFieldNumber::set_has_foo() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestDupFieldNumber::clear_has_foo() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestDupFieldNumber::clear_foo() { - if (foo_ != NULL) foo_->::protobuf_unittest::TestDupFieldNumber_Foo::Clear(); - clear_has_foo(); -} -inline const ::protobuf_unittest::TestDupFieldNumber_Foo& TestDupFieldNumber::foo() const { - return foo_ != NULL ? *foo_ : *default_instance_->foo_; -} -inline ::protobuf_unittest::TestDupFieldNumber_Foo* TestDupFieldNumber::mutable_foo() { - set_has_foo(); - if (foo_ == NULL) foo_ = new ::protobuf_unittest::TestDupFieldNumber_Foo; - return foo_; -} -inline ::protobuf_unittest::TestDupFieldNumber_Foo* TestDupFieldNumber::release_foo() { - clear_has_foo(); - ::protobuf_unittest::TestDupFieldNumber_Foo* temp = foo_; - foo_ = NULL; - return temp; -} - -// optional group Bar = 3 { -inline bool TestDupFieldNumber::has_bar() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestDupFieldNumber::set_has_bar() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestDupFieldNumber::clear_has_bar() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestDupFieldNumber::clear_bar() { - if (bar_ != NULL) bar_->::protobuf_unittest::TestDupFieldNumber_Bar::Clear(); - clear_has_bar(); -} -inline const ::protobuf_unittest::TestDupFieldNumber_Bar& TestDupFieldNumber::bar() const { - return bar_ != NULL ? *bar_ : *default_instance_->bar_; -} -inline ::protobuf_unittest::TestDupFieldNumber_Bar* TestDupFieldNumber::mutable_bar() { - set_has_bar(); - if (bar_ == NULL) bar_ = new ::protobuf_unittest::TestDupFieldNumber_Bar; - return bar_; -} -inline ::protobuf_unittest::TestDupFieldNumber_Bar* TestDupFieldNumber::release_bar() { - clear_has_bar(); - ::protobuf_unittest::TestDupFieldNumber_Bar* temp = bar_; - bar_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// TestNestedMessageHasBits_NestedMessage - -// repeated int32 nestedmessage_repeated_int32 = 1; -inline int TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_int32_size() const { - return nestedmessage_repeated_int32_.size(); -} -inline void TestNestedMessageHasBits_NestedMessage::clear_nestedmessage_repeated_int32() { - nestedmessage_repeated_int32_.Clear(); -} -inline ::google::protobuf::int32 TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_int32(int index) const { - return nestedmessage_repeated_int32_.Get(index); -} -inline void TestNestedMessageHasBits_NestedMessage::set_nestedmessage_repeated_int32(int index, ::google::protobuf::int32 value) { - nestedmessage_repeated_int32_.Set(index, value); -} -inline void TestNestedMessageHasBits_NestedMessage::add_nestedmessage_repeated_int32(::google::protobuf::int32 value) { - nestedmessage_repeated_int32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_int32() const { - return nestedmessage_repeated_int32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestNestedMessageHasBits_NestedMessage::mutable_nestedmessage_repeated_int32() { - return &nestedmessage_repeated_int32_; -} - -// repeated .protobuf_unittest.ForeignMessage nestedmessage_repeated_foreignmessage = 2; -inline int TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_foreignmessage_size() const { - return nestedmessage_repeated_foreignmessage_.size(); -} -inline void TestNestedMessageHasBits_NestedMessage::clear_nestedmessage_repeated_foreignmessage() { - nestedmessage_repeated_foreignmessage_.Clear(); -} -inline const ::protobuf_unittest::ForeignMessage& TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_foreignmessage(int index) const { - return nestedmessage_repeated_foreignmessage_.Get(index); -} -inline ::protobuf_unittest::ForeignMessage* TestNestedMessageHasBits_NestedMessage::mutable_nestedmessage_repeated_foreignmessage(int index) { - return nestedmessage_repeated_foreignmessage_.Mutable(index); -} -inline ::protobuf_unittest::ForeignMessage* TestNestedMessageHasBits_NestedMessage::add_nestedmessage_repeated_foreignmessage() { - return nestedmessage_repeated_foreignmessage_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& -TestNestedMessageHasBits_NestedMessage::nestedmessage_repeated_foreignmessage() const { - return nestedmessage_repeated_foreignmessage_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* -TestNestedMessageHasBits_NestedMessage::mutable_nestedmessage_repeated_foreignmessage() { - return &nestedmessage_repeated_foreignmessage_; -} - -// ------------------------------------------------------------------- - -// TestNestedMessageHasBits - -// optional .protobuf_unittest.TestNestedMessageHasBits.NestedMessage optional_nested_message = 1; -inline bool TestNestedMessageHasBits::has_optional_nested_message() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestNestedMessageHasBits::set_has_optional_nested_message() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestNestedMessageHasBits::clear_has_optional_nested_message() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestNestedMessageHasBits::clear_optional_nested_message() { - if (optional_nested_message_ != NULL) optional_nested_message_->::protobuf_unittest::TestNestedMessageHasBits_NestedMessage::Clear(); - clear_has_optional_nested_message(); -} -inline const ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage& TestNestedMessageHasBits::optional_nested_message() const { - return optional_nested_message_ != NULL ? *optional_nested_message_ : *default_instance_->optional_nested_message_; -} -inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* TestNestedMessageHasBits::mutable_optional_nested_message() { - set_has_optional_nested_message(); - if (optional_nested_message_ == NULL) optional_nested_message_ = new ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage; - return optional_nested_message_; -} -inline ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* TestNestedMessageHasBits::release_optional_nested_message() { - clear_has_optional_nested_message(); - ::protobuf_unittest::TestNestedMessageHasBits_NestedMessage* temp = optional_nested_message_; - optional_nested_message_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// TestCamelCaseFieldNames - -// optional int32 PrimitiveField = 1; -inline bool TestCamelCaseFieldNames::has_primitivefield() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestCamelCaseFieldNames::set_has_primitivefield() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestCamelCaseFieldNames::clear_has_primitivefield() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestCamelCaseFieldNames::clear_primitivefield() { - primitivefield_ = 0; - clear_has_primitivefield(); -} -inline ::google::protobuf::int32 TestCamelCaseFieldNames::primitivefield() const { - return primitivefield_; -} -inline void TestCamelCaseFieldNames::set_primitivefield(::google::protobuf::int32 value) { - set_has_primitivefield(); - primitivefield_ = value; -} - -// optional string StringField = 2; -inline bool TestCamelCaseFieldNames::has_stringfield() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestCamelCaseFieldNames::set_has_stringfield() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestCamelCaseFieldNames::clear_has_stringfield() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestCamelCaseFieldNames::clear_stringfield() { - if (stringfield_ != &::google::protobuf::internal::kEmptyString) { - stringfield_->clear(); - } - clear_has_stringfield(); -} -inline const ::std::string& TestCamelCaseFieldNames::stringfield() const { - return *stringfield_; -} -inline void TestCamelCaseFieldNames::set_stringfield(const ::std::string& value) { - set_has_stringfield(); - if (stringfield_ == &::google::protobuf::internal::kEmptyString) { - stringfield_ = new ::std::string; - } - stringfield_->assign(value); -} -inline void TestCamelCaseFieldNames::set_stringfield(const char* value) { - set_has_stringfield(); - if (stringfield_ == &::google::protobuf::internal::kEmptyString) { - stringfield_ = new ::std::string; - } - stringfield_->assign(value); -} -inline void TestCamelCaseFieldNames::set_stringfield(const char* value, size_t size) { - set_has_stringfield(); - if (stringfield_ == &::google::protobuf::internal::kEmptyString) { - stringfield_ = new ::std::string; - } - stringfield_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestCamelCaseFieldNames::mutable_stringfield() { - set_has_stringfield(); - if (stringfield_ == &::google::protobuf::internal::kEmptyString) { - stringfield_ = new ::std::string; - } - return stringfield_; -} -inline ::std::string* TestCamelCaseFieldNames::release_stringfield() { - clear_has_stringfield(); - if (stringfield_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = stringfield_; - stringfield_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional .protobuf_unittest.ForeignEnum EnumField = 3; -inline bool TestCamelCaseFieldNames::has_enumfield() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestCamelCaseFieldNames::set_has_enumfield() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestCamelCaseFieldNames::clear_has_enumfield() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestCamelCaseFieldNames::clear_enumfield() { - enumfield_ = 4; - clear_has_enumfield(); -} -inline protobuf_unittest::ForeignEnum TestCamelCaseFieldNames::enumfield() const { - return static_cast< protobuf_unittest::ForeignEnum >(enumfield_); -} -inline void TestCamelCaseFieldNames::set_enumfield(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - set_has_enumfield(); - enumfield_ = value; -} - -// optional .protobuf_unittest.ForeignMessage MessageField = 4; -inline bool TestCamelCaseFieldNames::has_messagefield() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void TestCamelCaseFieldNames::set_has_messagefield() { - _has_bits_[0] |= 0x00000008u; -} -inline void TestCamelCaseFieldNames::clear_has_messagefield() { - _has_bits_[0] &= ~0x00000008u; -} -inline void TestCamelCaseFieldNames::clear_messagefield() { - if (messagefield_ != NULL) messagefield_->::protobuf_unittest::ForeignMessage::Clear(); - clear_has_messagefield(); -} -inline const ::protobuf_unittest::ForeignMessage& TestCamelCaseFieldNames::messagefield() const { - return messagefield_ != NULL ? *messagefield_ : *default_instance_->messagefield_; -} -inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::mutable_messagefield() { - set_has_messagefield(); - if (messagefield_ == NULL) messagefield_ = new ::protobuf_unittest::ForeignMessage; - return messagefield_; -} -inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::release_messagefield() { - clear_has_messagefield(); - ::protobuf_unittest::ForeignMessage* temp = messagefield_; - messagefield_ = NULL; - return temp; -} - -// optional string StringPieceField = 5 [ctype = STRING_PIECE]; -inline bool TestCamelCaseFieldNames::has_stringpiecefield() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TestCamelCaseFieldNames::set_has_stringpiecefield() { - _has_bits_[0] |= 0x00000010u; -} -inline void TestCamelCaseFieldNames::clear_has_stringpiecefield() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TestCamelCaseFieldNames::clear_stringpiecefield() { - if (stringpiecefield_ != &::google::protobuf::internal::kEmptyString) { - stringpiecefield_->clear(); - } - clear_has_stringpiecefield(); -} -inline const ::std::string& TestCamelCaseFieldNames::stringpiecefield() const { - return *stringpiecefield_; -} -inline void TestCamelCaseFieldNames::set_stringpiecefield(const ::std::string& value) { - set_has_stringpiecefield(); - if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { - stringpiecefield_ = new ::std::string; - } - stringpiecefield_->assign(value); -} -inline void TestCamelCaseFieldNames::set_stringpiecefield(const char* value) { - set_has_stringpiecefield(); - if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { - stringpiecefield_ = new ::std::string; - } - stringpiecefield_->assign(value); -} -inline void TestCamelCaseFieldNames::set_stringpiecefield(const char* value, size_t size) { - set_has_stringpiecefield(); - if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { - stringpiecefield_ = new ::std::string; - } - stringpiecefield_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestCamelCaseFieldNames::mutable_stringpiecefield() { - set_has_stringpiecefield(); - if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { - stringpiecefield_ = new ::std::string; - } - return stringpiecefield_; -} -inline ::std::string* TestCamelCaseFieldNames::release_stringpiecefield() { - clear_has_stringpiecefield(); - if (stringpiecefield_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = stringpiecefield_; - stringpiecefield_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string CordField = 6 [ctype = CORD]; -inline bool TestCamelCaseFieldNames::has_cordfield() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void TestCamelCaseFieldNames::set_has_cordfield() { - _has_bits_[0] |= 0x00000020u; -} -inline void TestCamelCaseFieldNames::clear_has_cordfield() { - _has_bits_[0] &= ~0x00000020u; -} -inline void TestCamelCaseFieldNames::clear_cordfield() { - if (cordfield_ != &::google::protobuf::internal::kEmptyString) { - cordfield_->clear(); - } - clear_has_cordfield(); -} -inline const ::std::string& TestCamelCaseFieldNames::cordfield() const { - return *cordfield_; -} -inline void TestCamelCaseFieldNames::set_cordfield(const ::std::string& value) { - set_has_cordfield(); - if (cordfield_ == &::google::protobuf::internal::kEmptyString) { - cordfield_ = new ::std::string; - } - cordfield_->assign(value); -} -inline void TestCamelCaseFieldNames::set_cordfield(const char* value) { - set_has_cordfield(); - if (cordfield_ == &::google::protobuf::internal::kEmptyString) { - cordfield_ = new ::std::string; - } - cordfield_->assign(value); -} -inline void TestCamelCaseFieldNames::set_cordfield(const char* value, size_t size) { - set_has_cordfield(); - if (cordfield_ == &::google::protobuf::internal::kEmptyString) { - cordfield_ = new ::std::string; - } - cordfield_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestCamelCaseFieldNames::mutable_cordfield() { - set_has_cordfield(); - if (cordfield_ == &::google::protobuf::internal::kEmptyString) { - cordfield_ = new ::std::string; - } - return cordfield_; -} -inline ::std::string* TestCamelCaseFieldNames::release_cordfield() { - clear_has_cordfield(); - if (cordfield_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = cordfield_; - cordfield_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated int32 RepeatedPrimitiveField = 7; -inline int TestCamelCaseFieldNames::repeatedprimitivefield_size() const { - return repeatedprimitivefield_.size(); -} -inline void TestCamelCaseFieldNames::clear_repeatedprimitivefield() { - repeatedprimitivefield_.Clear(); -} -inline ::google::protobuf::int32 TestCamelCaseFieldNames::repeatedprimitivefield(int index) const { - return repeatedprimitivefield_.Get(index); -} -inline void TestCamelCaseFieldNames::set_repeatedprimitivefield(int index, ::google::protobuf::int32 value) { - repeatedprimitivefield_.Set(index, value); -} -inline void TestCamelCaseFieldNames::add_repeatedprimitivefield(::google::protobuf::int32 value) { - repeatedprimitivefield_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestCamelCaseFieldNames::repeatedprimitivefield() const { - return repeatedprimitivefield_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestCamelCaseFieldNames::mutable_repeatedprimitivefield() { - return &repeatedprimitivefield_; -} - -// repeated string RepeatedStringField = 8; -inline int TestCamelCaseFieldNames::repeatedstringfield_size() const { - return repeatedstringfield_.size(); -} -inline void TestCamelCaseFieldNames::clear_repeatedstringfield() { - repeatedstringfield_.Clear(); -} -inline const ::std::string& TestCamelCaseFieldNames::repeatedstringfield(int index) const { - return repeatedstringfield_.Get(index); -} -inline ::std::string* TestCamelCaseFieldNames::mutable_repeatedstringfield(int index) { - return repeatedstringfield_.Mutable(index); -} -inline void TestCamelCaseFieldNames::set_repeatedstringfield(int index, const ::std::string& value) { - repeatedstringfield_.Mutable(index)->assign(value); -} -inline void TestCamelCaseFieldNames::set_repeatedstringfield(int index, const char* value) { - repeatedstringfield_.Mutable(index)->assign(value); -} -inline void TestCamelCaseFieldNames::set_repeatedstringfield(int index, const char* value, size_t size) { - repeatedstringfield_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestCamelCaseFieldNames::add_repeatedstringfield() { - return repeatedstringfield_.Add(); -} -inline void TestCamelCaseFieldNames::add_repeatedstringfield(const ::std::string& value) { - repeatedstringfield_.Add()->assign(value); -} -inline void TestCamelCaseFieldNames::add_repeatedstringfield(const char* value) { - repeatedstringfield_.Add()->assign(value); -} -inline void TestCamelCaseFieldNames::add_repeatedstringfield(const char* value, size_t size) { - repeatedstringfield_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestCamelCaseFieldNames::repeatedstringfield() const { - return repeatedstringfield_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestCamelCaseFieldNames::mutable_repeatedstringfield() { - return &repeatedstringfield_; -} - -// repeated .protobuf_unittest.ForeignEnum RepeatedEnumField = 9; -inline int TestCamelCaseFieldNames::repeatedenumfield_size() const { - return repeatedenumfield_.size(); -} -inline void TestCamelCaseFieldNames::clear_repeatedenumfield() { - repeatedenumfield_.Clear(); -} -inline protobuf_unittest::ForeignEnum TestCamelCaseFieldNames::repeatedenumfield(int index) const { - return static_cast< protobuf_unittest::ForeignEnum >(repeatedenumfield_.Get(index)); -} -inline void TestCamelCaseFieldNames::set_repeatedenumfield(int index, protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - repeatedenumfield_.Set(index, value); -} -inline void TestCamelCaseFieldNames::add_repeatedenumfield(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - repeatedenumfield_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestCamelCaseFieldNames::repeatedenumfield() const { - return repeatedenumfield_; -} -inline ::google::protobuf::RepeatedField* -TestCamelCaseFieldNames::mutable_repeatedenumfield() { - return &repeatedenumfield_; -} - -// repeated .protobuf_unittest.ForeignMessage RepeatedMessageField = 10; -inline int TestCamelCaseFieldNames::repeatedmessagefield_size() const { - return repeatedmessagefield_.size(); -} -inline void TestCamelCaseFieldNames::clear_repeatedmessagefield() { - repeatedmessagefield_.Clear(); -} -inline const ::protobuf_unittest::ForeignMessage& TestCamelCaseFieldNames::repeatedmessagefield(int index) const { - return repeatedmessagefield_.Get(index); -} -inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::mutable_repeatedmessagefield(int index) { - return repeatedmessagefield_.Mutable(index); -} -inline ::protobuf_unittest::ForeignMessage* TestCamelCaseFieldNames::add_repeatedmessagefield() { - return repeatedmessagefield_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >& -TestCamelCaseFieldNames::repeatedmessagefield() const { - return repeatedmessagefield_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessage >* -TestCamelCaseFieldNames::mutable_repeatedmessagefield() { - return &repeatedmessagefield_; -} - -// repeated string RepeatedStringPieceField = 11 [ctype = STRING_PIECE]; -inline int TestCamelCaseFieldNames::repeatedstringpiecefield_size() const { - return repeatedstringpiecefield_.size(); -} -inline void TestCamelCaseFieldNames::clear_repeatedstringpiecefield() { - repeatedstringpiecefield_.Clear(); -} -inline const ::std::string& TestCamelCaseFieldNames::repeatedstringpiecefield(int index) const { - return repeatedstringpiecefield_.Get(index); -} -inline ::std::string* TestCamelCaseFieldNames::mutable_repeatedstringpiecefield(int index) { - return repeatedstringpiecefield_.Mutable(index); -} -inline void TestCamelCaseFieldNames::set_repeatedstringpiecefield(int index, const ::std::string& value) { - repeatedstringpiecefield_.Mutable(index)->assign(value); -} -inline void TestCamelCaseFieldNames::set_repeatedstringpiecefield(int index, const char* value) { - repeatedstringpiecefield_.Mutable(index)->assign(value); -} -inline void TestCamelCaseFieldNames::set_repeatedstringpiecefield(int index, const char* value, size_t size) { - repeatedstringpiecefield_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestCamelCaseFieldNames::add_repeatedstringpiecefield() { - return repeatedstringpiecefield_.Add(); -} -inline void TestCamelCaseFieldNames::add_repeatedstringpiecefield(const ::std::string& value) { - repeatedstringpiecefield_.Add()->assign(value); -} -inline void TestCamelCaseFieldNames::add_repeatedstringpiecefield(const char* value) { - repeatedstringpiecefield_.Add()->assign(value); -} -inline void TestCamelCaseFieldNames::add_repeatedstringpiecefield(const char* value, size_t size) { - repeatedstringpiecefield_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestCamelCaseFieldNames::repeatedstringpiecefield() const { - return repeatedstringpiecefield_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestCamelCaseFieldNames::mutable_repeatedstringpiecefield() { - return &repeatedstringpiecefield_; -} - -// repeated string RepeatedCordField = 12 [ctype = CORD]; -inline int TestCamelCaseFieldNames::repeatedcordfield_size() const { - return repeatedcordfield_.size(); -} -inline void TestCamelCaseFieldNames::clear_repeatedcordfield() { - repeatedcordfield_.Clear(); -} -inline const ::std::string& TestCamelCaseFieldNames::repeatedcordfield(int index) const { - return repeatedcordfield_.Get(index); -} -inline ::std::string* TestCamelCaseFieldNames::mutable_repeatedcordfield(int index) { - return repeatedcordfield_.Mutable(index); -} -inline void TestCamelCaseFieldNames::set_repeatedcordfield(int index, const ::std::string& value) { - repeatedcordfield_.Mutable(index)->assign(value); -} -inline void TestCamelCaseFieldNames::set_repeatedcordfield(int index, const char* value) { - repeatedcordfield_.Mutable(index)->assign(value); -} -inline void TestCamelCaseFieldNames::set_repeatedcordfield(int index, const char* value, size_t size) { - repeatedcordfield_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestCamelCaseFieldNames::add_repeatedcordfield() { - return repeatedcordfield_.Add(); -} -inline void TestCamelCaseFieldNames::add_repeatedcordfield(const ::std::string& value) { - repeatedcordfield_.Add()->assign(value); -} -inline void TestCamelCaseFieldNames::add_repeatedcordfield(const char* value) { - repeatedcordfield_.Add()->assign(value); -} -inline void TestCamelCaseFieldNames::add_repeatedcordfield(const char* value, size_t size) { - repeatedcordfield_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestCamelCaseFieldNames::repeatedcordfield() const { - return repeatedcordfield_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestCamelCaseFieldNames::mutable_repeatedcordfield() { - return &repeatedcordfield_; -} - -// ------------------------------------------------------------------- - -// TestFieldOrderings - -// optional string my_string = 11; -inline bool TestFieldOrderings::has_my_string() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestFieldOrderings::set_has_my_string() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestFieldOrderings::clear_has_my_string() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestFieldOrderings::clear_my_string() { - if (my_string_ != &::google::protobuf::internal::kEmptyString) { - my_string_->clear(); - } - clear_has_my_string(); -} -inline const ::std::string& TestFieldOrderings::my_string() const { - return *my_string_; -} -inline void TestFieldOrderings::set_my_string(const ::std::string& value) { - set_has_my_string(); - if (my_string_ == &::google::protobuf::internal::kEmptyString) { - my_string_ = new ::std::string; - } - my_string_->assign(value); -} -inline void TestFieldOrderings::set_my_string(const char* value) { - set_has_my_string(); - if (my_string_ == &::google::protobuf::internal::kEmptyString) { - my_string_ = new ::std::string; - } - my_string_->assign(value); -} -inline void TestFieldOrderings::set_my_string(const char* value, size_t size) { - set_has_my_string(); - if (my_string_ == &::google::protobuf::internal::kEmptyString) { - my_string_ = new ::std::string; - } - my_string_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestFieldOrderings::mutable_my_string() { - set_has_my_string(); - if (my_string_ == &::google::protobuf::internal::kEmptyString) { - my_string_ = new ::std::string; - } - return my_string_; -} -inline ::std::string* TestFieldOrderings::release_my_string() { - clear_has_my_string(); - if (my_string_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = my_string_; - my_string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional int64 my_int = 1; -inline bool TestFieldOrderings::has_my_int() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestFieldOrderings::set_has_my_int() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestFieldOrderings::clear_has_my_int() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestFieldOrderings::clear_my_int() { - my_int_ = GOOGLE_LONGLONG(0); - clear_has_my_int(); -} -inline ::google::protobuf::int64 TestFieldOrderings::my_int() const { - return my_int_; -} -inline void TestFieldOrderings::set_my_int(::google::protobuf::int64 value) { - set_has_my_int(); - my_int_ = value; -} - -// optional float my_float = 101; -inline bool TestFieldOrderings::has_my_float() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestFieldOrderings::set_has_my_float() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestFieldOrderings::clear_has_my_float() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestFieldOrderings::clear_my_float() { - my_float_ = 0; - clear_has_my_float(); -} -inline float TestFieldOrderings::my_float() const { - return my_float_; -} -inline void TestFieldOrderings::set_my_float(float value) { - set_has_my_float(); - my_float_ = value; -} - -// ------------------------------------------------------------------- - -// TestExtremeDefaultValues - -// optional bytes escaped_bytes = 1 [default = "\000\001\007\010\014\n\r\t\013\\\'\"\376"]; -inline bool TestExtremeDefaultValues::has_escaped_bytes() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestExtremeDefaultValues::set_has_escaped_bytes() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestExtremeDefaultValues::clear_has_escaped_bytes() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestExtremeDefaultValues::clear_escaped_bytes() { - if (escaped_bytes_ != &_default_escaped_bytes_) { - escaped_bytes_->assign(_default_escaped_bytes_); - } - clear_has_escaped_bytes(); -} -inline const ::std::string& TestExtremeDefaultValues::escaped_bytes() const { - return *escaped_bytes_; -} -inline void TestExtremeDefaultValues::set_escaped_bytes(const ::std::string& value) { - set_has_escaped_bytes(); - if (escaped_bytes_ == &_default_escaped_bytes_) { - escaped_bytes_ = new ::std::string; - } - escaped_bytes_->assign(value); -} -inline void TestExtremeDefaultValues::set_escaped_bytes(const char* value) { - set_has_escaped_bytes(); - if (escaped_bytes_ == &_default_escaped_bytes_) { - escaped_bytes_ = new ::std::string; - } - escaped_bytes_->assign(value); -} -inline void TestExtremeDefaultValues::set_escaped_bytes(const void* value, size_t size) { - set_has_escaped_bytes(); - if (escaped_bytes_ == &_default_escaped_bytes_) { - escaped_bytes_ = new ::std::string; - } - escaped_bytes_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestExtremeDefaultValues::mutable_escaped_bytes() { - set_has_escaped_bytes(); - if (escaped_bytes_ == &_default_escaped_bytes_) { - escaped_bytes_ = new ::std::string(_default_escaped_bytes_); - } - return escaped_bytes_; -} -inline ::std::string* TestExtremeDefaultValues::release_escaped_bytes() { - clear_has_escaped_bytes(); - if (escaped_bytes_ == &_default_escaped_bytes_) { - return NULL; - } else { - ::std::string* temp = escaped_bytes_; - escaped_bytes_ = const_cast< ::std::string*>(&_default_escaped_bytes_); - return temp; - } -} - -// optional uint32 large_uint32 = 2 [default = 4294967295]; -inline bool TestExtremeDefaultValues::has_large_uint32() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestExtremeDefaultValues::set_has_large_uint32() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestExtremeDefaultValues::clear_has_large_uint32() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestExtremeDefaultValues::clear_large_uint32() { - large_uint32_ = 4294967295u; - clear_has_large_uint32(); -} -inline ::google::protobuf::uint32 TestExtremeDefaultValues::large_uint32() const { - return large_uint32_; -} -inline void TestExtremeDefaultValues::set_large_uint32(::google::protobuf::uint32 value) { - set_has_large_uint32(); - large_uint32_ = value; -} - -// optional uint64 large_uint64 = 3 [default = 18446744073709551615]; -inline bool TestExtremeDefaultValues::has_large_uint64() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestExtremeDefaultValues::set_has_large_uint64() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestExtremeDefaultValues::clear_has_large_uint64() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestExtremeDefaultValues::clear_large_uint64() { - large_uint64_ = GOOGLE_ULONGLONG(18446744073709551615); - clear_has_large_uint64(); -} -inline ::google::protobuf::uint64 TestExtremeDefaultValues::large_uint64() const { - return large_uint64_; -} -inline void TestExtremeDefaultValues::set_large_uint64(::google::protobuf::uint64 value) { - set_has_large_uint64(); - large_uint64_ = value; -} - -// optional int32 small_int32 = 4 [default = -2147483647]; -inline bool TestExtremeDefaultValues::has_small_int32() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void TestExtremeDefaultValues::set_has_small_int32() { - _has_bits_[0] |= 0x00000008u; -} -inline void TestExtremeDefaultValues::clear_has_small_int32() { - _has_bits_[0] &= ~0x00000008u; -} -inline void TestExtremeDefaultValues::clear_small_int32() { - small_int32_ = -2147483647; - clear_has_small_int32(); -} -inline ::google::protobuf::int32 TestExtremeDefaultValues::small_int32() const { - return small_int32_; -} -inline void TestExtremeDefaultValues::set_small_int32(::google::protobuf::int32 value) { - set_has_small_int32(); - small_int32_ = value; -} - -// optional int64 small_int64 = 5 [default = -9223372036854775807]; -inline bool TestExtremeDefaultValues::has_small_int64() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TestExtremeDefaultValues::set_has_small_int64() { - _has_bits_[0] |= 0x00000010u; -} -inline void TestExtremeDefaultValues::clear_has_small_int64() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TestExtremeDefaultValues::clear_small_int64() { - small_int64_ = GOOGLE_LONGLONG(-9223372036854775807); - clear_has_small_int64(); -} -inline ::google::protobuf::int64 TestExtremeDefaultValues::small_int64() const { - return small_int64_; -} -inline void TestExtremeDefaultValues::set_small_int64(::google::protobuf::int64 value) { - set_has_small_int64(); - small_int64_ = value; -} - -// optional string utf8_string = 6 [default = "\341\210\264"]; -inline bool TestExtremeDefaultValues::has_utf8_string() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void TestExtremeDefaultValues::set_has_utf8_string() { - _has_bits_[0] |= 0x00000020u; -} -inline void TestExtremeDefaultValues::clear_has_utf8_string() { - _has_bits_[0] &= ~0x00000020u; -} -inline void TestExtremeDefaultValues::clear_utf8_string() { - if (utf8_string_ != &_default_utf8_string_) { - utf8_string_->assign(_default_utf8_string_); - } - clear_has_utf8_string(); -} -inline const ::std::string& TestExtremeDefaultValues::utf8_string() const { - return *utf8_string_; -} -inline void TestExtremeDefaultValues::set_utf8_string(const ::std::string& value) { - set_has_utf8_string(); - if (utf8_string_ == &_default_utf8_string_) { - utf8_string_ = new ::std::string; - } - utf8_string_->assign(value); -} -inline void TestExtremeDefaultValues::set_utf8_string(const char* value) { - set_has_utf8_string(); - if (utf8_string_ == &_default_utf8_string_) { - utf8_string_ = new ::std::string; - } - utf8_string_->assign(value); -} -inline void TestExtremeDefaultValues::set_utf8_string(const char* value, size_t size) { - set_has_utf8_string(); - if (utf8_string_ == &_default_utf8_string_) { - utf8_string_ = new ::std::string; - } - utf8_string_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestExtremeDefaultValues::mutable_utf8_string() { - set_has_utf8_string(); - if (utf8_string_ == &_default_utf8_string_) { - utf8_string_ = new ::std::string(_default_utf8_string_); - } - return utf8_string_; -} -inline ::std::string* TestExtremeDefaultValues::release_utf8_string() { - clear_has_utf8_string(); - if (utf8_string_ == &_default_utf8_string_) { - return NULL; - } else { - ::std::string* temp = utf8_string_; - utf8_string_ = const_cast< ::std::string*>(&_default_utf8_string_); - return temp; - } -} - -// optional float zero_float = 7 [default = 0]; -inline bool TestExtremeDefaultValues::has_zero_float() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void TestExtremeDefaultValues::set_has_zero_float() { - _has_bits_[0] |= 0x00000040u; -} -inline void TestExtremeDefaultValues::clear_has_zero_float() { - _has_bits_[0] &= ~0x00000040u; -} -inline void TestExtremeDefaultValues::clear_zero_float() { - zero_float_ = 0; - clear_has_zero_float(); -} -inline float TestExtremeDefaultValues::zero_float() const { - return zero_float_; -} -inline void TestExtremeDefaultValues::set_zero_float(float value) { - set_has_zero_float(); - zero_float_ = value; -} - -// optional float one_float = 8 [default = 1]; -inline bool TestExtremeDefaultValues::has_one_float() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void TestExtremeDefaultValues::set_has_one_float() { - _has_bits_[0] |= 0x00000080u; -} -inline void TestExtremeDefaultValues::clear_has_one_float() { - _has_bits_[0] &= ~0x00000080u; -} -inline void TestExtremeDefaultValues::clear_one_float() { - one_float_ = 1; - clear_has_one_float(); -} -inline float TestExtremeDefaultValues::one_float() const { - return one_float_; -} -inline void TestExtremeDefaultValues::set_one_float(float value) { - set_has_one_float(); - one_float_ = value; -} - -// optional float small_float = 9 [default = 1.5]; -inline bool TestExtremeDefaultValues::has_small_float() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void TestExtremeDefaultValues::set_has_small_float() { - _has_bits_[0] |= 0x00000100u; -} -inline void TestExtremeDefaultValues::clear_has_small_float() { - _has_bits_[0] &= ~0x00000100u; -} -inline void TestExtremeDefaultValues::clear_small_float() { - small_float_ = 1.5f; - clear_has_small_float(); -} -inline float TestExtremeDefaultValues::small_float() const { - return small_float_; -} -inline void TestExtremeDefaultValues::set_small_float(float value) { - set_has_small_float(); - small_float_ = value; -} - -// optional float negative_one_float = 10 [default = -1]; -inline bool TestExtremeDefaultValues::has_negative_one_float() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void TestExtremeDefaultValues::set_has_negative_one_float() { - _has_bits_[0] |= 0x00000200u; -} -inline void TestExtremeDefaultValues::clear_has_negative_one_float() { - _has_bits_[0] &= ~0x00000200u; -} -inline void TestExtremeDefaultValues::clear_negative_one_float() { - negative_one_float_ = -1; - clear_has_negative_one_float(); -} -inline float TestExtremeDefaultValues::negative_one_float() const { - return negative_one_float_; -} -inline void TestExtremeDefaultValues::set_negative_one_float(float value) { - set_has_negative_one_float(); - negative_one_float_ = value; -} - -// optional float negative_float = 11 [default = -1.5]; -inline bool TestExtremeDefaultValues::has_negative_float() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void TestExtremeDefaultValues::set_has_negative_float() { - _has_bits_[0] |= 0x00000400u; -} -inline void TestExtremeDefaultValues::clear_has_negative_float() { - _has_bits_[0] &= ~0x00000400u; -} -inline void TestExtremeDefaultValues::clear_negative_float() { - negative_float_ = -1.5f; - clear_has_negative_float(); -} -inline float TestExtremeDefaultValues::negative_float() const { - return negative_float_; -} -inline void TestExtremeDefaultValues::set_negative_float(float value) { - set_has_negative_float(); - negative_float_ = value; -} - -// optional float large_float = 12 [default = 2e+08]; -inline bool TestExtremeDefaultValues::has_large_float() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void TestExtremeDefaultValues::set_has_large_float() { - _has_bits_[0] |= 0x00000800u; -} -inline void TestExtremeDefaultValues::clear_has_large_float() { - _has_bits_[0] &= ~0x00000800u; -} -inline void TestExtremeDefaultValues::clear_large_float() { - large_float_ = 2e+08f; - clear_has_large_float(); -} -inline float TestExtremeDefaultValues::large_float() const { - return large_float_; -} -inline void TestExtremeDefaultValues::set_large_float(float value) { - set_has_large_float(); - large_float_ = value; -} - -// optional float small_negative_float = 13 [default = -8e-28]; -inline bool TestExtremeDefaultValues::has_small_negative_float() const { - return (_has_bits_[0] & 0x00001000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_small_negative_float() { - _has_bits_[0] |= 0x00001000u; -} -inline void TestExtremeDefaultValues::clear_has_small_negative_float() { - _has_bits_[0] &= ~0x00001000u; -} -inline void TestExtremeDefaultValues::clear_small_negative_float() { - small_negative_float_ = -8e-28f; - clear_has_small_negative_float(); -} -inline float TestExtremeDefaultValues::small_negative_float() const { - return small_negative_float_; -} -inline void TestExtremeDefaultValues::set_small_negative_float(float value) { - set_has_small_negative_float(); - small_negative_float_ = value; -} - -// optional double inf_double = 14 [default = inf]; -inline bool TestExtremeDefaultValues::has_inf_double() const { - return (_has_bits_[0] & 0x00002000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_inf_double() { - _has_bits_[0] |= 0x00002000u; -} -inline void TestExtremeDefaultValues::clear_has_inf_double() { - _has_bits_[0] &= ~0x00002000u; -} -inline void TestExtremeDefaultValues::clear_inf_double() { - inf_double_ = ::google::protobuf::internal::Infinity(); - clear_has_inf_double(); -} -inline double TestExtremeDefaultValues::inf_double() const { - return inf_double_; -} -inline void TestExtremeDefaultValues::set_inf_double(double value) { - set_has_inf_double(); - inf_double_ = value; -} - -// optional double neg_inf_double = 15 [default = -inf]; -inline bool TestExtremeDefaultValues::has_neg_inf_double() const { - return (_has_bits_[0] & 0x00004000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_neg_inf_double() { - _has_bits_[0] |= 0x00004000u; -} -inline void TestExtremeDefaultValues::clear_has_neg_inf_double() { - _has_bits_[0] &= ~0x00004000u; -} -inline void TestExtremeDefaultValues::clear_neg_inf_double() { - neg_inf_double_ = -::google::protobuf::internal::Infinity(); - clear_has_neg_inf_double(); -} -inline double TestExtremeDefaultValues::neg_inf_double() const { - return neg_inf_double_; -} -inline void TestExtremeDefaultValues::set_neg_inf_double(double value) { - set_has_neg_inf_double(); - neg_inf_double_ = value; -} - -// optional double nan_double = 16 [default = nan]; -inline bool TestExtremeDefaultValues::has_nan_double() const { - return (_has_bits_[0] & 0x00008000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_nan_double() { - _has_bits_[0] |= 0x00008000u; -} -inline void TestExtremeDefaultValues::clear_has_nan_double() { - _has_bits_[0] &= ~0x00008000u; -} -inline void TestExtremeDefaultValues::clear_nan_double() { - nan_double_ = ::google::protobuf::internal::NaN(); - clear_has_nan_double(); -} -inline double TestExtremeDefaultValues::nan_double() const { - return nan_double_; -} -inline void TestExtremeDefaultValues::set_nan_double(double value) { - set_has_nan_double(); - nan_double_ = value; -} - -// optional float inf_float = 17 [default = inf]; -inline bool TestExtremeDefaultValues::has_inf_float() const { - return (_has_bits_[0] & 0x00010000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_inf_float() { - _has_bits_[0] |= 0x00010000u; -} -inline void TestExtremeDefaultValues::clear_has_inf_float() { - _has_bits_[0] &= ~0x00010000u; -} -inline void TestExtremeDefaultValues::clear_inf_float() { - inf_float_ = static_cast(::google::protobuf::internal::Infinity()); - clear_has_inf_float(); -} -inline float TestExtremeDefaultValues::inf_float() const { - return inf_float_; -} -inline void TestExtremeDefaultValues::set_inf_float(float value) { - set_has_inf_float(); - inf_float_ = value; -} - -// optional float neg_inf_float = 18 [default = -inf]; -inline bool TestExtremeDefaultValues::has_neg_inf_float() const { - return (_has_bits_[0] & 0x00020000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_neg_inf_float() { - _has_bits_[0] |= 0x00020000u; -} -inline void TestExtremeDefaultValues::clear_has_neg_inf_float() { - _has_bits_[0] &= ~0x00020000u; -} -inline void TestExtremeDefaultValues::clear_neg_inf_float() { - neg_inf_float_ = static_cast(-::google::protobuf::internal::Infinity()); - clear_has_neg_inf_float(); -} -inline float TestExtremeDefaultValues::neg_inf_float() const { - return neg_inf_float_; -} -inline void TestExtremeDefaultValues::set_neg_inf_float(float value) { - set_has_neg_inf_float(); - neg_inf_float_ = value; -} - -// optional float nan_float = 19 [default = nan]; -inline bool TestExtremeDefaultValues::has_nan_float() const { - return (_has_bits_[0] & 0x00040000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_nan_float() { - _has_bits_[0] |= 0x00040000u; -} -inline void TestExtremeDefaultValues::clear_has_nan_float() { - _has_bits_[0] &= ~0x00040000u; -} -inline void TestExtremeDefaultValues::clear_nan_float() { - nan_float_ = static_cast(::google::protobuf::internal::NaN()); - clear_has_nan_float(); -} -inline float TestExtremeDefaultValues::nan_float() const { - return nan_float_; -} -inline void TestExtremeDefaultValues::set_nan_float(float value) { - set_has_nan_float(); - nan_float_ = value; -} - -// optional string cpp_trigraph = 20 [default = "? ? ?? ?? ??? ??/ ??-"]; -inline bool TestExtremeDefaultValues::has_cpp_trigraph() const { - return (_has_bits_[0] & 0x00080000u) != 0; -} -inline void TestExtremeDefaultValues::set_has_cpp_trigraph() { - _has_bits_[0] |= 0x00080000u; -} -inline void TestExtremeDefaultValues::clear_has_cpp_trigraph() { - _has_bits_[0] &= ~0x00080000u; -} -inline void TestExtremeDefaultValues::clear_cpp_trigraph() { - if (cpp_trigraph_ != &_default_cpp_trigraph_) { - cpp_trigraph_->assign(_default_cpp_trigraph_); - } - clear_has_cpp_trigraph(); -} -inline const ::std::string& TestExtremeDefaultValues::cpp_trigraph() const { - return *cpp_trigraph_; -} -inline void TestExtremeDefaultValues::set_cpp_trigraph(const ::std::string& value) { - set_has_cpp_trigraph(); - if (cpp_trigraph_ == &_default_cpp_trigraph_) { - cpp_trigraph_ = new ::std::string; - } - cpp_trigraph_->assign(value); -} -inline void TestExtremeDefaultValues::set_cpp_trigraph(const char* value) { - set_has_cpp_trigraph(); - if (cpp_trigraph_ == &_default_cpp_trigraph_) { - cpp_trigraph_ = new ::std::string; - } - cpp_trigraph_->assign(value); -} -inline void TestExtremeDefaultValues::set_cpp_trigraph(const char* value, size_t size) { - set_has_cpp_trigraph(); - if (cpp_trigraph_ == &_default_cpp_trigraph_) { - cpp_trigraph_ = new ::std::string; - } - cpp_trigraph_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestExtremeDefaultValues::mutable_cpp_trigraph() { - set_has_cpp_trigraph(); - if (cpp_trigraph_ == &_default_cpp_trigraph_) { - cpp_trigraph_ = new ::std::string(_default_cpp_trigraph_); - } - return cpp_trigraph_; -} -inline ::std::string* TestExtremeDefaultValues::release_cpp_trigraph() { - clear_has_cpp_trigraph(); - if (cpp_trigraph_ == &_default_cpp_trigraph_) { - return NULL; - } else { - ::std::string* temp = cpp_trigraph_; - cpp_trigraph_ = const_cast< ::std::string*>(&_default_cpp_trigraph_); - return temp; - } -} - -// ------------------------------------------------------------------- - -// SparseEnumMessage - -// optional .protobuf_unittest.TestSparseEnum sparse_enum = 1; -inline bool SparseEnumMessage::has_sparse_enum() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void SparseEnumMessage::set_has_sparse_enum() { - _has_bits_[0] |= 0x00000001u; -} -inline void SparseEnumMessage::clear_has_sparse_enum() { - _has_bits_[0] &= ~0x00000001u; -} -inline void SparseEnumMessage::clear_sparse_enum() { - sparse_enum_ = 123; - clear_has_sparse_enum(); -} -inline protobuf_unittest::TestSparseEnum SparseEnumMessage::sparse_enum() const { - return static_cast< protobuf_unittest::TestSparseEnum >(sparse_enum_); -} -inline void SparseEnumMessage::set_sparse_enum(protobuf_unittest::TestSparseEnum value) { - GOOGLE_DCHECK(protobuf_unittest::TestSparseEnum_IsValid(value)); - set_has_sparse_enum(); - sparse_enum_ = value; -} - -// ------------------------------------------------------------------- - -// OneString - -// optional string data = 1; -inline bool OneString::has_data() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void OneString::set_has_data() { - _has_bits_[0] |= 0x00000001u; -} -inline void OneString::clear_has_data() { - _has_bits_[0] &= ~0x00000001u; -} -inline void OneString::clear_data() { - if (data_ != &::google::protobuf::internal::kEmptyString) { - data_->clear(); - } - clear_has_data(); -} -inline const ::std::string& OneString::data() const { - return *data_; -} -inline void OneString::set_data(const ::std::string& value) { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - data_->assign(value); -} -inline void OneString::set_data(const char* value) { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - data_->assign(value); -} -inline void OneString::set_data(const char* value, size_t size) { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - data_->assign(reinterpret_cast(value), size); -} -inline ::std::string* OneString::mutable_data() { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - return data_; -} -inline ::std::string* OneString::release_data() { - clear_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = data_; - data_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// OneBytes - -// optional bytes data = 1; -inline bool OneBytes::has_data() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void OneBytes::set_has_data() { - _has_bits_[0] |= 0x00000001u; -} -inline void OneBytes::clear_has_data() { - _has_bits_[0] &= ~0x00000001u; -} -inline void OneBytes::clear_data() { - if (data_ != &::google::protobuf::internal::kEmptyString) { - data_->clear(); - } - clear_has_data(); -} -inline const ::std::string& OneBytes::data() const { - return *data_; -} -inline void OneBytes::set_data(const ::std::string& value) { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - data_->assign(value); -} -inline void OneBytes::set_data(const char* value) { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - data_->assign(value); -} -inline void OneBytes::set_data(const void* value, size_t size) { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - data_->assign(reinterpret_cast(value), size); -} -inline ::std::string* OneBytes::mutable_data() { - set_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - data_ = new ::std::string; - } - return data_; -} -inline ::std::string* OneBytes::release_data() { - clear_has_data(); - if (data_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = data_; - data_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// TestPackedTypes - -// repeated int32 packed_int32 = 90 [packed = true]; -inline int TestPackedTypes::packed_int32_size() const { - return packed_int32_.size(); -} -inline void TestPackedTypes::clear_packed_int32() { - packed_int32_.Clear(); -} -inline ::google::protobuf::int32 TestPackedTypes::packed_int32(int index) const { - return packed_int32_.Get(index); -} -inline void TestPackedTypes::set_packed_int32(int index, ::google::protobuf::int32 value) { - packed_int32_.Set(index, value); -} -inline void TestPackedTypes::add_packed_int32(::google::protobuf::int32 value) { - packed_int32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestPackedTypes::packed_int32() const { - return packed_int32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestPackedTypes::mutable_packed_int32() { - return &packed_int32_; -} - -// repeated int64 packed_int64 = 91 [packed = true]; -inline int TestPackedTypes::packed_int64_size() const { - return packed_int64_.size(); -} -inline void TestPackedTypes::clear_packed_int64() { - packed_int64_.Clear(); -} -inline ::google::protobuf::int64 TestPackedTypes::packed_int64(int index) const { - return packed_int64_.Get(index); -} -inline void TestPackedTypes::set_packed_int64(int index, ::google::protobuf::int64 value) { - packed_int64_.Set(index, value); -} -inline void TestPackedTypes::add_packed_int64(::google::protobuf::int64 value) { - packed_int64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestPackedTypes::packed_int64() const { - return packed_int64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestPackedTypes::mutable_packed_int64() { - return &packed_int64_; -} - -// repeated uint32 packed_uint32 = 92 [packed = true]; -inline int TestPackedTypes::packed_uint32_size() const { - return packed_uint32_.size(); -} -inline void TestPackedTypes::clear_packed_uint32() { - packed_uint32_.Clear(); -} -inline ::google::protobuf::uint32 TestPackedTypes::packed_uint32(int index) const { - return packed_uint32_.Get(index); -} -inline void TestPackedTypes::set_packed_uint32(int index, ::google::protobuf::uint32 value) { - packed_uint32_.Set(index, value); -} -inline void TestPackedTypes::add_packed_uint32(::google::protobuf::uint32 value) { - packed_uint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestPackedTypes::packed_uint32() const { - return packed_uint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestPackedTypes::mutable_packed_uint32() { - return &packed_uint32_; -} - -// repeated uint64 packed_uint64 = 93 [packed = true]; -inline int TestPackedTypes::packed_uint64_size() const { - return packed_uint64_.size(); -} -inline void TestPackedTypes::clear_packed_uint64() { - packed_uint64_.Clear(); -} -inline ::google::protobuf::uint64 TestPackedTypes::packed_uint64(int index) const { - return packed_uint64_.Get(index); -} -inline void TestPackedTypes::set_packed_uint64(int index, ::google::protobuf::uint64 value) { - packed_uint64_.Set(index, value); -} -inline void TestPackedTypes::add_packed_uint64(::google::protobuf::uint64 value) { - packed_uint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestPackedTypes::packed_uint64() const { - return packed_uint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestPackedTypes::mutable_packed_uint64() { - return &packed_uint64_; -} - -// repeated sint32 packed_sint32 = 94 [packed = true]; -inline int TestPackedTypes::packed_sint32_size() const { - return packed_sint32_.size(); -} -inline void TestPackedTypes::clear_packed_sint32() { - packed_sint32_.Clear(); -} -inline ::google::protobuf::int32 TestPackedTypes::packed_sint32(int index) const { - return packed_sint32_.Get(index); -} -inline void TestPackedTypes::set_packed_sint32(int index, ::google::protobuf::int32 value) { - packed_sint32_.Set(index, value); -} -inline void TestPackedTypes::add_packed_sint32(::google::protobuf::int32 value) { - packed_sint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestPackedTypes::packed_sint32() const { - return packed_sint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestPackedTypes::mutable_packed_sint32() { - return &packed_sint32_; -} - -// repeated sint64 packed_sint64 = 95 [packed = true]; -inline int TestPackedTypes::packed_sint64_size() const { - return packed_sint64_.size(); -} -inline void TestPackedTypes::clear_packed_sint64() { - packed_sint64_.Clear(); -} -inline ::google::protobuf::int64 TestPackedTypes::packed_sint64(int index) const { - return packed_sint64_.Get(index); -} -inline void TestPackedTypes::set_packed_sint64(int index, ::google::protobuf::int64 value) { - packed_sint64_.Set(index, value); -} -inline void TestPackedTypes::add_packed_sint64(::google::protobuf::int64 value) { - packed_sint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestPackedTypes::packed_sint64() const { - return packed_sint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestPackedTypes::mutable_packed_sint64() { - return &packed_sint64_; -} - -// repeated fixed32 packed_fixed32 = 96 [packed = true]; -inline int TestPackedTypes::packed_fixed32_size() const { - return packed_fixed32_.size(); -} -inline void TestPackedTypes::clear_packed_fixed32() { - packed_fixed32_.Clear(); -} -inline ::google::protobuf::uint32 TestPackedTypes::packed_fixed32(int index) const { - return packed_fixed32_.Get(index); -} -inline void TestPackedTypes::set_packed_fixed32(int index, ::google::protobuf::uint32 value) { - packed_fixed32_.Set(index, value); -} -inline void TestPackedTypes::add_packed_fixed32(::google::protobuf::uint32 value) { - packed_fixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestPackedTypes::packed_fixed32() const { - return packed_fixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestPackedTypes::mutable_packed_fixed32() { - return &packed_fixed32_; -} - -// repeated fixed64 packed_fixed64 = 97 [packed = true]; -inline int TestPackedTypes::packed_fixed64_size() const { - return packed_fixed64_.size(); -} -inline void TestPackedTypes::clear_packed_fixed64() { - packed_fixed64_.Clear(); -} -inline ::google::protobuf::uint64 TestPackedTypes::packed_fixed64(int index) const { - return packed_fixed64_.Get(index); -} -inline void TestPackedTypes::set_packed_fixed64(int index, ::google::protobuf::uint64 value) { - packed_fixed64_.Set(index, value); -} -inline void TestPackedTypes::add_packed_fixed64(::google::protobuf::uint64 value) { - packed_fixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestPackedTypes::packed_fixed64() const { - return packed_fixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestPackedTypes::mutable_packed_fixed64() { - return &packed_fixed64_; -} - -// repeated sfixed32 packed_sfixed32 = 98 [packed = true]; -inline int TestPackedTypes::packed_sfixed32_size() const { - return packed_sfixed32_.size(); -} -inline void TestPackedTypes::clear_packed_sfixed32() { - packed_sfixed32_.Clear(); -} -inline ::google::protobuf::int32 TestPackedTypes::packed_sfixed32(int index) const { - return packed_sfixed32_.Get(index); -} -inline void TestPackedTypes::set_packed_sfixed32(int index, ::google::protobuf::int32 value) { - packed_sfixed32_.Set(index, value); -} -inline void TestPackedTypes::add_packed_sfixed32(::google::protobuf::int32 value) { - packed_sfixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestPackedTypes::packed_sfixed32() const { - return packed_sfixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestPackedTypes::mutable_packed_sfixed32() { - return &packed_sfixed32_; -} - -// repeated sfixed64 packed_sfixed64 = 99 [packed = true]; -inline int TestPackedTypes::packed_sfixed64_size() const { - return packed_sfixed64_.size(); -} -inline void TestPackedTypes::clear_packed_sfixed64() { - packed_sfixed64_.Clear(); -} -inline ::google::protobuf::int64 TestPackedTypes::packed_sfixed64(int index) const { - return packed_sfixed64_.Get(index); -} -inline void TestPackedTypes::set_packed_sfixed64(int index, ::google::protobuf::int64 value) { - packed_sfixed64_.Set(index, value); -} -inline void TestPackedTypes::add_packed_sfixed64(::google::protobuf::int64 value) { - packed_sfixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestPackedTypes::packed_sfixed64() const { - return packed_sfixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestPackedTypes::mutable_packed_sfixed64() { - return &packed_sfixed64_; -} - -// repeated float packed_float = 100 [packed = true]; -inline int TestPackedTypes::packed_float_size() const { - return packed_float_.size(); -} -inline void TestPackedTypes::clear_packed_float() { - packed_float_.Clear(); -} -inline float TestPackedTypes::packed_float(int index) const { - return packed_float_.Get(index); -} -inline void TestPackedTypes::set_packed_float(int index, float value) { - packed_float_.Set(index, value); -} -inline void TestPackedTypes::add_packed_float(float value) { - packed_float_.Add(value); -} -inline const ::google::protobuf::RepeatedField< float >& -TestPackedTypes::packed_float() const { - return packed_float_; -} -inline ::google::protobuf::RepeatedField< float >* -TestPackedTypes::mutable_packed_float() { - return &packed_float_; -} - -// repeated double packed_double = 101 [packed = true]; -inline int TestPackedTypes::packed_double_size() const { - return packed_double_.size(); -} -inline void TestPackedTypes::clear_packed_double() { - packed_double_.Clear(); -} -inline double TestPackedTypes::packed_double(int index) const { - return packed_double_.Get(index); -} -inline void TestPackedTypes::set_packed_double(int index, double value) { - packed_double_.Set(index, value); -} -inline void TestPackedTypes::add_packed_double(double value) { - packed_double_.Add(value); -} -inline const ::google::protobuf::RepeatedField< double >& -TestPackedTypes::packed_double() const { - return packed_double_; -} -inline ::google::protobuf::RepeatedField< double >* -TestPackedTypes::mutable_packed_double() { - return &packed_double_; -} - -// repeated bool packed_bool = 102 [packed = true]; -inline int TestPackedTypes::packed_bool_size() const { - return packed_bool_.size(); -} -inline void TestPackedTypes::clear_packed_bool() { - packed_bool_.Clear(); -} -inline bool TestPackedTypes::packed_bool(int index) const { - return packed_bool_.Get(index); -} -inline void TestPackedTypes::set_packed_bool(int index, bool value) { - packed_bool_.Set(index, value); -} -inline void TestPackedTypes::add_packed_bool(bool value) { - packed_bool_.Add(value); -} -inline const ::google::protobuf::RepeatedField< bool >& -TestPackedTypes::packed_bool() const { - return packed_bool_; -} -inline ::google::protobuf::RepeatedField< bool >* -TestPackedTypes::mutable_packed_bool() { - return &packed_bool_; -} - -// repeated .protobuf_unittest.ForeignEnum packed_enum = 103 [packed = true]; -inline int TestPackedTypes::packed_enum_size() const { - return packed_enum_.size(); -} -inline void TestPackedTypes::clear_packed_enum() { - packed_enum_.Clear(); -} -inline protobuf_unittest::ForeignEnum TestPackedTypes::packed_enum(int index) const { - return static_cast< protobuf_unittest::ForeignEnum >(packed_enum_.Get(index)); -} -inline void TestPackedTypes::set_packed_enum(int index, protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - packed_enum_.Set(index, value); -} -inline void TestPackedTypes::add_packed_enum(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - packed_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestPackedTypes::packed_enum() const { - return packed_enum_; -} -inline ::google::protobuf::RepeatedField* -TestPackedTypes::mutable_packed_enum() { - return &packed_enum_; -} - -// ------------------------------------------------------------------- - -// TestUnpackedTypes - -// repeated int32 unpacked_int32 = 90 [packed = false]; -inline int TestUnpackedTypes::unpacked_int32_size() const { - return unpacked_int32_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_int32() { - unpacked_int32_.Clear(); -} -inline ::google::protobuf::int32 TestUnpackedTypes::unpacked_int32(int index) const { - return unpacked_int32_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_int32(int index, ::google::protobuf::int32 value) { - unpacked_int32_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_int32(::google::protobuf::int32 value) { - unpacked_int32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestUnpackedTypes::unpacked_int32() const { - return unpacked_int32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestUnpackedTypes::mutable_unpacked_int32() { - return &unpacked_int32_; -} - -// repeated int64 unpacked_int64 = 91 [packed = false]; -inline int TestUnpackedTypes::unpacked_int64_size() const { - return unpacked_int64_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_int64() { - unpacked_int64_.Clear(); -} -inline ::google::protobuf::int64 TestUnpackedTypes::unpacked_int64(int index) const { - return unpacked_int64_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_int64(int index, ::google::protobuf::int64 value) { - unpacked_int64_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_int64(::google::protobuf::int64 value) { - unpacked_int64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestUnpackedTypes::unpacked_int64() const { - return unpacked_int64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestUnpackedTypes::mutable_unpacked_int64() { - return &unpacked_int64_; -} - -// repeated uint32 unpacked_uint32 = 92 [packed = false]; -inline int TestUnpackedTypes::unpacked_uint32_size() const { - return unpacked_uint32_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_uint32() { - unpacked_uint32_.Clear(); -} -inline ::google::protobuf::uint32 TestUnpackedTypes::unpacked_uint32(int index) const { - return unpacked_uint32_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_uint32(int index, ::google::protobuf::uint32 value) { - unpacked_uint32_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_uint32(::google::protobuf::uint32 value) { - unpacked_uint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestUnpackedTypes::unpacked_uint32() const { - return unpacked_uint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestUnpackedTypes::mutable_unpacked_uint32() { - return &unpacked_uint32_; -} - -// repeated uint64 unpacked_uint64 = 93 [packed = false]; -inline int TestUnpackedTypes::unpacked_uint64_size() const { - return unpacked_uint64_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_uint64() { - unpacked_uint64_.Clear(); -} -inline ::google::protobuf::uint64 TestUnpackedTypes::unpacked_uint64(int index) const { - return unpacked_uint64_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_uint64(int index, ::google::protobuf::uint64 value) { - unpacked_uint64_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_uint64(::google::protobuf::uint64 value) { - unpacked_uint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestUnpackedTypes::unpacked_uint64() const { - return unpacked_uint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestUnpackedTypes::mutable_unpacked_uint64() { - return &unpacked_uint64_; -} - -// repeated sint32 unpacked_sint32 = 94 [packed = false]; -inline int TestUnpackedTypes::unpacked_sint32_size() const { - return unpacked_sint32_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_sint32() { - unpacked_sint32_.Clear(); -} -inline ::google::protobuf::int32 TestUnpackedTypes::unpacked_sint32(int index) const { - return unpacked_sint32_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_sint32(int index, ::google::protobuf::int32 value) { - unpacked_sint32_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_sint32(::google::protobuf::int32 value) { - unpacked_sint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestUnpackedTypes::unpacked_sint32() const { - return unpacked_sint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestUnpackedTypes::mutable_unpacked_sint32() { - return &unpacked_sint32_; -} - -// repeated sint64 unpacked_sint64 = 95 [packed = false]; -inline int TestUnpackedTypes::unpacked_sint64_size() const { - return unpacked_sint64_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_sint64() { - unpacked_sint64_.Clear(); -} -inline ::google::protobuf::int64 TestUnpackedTypes::unpacked_sint64(int index) const { - return unpacked_sint64_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_sint64(int index, ::google::protobuf::int64 value) { - unpacked_sint64_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_sint64(::google::protobuf::int64 value) { - unpacked_sint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestUnpackedTypes::unpacked_sint64() const { - return unpacked_sint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestUnpackedTypes::mutable_unpacked_sint64() { - return &unpacked_sint64_; -} - -// repeated fixed32 unpacked_fixed32 = 96 [packed = false]; -inline int TestUnpackedTypes::unpacked_fixed32_size() const { - return unpacked_fixed32_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_fixed32() { - unpacked_fixed32_.Clear(); -} -inline ::google::protobuf::uint32 TestUnpackedTypes::unpacked_fixed32(int index) const { - return unpacked_fixed32_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_fixed32(int index, ::google::protobuf::uint32 value) { - unpacked_fixed32_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_fixed32(::google::protobuf::uint32 value) { - unpacked_fixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestUnpackedTypes::unpacked_fixed32() const { - return unpacked_fixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestUnpackedTypes::mutable_unpacked_fixed32() { - return &unpacked_fixed32_; -} - -// repeated fixed64 unpacked_fixed64 = 97 [packed = false]; -inline int TestUnpackedTypes::unpacked_fixed64_size() const { - return unpacked_fixed64_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_fixed64() { - unpacked_fixed64_.Clear(); -} -inline ::google::protobuf::uint64 TestUnpackedTypes::unpacked_fixed64(int index) const { - return unpacked_fixed64_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_fixed64(int index, ::google::protobuf::uint64 value) { - unpacked_fixed64_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_fixed64(::google::protobuf::uint64 value) { - unpacked_fixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestUnpackedTypes::unpacked_fixed64() const { - return unpacked_fixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestUnpackedTypes::mutable_unpacked_fixed64() { - return &unpacked_fixed64_; -} - -// repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; -inline int TestUnpackedTypes::unpacked_sfixed32_size() const { - return unpacked_sfixed32_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_sfixed32() { - unpacked_sfixed32_.Clear(); -} -inline ::google::protobuf::int32 TestUnpackedTypes::unpacked_sfixed32(int index) const { - return unpacked_sfixed32_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_sfixed32(int index, ::google::protobuf::int32 value) { - unpacked_sfixed32_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_sfixed32(::google::protobuf::int32 value) { - unpacked_sfixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestUnpackedTypes::unpacked_sfixed32() const { - return unpacked_sfixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestUnpackedTypes::mutable_unpacked_sfixed32() { - return &unpacked_sfixed32_; -} - -// repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; -inline int TestUnpackedTypes::unpacked_sfixed64_size() const { - return unpacked_sfixed64_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_sfixed64() { - unpacked_sfixed64_.Clear(); -} -inline ::google::protobuf::int64 TestUnpackedTypes::unpacked_sfixed64(int index) const { - return unpacked_sfixed64_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_sfixed64(int index, ::google::protobuf::int64 value) { - unpacked_sfixed64_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_sfixed64(::google::protobuf::int64 value) { - unpacked_sfixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestUnpackedTypes::unpacked_sfixed64() const { - return unpacked_sfixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestUnpackedTypes::mutable_unpacked_sfixed64() { - return &unpacked_sfixed64_; -} - -// repeated float unpacked_float = 100 [packed = false]; -inline int TestUnpackedTypes::unpacked_float_size() const { - return unpacked_float_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_float() { - unpacked_float_.Clear(); -} -inline float TestUnpackedTypes::unpacked_float(int index) const { - return unpacked_float_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_float(int index, float value) { - unpacked_float_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_float(float value) { - unpacked_float_.Add(value); -} -inline const ::google::protobuf::RepeatedField< float >& -TestUnpackedTypes::unpacked_float() const { - return unpacked_float_; -} -inline ::google::protobuf::RepeatedField< float >* -TestUnpackedTypes::mutable_unpacked_float() { - return &unpacked_float_; -} - -// repeated double unpacked_double = 101 [packed = false]; -inline int TestUnpackedTypes::unpacked_double_size() const { - return unpacked_double_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_double() { - unpacked_double_.Clear(); -} -inline double TestUnpackedTypes::unpacked_double(int index) const { - return unpacked_double_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_double(int index, double value) { - unpacked_double_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_double(double value) { - unpacked_double_.Add(value); -} -inline const ::google::protobuf::RepeatedField< double >& -TestUnpackedTypes::unpacked_double() const { - return unpacked_double_; -} -inline ::google::protobuf::RepeatedField< double >* -TestUnpackedTypes::mutable_unpacked_double() { - return &unpacked_double_; -} - -// repeated bool unpacked_bool = 102 [packed = false]; -inline int TestUnpackedTypes::unpacked_bool_size() const { - return unpacked_bool_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_bool() { - unpacked_bool_.Clear(); -} -inline bool TestUnpackedTypes::unpacked_bool(int index) const { - return unpacked_bool_.Get(index); -} -inline void TestUnpackedTypes::set_unpacked_bool(int index, bool value) { - unpacked_bool_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_bool(bool value) { - unpacked_bool_.Add(value); -} -inline const ::google::protobuf::RepeatedField< bool >& -TestUnpackedTypes::unpacked_bool() const { - return unpacked_bool_; -} -inline ::google::protobuf::RepeatedField< bool >* -TestUnpackedTypes::mutable_unpacked_bool() { - return &unpacked_bool_; -} - -// repeated .protobuf_unittest.ForeignEnum unpacked_enum = 103 [packed = false]; -inline int TestUnpackedTypes::unpacked_enum_size() const { - return unpacked_enum_.size(); -} -inline void TestUnpackedTypes::clear_unpacked_enum() { - unpacked_enum_.Clear(); -} -inline protobuf_unittest::ForeignEnum TestUnpackedTypes::unpacked_enum(int index) const { - return static_cast< protobuf_unittest::ForeignEnum >(unpacked_enum_.Get(index)); -} -inline void TestUnpackedTypes::set_unpacked_enum(int index, protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - unpacked_enum_.Set(index, value); -} -inline void TestUnpackedTypes::add_unpacked_enum(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - unpacked_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestUnpackedTypes::unpacked_enum() const { - return unpacked_enum_; -} -inline ::google::protobuf::RepeatedField* -TestUnpackedTypes::mutable_unpacked_enum() { - return &unpacked_enum_; -} - -// ------------------------------------------------------------------- - -// TestPackedExtensions - -// ------------------------------------------------------------------- - -// TestDynamicExtensions_DynamicMessageType - -// optional int32 dynamic_field = 2100; -inline bool TestDynamicExtensions_DynamicMessageType::has_dynamic_field() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestDynamicExtensions_DynamicMessageType::set_has_dynamic_field() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestDynamicExtensions_DynamicMessageType::clear_has_dynamic_field() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestDynamicExtensions_DynamicMessageType::clear_dynamic_field() { - dynamic_field_ = 0; - clear_has_dynamic_field(); -} -inline ::google::protobuf::int32 TestDynamicExtensions_DynamicMessageType::dynamic_field() const { - return dynamic_field_; -} -inline void TestDynamicExtensions_DynamicMessageType::set_dynamic_field(::google::protobuf::int32 value) { - set_has_dynamic_field(); - dynamic_field_ = value; -} - -// ------------------------------------------------------------------- - -// TestDynamicExtensions - -// optional fixed32 scalar_extension = 2000; -inline bool TestDynamicExtensions::has_scalar_extension() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestDynamicExtensions::set_has_scalar_extension() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestDynamicExtensions::clear_has_scalar_extension() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestDynamicExtensions::clear_scalar_extension() { - scalar_extension_ = 0u; - clear_has_scalar_extension(); -} -inline ::google::protobuf::uint32 TestDynamicExtensions::scalar_extension() const { - return scalar_extension_; -} -inline void TestDynamicExtensions::set_scalar_extension(::google::protobuf::uint32 value) { - set_has_scalar_extension(); - scalar_extension_ = value; -} - -// optional .protobuf_unittest.ForeignEnum enum_extension = 2001; -inline bool TestDynamicExtensions::has_enum_extension() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestDynamicExtensions::set_has_enum_extension() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestDynamicExtensions::clear_has_enum_extension() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestDynamicExtensions::clear_enum_extension() { - enum_extension_ = 4; - clear_has_enum_extension(); -} -inline protobuf_unittest::ForeignEnum TestDynamicExtensions::enum_extension() const { - return static_cast< protobuf_unittest::ForeignEnum >(enum_extension_); -} -inline void TestDynamicExtensions::set_enum_extension(protobuf_unittest::ForeignEnum value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnum_IsValid(value)); - set_has_enum_extension(); - enum_extension_ = value; -} - -// optional .protobuf_unittest.TestDynamicExtensions.DynamicEnumType dynamic_enum_extension = 2002; -inline bool TestDynamicExtensions::has_dynamic_enum_extension() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestDynamicExtensions::set_has_dynamic_enum_extension() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestDynamicExtensions::clear_has_dynamic_enum_extension() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestDynamicExtensions::clear_dynamic_enum_extension() { - dynamic_enum_extension_ = 2200; - clear_has_dynamic_enum_extension(); -} -inline ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType TestDynamicExtensions::dynamic_enum_extension() const { - return static_cast< ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType >(dynamic_enum_extension_); -} -inline void TestDynamicExtensions::set_dynamic_enum_extension(::protobuf_unittest::TestDynamicExtensions_DynamicEnumType value) { - GOOGLE_DCHECK(::protobuf_unittest::TestDynamicExtensions_DynamicEnumType_IsValid(value)); - set_has_dynamic_enum_extension(); - dynamic_enum_extension_ = value; -} - -// optional .protobuf_unittest.ForeignMessage message_extension = 2003; -inline bool TestDynamicExtensions::has_message_extension() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void TestDynamicExtensions::set_has_message_extension() { - _has_bits_[0] |= 0x00000008u; -} -inline void TestDynamicExtensions::clear_has_message_extension() { - _has_bits_[0] &= ~0x00000008u; -} -inline void TestDynamicExtensions::clear_message_extension() { - if (message_extension_ != NULL) message_extension_->::protobuf_unittest::ForeignMessage::Clear(); - clear_has_message_extension(); -} -inline const ::protobuf_unittest::ForeignMessage& TestDynamicExtensions::message_extension() const { - return message_extension_ != NULL ? *message_extension_ : *default_instance_->message_extension_; -} -inline ::protobuf_unittest::ForeignMessage* TestDynamicExtensions::mutable_message_extension() { - set_has_message_extension(); - if (message_extension_ == NULL) message_extension_ = new ::protobuf_unittest::ForeignMessage; - return message_extension_; -} -inline ::protobuf_unittest::ForeignMessage* TestDynamicExtensions::release_message_extension() { - clear_has_message_extension(); - ::protobuf_unittest::ForeignMessage* temp = message_extension_; - message_extension_ = NULL; - return temp; -} - -// optional .protobuf_unittest.TestDynamicExtensions.DynamicMessageType dynamic_message_extension = 2004; -inline bool TestDynamicExtensions::has_dynamic_message_extension() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TestDynamicExtensions::set_has_dynamic_message_extension() { - _has_bits_[0] |= 0x00000010u; -} -inline void TestDynamicExtensions::clear_has_dynamic_message_extension() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TestDynamicExtensions::clear_dynamic_message_extension() { - if (dynamic_message_extension_ != NULL) dynamic_message_extension_->::protobuf_unittest::TestDynamicExtensions_DynamicMessageType::Clear(); - clear_has_dynamic_message_extension(); -} -inline const ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType& TestDynamicExtensions::dynamic_message_extension() const { - return dynamic_message_extension_ != NULL ? *dynamic_message_extension_ : *default_instance_->dynamic_message_extension_; -} -inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* TestDynamicExtensions::mutable_dynamic_message_extension() { - set_has_dynamic_message_extension(); - if (dynamic_message_extension_ == NULL) dynamic_message_extension_ = new ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType; - return dynamic_message_extension_; -} -inline ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* TestDynamicExtensions::release_dynamic_message_extension() { - clear_has_dynamic_message_extension(); - ::protobuf_unittest::TestDynamicExtensions_DynamicMessageType* temp = dynamic_message_extension_; - dynamic_message_extension_ = NULL; - return temp; -} - -// repeated string repeated_extension = 2005; -inline int TestDynamicExtensions::repeated_extension_size() const { - return repeated_extension_.size(); -} -inline void TestDynamicExtensions::clear_repeated_extension() { - repeated_extension_.Clear(); -} -inline const ::std::string& TestDynamicExtensions::repeated_extension(int index) const { - return repeated_extension_.Get(index); -} -inline ::std::string* TestDynamicExtensions::mutable_repeated_extension(int index) { - return repeated_extension_.Mutable(index); -} -inline void TestDynamicExtensions::set_repeated_extension(int index, const ::std::string& value) { - repeated_extension_.Mutable(index)->assign(value); -} -inline void TestDynamicExtensions::set_repeated_extension(int index, const char* value) { - repeated_extension_.Mutable(index)->assign(value); -} -inline void TestDynamicExtensions::set_repeated_extension(int index, const char* value, size_t size) { - repeated_extension_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestDynamicExtensions::add_repeated_extension() { - return repeated_extension_.Add(); -} -inline void TestDynamicExtensions::add_repeated_extension(const ::std::string& value) { - repeated_extension_.Add()->assign(value); -} -inline void TestDynamicExtensions::add_repeated_extension(const char* value) { - repeated_extension_.Add()->assign(value); -} -inline void TestDynamicExtensions::add_repeated_extension(const char* value, size_t size) { - repeated_extension_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestDynamicExtensions::repeated_extension() const { - return repeated_extension_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestDynamicExtensions::mutable_repeated_extension() { - return &repeated_extension_; -} - -// repeated sint32 packed_extension = 2006 [packed = true]; -inline int TestDynamicExtensions::packed_extension_size() const { - return packed_extension_.size(); -} -inline void TestDynamicExtensions::clear_packed_extension() { - packed_extension_.Clear(); -} -inline ::google::protobuf::int32 TestDynamicExtensions::packed_extension(int index) const { - return packed_extension_.Get(index); -} -inline void TestDynamicExtensions::set_packed_extension(int index, ::google::protobuf::int32 value) { - packed_extension_.Set(index, value); -} -inline void TestDynamicExtensions::add_packed_extension(::google::protobuf::int32 value) { - packed_extension_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestDynamicExtensions::packed_extension() const { - return packed_extension_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestDynamicExtensions::mutable_packed_extension() { - return &packed_extension_; -} - -// ------------------------------------------------------------------- - -// TestRepeatedScalarDifferentTagSizes - -// repeated fixed32 repeated_fixed32 = 12; -inline int TestRepeatedScalarDifferentTagSizes::repeated_fixed32_size() const { - return repeated_fixed32_.size(); -} -inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_fixed32() { - repeated_fixed32_.Clear(); -} -inline ::google::protobuf::uint32 TestRepeatedScalarDifferentTagSizes::repeated_fixed32(int index) const { - return repeated_fixed32_.Get(index); -} -inline void TestRepeatedScalarDifferentTagSizes::set_repeated_fixed32(int index, ::google::protobuf::uint32 value) { - repeated_fixed32_.Set(index, value); -} -inline void TestRepeatedScalarDifferentTagSizes::add_repeated_fixed32(::google::protobuf::uint32 value) { - repeated_fixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestRepeatedScalarDifferentTagSizes::repeated_fixed32() const { - return repeated_fixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestRepeatedScalarDifferentTagSizes::mutable_repeated_fixed32() { - return &repeated_fixed32_; -} - -// repeated int32 repeated_int32 = 13; -inline int TestRepeatedScalarDifferentTagSizes::repeated_int32_size() const { - return repeated_int32_.size(); -} -inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_int32() { - repeated_int32_.Clear(); -} -inline ::google::protobuf::int32 TestRepeatedScalarDifferentTagSizes::repeated_int32(int index) const { - return repeated_int32_.Get(index); -} -inline void TestRepeatedScalarDifferentTagSizes::set_repeated_int32(int index, ::google::protobuf::int32 value) { - repeated_int32_.Set(index, value); -} -inline void TestRepeatedScalarDifferentTagSizes::add_repeated_int32(::google::protobuf::int32 value) { - repeated_int32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestRepeatedScalarDifferentTagSizes::repeated_int32() const { - return repeated_int32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestRepeatedScalarDifferentTagSizes::mutable_repeated_int32() { - return &repeated_int32_; -} - -// repeated fixed64 repeated_fixed64 = 2046; -inline int TestRepeatedScalarDifferentTagSizes::repeated_fixed64_size() const { - return repeated_fixed64_.size(); -} -inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_fixed64() { - repeated_fixed64_.Clear(); -} -inline ::google::protobuf::uint64 TestRepeatedScalarDifferentTagSizes::repeated_fixed64(int index) const { - return repeated_fixed64_.Get(index); -} -inline void TestRepeatedScalarDifferentTagSizes::set_repeated_fixed64(int index, ::google::protobuf::uint64 value) { - repeated_fixed64_.Set(index, value); -} -inline void TestRepeatedScalarDifferentTagSizes::add_repeated_fixed64(::google::protobuf::uint64 value) { - repeated_fixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestRepeatedScalarDifferentTagSizes::repeated_fixed64() const { - return repeated_fixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestRepeatedScalarDifferentTagSizes::mutable_repeated_fixed64() { - return &repeated_fixed64_; -} - -// repeated int64 repeated_int64 = 2047; -inline int TestRepeatedScalarDifferentTagSizes::repeated_int64_size() const { - return repeated_int64_.size(); -} -inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_int64() { - repeated_int64_.Clear(); -} -inline ::google::protobuf::int64 TestRepeatedScalarDifferentTagSizes::repeated_int64(int index) const { - return repeated_int64_.Get(index); -} -inline void TestRepeatedScalarDifferentTagSizes::set_repeated_int64(int index, ::google::protobuf::int64 value) { - repeated_int64_.Set(index, value); -} -inline void TestRepeatedScalarDifferentTagSizes::add_repeated_int64(::google::protobuf::int64 value) { - repeated_int64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestRepeatedScalarDifferentTagSizes::repeated_int64() const { - return repeated_int64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestRepeatedScalarDifferentTagSizes::mutable_repeated_int64() { - return &repeated_int64_; -} - -// repeated float repeated_float = 262142; -inline int TestRepeatedScalarDifferentTagSizes::repeated_float_size() const { - return repeated_float_.size(); -} -inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_float() { - repeated_float_.Clear(); -} -inline float TestRepeatedScalarDifferentTagSizes::repeated_float(int index) const { - return repeated_float_.Get(index); -} -inline void TestRepeatedScalarDifferentTagSizes::set_repeated_float(int index, float value) { - repeated_float_.Set(index, value); -} -inline void TestRepeatedScalarDifferentTagSizes::add_repeated_float(float value) { - repeated_float_.Add(value); -} -inline const ::google::protobuf::RepeatedField< float >& -TestRepeatedScalarDifferentTagSizes::repeated_float() const { - return repeated_float_; -} -inline ::google::protobuf::RepeatedField< float >* -TestRepeatedScalarDifferentTagSizes::mutable_repeated_float() { - return &repeated_float_; -} - -// repeated uint64 repeated_uint64 = 262143; -inline int TestRepeatedScalarDifferentTagSizes::repeated_uint64_size() const { - return repeated_uint64_.size(); -} -inline void TestRepeatedScalarDifferentTagSizes::clear_repeated_uint64() { - repeated_uint64_.Clear(); -} -inline ::google::protobuf::uint64 TestRepeatedScalarDifferentTagSizes::repeated_uint64(int index) const { - return repeated_uint64_.Get(index); -} -inline void TestRepeatedScalarDifferentTagSizes::set_repeated_uint64(int index, ::google::protobuf::uint64 value) { - repeated_uint64_.Set(index, value); -} -inline void TestRepeatedScalarDifferentTagSizes::add_repeated_uint64(::google::protobuf::uint64 value) { - repeated_uint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestRepeatedScalarDifferentTagSizes::repeated_uint64() const { - return repeated_uint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestRepeatedScalarDifferentTagSizes::mutable_repeated_uint64() { - return &repeated_uint64_; -} - -// ------------------------------------------------------------------- - -// FooRequest - -// ------------------------------------------------------------------- - -// FooResponse - -// ------------------------------------------------------------------- - -// BarRequest - -// ------------------------------------------------------------------- - -// BarResponse - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestAllTypes_NestedEnum>() { - return ::protobuf_unittest::TestAllTypes_NestedEnum_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType>() { - return ::protobuf_unittest::TestDynamicExtensions_DynamicEnumType_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::ForeignEnum>() { - return protobuf_unittest::ForeignEnum_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::TestEnumWithDupValue>() { - return protobuf_unittest::TestEnumWithDupValue_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::TestSparseEnum>() { - return protobuf_unittest::TestSparseEnum_descriptor(); -} - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h deleted file mode 100644 index c4e16bbe..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +++ /dev/null @@ -1,2895 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_custom_options.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include "google/protobuf/descriptor.pb.h" -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - -class TestMessageWithCustomOptions; -class CustomOptionFooRequest; -class CustomOptionFooResponse; -class DummyMessageContainingEnum; -class DummyMessageInvalidAsOptionType; -class CustomOptionMinIntegerValues; -class CustomOptionMaxIntegerValues; -class CustomOptionOtherValues; -class SettingRealsFromPositiveInts; -class SettingRealsFromNegativeInts; -class ComplexOptionType1; -class ComplexOptionType2; -class ComplexOptionType2_ComplexOptionType4; -class ComplexOptionType3; -class ComplexOptionType3_ComplexOptionType5; -class ComplexOpt6; -class VariousComplexOptions; -class AggregateMessageSet; -class AggregateMessageSetElement; -class Aggregate; -class AggregateMessage; - -enum TestMessageWithCustomOptions_AnEnum { - TestMessageWithCustomOptions_AnEnum_ANENUM_VAL1 = 1, - TestMessageWithCustomOptions_AnEnum_ANENUM_VAL2 = 2 -}; -bool TestMessageWithCustomOptions_AnEnum_IsValid(int value); -const TestMessageWithCustomOptions_AnEnum TestMessageWithCustomOptions_AnEnum_AnEnum_MIN = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL1; -const TestMessageWithCustomOptions_AnEnum TestMessageWithCustomOptions_AnEnum_AnEnum_MAX = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL2; -const int TestMessageWithCustomOptions_AnEnum_AnEnum_ARRAYSIZE = TestMessageWithCustomOptions_AnEnum_AnEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TestMessageWithCustomOptions_AnEnum_descriptor(); -inline const ::std::string& TestMessageWithCustomOptions_AnEnum_Name(TestMessageWithCustomOptions_AnEnum value) { - return ::google::protobuf::internal::NameOfEnum( - TestMessageWithCustomOptions_AnEnum_descriptor(), value); -} -inline bool TestMessageWithCustomOptions_AnEnum_Parse( - const ::std::string& name, TestMessageWithCustomOptions_AnEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TestMessageWithCustomOptions_AnEnum_descriptor(), name, value); -} -enum DummyMessageContainingEnum_TestEnumType { - DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE1 = 22, - DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE2 = -23 -}; -bool DummyMessageContainingEnum_TestEnumType_IsValid(int value); -const DummyMessageContainingEnum_TestEnumType DummyMessageContainingEnum_TestEnumType_TestEnumType_MIN = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE2; -const DummyMessageContainingEnum_TestEnumType DummyMessageContainingEnum_TestEnumType_TestEnumType_MAX = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE1; -const int DummyMessageContainingEnum_TestEnumType_TestEnumType_ARRAYSIZE = DummyMessageContainingEnum_TestEnumType_TestEnumType_MAX + 1; - -const ::google::protobuf::EnumDescriptor* DummyMessageContainingEnum_TestEnumType_descriptor(); -inline const ::std::string& DummyMessageContainingEnum_TestEnumType_Name(DummyMessageContainingEnum_TestEnumType value) { - return ::google::protobuf::internal::NameOfEnum( - DummyMessageContainingEnum_TestEnumType_descriptor(), value); -} -inline bool DummyMessageContainingEnum_TestEnumType_Parse( - const ::std::string& name, DummyMessageContainingEnum_TestEnumType* value) { - return ::google::protobuf::internal::ParseNamedEnum( - DummyMessageContainingEnum_TestEnumType_descriptor(), name, value); -} -enum MethodOpt1 { - METHODOPT1_VAL1 = 1, - METHODOPT1_VAL2 = 2 -}; -bool MethodOpt1_IsValid(int value); -const MethodOpt1 MethodOpt1_MIN = METHODOPT1_VAL1; -const MethodOpt1 MethodOpt1_MAX = METHODOPT1_VAL2; -const int MethodOpt1_ARRAYSIZE = MethodOpt1_MAX + 1; - -const ::google::protobuf::EnumDescriptor* MethodOpt1_descriptor(); -inline const ::std::string& MethodOpt1_Name(MethodOpt1 value) { - return ::google::protobuf::internal::NameOfEnum( - MethodOpt1_descriptor(), value); -} -inline bool MethodOpt1_Parse( - const ::std::string& name, MethodOpt1* value) { - return ::google::protobuf::internal::ParseNamedEnum( - MethodOpt1_descriptor(), name, value); -} -enum AggregateEnum { - VALUE = 1 -}; -bool AggregateEnum_IsValid(int value); -const AggregateEnum AggregateEnum_MIN = VALUE; -const AggregateEnum AggregateEnum_MAX = VALUE; -const int AggregateEnum_ARRAYSIZE = AggregateEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* AggregateEnum_descriptor(); -inline const ::std::string& AggregateEnum_Name(AggregateEnum value) { - return ::google::protobuf::internal::NameOfEnum( - AggregateEnum_descriptor(), value); -} -inline bool AggregateEnum_Parse( - const ::std::string& name, AggregateEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - AggregateEnum_descriptor(), name, value); -} -// =================================================================== - -class TestMessageWithCustomOptions : public ::google::protobuf::Message { - public: - TestMessageWithCustomOptions(); - virtual ~TestMessageWithCustomOptions(); - - TestMessageWithCustomOptions(const TestMessageWithCustomOptions& from); - - inline TestMessageWithCustomOptions& operator=(const TestMessageWithCustomOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMessageWithCustomOptions& default_instance(); - - void Swap(TestMessageWithCustomOptions* other); - - // implements Message ---------------------------------------------- - - TestMessageWithCustomOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMessageWithCustomOptions& from); - void MergeFrom(const TestMessageWithCustomOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef TestMessageWithCustomOptions_AnEnum AnEnum; - static const AnEnum ANENUM_VAL1 = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL1; - static const AnEnum ANENUM_VAL2 = TestMessageWithCustomOptions_AnEnum_ANENUM_VAL2; - static inline bool AnEnum_IsValid(int value) { - return TestMessageWithCustomOptions_AnEnum_IsValid(value); - } - static const AnEnum AnEnum_MIN = - TestMessageWithCustomOptions_AnEnum_AnEnum_MIN; - static const AnEnum AnEnum_MAX = - TestMessageWithCustomOptions_AnEnum_AnEnum_MAX; - static const int AnEnum_ARRAYSIZE = - TestMessageWithCustomOptions_AnEnum_AnEnum_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - AnEnum_descriptor() { - return TestMessageWithCustomOptions_AnEnum_descriptor(); - } - static inline const ::std::string& AnEnum_Name(AnEnum value) { - return TestMessageWithCustomOptions_AnEnum_Name(value); - } - static inline bool AnEnum_Parse(const ::std::string& name, - AnEnum* value) { - return TestMessageWithCustomOptions_AnEnum_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional string field1 = 1 [ctype = CORD]; - inline bool has_field1() const; - inline void clear_field1(); - static const int kField1FieldNumber = 1; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& field1() const; - inline void set_field1(const ::std::string& value); - inline void set_field1(const char* value); - inline void set_field1(const char* value, size_t size); - inline ::std::string* mutable_field1(); - inline ::std::string* release_field1(); - public: - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageWithCustomOptions) - private: - inline void set_has_field1(); - inline void clear_has_field1(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* field1_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static TestMessageWithCustomOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class CustomOptionFooRequest : public ::google::protobuf::Message { - public: - CustomOptionFooRequest(); - virtual ~CustomOptionFooRequest(); - - CustomOptionFooRequest(const CustomOptionFooRequest& from); - - inline CustomOptionFooRequest& operator=(const CustomOptionFooRequest& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CustomOptionFooRequest& default_instance(); - - void Swap(CustomOptionFooRequest* other); - - // implements Message ---------------------------------------------- - - CustomOptionFooRequest* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CustomOptionFooRequest& from); - void MergeFrom(const CustomOptionFooRequest& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionFooRequest) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static CustomOptionFooRequest* default_instance_; -}; -// ------------------------------------------------------------------- - -class CustomOptionFooResponse : public ::google::protobuf::Message { - public: - CustomOptionFooResponse(); - virtual ~CustomOptionFooResponse(); - - CustomOptionFooResponse(const CustomOptionFooResponse& from); - - inline CustomOptionFooResponse& operator=(const CustomOptionFooResponse& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CustomOptionFooResponse& default_instance(); - - void Swap(CustomOptionFooResponse* other); - - // implements Message ---------------------------------------------- - - CustomOptionFooResponse* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CustomOptionFooResponse& from); - void MergeFrom(const CustomOptionFooResponse& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionFooResponse) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static CustomOptionFooResponse* default_instance_; -}; -// ------------------------------------------------------------------- - -class DummyMessageContainingEnum : public ::google::protobuf::Message { - public: - DummyMessageContainingEnum(); - virtual ~DummyMessageContainingEnum(); - - DummyMessageContainingEnum(const DummyMessageContainingEnum& from); - - inline DummyMessageContainingEnum& operator=(const DummyMessageContainingEnum& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DummyMessageContainingEnum& default_instance(); - - void Swap(DummyMessageContainingEnum* other); - - // implements Message ---------------------------------------------- - - DummyMessageContainingEnum* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DummyMessageContainingEnum& from); - void MergeFrom(const DummyMessageContainingEnum& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef DummyMessageContainingEnum_TestEnumType TestEnumType; - static const TestEnumType TEST_OPTION_ENUM_TYPE1 = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE1; - static const TestEnumType TEST_OPTION_ENUM_TYPE2 = DummyMessageContainingEnum_TestEnumType_TEST_OPTION_ENUM_TYPE2; - static inline bool TestEnumType_IsValid(int value) { - return DummyMessageContainingEnum_TestEnumType_IsValid(value); - } - static const TestEnumType TestEnumType_MIN = - DummyMessageContainingEnum_TestEnumType_TestEnumType_MIN; - static const TestEnumType TestEnumType_MAX = - DummyMessageContainingEnum_TestEnumType_TestEnumType_MAX; - static const int TestEnumType_ARRAYSIZE = - DummyMessageContainingEnum_TestEnumType_TestEnumType_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - TestEnumType_descriptor() { - return DummyMessageContainingEnum_TestEnumType_descriptor(); - } - static inline const ::std::string& TestEnumType_Name(TestEnumType value) { - return DummyMessageContainingEnum_TestEnumType_Name(value); - } - static inline bool TestEnumType_Parse(const ::std::string& name, - TestEnumType* value) { - return DummyMessageContainingEnum_TestEnumType_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.DummyMessageContainingEnum) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static DummyMessageContainingEnum* default_instance_; -}; -// ------------------------------------------------------------------- - -class DummyMessageInvalidAsOptionType : public ::google::protobuf::Message { - public: - DummyMessageInvalidAsOptionType(); - virtual ~DummyMessageInvalidAsOptionType(); - - DummyMessageInvalidAsOptionType(const DummyMessageInvalidAsOptionType& from); - - inline DummyMessageInvalidAsOptionType& operator=(const DummyMessageInvalidAsOptionType& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DummyMessageInvalidAsOptionType& default_instance(); - - void Swap(DummyMessageInvalidAsOptionType* other); - - // implements Message ---------------------------------------------- - - DummyMessageInvalidAsOptionType* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DummyMessageInvalidAsOptionType& from); - void MergeFrom(const DummyMessageInvalidAsOptionType& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.DummyMessageInvalidAsOptionType) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static DummyMessageInvalidAsOptionType* default_instance_; -}; -// ------------------------------------------------------------------- - -class CustomOptionMinIntegerValues : public ::google::protobuf::Message { - public: - CustomOptionMinIntegerValues(); - virtual ~CustomOptionMinIntegerValues(); - - CustomOptionMinIntegerValues(const CustomOptionMinIntegerValues& from); - - inline CustomOptionMinIntegerValues& operator=(const CustomOptionMinIntegerValues& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CustomOptionMinIntegerValues& default_instance(); - - void Swap(CustomOptionMinIntegerValues* other); - - // implements Message ---------------------------------------------- - - CustomOptionMinIntegerValues* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CustomOptionMinIntegerValues& from); - void MergeFrom(const CustomOptionMinIntegerValues& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionMinIntegerValues) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static CustomOptionMinIntegerValues* default_instance_; -}; -// ------------------------------------------------------------------- - -class CustomOptionMaxIntegerValues : public ::google::protobuf::Message { - public: - CustomOptionMaxIntegerValues(); - virtual ~CustomOptionMaxIntegerValues(); - - CustomOptionMaxIntegerValues(const CustomOptionMaxIntegerValues& from); - - inline CustomOptionMaxIntegerValues& operator=(const CustomOptionMaxIntegerValues& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CustomOptionMaxIntegerValues& default_instance(); - - void Swap(CustomOptionMaxIntegerValues* other); - - // implements Message ---------------------------------------------- - - CustomOptionMaxIntegerValues* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CustomOptionMaxIntegerValues& from); - void MergeFrom(const CustomOptionMaxIntegerValues& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionMaxIntegerValues) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static CustomOptionMaxIntegerValues* default_instance_; -}; -// ------------------------------------------------------------------- - -class CustomOptionOtherValues : public ::google::protobuf::Message { - public: - CustomOptionOtherValues(); - virtual ~CustomOptionOtherValues(); - - CustomOptionOtherValues(const CustomOptionOtherValues& from); - - inline CustomOptionOtherValues& operator=(const CustomOptionOtherValues& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CustomOptionOtherValues& default_instance(); - - void Swap(CustomOptionOtherValues* other); - - // implements Message ---------------------------------------------- - - CustomOptionOtherValues* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CustomOptionOtherValues& from); - void MergeFrom(const CustomOptionOtherValues& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.CustomOptionOtherValues) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static CustomOptionOtherValues* default_instance_; -}; -// ------------------------------------------------------------------- - -class SettingRealsFromPositiveInts : public ::google::protobuf::Message { - public: - SettingRealsFromPositiveInts(); - virtual ~SettingRealsFromPositiveInts(); - - SettingRealsFromPositiveInts(const SettingRealsFromPositiveInts& from); - - inline SettingRealsFromPositiveInts& operator=(const SettingRealsFromPositiveInts& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SettingRealsFromPositiveInts& default_instance(); - - void Swap(SettingRealsFromPositiveInts* other); - - // implements Message ---------------------------------------------- - - SettingRealsFromPositiveInts* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SettingRealsFromPositiveInts& from); - void MergeFrom(const SettingRealsFromPositiveInts& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.SettingRealsFromPositiveInts) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static SettingRealsFromPositiveInts* default_instance_; -}; -// ------------------------------------------------------------------- - -class SettingRealsFromNegativeInts : public ::google::protobuf::Message { - public: - SettingRealsFromNegativeInts(); - virtual ~SettingRealsFromNegativeInts(); - - SettingRealsFromNegativeInts(const SettingRealsFromNegativeInts& from); - - inline SettingRealsFromNegativeInts& operator=(const SettingRealsFromNegativeInts& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SettingRealsFromNegativeInts& default_instance(); - - void Swap(SettingRealsFromNegativeInts* other); - - // implements Message ---------------------------------------------- - - SettingRealsFromNegativeInts* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SettingRealsFromNegativeInts& from); - void MergeFrom(const SettingRealsFromNegativeInts& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.SettingRealsFromNegativeInts) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static SettingRealsFromNegativeInts* default_instance_; -}; -// ------------------------------------------------------------------- - -class ComplexOptionType1 : public ::google::protobuf::Message { - public: - ComplexOptionType1(); - virtual ~ComplexOptionType1(); - - ComplexOptionType1(const ComplexOptionType1& from); - - inline ComplexOptionType1& operator=(const ComplexOptionType1& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ComplexOptionType1& default_instance(); - - void Swap(ComplexOptionType1* other); - - // implements Message ---------------------------------------------- - - ComplexOptionType1* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ComplexOptionType1& from); - void MergeFrom(const ComplexOptionType1& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 foo = 1; - inline bool has_foo() const; - inline void clear_foo(); - static const int kFooFieldNumber = 1; - inline ::google::protobuf::int32 foo() const; - inline void set_foo(::google::protobuf::int32 value); - - // optional int32 foo2 = 2; - inline bool has_foo2() const; - inline void clear_foo2(); - static const int kFoo2FieldNumber = 2; - inline ::google::protobuf::int32 foo2() const; - inline void set_foo2(::google::protobuf::int32 value); - - // optional int32 foo3 = 3; - inline bool has_foo3() const; - inline void clear_foo3(); - static const int kFoo3FieldNumber = 3; - inline ::google::protobuf::int32 foo3() const; - inline void set_foo3(::google::protobuf::int32 value); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ComplexOptionType1) - // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType1) - private: - inline void set_has_foo(); - inline void clear_has_foo(); - inline void set_has_foo2(); - inline void clear_has_foo2(); - inline void set_has_foo3(); - inline void clear_has_foo3(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 foo_; - ::google::protobuf::int32 foo2_; - ::google::protobuf::int32 foo3_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static ComplexOptionType1* default_instance_; -}; -// ------------------------------------------------------------------- - -class ComplexOptionType2_ComplexOptionType4 : public ::google::protobuf::Message { - public: - ComplexOptionType2_ComplexOptionType4(); - virtual ~ComplexOptionType2_ComplexOptionType4(); - - ComplexOptionType2_ComplexOptionType4(const ComplexOptionType2_ComplexOptionType4& from); - - inline ComplexOptionType2_ComplexOptionType4& operator=(const ComplexOptionType2_ComplexOptionType4& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ComplexOptionType2_ComplexOptionType4& default_instance(); - - void Swap(ComplexOptionType2_ComplexOptionType4* other); - - // implements Message ---------------------------------------------- - - ComplexOptionType2_ComplexOptionType4* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ComplexOptionType2_ComplexOptionType4& from); - void MergeFrom(const ComplexOptionType2_ComplexOptionType4& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 waldo = 1; - inline bool has_waldo() const; - inline void clear_waldo(); - static const int kWaldoFieldNumber = 1; - inline ::google::protobuf::int32 waldo() const; - inline void set_waldo(::google::protobuf::int32 value); - - static const int kComplexOpt4FieldNumber = 7633546; - static ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4 >, 11, false > - complex_opt4; - // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType2.ComplexOptionType4) - private: - inline void set_has_waldo(); - inline void clear_has_waldo(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 waldo_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static ComplexOptionType2_ComplexOptionType4* default_instance_; -}; -// ------------------------------------------------------------------- - -class ComplexOptionType2 : public ::google::protobuf::Message { - public: - ComplexOptionType2(); - virtual ~ComplexOptionType2(); - - ComplexOptionType2(const ComplexOptionType2& from); - - inline ComplexOptionType2& operator=(const ComplexOptionType2& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ComplexOptionType2& default_instance(); - - void Swap(ComplexOptionType2* other); - - // implements Message ---------------------------------------------- - - ComplexOptionType2* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ComplexOptionType2& from); - void MergeFrom(const ComplexOptionType2& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef ComplexOptionType2_ComplexOptionType4 ComplexOptionType4; - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.ComplexOptionType1 bar = 1; - inline bool has_bar() const; - inline void clear_bar(); - static const int kBarFieldNumber = 1; - inline const ::protobuf_unittest::ComplexOptionType1& bar() const; - inline ::protobuf_unittest::ComplexOptionType1* mutable_bar(); - inline ::protobuf_unittest::ComplexOptionType1* release_bar(); - - // optional int32 baz = 2; - inline bool has_baz() const; - inline void clear_baz(); - static const int kBazFieldNumber = 2; - inline ::google::protobuf::int32 baz() const; - inline void set_baz(::google::protobuf::int32 value); - - // optional .protobuf_unittest.ComplexOptionType2.ComplexOptionType4 fred = 3; - inline bool has_fred() const; - inline void clear_fred(); - static const int kFredFieldNumber = 3; - inline const ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4& fred() const; - inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* mutable_fred(); - inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* release_fred(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ComplexOptionType2) - // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType2) - private: - inline void set_has_bar(); - inline void clear_has_bar(); - inline void set_has_baz(); - inline void clear_has_baz(); - inline void set_has_fred(); - inline void clear_has_fred(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::ComplexOptionType1* bar_; - ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* fred_; - ::google::protobuf::int32 baz_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static ComplexOptionType2* default_instance_; -}; -// ------------------------------------------------------------------- - -class ComplexOptionType3_ComplexOptionType5 : public ::google::protobuf::Message { - public: - ComplexOptionType3_ComplexOptionType5(); - virtual ~ComplexOptionType3_ComplexOptionType5(); - - ComplexOptionType3_ComplexOptionType5(const ComplexOptionType3_ComplexOptionType5& from); - - inline ComplexOptionType3_ComplexOptionType5& operator=(const ComplexOptionType3_ComplexOptionType5& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ComplexOptionType3_ComplexOptionType5& default_instance(); - - void Swap(ComplexOptionType3_ComplexOptionType5* other); - - // implements Message ---------------------------------------------- - - ComplexOptionType3_ComplexOptionType5* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ComplexOptionType3_ComplexOptionType5& from); - void MergeFrom(const ComplexOptionType3_ComplexOptionType5& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 plugh = 3; - inline bool has_plugh() const; - inline void clear_plugh(); - static const int kPlughFieldNumber = 3; - inline ::google::protobuf::int32 plugh() const; - inline void set_plugh(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType3.ComplexOptionType5) - private: - inline void set_has_plugh(); - inline void clear_has_plugh(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 plugh_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static ComplexOptionType3_ComplexOptionType5* default_instance_; -}; -// ------------------------------------------------------------------- - -class ComplexOptionType3 : public ::google::protobuf::Message { - public: - ComplexOptionType3(); - virtual ~ComplexOptionType3(); - - ComplexOptionType3(const ComplexOptionType3& from); - - inline ComplexOptionType3& operator=(const ComplexOptionType3& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ComplexOptionType3& default_instance(); - - void Swap(ComplexOptionType3* other); - - // implements Message ---------------------------------------------- - - ComplexOptionType3* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ComplexOptionType3& from); - void MergeFrom(const ComplexOptionType3& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef ComplexOptionType3_ComplexOptionType5 ComplexOptionType5; - - // accessors ------------------------------------------------------- - - // optional int32 qux = 1; - inline bool has_qux() const; - inline void clear_qux(); - static const int kQuxFieldNumber = 1; - inline ::google::protobuf::int32 qux() const; - inline void set_qux(::google::protobuf::int32 value); - - // optional group ComplexOptionType5 = 2 { - inline bool has_complexoptiontype5() const; - inline void clear_complexoptiontype5(); - static const int kComplexoptiontype5FieldNumber = 2; - inline const ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5& complexoptiontype5() const; - inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* mutable_complexoptiontype5(); - inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* release_complexoptiontype5(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOptionType3) - private: - inline void set_has_qux(); - inline void clear_has_qux(); - inline void set_has_complexoptiontype5(); - inline void clear_has_complexoptiontype5(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* complexoptiontype5_; - ::google::protobuf::int32 qux_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static ComplexOptionType3* default_instance_; -}; -// ------------------------------------------------------------------- - -class ComplexOpt6 : public ::google::protobuf::Message { - public: - ComplexOpt6(); - virtual ~ComplexOpt6(); - - ComplexOpt6(const ComplexOpt6& from); - - inline ComplexOpt6& operator=(const ComplexOpt6& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ComplexOpt6& default_instance(); - - void Swap(ComplexOpt6* other); - - // implements Message ---------------------------------------------- - - ComplexOpt6* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ComplexOpt6& from); - void MergeFrom(const ComplexOpt6& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 xyzzy = 7593951; - inline bool has_xyzzy() const; - inline void clear_xyzzy(); - static const int kXyzzyFieldNumber = 7593951; - inline ::google::protobuf::int32 xyzzy() const; - inline void set_xyzzy(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.ComplexOpt6) - private: - inline void set_has_xyzzy(); - inline void clear_has_xyzzy(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 xyzzy_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static ComplexOpt6* default_instance_; -}; -// ------------------------------------------------------------------- - -class VariousComplexOptions : public ::google::protobuf::Message { - public: - VariousComplexOptions(); - virtual ~VariousComplexOptions(); - - VariousComplexOptions(const VariousComplexOptions& from); - - inline VariousComplexOptions& operator=(const VariousComplexOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const VariousComplexOptions& default_instance(); - - void Swap(VariousComplexOptions* other); - - // implements Message ---------------------------------------------- - - VariousComplexOptions* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const VariousComplexOptions& from); - void MergeFrom(const VariousComplexOptions& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:protobuf_unittest.VariousComplexOptions) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static VariousComplexOptions* default_instance_; -}; -// ------------------------------------------------------------------- - -class AggregateMessageSet : public ::google::protobuf::Message { - public: - AggregateMessageSet(); - virtual ~AggregateMessageSet(); - - AggregateMessageSet(const AggregateMessageSet& from); - - inline AggregateMessageSet& operator=(const AggregateMessageSet& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const AggregateMessageSet& default_instance(); - - void Swap(AggregateMessageSet* other); - - // implements Message ---------------------------------------------- - - AggregateMessageSet* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const AggregateMessageSet& from); - void MergeFrom(const AggregateMessageSet& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(AggregateMessageSet) - // @@protoc_insertion_point(class_scope:protobuf_unittest.AggregateMessageSet) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static AggregateMessageSet* default_instance_; -}; -// ------------------------------------------------------------------- - -class AggregateMessageSetElement : public ::google::protobuf::Message { - public: - AggregateMessageSetElement(); - virtual ~AggregateMessageSetElement(); - - AggregateMessageSetElement(const AggregateMessageSetElement& from); - - inline AggregateMessageSetElement& operator=(const AggregateMessageSetElement& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const AggregateMessageSetElement& default_instance(); - - void Swap(AggregateMessageSetElement* other); - - // implements Message ---------------------------------------------- - - AggregateMessageSetElement* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const AggregateMessageSetElement& from); - void MergeFrom(const AggregateMessageSetElement& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string s = 1; - inline bool has_s() const; - inline void clear_s(); - static const int kSFieldNumber = 1; - inline const ::std::string& s() const; - inline void set_s(const ::std::string& value); - inline void set_s(const char* value); - inline void set_s(const char* value, size_t size); - inline ::std::string* mutable_s(); - inline ::std::string* release_s(); - - static const int kMessageSetExtensionFieldNumber = 15447542; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::AggregateMessageSet, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::AggregateMessageSetElement >, 11, false > - message_set_extension; - // @@protoc_insertion_point(class_scope:protobuf_unittest.AggregateMessageSetElement) - private: - inline void set_has_s(); - inline void clear_has_s(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* s_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static AggregateMessageSetElement* default_instance_; -}; -// ------------------------------------------------------------------- - -class Aggregate : public ::google::protobuf::Message { - public: - Aggregate(); - virtual ~Aggregate(); - - Aggregate(const Aggregate& from); - - inline Aggregate& operator=(const Aggregate& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Aggregate& default_instance(); - - void Swap(Aggregate* other); - - // implements Message ---------------------------------------------- - - Aggregate* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Aggregate& from); - void MergeFrom(const Aggregate& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 i = 1; - inline bool has_i() const; - inline void clear_i(); - static const int kIFieldNumber = 1; - inline ::google::protobuf::int32 i() const; - inline void set_i(::google::protobuf::int32 value); - - // optional string s = 2; - inline bool has_s() const; - inline void clear_s(); - static const int kSFieldNumber = 2; - inline const ::std::string& s() const; - inline void set_s(const ::std::string& value); - inline void set_s(const char* value); - inline void set_s(const char* value, size_t size); - inline ::std::string* mutable_s(); - inline ::std::string* release_s(); - - // optional .protobuf_unittest.Aggregate sub = 3; - inline bool has_sub() const; - inline void clear_sub(); - static const int kSubFieldNumber = 3; - inline const ::protobuf_unittest::Aggregate& sub() const; - inline ::protobuf_unittest::Aggregate* mutable_sub(); - inline ::protobuf_unittest::Aggregate* release_sub(); - - // optional .google.protobuf.FileOptions file = 4; - inline bool has_file() const; - inline void clear_file(); - static const int kFileFieldNumber = 4; - inline const ::google::protobuf::FileOptions& file() const; - inline ::google::protobuf::FileOptions* mutable_file(); - inline ::google::protobuf::FileOptions* release_file(); - - // optional .protobuf_unittest.AggregateMessageSet mset = 5; - inline bool has_mset() const; - inline void clear_mset(); - static const int kMsetFieldNumber = 5; - inline const ::protobuf_unittest::AggregateMessageSet& mset() const; - inline ::protobuf_unittest::AggregateMessageSet* mutable_mset(); - inline ::protobuf_unittest::AggregateMessageSet* release_mset(); - - static const int kNestedFieldNumber = 15476903; - static ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FileOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - nested; - // @@protoc_insertion_point(class_scope:protobuf_unittest.Aggregate) - private: - inline void set_has_i(); - inline void clear_has_i(); - inline void set_has_s(); - inline void clear_has_s(); - inline void set_has_sub(); - inline void clear_has_sub(); - inline void set_has_file(); - inline void clear_has_file(); - inline void set_has_mset(); - inline void clear_has_mset(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* s_; - ::protobuf_unittest::Aggregate* sub_; - ::google::protobuf::FileOptions* file_; - ::protobuf_unittest::AggregateMessageSet* mset_; - ::google::protobuf::int32 i_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(5 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static Aggregate* default_instance_; -}; -// ------------------------------------------------------------------- - -class AggregateMessage : public ::google::protobuf::Message { - public: - AggregateMessage(); - virtual ~AggregateMessage(); - - AggregateMessage(const AggregateMessage& from); - - inline AggregateMessage& operator=(const AggregateMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const AggregateMessage& default_instance(); - - void Swap(AggregateMessage* other); - - // implements Message ---------------------------------------------- - - AggregateMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const AggregateMessage& from); - void MergeFrom(const AggregateMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 fieldname = 1; - inline bool has_fieldname() const; - inline void clear_fieldname(); - static const int kFieldnameFieldNumber = 1; - inline ::google::protobuf::int32 fieldname() const; - inline void set_fieldname(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.AggregateMessage) - private: - inline void set_has_fieldname(); - inline void clear_has_fieldname(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 fieldname_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto(); - - void InitAsDefaultInstance(); - static AggregateMessage* default_instance_; -}; -// =================================================================== - -class TestServiceWithCustomOptions_Stub; - -class TestServiceWithCustomOptions : public ::google::protobuf::Service { - protected: - // This class should be treated as an abstract interface. - inline TestServiceWithCustomOptions() {}; - public: - virtual ~TestServiceWithCustomOptions(); - - typedef TestServiceWithCustomOptions_Stub Stub; - - static const ::google::protobuf::ServiceDescriptor* descriptor(); - - virtual void Foo(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::CustomOptionFooRequest* request, - ::protobuf_unittest::CustomOptionFooResponse* response, - ::google::protobuf::Closure* done); - - // implements Service ---------------------------------------------- - - const ::google::protobuf::ServiceDescriptor* GetDescriptor(); - void CallMethod(const ::google::protobuf::MethodDescriptor* method, - ::google::protobuf::RpcController* controller, - const ::google::protobuf::Message* request, - ::google::protobuf::Message* response, - ::google::protobuf::Closure* done); - const ::google::protobuf::Message& GetRequestPrototype( - const ::google::protobuf::MethodDescriptor* method) const; - const ::google::protobuf::Message& GetResponsePrototype( - const ::google::protobuf::MethodDescriptor* method) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestServiceWithCustomOptions); -}; - -class TestServiceWithCustomOptions_Stub : public TestServiceWithCustomOptions { - public: - TestServiceWithCustomOptions_Stub(::google::protobuf::RpcChannel* channel); - TestServiceWithCustomOptions_Stub(::google::protobuf::RpcChannel* channel, - ::google::protobuf::Service::ChannelOwnership ownership); - ~TestServiceWithCustomOptions_Stub(); - - inline ::google::protobuf::RpcChannel* channel() { return channel_; } - - // implements TestServiceWithCustomOptions ------------------------------------------ - - void Foo(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::CustomOptionFooRequest* request, - ::protobuf_unittest::CustomOptionFooResponse* response, - ::google::protobuf::Closure* done); - private: - ::google::protobuf::RpcChannel* channel_; - bool owns_channel_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestServiceWithCustomOptions_Stub); -}; - - -// ------------------------------------------------------------------- - -class AggregateService_Stub; - -class AggregateService : public ::google::protobuf::Service { - protected: - // This class should be treated as an abstract interface. - inline AggregateService() {}; - public: - virtual ~AggregateService(); - - typedef AggregateService_Stub Stub; - - static const ::google::protobuf::ServiceDescriptor* descriptor(); - - virtual void Method(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::AggregateMessage* request, - ::protobuf_unittest::AggregateMessage* response, - ::google::protobuf::Closure* done); - - // implements Service ---------------------------------------------- - - const ::google::protobuf::ServiceDescriptor* GetDescriptor(); - void CallMethod(const ::google::protobuf::MethodDescriptor* method, - ::google::protobuf::RpcController* controller, - const ::google::protobuf::Message* request, - ::google::protobuf::Message* response, - ::google::protobuf::Closure* done); - const ::google::protobuf::Message& GetRequestPrototype( - const ::google::protobuf::MethodDescriptor* method) const; - const ::google::protobuf::Message& GetResponsePrototype( - const ::google::protobuf::MethodDescriptor* method) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AggregateService); -}; - -class AggregateService_Stub : public AggregateService { - public: - AggregateService_Stub(::google::protobuf::RpcChannel* channel); - AggregateService_Stub(::google::protobuf::RpcChannel* channel, - ::google::protobuf::Service::ChannelOwnership ownership); - ~AggregateService_Stub(); - - inline ::google::protobuf::RpcChannel* channel() { return channel_; } - - // implements AggregateService ------------------------------------------ - - void Method(::google::protobuf::RpcController* controller, - const ::protobuf_unittest::AggregateMessage* request, - ::protobuf_unittest::AggregateMessage* response, - ::google::protobuf::Closure* done); - private: - ::google::protobuf::RpcChannel* channel_; - bool owns_channel_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AggregateService_Stub); -}; - - -// =================================================================== - -static const int kFileOpt1FieldNumber = 7736974; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FileOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - file_opt1; -static const int kMessageOpt1FieldNumber = 7739036; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - message_opt1; -static const int kFieldOpt1FieldNumber = 7740936; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - field_opt1; -static const int kFieldOpt2FieldNumber = 7753913; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - field_opt2; -static const int kEnumOpt1FieldNumber = 7753576; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - enum_opt1; -static const int kEnumValueOpt1FieldNumber = 1560678; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumValueOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - enum_value_opt1; -static const int kServiceOpt1FieldNumber = 7887650; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::ServiceOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - service_opt1; -static const int kMethodOpt1FieldNumber = 7890860; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::MethodOpt1, protobuf_unittest::MethodOpt1_IsValid>, 14, false > - method_opt1; -static const int kBoolOptFieldNumber = 7706090; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > - bool_opt; -static const int kInt32OptFieldNumber = 7705709; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - int32_opt; -static const int kInt64OptFieldNumber = 7705542; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > - int64_opt; -static const int kUint32OptFieldNumber = 7704880; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > - uint32_opt; -static const int kUint64OptFieldNumber = 7702367; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - uint64_opt; -static const int kSint32OptFieldNumber = 7701568; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > - sint32_opt; -static const int kSint64OptFieldNumber = 7700863; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - sint64_opt; -static const int kFixed32OptFieldNumber = 7700307; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > - fixed32_opt; -static const int kFixed64OptFieldNumber = 7700194; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - fixed64_opt; -static const int kSfixed32OptFieldNumber = 7698645; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - sfixed32_opt; -static const int kSfixed64OptFieldNumber = 7685475; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > - sfixed64_opt; -static const int kFloatOptFieldNumber = 7675390; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > - float_opt; -static const int kDoubleOptFieldNumber = 7673293; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > - double_opt; -static const int kStringOptFieldNumber = 7673285; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::StringTypeTraits, 9, false > - string_opt; -static const int kBytesOptFieldNumber = 7673238; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::StringTypeTraits, 12, false > - bytes_opt; -static const int kEnumOptFieldNumber = 7673233; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType, ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType_IsValid>, 14, false > - enum_opt; -static const int kMessageTypeOptFieldNumber = 7665967; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::DummyMessageInvalidAsOptionType >, 11, false > - message_type_opt; -static const int kQuuxFieldNumber = 7663707; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType1, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - quux; -static const int kCorgeFieldNumber = 7663442; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType1, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType3 >, 11, false > - corge; -static const int kGraultFieldNumber = 7650927; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType2, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - grault; -static const int kGarplyFieldNumber = 7649992; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::ComplexOptionType2, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType1 >, 11, false > - garply; -static const int kComplexOpt1FieldNumber = 7646756; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType1 >, 11, false > - complex_opt1; -static const int kComplexOpt2FieldNumber = 7636949; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType2 >, 11, false > - complex_opt2; -static const int kComplexOpt3FieldNumber = 7636463; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOptionType3 >, 11, false > - complex_opt3; -static const int kComplexopt6FieldNumber = 7595468; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ComplexOpt6 >, 10, false > - complexopt6; -static const int kFileoptFieldNumber = 15478479; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FileOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - fileopt; -static const int kMsgoptFieldNumber = 15480088; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - msgopt; -static const int kFieldoptFieldNumber = 15481374; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - fieldopt; -static const int kEnumoptFieldNumber = 15483218; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - enumopt; -static const int kEnumvaloptFieldNumber = 15486921; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::EnumValueOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - enumvalopt; -static const int kServiceoptFieldNumber = 15497145; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::ServiceOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - serviceopt; -static const int kMethodoptFieldNumber = 15512713; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::Aggregate >, 11, false > - methodopt; - -// =================================================================== - -// TestMessageWithCustomOptions - -// optional string field1 = 1 [ctype = CORD]; -inline bool TestMessageWithCustomOptions::has_field1() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestMessageWithCustomOptions::set_has_field1() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestMessageWithCustomOptions::clear_has_field1() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestMessageWithCustomOptions::clear_field1() { - if (field1_ != &::google::protobuf::internal::kEmptyString) { - field1_->clear(); - } - clear_has_field1(); -} -inline const ::std::string& TestMessageWithCustomOptions::field1() const { - return *field1_; -} -inline void TestMessageWithCustomOptions::set_field1(const ::std::string& value) { - set_has_field1(); - if (field1_ == &::google::protobuf::internal::kEmptyString) { - field1_ = new ::std::string; - } - field1_->assign(value); -} -inline void TestMessageWithCustomOptions::set_field1(const char* value) { - set_has_field1(); - if (field1_ == &::google::protobuf::internal::kEmptyString) { - field1_ = new ::std::string; - } - field1_->assign(value); -} -inline void TestMessageWithCustomOptions::set_field1(const char* value, size_t size) { - set_has_field1(); - if (field1_ == &::google::protobuf::internal::kEmptyString) { - field1_ = new ::std::string; - } - field1_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestMessageWithCustomOptions::mutable_field1() { - set_has_field1(); - if (field1_ == &::google::protobuf::internal::kEmptyString) { - field1_ = new ::std::string; - } - return field1_; -} -inline ::std::string* TestMessageWithCustomOptions::release_field1() { - clear_has_field1(); - if (field1_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = field1_; - field1_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// CustomOptionFooRequest - -// ------------------------------------------------------------------- - -// CustomOptionFooResponse - -// ------------------------------------------------------------------- - -// DummyMessageContainingEnum - -// ------------------------------------------------------------------- - -// DummyMessageInvalidAsOptionType - -// ------------------------------------------------------------------- - -// CustomOptionMinIntegerValues - -// ------------------------------------------------------------------- - -// CustomOptionMaxIntegerValues - -// ------------------------------------------------------------------- - -// CustomOptionOtherValues - -// ------------------------------------------------------------------- - -// SettingRealsFromPositiveInts - -// ------------------------------------------------------------------- - -// SettingRealsFromNegativeInts - -// ------------------------------------------------------------------- - -// ComplexOptionType1 - -// optional int32 foo = 1; -inline bool ComplexOptionType1::has_foo() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ComplexOptionType1::set_has_foo() { - _has_bits_[0] |= 0x00000001u; -} -inline void ComplexOptionType1::clear_has_foo() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ComplexOptionType1::clear_foo() { - foo_ = 0; - clear_has_foo(); -} -inline ::google::protobuf::int32 ComplexOptionType1::foo() const { - return foo_; -} -inline void ComplexOptionType1::set_foo(::google::protobuf::int32 value) { - set_has_foo(); - foo_ = value; -} - -// optional int32 foo2 = 2; -inline bool ComplexOptionType1::has_foo2() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void ComplexOptionType1::set_has_foo2() { - _has_bits_[0] |= 0x00000002u; -} -inline void ComplexOptionType1::clear_has_foo2() { - _has_bits_[0] &= ~0x00000002u; -} -inline void ComplexOptionType1::clear_foo2() { - foo2_ = 0; - clear_has_foo2(); -} -inline ::google::protobuf::int32 ComplexOptionType1::foo2() const { - return foo2_; -} -inline void ComplexOptionType1::set_foo2(::google::protobuf::int32 value) { - set_has_foo2(); - foo2_ = value; -} - -// optional int32 foo3 = 3; -inline bool ComplexOptionType1::has_foo3() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void ComplexOptionType1::set_has_foo3() { - _has_bits_[0] |= 0x00000004u; -} -inline void ComplexOptionType1::clear_has_foo3() { - _has_bits_[0] &= ~0x00000004u; -} -inline void ComplexOptionType1::clear_foo3() { - foo3_ = 0; - clear_has_foo3(); -} -inline ::google::protobuf::int32 ComplexOptionType1::foo3() const { - return foo3_; -} -inline void ComplexOptionType1::set_foo3(::google::protobuf::int32 value) { - set_has_foo3(); - foo3_ = value; -} - -// ------------------------------------------------------------------- - -// ComplexOptionType2_ComplexOptionType4 - -// optional int32 waldo = 1; -inline bool ComplexOptionType2_ComplexOptionType4::has_waldo() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ComplexOptionType2_ComplexOptionType4::set_has_waldo() { - _has_bits_[0] |= 0x00000001u; -} -inline void ComplexOptionType2_ComplexOptionType4::clear_has_waldo() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ComplexOptionType2_ComplexOptionType4::clear_waldo() { - waldo_ = 0; - clear_has_waldo(); -} -inline ::google::protobuf::int32 ComplexOptionType2_ComplexOptionType4::waldo() const { - return waldo_; -} -inline void ComplexOptionType2_ComplexOptionType4::set_waldo(::google::protobuf::int32 value) { - set_has_waldo(); - waldo_ = value; -} - -// ------------------------------------------------------------------- - -// ComplexOptionType2 - -// optional .protobuf_unittest.ComplexOptionType1 bar = 1; -inline bool ComplexOptionType2::has_bar() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ComplexOptionType2::set_has_bar() { - _has_bits_[0] |= 0x00000001u; -} -inline void ComplexOptionType2::clear_has_bar() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ComplexOptionType2::clear_bar() { - if (bar_ != NULL) bar_->::protobuf_unittest::ComplexOptionType1::Clear(); - clear_has_bar(); -} -inline const ::protobuf_unittest::ComplexOptionType1& ComplexOptionType2::bar() const { - return bar_ != NULL ? *bar_ : *default_instance_->bar_; -} -inline ::protobuf_unittest::ComplexOptionType1* ComplexOptionType2::mutable_bar() { - set_has_bar(); - if (bar_ == NULL) bar_ = new ::protobuf_unittest::ComplexOptionType1; - return bar_; -} -inline ::protobuf_unittest::ComplexOptionType1* ComplexOptionType2::release_bar() { - clear_has_bar(); - ::protobuf_unittest::ComplexOptionType1* temp = bar_; - bar_ = NULL; - return temp; -} - -// optional int32 baz = 2; -inline bool ComplexOptionType2::has_baz() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void ComplexOptionType2::set_has_baz() { - _has_bits_[0] |= 0x00000002u; -} -inline void ComplexOptionType2::clear_has_baz() { - _has_bits_[0] &= ~0x00000002u; -} -inline void ComplexOptionType2::clear_baz() { - baz_ = 0; - clear_has_baz(); -} -inline ::google::protobuf::int32 ComplexOptionType2::baz() const { - return baz_; -} -inline void ComplexOptionType2::set_baz(::google::protobuf::int32 value) { - set_has_baz(); - baz_ = value; -} - -// optional .protobuf_unittest.ComplexOptionType2.ComplexOptionType4 fred = 3; -inline bool ComplexOptionType2::has_fred() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void ComplexOptionType2::set_has_fred() { - _has_bits_[0] |= 0x00000004u; -} -inline void ComplexOptionType2::clear_has_fred() { - _has_bits_[0] &= ~0x00000004u; -} -inline void ComplexOptionType2::clear_fred() { - if (fred_ != NULL) fred_->::protobuf_unittest::ComplexOptionType2_ComplexOptionType4::Clear(); - clear_has_fred(); -} -inline const ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4& ComplexOptionType2::fred() const { - return fred_ != NULL ? *fred_ : *default_instance_->fred_; -} -inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* ComplexOptionType2::mutable_fred() { - set_has_fred(); - if (fred_ == NULL) fred_ = new ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4; - return fred_; -} -inline ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* ComplexOptionType2::release_fred() { - clear_has_fred(); - ::protobuf_unittest::ComplexOptionType2_ComplexOptionType4* temp = fred_; - fred_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// ComplexOptionType3_ComplexOptionType5 - -// optional int32 plugh = 3; -inline bool ComplexOptionType3_ComplexOptionType5::has_plugh() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ComplexOptionType3_ComplexOptionType5::set_has_plugh() { - _has_bits_[0] |= 0x00000001u; -} -inline void ComplexOptionType3_ComplexOptionType5::clear_has_plugh() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ComplexOptionType3_ComplexOptionType5::clear_plugh() { - plugh_ = 0; - clear_has_plugh(); -} -inline ::google::protobuf::int32 ComplexOptionType3_ComplexOptionType5::plugh() const { - return plugh_; -} -inline void ComplexOptionType3_ComplexOptionType5::set_plugh(::google::protobuf::int32 value) { - set_has_plugh(); - plugh_ = value; -} - -// ------------------------------------------------------------------- - -// ComplexOptionType3 - -// optional int32 qux = 1; -inline bool ComplexOptionType3::has_qux() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ComplexOptionType3::set_has_qux() { - _has_bits_[0] |= 0x00000001u; -} -inline void ComplexOptionType3::clear_has_qux() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ComplexOptionType3::clear_qux() { - qux_ = 0; - clear_has_qux(); -} -inline ::google::protobuf::int32 ComplexOptionType3::qux() const { - return qux_; -} -inline void ComplexOptionType3::set_qux(::google::protobuf::int32 value) { - set_has_qux(); - qux_ = value; -} - -// optional group ComplexOptionType5 = 2 { -inline bool ComplexOptionType3::has_complexoptiontype5() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void ComplexOptionType3::set_has_complexoptiontype5() { - _has_bits_[0] |= 0x00000002u; -} -inline void ComplexOptionType3::clear_has_complexoptiontype5() { - _has_bits_[0] &= ~0x00000002u; -} -inline void ComplexOptionType3::clear_complexoptiontype5() { - if (complexoptiontype5_ != NULL) complexoptiontype5_->::protobuf_unittest::ComplexOptionType3_ComplexOptionType5::Clear(); - clear_has_complexoptiontype5(); -} -inline const ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5& ComplexOptionType3::complexoptiontype5() const { - return complexoptiontype5_ != NULL ? *complexoptiontype5_ : *default_instance_->complexoptiontype5_; -} -inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* ComplexOptionType3::mutable_complexoptiontype5() { - set_has_complexoptiontype5(); - if (complexoptiontype5_ == NULL) complexoptiontype5_ = new ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5; - return complexoptiontype5_; -} -inline ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* ComplexOptionType3::release_complexoptiontype5() { - clear_has_complexoptiontype5(); - ::protobuf_unittest::ComplexOptionType3_ComplexOptionType5* temp = complexoptiontype5_; - complexoptiontype5_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// ComplexOpt6 - -// optional int32 xyzzy = 7593951; -inline bool ComplexOpt6::has_xyzzy() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ComplexOpt6::set_has_xyzzy() { - _has_bits_[0] |= 0x00000001u; -} -inline void ComplexOpt6::clear_has_xyzzy() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ComplexOpt6::clear_xyzzy() { - xyzzy_ = 0; - clear_has_xyzzy(); -} -inline ::google::protobuf::int32 ComplexOpt6::xyzzy() const { - return xyzzy_; -} -inline void ComplexOpt6::set_xyzzy(::google::protobuf::int32 value) { - set_has_xyzzy(); - xyzzy_ = value; -} - -// ------------------------------------------------------------------- - -// VariousComplexOptions - -// ------------------------------------------------------------------- - -// AggregateMessageSet - -// ------------------------------------------------------------------- - -// AggregateMessageSetElement - -// optional string s = 1; -inline bool AggregateMessageSetElement::has_s() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void AggregateMessageSetElement::set_has_s() { - _has_bits_[0] |= 0x00000001u; -} -inline void AggregateMessageSetElement::clear_has_s() { - _has_bits_[0] &= ~0x00000001u; -} -inline void AggregateMessageSetElement::clear_s() { - if (s_ != &::google::protobuf::internal::kEmptyString) { - s_->clear(); - } - clear_has_s(); -} -inline const ::std::string& AggregateMessageSetElement::s() const { - return *s_; -} -inline void AggregateMessageSetElement::set_s(const ::std::string& value) { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - s_->assign(value); -} -inline void AggregateMessageSetElement::set_s(const char* value) { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - s_->assign(value); -} -inline void AggregateMessageSetElement::set_s(const char* value, size_t size) { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - s_->assign(reinterpret_cast(value), size); -} -inline ::std::string* AggregateMessageSetElement::mutable_s() { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - return s_; -} -inline ::std::string* AggregateMessageSetElement::release_s() { - clear_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = s_; - s_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// Aggregate - -// optional int32 i = 1; -inline bool Aggregate::has_i() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void Aggregate::set_has_i() { - _has_bits_[0] |= 0x00000001u; -} -inline void Aggregate::clear_has_i() { - _has_bits_[0] &= ~0x00000001u; -} -inline void Aggregate::clear_i() { - i_ = 0; - clear_has_i(); -} -inline ::google::protobuf::int32 Aggregate::i() const { - return i_; -} -inline void Aggregate::set_i(::google::protobuf::int32 value) { - set_has_i(); - i_ = value; -} - -// optional string s = 2; -inline bool Aggregate::has_s() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void Aggregate::set_has_s() { - _has_bits_[0] |= 0x00000002u; -} -inline void Aggregate::clear_has_s() { - _has_bits_[0] &= ~0x00000002u; -} -inline void Aggregate::clear_s() { - if (s_ != &::google::protobuf::internal::kEmptyString) { - s_->clear(); - } - clear_has_s(); -} -inline const ::std::string& Aggregate::s() const { - return *s_; -} -inline void Aggregate::set_s(const ::std::string& value) { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - s_->assign(value); -} -inline void Aggregate::set_s(const char* value) { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - s_->assign(value); -} -inline void Aggregate::set_s(const char* value, size_t size) { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - s_->assign(reinterpret_cast(value), size); -} -inline ::std::string* Aggregate::mutable_s() { - set_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - s_ = new ::std::string; - } - return s_; -} -inline ::std::string* Aggregate::release_s() { - clear_has_s(); - if (s_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = s_; - s_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional .protobuf_unittest.Aggregate sub = 3; -inline bool Aggregate::has_sub() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void Aggregate::set_has_sub() { - _has_bits_[0] |= 0x00000004u; -} -inline void Aggregate::clear_has_sub() { - _has_bits_[0] &= ~0x00000004u; -} -inline void Aggregate::clear_sub() { - if (sub_ != NULL) sub_->::protobuf_unittest::Aggregate::Clear(); - clear_has_sub(); -} -inline const ::protobuf_unittest::Aggregate& Aggregate::sub() const { - return sub_ != NULL ? *sub_ : *default_instance_->sub_; -} -inline ::protobuf_unittest::Aggregate* Aggregate::mutable_sub() { - set_has_sub(); - if (sub_ == NULL) sub_ = new ::protobuf_unittest::Aggregate; - return sub_; -} -inline ::protobuf_unittest::Aggregate* Aggregate::release_sub() { - clear_has_sub(); - ::protobuf_unittest::Aggregate* temp = sub_; - sub_ = NULL; - return temp; -} - -// optional .google.protobuf.FileOptions file = 4; -inline bool Aggregate::has_file() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void Aggregate::set_has_file() { - _has_bits_[0] |= 0x00000008u; -} -inline void Aggregate::clear_has_file() { - _has_bits_[0] &= ~0x00000008u; -} -inline void Aggregate::clear_file() { - if (file_ != NULL) file_->::google::protobuf::FileOptions::Clear(); - clear_has_file(); -} -inline const ::google::protobuf::FileOptions& Aggregate::file() const { - return file_ != NULL ? *file_ : *default_instance_->file_; -} -inline ::google::protobuf::FileOptions* Aggregate::mutable_file() { - set_has_file(); - if (file_ == NULL) file_ = new ::google::protobuf::FileOptions; - return file_; -} -inline ::google::protobuf::FileOptions* Aggregate::release_file() { - clear_has_file(); - ::google::protobuf::FileOptions* temp = file_; - file_ = NULL; - return temp; -} - -// optional .protobuf_unittest.AggregateMessageSet mset = 5; -inline bool Aggregate::has_mset() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void Aggregate::set_has_mset() { - _has_bits_[0] |= 0x00000010u; -} -inline void Aggregate::clear_has_mset() { - _has_bits_[0] &= ~0x00000010u; -} -inline void Aggregate::clear_mset() { - if (mset_ != NULL) mset_->::protobuf_unittest::AggregateMessageSet::Clear(); - clear_has_mset(); -} -inline const ::protobuf_unittest::AggregateMessageSet& Aggregate::mset() const { - return mset_ != NULL ? *mset_ : *default_instance_->mset_; -} -inline ::protobuf_unittest::AggregateMessageSet* Aggregate::mutable_mset() { - set_has_mset(); - if (mset_ == NULL) mset_ = new ::protobuf_unittest::AggregateMessageSet; - return mset_; -} -inline ::protobuf_unittest::AggregateMessageSet* Aggregate::release_mset() { - clear_has_mset(); - ::protobuf_unittest::AggregateMessageSet* temp = mset_; - mset_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// AggregateMessage - -// optional int32 fieldname = 1; -inline bool AggregateMessage::has_fieldname() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void AggregateMessage::set_has_fieldname() { - _has_bits_[0] |= 0x00000001u; -} -inline void AggregateMessage::clear_has_fieldname() { - _has_bits_[0] &= ~0x00000001u; -} -inline void AggregateMessage::clear_fieldname() { - fieldname_ = 0; - clear_has_fieldname(); -} -inline ::google::protobuf::int32 AggregateMessage::fieldname() const { - return fieldname_; -} -inline void AggregateMessage::set_fieldname(::google::protobuf::int32 value) { - set_has_fieldname(); - fieldname_ = value; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::TestMessageWithCustomOptions_AnEnum>() { - return ::protobuf_unittest::TestMessageWithCustomOptions_AnEnum_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType>() { - return ::protobuf_unittest::DummyMessageContainingEnum_TestEnumType_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::MethodOpt1>() { - return protobuf_unittest::MethodOpt1_descriptor(); -} -template <> -inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest::AggregateEnum>() { - return protobuf_unittest::AggregateEnum_descriptor(); -} - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5fcustom_5foptions_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h deleted file mode 100644 index 3bf3b704..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +++ /dev/null @@ -1,211 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_embed_optimize_for.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include "google/protobuf/unittest_optimize_for.pb.h" -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); - -class TestEmbedOptimizedForSize; - -// =================================================================== - -class TestEmbedOptimizedForSize : public ::google::protobuf::Message { - public: - TestEmbedOptimizedForSize(); - virtual ~TestEmbedOptimizedForSize(); - - TestEmbedOptimizedForSize(const TestEmbedOptimizedForSize& from); - - inline TestEmbedOptimizedForSize& operator=(const TestEmbedOptimizedForSize& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestEmbedOptimizedForSize& default_instance(); - - void Swap(TestEmbedOptimizedForSize* other); - - // implements Message ---------------------------------------------- - - TestEmbedOptimizedForSize* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestEmbedOptimizedForSize& from); - void MergeFrom(const TestEmbedOptimizedForSize& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestOptimizedForSize optional_message = 1; - inline bool has_optional_message() const; - inline void clear_optional_message(); - static const int kOptionalMessageFieldNumber = 1; - inline const ::protobuf_unittest::TestOptimizedForSize& optional_message() const; - inline ::protobuf_unittest::TestOptimizedForSize* mutable_optional_message(); - inline ::protobuf_unittest::TestOptimizedForSize* release_optional_message(); - - // repeated .protobuf_unittest.TestOptimizedForSize repeated_message = 2; - inline int repeated_message_size() const; - inline void clear_repeated_message(); - static const int kRepeatedMessageFieldNumber = 2; - inline const ::protobuf_unittest::TestOptimizedForSize& repeated_message(int index) const; - inline ::protobuf_unittest::TestOptimizedForSize* mutable_repeated_message(int index); - inline ::protobuf_unittest::TestOptimizedForSize* add_repeated_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >& - repeated_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >* - mutable_repeated_message(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestEmbedOptimizedForSize) - private: - inline void set_has_optional_message(); - inline void clear_has_optional_message(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestOptimizedForSize* optional_message_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize > repeated_message_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto(); - - void InitAsDefaultInstance(); - static TestEmbedOptimizedForSize* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// TestEmbedOptimizedForSize - -// optional .protobuf_unittest.TestOptimizedForSize optional_message = 1; -inline bool TestEmbedOptimizedForSize::has_optional_message() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestEmbedOptimizedForSize::set_has_optional_message() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestEmbedOptimizedForSize::clear_has_optional_message() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestEmbedOptimizedForSize::clear_optional_message() { - if (optional_message_ != NULL) optional_message_->::protobuf_unittest::TestOptimizedForSize::Clear(); - clear_has_optional_message(); -} -inline const ::protobuf_unittest::TestOptimizedForSize& TestEmbedOptimizedForSize::optional_message() const { - return optional_message_ != NULL ? *optional_message_ : *default_instance_->optional_message_; -} -inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::mutable_optional_message() { - set_has_optional_message(); - if (optional_message_ == NULL) optional_message_ = new ::protobuf_unittest::TestOptimizedForSize; - return optional_message_; -} -inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::release_optional_message() { - clear_has_optional_message(); - ::protobuf_unittest::TestOptimizedForSize* temp = optional_message_; - optional_message_ = NULL; - return temp; -} - -// repeated .protobuf_unittest.TestOptimizedForSize repeated_message = 2; -inline int TestEmbedOptimizedForSize::repeated_message_size() const { - return repeated_message_.size(); -} -inline void TestEmbedOptimizedForSize::clear_repeated_message() { - repeated_message_.Clear(); -} -inline const ::protobuf_unittest::TestOptimizedForSize& TestEmbedOptimizedForSize::repeated_message(int index) const { - return repeated_message_.Get(index); -} -inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::mutable_repeated_message(int index) { - return repeated_message_.Mutable(index); -} -inline ::protobuf_unittest::TestOptimizedForSize* TestEmbedOptimizedForSize::add_repeated_message() { - return repeated_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >& -TestEmbedOptimizedForSize::repeated_message() const { - return repeated_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestOptimizedForSize >* -TestEmbedOptimizedForSize::mutable_repeated_message() { - return &repeated_message_; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -#ifndef SWIG -namespace google { -namespace protobuf { - - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5fembed_5foptimize_5ffor_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h deleted file mode 100644 index f9a53872..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +++ /dev/null @@ -1,56 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_empty.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fempty_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5fempty_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5fempty_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fempty_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fempty_2eproto(); - - -// =================================================================== - - -// =================================================================== - - -// =================================================================== - - -// @@protoc_insertion_point(namespace_scope) - -#ifndef SWIG -namespace google { -namespace protobuf { - - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5fempty_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h deleted file mode 100644 index 401905d8..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +++ /dev/null @@ -1,188 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_import.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fimport_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5fimport_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest_import { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_2eproto(); - -class ImportMessage; - -enum ImportEnum { - IMPORT_FOO = 7, - IMPORT_BAR = 8, - IMPORT_BAZ = 9 -}; -bool ImportEnum_IsValid(int value); -const ImportEnum ImportEnum_MIN = IMPORT_FOO; -const ImportEnum ImportEnum_MAX = IMPORT_BAZ; -const int ImportEnum_ARRAYSIZE = ImportEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* ImportEnum_descriptor(); -inline const ::std::string& ImportEnum_Name(ImportEnum value) { - return ::google::protobuf::internal::NameOfEnum( - ImportEnum_descriptor(), value); -} -inline bool ImportEnum_Parse( - const ::std::string& name, ImportEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - ImportEnum_descriptor(), name, value); -} -// =================================================================== - -class ImportMessage : public ::google::protobuf::Message { - public: - ImportMessage(); - virtual ~ImportMessage(); - - ImportMessage(const ImportMessage& from); - - inline ImportMessage& operator=(const ImportMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ImportMessage& default_instance(); - - void Swap(ImportMessage* other); - - // implements Message ---------------------------------------------- - - ImportMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ImportMessage& from); - void MergeFrom(const ImportMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 d = 1; - inline bool has_d() const; - inline void clear_d(); - static const int kDFieldNumber = 1; - inline ::google::protobuf::int32 d() const; - inline void set_d(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest_import.ImportMessage) - private: - inline void set_has_d(); - inline void clear_has_d(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 d_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_2eproto(); - - void InitAsDefaultInstance(); - static ImportMessage* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// ImportMessage - -// optional int32 d = 1; -inline bool ImportMessage::has_d() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ImportMessage::set_has_d() { - _has_bits_[0] |= 0x00000001u; -} -inline void ImportMessage::clear_has_d() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ImportMessage::clear_d() { - d_ = 0; - clear_has_d(); -} -inline ::google::protobuf::int32 ImportMessage::d() const { - return d_; -} -inline void ImportMessage::set_d(::google::protobuf::int32 value) { - set_has_d(); - d_ = value; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest_import - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> -inline const EnumDescriptor* GetEnumDescriptor< protobuf_unittest_import::ImportEnum>() { - return protobuf_unittest_import::ImportEnum_descriptor(); -} - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5fimport_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h deleted file mode 100644 index a29b673b..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +++ /dev/null @@ -1,151 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_import_lite.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fimport_5flite_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5fimport_5flite_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest_import { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); - -class ImportMessageLite; - -enum ImportEnumLite { - IMPORT_LITE_FOO = 7, - IMPORT_LITE_BAR = 8, - IMPORT_LITE_BAZ = 9 -}; -bool ImportEnumLite_IsValid(int value); -const ImportEnumLite ImportEnumLite_MIN = IMPORT_LITE_FOO; -const ImportEnumLite ImportEnumLite_MAX = IMPORT_LITE_BAZ; -const int ImportEnumLite_ARRAYSIZE = ImportEnumLite_MAX + 1; - -// =================================================================== - -class ImportMessageLite : public ::google::protobuf::MessageLite { - public: - ImportMessageLite(); - virtual ~ImportMessageLite(); - - ImportMessageLite(const ImportMessageLite& from); - - inline ImportMessageLite& operator=(const ImportMessageLite& from) { - CopyFrom(from); - return *this; - } - - static const ImportMessageLite& default_instance(); - - void Swap(ImportMessageLite* other); - - // implements Message ---------------------------------------------- - - ImportMessageLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const ImportMessageLite& from); - void MergeFrom(const ImportMessageLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 d = 1; - inline bool has_d() const; - inline void clear_d(); - static const int kDFieldNumber = 1; - inline ::google::protobuf::int32 d() const; - inline void set_d(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest_import.ImportMessageLite) - private: - inline void set_has_d(); - inline void clear_has_d(); - - ::google::protobuf::int32 d_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fimport_5flite_2eproto(); - - void InitAsDefaultInstance(); - static ImportMessageLite* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// ImportMessageLite - -// optional int32 d = 1; -inline bool ImportMessageLite::has_d() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ImportMessageLite::set_has_d() { - _has_bits_[0] |= 0x00000001u; -} -inline void ImportMessageLite::clear_has_d() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ImportMessageLite::clear_d() { - d_ = 0; - clear_has_d(); -} -inline ::google::protobuf::int32 ImportMessageLite::d() const { - return d_; -} -inline void ImportMessageLite::set_d(::google::protobuf::int32 value) { - set_has_d(); - d_ = value; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest_import - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5fimport_5flite_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h deleted file mode 100644 index 66c9fb41..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +++ /dev/null @@ -1,4752 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_lite.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5flite_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5flite_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include "google/protobuf/unittest_import_lite.pb.h" -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - -class TestAllTypesLite; -class TestAllTypesLite_NestedMessage; -class TestAllTypesLite_OptionalGroup; -class TestAllTypesLite_RepeatedGroup; -class ForeignMessageLite; -class TestPackedTypesLite; -class TestAllExtensionsLite; -class OptionalGroup_extension_lite; -class RepeatedGroup_extension_lite; -class TestPackedExtensionsLite; -class TestNestedExtensionLite; -class TestDeprecatedLite; - -enum TestAllTypesLite_NestedEnum { - TestAllTypesLite_NestedEnum_FOO = 1, - TestAllTypesLite_NestedEnum_BAR = 2, - TestAllTypesLite_NestedEnum_BAZ = 3 -}; -bool TestAllTypesLite_NestedEnum_IsValid(int value); -const TestAllTypesLite_NestedEnum TestAllTypesLite_NestedEnum_NestedEnum_MIN = TestAllTypesLite_NestedEnum_FOO; -const TestAllTypesLite_NestedEnum TestAllTypesLite_NestedEnum_NestedEnum_MAX = TestAllTypesLite_NestedEnum_BAZ; -const int TestAllTypesLite_NestedEnum_NestedEnum_ARRAYSIZE = TestAllTypesLite_NestedEnum_NestedEnum_MAX + 1; - -enum ForeignEnumLite { - FOREIGN_LITE_FOO = 4, - FOREIGN_LITE_BAR = 5, - FOREIGN_LITE_BAZ = 6 -}; -bool ForeignEnumLite_IsValid(int value); -const ForeignEnumLite ForeignEnumLite_MIN = FOREIGN_LITE_FOO; -const ForeignEnumLite ForeignEnumLite_MAX = FOREIGN_LITE_BAZ; -const int ForeignEnumLite_ARRAYSIZE = ForeignEnumLite_MAX + 1; - -// =================================================================== - -class TestAllTypesLite_NestedMessage : public ::google::protobuf::MessageLite { - public: - TestAllTypesLite_NestedMessage(); - virtual ~TestAllTypesLite_NestedMessage(); - - TestAllTypesLite_NestedMessage(const TestAllTypesLite_NestedMessage& from); - - inline TestAllTypesLite_NestedMessage& operator=(const TestAllTypesLite_NestedMessage& from) { - CopyFrom(from); - return *this; - } - - static const TestAllTypesLite_NestedMessage& default_instance(); - - void Swap(TestAllTypesLite_NestedMessage* other); - - // implements Message ---------------------------------------------- - - TestAllTypesLite_NestedMessage* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestAllTypesLite_NestedMessage& from); - void MergeFrom(const TestAllTypesLite_NestedMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 bb = 1; - inline bool has_bb() const; - inline void clear_bb(); - static const int kBbFieldNumber = 1; - inline ::google::protobuf::int32 bb() const; - inline void set_bb(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite.NestedMessage) - private: - inline void set_has_bb(); - inline void clear_has_bb(); - - ::google::protobuf::int32 bb_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypesLite_NestedMessage* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllTypesLite_OptionalGroup : public ::google::protobuf::MessageLite { - public: - TestAllTypesLite_OptionalGroup(); - virtual ~TestAllTypesLite_OptionalGroup(); - - TestAllTypesLite_OptionalGroup(const TestAllTypesLite_OptionalGroup& from); - - inline TestAllTypesLite_OptionalGroup& operator=(const TestAllTypesLite_OptionalGroup& from) { - CopyFrom(from); - return *this; - } - - static const TestAllTypesLite_OptionalGroup& default_instance(); - - void Swap(TestAllTypesLite_OptionalGroup* other); - - // implements Message ---------------------------------------------- - - TestAllTypesLite_OptionalGroup* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestAllTypesLite_OptionalGroup& from); - void MergeFrom(const TestAllTypesLite_OptionalGroup& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 17; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 17; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite.OptionalGroup) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypesLite_OptionalGroup* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllTypesLite_RepeatedGroup : public ::google::protobuf::MessageLite { - public: - TestAllTypesLite_RepeatedGroup(); - virtual ~TestAllTypesLite_RepeatedGroup(); - - TestAllTypesLite_RepeatedGroup(const TestAllTypesLite_RepeatedGroup& from); - - inline TestAllTypesLite_RepeatedGroup& operator=(const TestAllTypesLite_RepeatedGroup& from) { - CopyFrom(from); - return *this; - } - - static const TestAllTypesLite_RepeatedGroup& default_instance(); - - void Swap(TestAllTypesLite_RepeatedGroup* other); - - // implements Message ---------------------------------------------- - - TestAllTypesLite_RepeatedGroup* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestAllTypesLite_RepeatedGroup& from); - void MergeFrom(const TestAllTypesLite_RepeatedGroup& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 47; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 47; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite.RepeatedGroup) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypesLite_RepeatedGroup* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllTypesLite : public ::google::protobuf::MessageLite { - public: - TestAllTypesLite(); - virtual ~TestAllTypesLite(); - - TestAllTypesLite(const TestAllTypesLite& from); - - inline TestAllTypesLite& operator=(const TestAllTypesLite& from) { - CopyFrom(from); - return *this; - } - - static const TestAllTypesLite& default_instance(); - - void Swap(TestAllTypesLite* other); - - // implements Message ---------------------------------------------- - - TestAllTypesLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestAllTypesLite& from); - void MergeFrom(const TestAllTypesLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - typedef TestAllTypesLite_NestedMessage NestedMessage; - typedef TestAllTypesLite_OptionalGroup OptionalGroup; - typedef TestAllTypesLite_RepeatedGroup RepeatedGroup; - - typedef TestAllTypesLite_NestedEnum NestedEnum; - static const NestedEnum FOO = TestAllTypesLite_NestedEnum_FOO; - static const NestedEnum BAR = TestAllTypesLite_NestedEnum_BAR; - static const NestedEnum BAZ = TestAllTypesLite_NestedEnum_BAZ; - static inline bool NestedEnum_IsValid(int value) { - return TestAllTypesLite_NestedEnum_IsValid(value); - } - static const NestedEnum NestedEnum_MIN = - TestAllTypesLite_NestedEnum_NestedEnum_MIN; - static const NestedEnum NestedEnum_MAX = - TestAllTypesLite_NestedEnum_NestedEnum_MAX; - static const int NestedEnum_ARRAYSIZE = - TestAllTypesLite_NestedEnum_NestedEnum_ARRAYSIZE; - - // accessors ------------------------------------------------------- - - // optional int32 optional_int32 = 1; - inline bool has_optional_int32() const; - inline void clear_optional_int32(); - static const int kOptionalInt32FieldNumber = 1; - inline ::google::protobuf::int32 optional_int32() const; - inline void set_optional_int32(::google::protobuf::int32 value); - - // optional int64 optional_int64 = 2; - inline bool has_optional_int64() const; - inline void clear_optional_int64(); - static const int kOptionalInt64FieldNumber = 2; - inline ::google::protobuf::int64 optional_int64() const; - inline void set_optional_int64(::google::protobuf::int64 value); - - // optional uint32 optional_uint32 = 3; - inline bool has_optional_uint32() const; - inline void clear_optional_uint32(); - static const int kOptionalUint32FieldNumber = 3; - inline ::google::protobuf::uint32 optional_uint32() const; - inline void set_optional_uint32(::google::protobuf::uint32 value); - - // optional uint64 optional_uint64 = 4; - inline bool has_optional_uint64() const; - inline void clear_optional_uint64(); - static const int kOptionalUint64FieldNumber = 4; - inline ::google::protobuf::uint64 optional_uint64() const; - inline void set_optional_uint64(::google::protobuf::uint64 value); - - // optional sint32 optional_sint32 = 5; - inline bool has_optional_sint32() const; - inline void clear_optional_sint32(); - static const int kOptionalSint32FieldNumber = 5; - inline ::google::protobuf::int32 optional_sint32() const; - inline void set_optional_sint32(::google::protobuf::int32 value); - - // optional sint64 optional_sint64 = 6; - inline bool has_optional_sint64() const; - inline void clear_optional_sint64(); - static const int kOptionalSint64FieldNumber = 6; - inline ::google::protobuf::int64 optional_sint64() const; - inline void set_optional_sint64(::google::protobuf::int64 value); - - // optional fixed32 optional_fixed32 = 7; - inline bool has_optional_fixed32() const; - inline void clear_optional_fixed32(); - static const int kOptionalFixed32FieldNumber = 7; - inline ::google::protobuf::uint32 optional_fixed32() const; - inline void set_optional_fixed32(::google::protobuf::uint32 value); - - // optional fixed64 optional_fixed64 = 8; - inline bool has_optional_fixed64() const; - inline void clear_optional_fixed64(); - static const int kOptionalFixed64FieldNumber = 8; - inline ::google::protobuf::uint64 optional_fixed64() const; - inline void set_optional_fixed64(::google::protobuf::uint64 value); - - // optional sfixed32 optional_sfixed32 = 9; - inline bool has_optional_sfixed32() const; - inline void clear_optional_sfixed32(); - static const int kOptionalSfixed32FieldNumber = 9; - inline ::google::protobuf::int32 optional_sfixed32() const; - inline void set_optional_sfixed32(::google::protobuf::int32 value); - - // optional sfixed64 optional_sfixed64 = 10; - inline bool has_optional_sfixed64() const; - inline void clear_optional_sfixed64(); - static const int kOptionalSfixed64FieldNumber = 10; - inline ::google::protobuf::int64 optional_sfixed64() const; - inline void set_optional_sfixed64(::google::protobuf::int64 value); - - // optional float optional_float = 11; - inline bool has_optional_float() const; - inline void clear_optional_float(); - static const int kOptionalFloatFieldNumber = 11; - inline float optional_float() const; - inline void set_optional_float(float value); - - // optional double optional_double = 12; - inline bool has_optional_double() const; - inline void clear_optional_double(); - static const int kOptionalDoubleFieldNumber = 12; - inline double optional_double() const; - inline void set_optional_double(double value); - - // optional bool optional_bool = 13; - inline bool has_optional_bool() const; - inline void clear_optional_bool(); - static const int kOptionalBoolFieldNumber = 13; - inline bool optional_bool() const; - inline void set_optional_bool(bool value); - - // optional string optional_string = 14; - inline bool has_optional_string() const; - inline void clear_optional_string(); - static const int kOptionalStringFieldNumber = 14; - inline const ::std::string& optional_string() const; - inline void set_optional_string(const ::std::string& value); - inline void set_optional_string(const char* value); - inline void set_optional_string(const char* value, size_t size); - inline ::std::string* mutable_optional_string(); - inline ::std::string* release_optional_string(); - - // optional bytes optional_bytes = 15; - inline bool has_optional_bytes() const; - inline void clear_optional_bytes(); - static const int kOptionalBytesFieldNumber = 15; - inline const ::std::string& optional_bytes() const; - inline void set_optional_bytes(const ::std::string& value); - inline void set_optional_bytes(const char* value); - inline void set_optional_bytes(const void* value, size_t size); - inline ::std::string* mutable_optional_bytes(); - inline ::std::string* release_optional_bytes(); - - // optional group OptionalGroup = 16 { - inline bool has_optionalgroup() const; - inline void clear_optionalgroup(); - static const int kOptionalgroupFieldNumber = 16; - inline const ::protobuf_unittest::TestAllTypesLite_OptionalGroup& optionalgroup() const; - inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* mutable_optionalgroup(); - inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* release_optionalgroup(); - - // optional .protobuf_unittest.TestAllTypesLite.NestedMessage optional_nested_message = 18; - inline bool has_optional_nested_message() const; - inline void clear_optional_nested_message(); - static const int kOptionalNestedMessageFieldNumber = 18; - inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& optional_nested_message() const; - inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* mutable_optional_nested_message(); - inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* release_optional_nested_message(); - - // optional .protobuf_unittest.ForeignMessageLite optional_foreign_message = 19; - inline bool has_optional_foreign_message() const; - inline void clear_optional_foreign_message(); - static const int kOptionalForeignMessageFieldNumber = 19; - inline const ::protobuf_unittest::ForeignMessageLite& optional_foreign_message() const; - inline ::protobuf_unittest::ForeignMessageLite* mutable_optional_foreign_message(); - inline ::protobuf_unittest::ForeignMessageLite* release_optional_foreign_message(); - - // optional .protobuf_unittest_import.ImportMessageLite optional_import_message = 20; - inline bool has_optional_import_message() const; - inline void clear_optional_import_message(); - static const int kOptionalImportMessageFieldNumber = 20; - inline const ::protobuf_unittest_import::ImportMessageLite& optional_import_message() const; - inline ::protobuf_unittest_import::ImportMessageLite* mutable_optional_import_message(); - inline ::protobuf_unittest_import::ImportMessageLite* release_optional_import_message(); - - // optional .protobuf_unittest.TestAllTypesLite.NestedEnum optional_nested_enum = 21; - inline bool has_optional_nested_enum() const; - inline void clear_optional_nested_enum(); - static const int kOptionalNestedEnumFieldNumber = 21; - inline ::protobuf_unittest::TestAllTypesLite_NestedEnum optional_nested_enum() const; - inline void set_optional_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value); - - // optional .protobuf_unittest.ForeignEnumLite optional_foreign_enum = 22; - inline bool has_optional_foreign_enum() const; - inline void clear_optional_foreign_enum(); - static const int kOptionalForeignEnumFieldNumber = 22; - inline protobuf_unittest::ForeignEnumLite optional_foreign_enum() const; - inline void set_optional_foreign_enum(protobuf_unittest::ForeignEnumLite value); - - // optional .protobuf_unittest_import.ImportEnumLite optional_import_enum = 23; - inline bool has_optional_import_enum() const; - inline void clear_optional_import_enum(); - static const int kOptionalImportEnumFieldNumber = 23; - inline protobuf_unittest_import::ImportEnumLite optional_import_enum() const; - inline void set_optional_import_enum(protobuf_unittest_import::ImportEnumLite value); - - // optional string optional_string_piece = 24 [ctype = STRING_PIECE]; - inline bool has_optional_string_piece() const; - inline void clear_optional_string_piece(); - static const int kOptionalStringPieceFieldNumber = 24; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& optional_string_piece() const; - inline void set_optional_string_piece(const ::std::string& value); - inline void set_optional_string_piece(const char* value); - inline void set_optional_string_piece(const char* value, size_t size); - inline ::std::string* mutable_optional_string_piece(); - inline ::std::string* release_optional_string_piece(); - public: - - // optional string optional_cord = 25 [ctype = CORD]; - inline bool has_optional_cord() const; - inline void clear_optional_cord(); - static const int kOptionalCordFieldNumber = 25; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& optional_cord() const; - inline void set_optional_cord(const ::std::string& value); - inline void set_optional_cord(const char* value); - inline void set_optional_cord(const char* value, size_t size); - inline ::std::string* mutable_optional_cord(); - inline ::std::string* release_optional_cord(); - public: - - // repeated int32 repeated_int32 = 31; - inline int repeated_int32_size() const; - inline void clear_repeated_int32(); - static const int kRepeatedInt32FieldNumber = 31; - inline ::google::protobuf::int32 repeated_int32(int index) const; - inline void set_repeated_int32(int index, ::google::protobuf::int32 value); - inline void add_repeated_int32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeated_int32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeated_int32(); - - // repeated int64 repeated_int64 = 32; - inline int repeated_int64_size() const; - inline void clear_repeated_int64(); - static const int kRepeatedInt64FieldNumber = 32; - inline ::google::protobuf::int64 repeated_int64(int index) const; - inline void set_repeated_int64(int index, ::google::protobuf::int64 value); - inline void add_repeated_int64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - repeated_int64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_repeated_int64(); - - // repeated uint32 repeated_uint32 = 33; - inline int repeated_uint32_size() const; - inline void clear_repeated_uint32(); - static const int kRepeatedUint32FieldNumber = 33; - inline ::google::protobuf::uint32 repeated_uint32(int index) const; - inline void set_repeated_uint32(int index, ::google::protobuf::uint32 value); - inline void add_repeated_uint32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - repeated_uint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_repeated_uint32(); - - // repeated uint64 repeated_uint64 = 34; - inline int repeated_uint64_size() const; - inline void clear_repeated_uint64(); - static const int kRepeatedUint64FieldNumber = 34; - inline ::google::protobuf::uint64 repeated_uint64(int index) const; - inline void set_repeated_uint64(int index, ::google::protobuf::uint64 value); - inline void add_repeated_uint64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - repeated_uint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_repeated_uint64(); - - // repeated sint32 repeated_sint32 = 35; - inline int repeated_sint32_size() const; - inline void clear_repeated_sint32(); - static const int kRepeatedSint32FieldNumber = 35; - inline ::google::protobuf::int32 repeated_sint32(int index) const; - inline void set_repeated_sint32(int index, ::google::protobuf::int32 value); - inline void add_repeated_sint32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeated_sint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeated_sint32(); - - // repeated sint64 repeated_sint64 = 36; - inline int repeated_sint64_size() const; - inline void clear_repeated_sint64(); - static const int kRepeatedSint64FieldNumber = 36; - inline ::google::protobuf::int64 repeated_sint64(int index) const; - inline void set_repeated_sint64(int index, ::google::protobuf::int64 value); - inline void add_repeated_sint64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - repeated_sint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_repeated_sint64(); - - // repeated fixed32 repeated_fixed32 = 37; - inline int repeated_fixed32_size() const; - inline void clear_repeated_fixed32(); - static const int kRepeatedFixed32FieldNumber = 37; - inline ::google::protobuf::uint32 repeated_fixed32(int index) const; - inline void set_repeated_fixed32(int index, ::google::protobuf::uint32 value); - inline void add_repeated_fixed32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - repeated_fixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_repeated_fixed32(); - - // repeated fixed64 repeated_fixed64 = 38; - inline int repeated_fixed64_size() const; - inline void clear_repeated_fixed64(); - static const int kRepeatedFixed64FieldNumber = 38; - inline ::google::protobuf::uint64 repeated_fixed64(int index) const; - inline void set_repeated_fixed64(int index, ::google::protobuf::uint64 value); - inline void add_repeated_fixed64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - repeated_fixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_repeated_fixed64(); - - // repeated sfixed32 repeated_sfixed32 = 39; - inline int repeated_sfixed32_size() const; - inline void clear_repeated_sfixed32(); - static const int kRepeatedSfixed32FieldNumber = 39; - inline ::google::protobuf::int32 repeated_sfixed32(int index) const; - inline void set_repeated_sfixed32(int index, ::google::protobuf::int32 value); - inline void add_repeated_sfixed32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - repeated_sfixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_repeated_sfixed32(); - - // repeated sfixed64 repeated_sfixed64 = 40; - inline int repeated_sfixed64_size() const; - inline void clear_repeated_sfixed64(); - static const int kRepeatedSfixed64FieldNumber = 40; - inline ::google::protobuf::int64 repeated_sfixed64(int index) const; - inline void set_repeated_sfixed64(int index, ::google::protobuf::int64 value); - inline void add_repeated_sfixed64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - repeated_sfixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_repeated_sfixed64(); - - // repeated float repeated_float = 41; - inline int repeated_float_size() const; - inline void clear_repeated_float(); - static const int kRepeatedFloatFieldNumber = 41; - inline float repeated_float(int index) const; - inline void set_repeated_float(int index, float value); - inline void add_repeated_float(float value); - inline const ::google::protobuf::RepeatedField< float >& - repeated_float() const; - inline ::google::protobuf::RepeatedField< float >* - mutable_repeated_float(); - - // repeated double repeated_double = 42; - inline int repeated_double_size() const; - inline void clear_repeated_double(); - static const int kRepeatedDoubleFieldNumber = 42; - inline double repeated_double(int index) const; - inline void set_repeated_double(int index, double value); - inline void add_repeated_double(double value); - inline const ::google::protobuf::RepeatedField< double >& - repeated_double() const; - inline ::google::protobuf::RepeatedField< double >* - mutable_repeated_double(); - - // repeated bool repeated_bool = 43; - inline int repeated_bool_size() const; - inline void clear_repeated_bool(); - static const int kRepeatedBoolFieldNumber = 43; - inline bool repeated_bool(int index) const; - inline void set_repeated_bool(int index, bool value); - inline void add_repeated_bool(bool value); - inline const ::google::protobuf::RepeatedField< bool >& - repeated_bool() const; - inline ::google::protobuf::RepeatedField< bool >* - mutable_repeated_bool(); - - // repeated string repeated_string = 44; - inline int repeated_string_size() const; - inline void clear_repeated_string(); - static const int kRepeatedStringFieldNumber = 44; - inline const ::std::string& repeated_string(int index) const; - inline ::std::string* mutable_repeated_string(int index); - inline void set_repeated_string(int index, const ::std::string& value); - inline void set_repeated_string(int index, const char* value); - inline void set_repeated_string(int index, const char* value, size_t size); - inline ::std::string* add_repeated_string(); - inline void add_repeated_string(const ::std::string& value); - inline void add_repeated_string(const char* value); - inline void add_repeated_string(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string(); - - // repeated bytes repeated_bytes = 45; - inline int repeated_bytes_size() const; - inline void clear_repeated_bytes(); - static const int kRepeatedBytesFieldNumber = 45; - inline const ::std::string& repeated_bytes(int index) const; - inline ::std::string* mutable_repeated_bytes(int index); - inline void set_repeated_bytes(int index, const ::std::string& value); - inline void set_repeated_bytes(int index, const char* value); - inline void set_repeated_bytes(int index, const void* value, size_t size); - inline ::std::string* add_repeated_bytes(); - inline void add_repeated_bytes(const ::std::string& value); - inline void add_repeated_bytes(const char* value); - inline void add_repeated_bytes(const void* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_bytes() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_bytes(); - - // repeated group RepeatedGroup = 46 { - inline int repeatedgroup_size() const; - inline void clear_repeatedgroup(); - static const int kRepeatedgroupFieldNumber = 46; - inline const ::protobuf_unittest::TestAllTypesLite_RepeatedGroup& repeatedgroup(int index) const; - inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* mutable_repeatedgroup(int index); - inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* add_repeatedgroup(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >& - repeatedgroup() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >* - mutable_repeatedgroup(); - - // repeated .protobuf_unittest.TestAllTypesLite.NestedMessage repeated_nested_message = 48; - inline int repeated_nested_message_size() const; - inline void clear_repeated_nested_message(); - static const int kRepeatedNestedMessageFieldNumber = 48; - inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& repeated_nested_message(int index) const; - inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* mutable_repeated_nested_message(int index); - inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* add_repeated_nested_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >& - repeated_nested_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >* - mutable_repeated_nested_message(); - - // repeated .protobuf_unittest.ForeignMessageLite repeated_foreign_message = 49; - inline int repeated_foreign_message_size() const; - inline void clear_repeated_foreign_message(); - static const int kRepeatedForeignMessageFieldNumber = 49; - inline const ::protobuf_unittest::ForeignMessageLite& repeated_foreign_message(int index) const; - inline ::protobuf_unittest::ForeignMessageLite* mutable_repeated_foreign_message(int index); - inline ::protobuf_unittest::ForeignMessageLite* add_repeated_foreign_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >& - repeated_foreign_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >* - mutable_repeated_foreign_message(); - - // repeated .protobuf_unittest_import.ImportMessageLite repeated_import_message = 50; - inline int repeated_import_message_size() const; - inline void clear_repeated_import_message(); - static const int kRepeatedImportMessageFieldNumber = 50; - inline const ::protobuf_unittest_import::ImportMessageLite& repeated_import_message(int index) const; - inline ::protobuf_unittest_import::ImportMessageLite* mutable_repeated_import_message(int index); - inline ::protobuf_unittest_import::ImportMessageLite* add_repeated_import_message(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >& - repeated_import_message() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >* - mutable_repeated_import_message(); - - // repeated .protobuf_unittest.TestAllTypesLite.NestedEnum repeated_nested_enum = 51; - inline int repeated_nested_enum_size() const; - inline void clear_repeated_nested_enum(); - static const int kRepeatedNestedEnumFieldNumber = 51; - inline ::protobuf_unittest::TestAllTypesLite_NestedEnum repeated_nested_enum(int index) const; - inline void set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypesLite_NestedEnum value); - inline void add_repeated_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value); - inline const ::google::protobuf::RepeatedField& repeated_nested_enum() const; - inline ::google::protobuf::RepeatedField* mutable_repeated_nested_enum(); - - // repeated .protobuf_unittest.ForeignEnumLite repeated_foreign_enum = 52; - inline int repeated_foreign_enum_size() const; - inline void clear_repeated_foreign_enum(); - static const int kRepeatedForeignEnumFieldNumber = 52; - inline protobuf_unittest::ForeignEnumLite repeated_foreign_enum(int index) const; - inline void set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnumLite value); - inline void add_repeated_foreign_enum(protobuf_unittest::ForeignEnumLite value); - inline const ::google::protobuf::RepeatedField& repeated_foreign_enum() const; - inline ::google::protobuf::RepeatedField* mutable_repeated_foreign_enum(); - - // repeated .protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53; - inline int repeated_import_enum_size() const; - inline void clear_repeated_import_enum(); - static const int kRepeatedImportEnumFieldNumber = 53; - inline protobuf_unittest_import::ImportEnumLite repeated_import_enum(int index) const; - inline void set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnumLite value); - inline void add_repeated_import_enum(protobuf_unittest_import::ImportEnumLite value); - inline const ::google::protobuf::RepeatedField& repeated_import_enum() const; - inline ::google::protobuf::RepeatedField* mutable_repeated_import_enum(); - - // repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; - inline int repeated_string_piece_size() const; - inline void clear_repeated_string_piece(); - static const int kRepeatedStringPieceFieldNumber = 54; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& repeated_string_piece(int index) const; - inline ::std::string* mutable_repeated_string_piece(int index); - inline void set_repeated_string_piece(int index, const ::std::string& value); - inline void set_repeated_string_piece(int index, const char* value); - inline void set_repeated_string_piece(int index, const char* value, size_t size); - inline ::std::string* add_repeated_string_piece(); - inline void add_repeated_string_piece(const ::std::string& value); - inline void add_repeated_string_piece(const char* value); - inline void add_repeated_string_piece(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_string_piece() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_string_piece(); - public: - - // repeated string repeated_cord = 55 [ctype = CORD]; - inline int repeated_cord_size() const; - inline void clear_repeated_cord(); - static const int kRepeatedCordFieldNumber = 55; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& repeated_cord(int index) const; - inline ::std::string* mutable_repeated_cord(int index); - inline void set_repeated_cord(int index, const ::std::string& value); - inline void set_repeated_cord(int index, const char* value); - inline void set_repeated_cord(int index, const char* value, size_t size); - inline ::std::string* add_repeated_cord(); - inline void add_repeated_cord(const ::std::string& value); - inline void add_repeated_cord(const char* value); - inline void add_repeated_cord(const char* value, size_t size); - inline const ::google::protobuf::RepeatedPtrField< ::std::string>& repeated_cord() const; - inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_repeated_cord(); - public: - - // optional int32 default_int32 = 61 [default = 41]; - inline bool has_default_int32() const; - inline void clear_default_int32(); - static const int kDefaultInt32FieldNumber = 61; - inline ::google::protobuf::int32 default_int32() const; - inline void set_default_int32(::google::protobuf::int32 value); - - // optional int64 default_int64 = 62 [default = 42]; - inline bool has_default_int64() const; - inline void clear_default_int64(); - static const int kDefaultInt64FieldNumber = 62; - inline ::google::protobuf::int64 default_int64() const; - inline void set_default_int64(::google::protobuf::int64 value); - - // optional uint32 default_uint32 = 63 [default = 43]; - inline bool has_default_uint32() const; - inline void clear_default_uint32(); - static const int kDefaultUint32FieldNumber = 63; - inline ::google::protobuf::uint32 default_uint32() const; - inline void set_default_uint32(::google::protobuf::uint32 value); - - // optional uint64 default_uint64 = 64 [default = 44]; - inline bool has_default_uint64() const; - inline void clear_default_uint64(); - static const int kDefaultUint64FieldNumber = 64; - inline ::google::protobuf::uint64 default_uint64() const; - inline void set_default_uint64(::google::protobuf::uint64 value); - - // optional sint32 default_sint32 = 65 [default = -45]; - inline bool has_default_sint32() const; - inline void clear_default_sint32(); - static const int kDefaultSint32FieldNumber = 65; - inline ::google::protobuf::int32 default_sint32() const; - inline void set_default_sint32(::google::protobuf::int32 value); - - // optional sint64 default_sint64 = 66 [default = 46]; - inline bool has_default_sint64() const; - inline void clear_default_sint64(); - static const int kDefaultSint64FieldNumber = 66; - inline ::google::protobuf::int64 default_sint64() const; - inline void set_default_sint64(::google::protobuf::int64 value); - - // optional fixed32 default_fixed32 = 67 [default = 47]; - inline bool has_default_fixed32() const; - inline void clear_default_fixed32(); - static const int kDefaultFixed32FieldNumber = 67; - inline ::google::protobuf::uint32 default_fixed32() const; - inline void set_default_fixed32(::google::protobuf::uint32 value); - - // optional fixed64 default_fixed64 = 68 [default = 48]; - inline bool has_default_fixed64() const; - inline void clear_default_fixed64(); - static const int kDefaultFixed64FieldNumber = 68; - inline ::google::protobuf::uint64 default_fixed64() const; - inline void set_default_fixed64(::google::protobuf::uint64 value); - - // optional sfixed32 default_sfixed32 = 69 [default = 49]; - inline bool has_default_sfixed32() const; - inline void clear_default_sfixed32(); - static const int kDefaultSfixed32FieldNumber = 69; - inline ::google::protobuf::int32 default_sfixed32() const; - inline void set_default_sfixed32(::google::protobuf::int32 value); - - // optional sfixed64 default_sfixed64 = 70 [default = -50]; - inline bool has_default_sfixed64() const; - inline void clear_default_sfixed64(); - static const int kDefaultSfixed64FieldNumber = 70; - inline ::google::protobuf::int64 default_sfixed64() const; - inline void set_default_sfixed64(::google::protobuf::int64 value); - - // optional float default_float = 71 [default = 51.5]; - inline bool has_default_float() const; - inline void clear_default_float(); - static const int kDefaultFloatFieldNumber = 71; - inline float default_float() const; - inline void set_default_float(float value); - - // optional double default_double = 72 [default = 52000]; - inline bool has_default_double() const; - inline void clear_default_double(); - static const int kDefaultDoubleFieldNumber = 72; - inline double default_double() const; - inline void set_default_double(double value); - - // optional bool default_bool = 73 [default = true]; - inline bool has_default_bool() const; - inline void clear_default_bool(); - static const int kDefaultBoolFieldNumber = 73; - inline bool default_bool() const; - inline void set_default_bool(bool value); - - // optional string default_string = 74 [default = "hello"]; - inline bool has_default_string() const; - inline void clear_default_string(); - static const int kDefaultStringFieldNumber = 74; - inline const ::std::string& default_string() const; - inline void set_default_string(const ::std::string& value); - inline void set_default_string(const char* value); - inline void set_default_string(const char* value, size_t size); - inline ::std::string* mutable_default_string(); - inline ::std::string* release_default_string(); - - // optional bytes default_bytes = 75 [default = "world"]; - inline bool has_default_bytes() const; - inline void clear_default_bytes(); - static const int kDefaultBytesFieldNumber = 75; - inline const ::std::string& default_bytes() const; - inline void set_default_bytes(const ::std::string& value); - inline void set_default_bytes(const char* value); - inline void set_default_bytes(const void* value, size_t size); - inline ::std::string* mutable_default_bytes(); - inline ::std::string* release_default_bytes(); - - // optional .protobuf_unittest.TestAllTypesLite.NestedEnum default_nested_enum = 81 [default = BAR]; - inline bool has_default_nested_enum() const; - inline void clear_default_nested_enum(); - static const int kDefaultNestedEnumFieldNumber = 81; - inline ::protobuf_unittest::TestAllTypesLite_NestedEnum default_nested_enum() const; - inline void set_default_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value); - - // optional .protobuf_unittest.ForeignEnumLite default_foreign_enum = 82 [default = FOREIGN_LITE_BAR]; - inline bool has_default_foreign_enum() const; - inline void clear_default_foreign_enum(); - static const int kDefaultForeignEnumFieldNumber = 82; - inline protobuf_unittest::ForeignEnumLite default_foreign_enum() const; - inline void set_default_foreign_enum(protobuf_unittest::ForeignEnumLite value); - - // optional .protobuf_unittest_import.ImportEnumLite default_import_enum = 83 [default = IMPORT_LITE_BAR]; - inline bool has_default_import_enum() const; - inline void clear_default_import_enum(); - static const int kDefaultImportEnumFieldNumber = 83; - inline protobuf_unittest_import::ImportEnumLite default_import_enum() const; - inline void set_default_import_enum(protobuf_unittest_import::ImportEnumLite value); - - // optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; - inline bool has_default_string_piece() const; - inline void clear_default_string_piece(); - static const int kDefaultStringPieceFieldNumber = 84; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& default_string_piece() const; - inline void set_default_string_piece(const ::std::string& value); - inline void set_default_string_piece(const char* value); - inline void set_default_string_piece(const char* value, size_t size); - inline ::std::string* mutable_default_string_piece(); - inline ::std::string* release_default_string_piece(); - public: - - // optional string default_cord = 85 [default = "123", ctype = CORD]; - inline bool has_default_cord() const; - inline void clear_default_cord(); - static const int kDefaultCordFieldNumber = 85; - private: - // Hidden due to unknown ctype option. - inline const ::std::string& default_cord() const; - inline void set_default_cord(const ::std::string& value); - inline void set_default_cord(const char* value); - inline void set_default_cord(const char* value, size_t size); - inline ::std::string* mutable_default_cord(); - inline ::std::string* release_default_cord(); - public: - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllTypesLite) - private: - inline void set_has_optional_int32(); - inline void clear_has_optional_int32(); - inline void set_has_optional_int64(); - inline void clear_has_optional_int64(); - inline void set_has_optional_uint32(); - inline void clear_has_optional_uint32(); - inline void set_has_optional_uint64(); - inline void clear_has_optional_uint64(); - inline void set_has_optional_sint32(); - inline void clear_has_optional_sint32(); - inline void set_has_optional_sint64(); - inline void clear_has_optional_sint64(); - inline void set_has_optional_fixed32(); - inline void clear_has_optional_fixed32(); - inline void set_has_optional_fixed64(); - inline void clear_has_optional_fixed64(); - inline void set_has_optional_sfixed32(); - inline void clear_has_optional_sfixed32(); - inline void set_has_optional_sfixed64(); - inline void clear_has_optional_sfixed64(); - inline void set_has_optional_float(); - inline void clear_has_optional_float(); - inline void set_has_optional_double(); - inline void clear_has_optional_double(); - inline void set_has_optional_bool(); - inline void clear_has_optional_bool(); - inline void set_has_optional_string(); - inline void clear_has_optional_string(); - inline void set_has_optional_bytes(); - inline void clear_has_optional_bytes(); - inline void set_has_optionalgroup(); - inline void clear_has_optionalgroup(); - inline void set_has_optional_nested_message(); - inline void clear_has_optional_nested_message(); - inline void set_has_optional_foreign_message(); - inline void clear_has_optional_foreign_message(); - inline void set_has_optional_import_message(); - inline void clear_has_optional_import_message(); - inline void set_has_optional_nested_enum(); - inline void clear_has_optional_nested_enum(); - inline void set_has_optional_foreign_enum(); - inline void clear_has_optional_foreign_enum(); - inline void set_has_optional_import_enum(); - inline void clear_has_optional_import_enum(); - inline void set_has_optional_string_piece(); - inline void clear_has_optional_string_piece(); - inline void set_has_optional_cord(); - inline void clear_has_optional_cord(); - inline void set_has_default_int32(); - inline void clear_has_default_int32(); - inline void set_has_default_int64(); - inline void clear_has_default_int64(); - inline void set_has_default_uint32(); - inline void clear_has_default_uint32(); - inline void set_has_default_uint64(); - inline void clear_has_default_uint64(); - inline void set_has_default_sint32(); - inline void clear_has_default_sint32(); - inline void set_has_default_sint64(); - inline void clear_has_default_sint64(); - inline void set_has_default_fixed32(); - inline void clear_has_default_fixed32(); - inline void set_has_default_fixed64(); - inline void clear_has_default_fixed64(); - inline void set_has_default_sfixed32(); - inline void clear_has_default_sfixed32(); - inline void set_has_default_sfixed64(); - inline void clear_has_default_sfixed64(); - inline void set_has_default_float(); - inline void clear_has_default_float(); - inline void set_has_default_double(); - inline void clear_has_default_double(); - inline void set_has_default_bool(); - inline void clear_has_default_bool(); - inline void set_has_default_string(); - inline void clear_has_default_string(); - inline void set_has_default_bytes(); - inline void clear_has_default_bytes(); - inline void set_has_default_nested_enum(); - inline void clear_has_default_nested_enum(); - inline void set_has_default_foreign_enum(); - inline void clear_has_default_foreign_enum(); - inline void set_has_default_import_enum(); - inline void clear_has_default_import_enum(); - inline void set_has_default_string_piece(); - inline void clear_has_default_string_piece(); - inline void set_has_default_cord(); - inline void clear_has_default_cord(); - - ::google::protobuf::int32 optional_int32_; - ::google::protobuf::uint32 optional_uint32_; - ::google::protobuf::int64 optional_int64_; - ::google::protobuf::uint64 optional_uint64_; - ::google::protobuf::int32 optional_sint32_; - ::google::protobuf::uint32 optional_fixed32_; - ::google::protobuf::int64 optional_sint64_; - ::google::protobuf::uint64 optional_fixed64_; - ::google::protobuf::int32 optional_sfixed32_; - float optional_float_; - ::google::protobuf::int64 optional_sfixed64_; - double optional_double_; - ::std::string* optional_string_; - ::std::string* optional_bytes_; - ::protobuf_unittest::TestAllTypesLite_OptionalGroup* optionalgroup_; - ::protobuf_unittest::TestAllTypesLite_NestedMessage* optional_nested_message_; - ::protobuf_unittest::ForeignMessageLite* optional_foreign_message_; - ::protobuf_unittest_import::ImportMessageLite* optional_import_message_; - int optional_nested_enum_; - int optional_foreign_enum_; - ::std::string* optional_string_piece_; - ::std::string* optional_cord_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_int32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_int64_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_uint32_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_uint64_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sint32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sint64_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > repeated_fixed32_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > repeated_fixed64_; - int optional_import_enum_; - bool optional_bool_; - bool default_bool_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > repeated_sfixed32_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > repeated_sfixed64_; - ::google::protobuf::RepeatedField< float > repeated_float_; - ::google::protobuf::RepeatedField< double > repeated_double_; - ::google::protobuf::RepeatedField< bool > repeated_bool_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_bytes_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup > repeatedgroup_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage > repeated_nested_message_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite > repeated_foreign_message_; - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite > repeated_import_message_; - ::google::protobuf::RepeatedField repeated_nested_enum_; - ::google::protobuf::RepeatedField repeated_foreign_enum_; - ::google::protobuf::RepeatedField repeated_import_enum_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_string_piece_; - ::google::protobuf::RepeatedPtrField< ::std::string> repeated_cord_; - ::google::protobuf::int64 default_int64_; - ::google::protobuf::int32 default_int32_; - ::google::protobuf::uint32 default_uint32_; - ::google::protobuf::uint64 default_uint64_; - ::google::protobuf::int32 default_sint32_; - ::google::protobuf::uint32 default_fixed32_; - ::google::protobuf::int64 default_sint64_; - ::google::protobuf::uint64 default_fixed64_; - ::google::protobuf::int32 default_sfixed32_; - float default_float_; - ::google::protobuf::int64 default_sfixed64_; - double default_double_; - ::std::string* default_string_; - static const ::std::string _default_default_string_; - ::std::string* default_bytes_; - static const ::std::string _default_default_bytes_; - int default_nested_enum_; - int default_foreign_enum_; - ::std::string* default_string_piece_; - static const ::std::string _default_default_string_piece_; - ::std::string* default_cord_; - static const ::std::string _default_default_cord_; - int default_import_enum_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(68 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestAllTypesLite* default_instance_; -}; -// ------------------------------------------------------------------- - -class ForeignMessageLite : public ::google::protobuf::MessageLite { - public: - ForeignMessageLite(); - virtual ~ForeignMessageLite(); - - ForeignMessageLite(const ForeignMessageLite& from); - - inline ForeignMessageLite& operator=(const ForeignMessageLite& from) { - CopyFrom(from); - return *this; - } - - static const ForeignMessageLite& default_instance(); - - void Swap(ForeignMessageLite* other); - - // implements Message ---------------------------------------------- - - ForeignMessageLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const ForeignMessageLite& from); - void MergeFrom(const ForeignMessageLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 c = 1; - inline bool has_c() const; - inline void clear_c(); - static const int kCFieldNumber = 1; - inline ::google::protobuf::int32 c() const; - inline void set_c(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.ForeignMessageLite) - private: - inline void set_has_c(); - inline void clear_has_c(); - - ::google::protobuf::int32 c_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static ForeignMessageLite* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestPackedTypesLite : public ::google::protobuf::MessageLite { - public: - TestPackedTypesLite(); - virtual ~TestPackedTypesLite(); - - TestPackedTypesLite(const TestPackedTypesLite& from); - - inline TestPackedTypesLite& operator=(const TestPackedTypesLite& from) { - CopyFrom(from); - return *this; - } - - static const TestPackedTypesLite& default_instance(); - - void Swap(TestPackedTypesLite* other); - - // implements Message ---------------------------------------------- - - TestPackedTypesLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestPackedTypesLite& from); - void MergeFrom(const TestPackedTypesLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 packed_int32 = 90 [packed = true]; - inline int packed_int32_size() const; - inline void clear_packed_int32(); - static const int kPackedInt32FieldNumber = 90; - inline ::google::protobuf::int32 packed_int32(int index) const; - inline void set_packed_int32(int index, ::google::protobuf::int32 value); - inline void add_packed_int32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - packed_int32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_packed_int32(); - - // repeated int64 packed_int64 = 91 [packed = true]; - inline int packed_int64_size() const; - inline void clear_packed_int64(); - static const int kPackedInt64FieldNumber = 91; - inline ::google::protobuf::int64 packed_int64(int index) const; - inline void set_packed_int64(int index, ::google::protobuf::int64 value); - inline void add_packed_int64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - packed_int64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_packed_int64(); - - // repeated uint32 packed_uint32 = 92 [packed = true]; - inline int packed_uint32_size() const; - inline void clear_packed_uint32(); - static const int kPackedUint32FieldNumber = 92; - inline ::google::protobuf::uint32 packed_uint32(int index) const; - inline void set_packed_uint32(int index, ::google::protobuf::uint32 value); - inline void add_packed_uint32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - packed_uint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_packed_uint32(); - - // repeated uint64 packed_uint64 = 93 [packed = true]; - inline int packed_uint64_size() const; - inline void clear_packed_uint64(); - static const int kPackedUint64FieldNumber = 93; - inline ::google::protobuf::uint64 packed_uint64(int index) const; - inline void set_packed_uint64(int index, ::google::protobuf::uint64 value); - inline void add_packed_uint64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - packed_uint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_packed_uint64(); - - // repeated sint32 packed_sint32 = 94 [packed = true]; - inline int packed_sint32_size() const; - inline void clear_packed_sint32(); - static const int kPackedSint32FieldNumber = 94; - inline ::google::protobuf::int32 packed_sint32(int index) const; - inline void set_packed_sint32(int index, ::google::protobuf::int32 value); - inline void add_packed_sint32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - packed_sint32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_packed_sint32(); - - // repeated sint64 packed_sint64 = 95 [packed = true]; - inline int packed_sint64_size() const; - inline void clear_packed_sint64(); - static const int kPackedSint64FieldNumber = 95; - inline ::google::protobuf::int64 packed_sint64(int index) const; - inline void set_packed_sint64(int index, ::google::protobuf::int64 value); - inline void add_packed_sint64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - packed_sint64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_packed_sint64(); - - // repeated fixed32 packed_fixed32 = 96 [packed = true]; - inline int packed_fixed32_size() const; - inline void clear_packed_fixed32(); - static const int kPackedFixed32FieldNumber = 96; - inline ::google::protobuf::uint32 packed_fixed32(int index) const; - inline void set_packed_fixed32(int index, ::google::protobuf::uint32 value); - inline void add_packed_fixed32(::google::protobuf::uint32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& - packed_fixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* - mutable_packed_fixed32(); - - // repeated fixed64 packed_fixed64 = 97 [packed = true]; - inline int packed_fixed64_size() const; - inline void clear_packed_fixed64(); - static const int kPackedFixed64FieldNumber = 97; - inline ::google::protobuf::uint64 packed_fixed64(int index) const; - inline void set_packed_fixed64(int index, ::google::protobuf::uint64 value); - inline void add_packed_fixed64(::google::protobuf::uint64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& - packed_fixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* - mutable_packed_fixed64(); - - // repeated sfixed32 packed_sfixed32 = 98 [packed = true]; - inline int packed_sfixed32_size() const; - inline void clear_packed_sfixed32(); - static const int kPackedSfixed32FieldNumber = 98; - inline ::google::protobuf::int32 packed_sfixed32(int index) const; - inline void set_packed_sfixed32(int index, ::google::protobuf::int32 value); - inline void add_packed_sfixed32(::google::protobuf::int32 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - packed_sfixed32() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_packed_sfixed32(); - - // repeated sfixed64 packed_sfixed64 = 99 [packed = true]; - inline int packed_sfixed64_size() const; - inline void clear_packed_sfixed64(); - static const int kPackedSfixed64FieldNumber = 99; - inline ::google::protobuf::int64 packed_sfixed64(int index) const; - inline void set_packed_sfixed64(int index, ::google::protobuf::int64 value); - inline void add_packed_sfixed64(::google::protobuf::int64 value); - inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - packed_sfixed64() const; - inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_packed_sfixed64(); - - // repeated float packed_float = 100 [packed = true]; - inline int packed_float_size() const; - inline void clear_packed_float(); - static const int kPackedFloatFieldNumber = 100; - inline float packed_float(int index) const; - inline void set_packed_float(int index, float value); - inline void add_packed_float(float value); - inline const ::google::protobuf::RepeatedField< float >& - packed_float() const; - inline ::google::protobuf::RepeatedField< float >* - mutable_packed_float(); - - // repeated double packed_double = 101 [packed = true]; - inline int packed_double_size() const; - inline void clear_packed_double(); - static const int kPackedDoubleFieldNumber = 101; - inline double packed_double(int index) const; - inline void set_packed_double(int index, double value); - inline void add_packed_double(double value); - inline const ::google::protobuf::RepeatedField< double >& - packed_double() const; - inline ::google::protobuf::RepeatedField< double >* - mutable_packed_double(); - - // repeated bool packed_bool = 102 [packed = true]; - inline int packed_bool_size() const; - inline void clear_packed_bool(); - static const int kPackedBoolFieldNumber = 102; - inline bool packed_bool(int index) const; - inline void set_packed_bool(int index, bool value); - inline void add_packed_bool(bool value); - inline const ::google::protobuf::RepeatedField< bool >& - packed_bool() const; - inline ::google::protobuf::RepeatedField< bool >* - mutable_packed_bool(); - - // repeated .protobuf_unittest.ForeignEnumLite packed_enum = 103 [packed = true]; - inline int packed_enum_size() const; - inline void clear_packed_enum(); - static const int kPackedEnumFieldNumber = 103; - inline protobuf_unittest::ForeignEnumLite packed_enum(int index) const; - inline void set_packed_enum(int index, protobuf_unittest::ForeignEnumLite value); - inline void add_packed_enum(protobuf_unittest::ForeignEnumLite value); - inline const ::google::protobuf::RepeatedField& packed_enum() const; - inline ::google::protobuf::RepeatedField* mutable_packed_enum(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedTypesLite) - private: - - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_int32_; - mutable int _packed_int32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_int64_; - mutable int _packed_int64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_uint32_; - mutable int _packed_uint32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_uint64_; - mutable int _packed_uint64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sint32_; - mutable int _packed_sint32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sint64_; - mutable int _packed_sint64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > packed_fixed32_; - mutable int _packed_fixed32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::uint64 > packed_fixed64_; - mutable int _packed_fixed64_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > packed_sfixed32_; - mutable int _packed_sfixed32_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > packed_sfixed64_; - mutable int _packed_sfixed64_cached_byte_size_; - ::google::protobuf::RepeatedField< float > packed_float_; - mutable int _packed_float_cached_byte_size_; - ::google::protobuf::RepeatedField< double > packed_double_; - mutable int _packed_double_cached_byte_size_; - ::google::protobuf::RepeatedField< bool > packed_bool_; - mutable int _packed_bool_cached_byte_size_; - ::google::protobuf::RepeatedField packed_enum_; - mutable int _packed_enum_cached_byte_size_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(14 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestPackedTypesLite* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestAllExtensionsLite : public ::google::protobuf::MessageLite { - public: - TestAllExtensionsLite(); - virtual ~TestAllExtensionsLite(); - - TestAllExtensionsLite(const TestAllExtensionsLite& from); - - inline TestAllExtensionsLite& operator=(const TestAllExtensionsLite& from) { - CopyFrom(from); - return *this; - } - - static const TestAllExtensionsLite& default_instance(); - - void Swap(TestAllExtensionsLite* other); - - // implements Message ---------------------------------------------- - - TestAllExtensionsLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestAllExtensionsLite& from); - void MergeFrom(const TestAllExtensionsLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestAllExtensionsLite) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestAllExtensionsLite) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestAllExtensionsLite* default_instance_; -}; -// ------------------------------------------------------------------- - -class OptionalGroup_extension_lite : public ::google::protobuf::MessageLite { - public: - OptionalGroup_extension_lite(); - virtual ~OptionalGroup_extension_lite(); - - OptionalGroup_extension_lite(const OptionalGroup_extension_lite& from); - - inline OptionalGroup_extension_lite& operator=(const OptionalGroup_extension_lite& from) { - CopyFrom(from); - return *this; - } - - static const OptionalGroup_extension_lite& default_instance(); - - void Swap(OptionalGroup_extension_lite* other); - - // implements Message ---------------------------------------------- - - OptionalGroup_extension_lite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const OptionalGroup_extension_lite& from); - void MergeFrom(const OptionalGroup_extension_lite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 17; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 17; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.OptionalGroup_extension_lite) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static OptionalGroup_extension_lite* default_instance_; -}; -// ------------------------------------------------------------------- - -class RepeatedGroup_extension_lite : public ::google::protobuf::MessageLite { - public: - RepeatedGroup_extension_lite(); - virtual ~RepeatedGroup_extension_lite(); - - RepeatedGroup_extension_lite(const RepeatedGroup_extension_lite& from); - - inline RepeatedGroup_extension_lite& operator=(const RepeatedGroup_extension_lite& from) { - CopyFrom(from); - return *this; - } - - static const RepeatedGroup_extension_lite& default_instance(); - - void Swap(RepeatedGroup_extension_lite* other); - - // implements Message ---------------------------------------------- - - RepeatedGroup_extension_lite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const RepeatedGroup_extension_lite& from); - void MergeFrom(const RepeatedGroup_extension_lite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 47; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 47; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.RepeatedGroup_extension_lite) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static RepeatedGroup_extension_lite* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestPackedExtensionsLite : public ::google::protobuf::MessageLite { - public: - TestPackedExtensionsLite(); - virtual ~TestPackedExtensionsLite(); - - TestPackedExtensionsLite(const TestPackedExtensionsLite& from); - - inline TestPackedExtensionsLite& operator=(const TestPackedExtensionsLite& from) { - CopyFrom(from); - return *this; - } - - static const TestPackedExtensionsLite& default_instance(); - - void Swap(TestPackedExtensionsLite* other); - - // implements Message ---------------------------------------------- - - TestPackedExtensionsLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestPackedExtensionsLite& from); - void MergeFrom(const TestPackedExtensionsLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestPackedExtensionsLite) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestPackedExtensionsLite) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestPackedExtensionsLite* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestNestedExtensionLite : public ::google::protobuf::MessageLite { - public: - TestNestedExtensionLite(); - virtual ~TestNestedExtensionLite(); - - TestNestedExtensionLite(const TestNestedExtensionLite& from); - - inline TestNestedExtensionLite& operator=(const TestNestedExtensionLite& from) { - CopyFrom(from); - return *this; - } - - static const TestNestedExtensionLite& default_instance(); - - void Swap(TestNestedExtensionLite* other); - - // implements Message ---------------------------------------------- - - TestNestedExtensionLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestNestedExtensionLite& from); - void MergeFrom(const TestNestedExtensionLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - static const int kNestedExtensionFieldNumber = 12345; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - nested_extension; - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestNestedExtensionLite) - private: - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestNestedExtensionLite* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestDeprecatedLite : public ::google::protobuf::MessageLite { - public: - TestDeprecatedLite(); - virtual ~TestDeprecatedLite(); - - TestDeprecatedLite(const TestDeprecatedLite& from); - - inline TestDeprecatedLite& operator=(const TestDeprecatedLite& from) { - CopyFrom(from); - return *this; - } - - static const TestDeprecatedLite& default_instance(); - - void Swap(TestDeprecatedLite* other); - - // implements Message ---------------------------------------------- - - TestDeprecatedLite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestDeprecatedLite& from); - void MergeFrom(const TestDeprecatedLite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 deprecated_field = 1 [deprecated = true]; - inline bool has_deprecated_field() const PROTOBUF_DEPRECATED; - inline void clear_deprecated_field() PROTOBUF_DEPRECATED; - static const int kDeprecatedFieldFieldNumber = 1; - inline ::google::protobuf::int32 deprecated_field() const PROTOBUF_DEPRECATED; - inline void set_deprecated_field(::google::protobuf::int32 value) PROTOBUF_DEPRECATED; - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestDeprecatedLite) - private: - inline void set_has_deprecated_field(); - inline void clear_has_deprecated_field(); - - ::google::protobuf::int32 deprecated_field_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_2eproto(); - - void InitAsDefaultInstance(); - static TestDeprecatedLite* default_instance_; -}; -// =================================================================== - -static const int kOptionalInt32ExtensionLiteFieldNumber = 1; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - optional_int32_extension_lite; -static const int kOptionalInt64ExtensionLiteFieldNumber = 2; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > - optional_int64_extension_lite; -static const int kOptionalUint32ExtensionLiteFieldNumber = 3; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > - optional_uint32_extension_lite; -static const int kOptionalUint64ExtensionLiteFieldNumber = 4; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - optional_uint64_extension_lite; -static const int kOptionalSint32ExtensionLiteFieldNumber = 5; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > - optional_sint32_extension_lite; -static const int kOptionalSint64ExtensionLiteFieldNumber = 6; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - optional_sint64_extension_lite; -static const int kOptionalFixed32ExtensionLiteFieldNumber = 7; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > - optional_fixed32_extension_lite; -static const int kOptionalFixed64ExtensionLiteFieldNumber = 8; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - optional_fixed64_extension_lite; -static const int kOptionalSfixed32ExtensionLiteFieldNumber = 9; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - optional_sfixed32_extension_lite; -static const int kOptionalSfixed64ExtensionLiteFieldNumber = 10; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > - optional_sfixed64_extension_lite; -static const int kOptionalFloatExtensionLiteFieldNumber = 11; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > - optional_float_extension_lite; -static const int kOptionalDoubleExtensionLiteFieldNumber = 12; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > - optional_double_extension_lite; -static const int kOptionalBoolExtensionLiteFieldNumber = 13; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > - optional_bool_extension_lite; -static const int kOptionalStringExtensionLiteFieldNumber = 14; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 9, false > - optional_string_extension_lite; -static const int kOptionalBytesExtensionLiteFieldNumber = 15; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 12, false > - optional_bytes_extension_lite; -static const int kOptionalgroupExtensionLiteFieldNumber = 16; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::OptionalGroup_extension_lite >, 10, false > - optionalgroup_extension_lite; -static const int kOptionalNestedMessageExtensionLiteFieldNumber = 18; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedMessage >, 11, false > - optional_nested_message_extension_lite; -static const int kOptionalForeignMessageExtensionLiteFieldNumber = 19; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::ForeignMessageLite >, 11, false > - optional_foreign_message_extension_lite; -static const int kOptionalImportMessageExtensionLiteFieldNumber = 20; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest_import::ImportMessageLite >, 11, false > - optional_import_message_extension_lite; -static const int kOptionalNestedEnumExtensionLiteFieldNumber = 21; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedEnum, ::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid>, 14, false > - optional_nested_enum_extension_lite; -static const int kOptionalForeignEnumExtensionLiteFieldNumber = 22; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, false > - optional_foreign_enum_extension_lite; -static const int kOptionalImportEnumExtensionLiteFieldNumber = 23; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnumLite, protobuf_unittest_import::ImportEnumLite_IsValid>, 14, false > - optional_import_enum_extension_lite; -static const int kOptionalStringPieceExtensionLiteFieldNumber = 24; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 9, false > - optional_string_piece_extension_lite; -static const int kOptionalCordExtensionLiteFieldNumber = 25; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 9, false > - optional_cord_extension_lite; -static const int kRepeatedInt32ExtensionLiteFieldNumber = 31; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - repeated_int32_extension_lite; -static const int kRepeatedInt64ExtensionLiteFieldNumber = 32; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > - repeated_int64_extension_lite; -static const int kRepeatedUint32ExtensionLiteFieldNumber = 33; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > - repeated_uint32_extension_lite; -static const int kRepeatedUint64ExtensionLiteFieldNumber = 34; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - repeated_uint64_extension_lite; -static const int kRepeatedSint32ExtensionLiteFieldNumber = 35; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > - repeated_sint32_extension_lite; -static const int kRepeatedSint64ExtensionLiteFieldNumber = 36; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - repeated_sint64_extension_lite; -static const int kRepeatedFixed32ExtensionLiteFieldNumber = 37; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > - repeated_fixed32_extension_lite; -static const int kRepeatedFixed64ExtensionLiteFieldNumber = 38; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - repeated_fixed64_extension_lite; -static const int kRepeatedSfixed32ExtensionLiteFieldNumber = 39; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - repeated_sfixed32_extension_lite; -static const int kRepeatedSfixed64ExtensionLiteFieldNumber = 40; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > - repeated_sfixed64_extension_lite; -static const int kRepeatedFloatExtensionLiteFieldNumber = 41; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, false > - repeated_float_extension_lite; -static const int kRepeatedDoubleExtensionLiteFieldNumber = 42; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, false > - repeated_double_extension_lite; -static const int kRepeatedBoolExtensionLiteFieldNumber = 43; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, false > - repeated_bool_extension_lite; -static const int kRepeatedStringExtensionLiteFieldNumber = 44; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > - repeated_string_extension_lite; -static const int kRepeatedBytesExtensionLiteFieldNumber = 45; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedStringTypeTraits, 12, false > - repeated_bytes_extension_lite; -static const int kRepeatedgroupExtensionLiteFieldNumber = 46; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::RepeatedGroup_extension_lite >, 10, false > - repeatedgroup_extension_lite; -static const int kRepeatedNestedMessageExtensionLiteFieldNumber = 48; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedMessage >, 11, false > - repeated_nested_message_extension_lite; -static const int kRepeatedForeignMessageExtensionLiteFieldNumber = 49; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest::ForeignMessageLite >, 11, false > - repeated_foreign_message_extension_lite; -static const int kRepeatedImportMessageExtensionLiteFieldNumber = 50; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedMessageTypeTraits< ::protobuf_unittest_import::ImportMessageLite >, 11, false > - repeated_import_message_extension_lite; -static const int kRepeatedNestedEnumExtensionLiteFieldNumber = 51; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedEnumTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedEnum, ::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid>, 14, false > - repeated_nested_enum_extension_lite; -static const int kRepeatedForeignEnumExtensionLiteFieldNumber = 52; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, false > - repeated_foreign_enum_extension_lite; -static const int kRepeatedImportEnumExtensionLiteFieldNumber = 53; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest_import::ImportEnumLite, protobuf_unittest_import::ImportEnumLite_IsValid>, 14, false > - repeated_import_enum_extension_lite; -static const int kRepeatedStringPieceExtensionLiteFieldNumber = 54; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > - repeated_string_piece_extension_lite; -static const int kRepeatedCordExtensionLiteFieldNumber = 55; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::RepeatedStringTypeTraits, 9, false > - repeated_cord_extension_lite; -static const int kDefaultInt32ExtensionLiteFieldNumber = 61; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - default_int32_extension_lite; -static const int kDefaultInt64ExtensionLiteFieldNumber = 62; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 3, false > - default_int64_extension_lite; -static const int kDefaultUint32ExtensionLiteFieldNumber = 63; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, false > - default_uint32_extension_lite; -static const int kDefaultUint64ExtensionLiteFieldNumber = 64; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, false > - default_uint64_extension_lite; -static const int kDefaultSint32ExtensionLiteFieldNumber = 65; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 17, false > - default_sint32_extension_lite; -static const int kDefaultSint64ExtensionLiteFieldNumber = 66; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 18, false > - default_sint64_extension_lite; -static const int kDefaultFixed32ExtensionLiteFieldNumber = 67; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, false > - default_fixed32_extension_lite; -static const int kDefaultFixed64ExtensionLiteFieldNumber = 68; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, false > - default_fixed64_extension_lite; -static const int kDefaultSfixed32ExtensionLiteFieldNumber = 69; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 15, false > - default_sfixed32_extension_lite; -static const int kDefaultSfixed64ExtensionLiteFieldNumber = 70; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int64 >, 16, false > - default_sfixed64_extension_lite; -static const int kDefaultFloatExtensionLiteFieldNumber = 71; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< float >, 2, false > - default_float_extension_lite; -static const int kDefaultDoubleExtensionLiteFieldNumber = 72; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< double >, 1, false > - default_double_extension_lite; -static const int kDefaultBoolExtensionLiteFieldNumber = 73; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::PrimitiveTypeTraits< bool >, 8, false > - default_bool_extension_lite; -static const int kDefaultStringExtensionLiteFieldNumber = 74; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 9, false > - default_string_extension_lite; -static const int kDefaultBytesExtensionLiteFieldNumber = 75; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 12, false > - default_bytes_extension_lite; -static const int kDefaultNestedEnumExtensionLiteFieldNumber = 81; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::EnumTypeTraits< ::protobuf_unittest::TestAllTypesLite_NestedEnum, ::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid>, 14, false > - default_nested_enum_extension_lite; -static const int kDefaultForeignEnumExtensionLiteFieldNumber = 82; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, false > - default_foreign_enum_extension_lite; -static const int kDefaultImportEnumExtensionLiteFieldNumber = 83; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::EnumTypeTraits< protobuf_unittest_import::ImportEnumLite, protobuf_unittest_import::ImportEnumLite_IsValid>, 14, false > - default_import_enum_extension_lite; -static const int kDefaultStringPieceExtensionLiteFieldNumber = 84; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 9, false > - default_string_piece_extension_lite; -static const int kDefaultCordExtensionLiteFieldNumber = 85; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestAllExtensionsLite, - ::google::protobuf::internal::StringTypeTraits, 9, false > - default_cord_extension_lite; -static const int kPackedInt32ExtensionLiteFieldNumber = 90; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 5, true > - packed_int32_extension_lite; -static const int kPackedInt64ExtensionLiteFieldNumber = 91; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 3, true > - packed_int64_extension_lite; -static const int kPackedUint32ExtensionLiteFieldNumber = 92; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 13, true > - packed_uint32_extension_lite; -static const int kPackedUint64ExtensionLiteFieldNumber = 93; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 4, true > - packed_uint64_extension_lite; -static const int kPackedSint32ExtensionLiteFieldNumber = 94; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 17, true > - packed_sint32_extension_lite; -static const int kPackedSint64ExtensionLiteFieldNumber = 95; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 18, true > - packed_sint64_extension_lite; -static const int kPackedFixed32ExtensionLiteFieldNumber = 96; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint32 >, 7, true > - packed_fixed32_extension_lite; -static const int kPackedFixed64ExtensionLiteFieldNumber = 97; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::uint64 >, 6, true > - packed_fixed64_extension_lite; -static const int kPackedSfixed32ExtensionLiteFieldNumber = 98; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int32 >, 15, true > - packed_sfixed32_extension_lite; -static const int kPackedSfixed64ExtensionLiteFieldNumber = 99; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< ::google::protobuf::int64 >, 16, true > - packed_sfixed64_extension_lite; -static const int kPackedFloatExtensionLiteFieldNumber = 100; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< float >, 2, true > - packed_float_extension_lite; -static const int kPackedDoubleExtensionLiteFieldNumber = 101; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< double >, 1, true > - packed_double_extension_lite; -static const int kPackedBoolExtensionLiteFieldNumber = 102; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedPrimitiveTypeTraits< bool >, 8, true > - packed_bool_extension_lite; -static const int kPackedEnumExtensionLiteFieldNumber = 103; -extern ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestPackedExtensionsLite, - ::google::protobuf::internal::RepeatedEnumTypeTraits< protobuf_unittest::ForeignEnumLite, protobuf_unittest::ForeignEnumLite_IsValid>, 14, true > - packed_enum_extension_lite; - -// =================================================================== - -// TestAllTypesLite_NestedMessage - -// optional int32 bb = 1; -inline bool TestAllTypesLite_NestedMessage::has_bb() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypesLite_NestedMessage::set_has_bb() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypesLite_NestedMessage::clear_has_bb() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypesLite_NestedMessage::clear_bb() { - bb_ = 0; - clear_has_bb(); -} -inline ::google::protobuf::int32 TestAllTypesLite_NestedMessage::bb() const { - return bb_; -} -inline void TestAllTypesLite_NestedMessage::set_bb(::google::protobuf::int32 value) { - set_has_bb(); - bb_ = value; -} - -// ------------------------------------------------------------------- - -// TestAllTypesLite_OptionalGroup - -// optional int32 a = 17; -inline bool TestAllTypesLite_OptionalGroup::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypesLite_OptionalGroup::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypesLite_OptionalGroup::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypesLite_OptionalGroup::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestAllTypesLite_OptionalGroup::a() const { - return a_; -} -inline void TestAllTypesLite_OptionalGroup::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestAllTypesLite_RepeatedGroup - -// optional int32 a = 47; -inline bool TestAllTypesLite_RepeatedGroup::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypesLite_RepeatedGroup::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypesLite_RepeatedGroup::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypesLite_RepeatedGroup::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestAllTypesLite_RepeatedGroup::a() const { - return a_; -} -inline void TestAllTypesLite_RepeatedGroup::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestAllTypesLite - -// optional int32 optional_int32 = 1; -inline bool TestAllTypesLite::has_optional_int32() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestAllTypesLite::set_has_optional_int32() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestAllTypesLite::clear_has_optional_int32() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestAllTypesLite::clear_optional_int32() { - optional_int32_ = 0; - clear_has_optional_int32(); -} -inline ::google::protobuf::int32 TestAllTypesLite::optional_int32() const { - return optional_int32_; -} -inline void TestAllTypesLite::set_optional_int32(::google::protobuf::int32 value) { - set_has_optional_int32(); - optional_int32_ = value; -} - -// optional int64 optional_int64 = 2; -inline bool TestAllTypesLite::has_optional_int64() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestAllTypesLite::set_has_optional_int64() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestAllTypesLite::clear_has_optional_int64() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestAllTypesLite::clear_optional_int64() { - optional_int64_ = GOOGLE_LONGLONG(0); - clear_has_optional_int64(); -} -inline ::google::protobuf::int64 TestAllTypesLite::optional_int64() const { - return optional_int64_; -} -inline void TestAllTypesLite::set_optional_int64(::google::protobuf::int64 value) { - set_has_optional_int64(); - optional_int64_ = value; -} - -// optional uint32 optional_uint32 = 3; -inline bool TestAllTypesLite::has_optional_uint32() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void TestAllTypesLite::set_has_optional_uint32() { - _has_bits_[0] |= 0x00000004u; -} -inline void TestAllTypesLite::clear_has_optional_uint32() { - _has_bits_[0] &= ~0x00000004u; -} -inline void TestAllTypesLite::clear_optional_uint32() { - optional_uint32_ = 0u; - clear_has_optional_uint32(); -} -inline ::google::protobuf::uint32 TestAllTypesLite::optional_uint32() const { - return optional_uint32_; -} -inline void TestAllTypesLite::set_optional_uint32(::google::protobuf::uint32 value) { - set_has_optional_uint32(); - optional_uint32_ = value; -} - -// optional uint64 optional_uint64 = 4; -inline bool TestAllTypesLite::has_optional_uint64() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void TestAllTypesLite::set_has_optional_uint64() { - _has_bits_[0] |= 0x00000008u; -} -inline void TestAllTypesLite::clear_has_optional_uint64() { - _has_bits_[0] &= ~0x00000008u; -} -inline void TestAllTypesLite::clear_optional_uint64() { - optional_uint64_ = GOOGLE_ULONGLONG(0); - clear_has_optional_uint64(); -} -inline ::google::protobuf::uint64 TestAllTypesLite::optional_uint64() const { - return optional_uint64_; -} -inline void TestAllTypesLite::set_optional_uint64(::google::protobuf::uint64 value) { - set_has_optional_uint64(); - optional_uint64_ = value; -} - -// optional sint32 optional_sint32 = 5; -inline bool TestAllTypesLite::has_optional_sint32() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TestAllTypesLite::set_has_optional_sint32() { - _has_bits_[0] |= 0x00000010u; -} -inline void TestAllTypesLite::clear_has_optional_sint32() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TestAllTypesLite::clear_optional_sint32() { - optional_sint32_ = 0; - clear_has_optional_sint32(); -} -inline ::google::protobuf::int32 TestAllTypesLite::optional_sint32() const { - return optional_sint32_; -} -inline void TestAllTypesLite::set_optional_sint32(::google::protobuf::int32 value) { - set_has_optional_sint32(); - optional_sint32_ = value; -} - -// optional sint64 optional_sint64 = 6; -inline bool TestAllTypesLite::has_optional_sint64() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void TestAllTypesLite::set_has_optional_sint64() { - _has_bits_[0] |= 0x00000020u; -} -inline void TestAllTypesLite::clear_has_optional_sint64() { - _has_bits_[0] &= ~0x00000020u; -} -inline void TestAllTypesLite::clear_optional_sint64() { - optional_sint64_ = GOOGLE_LONGLONG(0); - clear_has_optional_sint64(); -} -inline ::google::protobuf::int64 TestAllTypesLite::optional_sint64() const { - return optional_sint64_; -} -inline void TestAllTypesLite::set_optional_sint64(::google::protobuf::int64 value) { - set_has_optional_sint64(); - optional_sint64_ = value; -} - -// optional fixed32 optional_fixed32 = 7; -inline bool TestAllTypesLite::has_optional_fixed32() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void TestAllTypesLite::set_has_optional_fixed32() { - _has_bits_[0] |= 0x00000040u; -} -inline void TestAllTypesLite::clear_has_optional_fixed32() { - _has_bits_[0] &= ~0x00000040u; -} -inline void TestAllTypesLite::clear_optional_fixed32() { - optional_fixed32_ = 0u; - clear_has_optional_fixed32(); -} -inline ::google::protobuf::uint32 TestAllTypesLite::optional_fixed32() const { - return optional_fixed32_; -} -inline void TestAllTypesLite::set_optional_fixed32(::google::protobuf::uint32 value) { - set_has_optional_fixed32(); - optional_fixed32_ = value; -} - -// optional fixed64 optional_fixed64 = 8; -inline bool TestAllTypesLite::has_optional_fixed64() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void TestAllTypesLite::set_has_optional_fixed64() { - _has_bits_[0] |= 0x00000080u; -} -inline void TestAllTypesLite::clear_has_optional_fixed64() { - _has_bits_[0] &= ~0x00000080u; -} -inline void TestAllTypesLite::clear_optional_fixed64() { - optional_fixed64_ = GOOGLE_ULONGLONG(0); - clear_has_optional_fixed64(); -} -inline ::google::protobuf::uint64 TestAllTypesLite::optional_fixed64() const { - return optional_fixed64_; -} -inline void TestAllTypesLite::set_optional_fixed64(::google::protobuf::uint64 value) { - set_has_optional_fixed64(); - optional_fixed64_ = value; -} - -// optional sfixed32 optional_sfixed32 = 9; -inline bool TestAllTypesLite::has_optional_sfixed32() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void TestAllTypesLite::set_has_optional_sfixed32() { - _has_bits_[0] |= 0x00000100u; -} -inline void TestAllTypesLite::clear_has_optional_sfixed32() { - _has_bits_[0] &= ~0x00000100u; -} -inline void TestAllTypesLite::clear_optional_sfixed32() { - optional_sfixed32_ = 0; - clear_has_optional_sfixed32(); -} -inline ::google::protobuf::int32 TestAllTypesLite::optional_sfixed32() const { - return optional_sfixed32_; -} -inline void TestAllTypesLite::set_optional_sfixed32(::google::protobuf::int32 value) { - set_has_optional_sfixed32(); - optional_sfixed32_ = value; -} - -// optional sfixed64 optional_sfixed64 = 10; -inline bool TestAllTypesLite::has_optional_sfixed64() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void TestAllTypesLite::set_has_optional_sfixed64() { - _has_bits_[0] |= 0x00000200u; -} -inline void TestAllTypesLite::clear_has_optional_sfixed64() { - _has_bits_[0] &= ~0x00000200u; -} -inline void TestAllTypesLite::clear_optional_sfixed64() { - optional_sfixed64_ = GOOGLE_LONGLONG(0); - clear_has_optional_sfixed64(); -} -inline ::google::protobuf::int64 TestAllTypesLite::optional_sfixed64() const { - return optional_sfixed64_; -} -inline void TestAllTypesLite::set_optional_sfixed64(::google::protobuf::int64 value) { - set_has_optional_sfixed64(); - optional_sfixed64_ = value; -} - -// optional float optional_float = 11; -inline bool TestAllTypesLite::has_optional_float() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void TestAllTypesLite::set_has_optional_float() { - _has_bits_[0] |= 0x00000400u; -} -inline void TestAllTypesLite::clear_has_optional_float() { - _has_bits_[0] &= ~0x00000400u; -} -inline void TestAllTypesLite::clear_optional_float() { - optional_float_ = 0; - clear_has_optional_float(); -} -inline float TestAllTypesLite::optional_float() const { - return optional_float_; -} -inline void TestAllTypesLite::set_optional_float(float value) { - set_has_optional_float(); - optional_float_ = value; -} - -// optional double optional_double = 12; -inline bool TestAllTypesLite::has_optional_double() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void TestAllTypesLite::set_has_optional_double() { - _has_bits_[0] |= 0x00000800u; -} -inline void TestAllTypesLite::clear_has_optional_double() { - _has_bits_[0] &= ~0x00000800u; -} -inline void TestAllTypesLite::clear_optional_double() { - optional_double_ = 0; - clear_has_optional_double(); -} -inline double TestAllTypesLite::optional_double() const { - return optional_double_; -} -inline void TestAllTypesLite::set_optional_double(double value) { - set_has_optional_double(); - optional_double_ = value; -} - -// optional bool optional_bool = 13; -inline bool TestAllTypesLite::has_optional_bool() const { - return (_has_bits_[0] & 0x00001000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_bool() { - _has_bits_[0] |= 0x00001000u; -} -inline void TestAllTypesLite::clear_has_optional_bool() { - _has_bits_[0] &= ~0x00001000u; -} -inline void TestAllTypesLite::clear_optional_bool() { - optional_bool_ = false; - clear_has_optional_bool(); -} -inline bool TestAllTypesLite::optional_bool() const { - return optional_bool_; -} -inline void TestAllTypesLite::set_optional_bool(bool value) { - set_has_optional_bool(); - optional_bool_ = value; -} - -// optional string optional_string = 14; -inline bool TestAllTypesLite::has_optional_string() const { - return (_has_bits_[0] & 0x00002000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_string() { - _has_bits_[0] |= 0x00002000u; -} -inline void TestAllTypesLite::clear_has_optional_string() { - _has_bits_[0] &= ~0x00002000u; -} -inline void TestAllTypesLite::clear_optional_string() { - if (optional_string_ != &::google::protobuf::internal::kEmptyString) { - optional_string_->clear(); - } - clear_has_optional_string(); -} -inline const ::std::string& TestAllTypesLite::optional_string() const { - return *optional_string_; -} -inline void TestAllTypesLite::set_optional_string(const ::std::string& value) { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - optional_string_->assign(value); -} -inline void TestAllTypesLite::set_optional_string(const char* value) { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - optional_string_->assign(value); -} -inline void TestAllTypesLite::set_optional_string(const char* value, size_t size) { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - optional_string_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_optional_string() { - set_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - optional_string_ = new ::std::string; - } - return optional_string_; -} -inline ::std::string* TestAllTypesLite::release_optional_string() { - clear_has_optional_string(); - if (optional_string_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_string_; - optional_string_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional bytes optional_bytes = 15; -inline bool TestAllTypesLite::has_optional_bytes() const { - return (_has_bits_[0] & 0x00004000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_bytes() { - _has_bits_[0] |= 0x00004000u; -} -inline void TestAllTypesLite::clear_has_optional_bytes() { - _has_bits_[0] &= ~0x00004000u; -} -inline void TestAllTypesLite::clear_optional_bytes() { - if (optional_bytes_ != &::google::protobuf::internal::kEmptyString) { - optional_bytes_->clear(); - } - clear_has_optional_bytes(); -} -inline const ::std::string& TestAllTypesLite::optional_bytes() const { - return *optional_bytes_; -} -inline void TestAllTypesLite::set_optional_bytes(const ::std::string& value) { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - optional_bytes_->assign(value); -} -inline void TestAllTypesLite::set_optional_bytes(const char* value) { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - optional_bytes_->assign(value); -} -inline void TestAllTypesLite::set_optional_bytes(const void* value, size_t size) { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - optional_bytes_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_optional_bytes() { - set_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - optional_bytes_ = new ::std::string; - } - return optional_bytes_; -} -inline ::std::string* TestAllTypesLite::release_optional_bytes() { - clear_has_optional_bytes(); - if (optional_bytes_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_bytes_; - optional_bytes_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional group OptionalGroup = 16 { -inline bool TestAllTypesLite::has_optionalgroup() const { - return (_has_bits_[0] & 0x00008000u) != 0; -} -inline void TestAllTypesLite::set_has_optionalgroup() { - _has_bits_[0] |= 0x00008000u; -} -inline void TestAllTypesLite::clear_has_optionalgroup() { - _has_bits_[0] &= ~0x00008000u; -} -inline void TestAllTypesLite::clear_optionalgroup() { - if (optionalgroup_ != NULL) optionalgroup_->::protobuf_unittest::TestAllTypesLite_OptionalGroup::Clear(); - clear_has_optionalgroup(); -} -inline const ::protobuf_unittest::TestAllTypesLite_OptionalGroup& TestAllTypesLite::optionalgroup() const { - return optionalgroup_ != NULL ? *optionalgroup_ : *default_instance_->optionalgroup_; -} -inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* TestAllTypesLite::mutable_optionalgroup() { - set_has_optionalgroup(); - if (optionalgroup_ == NULL) optionalgroup_ = new ::protobuf_unittest::TestAllTypesLite_OptionalGroup; - return optionalgroup_; -} -inline ::protobuf_unittest::TestAllTypesLite_OptionalGroup* TestAllTypesLite::release_optionalgroup() { - clear_has_optionalgroup(); - ::protobuf_unittest::TestAllTypesLite_OptionalGroup* temp = optionalgroup_; - optionalgroup_ = NULL; - return temp; -} - -// optional .protobuf_unittest.TestAllTypesLite.NestedMessage optional_nested_message = 18; -inline bool TestAllTypesLite::has_optional_nested_message() const { - return (_has_bits_[0] & 0x00010000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_nested_message() { - _has_bits_[0] |= 0x00010000u; -} -inline void TestAllTypesLite::clear_has_optional_nested_message() { - _has_bits_[0] &= ~0x00010000u; -} -inline void TestAllTypesLite::clear_optional_nested_message() { - if (optional_nested_message_ != NULL) optional_nested_message_->::protobuf_unittest::TestAllTypesLite_NestedMessage::Clear(); - clear_has_optional_nested_message(); -} -inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& TestAllTypesLite::optional_nested_message() const { - return optional_nested_message_ != NULL ? *optional_nested_message_ : *default_instance_->optional_nested_message_; -} -inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::mutable_optional_nested_message() { - set_has_optional_nested_message(); - if (optional_nested_message_ == NULL) optional_nested_message_ = new ::protobuf_unittest::TestAllTypesLite_NestedMessage; - return optional_nested_message_; -} -inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::release_optional_nested_message() { - clear_has_optional_nested_message(); - ::protobuf_unittest::TestAllTypesLite_NestedMessage* temp = optional_nested_message_; - optional_nested_message_ = NULL; - return temp; -} - -// optional .protobuf_unittest.ForeignMessageLite optional_foreign_message = 19; -inline bool TestAllTypesLite::has_optional_foreign_message() const { - return (_has_bits_[0] & 0x00020000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_foreign_message() { - _has_bits_[0] |= 0x00020000u; -} -inline void TestAllTypesLite::clear_has_optional_foreign_message() { - _has_bits_[0] &= ~0x00020000u; -} -inline void TestAllTypesLite::clear_optional_foreign_message() { - if (optional_foreign_message_ != NULL) optional_foreign_message_->::protobuf_unittest::ForeignMessageLite::Clear(); - clear_has_optional_foreign_message(); -} -inline const ::protobuf_unittest::ForeignMessageLite& TestAllTypesLite::optional_foreign_message() const { - return optional_foreign_message_ != NULL ? *optional_foreign_message_ : *default_instance_->optional_foreign_message_; -} -inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::mutable_optional_foreign_message() { - set_has_optional_foreign_message(); - if (optional_foreign_message_ == NULL) optional_foreign_message_ = new ::protobuf_unittest::ForeignMessageLite; - return optional_foreign_message_; -} -inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::release_optional_foreign_message() { - clear_has_optional_foreign_message(); - ::protobuf_unittest::ForeignMessageLite* temp = optional_foreign_message_; - optional_foreign_message_ = NULL; - return temp; -} - -// optional .protobuf_unittest_import.ImportMessageLite optional_import_message = 20; -inline bool TestAllTypesLite::has_optional_import_message() const { - return (_has_bits_[0] & 0x00040000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_import_message() { - _has_bits_[0] |= 0x00040000u; -} -inline void TestAllTypesLite::clear_has_optional_import_message() { - _has_bits_[0] &= ~0x00040000u; -} -inline void TestAllTypesLite::clear_optional_import_message() { - if (optional_import_message_ != NULL) optional_import_message_->::protobuf_unittest_import::ImportMessageLite::Clear(); - clear_has_optional_import_message(); -} -inline const ::protobuf_unittest_import::ImportMessageLite& TestAllTypesLite::optional_import_message() const { - return optional_import_message_ != NULL ? *optional_import_message_ : *default_instance_->optional_import_message_; -} -inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::mutable_optional_import_message() { - set_has_optional_import_message(); - if (optional_import_message_ == NULL) optional_import_message_ = new ::protobuf_unittest_import::ImportMessageLite; - return optional_import_message_; -} -inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::release_optional_import_message() { - clear_has_optional_import_message(); - ::protobuf_unittest_import::ImportMessageLite* temp = optional_import_message_; - optional_import_message_ = NULL; - return temp; -} - -// optional .protobuf_unittest.TestAllTypesLite.NestedEnum optional_nested_enum = 21; -inline bool TestAllTypesLite::has_optional_nested_enum() const { - return (_has_bits_[0] & 0x00080000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_nested_enum() { - _has_bits_[0] |= 0x00080000u; -} -inline void TestAllTypesLite::clear_has_optional_nested_enum() { - _has_bits_[0] &= ~0x00080000u; -} -inline void TestAllTypesLite::clear_optional_nested_enum() { - optional_nested_enum_ = 1; - clear_has_optional_nested_enum(); -} -inline ::protobuf_unittest::TestAllTypesLite_NestedEnum TestAllTypesLite::optional_nested_enum() const { - return static_cast< ::protobuf_unittest::TestAllTypesLite_NestedEnum >(optional_nested_enum_); -} -inline void TestAllTypesLite::set_optional_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); - set_has_optional_nested_enum(); - optional_nested_enum_ = value; -} - -// optional .protobuf_unittest.ForeignEnumLite optional_foreign_enum = 22; -inline bool TestAllTypesLite::has_optional_foreign_enum() const { - return (_has_bits_[0] & 0x00100000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_foreign_enum() { - _has_bits_[0] |= 0x00100000u; -} -inline void TestAllTypesLite::clear_has_optional_foreign_enum() { - _has_bits_[0] &= ~0x00100000u; -} -inline void TestAllTypesLite::clear_optional_foreign_enum() { - optional_foreign_enum_ = 4; - clear_has_optional_foreign_enum(); -} -inline protobuf_unittest::ForeignEnumLite TestAllTypesLite::optional_foreign_enum() const { - return static_cast< protobuf_unittest::ForeignEnumLite >(optional_foreign_enum_); -} -inline void TestAllTypesLite::set_optional_foreign_enum(protobuf_unittest::ForeignEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); - set_has_optional_foreign_enum(); - optional_foreign_enum_ = value; -} - -// optional .protobuf_unittest_import.ImportEnumLite optional_import_enum = 23; -inline bool TestAllTypesLite::has_optional_import_enum() const { - return (_has_bits_[0] & 0x00200000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_import_enum() { - _has_bits_[0] |= 0x00200000u; -} -inline void TestAllTypesLite::clear_has_optional_import_enum() { - _has_bits_[0] &= ~0x00200000u; -} -inline void TestAllTypesLite::clear_optional_import_enum() { - optional_import_enum_ = 7; - clear_has_optional_import_enum(); -} -inline protobuf_unittest_import::ImportEnumLite TestAllTypesLite::optional_import_enum() const { - return static_cast< protobuf_unittest_import::ImportEnumLite >(optional_import_enum_); -} -inline void TestAllTypesLite::set_optional_import_enum(protobuf_unittest_import::ImportEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); - set_has_optional_import_enum(); - optional_import_enum_ = value; -} - -// optional string optional_string_piece = 24 [ctype = STRING_PIECE]; -inline bool TestAllTypesLite::has_optional_string_piece() const { - return (_has_bits_[0] & 0x00400000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_string_piece() { - _has_bits_[0] |= 0x00400000u; -} -inline void TestAllTypesLite::clear_has_optional_string_piece() { - _has_bits_[0] &= ~0x00400000u; -} -inline void TestAllTypesLite::clear_optional_string_piece() { - if (optional_string_piece_ != &::google::protobuf::internal::kEmptyString) { - optional_string_piece_->clear(); - } - clear_has_optional_string_piece(); -} -inline const ::std::string& TestAllTypesLite::optional_string_piece() const { - return *optional_string_piece_; -} -inline void TestAllTypesLite::set_optional_string_piece(const ::std::string& value) { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - optional_string_piece_->assign(value); -} -inline void TestAllTypesLite::set_optional_string_piece(const char* value) { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - optional_string_piece_->assign(value); -} -inline void TestAllTypesLite::set_optional_string_piece(const char* value, size_t size) { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - optional_string_piece_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_optional_string_piece() { - set_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - optional_string_piece_ = new ::std::string; - } - return optional_string_piece_; -} -inline ::std::string* TestAllTypesLite::release_optional_string_piece() { - clear_has_optional_string_piece(); - if (optional_string_piece_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_string_piece_; - optional_string_piece_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// optional string optional_cord = 25 [ctype = CORD]; -inline bool TestAllTypesLite::has_optional_cord() const { - return (_has_bits_[0] & 0x00800000u) != 0; -} -inline void TestAllTypesLite::set_has_optional_cord() { - _has_bits_[0] |= 0x00800000u; -} -inline void TestAllTypesLite::clear_has_optional_cord() { - _has_bits_[0] &= ~0x00800000u; -} -inline void TestAllTypesLite::clear_optional_cord() { - if (optional_cord_ != &::google::protobuf::internal::kEmptyString) { - optional_cord_->clear(); - } - clear_has_optional_cord(); -} -inline const ::std::string& TestAllTypesLite::optional_cord() const { - return *optional_cord_; -} -inline void TestAllTypesLite::set_optional_cord(const ::std::string& value) { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - optional_cord_->assign(value); -} -inline void TestAllTypesLite::set_optional_cord(const char* value) { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - optional_cord_->assign(value); -} -inline void TestAllTypesLite::set_optional_cord(const char* value, size_t size) { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - optional_cord_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_optional_cord() { - set_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - optional_cord_ = new ::std::string; - } - return optional_cord_; -} -inline ::std::string* TestAllTypesLite::release_optional_cord() { - clear_has_optional_cord(); - if (optional_cord_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = optional_cord_; - optional_cord_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// repeated int32 repeated_int32 = 31; -inline int TestAllTypesLite::repeated_int32_size() const { - return repeated_int32_.size(); -} -inline void TestAllTypesLite::clear_repeated_int32() { - repeated_int32_.Clear(); -} -inline ::google::protobuf::int32 TestAllTypesLite::repeated_int32(int index) const { - return repeated_int32_.Get(index); -} -inline void TestAllTypesLite::set_repeated_int32(int index, ::google::protobuf::int32 value) { - repeated_int32_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_int32(::google::protobuf::int32 value) { - repeated_int32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestAllTypesLite::repeated_int32() const { - return repeated_int32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestAllTypesLite::mutable_repeated_int32() { - return &repeated_int32_; -} - -// repeated int64 repeated_int64 = 32; -inline int TestAllTypesLite::repeated_int64_size() const { - return repeated_int64_.size(); -} -inline void TestAllTypesLite::clear_repeated_int64() { - repeated_int64_.Clear(); -} -inline ::google::protobuf::int64 TestAllTypesLite::repeated_int64(int index) const { - return repeated_int64_.Get(index); -} -inline void TestAllTypesLite::set_repeated_int64(int index, ::google::protobuf::int64 value) { - repeated_int64_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_int64(::google::protobuf::int64 value) { - repeated_int64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestAllTypesLite::repeated_int64() const { - return repeated_int64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestAllTypesLite::mutable_repeated_int64() { - return &repeated_int64_; -} - -// repeated uint32 repeated_uint32 = 33; -inline int TestAllTypesLite::repeated_uint32_size() const { - return repeated_uint32_.size(); -} -inline void TestAllTypesLite::clear_repeated_uint32() { - repeated_uint32_.Clear(); -} -inline ::google::protobuf::uint32 TestAllTypesLite::repeated_uint32(int index) const { - return repeated_uint32_.Get(index); -} -inline void TestAllTypesLite::set_repeated_uint32(int index, ::google::protobuf::uint32 value) { - repeated_uint32_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_uint32(::google::protobuf::uint32 value) { - repeated_uint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestAllTypesLite::repeated_uint32() const { - return repeated_uint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestAllTypesLite::mutable_repeated_uint32() { - return &repeated_uint32_; -} - -// repeated uint64 repeated_uint64 = 34; -inline int TestAllTypesLite::repeated_uint64_size() const { - return repeated_uint64_.size(); -} -inline void TestAllTypesLite::clear_repeated_uint64() { - repeated_uint64_.Clear(); -} -inline ::google::protobuf::uint64 TestAllTypesLite::repeated_uint64(int index) const { - return repeated_uint64_.Get(index); -} -inline void TestAllTypesLite::set_repeated_uint64(int index, ::google::protobuf::uint64 value) { - repeated_uint64_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_uint64(::google::protobuf::uint64 value) { - repeated_uint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestAllTypesLite::repeated_uint64() const { - return repeated_uint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestAllTypesLite::mutable_repeated_uint64() { - return &repeated_uint64_; -} - -// repeated sint32 repeated_sint32 = 35; -inline int TestAllTypesLite::repeated_sint32_size() const { - return repeated_sint32_.size(); -} -inline void TestAllTypesLite::clear_repeated_sint32() { - repeated_sint32_.Clear(); -} -inline ::google::protobuf::int32 TestAllTypesLite::repeated_sint32(int index) const { - return repeated_sint32_.Get(index); -} -inline void TestAllTypesLite::set_repeated_sint32(int index, ::google::protobuf::int32 value) { - repeated_sint32_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_sint32(::google::protobuf::int32 value) { - repeated_sint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestAllTypesLite::repeated_sint32() const { - return repeated_sint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestAllTypesLite::mutable_repeated_sint32() { - return &repeated_sint32_; -} - -// repeated sint64 repeated_sint64 = 36; -inline int TestAllTypesLite::repeated_sint64_size() const { - return repeated_sint64_.size(); -} -inline void TestAllTypesLite::clear_repeated_sint64() { - repeated_sint64_.Clear(); -} -inline ::google::protobuf::int64 TestAllTypesLite::repeated_sint64(int index) const { - return repeated_sint64_.Get(index); -} -inline void TestAllTypesLite::set_repeated_sint64(int index, ::google::protobuf::int64 value) { - repeated_sint64_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_sint64(::google::protobuf::int64 value) { - repeated_sint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestAllTypesLite::repeated_sint64() const { - return repeated_sint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestAllTypesLite::mutable_repeated_sint64() { - return &repeated_sint64_; -} - -// repeated fixed32 repeated_fixed32 = 37; -inline int TestAllTypesLite::repeated_fixed32_size() const { - return repeated_fixed32_.size(); -} -inline void TestAllTypesLite::clear_repeated_fixed32() { - repeated_fixed32_.Clear(); -} -inline ::google::protobuf::uint32 TestAllTypesLite::repeated_fixed32(int index) const { - return repeated_fixed32_.Get(index); -} -inline void TestAllTypesLite::set_repeated_fixed32(int index, ::google::protobuf::uint32 value) { - repeated_fixed32_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_fixed32(::google::protobuf::uint32 value) { - repeated_fixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestAllTypesLite::repeated_fixed32() const { - return repeated_fixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestAllTypesLite::mutable_repeated_fixed32() { - return &repeated_fixed32_; -} - -// repeated fixed64 repeated_fixed64 = 38; -inline int TestAllTypesLite::repeated_fixed64_size() const { - return repeated_fixed64_.size(); -} -inline void TestAllTypesLite::clear_repeated_fixed64() { - repeated_fixed64_.Clear(); -} -inline ::google::protobuf::uint64 TestAllTypesLite::repeated_fixed64(int index) const { - return repeated_fixed64_.Get(index); -} -inline void TestAllTypesLite::set_repeated_fixed64(int index, ::google::protobuf::uint64 value) { - repeated_fixed64_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_fixed64(::google::protobuf::uint64 value) { - repeated_fixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestAllTypesLite::repeated_fixed64() const { - return repeated_fixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestAllTypesLite::mutable_repeated_fixed64() { - return &repeated_fixed64_; -} - -// repeated sfixed32 repeated_sfixed32 = 39; -inline int TestAllTypesLite::repeated_sfixed32_size() const { - return repeated_sfixed32_.size(); -} -inline void TestAllTypesLite::clear_repeated_sfixed32() { - repeated_sfixed32_.Clear(); -} -inline ::google::protobuf::int32 TestAllTypesLite::repeated_sfixed32(int index) const { - return repeated_sfixed32_.Get(index); -} -inline void TestAllTypesLite::set_repeated_sfixed32(int index, ::google::protobuf::int32 value) { - repeated_sfixed32_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_sfixed32(::google::protobuf::int32 value) { - repeated_sfixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestAllTypesLite::repeated_sfixed32() const { - return repeated_sfixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestAllTypesLite::mutable_repeated_sfixed32() { - return &repeated_sfixed32_; -} - -// repeated sfixed64 repeated_sfixed64 = 40; -inline int TestAllTypesLite::repeated_sfixed64_size() const { - return repeated_sfixed64_.size(); -} -inline void TestAllTypesLite::clear_repeated_sfixed64() { - repeated_sfixed64_.Clear(); -} -inline ::google::protobuf::int64 TestAllTypesLite::repeated_sfixed64(int index) const { - return repeated_sfixed64_.Get(index); -} -inline void TestAllTypesLite::set_repeated_sfixed64(int index, ::google::protobuf::int64 value) { - repeated_sfixed64_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_sfixed64(::google::protobuf::int64 value) { - repeated_sfixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestAllTypesLite::repeated_sfixed64() const { - return repeated_sfixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestAllTypesLite::mutable_repeated_sfixed64() { - return &repeated_sfixed64_; -} - -// repeated float repeated_float = 41; -inline int TestAllTypesLite::repeated_float_size() const { - return repeated_float_.size(); -} -inline void TestAllTypesLite::clear_repeated_float() { - repeated_float_.Clear(); -} -inline float TestAllTypesLite::repeated_float(int index) const { - return repeated_float_.Get(index); -} -inline void TestAllTypesLite::set_repeated_float(int index, float value) { - repeated_float_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_float(float value) { - repeated_float_.Add(value); -} -inline const ::google::protobuf::RepeatedField< float >& -TestAllTypesLite::repeated_float() const { - return repeated_float_; -} -inline ::google::protobuf::RepeatedField< float >* -TestAllTypesLite::mutable_repeated_float() { - return &repeated_float_; -} - -// repeated double repeated_double = 42; -inline int TestAllTypesLite::repeated_double_size() const { - return repeated_double_.size(); -} -inline void TestAllTypesLite::clear_repeated_double() { - repeated_double_.Clear(); -} -inline double TestAllTypesLite::repeated_double(int index) const { - return repeated_double_.Get(index); -} -inline void TestAllTypesLite::set_repeated_double(int index, double value) { - repeated_double_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_double(double value) { - repeated_double_.Add(value); -} -inline const ::google::protobuf::RepeatedField< double >& -TestAllTypesLite::repeated_double() const { - return repeated_double_; -} -inline ::google::protobuf::RepeatedField< double >* -TestAllTypesLite::mutable_repeated_double() { - return &repeated_double_; -} - -// repeated bool repeated_bool = 43; -inline int TestAllTypesLite::repeated_bool_size() const { - return repeated_bool_.size(); -} -inline void TestAllTypesLite::clear_repeated_bool() { - repeated_bool_.Clear(); -} -inline bool TestAllTypesLite::repeated_bool(int index) const { - return repeated_bool_.Get(index); -} -inline void TestAllTypesLite::set_repeated_bool(int index, bool value) { - repeated_bool_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_bool(bool value) { - repeated_bool_.Add(value); -} -inline const ::google::protobuf::RepeatedField< bool >& -TestAllTypesLite::repeated_bool() const { - return repeated_bool_; -} -inline ::google::protobuf::RepeatedField< bool >* -TestAllTypesLite::mutable_repeated_bool() { - return &repeated_bool_; -} - -// repeated string repeated_string = 44; -inline int TestAllTypesLite::repeated_string_size() const { - return repeated_string_.size(); -} -inline void TestAllTypesLite::clear_repeated_string() { - repeated_string_.Clear(); -} -inline const ::std::string& TestAllTypesLite::repeated_string(int index) const { - return repeated_string_.Get(index); -} -inline ::std::string* TestAllTypesLite::mutable_repeated_string(int index) { - return repeated_string_.Mutable(index); -} -inline void TestAllTypesLite::set_repeated_string(int index, const ::std::string& value) { - repeated_string_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_string(int index, const char* value) { - repeated_string_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_string(int index, const char* value, size_t size) { - repeated_string_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::add_repeated_string() { - return repeated_string_.Add(); -} -inline void TestAllTypesLite::add_repeated_string(const ::std::string& value) { - repeated_string_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_string(const char* value) { - repeated_string_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_string(const char* value, size_t size) { - repeated_string_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypesLite::repeated_string() const { - return repeated_string_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypesLite::mutable_repeated_string() { - return &repeated_string_; -} - -// repeated bytes repeated_bytes = 45; -inline int TestAllTypesLite::repeated_bytes_size() const { - return repeated_bytes_.size(); -} -inline void TestAllTypesLite::clear_repeated_bytes() { - repeated_bytes_.Clear(); -} -inline const ::std::string& TestAllTypesLite::repeated_bytes(int index) const { - return repeated_bytes_.Get(index); -} -inline ::std::string* TestAllTypesLite::mutable_repeated_bytes(int index) { - return repeated_bytes_.Mutable(index); -} -inline void TestAllTypesLite::set_repeated_bytes(int index, const ::std::string& value) { - repeated_bytes_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_bytes(int index, const char* value) { - repeated_bytes_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_bytes(int index, const void* value, size_t size) { - repeated_bytes_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::add_repeated_bytes() { - return repeated_bytes_.Add(); -} -inline void TestAllTypesLite::add_repeated_bytes(const ::std::string& value) { - repeated_bytes_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_bytes(const char* value) { - repeated_bytes_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_bytes(const void* value, size_t size) { - repeated_bytes_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypesLite::repeated_bytes() const { - return repeated_bytes_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypesLite::mutable_repeated_bytes() { - return &repeated_bytes_; -} - -// repeated group RepeatedGroup = 46 { -inline int TestAllTypesLite::repeatedgroup_size() const { - return repeatedgroup_.size(); -} -inline void TestAllTypesLite::clear_repeatedgroup() { - repeatedgroup_.Clear(); -} -inline const ::protobuf_unittest::TestAllTypesLite_RepeatedGroup& TestAllTypesLite::repeatedgroup(int index) const { - return repeatedgroup_.Get(index); -} -inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* TestAllTypesLite::mutable_repeatedgroup(int index) { - return repeatedgroup_.Mutable(index); -} -inline ::protobuf_unittest::TestAllTypesLite_RepeatedGroup* TestAllTypesLite::add_repeatedgroup() { - return repeatedgroup_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >& -TestAllTypesLite::repeatedgroup() const { - return repeatedgroup_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_RepeatedGroup >* -TestAllTypesLite::mutable_repeatedgroup() { - return &repeatedgroup_; -} - -// repeated .protobuf_unittest.TestAllTypesLite.NestedMessage repeated_nested_message = 48; -inline int TestAllTypesLite::repeated_nested_message_size() const { - return repeated_nested_message_.size(); -} -inline void TestAllTypesLite::clear_repeated_nested_message() { - repeated_nested_message_.Clear(); -} -inline const ::protobuf_unittest::TestAllTypesLite_NestedMessage& TestAllTypesLite::repeated_nested_message(int index) const { - return repeated_nested_message_.Get(index); -} -inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::mutable_repeated_nested_message(int index) { - return repeated_nested_message_.Mutable(index); -} -inline ::protobuf_unittest::TestAllTypesLite_NestedMessage* TestAllTypesLite::add_repeated_nested_message() { - return repeated_nested_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >& -TestAllTypesLite::repeated_nested_message() const { - return repeated_nested_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::TestAllTypesLite_NestedMessage >* -TestAllTypesLite::mutable_repeated_nested_message() { - return &repeated_nested_message_; -} - -// repeated .protobuf_unittest.ForeignMessageLite repeated_foreign_message = 49; -inline int TestAllTypesLite::repeated_foreign_message_size() const { - return repeated_foreign_message_.size(); -} -inline void TestAllTypesLite::clear_repeated_foreign_message() { - repeated_foreign_message_.Clear(); -} -inline const ::protobuf_unittest::ForeignMessageLite& TestAllTypesLite::repeated_foreign_message(int index) const { - return repeated_foreign_message_.Get(index); -} -inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::mutable_repeated_foreign_message(int index) { - return repeated_foreign_message_.Mutable(index); -} -inline ::protobuf_unittest::ForeignMessageLite* TestAllTypesLite::add_repeated_foreign_message() { - return repeated_foreign_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >& -TestAllTypesLite::repeated_foreign_message() const { - return repeated_foreign_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::ForeignMessageLite >* -TestAllTypesLite::mutable_repeated_foreign_message() { - return &repeated_foreign_message_; -} - -// repeated .protobuf_unittest_import.ImportMessageLite repeated_import_message = 50; -inline int TestAllTypesLite::repeated_import_message_size() const { - return repeated_import_message_.size(); -} -inline void TestAllTypesLite::clear_repeated_import_message() { - repeated_import_message_.Clear(); -} -inline const ::protobuf_unittest_import::ImportMessageLite& TestAllTypesLite::repeated_import_message(int index) const { - return repeated_import_message_.Get(index); -} -inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::mutable_repeated_import_message(int index) { - return repeated_import_message_.Mutable(index); -} -inline ::protobuf_unittest_import::ImportMessageLite* TestAllTypesLite::add_repeated_import_message() { - return repeated_import_message_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >& -TestAllTypesLite::repeated_import_message() const { - return repeated_import_message_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest_import::ImportMessageLite >* -TestAllTypesLite::mutable_repeated_import_message() { - return &repeated_import_message_; -} - -// repeated .protobuf_unittest.TestAllTypesLite.NestedEnum repeated_nested_enum = 51; -inline int TestAllTypesLite::repeated_nested_enum_size() const { - return repeated_nested_enum_.size(); -} -inline void TestAllTypesLite::clear_repeated_nested_enum() { - repeated_nested_enum_.Clear(); -} -inline ::protobuf_unittest::TestAllTypesLite_NestedEnum TestAllTypesLite::repeated_nested_enum(int index) const { - return static_cast< ::protobuf_unittest::TestAllTypesLite_NestedEnum >(repeated_nested_enum_.Get(index)); -} -inline void TestAllTypesLite::set_repeated_nested_enum(int index, ::protobuf_unittest::TestAllTypesLite_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); - repeated_nested_enum_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); - repeated_nested_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestAllTypesLite::repeated_nested_enum() const { - return repeated_nested_enum_; -} -inline ::google::protobuf::RepeatedField* -TestAllTypesLite::mutable_repeated_nested_enum() { - return &repeated_nested_enum_; -} - -// repeated .protobuf_unittest.ForeignEnumLite repeated_foreign_enum = 52; -inline int TestAllTypesLite::repeated_foreign_enum_size() const { - return repeated_foreign_enum_.size(); -} -inline void TestAllTypesLite::clear_repeated_foreign_enum() { - repeated_foreign_enum_.Clear(); -} -inline protobuf_unittest::ForeignEnumLite TestAllTypesLite::repeated_foreign_enum(int index) const { - return static_cast< protobuf_unittest::ForeignEnumLite >(repeated_foreign_enum_.Get(index)); -} -inline void TestAllTypesLite::set_repeated_foreign_enum(int index, protobuf_unittest::ForeignEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); - repeated_foreign_enum_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_foreign_enum(protobuf_unittest::ForeignEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); - repeated_foreign_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestAllTypesLite::repeated_foreign_enum() const { - return repeated_foreign_enum_; -} -inline ::google::protobuf::RepeatedField* -TestAllTypesLite::mutable_repeated_foreign_enum() { - return &repeated_foreign_enum_; -} - -// repeated .protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53; -inline int TestAllTypesLite::repeated_import_enum_size() const { - return repeated_import_enum_.size(); -} -inline void TestAllTypesLite::clear_repeated_import_enum() { - repeated_import_enum_.Clear(); -} -inline protobuf_unittest_import::ImportEnumLite TestAllTypesLite::repeated_import_enum(int index) const { - return static_cast< protobuf_unittest_import::ImportEnumLite >(repeated_import_enum_.Get(index)); -} -inline void TestAllTypesLite::set_repeated_import_enum(int index, protobuf_unittest_import::ImportEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); - repeated_import_enum_.Set(index, value); -} -inline void TestAllTypesLite::add_repeated_import_enum(protobuf_unittest_import::ImportEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); - repeated_import_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestAllTypesLite::repeated_import_enum() const { - return repeated_import_enum_; -} -inline ::google::protobuf::RepeatedField* -TestAllTypesLite::mutable_repeated_import_enum() { - return &repeated_import_enum_; -} - -// repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; -inline int TestAllTypesLite::repeated_string_piece_size() const { - return repeated_string_piece_.size(); -} -inline void TestAllTypesLite::clear_repeated_string_piece() { - repeated_string_piece_.Clear(); -} -inline const ::std::string& TestAllTypesLite::repeated_string_piece(int index) const { - return repeated_string_piece_.Get(index); -} -inline ::std::string* TestAllTypesLite::mutable_repeated_string_piece(int index) { - return repeated_string_piece_.Mutable(index); -} -inline void TestAllTypesLite::set_repeated_string_piece(int index, const ::std::string& value) { - repeated_string_piece_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_string_piece(int index, const char* value) { - repeated_string_piece_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_string_piece(int index, const char* value, size_t size) { - repeated_string_piece_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::add_repeated_string_piece() { - return repeated_string_piece_.Add(); -} -inline void TestAllTypesLite::add_repeated_string_piece(const ::std::string& value) { - repeated_string_piece_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_string_piece(const char* value) { - repeated_string_piece_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_string_piece(const char* value, size_t size) { - repeated_string_piece_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypesLite::repeated_string_piece() const { - return repeated_string_piece_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypesLite::mutable_repeated_string_piece() { - return &repeated_string_piece_; -} - -// repeated string repeated_cord = 55 [ctype = CORD]; -inline int TestAllTypesLite::repeated_cord_size() const { - return repeated_cord_.size(); -} -inline void TestAllTypesLite::clear_repeated_cord() { - repeated_cord_.Clear(); -} -inline const ::std::string& TestAllTypesLite::repeated_cord(int index) const { - return repeated_cord_.Get(index); -} -inline ::std::string* TestAllTypesLite::mutable_repeated_cord(int index) { - return repeated_cord_.Mutable(index); -} -inline void TestAllTypesLite::set_repeated_cord(int index, const ::std::string& value) { - repeated_cord_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_cord(int index, const char* value) { - repeated_cord_.Mutable(index)->assign(value); -} -inline void TestAllTypesLite::set_repeated_cord(int index, const char* value, size_t size) { - repeated_cord_.Mutable(index)->assign( - reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::add_repeated_cord() { - return repeated_cord_.Add(); -} -inline void TestAllTypesLite::add_repeated_cord(const ::std::string& value) { - repeated_cord_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_cord(const char* value) { - repeated_cord_.Add()->assign(value); -} -inline void TestAllTypesLite::add_repeated_cord(const char* value, size_t size) { - repeated_cord_.Add()->assign(reinterpret_cast(value), size); -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TestAllTypesLite::repeated_cord() const { - return repeated_cord_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TestAllTypesLite::mutable_repeated_cord() { - return &repeated_cord_; -} - -// optional int32 default_int32 = 61 [default = 41]; -inline bool TestAllTypesLite::has_default_int32() const { - return (_has_bits_[1] & 0x00010000u) != 0; -} -inline void TestAllTypesLite::set_has_default_int32() { - _has_bits_[1] |= 0x00010000u; -} -inline void TestAllTypesLite::clear_has_default_int32() { - _has_bits_[1] &= ~0x00010000u; -} -inline void TestAllTypesLite::clear_default_int32() { - default_int32_ = 41; - clear_has_default_int32(); -} -inline ::google::protobuf::int32 TestAllTypesLite::default_int32() const { - return default_int32_; -} -inline void TestAllTypesLite::set_default_int32(::google::protobuf::int32 value) { - set_has_default_int32(); - default_int32_ = value; -} - -// optional int64 default_int64 = 62 [default = 42]; -inline bool TestAllTypesLite::has_default_int64() const { - return (_has_bits_[1] & 0x00020000u) != 0; -} -inline void TestAllTypesLite::set_has_default_int64() { - _has_bits_[1] |= 0x00020000u; -} -inline void TestAllTypesLite::clear_has_default_int64() { - _has_bits_[1] &= ~0x00020000u; -} -inline void TestAllTypesLite::clear_default_int64() { - default_int64_ = GOOGLE_LONGLONG(42); - clear_has_default_int64(); -} -inline ::google::protobuf::int64 TestAllTypesLite::default_int64() const { - return default_int64_; -} -inline void TestAllTypesLite::set_default_int64(::google::protobuf::int64 value) { - set_has_default_int64(); - default_int64_ = value; -} - -// optional uint32 default_uint32 = 63 [default = 43]; -inline bool TestAllTypesLite::has_default_uint32() const { - return (_has_bits_[1] & 0x00040000u) != 0; -} -inline void TestAllTypesLite::set_has_default_uint32() { - _has_bits_[1] |= 0x00040000u; -} -inline void TestAllTypesLite::clear_has_default_uint32() { - _has_bits_[1] &= ~0x00040000u; -} -inline void TestAllTypesLite::clear_default_uint32() { - default_uint32_ = 43u; - clear_has_default_uint32(); -} -inline ::google::protobuf::uint32 TestAllTypesLite::default_uint32() const { - return default_uint32_; -} -inline void TestAllTypesLite::set_default_uint32(::google::protobuf::uint32 value) { - set_has_default_uint32(); - default_uint32_ = value; -} - -// optional uint64 default_uint64 = 64 [default = 44]; -inline bool TestAllTypesLite::has_default_uint64() const { - return (_has_bits_[1] & 0x00080000u) != 0; -} -inline void TestAllTypesLite::set_has_default_uint64() { - _has_bits_[1] |= 0x00080000u; -} -inline void TestAllTypesLite::clear_has_default_uint64() { - _has_bits_[1] &= ~0x00080000u; -} -inline void TestAllTypesLite::clear_default_uint64() { - default_uint64_ = GOOGLE_ULONGLONG(44); - clear_has_default_uint64(); -} -inline ::google::protobuf::uint64 TestAllTypesLite::default_uint64() const { - return default_uint64_; -} -inline void TestAllTypesLite::set_default_uint64(::google::protobuf::uint64 value) { - set_has_default_uint64(); - default_uint64_ = value; -} - -// optional sint32 default_sint32 = 65 [default = -45]; -inline bool TestAllTypesLite::has_default_sint32() const { - return (_has_bits_[1] & 0x00100000u) != 0; -} -inline void TestAllTypesLite::set_has_default_sint32() { - _has_bits_[1] |= 0x00100000u; -} -inline void TestAllTypesLite::clear_has_default_sint32() { - _has_bits_[1] &= ~0x00100000u; -} -inline void TestAllTypesLite::clear_default_sint32() { - default_sint32_ = -45; - clear_has_default_sint32(); -} -inline ::google::protobuf::int32 TestAllTypesLite::default_sint32() const { - return default_sint32_; -} -inline void TestAllTypesLite::set_default_sint32(::google::protobuf::int32 value) { - set_has_default_sint32(); - default_sint32_ = value; -} - -// optional sint64 default_sint64 = 66 [default = 46]; -inline bool TestAllTypesLite::has_default_sint64() const { - return (_has_bits_[1] & 0x00200000u) != 0; -} -inline void TestAllTypesLite::set_has_default_sint64() { - _has_bits_[1] |= 0x00200000u; -} -inline void TestAllTypesLite::clear_has_default_sint64() { - _has_bits_[1] &= ~0x00200000u; -} -inline void TestAllTypesLite::clear_default_sint64() { - default_sint64_ = GOOGLE_LONGLONG(46); - clear_has_default_sint64(); -} -inline ::google::protobuf::int64 TestAllTypesLite::default_sint64() const { - return default_sint64_; -} -inline void TestAllTypesLite::set_default_sint64(::google::protobuf::int64 value) { - set_has_default_sint64(); - default_sint64_ = value; -} - -// optional fixed32 default_fixed32 = 67 [default = 47]; -inline bool TestAllTypesLite::has_default_fixed32() const { - return (_has_bits_[1] & 0x00400000u) != 0; -} -inline void TestAllTypesLite::set_has_default_fixed32() { - _has_bits_[1] |= 0x00400000u; -} -inline void TestAllTypesLite::clear_has_default_fixed32() { - _has_bits_[1] &= ~0x00400000u; -} -inline void TestAllTypesLite::clear_default_fixed32() { - default_fixed32_ = 47u; - clear_has_default_fixed32(); -} -inline ::google::protobuf::uint32 TestAllTypesLite::default_fixed32() const { - return default_fixed32_; -} -inline void TestAllTypesLite::set_default_fixed32(::google::protobuf::uint32 value) { - set_has_default_fixed32(); - default_fixed32_ = value; -} - -// optional fixed64 default_fixed64 = 68 [default = 48]; -inline bool TestAllTypesLite::has_default_fixed64() const { - return (_has_bits_[1] & 0x00800000u) != 0; -} -inline void TestAllTypesLite::set_has_default_fixed64() { - _has_bits_[1] |= 0x00800000u; -} -inline void TestAllTypesLite::clear_has_default_fixed64() { - _has_bits_[1] &= ~0x00800000u; -} -inline void TestAllTypesLite::clear_default_fixed64() { - default_fixed64_ = GOOGLE_ULONGLONG(48); - clear_has_default_fixed64(); -} -inline ::google::protobuf::uint64 TestAllTypesLite::default_fixed64() const { - return default_fixed64_; -} -inline void TestAllTypesLite::set_default_fixed64(::google::protobuf::uint64 value) { - set_has_default_fixed64(); - default_fixed64_ = value; -} - -// optional sfixed32 default_sfixed32 = 69 [default = 49]; -inline bool TestAllTypesLite::has_default_sfixed32() const { - return (_has_bits_[1] & 0x01000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_sfixed32() { - _has_bits_[1] |= 0x01000000u; -} -inline void TestAllTypesLite::clear_has_default_sfixed32() { - _has_bits_[1] &= ~0x01000000u; -} -inline void TestAllTypesLite::clear_default_sfixed32() { - default_sfixed32_ = 49; - clear_has_default_sfixed32(); -} -inline ::google::protobuf::int32 TestAllTypesLite::default_sfixed32() const { - return default_sfixed32_; -} -inline void TestAllTypesLite::set_default_sfixed32(::google::protobuf::int32 value) { - set_has_default_sfixed32(); - default_sfixed32_ = value; -} - -// optional sfixed64 default_sfixed64 = 70 [default = -50]; -inline bool TestAllTypesLite::has_default_sfixed64() const { - return (_has_bits_[1] & 0x02000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_sfixed64() { - _has_bits_[1] |= 0x02000000u; -} -inline void TestAllTypesLite::clear_has_default_sfixed64() { - _has_bits_[1] &= ~0x02000000u; -} -inline void TestAllTypesLite::clear_default_sfixed64() { - default_sfixed64_ = GOOGLE_LONGLONG(-50); - clear_has_default_sfixed64(); -} -inline ::google::protobuf::int64 TestAllTypesLite::default_sfixed64() const { - return default_sfixed64_; -} -inline void TestAllTypesLite::set_default_sfixed64(::google::protobuf::int64 value) { - set_has_default_sfixed64(); - default_sfixed64_ = value; -} - -// optional float default_float = 71 [default = 51.5]; -inline bool TestAllTypesLite::has_default_float() const { - return (_has_bits_[1] & 0x04000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_float() { - _has_bits_[1] |= 0x04000000u; -} -inline void TestAllTypesLite::clear_has_default_float() { - _has_bits_[1] &= ~0x04000000u; -} -inline void TestAllTypesLite::clear_default_float() { - default_float_ = 51.5f; - clear_has_default_float(); -} -inline float TestAllTypesLite::default_float() const { - return default_float_; -} -inline void TestAllTypesLite::set_default_float(float value) { - set_has_default_float(); - default_float_ = value; -} - -// optional double default_double = 72 [default = 52000]; -inline bool TestAllTypesLite::has_default_double() const { - return (_has_bits_[1] & 0x08000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_double() { - _has_bits_[1] |= 0x08000000u; -} -inline void TestAllTypesLite::clear_has_default_double() { - _has_bits_[1] &= ~0x08000000u; -} -inline void TestAllTypesLite::clear_default_double() { - default_double_ = 52000; - clear_has_default_double(); -} -inline double TestAllTypesLite::default_double() const { - return default_double_; -} -inline void TestAllTypesLite::set_default_double(double value) { - set_has_default_double(); - default_double_ = value; -} - -// optional bool default_bool = 73 [default = true]; -inline bool TestAllTypesLite::has_default_bool() const { - return (_has_bits_[1] & 0x10000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_bool() { - _has_bits_[1] |= 0x10000000u; -} -inline void TestAllTypesLite::clear_has_default_bool() { - _has_bits_[1] &= ~0x10000000u; -} -inline void TestAllTypesLite::clear_default_bool() { - default_bool_ = true; - clear_has_default_bool(); -} -inline bool TestAllTypesLite::default_bool() const { - return default_bool_; -} -inline void TestAllTypesLite::set_default_bool(bool value) { - set_has_default_bool(); - default_bool_ = value; -} - -// optional string default_string = 74 [default = "hello"]; -inline bool TestAllTypesLite::has_default_string() const { - return (_has_bits_[1] & 0x20000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_string() { - _has_bits_[1] |= 0x20000000u; -} -inline void TestAllTypesLite::clear_has_default_string() { - _has_bits_[1] &= ~0x20000000u; -} -inline void TestAllTypesLite::clear_default_string() { - if (default_string_ != &_default_default_string_) { - default_string_->assign(_default_default_string_); - } - clear_has_default_string(); -} -inline const ::std::string& TestAllTypesLite::default_string() const { - return *default_string_; -} -inline void TestAllTypesLite::set_default_string(const ::std::string& value) { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string; - } - default_string_->assign(value); -} -inline void TestAllTypesLite::set_default_string(const char* value) { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string; - } - default_string_->assign(value); -} -inline void TestAllTypesLite::set_default_string(const char* value, size_t size) { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string; - } - default_string_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_default_string() { - set_has_default_string(); - if (default_string_ == &_default_default_string_) { - default_string_ = new ::std::string(_default_default_string_); - } - return default_string_; -} -inline ::std::string* TestAllTypesLite::release_default_string() { - clear_has_default_string(); - if (default_string_ == &_default_default_string_) { - return NULL; - } else { - ::std::string* temp = default_string_; - default_string_ = const_cast< ::std::string*>(&_default_default_string_); - return temp; - } -} - -// optional bytes default_bytes = 75 [default = "world"]; -inline bool TestAllTypesLite::has_default_bytes() const { - return (_has_bits_[1] & 0x40000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_bytes() { - _has_bits_[1] |= 0x40000000u; -} -inline void TestAllTypesLite::clear_has_default_bytes() { - _has_bits_[1] &= ~0x40000000u; -} -inline void TestAllTypesLite::clear_default_bytes() { - if (default_bytes_ != &_default_default_bytes_) { - default_bytes_->assign(_default_default_bytes_); - } - clear_has_default_bytes(); -} -inline const ::std::string& TestAllTypesLite::default_bytes() const { - return *default_bytes_; -} -inline void TestAllTypesLite::set_default_bytes(const ::std::string& value) { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string; - } - default_bytes_->assign(value); -} -inline void TestAllTypesLite::set_default_bytes(const char* value) { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string; - } - default_bytes_->assign(value); -} -inline void TestAllTypesLite::set_default_bytes(const void* value, size_t size) { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string; - } - default_bytes_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_default_bytes() { - set_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - default_bytes_ = new ::std::string(_default_default_bytes_); - } - return default_bytes_; -} -inline ::std::string* TestAllTypesLite::release_default_bytes() { - clear_has_default_bytes(); - if (default_bytes_ == &_default_default_bytes_) { - return NULL; - } else { - ::std::string* temp = default_bytes_; - default_bytes_ = const_cast< ::std::string*>(&_default_default_bytes_); - return temp; - } -} - -// optional .protobuf_unittest.TestAllTypesLite.NestedEnum default_nested_enum = 81 [default = BAR]; -inline bool TestAllTypesLite::has_default_nested_enum() const { - return (_has_bits_[1] & 0x80000000u) != 0; -} -inline void TestAllTypesLite::set_has_default_nested_enum() { - _has_bits_[1] |= 0x80000000u; -} -inline void TestAllTypesLite::clear_has_default_nested_enum() { - _has_bits_[1] &= ~0x80000000u; -} -inline void TestAllTypesLite::clear_default_nested_enum() { - default_nested_enum_ = 2; - clear_has_default_nested_enum(); -} -inline ::protobuf_unittest::TestAllTypesLite_NestedEnum TestAllTypesLite::default_nested_enum() const { - return static_cast< ::protobuf_unittest::TestAllTypesLite_NestedEnum >(default_nested_enum_); -} -inline void TestAllTypesLite::set_default_nested_enum(::protobuf_unittest::TestAllTypesLite_NestedEnum value) { - GOOGLE_DCHECK(::protobuf_unittest::TestAllTypesLite_NestedEnum_IsValid(value)); - set_has_default_nested_enum(); - default_nested_enum_ = value; -} - -// optional .protobuf_unittest.ForeignEnumLite default_foreign_enum = 82 [default = FOREIGN_LITE_BAR]; -inline bool TestAllTypesLite::has_default_foreign_enum() const { - return (_has_bits_[2] & 0x00000001u) != 0; -} -inline void TestAllTypesLite::set_has_default_foreign_enum() { - _has_bits_[2] |= 0x00000001u; -} -inline void TestAllTypesLite::clear_has_default_foreign_enum() { - _has_bits_[2] &= ~0x00000001u; -} -inline void TestAllTypesLite::clear_default_foreign_enum() { - default_foreign_enum_ = 5; - clear_has_default_foreign_enum(); -} -inline protobuf_unittest::ForeignEnumLite TestAllTypesLite::default_foreign_enum() const { - return static_cast< protobuf_unittest::ForeignEnumLite >(default_foreign_enum_); -} -inline void TestAllTypesLite::set_default_foreign_enum(protobuf_unittest::ForeignEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); - set_has_default_foreign_enum(); - default_foreign_enum_ = value; -} - -// optional .protobuf_unittest_import.ImportEnumLite default_import_enum = 83 [default = IMPORT_LITE_BAR]; -inline bool TestAllTypesLite::has_default_import_enum() const { - return (_has_bits_[2] & 0x00000002u) != 0; -} -inline void TestAllTypesLite::set_has_default_import_enum() { - _has_bits_[2] |= 0x00000002u; -} -inline void TestAllTypesLite::clear_has_default_import_enum() { - _has_bits_[2] &= ~0x00000002u; -} -inline void TestAllTypesLite::clear_default_import_enum() { - default_import_enum_ = 8; - clear_has_default_import_enum(); -} -inline protobuf_unittest_import::ImportEnumLite TestAllTypesLite::default_import_enum() const { - return static_cast< protobuf_unittest_import::ImportEnumLite >(default_import_enum_); -} -inline void TestAllTypesLite::set_default_import_enum(protobuf_unittest_import::ImportEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest_import::ImportEnumLite_IsValid(value)); - set_has_default_import_enum(); - default_import_enum_ = value; -} - -// optional string default_string_piece = 84 [default = "abc", ctype = STRING_PIECE]; -inline bool TestAllTypesLite::has_default_string_piece() const { - return (_has_bits_[2] & 0x00000004u) != 0; -} -inline void TestAllTypesLite::set_has_default_string_piece() { - _has_bits_[2] |= 0x00000004u; -} -inline void TestAllTypesLite::clear_has_default_string_piece() { - _has_bits_[2] &= ~0x00000004u; -} -inline void TestAllTypesLite::clear_default_string_piece() { - if (default_string_piece_ != &_default_default_string_piece_) { - default_string_piece_->assign(_default_default_string_piece_); - } - clear_has_default_string_piece(); -} -inline const ::std::string& TestAllTypesLite::default_string_piece() const { - return *default_string_piece_; -} -inline void TestAllTypesLite::set_default_string_piece(const ::std::string& value) { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string; - } - default_string_piece_->assign(value); -} -inline void TestAllTypesLite::set_default_string_piece(const char* value) { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string; - } - default_string_piece_->assign(value); -} -inline void TestAllTypesLite::set_default_string_piece(const char* value, size_t size) { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string; - } - default_string_piece_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_default_string_piece() { - set_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - default_string_piece_ = new ::std::string(_default_default_string_piece_); - } - return default_string_piece_; -} -inline ::std::string* TestAllTypesLite::release_default_string_piece() { - clear_has_default_string_piece(); - if (default_string_piece_ == &_default_default_string_piece_) { - return NULL; - } else { - ::std::string* temp = default_string_piece_; - default_string_piece_ = const_cast< ::std::string*>(&_default_default_string_piece_); - return temp; - } -} - -// optional string default_cord = 85 [default = "123", ctype = CORD]; -inline bool TestAllTypesLite::has_default_cord() const { - return (_has_bits_[2] & 0x00000008u) != 0; -} -inline void TestAllTypesLite::set_has_default_cord() { - _has_bits_[2] |= 0x00000008u; -} -inline void TestAllTypesLite::clear_has_default_cord() { - _has_bits_[2] &= ~0x00000008u; -} -inline void TestAllTypesLite::clear_default_cord() { - if (default_cord_ != &_default_default_cord_) { - default_cord_->assign(_default_default_cord_); - } - clear_has_default_cord(); -} -inline const ::std::string& TestAllTypesLite::default_cord() const { - return *default_cord_; -} -inline void TestAllTypesLite::set_default_cord(const ::std::string& value) { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string; - } - default_cord_->assign(value); -} -inline void TestAllTypesLite::set_default_cord(const char* value) { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string; - } - default_cord_->assign(value); -} -inline void TestAllTypesLite::set_default_cord(const char* value, size_t size) { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string; - } - default_cord_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestAllTypesLite::mutable_default_cord() { - set_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - default_cord_ = new ::std::string(_default_default_cord_); - } - return default_cord_; -} -inline ::std::string* TestAllTypesLite::release_default_cord() { - clear_has_default_cord(); - if (default_cord_ == &_default_default_cord_) { - return NULL; - } else { - ::std::string* temp = default_cord_; - default_cord_ = const_cast< ::std::string*>(&_default_default_cord_); - return temp; - } -} - -// ------------------------------------------------------------------- - -// ForeignMessageLite - -// optional int32 c = 1; -inline bool ForeignMessageLite::has_c() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ForeignMessageLite::set_has_c() { - _has_bits_[0] |= 0x00000001u; -} -inline void ForeignMessageLite::clear_has_c() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ForeignMessageLite::clear_c() { - c_ = 0; - clear_has_c(); -} -inline ::google::protobuf::int32 ForeignMessageLite::c() const { - return c_; -} -inline void ForeignMessageLite::set_c(::google::protobuf::int32 value) { - set_has_c(); - c_ = value; -} - -// ------------------------------------------------------------------- - -// TestPackedTypesLite - -// repeated int32 packed_int32 = 90 [packed = true]; -inline int TestPackedTypesLite::packed_int32_size() const { - return packed_int32_.size(); -} -inline void TestPackedTypesLite::clear_packed_int32() { - packed_int32_.Clear(); -} -inline ::google::protobuf::int32 TestPackedTypesLite::packed_int32(int index) const { - return packed_int32_.Get(index); -} -inline void TestPackedTypesLite::set_packed_int32(int index, ::google::protobuf::int32 value) { - packed_int32_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_int32(::google::protobuf::int32 value) { - packed_int32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestPackedTypesLite::packed_int32() const { - return packed_int32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestPackedTypesLite::mutable_packed_int32() { - return &packed_int32_; -} - -// repeated int64 packed_int64 = 91 [packed = true]; -inline int TestPackedTypesLite::packed_int64_size() const { - return packed_int64_.size(); -} -inline void TestPackedTypesLite::clear_packed_int64() { - packed_int64_.Clear(); -} -inline ::google::protobuf::int64 TestPackedTypesLite::packed_int64(int index) const { - return packed_int64_.Get(index); -} -inline void TestPackedTypesLite::set_packed_int64(int index, ::google::protobuf::int64 value) { - packed_int64_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_int64(::google::protobuf::int64 value) { - packed_int64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestPackedTypesLite::packed_int64() const { - return packed_int64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestPackedTypesLite::mutable_packed_int64() { - return &packed_int64_; -} - -// repeated uint32 packed_uint32 = 92 [packed = true]; -inline int TestPackedTypesLite::packed_uint32_size() const { - return packed_uint32_.size(); -} -inline void TestPackedTypesLite::clear_packed_uint32() { - packed_uint32_.Clear(); -} -inline ::google::protobuf::uint32 TestPackedTypesLite::packed_uint32(int index) const { - return packed_uint32_.Get(index); -} -inline void TestPackedTypesLite::set_packed_uint32(int index, ::google::protobuf::uint32 value) { - packed_uint32_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_uint32(::google::protobuf::uint32 value) { - packed_uint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestPackedTypesLite::packed_uint32() const { - return packed_uint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestPackedTypesLite::mutable_packed_uint32() { - return &packed_uint32_; -} - -// repeated uint64 packed_uint64 = 93 [packed = true]; -inline int TestPackedTypesLite::packed_uint64_size() const { - return packed_uint64_.size(); -} -inline void TestPackedTypesLite::clear_packed_uint64() { - packed_uint64_.Clear(); -} -inline ::google::protobuf::uint64 TestPackedTypesLite::packed_uint64(int index) const { - return packed_uint64_.Get(index); -} -inline void TestPackedTypesLite::set_packed_uint64(int index, ::google::protobuf::uint64 value) { - packed_uint64_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_uint64(::google::protobuf::uint64 value) { - packed_uint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestPackedTypesLite::packed_uint64() const { - return packed_uint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestPackedTypesLite::mutable_packed_uint64() { - return &packed_uint64_; -} - -// repeated sint32 packed_sint32 = 94 [packed = true]; -inline int TestPackedTypesLite::packed_sint32_size() const { - return packed_sint32_.size(); -} -inline void TestPackedTypesLite::clear_packed_sint32() { - packed_sint32_.Clear(); -} -inline ::google::protobuf::int32 TestPackedTypesLite::packed_sint32(int index) const { - return packed_sint32_.Get(index); -} -inline void TestPackedTypesLite::set_packed_sint32(int index, ::google::protobuf::int32 value) { - packed_sint32_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_sint32(::google::protobuf::int32 value) { - packed_sint32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestPackedTypesLite::packed_sint32() const { - return packed_sint32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestPackedTypesLite::mutable_packed_sint32() { - return &packed_sint32_; -} - -// repeated sint64 packed_sint64 = 95 [packed = true]; -inline int TestPackedTypesLite::packed_sint64_size() const { - return packed_sint64_.size(); -} -inline void TestPackedTypesLite::clear_packed_sint64() { - packed_sint64_.Clear(); -} -inline ::google::protobuf::int64 TestPackedTypesLite::packed_sint64(int index) const { - return packed_sint64_.Get(index); -} -inline void TestPackedTypesLite::set_packed_sint64(int index, ::google::protobuf::int64 value) { - packed_sint64_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_sint64(::google::protobuf::int64 value) { - packed_sint64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestPackedTypesLite::packed_sint64() const { - return packed_sint64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestPackedTypesLite::mutable_packed_sint64() { - return &packed_sint64_; -} - -// repeated fixed32 packed_fixed32 = 96 [packed = true]; -inline int TestPackedTypesLite::packed_fixed32_size() const { - return packed_fixed32_.size(); -} -inline void TestPackedTypesLite::clear_packed_fixed32() { - packed_fixed32_.Clear(); -} -inline ::google::protobuf::uint32 TestPackedTypesLite::packed_fixed32(int index) const { - return packed_fixed32_.Get(index); -} -inline void TestPackedTypesLite::set_packed_fixed32(int index, ::google::protobuf::uint32 value) { - packed_fixed32_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_fixed32(::google::protobuf::uint32 value) { - packed_fixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& -TestPackedTypesLite::packed_fixed32() const { - return packed_fixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* -TestPackedTypesLite::mutable_packed_fixed32() { - return &packed_fixed32_; -} - -// repeated fixed64 packed_fixed64 = 97 [packed = true]; -inline int TestPackedTypesLite::packed_fixed64_size() const { - return packed_fixed64_.size(); -} -inline void TestPackedTypesLite::clear_packed_fixed64() { - packed_fixed64_.Clear(); -} -inline ::google::protobuf::uint64 TestPackedTypesLite::packed_fixed64(int index) const { - return packed_fixed64_.Get(index); -} -inline void TestPackedTypesLite::set_packed_fixed64(int index, ::google::protobuf::uint64 value) { - packed_fixed64_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_fixed64(::google::protobuf::uint64 value) { - packed_fixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& -TestPackedTypesLite::packed_fixed64() const { - return packed_fixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* -TestPackedTypesLite::mutable_packed_fixed64() { - return &packed_fixed64_; -} - -// repeated sfixed32 packed_sfixed32 = 98 [packed = true]; -inline int TestPackedTypesLite::packed_sfixed32_size() const { - return packed_sfixed32_.size(); -} -inline void TestPackedTypesLite::clear_packed_sfixed32() { - packed_sfixed32_.Clear(); -} -inline ::google::protobuf::int32 TestPackedTypesLite::packed_sfixed32(int index) const { - return packed_sfixed32_.Get(index); -} -inline void TestPackedTypesLite::set_packed_sfixed32(int index, ::google::protobuf::int32 value) { - packed_sfixed32_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_sfixed32(::google::protobuf::int32 value) { - packed_sfixed32_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TestPackedTypesLite::packed_sfixed32() const { - return packed_sfixed32_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TestPackedTypesLite::mutable_packed_sfixed32() { - return &packed_sfixed32_; -} - -// repeated sfixed64 packed_sfixed64 = 99 [packed = true]; -inline int TestPackedTypesLite::packed_sfixed64_size() const { - return packed_sfixed64_.size(); -} -inline void TestPackedTypesLite::clear_packed_sfixed64() { - packed_sfixed64_.Clear(); -} -inline ::google::protobuf::int64 TestPackedTypesLite::packed_sfixed64(int index) const { - return packed_sfixed64_.Get(index); -} -inline void TestPackedTypesLite::set_packed_sfixed64(int index, ::google::protobuf::int64 value) { - packed_sfixed64_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_sfixed64(::google::protobuf::int64 value) { - packed_sfixed64_.Add(value); -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TestPackedTypesLite::packed_sfixed64() const { - return packed_sfixed64_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TestPackedTypesLite::mutable_packed_sfixed64() { - return &packed_sfixed64_; -} - -// repeated float packed_float = 100 [packed = true]; -inline int TestPackedTypesLite::packed_float_size() const { - return packed_float_.size(); -} -inline void TestPackedTypesLite::clear_packed_float() { - packed_float_.Clear(); -} -inline float TestPackedTypesLite::packed_float(int index) const { - return packed_float_.Get(index); -} -inline void TestPackedTypesLite::set_packed_float(int index, float value) { - packed_float_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_float(float value) { - packed_float_.Add(value); -} -inline const ::google::protobuf::RepeatedField< float >& -TestPackedTypesLite::packed_float() const { - return packed_float_; -} -inline ::google::protobuf::RepeatedField< float >* -TestPackedTypesLite::mutable_packed_float() { - return &packed_float_; -} - -// repeated double packed_double = 101 [packed = true]; -inline int TestPackedTypesLite::packed_double_size() const { - return packed_double_.size(); -} -inline void TestPackedTypesLite::clear_packed_double() { - packed_double_.Clear(); -} -inline double TestPackedTypesLite::packed_double(int index) const { - return packed_double_.Get(index); -} -inline void TestPackedTypesLite::set_packed_double(int index, double value) { - packed_double_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_double(double value) { - packed_double_.Add(value); -} -inline const ::google::protobuf::RepeatedField< double >& -TestPackedTypesLite::packed_double() const { - return packed_double_; -} -inline ::google::protobuf::RepeatedField< double >* -TestPackedTypesLite::mutable_packed_double() { - return &packed_double_; -} - -// repeated bool packed_bool = 102 [packed = true]; -inline int TestPackedTypesLite::packed_bool_size() const { - return packed_bool_.size(); -} -inline void TestPackedTypesLite::clear_packed_bool() { - packed_bool_.Clear(); -} -inline bool TestPackedTypesLite::packed_bool(int index) const { - return packed_bool_.Get(index); -} -inline void TestPackedTypesLite::set_packed_bool(int index, bool value) { - packed_bool_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_bool(bool value) { - packed_bool_.Add(value); -} -inline const ::google::protobuf::RepeatedField< bool >& -TestPackedTypesLite::packed_bool() const { - return packed_bool_; -} -inline ::google::protobuf::RepeatedField< bool >* -TestPackedTypesLite::mutable_packed_bool() { - return &packed_bool_; -} - -// repeated .protobuf_unittest.ForeignEnumLite packed_enum = 103 [packed = true]; -inline int TestPackedTypesLite::packed_enum_size() const { - return packed_enum_.size(); -} -inline void TestPackedTypesLite::clear_packed_enum() { - packed_enum_.Clear(); -} -inline protobuf_unittest::ForeignEnumLite TestPackedTypesLite::packed_enum(int index) const { - return static_cast< protobuf_unittest::ForeignEnumLite >(packed_enum_.Get(index)); -} -inline void TestPackedTypesLite::set_packed_enum(int index, protobuf_unittest::ForeignEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); - packed_enum_.Set(index, value); -} -inline void TestPackedTypesLite::add_packed_enum(protobuf_unittest::ForeignEnumLite value) { - GOOGLE_DCHECK(protobuf_unittest::ForeignEnumLite_IsValid(value)); - packed_enum_.Add(value); -} -inline const ::google::protobuf::RepeatedField& -TestPackedTypesLite::packed_enum() const { - return packed_enum_; -} -inline ::google::protobuf::RepeatedField* -TestPackedTypesLite::mutable_packed_enum() { - return &packed_enum_; -} - -// ------------------------------------------------------------------- - -// TestAllExtensionsLite - -// ------------------------------------------------------------------- - -// OptionalGroup_extension_lite - -// optional int32 a = 17; -inline bool OptionalGroup_extension_lite::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void OptionalGroup_extension_lite::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void OptionalGroup_extension_lite::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void OptionalGroup_extension_lite::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 OptionalGroup_extension_lite::a() const { - return a_; -} -inline void OptionalGroup_extension_lite::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// RepeatedGroup_extension_lite - -// optional int32 a = 47; -inline bool RepeatedGroup_extension_lite::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void RepeatedGroup_extension_lite::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void RepeatedGroup_extension_lite::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void RepeatedGroup_extension_lite::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 RepeatedGroup_extension_lite::a() const { - return a_; -} -inline void RepeatedGroup_extension_lite::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - -// ------------------------------------------------------------------- - -// TestPackedExtensionsLite - -// ------------------------------------------------------------------- - -// TestNestedExtensionLite - -// ------------------------------------------------------------------- - -// TestDeprecatedLite - -// optional int32 deprecated_field = 1 [deprecated = true]; -inline bool TestDeprecatedLite::has_deprecated_field() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestDeprecatedLite::set_has_deprecated_field() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestDeprecatedLite::clear_has_deprecated_field() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestDeprecatedLite::clear_deprecated_field() { - deprecated_field_ = 0; - clear_has_deprecated_field(); -} -inline ::google::protobuf::int32 TestDeprecatedLite::deprecated_field() const { - return deprecated_field_; -} -inline void TestDeprecatedLite::set_deprecated_field(::google::protobuf::int32 value) { - set_has_deprecated_field(); - deprecated_field_ = value; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5flite_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h deleted file mode 100644 index dceddcec..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +++ /dev/null @@ -1,150 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_lite_imports_nonlite.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include "google/protobuf/unittest.pb.h" -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); - -class TestLiteImportsNonlite; - -// =================================================================== - -class TestLiteImportsNonlite : public ::google::protobuf::MessageLite { - public: - TestLiteImportsNonlite(); - virtual ~TestLiteImportsNonlite(); - - TestLiteImportsNonlite(const TestLiteImportsNonlite& from); - - inline TestLiteImportsNonlite& operator=(const TestLiteImportsNonlite& from) { - CopyFrom(from); - return *this; - } - - static const TestLiteImportsNonlite& default_instance(); - - void Swap(TestLiteImportsNonlite* other); - - // implements Message ---------------------------------------------- - - TestLiteImportsNonlite* New() const; - void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from); - void CopyFrom(const TestLiteImportsNonlite& from); - void MergeFrom(const TestLiteImportsNonlite& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::std::string GetTypeName() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestAllTypes message = 1; - inline bool has_message() const; - inline void clear_message(); - static const int kMessageFieldNumber = 1; - inline const ::protobuf_unittest::TestAllTypes& message() const; - inline ::protobuf_unittest::TestAllTypes* mutable_message(); - inline ::protobuf_unittest::TestAllTypes* release_message(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestLiteImportsNonlite) - private: - inline void set_has_message(); - inline void clear_has_message(); - - ::protobuf_unittest::TestAllTypes* message_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto(); - - void InitAsDefaultInstance(); - static TestLiteImportsNonlite* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// TestLiteImportsNonlite - -// optional .protobuf_unittest.TestAllTypes message = 1; -inline bool TestLiteImportsNonlite::has_message() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestLiteImportsNonlite::set_has_message() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestLiteImportsNonlite::clear_has_message() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestLiteImportsNonlite::clear_message() { - if (message_ != NULL) message_->::protobuf_unittest::TestAllTypes::Clear(); - clear_has_message(); -} -inline const ::protobuf_unittest::TestAllTypes& TestLiteImportsNonlite::message() const { - return message_ != NULL ? *message_ : *default_instance_->message_; -} -inline ::protobuf_unittest::TestAllTypes* TestLiteImportsNonlite::mutable_message() { - set_has_message(); - if (message_ == NULL) message_ = new ::protobuf_unittest::TestAllTypes; - return message_; -} -inline ::protobuf_unittest::TestAllTypes* TestLiteImportsNonlite::release_message() { - clear_has_message(); - ::protobuf_unittest::TestAllTypes* temp = message_; - message_ = NULL; - return temp; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5flite_5fimports_5fnonlite_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h deleted file mode 100644 index 9bf04902..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +++ /dev/null @@ -1,816 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_mset.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fmset_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5fmset_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); - -class TestMessageSet; -class TestMessageSetContainer; -class TestMessageSetExtension1; -class TestMessageSetExtension2; -class RawMessageSet; -class RawMessageSet_Item; - -// =================================================================== - -class TestMessageSet : public ::google::protobuf::Message { - public: - TestMessageSet(); - virtual ~TestMessageSet(); - - TestMessageSet(const TestMessageSet& from); - - inline TestMessageSet& operator=(const TestMessageSet& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMessageSet& default_instance(); - - void Swap(TestMessageSet* other); - - // implements Message ---------------------------------------------- - - TestMessageSet* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMessageSet& from); - void MergeFrom(const TestMessageSet& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestMessageSet) - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSet) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[1]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); - - void InitAsDefaultInstance(); - static TestMessageSet* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestMessageSetContainer : public ::google::protobuf::Message { - public: - TestMessageSetContainer(); - virtual ~TestMessageSetContainer(); - - TestMessageSetContainer(const TestMessageSetContainer& from); - - inline TestMessageSetContainer& operator=(const TestMessageSetContainer& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMessageSetContainer& default_instance(); - - void Swap(TestMessageSetContainer* other); - - // implements Message ---------------------------------------------- - - TestMessageSetContainer* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMessageSetContainer& from); - void MergeFrom(const TestMessageSetContainer& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestMessageSet message_set = 1; - inline bool has_message_set() const; - inline void clear_message_set(); - static const int kMessageSetFieldNumber = 1; - inline const ::protobuf_unittest::TestMessageSet& message_set() const; - inline ::protobuf_unittest::TestMessageSet* mutable_message_set(); - inline ::protobuf_unittest::TestMessageSet* release_message_set(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSetContainer) - private: - inline void set_has_message_set(); - inline void clear_has_message_set(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestMessageSet* message_set_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); - - void InitAsDefaultInstance(); - static TestMessageSetContainer* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestMessageSetExtension1 : public ::google::protobuf::Message { - public: - TestMessageSetExtension1(); - virtual ~TestMessageSetExtension1(); - - TestMessageSetExtension1(const TestMessageSetExtension1& from); - - inline TestMessageSetExtension1& operator=(const TestMessageSetExtension1& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMessageSetExtension1& default_instance(); - - void Swap(TestMessageSetExtension1* other); - - // implements Message ---------------------------------------------- - - TestMessageSetExtension1* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMessageSetExtension1& from); - void MergeFrom(const TestMessageSetExtension1& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 i = 15; - inline bool has_i() const; - inline void clear_i(); - static const int kIFieldNumber = 15; - inline ::google::protobuf::int32 i() const; - inline void set_i(::google::protobuf::int32 value); - - static const int kMessageSetExtensionFieldNumber = 1545008; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestMessageSet, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestMessageSetExtension1 >, 11, false > - message_set_extension; - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSetExtension1) - private: - inline void set_has_i(); - inline void clear_has_i(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 i_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); - - void InitAsDefaultInstance(); - static TestMessageSetExtension1* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestMessageSetExtension2 : public ::google::protobuf::Message { - public: - TestMessageSetExtension2(); - virtual ~TestMessageSetExtension2(); - - TestMessageSetExtension2(const TestMessageSetExtension2& from); - - inline TestMessageSetExtension2& operator=(const TestMessageSetExtension2& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMessageSetExtension2& default_instance(); - - void Swap(TestMessageSetExtension2* other); - - // implements Message ---------------------------------------------- - - TestMessageSetExtension2* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMessageSetExtension2& from); - void MergeFrom(const TestMessageSetExtension2& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string str = 25; - inline bool has_str() const; - inline void clear_str(); - static const int kStrFieldNumber = 25; - inline const ::std::string& str() const; - inline void set_str(const ::std::string& value); - inline void set_str(const char* value); - inline void set_str(const char* value, size_t size); - inline ::std::string* mutable_str(); - inline ::std::string* release_str(); - - static const int kMessageSetExtensionFieldNumber = 1547769; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestMessageSet, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestMessageSetExtension2 >, 11, false > - message_set_extension; - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestMessageSetExtension2) - private: - inline void set_has_str(); - inline void clear_has_str(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* str_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); - - void InitAsDefaultInstance(); - static TestMessageSetExtension2* default_instance_; -}; -// ------------------------------------------------------------------- - -class RawMessageSet_Item : public ::google::protobuf::Message { - public: - RawMessageSet_Item(); - virtual ~RawMessageSet_Item(); - - RawMessageSet_Item(const RawMessageSet_Item& from); - - inline RawMessageSet_Item& operator=(const RawMessageSet_Item& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const RawMessageSet_Item& default_instance(); - - void Swap(RawMessageSet_Item* other); - - // implements Message ---------------------------------------------- - - RawMessageSet_Item* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const RawMessageSet_Item& from); - void MergeFrom(const RawMessageSet_Item& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required int32 type_id = 2; - inline bool has_type_id() const; - inline void clear_type_id(); - static const int kTypeIdFieldNumber = 2; - inline ::google::protobuf::int32 type_id() const; - inline void set_type_id(::google::protobuf::int32 value); - - // required bytes message = 3; - inline bool has_message() const; - inline void clear_message(); - static const int kMessageFieldNumber = 3; - inline const ::std::string& message() const; - inline void set_message(const ::std::string& value); - inline void set_message(const char* value); - inline void set_message(const void* value, size_t size); - inline ::std::string* mutable_message(); - inline ::std::string* release_message(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.RawMessageSet.Item) - private: - inline void set_has_type_id(); - inline void clear_has_type_id(); - inline void set_has_message(); - inline void clear_has_message(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::std::string* message_; - ::google::protobuf::int32 type_id_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); - - void InitAsDefaultInstance(); - static RawMessageSet_Item* default_instance_; -}; -// ------------------------------------------------------------------- - -class RawMessageSet : public ::google::protobuf::Message { - public: - RawMessageSet(); - virtual ~RawMessageSet(); - - RawMessageSet(const RawMessageSet& from); - - inline RawMessageSet& operator=(const RawMessageSet& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const RawMessageSet& default_instance(); - - void Swap(RawMessageSet* other); - - // implements Message ---------------------------------------------- - - RawMessageSet* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const RawMessageSet& from); - void MergeFrom(const RawMessageSet& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef RawMessageSet_Item Item; - - // accessors ------------------------------------------------------- - - // repeated group Item = 1 { - inline int item_size() const; - inline void clear_item(); - static const int kItemFieldNumber = 1; - inline const ::protobuf_unittest::RawMessageSet_Item& item(int index) const; - inline ::protobuf_unittest::RawMessageSet_Item* mutable_item(int index); - inline ::protobuf_unittest::RawMessageSet_Item* add_item(); - inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >& - item() const; - inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >* - mutable_item(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.RawMessageSet) - private: - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item > item_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fmset_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fmset_2eproto(); - - void InitAsDefaultInstance(); - static RawMessageSet* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// TestMessageSet - -// ------------------------------------------------------------------- - -// TestMessageSetContainer - -// optional .protobuf_unittest.TestMessageSet message_set = 1; -inline bool TestMessageSetContainer::has_message_set() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestMessageSetContainer::set_has_message_set() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestMessageSetContainer::clear_has_message_set() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestMessageSetContainer::clear_message_set() { - if (message_set_ != NULL) message_set_->::protobuf_unittest::TestMessageSet::Clear(); - clear_has_message_set(); -} -inline const ::protobuf_unittest::TestMessageSet& TestMessageSetContainer::message_set() const { - return message_set_ != NULL ? *message_set_ : *default_instance_->message_set_; -} -inline ::protobuf_unittest::TestMessageSet* TestMessageSetContainer::mutable_message_set() { - set_has_message_set(); - if (message_set_ == NULL) message_set_ = new ::protobuf_unittest::TestMessageSet; - return message_set_; -} -inline ::protobuf_unittest::TestMessageSet* TestMessageSetContainer::release_message_set() { - clear_has_message_set(); - ::protobuf_unittest::TestMessageSet* temp = message_set_; - message_set_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// TestMessageSetExtension1 - -// optional int32 i = 15; -inline bool TestMessageSetExtension1::has_i() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestMessageSetExtension1::set_has_i() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestMessageSetExtension1::clear_has_i() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestMessageSetExtension1::clear_i() { - i_ = 0; - clear_has_i(); -} -inline ::google::protobuf::int32 TestMessageSetExtension1::i() const { - return i_; -} -inline void TestMessageSetExtension1::set_i(::google::protobuf::int32 value) { - set_has_i(); - i_ = value; -} - -// ------------------------------------------------------------------- - -// TestMessageSetExtension2 - -// optional string str = 25; -inline bool TestMessageSetExtension2::has_str() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestMessageSetExtension2::set_has_str() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestMessageSetExtension2::clear_has_str() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestMessageSetExtension2::clear_str() { - if (str_ != &::google::protobuf::internal::kEmptyString) { - str_->clear(); - } - clear_has_str(); -} -inline const ::std::string& TestMessageSetExtension2::str() const { - return *str_; -} -inline void TestMessageSetExtension2::set_str(const ::std::string& value) { - set_has_str(); - if (str_ == &::google::protobuf::internal::kEmptyString) { - str_ = new ::std::string; - } - str_->assign(value); -} -inline void TestMessageSetExtension2::set_str(const char* value) { - set_has_str(); - if (str_ == &::google::protobuf::internal::kEmptyString) { - str_ = new ::std::string; - } - str_->assign(value); -} -inline void TestMessageSetExtension2::set_str(const char* value, size_t size) { - set_has_str(); - if (str_ == &::google::protobuf::internal::kEmptyString) { - str_ = new ::std::string; - } - str_->assign(reinterpret_cast(value), size); -} -inline ::std::string* TestMessageSetExtension2::mutable_str() { - set_has_str(); - if (str_ == &::google::protobuf::internal::kEmptyString) { - str_ = new ::std::string; - } - return str_; -} -inline ::std::string* TestMessageSetExtension2::release_str() { - clear_has_str(); - if (str_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = str_; - str_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// RawMessageSet_Item - -// required int32 type_id = 2; -inline bool RawMessageSet_Item::has_type_id() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void RawMessageSet_Item::set_has_type_id() { - _has_bits_[0] |= 0x00000001u; -} -inline void RawMessageSet_Item::clear_has_type_id() { - _has_bits_[0] &= ~0x00000001u; -} -inline void RawMessageSet_Item::clear_type_id() { - type_id_ = 0; - clear_has_type_id(); -} -inline ::google::protobuf::int32 RawMessageSet_Item::type_id() const { - return type_id_; -} -inline void RawMessageSet_Item::set_type_id(::google::protobuf::int32 value) { - set_has_type_id(); - type_id_ = value; -} - -// required bytes message = 3; -inline bool RawMessageSet_Item::has_message() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void RawMessageSet_Item::set_has_message() { - _has_bits_[0] |= 0x00000002u; -} -inline void RawMessageSet_Item::clear_has_message() { - _has_bits_[0] &= ~0x00000002u; -} -inline void RawMessageSet_Item::clear_message() { - if (message_ != &::google::protobuf::internal::kEmptyString) { - message_->clear(); - } - clear_has_message(); -} -inline const ::std::string& RawMessageSet_Item::message() const { - return *message_; -} -inline void RawMessageSet_Item::set_message(const ::std::string& value) { - set_has_message(); - if (message_ == &::google::protobuf::internal::kEmptyString) { - message_ = new ::std::string; - } - message_->assign(value); -} -inline void RawMessageSet_Item::set_message(const char* value) { - set_has_message(); - if (message_ == &::google::protobuf::internal::kEmptyString) { - message_ = new ::std::string; - } - message_->assign(value); -} -inline void RawMessageSet_Item::set_message(const void* value, size_t size) { - set_has_message(); - if (message_ == &::google::protobuf::internal::kEmptyString) { - message_ = new ::std::string; - } - message_->assign(reinterpret_cast(value), size); -} -inline ::std::string* RawMessageSet_Item::mutable_message() { - set_has_message(); - if (message_ == &::google::protobuf::internal::kEmptyString) { - message_ = new ::std::string; - } - return message_; -} -inline ::std::string* RawMessageSet_Item::release_message() { - clear_has_message(); - if (message_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = message_; - message_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } -} - -// ------------------------------------------------------------------- - -// RawMessageSet - -// repeated group Item = 1 { -inline int RawMessageSet::item_size() const { - return item_.size(); -} -inline void RawMessageSet::clear_item() { - item_.Clear(); -} -inline const ::protobuf_unittest::RawMessageSet_Item& RawMessageSet::item(int index) const { - return item_.Get(index); -} -inline ::protobuf_unittest::RawMessageSet_Item* RawMessageSet::mutable_item(int index) { - return item_.Mutable(index); -} -inline ::protobuf_unittest::RawMessageSet_Item* RawMessageSet::add_item() { - return item_.Add(); -} -inline const ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >& -RawMessageSet::item() const { - return item_; -} -inline ::google::protobuf::RepeatedPtrField< ::protobuf_unittest::RawMessageSet_Item >* -RawMessageSet::mutable_item() { - return &item_; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -#ifndef SWIG -namespace google { -namespace protobuf { - - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5fmset_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h deleted file mode 100644 index b2afc88f..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +++ /dev/null @@ -1,197 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_no_generic_services.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { -namespace no_generic_services_test { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); - -class TestMessage; - -enum TestEnum { - FOO = 1 -}; -bool TestEnum_IsValid(int value); -const TestEnum TestEnum_MIN = FOO; -const TestEnum TestEnum_MAX = FOO; -const int TestEnum_ARRAYSIZE = TestEnum_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TestEnum_descriptor(); -inline const ::std::string& TestEnum_Name(TestEnum value) { - return ::google::protobuf::internal::NameOfEnum( - TestEnum_descriptor(), value); -} -inline bool TestEnum_Parse( - const ::std::string& name, TestEnum* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TestEnum_descriptor(), name, value); -} -// =================================================================== - -class TestMessage : public ::google::protobuf::Message { - public: - TestMessage(); - virtual ~TestMessage(); - - TestMessage(const TestMessage& from); - - inline TestMessage& operator=(const TestMessage& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestMessage& default_instance(); - - void Swap(TestMessage* other); - - // implements Message ---------------------------------------------- - - TestMessage* New() const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TestMessage& from); - void MergeFrom(const TestMessage& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 a = 1; - inline bool has_a() const; - inline void clear_a(); - static const int kAFieldNumber = 1; - inline ::google::protobuf::int32 a() const; - inline void set_a(::google::protobuf::int32 value); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestMessage) - // @@protoc_insertion_point(class_scope:google.protobuf.no_generic_services_test.TestMessage) - private: - inline void set_has_a(); - inline void clear_has_a(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 a_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto(); - - void InitAsDefaultInstance(); - static TestMessage* default_instance_; -}; -// =================================================================== - -static const int kTestExtensionFieldNumber = 1000; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::no_generic_services_test::TestMessage, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - test_extension; - -// =================================================================== - -// TestMessage - -// optional int32 a = 1; -inline bool TestMessage::has_a() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestMessage::set_has_a() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestMessage::clear_has_a() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestMessage::clear_a() { - a_ = 0; - clear_has_a(); -} -inline ::google::protobuf::int32 TestMessage::a() const { - return a_; -} -inline void TestMessage::set_a(::google::protobuf::int32 value) { - set_has_a(); - a_ = value; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace no_generic_services_test -} // namespace protobuf -} // namespace google - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> -inline const EnumDescriptor* GetEnumDescriptor< google::protobuf::no_generic_services_test::TestEnum>() { - return google::protobuf::no_generic_services_test::TestEnum_descriptor(); -} - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5fno_5fgeneric_5fservices_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h b/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h deleted file mode 100644 index bcea5ebc..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +++ /dev/null @@ -1,403 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/unittest_optimize_for.proto - -#ifndef PROTOBUF_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 2004000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include "google/protobuf/unittest.pb.h" -// @@protoc_insertion_point(includes) - -namespace protobuf_unittest { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - -class TestOptimizedForSize; -class TestRequiredOptimizedForSize; -class TestOptionalOptimizedForSize; - -// =================================================================== - -class TestOptimizedForSize : public ::google::protobuf::Message { - public: - TestOptimizedForSize(); - virtual ~TestOptimizedForSize(); - - TestOptimizedForSize(const TestOptimizedForSize& from); - - inline TestOptimizedForSize& operator=(const TestOptimizedForSize& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestOptimizedForSize& default_instance(); - - void Swap(TestOptimizedForSize* other); - - // implements Message ---------------------------------------------- - - TestOptimizedForSize* New() const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 i = 1; - inline bool has_i() const; - inline void clear_i(); - static const int kIFieldNumber = 1; - inline ::google::protobuf::int32 i() const; - inline void set_i(::google::protobuf::int32 value); - - // optional .protobuf_unittest.ForeignMessage msg = 19; - inline bool has_msg() const; - inline void clear_msg(); - static const int kMsgFieldNumber = 19; - inline const ::protobuf_unittest::ForeignMessage& msg() const; - inline ::protobuf_unittest::ForeignMessage* mutable_msg(); - inline ::protobuf_unittest::ForeignMessage* release_msg(); - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(TestOptimizedForSize) - static const int kTestExtensionFieldNumber = 1234; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestOptimizedForSize, - ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > - test_extension; - static const int kTestExtension2FieldNumber = 1235; - static ::google::protobuf::internal::ExtensionIdentifier< ::protobuf_unittest::TestOptimizedForSize, - ::google::protobuf::internal::MessageTypeTraits< ::protobuf_unittest::TestRequiredOptimizedForSize >, 11, false > - test_extension2; - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestOptimizedForSize) - private: - inline void set_has_i(); - inline void clear_has_i(); - inline void set_has_msg(); - inline void clear_has_msg(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::ForeignMessage* msg_; - ::google::protobuf::int32 i_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - - void InitAsDefaultInstance(); - static TestOptimizedForSize* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestRequiredOptimizedForSize : public ::google::protobuf::Message { - public: - TestRequiredOptimizedForSize(); - virtual ~TestRequiredOptimizedForSize(); - - TestRequiredOptimizedForSize(const TestRequiredOptimizedForSize& from); - - inline TestRequiredOptimizedForSize& operator=(const TestRequiredOptimizedForSize& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestRequiredOptimizedForSize& default_instance(); - - void Swap(TestRequiredOptimizedForSize* other); - - // implements Message ---------------------------------------------- - - TestRequiredOptimizedForSize* New() const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required int32 x = 1; - inline bool has_x() const; - inline void clear_x(); - static const int kXFieldNumber = 1; - inline ::google::protobuf::int32 x() const; - inline void set_x(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestRequiredOptimizedForSize) - private: - inline void set_has_x(); - inline void clear_has_x(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::int32 x_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - - void InitAsDefaultInstance(); - static TestRequiredOptimizedForSize* default_instance_; -}; -// ------------------------------------------------------------------- - -class TestOptionalOptimizedForSize : public ::google::protobuf::Message { - public: - TestOptionalOptimizedForSize(); - virtual ~TestOptionalOptimizedForSize(); - - TestOptionalOptimizedForSize(const TestOptionalOptimizedForSize& from); - - inline TestOptionalOptimizedForSize& operator=(const TestOptionalOptimizedForSize& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _unknown_fields_; - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return &_unknown_fields_; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TestOptionalOptimizedForSize& default_instance(); - - void Swap(TestOptionalOptimizedForSize* other); - - // implements Message ---------------------------------------------- - - TestOptionalOptimizedForSize* New() const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .protobuf_unittest.TestRequiredOptimizedForSize o = 1; - inline bool has_o() const; - inline void clear_o(); - static const int kOFieldNumber = 1; - inline const ::protobuf_unittest::TestRequiredOptimizedForSize& o() const; - inline ::protobuf_unittest::TestRequiredOptimizedForSize* mutable_o(); - inline ::protobuf_unittest::TestRequiredOptimizedForSize* release_o(); - - // @@protoc_insertion_point(class_scope:protobuf_unittest.TestOptionalOptimizedForSize) - private: - inline void set_has_o(); - inline void clear_has_o(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::protobuf_unittest::TestRequiredOptimizedForSize* o_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; - - friend void protobuf_AddDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - friend void protobuf_AssignDesc_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto(); - - void InitAsDefaultInstance(); - static TestOptionalOptimizedForSize* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// TestOptimizedForSize - -// optional int32 i = 1; -inline bool TestOptimizedForSize::has_i() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestOptimizedForSize::set_has_i() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestOptimizedForSize::clear_has_i() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestOptimizedForSize::clear_i() { - i_ = 0; - clear_has_i(); -} -inline ::google::protobuf::int32 TestOptimizedForSize::i() const { - return i_; -} -inline void TestOptimizedForSize::set_i(::google::protobuf::int32 value) { - set_has_i(); - i_ = value; -} - -// optional .protobuf_unittest.ForeignMessage msg = 19; -inline bool TestOptimizedForSize::has_msg() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TestOptimizedForSize::set_has_msg() { - _has_bits_[0] |= 0x00000002u; -} -inline void TestOptimizedForSize::clear_has_msg() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TestOptimizedForSize::clear_msg() { - if (msg_ != NULL) msg_->::protobuf_unittest::ForeignMessage::Clear(); - clear_has_msg(); -} -inline const ::protobuf_unittest::ForeignMessage& TestOptimizedForSize::msg() const { - return msg_ != NULL ? *msg_ : *default_instance_->msg_; -} -inline ::protobuf_unittest::ForeignMessage* TestOptimizedForSize::mutable_msg() { - set_has_msg(); - if (msg_ == NULL) msg_ = new ::protobuf_unittest::ForeignMessage; - return msg_; -} -inline ::protobuf_unittest::ForeignMessage* TestOptimizedForSize::release_msg() { - clear_has_msg(); - ::protobuf_unittest::ForeignMessage* temp = msg_; - msg_ = NULL; - return temp; -} - -// ------------------------------------------------------------------- - -// TestRequiredOptimizedForSize - -// required int32 x = 1; -inline bool TestRequiredOptimizedForSize::has_x() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestRequiredOptimizedForSize::set_has_x() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestRequiredOptimizedForSize::clear_has_x() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestRequiredOptimizedForSize::clear_x() { - x_ = 0; - clear_has_x(); -} -inline ::google::protobuf::int32 TestRequiredOptimizedForSize::x() const { - return x_; -} -inline void TestRequiredOptimizedForSize::set_x(::google::protobuf::int32 value) { - set_has_x(); - x_ = value; -} - -// ------------------------------------------------------------------- - -// TestOptionalOptimizedForSize - -// optional .protobuf_unittest.TestRequiredOptimizedForSize o = 1; -inline bool TestOptionalOptimizedForSize::has_o() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TestOptionalOptimizedForSize::set_has_o() { - _has_bits_[0] |= 0x00000001u; -} -inline void TestOptionalOptimizedForSize::clear_has_o() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TestOptionalOptimizedForSize::clear_o() { - if (o_ != NULL) o_->::protobuf_unittest::TestRequiredOptimizedForSize::Clear(); - clear_has_o(); -} -inline const ::protobuf_unittest::TestRequiredOptimizedForSize& TestOptionalOptimizedForSize::o() const { - return o_ != NULL ? *o_ : *default_instance_->o_; -} -inline ::protobuf_unittest::TestRequiredOptimizedForSize* TestOptionalOptimizedForSize::mutable_o() { - set_has_o(); - if (o_ == NULL) o_ = new ::protobuf_unittest::TestRequiredOptimizedForSize; - return o_; -} -inline ::protobuf_unittest::TestRequiredOptimizedForSize* TestOptionalOptimizedForSize::release_o() { - clear_has_o(); - ::protobuf_unittest::TestRequiredOptimizedForSize* temp = o_; - o_ = NULL; - return temp; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf_unittest - -#ifndef SWIG -namespace google { -namespace protobuf { - - -} // namespace google -} // namespace protobuf -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2funittest_5foptimize_5ffor_2eproto__INCLUDED diff --git a/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h b/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h deleted file mode 100644 index 84c2e2b6..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +++ /dev/null @@ -1,268 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Contains classes used to keep track of unrecognized fields seen while -// parsing a protocol message. - -#ifndef GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ -#define GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - -class Message; // message.h -class UnknownField; // below - -// An UnknownFieldSet contains fields that were encountered while parsing a -// message but were not defined by its type. Keeping track of these can be -// useful, especially in that they may be written if the message is serialized -// again without being cleared in between. This means that software which -// simply receives messages and forwards them to other servers does not need -// to be updated every time a new field is added to the message definition. -// -// To get the UnknownFieldSet attached to any message, call -// Reflection::GetUnknownFields(). -// -// This class is necessarily tied to the protocol buffer wire format, unlike -// the Reflection interface which is independent of any serialization scheme. -class LIBPROTOBUF_EXPORT UnknownFieldSet { - public: - UnknownFieldSet(); - ~UnknownFieldSet(); - - // Remove all fields. - inline void Clear(); - - // Is this set empty? - inline bool empty() const; - - // Merge the contents of some other UnknownFieldSet with this one. - void MergeFrom(const UnknownFieldSet& other); - - // Swaps the contents of some other UnknownFieldSet with this one. - inline void Swap(UnknownFieldSet* x); - - // Computes (an estimate of) the total number of bytes currently used for - // storing the unknown fields in memory. Does NOT include - // sizeof(*this) in the calculation. - int SpaceUsedExcludingSelf() const; - - // Version of SpaceUsed() including sizeof(*this). - int SpaceUsed() const; - - // Returns the number of fields present in the UnknownFieldSet. - inline int field_count() const; - // Get a field in the set, where 0 <= index < field_count(). The fields - // appear in the order in which they were added. - inline const UnknownField& field(int index) const; - // Get a mutable pointer to a field in the set, where - // 0 <= index < field_count(). The fields appear in the order in which - // they were added. - inline UnknownField* mutable_field(int index); - - // Adding fields --------------------------------------------------- - - void AddVarint(int number, uint64 value); - void AddFixed32(int number, uint32 value); - void AddFixed64(int number, uint64 value); - void AddLengthDelimited(int number, const string& value); - string* AddLengthDelimited(int number); - UnknownFieldSet* AddGroup(int number); - - // Adds an unknown field from another set. - void AddField(const UnknownField& field); - - // Parsing helpers ------------------------------------------------- - // These work exactly like the similarly-named methods of Message. - - bool MergeFromCodedStream(io::CodedInputStream* input); - bool ParseFromCodedStream(io::CodedInputStream* input); - bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); - bool ParseFromArray(const void* data, int size); - inline bool ParseFromString(const string& data) { - return ParseFromArray(data.data(), data.size()); - } - - private: - void ClearFallback(); - - vector* fields_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet); -}; - -// Represents one field in an UnknownFieldSet. -class LIBPROTOBUF_EXPORT UnknownField { - public: - enum Type { - TYPE_VARINT, - TYPE_FIXED32, - TYPE_FIXED64, - TYPE_LENGTH_DELIMITED, - TYPE_GROUP - }; - - // The field's tag number, as seen on the wire. - inline int number() const; - - // The field type. - inline Type type() const; - - // Accessors ------------------------------------------------------- - // Each method works only for UnknownFields of the corresponding type. - - inline uint64 varint() const; - inline uint32 fixed32() const; - inline uint64 fixed64() const; - inline const string& length_delimited() const; - inline const UnknownFieldSet& group() const; - - inline void set_varint(uint64 value); - inline void set_fixed32(uint32 value); - inline void set_fixed64(uint64 value); - inline void set_length_delimited(const string& value); - inline string* mutable_length_delimited(); - inline UnknownFieldSet* mutable_group(); - - private: - friend class UnknownFieldSet; - - // If this UnknownField contains a pointer, delete it. - void Delete(); - - // Make a deep copy of any pointers in this UnknownField. - void DeepCopy(); - - unsigned int number_ : 29; - unsigned int type_ : 3; - union { - uint64 varint_; - uint32 fixed32_; - uint64 fixed64_; - string* length_delimited_; - UnknownFieldSet* group_; - }; -}; - -// =================================================================== -// inline implementations - -inline void UnknownFieldSet::Clear() { - if (fields_ != NULL) { - ClearFallback(); - } -} - -inline bool UnknownFieldSet::empty() const { - return fields_ == NULL || fields_->empty(); -} - -inline void UnknownFieldSet::Swap(UnknownFieldSet* x) { - std::swap(fields_, x->fields_); -} - -inline int UnknownFieldSet::field_count() const { - return (fields_ == NULL) ? 0 : fields_->size(); -} -inline const UnknownField& UnknownFieldSet::field(int index) const { - return (*fields_)[index]; -} -inline UnknownField* UnknownFieldSet::mutable_field(int index) { - return &(*fields_)[index]; -} - -inline void UnknownFieldSet::AddLengthDelimited( - int number, const string& value) { - AddLengthDelimited(number)->assign(value); -} - -inline int UnknownField::number() const { return number_; } -inline UnknownField::Type UnknownField::type() const { - return static_cast(type_); -} - -inline uint64 UnknownField::varint () const { - GOOGLE_DCHECK_EQ(type_, TYPE_VARINT); - return varint_; -} -inline uint32 UnknownField::fixed32() const { - GOOGLE_DCHECK_EQ(type_, TYPE_FIXED32); - return fixed32_; -} -inline uint64 UnknownField::fixed64() const { - GOOGLE_DCHECK_EQ(type_, TYPE_FIXED64); - return fixed64_; -} -inline const string& UnknownField::length_delimited() const { - GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); - return *length_delimited_; -} -inline const UnknownFieldSet& UnknownField::group() const { - GOOGLE_DCHECK_EQ(type_, TYPE_GROUP); - return *group_; -} - -inline void UnknownField::set_varint(uint64 value) { - GOOGLE_DCHECK_EQ(type_, TYPE_VARINT); - varint_ = value; -} -inline void UnknownField::set_fixed32(uint32 value) { - GOOGLE_DCHECK_EQ(type_, TYPE_FIXED32); - fixed32_ = value; -} -inline void UnknownField::set_fixed64(uint64 value) { - GOOGLE_DCHECK_EQ(type_, TYPE_FIXED64); - fixed64_ = value; -} -inline void UnknownField::set_length_delimited(const string& value) { - GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); - length_delimited_->assign(value); -} -inline string* UnknownField::mutable_length_delimited() { - GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); - return length_delimited_; -} -inline UnknownFieldSet* UnknownField::mutable_group() { - GOOGLE_DCHECK_EQ(type_, TYPE_GROUP); - return group_; -} - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h b/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h deleted file mode 100644 index c7539250..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +++ /dev/null @@ -1,304 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// atenasio@google.com (Chris Atenasio) (ZigZag transform) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_H__ -#define GOOGLE_PROTOBUF_WIRE_FORMAT_H__ - -#include -#include -#include -#include -#include - -// Do UTF-8 validation on string type in Debug build only -#ifndef NDEBUG -#define GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED -#endif - -namespace google { -namespace protobuf { - namespace io { - class CodedInputStream; // coded_stream.h - class CodedOutputStream; // coded_stream.h - } - class UnknownFieldSet; // unknown_field_set.h -} - -namespace protobuf { -namespace internal { - -// This class is for internal use by the protocol buffer library and by -// protocol-complier-generated message classes. It must not be called -// directly by clients. -// -// This class contains code for implementing the binary protocol buffer -// wire format via reflection. The WireFormatLite class implements the -// non-reflection based routines. -// -// This class is really a namespace that contains only static methods -class LIBPROTOBUF_EXPORT WireFormat { - public: - - // Given a field return its WireType - static inline WireFormatLite::WireType WireTypeForField( - const FieldDescriptor* field); - - // Given a FieldSescriptor::Type return its WireType - static inline WireFormatLite::WireType WireTypeForFieldType( - FieldDescriptor::Type type); - - // Compute the byte size of a tag. For groups, this includes both the start - // and end tags. - static inline int TagSize(int field_number, FieldDescriptor::Type type); - - // These procedures can be used to implement the methods of Message which - // handle parsing and serialization of the protocol buffer wire format - // using only the Reflection interface. When you ask the protocol - // compiler to optimize for code size rather than speed, it will implement - // those methods in terms of these procedures. Of course, these are much - // slower than the specialized implementations which the protocol compiler - // generates when told to optimize for speed. - - // Read a message in protocol buffer wire format. - // - // This procedure reads either to the end of the input stream or through - // a WIRETYPE_END_GROUP tag ending the message, whichever comes first. - // It returns false if the input is invalid. - // - // Required fields are NOT checked by this method. You must call - // IsInitialized() on the resulting message yourself. - static bool ParseAndMergePartial(io::CodedInputStream* input, - Message* message); - - // Serialize a message in protocol buffer wire format. - // - // Any embedded messages within the message must have their correct sizes - // cached. However, the top-level message need not; its size is passed as - // a parameter to this procedure. - // - // These return false iff the underlying stream returns a write error. - static void SerializeWithCachedSizes( - const Message& message, - int size, io::CodedOutputStream* output); - - // Implements Message::ByteSize() via reflection. WARNING: The result - // of this method is *not* cached anywhere. However, all embedded messages - // will have their ByteSize() methods called, so their sizes will be cached. - // Therefore, calling this method is sufficient to allow you to call - // WireFormat::SerializeWithCachedSizes() on the same object. - static int ByteSize(const Message& message); - - // ----------------------------------------------------------------- - // Helpers for dealing with unknown fields - - // Skips a field value of the given WireType. The input should start - // positioned immediately after the tag. If unknown_fields is non-NULL, - // the contents of the field will be added to it. - static bool SkipField(io::CodedInputStream* input, uint32 tag, - UnknownFieldSet* unknown_fields); - - // Reads and ignores a message from the input. If unknown_fields is non-NULL, - // the contents will be added to it. - static bool SkipMessage(io::CodedInputStream* input, - UnknownFieldSet* unknown_fields); - - // Write the contents of an UnknownFieldSet to the output. - static void SerializeUnknownFields(const UnknownFieldSet& unknown_fields, - io::CodedOutputStream* output); - // Same as above, except writing directly to the provided buffer. - // Requires that the buffer have sufficient capacity for - // ComputeUnknownFieldsSize(unknown_fields). - // - // Returns a pointer past the last written byte. - static uint8* SerializeUnknownFieldsToArray( - const UnknownFieldSet& unknown_fields, - uint8* target); - - // Same thing except for messages that have the message_set_wire_format - // option. - static void SerializeUnknownMessageSetItems( - const UnknownFieldSet& unknown_fields, - io::CodedOutputStream* output); - // Same as above, except writing directly to the provided buffer. - // Requires that the buffer have sufficient capacity for - // ComputeUnknownMessageSetItemsSize(unknown_fields). - // - // Returns a pointer past the last written byte. - static uint8* SerializeUnknownMessageSetItemsToArray( - const UnknownFieldSet& unknown_fields, - uint8* target); - - // Compute the size of the UnknownFieldSet on the wire. - static int ComputeUnknownFieldsSize(const UnknownFieldSet& unknown_fields); - - // Same thing except for messages that have the message_set_wire_format - // option. - static int ComputeUnknownMessageSetItemsSize( - const UnknownFieldSet& unknown_fields); - - - // Helper functions for encoding and decoding tags. (Inlined below and in - // _inl.h) - // - // This is different from MakeTag(field->number(), field->type()) in the case - // of packed repeated fields. - static uint32 MakeTag(const FieldDescriptor* field); - - // Parse a single field. The input should start out positioned immidately - // after the tag. - static bool ParseAndMergeField( - uint32 tag, - const FieldDescriptor* field, // May be NULL for unknown - Message* message, - io::CodedInputStream* input); - - // Serialize a single field. - static void SerializeFieldWithCachedSizes( - const FieldDescriptor* field, // Cannot be NULL - const Message& message, - io::CodedOutputStream* output); - - // Compute size of a single field. If the field is a message type, this - // will call ByteSize() for the embedded message, insuring that it caches - // its size. - static int FieldByteSize( - const FieldDescriptor* field, // Cannot be NULL - const Message& message); - - // Parse/serialize a MessageSet::Item group. Used with messages that use - // opion message_set_wire_format = true. - static bool ParseAndMergeMessageSetItem( - io::CodedInputStream* input, - Message* message); - static void SerializeMessageSetItemWithCachedSizes( - const FieldDescriptor* field, - const Message& message, - io::CodedOutputStream* output); - static int MessageSetItemByteSize( - const FieldDescriptor* field, - const Message& message); - - // Computes the byte size of a field, excluding tags. For packed fields, it - // only includes the size of the raw data, and not the size of the total - // length, but for other length-delimited types, the size of the length is - // included. - static int FieldDataOnlyByteSize( - const FieldDescriptor* field, // Cannot be NULL - const Message& message); - - enum Operation { - PARSE, - SERIALIZE, - }; - - // Verifies that a string field is valid UTF8, logging an error if not. - static void VerifyUTF8String(const char* data, int size, Operation op); - - private: - // Verifies that a string field is valid UTF8, logging an error if not. - static void VerifyUTF8StringFallback( - const char* data, - int size, - Operation op); - - - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormat); -}; - -// Subclass of FieldSkipper which saves skipped fields to an UnknownFieldSet. -class LIBPROTOBUF_EXPORT UnknownFieldSetFieldSkipper : public FieldSkipper { - public: - UnknownFieldSetFieldSkipper(UnknownFieldSet* unknown_fields) - : unknown_fields_(unknown_fields) {} - virtual ~UnknownFieldSetFieldSkipper() {} - - // implements FieldSkipper ----------------------------------------- - virtual bool SkipField(io::CodedInputStream* input, uint32 tag); - virtual bool SkipMessage(io::CodedInputStream* input); - virtual void SkipUnknownEnum(int field_number, int value); - - private: - UnknownFieldSet* unknown_fields_; -}; - -// inline methods ==================================================== - -inline WireFormatLite::WireType WireFormat::WireTypeForField( - const FieldDescriptor* field) { - if (field->options().packed()) { - return WireFormatLite::WIRETYPE_LENGTH_DELIMITED; - } else { - return WireTypeForFieldType(field->type()); - } -} - -inline WireFormatLite::WireType WireFormat::WireTypeForFieldType( - FieldDescriptor::Type type) { - // Some compilers don't like enum -> enum casts, so we implicit_cast to - // int first. - return WireFormatLite::WireTypeForFieldType( - static_cast( - implicit_cast(type))); -} - -inline uint32 WireFormat::MakeTag(const FieldDescriptor* field) { - return WireFormatLite::MakeTag(field->number(), WireTypeForField(field)); -} - -inline int WireFormat::TagSize(int field_number, FieldDescriptor::Type type) { - // Some compilers don't like enum -> enum casts, so we implicit_cast to - // int first. - return WireFormatLite::TagSize(field_number, - static_cast( - implicit_cast(type))); -} - -inline void WireFormat::VerifyUTF8String(const char* data, int size, - WireFormat::Operation op) { -#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - WireFormat::VerifyUTF8StringFallback(data, size, op); -#endif -} - - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_WIRE_FORMAT_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h b/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h deleted file mode 100644 index e3d5b2d8..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +++ /dev/null @@ -1,620 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// atenasio@google.com (Chris Atenasio) (ZigZag transform) -// wink@google.com (Wink Saville) (refactored from wire_format.h) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ -#define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ - -#include -#include - -namespace google { - -namespace protobuf { - template class RepeatedField; // repeated_field.h - namespace io { - class CodedInputStream; // coded_stream.h - class CodedOutputStream; // coded_stream.h - } -} - -namespace protobuf { -namespace internal { - -class StringPieceField; - -// This class is for internal use by the protocol buffer library and by -// protocol-complier-generated message classes. It must not be called -// directly by clients. -// -// This class contains helpers for implementing the binary protocol buffer -// wire format without the need for reflection. Use WireFormat when using -// reflection. -// -// This class is really a namespace that contains only static methods. -class LIBPROTOBUF_EXPORT WireFormatLite { - public: - - // ----------------------------------------------------------------- - // Helper constants and functions related to the format. These are - // mostly meant for internal and generated code to use. - - // The wire format is composed of a sequence of tag/value pairs, each - // of which contains the value of one field (or one element of a repeated - // field). Each tag is encoded as a varint. The lower bits of the tag - // identify its wire type, which specifies the format of the data to follow. - // The rest of the bits contain the field number. Each type of field (as - // declared by FieldDescriptor::Type, in descriptor.h) maps to one of - // these wire types. Immediately following each tag is the field's value, - // encoded in the format specified by the wire type. Because the tag - // identifies the encoding of this data, it is possible to skip - // unrecognized fields for forwards compatibility. - - enum WireType { - WIRETYPE_VARINT = 0, - WIRETYPE_FIXED64 = 1, - WIRETYPE_LENGTH_DELIMITED = 2, - WIRETYPE_START_GROUP = 3, - WIRETYPE_END_GROUP = 4, - WIRETYPE_FIXED32 = 5, - }; - - // Lite alternative to FieldDescriptor::Type. Must be kept in sync. - enum FieldType { - TYPE_DOUBLE = 1, - TYPE_FLOAT = 2, - TYPE_INT64 = 3, - TYPE_UINT64 = 4, - TYPE_INT32 = 5, - TYPE_FIXED64 = 6, - TYPE_FIXED32 = 7, - TYPE_BOOL = 8, - TYPE_STRING = 9, - TYPE_GROUP = 10, - TYPE_MESSAGE = 11, - TYPE_BYTES = 12, - TYPE_UINT32 = 13, - TYPE_ENUM = 14, - TYPE_SFIXED32 = 15, - TYPE_SFIXED64 = 16, - TYPE_SINT32 = 17, - TYPE_SINT64 = 18, - MAX_FIELD_TYPE = 18, - }; - - // Lite alternative to FieldDescriptor::CppType. Must be kept in sync. - enum CppType { - CPPTYPE_INT32 = 1, - CPPTYPE_INT64 = 2, - CPPTYPE_UINT32 = 3, - CPPTYPE_UINT64 = 4, - CPPTYPE_DOUBLE = 5, - CPPTYPE_FLOAT = 6, - CPPTYPE_BOOL = 7, - CPPTYPE_ENUM = 8, - CPPTYPE_STRING = 9, - CPPTYPE_MESSAGE = 10, - MAX_CPPTYPE = 10, - }; - - // Helper method to get the CppType for a particular Type. - static CppType FieldTypeToCppType(FieldType type); - - // Given a FieldSescriptor::Type return its WireType - static inline WireFormatLite::WireType WireTypeForFieldType( - WireFormatLite::FieldType type) { - return kWireTypeForFieldType[type]; - } - - // Number of bits in a tag which identify the wire type. - static const int kTagTypeBits = 3; - // Mask for those bits. - static const uint32 kTagTypeMask = (1 << kTagTypeBits) - 1; - - // Helper functions for encoding and decoding tags. (Inlined below and in - // _inl.h) - // - // This is different from MakeTag(field->number(), field->type()) in the case - // of packed repeated fields. - static uint32 MakeTag(int field_number, WireType type); - static WireType GetTagWireType(uint32 tag); - static int GetTagFieldNumber(uint32 tag); - - // Compute the byte size of a tag. For groups, this includes both the start - // and end tags. - static inline int TagSize(int field_number, WireFormatLite::FieldType type); - - // Skips a field value with the given tag. The input should start - // positioned immediately after the tag. Skipped values are simply discarded, - // not recorded anywhere. See WireFormat::SkipField() for a version that - // records to an UnknownFieldSet. - static bool SkipField(io::CodedInputStream* input, uint32 tag); - - // Reads and ignores a message from the input. Skipped values are simply - // discarded, not recorded anywhere. See WireFormat::SkipMessage() for a - // version that records to an UnknownFieldSet. - static bool SkipMessage(io::CodedInputStream* input); - -// This macro does the same thing as WireFormatLite::MakeTag(), but the -// result is usable as a compile-time constant, which makes it usable -// as a switch case or a template input. WireFormatLite::MakeTag() is more -// type-safe, though, so prefer it if possible. -#define GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(FIELD_NUMBER, TYPE) \ - static_cast( \ - ((FIELD_NUMBER) << ::google::protobuf::internal::WireFormatLite::kTagTypeBits) \ - | (TYPE)) - - // These are the tags for the old MessageSet format, which was defined as: - // message MessageSet { - // repeated group Item = 1 { - // required int32 type_id = 2; - // required string message = 3; - // } - // } - static const int kMessageSetItemNumber = 1; - static const int kMessageSetTypeIdNumber = 2; - static const int kMessageSetMessageNumber = 3; - static const int kMessageSetItemStartTag = - GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetItemNumber, - WireFormatLite::WIRETYPE_START_GROUP); - static const int kMessageSetItemEndTag = - GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetItemNumber, - WireFormatLite::WIRETYPE_END_GROUP); - static const int kMessageSetTypeIdTag = - GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetTypeIdNumber, - WireFormatLite::WIRETYPE_VARINT); - static const int kMessageSetMessageTag = - GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kMessageSetMessageNumber, - WireFormatLite::WIRETYPE_LENGTH_DELIMITED); - - // Byte size of all tags of a MessageSet::Item combined. - static const int kMessageSetItemTagsSize; - - // Helper functions for converting between floats/doubles and IEEE-754 - // uint32s/uint64s so that they can be written. (Assumes your platform - // uses IEEE-754 floats.) - static uint32 EncodeFloat(float value); - static float DecodeFloat(uint32 value); - static uint64 EncodeDouble(double value); - static double DecodeDouble(uint64 value); - - // Helper functions for mapping signed integers to unsigned integers in - // such a way that numbers with small magnitudes will encode to smaller - // varints. If you simply static_cast a negative number to an unsigned - // number and varint-encode it, it will always take 10 bytes, defeating - // the purpose of varint. So, for the "sint32" and "sint64" field types, - // we ZigZag-encode the values. - static uint32 ZigZagEncode32(int32 n); - static int32 ZigZagDecode32(uint32 n); - static uint64 ZigZagEncode64(int64 n); - static int64 ZigZagDecode64(uint64 n); - - // ================================================================= - // Methods for reading/writing individual field. The implementations - // of these methods are defined in wire_format_lite_inl.h; you must #include - // that file to use these. - -// Avoid ugly line wrapping -#define input io::CodedInputStream* input -#define output io::CodedOutputStream* output -#define field_number int field_number -#define INL GOOGLE_ATTRIBUTE_ALWAYS_INLINE - - // Read fields, not including tags. The assumption is that you already - // read the tag to determine what field to read. - - // For primitive fields, we just use a templatized routine parameterized by - // the represented type and the FieldType. These are specialized with the - // appropriate definition for each declared type. - template - static inline bool ReadPrimitive(input, CType* value) INL; - - // Reads repeated primitive values, with optimizations for repeats. - // tag_size and tag should both be compile-time constants provided by the - // protocol compiler. - template - static inline bool ReadRepeatedPrimitive(int tag_size, - uint32 tag, - input, - RepeatedField* value) INL; - - // Identical to ReadRepeatedPrimitive, except will not inline the - // implementation. - template - static bool ReadRepeatedPrimitiveNoInline(int tag_size, - uint32 tag, - input, - RepeatedField* value); - - // Reads a primitive value directly from the provided buffer. It returns a - // pointer past the segment of data that was read. - // - // This is only implemented for the types with fixed wire size, e.g. - // float, double, and the (s)fixed* types. - template - static inline const uint8* ReadPrimitiveFromArray(const uint8* buffer, - CType* value) INL; - - // Reads a primitive packed field. - // - // This is only implemented for packable types. - template - static inline bool ReadPackedPrimitive(input, - RepeatedField* value) INL; - - // Identical to ReadPackedPrimitive, except will not inline the - // implementation. - template - static bool ReadPackedPrimitiveNoInline(input, RepeatedField* value); - - // Read a packed enum field. Values for which is_valid() returns false are - // dropped. - static bool ReadPackedEnumNoInline(input, - bool (*is_valid)(int), - RepeatedField* value); - - static bool ReadString(input, string* value); - static bool ReadBytes (input, string* value); - - static inline bool ReadGroup (field_number, input, MessageLite* value); - static inline bool ReadMessage(input, MessageLite* value); - - // Like above, but de-virtualize the call to MergePartialFromCodedStream(). - // The pointer must point at an instance of MessageType, *not* a subclass (or - // the subclass must not override MergePartialFromCodedStream()). - template - static inline bool ReadGroupNoVirtual(field_number, input, - MessageType* value); - template - static inline bool ReadMessageNoVirtual(input, MessageType* value); - - // Write a tag. The Write*() functions typically include the tag, so - // normally there's no need to call this unless using the Write*NoTag() - // variants. - static inline void WriteTag(field_number, WireType type, output) INL; - - // Write fields, without tags. - static inline void WriteInt32NoTag (int32 value, output) INL; - static inline void WriteInt64NoTag (int64 value, output) INL; - static inline void WriteUInt32NoTag (uint32 value, output) INL; - static inline void WriteUInt64NoTag (uint64 value, output) INL; - static inline void WriteSInt32NoTag (int32 value, output) INL; - static inline void WriteSInt64NoTag (int64 value, output) INL; - static inline void WriteFixed32NoTag (uint32 value, output) INL; - static inline void WriteFixed64NoTag (uint64 value, output) INL; - static inline void WriteSFixed32NoTag(int32 value, output) INL; - static inline void WriteSFixed64NoTag(int64 value, output) INL; - static inline void WriteFloatNoTag (float value, output) INL; - static inline void WriteDoubleNoTag (double value, output) INL; - static inline void WriteBoolNoTag (bool value, output) INL; - static inline void WriteEnumNoTag (int value, output) INL; - - // Write fields, including tags. - static void WriteInt32 (field_number, int32 value, output); - static void WriteInt64 (field_number, int64 value, output); - static void WriteUInt32 (field_number, uint32 value, output); - static void WriteUInt64 (field_number, uint64 value, output); - static void WriteSInt32 (field_number, int32 value, output); - static void WriteSInt64 (field_number, int64 value, output); - static void WriteFixed32 (field_number, uint32 value, output); - static void WriteFixed64 (field_number, uint64 value, output); - static void WriteSFixed32(field_number, int32 value, output); - static void WriteSFixed64(field_number, int64 value, output); - static void WriteFloat (field_number, float value, output); - static void WriteDouble (field_number, double value, output); - static void WriteBool (field_number, bool value, output); - static void WriteEnum (field_number, int value, output); - - static void WriteString(field_number, const string& value, output); - static void WriteBytes (field_number, const string& value, output); - - static void WriteGroup( - field_number, const MessageLite& value, output); - static void WriteMessage( - field_number, const MessageLite& value, output); - // Like above, but these will check if the output stream has enough - // space to write directly to a flat array. - static void WriteGroupMaybeToArray( - field_number, const MessageLite& value, output); - static void WriteMessageMaybeToArray( - field_number, const MessageLite& value, output); - - // Like above, but de-virtualize the call to SerializeWithCachedSizes(). The - // pointer must point at an instance of MessageType, *not* a subclass (or - // the subclass must not override SerializeWithCachedSizes()). - template - static inline void WriteGroupNoVirtual( - field_number, const MessageType& value, output); - template - static inline void WriteMessageNoVirtual( - field_number, const MessageType& value, output); - -#undef output -#define output uint8* target - - // Like above, but use only *ToArray methods of CodedOutputStream. - static inline uint8* WriteTagToArray(field_number, WireType type, output) INL; - - // Write fields, without tags. - static inline uint8* WriteInt32NoTagToArray (int32 value, output) INL; - static inline uint8* WriteInt64NoTagToArray (int64 value, output) INL; - static inline uint8* WriteUInt32NoTagToArray (uint32 value, output) INL; - static inline uint8* WriteUInt64NoTagToArray (uint64 value, output) INL; - static inline uint8* WriteSInt32NoTagToArray (int32 value, output) INL; - static inline uint8* WriteSInt64NoTagToArray (int64 value, output) INL; - static inline uint8* WriteFixed32NoTagToArray (uint32 value, output) INL; - static inline uint8* WriteFixed64NoTagToArray (uint64 value, output) INL; - static inline uint8* WriteSFixed32NoTagToArray(int32 value, output) INL; - static inline uint8* WriteSFixed64NoTagToArray(int64 value, output) INL; - static inline uint8* WriteFloatNoTagToArray (float value, output) INL; - static inline uint8* WriteDoubleNoTagToArray (double value, output) INL; - static inline uint8* WriteBoolNoTagToArray (bool value, output) INL; - static inline uint8* WriteEnumNoTagToArray (int value, output) INL; - - // Write fields, including tags. - static inline uint8* WriteInt32ToArray( - field_number, int32 value, output) INL; - static inline uint8* WriteInt64ToArray( - field_number, int64 value, output) INL; - static inline uint8* WriteUInt32ToArray( - field_number, uint32 value, output) INL; - static inline uint8* WriteUInt64ToArray( - field_number, uint64 value, output) INL; - static inline uint8* WriteSInt32ToArray( - field_number, int32 value, output) INL; - static inline uint8* WriteSInt64ToArray( - field_number, int64 value, output) INL; - static inline uint8* WriteFixed32ToArray( - field_number, uint32 value, output) INL; - static inline uint8* WriteFixed64ToArray( - field_number, uint64 value, output) INL; - static inline uint8* WriteSFixed32ToArray( - field_number, int32 value, output) INL; - static inline uint8* WriteSFixed64ToArray( - field_number, int64 value, output) INL; - static inline uint8* WriteFloatToArray( - field_number, float value, output) INL; - static inline uint8* WriteDoubleToArray( - field_number, double value, output) INL; - static inline uint8* WriteBoolToArray( - field_number, bool value, output) INL; - static inline uint8* WriteEnumToArray( - field_number, int value, output) INL; - - static inline uint8* WriteStringToArray( - field_number, const string& value, output) INL; - static inline uint8* WriteBytesToArray( - field_number, const string& value, output) INL; - - static inline uint8* WriteGroupToArray( - field_number, const MessageLite& value, output) INL; - static inline uint8* WriteMessageToArray( - field_number, const MessageLite& value, output) INL; - - // Like above, but de-virtualize the call to SerializeWithCachedSizes(). The - // pointer must point at an instance of MessageType, *not* a subclass (or - // the subclass must not override SerializeWithCachedSizes()). - template - static inline uint8* WriteGroupNoVirtualToArray( - field_number, const MessageType& value, output) INL; - template - static inline uint8* WriteMessageNoVirtualToArray( - field_number, const MessageType& value, output) INL; - -#undef output -#undef input -#undef INL - -#undef field_number - - // Compute the byte size of a field. The XxSize() functions do NOT include - // the tag, so you must also call TagSize(). (This is because, for repeated - // fields, you should only call TagSize() once and multiply it by the element - // count, but you may have to call XxSize() for each individual element.) - static inline int Int32Size ( int32 value); - static inline int Int64Size ( int64 value); - static inline int UInt32Size (uint32 value); - static inline int UInt64Size (uint64 value); - static inline int SInt32Size ( int32 value); - static inline int SInt64Size ( int64 value); - static inline int EnumSize ( int value); - - // These types always have the same size. - static const int kFixed32Size = 4; - static const int kFixed64Size = 8; - static const int kSFixed32Size = 4; - static const int kSFixed64Size = 8; - static const int kFloatSize = 4; - static const int kDoubleSize = 8; - static const int kBoolSize = 1; - - static inline int StringSize(const string& value); - static inline int BytesSize (const string& value); - - static inline int GroupSize (const MessageLite& value); - static inline int MessageSize(const MessageLite& value); - - // Like above, but de-virtualize the call to ByteSize(). The - // pointer must point at an instance of MessageType, *not* a subclass (or - // the subclass must not override ByteSize()). - template - static inline int GroupSizeNoVirtual (const MessageType& value); - template - static inline int MessageSizeNoVirtual(const MessageType& value); - - private: - // A helper method for the repeated primitive reader. This method has - // optimizations for primitive types that have fixed size on the wire, and - // can be read using potentially faster paths. - template - static inline bool ReadRepeatedFixedSizePrimitive( - int tag_size, - uint32 tag, - google::protobuf::io::CodedInputStream* input, - RepeatedField* value) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - - static const CppType kFieldTypeToCppTypeMap[]; - static const WireFormatLite::WireType kWireTypeForFieldType[]; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormatLite); -}; - -// A class which deals with unknown values. The default implementation just -// discards them. WireFormat defines a subclass which writes to an -// UnknownFieldSet. This class is used by ExtensionSet::ParseField(), since -// ExtensionSet is part of the lite library but UnknownFieldSet is not. -class LIBPROTOBUF_EXPORT FieldSkipper { - public: - FieldSkipper() {} - virtual ~FieldSkipper() {} - - // Skip a field whose tag has already been consumed. - virtual bool SkipField(io::CodedInputStream* input, uint32 tag); - - // Skip an entire message or group, up to an end-group tag (which is consumed) - // or end-of-stream. - virtual bool SkipMessage(io::CodedInputStream* input); - - // Deal with an already-parsed unrecognized enum value. The default - // implementation does nothing, but the UnknownFieldSet-based implementation - // saves it as an unknown varint. - virtual void SkipUnknownEnum(int field_number, int value); -}; - -// inline methods ==================================================== - -inline WireFormatLite::CppType -WireFormatLite::FieldTypeToCppType(FieldType type) { - return kFieldTypeToCppTypeMap[type]; -} - -inline uint32 WireFormatLite::MakeTag(int field_number, WireType type) { - return GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(field_number, type); -} - -inline WireFormatLite::WireType WireFormatLite::GetTagWireType(uint32 tag) { - return static_cast(tag & kTagTypeMask); -} - -inline int WireFormatLite::GetTagFieldNumber(uint32 tag) { - return static_cast(tag >> kTagTypeBits); -} - -inline int WireFormatLite::TagSize(int field_number, - WireFormatLite::FieldType type) { - int result = io::CodedOutputStream::VarintSize32( - field_number << kTagTypeBits); - if (type == TYPE_GROUP) { - // Groups have both a start and an end tag. - return result * 2; - } else { - return result; - } -} - -inline uint32 WireFormatLite::EncodeFloat(float value) { - union {float f; uint32 i;}; - f = value; - return i; -} - -inline float WireFormatLite::DecodeFloat(uint32 value) { - union {float f; uint32 i;}; - i = value; - return f; -} - -inline uint64 WireFormatLite::EncodeDouble(double value) { - union {double f; uint64 i;}; - f = value; - return i; -} - -inline double WireFormatLite::DecodeDouble(uint64 value) { - union {double f; uint64 i;}; - i = value; - return f; -} - -// ZigZag Transform: Encodes signed integers so that they can be -// effectively used with varint encoding. -// -// varint operates on unsigned integers, encoding smaller numbers into -// fewer bytes. If you try to use it on a signed integer, it will treat -// this number as a very large unsigned integer, which means that even -// small signed numbers like -1 will take the maximum number of bytes -// (10) to encode. ZigZagEncode() maps signed integers to unsigned -// in such a way that those with a small absolute value will have smaller -// encoded values, making them appropriate for encoding using varint. -// -// int32 -> uint32 -// ------------------------- -// 0 -> 0 -// -1 -> 1 -// 1 -> 2 -// -2 -> 3 -// ... -> ... -// 2147483647 -> 4294967294 -// -2147483648 -> 4294967295 -// -// >> encode >> -// << decode << - -inline uint32 WireFormatLite::ZigZagEncode32(int32 n) { - // Note: the right-shift must be arithmetic - return (n << 1) ^ (n >> 31); -} - -inline int32 WireFormatLite::ZigZagDecode32(uint32 n) { - return (n >> 1) ^ -static_cast(n & 1); -} - -inline uint64 WireFormatLite::ZigZagEncode64(int64 n) { - // Note: the right-shift must be arithmetic - return (n << 1) ^ (n >> 63); -} - -inline int64 WireFormatLite::ZigZagDecode64(uint64 n) { - return (n >> 1) ^ -static_cast(n & 1); -} - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ diff --git a/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h b/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h deleted file mode 100644 index 103b0bd0..00000000 --- a/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +++ /dev/null @@ -1,774 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// wink@google.com (Wink Saville) (refactored from wire_format.h) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ -#define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ - -#include -#include -#include -#include -#include -#include -#include - - -namespace google { -namespace protobuf { -namespace internal { - -// Implementation details of ReadPrimitive. - -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - int32* value) { - uint32 temp; - if (!input->ReadVarint32(&temp)) return false; - *value = static_cast(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - int64* value) { - uint64 temp; - if (!input->ReadVarint64(&temp)) return false; - *value = static_cast(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - uint32* value) { - return input->ReadVarint32(value); -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - uint64* value) { - return input->ReadVarint64(value); -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - int32* value) { - uint32 temp; - if (!input->ReadVarint32(&temp)) return false; - *value = ZigZagDecode32(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - int64* value) { - uint64 temp; - if (!input->ReadVarint64(&temp)) return false; - *value = ZigZagDecode64(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - uint32* value) { - return input->ReadLittleEndian32(value); -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - uint64* value) { - return input->ReadLittleEndian64(value); -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - int32* value) { - uint32 temp; - if (!input->ReadLittleEndian32(&temp)) return false; - *value = static_cast(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - int64* value) { - uint64 temp; - if (!input->ReadLittleEndian64(&temp)) return false; - *value = static_cast(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - float* value) { - uint32 temp; - if (!input->ReadLittleEndian32(&temp)) return false; - *value = DecodeFloat(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - double* value) { - uint64 temp; - if (!input->ReadLittleEndian64(&temp)) return false; - *value = DecodeDouble(temp); - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - bool* value) { - uint32 temp; - if (!input->ReadVarint32(&temp)) return false; - *value = temp != 0; - return true; -} -template <> -inline bool WireFormatLite::ReadPrimitive( - io::CodedInputStream* input, - int* value) { - uint32 temp; - if (!input->ReadVarint32(&temp)) return false; - *value = static_cast(temp); - return true; -} - -template <> -inline const uint8* WireFormatLite::ReadPrimitiveFromArray< - uint32, WireFormatLite::TYPE_FIXED32>( - const uint8* buffer, - uint32* value) { - return io::CodedInputStream::ReadLittleEndian32FromArray(buffer, value); -} -template <> -inline const uint8* WireFormatLite::ReadPrimitiveFromArray< - uint64, WireFormatLite::TYPE_FIXED64>( - const uint8* buffer, - uint64* value) { - return io::CodedInputStream::ReadLittleEndian64FromArray(buffer, value); -} -template <> -inline const uint8* WireFormatLite::ReadPrimitiveFromArray< - int32, WireFormatLite::TYPE_SFIXED32>( - const uint8* buffer, - int32* value) { - uint32 temp; - buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp); - *value = static_cast(temp); - return buffer; -} -template <> -inline const uint8* WireFormatLite::ReadPrimitiveFromArray< - int64, WireFormatLite::TYPE_SFIXED64>( - const uint8* buffer, - int64* value) { - uint64 temp; - buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp); - *value = static_cast(temp); - return buffer; -} -template <> -inline const uint8* WireFormatLite::ReadPrimitiveFromArray< - float, WireFormatLite::TYPE_FLOAT>( - const uint8* buffer, - float* value) { - uint32 temp; - buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp); - *value = DecodeFloat(temp); - return buffer; -} -template <> -inline const uint8* WireFormatLite::ReadPrimitiveFromArray< - double, WireFormatLite::TYPE_DOUBLE>( - const uint8* buffer, - double* value) { - uint64 temp; - buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp); - *value = DecodeDouble(temp); - return buffer; -} - -template -inline bool WireFormatLite::ReadRepeatedPrimitive(int, // tag_size, unused. - uint32 tag, - io::CodedInputStream* input, - RepeatedField* values) { - CType value; - if (!ReadPrimitive(input, &value)) return false; - values->Add(value); - int elements_already_reserved = values->Capacity() - values->size(); - while (elements_already_reserved > 0 && input->ExpectTag(tag)) { - if (!ReadPrimitive(input, &value)) return false; - values->AddAlreadyReserved(value); - elements_already_reserved--; - } - return true; -} - -template -inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive( - int tag_size, - uint32 tag, - io::CodedInputStream* input, - RepeatedField* values) { - GOOGLE_DCHECK_EQ(UInt32Size(tag), tag_size); - CType value; - if (!ReadPrimitive(input, &value)) - return false; - values->Add(value); - - // For fixed size values, repeated values can be read more quickly by - // reading directly from a raw array. - // - // We can get a tight loop by only reading as many elements as can be - // added to the RepeatedField without having to do any resizing. Additionally, - // we only try to read as many elements as are available from the current - // buffer space. Doing so avoids having to perform boundary checks when - // reading the value: the maximum number of elements that can be read is - // known outside of the loop. - const void* void_pointer; - int size; - input->GetDirectBufferPointerInline(&void_pointer, &size); - if (size > 0) { - const uint8* buffer = reinterpret_cast(void_pointer); - // The number of bytes each type occupies on the wire. - const int per_value_size = tag_size + sizeof(value); - - int elements_available = min(values->Capacity() - values->size(), - size / per_value_size); - int num_read = 0; - while (num_read < elements_available && - (buffer = io::CodedInputStream::ExpectTagFromArray( - buffer, tag)) != NULL) { - buffer = ReadPrimitiveFromArray(buffer, &value); - values->AddAlreadyReserved(value); - ++num_read; - } - const int read_bytes = num_read * per_value_size; - if (read_bytes > 0) { - input->Skip(read_bytes); - } - } - return true; -} - -// Specializations of ReadRepeatedPrimitive for the fixed size types, which use -// the optimized code path. -#define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \ -template <> \ -inline bool WireFormatLite::ReadRepeatedPrimitive< \ - CPPTYPE, WireFormatLite::DECLARED_TYPE>( \ - int tag_size, \ - uint32 tag, \ - io::CodedInputStream* input, \ - RepeatedField* values) { \ - return ReadRepeatedFixedSizePrimitive< \ - CPPTYPE, WireFormatLite::DECLARED_TYPE>( \ - tag_size, tag, input, values); \ -} - -READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32); -READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64); -READ_REPEATED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32); -READ_REPEATED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64); -READ_REPEATED_FIXED_SIZE_PRIMITIVE(float, TYPE_FLOAT); -READ_REPEATED_FIXED_SIZE_PRIMITIVE(double, TYPE_DOUBLE); - -#undef READ_REPEATED_FIXED_SIZE_PRIMITIVE - -template -bool WireFormatLite::ReadRepeatedPrimitiveNoInline( - int tag_size, - uint32 tag, - io::CodedInputStream* input, - RepeatedField* value) { - return ReadRepeatedPrimitive( - tag_size, tag, input, value); -} - -template -inline bool WireFormatLite::ReadPackedPrimitive(io::CodedInputStream* input, - RepeatedField* values) { - uint32 length; - if (!input->ReadVarint32(&length)) return false; - io::CodedInputStream::Limit limit = input->PushLimit(length); - while (input->BytesUntilLimit() > 0) { - CType value; - if (!ReadPrimitive(input, &value)) return false; - values->Add(value); - } - input->PopLimit(limit); - return true; -} - -template -bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input, - RepeatedField* values) { - return ReadPackedPrimitive(input, values); -} - - -inline bool WireFormatLite::ReadGroup(int field_number, - io::CodedInputStream* input, - MessageLite* value) { - if (!input->IncrementRecursionDepth()) return false; - if (!value->MergePartialFromCodedStream(input)) return false; - input->DecrementRecursionDepth(); - // Make sure the last thing read was an end tag for this group. - if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) { - return false; - } - return true; -} -inline bool WireFormatLite::ReadMessage(io::CodedInputStream* input, - MessageLite* value) { - uint32 length; - if (!input->ReadVarint32(&length)) return false; - if (!input->IncrementRecursionDepth()) return false; - io::CodedInputStream::Limit limit = input->PushLimit(length); - if (!value->MergePartialFromCodedStream(input)) return false; - // Make sure that parsing stopped when the limit was hit, not at an endgroup - // tag. - if (!input->ConsumedEntireMessage()) return false; - input->PopLimit(limit); - input->DecrementRecursionDepth(); - return true; -} - -// We name the template parameter something long and extremely unlikely to occur -// elsewhere because a *qualified* member access expression designed to avoid -// virtual dispatch, C++03 [basic.lookup.classref] 3.4.5/4 requires that the -// name of the qualifying class to be looked up both in the context of the full -// expression (finding the template parameter) and in the context of the object -// whose member we are accessing. This could potentially find a nested type -// within that object. The standard goes on to require these names to refer to -// the same entity, which this collision would violate. The lack of a safe way -// to avoid this collision appears to be a defect in the standard, but until it -// is corrected, we choose the name to avoid accidental collisions. -template -inline bool WireFormatLite::ReadGroupNoVirtual( - int field_number, io::CodedInputStream* input, - MessageType_WorkAroundCppLookupDefect* value) { - if (!input->IncrementRecursionDepth()) return false; - if (!value-> - MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input)) - return false; - input->DecrementRecursionDepth(); - // Make sure the last thing read was an end tag for this group. - if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) { - return false; - } - return true; -} -template -inline bool WireFormatLite::ReadMessageNoVirtual( - io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) { - uint32 length; - if (!input->ReadVarint32(&length)) return false; - if (!input->IncrementRecursionDepth()) return false; - io::CodedInputStream::Limit limit = input->PushLimit(length); - if (!value-> - MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input)) - return false; - // Make sure that parsing stopped when the limit was hit, not at an endgroup - // tag. - if (!input->ConsumedEntireMessage()) return false; - input->PopLimit(limit); - input->DecrementRecursionDepth(); - return true; -} - -// =================================================================== - -inline void WireFormatLite::WriteTag(int field_number, WireType type, - io::CodedOutputStream* output) { - output->WriteTag(MakeTag(field_number, type)); -} - -inline void WireFormatLite::WriteInt32NoTag(int32 value, - io::CodedOutputStream* output) { - output->WriteVarint32SignExtended(value); -} -inline void WireFormatLite::WriteInt64NoTag(int64 value, - io::CodedOutputStream* output) { - output->WriteVarint64(static_cast(value)); -} -inline void WireFormatLite::WriteUInt32NoTag(uint32 value, - io::CodedOutputStream* output) { - output->WriteVarint32(value); -} -inline void WireFormatLite::WriteUInt64NoTag(uint64 value, - io::CodedOutputStream* output) { - output->WriteVarint64(value); -} -inline void WireFormatLite::WriteSInt32NoTag(int32 value, - io::CodedOutputStream* output) { - output->WriteVarint32(ZigZagEncode32(value)); -} -inline void WireFormatLite::WriteSInt64NoTag(int64 value, - io::CodedOutputStream* output) { - output->WriteVarint64(ZigZagEncode64(value)); -} -inline void WireFormatLite::WriteFixed32NoTag(uint32 value, - io::CodedOutputStream* output) { - output->WriteLittleEndian32(value); -} -inline void WireFormatLite::WriteFixed64NoTag(uint64 value, - io::CodedOutputStream* output) { - output->WriteLittleEndian64(value); -} -inline void WireFormatLite::WriteSFixed32NoTag(int32 value, - io::CodedOutputStream* output) { - output->WriteLittleEndian32(static_cast(value)); -} -inline void WireFormatLite::WriteSFixed64NoTag(int64 value, - io::CodedOutputStream* output) { - output->WriteLittleEndian64(static_cast(value)); -} -inline void WireFormatLite::WriteFloatNoTag(float value, - io::CodedOutputStream* output) { - output->WriteLittleEndian32(EncodeFloat(value)); -} -inline void WireFormatLite::WriteDoubleNoTag(double value, - io::CodedOutputStream* output) { - output->WriteLittleEndian64(EncodeDouble(value)); -} -inline void WireFormatLite::WriteBoolNoTag(bool value, - io::CodedOutputStream* output) { - output->WriteVarint32(value ? 1 : 0); -} -inline void WireFormatLite::WriteEnumNoTag(int value, - io::CodedOutputStream* output) { - output->WriteVarint32SignExtended(value); -} - -// See comment on ReadGroupNoVirtual to understand the need for this template -// parameter name. -template -inline void WireFormatLite::WriteGroupNoVirtual( - int field_number, const MessageType_WorkAroundCppLookupDefect& value, - io::CodedOutputStream* output) { - WriteTag(field_number, WIRETYPE_START_GROUP, output); - value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output); - WriteTag(field_number, WIRETYPE_END_GROUP, output); -} -template -inline void WireFormatLite::WriteMessageNoVirtual( - int field_number, const MessageType_WorkAroundCppLookupDefect& value, - io::CodedOutputStream* output) { - WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output); - output->WriteVarint32( - value.MessageType_WorkAroundCppLookupDefect::GetCachedSize()); - value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output); -} - -// =================================================================== - -inline uint8* WireFormatLite::WriteTagToArray(int field_number, - WireType type, - uint8* target) { - return io::CodedOutputStream::WriteTagToArray(MakeTag(field_number, type), - target); -} - -inline uint8* WireFormatLite::WriteInt32NoTagToArray(int32 value, - uint8* target) { - return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target); -} -inline uint8* WireFormatLite::WriteInt64NoTagToArray(int64 value, - uint8* target) { - return io::CodedOutputStream::WriteVarint64ToArray( - static_cast(value), target); -} -inline uint8* WireFormatLite::WriteUInt32NoTagToArray(uint32 value, - uint8* target) { - return io::CodedOutputStream::WriteVarint32ToArray(value, target); -} -inline uint8* WireFormatLite::WriteUInt64NoTagToArray(uint64 value, - uint8* target) { - return io::CodedOutputStream::WriteVarint64ToArray(value, target); -} -inline uint8* WireFormatLite::WriteSInt32NoTagToArray(int32 value, - uint8* target) { - return io::CodedOutputStream::WriteVarint32ToArray(ZigZagEncode32(value), - target); -} -inline uint8* WireFormatLite::WriteSInt64NoTagToArray(int64 value, - uint8* target) { - return io::CodedOutputStream::WriteVarint64ToArray(ZigZagEncode64(value), - target); -} -inline uint8* WireFormatLite::WriteFixed32NoTagToArray(uint32 value, - uint8* target) { - return io::CodedOutputStream::WriteLittleEndian32ToArray(value, target); -} -inline uint8* WireFormatLite::WriteFixed64NoTagToArray(uint64 value, - uint8* target) { - return io::CodedOutputStream::WriteLittleEndian64ToArray(value, target); -} -inline uint8* WireFormatLite::WriteSFixed32NoTagToArray(int32 value, - uint8* target) { - return io::CodedOutputStream::WriteLittleEndian32ToArray( - static_cast(value), target); -} -inline uint8* WireFormatLite::WriteSFixed64NoTagToArray(int64 value, - uint8* target) { - return io::CodedOutputStream::WriteLittleEndian64ToArray( - static_cast(value), target); -} -inline uint8* WireFormatLite::WriteFloatNoTagToArray(float value, - uint8* target) { - return io::CodedOutputStream::WriteLittleEndian32ToArray(EncodeFloat(value), - target); -} -inline uint8* WireFormatLite::WriteDoubleNoTagToArray(double value, - uint8* target) { - return io::CodedOutputStream::WriteLittleEndian64ToArray(EncodeDouble(value), - target); -} -inline uint8* WireFormatLite::WriteBoolNoTagToArray(bool value, - uint8* target) { - return io::CodedOutputStream::WriteVarint32ToArray(value ? 1 : 0, target); -} -inline uint8* WireFormatLite::WriteEnumNoTagToArray(int value, - uint8* target) { - return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target); -} - -inline uint8* WireFormatLite::WriteInt32ToArray(int field_number, - int32 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteInt32NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteInt64ToArray(int field_number, - int64 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteInt64NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteUInt32ToArray(int field_number, - uint32 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteUInt32NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteUInt64ToArray(int field_number, - uint64 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteUInt64NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteSInt32ToArray(int field_number, - int32 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteSInt32NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteSInt64ToArray(int field_number, - int64 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteSInt64NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteFixed32ToArray(int field_number, - uint32 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target); - return WriteFixed32NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteFixed64ToArray(int field_number, - uint64 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target); - return WriteFixed64NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteSFixed32ToArray(int field_number, - int32 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target); - return WriteSFixed32NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteSFixed64ToArray(int field_number, - int64 value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target); - return WriteSFixed64NoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteFloatToArray(int field_number, - float value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target); - return WriteFloatNoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteDoubleToArray(int field_number, - double value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target); - return WriteDoubleNoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteBoolToArray(int field_number, - bool value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteBoolNoTagToArray(value, target); -} -inline uint8* WireFormatLite::WriteEnumToArray(int field_number, - int value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_VARINT, target); - return WriteEnumNoTagToArray(value, target); -} - -inline uint8* WireFormatLite::WriteStringToArray(int field_number, - const string& value, - uint8* target) { - // String is for UTF-8 text only - // WARNING: In wire_format.cc, both strings and bytes are handled by - // WriteString() to avoid code duplication. If the implementations become - // different, you will need to update that usage. - target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); - target = io::CodedOutputStream::WriteVarint32ToArray(value.size(), target); - return io::CodedOutputStream::WriteStringToArray(value, target); -} -inline uint8* WireFormatLite::WriteBytesToArray(int field_number, - const string& value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); - target = io::CodedOutputStream::WriteVarint32ToArray(value.size(), target); - return io::CodedOutputStream::WriteStringToArray(value, target); -} - - -inline uint8* WireFormatLite::WriteGroupToArray(int field_number, - const MessageLite& value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); - target = value.SerializeWithCachedSizesToArray(target); - return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); -} -inline uint8* WireFormatLite::WriteMessageToArray(int field_number, - const MessageLite& value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); - target = io::CodedOutputStream::WriteVarint32ToArray( - value.GetCachedSize(), target); - return value.SerializeWithCachedSizesToArray(target); -} - -// See comment on ReadGroupNoVirtual to understand the need for this template -// parameter name. -template -inline uint8* WireFormatLite::WriteGroupNoVirtualToArray( - int field_number, const MessageType_WorkAroundCppLookupDefect& value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); - target = value.MessageType_WorkAroundCppLookupDefect - ::SerializeWithCachedSizesToArray(target); - return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); -} -template -inline uint8* WireFormatLite::WriteMessageNoVirtualToArray( - int field_number, const MessageType_WorkAroundCppLookupDefect& value, - uint8* target) { - target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); - target = io::CodedOutputStream::WriteVarint32ToArray( - value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target); - return value.MessageType_WorkAroundCppLookupDefect - ::SerializeWithCachedSizesToArray(target); -} - -// =================================================================== - -inline int WireFormatLite::Int32Size(int32 value) { - return io::CodedOutputStream::VarintSize32SignExtended(value); -} -inline int WireFormatLite::Int64Size(int64 value) { - return io::CodedOutputStream::VarintSize64(static_cast(value)); -} -inline int WireFormatLite::UInt32Size(uint32 value) { - return io::CodedOutputStream::VarintSize32(value); -} -inline int WireFormatLite::UInt64Size(uint64 value) { - return io::CodedOutputStream::VarintSize64(value); -} -inline int WireFormatLite::SInt32Size(int32 value) { - return io::CodedOutputStream::VarintSize32(ZigZagEncode32(value)); -} -inline int WireFormatLite::SInt64Size(int64 value) { - return io::CodedOutputStream::VarintSize64(ZigZagEncode64(value)); -} -inline int WireFormatLite::EnumSize(int value) { - return io::CodedOutputStream::VarintSize32SignExtended(value); -} - -inline int WireFormatLite::StringSize(const string& value) { - return io::CodedOutputStream::VarintSize32(value.size()) + - value.size(); -} -inline int WireFormatLite::BytesSize(const string& value) { - return io::CodedOutputStream::VarintSize32(value.size()) + - value.size(); -} - - -inline int WireFormatLite::GroupSize(const MessageLite& value) { - return value.ByteSize(); -} -inline int WireFormatLite::MessageSize(const MessageLite& value) { - int size = value.ByteSize(); - return io::CodedOutputStream::VarintSize32(size) + size; -} - -// See comment on ReadGroupNoVirtual to understand the need for this template -// parameter name. -template -inline int WireFormatLite::GroupSizeNoVirtual( - const MessageType_WorkAroundCppLookupDefect& value) { - return value.MessageType_WorkAroundCppLookupDefect::ByteSize(); -} -template -inline int WireFormatLite::MessageSizeNoVirtual( - const MessageType_WorkAroundCppLookupDefect& value) { - int size = value.MessageType_WorkAroundCppLookupDefect::ByteSize(); - return io::CodedOutputStream::VarintSize32(size) + size; -} - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ From 2797c017834d9bccd0719472e86a53a38a61c349 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 17 Jul 2013 14:21:36 -0600 Subject: [PATCH 0456/1191] Fix requires --- lib/protobuf/field/base_field.rb | 1 - lib/protobuf/message.rb | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 9cd34535..2458e281 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,4 +1,3 @@ -require 'protobuf' require 'protobuf/wire_type' require 'protobuf/field/field_array' diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index eda4f330..8882b44c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,3 +1,4 @@ +require 'stringio' require 'set' require 'protobuf/field' require 'protobuf/enum' @@ -214,7 +215,7 @@ def parse_from(stream) end def parse_from_string(string) - parse_from(StringIO.new(string)) + parse_from(::StringIO.new(string)) end def respond_to_has?(key) From 544058f2d2cfff0a136317c7259fbc7037e3ec68 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 17 Jul 2013 14:22:08 -0600 Subject: [PATCH 0457/1191] Add env variable PB_NO_NETWORKING. When present do not automatically require service/client code --- lib/protobuf.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index f2d87f60..a0c53441 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -92,20 +92,22 @@ def self.print_deprecation_warnings=(value) end -require 'protobuf/rpc/client' -require 'protobuf/rpc/service' - -env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') { - ::Protobuf::DEFAULT_CONNECTOR -}.to_s.downcase.strip.to_sym - -if ::Protobuf::CONNECTORS.include?(env_connector_type) - require "protobuf/#{env_connector_type}" -else - $stderr.puts <<-WARN +unless ENV.key?('PB_NO_NETWORKING') + require 'protobuf/rpc/client' + require 'protobuf/rpc/service' + + env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') { + ::Protobuf::DEFAULT_CONNECTOR + }.to_s.downcase.strip.to_sym + + if ::Protobuf::CONNECTORS.include?(env_connector_type) + require "protobuf/#{env_connector_type}" + else + $stderr.puts <<-WARN [WARNING] Require attempted on an invalid connector type '#{env_connector_type}'. Falling back to default '#{::Protobuf::DEFAULT_CONNECTOR}' connector. - WARN + WARN - require "protobuf/#{::Protobuf::DEFAULT_CONNECTOR}" + require "protobuf/#{::Protobuf::DEFAULT_CONNECTOR}" + end end From 6fd6c50acac283e88a4a08712c96a85cc9e1f55d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 17 Jul 2013 16:17:24 -0600 Subject: [PATCH 0458/1191] Add 2.5.0 plugin and descriptor proto definitions to support the plugin generator --- .../google/protobuf/compiler/plugin.pb.rb | 51 ++ .../google/protobuf/descriptor.pb.rb | 248 +++++++ proto/google/protobuf/compiler/plugin.proto | 147 +++++ proto/google/protobuf/descriptor.proto | 620 ++++++++++++++++++ 4 files changed, 1066 insertions(+) create mode 100644 lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb create mode 100644 lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb create mode 100644 proto/google/protobuf/compiler/plugin.proto create mode 100644 proto/google/protobuf/descriptor.proto diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb new file mode 100644 index 00000000..886b9f88 --- /dev/null +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -0,0 +1,51 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +## +# Imports +# +require 'google/protobuf/descriptor.pb' + +module Google + + module Protobuf + + module Compiler + + ## + # Message Classes + # + class CodeGeneratorRequest < ::Protobuf::Message; end + class CodeGeneratorResponse < ::Protobuf::Message + class File < ::Protobuf::Message; end + end + + ## + # Message Fields + # + class CodeGeneratorRequest + repeated ::Protobuf::Field::StringField, :file_to_generate, 1 + optional ::Protobuf::Field::StringField, :parameter, 2 + repeated ::Google::Protobuf::FileDescriptorProto, :proto_file, 15 + end + + class CodeGeneratorResponse + class File + optional ::Protobuf::Field::StringField, :name, 1 + optional ::Protobuf::Field::StringField, :insertion_point, 2 + optional ::Protobuf::Field::StringField, :content, 15 + end + + optional ::Protobuf::Field::StringField, :error, 1 + repeated ::Google::Protobuf::Compiler::CodeGeneratorResponse::File, :file, 15 + end + + + end + + end + +end + diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb new file mode 100644 index 00000000..2da3c7a5 --- /dev/null +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -0,0 +1,248 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Google + + module Protobuf + + ## + # Message Classes + # + class FileDescriptorSet < ::Protobuf::Message; end + class FileDescriptorProto < ::Protobuf::Message; end + class DescriptorProto < ::Protobuf::Message + class ExtensionRange < ::Protobuf::Message; end + end + class FieldDescriptorProto < ::Protobuf::Message + class Type < ::Protobuf::Enum + define :TYPE_DOUBLE, 1 + define :TYPE_FLOAT, 2 + define :TYPE_INT64, 3 + define :TYPE_UINT64, 4 + define :TYPE_INT32, 5 + define :TYPE_FIXED64, 6 + define :TYPE_FIXED32, 7 + define :TYPE_BOOL, 8 + define :TYPE_STRING, 9 + define :TYPE_GROUP, 10 + define :TYPE_MESSAGE, 11 + define :TYPE_BYTES, 12 + define :TYPE_UINT32, 13 + define :TYPE_ENUM, 14 + define :TYPE_SFIXED32, 15 + define :TYPE_SFIXED64, 16 + define :TYPE_SINT32, 17 + define :TYPE_SINT64, 18 + end + + class Label < ::Protobuf::Enum + define :LABEL_OPTIONAL, 1 + define :LABEL_REQUIRED, 2 + define :LABEL_REPEATED, 3 + end + + end + class EnumDescriptorProto < ::Protobuf::Message; end + class EnumValueDescriptorProto < ::Protobuf::Message; end + class ServiceDescriptorProto < ::Protobuf::Message; end + class MethodDescriptorProto < ::Protobuf::Message; end + class FileOptions < ::Protobuf::Message + class OptimizeMode < ::Protobuf::Enum + define :SPEED, 1 + define :CODE_SIZE, 2 + define :LITE_RUNTIME, 3 + end + + end + class MessageOptions < ::Protobuf::Message; end + class FieldOptions < ::Protobuf::Message + class CType < ::Protobuf::Enum + define :STRING, 0 + define :CORD, 1 + define :STRING_PIECE, 2 + end + + end + class EnumOptions < ::Protobuf::Message; end + class EnumValueOptions < ::Protobuf::Message; end + class ServiceOptions < ::Protobuf::Message; end + class MethodOptions < ::Protobuf::Message; end + class UninterpretedOption < ::Protobuf::Message + class NamePart < ::Protobuf::Message; end + end + class SourceCodeInfo < ::Protobuf::Message + class Location < ::Protobuf::Message; end + end + + ## + # Message Fields + # + class FileDescriptorSet + repeated ::Google::Protobuf::FileDescriptorProto, :file, 1 + end + + class FileDescriptorProto + optional ::Protobuf::Field::StringField, :name, 1 + optional ::Protobuf::Field::StringField, :package, 2 + repeated ::Protobuf::Field::StringField, :dependency, 3 + repeated ::Protobuf::Field::Int32Field, :public_dependency, 10 + repeated ::Protobuf::Field::Int32Field, :weak_dependency, 11 + repeated ::Google::Protobuf::DescriptorProto, :message_type, 4 + repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 5 + repeated ::Google::Protobuf::ServiceDescriptorProto, :service, 6 + repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 7 + optional ::Google::Protobuf::FileOptions, :options, 8 + optional ::Google::Protobuf::SourceCodeInfo, :source_code_info, 9 + end + + class DescriptorProto + class ExtensionRange + optional ::Protobuf::Field::Int32Field, :start, 1 + optional ::Protobuf::Field::Int32Field, :end, 2 + end + + optional ::Protobuf::Field::StringField, :name, 1 + repeated ::Google::Protobuf::FieldDescriptorProto, :field, 2 + repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 6 + repeated ::Google::Protobuf::DescriptorProto, :nested_type, 3 + repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 4 + repeated ::Google::Protobuf::DescriptorProto::ExtensionRange, :extension_range, 5 + optional ::Google::Protobuf::MessageOptions, :options, 7 + end + + class FieldDescriptorProto + optional ::Protobuf::Field::StringField, :name, 1 + optional ::Protobuf::Field::Int32Field, :number, 3 + optional ::Google::Protobuf::FieldDescriptorProto::Label, :label, 4 + optional ::Google::Protobuf::FieldDescriptorProto::Type, :type, 5 + optional ::Protobuf::Field::StringField, :type_name, 6 + optional ::Protobuf::Field::StringField, :extendee, 2 + optional ::Protobuf::Field::StringField, :default_value, 7 + optional ::Google::Protobuf::FieldOptions, :options, 8 + end + + class EnumDescriptorProto + optional ::Protobuf::Field::StringField, :name, 1 + repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2 + optional ::Google::Protobuf::EnumOptions, :options, 3 + end + + class EnumValueDescriptorProto + optional ::Protobuf::Field::StringField, :name, 1 + optional ::Protobuf::Field::Int32Field, :number, 2 + optional ::Google::Protobuf::EnumValueOptions, :options, 3 + end + + class ServiceDescriptorProto + optional ::Protobuf::Field::StringField, :name, 1 + repeated ::Google::Protobuf::MethodDescriptorProto, :method, 2 + optional ::Google::Protobuf::ServiceOptions, :options, 3 + end + + class MethodDescriptorProto + optional ::Protobuf::Field::StringField, :name, 1 + optional ::Protobuf::Field::StringField, :input_type, 2 + optional ::Protobuf::Field::StringField, :output_type, 3 + optional ::Google::Protobuf::MethodOptions, :options, 4 + end + + class FileOptions + optional ::Protobuf::Field::StringField, :java_package, 1 + optional ::Protobuf::Field::StringField, :java_outer_classname, 8 + optional ::Protobuf::Field::BoolField, :java_multiple_files, 10, :default => false + optional ::Protobuf::Field::BoolField, :java_generate_equals_and_hash, 20, :default => false + optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED + optional ::Protobuf::Field::StringField, :go_package, 11 + optional ::Protobuf::Field::BoolField, :cc_generic_services, 16, :default => false + optional ::Protobuf::Field::BoolField, :java_generic_services, 17, :default => false + optional ::Protobuf::Field::BoolField, :py_generic_services, 18, :default => false + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + + # Extension Fields + extensions 1000...536870912 + end + + class MessageOptions + optional ::Protobuf::Field::BoolField, :message_set_wire_format, 1, :default => false + optional ::Protobuf::Field::BoolField, :no_standard_descriptor_accessor, 2, :default => false + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + + # Extension Fields + extensions 1000...536870912 + end + + class FieldOptions + optional ::Google::Protobuf::FieldOptions::CType, :ctype, 1, :default => ::Google::Protobuf::FieldOptions::CType::STRING + optional ::Protobuf::Field::BoolField, :packed, 2 + optional ::Protobuf::Field::BoolField, :lazy, 5, :default => false + optional ::Protobuf::Field::BoolField, :deprecated, 3, :default => false + optional ::Protobuf::Field::StringField, :experimental_map_key, 9 + optional ::Protobuf::Field::BoolField, :weak, 10, :default => false + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + + # Extension Fields + extensions 1000...536870912 + end + + class EnumOptions + optional ::Protobuf::Field::BoolField, :allow_alias, 2, :default => true + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + + # Extension Fields + extensions 1000...536870912 + end + + class EnumValueOptions + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + + # Extension Fields + extensions 1000...536870912 + end + + class ServiceOptions + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + + # Extension Fields + extensions 1000...536870912 + end + + class MethodOptions + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + + # Extension Fields + extensions 1000...536870912 + end + + class UninterpretedOption + class NamePart + required ::Protobuf::Field::StringField, :name_part, 1 + required ::Protobuf::Field::BoolField, :is_extension, 2 + end + + repeated ::Google::Protobuf::UninterpretedOption::NamePart, :name, 2 + optional ::Protobuf::Field::StringField, :identifier_value, 3 + optional ::Protobuf::Field::Uint64Field, :positive_int_value, 4 + optional ::Protobuf::Field::Int64Field, :negative_int_value, 5 + optional ::Protobuf::Field::DoubleField, :double_value, 6 + optional ::Protobuf::Field::BytesField, :string_value, 7 + optional ::Protobuf::Field::StringField, :aggregate_value, 8 + end + + class SourceCodeInfo + class Location + repeated ::Protobuf::Field::Int32Field, :path, 1, :packed => true + repeated ::Protobuf::Field::Int32Field, :span, 2, :packed => true + optional ::Protobuf::Field::StringField, :leading_comments, 3 + optional ::Protobuf::Field::StringField, :trailing_comments, 4 + end + + repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1 + end + + + end + +end + diff --git a/proto/google/protobuf/compiler/plugin.proto b/proto/google/protobuf/compiler/plugin.proto new file mode 100644 index 00000000..77b888f3 --- /dev/null +++ b/proto/google/protobuf/compiler/plugin.proto @@ -0,0 +1,147 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// +// WARNING: The plugin interface is currently EXPERIMENTAL and is subject to +// change. +// +// protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is +// just a program that reads a CodeGeneratorRequest from stdin and writes a +// CodeGeneratorResponse to stdout. +// +// Plugins written using C++ can use google/protobuf/compiler/plugin.h instead +// of dealing with the raw protocol defined here. +// +// A plugin executable needs only to be placed somewhere in the path. The +// plugin should be named "protoc-gen-$NAME", and will then be used when the +// flag "--${NAME}_out" is passed to protoc. + +package google.protobuf.compiler; +option java_package = "com.google.protobuf.compiler"; +option java_outer_classname = "PluginProtos"; + +import "google/protobuf/descriptor.proto"; + +// An encoded CodeGeneratorRequest is written to the plugin's stdin. +message CodeGeneratorRequest { + // The .proto files that were explicitly listed on the command-line. The + // code generator should generate code only for these files. Each file's + // descriptor will be included in proto_file, below. + repeated string file_to_generate = 1; + + // The generator parameter passed on the command-line. + optional string parameter = 2; + + // FileDescriptorProtos for all files in files_to_generate and everything + // they import. The files will appear in topological order, so each file + // appears before any file that imports it. + // + // protoc guarantees that all proto_files will be written after + // the fields above, even though this is not technically guaranteed by the + // protobuf wire format. This theoretically could allow a plugin to stream + // in the FileDescriptorProtos and handle them one by one rather than read + // the entire set into memory at once. However, as of this writing, this + // is not similarly optimized on protoc's end -- it will store all fields in + // memory at once before sending them to the plugin. + repeated FileDescriptorProto proto_file = 15; +} + +// The plugin writes an encoded CodeGeneratorResponse to stdout. +message CodeGeneratorResponse { + // Error message. If non-empty, code generation failed. The plugin process + // should exit with status code zero even if it reports an error in this way. + // + // This should be used to indicate errors in .proto files which prevent the + // code generator from generating correct code. Errors which indicate a + // problem in protoc itself -- such as the input CodeGeneratorRequest being + // unparseable -- should be reported by writing a message to stderr and + // exiting with a non-zero status code. + optional string error = 1; + + // Represents a single generated file. + message File { + // The file name, relative to the output directory. The name must not + // contain "." or ".." components and must be relative, not be absolute (so, + // the file cannot lie outside the output directory). "/" must be used as + // the path separator, not "\". + // + // If the name is omitted, the content will be appended to the previous + // file. This allows the generator to break large files into small chunks, + // and allows the generated text to be streamed back to protoc so that large + // files need not reside completely in memory at one time. Note that as of + // this writing protoc does not optimize for this -- it will read the entire + // CodeGeneratorResponse before writing files to disk. + optional string name = 1; + + // If non-empty, indicates that the named file should already exist, and the + // content here is to be inserted into that file at a defined insertion + // point. This feature allows a code generator to extend the output + // produced by another code generator. The original generator may provide + // insertion points by placing special annotations in the file that look + // like: + // @@protoc_insertion_point(NAME) + // The annotation can have arbitrary text before and after it on the line, + // which allows it to be placed in a comment. NAME should be replaced with + // an identifier naming the point -- this is what other generators will use + // as the insertion_point. Code inserted at this point will be placed + // immediately above the line containing the insertion point (thus multiple + // insertions to the same point will come out in the order they were added). + // The double-@ is intended to make it unlikely that the generated code + // could contain things that look like insertion points by accident. + // + // For example, the C++ code generator places the following line in the + // .pb.h files that it generates: + // // @@protoc_insertion_point(namespace_scope) + // This line appears within the scope of the file's package namespace, but + // outside of any particular class. Another plugin can then specify the + // insertion_point "namespace_scope" to generate additional classes or + // other declarations that should be placed in this scope. + // + // Note that if the line containing the insertion point begins with + // whitespace, the same whitespace will be added to every line of the + // inserted text. This is useful for languages like Python, where + // indentation matters. In these languages, the insertion point comment + // should be indented the same amount as any inserted code will need to be + // in order to work correctly in that context. + // + // The code generator that generates the initial file and the one which + // inserts into it must both run as part of a single invocation of protoc. + // Code generators are executed in the order in which they appear on the + // command line. + // + // If |insertion_point| is present, |name| must also be present. + optional string insertion_point = 2; + + // The file contents. + optional string content = 15; + } + repeated File file = 15; +} diff --git a/proto/google/protobuf/descriptor.proto b/proto/google/protobuf/descriptor.proto new file mode 100644 index 00000000..a785f79f --- /dev/null +++ b/proto/google/protobuf/descriptor.proto @@ -0,0 +1,620 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// The messages in this file describe the definitions found in .proto files. +// A valid .proto file can be translated directly to a FileDescriptorProto +// without any other information (e.g. without reading its imports). + + + +package google.protobuf; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DescriptorProtos"; + +// descriptor.proto must be optimized for speed because reflection-based +// algorithms don't work during bootstrapping. +option optimize_for = SPEED; + +// The protocol compiler can output a FileDescriptorSet containing the .proto +// files it parses. +message FileDescriptorSet { + repeated FileDescriptorProto file = 1; +} + +// Describes a complete .proto file. +message FileDescriptorProto { + optional string name = 1; // file name, relative to root of source tree + optional string package = 2; // e.g. "foo", "foo.bar", etc. + + // Names of files imported by this file. + repeated string dependency = 3; + // Indexes of the public imported files in the dependency list above. + repeated int32 public_dependency = 10; + // Indexes of the weak imported files in the dependency list. + // For Google-internal migration only. Do not use. + repeated int32 weak_dependency = 11; + + // All top-level definitions in this file. + repeated DescriptorProto message_type = 4; + repeated EnumDescriptorProto enum_type = 5; + repeated ServiceDescriptorProto service = 6; + repeated FieldDescriptorProto extension = 7; + + optional FileOptions options = 8; + + // This field contains optional information about the original source code. + // You may safely remove this entire field whithout harming runtime + // functionality of the descriptors -- the information is needed only by + // development tools. + optional SourceCodeInfo source_code_info = 9; +} + +// Describes a message type. +message DescriptorProto { + optional string name = 1; + + repeated FieldDescriptorProto field = 2; + repeated FieldDescriptorProto extension = 6; + + repeated DescriptorProto nested_type = 3; + repeated EnumDescriptorProto enum_type = 4; + + message ExtensionRange { + optional int32 start = 1; + optional int32 end = 2; + } + repeated ExtensionRange extension_range = 5; + + optional MessageOptions options = 7; +} + +// Describes a field within a message. +message FieldDescriptorProto { + enum Type { + // 0 is reserved for errors. + // Order is weird for historical reasons. + TYPE_DOUBLE = 1; + TYPE_FLOAT = 2; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + // negative values are likely. + TYPE_INT64 = 3; + TYPE_UINT64 = 4; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + // negative values are likely. + TYPE_INT32 = 5; + TYPE_FIXED64 = 6; + TYPE_FIXED32 = 7; + TYPE_BOOL = 8; + TYPE_STRING = 9; + TYPE_GROUP = 10; // Tag-delimited aggregate. + TYPE_MESSAGE = 11; // Length-delimited aggregate. + + // New in version 2. + TYPE_BYTES = 12; + TYPE_UINT32 = 13; + TYPE_ENUM = 14; + TYPE_SFIXED32 = 15; + TYPE_SFIXED64 = 16; + TYPE_SINT32 = 17; // Uses ZigZag encoding. + TYPE_SINT64 = 18; // Uses ZigZag encoding. + }; + + enum Label { + // 0 is reserved for errors + LABEL_OPTIONAL = 1; + LABEL_REQUIRED = 2; + LABEL_REPEATED = 3; + // TODO(sanjay): Should we add LABEL_MAP? + }; + + optional string name = 1; + optional int32 number = 3; + optional Label label = 4; + + // If type_name is set, this need not be set. If both this and type_name + // are set, this must be either TYPE_ENUM or TYPE_MESSAGE. + optional Type type = 5; + + // For message and enum types, this is the name of the type. If the name + // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + // rules are used to find the type (i.e. first the nested types within this + // message are searched, then within the parent, on up to the root + // namespace). + optional string type_name = 6; + + // For extensions, this is the name of the type being extended. It is + // resolved in the same manner as type_name. + optional string extendee = 2; + + // For numeric types, contains the original text representation of the value. + // For booleans, "true" or "false". + // For strings, contains the default text contents (not escaped in any way). + // For bytes, contains the C escaped value. All bytes >= 128 are escaped. + // TODO(kenton): Base-64 encode? + optional string default_value = 7; + + optional FieldOptions options = 8; +} + +// Describes an enum type. +message EnumDescriptorProto { + optional string name = 1; + + repeated EnumValueDescriptorProto value = 2; + + optional EnumOptions options = 3; +} + +// Describes a value within an enum. +message EnumValueDescriptorProto { + optional string name = 1; + optional int32 number = 2; + + optional EnumValueOptions options = 3; +} + +// Describes a service. +message ServiceDescriptorProto { + optional string name = 1; + repeated MethodDescriptorProto method = 2; + + optional ServiceOptions options = 3; +} + +// Describes a method of a service. +message MethodDescriptorProto { + optional string name = 1; + + // Input and output type names. These are resolved in the same way as + // FieldDescriptorProto.type_name, but must refer to a message type. + optional string input_type = 2; + optional string output_type = 3; + + optional MethodOptions options = 4; +} + + +// =================================================================== +// Options + +// Each of the definitions above may have "options" attached. These are +// just annotations which may cause code to be generated slightly differently +// or may contain hints for code that manipulates protocol messages. +// +// Clients may define custom options as extensions of the *Options messages. +// These extensions may not yet be known at parsing time, so the parser cannot +// store the values in them. Instead it stores them in a field in the *Options +// message called uninterpreted_option. This field must have the same name +// across all *Options messages. We then use this field to populate the +// extensions when we build a descriptor, at which point all protos have been +// parsed and so all extensions are known. +// +// Extension numbers for custom options may be chosen as follows: +// * For options which will only be used within a single application or +// organization, or for experimental options, use field numbers 50000 +// through 99999. It is up to you to ensure that you do not use the +// same number for multiple options. +// * For options which will be published and used publicly by multiple +// independent entities, e-mail protobuf-global-extension-registry@google.com +// to reserve extension numbers. Simply provide your project name (e.g. +// Object-C plugin) and your porject website (if available) -- there's no need +// to explain how you intend to use them. Usually you only need one extension +// number. You can declare multiple options with only one extension number by +// putting them in a sub-message. See the Custom Options section of the docs +// for examples: +// http://code.google.com/apis/protocolbuffers/docs/proto.html#options +// If this turns out to be popular, a web service will be set up +// to automatically assign option numbers. + + +message FileOptions { + + // Sets the Java package where classes generated from this .proto will be + // placed. By default, the proto package is used, but this is often + // inappropriate because proto packages do not normally start with backwards + // domain names. + optional string java_package = 1; + + + // If set, all the classes from the .proto file are wrapped in a single + // outer class with the given name. This applies to both Proto1 + // (equivalent to the old "--one_java_file" option) and Proto2 (where + // a .proto always translates to a single class, but you may want to + // explicitly choose the class name). + optional string java_outer_classname = 8; + + // If set true, then the Java code generator will generate a separate .java + // file for each top-level message, enum, and service defined in the .proto + // file. Thus, these types will *not* be nested inside the outer class + // named by java_outer_classname. However, the outer class will still be + // generated to contain the file's getDescriptor() method as well as any + // top-level extensions defined in the file. + optional bool java_multiple_files = 10 [default=false]; + + // If set true, then the Java code generator will generate equals() and + // hashCode() methods for all messages defined in the .proto file. This is + // purely a speed optimization, as the AbstractMessage base class includes + // reflection-based implementations of these methods. + optional bool java_generate_equals_and_hash = 20 [default=false]; + + // Generated classes can be optimized for speed or code size. + enum OptimizeMode { + SPEED = 1; // Generate complete code for parsing, serialization, + // etc. + CODE_SIZE = 2; // Use ReflectionOps to implement these methods. + LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. + } + optional OptimizeMode optimize_for = 9 [default=SPEED]; + + // Sets the Go package where structs generated from this .proto will be + // placed. There is no default. + optional string go_package = 11; + + + + // Should generic services be generated in each language? "Generic" services + // are not specific to any particular RPC system. They are generated by the + // main code generators in each language (without additional plugins). + // Generic services were the only kind of service generation supported by + // early versions of proto2. + // + // Generic services are now considered deprecated in favor of using plugins + // that generate code specific to your particular RPC system. Therefore, + // these default to false. Old code which depends on generic services should + // explicitly set them to true. + optional bool cc_generic_services = 16 [default=false]; + optional bool java_generic_services = 17 [default=false]; + optional bool py_generic_services = 18 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message MessageOptions { + // Set true to use the old proto1 MessageSet wire format for extensions. + // This is provided for backwards-compatibility with the MessageSet wire + // format. You should not use this for any other reason: It's less + // efficient, has fewer features, and is more complicated. + // + // The message must be defined exactly as follows: + // message Foo { + // option message_set_wire_format = true; + // extensions 4 to max; + // } + // Note that the message cannot have any defined fields; MessageSets only + // have extensions. + // + // All extensions of your type must be singular messages; e.g. they cannot + // be int32s, enums, or repeated messages. + // + // Because this is an option, the above two restrictions are not enforced by + // the protocol compiler. + optional bool message_set_wire_format = 1 [default=false]; + + // Disables the generation of the standard "descriptor()" accessor, which can + // conflict with a field of the same name. This is meant to make migration + // from proto1 easier; new code should avoid fields named "descriptor". + optional bool no_standard_descriptor_accessor = 2 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message FieldOptions { + // The ctype option instructs the C++ code generator to use a different + // representation of the field than it normally would. See the specific + // options below. This option is not yet implemented in the open source + // release -- sorry, we'll try to include it in a future version! + optional CType ctype = 1 [default = STRING]; + enum CType { + // Default mode. + STRING = 0; + + CORD = 1; + + STRING_PIECE = 2; + } + // The packed option can be enabled for repeated primitive fields to enable + // a more efficient representation on the wire. Rather than repeatedly + // writing the tag and type for each element, the entire array is encoded as + // a single length-delimited blob. + optional bool packed = 2; + + + + // Should this field be parsed lazily? Lazy applies only to message-type + // fields. It means that when the outer message is initially parsed, the + // inner message's contents will not be parsed but instead stored in encoded + // form. The inner message will actually be parsed when it is first accessed. + // + // This is only a hint. Implementations are free to choose whether to use + // eager or lazy parsing regardless of the value of this option. However, + // setting this option true suggests that the protocol author believes that + // using lazy parsing on this field is worth the additional bookkeeping + // overhead typically needed to implement it. + // + // This option does not affect the public interface of any generated code; + // all method signatures remain the same. Furthermore, thread-safety of the + // interface is not affected by this option; const methods remain safe to + // call from multiple threads concurrently, while non-const methods continue + // to require exclusive access. + // + // + // Note that implementations may choose not to check required fields within + // a lazy sub-message. That is, calling IsInitialized() on the outher message + // may return true even if the inner message has missing required fields. + // This is necessary because otherwise the inner message would have to be + // parsed in order to perform the check, defeating the purpose of lazy + // parsing. An implementation which chooses not to check required fields + // must be consistent about it. That is, for any particular sub-message, the + // implementation must either *always* check its required fields, or *never* + // check its required fields, regardless of whether or not the message has + // been parsed. + optional bool lazy = 5 [default=false]; + + // Is this field deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for accessors, or it will be completely ignored; in the very least, this + // is a formalization for deprecating fields. + optional bool deprecated = 3 [default=false]; + + // EXPERIMENTAL. DO NOT USE. + // For "map" fields, the name of the field in the enclosed type that + // is the key for this map. For example, suppose we have: + // message Item { + // required string name = 1; + // required string value = 2; + // } + // message Config { + // repeated Item items = 1 [experimental_map_key="name"]; + // } + // In this situation, the map key for Item will be set to "name". + // TODO: Fully-implement this, then remove the "experimental_" prefix. + optional string experimental_map_key = 9; + + // For Google-internal migration only. Do not use. + optional bool weak = 10 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumOptions { + + // Set this option to false to disallow mapping different tag names to a same + // value. + optional bool allow_alias = 2 [default=true]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumValueOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message ServiceOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message MethodOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + + +// A message representing a option the parser does not recognize. This only +// appears in options protos created by the compiler::Parser class. +// DescriptorPool resolves these when building Descriptor objects. Therefore, +// options protos in descriptor objects (e.g. returned by Descriptor::options(), +// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions +// in them. +message UninterpretedOption { + // The name of the uninterpreted option. Each string represents a segment in + // a dot-separated name. is_extension is true iff a segment represents an + // extension (denoted with parentheses in options specs in .proto files). + // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents + // "foo.(bar.baz).qux". + message NamePart { + required string name_part = 1; + required bool is_extension = 2; + } + repeated NamePart name = 2; + + // The value of the uninterpreted option, in whatever type the tokenizer + // identified it as during parsing. Exactly one of these should be set. + optional string identifier_value = 3; + optional uint64 positive_int_value = 4; + optional int64 negative_int_value = 5; + optional double double_value = 6; + optional bytes string_value = 7; + optional string aggregate_value = 8; +} + +// =================================================================== +// Optional source code info + +// Encapsulates information about the original source file from which a +// FileDescriptorProto was generated. +message SourceCodeInfo { + // A Location identifies a piece of source code in a .proto file which + // corresponds to a particular definition. This information is intended + // to be useful to IDEs, code indexers, documentation generators, and similar + // tools. + // + // For example, say we have a file like: + // message Foo { + // optional string foo = 1; + // } + // Let's look at just the field definition: + // optional string foo = 1; + // ^ ^^ ^^ ^ ^^^ + // a bc de f ghi + // We have the following locations: + // span path represents + // [a,i) [ 4, 0, 2, 0 ] The whole field definition. + // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + // [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + // [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + // + // Notes: + // - A location may refer to a repeated field itself (i.e. not to any + // particular index within it). This is used whenever a set of elements are + // logically enclosed in a single code segment. For example, an entire + // extend block (possibly containing multiple extension definitions) will + // have an outer location whose path refers to the "extensions" repeated + // field without an index. + // - Multiple locations may have the same path. This happens when a single + // logical declaration is spread out across multiple places. The most + // obvious example is the "extend" block again -- there may be multiple + // extend blocks in the same scope, each of which will have the same path. + // - A location's span is not always a subset of its parent's span. For + // example, the "extendee" of an extension declaration appears at the + // beginning of the "extend" block and is shared by all extensions within + // the block. + // - Just because a location's span is a subset of some other location's span + // does not mean that it is a descendent. For example, a "group" defines + // both a type and a field in a single declaration. Thus, the locations + // corresponding to the type and field and their components will overlap. + // - Code which tries to interpret locations should probably be designed to + // ignore those that it doesn't understand, as more types of locations could + // be recorded in the future. + repeated Location location = 1; + message Location { + // Identifies which part of the FileDescriptorProto was defined at this + // location. + // + // Each element is a field number or an index. They form a path from + // the root FileDescriptorProto to the place where the definition. For + // example, this path: + // [ 4, 3, 2, 7, 1 ] + // refers to: + // file.message_type(3) // 4, 3 + // .field(7) // 2, 7 + // .name() // 1 + // This is because FileDescriptorProto.message_type has field number 4: + // repeated DescriptorProto message_type = 4; + // and DescriptorProto.field has field number 2: + // repeated FieldDescriptorProto field = 2; + // and FieldDescriptorProto.name has field number 1: + // optional string name = 1; + // + // Thus, the above path gives the location of a field name. If we removed + // the last element: + // [ 4, 3, 2, 7 ] + // this path refers to the whole field declaration (from the beginning + // of the label to the terminating semicolon). + repeated int32 path = 1 [packed=true]; + + // Always has exactly three or four elements: start line, start column, + // end line (optional, otherwise assumed same as start line), end column. + // These are packed into a single field for efficiency. Note that line + // and column numbers are zero-based -- typically you will want to add + // 1 to each before displaying to a user. + repeated int32 span = 2 [packed=true]; + + // If this SourceCodeInfo represents a complete declaration, these are any + // comments appearing before and after the declaration which appear to be + // attached to the declaration. + // + // A series of line comments appearing on consecutive lines, with no other + // tokens appearing on those lines, will be treated as a single comment. + // + // Only the comment content is provided; comment markers (e.g. //) are + // stripped out. For block comments, leading whitespace and an asterisk + // will be stripped from the beginning of each line other than the first. + // Newlines are included in the output. + // + // Examples: + // + // optional int32 foo = 1; // Comment attached to foo. + // // Comment attached to bar. + // optional int32 bar = 2; + // + // optional string baz = 3; + // // Comment attached to baz. + // // Another line attached to baz. + // + // // Comment attached to qux. + // // + // // Another line attached to qux. + // optional double qux = 4; + // + // optional string corge = 5; + // /* Block comment attached + // * to corge. Leading asterisks + // * will be removed. */ + // /* Block comment attached to + // * grault. */ + // optional int32 grault = 6; + optional string leading_comments = 3; + optional string trailing_comments = 4; + } +} From 07d377d7a681537d98921cc4acd91019d8c1bb50 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 18 Jul 2013 11:40:21 -0600 Subject: [PATCH 0459/1191] Add protoc-gen-ruby and CodeGenerator to conform to google's third-party plugin interface via stdin/out --- bin/protoc-gen-ruby | 26 ++++++++++ lib/protobuf/code_generator.rb | 43 +++++++++++++++++ spec/bin/protoc-gen-ruby_spec.rb | 18 +++++++ spec/lib/protobuf/code_generator_spec.rb | 60 ++++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100755 bin/protoc-gen-ruby create mode 100644 lib/protobuf/code_generator.rb create mode 100644 spec/bin/protoc-gen-ruby_spec.rb create mode 100644 spec/lib/protobuf/code_generator_spec.rb diff --git a/bin/protoc-gen-ruby b/bin/protoc-gen-ruby new file mode 100755 index 00000000..37441c33 --- /dev/null +++ b/bin/protoc-gen-ruby @@ -0,0 +1,26 @@ +#!/usr/bin/env ruby + +# Before requiring protobuf, ensure that we will not load any +# server or client code. +# +ENV['PB_NO_NETWORKING'] = '1' + +$LOAD_PATH << ::File.expand_path("../../lib", __FILE__) +require 'protobuf' + +# Setup the loadpath so that plugin.pb will +# be able to require the descriptor.pb file. +# +$LOAD_PATH << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) +require 'google/protobuf/compiler/plugin.pb' + +# Read the request bytes from STDIN, pass to the CodeGenerator, and +# write to STDOUT the generated response_bytes. +# +require 'protobuf/code_generator' + +request_bytes = STDIN.read +code_generator = ::Protobuf::CodeGenerator.new(request_bytes) +response_bytes = code_generator.response_bytes +STDOUT.print(response_bytes) + diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb new file mode 100644 index 00000000..6b6c7c67 --- /dev/null +++ b/lib/protobuf/code_generator.rb @@ -0,0 +1,43 @@ +require 'protobuf/generators/file_generator' + +module Protobuf + class CodeGenerator + + CodeGeneratorFatalError = Class.new(RuntimeError) + + def self.fatal(message) + raise CodeGeneratorFatalError, message + end + + def self.print_tag_warning_suppress + STDERR.puts "Suppress tag warning output with PB_NO_TAG_WARNINGS=1." + def self.print_tag_warning_suppress; end + end + + def self.warn(message) + STDERR.puts("[WARN] #{message}") + end + + def initialize(request_bytes) + @request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.new + @request.parse_from_string(request_bytes) + @generated_files = [] + end + + def generate_file(file_descriptor) + file_generator = ::Protobuf::Generators::FileGenerator.new(file_descriptor) + @generated_files << file_generator.generate_output_file + end + + def response_bytes + @request.proto_file.each do |file_descriptor| + generate_file(file_descriptor) + end + + response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.new(:file => @generated_files) + return response.serialize_to_string + end + + end +end + diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb new file mode 100644 index 00000000..79d2e445 --- /dev/null +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +require 'protobuf/code_generator' + +describe 'protoc-gen-ruby' do + let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) } + let(:request_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:file_to_generate => [ "test/foo.proto" ]) } + let(:expected_file) { ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') } + let(:expected_response_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:files => [ expected_file ]).serialize_to_string } + + it 'reads the serialized request bytes and outputs serialized response bytes' do + ::IO.popen(binpath, 'w+') do |pipe| + pipe.write(request_bytes) + pipe.read(expected_response_bytes.size).should eq expected_response_bytes + end + end +end + diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb new file mode 100644 index 00000000..3674a082 --- /dev/null +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +require 'protobuf/code_generator' + +describe ::Protobuf::CodeGenerator do + + # Some constants to shorten things up + DESCRIPTOR = ::Google::Protobuf + COMPILER = ::Google::Protobuf::Compiler + + describe '#response_bytes' do + let(:input_file1) { DESCRIPTOR::FileDescriptorProto.new(:name => 'test/foo.proto') } + let(:input_file2) { DESCRIPTOR::FileDescriptorProto.new(:name => 'test/bar.proto') } + + let(:output_file1) { COMPILER::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') } + let(:output_file2) { COMPILER::CodeGeneratorResponse::File.new(:name => 'test/bar.pb.rb') } + + let(:file_generator1) { mock('file generator 1', :generate_output_file => output_file1) } + let(:file_generator2) { mock('file generator 2', :generate_output_file => output_file2) } + + let(:request_bytes) do + COMPILER::CodeGeneratorRequest.new(:proto_file => [ input_file1, input_file2 ]).serialize_to_string + end + + let(:expected_response_bytes) do + COMPILER::CodeGeneratorResponse.new(:file => [ output_file1, output_file2 ]).serialize_to_string + end + + before do + ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file1).and_return(file_generator1) + ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file2).and_return(file_generator2) + end + + it 'returns the serialized CodeGeneratorResponse which contains the generated file contents' do + generator = described_class.new(request_bytes) + generator.response_bytes.should eq expected_response_bytes + end + end + + context 'class-level printing methods' do + describe '.fatal' do + it 'raises a CodeGeneratorFatalError error' do + expect { + described_class.fatal("something is wrong") + }.to raise_error( + ::Protobuf::CodeGenerator::CodeGeneratorFatalError, + "something is wrong" + ) + end + end + + describe '.warn' do + it 'prints a warning to stderr' do + STDERR.should_receive(:puts).with("[WARN] a warning") + described_class.warn("a warning") + end + end + end + +end From 6ad525b6e1220b602d01a256f052c3dfbd12cb12 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 18 Jul 2013 11:40:49 -0600 Subject: [PATCH 0460/1191] Add Generators Base as parent class for code generators --- lib/protobuf/generators/base.rb | 67 +++++++++++++++++ spec/lib/protobuf/generators/base_spec.rb | 87 +++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 lib/protobuf/generators/base.rb create mode 100644 spec/lib/protobuf/generators/base_spec.rb diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb new file mode 100644 index 00000000..81f9439e --- /dev/null +++ b/lib/protobuf/generators/base.rb @@ -0,0 +1,67 @@ +require 'protobuf/code_generator' +require 'protobuf/generators/printable' + +module Protobuf + module Generators + class Base + include ::Protobuf::Generators::Printable + + def self.validate_tags(type_name, tags) + return if tags.empty? + + unique_tags = tags.uniq + + if unique_tags.size < tags.size + ::Protobuf::CodeGenerator.fatal("#{type_name} object has duplicate tags. Expected #{unique_tags.size} tags, but got #{tags.size}. Suppress with PB_NO_TAG_WARNINGS=1.") + end + + unless ENV.key?('PB_NO_TAG_WARNINGS') + range = ((tags.min)..(tags.max)) + + if tags.size < range.size + ::Protobuf::CodeGenerator.print_tag_warning_suppress + ::Protobuf::CodeGenerator.warn("#{type_name} object should have #{range.size} tags (#{range.begin}..#{range.end}), but found #{tags.size} tags.") + end + end + end + + attr_reader :descriptor, :namespace, :options + + def initialize(descriptor, indent_level = 0, options = {}) + @descriptor = descriptor + @options = options + @namespace = @options.fetch(:namespace) { [] } + init_printer(indent_level) + end + + def fully_qualified_type_namespace + ".#{type_namespace.join('.')}" + end + + def run_once(label, &block) + tracker_ivar = "@_#{label}_compiled" + value_ivar = "@_#{label}_compiled_value" + + if instance_variable_get(tracker_ivar) + return instance_variable_get(value_ivar) + else + return_value = block.call + instance_variable_set(tracker_ivar, true) + instance_variable_set(value_ivar, return_value) + return return_value + end + end + + def to_s + compile + print_contents # see Printable + end + + def type_namespace + @type_namespace ||= @namespace + [ descriptor.name ] + end + + end + end +end + diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb new file mode 100644 index 00000000..6d89aab3 --- /dev/null +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -0,0 +1,87 @@ +require 'spec_helper' + +require 'protobuf/code_generator' +require 'protobuf/generators/base' + +describe ::Protobuf::Generators::Base do + + subject { described_class.new(mock) } + + context 'namespaces' do + let(:descriptor) { mock(:name => 'Baz') } + subject { described_class.new(descriptor, 0, :namespace => [ :foo, :bar ]) } + its(:type_namespace) { should eq [ :foo, :bar, 'Baz' ] } + its(:fully_qualified_type_namespace) { should eq '.foo.bar.Baz' } + end + + describe '#run_once' do + it 'protects the block from being entered more than once' do + foo = 0 + bar = 0 + + test_run_once = lambda do + bar += 1 + subject.run_once(:foo_test) do + foo += 1 + end + end + + 10.times { test_run_once.call } + expect(foo).to eq(1) + expect(bar).to eq(10) + end + + it 'always returns the same object' do + rv = subject.run_once(:foo_test) do + "foo bar" + end + expect(rv).to eq("foo bar") + + rv = subject.run_once(:foo_test) do + "baz quux" + end + expect(rv).to eq("foo bar") + end + end + + describe '#to_s' do + before do + class ToStringTest < ::Protobuf::Generators::Base + def compile + run_once(:compile) do + puts "this is a test" + end + end + end + end + + subject { ToStringTest.new(mock) } + + it 'compiles and returns the contents' do + 10.times do + expect(subject.to_s).to eq("this is a test\n") + end + end + end + + describe '#validate_tags' do + context 'when tags are duplicated' do + it 'fails with a GeneratorFatalError' do + ::Protobuf::CodeGenerator.should_receive(:fatal) + .with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/) + + described_class.validate_tags("FooBar", [1,2,2,3]) + end + end + + context 'when tags are missing in the range' do + it 'prints a warning' do + ::Protobuf::CodeGenerator.should_receive(:warn) + .with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) + described_class.validate_tags("FooBar", [1,2,4,5]) + end + end + end + +end + From 41031ec1e5db51cb744d1e91f6ab08f274d02ce0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 18 Jul 2013 11:41:27 -0600 Subject: [PATCH 0461/1191] Add EnumGenerator class to generate a ruby class from an EnumDescriptorProto --- lib/protobuf/generators/enum_generator.rb | 31 +++++++++++++ .../generators/enum_generator_spec.rb | 45 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 lib/protobuf/generators/enum_generator.rb create mode 100644 spec/lib/protobuf/generators/enum_generator_spec.rb diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb new file mode 100644 index 00000000..6bd5e692 --- /dev/null +++ b/lib/protobuf/generators/enum_generator.rb @@ -0,0 +1,31 @@ +require 'protobuf/generators/base' + +module Protobuf + module Generators + class EnumGenerator < Base + + def compile + run_once(:compile) do + tags = [] + + print_class(descriptor.name, :enum) do + descriptor.value.each do |enum_value_descriptor| + tags << enum_value_descriptor.number + puts build_value(enum_value_descriptor) + end + end + + self.class.validate_tags(fully_qualified_type_namespace, tags) + end + end + + def build_value(enum_value_descriptor) + name = enum_value_descriptor.name + number = enum_value_descriptor.number + return "define :#{name}, #{number}" + end + + end + end +end + diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb new file mode 100644 index 00000000..c1534415 --- /dev/null +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +require 'protobuf/generators/enum_generator' + +describe ::Protobuf::Generators::EnumGenerator do + + let(:values) { + [ + { :name => 'FOO', :number => 1 }, + { :name => 'BAR', :number => 2 }, + { :name => 'BAZ', :number => 3 } + ] + } + let(:enum_fields) { { :name => 'TestEnum', + :value => values } } + + let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) } + + subject { described_class.new(enum) } + + describe '#compile' do + let(:compiled) { + %q{class TestEnum < ::Protobuf::Enum + define :FOO, 1 + define :BAR, 2 + define :BAZ, 3 +end + +} + } + + it 'compiles the enum and it\'s field values' do + subject.compile + subject.to_s.should eq(compiled) + end + end + + describe '#build_value' do + it 'returns a string identifying the given enum value' do + subject.build_value(enum.value.first).should eq("define :FOO, 1") + end + end + +end + From f2a7e2ab7b8b5c4160f17e64c4b09b6e70f748b0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 18 Jul 2013 11:42:00 -0600 Subject: [PATCH 0462/1191] Add Fieldgenerator to return a ruby field definition from a FieldDescriptorProto --- lib/protobuf/generators/field_generator.rb | 92 +++++++++++++++++++ .../generators/field_generator_spec.rb | 80 ++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 lib/protobuf/generators/field_generator.rb create mode 100644 spec/lib/protobuf/generators/field_generator_spec.rb diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb new file mode 100644 index 00000000..6ffae83e --- /dev/null +++ b/lib/protobuf/generators/field_generator.rb @@ -0,0 +1,92 @@ +require 'protobuf/generators/base' + +module Protobuf + module Generators + class FieldGenerator < Base + + attr_reader :field_options + + def applicable_options + @applicable_options ||= field_options.map { |k, v| ":#{k} => #{v}" } + end + + def default_value + @default_value ||= begin + if defaulted? + raw_default_value = descriptor.default_value + + case descriptor.type.name + when :TYPE_ENUM then + "#{type_name}::#{raw_default_value}" + when :TYPE_STRING then + "'#{raw_default_value.gsub(/'/, '\\\\\'')}'" + else + raw_default_value + end + end + end + end + + def defaulted? + descriptor.respond_to_has_and_present?(:default_value) + end + + def deprecated? + descriptor.options.try(:deprecated?) { false } + end + + def extension? + descriptor.respond_to_has_and_present?(:extendee) + end + + def compile + run_once(:compile) do + field_definition = [ "#{label} #{type_name}", name, number, applicable_options ] + puts field_definition.flatten.compact.join(', ') + end + end + + def label + @label ||= descriptor.label.name.to_s.downcase.sub(/label_/, '') # required, optional, repeated + end + + def name + @name ||= ":#{descriptor.name}" + end + + def number + @number ||= descriptor.number + end + + def field_options + @field_options ||= begin + opts = {} + opts[:default] = default_value if defaulted? + opts[:packed] = 'true' if packed? + opts[:deprecated] = 'true' if deprecated? + opts[:extension] = 'true' if extension? + opts + end + end + + def packed? + descriptor.options.try(:packed?) { false } + end + + # Determine the field type + def type_name + @type_name ||= begin + case descriptor.type.name + when :TYPE_MESSAGE, :TYPE_ENUM, :TYPE_GROUP then + type_name = modulize(descriptor.type_name) + else + type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '') + type_name = "::Protobuf::Field::#{modulize(type_name)}Field" + end + end + end + + end + end +end + diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb new file mode 100644 index 00000000..0f804638 --- /dev/null +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -0,0 +1,80 @@ +require 'spec_helper' + +require 'protobuf/generators/field_generator.rb' + +describe ::Protobuf::Generators::FieldGenerator do + + let(:label_enum) { :LABEL_OPTIONAL } + let(:name) { 'foo_bar' } + let(:number) { 3 } + let(:type_enum) { :TYPE_STRING } + let(:type_name) { nil } + let(:default_value) { nil } + let(:extendee) { nil } + let(:field_options) { {} } + + let(:field_fields) { { :label => label_enum, + :name => name, + :number => number, + :type => type_enum, + :type_name => type_name, + :default_value => default_value, + :extendee => extendee, + :options => field_options } } + + let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) } + + describe '#compile' do + subject { described_class.new(field).to_s } + + it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3\n" } + + context 'when the type is another message' do + let(:type_enum) { :TYPE_MESSAGE } + let(:type_name) { '.foo.bar.Baz' } + + it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" } + end + + context 'when a default value is used' do + let(:type_enum) { :TYPE_INT32 } + let(:default_value) { '42' } + it { should eq "optional ::Protobuf::Field::Int32Field, :foo_bar, 3, :default => 42\n" } + + context 'when type is an enum' do + let(:type_enum) { :TYPE_ENUM } + let(:type_name) { '.foo.bar.Baz' } + let(:default_value) { 'QUUX' } + + it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } + end + + context 'when the type is a string' do + let(:type_enum) { :TYPE_STRING } + let(:default_value) { "a default 'string'" } + + it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :default => 'a default \\'string\\''\n" } + end + end + + context 'when the field is an extension' do + let(:extendee) { 'foo.bar.Baz' } + + it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :extension => true\n" } + end + + context 'when field is packed' do + let(:field_options) { { :packed => true } } + + it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :packed => true\n" } + end + + context 'when field is deprecated' do + let(:field_options) { { :deprecated => true } } + + it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :deprecated => true\n" } + end + end + +end + From 1faebf34ce755adc52d7f95be6993cdbe9da4706 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 18 Jul 2013 11:42:35 -0600 Subject: [PATCH 0463/1191] Add ServiceGenerator to generate a ruby service class from a ServiceDescriptorProto --- lib/protobuf/generators/service_generator.rb | 27 ++++++++++++ .../generators/service_generator_spec.rb | 43 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 lib/protobuf/generators/service_generator.rb create mode 100644 spec/lib/protobuf/generators/service_generator_spec.rb diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb new file mode 100644 index 00000000..2c5a4891 --- /dev/null +++ b/lib/protobuf/generators/service_generator.rb @@ -0,0 +1,27 @@ +require 'protobuf/generators/base' + +module Protobuf + module Generators + class ServiceGenerator < Base + + def compile + run_once(:compile) do + print_class(descriptor.name, :service) do + descriptor.method.each do |method_descriptor| + puts build_method(method_descriptor) + end + end + end + end + + def build_method(method_descriptor) + name = method_descriptor.name + request_klass = modulize(method_descriptor.input_type) + response_klass = modulize(method_descriptor.output_type) + return "rpc :#{name.underscore}, #{request_klass}, #{response_klass}" + end + + end + end +end + diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb new file mode 100644 index 00000000..c10c6293 --- /dev/null +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +require 'protobuf/generators/service_generator' + +describe ::Protobuf::Generators::ServiceGenerator do + + let(:methods) { + [ + { :name => 'Search', :input_type => 'FooRequest', :output_type => 'FooResponse' }, + { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' } + ] + } + let(:service_fields) { { :name => 'TestService', + :method => methods } } + + let(:service) { ::Google::Protobuf::ServiceDescriptorProto.new(service_fields) } + + subject { described_class.new(service) } + + describe '#compile' do + let(:compiled) { + %q{class TestService < ::Protobuf::Rpc::Service + rpc :search, FooRequest, FooResponse + rpc :foo_bar, ::Foo::Request, ::Bar::Response +end + +} + } + + it 'compiles the service and it\'s rpc methods' do + subject.compile + subject.to_s.should eq(compiled) + end + end + + describe '#build_method' do + it 'returns a string identifying the given method descriptor' do + subject.build_method(service.method.first).should eq("rpc :search, FooRequest, FooResponse") + end + end + +end + From 5d36ce7720f078bb1801f7cedaf45d0e4a647978 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 18 Jul 2013 15:30:19 -0600 Subject: [PATCH 0464/1191] Add ExtensionGenerator to generate a ruby class for extended message fields where the message is not defined in the given file --- .../generators/extension_generator.rb | 28 ++++++++++++ .../generators/extension_generator_spec.rb | 43 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 lib/protobuf/generators/extension_generator.rb create mode 100644 spec/lib/protobuf/generators/extension_generator_spec.rb diff --git a/lib/protobuf/generators/extension_generator.rb b/lib/protobuf/generators/extension_generator.rb new file mode 100644 index 00000000..57e34117 --- /dev/null +++ b/lib/protobuf/generators/extension_generator.rb @@ -0,0 +1,28 @@ +require 'protobuf/generators/base' +require 'protobuf/generators/group_generator' + +module Protobuf + module Generators + class ExtensionGenerator < Base + + def initialize(message_type, field_descriptors, indent_level) + super(nil, indent_level) + @message_type = modulize(message_type) + @field_descriptors = field_descriptors + end + + def compile + run_once(:compile) do + print_class(@message_type, :message) do + group = GroupGenerator.new(current_indent) + group.add_extension_fields(@field_descriptors) + group.order = [ :extension_field ] + print group.to_s + end + end + end + + end + end +end + diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb new file mode 100644 index 00000000..20df2f69 --- /dev/null +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +require 'protobuf/code_generator' +require 'protobuf/generators/extension_generator' + +describe ::Protobuf::Generators::ExtensionGenerator do + + let(:field_descriptors) { + [ + mock('field descriptor 1', :to_s => " field 1\n"), + mock('field descriptor 2', :to_s => " field 2\n"), + mock('field descriptor 3', :to_s => " field 3\n") + ] + } + let(:message_type) { 'FooBar' } + + before do + ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[0], 1).and_return(field_descriptors[0]) + ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[1], 1).and_return(field_descriptors[1]) + ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[2], 1).and_return(field_descriptors[2]) + end + + subject { described_class.new(message_type, field_descriptors, 0) } + + describe '#compile' do + let(:compiled) { + %q{class FooBar < ::Protobuf::Message + field 1 + field 2 + field 3 +end + +} + } + + it 'compiles the a class with the extension fields' do + subject.compile + subject.to_s.should eq(compiled) + end + end + +end + From aa46d0e691a43e8bd16e53479db6348b4f47847f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 18 Jul 2013 15:50:36 -0600 Subject: [PATCH 0465/1191] add lifecycle handler and call registered blocks after_server_bind when running, will fill in more lifecycle events as we continue to build up the server --- lib/protobuf/cli.rb | 6 +++-- lib/protobuf/lifecycle.rb | 33 ++++++++++++++++++++++++++ lib/protobuf/rpc/servers/zmq/server.rb | 4 +++- lib/protobuf/rpc/servers/zmq_runner.rb | 5 ++-- spec/lib/protobuf/cli_spec.rb | 20 +++++++++++++--- 5 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 lib/protobuf/lifecycle.rb diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 4a12e2fa..b973e434 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,5 +1,6 @@ require 'thor' require 'protobuf/version' +require 'protobuf/lifecycle' require 'protobuf/logger' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/rpc/servers/socket_runner' @@ -87,7 +88,7 @@ def configure_gc def configure_logger debug_say('Configuring logger') ::Protobuf::Logger.configure({ :file => options.log || STDOUT, - :level => options.debug? ? ::Logger::DEBUG : options.level }) + :level => options.debug? ? ::Logger::DEBUG : options.level }) # Debug output the server options to the log file. ::Protobuf::Logger.debug { 'Debugging options:' } @@ -242,9 +243,10 @@ def start_server ::Protobuf::Logger.info { "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" } + + ::Protobuf::Lifecycle.trigger( "after_server_bind" ) end end end end end - diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb new file mode 100644 index 00000000..8ac8dd3f --- /dev/null +++ b/lib/protobuf/lifecycle.rb @@ -0,0 +1,33 @@ +module Protobuf + class Lifecycle + + def self.register( event_name, &blk ) + event_name = normalized_event_name( event_name ) + + lifecycle_events[ event_name ] ||= [] + lifecycle_events[ event_name ] << blk + end + + def self.trigger( event_name ) + event_name = normalized_event_name( event_name ) + + if lifecycle_events.has_key?( event_name ) + lifecycle_events[ event_name ].each do |block| + block.call + end + end + end + + def self.normalized_event_name( event_name ) + return "#{event_name}".downcase + end + + class << self + attr_accessor :lifecycle_events + + alias_method :on, :register + end + + @lifecycle_events ||= {} + end +end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 7b0438bb..58faeef5 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -167,8 +167,10 @@ def run start_broker unless brokerless? start_missing_workers + + yield if block_given? # runs on startup wait_for_shutdown_signal - broadcast_flatline if broadcast_beacons? + broadcast_flatline if broadcast_beacons? Thread.pass until reap_dead_workers.empty? @broker.join unless brokerless? ensure diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 0aefba4d..95cf90d2 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -20,8 +20,9 @@ def initialize(options) def run @server = ::Protobuf::Rpc::Zmq::Server.new(@options) register_signals - yield if block_given? - @server.run + @server.run do + yield if block_given? + end end def running? diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index dd6d404d..e58f4bf0 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -7,9 +7,23 @@ File.expand_path('../../../support/test_app_file.rb', __FILE__) end - let(:sock_runner) { double "SocketRunner", run: nil, register_signals: nil } - let(:zmq_runner) { double "ZmqRunner", run: nil, register_signals: nil } - let(:evented_runner) { double "EventedRunner", run: nil, register_signals: nil } + let(:sock_runner) { + runner = double("SocketRunner", :register_signals => nil) + runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } + runner + } + + let(:zmq_runner) { + runner = double "ZmqRunner", register_signals: nil + runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } + runner + } + + let(:evented_runner) { + runner = double "EventedRunner", register_signals: nil + runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } + runner + } before(:each) do ::Protobuf::Rpc::SocketRunner.stub(:new) { sock_runner } From f5748b775f0aec60046d1391a5079f6b73b04028 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 19 Jul 2013 16:43:02 -0600 Subject: [PATCH 0466/1191] add specs for lifecycle class --- lib/protobuf/lifecycle.rb | 1 + spec/lib/protobuf/lifecycle_spec.rb | 70 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 spec/lib/protobuf/lifecycle_spec.rb diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 8ac8dd3f..4727b18a 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -2,6 +2,7 @@ module Protobuf class Lifecycle def self.register( event_name, &blk ) + raise "Lifecycle register must have a block" unless block_given? event_name = normalized_event_name( event_name ) lifecycle_events[ event_name ] ||= [] diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb new file mode 100644 index 00000000..5a108acc --- /dev/null +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -0,0 +1,70 @@ +require 'spec_helper' +require 'protobuf/lifecycle' + +describe ::Protobuf::Lifecycle do + subject { described_class } + + before(:each) do + described_class.lifecycle_events = {} + end + + it "registers a string as the event_name" do + expect { + subject.register("something") do + true + end + }.to change { subject.lifecycle_events.size }.by(1) + end + + it "registers a symbol as the event_name" do + expect { + subject.register("something") do + true + end + }.to change { subject.lifecycle_events.size }.by(1) + end + + it "only registers blocks for event callbacks" do + expect { + subject.register("something") + }.to raise_error( /block/ ) + end + + it "calls the registered block when triggered" do + this = nil + subject.register("this") do + this = "not nil" + end + + subject.trigger("this") + this.should_not be_nil + this.should eq("not nil") + end + + it "calls multiple registered blocks when triggered" do + this = nil + that = nil + + subject.register("this") do + this = "not nil" + end + + subject.register("this") do + that = "not nil" + end + + subject.trigger("this") + this.should_not be_nil + this.should eq("not nil") + that.should_not be_nil + that.should eq("not nil") + end + + context "normalized event names" do + specify { subject.normalized_event_name(:derp).should eq("derp") } + specify { subject.normalized_event_name(:Derp).should eq("derp") } + specify { subject.normalized_event_name("DERP").should eq("derp") } + specify { subject.normalized_event_name("derp").should eq("derp") } + end + +end From 228a92743ec4b65cea370c8a17949eda76ec8ac6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 19 Jul 2013 16:57:48 -0600 Subject: [PATCH 0467/1191] bump to 2.8.0.beta9 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 250b5b14..253ada00 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta8' + VERSION = '2.8.0.beta9' PROTOC_VERSION = '2.4.1' end From d1c8a41904a434b5e8e821826ef7c26bc2953b66 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 18 Jul 2013 15:18:29 -0600 Subject: [PATCH 0468/1191] Add encoding tests --- Rakefile | 17 +- lib/protobuf/field/varint_field.rb | 11 +- spec/encoding/all_types_spec.rb | 91 +++ spec/encoding/extreme_values_spec.rb | Bin 0 -> 1352 bytes spec/spec_helper.rb | 12 - spec/support/test/all_types.data.txt | 119 +++ spec/support/test/google_unittest.pb.rb | 534 +++++++++++++ spec/support/test/google_unittest.proto | 713 ++++++++++++++++++ .../support/test/google_unittest_import.pb.rb | 37 + .../support/test/google_unittest_import.proto | 64 ++ .../test/google_unittest_import_public.pb.rb | 8 + .../test/google_unittest_import_public.proto | 38 + 12 files changed, 1623 insertions(+), 21 deletions(-) create mode 100644 spec/encoding/all_types_spec.rb create mode 100644 spec/encoding/extreme_values_spec.rb create mode 100644 spec/support/test/all_types.data.txt create mode 100644 spec/support/test/google_unittest.pb.rb create mode 100644 spec/support/test/google_unittest.proto create mode 100644 spec/support/test/google_unittest_import.pb.rb create mode 100644 spec/support/test/google_unittest_import.proto create mode 100644 spec/support/test/google_unittest_import_public.pb.rb create mode 100644 spec/support/test/google_unittest_import_public.proto diff --git a/Rakefile b/Rakefile index 15f786bc..4e0fd214 100644 --- a/Rakefile +++ b/Rakefile @@ -8,12 +8,25 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" -desc "Default: run specs." -task :default => :spec +desc "Default: compile test protos and run specs." +task :default => [:compile_protos, :spec] desc "Run specs" RSpec::Core::RakeTask.new(:spec) +desc "Compile test protos" +task :compile_protos do + unless defined?(JRUBY_VERSION) + unless ENV['NO_COMPILE_TEST_PROTOS'] + $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' + proto_path = File.expand_path("../spec/support/", __FILE__) + cmd = "rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')}" + puts cmd + %x{#{cmd}} + end + end +end + ## # rake-compiler # diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index fce10667..7eba8d20 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -4,8 +4,8 @@ module Protobuf module Field class VarintField < BaseField INT32_MAX = 2**31 - 1 - INT32_MIN = -2**31 - INT64_MAX = 2**63 - 1 + INT32_MIN = -2**31 + INT64_MAX = 2**63 - 1 INT64_MIN = -2**63 UINT32_MAX = 2**32 - 1 UINT64_MAX = 2**64 - 1 @@ -26,15 +26,12 @@ def self.decode(bytes) end def self.encode(value) - return [value].pack('C') if value < 128 - bytes = [] - until value == 0 + until value < 128 bytes << (0x80 | (value & 0x7f)) value >>= 7 end - bytes[-1] &= 0x7f - bytes.pack('C*') + (bytes << value).pack('C*') end ## diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb new file mode 100644 index 00000000..3f278cbf --- /dev/null +++ b/spec/encoding/all_types_spec.rb @@ -0,0 +1,91 @@ +require 'spec_helper' + +describe ::Protobuf do + it "correctly encodes all types" do + message = GoogleUnittest::TestAllTypes.new( + optional_int32: 101, + optional_int64: 102, + optional_uint32: 103, + optional_uint64: 104, + optional_sint32: 105, + optional_sint64: 106, + optional_fixed32: 107, + optional_fixed64: 108, + optional_sfixed32: 109, + optional_sfixed64: 110, + optional_float: 111, + optional_double: 112, + optional_bool: true, + optional_string: "115", + optional_bytes: "116", + optional_nested_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 118), + optional_foreign_message: GoogleUnittest::ForeignMessage.new(c: 119), + optional_import_message: GoogleUnittestImport::ImportMessage.new(d: 120), + optional_nested_enum: GoogleUnittest::TestAllTypes::NestedEnum::BAZ, + optional_foreign_enum: GoogleUnittest::ForeignEnum::FOREIGN_BAZ, + optional_import_enum: GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + optional_string_piece: "124", + optional_cord: "125", + optional_public_import_message: GoogleUnittestImport::PublicImportMessage.new(e: 126), + optional_lazy_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 127), + repeated_int32: [201, 301], + repeated_int64: [202, 302], + repeated_uint32: [203, 303], + repeated_uint64: [204, 304], + repeated_sint32: [205, 305], + repeated_sint64: [206, 306], + repeated_fixed32: [207, 307], + repeated_fixed64: [208, 308], + repeated_sfixed32: [209, 309], + repeated_sfixed64: [210, 310], + repeated_float: [211, 311], + repeated_double: [212, 312], + repeated_bool: [true, false], + repeated_string: ["215", "315"], + repeated_bytes: ["216", "316"], + repeated_nested_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 218), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 318)], + repeated_foreign_message: [::GoogleUnittest::ForeignMessage.new(c: 219), + ::GoogleUnittest::ForeignMessage.new(c: 319)], + repeated_import_message: [::GoogleUnittestImport::ImportMessage.new(d: 220), + ::GoogleUnittestImport::ImportMessage.new(d: 320)], + repeated_nested_enum: [::GoogleUnittest::TestAllTypes::NestedEnum::BAR, + ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ], + repeated_foreign_enum: [::GoogleUnittest::ForeignEnum::FOREIGN_BAR, + ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ], + repeated_import_enum: [::GoogleUnittestImport::ImportEnum::IMPORT_BAR, + ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ], + repeated_string_piece: ["224", "324"], + repeated_cord: ["225", "325"], + repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:227), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:327)], + default_int32: 401, + default_int64: 402, + default_uint32: 403, + default_uint64: 404, + default_sint32: 405, + default_sint64: 406, + default_fixed32: 407, + default_fixed64: 408, + default_sfixed32: 409, + default_sfixed64: 410, + default_float: 411, + default_double: 412, + default_bool: false, + default_string: "415", + default_bytes: "416", + default_nested_enum: ::GoogleUnittest::TestAllTypes::NestedEnum::FOO, + default_foreign_enum: ::GoogleUnittest::ForeignEnum::FOREIGN_FOO, + default_import_enum: ::GoogleUnittestImport::ImportEnum::IMPORT_FOO, + default_string_piece: "424", + default_cord: "425", + ) + + data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__) + data = File.open(data_file_path, 'rb') do |file| + file.read + end + + data.should eq message.serialize_to_string + end +end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..8f8c0b9d9328f9b024258fb5c398afa3ea9071c3 GIT binary patch literal 1352 zcmaKsYj2w{6o&ITzrxBFTCEUn2?VK~CT*D_P0>DdlO`cq1`dfO*QUnwrvCVuOYJsm zmp~xqdEaxekB@}gj!HmI+dzqrz#5Rwd|p9YN?HKQvY%2YQFJw`#2g{2(4rJlLaEpz z0$vJ@B6v^|ZUEg8)#Vvy&;TYW9NoJoWyCgjuYc&kkQWF zgkcmVp&zZ&Rh%TN)VFM>>J+z1Qhpd;s|&&?w&_2C6u4%BsQ$5UVh9d)I55LwXu}7d zO`OAlD0&C@jnuVT0~opcT0c&tc^1MaKRt>2jzbD=XfeubT#2q=x)83=wtuZG+wHfz z{qFjYG1E4Bf?t#FhbZCy8t%XBjaTnua{ka|3TVLp#xvAp_c~nJG*~a@L6YV;tmkK> zzthoQmilz<@=DOv^oUKxj5TVD%1+%W`C)BY$yiqSo~k46>u5+w@9P;8HiKbDoiO)8 z&RAuc$*7@F!U;->S!qGt4yqF%2xrk^*o^1%;ZhMra7`KDhA2HrXsho%cxVW(hM_aZ z^OpK(yQUFRE&DdHoZ1Q=+ltqlcm?Io1;Ti{`|%CqbL0NvDH`BsZ^K<6M;6Yx?n>yn u&*6D$6aBrXr??va1FvkZUV9WBs}S72G%>FQNeQD*fR&gwuh#Xd{`?DvYKKt( literal 0 HcmV?d00001 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 98ae56be..e5eae29a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,18 +25,6 @@ ::RSpec.configure do |c| c.include(::Sander6::CustomMatchers) c.mock_with :rspec - - c.before(:suite) do - unless defined?(JRUBY_VERSION) - unless ENV['NO_COMPILE_TEST_PROTOS'] - $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - proto_path = File.expand_path("../support/", __FILE__) - cmd = %Q{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } - puts cmd - %x{#{cmd}} - end - end - end end Dir[File.expand_path('../support/**/*.pb.rb', __FILE__)].each do |proto_file| diff --git a/spec/support/test/all_types.data.txt b/spec/support/test/all_types.data.txt new file mode 100644 index 00000000..fc2088dd --- /dev/null +++ b/spec/support/test/all_types.data.txt @@ -0,0 +1,119 @@ +optional_int32: 101 +optional_int64: 102 +optional_uint32: 103 +optional_uint64: 104 +optional_sint32: 105 +optional_sint64: 106 +optional_fixed32: 107 +optional_fixed64: 108 +optional_sfixed32: 109 +optional_sfixed64: 110 +optional_float: 111 +optional_double: 112 +optional_bool: true +optional_string: "115" +optional_bytes: "116" +optional_nested_message { + bb: 118 +} +optional_foreign_message { + c: 119 +} +optional_import_message { + d: 120 +} +optional_nested_enum: BAZ +optional_foreign_enum: FOREIGN_BAZ +optional_import_enum: IMPORT_BAZ +optional_string_piece: "124" +optional_cord: "125" +optional_public_import_message { + e: 126 +} +optional_lazy_message { + bb: 127 +} +repeated_int32: 201 +repeated_int32: 301 +repeated_int64: 202 +repeated_int64: 302 +repeated_uint32: 203 +repeated_uint32: 303 +repeated_uint64: 204 +repeated_uint64: 304 +repeated_sint32: 205 +repeated_sint32: 305 +repeated_sint64: 206 +repeated_sint64: 306 +repeated_fixed32: 207 +repeated_fixed32: 307 +repeated_fixed64: 208 +repeated_fixed64: 308 +repeated_sfixed32: 209 +repeated_sfixed32: 309 +repeated_sfixed64: 210 +repeated_sfixed64: 310 +repeated_float: 211 +repeated_float: 311 +repeated_double: 212 +repeated_double: 312 +repeated_bool: true +repeated_bool: false +repeated_string: "215" +repeated_string: "315" +repeated_bytes: "216" +repeated_bytes: "316" +repeated_nested_message { + bb: 218 +} +repeated_nested_message { + bb: 318 +} +repeated_foreign_message { + c: 219 +} +repeated_foreign_message { + c: 319 +} +repeated_import_message { + d: 220 +} +repeated_import_message { + d: 320 +} +repeated_nested_enum: BAR +repeated_nested_enum: BAZ +repeated_foreign_enum: FOREIGN_BAR +repeated_foreign_enum: FOREIGN_BAZ +repeated_import_enum: IMPORT_BAR +repeated_import_enum: IMPORT_BAZ +repeated_string_piece: "224" +repeated_string_piece: "324" +repeated_cord: "225" +repeated_cord: "325" +repeated_lazy_message { + bb: 227 +} +repeated_lazy_message { + bb: 327 +} +default_int32: 401 +default_int64: 402 +default_uint32: 403 +default_uint64: 404 +default_sint32: 405 +default_sint64: 406 +default_fixed32: 407 +default_fixed64: 408 +default_sfixed32: 409 +default_sfixed64: 410 +default_float: 411 +default_double: 412 +default_bool: false +default_string: "415" +default_bytes: "416" +default_nested_enum: FOO +default_foreign_enum: FOREIGN_FOO +default_import_enum: IMPORT_FOO +default_string_piece: "424" +default_cord: "425" diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb new file mode 100644 index 00000000..089ecb4c --- /dev/null +++ b/spec/support/test/google_unittest.pb.rb @@ -0,0 +1,534 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' +require 'protobuf/rpc/service' + +## +# Imports +# +require 'test/google_unittest_import.pb' + +module GoogleUnittest + + ## + # Enum Classes + # + class ForeignEnum < ::Protobuf::Enum + define :FOREIGN_FOO, 4 + define :FOREIGN_BAR, 5 + define :FOREIGN_BAZ, 6 + end + + class TestSparseEnum < ::Protobuf::Enum + define :SPARSE_A, 123 + define :SPARSE_B, 62374 + define :SPARSE_C, 12589234 + define :SPARSE_D, -15 + define :SPARSE_E, -53452 + define :SPARSE_F, 0 + define :SPARSE_G, 2 + end + + + ## + # Message Classes + # + class TestAllTypes < ::Protobuf::Message + class NestedEnum < ::Protobuf::Enum + define :FOO, 1 + define :BAR, 2 + define :BAZ, 3 + end + + class NestedMessage < ::Protobuf::Message; end + end + class TestDeprecatedFields < ::Protobuf::Message; end + class ForeignMessage < ::Protobuf::Message; end + class TestAllExtensions < ::Protobuf::Message; end + class TestNestedExtension < ::Protobuf::Message; end + class TestRequired < ::Protobuf::Message; end + class TestRequiredForeign < ::Protobuf::Message; end + class TestForeignNested < ::Protobuf::Message; end + class TestEmptyMessage < ::Protobuf::Message; end + class TestEmptyMessageWithExtensions < ::Protobuf::Message; end + class TestMultipleExtensionRanges < ::Protobuf::Message; end + class TestReallyLargeTagNumber < ::Protobuf::Message; end + class TestRecursiveMessage < ::Protobuf::Message; end + class TestMutualRecursionA < ::Protobuf::Message; end + class TestMutualRecursionB < ::Protobuf::Message; end + class TestDupFieldNumber < ::Protobuf::Message; end + class TestEagerMessage < ::Protobuf::Message; end + class TestLazyMessage < ::Protobuf::Message; end + class TestNestedMessageHasBits < ::Protobuf::Message + class NestedMessage < ::Protobuf::Message; end + end + class TestCamelCaseFieldNames < ::Protobuf::Message; end + class TestFieldOrderings < ::Protobuf::Message; end + class TestExtremeDefaultValues < ::Protobuf::Message; end + class SparseEnumMessage < ::Protobuf::Message; end + class OneString < ::Protobuf::Message; end + class MoreString < ::Protobuf::Message; end + class OneBytes < ::Protobuf::Message; end + class MoreBytes < ::Protobuf::Message; end + class TestPackedTypes < ::Protobuf::Message; end + class TestUnpackedTypes < ::Protobuf::Message; end + class TestPackedExtensions < ::Protobuf::Message; end + class TestDynamicExtensions < ::Protobuf::Message + class DynamicEnumType < ::Protobuf::Enum + define :DYNAMIC_FOO, 2200 + define :DYNAMIC_BAR, 2201 + define :DYNAMIC_BAZ, 2202 + end + + class DynamicMessageType < ::Protobuf::Message; end + end + class TestRepeatedScalarDifferentTagSizes < ::Protobuf::Message; end + class TestParsingMerge < ::Protobuf::Message + class RepeatedFieldsGenerator < ::Protobuf::Message; end + end + class TestCommentInjectionMessage < ::Protobuf::Message; end + class FooRequest < ::Protobuf::Message; end + class FooResponse < ::Protobuf::Message; end + class FooClientMessage < ::Protobuf::Message; end + class FooServerMessage < ::Protobuf::Message; end + class BarRequest < ::Protobuf::Message; end + class BarResponse < ::Protobuf::Message; end + + ## + # Message Fields + # + class TestAllTypes + class NestedMessage + optional ::Protobuf::Field::Int32Field, :bb, 1 + end + + optional ::Protobuf::Field::Int32Field, :optional_int32, 1 + optional ::Protobuf::Field::Int64Field, :optional_int64, 2 + optional ::Protobuf::Field::Uint32Field, :optional_uint32, 3 + optional ::Protobuf::Field::Uint64Field, :optional_uint64, 4 + optional ::Protobuf::Field::Sint32Field, :optional_sint32, 5 + optional ::Protobuf::Field::Sint64Field, :optional_sint64, 6 + optional ::Protobuf::Field::Fixed32Field, :optional_fixed32, 7 + optional ::Protobuf::Field::Fixed64Field, :optional_fixed64, 8 + optional ::Protobuf::Field::Sfixed32Field, :optional_sfixed32, 9 + optional ::Protobuf::Field::Sfixed64Field, :optional_sfixed64, 10 + optional ::Protobuf::Field::FloatField, :optional_float, 11 + optional ::Protobuf::Field::DoubleField, :optional_double, 12 + optional ::Protobuf::Field::BoolField, :optional_bool, 13 + optional ::Protobuf::Field::StringField, :optional_string, 14 + optional ::Protobuf::Field::BytesField, :optional_bytes, 15 + optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message, 18 + optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message, 19 + optional ::GoogleUnittestImport::ImportMessage, :optional_import_message, 20 + optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21 + optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum, 22 + optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum, 23 + optional ::Protobuf::Field::StringField, :optional_string_piece, 24 + optional ::Protobuf::Field::StringField, :optional_cord, 25 + optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message, 26 + optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27 + repeated ::Protobuf::Field::Int32Field, :repeated_int32, 31 + repeated ::Protobuf::Field::Int64Field, :repeated_int64, 32 + repeated ::Protobuf::Field::Uint32Field, :repeated_uint32, 33 + repeated ::Protobuf::Field::Uint64Field, :repeated_uint64, 34 + repeated ::Protobuf::Field::Sint32Field, :repeated_sint32, 35 + repeated ::Protobuf::Field::Sint64Field, :repeated_sint64, 36 + repeated ::Protobuf::Field::Fixed32Field, :repeated_fixed32, 37 + repeated ::Protobuf::Field::Fixed64Field, :repeated_fixed64, 38 + repeated ::Protobuf::Field::Sfixed32Field, :repeated_sfixed32, 39 + repeated ::Protobuf::Field::Sfixed64Field, :repeated_sfixed64, 40 + repeated ::Protobuf::Field::FloatField, :repeated_float, 41 + repeated ::Protobuf::Field::DoubleField, :repeated_double, 42 + repeated ::Protobuf::Field::BoolField, :repeated_bool, 43 + repeated ::Protobuf::Field::StringField, :repeated_string, 44 + repeated ::Protobuf::Field::BytesField, :repeated_bytes, 45 + repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message, 48 + repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message, 49 + repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message, 50 + repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51 + repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum, 52 + repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum, 53 + repeated ::Protobuf::Field::StringField, :repeated_string_piece, 54 + repeated ::Protobuf::Field::StringField, :repeated_cord, 55 + repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57 + optional ::Protobuf::Field::Int32Field, :default_int32, 61, :default => 41 + optional ::Protobuf::Field::Int64Field, :default_int64, 62, :default => 42 + optional ::Protobuf::Field::Uint32Field, :default_uint32, 63, :default => 43 + optional ::Protobuf::Field::Uint64Field, :default_uint64, 64, :default => 44 + optional ::Protobuf::Field::Sint32Field, :default_sint32, 65, :default => -45 + optional ::Protobuf::Field::Sint64Field, :default_sint64, 66, :default => 46 + optional ::Protobuf::Field::Fixed32Field, :default_fixed32, 67, :default => 47 + optional ::Protobuf::Field::Fixed64Field, :default_fixed64, 68, :default => 48 + optional ::Protobuf::Field::Sfixed32Field, :default_sfixed32, 69, :default => 49 + optional ::Protobuf::Field::Sfixed64Field, :default_sfixed64, 70, :default => -50 + optional ::Protobuf::Field::FloatField, :default_float, 71, :default => 51.5 + optional ::Protobuf::Field::DoubleField, :default_double, 72, :default => 52000 + optional ::Protobuf::Field::BoolField, :default_bool, 73, :default => true + optional ::Protobuf::Field::StringField, :default_string, 74, :default => "hello" + optional ::Protobuf::Field::BytesField, :default_bytes, 75, :default => "world" + optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR + optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR + optional ::GoogleUnittestImport::ImportEnum, :default_import_enum, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR + optional ::Protobuf::Field::StringField, :default_string_piece, 84, :default => "abc" + optional ::Protobuf::Field::StringField, :default_cord, 85, :default => "123" + end + + class TestDeprecatedFields + optional ::Protobuf::Field::Int32Field, :deprecated_int32, 1, :deprecated => true + end + + class ForeignMessage + optional ::Protobuf::Field::Int32Field, :c, 1 + end + + class TestAllExtensions + + # Extension Fields + extensions 1...536870912 + optional ::Protobuf::Field::Int32Field, :optional_int32_extension, 1, :extension => true + optional ::Protobuf::Field::Int64Field, :optional_int64_extension, 2, :extension => true + optional ::Protobuf::Field::Uint32Field, :optional_uint32_extension, 3, :extension => true + optional ::Protobuf::Field::Uint64Field, :optional_uint64_extension, 4, :extension => true + optional ::Protobuf::Field::Sint32Field, :optional_sint32_extension, 5, :extension => true + optional ::Protobuf::Field::Sint64Field, :optional_sint64_extension, 6, :extension => true + optional ::Protobuf::Field::Fixed32Field, :optional_fixed32_extension, 7, :extension => true + optional ::Protobuf::Field::Fixed64Field, :optional_fixed64_extension, 8, :extension => true + optional ::Protobuf::Field::Sfixed32Field, :optional_sfixed32_extension, 9, :extension => true + optional ::Protobuf::Field::Sfixed64Field, :optional_sfixed64_extension, 10, :extension => true + optional ::Protobuf::Field::FloatField, :optional_float_extension, 11, :extension => true + optional ::Protobuf::Field::DoubleField, :optional_double_extension, 12, :extension => true + optional ::Protobuf::Field::BoolField, :optional_bool_extension, 13, :extension => true + optional ::Protobuf::Field::StringField, :optional_string_extension, 14, :extension => true + optional ::Protobuf::Field::BytesField, :optional_bytes_extension, 15, :extension => true + optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message_extension, 18, :extension => true + optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message_extension, 19, :extension => true + optional ::GoogleUnittestImport::ImportMessage, :optional_import_message_extension, 20, :extension => true + optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum_extension, 21, :extension => true + optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum_extension, 22, :extension => true + optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum_extension, 23, :extension => true + optional ::Protobuf::Field::StringField, :optional_string_piece_extension, 24, :extension => true + optional ::Protobuf::Field::StringField, :optional_cord_extension, 25, :extension => true + optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message_extension, 26, :extension => true + optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message_extension, 27, :extension => true + repeated ::Protobuf::Field::Int32Field, :repeated_int32_extension, 31, :extension => true + repeated ::Protobuf::Field::Int64Field, :repeated_int64_extension, 32, :extension => true + repeated ::Protobuf::Field::Uint32Field, :repeated_uint32_extension, 33, :extension => true + repeated ::Protobuf::Field::Uint64Field, :repeated_uint64_extension, 34, :extension => true + repeated ::Protobuf::Field::Sint32Field, :repeated_sint32_extension, 35, :extension => true + repeated ::Protobuf::Field::Sint64Field, :repeated_sint64_extension, 36, :extension => true + repeated ::Protobuf::Field::Fixed32Field, :repeated_fixed32_extension, 37, :extension => true + repeated ::Protobuf::Field::Fixed64Field, :repeated_fixed64_extension, 38, :extension => true + repeated ::Protobuf::Field::Sfixed32Field, :repeated_sfixed32_extension, 39, :extension => true + repeated ::Protobuf::Field::Sfixed64Field, :repeated_sfixed64_extension, 40, :extension => true + repeated ::Protobuf::Field::FloatField, :repeated_float_extension, 41, :extension => true + repeated ::Protobuf::Field::DoubleField, :repeated_double_extension, 42, :extension => true + repeated ::Protobuf::Field::BoolField, :repeated_bool_extension, 43, :extension => true + repeated ::Protobuf::Field::StringField, :repeated_string_extension, 44, :extension => true + repeated ::Protobuf::Field::BytesField, :repeated_bytes_extension, 45, :extension => true + repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message_extension, 48, :extension => true + repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message_extension, 49, :extension => true + repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message_extension, 50, :extension => true + repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum_extension, 51, :extension => true + repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum_extension, 52, :extension => true + repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum_extension, 53, :extension => true + repeated ::Protobuf::Field::StringField, :repeated_string_piece_extension, 54, :extension => true + repeated ::Protobuf::Field::StringField, :repeated_cord_extension, 55, :extension => true + repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message_extension, 57, :extension => true + optional ::Protobuf::Field::Int32Field, :default_int32_extension, 61, :default => 41, :extension => true + optional ::Protobuf::Field::Int64Field, :default_int64_extension, 62, :default => 42, :extension => true + optional ::Protobuf::Field::Uint32Field, :default_uint32_extension, 63, :default => 43, :extension => true + optional ::Protobuf::Field::Uint64Field, :default_uint64_extension, 64, :default => 44, :extension => true + optional ::Protobuf::Field::Sint32Field, :default_sint32_extension, 65, :default => -45, :extension => true + optional ::Protobuf::Field::Sint64Field, :default_sint64_extension, 66, :default => 46, :extension => true + optional ::Protobuf::Field::Fixed32Field, :default_fixed32_extension, 67, :default => 47, :extension => true + optional ::Protobuf::Field::Fixed64Field, :default_fixed64_extension, 68, :default => 48, :extension => true + optional ::Protobuf::Field::Sfixed32Field, :default_sfixed32_extension, 69, :default => 49, :extension => true + optional ::Protobuf::Field::Sfixed64Field, :default_sfixed64_extension, 70, :default => -50, :extension => true + optional ::Protobuf::Field::FloatField, :default_float_extension, 71, :default => 51.5, :extension => true + optional ::Protobuf::Field::DoubleField, :default_double_extension, 72, :default => 52000, :extension => true + optional ::Protobuf::Field::BoolField, :default_bool_extension, 73, :default => true, :extension => true + optional ::Protobuf::Field::StringField, :default_string_extension, 74, :default => "hello", :extension => true + optional ::Protobuf::Field::BytesField, :default_bytes_extension, 75, :default => "world", :extension => true + optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum_extension, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, :extension => true + optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum_extension, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, :extension => true + optional ::GoogleUnittestImport::ImportEnum, :default_import_enum_extension, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, :extension => true + optional ::Protobuf::Field::StringField, :default_string_piece_extension, 84, :default => "abc", :extension => true + optional ::Protobuf::Field::StringField, :default_cord_extension, 85, :default => "123", :extension => true + optional ::Protobuf::Field::StringField, :test, 1002, :default => "test", :extension => true + optional ::GoogleUnittest::TestRequired, :single, 1000, :extension => true + repeated ::GoogleUnittest::TestRequired, :multi, 1001, :extension => true + end + + class TestRequired + required ::Protobuf::Field::Int32Field, :a, 1 + optional ::Protobuf::Field::Int32Field, :dummy2, 2 + required ::Protobuf::Field::Int32Field, :b, 3 + optional ::Protobuf::Field::Int32Field, :dummy4, 4 + optional ::Protobuf::Field::Int32Field, :dummy5, 5 + optional ::Protobuf::Field::Int32Field, :dummy6, 6 + optional ::Protobuf::Field::Int32Field, :dummy7, 7 + optional ::Protobuf::Field::Int32Field, :dummy8, 8 + optional ::Protobuf::Field::Int32Field, :dummy9, 9 + optional ::Protobuf::Field::Int32Field, :dummy10, 10 + optional ::Protobuf::Field::Int32Field, :dummy11, 11 + optional ::Protobuf::Field::Int32Field, :dummy12, 12 + optional ::Protobuf::Field::Int32Field, :dummy13, 13 + optional ::Protobuf::Field::Int32Field, :dummy14, 14 + optional ::Protobuf::Field::Int32Field, :dummy15, 15 + optional ::Protobuf::Field::Int32Field, :dummy16, 16 + optional ::Protobuf::Field::Int32Field, :dummy17, 17 + optional ::Protobuf::Field::Int32Field, :dummy18, 18 + optional ::Protobuf::Field::Int32Field, :dummy19, 19 + optional ::Protobuf::Field::Int32Field, :dummy20, 20 + optional ::Protobuf::Field::Int32Field, :dummy21, 21 + optional ::Protobuf::Field::Int32Field, :dummy22, 22 + optional ::Protobuf::Field::Int32Field, :dummy23, 23 + optional ::Protobuf::Field::Int32Field, :dummy24, 24 + optional ::Protobuf::Field::Int32Field, :dummy25, 25 + optional ::Protobuf::Field::Int32Field, :dummy26, 26 + optional ::Protobuf::Field::Int32Field, :dummy27, 27 + optional ::Protobuf::Field::Int32Field, :dummy28, 28 + optional ::Protobuf::Field::Int32Field, :dummy29, 29 + optional ::Protobuf::Field::Int32Field, :dummy30, 30 + optional ::Protobuf::Field::Int32Field, :dummy31, 31 + optional ::Protobuf::Field::Int32Field, :dummy32, 32 + required ::Protobuf::Field::Int32Field, :c, 33 + end + + class TestRequiredForeign + optional ::GoogleUnittest::TestRequired, :optional_message, 1 + repeated ::GoogleUnittest::TestRequired, :repeated_message, 2 + optional ::Protobuf::Field::Int32Field, :dummy, 3 + end + + class TestForeignNested + optional ::GoogleUnittest::TestAllTypes::NestedMessage, :foreign_nested, 1 + end + + class TestReallyLargeTagNumber + optional ::Protobuf::Field::Int32Field, :a, 1 + optional ::Protobuf::Field::Int32Field, :bb, 268435455 + end + + class TestRecursiveMessage + optional ::GoogleUnittest::TestRecursiveMessage, :a, 1 + optional ::Protobuf::Field::Int32Field, :i, 2 + end + + class TestMutualRecursionA + optional ::GoogleUnittest::TestMutualRecursionB, :bb, 1 + end + + class TestMutualRecursionB + optional ::GoogleUnittest::TestMutualRecursionA, :a, 1 + optional ::Protobuf::Field::Int32Field, :optional_int32, 2 + end + + class TestDupFieldNumber + optional ::Protobuf::Field::Int32Field, :a, 1 + end + + class TestEagerMessage + optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 + end + + class TestLazyMessage + optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 + end + + class TestNestedMessageHasBits + class NestedMessage + repeated ::Protobuf::Field::Int32Field, :nestedmessage_repeated_int32, 1 + repeated ::GoogleUnittest::ForeignMessage, :nestedmessage_repeated_foreignmessage, 2 + end + + optional ::GoogleUnittest::TestNestedMessageHasBits::NestedMessage, :optional_nested_message, 1 + end + + class TestCamelCaseFieldNames + optional ::Protobuf::Field::Int32Field, :primitivefield, 1 + optional ::Protobuf::Field::StringField, :stringfield, 2 + optional ::GoogleUnittest::ForeignEnum, :enumfield, 3 + optional ::GoogleUnittest::ForeignMessage, :messagefield, 4 + optional ::Protobuf::Field::StringField, :stringpiecefield, 5 + optional ::Protobuf::Field::StringField, :cordfield, 6 + repeated ::Protobuf::Field::Int32Field, :repeatedprimitivefield, 7 + repeated ::Protobuf::Field::StringField, :repeatedstringfield, 8 + repeated ::GoogleUnittest::ForeignEnum, :repeatedenumfield, 9 + repeated ::GoogleUnittest::ForeignMessage, :repeatedmessagefield, 10 + repeated ::Protobuf::Field::StringField, :repeatedstringpiecefield, 11 + repeated ::Protobuf::Field::StringField, :repeatedcordfield, 12 + end + + class TestFieldOrderings + optional ::Protobuf::Field::StringField, :my_string, 11 + optional ::Protobuf::Field::Int64Field, :my_int, 1 + optional ::Protobuf::Field::FloatField, :my_float, 101 + + # Extension Fields + extensions 2...11 + extensions 12...101 + optional ::Protobuf::Field::StringField, :my_extension_string, 50, :extension => true + optional ::Protobuf::Field::Int32Field, :my_extension_int, 5, :extension => true + end + + class TestExtremeDefaultValues + optional ::Protobuf::Field::BytesField, :escaped_bytes, 1, :default => "\0\001\a\b\f\n\r\t\v\\\'\"\xfe" + optional ::Protobuf::Field::Uint32Field, :large_uint32, 2, :default => 4294967295 + optional ::Protobuf::Field::Uint64Field, :large_uint64, 3, :default => 18446744073709551615 + optional ::Protobuf::Field::Int32Field, :small_int32, 4, :default => -2147483647 + optional ::Protobuf::Field::Int64Field, :small_int64, 5, :default => -9223372036854775807 + optional ::Protobuf::Field::Int32Field, :really_small_int32, 21, :default => -2147483648 + optional ::Protobuf::Field::Int64Field, :really_small_int64, 22, :default => -9223372036854775808 + optional ::Protobuf::Field::StringField, :utf8_string, 6, :default => "ሴ" + optional ::Protobuf::Field::FloatField, :zero_float, 7, :default => 0 + optional ::Protobuf::Field::FloatField, :one_float, 8, :default => 1 + optional ::Protobuf::Field::FloatField, :small_float, 9, :default => 1.5 + optional ::Protobuf::Field::FloatField, :negative_one_float, 10, :default => -1 + optional ::Protobuf::Field::FloatField, :negative_float, 11, :default => -1.5 + optional ::Protobuf::Field::FloatField, :large_float, 12, :default => 2e+08 + optional ::Protobuf::Field::FloatField, :small_negative_float, 13, :default => -8e-28 + optional ::Protobuf::Field::DoubleField, :inf_double, 14, :default => Float::INFINITY + optional ::Protobuf::Field::DoubleField, :neg_inf_double, 15, :default => -Float::INFINITY + optional ::Protobuf::Field::DoubleField, :nan_double, 16, :default => Float::NAN + optional ::Protobuf::Field::FloatField, :inf_float, 17, :default => Float::INFINITY + optional ::Protobuf::Field::FloatField, :neg_inf_float, 18, :default => -Float::INFINITY + optional ::Protobuf::Field::FloatField, :nan_float, 19, :default => Float::NAN + optional ::Protobuf::Field::StringField, :cpp_trigraph, 20, :default => "? ? ?? ?? ??? ??/ ??-" + optional ::Protobuf::Field::StringField, :string_with_zero, 23, :default => "hello" + optional ::Protobuf::Field::BytesField, :bytes_with_zero, 24, :default => "world" + optional ::Protobuf::Field::StringField, :string_piece_with_zero, 25, :default => "abc" + optional ::Protobuf::Field::StringField, :cord_with_zero, 26, :default => "123" + end + + class SparseEnumMessage + optional ::GoogleUnittest::TestSparseEnum, :sparse_enum, 1 + end + + class OneString + optional ::Protobuf::Field::StringField, :data, 1 + end + + class MoreString + repeated ::Protobuf::Field::StringField, :data, 1 + end + + class OneBytes + optional ::Protobuf::Field::BytesField, :data, 1 + end + + class MoreBytes + repeated ::Protobuf::Field::BytesField, :data, 1 + end + + class TestPackedTypes + repeated ::Protobuf::Field::Int32Field, :packed_int32, 90, :packed => true + repeated ::Protobuf::Field::Int64Field, :packed_int64, 91, :packed => true + repeated ::Protobuf::Field::Uint32Field, :packed_uint32, 92, :packed => true + repeated ::Protobuf::Field::Uint64Field, :packed_uint64, 93, :packed => true + repeated ::Protobuf::Field::Sint32Field, :packed_sint32, 94, :packed => true + repeated ::Protobuf::Field::Sint64Field, :packed_sint64, 95, :packed => true + repeated ::Protobuf::Field::Fixed32Field, :packed_fixed32, 96, :packed => true + repeated ::Protobuf::Field::Fixed64Field, :packed_fixed64, 97, :packed => true + repeated ::Protobuf::Field::Sfixed32Field, :packed_sfixed32, 98, :packed => true + repeated ::Protobuf::Field::Sfixed64Field, :packed_sfixed64, 99, :packed => true + repeated ::Protobuf::Field::FloatField, :packed_float, 100, :packed => true + repeated ::Protobuf::Field::DoubleField, :packed_double, 101, :packed => true + repeated ::Protobuf::Field::BoolField, :packed_bool, 102, :packed => true + repeated ::GoogleUnittest::ForeignEnum, :packed_enum, 103, :packed => true + end + + class TestUnpackedTypes + repeated ::Protobuf::Field::Int32Field, :unpacked_int32, 90, :packed => false + repeated ::Protobuf::Field::Int64Field, :unpacked_int64, 91, :packed => false + repeated ::Protobuf::Field::Uint32Field, :unpacked_uint32, 92, :packed => false + repeated ::Protobuf::Field::Uint64Field, :unpacked_uint64, 93, :packed => false + repeated ::Protobuf::Field::Sint32Field, :unpacked_sint32, 94, :packed => false + repeated ::Protobuf::Field::Sint64Field, :unpacked_sint64, 95, :packed => false + repeated ::Protobuf::Field::Fixed32Field, :unpacked_fixed32, 96, :packed => false + repeated ::Protobuf::Field::Fixed64Field, :unpacked_fixed64, 97, :packed => false + repeated ::Protobuf::Field::Sfixed32Field, :unpacked_sfixed32, 98, :packed => false + repeated ::Protobuf::Field::Sfixed64Field, :unpacked_sfixed64, 99, :packed => false + repeated ::Protobuf::Field::FloatField, :unpacked_float, 100, :packed => false + repeated ::Protobuf::Field::DoubleField, :unpacked_double, 101, :packed => false + repeated ::Protobuf::Field::BoolField, :unpacked_bool, 102, :packed => false + repeated ::GoogleUnittest::ForeignEnum, :unpacked_enum, 103, :packed => false + end + + class TestPackedExtensions + + # Extension Fields + extensions 1...536870912 + repeated ::Protobuf::Field::Int32Field, :packed_int32_extension, 90, :packed => true, :extension => true + repeated ::Protobuf::Field::Int64Field, :packed_int64_extension, 91, :packed => true, :extension => true + repeated ::Protobuf::Field::Uint32Field, :packed_uint32_extension, 92, :packed => true, :extension => true + repeated ::Protobuf::Field::Uint64Field, :packed_uint64_extension, 93, :packed => true, :extension => true + repeated ::Protobuf::Field::Sint32Field, :packed_sint32_extension, 94, :packed => true, :extension => true + repeated ::Protobuf::Field::Sint64Field, :packed_sint64_extension, 95, :packed => true, :extension => true + repeated ::Protobuf::Field::Fixed32Field, :packed_fixed32_extension, 96, :packed => true, :extension => true + repeated ::Protobuf::Field::Fixed64Field, :packed_fixed64_extension, 97, :packed => true, :extension => true + repeated ::Protobuf::Field::Sfixed32Field, :packed_sfixed32_extension, 98, :packed => true, :extension => true + repeated ::Protobuf::Field::Sfixed64Field, :packed_sfixed64_extension, 99, :packed => true, :extension => true + repeated ::Protobuf::Field::FloatField, :packed_float_extension, 100, :packed => true, :extension => true + repeated ::Protobuf::Field::DoubleField, :packed_double_extension, 101, :packed => true, :extension => true + repeated ::Protobuf::Field::BoolField, :packed_bool_extension, 102, :packed => true, :extension => true + repeated ::GoogleUnittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true + end + + class TestDynamicExtensions + class DynamicMessageType + optional ::Protobuf::Field::Int32Field, :dynamic_field, 2100 + end + + optional ::Protobuf::Field::Fixed32Field, :scalar_extension, 2000 + optional ::GoogleUnittest::ForeignEnum, :enum_extension, 2001 + optional ::GoogleUnittest::TestDynamicExtensions::DynamicEnumType, :dynamic_enum_extension, 2002 + optional ::GoogleUnittest::ForeignMessage, :message_extension, 2003 + optional ::GoogleUnittest::TestDynamicExtensions::DynamicMessageType, :dynamic_message_extension, 2004 + repeated ::Protobuf::Field::StringField, :repeated_extension, 2005 + repeated ::Protobuf::Field::Sint32Field, :packed_extension, 2006, :packed => true + end + + class TestRepeatedScalarDifferentTagSizes + repeated ::Protobuf::Field::Fixed32Field, :repeated_fixed32, 12 + repeated ::Protobuf::Field::Int32Field, :repeated_int32, 13 + repeated ::Protobuf::Field::Fixed64Field, :repeated_fixed64, 2046 + repeated ::Protobuf::Field::Int64Field, :repeated_int64, 2047 + repeated ::Protobuf::Field::FloatField, :repeated_float, 262142 + repeated ::Protobuf::Field::Uint64Field, :repeated_uint64, 262143 + end + + class TestParsingMerge + class RepeatedFieldsGenerator + repeated ::GoogleUnittest::TestAllTypes, :field1, 1 + repeated ::GoogleUnittest::TestAllTypes, :field2, 2 + repeated ::GoogleUnittest::TestAllTypes, :field3, 3 + repeated ::GoogleUnittest::TestAllTypes, :ext1, 1000 + repeated ::GoogleUnittest::TestAllTypes, :ext2, 1001 + end + + required ::GoogleUnittest::TestAllTypes, :required_all_types, 1 + optional ::GoogleUnittest::TestAllTypes, :optional_all_types, 2 + repeated ::GoogleUnittest::TestAllTypes, :repeated_all_types, 3 + + # Extension Fields + extensions 1000...536870912 + optional ::GoogleUnittest::TestAllTypes, :optional_ext, 1000, :extension => true + repeated ::GoogleUnittest::TestAllTypes, :repeated_ext, 1001, :extension => true + end + + class TestCommentInjectionMessage + optional ::Protobuf::Field::StringField, :a, 1, :default => "*/ <- Neither should this." + end + + + ## + # Services + # + class TestService < ::Protobuf::Rpc::Service + rpc :foo, ::GoogleUnittest::FooRequest, ::GoogleUnittest::FooResponse + rpc :bar, ::GoogleUnittest::BarRequest, ::GoogleUnittest::BarResponse + end +end + diff --git a/spec/support/test/google_unittest.proto b/spec/support/test/google_unittest.proto new file mode 100644 index 00000000..f97e882c --- /dev/null +++ b/spec/support/test/google_unittest.proto @@ -0,0 +1,713 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// A proto file we will use for unit testing. + +import "test/google_unittest_import.proto"; + +// We don't put this in a package within proto2 because we need to make sure +// that the generated code doesn't depend on being in the proto2 namespace. +// In test_util.h we do "using namespace unittest = google_unittest". +package googleUnittest; + +// This proto includes every type of field in both singular and repeated +// forms. +message TestAllTypes { + message NestedMessage { + // The field name "b" fails to compile in proto1 because it conflicts with + // a local variable named "b" in one of the generated methods. Doh. + // This file needs to compile in proto1 to test backwards-compatibility. + optional int32 bb = 1; + } + + enum NestedEnum { + FOO = 1; + BAR = 2; + BAZ = 3; + } + + // Singular + optional int32 optional_int32 = 1; + optional int64 optional_int64 = 2; + optional uint32 optional_uint32 = 3; + optional uint64 optional_uint64 = 4; + optional sint32 optional_sint32 = 5; + optional sint64 optional_sint64 = 6; + optional fixed32 optional_fixed32 = 7; + optional fixed64 optional_fixed64 = 8; + optional sfixed32 optional_sfixed32 = 9; + optional sfixed64 optional_sfixed64 = 10; + optional float optional_float = 11; + optional double optional_double = 12; + optional bool optional_bool = 13; + optional string optional_string = 14; + optional bytes optional_bytes = 15; + + // TODO: Support groups + //optional group OptionalGroup = 16 { + // optional int32 a = 17; + //} + + optional NestedMessage optional_nested_message = 18; + optional ForeignMessage optional_foreign_message = 19; + optional googleUnittestImport.ImportMessage optional_import_message = 20; + + optional NestedEnum optional_nested_enum = 21; + optional ForeignEnum optional_foreign_enum = 22; + optional googleUnittestImport.ImportEnum optional_import_enum = 23; + + optional string optional_string_piece = 24 [ctype=STRING_PIECE]; + optional string optional_cord = 25 [ctype=CORD]; + + // Defined in unittest_import_public.proto + optional googleUnittestImport.PublicImportMessage + optional_public_import_message = 26; + + optional NestedMessage optional_lazy_message = 27; // [lazy=true]; + + // Repeated + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; + repeated sfixed32 repeated_sfixed32 = 39; + repeated sfixed64 repeated_sfixed64 = 40; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; + + // TODO: Support groups + //repeated group RepeatedGroup = 46 { + // optional int32 a = 47; + //} + + repeated NestedMessage repeated_nested_message = 48; + repeated ForeignMessage repeated_foreign_message = 49; + repeated googleUnittestImport.ImportMessage repeated_import_message = 50; + + repeated NestedEnum repeated_nested_enum = 51; + repeated ForeignEnum repeated_foreign_enum = 52; + repeated googleUnittestImport.ImportEnum repeated_import_enum = 53; + + repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; + repeated string repeated_cord = 55 [ctype=CORD]; + + repeated NestedMessage repeated_lazy_message = 57; // [lazy=true]; + + // Singular with defaults + optional int32 default_int32 = 61 [default = 41 ]; + optional int64 default_int64 = 62 [default = 42 ]; + optional uint32 default_uint32 = 63 [default = 43 ]; + optional uint64 default_uint64 = 64 [default = 44 ]; + optional sint32 default_sint32 = 65 [default = -45 ]; + optional sint64 default_sint64 = 66 [default = 46 ]; + optional fixed32 default_fixed32 = 67 [default = 47 ]; + optional fixed64 default_fixed64 = 68 [default = 48 ]; + optional sfixed32 default_sfixed32 = 69 [default = 49 ]; + optional sfixed64 default_sfixed64 = 70 [default = -50 ]; + optional float default_float = 71 [default = 51.5 ]; + optional double default_double = 72 [default = 52e3 ]; + optional bool default_bool = 73 [default = true ]; + optional string default_string = 74 [default = "hello"]; + optional bytes default_bytes = 75 [default = "world"]; + + optional NestedEnum default_nested_enum = 81 [default = BAR ]; + optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; + optional googleUnittestImport.ImportEnum + default_import_enum = 83 [default = IMPORT_BAR]; + + optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; + optional string default_cord = 85 [ctype=CORD,default="123"]; +} + +message TestDeprecatedFields { + optional int32 deprecated_int32 = 1 [deprecated=true]; +} + +// Define these after TestAllTypes to make sure the compiler can handle +// that. +message ForeignMessage { + optional int32 c = 1; +} + +enum ForeignEnum { + FOREIGN_FOO = 4; + FOREIGN_BAR = 5; + FOREIGN_BAZ = 6; +} + +message TestAllExtensions { + extensions 1 to max; +} + +extend TestAllExtensions { + // Singular + optional int32 optional_int32_extension = 1; + optional int64 optional_int64_extension = 2; + optional uint32 optional_uint32_extension = 3; + optional uint64 optional_uint64_extension = 4; + optional sint32 optional_sint32_extension = 5; + optional sint64 optional_sint64_extension = 6; + optional fixed32 optional_fixed32_extension = 7; + optional fixed64 optional_fixed64_extension = 8; + optional sfixed32 optional_sfixed32_extension = 9; + optional sfixed64 optional_sfixed64_extension = 10; + optional float optional_float_extension = 11; + optional double optional_double_extension = 12; + optional bool optional_bool_extension = 13; + optional string optional_string_extension = 14; + optional bytes optional_bytes_extension = 15; + + // TODO: Support groups + //optional group OptionalGroup_extension = 16 { + // optional int32 a = 17; + //} + + optional TestAllTypes.NestedMessage optional_nested_message_extension = 18; + optional ForeignMessage optional_foreign_message_extension = 19; + optional googleUnittestImport.ImportMessage + optional_import_message_extension = 20; + + optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21; + optional ForeignEnum optional_foreign_enum_extension = 22; + optional googleUnittestImport.ImportEnum + optional_import_enum_extension = 23; + + optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE]; + optional string optional_cord_extension = 25 [ctype=CORD]; + + optional googleUnittestImport.PublicImportMessage + optional_public_import_message_extension = 26; + + optional TestAllTypes.NestedMessage + optional_lazy_message_extension = 27; // [lazy=true]; + + // Repeated + repeated int32 repeated_int32_extension = 31; + repeated int64 repeated_int64_extension = 32; + repeated uint32 repeated_uint32_extension = 33; + repeated uint64 repeated_uint64_extension = 34; + repeated sint32 repeated_sint32_extension = 35; + repeated sint64 repeated_sint64_extension = 36; + repeated fixed32 repeated_fixed32_extension = 37; + repeated fixed64 repeated_fixed64_extension = 38; + repeated sfixed32 repeated_sfixed32_extension = 39; + repeated sfixed64 repeated_sfixed64_extension = 40; + repeated float repeated_float_extension = 41; + repeated double repeated_double_extension = 42; + repeated bool repeated_bool_extension = 43; + repeated string repeated_string_extension = 44; + repeated bytes repeated_bytes_extension = 45; + + // TODO: Support groups + //repeated group RepeatedGroup_extension = 46 { + // optional int32 a = 47; + //} + + repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48; + repeated ForeignMessage repeated_foreign_message_extension = 49; + repeated googleUnittestImport.ImportMessage + repeated_import_message_extension = 50; + + repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51; + repeated ForeignEnum repeated_foreign_enum_extension = 52; + repeated googleUnittestImport.ImportEnum + repeated_import_enum_extension = 53; + + repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE]; + repeated string repeated_cord_extension = 55 [ctype=CORD]; + + repeated TestAllTypes.NestedMessage + repeated_lazy_message_extension = 57; // [lazy=true]; + + // Singular with defaults + optional int32 default_int32_extension = 61 [default = 41 ]; + optional int64 default_int64_extension = 62 [default = 42 ]; + optional uint32 default_uint32_extension = 63 [default = 43 ]; + optional uint64 default_uint64_extension = 64 [default = 44 ]; + optional sint32 default_sint32_extension = 65 [default = -45 ]; + optional sint64 default_sint64_extension = 66 [default = 46 ]; + optional fixed32 default_fixed32_extension = 67 [default = 47 ]; + optional fixed64 default_fixed64_extension = 68 [default = 48 ]; + optional sfixed32 default_sfixed32_extension = 69 [default = 49 ]; + optional sfixed64 default_sfixed64_extension = 70 [default = -50 ]; + optional float default_float_extension = 71 [default = 51.5 ]; + optional double default_double_extension = 72 [default = 52e3 ]; + optional bool default_bool_extension = 73 [default = true ]; + optional string default_string_extension = 74 [default = "hello"]; + optional bytes default_bytes_extension = 75 [default = "world"]; + + optional TestAllTypes.NestedEnum + default_nested_enum_extension = 81 [default = BAR]; + optional ForeignEnum + default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; + optional googleUnittestImport.ImportEnum + default_import_enum_extension = 83 [default = IMPORT_BAR]; + + optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, + default="abc"]; + optional string default_cord_extension = 85 [ctype=CORD, default="123"]; +} + +message TestNestedExtension { + extend TestAllExtensions { + // Check for bug where string extensions declared in tested scope did not + // compile. + optional string test = 1002 [default="test"]; + } +} + +// We have separate messages for testing required fields because it's +// annoying to have to fill in required fields in TestProto in order to +// do anything with it. Note that we don't need to test every type of +// required filed because the code output is basically identical to +// optional fields for all types. +message TestRequired { + required int32 a = 1; + optional int32 dummy2 = 2; + required int32 b = 3; + + extend TestAllExtensions { + optional TestRequired single = 1000; + repeated TestRequired multi = 1001; + } + + // Pad the field count to 32 so that we can test that IsInitialized() + // properly checks multiple elements of has_bits_. + optional int32 dummy4 = 4; + optional int32 dummy5 = 5; + optional int32 dummy6 = 6; + optional int32 dummy7 = 7; + optional int32 dummy8 = 8; + optional int32 dummy9 = 9; + optional int32 dummy10 = 10; + optional int32 dummy11 = 11; + optional int32 dummy12 = 12; + optional int32 dummy13 = 13; + optional int32 dummy14 = 14; + optional int32 dummy15 = 15; + optional int32 dummy16 = 16; + optional int32 dummy17 = 17; + optional int32 dummy18 = 18; + optional int32 dummy19 = 19; + optional int32 dummy20 = 20; + optional int32 dummy21 = 21; + optional int32 dummy22 = 22; + optional int32 dummy23 = 23; + optional int32 dummy24 = 24; + optional int32 dummy25 = 25; + optional int32 dummy26 = 26; + optional int32 dummy27 = 27; + optional int32 dummy28 = 28; + optional int32 dummy29 = 29; + optional int32 dummy30 = 30; + optional int32 dummy31 = 31; + optional int32 dummy32 = 32; + + required int32 c = 33; +} + +message TestRequiredForeign { + optional TestRequired optional_message = 1; + repeated TestRequired repeated_message = 2; + optional int32 dummy = 3; +} + +// Test that we can use NestedMessage from outside TestAllTypes. +message TestForeignNested { + optional TestAllTypes.NestedMessage foreign_nested = 1; +} + +// TestEmptyMessage is used to test unknown field support. +message TestEmptyMessage { +} + +// Like above, but declare all field numbers as potential extensions. No +// actual extensions should ever be defined for this type. +message TestEmptyMessageWithExtensions { + extensions 1 to max; +} + +message TestMultipleExtensionRanges { + extensions 42; + extensions 4143 to 4243; + extensions 65536 to max; +} + +// Test that really large tag numbers don't break anything. +message TestReallyLargeTagNumber { + // The largest possible tag number is 2^28 - 1, since the wire format uses + // three bits to communicate wire type. + optional int32 a = 1; + optional int32 bb = 268435455; +} + +message TestRecursiveMessage { + optional TestRecursiveMessage a = 1; + optional int32 i = 2; +} + +// Test that mutual recursion works. +message TestMutualRecursionA { + optional TestMutualRecursionB bb = 1; +} + +message TestMutualRecursionB { + optional TestMutualRecursionA a = 1; + optional int32 optional_int32 = 2; +} + +// Test that groups have disjoint field numbers from their siblings and +// parents. This is NOT possible in proto1; only proto2. When attempting +// to compile with proto1, this will emit an error; so we only include it +// in google_unittest_proto. +message TestDupFieldNumber { // NO_PROTO1 + optional int32 a = 1; // NO_PROTO1 + // TODO: Support groups + //optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 + //optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 +} // NO_PROTO1 + +// Additional messages for testing lazy fields. +message TestEagerMessage { + optional TestAllTypes sub_message = 1; // [lazy=false]; +} +message TestLazyMessage { + optional TestAllTypes sub_message = 1; // [lazy=true]; +} + +// Needed for a Python test. +message TestNestedMessageHasBits { + message NestedMessage { + repeated int32 nestedmessage_repeated_int32 = 1; + repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2; + } + optional NestedMessage optional_nested_message = 1; +} + + +// Test an enum that has multiple values with the same number. +// TODO: update and test this when the new compiler is released +// enum TestEnumWithDupValue { +// option allow_alias = true; +// FOO1 = 1; +// BAR1 = 2; +// BAZ = 3; +// FOO2 = 1; +// BAR2 = 2; +// } + +// Test an enum with large, unordered values. +enum TestSparseEnum { + SPARSE_A = 123; + SPARSE_B = 62374; + SPARSE_C = 12589234; + SPARSE_D = -15; + SPARSE_E = -53452; + SPARSE_F = 0; + SPARSE_G = 2; +} + +// Test message with CamelCase field names. This violates Protocol Buffer +// standard style. +message TestCamelCaseFieldNames { + optional int32 PrimitiveField = 1; + optional string StringField = 2; + optional ForeignEnum EnumField = 3; + optional ForeignMessage MessageField = 4; + optional string StringPieceField = 5 [ctype=STRING_PIECE]; + optional string CordField = 6 [ctype=CORD]; + + repeated int32 RepeatedPrimitiveField = 7; + repeated string RepeatedStringField = 8; + repeated ForeignEnum RepeatedEnumField = 9; + repeated ForeignMessage RepeatedMessageField = 10; + repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE]; + repeated string RepeatedCordField = 12 [ctype=CORD]; +} + + +// We list fields out of order, to ensure that we're using field number and not +// field index to determine serialization order. +message TestFieldOrderings { + optional string my_string = 11; + extensions 2 to 10; + optional int64 my_int = 1; + extensions 12 to 100; + optional float my_float = 101; +} + + +extend TestFieldOrderings { + optional string my_extension_string = 50; + optional int32 my_extension_int = 5; +} + + +message TestExtremeDefaultValues { + optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; + optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF]; + optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF]; + optional int32 small_int32 = 4 [default = -0x7FFFFFFF]; + optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF]; + optional int32 really_small_int32 = 21 [default = -0x80000000]; + optional int64 really_small_int64 = 22 [default = -0x8000000000000000]; + + // The default value here is UTF-8 for "\u1234". (We could also just type + // the UTF-8 text directly into this text file rather than escape it, but + // lots of people use editors that would be confused by this.) + optional string utf8_string = 6 [default = "\341\210\264"]; + + // Tests for single-precision floating-point values. + optional float zero_float = 7 [default = 0]; + optional float one_float = 8 [default = 1]; + optional float small_float = 9 [default = 1.5]; + optional float negative_one_float = 10 [default = -1]; + optional float negative_float = 11 [default = -1.5]; + // Using exponents + optional float large_float = 12 [default = 2E8]; + optional float small_negative_float = 13 [default = -8e-28]; + + // Text for nonfinite floating-point values. + optional double inf_double = 14 [default = inf]; + optional double neg_inf_double = 15 [default = -inf]; + optional double nan_double = 16 [default = nan]; + optional float inf_float = 17 [default = inf]; + optional float neg_inf_float = 18 [default = -inf]; + optional float nan_float = 19 [default = nan]; + + // Tests for C++ trigraphs. + // Trigraphs should be escaped in C++ generated files, but they should not be + // escaped for other languages. + // Note that in .proto file, "\?" is a valid way to escape ? in string + // literals. + optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"]; + + // String defaults containing the character '\000' + optional string string_with_zero = 23 [default = "hel\000lo"]; + optional bytes bytes_with_zero = 24 [default = "wor\000ld"]; + optional string string_piece_with_zero = 25 [ctype=STRING_PIECE, + default="ab\000c"]; + optional string cord_with_zero = 26 [ctype=CORD, + default="12\0003"]; +} + +message SparseEnumMessage { + optional TestSparseEnum sparse_enum = 1; +} + +// Test String and Bytes: string is for valid UTF-8 strings +message OneString { + optional string data = 1; +} + +message MoreString { + repeated string data = 1; +} + +message OneBytes { + optional bytes data = 1; +} + +message MoreBytes { + repeated bytes data = 1; +} + + +// Test messages for packed fields + +message TestPackedTypes { + repeated int32 packed_int32 = 90 [packed = true]; + repeated int64 packed_int64 = 91 [packed = true]; + repeated uint32 packed_uint32 = 92 [packed = true]; + repeated uint64 packed_uint64 = 93 [packed = true]; + repeated sint32 packed_sint32 = 94 [packed = true]; + repeated sint64 packed_sint64 = 95 [packed = true]; + repeated fixed32 packed_fixed32 = 96 [packed = true]; + repeated fixed64 packed_fixed64 = 97 [packed = true]; + repeated sfixed32 packed_sfixed32 = 98 [packed = true]; + repeated sfixed64 packed_sfixed64 = 99 [packed = true]; + repeated float packed_float = 100 [packed = true]; + repeated double packed_double = 101 [packed = true]; + repeated bool packed_bool = 102 [packed = true]; + repeated ForeignEnum packed_enum = 103 [packed = true]; +} + +// A message with the same fields as TestPackedTypes, but without packing. Used +// to test packed <-> unpacked wire compatibility. +message TestUnpackedTypes { + repeated int32 unpacked_int32 = 90 [packed = false]; + repeated int64 unpacked_int64 = 91 [packed = false]; + repeated uint32 unpacked_uint32 = 92 [packed = false]; + repeated uint64 unpacked_uint64 = 93 [packed = false]; + repeated sint32 unpacked_sint32 = 94 [packed = false]; + repeated sint64 unpacked_sint64 = 95 [packed = false]; + repeated fixed32 unpacked_fixed32 = 96 [packed = false]; + repeated fixed64 unpacked_fixed64 = 97 [packed = false]; + repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; + repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; + repeated float unpacked_float = 100 [packed = false]; + repeated double unpacked_double = 101 [packed = false]; + repeated bool unpacked_bool = 102 [packed = false]; + repeated ForeignEnum unpacked_enum = 103 [packed = false]; +} + +message TestPackedExtensions { + extensions 1 to max; +} + +extend TestPackedExtensions { + repeated int32 packed_int32_extension = 90 [packed = true]; + repeated int64 packed_int64_extension = 91 [packed = true]; + repeated uint32 packed_uint32_extension = 92 [packed = true]; + repeated uint64 packed_uint64_extension = 93 [packed = true]; + repeated sint32 packed_sint32_extension = 94 [packed = true]; + repeated sint64 packed_sint64_extension = 95 [packed = true]; + repeated fixed32 packed_fixed32_extension = 96 [packed = true]; + repeated fixed64 packed_fixed64_extension = 97 [packed = true]; + repeated sfixed32 packed_sfixed32_extension = 98 [packed = true]; + repeated sfixed64 packed_sfixed64_extension = 99 [packed = true]; + repeated float packed_float_extension = 100 [packed = true]; + repeated double packed_double_extension = 101 [packed = true]; + repeated bool packed_bool_extension = 102 [packed = true]; + repeated ForeignEnum packed_enum_extension = 103 [packed = true]; +} + +// Used by ExtensionSetTest/DynamicExtensions. The test actually builds +// a set of extensions to TestAllExtensions dynamically, based on the fields +// of this message type. +message TestDynamicExtensions { + enum DynamicEnumType { + DYNAMIC_FOO = 2200; + DYNAMIC_BAR = 2201; + DYNAMIC_BAZ = 2202; + } + message DynamicMessageType { + optional int32 dynamic_field = 2100; + } + + optional fixed32 scalar_extension = 2000; + optional ForeignEnum enum_extension = 2001; + optional DynamicEnumType dynamic_enum_extension = 2002; + + optional ForeignMessage message_extension = 2003; + optional DynamicMessageType dynamic_message_extension = 2004; + + repeated string repeated_extension = 2005; + repeated sint32 packed_extension = 2006 [packed = true]; +} + +message TestRepeatedScalarDifferentTagSizes { + // Parsing repeated fixed size values used to fail. This message needs to be + // used in order to get a tag of the right size; all of the repeated fields + // in TestAllTypes didn't trigger the check. + repeated fixed32 repeated_fixed32 = 12; + // Check for a varint type, just for good measure. + repeated int32 repeated_int32 = 13; + + // These have two-byte tags. + repeated fixed64 repeated_fixed64 = 2046; + repeated int64 repeated_int64 = 2047; + + // Three byte tags. + repeated float repeated_float = 262142; + repeated uint64 repeated_uint64 = 262143; +} + +// Test that if an optional or required message/group field appears multiple +// times in the input, they need to be merged. +message TestParsingMerge { + // RepeatedFieldsGenerator defines matching field types as TestParsingMerge, + // except that all fields are repeated. In the tests, we will serialize the + // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge. + // Repeated fields in RepeatedFieldsGenerator are expected to be merged into + // the corresponding required/optional fields in TestParsingMerge. + message RepeatedFieldsGenerator { + repeated TestAllTypes field1 = 1; + repeated TestAllTypes field2 = 2; + repeated TestAllTypes field3 = 3; + // TODO: Support groups + //repeated group Group1 = 10 { + // optional TestAllTypes field1 = 11; + //} + //repeated group Group2 = 20 { + // optional TestAllTypes field1 = 21; + //} + repeated TestAllTypes ext1 = 1000; + repeated TestAllTypes ext2 = 1001; + } + required TestAllTypes required_all_types = 1; + optional TestAllTypes optional_all_types = 2; + repeated TestAllTypes repeated_all_types = 3; + // TODO: Support groups + //optional group OptionalGroup = 10 { + // optional TestAllTypes optional_group_all_types = 11; + //} + //repeated group RepeatedGroup = 20 { + // optional TestAllTypes repeated_group_all_types = 21; + //} + extensions 1000 to max; + extend TestParsingMerge { + optional TestAllTypes optional_ext = 1000; + repeated TestAllTypes repeated_ext = 1001; + } +} + +message TestCommentInjectionMessage { + // */ <- This should not close the generated doc comment + optional string a = 1 [default="*/ <- Neither should this."]; +} + + +// Test that RPC services work. +message FooRequest {} +message FooResponse {} + +message FooClientMessage {} +message FooServerMessage{} + +service TestService { + rpc Foo(FooRequest) returns (FooResponse); + rpc Bar(BarRequest) returns (BarResponse); +} + + +message BarRequest {} +message BarResponse {} diff --git a/spec/support/test/google_unittest_import.pb.rb b/spec/support/test/google_unittest_import.pb.rb new file mode 100644 index 00000000..0aba8b79 --- /dev/null +++ b/spec/support/test/google_unittest_import.pb.rb @@ -0,0 +1,37 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module GoogleUnittestImport + + ## + # Enum Classes + # + class ImportEnum < ::Protobuf::Enum + define :IMPORT_FOO, 7 + define :IMPORT_BAR, 8 + define :IMPORT_BAZ, 9 + end + + + ## + # Message Classes + # + class PublicImportMessage < ::Protobuf::Message; end + class ImportMessage < ::Protobuf::Message; end + + ## + # Message Fields + # + class PublicImportMessage + optional ::Protobuf::Field::Int32Field, :e, 1 + end + + class ImportMessage + optional ::Protobuf::Field::Int32Field, :d, 1 + end + + +end + diff --git a/spec/support/test/google_unittest_import.proto b/spec/support/test/google_unittest_import.proto new file mode 100644 index 00000000..2814e46f --- /dev/null +++ b/spec/support/test/google_unittest_import.proto @@ -0,0 +1,64 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// A proto file which is imported by unittest.proto to test importing. + + +// We don't put this in a package within proto2 because we need to make sure +// that the generated code doesn't depend on being in the proto2 namespace. +// In test_util.h we do +// "using namespace unittest_import = protobuf_unittest_import". +package googleUnittestImport; + +//############################## Test public import +// TODO: This will be supported in the next release of the +// compiler +// import public "test/google_unittest_import_public.proto"; + +message PublicImportMessage { + optional int32 e = 1; +} + +//############################### + +message ImportMessage { + optional int32 d = 1; +} + +enum ImportEnum { + IMPORT_FOO = 7; + IMPORT_BAR = 8; + IMPORT_BAZ = 9; +} + diff --git a/spec/support/test/google_unittest_import_public.pb.rb b/spec/support/test/google_unittest_import_public.pb.rb new file mode 100644 index 00000000..775b9de2 --- /dev/null +++ b/spec/support/test/google_unittest_import_public.pb.rb @@ -0,0 +1,8 @@ +## +# This file is auto-generated. DO NOT EDIT! +# + +module GoogleUnittestImport + +end + diff --git a/spec/support/test/google_unittest_import_public.proto b/spec/support/test/google_unittest_import_public.proto new file mode 100644 index 00000000..9a57a4f5 --- /dev/null +++ b/spec/support/test/google_unittest_import_public.proto @@ -0,0 +1,38 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: liujisi@google.com (Pherl Liu) + + +package googleUnittestImport; + +//message PublicImportMessage { +// optional int32 e = 1; +//} From b85b34d688fc06281f4d1d507414b50487deb7c1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 24 Jul 2013 10:02:01 -0600 Subject: [PATCH 0469/1191] Add FileGenerator, MessageGenerator, GroupGenerator, Printable module --- lib/protobuf/generators/file_generator.rb | 140 +++++++++++++++ lib/protobuf/generators/group_generator.rb | 113 ++++++++++++ lib/protobuf/generators/message_generator.rb | 99 +++++++++++ lib/protobuf/generators/printable.rb | 161 ++++++++++++++++++ .../generators/file_generator_spec.rb | 29 ++++ .../generators/message_generator_spec.rb | 0 6 files changed, 542 insertions(+) create mode 100644 lib/protobuf/generators/file_generator.rb create mode 100644 lib/protobuf/generators/group_generator.rb create mode 100644 lib/protobuf/generators/message_generator.rb create mode 100644 lib/protobuf/generators/printable.rb create mode 100644 spec/lib/protobuf/generators/file_generator_spec.rb create mode 100644 spec/lib/protobuf/generators/message_generator_spec.rb diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb new file mode 100644 index 00000000..86ee0b44 --- /dev/null +++ b/lib/protobuf/generators/file_generator.rb @@ -0,0 +1,140 @@ +require 'set' +require 'protobuf/generators/base' +require 'protobuf/generators/group_generator' + +module Protobuf + module Generators + class FileGenerator < Base + + attr_reader :output_file + + def initialize(*args) + super + @output_file = ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => file_name) + @extension_fields = Hash.new { |h, k| h[k] = [] } + @known_messages = [] + @dangling_messages = {} + end + + def file_name + convert_filename(descriptor.name, false) + end + + def compile + run_once(:compile) do + map_extensions(descriptor, [ descriptor.package ]) + extract_dangling_extensions + + print_file_comment + print_generic_requires + print_import_requires + + print_package do + group = GroupGenerator.new(current_indent) + group.add_enums(descriptor.enum_type, :namespace => [ descriptor.package ]) + group.add_message_declarations(descriptor.message_type) + group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [ descriptor.package ]) + group.add_extended_messages(@unknown_extensions) + group.add_services(descriptor.service) + + group.add_header(:enum, 'Enum Classes') + group.add_header(:message_declaration, 'Message Classes') + group.add_header(:message, 'Message Fields') + group.add_header(:extended_message, 'Extended Message Fields') + group.add_header(:service, 'Service Classes') + print group.to_s + end + + end + end + + def extract_dangling_extensions + @unknown_extensions = @extension_fields.select do |k, v| + ! @known_messages.include?(k) + end + end + + def generate_output_file + compile + output_file.content = to_s + output_file + end + + # Recursively map out all extensions known in this file. + # The key is the type_name of the message being extended, and + # the value is an array of field descriptors. + # + def map_extensions(descriptor, namespaces) + # Record all the message descriptor name's we encounter (should be the whole tree). + if descriptor.is_a?(::Google::Protobuf::DescriptorProto) + if fully_qualified_token?(descriptor.name) + @known_messages << descriptor.name + else + fully_qualified_namespace = ".#{namespaces.join('.')}" + @known_messages << fully_qualified_namespace + end + end + + descriptor.extension.each do |field_descriptor| + @extension_fields[field_descriptor.extendee] << field_descriptor + end + + if descriptor.respond_to_has_and_present?(:message_type) + descriptor.message_type.each do |message_descriptor| + map_extensions(message_descriptor, (namespaces + [ message_descriptor.name ])) + end + end + + if descriptor.respond_to_has_and_present?(:nested_type) + descriptor.nested_type.each do |nested_descriptor| + map_extensions(nested_descriptor, (namespaces + [ nested_descriptor.name ])) + end + end + end + + def print_file_comment + puts "##" + puts "# This file is auto-generated. DO NOT EDIT!" + puts "#" + end + + def print_generic_requires + print_require("protobuf/message") + print_require("protobuf/rpc/service") if descriptor.service.count > 0 + puts + end + + def print_import_requires + if descriptor.dependency.count > 0 + header "Imports" + + descriptor.dependency.each do |dependency| + print_require(convert_filename(dependency)) + end + + puts + end + end + + def print_package(&block) + final = lambda { block.call } + namespaces = descriptor.package.split('.') + namespaces.reverse.inject(final) { |previous, namespace| + lambda { print_module(namespace, &previous) } + }.call + end + + private + + def convert_filename(filename, for_require = true) + filename.sub(/\.proto/, (for_require ? '.pb' : '.pb.rb')) + end + + def fully_qualified_token?(token) + token[0] == '.' + end + + end + end +end + diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb new file mode 100644 index 00000000..84d95176 --- /dev/null +++ b/lib/protobuf/generators/group_generator.rb @@ -0,0 +1,113 @@ +require 'protobuf/generators/enum_generator' +require 'protobuf/generators/extension_generator' +require 'protobuf/generators/field_generator' +require 'protobuf/generators/message_generator' +require 'protobuf/generators/service_generator' + +module Protobuf + module Generators + class GroupGenerator + include ::Protobuf::Generators::Printable + + attr_reader :groups, :indent_level + attr_writer :order + + def initialize(indent_level = 0) + @groups = Hash.new { |h, k| h[k] = [] } + @headers = {} + @comments = {} + @handlers = {} + @indent_level = indent_level + @order = [ :enum, :message_declaration, :message, :extended_message, :service ] + init_printer(indent_level) + end + + def add_enums(enum_descriptors, options) + enum_descriptors.each do |enum_descriptor| + @groups[:enum] << EnumGenerator.new(enum_descriptor, indent_level, options) + end + end + + def add_comment(type, message) + @comments[type] = message + end + + def add_extended_messages(extended_messages) + extended_messages.each do |message_type, field_descriptors| + @groups[:extended_message] << ExtensionGenerator.new(message_type, field_descriptors, indent_level) + end + end + + def add_extension_fields(field_descriptors) + field_descriptors.each do |field_descriptor| + @groups[:extension_field] << FieldGenerator.new(field_descriptor, indent_level) + end + end + + def add_extension_ranges(extension_ranges, &item_handler) + @groups[:extension_range] = extension_ranges + @handlers[:extension_range] = item_handler + end + + def add_header(type, message) + @headers[type] = message + end + + def add_message_declarations(descriptors) + descriptors.each do |descriptor| + @groups[:message_declaration] << MessageGenerator.new(descriptor, indent_level, :declaration => true) + end + end + + def add_message_fields(field_descriptors) + field_descriptors.each do |field_descriptor| + @groups[:field] << FieldGenerator.new(field_descriptor, indent_level) + end + end + + def add_messages(descriptors, options = {}) + descriptors.each do |descriptor| + @groups[:message] << MessageGenerator.new(descriptor, indent_level, options) + end + end + + def add_services(service_descriptors) + service_descriptors.each do |service_descriptor| + @groups[:service] << ServiceGenerator.new(service_descriptor, indent_level) + end + end + + def compile + @order.each do |type| + items = @groups[type] + if items.count > 0 + item_handler = @handlers[type] + + item_header = @headers[type] + header(item_header) if item_header + + item_comment = @comments[type] + comment(item_comment) if item_comment + + items.each do |item| + if item_handler + puts item_handler.call(item) + else + print item.to_s + end + end + + puts if type == :message_declaration + end + end + end + + def to_s + compile + print_contents + end + + end + end +end + diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb new file mode 100644 index 00000000..c9ea7af1 --- /dev/null +++ b/lib/protobuf/generators/message_generator.rb @@ -0,0 +1,99 @@ +require 'protobuf/generators/base' +require 'protobuf/generators/group_generator' + +module Protobuf + module Generators + class MessageGenerator < Base + + def initialize(descriptor, indent_level, options = {}) + super + @only_declarations = options.fetch(:declaration) { false } + @extension_fields = options.fetch(:extension_fields) { {} } + end + + def compile + run_once(:compile) do + if @only_declarations + compile_declaration + else + compile_message + end + end + end + + def compile_declaration + run_once(:compile_declaration) do + if is_printable? + print_class(descriptor.name, :message) do + group = GroupGenerator.new(current_indent) + group.add_enums(descriptor.enum_type, :namespace => type_namespace) + group.add_message_declarations(descriptor.nested_type) + print group.to_s + end + else + print_class(descriptor.name, :message) + end + end + end + + def compile_message + run_once(:compile_message) do + if is_printable? + print_class(descriptor.name, nil) do + group = GroupGenerator.new(current_indent) + group.add_messages(descriptor.nested_type, :extension_fields => @extension_fields, :namespace => type_namespace) + group.add_message_fields(descriptor.field) + self.class.validate_tags(fully_qualified_type_namespace, descriptor.field.map(&:number)) + + group.add_comment(:extension_range, 'Extension Fields') + group.add_extension_ranges(descriptor.extension_range) do |extension_range| + "extensions #{extension_range.start}...#{extension_range.end}" + end + + group.add_extension_fields(message_extension_fields) + + group.order = [ :message, :field, :extension_range, :extension_field ] + print group.to_s + end + end + end + end + + private + + def has_extensions? + ! message_extension_fields.empty? + end + + def has_fields? + descriptor.field.count > 0 + end + + def has_nested_enums? + descriptor.enum_type.count > 0 + end + + def has_nested_messages? + descriptor.nested_type.count > 0 + end + + def has_nested_types? + has_nested_enums? || has_nested_messages? + end + + def is_printable? + if @only_declarations + has_nested_types? + else + has_fields? || has_nested_messages? || has_extensions? + end + end + + def message_extension_fields + @extension_fields.fetch(fully_qualified_type_namespace) { [] } + end + + end + end +end + diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb new file mode 100644 index 00000000..34440ad0 --- /dev/null +++ b/lib/protobuf/generators/printable.rb @@ -0,0 +1,161 @@ +module Protobuf + module Generators + module Printable + + PARENT_CLASS_MESSAGE = "::Protobuf::Message".freeze + PARENT_CLASS_ENUM = "::Protobuf::Enum".freeze + PARENT_CLASS_SERVICE = "::Protobuf::Rpc::Service".freeze + + # Initialize the printer. + # Must be called by any class/module that includes the Printable module. + # + def init_printer(indent_level) + @io = ::StringIO.new + @_indent_level = indent_level.to_i || 0 + end + + private + + # Print a one-line comment. + # + def comment(message) + puts "# #{message}" + end + + def current_indent + @_indent_level + end + + # Print a "header" comment. + # + # header("Lorem ipsum dolor") + # ## + # # Lorem ipsum dolor + # # + def header(message) + puts + puts "##" + puts "# #{message}" + puts "#" + end + + # Increase the indent level. An outdent will only occur if given a block + # (after the block is finished). + # + def indent + @_indent_level += 1 + yield + outdent + end + + # Take a string and upcase the first character of each namespace. + # Due to the nature of varying standards about how class/modules are named + # (e.g. CamelCase, Underscore_Case, SCREAMING_SNAKE_CASE), we only want + # to capitalize the first character to ensure ruby will treat the value + # as a constant. Otherwise we do not attempt to change the + # token's definition. + # + # modulize("foo.bar.Baz") -> "::Foo::Bar::Baz" + # modulize("foo.bar.baz") -> "::Foo::Bar::Baz" + # modulize("foo.bar.BAZ") -> "::Foo::Bar::BAZ" + # + def modulize(name) + name = name.gsub(/\./, '::') + name = name.gsub(/(^(?:::)?[a-z]|::[a-z])/) { |match| match.upcase } + name + end + + # Decrease the indent level. Cannot be negative. + # + def outdent + @_indent_level -= 1 unless @_indent_level == 0 + end + + # Return the parent class for a given type. + # Valid types are :message, :enum, and :service, otherwise an error + # will be thrown. + # + def parent_class(type) + case type + when :message then + PARENT_CLASS_MESSAGE + when :enum then + PARENT_CLASS_ENUM + when :service then + PARENT_CLASS_SERVICE + else + raise "Unknown parent class type #{type}: #{caller[0..5].join("\n")}" + end + end + + # Print a class or module block, indicated by type. + # If a class, can be given a parent class to inherit from. + # If a block is given, call the block from within an indent block. + # Otherwise, end the block on the same line. + # + def print_block(name, parent_klass, type, &block) + name = modulize(name) + block_def = "#{type} #{name}" + block_def += " < #{parent_class(parent_klass)}" if parent_klass + + if block_given? + puts block_def + indent { block.call } + puts "end" + puts + else + block_def += "; end" + puts block_def + end + end + + # Use print_block to print a class, with optional parent class + # to inherit from. Accepts a block for use with print_block. + # + def print_class(name, parent_klass, &block) + print_block(name, parent_klass, :class, &block) + end + + # Use print_block to print a module. + # Accepts a block for use with print_block. + # + def print_module(name, &block) + print_block(name, nil, :module, &block) + end + + # Print a file require. + # + # print_require('foo/bar/baz') -> "require 'foo/bar/baz'" + # + def print_require(file) + puts "require '#{file}'" + end + + # Puts the given message prefixed by the indent level. + # If no message is given print a newline. + # + def puts(message = nil) + if message + @io.puts((" " * @_indent_level) + message) + else + @io.puts + end + end + + # Print the given message raw, no indent. + # + def print(contents) + @io.print(contents) + end + + # Returns the contents of the underlying StringIO object. + # + def print_contents + @io.rewind + @io.read + end + + end + end +end + diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb new file mode 100644 index 00000000..19559c9a --- /dev/null +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +require 'protobuf/generators/file_generator' + +describe ::Protobuf::Generators::FileGenerator do + + let(:base_descriptor_fields) { { :name => 'test/foo.proto' } } + let(:descriptor_fields) { base_descriptor_fields } + let(:file_descriptor) { ::Google::Protobuf::FileDescriptorProto.new(descriptor_fields) } + + subject { described_class.new(file_descriptor) } + its(:file_name) { should eq 'test/foo.pb.rb' } + + describe '#print_import_requires' do + let(:descriptor_fields) do + base_descriptor_fields.merge!({ :dependency => [ 'test/bar.proto', + 'test/baz.proto' ] }) + end + + it 'prints a ruby require for each dependency' do + subject.should_receive(:print_require).with('test/bar.pb') + subject.should_receive(:print_require).with('test/baz.pb') + subject.print_import_requires + end + + end + +end + diff --git a/spec/lib/protobuf/generators/message_generator_spec.rb b/spec/lib/protobuf/generators/message_generator_spec.rb new file mode 100644 index 00000000..e69de29b From 908ba8fa67348e7e2b41a0424260f10028e3cbdf Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 24 Jul 2013 10:02:22 -0600 Subject: [PATCH 0470/1191] Re-generated spec support protos --- spec/benchmark/tasks.rb | 2 +- spec/functional/evented_server_spec.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- .../generators/field_generator_spec.rb | 2 +- spec/lib/protobuf/logger_spec.rb | 5 +++ spec/lib/protobuf/rpc/client_spec.rb | 2 +- .../rpc/servers/evented_server_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 2 +- spec/spec_helper.rb | 4 ++- spec/support/server.rb | 2 +- spec/support/test/enum.pb.rb | 18 +++++----- spec/support/test/extended.pb.rb | 8 +++-- .../support/test/multi_field_extensions.pb.rb | 36 +++++++++++++++---- .../support/test/multi_field_extensions.proto | 14 ++++++-- spec/support/test/resource.pb.rb | 36 ++++++++++--------- spec/support/test/resource_service.rb | 21 ----------- 18 files changed, 94 insertions(+), 68 deletions(-) delete mode 100644 spec/support/test/resource_service.rb diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 75267453..d355a050 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,6 +1,6 @@ require 'benchmark' require 'support/all' -require 'support/test/resource_service' +require 'support/test/resource.pb' begin require 'perftools' diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 121203bf..91a8adc6 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' describe 'Functional EventMachine Client' do before(:each) do diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 2af158d1..4d395b11 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' describe 'Functional Socket Client' do before(:all) do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 433ccae6..e4bcb501 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' require 'protobuf/rpc/service_directory' describe 'Functional ZMQ Client' do diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 0f804638..2e242d27 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -require 'protobuf/generators/field_generator.rb' +require 'protobuf/generators/field_generator' describe ::Protobuf::Generators::FieldGenerator do diff --git a/spec/lib/protobuf/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb index 2bcd670d..04ce7dbe 100644 --- a/spec/lib/protobuf/logger_spec.rb +++ b/spec/lib/protobuf/logger_spec.rb @@ -1,5 +1,6 @@ require 'protobuf/logger' require 'stringio' +require 'fileutils' describe Protobuf::Logger do @@ -11,6 +12,10 @@ Protobuf::Logger.level = ::Logger::INFO end + after(:all) do + ::FileUtils.rm_f('myfile.log') + end + describe '.instance' do it 'doesn\'t create a logger if the file was not set' do diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index c38af459..d59e0300 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' describe Protobuf::Rpc::Client do before(:each) do diff --git a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb index 558044ce..952fb935 100644 --- a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/evented' diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 84de8c13..29750bb4 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/evented' require 'protobuf/socket' diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index b3f4952f..4dcd913e 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' describe Protobuf::Rpc::Service do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 98ae56be..981536e6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,11 +8,13 @@ $: << ::File.expand_path('..', File.dirname(__FILE__)) $: << ::File.expand_path('../spec/support', File.dirname(__FILE__)) -#$: << ::File.expand_path('../lib', File.dirname(__FILE__)) require 'protobuf' require ::File.dirname(__FILE__) + '/support/all' +$: << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) +require 'google/protobuf/compiler/plugin.pb' + # Including a way to turn on debug logger for spec runs if ENV["DEBUG"] debug_log = ::File.expand_path('../debug_specs.log', File.dirname(__FILE__) ) diff --git a/spec/support/server.rb b/spec/support/server.rb index 7fa49c2d..a3169e35 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -5,7 +5,7 @@ require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/servers/zmq_runner' -require 'spec/support/test/resource_service' +require 'spec/support/test/resource.pb' # Want to abort if server dies? Thread.abort_on_exception = true diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index 8e4039c9..43f2105e 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -3,6 +3,7 @@ # require 'protobuf/message' + ## # Imports # @@ -17,13 +18,14 @@ class EnumTestType < ::Protobuf::Enum define :ONE, 1 define :TWO, 2 end - - + + ## # Message Classes # class EnumTestMessage < ::Protobuf::Message; end - + + ## # Message Fields # @@ -32,14 +34,14 @@ class EnumTestMessage optional ::Test::EnumTestType, :default_enum, 2, :default => ::Test::EnumTestType::ONE repeated ::Test::EnumTestType, :repeated_enums, 3 end - - + + ## - # Extended Messages + # Extended Message Fields # - class ::Test::Resource + class ::Test::Resource < ::Protobuf::Message optional ::Protobuf::Field::Int32Field, :ext_other_file_defined_field, 200, :extension => true end - + end diff --git a/spec/support/test/extended.pb.rb b/spec/support/test/extended.pb.rb index 2977c0e6..219ba88f 100644 --- a/spec/support/test/extended.pb.rb +++ b/spec/support/test/extended.pb.rb @@ -1,6 +1,8 @@ ## # This file is auto-generated. DO NOT EDIT! # +require 'protobuf/message' + ## # Imports @@ -10,11 +12,11 @@ module Test ## - # Extended Messages + # Extended Message Fields # - class ::Test::Resource + class ::Test::Resource < ::Protobuf::Message optional ::Protobuf::Field::Int64Field, :deleted_at, 300, :extension => true end - + end diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/test/multi_field_extensions.pb.rb index db70f1e2..8a3c03a2 100644 --- a/spec/support/test/multi_field_extensions.pb.rb +++ b/spec/support/test/multi_field_extensions.pb.rb @@ -13,22 +13,44 @@ class Type < ::Protobuf::Enum define :PayloadTypeA, 1 define :PayloadTypeB, 2 end - + + end + + class PayloadA < ::Protobuf::Message + class Foo < ::Protobuf::Message; end + + end + + class PayloadB < ::Protobuf::Message + class Foo < ::Protobuf::Message; end + end - class PayloadA < ::Protobuf::Message; end - class PayloadB < ::Protobuf::Message; end - + + + ## # Message Fields # class Header required ::Test::Header::Type, :type, 1 - # Extension Fields extensions 100...536870912 optional ::Test::PayloadA, :payload, 100, :extension => true end - - + + class PayloadA + class Foo + optional ::Protobuf::Field::StringField, :foo_a, 1 + end + + end + + class PayloadB + class Foo + optional ::Protobuf::Field::StringField, :foo_b, 1 + end + + end + end diff --git a/spec/support/test/multi_field_extensions.proto b/spec/support/test/multi_field_extensions.proto index 2a28c844..200d74f3 100644 --- a/spec/support/test/multi_field_extensions.proto +++ b/spec/support/test/multi_field_extensions.proto @@ -2,22 +2,32 @@ package test; message Header { extensions 100 to max; + enum Type { PayloadTypeA = 1; PayloadTypeB = 2; } + required Type type = 1; } message PayloadA { + message Foo { + optional string foo_a = 1; + } + extend Header { optional PayloadA payload = 100; } } message PayloadB { - //extend Header { - // UNCOMMENT TO TEST FAILING WITH MULTIPLE FIELDS + message Foo { + optional string foo_b = 1; + } + + // UNCOMMENT TO TEST RUNTIME FAILING WITH MULTIPLE FIELDS + // extend Header { // optional PayloadB payload = 101; //} } diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 52514c74..77d5f4d9 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -15,8 +15,8 @@ class StatusType < ::Protobuf::Enum define :DISABLED, 2 define :DELETED, 3 end - - + + ## # Message Classes # @@ -28,15 +28,21 @@ class SearchType < ::Protobuf::Enum define :FLAT, 1 define :NESTED, 2 end - + end + class MessageParent < ::Protobuf::Message class MessageChild < ::Protobuf::Message; end + end + class Nested < ::Protobuf::Message class NestedLevelOne < ::Protobuf::Message; end + end - + + + ## # Message Fields # @@ -44,17 +50,16 @@ class ResourceFindRequest required ::Protobuf::Field::StringField, :name, 1 optional ::Protobuf::Field::BoolField, :active, 2 end - + class ResourceSleepRequest optional ::Protobuf::Field::Int32Field, :sleep, 1 end - + class Resource required ::Protobuf::Field::StringField, :name, 1 optional ::Protobuf::Field::Int64Field, :date_created, 2 optional ::Test::StatusType, :status, 3 repeated ::Test::StatusType, :repeated_enum, 4 - # Extension Fields extensions 100...536870912 optional ::Protobuf::Field::BoolField, :ext_is_searchable, 100, :extension => true @@ -63,42 +68,41 @@ class Resource optional ::Protobuf::Field::BoolField, :ext_nested_in_level_one, 105, :extension => true optional ::Protobuf::Field::BoolField, :ext_dup_field, 106, :extension => true end - + class MessageParent class MessageChild optional ::Protobuf::Field::StringField, :child1, 1 end - + end - + class Nested class NestedLevelOne optional ::Protobuf::Field::BoolField, :level_one, 1, :default => true - # Extension Fields extensions 100...102 optional ::Protobuf::Field::BoolField, :ext_nested_level_one_outer, 101, :extension => true optional ::Protobuf::Field::BoolField, :ext_nested_level_one, 100, :extension => true end - + optional ::Protobuf::Field::StringField, :name, 1 optional ::Test::Resource, :resource, 2 repeated ::Test::Resource, :multiple_resources, 3 optional ::Test::StatusType, :status, 4 - # Extension Fields extensions 100...111 optional ::Protobuf::Field::StringField, :foo, 100, :extension => true optional ::Protobuf::Field::Int64Field, :bar, 101, :extension => true end - - + + ## - # Services + # Service Classes # class ResourceService < ::Protobuf::Rpc::Service rpc :find, ::Test::ResourceFindRequest, ::Test::Resource rpc :find_with_sleep, ::Test::ResourceSleepRequest, ::Test::Resource end + end diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb deleted file mode 100644 index 33072ba4..00000000 --- a/spec/support/test/resource_service.rb +++ /dev/null @@ -1,21 +0,0 @@ -require ::File.expand_path('../resource.pb', __FILE__) - -module Test - class ResourceService - - # request -> Test::ResourceFindRequest - # response -> Test::Resource - def find - response.name = request.name - response.status = request.active ? 1 : 0 - end - - # request -> Test::ResourceSleepRequest - # response -> Test::Resource - def find_with_sleep - sleep (request.sleep || 1) - response.name = 'Request should have timed out' - end - - end -end From 9046b683b8d9f8f02740fd675a1a383b6eece9ab Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 24 Jul 2013 14:34:27 -0600 Subject: [PATCH 0471/1191] Revert rake compile_protos task --- Rakefile | 17 ++--------------- spec/spec_helper.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Rakefile b/Rakefile index 4e0fd214..15f786bc 100644 --- a/Rakefile +++ b/Rakefile @@ -8,25 +8,12 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" -desc "Default: compile test protos and run specs." -task :default => [:compile_protos, :spec] +desc "Default: run specs." +task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new(:spec) -desc "Compile test protos" -task :compile_protos do - unless defined?(JRUBY_VERSION) - unless ENV['NO_COMPILE_TEST_PROTOS'] - $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - proto_path = File.expand_path("../spec/support/", __FILE__) - cmd = "rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')}" - puts cmd - %x{#{cmd}} - end - end -end - ## # rake-compiler # diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e5eae29a..98ae56be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,6 +25,18 @@ ::RSpec.configure do |c| c.include(::Sander6::CustomMatchers) c.mock_with :rspec + + c.before(:suite) do + unless defined?(JRUBY_VERSION) + unless ENV['NO_COMPILE_TEST_PROTOS'] + $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' + proto_path = File.expand_path("../support/", __FILE__) + cmd = %Q{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } + puts cmd + %x{#{cmd}} + end + end + end end Dir[File.expand_path('../support/**/*.pb.rb', __FILE__)].each do |proto_file| From 271bb7c8ed3c2bc94d1f4904c4606ba61744aec1 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Fri, 9 Aug 2013 14:44:23 -0600 Subject: [PATCH 0472/1191] Restore the resource_service file --- spec/benchmark/tasks.rb | 2 +- spec/functional/evented_server_spec.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/rpc/client_spec.rb | 2 +- .../rpc/servers/evented_server_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 2 +- spec/support/server.rb | 2 +- spec/support/test/resource_service.rb | 21 +++++++++++++++++++ 10 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 spec/support/test/resource_service.rb diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index d355a050..75267453 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,6 +1,6 @@ require 'benchmark' require 'support/all' -require 'support/test/resource.pb' +require 'support/test/resource_service' begin require 'perftools' diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb index 91a8adc6..121203bf 100644 --- a/spec/functional/evented_server_spec.rb +++ b/spec/functional/evented_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' describe 'Functional EventMachine Client' do before(:each) do diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 4d395b11..2af158d1 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' describe 'Functional Socket Client' do before(:all) do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index e4bcb501..433ccae6 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' require 'protobuf/rpc/service_directory' describe 'Functional ZMQ Client' do diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index d59e0300..c38af459 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' describe Protobuf::Rpc::Client do before(:each) do diff --git a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb index 952fb935..558044ce 100644 --- a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/evented' diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 29750bb4..84de8c13 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/evented' require 'protobuf/socket' diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 4dcd913e..b3f4952f 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' describe Protobuf::Rpc::Service do diff --git a/spec/support/server.rb b/spec/support/server.rb index a3169e35..7fa49c2d 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -5,7 +5,7 @@ require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/servers/zmq_runner' -require 'spec/support/test/resource.pb' +require 'spec/support/test/resource_service' # Want to abort if server dies? Thread.abort_on_exception = true diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb new file mode 100644 index 00000000..33072ba4 --- /dev/null +++ b/spec/support/test/resource_service.rb @@ -0,0 +1,21 @@ +require ::File.expand_path('../resource.pb', __FILE__) + +module Test + class ResourceService + + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find + response.name = request.name + response.status = request.active ? 1 : 0 + end + + # request -> Test::ResourceSleepRequest + # response -> Test::Resource + def find_with_sleep + sleep (request.sleep || 1) + response.name = 'Request should have timed out' + end + + end +end From 1499c75eb1e818601fe675530af3494be426cc79 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 13 Aug 2013 15:04:09 -0600 Subject: [PATCH 0473/1191] Support arg passing when triggering a lifecycle event --- lib/protobuf/lifecycle.rb | 10 ++++++--- spec/lib/protobuf/lifecycle_spec.rb | 32 ++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 4727b18a..e0082307 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -9,16 +9,20 @@ def self.register( event_name, &blk ) lifecycle_events[ event_name ] << blk end - def self.trigger( event_name ) + def self.trigger( event_name, *args ) event_name = normalized_event_name( event_name ) if lifecycle_events.has_key?( event_name ) lifecycle_events[ event_name ].each do |block| - block.call + if ! args.empty? && block.arity != 0 + block.call(*args) + else + block.call + end end end end - + def self.normalized_event_name( event_name ) return "#{event_name}".downcase end diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index 5a108acc..e889ce82 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -27,7 +27,7 @@ it "only registers blocks for event callbacks" do expect { subject.register("something") - }.to raise_error( /block/ ) + }.to raise_error( /block/ ) end it "calls the registered block when triggered" do @@ -60,6 +60,36 @@ that.should eq("not nil") end + context 'when the registered block has arity' do + context 'and the triggered event does not have args' do + it 'does not pass the args' do + outer_bar = nil + + subject.register('foo') do |bar| + bar.should be_nil + outer_bar = 'triggered' + end + + subject.trigger('foo') + outer_bar.should eq 'triggered' + end + end + + context 'and the triggered event has arguments' do + it 'does not pass the args' do + outer_bar = nil + + subject.register('foo') do |bar| + bar.should_not be_nil + outer_bar = bar + end + + subject.trigger('foo', 'baz') + outer_bar.should eq 'baz' + end + end + end + context "normalized event names" do specify { subject.normalized_event_name(:derp).should eq("derp") } specify { subject.normalized_event_name(:Derp).should eq("derp") } From ebe780d02f33d0c2cecbc0320f489597578a2468 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 13 Aug 2013 15:04:34 -0600 Subject: [PATCH 0474/1191] Trigger added, updated, removed events for ServiceDirectory listings --- lib/protobuf/rpc/service_directory.rb | 33 +++++++++---- .../protobuf/rpc/service_directory_spec.rb | 48 +++++++++++++++++-- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 59aa8524..3d06031e 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -4,6 +4,7 @@ require 'thread' require 'timeout' +require 'protobuf/lifecycle' require 'protobuf/rpc/dynamic_discovery.pb' module Protobuf @@ -73,21 +74,23 @@ def initialize def add_listing_for(server) if server && server.uuid - - log_debug do - action = @listings[server.uuid] ? "Updating" : "Adding"; - sign_message("#{action} server: #{server.inspect}") - end - @mutex.synchronize do - @listings[server.uuid] = Listing.new(server) - end + action = @listings.key?(server.uuid) ? :updated : :added + log_debug { sign_message("#{action} server: #{server.inspect}") } + listing = Listing.new(server) + @listings[server.uuid] = listing + trigger(action, listing) + end else log_info { sign_message("Cannot add server without uuid: #{server.inspect}") } end end + def each_listing(&block) + @listings.each_value(&block) + end + def lookup(service) if running? @mutex.synchronize do @@ -105,7 +108,12 @@ def lookup(service) def remove_expired_listings @mutex.synchronize do @listings.delete_if do |uuid, listing| - listing.expired? + if listing.expired? + trigger(:removed, listing) + true + else + false + end end end end @@ -115,7 +123,8 @@ def remove_listing_for(server) log_debug { sign_message("Removing server: #{server.inspect}") } @mutex.synchronize do - @listings.delete(server.uuid) + deleted_listing = @listings.delete(server.uuid) + trigger(:removed, deleted_listing) end else @@ -188,6 +197,10 @@ def run retry end + def trigger(action, listing) + ::Protobuf::Lifecycle.trigger("directory.listing.#{action}", listing) + end + def wait_for_beacon data, addr = @socket.recvfrom(2048) diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 0f950adf..36d09032 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -58,17 +58,55 @@ def duration end end + describe '#add_listing_for' do + let(:server) { double('server', { :uuid => '123', + :services => ['Known::Service'], + :address => "0.0.0.0", + :port => 9999, + :ttl => 15 }) } + + it 'adds the listing to the known @listings' do + expect { + ::Protobuf::Lifecycle.should_receive(:trigger) + .with('directory.listing.added', an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing)) + .once + instance.add_listing_for(server) + }.to change(listings, :size).from(0).to(1) + end + end + + describe '#each_listing' do + let(:listing_doubles) { { '1' => double('listing 1'), + '2' => double('listing 2'), + '3' => double('listing 3') } } + + before do + instance.instance_variable_set(:@listings, listing_doubles) + end + + it 'invokes the given block for each listing known by the directory' do + yielded_listings = [] + instance.each_listing do |listing| + yielded_listings << listing + end + yielded_listings.should eq(listing_doubles.values) + end + end + describe "#remove_expired_listings" do + let(:listing_doubles) { { '1' => double(:expired? => true), + '2' => double(:expired? => true), + '3' => double(:expired? => false) } } + before do - instance.instance_variable_set(:@listings, { - '1' => double(:expired? => true), - '2' => double(:expired? => true), - '3' => double(:expired? => false), - }) + instance.instance_variable_set(:@listings, listing_doubles) end it "removes expired listings" do expect { + ::Protobuf::Lifecycle.should_receive(:trigger) + .with('directory.listing.removed', an_instance_of(RSpec::Mocks::Mock)) + .twice instance.remove_expired_listings }.to change(listings, :size).from(3).to(1) listings.keys.should eq ['3'] From ae16cc7ccc62501c372e5e5dcee923a75b84ff4f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 11:02:58 -0600 Subject: [PATCH 0475/1191] Define Float::INFINITY and Float::NAN if not already defined (< ruby 1.9) This paves the way for having inf, -inf, nan default values for float/double fields. --- lib/protobuf/message.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 8882b44c..54ee2ce3 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -5,6 +5,18 @@ require 'protobuf/exceptions' require 'protobuf/message/decoder' +# Define Float::INFINITY if it's not already defined (e.g. < ruby 1.9) +unless defined?(::Float::INFINITY) + puts 'DEFINING INFINITY' + ::Float::INFINITY = (1.0 / 0.0).freeze +end + +# Define Float::NAN if it's not already defined (e.g. < ruby 1.9) +unless defined?(::Float::NAN) + puts 'DEFINING NAN' + ::Float::NAN = (0.0 / 0.0).freeze +end + module Protobuf class Message From 01f16db59e5476de366d1c42c2c5114554c40bd3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 11:04:09 -0600 Subject: [PATCH 0476/1191] Add support for inf, -inf, and nan default values for double/float fields Also adds test/default.proto test file to inspect the generated code visually. --- lib/protobuf/generators/base.rb | 1 - lib/protobuf/generators/field_generator.rb | 52 ++++++++++++++++--- .../generators/field_generator_spec.rb | 23 +++++++- spec/support/test/defaults.pb.rb | 25 +++++++++ spec/support/test/defaults.proto | 9 ++++ 5 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 spec/support/test/defaults.pb.rb create mode 100644 spec/support/test/defaults.proto diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 81f9439e..49e1b9f1 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -1,4 +1,3 @@ -require 'protobuf/code_generator' require 'protobuf/generators/printable' module Protobuf diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 6ffae83e..4c3a1d7c 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -4,6 +4,19 @@ module Protobuf module Generators class FieldGenerator < Base + ## + # Constants + # + PROTO_INFINITY_DEFAULT = /^inf$/i.freeze + PROTO_NEGATIVE_INFINITY_DEFAULT = /^-inf$/i.freeze + PROTO_NAN_DEFAULT = /^nan$/i.freeze + RUBY_INFINITY_DEFAULT = '::Float::INFINITY'.freeze + RUBY_NEGATIVE_INFINITY_DEFAULT = '-::Float::INFINITY'.freeze + RUBY_NAN_DEFAULT = '::Float::NAN'.freeze + + ## + # Attributes + # attr_reader :field_options def applicable_options @@ -13,15 +26,15 @@ def applicable_options def default_value @default_value ||= begin if defaulted? - raw_default_value = descriptor.default_value - case descriptor.type.name when :TYPE_ENUM then - "#{type_name}::#{raw_default_value}" - when :TYPE_STRING then - "'#{raw_default_value.gsub(/'/, '\\\\\'')}'" + enum_default_value + when :TYPE_STRING, :TYPE_BYTES then + string_default_value + when :TYPE_FLOAT, :TYPE_DOUBLE then + float_double_default_value else - raw_default_value + verbatim_default_value end end end @@ -86,6 +99,33 @@ def type_name end end + private + + def enum_default_value + "#{type_name}::#{verbatim_default_value}" + end + + def float_double_default_value + case verbatim_default_value + when PROTO_INFINITY_DEFAULT then + RUBY_INFINITY_DEFAULT + when PROTO_NEGATIVE_INFINITY_DEFAULT then + RUBY_NEGATIVE_INFINITY_DEFAULT + when PROTO_NAN_DEFAULT then + RUBY_NAN_DEFAULT + else + verbatim_default_value + end + end + + def string_default_value + %Q{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"} + end + + def verbatim_default_value + descriptor.default_value + end + end end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 2e242d27..8f536143 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -51,9 +51,28 @@ context 'when the type is a string' do let(:type_enum) { :TYPE_STRING } - let(:default_value) { "a default 'string'" } + let(:default_value) { "a default \"string\"" } - it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :default => 'a default \\'string\\''\n" } + it { should eq %Q{optional ::Protobuf::Field::StringField, :foo_bar, 3, :default => "a default \"string\""\n} } + end + + context 'when float or double field type' do + let(:type_enum) { :TYPE_DOUBLE } + + context 'when the default value is "nan"' do + let(:default_value) { 'nan' } + it { should match(/::Float::NAN/) } + end + + context 'when the default value is "inf"' do + let(:default_value) { 'inf' } + it { should match(/::Float::INFINITY/) } + end + + context 'when the default value is "-inf"' do + let(:default_value) { '-inf' } + it { should match(/-::Float::INFINITY/) } + end end end diff --git a/spec/support/test/defaults.pb.rb b/spec/support/test/defaults.pb.rb new file mode 100644 index 00000000..83497e9f --- /dev/null +++ b/spec/support/test/defaults.pb.rb @@ -0,0 +1,25 @@ +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Test + + ## + # Message Classes + # + class Defaults < ::Protobuf::Message; end + + + ## + # Message Fields + # + class Defaults + optional ::Protobuf::Field::BytesField, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" + optional ::Protobuf::Field::DoubleField, :infinity_default, 2, :default => ::Float::INFINITY + optional ::Protobuf::Field::FloatField, :neg_infinity_default, 3, :default => -::Float::INFINITY + optional ::Protobuf::Field::DoubleField, :nan_default, 4, :default => ::Float::NAN + end + +end + diff --git a/spec/support/test/defaults.proto b/spec/support/test/defaults.proto new file mode 100644 index 00000000..1a657e92 --- /dev/null +++ b/spec/support/test/defaults.proto @@ -0,0 +1,9 @@ +package test; + +message Defaults { + optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; + optional double infinity_default = 2 [default = inf]; + optional float neg_infinity_default = 3 [default = -inf]; + optional double nan_default = 4 [default = nan]; +} + From 0bc967428d9812ffb22771dead4d494bcf9f77e0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 11:31:34 -0600 Subject: [PATCH 0477/1191] rprotoc now simply execs against protoc with the same args The command will print a deprecation warning (to stderr) as well as the actual command executed (to stdout). --- bin/rprotoc | 62 ++++------------------------------------------------- 1 file changed, 4 insertions(+), 58 deletions(-) diff --git a/bin/rprotoc b/bin/rprotoc index 97c21ce4..4556c009 100755 --- a/bin/rprotoc +++ b/bin/rprotoc @@ -1,62 +1,8 @@ #!/usr/bin/env ruby -require 'rubygems' -require 'ffi' +command = [ 'protoc', ARGV ].flatten.join(' ') -base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$stderr.puts "[DEPRECATED] `rprotoc` is deprecated. Use `protoc --ruby_out ...` instead." +$stdout.puts command -GENERATOR_FILE_PATH = case - when File.exists?(File.join(base_dir, "ruby_generator.bundle")) then - File.join(base_dir, "ruby_generator.bundle") - when File.exists?(File.join(base_dir, "ruby_generator.dll")) then - File.join(base_dir, "ruby_generator.dll") - else - File.join(base_dir, "ruby_generator.so") - end - -unless File.exists?(GENERATOR_FILE_PATH) - $stdout << <<-WARNING - Cannot locate shared object to plugin to protocol buffers generator. - Thought the file would be located at #{GENERATOR_FILE_PATH} - - If you are running on Windows you should compile protocol buffer - definitions on another VM and then use those definitions locally. - - Only the compiler is restricted by this. The definitions should work without issue. - WARNING - $stdout << $/ - - exit 1 -end - -module Protobuf - module RProtoC - extend FFI::Library - ffi_lib ::GENERATOR_FILE_PATH - attach_function :_rprotoc_extern, [:int, :pointer], :int32 - - def self.compile_proto(args) - GC.disable # Don't want strings to be GC'd while protoc has them - args = args.dup - args.unshift("rprotoc") - args << "--help" if args.size == 1 - - ptr_params = [] - args.each do |param| - ptr_params << ::FFI::MemoryPointer.from_string(param.dup) - end - ptr_params << nil - - argv = ::FFI::MemoryPointer.new(:pointer, ptr_params.size) - ptr_params.each_with_index do |param_pointer, index| - argv[index].put_pointer(0, param_pointer) - end - - self._rprotoc_extern(ptr_params.compact.size, argv) - ensure - GC.enable - end - end -end - -::Protobuf::RProtoC.compile_proto(ARGV) +exec command From 51d447fc7bea2ebaf7e0633e062b6a1d1def25ac Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 20 Aug 2013 11:37:00 -0600 Subject: [PATCH 0478/1191] Track the data.bin files --- .gitignore | 1 - spec/support/test/all_types.data.bin | Bin 0 -> 486 bytes spec/support/test/extreme_values.data.bin | Bin 0 -> 220 bytes 3 files changed, 1 deletion(-) create mode 100644 spec/support/test/all_types.data.bin create mode 100644 spec/support/test/extreme_values.data.bin diff --git a/.gitignore b/.gitignore index 1a65e74b..a3a7def3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ doc .yardoc .DS_Store *.so -*.bin Gemfile.lock tmp/* ext/defs diff --git a/spec/support/test/all_types.data.bin b/spec/support/test/all_types.data.bin new file mode 100644 index 0000000000000000000000000000000000000000..15596ae918330261374ccc4db2af9d3d0855654c GIT binary patch literal 486 zcmXxfJuE{}6bJBo&bhB%H>1&L^giy}B#+Jpu`(EZ#MeOLYv9Gyn5rb6BB@S|C~6Xk z&jqESjiD(qU=WkBqjRfHZhrZndv9{jH3yrAT83Lk+RD)W3>{-ah|Y0FSN8?3`=zt_g7f1 z@9E?<&Wk8SZ;TDLVkOR8!KnYAru_;+1;sm(Z7J5V)VIza>sa10ky!=pIj*oTpuNB( z`wH4i42c(|$w*TqOJa1ADRt3KQ0oohjH#y~Hs?ncG5fo!rvi_6HdH+_5vLx41Rjn5{AYsVRXv!Gm+U}lK F{Q_GAZ;Ai_ literal 0 HcmV?d00001 diff --git a/spec/support/test/extreme_values.data.bin b/spec/support/test/extreme_values.data.bin new file mode 100644 index 0000000000000000000000000000000000000000..f2f67cfb0c5f878b9d39041b761086b16e6d89fe GIT binary patch literal 220 zcmd<$Wng6I;Njxs2yHBp5I%G&VFe`~a~TH9$--U^HTW*s;Zy0SH_f z7#i$-85j=OhXPsqV}Y#wsS11Sd~>(8*G?(~DPdsvP+tjU{BLB0uzu9{0$C09Q$gha zxj^zj{USzDdj%kbA`qny#JVdOLAF91u>s76xMCM0TSjUQLr(r7Mz-?&B8HrlQ;aN$ ONes!C7+DOB7>oe}EKYy` literal 0 HcmV?d00001 From 95e14148c54440b574db1e5d68f10decff4dacb8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 13:31:41 -0600 Subject: [PATCH 0479/1191] Remove 1.8 compatability for nan/infinity, we aren't supporting 1.8 --- lib/protobuf/message.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 54ee2ce3..8882b44c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -5,18 +5,6 @@ require 'protobuf/exceptions' require 'protobuf/message/decoder' -# Define Float::INFINITY if it's not already defined (e.g. < ruby 1.9) -unless defined?(::Float::INFINITY) - puts 'DEFINING INFINITY' - ::Float::INFINITY = (1.0 / 0.0).freeze -end - -# Define Float::NAN if it's not already defined (e.g. < ruby 1.9) -unless defined?(::Float::NAN) - puts 'DEFINING NAN' - ::Float::NAN = (0.0 / 0.0).freeze -end - module Protobuf class Message From 59f9a4113ada5cd61bdd912c895b878762f6bf53 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 13:51:43 -0600 Subject: [PATCH 0480/1191] Create CHANGES.md Decalaring changelog bankruptcy for versions prior to 2.8.0. --- CHANGES.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CHANGES.md diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 00000000..b2999b9f --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,11 @@ +2.8.0 +----------- + +- New compiler supports protobuf compilation/runtime with protoc <= v2.5.0 (c++ compiler removed). [#109] +- Deprecated rprotoc in favor of protoc. [0bc9674] +- Added service dynamic discovery to the ZMQ connector and server. [#91, @devin-c] + +Versions < 2.8.0 +----------- + +- Please refer to commit logs for changes. From 93cfe65c467ad669c0b9ba679b215a9932730710 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 13:58:57 -0600 Subject: [PATCH 0481/1191] Moving UPGRADING.md content into CHANGES.md under heading "2.0.0" --- CHANGES.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b2999b9f..c6ad60ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,62 @@ - Deprecated rprotoc in favor of protoc. [0bc9674] - Added service dynamic discovery to the ZMQ connector and server. [#91, @devin-c] -Versions < 2.8.0 +2.0.0 ----------- -- Please refer to commit logs for changes. +#### `rprotoc` changes + +* New option `--ruby_out` to specify the output directory to place generated ruby files. If not provided, ruby code will not be generated. +* Extends `libprotoc` to hook in directly to google's provided compiler mechanism. +* Removed all previous compiler code including the racc parser, node visitors, etc. +* See `protoc --help` for default options. + +#### `rprotoc` generated files changes + +* Import `require`s now occur outside of any module or class declaration which solves ruby vm warnings previously seen. +* Empty inherited Message and Enum classes are pre-defined in the file, then reopened and their fields applied. This solves the issue of recursive field dependencies of two or more types in the same file. +* Generated DSL lines for message fields include the fully qualified name of the type (e.g. `optional ::Protobuf::Field::StringField, :name, 1`) +* Support for any combination of `packed`, `deprecated`, and `default` as options to pass to a field definition. +* Services are now generated in the corresponding `.pb.rb` file instead of their own `*_service.rb` files as before. + +#### `rpc_server` changes + +* Removed `--env` option. The running application or program is solely in charge of ensuring it's environment is properly loaded. +* Removed reading of `PB_CLIENT_TYPE`, `PB_SERVER_TYPE` environment variables. Should use mode switches or custom requires (see below) instead. +* Removed `--client_socket` in favor of using mode switches. This also means client calls made by the `rpc_server` will run as the same connector type as the given mode (socket, zmq, or evented). +* Removed `--pre-cache-definitions` switch in favor of always pre-caching for performance. +* Removed `--gc-pause-serialization` since using `--gc-pause-request` in conjunction was redundant. +* Removed `--client-type` in favor of mode switches. +* Removed `--server-type` in favor of mode switches. +* Added mode switch `--evented`. +* Added `--threads` to specify number of ZMQ Worker threads to use. Ignored if mode is not zmq. +* Added `--print-deprecation-warnings` switch to tell the server whether or not to print deprecation warnings on field usage. Enabled by default. +* See `rpc_server help start` for all options and usage. Note: the `start` task is the default and not necessary when running the `rpc_server`. + +#### Message changes + +* `Message#get_field` usage should now specify either `Message#get_field_by_name` or `Message#get_field_by_tag`, depending on your lookup criteria. +* Support for STDERR output when accessing a message field which has been defined as `[deprecated=true]`. Deprecated warnings can be skipped by running your application or program with `PB_IGNORE_DEPRECATIONS=1`. +* Significant internal refactoring which provides huge boosts in speed and efficiency both in accessing/writing Message field values, as well as serialization and deserialization routines. +* Refactor `Message#to_hash` to delegate hash representations to the field values, simply collecting the display values and returning a hash of fields that are set. This also affects `to_json` output. + +#### Enum changes + +* Add `Enum.fetch` class method to polymorphically retrieve an `EnumValue` object. +* Add `Enum.value_by_name` to retrieve the corresponding `EnumValue` to the given symbol name. +* Add `Enum.enum_by_value` to retrieve the corresponding `EnumValue` to the given integer value. + +#### RPC Service changes + +* `async_responder` paradigm is no longer supported. +* `self.response=` paradigm should be converted to using `respond_with(object)`. +* Significant internal changes that should not bleed beyond the API but which make maintaining the code much easier. + +#### RPC Client changes + +* In the absence of `PB_CLIENT_TYPE` environment var, you should be requiring the specific connector type specifically. For instance, if you wish to run in zmq mode for client requests, update your Gemfile: `gem 'protobuf', :require => 'protobuf/zmq'`. +* `:async` option on client calls is no longer recognized. + +#### Other changes + +* Moved files out of `lib/protobuf/common` folder into `lib/protobuf`. Files affected are logger, wire_type, util. The only update would need to be the require path to these files since the modules were always `Protobuf::{TYPE}`. From c8aa21008b53ce696f2bc1a2d581bdce132505f8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 13:59:21 -0600 Subject: [PATCH 0482/1191] Deleting UPGRADING.md in favor of CHANGES.md --- UPGRADING.md | 60 ---------------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 UPGRADING.md diff --git a/UPGRADING.md b/UPGRADING.md deleted file mode 100644 index 6bf87bd2..00000000 --- a/UPGRADING.md +++ /dev/null @@ -1,60 +0,0 @@ -# Upgrading from 1.X to 2.0 - -I'm sure I'm missing quite a few of the smaller changes that have been made, but here is a list of changes that should affect any external programs or applications using `protobuf`. - -## `rprotoc` changes - -* New option `--ruby_out` to specify the output directory to place generated ruby files. If not provided, ruby code will not be generated. -* Extends `libprotoc` to hook in directly to google's provided compiler mechanism. -* Removed all previous compiler code including the racc parser, node visitors, etc. -* See `protoc --help` for default options. - -## `rprotoc` generated files changes - -* Import `require`s now occur outside of any module or class declaration which solves ruby vm warnings previously seen. -* Empty inherited Message and Enum classes are pre-defined in the file, then reopened and their fields applied. This solves the issue of recursive field dependencies of two or more types in the same file. -* Generated DSL lines for message fields include the fully qualified name of the type (e.g. optional `::Protobuf::Field::StringField`, :name, 1) -* Support for any combination of `packed`, `deprecated`, and `default` as options to pass to a field definition. -* Services are now generated in the corresponding `.pb.rb` file instead of their own `*_service.rb` files as before. - -## `rpc_server` changes - -* Removed `--env` option. The running application or program is solely in charge of ensuring it's environment is properly loaded. -* Removed reading of `PB_CLIENT_TYPE`, `PB_SERVER_TYPE` environment variables. Should use mode switches or custom requires (see below) instead. -* Removed `--client_socket` in favor of using mode switches. This also means client calls made by the `rpc_server` will run as the same connector type as the given mode (socket, zmq, or evented). -* Removed `--pre-cache-definitions` switch in favor of always pre-caching for performance. -* Removed `--gc-pause-serialization` since using `--gc-pause-request` in conjunction was redundant. -* Removed `--client-type` in favor of mode switches. -* Removed `--server-type` in favor of mode switches. -* Added mode switch `--evented`. -* Added `--threads` to specify number of ZMQ Worker threads to use. Ignored if mode is not zmq. -* Added `--print-deprecation-warnings` switch to tell the server whether or not to print deprecation warnings on field usage. Enabled by default. -* See `rpc_server help start` for all options and usage. Note: the `start` task is the default and not necessary when running the `rpc_server`. - -## Message changes - -* `Message#get_field` usage should now specify either `Message#get_field_by_name` or `Message#get_field_by_tag`, depending on your lookup criteria. -* Support for STDERR output when accessing a message field which has been defined as `[deprecated=true]`. Deprecated warnings can be skipped by running your application or program with `PB_IGNORE_DEPRECATIONS=1`. -* Significant internal refactoring which provides huge boosts in speed and efficiency both in accessing/writing Message field values, as well as serialization and deserialization routines. -* Refactor `Message#to_hash` to delegate hash representations to the field values, simply collecting the display values and returning a hash of fields that are set. This also affects `to_json` output. - -## Enum changes - -* Add `Enum.fetch` class method to polymorphically retrieve an `EnumValue` object. -* Add `Enum.value_by_name` to retrieve the corresponding `EnumValue` to the given symbol name. -* Add `Enum.enum_by_value` to retrieve the corresponding `EnumValue` to the given integer value. - -## RPC Service changes - -* `async_responder` paradigm is no longer supported. -* `self.response=` paradigm should be converted to using `respond_with(object)`. -* Significant internal changes that should not bleed beyond the API but which make maintaining the code much easier. - -## RPC Client changes - -* In the absence of `PB_CLIENT_TYPE` environment var, you should be requiring the specific connector type specifically. For instance, if you wish to run in zmq mode for client requests, update your Gemfile: `gem 'protobuf', :require => 'protobuf/zmq'`. -* `:async` option on client calls is no longer recognized. - -## Other changes - -* Moved files out of `lib/protobuf/common` folder into `lib/protobuf`. Files affected are logger, wire_type, util. The only update would need to be the require path to these files since the modules were always `Protobuf::{TYPE}`. From 79fa89b6b8fc02cd689283c0f84b43306248018e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 14:36:48 -0600 Subject: [PATCH 0483/1191] Update README.md to remove/fix outdated information --- README.md | 134 ++++++++++++++++++++++++------------------------------ 1 file changed, 60 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 00fa0fde..0f5faf22 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,17 @@ [![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) -___IMPORTANT: Those upgrading from version 1.4.2 to 2.X should read the -[UPGRADING.md](https://github.com/localshred/protobuf/blob/master/UPGRADING.md) notes___ +___See [CHANGES.md](https://github.com/localshred/protobuf/blob/master/CHANGES.md) for up-to-date + API changes.___ -Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby. -We currently support version 2.4.1 with support for the new 2.5 coming shortly after -it becomes final. +Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. --- ## Install -You will likely need to install protobuf from your favorite package manager -or from source. This gem currently supports protobuf 2.4.1. You may alternatively -specify a `PROTOC_SRC` when installing with rubygems (see below). +You will need to install protobuf from your favorite package manager +or from source. This gem currently supports protobuf <= 2.5.0. ### OSX Install @@ -31,21 +28,17 @@ $ sudo apt-get install -y protobuf ### Gem Install -Once the protobuf package is installed, go ahead and install with rubygems. -If you'd like to skip installing the protobuf package (above) and specify an -alternate location for the protobuf package, for instance if you have a custom -protoc package, then specify it with `PROTOC_SRC=/path/to/src`. +Once the protobuf package is installed, install this gem with rubygems/bundler. _Please note that this will void your warranty as it were. If you compiled with a custom protobuf package and are having issues it may be difficult to troubleshoot._ ```shell $ gem install protobuf - -# Provide an alternative protoc source directory to build from. -$ PROTOC_SRC=/path/to/protobuf/src gem install protobuf ``` -## 1. Generating ruby classes from `.proto` files +------ + +## Generating ruby classes from `.proto` files Protocol Buffers are great because they allow you to clearly define data storage or data transfer packets. Google officially supports Java, C++, and Python for @@ -53,24 +46,23 @@ compilation and usage. Let's make it ruby aware! Let's say you have a `defs.proto` file that defines a User message. -``` +```protobuf package foo; message User { - required string first_name = 1; - required string last_name = 2; + optional string first_name = 1; + optional string last_name = 2; } ``` Now let's compile that definition to ruby: -``` -$ rprotoc defs.proto --ruby_out ./lib +```shell +$ protoc defs.proto --ruby_out ./lib ``` The previous line will take whatever is defined in `defs.proto` and output ruby classes to the `./lib` directory, obeying the package -directive. Assuming that's all `defs.proto` had defined, `./lib` -should now look like this: +directive. Your `./lib` should now look like this: ``` - lib @@ -85,18 +77,16 @@ module Foo class User < ::Protobuf::Message; end class User - required :string, :first_name, 1 - required :string, :last_name, 2 + optional ::Protobuf::Field::StringField, :first_name, 1 + optional ::Protobuf::Field::StringField, :last_name, 2 end end ``` -___Note:__ The generator will pre-define all the classes empty and then -re-open to apply the defined fields. This is an optimization to prevent -recursive field errors._ +__Note:__ The generator will pre-define all message/enum classes empty and then +re-open to apply the defined fields. This is to prevent field dependency errors. -The generated class is now just a plain old ruby object. -You can use it however you wish. +The generated class is now just a plain old ruby object. You can use it however you wish. ```ruby require 'lib/foo/user.pb' @@ -129,25 +119,20 @@ inflated_user = Foo::User.new.parse_from_string(bytes) inflated_user == user #=> true ``` -## 2. RPC +## Callings Services with RPC -RPC is one of many technologies that tries to solve the problem of getting -smaller pieces of data from one place to another. Many will argue for or -against RPC and its usefulness, but I'm not going to do that here. Google's -Protocol Buffers provides support for Services with RPC and that's why you're here. +Google's Protocol Buffers provides support for Services with RPC. -Any discussion about RPC leads to a discussion about clients and servers -and the remote procedures themselves. For our purposes, we'll talk about -a `Client` (process that is calling the server/service), a `Service` -(the remote procedure), and a `Server` (the process that manages one or more -services). We'll start with the Service first. +For our purposes, we'll talk about a `Client` (process that is calling +the server/service), a `Service` (the remote procedure), and a `Server` +(the process that manages one or more services). We'll start with the Service first. ### Services Services are simply classes that have endpoint methods defined. Here's what one looks like in protobuf: -``` +```protobuf package foo; message UserRequest { optional string email = 1; @@ -177,14 +162,12 @@ __Important Note: The UserService class here is a *stub*. You should not provide your implementation in this generated file as subsequent generations will wipe out your implmentation. Read on to learn how to use this stub.__ -Did you read the note above? Go read it. I'll wait. - -Ok, now that you have a generated service stub, you'll want to require it -from `lib` and implement the methods. Create a service implementation file -in your project. In rails I'd put this in `app/services/user_service.rb`. +Now that you have a generated service stub, you'll want to require it +from `lib` and provide the implementation. Create a service implementation file +in your project. In rails I'd put this in `app/services/foo/user_service.rb`. ```ruby -# app/services/user_service.rb +# app/services/foo/user_service.rb require 'lib/foo/user.pb' # Reopen the class and provide the implementation for each rpc method defined. @@ -195,10 +178,12 @@ module Foo # response -> Foo::UserResponse def find # request.email will be the unpacked string that was sent by the client request + users = [] User.find_by_email(request.email).each do |user| - # must only use a proto instance of Foo::User when appending to the `users` field - response.users << user.to_proto + users << user.to_proto end + + respond_with(:users => users) end end @@ -209,7 +194,7 @@ Simply implement the instance method for the defined rpc. You can provide any other methods in this class as helpers, but only those defined in the proto file will be callable by remote clients. Every request made by a client will provide a non-empty request of the defined type. The server creates a new -service instance based on the request, so you should not be constrained to just +service instance for every request, so you should not be constrained to just the endpoint method. This is similar to rails controllers where only methods defined by the routes file are hooked up to HTTP requests, but it's very common to implement private methods to aid in code quality and simpilicity. @@ -221,7 +206,7 @@ entirely. If you need to create your own response object (a valid case), simply `respond_with(new_response)`. The returned object should conform to one of three properties: 1. Response should be of same type as defined by the rpc definition (in this case, `Foo::UserList`), or -2. Response should be a hash. This hash will be used to construct an instance of the defined type and should therefore conform to the appropriate fields for that type. +2. Response should be a hash, respond to `to_hash`, or respond to `to_proto_hash`. The hash will be used to construct an instance of the defined type and should therefore conform to the appropriate fields for that type. 3. Response should respond to the `to_proto` method. The object returned by `to_proto` should be an instance of the defined response type. If at any time the implementation encounters an error, the client can be @@ -300,8 +285,8 @@ or `respond_with` just like you can in the endpoint methods. __Before Filters__ – Returning `false` from a before filter will cancel any other filter calls which would run afterwards, as well as canceling -invocation of the service method. Note: You must actually return false, -not just a "falsey" value such as nil. +invocation of the service method. _Note: You must actually return `false`, +not just a "falsey" value such as `nil`._ __After Filters__ – No request shortcutting. @@ -333,10 +318,8 @@ would have the filter applied. ### Servers -A service is nothing without being hooked up to a socket. It's the -nerdy kid waiting by the telephone for someone to call without knowing -that the phone company disconnected their house. Sad and pathetic. -So hook up the phone lines! +Services need to be hooked up to a socket to be called by clients. +Use the provided program `rpc_server`: ``` $ rpc_server -o myserver.com -p 9399 -l ./log/protobuf.log ./config/environment.rb @@ -363,7 +346,7 @@ result in shutting the server down gracefully. ``` $ ps aux | grep rpc_server -1234 ... rpc_server myservice.com:9399 +1234 ... rpc_server myserver.com:9399 $ kill -QUIT 1234 rpc_server shutdown @@ -371,8 +354,11 @@ rpc_server shutdown ### Clients -A lot of work has gone into making the client calls simple and easy -to use yet still powerful. Clients have a DSL that feels very ajaxy. +Calling a service with a clients feels very ajaxy. If you prefer +a simpler syntax I highly recommend using [ActiveRemote](https://github.com/liveh2o/active_remote) +which was developed in conjunction with this library to make +interacting with a remote service feel identical to using an +ActiveRecord model. Seriously, it's wicked cool. ```ruby # require the defs from the shared gem/repo @@ -384,18 +370,18 @@ req = Foo::UserRequest.new(:email => 'jeff@gmail.com') # Use the UserService class to generate a client, invoke the rpc method # while passing the request object. # We could also simply pass a hash to find. -Foo::UserService.client.find(req) do |c| +Foo::UserService.client.find(req) do |client| # This block will be executed (registering the callbacks) # before the request actualy occurs. - # the `c` param in this block is the `.client` object - # that is generated from the call above + # the `client` param in this block is the object + # that is created by `Foo::UserService.client`. # Register a block for execution when the response # is deemed successful from the service. Accepts - # the unpacked response as its only parameter + # the unpacked response as its only parameter. c.on_success do |response| - response.users.each do |u| - puts u.inspect + response.users.each do |user| + puts user.inspect end end @@ -404,8 +390,8 @@ Foo::UserService.client.find(req) do |c| # or server-side failure. The object passed to the # block has a `message` and a `code` attribute # to aid in logging/diagnosing the failure. - c.on_failure do |err| - puts 'It failed: ' + err.message + c.on_failure do |error| + puts 'It failed: ' + error.message end end ``` @@ -414,9 +400,9 @@ Many different options can be passed to the `.client` call above (such as `:timeout => 600`). See the `lib/protobuf/rpc/client.rb` and `lib/protobuf/rpc/service.rb` files for more documentation. -### Dynamic Discovery (ZMQ Only) +### Dynamic Service Discovery (ZMQ Only) It is possible to setup the RPC server and client in a way that -allows servers to be dynamically discovered by the client. +allows servers/services to be dynamically discovered by client processes. #### In the client ```ruby @@ -428,14 +414,14 @@ end # given port when sending beacons and have its own service # directory. You can prevent this code from running on the # server if needed: -unless defined? ::Protobuf::CLI +unless defined?(::Protobuf::CLI) ServiceDirectory.start do |config| config.port = 53000 end end ``` -#### Starting the server +#### Starting the server with dynamic discovery enabled ``` $ rpc_server --broadcast-beacons --beacon-port 53000 ... ``` @@ -447,10 +433,10 @@ desired service each time a request is made. __CAUTION:__ When running multiple environments on a single network, e.g., qa and staging, be sure that each environment is setup with -a unique beacon port; otherwise, clients in one environment _will_ +a unique beacon port; otherwise, clients in one environment ___will___ make requests to servers in the other environment. -Check out {Protobuf::ServiceDirectory} for more details. +Check out the source for Protobuf::ServiceDirectory for more details. ## 3. RPC Interop From eff21a1c084570d1028fefb6257bda127b85f820 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 17:24:55 -0600 Subject: [PATCH 0484/1191] Rename Message#serialize_to_string to encode, add class-level Message.encode Prefer the shorter term "encoding". Setup an alias to the old method name (serialize_to_string) so that we don't break backwards compat. Also added a class-level encode method to make it simpler to create and encode a message (a common use-case). --- lib/protobuf/code_generator.rb | 3 +- lib/protobuf/field/message_field.rb | 2 +- lib/protobuf/message.rb | 56 ++++++++++++++------------ lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 4 +- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- spec/lib/protobuf/message_spec.rb | 14 +++++-- 7 files changed, 48 insertions(+), 35 deletions(-) diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 6b6c7c67..43ce6d48 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -34,8 +34,7 @@ def response_bytes generate_file(file_descriptor) end - response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.new(:file => @generated_files) - return response.serialize_to_string + return ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files) end end diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 2e2e2466..8ad36a35 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -20,7 +20,7 @@ def decode(bytes) end def encode(value) - bytes = value.serialize_to_string + bytes = value.encode result = ::Protobuf::Field::VarintField.encode(bytes.size) result << bytes end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 8882b44c..6bf34bf0 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -47,6 +47,11 @@ def self.define_field(rule, type, fname, tag, options) end end + # Create a new object with the given values and return the encoded bytes. + def self.encode(values = {}) + self.new(values).encode + end + # Reserve field numbers for extensions. Don't use this method directly. def self.extensions(range) extension_fields.add_range(range) @@ -175,6 +180,28 @@ def each_field_for_serialization end end + def encode + stream = "" + + each_field_for_serialization do |field, value| + if field.repeated? + if field.packed? + key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED + packed_value = value.map { |val| field.encode(val) }.join + stream << ::Protobuf::Field::VarintField.encode(key) + stream << ::Protobuf::Field::VarintField.encode(packed_value.size) + stream << packed_value + else + value.each { |val| write_pair(stream, field, val) } + end + else + write_pair(stream, field, value) + end + end + + return stream + end + # Returns extension fields. See Message#fields method. def extension_fields self.class.extension_fields @@ -227,28 +254,6 @@ def respond_to_has_and_present?(key) (self.__send__(key).present? || [true, false].include?(self.__send__(key))) end - def serialize_to_string - stream = "" - - each_field_for_serialization do |field, value| - if field.repeated? - if field.packed? - key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED - packed_value = value.map { |val| field.encode(val) }.join - stream << ::Protobuf::Field::VarintField.encode(key) - stream << ::Protobuf::Field::VarintField.encode(packed_value.size) - stream << packed_value - else - value.each { |val| write_pair(stream, field, val) } - end - else - write_pair(stream, field, value) - end - end - - return stream - end - def set_field(tag, bytes) field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) field.set(self, bytes) if field @@ -298,11 +303,12 @@ def []=(name, value) ## # Instance Aliases # + alias_method :to_s, :encode + alias_method :bytes, :encode + alias_method :serialize, :encode + alias_method :serialize_to_string, :encode alias_method :to_hash_value, :to_hash alias_method :to_proto_hash, :to_hash - alias_method :to_s, :serialize_to_string - alias_method :bytes, :serialize_to_string - alias_method :serialize, :serialize_to_string alias_method :responds_to_has?, :respond_to_has? alias_method :respond_to_and_has?, :respond_to_has? alias_method :responds_to_and_has?, :respond_to_has? diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index e3ed8e62..eb9f349f 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -114,7 +114,7 @@ def request_bytes :request_proto => @options[:request], :caller => request_caller } - return ::Protobuf::Socketrpc::Request.new(fields).serialize_to_string + return ::Protobuf::Socketrpc::Request.encode(fields) rescue => e fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 58faeef5..93edae11 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -79,7 +79,7 @@ def broadcast_flatline :server => self.to_proto ) - @beacon_socket.send flatline.serialize_to_string, 0 + @beacon_socket.send(flatline.encode, 0) end def broadcast_heartbeat @@ -90,7 +90,7 @@ def broadcast_heartbeat :server => self.to_proto ) - @beacon_socket.send(heartbeat.serialize_to_string, 0) + @beacon_socket.send(heartbeat.encode, 0) log_debug { sign_message("sent heartbeat to #{beacon_uri}") } end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index bdf7cee0..c9f86af7 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -64,7 +64,7 @@ def running? end def send_data - data = @response.serialize_to_string + data = @response.encode @stats.response_size = data.size diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 94384aa7..0b28e0d1 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -50,6 +50,14 @@ end end + describe '.encode' do + let(:values) { { :name => "Jim" } } + + it 'creates a new message object with the given values and returns the encoded bytes' do + ::Test::Resource.encode(values).should eq ::Test::Resource.new(values).encode + end + end + describe '#initialize' do it "initializes the enum getter to 0" do test_enum = Test::EnumTestMessage.new @@ -89,7 +97,7 @@ it "accepts UTF-8 strings into string fields" do message = ::Test::Resource.new(:name => "Kyle Redfearn\u0060s iPad") - expect { message.serialize_to_string }.to_not raise_error + expect { message.encode }.to_not raise_error end it "keeps utf-8 when utf-8 is input for string fields" do @@ -118,7 +126,7 @@ it "raises a 'message not initialized' error" do expect { - message.serialize_to_string + message.encode }.to raise_error(Protobuf::SerializationError, /required/i) end end @@ -129,7 +137,7 @@ it "does not raise an error when repeated fields are []" do expect { message.repeated_enum = [] - message.serialize_to_string + message.encode }.to_not raise_error end From 7e598714796447446c36becc1edf6489edfdef6b Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 17:30:16 -0600 Subject: [PATCH 0485/1191] Rename Message#parse_from_string to decode. Prefer shorter "decode" method for converting from bytes to an inflated message. Add class-level method to create a new object of the message type and decode the bytes. This in practice is the ONLY use-case for decoding bytes. --- lib/protobuf/code_generator.rb | 3 +- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/field/message_field.rb | 4 +-- lib/protobuf/message.rb | 28 +++++++++++++------ lib/protobuf/rpc/connectors/common.rb | 8 ++---- lib/protobuf/rpc/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- lib/protobuf/rpc/service.rb | 6 ++-- lib/protobuf/rpc/service_directory.rb | 3 +- spec/bin/protoc-gen-ruby_spec.rb | 2 +- spec/lib/protobuf/code_generator_spec.rb | 4 +-- spec/lib/protobuf/message_spec.rb | 16 +++++++---- .../protobuf/rpc/connectors/common_spec.rb | 2 +- .../protobuf/rpc/service_directory_spec.rb | 4 +-- spec/lib/protobuf/rpc/service_spec.rb | 6 ++-- 15 files changed, 51 insertions(+), 41 deletions(-) diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 43ce6d48..df4b5ccf 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -19,8 +19,7 @@ def self.warn(message) end def initialize(request_bytes) - @request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.new - @request.parse_from_string(request_bytes) + @request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes) @generated_files = [] end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index e9725da6..fdb237cd 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -46,7 +46,7 @@ def define_setter end def encode(value) - value = value.serialize_to_string if value.is_a?(::Protobuf::Message) + value = value.encode if value.is_a?(::Protobuf::Message) value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value.size) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 8ad36a35..ead5807a 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -14,9 +14,7 @@ def acceptable?(val) end def decode(bytes) - message = type.new - message.parse_from_string(bytes) - message + type.decode(bytes) end def encode(value) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6bf34bf0..dbb2418a 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -23,6 +23,10 @@ def self.all_fields end end + def self.decode(bytes) + self.new.decode(bytes) + end + # Define a field. Don't use this method directly. def self.define_field(rule, type, fname, tag, options) field_array = options[:extension] ? extension_fields : fields @@ -98,7 +102,7 @@ def self.get_field_by_name(name) # Find a field object by +tag+ number. def self.get_field_by_tag(tag) fields[tag] - rescue TypeError => e + rescue TypeError tag = tag.nil? ? 'nil' : tag.to_s raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") end @@ -150,6 +154,16 @@ def clone copy_to(super, :clone) end + # Decode the given string bytes into this object. + def decode(string) + decode_from(::StringIO.new(string)) + end + + # Decode the given stream into this object. + def decode_from(stream) + Decoder.decode(stream, self) + end + def dup copy_to(super, :dup) end @@ -237,14 +251,6 @@ def inspect to_hash.inspect end - def parse_from(stream) - Decoder.decode(stream, self) - end - - def parse_from_string(string) - parse_from(::StringIO.new(string)) - end - def respond_to_has?(key) self.respond_to?(key) && self.has_field?(key) end @@ -303,6 +309,10 @@ def []=(name, value) ## # Instance Aliases # + alias_method :parse_from_string, :decode + alias_method :deserialize, :decode + alias_method :parse_from, :decode_from + alias_method :deserialize_from, :decode_from alias_method :to_s, :encode alias_method :bytes, :encode alias_method :serialize, :encode diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index eb9f349f..9bdeeebd 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -74,8 +74,7 @@ def parse_response log_debug { sign_message("Parsing response from server (connection closed)") } # Parse out the raw response - response_wrapper = Protobuf::Socketrpc::Response.new - response_wrapper.parse_from_string(@response_data) + response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) # Determine success or failure based on parsed data if response_wrapper.has_field?(:error_reason) @@ -88,8 +87,7 @@ def parse_response log_debug { sign_message("Successful response parsed") } # Ensure client_response is an instance - response_type = @options[:response_type].new - parsed = response_type.parse_from_string(response_wrapper.response_proto.to_s) + parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) if parsed.nil? and not response_wrapper.has_field?(:error_reason) fail(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') @@ -139,7 +137,7 @@ def succeed(response) # def timeout_wrap(&block) ::Timeout.timeout(options[:timeout], &block) - rescue ::Timeout::Error => e + rescue ::Timeout::Error fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond") end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 1e2958d5..684f1d7d 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -67,7 +67,7 @@ def log_signature # Parse the incoming request object into our expected request object def parse_request_from_buffer log_debug { sign_message("Parsing request from buffer: #{@request_data}") } - @request.parse_from_string(@request_data) + @request.decode(@request_data) rescue => error exc = ::Protobuf::Rpc::BadRequestData.new("Unable to parse request: #{error.message}") log_error { exc.message } diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index c9f86af7..964f823d 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -25,7 +25,7 @@ def initialize(server) # Instance Methods # def process_request - @client_address, empty, @request_data = read_from_backend + @client_address, _, @request_data = read_from_backend unless @request_data.nil? log_debug { sign_message("handling request") } diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index c708de58..a90e7b66 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -100,12 +100,12 @@ def self.rpc_method?(name) # code def self.implemented_services classes = (self.subclasses || []).select do |subclass| - subclass.rpcs.any? do |(name, method)| + subclass.rpcs.any? do |(name, _)| subclass.method_defined? name end end - classes.map &:name + classes.map(&:name) end ## @@ -138,7 +138,7 @@ def response # def request @_request ||= if @_request_bytes.present? - request_type.new.parse_from_string(@_request_bytes) + request_type.decode(@_request_bytes) else request_type.new end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 3d06031e..53995c16 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -204,8 +204,7 @@ def trigger(action, listing) def wait_for_beacon data, addr = @socket.recvfrom(2048) - beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new - beacon.parse_from_string(data) + beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.decode(data) # Favor the address captured by the socket beacon.try(:server).try(:address=, addr[3]) diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb index 79d2e445..a38f165f 100644 --- a/spec/bin/protoc-gen-ruby_spec.rb +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -6,7 +6,7 @@ let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) } let(:request_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:file_to_generate => [ "test/foo.proto" ]) } let(:expected_file) { ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') } - let(:expected_response_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:files => [ expected_file ]).serialize_to_string } + let(:expected_response_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(:files => [ expected_file ]) } it 'reads the serialized request bytes and outputs serialized response bytes' do ::IO.popen(binpath, 'w+') do |pipe| diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 3674a082..ec71f0f7 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -19,11 +19,11 @@ let(:file_generator2) { mock('file generator 2', :generate_output_file => output_file2) } let(:request_bytes) do - COMPILER::CodeGeneratorRequest.new(:proto_file => [ input_file1, input_file2 ]).serialize_to_string + COMPILER::CodeGeneratorRequest.encode(:proto_file => [ input_file1, input_file2 ]) end let(:expected_response_bytes) do - COMPILER::CodeGeneratorResponse.new(:file => [ output_file1, output_file2 ]).serialize_to_string + COMPILER::CodeGeneratorResponse.encode(:file => [ output_file1, output_file2 ]) end before do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 0b28e0d1..d4c198e1 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -2,6 +2,14 @@ describe Protobuf::Message do + describe '.decode' do + let(:message) { ::Test::Resource.new(:name => "Jim") } + + it 'creates a new message object decoded from the given bytes' do + ::Test::Resource.decode(message.encode).should eq message + end + end + describe '.define_field' do context 'when defining a field with a tag that has already been used' do it 'raises a TagCollisionError' do @@ -77,7 +85,7 @@ it "does not try to set attributes which have nil values" do Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=") - test_enum = Test::EnumTestMessage.new(:non_default_enum => nil) + Test::EnumTestMessage.new(:non_default_enum => nil) end it "takes a hash as an initialization argument" do @@ -105,8 +113,7 @@ name.force_encoding("UTF-8") message = ::Test::Resource.new(:name => name) - new_message = ::Test::Resource.new - new_message.parse_from_string(message.serialize_to_string) + new_message = ::Test::Resource.decode(message.encode) (new_message.name == name).should be_true end @@ -115,8 +122,7 @@ name.force_encoding("ASCII-8BIT") message = ::Test::Resource.new(:name => name) - new_message = ::Test::Resource.new - new_message.parse_from_string(message.serialize_to_string) + new_message = ::Test::Resource.decode(message.encode) (new_message.name == "my name").should be_true end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index bf4df29e..9d75ce03 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -87,7 +87,7 @@ before { subject.stub(:validate_request_type!).and_return(true) } before { subject.should_not_receive(:fail) } - its(:request_bytes) { should eq expected.serialize_to_string } + its(:request_bytes) { should eq expected.encode } end describe "#verify_callbacks" do diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 36d09032..9da989e0 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -159,7 +159,7 @@ def thread :server => server, :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT )} - let(:payload) { beacon.serialize_to_string } + let(:payload) { beacon.encode } it "adds a listing" do instance.should_receive(:add_listing_for).with(server) @@ -175,7 +175,7 @@ def thread :server => server, :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE )} - let(:payload) { beacon.serialize_to_string } + let(:payload) { beacon.encode } it "removes a listing" do instance.should_receive(:remove_listing_for).with(server) diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index b3f4952f..f9807b3d 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -131,7 +131,7 @@ def find_with_rpc_failed context 'when calling the rpc method' do context 'when response is implied' do - subject { NewTestService.new(:find_with_implied_response, request.serialize_to_string) } + subject { NewTestService.new(:find_with_implied_response, request.encode) } before { subject.find_with_implied_response } its(:response) { should be_a(Test::Resource) } @@ -139,7 +139,7 @@ def find_with_rpc_failed end context 'when using respond_with paradigm' do - subject { NewTestService.new(:find_with_respond_with, request.serialize_to_string) } + subject { NewTestService.new(:find_with_respond_with, request.encode) } before { subject.find_with_respond_with } its(:response) { should be_a(Test::Resource) } @@ -148,7 +148,7 @@ def find_with_rpc_failed end context 'when calling rpc_failed in the method' do - subject { NewTestService.new(:find_with_rpc_failed, request.serialize_to_string) } + subject { NewTestService.new(:find_with_rpc_failed, request.encode) } it 'invokes the rpc_failed callback with the error' do error = nil From 9ebd81d052add418e81c532809e53acf94cec8cb Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 17:39:48 -0600 Subject: [PATCH 0486/1191] Remove a bunch of old test/example code that is no longer relevant or already covered by specs --- examples/addressbook.pb.rb | 55 --- examples/addressbook.proto | 24 -- examples/reading_a_message.rb | 32 -- examples/writing_a_message.rb | 46 --- ext/ruby_generator/Makefile | 10 - ext/ruby_generator/RubyGenerator.cpp | 544 --------------------------- ext/ruby_generator/RubyGenerator.h | 206 ---------- ext/ruby_generator/extconf.rb | 35 -- ext/ruby_generator/protoc-ruby | Bin 232308 -> 0 bytes test/data/data.bin | 3 - test/data/data_source.py | 14 - test/data/types.bin | Bin 10999 -> 0 bytes test/data/types_source.py | 22 -- test/data/unk.png | Bin 10938 -> 0 bytes test/proto/addressbook.pb.rb | 66 ---- test/proto/addressbook.proto | 33 -- test/proto/addressbook_base.pb.rb | 58 --- test/proto/addressbook_base.proto | 26 -- test/proto/addressbook_ext.pb.rb | 20 - test/proto/addressbook_ext.proto | 6 - test/proto/collision.pb.rb | 17 - test/proto/collision.proto | 5 - test/proto/ext_collision.pb.rb | 24 -- test/proto/ext_collision.proto | 8 - test/proto/ext_range.pb.rb | 22 -- test/proto/ext_range.proto | 7 - test/proto/float_default.proto | 10 - test/proto/lowercase.pb.rb | 30 -- test/proto/lowercase.proto | 9 - test/proto/merge.pb.rb | 39 -- test/proto/merge.proto | 15 - test/proto/nested.pb.rb | 30 -- test/proto/nested.proto | 9 - test/proto/optional_field.pb.rb | 35 -- test/proto/optional_field.proto | 12 - test/proto/packed.pb.rb | 22 -- test/proto/packed.proto | 6 - test/proto/rpc.proto | 6 - test/proto/types.pb.rb | 84 ----- test/proto/types.proto | 37 -- test/test_addressbook.rb | 56 --- test/test_enum_value.rb | 41 -- test/test_extension.rb | 36 -- test/test_lowercase.rb | 11 - test/test_message.rb | 128 ------- test/test_optional_field.rb | 103 ----- test/test_packed_field.rb | 40 -- test/test_parse.rb | 15 - test/test_repeated_types.rb | 132 ------- test/test_serialize.rb | 61 --- test/test_standard_message.rb | 96 ----- test/test_types.rb | 226 ----------- 52 files changed, 2572 deletions(-) delete mode 100644 examples/addressbook.pb.rb delete mode 100644 examples/addressbook.proto delete mode 100644 examples/reading_a_message.rb delete mode 100644 examples/writing_a_message.rb delete mode 100644 ext/ruby_generator/Makefile delete mode 100644 ext/ruby_generator/RubyGenerator.cpp delete mode 100644 ext/ruby_generator/RubyGenerator.h delete mode 100644 ext/ruby_generator/extconf.rb delete mode 100755 ext/ruby_generator/protoc-ruby delete mode 100644 test/data/data.bin delete mode 100644 test/data/data_source.py delete mode 100644 test/data/types.bin delete mode 100644 test/data/types_source.py delete mode 100644 test/data/unk.png delete mode 100644 test/proto/addressbook.pb.rb delete mode 100644 test/proto/addressbook.proto delete mode 100644 test/proto/addressbook_base.pb.rb delete mode 100644 test/proto/addressbook_base.proto delete mode 100644 test/proto/addressbook_ext.pb.rb delete mode 100644 test/proto/addressbook_ext.proto delete mode 100644 test/proto/collision.pb.rb delete mode 100644 test/proto/collision.proto delete mode 100644 test/proto/ext_collision.pb.rb delete mode 100644 test/proto/ext_collision.proto delete mode 100644 test/proto/ext_range.pb.rb delete mode 100644 test/proto/ext_range.proto delete mode 100644 test/proto/float_default.proto delete mode 100644 test/proto/lowercase.pb.rb delete mode 100644 test/proto/lowercase.proto delete mode 100644 test/proto/merge.pb.rb delete mode 100644 test/proto/merge.proto delete mode 100644 test/proto/nested.pb.rb delete mode 100644 test/proto/nested.proto delete mode 100644 test/proto/optional_field.pb.rb delete mode 100644 test/proto/optional_field.proto delete mode 100644 test/proto/packed.pb.rb delete mode 100644 test/proto/packed.proto delete mode 100644 test/proto/rpc.proto delete mode 100644 test/proto/types.pb.rb delete mode 100644 test/proto/types.proto delete mode 100644 test/test_addressbook.rb delete mode 100644 test/test_enum_value.rb delete mode 100644 test/test_extension.rb delete mode 100644 test/test_lowercase.rb delete mode 100644 test/test_message.rb delete mode 100644 test/test_optional_field.rb delete mode 100644 test/test_packed_field.rb delete mode 100644 test/test_parse.rb delete mode 100644 test/test_repeated_types.rb delete mode 100644 test/test_serialize.rb delete mode 100644 test/test_standard_message.rb delete mode 100644 test/test_types.rb diff --git a/examples/addressbook.pb.rb b/examples/addressbook.pb.rb deleted file mode 100644 index 552b55b8..00000000 --- a/examples/addressbook.pb.rb +++ /dev/null @@ -1,55 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package tutorial; -# -# message Person { -# required string name = 1; -# required int32 id = 2; -# optional string email = 3; -# -# enum PhoneType { -# MOBILE = 0; -# HOME = 1; -# WORK = 2; -# } -# -# message PhoneNumber { -# required string number = 1; -# optional PhoneType type = 2 [default = HOME]; -# } -# -# repeated PhoneNumber phone = 4; -# } -# -# message AddressBook { -# repeated Person person = 1; -# } - -require 'protobuf/message/message' -require 'protobuf/enum' -require 'protobuf/message/extend' - -module Tutorial - class Person < ::Protobuf::Message - defined_in __FILE__ - required :string, :name, 1 - required :int32, :id, 2 - optional :string, :email, 3 - class PhoneType < ::Protobuf::Enum - defined_in __FILE__ - MOBILE = 0 - HOME = 1 - WORK = 2 - end - class PhoneNumber < ::Protobuf::Message - defined_in __FILE__ - required :string, :number, 1 - optional :PhoneType, :type, 2, :default => :HOME - end - repeated :PhoneNumber, :phone, 4 - end - class AddressBook < ::Protobuf::Message - defined_in __FILE__ - repeated :Person, :person, 1 - end -end diff --git a/examples/addressbook.proto b/examples/addressbook.proto deleted file mode 100644 index 13913b80..00000000 --- a/examples/addressbook.proto +++ /dev/null @@ -1,24 +0,0 @@ -package tutorial; - -message Person { - required string name = 1; - required int32 id = 2; - optional string email = 3; - - enum PhoneType { - MOBILE = 0; - HOME = 1; - WORK = 2; - } - - message PhoneNumber { - required string number = 1; - optional PhoneType type = 2 [default = HOME]; - } - - repeated PhoneNumber phone = 4; -} - -message AddressBook { - repeated Person person = 1; -} diff --git a/examples/reading_a_message.rb b/examples/reading_a_message.rb deleted file mode 100644 index 10bf49c9..00000000 --- a/examples/reading_a_message.rb +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env ruby - -require 'addressbook.pb' - -def list_people(address_book) - address_book.person.each do |person| - puts "Person ID: #{person.id}" - puts " Name: #{person.name}" - puts " E-mail: #{person.email}" unless person.email.empty? - person.phone.each do |phone_number| - print(case phone_number.type - when Tutorial::Person::PhoneType::MOBILE then - ' Mobile phone #: ' - when Tutorial::Person::PhoneType::HOME then - ' Home phone #: ' - when Tutorial::Person::PhoneType::WORK then - ' Work phone #: ' - end) - puts phone_number.number - end - end -end - -unless ARGV.size == 1 - puts "Usage: #{$0} ADDRESS_BOOK_FILE" - exit -end - -address_book = Tutorial::AddressBook.new -address_book.parse_from_file ARGV[0] - -list_people address_book diff --git a/examples/writing_a_message.rb b/examples/writing_a_message.rb deleted file mode 100644 index ab09b18a..00000000 --- a/examples/writing_a_message.rb +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env ruby - -require 'addressbook.pb' - -def prompt_for_address(person) - print 'Enter person ID number: ' - person.id = STDIN.gets.strip.to_i - print 'Enter name: ' - person.name = STDIN.gets.strip - print 'Enter email address (blank for none): ' - email = STDIN.gets.strip - person.email = email unless email.empty? - - loop do - print 'Enter a phone number (or leave blank to finish): ' - break if (number = STDIN.gets.strip).empty? - - person.phone << Tutorial::Person::PhoneNumber.new - person.phone.last.number = number - - print 'Is this a mobile, home, or work phone? ' - person.phone.last.type = - case type = STDIN.gets.strip - when 'mobile' then - Tutorial::Person::PhoneType::MOBILE - when 'home' then - Tutorial::Person::PhoneType::HOME - when 'work' then - Tutorial::Person::PhoneType::WORK - else - puts 'Unknown phone type; leaving as default value.' - nil - end - end -end - -unless ARGV.size == 1 - puts "Usage: #{$0} ADDRESS_BOOK_FILE" - exit -end - -address_book = Tutorial::AddressBook.new -address_book.parse_from_file ARGV[0] if File.exist? ARGV[0] -address_book.person << Tutorial::Person.new -prompt_for_address address_book.person.last -address_book.serialize_to_file ARGV[0] diff --git a/ext/ruby_generator/Makefile b/ext/ruby_generator/Makefile deleted file mode 100644 index 54fc40b9..00000000 --- a/ext/ruby_generator/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: \ - RubyGenerator.h \ - RubyGenerator.cpp - g++ -Wall -I/code/src/utilities/protobuf-2.4.1/src -lprotoc -lprotobuf -lpthread -o protoc-ruby RubyGenerator.cpp - -test: - rm -rf test/out/* - ./protoc-ruby --proto_path=../defs --ruby_out=../out ../defs/atlas/util.proto ../defs/atlas/newman/*.proto - -.PHONY: all test diff --git a/ext/ruby_generator/RubyGenerator.cpp b/ext/ruby_generator/RubyGenerator.cpp deleted file mode 100644 index c5e0475e..00000000 --- a/ext/ruby_generator/RubyGenerator.cpp +++ /dev/null @@ -1,544 +0,0 @@ -#include "RubyGenerator.h" - -namespace google { -namespace protobuf { -namespace compiler { -namespace ruby { - -RubyGenerator::RubyGenerator() {} // Constructor -RubyGenerator::~RubyGenerator() {} // Destructor - -// Generate one or more ruby source files for the given proto file. -bool RubyGenerator::Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const { - file_ = file; - context_ = context; - - filename = CreateRubyFileName(file_->name()); - ns_vector.clear(); - extended_messages.clear(); - SplitStringUsing(file_->package(), ".", &ns_vector); - - // Get a ZeroCopyOutputStream object of the data. - scoped_ptr output(context_->Open(filename)); - - // Check the data against Google's proto checking algorithm. - GOOGLE_CHECK(output.get()); - - // Get a printer. - io::Printer printer(output.get(), '$'); - printer_ = &printer; - - PrintGeneratedFileComment(); - PrintGenericRequires(); - PrintImportRequires(); - - PrintEnclosingNamespaceModules(); - StoreExtensionFields(file_); - - PrintEnumsForFileDescriptor(file_, false); - PrintMessagesForFileDescriptor(file_, false); - PrintMessagesForFileDescriptor(file_, true); - PrintDanglingExtendedMessages(); - PrintServices(); - - PrintEnclosingNamespaceModuleEnds(); - - if (printer.failed()) { - *error = "An unknown error occured writing file " + filename; - return false; - } - else { - return true; - } -} // end Generate() - -// -///////////////////////////////////////////////// [ namespaces ] ////////////// -// - -void RubyGenerator::PrintEnclosingNamespaceModules() const { - PrintNewLine(); - vector::iterator iter; - map data; - for (iter = ns_vector.begin(); iter < ns_vector.end(); iter++) { - data["ns"] = Constantize(*iter, false); - - printer_->Print(data, "module $ns$"); - PrintNewLine(); - PrintNewLine(); - printer_->Indent(); - } -} - -void RubyGenerator::PrintEnclosingNamespaceModuleEnds() const { - vector::iterator iter; - for (iter = ns_vector.begin(); iter < ns_vector.end(); iter++) { - printer_->Outdent(); - printer_->Print("end"); - PrintNewLine(); - PrintNewLine(); - } -} - - -// -///////////////////////////////////////////////// [ messages ] //////////////// -// - -// Print a comment and then iteratively PrintMessage for each message -// type defined by in this FileDescriptor scope. -// -void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const { - if (descriptor->message_type_count() > 0) { - if (print_fields) { - PrintComment("Message Fields", true); - } - else { - PrintComment("Message Classes", true); - } - - for (int i = 0; i < descriptor->message_type_count(); i++) { - PrintMessage(descriptor->message_type(i), print_fields); - } - PrintNewLine(); - } -} - -// Iterates the nested types of a message descriptor and calls PrintMessage for each. -// -void RubyGenerator::PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const { - for (int i = 0; i < descriptor->nested_type_count(); i++) { - PrintMessage(descriptor->nested_type(i), print_fields); - } -} - -// Print out the given descriptor message as a Ruby class. -// -void RubyGenerator::PrintMessage(const Descriptor* descriptor, bool print_fields) const { - map data; - data["class_name"] = descriptor->name(); - - switch (print_fields) { - case false: - - if (DescriptorHasNestedTypes(descriptor)) { - printer_->Print(data, "class $class_name$ < ::Protobuf::Message"); - PrintNewLine(); - printer_->Indent(); - - if (descriptor->enum_type_count() > 0) { - PrintEnumsForDescriptor(descriptor, true); - } - - if (descriptor->nested_type_count() > 0) { - PrintMessagesForDescriptor(descriptor, false); - } - - printer_->Outdent(); - printer_->Print(data, "end"); - } - else { - printer_->Print(data, "class $class_name$ < ::Protobuf::Message; end"); - } - - PrintNewLine(); - StoreExtensionFields(descriptor); - - break; - - case true: - - if (descriptor->field_count() > 0 || DescriptorHasExtensions(descriptor)) { - printer_->Print(data, "class $class_name$"); - PrintNewLine(); - printer_->Indent(); - - if (descriptor->nested_type_count() > 0) { - PrintMessagesForDescriptor(descriptor, true); - } - - // Print Fields - if (descriptor->field_count() > 0) { - for (int i = 0; i < descriptor->field_count(); i++) { - PrintMessageField(descriptor->field(i)); - } - } - - PrintExtensionRangesForDescriptor(descriptor); - - // Print Extension Fields - if (DescriptorHasExtensions(descriptor)) { - PrintMessageExtensionFields(descriptor->full_name()); - } - - printer_->Outdent(); - printer_->Print(data, "end"); - PrintNewLine(); - PrintNewLine(); - } - else if (descriptor->nested_type_count() > 0) { - printer_->Print(data, "class $class_name$"); - PrintNewLine(); - printer_->Indent(); - - if (descriptor->nested_type_count() > 0) { - PrintMessagesForDescriptor(descriptor, true); - } - - printer_->Outdent(); - printer_->Print(data, "end"); - PrintNewLine(); - PrintNewLine(); - } - - break; - } -} - -void RubyGenerator::PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const { - if (descriptor->extension_range_count() > 0) { - PrintNewLine(); - PrintComment("Extension Fields", false); - - for (int i = 0; i < descriptor->extension_range_count(); i++) { - const Descriptor::ExtensionRange* range = descriptor->extension_range(i); - map data; - data["message_class"] = Constantize(descriptor->full_name()); - data["start"] = SimpleItoa(range->start); - data["end"] = SimpleItoa(range->end); - printer_->Print(data, "extensions $start$...$end$"); - PrintNewLine(); - } - } -} - -// Print the given FieldDescriptor to the Message DSL methods. -void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const { - map data; - data["field_presence"] = ""; - data["field_name"] = descriptor->lowercase_name(); - data["tag_number"] = SimpleItoa(descriptor->number()); - data["data_type"] = ""; - data["default_opt"] = ""; - data["packed_opt"] = ""; - data["deprecated_opt"] = ""; - data["extension_opt"] = ""; - - if (descriptor->is_required()) { - data["field_presence"] = "required"; - } - else if (descriptor->is_optional()) { - data["field_presence"] = "optional"; - } - else if (descriptor->is_repeated()) { - data["field_presence"] = "repeated"; - } - - switch (descriptor->type()) { - // Primitives - case FieldDescriptor::TYPE_DOUBLE: data["data_type"] = "::Protobuf::Field::DoubleField"; break; - case FieldDescriptor::TYPE_FLOAT: data["data_type"] = "::Protobuf::Field::FloatField"; break; - case FieldDescriptor::TYPE_INT64: data["data_type"] = "::Protobuf::Field::Int64Field"; break; - case FieldDescriptor::TYPE_UINT64: data["data_type"] = "::Protobuf::Field::Uint64Field"; break; - case FieldDescriptor::TYPE_INT32: data["data_type"] = "::Protobuf::Field::Int32Field"; break; - case FieldDescriptor::TYPE_FIXED64: data["data_type"] = "::Protobuf::Field::Fixed64Field"; break; - case FieldDescriptor::TYPE_FIXED32: data["data_type"] = "::Protobuf::Field::Fixed32Field"; break; - case FieldDescriptor::TYPE_BOOL: data["data_type"] = "::Protobuf::Field::BoolField"; break; - case FieldDescriptor::TYPE_STRING: data["data_type"] = "::Protobuf::Field::StringField"; break; - case FieldDescriptor::TYPE_BYTES: data["data_type"] = "::Protobuf::Field::BytesField"; break; - case FieldDescriptor::TYPE_UINT32: data["data_type"] = "::Protobuf::Field::Uint32Field"; break; - case FieldDescriptor::TYPE_SFIXED32: data["data_type"] = "::Protobuf::Field::Sfixed32Field"; break; - case FieldDescriptor::TYPE_SFIXED64: data["data_type"] = "::Protobuf::Field::Sfixed64Field"; break; - case FieldDescriptor::TYPE_SINT32: data["data_type"] = "::Protobuf::Field::Sint32Field"; break; - case FieldDescriptor::TYPE_SINT64: data["data_type"] = "::Protobuf::Field::Sint64Field"; break; - - // Enums - case FieldDescriptor::TYPE_ENUM: - data["data_type"] = Constantize(descriptor->enum_type()->full_name()); - break; - - // Messages - case FieldDescriptor::TYPE_GROUP: - case FieldDescriptor::TYPE_MESSAGE: - default: - data["data_type"] = Constantize(descriptor->message_type()->full_name()); - break; - } - - if (descriptor->has_default_value()) { - string value; - switch(descriptor->cpp_type()) { - case FieldDescriptor::CPPTYPE_INT32: value = SimpleItoa(descriptor->default_value_int32()); break; - case FieldDescriptor::CPPTYPE_INT64: value = SimpleItoa(descriptor->default_value_int64()); break; - case FieldDescriptor::CPPTYPE_UINT32: value = SimpleItoa(descriptor->default_value_uint32()); break; - case FieldDescriptor::CPPTYPE_UINT64: value = SimpleItoa(descriptor->default_value_uint64()); break; - case FieldDescriptor::CPPTYPE_DOUBLE: value = SimpleDtoa(descriptor->default_value_double()); break; - case FieldDescriptor::CPPTYPE_FLOAT: value = SimpleFtoa(descriptor->default_value_float()); break; - case FieldDescriptor::CPPTYPE_BOOL: value = descriptor->default_value_bool() ? "true" : "false"; break; - case FieldDescriptor::CPPTYPE_ENUM: value = FullEnumNamespace(descriptor->default_value_enum()); break; - case FieldDescriptor::CPPTYPE_STRING: value = "\"" + descriptor->default_value_string() + "\""; break; - default: break; - } - data["default_opt"] = strings::Substitute(", :default => $0", value); - } - - if (descriptor->is_packable() && descriptor->options().has_packed()) { - string packed_bool = descriptor->options().packed() ? "true" : "false"; - data["packed_opt"] = strings::Substitute(", :packed => $0", packed_bool); - } - - if (descriptor->options().has_deprecated()) { - string deprecated_bool = descriptor->options().deprecated() ? "true" : "false"; - data["deprecated_opt"] = strings::Substitute(", :deprecated => $0", deprecated_bool); - } - - if (descriptor->is_extension()) { - data["extension_opt"] = ", :extension => true"; - } - - printer_->Print(data, - "$field_presence$ " - "$data_type$, " - ":$field_name$, " - "$tag_number$" - "$default_opt$" - "$packed_opt$" - "$deprecated_opt$" - "$extension_opt$"); - PrintNewLine(); -} - -// Print out each extension field previously mapped to the full name of -// the descriptor message. -// -// After printign the fields, erase the fields from the map so that we know -// which fields are dangling and to print wrapped in a re-opened class block. -// -void RubyGenerator::PrintMessageExtensionFields(const string full_name) const { - vector message_extensions = extended_messages[full_name]; - vector::iterator it; - for (it = message_extensions.begin(); it != message_extensions.end(); ++it) { - PrintMessageField(*it); - } - extended_messages.erase(full_name); -} - -// -///////////////////////////////////////////////// [ enums ] /////////////////// -// - -void RubyGenerator::PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const { - for (int i = 0; i < descriptor->enum_type_count(); i++) { - PrintEnum(descriptor->enum_type(i)); - } -} - -void RubyGenerator::PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const { - if (descriptor->enum_type_count() > 0) { - if (print_values) { - PrintComment("Enum Values", true); - } - else { - PrintComment("Enum Classes", true); - } - - for (int i = 0; i < descriptor->enum_type_count(); i++) { - PrintEnum(descriptor->enum_type(i)); - } - PrintNewLine(); - } -} - -// Print the given enum descriptor as a Ruby class. -void RubyGenerator::PrintEnum(const EnumDescriptor* descriptor) const { - map data; - data["class_name"] = descriptor->name(); - - printer_->Print(data, "class $class_name$ < ::Protobuf::Enum"); - printer_->Indent(); - PrintNewLine(); - - for (int i = 0; i < descriptor->value_count(); i++) { - PrintEnumValue(descriptor->value(i)); - } - - printer_->Outdent(); - printer_->Print(data, "end"); - PrintNewLine(); - PrintNewLine(); -} - -// Print the given enum value to the Enum class DSL methods. -void RubyGenerator::PrintEnumValue(const EnumValueDescriptor* descriptor) const { - map data; - data["name"] = descriptor->name(); - data["number"] = ConvertIntToString(descriptor->number()); - printer_->Print(data, "define :$name$, $number$"); - PrintNewLine(); -} - -// -///////////////////////////////////////////////// [ services ] //////////////// -// - -void RubyGenerator::PrintServices() const { - if (file_->service_count() > 0) { - PrintComment("Services", true); - for (int i = 0; i < file_->service_count(); i++) { - PrintService(file_->service(i)); - } - } -} - -// Print the given service as a Ruby class. -void RubyGenerator::PrintService(const ServiceDescriptor* descriptor) const { - map data; - data["class_name"] = descriptor->name(); - - printer_->Print(data, "class $class_name$ < ::Protobuf::Rpc::Service"); - PrintNewLine(); - printer_->Indent(); - - for (int i = 0; i < descriptor->method_count(); i++) { - PrintServiceMethod(descriptor->method(i)); - } - - printer_->Outdent(); - printer_->Print("end"); - PrintNewLine(); -} - -// Print the rpc DSL declaration to the Ruby service class. -void RubyGenerator::PrintServiceMethod(const MethodDescriptor* descriptor) const { - map data; - data["name"] = Underscore(descriptor->name()); - data["request_klass"] = Constantize(descriptor->input_type()->full_name()); - data["response_klass"] = Constantize(descriptor->output_type()->full_name()); - printer_->Print(data, "rpc :$name$, $request_klass$, $response_klass$"); - PrintNewLine(); -} - - -// -///////////////////////////////////////////////// [ general ] //////////////// -// - -void RubyGenerator::PrintDanglingExtendedMessages() const { - if (extended_messages.size() > 0) { - PrintComment("Extended Messages", true); - - tr1::unordered_map >::iterator it; - for (it = extended_messages.begin(); it != extended_messages.end(); ++it ) { - map data; - data["class_name"] = Constantize(it->first); - - printer_->Print(data, "class $class_name$"); - printer_->Indent(); - PrintNewLine(); - - PrintMessageExtensionFields(it->first); - - printer_->Outdent(); - printer_->Print(data, "end"); - PrintNewLine(); - PrintNewLine(); - } - } -} - -// Explicitly check for the key with `count` so that we don't create -// empty vectors for classes simply using bracket access. -// -bool RubyGenerator::DescriptorHasExtensions(const Descriptor* descriptor) const { - const string full_name = descriptor->full_name(); - if (extended_messages.count(full_name) > 0) { - return (extended_messages[full_name].size()); - } - else { - return 0; - } -} - -// Print a header or one-line comment (as indicated by the as_header bool). -void RubyGenerator::PrintComment(string comment, bool as_header) const { - char format[] = "# $comment$\n"; - char format_multi[] = "##\n# $comment$\n#\n"; - - map data; - data["comment"] = comment; - - if (as_header) { - printer_->Print(data, format_multi); - } - else { - printer_->Print(data, format); - } -} - -// Prints a require with the given ruby library. -void RubyGenerator::PrintRequire(string lib_name) const { - map data; - data["lib"] = lib_name; - printer_->Print(data, "require '$lib$'\n"); -} - -// Print a comment indicating that the file was generated. -void RubyGenerator::PrintGeneratedFileComment() const { - PrintComment("This file is auto-generated. DO NOT EDIT!", true); -} - -// Print out message requires as they pertain to the ruby library. -void RubyGenerator::PrintGenericRequires() const { - if (file_->message_type_count() > 0) { - PrintRequire("protobuf/message"); - } - if (file_->service_count() > 0) { - PrintRequire("protobuf/rpc/service"); - } -} - -void RubyGenerator::PrintImportRequires() const { - if (file_->dependency_count() > 0) { - PrintNewLine(); - PrintComment("Imports", true); - for (int i = 0; i < file_->dependency_count(); i++) { - PrintRequire(CreateRubyFileName(file_->dependency(i)->name(), true)); - } - } -} - -// Print a one-line comment. -void RubyGenerator::PrintComment(string comment) const { - PrintComment(comment, false); -} - -void RubyGenerator::PrintNewLine() const { - printer_->Print("\n"); -} - -// We need to store any extension fields defined in the scope of this -// descriptor message by the field's containing type. -void RubyGenerator::StoreExtensionFields(const FileDescriptor* descriptor) const { - for (int i = 0; i < descriptor->extension_count(); i++) { - const FieldDescriptor* extension_field = descriptor->extension(i); - const Descriptor* containing = extension_field->containing_type(); - extended_messages[containing->full_name()].push_back(extension_field); - } -} - -// Same as above, only accept the Descriptor type instead of FileDescriptor. -void RubyGenerator::StoreExtensionFields(const Descriptor* descriptor) const { - for (int i = 0; i < descriptor->extension_count(); i++) { - const FieldDescriptor* extension_field = descriptor->extension(i); - const Descriptor* containing = extension_field->containing_type(); - extended_messages[containing->full_name()].push_back(extension_field); - } -} - -} // namespace ruby -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/ext/ruby_generator/RubyGenerator.h b/ext/ruby_generator/RubyGenerator.h deleted file mode 100644 index dc0b7e7c..00000000 --- a/ext/ruby_generator/RubyGenerator.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H -#define GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace ruby { - -class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator { - public: - RubyGenerator(); - ~RubyGenerator(); - - // implemented Generate method from parent - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const; - - private: - mutable GeneratorContext* context_; - mutable io::Printer* printer_; - mutable const FileDescriptor* file_; - mutable string filename; - mutable vector ns_vector; - mutable tr1::unordered_map > extended_messages; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RubyGenerator); - - bool DescriptorHasExtensions(const Descriptor* descriptor) const; - void PrintDanglingExtendedMessages() const; - void PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const; - - void PrintEnclosingNamespaceModules() const; - void PrintEnclosingNamespaceModuleEnds() const; - - void PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const; - void PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const; - void PrintMessage(const Descriptor* descriptor, bool print_fields) const; - void PrintMessageField(const FieldDescriptor* descriptor) const; - void PrintMessageExtensionFields(const string full_name) const; - - void PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const; - void PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const; - void PrintEnum(const EnumDescriptor* descriptor) const; - void PrintEnumValue(const EnumValueDescriptor* descriptor) const; - - void PrintServices() const; - void PrintService(const ServiceDescriptor* descriptor) const; - void PrintServiceMethod(const MethodDescriptor* descriptor) const; - - void PrintGeneratedFileComment() const; - void PrintGenericRequires() const; - void PrintImportRequires() const; - void PrintComment(string comment) const; - void PrintComment(string comment, bool as_header) const; - void PrintRequire(string lib_name) const; - void PrintNewLine() const; - - void StoreExtensionFields(const FileDescriptor* descriptor) const; - void StoreExtensionFields(const Descriptor* descriptor) const; - - // Take the proto file name, strip ".proto" - // from the end and add ".pb.rb" - static string CreateRubyFileName(const string proto_filename) { - return CreateRubyFileName(proto_filename, false); - } - - static string CreateRubyFileName(const string proto_filename, bool for_require) { - string replacement = for_require ? ".pb" : ".pb.rb"; - return StringReplace(proto_filename, ".proto", replacement, false); - } - - static string ConvertIntToString(int number) { - stringstream stream; - stream << number; - return stream.str(); - } - - static string ConvertDoubleToString(double number) { - stringstream stream; - stream << number; - return stream.str(); - } - - static string ConvertFloatToString(float number) { - stringstream stream; - stream << number; - return stream.str(); - } - - static string Constantize(string full_path) { - return Constantize(full_path, true); - } - - static string Constantize(string full_path, bool is_top_level) { - stringstream constantized; - - if (is_top_level) { - constantized << "::"; - } - - string::iterator i; - bool segment_end = true; - for (i = full_path.begin(); i < full_path.end(); i++) { - char c = *i; - if (c == 46) { // period char - constantized << ':' << ':'; - segment_end = true; - continue; - } - else if (c == 95) { // underscore char - segment_end = true; - } - else if (segment_end) { - if (c >= 97 && c <= 122) { // a-z chars - c -= 32; - } - segment_end = false; - } - constantized << c; - } - - return constantized.str(); - } - - static string Underscore(string name) { - stringstream underscored; - - string::iterator i; - for (i = name.begin(); i < name.end(); i++) { - char c = *i; - if (c >= 65 && c <= 90) { // a-z chars - if (i != name.begin()) { - underscored << '_'; - } - c += 32; - } - underscored << c; - } - - return underscored.str(); - } - - static string FullEnumNamespace(const EnumValueDescriptor* descriptor) { - string parent_enum_type = Constantize(descriptor->type()->full_name()); - string enum_name = descriptor->name(); - - return strings::Substitute("$0::$1", parent_enum_type, enum_name); - } - - static bool DescriptorHasNestedTypes(const Descriptor* descriptor) { - return (descriptor->enum_type_count() > 0 || descriptor->nested_type_count() > 0); - } - -}; // class RubyGenerator - -} // namespace ruby -} // namespace compiler -} // namespace protobuf -} // namespace google - -#ifdef __cplusplus -extern "C" { -#endif - -int _rprotoc_extern(int argc, char* argv[]) { - google::protobuf::compiler::CommandLineInterface cli; - - google::protobuf::compiler::ruby::RubyGenerator ruby_generator; - cli.RegisterGenerator("--ruby_out", &ruby_generator, - "Generate Ruby-compatible protobuf message and service classes."); - - return cli.Run(argc, argv); -} - -/* - -Use for testing: - -int main(int argc, char* argv[]) { - return _rprotoc_extern(argc, argv); -} - -*/ - -#ifdef __cplusplus -} -#endif - -#endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H diff --git a/ext/ruby_generator/extconf.rb b/ext/ruby_generator/extconf.rb deleted file mode 100644 index 0a4efd0d..00000000 --- a/ext/ruby_generator/extconf.rb +++ /dev/null @@ -1,35 +0,0 @@ -unless defined?(JRUBY_VERSION) - begin - require 'mkmf' - include_directory = File.expand_path(ENV['PROTOC_SRC'] || File.join(File.dirname(__FILE__), "..", "protobuf-2.4.1", "src")) - - $CPPFLAGS << " -I#{include_directory}" - $CPPFLAGS << " -Wall " - - have_library("pthread") - have_library("protoc") - have_library("protobuf") - - create_makefile('ruby_generator') - rescue ::Gem::Installer::ExtensionBuildError => ex - $stdout << <<-WARNING - Cannot compile native extension. - - If you are running on Jruby or Windows you should compile protocol buffer - definitions on another computer and then use those definitions locally. - - Only the compiler is restricted by this. The definitions should work without issue. - WARNING - $stdout << $/ - end -else - $stdout << <<-WARNING - Cannot compile native extension. - - If you are running on Jruby or Windows you should compile protocol buffer - definitions on another computer and then use those definitions locally. - - Only the compiler is restricted by this. The definitions should work without issue. - WARNING - $stdout << $/ -end diff --git a/ext/ruby_generator/protoc-ruby b/ext/ruby_generator/protoc-ruby deleted file mode 100755 index 40417eeb4e0636a0c205e087d80d14a6e704e150..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 232308 zcmeFa34B!5`9C~R(4fS`DvC=b?zqRgfyH)EM@J-z3zoWp8=^%`kti-`C{CNncr{j2 zX{9xGu~bpx+F(fyh)hs~SQTQWH7eCRov4wzpi=pNzt3~dT_$q__V@nZ_xFB2<^y-` zIp^8W^E~I=bI-kZ<>&8xxn(TY?;EjLZU0y-wjKV@DT&2WwY%di7TXE`llVVz;<(W# zCeBWrekyCjfBnM6q9xK93MLaLo|%|%W*9{9dkUzSGGvPl#Q#ACW#Yu?m&};%;}_D4 z?+9hkeA+0b$MOIloQ2w8apJ^_uDbH-={R06mGy=6n$GAa^y-WNEK?ruuNS?mr`KF~ zwbxuoZ}@piZ>^zc%NC);(A&aPOq@u16Q^79y~z=q!imX|;DW_6wB5{o8Q6(i?0bScV%!{(;`r z)2Cf_<)sFqP`)NZ@2|!{EC=Zo$~tjk&6U?)cICwrFS~N`RiIf&Z`#jQzAi(A<-YzV zPP}Bw#L3exxZ)CpDx^2zmr8Hmcx`7nC|@CM#zi}Xo;dON(Pxehw8H;Il5$gL|&mA{D-tEXLcDdd`X%>~ooeo^#>8~7OL^(EKDiI-j#2(w=Fh8y`TJ(h#?*gf|L zOgVAll~X5PeccroUNv=M_4H}I=#4Yg_KjU#h-AyuRr9%Dn-KnG5SI|vd<&{RQKy2tC$gsHC)#}*0EJAHtClBv64hg za??=4FYh1Q9i-3wqJL~?LoBv6s>ZP%f3z|G-v&CX@c(31M*Nk(-#>OnP*DT74Sp-| zpLy(%nyaTBGWD_x54rfdsTZTnzg_U3a^#<0dhTCuJZ#Hf?|;ziE9Rc^=3c0y9a^ouV#;DCdV z4C3tr>a^38W&L9=`e;8>9`}N3e?XwzjPtMmzP7;E7Wmo%Ut8d73w&*XuPyMk1-`bx z*B1EN0$*F;YYY6pX@SdQ$@D*yv)A?{Gc!w)PEC3G^Vy60Eqd!4$$smS>6h{YlCu|; zBxjF|)qKJ;_eNa2rnBz&6Z*wIYQW!kqR;9s$5n26ebRBNH*VaROgphJ@#9q0;BNR)x~3=Tq#D=&0yic4#Zas;#d99O(gQ1I2!7VBK1JGvoKyPUn^;FTcRwdJmlNpBv_vPb- zd?rQd$zizA$)A!*Z7=%FO=eOTC!AdlF^yeG;H-NrHT<9YlaHeN;@CHiuqW6loeySFGgE{ z((OvA&11XVuzeV7D47(gq!YKouhdaiy5IaA9VLI9rMt$b+X1@PpYp#If662}Jj!bf z?o@ao5?XUIz0|#ssF}q28_MCrsl>C}12+3RCvjf-mE>{nOydVSUFwV%bN$NNIR>_kCtBKpiG zSEvb%w!Qk5J=K;@tjQmpO{^j7{Gpk|l5_%&m1qaYF8o6Jth@Xq-=z}mnS`58EXh~7 z|3S5qqWtnwT@qRID!AfhnY{C`s zE&&u`+J#KWoO{60jg(!KvQ5jK0P1A9gyl@t`sCAbV&gB_?{Y@@(1V*o;@%raE9za4OGylj-mAVk(M_zy5WtCt`w#yg$|DwlDY6&srD0N9e|+E z$1Ry|pG+6X2*e;lP?Ro@P`4p;F9^9AvYEAnog#@_#87FNxXCd;$)FnYUVT+W{m~Ki z`$p7npF5gHe4m-}3LYNi;R4io3T55DV0VD=pjrqUaJZp#n=ITcy=XQf$pqHj^;LH> zux?pMXeZG`s8VtK#2h%(oGYQYGoICSsQu6)c0vlSnqw-*Ac2dQvBDiHAo;^HiCd6! zU{cIT&{qz~q4je!ePZt=>Llykl1tMshAUGM;Aez7NGQBwC?GMbaM#d%HBSQnm2~2k z+@-)r6~k&MnJk0jgtYuaebpa=S~3*eeM!hk%!8KCULjiA2szFQNiF9Ama1Qj0ZX)G zh5Ky*F`l>h^BayDMR6}l@mK}crZ)4nIYC&oIDNnLyL zpsAsrybdkwG)40}a~QGHsSzM1?u?PQl?CR&ixel5Qt7kq2~xovI2It{)Twa-EPf4t zP*5L(qm0mnmkTHzU9fYv($`0!-S+hT7(wb2?~aPqd?$atWdX0ZEa>>6I6*KZ zUoj*PSNBIAk7HD+N@M12tR$B%&%0NQpg8$G;UO02o?bvn0kWoo6MxL~i|Mo~-Q`OJ zH}|@sLvl0-!_$peT}G^@;1}-cBJ{vNJr9L5_y^Y**w+070H;UW2kr>md zg5H=}E_H`sa6=V6zw^*fkRsAG=&2Q)do6bVYI6smv+gHwKF;`-W3mR64g_EqI$7HO z#x@e_LTv}8au{;+2f165`s^if34Fv_qJx3ITxN8EV*mUf^DisOto!(pR_a;ZwX`=U z&VelXBsx5lCB3oWW1CMQ?C4Kn50iR7<|KuQ+$nu=3QxUpVOuLU^`G-J@WD>f=ISqk zgToh~08fk<9R4n?kg9)t7enYVkt?zf)*IT z8yFYEB{;Kg@MqR`XiU8Y?~fQ>&L&;ZF{916aPfq2aa6eY?Qn5;xVW1RH1F{ea7TvU z&J4-tdG-+xobiw`d+6=MtUu50h6ub0Wb94TaZ6{Sub74l#u5?m8{7I*(wbY@d8S-NMVnIoMLvjg5XMol|Je;OG}{Af|C&fX(5)| z0=tsjy8s0eR<$oiN>PjeI~^=Ea(5%rtOTP%5>%=L7JVVnGbyRH9Eo5!-i{q(mJSC% zfErC?B4UgWzE6P;>|>`JMs^vdRrWY2xt%Jk_F~qZB}n;GEeB5Pd=4@`Iw=c$rsW{@ zR#u`ISzp60NcS3YFg~*ff|I^8814Yyait3+lWwr{iZ0gKCh6}VR2o-UFW_1CE_$JH zT&MKD3t4J3jr5%dEG^?ZJ&MPsDmraCH32o^JHjo~$})%N+Y~dS(EvezBo)5zObyv% z5=-F-@==epv;@jphXjmu-ot)JcLJb5!m9R+j4vq>3+&gSn2+T$0pGbXBtf-GV9{%d z4iQ*uITFEeyapUi&tg&3I!>Y%0$7fuK(9fiA%JB~^_Rma?>rSydk*t!0q6WrVk^OA z?K&|gm$g$CY=29&!J~?`Y+22Fasa5FPO8R71{{iW=ugo9@dYDmEm=PMnA?aHF^VBSls14ZX0kdi))1iu-iOrEYL`oRZ+lu zRU+-4teaGcJV)RvjFAYdFewYRyQPXT&&Y(O7@<0!HwsQ7Rh^39BE{To8S=*YsMXGC zKfw6sdiu!o-6oEu7g2F3oX7V@%$uzcT@bGFiYGL8uGOA4_Bmr9u9aI}=m z4$(s?@v=hzzvNJ=Di|hS6Sr?hG_8(qS`^*HecurT8>5?Uj&8avx@kgm6Rt+1#5gdz zX@}^hSaj3Bknti^el5D`+32Q+qMJA}NAQ{z*_6LB_j681UtW*HR33)$FbCH`xjYZQ zVR0i5U7zES;$Z|2k77=l8^E(ic!=T3C%1G14nO2!e;yuV-Df;BviJ@Ulflh%=d8P7 zxVN%WK{Gm>{hBZ{7jOuN2XZn%jWbE{Tl>SYag)mw4@c6JU|TR8dh(BVHh^|5Q*T;Q z0prBv1ihNiI1>cjA<^6=h!;?_44y!AVh&wvCWQNHpqU$gs6X_tCX6!>pQ)TTH?!`u z7~w?&r*zMAcsicdOw(`Jv0r3%s-UFQrw$ScIqu1bFoQB>T6G*;>Mm8ZjF)%*C>3)1 z6_Dw~6VPg?=)sFO-*!I6wT1-Rar+gZnZy&g_lA?)?vnq|Zsi{&=ia^NQOfK_++!4G zSl+bES}e*cnpiGj4RNge2=QlNQH#j+9U~NSThLlru@ZeLQ9ixF|T9vNH{P037E6P60+2>(JqU52~^ zBv-v4W2PHA{mIy^1ae=*5qHHDKuTPTS>+xCmUWBjoOcDiKE>a<)TQXMdWT23lQfKB z=ZDOe9DaE7SUMILan_i)j`QN`Ergl$kL%gGgj2NCJW zhZ&998-|J3G$*?0r;$zh>BXt#FNml=C8GX25%t4!@4$Y!yOFU40}TuQ_WzZ{bVmd6SZ`lTlRz9%q+17PJ~R;BAG@qlRJ~%pf|X> z&*G_fgX}u~tZDQx^jiw#Ski?VE8}26x2eZF^HRtjFs5<>McaL`D#}+$1NqPtF1? z){Pp8?JpfYQ(yHALaFBWo`%r4R2X|TPU-dIJ$>KU-GqaTd6X{mIgwnbLFp2)3)Vcj1qXOW^CLwz>UhU!@UY$1fSDQmah+Sf9GpbqJh zWU%)2ge;dB_rNM_n>yoYcul|=mtuy5>l0b_Y_q@=`vaJc3z%)b7p|_aT1_u}&|6b$ zp%h4}i6>-DEl}K^a`>%VB%;Xl1$1-X1hCFjg6xm8H(2)^cA#^_|rnQ#Y$cj16U@V-mI* z18v@xTW2)MGB~V?gnI?(9bDU06ORn#BHevP61tLcO0(k#)2J|FgIDdWVTAB=bbyei z86>WgUpjSb2_Z61mgC1=sAw5)aK2Y6c(r~Y+S9UPQAvcftXL>nh4zsyH&kRV9-(C~ z9tq?UoDBX9?XZCn*ZoYArY@6CgfY{Lpo=7$G`6|9zeJECp<{2GiogW}BSKSv%Hv9< z392beED#9G7cqXI+v{l9Is(bSR(ibH%-gy6JG8(Yj`o2}%Eek^7)0LW-pnd9t$N+R z)XgZGo!H>smQ--)Q)#)@V5G%bL&9?bA7hjuAp^OJj)eyi{QwSq7o*+EzXGE_WK`p1 z-G0gpQ)gwy#R+Na7Ln@@29fIzmi~RfrH^pU-B=YPrC?tR zYKV(SZ4oUu_iNhEYc+V|BBUf z|6j3s?*A)RACIU%DE9($>wBCgUc$qC9=^>wZs5%Qn1`i2oXfg3ICzG|8tG1(JAXVL z2^&^NUd*}=qaO?AkH;`DbpAMhEKj}p;}3MU5}rTyC$)(A;|Yr3&mZ@bimx(%{M62Z z+Q5YF>(3vDFo=e!v>1@HZkid@jwFn9XUMtKKwY+RDBZ2^`QwR7fl;Bn?ELX}a6*qX zSe+uoqz0uiuhIYenm>-+nWA~~$5y$a7BPR^9eb+d5F!B|d<95*JUSe?zzXZ?CVqU1pYB!RzW1AB@5-uns04 zvsG(Lh5^@coYHN^@O1nf<9B26}I)z~zt5q;8ZxzyOn| z#c<5gMF6@n{SiXVsIBGgQ-RFA$7H#q@+VVw765Zho0b%Y4eECD#|WIS4~8NU0^<Z=~%)R~)r*AwQ8nRHwY;20?!AW&Nz~pRI_l> zxv_tr`4mIf%&-N@On?ME_aN_)SF3bZ*wsk&*;ES%(ob_|;6|}!HVRJUGn09Qf6Mt^ z;Gt1!(}ooh(#q;#uws{G9Fo@Vy$0@p#NEUSOwqO89U-xxoqH1@9H? z#q@6)zKy94MsnSoC!mOTbZTEk`04j`IVZJ~c#VlG3q!yUm$~CmbT1WTBzBG@;T*IOR_xvp`FMf@=wiy@?FA?w%~EhL!1c<@>x^>6V`qFzlSkZk zhAu6%vdqpn-$*GNO2}%oRQR2Nxs25g)0xnyknxZP8!B?WOk2nlM>=B(R~HUPJCLn9 z_i()OZ>g_95lO-83|=xDgSG{*E|F1AR-=^#CO^XBT(Gd6fvJkc#caj9d-g+Nk<_bZ z#m1aPu>a0$kvo;Py=tzeb(|r`#383noxVBP^rj44+rMaBTL59TN0C!AG8)L5atp1E zi)eK&UPO~8{J9GcGR>n*8yQAsRJ|DW@Y$uj%>drYEACejVLZ7u|GibkhaVO(#b;9TDAx z>2;LK+eA05$EY4*sJEhZ-GIaSJiNo=K|EW=!vs+FoIC68 zH^|OgF^epR{ow2%0y#T-@Z+Q=X{k#~6TlvAJz5%vO~ok1J`~83kEB$tCHLP_8mgss zEmdf#MN7lAG*3&FTAHJ!5n8I#Qd~-r;tQBIpeQ&_=^@`?snIlY z^m)^pRuI8)l(jAG)JxCoMU=Sc;pjvt{Wow}92 zlu50Z=2R_9MiAUjXQhvNg{37>X~D?|fwU0I)t-QSdpn>4s(pgwkTmJHt%OZZQncoR ze>GwP?q<20>Kfxgm)gRAOt%p9;H_)LIFNU?hAkA>kz5 z;5gc2!sM8(!8V<0Q!{2-d4gL9BH%0$0Q{wEIge0@JR8mrNz|kgDRIT|QTMa71j|2f(15GlH`E5eu@f~ry(nm+I)My&%m`SwDE!tEIrLQMLeekrF7Y6$u!vwt`mfCmM5Bwez&7X3V+` zLc?6ssH3e3NzkDZSoGb9o=Hiq@y_EonNm94Av#@3$MPL2eCb@Qx0HxtDD4AE z?$Ii2wdt07=&iWbrromlQPM4@k=^nr+JoI9fZ8o*G6peoG2Jq-4nsb=g=Kcj?TQJ- zOum>Q6@IsD2r1K}$|!xs@lhF5oVuq3%Bn^JMzx9M0h?BBL z`WZtF+ggpyW@@ocZT2m8FkY^qjkMXFXb;-#z>s(qDxRf%B#Ge$C~K`aL@?si#e+5z zmTI%^fxyFRi?vzBVWiW_GHtf6$N<7J%)(~nDwJolQ6Zr!RVbyeI6msDaB1-~fwDr9 zfD!T-2~<>Rq^yxXVH}wG&%;>cx0kUX_2k0tg;A(oO_%by5_{}-dgNNuKnY6$J5TC{&&lg*%wrjh-V zK|5??W~GiJfNIr)`vVob+O1V%>WM7Vs+TEdCNtvWZPMT2Ug^cBZP-O?<(w8u{2R&I%Zm#`iZ-jFN?&n&)K)=-;sRwACjq1Q1yJ05g8}5Lb^?mI zdjk%+JjAd~8CpXOB{DKGYb^sJ7zURg?OXQ24QkodVp$%=vKUIqzROs45giYY(5Yqj zKA5FO(@4v%Mtjh*0;ra~9?=CMW?0LfPvlH1%e3s1ikV5xF_!(cRQQ%%6H>H86;=9* zLIXWk8oc$Rd2X(5UdD%}Jx2J&z&KD<_x@7wK5ET|i^K$dih( zMwW6fK&H$+|?=-GW&kaUEaF}4t)=FeNylKq#f?{S;wZ?2uNQLihqe5C#susazCLi@W zOG}`vRwQ7w`T?|Z?*SCdW>xEtV(tgq`DPm%Vi;G37Wx&&4rYt2wG4=080>R|(5^6M zYa%r60kG(l?!TXy%{0<%PoX_%HeE{-v;E+6pyDp0HQOJFjJu4+Yn8BlQ_&YJCx;bJzH zncL1&OgwCB%yxoQ_-4B?q(!xAq4X8UN8Q?^71W9Zj8=mVhuIDS6m+qw-Gyk#<*`m| zgY?!A!&+r%p(itT;NL+8L@*3mzAd!l#%$jvG}bBAY}`YOA;C1#Y)P~S%_e|qw*03+ z#j9?t*>0fCGp#JsZ2KrCZcH1ql}Uwfwz(lK8dM9VuQ)#HD{yQ`fiWVe6$u!v-h@`} zCv<S9&f2gTe>d;V%qF##0TB#?F_mJc zNycnT2#wW7HQOnBiP=me&Gt962fa-I)oe4d+X-f?v}UWK%`>em)7x4U6SrE8?)OQB zZ?-idEjm;SrLQSRkxpsZFTV6?geTDf(Af-Y9I4-gHx6YvctYqstX!!BiLp%*cB zF#lt%Wk3YOV7o(vcC|5^Lujl9s@ZnjQ_N->X|~^@J!m!oRI{D%5m3{q;nr+N(&m{~ zmT9(Giixco#%z~Mg>SYEAuW1T3#G3(KI$QsmOxppNWf@y8MJaw0~Bdq+W_wjPIvh@Ap|v@U#VIs zeZ}!n7YQnW1@^hH+(Rp?4)RII`9-Y3F`T3f zts(xo4#*gUSZf&&!7w;#f1%xM%=Rduozy%v+jnG7Y@=zU*|KO4noR)JY?prkR6Gr2 z&Gr^;j)#Jb*?zB>@DO9R+oZxb+l?VDs#Oc6uQ)#H8J3nnS*=LGXtfMlxix@-E>^WQ zh=$x@*llOcc58@XtunOG4>NW!Z)2@xKm@~p-w6ZlHe&XlWXyJ@VrEjqjoH306~5W#hO}r@y9n9NUYZ(y1_RGFPyTh36I6`Ax zPtEqCY*lSEjWpX2&>l3K0IJzGbORL}uQ)#HKjGMr0_%D~tw_LVb=`27ZA;a~s&*xia?i&nhOKN;8(fUn+dduL&8VLk*$y z6~{;Yp`|5I)}Khg7-lH^$#nn)U94&!y(dL60_?P}&99 zgtc4KhgFt?)LRZjF&xg>3mmQjRBjZO?yUp;4!%GKit*QRVzOmP9H<8|C7r%r9Y~wR zfvVP;rg8zt^N)-_>{MhCugc~QU8m7B(t&<$X_>`K-5DjcMvDihTEz`;}9q7l3 ziIp?sK$l2`??AhTj8d*f3GTe|QTO*~5z3l~1dNG3r-{Y_3c6U;9;bt2fzg=x9Tf2{ zu)DFP&34OyAqgr}0*gMK=*S*HjzlmVXM>}qGb%)#D+dca*m971%Yi6{!_Iqv!@=ZWlF#*U1KzIL4&7caN4cr+<3VDv z64PN1|4Ut86V@+*!xi)Gfs>J=teBTz#k>n$UiQ;|TM&ETVyKhMNL_fv-0TB%CP~zJyal5>8SHE$}!iq10Om ziDD!iNeQO`DtF%iU&7p5>qPV^O^2MbizCUKa(RA}svGv?V+ zDtwg}hE#4=l`Zh!{wcQ9-RWMB5XGqc>~2tb1E6xawd6^7g-SR{v>EapdA0$9^20^$ zASH=qIMvkv?I1uR@_R^p5``wq382o!&I%!8P#-B3zBbE4+O(-QhJZU*u`%ytz3o7v z7;WOz=3qdV1R&18D?aLB6yj;_F|3O9NvPF1kc@a>ceHM#_+Do{V1O_6Rc9f8LvkcO4nlOlrC zO2NireMAIm?UV@-BzUqz&Q@S_lr!waM8#O_=f%%S>9(;MhiC4we=~AUkWJ}$C$pr| zlzfCIq zNm_TvExOb#f}7=i)Rd(qP}U7ez&OcYcY%}q0Z=fXRc#wBidb-i(Ly6MN!t*TphqRJ z=qs7RaZj7ImLm}i$8*5ZPSOVRsU&|6&XVax@LdKvun&}xXP3+#ZK4=TkL?WE^W=uf zva!`&g5-zLt|1QP%E1C(YB@-~m6a%lL(NcdNRxxfhY!LHI7xd(`mR33UpzgIk0X89 z58p>Z=B=r;u%7~!VYKlzlaxbXgO;Wy!j<~vx73qZy_D-x=cBe>j(jYAivgnEB;$2g zaQrc{+->MTXz5GRKbW3~?F&GVq`#+MhACN%09?-%5bS;ys*={nfUr2D;89v^H^qarxZV_Z)8cSG z7-Hns^t^Eu1@yv=7{1%=}~x&J4J<+paRmig5;;5sUZ%Nl!FCcyT&9rska=6VmPeZ4ji@+ee{~I369UW zc^K}%RCFmi94~joQLYzX=42X4)cD9K&`+9#G1*{F5llNv{10|3!${RYkc6?$FGF!w zBkM}x${4@cJ`)RS- z6nEBQlPPYk#ST;4@K<3J>TT>Zm&sy6l zL@=Fl-Zulf+JvF1j;??aR82`3s-h$eRZkLzs>XydLkwK{d+xJ#8ddBkMH#1+Dk5R1 z;;ju5oJ<&Xa>j%qXSj$#1rkOrel%h5%)RX;lQ5abIC^KQ~rQoyl4hQNZ#Sg3X79l_j6xHY~A0(8H=EmOjDF zR(b20u=pleSX@5AZE%}_YgrsAEP&nQ2{_*fxDqbmp05%~v_PUQRU$n0s}k|aX+yOc zR4rInr%}7vqq@*g{iqC7OH^WcX~!sdF{Az}^kKamCF*zWCzhFEI{E}q1cPer=omKQ z!naH#JNjJZ=-t>9Kr^ns0#u{})6oMfxCcDb$}&6pXd|mWzX=`plnTG2`KY$hvCWEL zp7zAt+IYwN7}cet+dPez8;u{>78>uM@>_Lg5*)9VQ!Da;Zo{Di94ycT044QtZnpA^ zkm@?k+em|bl3RUy$V7U-s+?S5q>(4N$J}mQTmYfryT~_ubX&Re(QU)M3*0TxVgiwW zm#0y;;on^jjgF^ucoG}u@+7v9P)dBiBP#Rx@qU=rUB7S?+=dT)fwHiIJ#+mbkonHn`)z*E{|?HGrH-! z(M`jno4y&{v|;N=L%kE-)DhkEbad12qML4uZkiF@bYXPU*yyGsqnj$Co3@H>`e>_2 z8~!7@sXe;svFN6`(M>;zZmN!MIy<`Q_~@pCqnn0CH}#Kh>K+tn!&T8uZP85+L^s_P z-E>oQ)0F6@)1#Y4MK|pe-Bcdk^m$37q1Hw>t%z=FiEjE$bknWTP1i&>O^R+B6Ww%p zbklCpO(oGy>$Z%v;hN~CrO{2z(M`XMZn`D9>B{J)3DHf*MmHT8-Ly+|)4=Ga54MQ3 zAwQcHG0;C7-Skj&)7m}v-E@3()4|bAL!+DeM>lm3j5O4$=%%*lrU#;% z?uu@@DY|J&bkph4O{1cl_K9vPk8b*$E2G6{%WI>XRzx?oL^u5=y6KMSrW>N0E{SeB zHM(hJbkm;EO{LLI8@O0h+=lN&H+4ieJssWjyXdCdqMK$!H(eUtbXs)NccPp2j&3T8 zZsMc65jK1~x=G%5UflA30#?r9qQ|QXaM+E9AMx<+(>R>L!~Hx=S%||fJlyqX9Ny*O z*DU_I6^9*pxSWTszu+*6hue7=*oMOe&*1O`5Bo2|;U}znjfePR93Eudmpn{)7Ke4L zOYrRRB{&?zLjwOTFU29rvpd^y_!bY8Nd4&dQ;f5YKZ9v)_K>oquB@J}3G;@J*=$Kf&_9_FF{ zKX5pahhOsW1`mh4fx~njmhdpB3x|hzSjWT5Z{jeOhevtX2HzFQHLbec|HpFc16ka6J!)vf(x!R{aZy;zK=tUhZA|&{sSx%*#(lUyMJpeHo0NSl8qbhg@deuYm~Nc+;}|t{|0pWW9;eW z8#h+0*tqd6n34a#j}E;Jy?7tY{~Wq+1N!VRbkF7Jlha|skMaL**zRZ;Yz_Y303+=T z%lr`kOJS10yP&;yRb}|OhX_cYn26SYFG z7H6G6>jXV4XyMyX@=+6RVsI}55|{gK-bhmQDgM?aR@PUom?K}_zAInp-mwHi240Cg2i)dhMJjQZe0)1l?4Q3s z&u?*qYSumS&oTQ(ZhX7}CbX|O)qM(hH*hbZf%Wsh0Ce_x+)8cRt6yE}5a?MiN8SWI zh_e9yTLV+1m-L0XPHD+HHa3m`hUwIs&@TGmrPfX*>Ys)ju($O1=vuS9#|FxKp+M(P z%A^LPCY^v$?K>@J5CnS-4CDwy*St+#p!f-HLCmd%knVXZni0lbBJO41a*0u*{Y$LN z@7xAyiW%W?aUt`K;eN^VX(hSU-{7LON_Lkg8NQR@n`0uG$d{sxM0Xj9=BU~13t@L6 zb^n!{XNx~N6GS=j{;}!@=F@kMX%egbae+FM`6No#T?_95u}NZ~(sA7^nGcZ(!so{O z^b5j{BY@fizhYNo`vXjYUNYRU{Q+gJF#kg_?Y@?*yGSay!mMWaoo|LYRs_5?j_5wp zt%eGH(wOCU#wWjx)tmlqGH@D9a~&mh%Ew|J05|iZCqjH9aEa zJ`D8Q5+Aq4Y74i^16Q21#lyzu@&x-~V7uF?MA|)BccFlD8CoTJ#i!a1surx#Qf>FB z;xl?e^$b#NRf!RU@p1%*xP~)i_517*>9-LFvF5rq_lVQ*DQE2c>E$ ziW?2IGBEtKUPxc?xj{8`t_z369XU^@wZ2ZB(8+==60l?jNz&RGpYju(Ztf4AauPL2 zght@hQy~>RE%P}~%d>nC=rrM45sVRu(ikn_uD>`W*8fFA8^rE~3qjtK8Q*=9zDGWF zA+yDK95~Xut|v1-mnSm!r_4uKnHR)k`e!~<`GA@;PIEd>ijkdGDWxSLB-5=eBG;#Q zr614S{*Z@5#P@)5%d)c6RvUmiYYB6&+-WE$DHW2p6GR5Q{Ei`5tO?JtMKxhhLsZiz zP$Gh0S9H_L=qBWwD1yI@ZgL`<^4Av^FMnx7{h1N+N!=aRC>;8j-eBy8EpiWw?Pv-$F&uA z9~Brn;O&Kg#Wy+1o@z_ArBizWW_ndderK=mS9VJyoG{lPBb(*U8;*v18wd!`(&U_7aCgW4O;AlfbFEyT0mfxrzD#y@y#qlcVHRXUGaaZ43j3M71P}-LLl2 zhRHkwZF>(DdG2xU2cM1iFyFffd&BCg=G0fs;jW9Fl}S}ka9%R(*M^$l-cyMCi~6cx z5O+t5>wW2<5-J&?j2O2(8mch^xijQnYuU-t-{S=&zh`fC%Y1b!eL7I*+tYk?z4`NV z)vU}-!`K2+BKl$&LDar^Un{F&de&8#ydqQWi9Y3ImcOH7)3;cfxTjx!0FLPQd+HLu ztWW%svp#;OwYPi+xSkRX&7Pi+?`J>q<%C9PbxJLc9`&5i7izd<9hs^Gp4 zON6@eSM^oDBJQQx)F@~H$ML>1$ubni#f1y3q<=Z^@%MP z&b#W@^;N$H8~dF}&+He^^>y_sKfOZD%kTNoy!@?8+*@CDFG!T#@?-UG(Pt7RMZ0B?(eW2Y4#2)DK`o}f>vj*mIn=mWF%%KbCGINmrRZ5&WNJlo% zj+(;_6Wf%Z8Bu?EME&<8>W`18KQy9#x7+}Ddaj!z@?|_c#KRdJY12G#2=NSpE6w@l z`gC@8@h|C&*3k!%+k=neAVkuu@S#w*2mQfl&eW_$UA(U5ZCtI?C*HC%nQ!=c_ug9ZQU8y8R2hNohPG` zU_pvm0_W?4)Ft|Od25m-guF$4khDY$PNCh5@+VXGV~+39->zDPX3$1-k&0`m;1e$1 zx2vjxu7!CLT}xII+^yi1;$2V9pu5t+p2UR+uZZhYJW)4$^<%nO!S}7YA5=Fh@_nn@ zA&*Q}re6+PfyJC!8iAopP5-Zc-ztWSlw30dkG7h#SglV2TwP6IY#25;MvzR0?VO9fYp)8g+qxs{^oXPA+? z2qmjUM9lFHpnHhQR%vK=V)PPa3cqc;2uVO2;v%LB3U%uwC&4Ts3{E*RC&3;tfLxKf zt6*LPQ0*J|5yg_3MqaAAqyJziXX4h5_yse}ph)KF3XkDS$;^1rJ-sBEUX7*GjR+s7 zLL{f1lWB)5Fzy3FuvN~FM`z&S2EfSD-t=S+({fCJ)N)+SQp?F|mNml57+EDtAv}!D zu%0D0+X^#Xmm@FwV+5!!z#I+dLmtH5@xScKb4vM>J49Dpqr9{(P$jSEGy?b8P$cZ7nPG z(e{Fxl+{tA5LTi@p>4SmwZE?r7`p%bz417;ZPxt~ehO3fK#afaB}%SLKe-SkSUr>C zNqVt+w_-8a6%;{&9@N-h?9YtBpmR!aCb23sueb@>zzh)?1e8B_O%c9Ocm)GeaG6QOR(c#(1RU=TVQdv^!uzzNnm%N|6~}r#y6L&-CIna%!Cyo-&5mr! zR~HvAe_llWn27qLavyL7shRWD4|v#(OGf9R*K@z(8DE;Kqh>9K&ILS_v2_L=!**WQ zefB;(dd}{iB)7dJ5tQCJ8hf0dE{7ugOZIyynbs`7ATBkmLnmk5ixE#I_(CHICw&?G z2gpe>Tw>tEr%Dr8eU>>}JAMlWp8(1Zc7z3wL>pWNOGUZw(S?rWFfFJRK|v5Y5AuUsRf={xBQH-z(jmb zVIEov{h{lgP5Z+_!W8v~vp}(zKb%1}|113AP6)34Fsr)>Uh54RNQ{r8O^o4`p2?4Q z6&*e*fW$vDeC#BBpX40}P{<(rXy*-AD4m7zmWEt-eTLBrW;4*25!x&)+^OetNTudC zQZLE+g(gce?o(WVjpM)^-;{J}<|Lh&4Y)Oi>wcNFr=QeW86T13*;sv)&%FkO;H2Iq zJf?DqTBKOa<5c$7e=VHmp$?bun7_$Fz)z6st&Cp)BKHMY+fP_y&L%W4VbhxruPKcd zrGbf>&=?CE7KPzKw#A0etow!t2@r+_q_?@jdgcaft-rUh|G z%RdCyf8*mnlToS!fH_ZsJ6U2rXU-{|!3WZC|UP>t_2Gm&KDC2XL{;%YCe zPs`qW?s3c7x$9m)M(fOvCv<%*S@xGUNYI%)l>Tq>H`2TO$)F0F^y&qVvljo8WsfW} zpgqY29_W6=hcft&&2u&P2@<#VsriiAd<#?7OzC#}ptqbsg?TSvDS<c4RoW2o34?b0sG2K)kn#TmL;E_VQp9T$n$Ey z0uxxNeBAi|0C$|l9kIE5X|GItLWD-zIwhjjmwA%qE8Yg)aEr~=x7y-vwyjJbmv5?% zheyaw{QCIeymJxgNE8eFXj5KN8ALC@g%gbETRuP}HwiIrlMs{ohNzEE*$h3a`_`no zZyuTW{|q0gEMCpT*2AQR15%u%w*s54BiuT)x;Wzj7(DAKfUA#JZ&GJie-m154#fY> zOyozGmrcCumQ6*MM#!e5!_Abw`+aEN{mvUQz0$0g4K;UEL~!u68*byj@~h;mP4h`;P8g=wEghH@}rVwJeS86quD(aZZM`Vdj701qHZ|8QgyV z1@1Kl_Zypo%Q>3PQj!;8K31B?YgA-jG{6s$#mRn)GX0A94rZJ(6&^HwH~HOa`VR8D z_4IAzcQ7}$eJUHd6Lv_Gcpqkhu)%y5;n}kVbrL$>Y%;K?tu+h8l319z&ddY?Lb(iCI zwrAe8RX1&3CwNx%{2&xTTfvhxNNlDo4)-~_L*dGX-6E=3cwP)rIE?Wz{BqPUDLc6R znypx1FXu~C_UQgr3O%@D!F5$#KO$yu$-`*jV@{(>3S=_yycGQ1?T|~L1dUa9n=0T1 zG@IRBDgGb8ovwfo5_gIdo$dsdc{jeM(;Z5?6u2m;Rr+2nN^Nq?H2og%)dF2$ISPGS z#@e^guFwt=!UWor!7K*uaOCN`TTw_0b^M2Mj8@4Ef^yhIA(z1(WdoP)`?^a#wisW? z`>*<5^8PneO>U&f3%sihd3Fv~VUOacZz+MfDTrb-2eY1Gub-{uU}~6bWV<{dCPD3T zk5z)%4aKkA`+h$T4pI?=^vSa077MdnMS9sftRXDJ#Cpi< z*uuZA><7=M+gR1Hu57~d>&nhvR(9~Bvb)Sl-~+oQ=jOllN*^P?kcU4_ijjw>inPV|j3va`2BqD3rU3!wn9@1#=`U z@cyhqDs;~RN@_9mEJqyKIrN~17S6oAA!kKEN}pxjbu>pv3v@KN6ehO5ZBgwp=^O5p zC^&eh(V3ns84vsKBBe0ndNE(G@cPJMtctZhu4SJ?C4bNaYB+*01{aT#BB?(dC3h?J zKBL6?CN&EUCccp4`V`XIwU6GhJOc6c5$zq0uQ$D_O~zMa~D zty@#<=}NH!a2=rBiQi65ZXw;H{jkqi*(@)O@P^8p`f^#LZ!us0bY@?Oo5c0jn1O|h>9SOpEIaQEP#J{&zJfmIilMKd$ z0}WaCK3l8qPbIoQo!N{^QOVv)8UHKyEeLC4iAzOM;Y89JZ*SO0@)7e}IV(JDh*6

vEyKDsXM5u;`QUnhKj#FclB6>j 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 diff --git a/test/data/types_source.py b/test/data/types_source.py deleted file mode 100644 index 14b3094d..00000000 --- a/test/data/types_source.py +++ /dev/null @@ -1,22 +0,0 @@ -import types_pb2 -import sys - -types = types_pb2.TestTypes() -types.type1 = 0.01 -types.type2 = 0.1 -types.type3 = 1 -types.type4 = 10 -types.type5 = 100 -types.type6 = 1000 -types.type7 = -1 -types.type8 = -10 -types.type9 = 10000 -types.type10 = 100000 -types.type11 = False -types.type12 = 'hello all types' -# TODO test type13 -#types.type13 = - -f = open('types.bin', 'wb') -f.write(types.SerializeToString()) -f.close() diff --git a/test/data/unk.png b/test/data/unk.png deleted file mode 100644 index 37eabea7175930728eb92bd1cd572156405e98bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10938 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 diff --git a/test/proto/addressbook.pb.rb b/test/proto/addressbook.pb.rb deleted file mode 100644 index 1f9a113a..00000000 --- a/test/proto/addressbook.pb.rb +++ /dev/null @@ -1,66 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package tutorial; -# -# message Person { -# required string name = 1; -# required int32 id = 2; -# optional string email = 3; -# -# enum PhoneType { -# MOBILE = 0; -# HOME = 1; -# WORK = 2; -# } -# -# message PhoneNumber { -# required string number = 1; -# optional PhoneType type = 2 [default = HOME]; -# } -# -# repeated PhoneNumber phone = 4; -# optional uint32 age = 5 [default = 20]; -# -# extensions 100 to 200; -# } -# -# /* -# extend Person { -# optional int32 age = 100; -# } -# */ -# -# message AddressBook { -# repeated Person person = 1; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Tutorial - class Person < ::Protobuf::Message - defined_in __FILE__ - required :string, :name, 1 - required :int32, :id, 2 - optional :string, :email, 3 - class PhoneType < ::Protobuf::Enum - defined_in __FILE__ - define :MOBILE, 0 - define :HOME, 1 - define :WORK, 2 - end - class PhoneNumber < ::Protobuf::Message - defined_in __FILE__ - required :string, :number, 1 - optional :PhoneType, :type, 2, :default => :HOME - end - repeated :PhoneNumber, :phone, 4 - optional :uint32, :age, 5, :default => 20 - extensions 100..200 - end - class AddressBook < ::Protobuf::Message - defined_in __FILE__ - repeated :Person, :person, 1 - end -end \ No newline at end of file diff --git a/test/proto/addressbook.proto b/test/proto/addressbook.proto deleted file mode 100644 index d8350438..00000000 --- a/test/proto/addressbook.proto +++ /dev/null @@ -1,33 +0,0 @@ -package tutorial; - -message Person { - required string name = 1; - required int32 id = 2; - optional string email = 3; - - enum PhoneType { - MOBILE = 0; - HOME = 1; - WORK = 2; - } - - message PhoneNumber { - required string number = 1; - optional PhoneType type = 2 [default = HOME]; - } - - repeated PhoneNumber phone = 4; - optional uint32 age = 5 [default = 20]; - - extensions 100 to 200; -} - -/* -extend Person { - optional int32 age = 100; -} -*/ - -message AddressBook { - repeated Person person = 1; -} diff --git a/test/proto/addressbook_base.pb.rb b/test/proto/addressbook_base.pb.rb deleted file mode 100644 index 95b2c6ad..00000000 --- a/test/proto/addressbook_base.pb.rb +++ /dev/null @@ -1,58 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package tutorial_ext; -# -# message Person { -# required string name = 1; -# required int32 id = 2; -# optional string email = 3; -# -# enum PhoneType { -# MOBILE = 0; -# HOME = 1; -# WORK = 2; -# } -# -# message PhoneNumber { -# required string number = 1; -# optional PhoneType type = 2 [default = HOME]; -# } -# -# repeated PhoneNumber phone = 4; -# -# extensions 100 to 200; -# } -# -# message AddressBook { -# repeated Person person = 1; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module TutorialExt - class Person < ::Protobuf::Message - defined_in __FILE__ - required :string, :name, 1 - required :int32, :id, 2 - optional :string, :email, 3 - class PhoneType < ::Protobuf::Enum - defined_in __FILE__ - define :MOBILE, 0 - define :HOME, 1 - define :WORK, 2 - end - class PhoneNumber < ::Protobuf::Message - defined_in __FILE__ - required :string, :number, 1 - optional :PhoneType, :type, 2, :default => :HOME - end - repeated :PhoneNumber, :phone, 4 - extensions 100..200 - end - class AddressBook < ::Protobuf::Message - defined_in __FILE__ - repeated :Person, :person, 1 - end -end \ No newline at end of file diff --git a/test/proto/addressbook_base.proto b/test/proto/addressbook_base.proto deleted file mode 100644 index adb2ece0..00000000 --- a/test/proto/addressbook_base.proto +++ /dev/null @@ -1,26 +0,0 @@ -package tutorial_ext; - -message Person { - required string name = 1; - required int32 id = 2; - optional string email = 3; - - enum PhoneType { - MOBILE = 0; - HOME = 1; - WORK = 2; - } - - message PhoneNumber { - required string number = 1; - optional PhoneType type = 2 [default = HOME]; - } - - repeated PhoneNumber phone = 4; - - extensions 100 to 200; -} - -message AddressBook { - repeated Person person = 1; -} diff --git a/test/proto/addressbook_ext.pb.rb b/test/proto/addressbook_ext.pb.rb deleted file mode 100644 index 79e7b31b..00000000 --- a/test/proto/addressbook_ext.pb.rb +++ /dev/null @@ -1,20 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# import "test/proto/addressbook_base.proto"; -# package tutorial_ext; -# -# extend Person { -# optional int32 age = 100; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -require 'test/proto/addressbook_base.pb' -module TutorialExt - class Person < ::Protobuf::Message - defined_in __FILE__ - optional :int32, :age, 100, :extension => true - end -end \ No newline at end of file diff --git a/test/proto/addressbook_ext.proto b/test/proto/addressbook_ext.proto deleted file mode 100644 index 0fe9397c..00000000 --- a/test/proto/addressbook_ext.proto +++ /dev/null @@ -1,6 +0,0 @@ -import "test/proto/addressbook_base.proto"; -package tutorial_ext; - -extend Person { - optional int32 age = 100; -} diff --git a/test/proto/collision.pb.rb b/test/proto/collision.pb.rb deleted file mode 100644 index 83cd91ac..00000000 --- a/test/proto/collision.pb.rb +++ /dev/null @@ -1,17 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# message CollisionTest { -# optional string a = 1; -# optional string b = 1; -# } -# - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -class CollisionTest < ::Protobuf::Message - defined_in __FILE__ - optional :string, :a, 1 - optional :string, :b, 1 -end diff --git a/test/proto/collision.proto b/test/proto/collision.proto deleted file mode 100644 index b765c8ea..00000000 --- a/test/proto/collision.proto +++ /dev/null @@ -1,5 +0,0 @@ -message CollisionTest { - optional string a = 1; - optional string b = 1; -} - diff --git a/test/proto/ext_collision.pb.rb b/test/proto/ext_collision.pb.rb deleted file mode 100644 index 5a3125fe..00000000 --- a/test/proto/ext_collision.pb.rb +++ /dev/null @@ -1,24 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# message ExtCollisionTest { -# extensions 1 to 10; -# } -# -# message ExtCollisionTest { -# optional string a = 1; -# optional string b = 1; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -class ExtCollisionTest < ::Protobuf::Message - defined_in __FILE__ - extensions 1..10 -end -class ExtCollisionTest < ::Protobuf::Message - defined_in __FILE__ - optional :string, :a, 1 - optional :string, :b, 1 -end diff --git a/test/proto/ext_collision.proto b/test/proto/ext_collision.proto deleted file mode 100644 index 28de7105..00000000 --- a/test/proto/ext_collision.proto +++ /dev/null @@ -1,8 +0,0 @@ -message ExtCollisionTest { - extensions 1 to 10; -} - -message ExtCollisionTest { - optional string a = 1; - optional string b = 1; -} diff --git a/test/proto/ext_range.pb.rb b/test/proto/ext_range.pb.rb deleted file mode 100644 index 1a70161c..00000000 --- a/test/proto/ext_range.pb.rb +++ /dev/null @@ -1,22 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# message ExtRangeTest { -# extensions 1 to 10; -# } -# -# extend ExtRangeTest { -# optional string a = 11; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -class ExtRangeTest < ::Protobuf::Message - defined_in __FILE__ - extensions 1..10 -end -class ExtRangeTest < ::Protobuf::Message - defined_in __FILE__ - optional :string, :a, 11, :extension => true -end diff --git a/test/proto/ext_range.proto b/test/proto/ext_range.proto deleted file mode 100644 index ff1f9b72..00000000 --- a/test/proto/ext_range.proto +++ /dev/null @@ -1,7 +0,0 @@ -message ExtRangeTest { - extensions 1 to 10; -} - -extend ExtRangeTest { - optional string a = 11; -} diff --git a/test/proto/float_default.proto b/test/proto/float_default.proto deleted file mode 100644 index f48d3d63..00000000 --- a/test/proto/float_default.proto +++ /dev/null @@ -1,10 +0,0 @@ -message M { - optional float f = 1 [default = 4.2]; - optional float g = 2 [default = -4.2]; - optional float h = 3 [default = 4352]; - optional float i = 4 [default = 23145.2 ]; - optional float j = 5 [default = -5 ]; - optional float k = 6 [default = +23 ]; - optional float l = 7 [default = +23.42 ]; -} - diff --git a/test/proto/lowercase.pb.rb b/test/proto/lowercase.pb.rb deleted file mode 100644 index 3ebfbf51..00000000 --- a/test/proto/lowercase.pb.rb +++ /dev/null @@ -1,30 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package test.lowercase; -# -# message foo { -# message bar { -# } -# } -# message baaz { -# required foo.bar x = 1; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Test - module Lowercase - class Foo < ::Protobuf::Message - defined_in __FILE__ - class Bar < ::Protobuf::Message - defined_in __FILE__ - end - end - class Baaz < ::Protobuf::Message - defined_in __FILE__ - required :'foo::bar', :x, 1 - end - end -end \ No newline at end of file diff --git a/test/proto/lowercase.proto b/test/proto/lowercase.proto deleted file mode 100644 index ab52be42..00000000 --- a/test/proto/lowercase.proto +++ /dev/null @@ -1,9 +0,0 @@ -package test.lowercase; - -message foo { - message bar { - } -} -message baaz { - required foo.bar x = 1; -} diff --git a/test/proto/merge.pb.rb b/test/proto/merge.pb.rb deleted file mode 100644 index e31af31c..00000000 --- a/test/proto/merge.pb.rb +++ /dev/null @@ -1,39 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package test; -# -# message MergeMessage { -# message InnerMessage1 { -# required string name = 1; -# } -# message InnerMessage2 { -# required string name = 1; -# repeated InnerMessage1 repeate_message = 2; -# } -# -# required string name = 1; -# repeated InnerMessage1 repeate_message = 2; -# required InnerMessage2 require_message = 3; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Test - class MergeMessage < ::Protobuf::Message - defined_in __FILE__ - class InnerMessage1 < ::Protobuf::Message - defined_in __FILE__ - required :string, :name, 1 - end - class InnerMessage2 < ::Protobuf::Message - defined_in __FILE__ - required :string, :name, 1 - repeated :InnerMessage1, :repeate_message, 2 - end - required :string, :name, 1 - repeated :InnerMessage1, :repeate_message, 2 - required :InnerMessage2, :require_message, 3 - end -end \ No newline at end of file diff --git a/test/proto/merge.proto b/test/proto/merge.proto deleted file mode 100644 index 45a0bbdd..00000000 --- a/test/proto/merge.proto +++ /dev/null @@ -1,15 +0,0 @@ -package test; - -message MergeMessage { - message InnerMessage1 { - required string name = 1; - } - message InnerMessage2 { - required string name = 1; - repeated InnerMessage1 repeate_message = 2; - } - - required string name = 1; - repeated InnerMessage1 repeate_message = 2; - required InnerMessage2 require_message = 3; -} diff --git a/test/proto/nested.pb.rb b/test/proto/nested.pb.rb deleted file mode 100644 index afbf41bd..00000000 --- a/test/proto/nested.pb.rb +++ /dev/null @@ -1,30 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package test.nested; -# -# message Foo { -# message Bar { -# } -# } -# message Baaz { -# optional Foo.Bar x = 1; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Test - module Nested - class Foo < ::Protobuf::Message - defined_in __FILE__ - class Bar < ::Protobuf::Message - defined_in __FILE__ - end - end - class Baaz < ::Protobuf::Message - defined_in __FILE__ - optional :'Foo::Bar', :x, 1 - end - end -end \ No newline at end of file diff --git a/test/proto/nested.proto b/test/proto/nested.proto deleted file mode 100644 index 14974480..00000000 --- a/test/proto/nested.proto +++ /dev/null @@ -1,9 +0,0 @@ -package test.nested; - -message Foo { - message Bar { - } -} -message Baaz { - optional Foo.Bar x = 1; -} diff --git a/test/proto/optional_field.pb.rb b/test/proto/optional_field.pb.rb deleted file mode 100644 index 8f57e636..00000000 --- a/test/proto/optional_field.pb.rb +++ /dev/null @@ -1,35 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package test.optional_field; -# -# message Message { -# enum Enum { -# A = 1; -# B = 2; -# } -# optional uint32 number = 1 [default = 20]; -# optional string text = 2 [default = "default string"]; -# optional Enum enum = 3 [default = B]; -# optional int32 signed = 4 [default = -100]; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Test - module OptionalField - class Message < ::Protobuf::Message - defined_in __FILE__ - class Enum < ::Protobuf::Enum - defined_in __FILE__ - define :A, 1 - define :B, 2 - end - optional :uint32, :number, 1, :default => 20 - optional :string, :text, 2, :default => "default string" - optional :Enum, :enum, 3, :default => :B - optional :int32, :signed, 4, :default => -100 - end - end -end \ No newline at end of file diff --git a/test/proto/optional_field.proto b/test/proto/optional_field.proto deleted file mode 100644 index bb4f45e0..00000000 --- a/test/proto/optional_field.proto +++ /dev/null @@ -1,12 +0,0 @@ -package test.optional_field; - -message Message { - enum Enum { - A = 1; - B = 2; - } - optional uint32 number = 1 [default = 20]; - optional string text = 2 [default = "default string"]; - optional Enum enum = 3 [default = B]; - optional int32 signed = 4 [default = -100]; -} diff --git a/test/proto/packed.pb.rb b/test/proto/packed.pb.rb deleted file mode 100644 index 1c58b2e3..00000000 --- a/test/proto/packed.pb.rb +++ /dev/null @@ -1,22 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package test.packed_field; -# -# message Message { -# repeated int32 a = 1 [packed = true]; -# repeated fixed32 b = 2 [packed = true]; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Test - module PackedField - class Message < ::Protobuf::Message - defined_in __FILE__ - repeated :int32, :a, 1, :packed => true - repeated :fixed32, :b, 2, :packed => true - end - end -end \ No newline at end of file diff --git a/test/proto/packed.proto b/test/proto/packed.proto deleted file mode 100644 index 499bfa96..00000000 --- a/test/proto/packed.proto +++ /dev/null @@ -1,6 +0,0 @@ -package test.packed_field; - -message Message { - repeated int32 a = 1 [packed = true]; - repeated fixed32 b = 2 [packed = true]; -} diff --git a/test/proto/rpc.proto b/test/proto/rpc.proto deleted file mode 100644 index 5f4f7f48..00000000 --- a/test/proto/rpc.proto +++ /dev/null @@ -1,6 +0,0 @@ -package tutorial; - -service AddressBookService { - rpc Search (Person) returns (AddressBook); - rpc Add (Person) returns (Person); -} diff --git a/test/proto/types.pb.rb b/test/proto/types.pb.rb deleted file mode 100644 index 3bc6f0e2..00000000 --- a/test/proto/types.pb.rb +++ /dev/null @@ -1,84 +0,0 @@ -### Generated by rprotoc. DO NOT EDIT! -### -# package test.types; -# -# message TestTypes { -# required double type1 = 1; -# required float type2 = 2; -# required int32 type3 = 3; -# required int64 type4 = 4; -# required uint32 type5 = 5; -# required uint64 type6 = 6; -# required sint32 type7 = 7; -# required sint64 type8 = 8; -# required fixed32 type9 = 9; -# required fixed64 type10 = 10; -# required bool type11 = 11; -# required string type12 = 12; -# required bytes type13 = 13; -# required sfixed32 type14 = 14; -# required sfixed64 type15 = 15; -# } -# -# message RepeatedTypes { -# repeated double type1 = 1; -# repeated float type2 = 2; -# repeated int32 type3 = 3; -# repeated int64 type4 = 4; -# repeated uint32 type5 = 5; -# repeated uint64 type6 = 6; -# repeated sint32 type7 = 7; -# repeated sint64 type8 = 8; -# repeated fixed32 type9 = 9; -# repeated fixed64 type10 = 10; -# repeated bool type11 = 11; -# repeated string type12 = 12; -# repeated bytes type13 = 13; -# repeated sfixed32 type14 = 14; -# repeated sfixed64 type15 = 15; -# } - -require 'protobuf/message/message' -require 'protobuf/message/enum' -require 'protobuf/message/extend' - -module Test - module Types - class TestTypes < ::Protobuf::Message - defined_in __FILE__ - required :double, :type1, 1 - required :float, :type2, 2 - required :int32, :type3, 3 - required :int64, :type4, 4 - required :uint32, :type5, 5 - required :uint64, :type6, 6 - required :sint32, :type7, 7 - required :sint64, :type8, 8 - required :fixed32, :type9, 9 - required :fixed64, :type10, 10 - required :bool, :type11, 11 - required :string, :type12, 12 - required :bytes, :type13, 13 - required :sfixed32, :type14, 14 - required :sfixed64, :type15, 15 - end - class RepeatedTypes < ::Protobuf::Message - defined_in __FILE__ - repeated :double, :type1, 1 - repeated :float, :type2, 2 - repeated :int32, :type3, 3 - repeated :int64, :type4, 4 - repeated :uint32, :type5, 5 - repeated :uint64, :type6, 6 - repeated :sint32, :type7, 7 - repeated :sint64, :type8, 8 - repeated :fixed32, :type9, 9 - repeated :fixed64, :type10, 10 - repeated :bool, :type11, 11 - repeated :string, :type12, 12 - repeated :bytes, :type13, 13 - repeated :sfixed32, :type14, 14 - repeated :sfixed64, :type15, 15 - end - end -end diff --git a/test/proto/types.proto b/test/proto/types.proto deleted file mode 100644 index 984bc5e9..00000000 --- a/test/proto/types.proto +++ /dev/null @@ -1,37 +0,0 @@ -package test.types; - -message TestTypes { - required double type1 = 1; - required float type2 = 2; - required int32 type3 = 3; - required int64 type4 = 4; - required uint32 type5 = 5; - required uint64 type6 = 6; - required sint32 type7 = 7; - required sint64 type8 = 8; - required fixed32 type9 = 9; - required fixed64 type10 = 10; - required bool type11 = 11; - required string type12 = 12; - required bytes type13 = 13; - required sfixed32 type14 = 14; - required sfixed64 type15 = 15; -} - -message RepeatedTypes { - repeated double type1 = 1; - repeated float type2 = 2; - repeated int32 type3 = 3; - repeated int64 type4 = 4; - repeated uint32 type5 = 5; - repeated uint64 type6 = 6; - repeated sint32 type7 = 7; - repeated sint64 type8 = 8; - repeated fixed32 type9 = 9; - repeated fixed64 type10 = 10; - repeated bool type11 = 11; - repeated string type12 = 12; - repeated bytes type13 = 13; - repeated sfixed32 type14 = 14; - repeated sfixed64 type15 = 15; -} diff --git a/test/test_addressbook.rb b/test/test_addressbook.rb deleted file mode 100644 index 35660b86..00000000 --- a/test/test_addressbook.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'test/unit' -require 'protobuf/message/message' -require 'protobuf/enum' -require 'test/proto/addressbook.pb' - -class AddressbookTest < Test::Unit::TestCase - def test_enum - phone_number = Tutorial::Person::PhoneNumber.new - assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type) - phone_number.type = Tutorial::Person::PhoneType::MOBILE - assert_equal(0, phone_number.type) - phone_number.type = Tutorial::Person::PhoneType::HOME - assert_equal(1, phone_number.type) - phone_number.type = Tutorial::Person::PhoneType::WORK - assert_equal(2, phone_number.type) - assert_raise(TypeError) do - phone_number.type = 3 - end - end - - def test_symbol_enum - phone_number = Tutorial::Person::PhoneNumber.new - assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type) - phone_number.type = :MOBILE - assert_equal(0, phone_number.type) - phone_number.type = :HOME - assert_equal(1, phone_number.type) - phone_number.type = :WORK - assert_equal(2, phone_number.type) - assert_raise(TypeError) do - phone_number.type = :UNKNOWN - end - end - - def test_initial_value - person = Tutorial::Person.new - assert_nil(person.name) - assert_nil(person.id) - assert_equal([], person.phone) - assert_equal('', person.email) - end - - def test_repeatable - address_book = Tutorial::AddressBook.new - assert_equal([], address_book.person) - assert_instance_of(Protobuf::Field::FieldArray, address_book.person) - address_book.person << Tutorial::Person.new - assert_equal(1, address_book.person.size) - assert_raise(TypeError) do - address_book.person << 1 - end - assert_equal(1, address_book.person.size) - address_book.person << Tutorial::Person.new - assert_equal(2, address_book.person.size) - end -end diff --git a/test/test_enum_value.rb b/test/test_enum_value.rb deleted file mode 100644 index 59f5269a..00000000 --- a/test/test_enum_value.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'test/unit' -require 'protobuf/message/message' -require 'protobuf/enum' -require 'test/proto/addressbook.pb' -require 'test/proto/addressbook_base.pb' - -class EnumValueTest < Test::Unit::TestCase - def test_enum_value - e = Protobuf::EnumValue.new(Object, :name, 100) - assert_kind_of(Protobuf::EnumValue, e) - assert_equal(:name, e.name) - assert_equal(100, e.value) - assert_equal('name', e.to_s) - assert_equal('name', "#{e}") - assert(e == 100) - assert(100 == e) - assert(101, e + 1) - assert(101, 1 + e) - end - - def test_enum_field_and_enum_value - phone_number = Tutorial::Person::PhoneNumber.new - - assert_kind_of(Protobuf::EnumValue, phone_number.type) - assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type) - - phone_number.type = 1 - assert_kind_of(Protobuf::EnumValue, phone_number.type) - assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type) - assert_equal(1, phone_number.type) - - phone_number.type = :HOME - assert_kind_of(Protobuf::EnumValue, phone_number.type) - assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type) - assert_equal(1, phone_number.type) - - assert_raise(TypeError) do - phone_number.type = TutorialExt::Person::PhoneType::HOME - end - end -end diff --git a/test/test_extension.rb b/test/test_extension.rb deleted file mode 100644 index 6384db7f..00000000 --- a/test/test_extension.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test/unit' -require 'test/proto/addressbook_ext.pb' - -class ExtensionTest < Test::Unit::TestCase - def test_accessor - assert(TutorialExt::Person.extension_fields.to_a.map{|t, f| f.name}.include?(:age)) - person = TutorialExt::Person.new - assert_nothing_raised {person.age = 100} - assert_equal(100, person.age) - end - - def test_serialize - # serialize to string - person = TutorialExt::Person.new - person.id = 1234 - person.age = 70 - person.name = 'John Doe' - person.email = 'jdoe@example.com' - phone = TutorialExt::Person::PhoneNumber.new - phone.number = '555-4321' - phone.type = TutorialExt::Person::PhoneType::HOME - person.phone << phone - serialized_string = person.serialize_to_string - - # parse the serialized string - person2 = TutorialExt::Person.new - person2.parse_from_string serialized_string - assert_equal(1234, person2.id) - assert_equal(70, person2.age) - assert_equal('John Doe', person2.name) - assert_equal('jdoe@example.com', person2.email) - assert_equal(1, person2.phone.size) - assert_equal('555-4321', person2.phone[0].number) - assert_equal(TutorialExt::Person::PhoneType::HOME, person2.phone[0].type) - end -end diff --git a/test/test_lowercase.rb b/test/test_lowercase.rb deleted file mode 100644 index 7e7f7689..00000000 --- a/test/test_lowercase.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'test/unit' -require 'test/proto/lowercase.pb' - -class LowercaseTest < Test::Unit::TestCase - def test_lowercase - message = nil - assert_nothing_raised { message = Test::Lowercase::Baaz.new } - assert_nothing_raised { message.x = Test::Lowercase::Foo::Bar.new } - assert_equal(Test::Lowercase::Foo::Bar, message.get_field_by_name(:x).type) - end -end diff --git a/test/test_message.rb b/test/test_message.rb deleted file mode 100644 index bb0da7b1..00000000 --- a/test/test_message.rb +++ /dev/null @@ -1,128 +0,0 @@ -require 'protobuf/message/message' -require 'test/proto/addressbook.pb' -require 'test/proto/merge.pb' -require 'test/unit' - -# It should not conflict with Test::InnerMessage1 which is included in merge.proto -class InnerMessage1; end - -class MessageTest < Test::Unit::TestCase - def test_equality - person1 = Tutorial::Person.new :name => 'ando' - person2 = Tutorial::Person.new :name => 'ando' - person3 = Tutorial::Person.new :name => 'Ando' - assert(person1 == person2) - assert(person1 != person3) - assert(person1 != 'ando') - end - - def test_bracketed_access - person = Tutorial::Person.new - name_tag = 1 - person[name_tag] = 'Ichiro' - assert_equal('Ichiro', person.name) - assert_equal('Ichiro', person[name_tag]) - - person[:id] = 100 - assert_equal(100, person.id) - person['id'] = 200 - assert_equal(200, person.id) - assert_equal(200, person[:id]) - assert_equal(200, person['id']) - end - - def test_initialize_with_hash - person = Tutorial::Person.new(:name => 'Jiro', :id => 300, :email => 'jiro@ema.il') - assert_equal('Jiro', person.name) - assert_equal(300, person.id) - assert_equal('jiro@ema.il', person.email) - - # initialize with array of hash - person = Tutorial::Person.new(:phone => [{:number => 'phone1'}, {:number => 'phone2'}]) - assert_equal('phone1', person.phone[0].number) - assert_equal('phone2', person.phone[1].number) - - # initalize with hash in hash - message = Test::MergeMessage.new(:require_message => { :name => 'name1', :repeate_message => [{:name => 'name2'}] }) - assert_equal('name1', message.require_message.name) - assert_equal('name2', message.require_message.repeate_message[0].name) - - message.require_message = { :name => 'name21' } - message.require_message.repeate_message = [ {:name => 'name22'} ] - assert_equal('name21', message.require_message.name) - assert_equal('name22', message.require_message.repeate_message[0].name) - assert_equal(1, message.require_message.repeate_message.size) - end - - def test_defined_filenames - assert(Tutorial::Person.defined_filenames) - assert_equal(1, Tutorial::Person.defined_filenames.size) - assert_match(%r{/.*/proto/addressbook\.pb\.rb}, Tutorial::Person.defined_filenames.first) - end - - def test_proto_filenames - assert(Tutorial::Person.proto_filenames) - assert_equal(1, Tutorial::Person.proto_filenames.size) - assert_equal('test/proto/addressbook.proto', Tutorial::Person.proto_filenames.first) - end - - def test_proto_contents - assert_equal(<<-EOS.strip, Tutorial::Person.proto_contents.values.first.strip) -package tutorial; - -message Person { - required string name = 1; - required int32 id = 2; - optional string email = 3; - - enum PhoneType { - MOBILE = 0; - HOME = 1; - WORK = 2; - } - - message PhoneNumber { - required string number = 1; - optional PhoneType type = 2 [default = HOME]; - } - - repeated PhoneNumber phone = 4; - optional uint32 age = 5 [default = 20]; - - extensions 100 to 200; -} - -/* -extend Person { - optional int32 age = 100; -} -*/ - -message AddressBook { - repeated Person person = 1; -} - EOS - end - - def test_merge_field - inner_message1_2 = Test::MergeMessage::InnerMessage2.new(:name => 'name12') - inner_message1_2.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name121') - message1 = Test::MergeMessage.new(:name => 'name1', :require_message => inner_message1_2) - message1.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name11') - - inner_message2_2 = Test::MergeMessage::InnerMessage2.new(:name => 'name22') - inner_message2_2.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name221') - message2 = Test::MergeMessage.new(:name => 'name2', :require_message => inner_message2_2) - message2.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name21') - - message1.merge_from(message2) - assert_equal('name2', message1.name) - assert_equal(2, message1.repeate_message.size) - assert_equal('name11', message1.repeate_message[0].name) - assert_equal('name21', message1.repeate_message[1].name) - assert_equal('name22', message1.require_message.name) - assert_equal(2, message1.require_message.repeate_message.size) - assert_equal('name121', message1.require_message.repeate_message[0].name) - assert_equal('name221', message1.require_message.repeate_message[1].name) - end -end diff --git a/test/test_optional_field.rb b/test/test_optional_field.rb deleted file mode 100644 index 5b04bb11..00000000 --- a/test/test_optional_field.rb +++ /dev/null @@ -1,103 +0,0 @@ -require 'test/unit' -require 'test/proto/optional_field.pb' - -class OptionalFieldTest < Test::Unit::TestCase - def test_accessor - message = Test::OptionalField::Message.new - - # default values - assert(!message.has_field?(:number)) - assert_equal(20, message.number) - - assert(!message.has_field?(:text)) - assert_equal('default string', message.text) - - assert(!message.has_field?(:enum)) - assert_equal(2, message.enum) - - assert(!message.has_field?(:signed)) - assert_equal(-100, message.signed) - - # assign values - assert_nothing_raised { message.number = 100 } - assert(message.has_field?(:number)) - assert_equal(100, message.number) - - assert_nothing_raised { message.text = 'abc' } - assert(message.has_field?(:text)) - assert_equal('abc', message.text) - - assert_nothing_raised { message.enum = Test::OptionalField::Message::Enum::A } - assert(message.has_field?(:enum)) - assert_equal(1, message.enum) - - assert_nothing_raised { message.signed = -20 } - assert(message.has_field?(:signed)) - assert_equal(-20, message.signed) - end - - def test_serialize - message1 = Test::OptionalField::Message.new - message2 = Test::OptionalField::Message.new - - # all fields are empty - serialized_string = message1.to_s - assert(serialized_string.empty?) - message2.parse_from_string(serialized_string) - assert_equal(message1.number, message2.number) - assert_equal(message1.text, message2.text) - assert_equal(message1.enum, message2.enum) - assert_equal(message1.signed, message2.signed) - assert(!message2.has_field?(:number)) - assert(!message2.has_field?(:text)) - assert(!message2.has_field?(:enum)) - assert(!message2.has_field?(:signed)) - - # assign the value whith is equal to default value - message1 = Test::OptionalField::Message.new - message1.number = message1.number - message1.text = message1.text - message1.enum = message1.enum - message1.signed = message1.signed - serialized_string = message1.to_s - assert !serialized_string.empty? - - # set some fields - message1 = Test::OptionalField::Message.new - message1.number = 100 - message1.text = 'new text' - serialized_string = message1.to_s - message2.parse_from_string(serialized_string) - assert_equal(message1.number, message2.number) - assert_equal(message1.text, message2.text) - assert_equal(message1.enum, message2.enum) - assert_equal(message1.signed, message2.signed) - assert( message2.has_field?(:number)) - assert( message2.has_field?(:text)) - assert(!message2.has_field?(:enum)) - assert(!message2.has_field?(:signed)) - end - - def test_merge_optional_fields - src1 = Test::OptionalField::Message.new - src2 = Test::OptionalField::Message.new - dst = Test::OptionalField::Message.new - - src1.number = 100 - src1.text = 'old' - src2.text = 'new' - src2.signed = 20 - - serialized_string = src1.to_s + src2.to_s - dst.parse_from_string(serialized_string) - - assert_equal(100, dst.number) - assert_equal('new', dst.text) - assert_equal(20, dst.signed) - assert dst.has_field?(:number) - assert dst.has_field?(:text) - assert !dst.has_field?(:enum) - assert dst.has_field?(:signed) - end - -end diff --git a/test/test_packed_field.rb b/test/test_packed_field.rb deleted file mode 100644 index 1583cd42..00000000 --- a/test/test_packed_field.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'test/unit' -require 'test/proto/packed.pb' - -class PackedFieldTest < Test::Unit::TestCase - - def test_packed_field - values = [1, 1_000, 10_000, 1_000_000, 1_000_000_000] - - # encode - message = Test::PackedField::Message.new - message.a = values - message.b = values - - expected = '' - serialized_string = nil - assert_nothing_raised { serialized_string = message.serialize_to_string } - - value = values.map {|v| Protobuf::Field::VarintField.encode(v) }.join - expected << Protobuf::Field::VarintField.encode((1 << 3) | 2) # tag=1, wire_type=2 (length-delimited) - expected << Protobuf::Field::VarintField.encode(value.size) - expected << value - - value = values.pack('V*') - expected << Protobuf::Field::VarintField.encode((2 << 3) | 2) # tag=2, wire_type=2 (length-delimited) - expected << Protobuf::Field::VarintField.encode(value.size) - expected << value - - assert_equal(expected, serialized_string) - - # decode - message2 = Test::PackedField::Message.new - assert_nothing_raised { message2.parse_from_string(serialized_string) } - - values.each_with_index do |val, n| - assert_equal(val, message.a[n]) - assert_equal(val, message.b[n]) - end - end - -end diff --git a/test/test_parse.rb b/test/test_parse.rb deleted file mode 100644 index 702ddc26..00000000 --- a/test/test_parse.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'test/unit' -require 'test/proto/addressbook.pb' - -class ParseTest < Test::Unit::TestCase - def test_parse - person = Tutorial::Person.new - person.parse_from_file('test/data/data.bin') - assert_equal(1234, person.id) - assert_equal('John Doe', person.name) - assert_equal('jdoe@example.com', person.email) - assert_equal(1, person.phone.size) - assert_equal('555-4321', person.phone[0].number) - assert_equal(Tutorial::Person::PhoneType::HOME, person.phone[0].type) - end -end diff --git a/test/test_repeated_types.rb b/test/test_repeated_types.rb deleted file mode 100644 index 5e197195..00000000 --- a/test/test_repeated_types.rb +++ /dev/null @@ -1,132 +0,0 @@ -require 'test/unit' -require 'test/proto/types.pb' - -class RepeatedTypesTest < Test::Unit::TestCase - def test_serialize - # empty set - types = Test::Types::RepeatedTypes.new - assert_equal('', types.to_s) - - # has 1 member - types = Test::Types::RepeatedTypes.new - types.type1 << 0.01 - types.type2 << 0.1 - types.type3 << 1 - types.type4 << 10 - types.type5 << 100 - types.type6 << 1000 - types.type7 << -1 - types.type8 << -10 - types.type9 << 10000 - types.type10 << 100000 - types.type11 << false - types.type12 << 'hello all types' - image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read} - types.type13 << image_bin - types.type14 << -100 - types.type15 << -1000 - - serialized_string = types.serialize_to_string - - types2 = Test::Types::RepeatedTypes.new - types2.parse_from_string serialized_string - assert_in_delta(0.01, types2.type1[0], 0.00001) - assert_in_delta(0.1, types2.type2[0], 0.00001) - assert_equal(1, types2.type3[0]) - assert_equal(10, types2.type4[0]) - assert_equal(100, types2.type5[0]) - assert_equal(1000, types2.type6[0]) - assert_equal(-1, types2.type7[0]) - assert_equal(-10, types2.type8[0]) - assert_equal(10000, types2.type9[0]) - assert_equal(100000, types2.type10[0]) - assert(!types2.type11[0]) - assert_equal('hello all types', types2.type12[0]) - assert_equal(10938, types2.type13[0].size) - assert_equal(image_bin, types2.type13[0]) - assert_equal(-100, types2.type14[0]) - assert_equal(-1000, types2.type15[0]) - - # has 2 members - types.type1 << 1.0/0 # double (Inf) - types.type2 << -1.0/0 # float (-Inf) - types.type3 << -1 # int32 - types.type4 << -10 # int64 - types.type5 << 100 # uint32 - types.type6 << 1000 # uint64 - types.type7 << -1000 # sint32 - types.type8 << -10000 # sint64 - types.type9 << 10000 # fixed32 - types.type10 << 100000 # fixed64 - types.type11 << true - types.type12 << 'hello all types' - image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read} - types.type13 << image_bin - types.type14 << -2_000_000_000 # sfixed32 - types.type15 << -8_000_000_000_000_000_000 # sfixed64 - - serialized_string = types.serialize_to_string - - types2 = Test::Types::RepeatedTypes.new - types2.parse_from_string serialized_string - assert_in_delta(0.01, types2.type1[0], 0.00001) - assert_in_delta(0.1, types2.type2[0], 0.00001) - assert_equal(1, types2.type3[0]) - assert_equal(10, types2.type4[0]) - assert_equal(100, types2.type5[0]) - assert_equal(1000, types2.type6[0]) - assert_equal(-1, types2.type7[0]) - assert_equal(-10, types2.type8[0]) - assert_equal(10000, types2.type9[0]) - assert_equal(100000, types2.type10[0]) - assert(!types2.type11[0]) - assert_equal('hello all types', types2.type12[0]) - assert_equal(10938, types2.type13[0].size) - assert_equal(image_bin, types2.type13[0]) - assert_equal(-100, types2.type14[0]) - assert_equal(-1000, types2.type15[0]) - - assert_equal(1.0/0.0, types2.type1[1]) - assert_equal(-1.0/0.0, types2.type2[1]) - assert_equal(-1, types2.type3[1]) - assert_equal(-10, types2.type4[1]) - assert_equal(100, types2.type5[1]) - assert_equal(1000, types2.type6[1]) - assert_equal(-1000, types2.type7[1]) - assert_equal(-10000, types2.type8[1]) - assert_equal(10000, types2.type9[1]) - assert_equal(100000, types2.type10[1]) - assert types2.type11[1] - assert_equal('hello all types', types2.type12[1]) - assert_equal(10938, types2.type13[1].size) - assert_equal(image_bin, types2.type13[1]) - assert_equal(-2_000_000_000, types2.type14[1]) - assert_equal(-8_000_000_000_000_000_000, types2.type15[1]) - end - - def test_repeated_types - types = Test::Types::RepeatedTypes.new - # types.type3 is a repeated int32 field. - assert(types.type3.empty?) - types.type3 << 0 - types.type3 << 1 - assert_equal(0, types.type3[0]) - assert_equal(1, types.type3[1]) - assert_equal(2, types.type3.size) - - assert_raise(TypeError) do - types.type3 << 'string' - end - - types.type3[1] = 10 - assert_equal(0, types.type3[0]) - assert_equal(10, types.type3[1]) - assert_equal(2, types.type3.size) - - types.type3.replace([10, 20, 30]) - assert_equal(10, types.type3[0]) - assert_equal(20, types.type3[1]) - assert_equal(30, types.type3[2]) - assert_equal(3, types.type3.size) - end -end diff --git a/test/test_serialize.rb b/test/test_serialize.rb deleted file mode 100644 index 407d3ef7..00000000 --- a/test/test_serialize.rb +++ /dev/null @@ -1,61 +0,0 @@ -# encoding: utf-8 -require 'test/unit' -require 'test/proto/addressbook.pb' - -class SerializeTest < Test::Unit::TestCase - def test_serialize - # serialize to string - person = Tutorial::Person.new - person.id = 1234 - person.name = 'John Doe' - person.email = 'jdoe@example.com' - phone = Tutorial::Person::PhoneNumber.new - phone.number = '555-4321' - phone.type = Tutorial::Person::PhoneType::HOME - person.phone << phone - serialized_string = person.serialize_to_string - - # parse the serialized string - person2 = Tutorial::Person.new - person2.parse_from_string(serialized_string) - assert_equal(1234, person2.id) - assert_equal('John Doe', person2.name) - assert_equal('jdoe@example.com', person2.email) - assert_equal(1, person2.phone.size) - assert_equal('555-4321', person2.phone[0].number) - assert_equal(Tutorial::Person::PhoneType::HOME, person2.phone[0].type) - end - - def test_serialize_utf8string - # serialize to string - person = Tutorial::Person.new - person.id = 1234 - person.name = '山田 太郎' # kanji characters - serialized_string = person.serialize_to_string - - # parse the serialized string - person2 = Tutorial::Person.new - person2.parse_from_string(serialized_string) - assert_equal(1234, person2.id) - assert_equal('山田 太郎', person2.name) - end - - def test_unknown_field - person = Tutorial::Person.new - person.id = 1234 - person.name = 'a b c' - serialized_string = person.serialize_to_string - - # add invalid field - tag = 1000 - wire_type = Protobuf::WireType::VARINT - serialized_string << Protobuf::Field::VarintField.encode((tag << 3) | wire_type) - serialized_string << Protobuf::Field::VarintField.encode(100) - - # decode - person2 = Tutorial::Person.new - person2.parse_from_string(serialized_string) - - assert_equal(person, person2) - end -end diff --git a/test/test_standard_message.rb b/test/test_standard_message.rb deleted file mode 100644 index 44e97ce6..00000000 --- a/test/test_standard_message.rb +++ /dev/null @@ -1,96 +0,0 @@ -require 'test/unit' -require 'protobuf/message/message' -require 'protobuf/enum' -require 'test/proto/addressbook.pb' - -class StandardMessageTest < Test::Unit::TestCase - def test_initialized - person = Tutorial::Person.new - assert(!person.initialized?) - assert_raise(Protobuf::NotInitializedError) { person.to_s } - person.name = 'name' - assert(!person.initialized?) - person.id = 12 - assert( person.initialized?) - - # repeated field - person.phone << Tutorial::Person::PhoneNumber.new - assert(!person.initialized?) - person.phone.last.number = '123-456' - assert( person.initialized?) - end - - def test_clear - person = Tutorial::Person.new - person.name = 'name' - person.id = 1234 - person.email = 'abc@cde.fgh' - person.phone << Tutorial::Person::PhoneNumber.new - person.clear! - - assert_nil(person.name) - assert_nil(person.id) - assert_equal('', person.email) - assert_equal(0, person.phone.size) - - assert(!person.has_field?(:name)) - assert(!person.has_field?(:id)) - assert(!person.has_field?(:email)) - end - - def test_dup - person = Tutorial::Person.new - person.name = 'name' - person.id = 1234 - person.email = 'abc@cde.fgh' - person.phone << Tutorial::Person::PhoneNumber.new - person.phone.last.number = '123-456' - person.phone.last.type = Tutorial::Person::PhoneType::MOBILE - person.phone << Tutorial::Person::PhoneNumber.new - person.phone.last.number = '456-123' - person.phone.last.type = Tutorial::Person::PhoneType::WORK - - person2 = person.dup - assert(person == person2) - assert(!person.eql?(person2)) - assert_equal(person.name, person2.name) - assert_equal(person.id, person2.id) - assert_equal(person.email, person2.email) - assert_equal(person.phone.size, person2.phone.size) - assert(person.phone.first == person2.phone.first) - assert(!person.phone.first.eql?(person2.phone.first)) - assert_equal(person.phone.first.number, person2.phone.first.number) - assert_equal(person.phone.first.type, person2.phone.first.type) - assert(person.phone.last == person2.phone.last) - assert(!person.phone.last.eql?(person2.phone.last)) - assert_equal(person.phone.last.number, person2.phone.last.number) - assert_equal(person.phone.last.type, person2.phone.last.type) - end - - def test_inspect - person = Tutorial::Person.new - person.name = 'name' - person.id = 1234 - person.email = 'abc@cde.fgh' - person.phone << Tutorial::Person::PhoneNumber.new - person.phone.last.number = '123-456' - person.phone.last.type = Tutorial::Person::PhoneType::MOBILE - person.phone << Tutorial::Person::PhoneNumber.new - person.phone.last.number = '456-123' - person.phone.last.type = Tutorial::Person::PhoneType::WORK - - assert_equal <<-EOS, person.inspect -name: "name" -id: 1234 -email: "abc@cde.fgh" -phone { - number: "123-456" - type: MOBILE -} -phone { - number: "456-123" - type: WORK -} - EOS - end -end diff --git a/test/test_types.rb b/test/test_types.rb deleted file mode 100644 index cbd22d18..00000000 --- a/test/test_types.rb +++ /dev/null @@ -1,226 +0,0 @@ -require 'test/unit' -require 'test/proto/types.pb' - -class TypesTest < Test::Unit::TestCase - def test_serialize - types = Test::Types::TestTypes.new - types.type1 = 0.01 - types.type2 = 0.1 - types.type3 = 1 - types.type4 = 10 - types.type5 = 100 - types.type6 = 1000 - types.type7 = -1 - types.type8 = -10 - types.type9 = 10000 - types.type10 = 100000 - types.type11 = false - types.type12 = 'hello all types' - image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read} - types.type13 = image_bin - types.type14 = -100 - types.type15 = -1000 - - serialized_string = types.serialize_to_string - - types2 = Test::Types::TestTypes.new - types2.parse_from_string(serialized_string) - assert_in_delta(0.01, types2.type1, 0.00001) - assert_in_delta(0.1, types2.type2, 0.00001) - assert_equal(1, types2.type3) - assert_equal(10, types2.type4) - assert_equal(100, types2.type5) - assert_equal(1000, types2.type6) - assert_equal(-1, types2.type7) - assert_equal(-10, types2.type8) - assert_equal(10000, types2.type9) - assert_equal(100000, types2.type10) - assert(!types2.type11) - assert_equal('hello all types', types2.type12) - assert_equal(10938, types2.type13.size) - assert_equal(image_bin, types2.type13) - assert_equal(-100, types2.type14) - assert_equal(-1000, types2.type15) - end - - def test_serialize2 - types = Test::Types::TestTypes.new - types.type1 = 1.0/0 # double (Inf) - types.type2 = -1.0/0 # float (-Inf) - types.type3 = -1 # int32 - types.type4 = -10 # int64 - types.type5 = 100 # uint32 - types.type6 = 1000 # uint64 - types.type7 = -1000 # sint32 - types.type8 = -10000 # sint64 - types.type9 = 10000 # fixed32 - types.type10 = 100000 # fixed64 - types.type11 = true - types.type12 = 'hello all types' - image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read} - types.type13 = image_bin - types.type14 = -2_000_000_000 # sfixed32 - types.type15 = -8_000_000_000_000_000_000 # sfixed64 - - serialized_string = types.serialize_to_string - - types2 = Test::Types::TestTypes.new - types2.parse_from_string(serialized_string) - assert_equal(1.0/0.0, types2.type1) - assert_equal(-1.0/0.0, types2.type2) - assert_equal(-1, types2.type3) - assert_equal(-10, types2.type4) - assert_equal(100, types2.type5) - assert_equal(1000, types2.type6) - assert_equal(-1000, types2.type7) - assert_equal(-10000, types2.type8) - assert_equal(10000, types2.type9) - assert_equal(100000, types2.type10) - assert(types2.type11) - assert_equal('hello all types', types2.type12) - assert_equal(10938, types2.type13.size) - assert_equal(image_bin, types2.type13) - assert_equal(-2_000_000_000, types2.type14) - assert_equal(-8_000_000_000_000_000_000, types2.type15) - end - - def test_parse - types = Test::Types::TestTypes.new - types.parse_from_file('test/data/types.bin') - assert_in_delta(0.01, types.type1, 0.00001) - assert_in_delta(0.1, types.type2, 0.00001) - assert_equal(1, types.type3) - assert_equal(10, types.type4) - assert_equal(100, types.type5) - assert_equal(1000, types.type6) - assert_equal(-1, types.type7) - assert_equal(-10, types.type8) - assert_equal(10000, types.type9) - assert_equal(100000, types.type10) - assert_equal(false, !!types.type11) - assert_equal('hello all types', types.type12) - assert_equal(File.open('test/data/unk.png', 'r+b'){|f| f.read}, types.type13) - end - - def test_double - # double fixed 64-bit - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type1 = 1 } - assert_nothing_raised { types.type1 = 1.0 } - assert_raise(TypeError) { types.type1 = '' } - assert_nothing_raised { types.type1 = Protobuf::Field::DoubleField.max } - assert_nothing_raised { types.type1 = Protobuf::Field::DoubleField.min } - end - - def test_float - # float fixed 32-bit - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type2 = 1 } - assert_nothing_raised { types.type2 = 1.0 } - assert_raise(TypeError) { types.type2 = '' } - assert_nothing_raised { types.type2 = Protobuf::Field::FloatField.max } - assert_nothing_raised { types.type2 = Protobuf::Field::FloatField.min } - end - - def test_int32 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type3 = 1 } - assert_nothing_raised { types.type3 = -1 } - assert_raise(TypeError) { types.type3 = 1.0 } - assert_raise(TypeError) { types.type3 = '' } - end - - def test_int64 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type4 = 1 } - assert_nothing_raised { types.type4 = -1 } - assert_raise(TypeError) { types.type4 = 1.0 } - assert_raise(TypeError) { types.type4 = '' } - end - - def test_uint32 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type5 = 1 } - assert_raise(RangeError) { types.type5 = -1 } - assert_raise(TypeError) { types.type5 = 1.0 } - assert_raise(TypeError) { types.type5 = '' } - end - - def test_uint64 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type6 = 1 } - assert_raise(RangeError) { types.type6 = -1 } - assert_raise(TypeError) { types.type6 = 1.0 } - assert_raise(TypeError) { types.type6 = '' } - end - - def test_sint32 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type7 = 1 } - assert_nothing_raised { types.type7 = -1 } - assert_raise(TypeError) { types.type7 = 1.0 } - assert_raise(TypeError) { types.type7 = '' } - end - - def test_sint64 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type8 = 1 } - assert_nothing_raised { types.type8 = -1 } - assert_raise(TypeError) { types.type8 = 1.0 } - assert_raise(TypeError) { types.type8 = '' } - end - - def test_fixed32 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type9 = 1 } - assert_raise(TypeError) { types.type9 = 1.0 } - assert_raise(TypeError) { types.type9 = '' } - assert_nothing_raised { types.type9 = Protobuf::Field::Fixed32Field.max } - assert_raise(RangeError) { types.type9 = Protobuf::Field::Fixed32Field.max + 1 } - assert_nothing_raised { types.type9 = Protobuf::Field::Fixed32Field.min } - assert_raise(RangeError) { types.type9 = Protobuf::Field::Fixed32Field.min - 1 } - end - - def test_fixed64 - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type10 = 1 } - assert_raise(TypeError) { types.type10 = 1.0 } - assert_raise(TypeError) { types.type10 = '' } - assert_nothing_raised { types.type10 = Protobuf::Field::Fixed64Field.max } - assert_raise(RangeError) { types.type10 = Protobuf::Field::Fixed64Field.max + 1 } - assert_nothing_raised { types.type10 = Protobuf::Field::Fixed64Field.min } - assert_raise(RangeError) { types.type10 = Protobuf::Field::Fixed64Field.min - 1 } - end - - def test_bool - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type11 = true } - assert_nothing_raised { types.type11 = false } - assert_nothing_raised { types.type11 = nil } - assert_raise(TypeError) { types.type11 = 0 } - assert_raise(TypeError) { types.type11 = '' } - end - - def test_string - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type12 = '' } - assert_nothing_raised { types.type12 = 'hello' } - assert_nothing_raised { types.type12 = nil } - assert_raise(TypeError) { types.type12 = 0 } - assert_raise(TypeError) { types.type12 = true } - end - - def test_bytes - types = Test::Types::TestTypes.new - assert_nothing_raised { types.type13 = '' } - assert_nothing_raised { types.type13 = 'hello' } - assert_nothing_raised { types.type13 = nil } - assert_raise(TypeError) { types.type13 = 0 } - assert_raise(TypeError) { types.type13 = true } - assert_raise(TypeError) { types.type13 = [] } - end - - def test_varint_getbytes - assert_equal("\xac\x02", Protobuf::Field::VarintField.encode(300)) - end -end From 01fee740bd022d54b7d75e982b2c0798f094e4e5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 23:17:41 -0600 Subject: [PATCH 0487/1191] Fix bug where ruby < 2.0.0 Range#size is not defined --- lib/protobuf/generators/base.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 49e1b9f1..4981488f 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -15,11 +15,16 @@ def self.validate_tags(type_name, tags) end unless ENV.key?('PB_NO_TAG_WARNINGS') - range = ((tags.min)..(tags.max)) + range = (tags.min)..(tags.max) + if range.respond_to?(:size) + expected_size = range.size + else + expected_size = range.to_a.size + end - if tags.size < range.size + if tags.size < expected_size ::Protobuf::CodeGenerator.print_tag_warning_suppress - ::Protobuf::CodeGenerator.warn("#{type_name} object should have #{range.size} tags (#{range.begin}..#{range.end}), but found #{tags.size} tags.") + ::Protobuf::CodeGenerator.warn("#{type_name} object should have #{expected_size} tags (#{range.begin}..#{range.end}), but found #{tags.size} tags.") end end end From 5b8fc3c492aa96e6622b2b523553c0aebf3d9af2 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 23:17:54 -0600 Subject: [PATCH 0488/1191] Set PROTOC_VERSION to 2.5.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b6650147..2c001a20 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf VERSION = '2.7.11' - PROTOC_VERSION = '2.4.1' + PROTOC_VERSION = '2.5.0' end From f24e60f68b7763d98f7f2d2784d7931512f94380 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 23:18:30 -0600 Subject: [PATCH 0489/1191] Compile with protoc --plugin in spec_helper --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 981536e6..7fea70fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,7 +33,7 @@ unless ENV['NO_COMPILE_TEST_PROTOS'] $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' proto_path = File.expand_path("../support/", __FILE__) - cmd = %Q{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} } + cmd = %Q{ protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')} } puts cmd %x{#{cmd}} end From 2ab58cd53ab0bfdcfe18099225927ba4961310c7 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 20 Aug 2013 23:20:21 -0600 Subject: [PATCH 0490/1191] Update gemspec, fixes activesupport < 1.9.3 dependency * Add devin-c as gem author * Remove java platform setting * Remove gem extensions setting * Constrain activesupport to < 4.0 --- protobuf.gemspec | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index d40fbefa..46ad1e76 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -1,44 +1,34 @@ # encoding: UTF-8 -$:.push File.expand_path("./lib", File.dirname(__FILE__)) +$:.push ::File.expand_path("../lib", __FILE__) require "protobuf/version" -Gem::Specification.new do |s| +::Gem::Specification.new do |s| s.name = 'protobuf' - s.version = Protobuf::VERSION - s.date = Time.now.strftime('%Y-%m-%d') + s.version = ::Protobuf::VERSION + s.date = ::Time.now.strftime('%Y-%m-%d') - s.authors = ['BJ Neilsen', 'Brandon Dewitt'] - s.email = ["bj.neilsen+protobuf@gmail.com", "brandonsdewitt+protobuf@gmail.com"] - s.homepage = "https://github.com/localshred/protobuf" - s.summary = "Google Protocol Buffers v#{Protobuf::PROTOC_VERSION} Serialization and RPC implementation for Ruby." + s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen'] + s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com'] + s.homepage = 'https://github.com/localshred/protobuf' + s.summary = "Google Protocol Buffers serialization and RPC implementation for Ruby." s.description = s.summary s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ["lib"] - unless ENV['WITHOUT_PROTO_COMPILER'] - if defined?(JRUBY_VERSION) - s.platform = 'java' - else - s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb') - end - end - - s.add_dependency 'activesupport' - s.add_dependency 'ffi' + s.add_dependency 'activesupport', '< 4.0' s.add_dependency 'multi_json' s.add_dependency 'thor' s.add_development_dependency 'eventmachine' s.add_development_dependency 'ffi-rzmq' - # s.add_development_dependency 'perftools.rb' - s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' s.add_development_dependency 'rake-compiler' s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' + # s.add_development_dependency 'perftools.rb' end From 0bdd7079da13425c6582d5ea27404644b778c9ea Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Aug 2013 09:59:17 -0600 Subject: [PATCH 0491/1191] Cleanup spec_helper --- spec/spec_helper.rb | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7fea70fe..fb2e2cd7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,17 +6,17 @@ Bundler.setup :default, :development, :test require 'pry' -$: << ::File.expand_path('..', File.dirname(__FILE__)) -$: << ::File.expand_path('../spec/support', File.dirname(__FILE__)) +$: << ::File.expand_path('../..', __FILE__) +$: << ::File.expand_path('../support', __FILE__) require 'protobuf' -require ::File.dirname(__FILE__) + '/support/all' +require ::File.expand_path('../support/all', __FILE__) $: << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) require 'google/protobuf/compiler/plugin.pb' # Including a way to turn on debug logger for spec runs -if ENV["DEBUG"] +if ENV.key?('DEBUG') debug_log = ::File.expand_path('../debug_specs.log', File.dirname(__FILE__) ) ::Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) end @@ -29,21 +29,18 @@ c.mock_with :rspec c.before(:suite) do - unless defined?(JRUBY_VERSION) - unless ENV['NO_COMPILE_TEST_PROTOS'] - $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - proto_path = File.expand_path("../support/", __FILE__) - cmd = %Q{ protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')} } - puts cmd - %x{#{cmd}} - end + unless ENV['NO_COMPILE_TEST_PROTOS'] + $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' + proto_path = File.expand_path("../support/", __FILE__) + cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + puts cmd + %x{#{cmd}} end end end -Dir[File.expand_path('../support/**/*.pb.rb', __FILE__)].each do |proto_file| - require proto_file -end +support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) +Dir[support_proto_glob].each { |proto_file| require proto_file } class ::Protobuf::Rpc::Client def ==(other) From 0accd6048a10241b1ffe7c0d32ee3382643e0862 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Aug 2013 10:19:24 -0600 Subject: [PATCH 0492/1191] Add WTFPL license --- LICENSE.txt | 14 ++++++++++++++ protobuf.gemspec | 1 + 2 files changed, 15 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..dd94252a --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + diff --git a/protobuf.gemspec b/protobuf.gemspec index 46ad1e76..6cd7bdc0 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -6,6 +6,7 @@ require "protobuf/version" s.name = 'protobuf' s.version = ::Protobuf::VERSION s.date = ::Time.now.strftime('%Y-%m-%d') + s.license = 'WTFPL' s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen'] s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com'] From 505fd156cda8ec0a331eeb18c325238da96a2498 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Aug 2013 10:22:29 -0600 Subject: [PATCH 0493/1191] Fix encoding in google_unittest.pb.rb --- spec/data/data.bin | 3 + spec/data/types.bin | Bin 0 -> 10999 bytes spec/support/test/google_unittest.pb.rb | 173 +++++++++--------- .../support/test/google_unittest_import.pb.rb | 12 +- .../test/google_unittest_import_public.pb.rb | 2 +- 5 files changed, 101 insertions(+), 89 deletions(-) create mode 100644 spec/data/data.bin create mode 100644 spec/data/types.bin diff --git a/spec/data/data.bin b/spec/data/data.bin new file mode 100644 index 00000000..42632981 --- /dev/null +++ b/spec/data/data.bin @@ -0,0 +1,3 @@ + +John Doe� jdoe@example.com" +555-4321 \ No newline at end of file diff --git a/spec/data/types.bin b/spec/data/types.bin new file mode 100644 index 0000000000000000000000000000000000000000..07e0f18d29188fb0fa5569b53b5226db90c8ec09 GIT binary patch literal 10999 zcmW++1w7pU8#gt^@Wa$h%!%oqI5~B?J5O`EyG?UU*EFYw>1Mjwbazfo8~^YA?)7yq z&fVwpeLm0ge%|l*1Jj4FN_xXPROHRr=%^6M3#wNPX6*Yf`Cf<;DB#f}A*p-~e}VMx z3yN!H4ud&RnZRIFu3nDjE;cP1k;;nFuV0b90$zR%k&#dZp3VMU80f%v$IWDQ;0e`I zOhF6@sU{xl(F6_n867GoErIm>@A0+0BnkKprlX9G3lb6*-oNWbB~7~<5)$J(h=iEB z=i*7W4orV8eJ{YHT<>8R>QvGc`9)&ryZKNGjH%(xNL)o6OJDl;sUakYV2C^g+2wSX zaUhi!iF^TvsK}o-`I46*5Hd({Nw(8+WcGaId%0ROxmiV7q8rKOXtNWaUqYA475Ky| z`B2r`pu14pj6Q_VgwV53$JKLo;#0|OVW7gCN%5sZ9%rCp%U3X(u9vF_GUXGP?O(_W>J9`wB--{hAG#SRkuczv`sjC7Z z6%5+sn(C5$uzKb8@|^yGC9B1{H%5N6!EB>FMs!A0qGr=IprqV54ncNF-gKR(8xPu? z`*EyWGN!UpTwjwH@P7-_BV$IoGWW@^p@!-EU+ICq`H-ibq`W6Fk_UG%1QMQz(ZQ*? zIi#r_D*U4Z2PesE&he!3&YrafE#z2}=r~B}-awp}##&g!F{D`kxcr?XPH*E2hO-g2 z*RrMg+S^5FtE*vj1sdOgwkUC-+gRnROb~pFy7Ybh(3~5#_mD{qzW-2^wZAg2f4 zT$j6LWL4x|211M*wC1NwtmVgbvL5ZfKg$urDJ**I>GI5@V=f1Cl<<)q(I7;MuIp#C zA<(5HJM%D;$o+0S#WmG$P(Ib*0N3biMVGsP+>NA0VYBZJB)!^pA{ClUFL5ch(=Btl z3y-jIu{r!*zRbI#su^~}xC(T6K$5H(GzXWhn!+EM3M)=y^ZCceKxts%L7(Rf92zZj z8Rj3_wnQ2lMfLT`G}3Y3JWdU>6zNafZzxteJG*Y{O&UZNhpIlcmigqp8#9&CBupqW z-+O42xWj#ykZ7M8DnSjW;p7~cZ}z`eG_c&ap>$CbWAyXSYRNu0ILK$zrOqgxnw}Q- z^AoD9tW;N5|7N$uyXv*~?*9J%cKgP%*=t82sL^Jj!9~z5ThGw}*SO3BT6;tV!MN40 z$oTw91```jY-X`3pGCHQpI(lg_3&l=j5`Xlb6&Lq{yRFO-{G4Mhr)4;=%tDh(K#qLU6$?xh1>2_S; z&R(T~gx%~i@)9I>TP6DU3)c7E-f+UmlxxkFmKHw8btGW#^78Tt6MLtg6eTkdDm>9S zw@|!Ngsg$VJGRb8PC@tM^~HKy{buK|oE!>tbaayA1JghKcuz{+)^F#BOxJwFhiA#S z4Se>$mg0__CP=723X3aRJVxRq)QMx>?o0$IfOY+kv6jM`EnZ(eM z9dQgX;avLE5g<3d=~i-o{J7;Rpk>f&QC9;*lI-nUugCL&X8*qesjLQ@yJMMuuCFBg%S%4DvQ2XaX=ta!qhMMsG9pyp0cSy^k zfMLL2x2MO6=Pddh&tL?Canynf=W|GSIJ$tKptX%n&*_aRXSz(0>VC`k@0C`5*L^(R zOgsMl#840E6+&n$`eVjz6# zba`mq!f%ZJ>0G)b%+wJL^qHfp&6|g*F#&p|oWh$%t+9=F5m6>2M{!uP1Z`DJa`;jCNI>4yXfwOIx=zl|4=x{*ySTXg zfT}#^la&>IqWD&d+ZzfIPng(==+CEu{QUK6YIauBkW{XFJ|fW0JkhC4fGcwh75N3X z0!``&l<<{I#OGa0AxBXVDl!UtAT+kEP*GFyDI_9C&PG15P}0;MtS@R7GvS|d6@_Gm zse@n2X@!ubODgK@%&oJW0HSv83Et7Db*_IbbEf|`@(Dj!nL&az_mhelVHuyW4kMh= z^DE-0yE0)qmNfXMe%9O0=6=spmgxml_4fDS#2oahxny*3kUFzQkCh!GbD4-@q1{eLlBj+=Cr{@#h{ zaO=ajM+@~X#IdolI~q=G&2z&#UO3dK;uy}&#gGYhC1?Pttv&VJ0ePD)3@-o z2%a}flkU7Ad8&M2_7F0qhiefQ0d4T{wo1tnF*HBBM{=uoYr9^w-I?!&)>JGRGS{{Kzi2n@Zm19gsHa?oI{5dyA5Z#xSp1uJTXqKQy+|kFX%Wfsb1i9_`=P^HZ zSb5;fb+gh76jhz(Fy^h)fqkJlIo|A@yS?1K_3n`G4GsB6_lUuJL+8$_8U#YSQj?ho zE8HYOu_RLBy+nZuw?eOda(q5qxv;?mN{heUb0-m9azgVR%bqUbz^S5f&1V-_#Y9{vJ3 z`_1iWmJ{xc8ZOUPm%#Swyu~>lNO^Fr*$@qN)`|g6$aL%2f`XuK8k{{>DUxF zK5{E@CY!msej%V&RMydf*x9iF7_s$Pnl_ebo)lE)REXei;W@r-2W4iz032B&y>yw(?veO7Jy9(WLsER0LW1L z+X*#9Y&=Iu4op!}Ru);3FL!Kp&rm^af&AbY>XkTvE7LsSg*AO^6| z61ad>0&Y(eWIv6euDR(r53&5^Y~7HbAAEP`1$^-A8&jYa1Banmo(%L6Mn*=AF!3X@ zI1>_JF#y_GSXkQb56jIRvlJ~Cib438*u7MlWBAzUm|^1kEs7dnUuk@BZsnc%Z;|}1 zs%#R_aLw`FD*T7p4?r166*IV-s+O5%gcHcXqkAExGHbGvlascKVWwMO;T*4B(w5fN z^qd?zqUcInZK7y2NtH>rY@iy5J~N_*ngXulKz&uWsQ7y^i+h7k5WQ~kkz2&2T+w|rKMl<@`6s58oBuR zJf-o;1A8~V78HaONXK7fpZdNmnHk!O7a9N9asC>}ZA$-J>Tcr%@w{)l2>_7;a=vNh zHz!_Eu3U(GpeK0zV5X$mdFR!+Cvv%w^h%;+A~xugR3b0iLDMI05t^i0O&v2igi9W_8s@Xs+}*kA^B7LjLPa7I}dBm!fUtvAAywV zwy2{X;Y2Fj&9afW&lk2Np0X2Jm;t=oeB^Z5 zim6)ZRY%&)M9vG$-RV?Zy_Z(jT>hQJt#dJjM7*x!vIG5P6@9eKf!ge1&vzy*B9C8S zj01C>PmIz}$1>?%no;9&i2SOmLEe854K!j;a9q`qx|Y`EPc@~f`S}P00)u+cqAs-8 z1PDw^m1*4qa6A7}3}DQYD=P}zWGo>TyqO1whtP=}p(g#R3+*tx?OJ|lBp(1~07nwe zl~y4HQ{ejC{4N5L1)xugxlaj74$JF*9EAH1d1?k`f~pt7O<-+@i+pV5+zixdxfvzT z_jq~D?1BOwXAT|b4)g6kH=GuOs_&{8UImE;0{K11+Ed-T!yCJZd1qr>@^wN77Q6-!KC6S&fHvAO(g(aS3bWlxWff7my!)f@WLZ|NdT0J?ov z{d`~jcx)-MHJr@E5ETr90BnpL=Ou8DJDF>bbVm2nsQ~Yj()eY*XW+#GN+2Xn(ixy_ z6-(6C)}~69t>nD+@61JciSre~_i77-i$leR0+_q%B6 z$4@r1U0YX^)6>pMjSa4sOfN=uob@~XvpfGTb?)4rZ~fSE0)&>Gon6`(05}$D85x^D z%hdky{g11jAr5{=dfyux*bJOXY! z+HO{TtTOs*Ob2ck=Q^Y`G&C0Ejt&ks#y+lXA1~BBZqti&?>L{YociB1v}>P_MhM0f zY?A{Wx_0516UPZs)Usj^^!jGsJ5G2RAyx?F;sI+vBj$ThY|z_QaXguxEIGZ;d{sNWc^LwCxgy zt^E%^pgq!s7@ebtS$EClO+krHXy*|fP6)jIYp3Pj9CLO{dL680nOW%oR(pPTOtc+U7}Qn$bd5QcZ} z-fcTKJNp$Bde3@OX?Ez!wpZ)_q8-|C?(>1us%wbB(Kw4t3wE7QBva5@4Azel9DkMl z$aexVUQ5WyLysd7#33X!*42d+CLRRDsljeZQ_-v9inMNFbUa(I41s{!+uLiPdkNX9 zr|fY4ay@94>-TeaPYDad%aH8XGaoQhNhpd{;2nNTWd7;}hMDAgrK74E!Pf*fM}QOo zG82$vw)lBkvLJjD3k!4&4Qp%bW+oCj`YND502qKD`2&GY>2**)hdHS#$SESC1dxO& z8A6B3FhnKMsJj>Z=9?4zzWv32eY9oFwXfflX%lE)2}8aZRb%j3t!hS>On0xZQ=N7^ zu>Sq~*Q{qP=X97!JPDSZw+%*Q>JITAyAgh`f;A%4rVsZIAS6@X(x)* zUe)10DS-@AVa3J8d@j4#D=RB$FnpF)OF_%H9kcfJ%lDIb`3o9O81njANf2jZXM z3+Xx(3v2yV^tu>71)};Ge}vbD{KgsFETk>4_77q;TKG|JwYct-`Z24oA>U zH7t$P4V}nivz{F!oA^In=5mRMOaSC^p~m#3d+WQTAy*%9b4;B?l{aYRzoM2-iUDHA z!662wFye`XqIrsA0F)CGJp|zIi1PB0-%d{BeYF#*{wbO&tf@3)vG~z%j(9IGFR@?0 z{>OP)^_#k2j^P>Mj5)%$Bug!1?0V**HRtt(t%t}u!4lw4Hw*tgEd@Nj=4urGS+Du+ znQ6)MXW;ls_TUbxG#ZvIx)j$oB+)V|NNPhg2Do*VcWSX4n95^KJtDu&Heqwo|?JNo+{$D zrlV~ICe;<5rSd`ijRg{7k$uZu%`^$_UgZhy8s(_64X+%*mZWidvNKHq<)5@TOPe3; zD8wFKWIG7tZf@)OSNZex%I_KOebqsm|&L8er34 z{|Z z^PCSZ6AD1j<0F`WfFLF|mII*FR@4A#2X z2(vCP&hL+_Q!P$lBRPwN;Qd`EH zTwew4ws`%45S7lL+olGNV=Eu0L><}t)8FAnv5wNL2eE#8b35}IbdHvBNXa~z=KLPU#+{mIeRIH&Wu+ee>|LxK}7sbc25 z01l^C=0RJj$hR3bU<0Aba1Pc6gVYHjI}4V%Tk|!h$1APGbqo6A-*+$XYNuF)c5KlS znPxa_Y1sgj8ZxUTxBSw^-OHYqn``Ooo7K@F?CtHne|k!jt&mrWED2ZPL2Dh6A0xtD z@|e504We75EbITxNzC*4yVJYY>Ez{rj-xUl*Rw~Rt_oCE9|x590-zCAd|^X{2@`J{ zN78QasO?)b0h=1&L}!2?{DSFHls|KFQw1%c}Flop)k$jZApi6ow0zldmwP(cQ3?=fw~`CMvRrZ_nIP$~R65 zog*Q@+0)P%Der;Se8~=X6);#m=>|+bR{_9i&~NjEhuxuZ*9DK|{gGWJe7Cq3|4-Pk9ul;>5B?kQ}*z@vq znTnKUa(1?VMoGk=%9J^KG}h)1bGGflo!n|V0%5*|Bbi}6G{TuV2JpGdX*o8yY*CZz z0Vh$b_`taLZt!Ky>v4F5d9#yKa8l>fm#Dzla3Z#hV#4}9OY-}B#&CQY#E%qSHj3OZ z@zpLh6Uj!a!9-V&SX!z~We%vAu&Tp`Yq95_DQRmfE5Jr!LFrErfUBtf+7LN_zza!z5A44`p|IVX(W5`U}RA6@QB)dKr*n_5j0}ETQnz7 z=5WsHou50FR^j7Ahxtug{STvHFm$qsV#S&yVT5c{p-4u;`IgZaFmt{%_An?|46U^5 zVO?6HZ7SySq|5K{HcGr#@i&-rv$3%`yK9qIR7{$X0lSr=wdzSBvj(_Er$>@>-reya z89pw$XDl+|q32pBS9BH|%JL^u>&rveLXc@N8Ma@6pb+O~WX05wsHi9rFWL&Nl-+X8 z-L{k{<`FXQA$-!4b6Z+1CBJ8a?Y46i`eZcVTPXaMiQ7Ogp_y;jMX>N8&+} zC_!BrqWoVE6*&$U7%b13{==r8H8bt1wA`nU+#}JaT`3WyuEC;(6@~{&f&kq+J=dt~ zH}}l^vE&R0yFm17|M=5hBRdy`iN*W=WA&`xN^~{aJj)bZ@h8;-8}~EI8)HXmsiK5b z|Alwk@=Lw6h?Jr!9MV`DlLZ{=leLYsjAR#v^=s{~UWOH+K+wn9OBJiZgo4sH5_6XPZ zj`J0s`0)d^^XaM@nAuQgj~h1xt-O^^(U-}e|86=BB5UBgtD9>i$cl40=^=zGXJA>{ ztE_G37q7;RoY3SxlOw%{;3xI+E4B;vEj>RlhWM%RW!qn$ECEv02SB}-fNTPEEHlj; z=IpLkG_SWCVJv6}Wri;^yhShnIhU>i5K!WBlXo=b^W5d*U85m%!0>fziA>J7MV=h+ zq^K)(EaHRylV`9Qc*JoHJmvT*G{`qs;pcF`ZMWLnjy>r6_m@L2u^#Vp9VY$U(kk_q z0J~441qEe$ubyH=3xUQFe4|m3D zKp=MRV-Sc@v|j9MbjSctn<2enC*}&2>V;-zICJk0tI&-Oyk=OCxY#=G{MkzwU)KHK zljf#8gQjSwsb$v;TVlHXc8DY$xisnW z_^-l->mTs#e(qgPEicQPn$iFg$AvO?YnyUn>w4JJx6&1CA+8y9V>|n%g7x-f?g^2VfldTpw=?!fAF^{59>@8l6qk zHOSZcw564qrKnTtwx0P z0DbHF=^2wVk|ZA|DN0Bh4JcrkfD)_6!$w^A%%}o=g!Hsbbi;PHyRyo%)B8;PQN>*u z30g1(F_6N*z)6F^-zYpC3RPC)A#C19t&pEvQzN?BWO?=&Vl8rSZPyQo9M~E;fDks8 z0nXs>??U|iW6BP}aKo?$_ctpUdYpNUMap>FmuNBKm@!v<5pVa+-`qH{ZDSSUd&LBY z{<6`L^6YqvcjIj!C8fFJ<85La)cu~irBoor$0aJ?xN&L7jMLnHZrBdpj(6#O^fbgu zcw*ZsTpkfX`2GTuQZv(2d_LM00GMY>!Ey zX~>MRkp@ti<^e`6b15?ipznCJ_>u65W;l{$vNDes>1o%_?D^f;{5!H~zq5dk+&FO1 zBsbdUPtqz9=?f~z=Iz~U{jrvqg0;898Qukj9kSc)f(w+ADhWHA-t4c?LRFTV*6iob zv~N zgl_TIRm=o4P6%VNcnWBghzp^r4hfRw^10FA;Gx*syd!O}ySeDuU;)>3k~PY;vbjI@ z@797Q6@o?UgF2^w?4Ke3^TjFRfxbpbf^n1h#;C~0=T;68#bm@ZrAtgCj%uUc@O|5f z51UZOxQ5|)d8gMxh3`zC8Hz)SLlDR{-a8u3fgFtAQBTP@m1ApQ_@=HYEdO1fs(Aq$+=J5nE`k|89qE?FTSq1uPH1 zkE!Lp$tYn`I-71X=3%&jW>$oooZwVV-y|~cAPsCeNl8iZIc=f>-u^8U3%H>*oJE0G z-3wAI%6fsrOjJZJ`1ix8r^agNSkrP2w$F{Vypjfo(3{;Kkpv7;vS12J04R4vohr4V z^*EiC4|B4q%ltf@gxF4V6JI<#i@tJYD-z&*CM6+RA5E|G{WAqjT{g-}-g+IT%N_!w zof)$QbBE`r5=P4%ktgGuaC%}|YR6{6Wmfw0()iU(Q*0cZe`5vlJY_GzcKnABe3g7( z;>KJH>KMt|tQz?h79rVcmZG?*H#;q@m7rdRX%$OL%k+#4C=?o8u2t=P`16Be7GF)1 zOLq6n1bDc7U~&E`;&pT%L%i#!c*pxSJJ}&+O{)K9npRmZR~@R)emh8|XUS|{HXrQo ze{FBi2E1dkw`Av9_fE|QeAzfK&9`((hKi;bCU}t&c=_|o%@rlv!bOGQz`W+bwMD)S zCrtdG{^H{s92~?@Q&WqHkLTjyk)%s1$(tHV#r@^HF89t=IDhNvO~M;fwWfAe?#mU0 z@{Lz{iHc=0aiM(YpBYMowby5qEF&bu=V3U2*e($Sq8$B^U_lNU~^2 zu>aX8oatQ^nPu3hR;Q)gLw@c#Pl@R*==8jqK_F5LYCBoMV8W5don0hnLA@Y6{O+&g zSN7d~SV_xGs{`xCL5>W7P%BhM(x^9X6a=()^jfhROes#PAlfLE9&m%TpQ3&xiy0mS zLsX0XmW?l*A)P)zO_$FKhD)nyj1pnlH%4ZVrH6+j0g`>Hc}C8~7Crvs zIH!nd64>)Y&fR#i9hLSfRDyZPP$nTlE(>h3Z=hE8FZsb@&Mm*ma> zCCjG9))fy~Wz;eY)!f^6FGx&6Em|bl9hG-0uxp}-ejx3IG1l?OvT2~+%$>J_@>JOes^;k9u3IwmY_7c?H^`z1NFN@5lu;N0OA#@dm9BQTe5%jA>)& zysem$AF6ut2~>>Di+99!iFqTpk>FNwzk#=21xQEsITt2+Ij4ii#uR;p-|2j~R>!~$ z9mL1{?D_onKgHafqEd}x=HH1cxEW8m&w-+a)JW)Jnox>usiHVds>;I3$r?OVzzOY zgK02bQcsnE{nOLw&Ggjo&Dly+hjyNRk*9e7;$l^d7m6kQDN=%LZOUVB9loom*?mY1 zJ%#tDBxssz#s*WR@(h|?c~BH1U?9_`B?n^stvK0yBamt*xY z^}if%L}E@3yTg<7m$I@=be`B)&1+%9?#l_S^CFZN$o>Si--YefoIYl6@={VU5TasX zk)or&=R4*Md&BgD9rdm)sCWpr04;$=GWuzE!Qxbi@o`#%CoFr+5_Qb(QfY}s&S$Ib zolbNk7L3DJR~e94Sa1vlbtm$O5mpW!n^*gUmkCl%LCdy@p`k0q>sN%;nes$UPBiko zdh784S-RIO1o#O?u5dSl-DZ?z@I%qR50GEn<-9z7HE5v%LGjNv$Yx#CJ=X6aqswf6 z?JLYiLKelvlbo-NXU2)nTGG!XZNqOKKo3Qa=~+j5jfJsR?H4*q1Q zy>JL(XykEj8o?8j-=2}JNG-SSZY}vH@_U(HR5k5zy#KdLY5cbjxLq*KZ@TIiVVm31 z1T2iLnyiQmA6lzGkkDS8%}DS9YY-tGm}X?b(%|^}BBEhS}rqSi$xL?wPVw#(6~x ziY{vBR@Uz8mj@WsGCwX!@|$eTA^Ek_qYXG(r1LLX5(nEl%7Uy|E!p|gx8o^C9e+Q9 zH)P^Oixhz^=_@MhnQlz6;>PO1(yn6DL!nTW1bL!CvsZ+gFsrW&_$w=bPdic2b~nP2 zUjr5={Pl||Kyw85NsT@>mRJ3%dns|^ns3!lQ-O;La5!!KG=gk*gWTKJm*kYa_U%o~o2m81lDdfbepH)&VBE@J9td>DXEL8a! zl=*Tn@%0c$r-$;}dUeAx>uT~00rXBwz;Cu$yQN1~v0L^7Mw>l>((x6?$GO4!9QO8h z6)*)swxB-W@!=;LGZ+O`Ih{0Y*TZ@xH)8X5nO>uS(>za(|1jX*lO#cQ;nLvw6SB%j-L^97j6FU7Hwl3JRz~6U~6__m>-X&7o(M=?f*#Fgr^)@ZY1<-s;+}Y7Q2z x9wyG_NJyTGSTdudOjDOGuT?O(X1Ul=k?0msWtXlE3V}aHf=DV#REZl0{|~LZcBcRU literal 0 HcmV?d00001 diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index 089ecb4c..8cd4c32c 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,9 +1,12 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # require 'protobuf/message' require 'protobuf/rpc/service' + ## # Imports # @@ -19,7 +22,7 @@ class ForeignEnum < ::Protobuf::Enum define :FOREIGN_BAR, 5 define :FOREIGN_BAZ, 6 end - + class TestSparseEnum < ::Protobuf::Enum define :SPARSE_A, 123 define :SPARSE_B, 62374 @@ -29,8 +32,8 @@ class TestSparseEnum < ::Protobuf::Enum define :SPARSE_F, 0 define :SPARSE_G, 2 end - - + + ## # Message Classes # @@ -40,9 +43,11 @@ class NestedEnum < ::Protobuf::Enum define :BAR, 2 define :BAZ, 3 end - + class NestedMessage < ::Protobuf::Message; end + end + class TestDeprecatedFields < ::Protobuf::Message; end class ForeignMessage < ::Protobuf::Message; end class TestAllExtensions < ::Protobuf::Message; end @@ -62,7 +67,9 @@ class TestEagerMessage < ::Protobuf::Message; end class TestLazyMessage < ::Protobuf::Message; end class TestNestedMessageHasBits < ::Protobuf::Message class NestedMessage < ::Protobuf::Message; end + end + class TestCamelCaseFieldNames < ::Protobuf::Message; end class TestFieldOrderings < ::Protobuf::Message; end class TestExtremeDefaultValues < ::Protobuf::Message; end @@ -80,13 +87,17 @@ class DynamicEnumType < ::Protobuf::Enum define :DYNAMIC_BAR, 2201 define :DYNAMIC_BAZ, 2202 end - + class DynamicMessageType < ::Protobuf::Message; end + end + class TestRepeatedScalarDifferentTagSizes < ::Protobuf::Message; end class TestParsingMerge < ::Protobuf::Message class RepeatedFieldsGenerator < ::Protobuf::Message; end + end + class TestCommentInjectionMessage < ::Protobuf::Message; end class FooRequest < ::Protobuf::Message; end class FooResponse < ::Protobuf::Message; end @@ -94,7 +105,8 @@ class FooClientMessage < ::Protobuf::Message; end class FooServerMessage < ::Protobuf::Message; end class BarRequest < ::Protobuf::Message; end class BarResponse < ::Protobuf::Message; end - + + ## # Message Fields # @@ -102,7 +114,7 @@ class TestAllTypes class NestedMessage optional ::Protobuf::Field::Int32Field, :bb, 1 end - + optional ::Protobuf::Field::Int32Field, :optional_int32, 1 optional ::Protobuf::Field::Int64Field, :optional_int64, 2 optional ::Protobuf::Field::Uint32Field, :optional_uint32, 3 @@ -173,17 +185,16 @@ class NestedMessage optional ::Protobuf::Field::StringField, :default_string_piece, 84, :default => "abc" optional ::Protobuf::Field::StringField, :default_cord, 85, :default => "123" end - + class TestDeprecatedFields optional ::Protobuf::Field::Int32Field, :deprecated_int32, 1, :deprecated => true end - + class ForeignMessage optional ::Protobuf::Field::Int32Field, :c, 1 end - + class TestAllExtensions - # Extension Fields extensions 1...536870912 optional ::Protobuf::Field::Int32Field, :optional_int32_extension, 1, :extension => true @@ -259,7 +270,7 @@ class TestAllExtensions optional ::GoogleUnittest::TestRequired, :single, 1000, :extension => true repeated ::GoogleUnittest::TestRequired, :multi, 1001, :extension => true end - + class TestRequired required ::Protobuf::Field::Int32Field, :a, 1 optional ::Protobuf::Field::Int32Field, :dummy2, 2 @@ -295,86 +306,85 @@ class TestRequired optional ::Protobuf::Field::Int32Field, :dummy32, 32 required ::Protobuf::Field::Int32Field, :c, 33 end - + class TestRequiredForeign optional ::GoogleUnittest::TestRequired, :optional_message, 1 repeated ::GoogleUnittest::TestRequired, :repeated_message, 2 optional ::Protobuf::Field::Int32Field, :dummy, 3 end - + class TestForeignNested optional ::GoogleUnittest::TestAllTypes::NestedMessage, :foreign_nested, 1 end - + class TestReallyLargeTagNumber optional ::Protobuf::Field::Int32Field, :a, 1 optional ::Protobuf::Field::Int32Field, :bb, 268435455 end - + class TestRecursiveMessage optional ::GoogleUnittest::TestRecursiveMessage, :a, 1 optional ::Protobuf::Field::Int32Field, :i, 2 end - + class TestMutualRecursionA optional ::GoogleUnittest::TestMutualRecursionB, :bb, 1 end - + class TestMutualRecursionB optional ::GoogleUnittest::TestMutualRecursionA, :a, 1 optional ::Protobuf::Field::Int32Field, :optional_int32, 2 end - + class TestDupFieldNumber optional ::Protobuf::Field::Int32Field, :a, 1 end - + class TestEagerMessage optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 end - + class TestLazyMessage optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 end - + class TestNestedMessageHasBits class NestedMessage repeated ::Protobuf::Field::Int32Field, :nestedmessage_repeated_int32, 1 repeated ::GoogleUnittest::ForeignMessage, :nestedmessage_repeated_foreignmessage, 2 end - + optional ::GoogleUnittest::TestNestedMessageHasBits::NestedMessage, :optional_nested_message, 1 end - + class TestCamelCaseFieldNames - optional ::Protobuf::Field::Int32Field, :primitivefield, 1 - optional ::Protobuf::Field::StringField, :stringfield, 2 - optional ::GoogleUnittest::ForeignEnum, :enumfield, 3 - optional ::GoogleUnittest::ForeignMessage, :messagefield, 4 - optional ::Protobuf::Field::StringField, :stringpiecefield, 5 - optional ::Protobuf::Field::StringField, :cordfield, 6 - repeated ::Protobuf::Field::Int32Field, :repeatedprimitivefield, 7 - repeated ::Protobuf::Field::StringField, :repeatedstringfield, 8 - repeated ::GoogleUnittest::ForeignEnum, :repeatedenumfield, 9 - repeated ::GoogleUnittest::ForeignMessage, :repeatedmessagefield, 10 - repeated ::Protobuf::Field::StringField, :repeatedstringpiecefield, 11 - repeated ::Protobuf::Field::StringField, :repeatedcordfield, 12 - end - + optional ::Protobuf::Field::Int32Field, :PrimitiveField, 1 + optional ::Protobuf::Field::StringField, :StringField, 2 + optional ::GoogleUnittest::ForeignEnum, :EnumField, 3 + optional ::GoogleUnittest::ForeignMessage, :MessageField, 4 + optional ::Protobuf::Field::StringField, :StringPieceField, 5 + optional ::Protobuf::Field::StringField, :CordField, 6 + repeated ::Protobuf::Field::Int32Field, :RepeatedPrimitiveField, 7 + repeated ::Protobuf::Field::StringField, :RepeatedStringField, 8 + repeated ::GoogleUnittest::ForeignEnum, :RepeatedEnumField, 9 + repeated ::GoogleUnittest::ForeignMessage, :RepeatedMessageField, 10 + repeated ::Protobuf::Field::StringField, :RepeatedStringPieceField, 11 + repeated ::Protobuf::Field::StringField, :RepeatedCordField, 12 + end + class TestFieldOrderings optional ::Protobuf::Field::StringField, :my_string, 11 optional ::Protobuf::Field::Int64Field, :my_int, 1 optional ::Protobuf::Field::FloatField, :my_float, 101 - # Extension Fields extensions 2...11 extensions 12...101 optional ::Protobuf::Field::StringField, :my_extension_string, 50, :extension => true optional ::Protobuf::Field::Int32Field, :my_extension_int, 5, :extension => true end - + class TestExtremeDefaultValues - optional ::Protobuf::Field::BytesField, :escaped_bytes, 1, :default => "\0\001\a\b\f\n\r\t\v\\\'\"\xfe" + optional ::Protobuf::Field::BytesField, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" optional ::Protobuf::Field::Uint32Field, :large_uint32, 2, :default => 4294967295 optional ::Protobuf::Field::Uint64Field, :large_uint64, 3, :default => 18446744073709551615 optional ::Protobuf::Field::Int32Field, :small_int32, 4, :default => -2147483647 @@ -389,39 +399,39 @@ class TestExtremeDefaultValues optional ::Protobuf::Field::FloatField, :negative_float, 11, :default => -1.5 optional ::Protobuf::Field::FloatField, :large_float, 12, :default => 2e+08 optional ::Protobuf::Field::FloatField, :small_negative_float, 13, :default => -8e-28 - optional ::Protobuf::Field::DoubleField, :inf_double, 14, :default => Float::INFINITY - optional ::Protobuf::Field::DoubleField, :neg_inf_double, 15, :default => -Float::INFINITY - optional ::Protobuf::Field::DoubleField, :nan_double, 16, :default => Float::NAN - optional ::Protobuf::Field::FloatField, :inf_float, 17, :default => Float::INFINITY - optional ::Protobuf::Field::FloatField, :neg_inf_float, 18, :default => -Float::INFINITY - optional ::Protobuf::Field::FloatField, :nan_float, 19, :default => Float::NAN + optional ::Protobuf::Field::DoubleField, :inf_double, 14, :default => ::Float::INFINITY + optional ::Protobuf::Field::DoubleField, :neg_inf_double, 15, :default => -::Float::INFINITY + optional ::Protobuf::Field::DoubleField, :nan_double, 16, :default => ::Float::NAN + optional ::Protobuf::Field::FloatField, :inf_float, 17, :default => ::Float::INFINITY + optional ::Protobuf::Field::FloatField, :neg_inf_float, 18, :default => -::Float::INFINITY + optional ::Protobuf::Field::FloatField, :nan_float, 19, :default => ::Float::NAN optional ::Protobuf::Field::StringField, :cpp_trigraph, 20, :default => "? ? ?? ?? ??? ??/ ??-" optional ::Protobuf::Field::StringField, :string_with_zero, 23, :default => "hello" - optional ::Protobuf::Field::BytesField, :bytes_with_zero, 24, :default => "world" + optional ::Protobuf::Field::BytesField, :bytes_with_zero, 24, :default => "wor\000ld" optional ::Protobuf::Field::StringField, :string_piece_with_zero, 25, :default => "abc" optional ::Protobuf::Field::StringField, :cord_with_zero, 26, :default => "123" end - + class SparseEnumMessage optional ::GoogleUnittest::TestSparseEnum, :sparse_enum, 1 end - + class OneString optional ::Protobuf::Field::StringField, :data, 1 end - + class MoreString repeated ::Protobuf::Field::StringField, :data, 1 end - + class OneBytes optional ::Protobuf::Field::BytesField, :data, 1 end - + class MoreBytes repeated ::Protobuf::Field::BytesField, :data, 1 end - + class TestPackedTypes repeated ::Protobuf::Field::Int32Field, :packed_int32, 90, :packed => true repeated ::Protobuf::Field::Int64Field, :packed_int64, 91, :packed => true @@ -438,26 +448,25 @@ class TestPackedTypes repeated ::Protobuf::Field::BoolField, :packed_bool, 102, :packed => true repeated ::GoogleUnittest::ForeignEnum, :packed_enum, 103, :packed => true end - + class TestUnpackedTypes - repeated ::Protobuf::Field::Int32Field, :unpacked_int32, 90, :packed => false - repeated ::Protobuf::Field::Int64Field, :unpacked_int64, 91, :packed => false - repeated ::Protobuf::Field::Uint32Field, :unpacked_uint32, 92, :packed => false - repeated ::Protobuf::Field::Uint64Field, :unpacked_uint64, 93, :packed => false - repeated ::Protobuf::Field::Sint32Field, :unpacked_sint32, 94, :packed => false - repeated ::Protobuf::Field::Sint64Field, :unpacked_sint64, 95, :packed => false - repeated ::Protobuf::Field::Fixed32Field, :unpacked_fixed32, 96, :packed => false - repeated ::Protobuf::Field::Fixed64Field, :unpacked_fixed64, 97, :packed => false - repeated ::Protobuf::Field::Sfixed32Field, :unpacked_sfixed32, 98, :packed => false - repeated ::Protobuf::Field::Sfixed64Field, :unpacked_sfixed64, 99, :packed => false - repeated ::Protobuf::Field::FloatField, :unpacked_float, 100, :packed => false - repeated ::Protobuf::Field::DoubleField, :unpacked_double, 101, :packed => false - repeated ::Protobuf::Field::BoolField, :unpacked_bool, 102, :packed => false - repeated ::GoogleUnittest::ForeignEnum, :unpacked_enum, 103, :packed => false - end - + repeated ::Protobuf::Field::Int32Field, :unpacked_int32, 90 + repeated ::Protobuf::Field::Int64Field, :unpacked_int64, 91 + repeated ::Protobuf::Field::Uint32Field, :unpacked_uint32, 92 + repeated ::Protobuf::Field::Uint64Field, :unpacked_uint64, 93 + repeated ::Protobuf::Field::Sint32Field, :unpacked_sint32, 94 + repeated ::Protobuf::Field::Sint64Field, :unpacked_sint64, 95 + repeated ::Protobuf::Field::Fixed32Field, :unpacked_fixed32, 96 + repeated ::Protobuf::Field::Fixed64Field, :unpacked_fixed64, 97 + repeated ::Protobuf::Field::Sfixed32Field, :unpacked_sfixed32, 98 + repeated ::Protobuf::Field::Sfixed64Field, :unpacked_sfixed64, 99 + repeated ::Protobuf::Field::FloatField, :unpacked_float, 100 + repeated ::Protobuf::Field::DoubleField, :unpacked_double, 101 + repeated ::Protobuf::Field::BoolField, :unpacked_bool, 102 + repeated ::GoogleUnittest::ForeignEnum, :unpacked_enum, 103 + end + class TestPackedExtensions - # Extension Fields extensions 1...536870912 repeated ::Protobuf::Field::Int32Field, :packed_int32_extension, 90, :packed => true, :extension => true @@ -475,12 +484,12 @@ class TestPackedExtensions repeated ::Protobuf::Field::BoolField, :packed_bool_extension, 102, :packed => true, :extension => true repeated ::GoogleUnittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true end - + class TestDynamicExtensions class DynamicMessageType optional ::Protobuf::Field::Int32Field, :dynamic_field, 2100 end - + optional ::Protobuf::Field::Fixed32Field, :scalar_extension, 2000 optional ::GoogleUnittest::ForeignEnum, :enum_extension, 2001 optional ::GoogleUnittest::TestDynamicExtensions::DynamicEnumType, :dynamic_enum_extension, 2002 @@ -489,7 +498,7 @@ class DynamicMessageType repeated ::Protobuf::Field::StringField, :repeated_extension, 2005 repeated ::Protobuf::Field::Sint32Field, :packed_extension, 2006, :packed => true end - + class TestRepeatedScalarDifferentTagSizes repeated ::Protobuf::Field::Fixed32Field, :repeated_fixed32, 12 repeated ::Protobuf::Field::Int32Field, :repeated_int32, 13 @@ -498,7 +507,7 @@ class TestRepeatedScalarDifferentTagSizes repeated ::Protobuf::Field::FloatField, :repeated_float, 262142 repeated ::Protobuf::Field::Uint64Field, :repeated_uint64, 262143 end - + class TestParsingMerge class RepeatedFieldsGenerator repeated ::GoogleUnittest::TestAllTypes, :field1, 1 @@ -507,28 +516,28 @@ class RepeatedFieldsGenerator repeated ::GoogleUnittest::TestAllTypes, :ext1, 1000 repeated ::GoogleUnittest::TestAllTypes, :ext2, 1001 end - + required ::GoogleUnittest::TestAllTypes, :required_all_types, 1 optional ::GoogleUnittest::TestAllTypes, :optional_all_types, 2 repeated ::GoogleUnittest::TestAllTypes, :repeated_all_types, 3 - # Extension Fields extensions 1000...536870912 optional ::GoogleUnittest::TestAllTypes, :optional_ext, 1000, :extension => true repeated ::GoogleUnittest::TestAllTypes, :repeated_ext, 1001, :extension => true end - + class TestCommentInjectionMessage optional ::Protobuf::Field::StringField, :a, 1, :default => "*/ <- Neither should this." end - - + + ## - # Services + # Service Classes # class TestService < ::Protobuf::Rpc::Service rpc :foo, ::GoogleUnittest::FooRequest, ::GoogleUnittest::FooResponse rpc :bar, ::GoogleUnittest::BarRequest, ::GoogleUnittest::BarResponse end + end diff --git a/spec/support/test/google_unittest_import.pb.rb b/spec/support/test/google_unittest_import.pb.rb index 0aba8b79..f1b600f7 100644 --- a/spec/support/test/google_unittest_import.pb.rb +++ b/spec/support/test/google_unittest_import.pb.rb @@ -13,25 +13,25 @@ class ImportEnum < ::Protobuf::Enum define :IMPORT_BAR, 8 define :IMPORT_BAZ, 9 end - - + + ## # Message Classes # class PublicImportMessage < ::Protobuf::Message; end class ImportMessage < ::Protobuf::Message; end - + + ## # Message Fields # class PublicImportMessage optional ::Protobuf::Field::Int32Field, :e, 1 end - + class ImportMessage optional ::Protobuf::Field::Int32Field, :d, 1 end - - + end diff --git a/spec/support/test/google_unittest_import_public.pb.rb b/spec/support/test/google_unittest_import_public.pb.rb index 775b9de2..68a35d5c 100644 --- a/spec/support/test/google_unittest_import_public.pb.rb +++ b/spec/support/test/google_unittest_import_public.pb.rb @@ -1,8 +1,8 @@ ## # This file is auto-generated. DO NOT EDIT! # +require 'protobuf/message' module GoogleUnittestImport - end From ca9616a8d9fb1bf1273ec9efcf9d2dd7a0931d89 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Aug 2013 10:49:38 -0600 Subject: [PATCH 0494/1191] Update CHANGES.md --- CHANGES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c6ad60ce..a6edda4a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ - New compiler supports protobuf compilation/runtime with protoc <= v2.5.0 (c++ compiler removed). [#109] - Deprecated rprotoc in favor of protoc. [0bc9674] - Added service dynamic discovery to the ZMQ connector and server. [#91, @devin-c] +- No longer creating `-java` platform gem due to removal of c++ compiler. +- Added WTFPL license. 2.0.0 ----------- @@ -63,4 +65,4 @@ #### Other changes -* Moved files out of `lib/protobuf/common` folder into `lib/protobuf`. Files affected are logger, wire_type, util. The only update would need to be the require path to these files since the modules were always `Protobuf::{TYPE}`. +* Moved files out of `lib/protobuf/common` folder into `lib/protobuf`. Files affected are logger, wire\_type, util. The only update would need to be the require path to these files since the modules were always `Protobuf::{TYPE}`. From e7a51293eb5852905f280ebfe45a5c87984d216f Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Fri, 14 Jun 2013 16:11:32 -0600 Subject: [PATCH 0495/1191] Accept values that respond to `to_f` in FloatField. The checking for acceptable FloatField values was verifying that values fell between -Infinity and Infinity. This worked for any number object, including BigDecimal in MRI 1.9.2 <= & JRuby. In MRI 1.9.3 >=, setting a BigDecimal raised a type error. Since BigDecimal values pack the same way as Float values and their aren't min/max values for double/float fields in Protocol Buffers, a simple `respond_to?(:to_f)` call will suffice when checking for acceptable values. Closes #90. From ec2e9d9da2576a02ae89372b61a463b5d2cd6d8d Mon Sep 17 00:00:00 2001 From: Michael Xavier Date: Fri, 14 Jun 2013 15:21:24 -0700 Subject: [PATCH 0496/1191] Add fallback support for activesupport 2 From b8520f4ebbe6f6c86b365d706c8a9f434fd57f05 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 21 Aug 2013 10:53:34 -0600 Subject: [PATCH 0497/1191] Bump version 2.8.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 253ada00..06873970 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.0.beta9' + VERSION = '2.8.0' PROTOC_VERSION = '2.4.1' end From acff0d26d8ce8d3f5ea7eac8bd23e193e8239380 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 22 Aug 2013 09:28:16 -0600 Subject: [PATCH 0498/1191] Remove rake-compiler dependency and its Rakefile integration --- Rakefile | 18 ++---------------- protobuf.gemspec | 1 - 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/Rakefile b/Rakefile index 15f786bc..e29f0219 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ -$:.push File.expand_path("./", File.dirname(__FILE__)) -$:.push File.expand_path("./spec", File.dirname(__FILE__)) +$: << ::File.expand_path('../', __FILE__) +$: << ::File.expand_path('../spec', __FILE__) require "rubygems" require "rubygems/package_task" @@ -13,17 +13,3 @@ task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new(:spec) - -## -# rake-compiler -# -spec = Gem::Specification.load("protobuf.gemspec") - -Gem::PackageTask.new(spec) do |pkg| -end - -if RUBY_PLATFORM =~ /java/ - require "rake/javaextensiontask" -else - require "rake/extensiontask" -end diff --git a/protobuf.gemspec b/protobuf.gemspec index 6cd7bdc0..20c8d9a2 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -27,7 +27,6 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' - s.add_development_dependency 'rake-compiler' s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' From 00c599bda0845678b7a38d7dbeccdc4bacf5b472 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 26 Aug 2013 15:37:29 -0600 Subject: [PATCH 0499/1191] Increase directory lookup speed This improves lookup speed in a number of ways. The mutex locking has been removed, which I believe is the primary culprit of the increased lookup times. Writing new listings only happens in a single thread, so the mutex was an unnecessary precaution. Additionally, the listings are now hashed by service name for the lookup method, removing all iteration from the lookup process (except perhaps on a hash collision). --- lib/protobuf/rpc/service_directory.rb | 188 ++++++----- .../protobuf/rpc/service_directory_spec.rb | 318 ++++++++++-------- spec/support/test/google_unittest.pb.rb | 2 - 3 files changed, 288 insertions(+), 220 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 53995c16..55482598 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -1,6 +1,7 @@ require 'delegate' require 'singleton' require 'socket' +require 'set' require 'thread' require 'timeout' @@ -21,20 +22,32 @@ class Listing < Delegator attr_reader :expires_at def initialize(server) - @server = server - @expires_at = Time.now.to_i + ttl + update(server) end def current? !expired? end + def eql?(other) + uuid.eql?(other.uuid) + end + def expired? Time.now.to_i >= @expires_at end + def hash + uuid.hash + end + def ttl - [super.to_i, 3].max + [super.to_i, 1].max + end + + def update(server) + @server = server + @expires_at = Time.now.to_i + ttl end def __getobj__ @@ -65,70 +78,22 @@ def self.stop self.instance.stop end + # # Instance Methods # def initialize - @listings = {} - @mutex = Mutex.new - end - - def add_listing_for(server) - if server && server.uuid - @mutex.synchronize do - action = @listings.key?(server.uuid) ? :updated : :added - log_debug { sign_message("#{action} server: #{server.inspect}") } - - listing = Listing.new(server) - @listings[server.uuid] = listing - trigger(action, listing) - end - else - log_info { sign_message("Cannot add server without uuid: #{server.inspect}") } - end + reset end def each_listing(&block) - @listings.each_value(&block) + @listings_by_uuid.each_value(&block) end def lookup(service) if running? - @mutex.synchronize do - listings = @listings.values.select do |listing| - listing.services.any? do |listed_service| - listing.current? && listed_service == service.to_s - end - end - - listings.sample - end - end - end - - def remove_expired_listings - @mutex.synchronize do - @listings.delete_if do |uuid, listing| - if listing.expired? - trigger(:removed, listing) - true - else - false - end - end - end - end - - def remove_listing_for(server) - if server && server.uuid - log_debug { sign_message("Removing server: #{server.inspect}") } - - @mutex.synchronize do - deleted_listing = @listings.delete(server.uuid) - trigger(:removed, deleted_listing) + if @listings_by_service.key?(service) + @listings_by_service[service].entries.sample end - - else - log_info { sign_message("Cannot remove server without uuid: #{server.inspect}") } end end @@ -154,18 +119,34 @@ def start def stop log_info { sign_message("Stopping directory") } - @mutex.synchronize do - @thread.try(:kill) - @thread = nil - @listings = {} - end - + @thread.try(:kill).try(:join) @socket.try(:close) - @socket = nil + + reset end private + def add_or_update_listing(uuid, server) + listing = @listings_by_uuid[uuid] + + if listing + action = :updated + listing.update(server) + else + action = :added + listing = Listing.new(server) + @listings_by_uuid[uuid] = listing + end + + listing.services.each do |service| + @listings_by_service[service] << listing + end + + trigger(action, listing) + log_debug { sign_message("#{action} server: #{server.inspect}") } + end + def init_socket @socket = UDPSocket.new @socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true) @@ -178,39 +159,80 @@ def init_socket end def process_beacon(beacon) - case beacon.beacon_type - when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT - add_listing_for(beacon.server) - when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE - remove_listing_for(beacon.server) + server = beacon.server + uuid = server.try(:uuid) + + if server && uuid + case beacon.beacon_type + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT + add_or_update_listing(uuid, server) + when ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE + remove_listing(uuid) + end + else + log_info { sign_message("Ignoring incomplete beacon: #{beacon.inspect}") } + end + end + + def read_beacon + data, addr = @socket.recvfrom(2048) + + beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.decode(data) + + # Favor the address captured by the socket + beacon.try(:server).try(:address=, addr[3]) + + beacon + end + + def remove_expired_listings + log_debug { sign_message("Removing expired listings") } + @listings_by_uuid.each do |uuid, listing| + remove_listing(uuid) if listing.expired? end end + def remove_listing(uuid) + listing = @listings_by_uuid[uuid] or return + + log_debug { sign_message("Removing listing: #{listing.inspect}") } + + @listings_by_service.each do |service, listings| + listings.delete(listing) + end + + trigger(:removed, @listings_by_uuid.delete(uuid)) + end + + def reset + @thread = nil + @socket = nil + @listings_by_uuid = {} + @listings_by_service = Hash.new { |h, k| h[k] = Set.new } + end + def run + sweep_interval = 1 # sweep expired listings every 1 second + next_sweep = Time.now.to_i + sweep_interval + loop do - beacon = wait_for_beacon - process_beacon(beacon) - remove_expired_listings + timeout = [next_sweep - Time.now.to_i, 0.1].max + readable = IO.select([@socket], nil, nil, timeout) + process_beacon(read_beacon) if readable + + if Time.now.to_i >= next_sweep + remove_expired_listings + next_sweep = Time.now.to_i + sweep_interval + end end rescue => e - log_debug { sign_message("error: (#{e.class}) #{e.message}") } + log_debug { sign_message("ERROR: (#{e.class}) #{e.message}\n#{e.backtrace.join("\n")}") } retry end def trigger(action, listing) ::Protobuf::Lifecycle.trigger("directory.listing.#{action}", listing) end - - def wait_for_beacon - data, addr = @socket.recvfrom(2048) - - beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.decode(data) - - # Favor the address captured by the socket - beacon.try(:server).try(:address=, addr[3]) - - beacon - end end end end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 9da989e0..bdd6dea9 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -3,185 +3,233 @@ require 'protobuf/rpc/service_directory' describe ::Protobuf::Rpc::ServiceDirectory do - let(:instance) { ::Protobuf::Rpc::ServiceDirectory.instance } - - def listings - instance.instance_variable_get(:@listings) + subject { described_class.instance } + + let(:echo_server) { + ::Protobuf::Rpc::DynamicDiscovery::Server.new( + :uuid => 'echo', + :address => '127.0.0.1', + :port => '1111', + :ttl => 10, + :services => %w[EchoService] + ) + } + + let(:hello_server) { + ::Protobuf::Rpc::DynamicDiscovery::Server.new( + :uuid => "hello", + :address => '127.0.0.1', + :port => "1112", + :ttl => 10, + :services => %w[HelloService] + ) + } + + let(:hello_server_with_short_ttl) { + ::Protobuf::Rpc::DynamicDiscovery::Server.new( + :uuid => "hello_server_with_short_ttl", + :address => '127.0.0.1', + :port => '1113', + :ttl => 1, + :services => %w[HelloService] + ) + } + + let(:combo_server) { + ::Protobuf::Rpc::DynamicDiscovery::Server.new( + :uuid => "combo", + :address => '127.0.0.1', + :port => '1114', + :ttl => 10, + :services => %w[HelloService EchoService] + ) + } + + before(:all) do + @address = "127.0.0.1" + @port = 33333 + @socket = UDPSocket.new + + described_class.address = @address + described_class.port = @port end - def duration - start = Time.now.to_f - yield - Time.now.to_f - start + def expect_event_trigger(event) + ::Protobuf::Lifecycle + .should_receive(:trigger) + .with(event, + an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing)) + .once end - after do - instance.stop + def send_beacon(type, server) + type = type.to_s.upcase + beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( + :server => server, + :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType.fetch(type) + ) + + @socket.send(beacon.encode, 0, @address, @port) + sleep 0.01 # give the service directory time to process the beacon end - it "is a singleton" do - instance.should be_a_kind_of(Singleton) + it "should be a singleton" do + subject.should be_a_kind_of(Singleton) end - describe "#lookup" do - let(:server) { double('server', :uuid => '123', - :services => ['Known::Service'], - :address => "0.0.0.0", - :port => 9999, - :ttl => 15) } - let(:listing) { ::Protobuf::Rpc::ServiceDirectory::Listing.new(server) } + it "should be configured to listen to address 127.0.0.1" do + described_class.address.should eq '127.0.0.1' + end - before do - instance.stub(:running?) { true } - end + it "should be configured to listen to port 33333" do + described_class.port.should eq 33333 + end - it "returns a listing for the given service" do - instance.add_listing_for(server) - instance.lookup("Known::Service").should eq listing - end + it "should defer .start to the instance#start" do + described_class.instance.should_receive(:start) + described_class.start + end - it "returns random listings" do - instance.add_listing_for double(:uuid => 1, :ttl => 5, :services => ["Test"]) - instance.add_listing_for double(:uuid => 2, :ttl => 5, :services => ["Test"]) + it "should yeild itself to blocks passed to .start" do + described_class.instance.stub(:start) + expect { |b| described_class.start(&b) }.to yield_with_args(described_class) + end - uuids = 100.times.map { instance.lookup("Test").uuid } - uuids.count(1).should be_within(25).of(50) - uuids.count(2).should be_within(25).of(50) - end + it "should defer .stop to the instance#stop" do + described_class.instance.should_receive(:stop) + described_class.stop + end - it "does not return expired listings" do - instance.instance_variable_set(:@listings, { - '1' => double(:current? => false, :services => ["Test"]), - }) + context "stopped" do + before { subject.stop } - instance.lookup("Test").should be_nil + describe "#lookup" do + it "should return nil" do + send_beacon(:heartbeat, echo_server) + subject.lookup("EchoService").should be_nil + end end - end - describe '#add_listing_for' do - let(:server) { double('server', { :uuid => '123', - :services => ['Known::Service'], - :address => "0.0.0.0", - :port => 9999, - :ttl => 15 }) } - - it 'adds the listing to the known @listings' do - expect { - ::Protobuf::Lifecycle.should_receive(:trigger) - .with('directory.listing.added', an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing)) - .once - instance.add_listing_for(server) - }.to change(listings, :size).from(0).to(1) + describe "#restart" do + it "should start the service" do + subject.restart + subject.should be_running + end end - end - - describe '#each_listing' do - let(:listing_doubles) { { '1' => double('listing 1'), - '2' => double('listing 2'), - '3' => double('listing 3') } } - before do - instance.instance_variable_set(:@listings, listing_doubles) + describe "#running" do + it "should be false" do + subject.should_not be_running + end end - it 'invokes the given block for each listing known by the directory' do - yielded_listings = [] - instance.each_listing do |listing| - yielded_listings << listing + describe "#stop" do + it "has no effect" do + subject.stop end - yielded_listings.should eq(listing_doubles.values) end end - describe "#remove_expired_listings" do - let(:listing_doubles) { { '1' => double(:expired? => true), - '2' => double(:expired? => true), - '3' => double(:expired? => false) } } + context "started" do + before { subject.start } + after { subject.stop } - before do - instance.instance_variable_set(:@listings, listing_doubles) - end + it { should be_running } - it "removes expired listings" do - expect { - ::Protobuf::Lifecycle.should_receive(:trigger) - .with('directory.listing.removed', an_instance_of(RSpec::Mocks::Mock)) - .twice - instance.remove_expired_listings - }.to change(listings, :size).from(3).to(1) - listings.keys.should eq ['3'] + it "should trigger added events" do + expect_event_trigger("directory.listing.added") + send_beacon(:heartbeat, echo_server) end - end - describe "#start" do - it "creates a thread" do - Thread.should_receive(:new) - instance.start + it "should trigger updated events" do + send_beacon(:heartbeat, echo_server) + expect_event_trigger("directory.listing.updated") + send_beacon(:heartbeat, echo_server) end - it "initializes the socket" do - instance.should_receive :init_socket - instance.start + it "should trigger removed events" do + send_beacon(:heartbeat, echo_server) + expect_event_trigger("directory.listing.removed") + send_beacon(:flatline, echo_server) end - it "calls #run" do - instance.should_receive(:run) - instance.start - sleep 0.01 - end + describe "#each_listing" do + let(:listing_doubles) { { '1' => double('listing 1'), + '2' => double('listing 2'), + '3' => double('listing 3') } } - it "changes the running state" do - expect { - instance.start - }.to change(instance, :running?).from(false).to(true) + before do + send_beacon(:heartbeat, hello_server) + send_beacon(:heartbeat, echo_server) + send_beacon(:heartbeat, combo_server) + end + + it 'invokes the given block for each listing known by the directory' do + expect { |block| + subject.each_listing(&block) + }.to yield_control.exactly(3).times + end end - end - describe "a running service directory" do - let(:socket) { UDPSocket.new } + describe "#lookup" do + it "should provide listings by service" do + send_beacon(:heartbeat, hello_server) + subject.lookup("HelloService").to_hash.should eq hello_server.to_hash + end - def thread - instance.instance_variable_get(:@thread) - end + it "should return random listings" do + send_beacon(:heartbeat, hello_server) + send_beacon(:heartbeat, combo_server) - before do - described_class.start do |config| - config.address = "127.0.0.1" - config.port = 33333 + uuids = 100.times.map { subject.lookup("HelloService").uuid } + uuids.count("hello").should be_within(25).of(50) + uuids.count("combo").should be_within(25).of(50) end - socket.connect described_class.address, described_class.port + it "should not return expired listings" do + send_beacon(:heartbeat, hello_server_with_short_ttl) + send_beacon(:heartbeat, hello_server) + sleep 1 + uuids = 100.times.map { subject.lookup("HelloService").uuid } + uuids.count("hello_server_with_short_ttl").should eq 0 + end + + it "should not return flatlined servers" do + send_beacon(:heartbeat, echo_server) + send_beacon(:heartbeat, combo_server) + send_beacon(:flatline, echo_server) + + uuids = 100.times.map { subject.lookup("EchoService").uuid } + uuids.count("combo").should eq 100 + end + end + + describe "#restart" do + it "should clear all listings" do + send_beacon(:heartbeat, echo_server) + send_beacon(:heartbeat, combo_server) + subject.restart + subject.lookup("EchoService").should be_nil + end end - context "receiving a heartbeat" do - let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'heartbeat', :address => '127.0.0.1') } - let(:beacon) { ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( - :server => server, - :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT - )} - let(:payload) { beacon.encode } - - it "adds a listing" do - instance.should_receive(:add_listing_for).with(server) - instance.should_receive(:remove_expired_listings) - socket.send(payload, 0) - sleep 0.01 + describe "#running" do + it "should be true" do + subject.should be_running end end - context "receiving a flatline" do - let(:server) { ::Protobuf::Rpc::DynamicDiscovery::Server.new(:uuid => 'flatline', :address => '127.0.0.1') } - let(:beacon) { ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( - :server => server, - :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE - )} - let(:payload) { beacon.encode } - - it "removes a listing" do - instance.should_receive(:remove_listing_for).with(server) - instance.should_receive(:remove_expired_listings) - socket.send(payload, 0) - sleep 0.01 + describe "#stop" do + it "should clear all listings" do + send_beacon(:heartbeat, echo_server) + send_beacon(:heartbeat, combo_server) + subject.stop + subject.lookup("EchoService").should be_nil + end + + it "should stop the server" do + subject.stop + subject.should_not be_running end end end diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index 8cd4c32c..b41bcc50 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - ## # This file is auto-generated. DO NOT EDIT! # From cd7f8f67d56dd287538405f1b3d9675071fb1e3b Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 26 Aug 2013 16:14:44 -0600 Subject: [PATCH 0500/1191] Cleanup the specs --- .../protobuf/rpc/service_directory_spec.rb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index bdd6dea9..bc6867b9 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -154,17 +154,11 @@ def send_beacon(type, server) end describe "#each_listing" do - let(:listing_doubles) { { '1' => double('listing 1'), - '2' => double('listing 2'), - '3' => double('listing 3') } } - - before do + it "should yield to a block for each listing" do send_beacon(:heartbeat, hello_server) send_beacon(:heartbeat, echo_server) send_beacon(:heartbeat, combo_server) - end - it 'invokes the given block for each listing known by the directory' do expect { |block| subject.each_listing(&block) }.to yield_control.exactly(3).times @@ -188,10 +182,8 @@ def send_beacon(type, server) it "should not return expired listings" do send_beacon(:heartbeat, hello_server_with_short_ttl) - send_beacon(:heartbeat, hello_server) sleep 1 - uuids = 100.times.map { subject.lookup("HelloService").uuid } - uuids.count("hello_server_with_short_ttl").should eq 0 + subject.lookup("HelloService").should be_nil end it "should not return flatlined servers" do @@ -202,6 +194,14 @@ def send_beacon(type, server) uuids = 100.times.map { subject.lookup("EchoService").uuid } uuids.count("combo").should eq 100 end + + it "should return up-to-date listings" do + send_beacon(:heartbeat, echo_server) + echo_server.port = "7777" + send_beacon(:heartbeat, echo_server) + + subject.lookup("EchoService").port.should eq "7777" + end end describe "#restart" do From e658bed73501d3f2e410191b7b2a58421d242b87 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 27 Aug 2013 10:17:32 -0600 Subject: [PATCH 0501/1191] Benchmark lookup performance --- .../protobuf/rpc/service_directory_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index bc6867b9..8f0245c4 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -233,4 +233,38 @@ def send_beacon(type, server) end end end + + if ENV.key?("BENCH") + context "performance" do + let(:servers) { + 100.times.collect do |x| + ::Protobuf::Rpc::DynamicDiscovery::Server.new( + :uuid => server_name = "performance_server#{x + 1}", + :address => '127.0.0.1', + :port => (5555 + x).to_s, + :ttl => 10, + :services => 10.times.collect { |y| "PerformanceService#{y}" } + ) + end + } + + before do + require 'benchmark' + subject.start + servers.each { |server| send_beacon(:heartbeat, server) } + end + + after do + subject.stop + end + + it "should perform lookups in constant time" do + puts "" + Benchmark.bm do |x| + x.report { 100_000.times { subject.lookup("PerformanceService#{rand(1..10)}") } } + end + puts "" + end + end + end end From d7f7e81add3f761c9f3fb3414aa309c92646ec69 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 27 Aug 2013 10:29:59 -0600 Subject: [PATCH 0502/1191] Only lookup defined services in the benchmark --- spec/lib/protobuf/rpc/service_directory_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 8f0245c4..bbbdebff 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -261,7 +261,7 @@ def send_beacon(type, server) it "should perform lookups in constant time" do puts "" Benchmark.bm do |x| - x.report { 100_000.times { subject.lookup("PerformanceService#{rand(1..10)}") } } + x.report { 1_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } end puts "" end From 7e6f039fc86bb680b16403e3cf5fe6d126696c7c Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 27 Aug 2013 10:58:10 -0600 Subject: [PATCH 0503/1191] Randomize benchmark servers ttls' --- spec/lib/protobuf/rpc/service_directory_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index bbbdebff..713ed5e0 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -242,7 +242,7 @@ def send_beacon(type, server) :uuid => server_name = "performance_server#{x + 1}", :address => '127.0.0.1', :port => (5555 + x).to_s, - :ttl => 10, + :ttl => rand(1..5), :services => 10.times.collect { |y| "PerformanceService#{y}" } ) end @@ -259,11 +259,12 @@ def send_beacon(type, server) end it "should perform lookups in constant time" do - puts "" - Benchmark.bm do |x| - x.report { 1_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } + print "\n\n" + Benchmark.bm(17) do |x| + x.report(" 1_000 lookups:") { 1_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } + x.report(" 10_000 lookups:") { 10_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } + x.report("100_000 lookups:") { 100_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } end - puts "" end end end From d3c7a925c7da2db6159f8c4464a042621a155ff2 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 28 Aug 2013 14:07:49 -0600 Subject: [PATCH 0504/1191] Adds the end timestamp to Stat#to_s output Also adds the request size if to_s is called before the stat is stopped to aid in long-running request debugging. --- lib/protobuf/rpc/stat.rb | 18 +++++--- protobuf.gemspec | 1 + spec/lib/protobuf/rpc/stat_spec.rb | 70 ++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 spec/lib/protobuf/rpc/stat_spec.rb diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 6b9ef085..5dd504ca 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -1,4 +1,5 @@ require 'date' +require 'time' require 'protobuf/logger' module Protobuf @@ -11,6 +12,8 @@ class Stat def initialize(mode = :SERVER) @mode = mode + @request_size = 0 + @response_size = 0 start end @@ -43,16 +46,20 @@ def service end def sizes - "#{@request_size || 0}B/#{@response_size || 0}B" if stopped? + if stopped? + "#{@request_size}B/#{@response_size}B" + else + "#{@request_size}B/-" + end end def start - @start_time ||= Time.now + @start_time ||= ::Time.now end def stop start unless @start_time - @end_time ||= Time.now + @end_time ||= ::Time.now end def stopped? @@ -77,13 +84,14 @@ def to_s server? ? client : server, trace_id, rpc, + sizes, elapsed_time, - sizes + @end_time.try(:iso8601) ].compact.join(' - ') end def trace_id - Thread.current.object_id.to_s(16) + ::Thread.current.object_id.to_s(16) end end diff --git a/protobuf.gemspec b/protobuf.gemspec index 20c8d9a2..afd23698 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -30,5 +30,6 @@ require "protobuf/version" s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' + s.add_development_dependency 'timecop' # s.add_development_dependency 'perftools.rb' end diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb new file mode 100644 index 00000000..ad6b7f8d --- /dev/null +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -0,0 +1,70 @@ +require 'spec_helper' +require 'timecop' +require 'active_support/core_ext/numeric/time' + +describe ::Protobuf::Rpc::Stat do + + before(:all) do + unless defined?(BarService) + class BarService < ::Struct.new(:method_name); end + end + end + + describe 'server mode' do + it 'describes a server response to a client' do + ::Timecop.freeze(10.minutes.ago) do + stats = ::Protobuf::Rpc::Stat.new(:SERVER) + stats.client = 'myserver1' + stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars)) + stats.request_size = 43 + stats.response_size = 1302 + + ::Timecop.freeze(1.62.seconds.from_now) do + stats.stop + stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}" + end + end + end + + context 'when request is still running' do + it 'omits response size, duration, and timestamp' do + stats = ::Protobuf::Rpc::Stat.new(:SERVER) + stats.client = 'myserver1' + stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars)) + stats.request_size = 43 + stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-" + end + end + end + + describe 'client mode' do + it 'describes a client request to a server' do + ::Timecop.freeze(10.minutes.ago) do + stats = ::Protobuf::Rpc::Stat.new(:CLIENT) + stats.server = ['30000', 'myserver1.myhost.com'] + stats.service = 'Foo::BarService' + stats.method_name = 'find_bars' + stats.request_size = 37 + stats.response_size = 12345 + + ::Timecop.freeze(0.832.seconds.from_now) do + stats.stop + stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}" + end + + end + end + + context 'when request is still running' do + it 'omits response size, duration, and timestamp' do + stats = ::Protobuf::Rpc::Stat.new(:CLIENT) + stats.server = ['30000', 'myserver1.myhost.com'] + stats.service = 'Foo::BarService' + stats.method_name = 'find_bars' + stats.request_size = 37 + stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-" + end + end + end + +end From d333b2eb3f47bd30e7ae7119a4d5886685aee618 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 28 Aug 2013 14:09:27 -0600 Subject: [PATCH 0505/1191] Set the request size in the server when decoding the request from the buffer Previously this was handled only in the socket and em server/workers, but not in ZMQ. I pulled the code out of the implementing servers and handle it in the base server class. --- lib/protobuf/rpc/server.rb | 1 + lib/protobuf/rpc/servers/evented/server.rb | 1 - lib/protobuf/rpc/servers/socket/worker.rb | 2 -- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 684f1d7d..f19232ee 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -67,6 +67,7 @@ def log_signature # Parse the incoming request object into our expected request object def parse_request_from_buffer log_debug { sign_message("Parsing request from buffer: #{@request_data}") } + @stats.request_size = @request_data.size @request.decode(@request_data) rescue => error exc = ::Protobuf::Rpc::BadRequestData.new("Unable to parse request: #{error.message}") diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb index e36c5107..a39f2336 100644 --- a/lib/protobuf/rpc/servers/evented/server.rb +++ b/lib/protobuf/rpc/servers/evented/server.rb @@ -19,7 +19,6 @@ def receive_data(data) @request_buffer << data @request_data = @request_buffer.data - @stats.request_size = @request_buffer.size handle_client if @request_buffer.flushed? end diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index c788211c..b6c7d13c 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -20,8 +20,6 @@ def initialize(sock, &complete_cb) request_buffer << read_data @request_data = request_buffer.data - @stats.request_size = request_buffer.size - log_debug { sign_message("handling request") } handle_client if request_buffer.flushed? end From 7e92075237e5705331812bf4b88ed0ba6051a6f8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 28 Aug 2013 14:10:00 -0600 Subject: [PATCH 0506/1191] Ensure the response and request sizes are populated from the common client connector at the correct time --- lib/protobuf/rpc/connectors/common.rb | 2 ++ lib/protobuf/rpc/connectors/socket.rb | 1 - lib/protobuf/rpc/connectors/zmq.rb | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 9bdeeebd..e31a0820 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -74,6 +74,7 @@ def parse_response log_debug { sign_message("Parsing response from server (connection closed)") } # Parse out the raw response + @stats.response_size = @response_data.size response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) # Determine success or failure based on parsed data @@ -120,6 +121,7 @@ def request_bytes def setup_connection initialize_stats @request_data = request_bytes + @stats.request_size = request_bytes.size end def succeed(response) diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 1694c201..1507acc7 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -55,7 +55,6 @@ def read_response return if error? response_buffer = ::Protobuf::Rpc::Buffer.new(:read) response_buffer << read_data - @stats.response_size = response_buffer.size @response_data = response_buffer.data parse_response if response_buffer.flushed? end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b1028b9c..e1c44162 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -115,7 +115,6 @@ def host_alive?(host) def send_request_with_lazy_pirate attempt = 0 timeout = options[:timeout].to_f - @stats.request_size = @request_data.size begin attempt += 1 From 915d14e3ed3a2e0337bbe47a73572d8f2bd6cd5d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 28 Aug 2013 14:28:07 -0600 Subject: [PATCH 0507/1191] Use double instead of mock (deprecated in latest version of rspec) --- spec/lib/protobuf/code_generator_spec.rb | 4 ++-- spec/lib/protobuf/generators/base_spec.rb | 6 +++--- .../protobuf/generators/extension_generator_spec.rb | 6 +++--- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 12 ++++++------ spec/lib/protobuf/rpc/service_dispatcher_spec.rb | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index ec71f0f7..65cace6a 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -15,8 +15,8 @@ let(:output_file1) { COMPILER::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') } let(:output_file2) { COMPILER::CodeGeneratorResponse::File.new(:name => 'test/bar.pb.rb') } - let(:file_generator1) { mock('file generator 1', :generate_output_file => output_file1) } - let(:file_generator2) { mock('file generator 2', :generate_output_file => output_file2) } + let(:file_generator1) { double('file generator 1', :generate_output_file => output_file1) } + let(:file_generator2) { double('file generator 2', :generate_output_file => output_file2) } let(:request_bytes) do COMPILER::CodeGeneratorRequest.encode(:proto_file => [ input_file1, input_file2 ]) diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 6d89aab3..27157b77 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -5,10 +5,10 @@ describe ::Protobuf::Generators::Base do - subject { described_class.new(mock) } + subject { described_class.new(double) } context 'namespaces' do - let(:descriptor) { mock(:name => 'Baz') } + let(:descriptor) { double(:name => 'Baz') } subject { described_class.new(descriptor, 0, :namespace => [ :foo, :bar ]) } its(:type_namespace) { should eq [ :foo, :bar, 'Baz' ] } its(:fully_qualified_type_namespace) { should eq '.foo.bar.Baz' } @@ -55,7 +55,7 @@ def compile end end - subject { ToStringTest.new(mock) } + subject { ToStringTest.new(double) } it 'compiles and returns the contents' do 10.times do diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 20df2f69..da072abe 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -7,9 +7,9 @@ let(:field_descriptors) { [ - mock('field descriptor 1', :to_s => " field 1\n"), - mock('field descriptor 2', :to_s => " field 2\n"), - mock('field descriptor 3', :to_s => " field 3\n") + double('field descriptor 1', :to_s => " field 1\n"), + double('field descriptor 2', :to_s => " field 2\n"), + double('field descriptor 3', :to_s => " field 3\n") ] } let(:message_type) { 'FooBar' } diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index f8e48991..a5f4ba38 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -12,20 +12,20 @@ :port => "9400" }} - let(:socket_mock) do - sm = mock(::ZMQ::Socket) + let(:socket_double) do + sm = double(::ZMQ::Socket) sm.stub(:connect).and_return(0) sm end - let(:zmq_context_mock) do - zc = mock(::ZMQ::Context) - zc.stub(:socket).and_return(socket_mock) + let(:zmq_context_double) do + zc = double(::ZMQ::Context) + zc.stub(:socket).and_return(socket_double) zc end before do - ::ZMQ::Context.stub(:new).and_return(zmq_context_mock) + ::ZMQ::Context.stub(:new).and_return(zmq_context_double) end describe "#lookup_server_uri" do diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 1a0fed01..85b89248 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -67,7 +67,7 @@ def non_rpc_method; end context 'an object that responds to to_hash but is not a hash' do let(:hashable) do - mock('hashable', :to_hash => { :name => 'hashable' }) + double('hashable', :to_hash => { :name => 'hashable' }) end before { subject.callable_method.should_receive(:call) } before { subject.service.stub(:response).and_return(hashable) } @@ -78,7 +78,7 @@ def non_rpc_method; end context 'an object that responds to to_proto' do let(:protoable) do - mock('protoable', :to_proto => Test::Resource.new(:name => 'protoable')) + double('protoable', :to_proto => Test::Resource.new(:name => 'protoable')) end before { subject.callable_method.should_receive(:call) } before { subject.service.stub(:response).and_return(protoable) } From dc2cffc7cbff8e73dfa7107b765018121f9deba6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 28 Aug 2013 15:46:17 -0600 Subject: [PATCH 0508/1191] Bump version 2.8.1 --- CHANGES.md | 8 ++++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a6edda4a..3e4ebd12 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +2.8.1 +---------- + +- Improve `ServiceDirectory` lookup speed ~10x, lookups now done in constant time (devin-c). +- Add Timestamp to end of rpc stat log (represents ending time of request processing). +- Set `request_size` in the rpc stat within ZMQ Worker (previously missing). +- Ensure `request_size` and `response_size` are set on rpc stat for client requests. + 2.8.0 ----------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 2c001a20..2393546e 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.7.11' + VERSION = '2.8.1' PROTOC_VERSION = '2.5.0' end From be180c16596e35f2dff9c49906707c25673d2cf3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 28 Aug 2013 15:52:14 -0600 Subject: [PATCH 0509/1191] Reference release notes in README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f5faf22..ee140706 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ [![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) -___See [CHANGES.md](https://github.com/localshred/protobuf/blob/master/CHANGES.md) for up-to-date - API changes.___ +___See [CHANGES.md](https://github.com/localshred/protobuf/blob/master/CHANGES.md) or [Release Notes](https://github.com/localshred/protobuf/releases) for significant version changes.___ Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. From c8ffe653ae47fbead70c4707fc89755466b77ab5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 29 Aug 2013 14:29:38 -0600 Subject: [PATCH 0510/1191] Remove eventmachine from the client/connector side --- lib/protobuf.rb | 6 +- lib/protobuf/ext/eventmachine.rb | 14 --- lib/protobuf/lifecycle.rb | 14 +-- lib/protobuf/rpc/client.rb | 2 +- lib/protobuf/rpc/connector.rb | 2 - lib/protobuf/rpc/connectors/em_client.rb | 84 ------------------ lib/protobuf/rpc/connectors/eventmachine.rb | 87 ------------------- spec/lib/protobuf/rpc/client_spec.rb | 94 +-------------------- spec/lib/protobuf/rpc/connector_spec.rb | 8 +- spec/lib/protobuf_spec.rb | 6 +- 10 files changed, 16 insertions(+), 301 deletions(-) delete mode 100644 lib/protobuf/ext/eventmachine.rb delete mode 100644 lib/protobuf/rpc/connectors/em_client.rb delete mode 100644 lib/protobuf/rpc/connectors/eventmachine.rb diff --git a/lib/protobuf.rb b/lib/protobuf.rb index a0c53441..ba7f3aa2 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -19,7 +19,7 @@ module Protobuf # See Protobuf#connector_type documentation. - CONNECTORS = [ :socket, :zmq, :evented ].freeze + CONNECTORS = [ :socket, :zmq ].freeze # Default is Socket as it has no external dependencies. DEFAULT_CONNECTOR = :socket @@ -64,7 +64,7 @@ def self.connector_type=(type) # This optomization provides a huge boost in speed to rpc requests. def self.gc_pause_server_request? return @_gc_pause_server_request unless @_gc_pause_server_request.nil? - gc_pause_server_request = false + self.gc_pause_server_request = false end def self.gc_pause_server_request=(value) @@ -83,7 +83,7 @@ def self.gc_pause_server_request=(value) # The rpc_server option will override the ENV setting. def self.print_deprecation_warnings? return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil? - print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true + self.print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true end def self.print_deprecation_warnings=(value) diff --git a/lib/protobuf/ext/eventmachine.rb b/lib/protobuf/ext/eventmachine.rb deleted file mode 100644 index e49d986e..00000000 --- a/lib/protobuf/ext/eventmachine.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'fiber' - -# Method from em-synchrony -# https://github.com/igrigorik/em-synchrony -# -# A convenience method for wrapping EM.run body within -# a Ruby Fiber such that async operations can be transparently -# paused and resumed based on IO scheduling -module EventMachine - def self.fiber_run(blk=nil, tail=nil, &block) - context = Proc.new{ Fiber.new{ (b = blk || block) and b.call }.resume } - self.run(context, tail) - end -end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index e0082307..7af01668 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -1,19 +1,19 @@ module Protobuf class Lifecycle - def self.register( event_name, &blk ) + def self.register(event_name, &blk) raise "Lifecycle register must have a block" unless block_given? - event_name = normalized_event_name( event_name ) + event_name = normalized_event_name(event_name) lifecycle_events[ event_name ] ||= [] lifecycle_events[ event_name ] << blk end - def self.trigger( event_name, *args ) - event_name = normalized_event_name( event_name ) + def self.trigger(event_name, *args) + event_name = normalized_event_name(event_name) - if lifecycle_events.has_key?( event_name ) - lifecycle_events[ event_name ].each do |block| + if lifecycle_events.has_key?(event_name) + lifecycle_events[event_name].each do |block| if ! args.empty? && block.arity != 0 block.call(*args) else @@ -23,7 +23,7 @@ def self.trigger( event_name, *args ) end end - def self.normalized_event_name( event_name ) + def self.normalized_event_name(event_name) return "#{event_name}".downcase end diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index be88bf80..02ca7cd2 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -134,7 +134,7 @@ def method_missing(method_name, *params) end end - # Send the request to the service through eventmachine. + # Send the request to the service. # This method is usually never called directly # but is invoked by method_missing (see docs above). # diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb index 99a61af8..b3f15453 100644 --- a/lib/protobuf/rpc/connector.rb +++ b/lib/protobuf/rpc/connector.rb @@ -7,8 +7,6 @@ class Connector # Returns a connector class for the pre-defined connector_type. def self.connector_for_client case ::Protobuf.connector_type - when :evented then - ::Protobuf::Rpc::Connectors::EventMachine when :zmq then ::Protobuf::Rpc::Connectors::Zmq else diff --git a/lib/protobuf/rpc/connectors/em_client.rb b/lib/protobuf/rpc/connectors/em_client.rb deleted file mode 100644 index e5c202e4..00000000 --- a/lib/protobuf/rpc/connectors/em_client.rb +++ /dev/null @@ -1,84 +0,0 @@ -# Handles client connections to the server -module Protobuf - module Rpc - module Connectors - - class EMClient < EM::Connection - include Protobuf::Logger::LogMethods - include Protobuf::Rpc::Connectors::Common - - attr_reader :options, :request, :response - attr_reader :error, :error_reason, :error_message - - ## - # Constructor - # - def initialize(options = {}, &failure_cb) - @failure_cb = failure_cb - @options = DEFAULT_OPTIONS.merge(options) - @response_buffer = ::Protobuf::Rpc::Buffer.new(:read) - verify_options! - - log_debug { sign_message("Client Initialized: #{options.inspect}") } - rescue => e - fail(:RPC_ERROR, "Failed to initialize connection: #{e.message}") - end - - ## - # Class Methods - # - def self.connect(options = {}) - options = DEFAULT_OPTIONS.merge(options) - log_debug { sign_message("Connecting to server: #{options.inspect}") } - EM.connect(options[:host], options[:port], self, options) - end - - # turn post_init back into a no-op for event machine - def post_init - end - - ## - # Instance Methods - # - # Completion callback registration - def on_complete(&complete_cb) - @complete_cb = complete_cb - end - - # Failure callback registration - def on_failure(&failure_cb) - @failure_cb = failure_cb - end - - # Success callback registration - def on_success(&success_cb) - @success_cb = success_cb - end - - def receive_data(data) - log_debug { sign_message("receive_data: #{data}") } - @response_buffer << data - @response_data = @response_buffer.data - parse_response if !@response_data.nil? && @response_buffer.flushed? - end - - def send_data - request_buffer = ::Protobuf::Rpc::Buffer.new(:write) - request_buffer.set_data(@request_data) - log_debug { sign_message("sending data: #{request_buffer.inspect}") } - super(request_buffer.write) - rescue => e - fail(:RPC_ERROR, "Connection error: #{e.message}") - end - - # overwriting this method for java because it's broken in eventmachine. See https://github.com/eventmachine/eventmachine/issues/14 - if RUBY_PLATFORM =~ /java/ - def error? - !!@error - end - end - - end - end - end -end diff --git a/lib/protobuf/rpc/connectors/eventmachine.rb b/lib/protobuf/rpc/connectors/eventmachine.rb deleted file mode 100644 index 4a25cfec..00000000 --- a/lib/protobuf/rpc/connectors/eventmachine.rb +++ /dev/null @@ -1,87 +0,0 @@ -require 'protobuf/rpc/connectors/base' -require 'protobuf/rpc/connectors/em_client' - -module Protobuf - module Rpc - module Connectors - class EventMachine < Base - - def send_request - ensure_em_running do - f = Fiber.current - - ::EM.next_tick do - log_debug { sign_message('Scheduling EventMachine client request to be created on next tick') } - cnxn = EMClient.connect(options, &ensure_cb) - cnxn.on_success(&success_cb) if success_cb - cnxn.on_failure(&ensure_cb) - cnxn.on_complete { resume_fiber(f) } - cnxn.setup_connection - cnxn.send_data - log_debug { sign_message('Connection scheduled') } - end - - set_timeout_and_validate_fiber - end - end - - # Returns a callable that ensures any errors will be returned to the client - # - # If a failure callback was set, just use that as a direct assignment - # otherwise implement one here that simply throws an exception, since we - # don't want to swallow the black holes. - # - def ensure_cb - @ensure_cb ||= (@failure_cb || lambda { |error| raise "#{error.code.name}: #{error.message}" }) - end - - def log_signature - @_log_signature ||= "client-#{self.class}" - end - - private - - def ensure_em_running(&blk) - if ::EM.reactor_running? - @using_global_reactor = true - yield - else - @using_global_reactor = false - ::EM.fiber_run do - blk.call - ::EM.stop - end - end - end - - def resume_fiber(fib) - ::EM::cancel_timer(@timeout_timer) - fib.resume(true) - rescue => ex - log_exception(ex) - message = "Synchronous client failed: #{ex.message}" - error_stop_reactor(message) - end - - def set_timeout_and_validate_fiber - @timeout_timer = ::EM::add_timer(@options[:timeout]) do - message = "Client timeout of #{@options[:timeout]} seconds expired" - error_stop_reactor(message) - end - - Fiber.yield - rescue FiberError => ex - log_exception(ex) - message = "Synchronous calls must be in 'EM.fiber_run' block" - error_stop_reactor(message) - end - - def error_stop_reactor(message) - err = Protobuf::Rpc::ClientError.new(Protobuf::Socketrpc::ErrorReason::RPC_ERROR, message) - ensure_cb.call(err) - ::EM.stop unless @using_global_reactor - end - end - end - end -end diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index c38af459..6046386a 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -3,99 +3,7 @@ describe Protobuf::Rpc::Client do before(:each) do - load 'protobuf/evented.rb' - end - - context "when using fiber based calls", :skip => true do - it "waits for response" do - EventMachine.fiber_run do - StubServer.new(:delay => 1) do |server| - client = Test::ResourceService.client - start = now - - client.find(:name => "Test Name", :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end - end - - (now - start).should be_within(server.options.delay * 0.10).of(server.options.delay) - end - - EM.stop - end - end - - it "throws and error when call is attempted without 'EventMachine.fiber_run'" do - subject = Proc.new do - EventMachine.run do - StubServer.new(:delay => 1) do |server| - client = Test::ResourceService.client - client.find(:name => "Test Name", :active => true) - end - end - end - - subject.should raise_error(RuntimeError, /EM.fiber_run/) - end - - it "throws a timeout when client timeout is exceeded" do - error = nil - test_proc = Proc.new do - EventMachine.fiber_run do - StubServer.new(:delay => 2) do |server| - client = Test::ResourceService.client(:timeout => 1) - client.find(:name => "Test Name", :active => true) do |cl| - cl.on_success {} - cl.on_failure {|f| error = f} - end - end - EM.stop - end - end - - test_proc.call - error.message.should =~ /timeout/i - end - - context "without reactor_running?" do - - it "throws a timeout when client timeout is exceeded" do - subject = Proc.new do - StubServer.new(:delay => 2) do |server| - client = Test::ResourceService.client(:timeout => 1) - client.find(:name => "Test Name", :active => true) - end - end - - subject.should raise_error(RuntimeError, /timeout/i) - end - - it "calls failure_cb & throws a timeout when client timeout is exceeded" do - failure_message = nil - - subject = Proc.new do - StubServer.new(:delay => 2) do |server| - client = Test::ResourceService.client(:timeout => 1) - client.find(:name => "Test Name", :active => true) do |c| - c.on_failure do |f| - failure_message = f.message - end - end - end - end - - subject.call - failure_message.should match(/timeout/) - end - - end - + load 'protobuf/socket.rb' end context 'when creating a client from a service' do diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index e2dfa389..92637452 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper' require 'protobuf/socket' -require 'protobuf/evented' require 'protobuf/zmq' describe ::Protobuf::Rpc::Connector do @@ -14,15 +13,10 @@ end context 'Protobuf.connector_type is not a known value' do - before { ::Protobuf.connector_type = :socket } + before { ::Protobuf.stub(:connector_type) { :foo } } it { should eq ::Protobuf::Rpc::Connectors::Socket } end - context 'Protobuf.connector_type is evented' do - before { ::Protobuf.connector_type = :evented } - it { should eq ::Protobuf::Rpc::Connectors::EventMachine } - end - context 'Protobuf.connector_type is zmq' do before { ::Protobuf.connector_type = :zmq } it { should eq ::Protobuf::Rpc::Connectors::Zmq } diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 4d5f24be..e2f50e8e 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -26,15 +26,15 @@ described_class.connector_type.should eq :socket end - it 'accepts socket, evented, or zmq' do - [:socket, :evented, :zmq].each do |type| + it 'accepts socket or zmq' do + [:socket, :zmq].each do |type| described_class.connector_type = type described_class.connector_type.should eq type end end it 'does not accept other types' do - [:hello, :world].each do |type| + [:hello, :world, :evented].each do |type| expect { described_class.connector_type = type }.to raise_error(ArgumentError) From b4f7c68b2de7e4bd37af2dd9c25a8f0268992143 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 29 Aug 2013 14:30:30 -0600 Subject: [PATCH 0511/1191] Remove eventmachine from the server/runner side --- lib/protobuf/cli.rb | 20 +---- lib/protobuf/evented.rb | 22 ------ lib/protobuf/rpc/servers/evented/server.rb | 36 --------- lib/protobuf/rpc/servers/evented_runner.rb | 31 -------- spec/benchmark/tasks.rb | 76 ------------------- spec/functional/embedded_service_spec.rb | 7 -- spec/functional/evented_server_spec.rb | 64 ---------------- spec/lib/protobuf/cli_spec.rb | 48 ++---------- .../rpc/servers/evented_server_spec.rb | 19 ----- .../rpc/servers/socket_server_spec.rb | 6 -- spec/lib/protobuf/rpc/service_filters_spec.rb | 8 +- spec/spec_helper.rb | 7 ++ spec/support/server.rb | 21 +---- 13 files changed, 19 insertions(+), 346 deletions(-) delete mode 100644 lib/protobuf/evented.rb delete mode 100644 lib/protobuf/rpc/servers/evented/server.rb delete mode 100644 lib/protobuf/rpc/servers/evented_runner.rb delete mode 100644 spec/functional/embedded_service_spec.rb delete mode 100644 spec/functional/evented_server_spec.rb delete mode 100644 spec/lib/protobuf/rpc/servers/evented_server_spec.rb diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index b973e434..1b1d6ec8 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -2,7 +2,6 @@ require 'protobuf/version' require 'protobuf/lifecycle' require 'protobuf/logger' -require 'protobuf/rpc/servers/evented_runner' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq_runner' @@ -27,7 +26,6 @@ class CLI < ::Thor 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/)' option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.' - option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).' option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.' option :beacon_interval, :type => :numeric, :desc => 'Broadcast beacons every N seconds. (default: 5)' @@ -110,16 +108,12 @@ def configure_runner_mode @runner_mode = :socket elsif options.zmq? @runner_mode = :zmq - elsif options.evented? - @runner_mode = :evented else case server_type = ENV["PB_SERVER_TYPE"] when nil, /socket/i @runner_mode = :socket when /zmq/i @runner_mode = :zmq - when /evented/i - @runner_mode = :evented else say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow @runner_mode = :socket @@ -149,8 +143,6 @@ def configure_traps def create_runner debug_say("Creating #{@runner_mode} runner") @runner = case @runner_mode - when :evented - create_evented_runner when :zmq create_zmq_runner when :socket @@ -171,11 +163,7 @@ def exit_requested? # Internal helper to determine if the modes are multi-set which is not valid. def multi_mode? - [ - options.zmq?, - options.evented?, - options.socket?, - ].count(true) > 1 + options.zmq? && options.socket? end # Require the application file given, exiting if the file doesn't exist. @@ -210,12 +198,6 @@ def say_and_exit(message, exception = nil) exit(1) end - def create_evented_runner - require 'protobuf/evented' - - @runner = ::Protobuf::Rpc::EventedRunner.new(runner_options) - end - def create_socket_runner require 'protobuf/socket' diff --git a/lib/protobuf/evented.rb b/lib/protobuf/evented.rb deleted file mode 100644 index 4ba3e84f..00000000 --- a/lib/protobuf/evented.rb +++ /dev/null @@ -1,22 +0,0 @@ -## -## Evented Mode -## -# -# Require this file if you wish to run your server and/or client RPC -# with the evented handlers via EventMachine. -# -# To run with rpc_server specify the switch `evented`: -# -# rpc_server --evented myapp.rb -# -# To run for client-side only override the require in your Gemfile: -# -# gem 'protobuf', :require => 'protobuf/evented' -# -require 'protobuf' -Protobuf.connector_type = :evented - -require 'eventmachine' -require 'protobuf/ext/eventmachine' -require 'protobuf/rpc/servers/evented/server' -require 'protobuf/rpc/connectors/eventmachine' diff --git a/lib/protobuf/rpc/servers/evented/server.rb b/lib/protobuf/rpc/servers/evented/server.rb deleted file mode 100644 index a39f2336..00000000 --- a/lib/protobuf/rpc/servers/evented/server.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'protobuf/rpc/server' - -module Protobuf - module Rpc - module Evented - class Server < ::EventMachine::Connection - include ::Protobuf::Rpc::Server - include ::Protobuf::Logger::LogMethods - - # Initialize a new read buffer for storing client request info - def post_init - initialize_request! - @request_buffer = Protobuf::Rpc::Buffer.new(:read) - end - - # Receive a chunk of data, potentially flushed to handle_client - def receive_data(data) - log_debug { sign_message("receive_data: #{data}") } - - @request_buffer << data - @request_data = @request_buffer.data - - handle_client if @request_buffer.flushed? - end - - def send_data - response_buffer = Protobuf::Rpc::Buffer.new(:write) - response_buffer.set_data(@response) - @stats.response_size = response_buffer.size - log_debug { sign_message("sending data: #{response_buffer.inspect}") } - super(response_buffer.write) - end - end - end - end -end diff --git a/lib/protobuf/rpc/servers/evented_runner.rb b/lib/protobuf/rpc/servers/evented_runner.rb deleted file mode 100644 index 38acade0..00000000 --- a/lib/protobuf/rpc/servers/evented_runner.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Protobuf - module Rpc - class EventedRunner - - def initialize(options) - @options = options - end - - def run - # Startup and run the rpc server - ::EventMachine.schedule do - ::EventMachine.start_server( - @options[:host], - @options[:port], - ::Protobuf::Rpc::Evented::Server - ) - end - - # Join or start the reactor - yield if block_given? - - ::EM.reactor_running? ? ::EM.reactor_thread.join : ::EM.run - end - - def stop - ::EventMachine.stop_event_loop if ::EventMachine.reactor_running? - end - - end - end -end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 75267453..d5287b86 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -28,43 +28,8 @@ def benchmark_wrapper(global_bench = nil) end end - def em_client_em_server(number_tests, test_length, global_bench = nil) - EM.stop if EM.reactor_running? - - EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server| - benchmark_wrapper(global_bench) do |bench| - bench.report("ES / EC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } - end - end - end - - EM.stop - end - end - - def em_client_sock_server(number_tests, test_length, global_bench = nil) - EM.stop if EM.reactor_running? - - EventMachine.fiber_run do - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - - benchmark_wrapper(global_bench) do |bench| - bench.report("SS / EC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } - end - end - end - - EM.stop - end - end - def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - EM.stop if EM.reactor_running? StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| client = ::Test::ResourceService.client(:port => 9399) @@ -77,26 +42,6 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) end end - def sock_client_em_server(number_tests, test_length, global_bench = nil) - load "protobuf/socket.rb" - EM.stop if EM.reactor_running? - em_thread = Thread.new { EM.run } - Thread.pass until EM.reactor_running? - - StubServer.new(:port => 9399) do |server| - client = ::Test::ResourceService.client(:port => 9399) - - benchmark_wrapper(global_bench) do |bench| - bench.report("ES / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } - end - end - end - - EM.stop - Thread.kill(em_thread) if em_thread - end - def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| @@ -149,40 +94,19 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) puts args[:profile_output] end - desc "benchmark EventMachine client with EventMachine server" - task :em_client_em_server, [:number, :length] do |t, args| - args.with_defaults(:number => 1000, :length => 100) - em_client_em_server(args[:number], args[:length]) - end - - desc "benchmark EventMachine client with Socket server" - task :em_client_sock_server, [:number, :length] do |t, args| - args.with_defaults(:number => 1000, :length => 100) - em_client_sock_server(args[:number], args[:length]) - end - desc "benchmark Socket client with Socket server" task :sock_client_sock_server, [:number, :length] do |t, args| args.with_defaults(:number => 1000, :length => 100) sock_client_sock_server(args[:number], args[:length]) end - desc "benchmark Socket client with EventMachine server" - task :sock_client_em_server, [:number, :length] do |t, args| - args.with_defaults(:number => 1000, :length => 100) - sock_client_em_server(args[:number], args[:length]) - end - desc "benchmark server performance" task :servers, [:number, :length] do |t, args| args.with_defaults(:number => 1000, :length => 100) Benchmark.bm(10) do |bench| # zmq_client_zmq_server(args[:number], args[:length], bench) - # em_client_em_server(args[:number], args[:length], bench) - # em_client_sock_server(args[:number], args[:length], bench) sock_client_sock_server(args[:number], args[:length], bench) - # sock_client_em_server(args[:number], args[:length], bench) end end end diff --git a/spec/functional/embedded_service_spec.rb b/spec/functional/embedded_service_spec.rb deleted file mode 100644 index e2a5c529..00000000 --- a/spec/functional/embedded_service_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe 'An Embedded Service Call Hierarchy' do - - - -end \ No newline at end of file diff --git a/spec/functional/evented_server_spec.rb b/spec/functional/evented_server_spec.rb deleted file mode 100644 index 121203bf..00000000 --- a/spec/functional/evented_server_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'spec_helper' -require 'spec/support/test/resource_service' - -describe 'Functional EventMachine Client' do - before(:each) do - load 'protobuf/evented.rb' - end - - it 'runs fine when required fields are set' do - expect { - EventMachine.fiber_run do - StubServer.new do |server| - client = ::Test::ResourceService.client(:timeout => 5) - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end - end - end - EM.stop - end - }.to_not raise_error - end - - it 'calls the on_failure callback when a message is malformed' do - error = nil - EventMachine.fiber_run do - StubServer.new do |server| - request = ::Test::ResourceFindRequest.new(:active => true) - client = ::Test::ResourceService.client - - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end - end - EM.stop - end - error.message.should =~ /name.*required/ - end - - it 'calls the on_failure callback when the request type is wrong' do - error = nil - EventMachine.fiber_run do - StubServer.new do |server| - request = ::Test::Resource.new(:name => 'Test Name') - client = ::Test::ResourceService.client - - client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} - end - end - EM.stop - end - error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i - end -end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index e58f4bf0..9f98cd1c 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -7,28 +7,21 @@ File.expand_path('../../../support/test_app_file.rb', __FILE__) end - let(:sock_runner) { + let(:sock_runner) { runner = double("SocketRunner", :register_signals => nil) runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } runner } - let(:zmq_runner) { + let(:zmq_runner) { runner = double "ZmqRunner", register_signals: nil runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } runner } - let(:evented_runner) { - runner = double "EventedRunner", register_signals: nil - runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } - runner - } - before(:each) do ::Protobuf::Rpc::SocketRunner.stub(:new) { sock_runner } ::Protobuf::Rpc::ZmqRunner.stub(:new) { zmq_runner } - ::Protobuf::Rpc::EventedRunner.stub(:new) { evented_runner } end describe '#start' do @@ -176,7 +169,6 @@ let(:runner) { ::Protobuf::Rpc::SocketRunner } before do - ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) ::Protobuf::Rpc::ZmqRunner.should_not_receive(:new) end @@ -185,7 +177,7 @@ described_class.start(args) end - it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do + it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do ENV['PB_SERVER_TYPE'] = "Socket" runner.should_receive(:new).and_return(sock_runner) described_class.start(args) @@ -198,40 +190,12 @@ end end - context 'evented' do - let(:test_args) { [ '--evented' ] } - let(:runner) { ::Protobuf::Rpc::EventedRunner } - - before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:new) - end - - it 'is activated by the --evented switch' do - runner.should_receive(:new).and_return(evented_runner) - described_class.start(args) - end - - it 'is activated by PB_SERVER_TYPE=Evented ENV variable' do - ENV['PB_SERVER_TYPE'] = "Evented" - runner.should_receive(:new).and_return(evented_runner) - described_class.start(args) - ENV.delete('PB_SERVER_TYPE') - end - - it 'configures the connector type to be evented' do - load "protobuf/evented.rb" - ::Protobuf.connector_type.should == :evented - end - end - context 'zmq workers only' do let(:test_args) { [ '--workers_only', '--zmq' ] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) end it 'is activated by the --workers_only switch' do @@ -242,7 +206,7 @@ described_class.start(args) end - it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do + it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do ENV['PB_WORKERS_ONLY'] = "1" runner.should_receive(:new) do |options| options[:workers_only].should be_true @@ -259,7 +223,6 @@ before do ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) end it 'is activated by the --worker_port switch' do @@ -277,7 +240,6 @@ before do ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) - ::Protobuf::Rpc::EventedRunner.should_not_receive(:new) end it 'is activated by the --zmq switch' do @@ -285,7 +247,7 @@ described_class.start(args) end - it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do + it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do ENV['PB_SERVER_TYPE'] = "Zmq" runner.should_receive(:new) described_class.start(args) diff --git a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb b/spec/lib/protobuf/rpc/servers/evented_server_spec.rb deleted file mode 100644 index 558044ce..00000000 --- a/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' -require 'spec/support/test/resource_service' -require 'protobuf/rpc/servers/evented_runner' -require 'protobuf/evented' - -describe Protobuf::Rpc::Evented::Server do - - it "provides a Runner class" do - runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") - expect { runner_class.constantize }.to_not raise_error - end - - it "Runner provides a stop method" do - runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner").constantize - runner = runner_class.new({}) - runner.respond_to?(:stop).should be_true - end - -end diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 84de8c13..5257291b 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' require 'spec/support/test/resource_service' require 'protobuf/rpc/servers/socket_runner' -require 'protobuf/evented' require 'protobuf/socket' describe Protobuf::Rpc::Socket::Server do @@ -32,11 +31,6 @@ @server.should respond_to(:stop) end - it "provides a Runner class" do - runner_class = described_class.to_s.gsub(/Evented::Server/, "EventedRunner") - expect { runner_class.constantize }.to_not raise_error - end - it "signals the Server is running" do @server.should be_running end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 43ccbcbf..0d072ffd 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -416,7 +416,7 @@ def custom_error_occurred(ex) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :filter_with_error3, :custom_error_occurred ]) subject.ex_class.should eq CustomError3 - }.to_not raise_error(CustomError3) + }.not_to raise_error(CustomError3) end end @@ -437,7 +437,7 @@ def custom_error_occurred(ex) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :filter_with_error1, :custom_error_occurred ]) subject.ex_class.should eq CustomError1 - }.to_not raise_error(CustomError1) + }.not_to raise_error(CustomError1) end end end @@ -457,7 +457,7 @@ def custom_error_occurred(ex) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :filter_with_error1, :block_rescue_handler ]) subject.ex_class.should eq CustomError1 - }.to_not raise_error(CustomError1) + }.not_to raise_error(CustomError1) end end @@ -476,7 +476,7 @@ def custom_error_occurred(ex) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) subject.ex_class.should eq RuntimeError - }.to_not raise_error + }.not_to raise_error end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb2e2cd7..d76aec68 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'simplecov' SimpleCov.start +require 'timeout' require 'rubygems' require 'bundler' Bundler.setup :default, :development, :test @@ -37,6 +38,12 @@ %x{#{cmd}} end end + + c.around(:each) do |example| + Timeout::timeout(10) { + example.run + } + end end support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) diff --git a/spec/support/server.rb b/spec/support/server.rb index 7fa49c2d..5439e9b1 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -12,7 +12,7 @@ module StubProtobufServerFactory def self.build(delay) - new_server = Class.new(Protobuf::Rpc::Evented::Server) do + new_server = Class.new(Protobuf::Rpc::Socket::Server) do def self.sleep_interval @sleep_interval end @@ -43,7 +43,7 @@ def initialize(options = {}) :port => 9399, :worker_port => 9400, :delay => 0, - :server => Protobuf::Rpc::Evented::Server }.merge(options)) + :server => Protobuf::Rpc::Socket::Server }.merge(options)) start yield self @@ -53,27 +53,12 @@ def initialize(options = {}) def start case - when @options.server == Protobuf::Rpc::Evented::Server - start_em_server when @options.server == Protobuf::Rpc::Zmq::Server start_zmq_server else start_socket_server end log_debug { sign_message("Server started #{@options.host}:#{@options.port}") } - rescue => ex - if ex =~ /no acceptor/ # Means EM didn't shutdown in the next_tick yet - stop - retry - end - end - - def start_em_server - @server_handle = EventMachine.start_server( - @options.host, - @options.port, - StubProtobufServerFactory.build(@options.delay) - ) end def start_socket_server @@ -92,8 +77,6 @@ def start_zmq_server def stop case - when @options.server == Protobuf::Rpc::Evented::Server then - EventMachine.stop_server(@server_handle) if @server_handle when @options.server == Protobuf::Rpc::Zmq::Server then @zmq_runner.try :stop @zmq_thread.join if @zmq_thread From 6e3994d1bf61dbca66bbd1dded5538f4c26728cb Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 29 Aug 2013 14:30:38 -0600 Subject: [PATCH 0512/1191] Remove the eventmachine gem dependency --- protobuf.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index afd23698..4ad5255a 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -23,7 +23,6 @@ require "protobuf/version" s.add_dependency 'multi_json' s.add_dependency 'thor' - s.add_development_dependency 'eventmachine' s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' From 0557e91900e7de6ae6a8c2658a2c487ebff89660 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 29 Aug 2013 17:07:32 -0600 Subject: [PATCH 0513/1191] Fix specs that were causing the zmq functional server spec to hang --- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 9 ++- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- spec/functional/zmq_server_spec.rb | 63 +++++++++---------- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 8 +++ spec/lib/protobuf/rpc/service_filters_spec.rb | 6 +- spec/spec_helper.rb | 6 -- 7 files changed, 47 insertions(+), 49 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index e31a0820..e21a6cd5 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -74,7 +74,7 @@ def parse_response log_debug { sign_message("Parsing response from server (connection closed)") } # Parse out the raw response - @stats.response_size = @response_data.size + @stats.response_size = @response_data.size unless @response_data.nil? response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) # Determine success or failure based on parsed data diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index e1c44162..0dcd8dee 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -89,6 +89,7 @@ def error? def lookup_server_uri begin listing = service_directory.lookup(service) + host = listing.try(:address) || options[:host] port = listing.try(:port) || options[:port] end until host_alive?( host ) @@ -144,9 +145,11 @@ def send_request_with_timeout(timeout, attempt = 0) raise RequestTimeout end ensure - log_debug { sign_message("Closing Socket") } - zmq_error_check(socket.close, :socket_close) - log_debug { sign_message("Socket closed") } + unless socket.nil? + log_debug { sign_message("Closing Socket") } + zmq_error_check(socket.close, :socket_close) + log_debug { sign_message("Socket closed") } + end end # The service we're attempting to connect to diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 95cf90d2..6314a156 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -20,7 +20,7 @@ def initialize(options) def run @server = ::Protobuf::Rpc::Zmq::Server.new(@options) register_signals - @server.run do + @server.run do yield if block_given? end end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 29c3e0e5..3f391a6f 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -4,29 +4,24 @@ require 'protobuf/rpc/service_directory' describe 'Functional ZMQ Client' do - let(:options) {{ - :host => "127.0.0.1", - :port => 9399, - :worker_port => 9400, - :backlog => 100, - :threshold => 100, - :threads => 5 - }} - - let(:server) { ::Protobuf::Rpc::Zmq::Server.new(options) } - let!(:server_thread) { Thread.new(server) { |server| server.run } } - before(:all) do load "protobuf/zmq.rb" + options = { + :host => "127.0.0.1", + :port => 9399, + :worker_port => 9408, + :backlog => 100, + :threshold => 100, + :threads => 5 + } + @runner = ::Protobuf::Rpc::ZmqRunner.new(options) + @server_thread = Thread.new(@runner) { |runner| runner.run } + Thread.pass until @runner.running? end - before do - Thread.pass until server.running? - end - - after do - server.stop - server_thread.join + after(:all) do + @runner.stop + @server_thread.join end it 'runs fine when required fields are set' do @@ -47,24 +42,22 @@ end it 'runs under heavy load' do - 100.times do |x| - 50.times.map do |y| - Thread.new do - client = ::Test::ResourceService.client - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect - end + 10.times.map do |y| + Thread.new do + client = ::Test::ResourceService.client + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Test::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect end end - end.each(&:join) - end + end + end.each(&:join) end context 'when a message is malformed' do diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index a5f4ba38..cf92ae8e 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -28,6 +28,14 @@ ::ZMQ::Context.stub(:new).and_return(zmq_context_double) end + before(:all) do + @ping_port_before = ENV['PB_RPC_PING_PORT'] + end + + after(:all) do + ENV['PB_RPC_PING_PORT'] = @ping_port_before + end + describe "#lookup_server_uri" do let(:service_directory) { double('ServiceDirectory', :running? => running? ) } let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) } diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 0d072ffd..fd991822 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -416,7 +416,7 @@ def custom_error_occurred(ex) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :filter_with_error3, :custom_error_occurred ]) subject.ex_class.should eq CustomError3 - }.not_to raise_error(CustomError3) + }.not_to raise_error end end @@ -437,7 +437,7 @@ def custom_error_occurred(ex) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :filter_with_error1, :custom_error_occurred ]) subject.ex_class.should eq CustomError1 - }.not_to raise_error(CustomError1) + }.not_to raise_error end end end @@ -457,7 +457,7 @@ def custom_error_occurred(ex) subject.__send__(:run_filters, :endpoint) subject.called.should eq([ :filter_with_error1, :block_rescue_handler ]) subject.ex_class.should eq CustomError1 - }.not_to raise_error(CustomError1) + }.not_to raise_error end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d76aec68..79aa1e85 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,12 +38,6 @@ %x{#{cmd}} end end - - c.around(:each) do |example| - Timeout::timeout(10) { - example.run - } - end end support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) From a0d56a0fa39cacd5771b1f5282c6ff3eb4249727 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 29 Aug 2013 17:28:07 -0600 Subject: [PATCH 0514/1191] Remove GC.start in Server#enable_gc --- lib/protobuf/rpc/server.rb | 2 +- spec/functional/zmq_server_spec.rb | 45 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index f19232ee..765ccd9a 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -22,7 +22,7 @@ def disable_gc! end def enable_gc! - ::GC.enable && ::GC.start if ::Protobuf.gc_pause_server_request? + ::GC.enable if ::Protobuf.gc_pause_server_request? end # Invoke the service method dictated by the proto wrapper request object diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 3f391a6f..4591bb58 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -6,15 +6,12 @@ describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" - options = { - :host => "127.0.0.1", - :port => 9399, - :worker_port => 9408, - :backlog => 100, - :threshold => 100, - :threads => 5 - } - @runner = ::Protobuf::Rpc::ZmqRunner.new(options) + @runner = ::Protobuf::Rpc::ZmqRunner.new({ :host => "127.0.0.1", + :port => 9399, + :worker_port => 9408, + :backlog => 100, + :threshold => 100, + :threads => 5 }) @server_thread = Thread.new(@runner) { |runner| runner.run } Thread.pass until @runner.running? end @@ -42,22 +39,24 @@ end it 'runs under heavy load' do - 10.times.map do |y| - Thread.new do - client = ::Test::ResourceService.client - - client.find(:name => 'Test Name', :active => true) do |c| - c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) - end - - c.on_failure do |err| - raise err.inspect + 100.times do |x| + 50.times.map do |y| + Thread.new do + client = ::Test::ResourceService.client + + client.find(:name => 'Test Name', :active => true) do |c| + c.on_success do |succ| + succ.name.should eq("Test Name") + succ.status.should eq(::Test::StatusType::ENABLED) + end + + c.on_failure do |err| + raise err.inspect + end end end - end - end.each(&:join) + end.each(&:join) + end end context 'when a message is malformed' do From 75d8e4f50bd37e69c12c11f3b23834cf2bb9eeec Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 29 Aug 2013 17:30:21 -0600 Subject: [PATCH 0515/1191] Add back encoding to google unittest.pb --- spec/support/test/google_unittest.pb.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index b41bcc50..8cd4c32c 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # From c7ada62793b009086fa9b2a9efcf45f323a727ea Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 30 Aug 2013 11:20:34 -0600 Subject: [PATCH 0516/1191] Require benchmark tasks, fixed typos --- Rakefile | 2 +- protobuf.gemspec | 2 +- spec/benchmark/tasks.rb | 3 ++- spec/support/packed_field.rb | 30 ++++++++++++++++-------------- spec/support/server.rb | 4 ++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Rakefile b/Rakefile index e29f0219..afeb8d56 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ $: << ::File.expand_path('../spec', __FILE__) require "rubygems" require "rubygems/package_task" require "bundler/gem_tasks" -# require "benchmark/tasks" +require "benchmark/tasks" require "rspec/core/rake_task" diff --git a/protobuf.gemspec b/protobuf.gemspec index 4ad5255a..457043aa 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -30,5 +30,5 @@ require "protobuf/version" s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' s.add_development_dependency 'timecop' - # s.add_development_dependency 'perftools.rb' + s.add_development_dependency 'perftools.rb' end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index d5287b86..8c45d685 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,4 +1,5 @@ require 'benchmark' +require 'protobuf/socket' require 'support/all' require 'support/test/resource_service' @@ -105,7 +106,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :length => 100) Benchmark.bm(10) do |bench| - # zmq_client_zmq_server(args[:number], args[:length], bench) + zmq_client_zmq_server(args[:number], args[:length], bench) sock_client_sock_server(args[:number], args[:length], bench) end end diff --git a/spec/support/packed_field.rb b/spec/support/packed_field.rb index 7f731503..3fef7350 100644 --- a/spec/support/packed_field.rb +++ b/spec/support/packed_field.rb @@ -1,21 +1,23 @@ -shared_examples_for :packable_field do |klass| +if defined?(RSpec) + shared_examples_for :packable_field do |klass| - before(:all) do - unless defined?(PackableFieldTest) - class PackableFieldTest < ::Protobuf::Message; end - end + before(:all) do + unless defined?(PackableFieldTest) + class PackableFieldTest < ::Protobuf::Message; end + end - field_klass = klass - field_name = "#{klass.name.split('::').last.underscore}_packed_field".to_sym - tag_num = PackableFieldTest.fields.size + 1 - PackableFieldTest.repeated(field_klass, field_name, tag_num, :packed => true) - end + field_klass = klass + field_name = "#{klass.name.split('::').last.underscore}_packed_field".to_sym + tag_num = PackableFieldTest.fields.size + 1 + PackableFieldTest.repeated(field_klass, field_name, tag_num, :packed => true) + end - let(:field_name) { "#{klass.name.split('::').last.underscore}_packed_field" } - let(:message_instance) { PackableFieldTest.new(field_name => [100, 200, 300]) } + let(:field_name) { "#{klass.name.split('::').last.underscore}_packed_field" } + let(:message_instance) { PackableFieldTest.new(field_name => [100, 200, 300]) } - subject { message_instance.fields.last } + subject { message_instance.fields.last } - it { should be_packed } + it { should be_packed } + end end diff --git a/spec/support/server.rb b/spec/support/server.rb index 5439e9b1..a88db354 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -62,14 +62,14 @@ def start end def start_socket_server - @sock_runner = ::Protobuf::Rpc::SocketRunner.new(opt) + @sock_runner = ::Protobuf::Rpc::SocketRunner.new(options) @sock_thread = Thread.new(@sock_runner) { |runner| runner.run } @sock_thread.abort_on_exception = true # Set for testing purposes Thread.pass until @sock_runner.running? end def start_zmq_server - @zmq_runnger = ::Protobuf::Rpc::ZmqRunner.new(opt) + @zmq_runner = ::Protobuf::Rpc::ZmqRunner.new(options) @zmq_thread = Thread.new(@zmq_runner) { |runner| runner.run } @zmq_thread.abort_on_exception = true # Set for testing purposes Thread.pass until @zmq_runner.running? From 36f0a2c37049555415f430972fb9215867d8c973 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 3 Sep 2013 21:30:47 -0600 Subject: [PATCH 0517/1191] Remove activesupport < 4 version constraint --- protobuf.gemspec | 2 +- spec/support/test/google_unittest.pb.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index afd23698..ce5415de 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -19,7 +19,7 @@ require "protobuf/version" s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'activesupport', '< 4.0' + s.add_dependency 'activesupport' s.add_dependency 'multi_json' s.add_dependency 'thor' diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index b41bcc50..8cd4c32c 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # From 2caadfb01428716986c362e918495148e8211b35 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 3 Sep 2013 21:32:51 -0600 Subject: [PATCH 0518/1191] Bump version 2.8.2 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 3e4ebd12..0d8e7a36 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +2.8.2 +---------- + +- Remove the <4.0 version constraint on ActiveSupport. + 2.8.1 ---------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 2393546e..9bf5a2fd 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.1' + VERSION = '2.8.2' PROTOC_VERSION = '2.5.0' end From 475e414357c3fabebdefe81910b35e741422c5c4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 4 Sep 2013 17:00:02 -0600 Subject: [PATCH 0519/1191] Add deprecation warning when loading protobuf/evented --- lib/protobuf/evented.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/protobuf/evented.rb b/lib/protobuf/evented.rb index 4ba3e84f..f950a894 100644 --- a/lib/protobuf/evented.rb +++ b/lib/protobuf/evented.rb @@ -13,6 +13,21 @@ # # gem 'protobuf', :require => 'protobuf/evented' # +$stderr.puts <<-WARN + [DEPRECATED] You are using the evented connector and/or server which has been deprecated. + Versions >= 3.0 will no longer provide the evented module for clients + and servers. You should upgrade to the socket or zmq transport configurations. + + To upgrade your rpc_server, simply replace `--evented` option + with `--socket` or `--zmq`. If you are using the `PB_CLIENT_TYPE` + env variable, simply assign it to socket or zmq. + + If you are requiring the gem in your gemfile expclitly, change + the require to match your chosen transport type: + + `gem 'protobuf', :require => 'protobuf/socket'` +WARN + require 'protobuf' Protobuf.connector_type = :evented From d95dbccf6839b97cb450212c4e3ed67884c924a3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 4 Sep 2013 17:02:10 -0600 Subject: [PATCH 0520/1191] Bump version 2.8.3 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 0d8e7a36..3296349b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +2.8.3 +---------- + +- Add Deprecation warning when requiring `protobuf/evented`. Version 3.x will not support the eventmachine transport layer for client or server. + 2.8.2 ---------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9bf5a2fd..094ab33c 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.2' + VERSION = '2.8.3' PROTOC_VERSION = '2.5.0' end From 302ef0c46ad3671f8952f930ef70c33594cfa22a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 6 Sep 2013 10:34:35 -0600 Subject: [PATCH 0521/1191] Dup string value when encoding if it is frozen String#encode! will raise a RuntimeError if the string instance is frozen. The normal string setter for required or optional string fields already dups the incoming string to avoid reference issues. However when the field is a repeated string field the assigned array is dup'ed, but ruby keeps any string's frozen state. The fix is simply to dup any string value when we go to encode if it is frozen. --- lib/protobuf/field/string_field.rb | 3 ++- spec/lib/protobuf/field/string_field_spec.rb | 23 ++++++++++++++++++++ spec/support/test/resource.pb.rb | 2 ++ spec/support/test/resource.proto | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/lib/protobuf/field/string_field_spec.rb diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 01630d11..dc50bc09 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -10,8 +10,9 @@ def decode(bytes) bytes end + # TODO: make replace character configurable? def encode(value) - # TODO: make replace character configurable? + value = value.dup if value.frozen? value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb new file mode 100644 index 00000000..b45e4c07 --- /dev/null +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe ::Protobuf::Field::StringField do + describe '#encode' do + context 'when a repeated string field contains frozen strings' do + it 'does not raise an encoding error' do + expect { + frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] + ::Test::ResourceFindRequest.encode(:name => 'resource', :widgets => frozen_strings) + }.not_to raise_error + end + end + + context 'when a repeated bytes field contains frozen strings' do + it 'does not raise an encoding error' do + expect { + frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] + ::Test::ResourceFindRequest.encode(:name => 'resource', :widget_bytes => frozen_strings) + }.not_to raise_error + end + end + end +end diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 77d5f4d9..0bca8a0c 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -49,6 +49,8 @@ class NestedLevelOne < ::Protobuf::Message; end class ResourceFindRequest required ::Protobuf::Field::StringField, :name, 1 optional ::Protobuf::Field::BoolField, :active, 2 + repeated ::Protobuf::Field::StringField, :widgets, 3 + repeated ::Protobuf::Field::BytesField, :widget_bytes, 4 end class ResourceSleepRequest diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index 4f62d5bc..958ade6a 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -10,6 +10,8 @@ enum StatusType { message ResourceFindRequest { required string name = 1; optional bool active = 2; + repeated string widgets = 3; + repeated bytes widget_bytes = 4; } message ResourceSleepRequest { From 25e64d3caf43f3d2379833aa1d2fe3a645c4bc4a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 6 Sep 2013 11:00:12 -0600 Subject: [PATCH 0522/1191] Bump version 2.8.4 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 3296349b..60154274 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +2.8.4 +---------- + +- Fix issue where frozen strings assigned in a repeated field would cause encoding runtime errors. (#117) + 2.8.3 ---------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 094ab33c..2133968f 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.3' + VERSION = '2.8.4' PROTOC_VERSION = '2.5.0' end From 516c9954c1235424c33eddb708cb68d446a5927d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 10 Sep 2013 11:29:24 -0600 Subject: [PATCH 0523/1191] Force service name to string when performing directory lookup --- lib/protobuf/rpc/service_directory.rb | 4 ++-- spec/lib/protobuf/rpc/service_directory_spec.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 55482598..24743140 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -91,8 +91,8 @@ def each_listing(&block) def lookup(service) if running? - if @listings_by_service.key?(service) - @listings_by_service[service].entries.sample + if @listings_by_service.key?(service.to_s) + @listings_by_service[service.to_s].entries.sample end end end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 713ed5e0..677198f5 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -49,6 +49,7 @@ @address = "127.0.0.1" @port = 33333 @socket = UDPSocket.new + EchoService = Class.new described_class.address = @address described_class.port = @port @@ -202,6 +203,13 @@ def send_beacon(type, server) subject.lookup("EchoService").port.should eq "7777" end + + context 'when given service identifier is a class name' do + it 'returns the listing corresponding to the class name' do + send_beacon(:heartbeat, echo_server) + subject.lookup(EchoService).uuid.should eq echo_server.uuid + end + end end describe "#restart" do @@ -239,7 +247,7 @@ def send_beacon(type, server) let(:servers) { 100.times.collect do |x| ::Protobuf::Rpc::DynamicDiscovery::Server.new( - :uuid => server_name = "performance_server#{x + 1}", + :uuid => "performance_server#{x + 1}", :address => '127.0.0.1', :port => (5555 + x).to_s, :ttl => rand(1..5), From 3a1705c0e0cfe40bec8e831cd534b65cd5b5ed1e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 10 Sep 2013 11:34:47 -0600 Subject: [PATCH 0524/1191] Bump version 2.8.5 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 60154274..7bb7c803 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +2.8.5 +---------- + +- Fix issue where ServiceDirectory lookups were failing when given a class name, breaking the directory load balancing. (#119) + 2.8.4 ---------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 2133968f..0dfbf1b7 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.4' + VERSION = '2.8.5' PROTOC_VERSION = '2.5.0' end From 067a3e381f8d973546e85eae36bd0fbda006b74a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 16 Sep 2013 22:42:32 -0600 Subject: [PATCH 0525/1191] Always dup string/bytes values before encoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should always dup the string or bytes value before encoding because we are `force_encoding` to BINARY encoding (ascii-8bit) which is actually changing the value of the string if it contains unicode characters. Before this change, if a string or bytes field contained a unicode character, that field was effectively corrupted from its source value after the proto was encoded. ```ruby resource = Test::Resource.new(:name => "\u20ac") # => {:name=>"€"} resource.encode resource.name # => "\xE2\x82\xAC" resource.encode resource.name # => "" ``` It should be noted this behavior is not present when the string contains characters that fall inside the normal ascii range. Fixes #120. --- lib/protobuf/field/bytes_field.rb | 14 +++++++----- lib/protobuf/field/string_field.rb | 15 +++++++------ spec/lib/protobuf/field/string_field_spec.rb | 23 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index fdb237cd..e0803073 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -18,8 +18,9 @@ def acceptable?(val) end def decode(bytes) - bytes.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - bytes + bytes_to_decode = bytes.dup + bytes_to_decode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + bytes_to_decode end def define_setter @@ -46,11 +47,12 @@ def define_setter end def encode(value) - value = value.encode if value.is_a?(::Protobuf::Message) - value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + value_to_encode = value.dup + value_to_encode = value.encode if value.is_a?(::Protobuf::Message) + value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - string_size = ::Protobuf::Field::VarintField.encode(value.size) - string_size << value + string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) + string_size << value_to_encode end def wire_type diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index dc50bc09..ba6de481 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -6,18 +6,19 @@ class StringField < BytesField ENCODING = 'UTF-8'.freeze def decode(bytes) - bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) - bytes + bytes_to_decode = bytes.dup + bytes_to_decode.force_encoding(::Protobuf::Field::StringField::ENCODING) + bytes_to_decode end # TODO: make replace character configurable? def encode(value) - value = value.dup if value.frozen? - value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") - value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + value_to_encode = value.dup + value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - string_size = ::Protobuf::Field::VarintField.encode(value.size) - string_size << value + string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) + string_size << value_to_encode end end end diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index b45e4c07..50ba13b9 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -1,6 +1,9 @@ +# encoding: utf-8 + require 'spec_helper' describe ::Protobuf::Field::StringField do + describe '#encode' do context 'when a repeated string field contains frozen strings' do it 'does not raise an encoding error' do @@ -19,5 +22,25 @@ }.not_to raise_error end end + + it 'does not alter string values after encoding multiple times' do + source_string = "foo" + proto = ::Test::Resource.new(:name => source_string) + proto.encode + proto.name.should eq source_string + proto.encode + proto.name.should eq source_string + end + + it 'does not alter unicode string values after encoding multiple times' do + source_string = "¢" + proto = ::Test::Resource.new(:name => source_string) + proto.encode + proto.name.should eq source_string + proto.encode + proto.name.should eq source_string + end end + + end From 15b2416acc541a3d5f3957f65d3fd5be7f75f43e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Sep 2013 09:32:42 -0600 Subject: [PATCH 0526/1191] Bump version 2.8.6 --- CHANGES.md | 10 ++++++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 7bb7c803..a51443a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +2.8.6 +--------- + +- Fix string/byte encoding issue when unicode characters present. Reported by @foxban. This was also backported to v2.7.12. [#120] + 2.8.5 ---------- @@ -35,6 +40,11 @@ - No longer creating `-java` platform gem due to removal of c++ compiler. - Added WTFPL license. +2.7.12 +----------- + +- Backport string/byte encoding issue when unicode characters present. [code: #122, original issue: #120] + 2.0.0 ----------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 0dfbf1b7..b9a4faf9 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.5' + VERSION = '2.8.6' PROTOC_VERSION = '2.5.0' end From 84fb885bdd386a2f73ab0d8100950f395a7af45d Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Tue, 24 Sep 2013 22:00:33 -0600 Subject: [PATCH 0527/1191] Ignore rspec config. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a3a7def3..00a05ea3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ pkg/* .bundle .rvmrc +.rspec *.log coverage doc From 125341506c3c380cfb2e298425cee84b29ce5601 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Tue, 24 Sep 2013 22:01:06 -0600 Subject: [PATCH 0528/1191] Fire active support load hooks for RPC client, server. --- lib/protobuf/rpc/client.rb | 4 ++++ lib/protobuf/rpc/service.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index be88bf80..9f01e896 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -162,5 +162,9 @@ def send_request end end + + if ActiveSupport::VERSION::MAJOR > 2 + ActiveSupport.run_load_hooks(:protobuf_rpc_client, Client) + end end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index a90e7b66..1f3f9f49 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -205,5 +205,9 @@ def rpc_failed(message) end end + + if ActiveSupport::VERSION::MAJOR > 2 + ActiveSupport.run_load_hooks(:protobuf_rpc_service, Service) + end end end From 525951ffdeebdd1ca7a33a506edc667afddf01fc Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Tue, 1 Oct 2013 12:42:58 -0600 Subject: [PATCH 0529/1191] Add all_listings_for method. --- lib/protobuf/rpc/service_directory.rb | 8 ++++++++ spec/lib/protobuf/rpc/service_directory_spec.rb | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 24743140..fcaa5c79 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -85,6 +85,14 @@ def initialize reset end + def all_listings_for(service) + if running? + if @listings_by_service.key?(service.to_s) + @listings_by_service[service.to_s].entries.shuffle + end + end + end + def each_listing(&block) @listings_by_uuid.each_value(&block) end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 677198f5..3e2a52bb 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -154,6 +154,15 @@ def send_beacon(type, server) send_beacon(:flatline, echo_server) end + describe "#all_listings_for" do + it "returns all listings for a given service" do + send_beacon(:heartbeat, hello_server) + send_beacon(:heartbeat, combo_server) + + subject.all_listings_for("HelloService").size.should eq(2) + end + end + describe "#each_listing" do it "should yield to a block for each listing" do send_beacon(:heartbeat, hello_server) From 13b9e1959964d2c8b5b1923c007206ca7a0b7319 Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Tue, 1 Oct 2013 12:43:17 -0600 Subject: [PATCH 0530/1191] Raise an error if no host is found. --- lib/protobuf/rpc/connectors/zmq.rb | 19 +++++++++++++------ spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index e1c44162..d6803bce 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -87,13 +87,20 @@ def error? # to the host and port in the options # def lookup_server_uri - begin - listing = service_directory.lookup(service) - host = listing.try(:address) || options[:host] - port = listing.try(:port) || options[:port] - end until host_alive?( host ) + listings = service_directory.all_listings_for(service) + if listings + listings.each do |listing| + host = listing.try(:address) + port = listing.try(:port) + return "tcp://#{host}:#{port}" if host_alive?(host) + end + end + + host = options[:host] + port = options[:port] + return "tcp://#{host}:#{port}" if host_alive?(host) - "tcp://#{host}:#{port}" + raise "Host not found for service #{service}" end def host_alive?(host) diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index a5f4ba38..49c5180c 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -31,6 +31,7 @@ describe "#lookup_server_uri" do let(:service_directory) { double('ServiceDirectory', :running? => running? ) } let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) } + let(:listings) { [listing] } let(:running?) { true } before do @@ -39,12 +40,12 @@ context "when the service directory is running" do it "searches the service directory" do - service_directory.should_receive(:lookup).and_return(listing) + service_directory.should_receive(:all_listings_for).and_return(listings) subject.send(:lookup_server_uri).should eq "tcp://127.0.0.2:9399" end it "defaults to the options" do - service_directory.should_receive(:lookup) { nil } + service_directory.should_receive(:all_listings_for) { nil } subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end @@ -53,17 +54,25 @@ let(:running?) { false } it "defaults to the options" do - service_directory.should_receive(:lookup) { nil } + service_directory.should_receive(:all_listings_for) { nil } subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end it "checks if the server is alive" do - service_directory.should_receive(:lookup) { nil } + service_directory.should_receive(:all_listings_for) { nil } subject.should_receive(:host_alive?).with("127.0.0.1") { true } subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end + context "when no host is alive" do + it "raises an error" do + service_directory.stub(:all_listings_for).and_return(listings) + subject.stub(:host_alive?).and_return(false) + expect { subject.send(:lookup_server_uri) }.to raise_error + end + end + end describe "#host_alive?" do From 7905b579c650131858a45435617fd029f633d8fc Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Tue, 1 Oct 2013 13:26:28 -0600 Subject: [PATCH 0531/1191] Try 5 times before aborting rpc call. --- lib/protobuf/rpc/connectors/zmq.rb | 24 ++++++++++++-------- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 8 +++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index d6803bce..828828f1 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -87,18 +87,22 @@ def error? # to the host and port in the options # def lookup_server_uri - listings = service_directory.all_listings_for(service) - if listings - listings.each do |listing| - host = listing.try(:address) - port = listing.try(:port) - return "tcp://#{host}:#{port}" if host_alive?(host) + 5.times do + listings = service_directory.all_listings_for(service) + if listings + listings.each do |listing| + host = listing.try(:address) + port = listing.try(:port) + return "tcp://#{host}:#{port}" if host_alive?(host) + end end - end - host = options[:host] - port = options[:port] - return "tcp://#{host}:#{port}" if host_alive?(host) + host = options[:host] + port = options[:port] + return "tcp://#{host}:#{port}" if host_alive?(host) + + sleep 1 + end raise "Host not found for service #{service}" end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 49c5180c..2649ab00 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -40,12 +40,12 @@ context "when the service directory is running" do it "searches the service directory" do - service_directory.should_receive(:all_listings_for).and_return(listings) + service_directory.stub(:all_listings_for).and_return(listings) subject.send(:lookup_server_uri).should eq "tcp://127.0.0.2:9399" end it "defaults to the options" do - service_directory.should_receive(:all_listings_for) { nil } + service_directory.stub(:all_listings_for).and_return(nil) subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end @@ -54,13 +54,13 @@ let(:running?) { false } it "defaults to the options" do - service_directory.should_receive(:all_listings_for) { nil } + service_directory.stub(:all_listings_for).and_return(nil) subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end it "checks if the server is alive" do - service_directory.should_receive(:all_listings_for) { nil } + service_directory.stub(:all_listings_for).and_return(nil) subject.should_receive(:host_alive?).with("127.0.0.1") { true } subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end From c40b9ba5a7f1a00939db385eaa1ed68442d0bf24 Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Tue, 1 Oct 2013 13:38:00 -0600 Subject: [PATCH 0532/1191] Only close the socket if it was created successfully. --- lib/protobuf/rpc/connectors/zmq.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 828828f1..41930e20 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -156,7 +156,7 @@ def send_request_with_timeout(timeout, attempt = 0) end ensure log_debug { sign_message("Closing Socket") } - zmq_error_check(socket.close, :socket_close) + zmq_error_check(socket.close, :socket_close) if socket log_debug { sign_message("Socket closed") } end From af76be900debe00be88e68092346d0717510bbad Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Tue, 1 Oct 2013 17:10:15 -0600 Subject: [PATCH 0533/1191] all_listings_for returns an empty array when no listings are present. --- lib/protobuf/rpc/connectors/zmq.rb | 11 ++++------- lib/protobuf/rpc/service_directory.rb | 8 ++++---- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 6 +++--- spec/lib/protobuf/rpc/service_directory_spec.rb | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 41930e20..fa25c4a8 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -88,13 +88,10 @@ def error? # def lookup_server_uri 5.times do - listings = service_directory.all_listings_for(service) - if listings - listings.each do |listing| - host = listing.try(:address) - port = listing.try(:port) - return "tcp://#{host}:#{port}" if host_alive?(host) - end + service_directory.all_listings_for(service).each do |listing| + host = listing.try(:address) + port = listing.try(:port) + return "tcp://#{host}:#{port}" if host_alive?(host) end host = options[:host] diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index fcaa5c79..0bd75a88 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -86,10 +86,10 @@ def initialize end def all_listings_for(service) - if running? - if @listings_by_service.key?(service.to_s) - @listings_by_service[service.to_s].entries.shuffle - end + if running? && @listings_by_service.key?(service.to_s) + @listings_by_service[service.to_s].entries.shuffle + else + [] end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 2649ab00..cf6fa148 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -45,7 +45,7 @@ end it "defaults to the options" do - service_directory.stub(:all_listings_for).and_return(nil) + service_directory.stub(:all_listings_for).and_return([]) subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end @@ -54,13 +54,13 @@ let(:running?) { false } it "defaults to the options" do - service_directory.stub(:all_listings_for).and_return(nil) + service_directory.stub(:all_listings_for).and_return([]) subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end end it "checks if the server is alive" do - service_directory.stub(:all_listings_for).and_return(nil) + service_directory.stub(:all_listings_for).and_return([]) subject.should_receive(:host_alive?).with("127.0.0.1") { true } subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 3e2a52bb..9cc5d8b8 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -155,11 +155,19 @@ def send_beacon(type, server) end describe "#all_listings_for" do - it "returns all listings for a given service" do - send_beacon(:heartbeat, hello_server) - send_beacon(:heartbeat, combo_server) + context "when listings are present" do + it "returns all listings for a given service" do + send_beacon(:heartbeat, hello_server) + send_beacon(:heartbeat, combo_server) + + subject.all_listings_for("HelloService").size.should eq(2) + end + end - subject.all_listings_for("HelloService").size.should eq(2) + context "when no listings are present" do + it "returns and empty array" do + subject.all_listings_for("HelloService").size.should eq(0) + end end end From 3b2187a0eccee21ac1acdecfe12eb841df4a1a9e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 7 Oct 2013 11:34:32 -0600 Subject: [PATCH 0534/1191] Bump version 2.8.7 --- CHANGES.md | 6 ++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a51443a9..b9057fa6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +2.8.7 +--------- + +- Fire ActiveSupport load hooks when RPC Server and Client classes are loaded. [#126, @liveh2o] +- Prevent infinite loop when doing service lookup from directory. [#125, @brianstien] + 2.8.6 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b9a4faf9..44ef15f0 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.6' + VERSION = '2.8.7' PROTOC_VERSION = '2.5.0' end From 5cc65a0a828e14c726097b916f76a2209b45d388 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 8 Nov 2013 13:49:58 -0500 Subject: [PATCH 0535/1191] Drop heavy load constraints on zmq functional spec --- spec/functional/zmq_server_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 4591bb58..543835ce 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -39,8 +39,8 @@ end it 'runs under heavy load' do - 100.times do |x| - 50.times.map do |y| + 10.times do |x| + 5.times.map do |y| Thread.new do client = ::Test::ResourceService.client From db3cbc673631327b7e2585af3fb39c3ee7b0fc31 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 12 Nov 2013 14:50:36 -0700 Subject: [PATCH 0536/1191] Add Enum.integer_values to return an array of all defined int values for an enum --- lib/protobuf/enum.rb | 4 ++++ spec/lib/protobuf/enum_spec.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index ab8fded2..ec2b3d38 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -32,6 +32,10 @@ def self.enum_by_value(value) value_by_name(name_by_value(value)) end + def self.integer_values + self.values.values.map(&:to_i) + end + def self.name_by_value(value) (!value.nil? && value.respond_to?(:to_i)) ? @names[value.to_i] : nil end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index afacc4ee..f3ec64fc 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -95,6 +95,20 @@ end end + describe '.integer_values' do + before do + IntegerValuesEnumTest = ::Class.new(::Protobuf::Enum) do + define :FOO, 1 + define :BAR, 2 + define :BAZ, 5 + end + end + + it 'provides an array of the integer values' do + IntegerValuesEnumTest.integer_values.should eq([ 1, 2, 5 ]) + end + end + context 'when coercing from enum' do subject { Test::StatusType::PENDING } it { should eq(0) } From 58eafd19570089585b48ecbe70c6a82fb32b6c75 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 12 Nov 2013 16:11:09 -0700 Subject: [PATCH 0537/1191] Extract spec/support proto building to rake task, call from spec_helper --- Rakefile | 12 +++++++++++- spec/spec_helper.rb | 5 +---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index e29f0219..222a46c3 100644 --- a/Rakefile +++ b/Rakefile @@ -12,4 +12,14 @@ desc "Default: run specs." task :default => :spec desc "Run specs" -RSpec::Core::RakeTask.new(:spec) +::RSpec::Core::RakeTask.new(:spec) + +namespace :spec do + desc "Compile Test Protos in spec/supprt/" + task :compile_test_protos do |task, args| + proto_path = ::File.expand_path('../spec/support/', __FILE__) + cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + puts cmd + exec cmd + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb2e2cd7..77ad8971 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,10 +31,7 @@ c.before(:suite) do unless ENV['NO_COMPILE_TEST_PROTOS'] $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - proto_path = File.expand_path("../support/", __FILE__) - cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} - puts cmd - %x{#{cmd}} + ::Rake::Task['spec:compile_test_protos'] end end end From 34427ec44b11a13b9853d1bc3665456539b41631 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 12 Nov 2013 16:12:17 -0700 Subject: [PATCH 0538/1191] Add support for generating enum's with `option allow_alias = true` --- lib/protobuf/generators/enum_generator.rb | 13 ++++++++++++- spec/lib/protobuf/enum_spec.rb | 2 +- spec/support/test/enum.pb.rb | 12 ++++++++++++ spec/support/test/enum.proto | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 6bd5e692..100ca76f 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -4,18 +4,29 @@ module Protobuf module Generators class EnumGenerator < Base + def allow_alias? + descriptor.options.try(:allow_alias!) { false } + end + def compile run_once(:compile) do tags = [] print_class(descriptor.name, :enum) do + if allow_alias? + puts "option :allow_alias => true" + puts + end + descriptor.value.each do |enum_value_descriptor| tags << enum_value_descriptor.number puts build_value(enum_value_descriptor) end end - self.class.validate_tags(fully_qualified_type_namespace, tags) + unless allow_alias? + self.class.validate_tags(fully_qualified_type_namespace, tags) + end end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index f3ec64fc..ac7fa603 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -53,7 +53,7 @@ end describe '.name_by_value' do - it 'get the name by value of the enum given the enum' do + it 'get the name by value of the enum given the enum' do Test::EnumTestType.name_by_value(::Test::EnumTestType::THREE).should eq name end diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index 43f2105e..f736e861 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -19,6 +19,15 @@ class EnumTestType < ::Protobuf::Enum define :TWO, 2 end + class AliasedEnum < ::Protobuf::Enum + option :allow_alias => true + + define :THREE, 3 + define :TRES, 3 + define :FOUR, 4 + define :CUATRO, 4 + end + ## # Message Classes @@ -33,6 +42,9 @@ class EnumTestMessage optional ::Test::EnumTestType, :non_default_enum, 1 optional ::Test::EnumTestType, :default_enum, 2, :default => ::Test::EnumTestType::ONE repeated ::Test::EnumTestType, :repeated_enums, 3 + optional ::Test::AliasedEnum, :alias_non_default_enum, 4 + optional ::Test::AliasedEnum, :alias_default_enum, 5, :default => ::Test::AliasedEnum::CUATRO + repeated ::Test::AliasedEnum, :alias_repeated_enums, 6 end diff --git a/spec/support/test/enum.proto b/spec/support/test/enum.proto index 35a11531..e0624937 100644 --- a/spec/support/test/enum.proto +++ b/spec/support/test/enum.proto @@ -8,10 +8,25 @@ enum EnumTestType { TWO = 2; } +// Uses aliases +enum AliasedEnum { + option allow_alias = true; + + THREE = 3; + TRES = 3; + + FOUR = 4; + CUATRO = 4; +} + message EnumTestMessage { optional EnumTestType non_default_enum = 1; optional EnumTestType default_enum = 2 [default=ONE]; repeated EnumTestType repeated_enums = 3; + + optional AliasedEnum alias_non_default_enum = 4; + optional AliasedEnum alias_default_enum = 5 [default=CUATRO]; + repeated AliasedEnum alias_repeated_enums = 6; } extend test.Resource { From 6bced25bb18512fa3917657b5b754af1d3f7bbb0 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 13 Nov 2013 15:15:50 -0700 Subject: [PATCH 0539/1191] Bind broadcast socket to the frontend ip This will ensure that the beacons get broadcast through the interface that the clients are listening on. --- lib/protobuf/rpc/servers/zmq/server.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 93edae11..ddc71f59 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -33,10 +33,6 @@ def add_worker @total_workers = total_workers + 1 end - def backend_ip - frontend_ip - end - def backend_port options[:worker_port] || frontend_port + 1 end @@ -106,6 +102,7 @@ def brokerless? def frontend_ip @frontend_ip ||= resolve_ip(options[:host]) end + alias_method :backend_ip, :frontend_ip def frontend_port options[:port] @@ -170,7 +167,7 @@ def run yield if block_given? # runs on startup wait_for_shutdown_signal - broadcast_flatline if broadcast_beacons? + broadcast_flatline if broadcast_beacons? Thread.pass until reap_dead_workers.empty? @broker.join unless brokerless? ensure @@ -248,6 +245,13 @@ def wait_for_shutdown_signal def init_beacon_socket @beacon_socket = UDPSocket.new @beacon_socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true) + @beacon_socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true) + + if defined?(::Socket::SO_REUSEPORT) + @beacon_socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, true) + end + + @beacon_socket.bind(frontend_ip, beacon_port) @beacon_socket.connect(beacon_ip, beacon_port) end From dd0748cf2e060c8a6322c6bff229450241d60412 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 14 Nov 2013 13:37:12 -0700 Subject: [PATCH 0540/1191] Add Optionable module to provide option setting support for Enum --- lib/protobuf/generators/enum_generator.rb | 2 +- lib/protobuf/optionable.rb | 23 ++++++++++ .../generators/enum_generator_spec.rb | 25 +++++++++- spec/lib/protobuf/optionable_spec.rb | 46 +++++++++++++++++++ spec/spec_helper.rb | 2 + spec/support/test/enum.pb.rb | 2 +- 6 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 lib/protobuf/optionable.rb create mode 100644 spec/lib/protobuf/optionable_spec.rb diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 100ca76f..90b70221 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -14,7 +14,7 @@ def compile print_class(descriptor.name, :enum) do if allow_alias? - puts "option :allow_alias => true" + puts "set_option :allow_alias" puts end diff --git a/lib/protobuf/optionable.rb b/lib/protobuf/optionable.rb new file mode 100644 index 00000000..964884e9 --- /dev/null +++ b/lib/protobuf/optionable.rb @@ -0,0 +1,23 @@ +require 'active_support/concern' + +module Protobuf + module Optionable + extend ::ActiveSupport::Concern + + module ClassMethods + def get_option(name) + @_optionable_options.try(:[], name) + end + + def set_option(name, value = true) + @_optionable_options ||= {} + @_optionable_options[name] = value + end + end + + def get_option(name) + self.class.get_option(name) + end + + end +end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index c1534415..9d7048f5 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -11,8 +11,10 @@ { :name => 'BAZ', :number => 3 } ] } + let(:options) { nil } let(:enum_fields) { { :name => 'TestEnum', - :value => values } } + :value => values, + :options => options } } let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) } @@ -33,6 +35,27 @@ subject.compile subject.to_s.should eq(compiled) end + + context 'when allow_alias option is set' do + let(:compiled) { + %q{class TestEnum < ::Protobuf::Enum + set_option :allow_alias + + define :FOO, 1 + define :BAR, 2 + define :BAZ, 3 +end + +} + } + + let(:options) { { :allow_alias => true } } + + it 'sets the allow_alias option' do + subject.compile + subject.to_s.should eq(compiled) + end + end end describe '#build_value' do diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb new file mode 100644 index 00000000..6de32c34 --- /dev/null +++ b/spec/lib/protobuf/optionable_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' +require 'protobuf/optionable' + +describe 'Optionable' do + + describe '.set_option' do + before(:all) do + OptionableSetOptionTest = ::Class.new do + include ::Protobuf::Optionable + end + end + + it 'stores the given option and value' do + expect(OptionableSetOptionTest).to respond_to(:set_option) + expect(OptionableSetOptionTest.method(:set_option).arity).to eq(-2) + expect { + OptionableSetOptionTest.set_option(:foo, :bar) + }.to_not raise_error + end + + it 'defaults the value to true' do + OptionableSetOptionTest.set_option(:baz_enabled) + expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_true + end + end + + describe '.get_option' do + before(:all) do + OptionableGetOptionTest = ::Class.new do + include ::Protobuf::Optionable + set_option :foo, :bar + end + end + + it 'retrieves the option for the given name, if any' do + expect(OptionableGetOptionTest.get_option(:foo)).to eq(:bar) + expect(OptionableGetOptionTest.get_option(:baz)).to be_nil + end + + it 'retrieves the option in the context of an instance' do + expect(OptionableGetOptionTest.new.get_option(:foo)).to eq(:bar) + expect(OptionableGetOptionTest.new.get_option(:baz)).to be_nil + end + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 77ad8971..40528c60 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,6 +30,8 @@ c.before(:suite) do unless ENV['NO_COMPILE_TEST_PROTOS'] + require 'rake' + load ::File.expand_path('../../Rakefile', __FILE__) $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' ::Rake::Task['spec:compile_test_protos'] end diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index f736e861..aa5c7b34 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -20,7 +20,7 @@ class EnumTestType < ::Protobuf::Enum end class AliasedEnum < ::Protobuf::Enum - option :allow_alias => true + set_option :allow_alias define :THREE, 3 define :TRES, 3 From 979cb909b3b9dc4d0ee348e5612f95c5dddc5e82 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 14 Nov 2013 13:37:42 -0700 Subject: [PATCH 0541/1191] Use Enum.fetch instead of custom coercion outside of Enum class --- lib/protobuf/field/enum_field.rb | 10 +--------- lib/protobuf/rpc/connectors/common.rb | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index a2999f35..2a27c486 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -4,15 +4,7 @@ module Protobuf module Field class EnumField < VarintField def acceptable?(val) - case val - when Symbol then - raise TypeError, "Enum #{val} is not known for type #{@type}" unless @type.const_defined?(val) - when EnumValue then - raise TypeError, "Enum #{val} is not owned by #{@type}" if val.parent_class != @type - else - raise TypeError, "Tag #{val} is not valid for Enum #{@type}" unless @type.valid_tag?(val) - end - true + ! @type.fetch(val).nil? end def encode(value) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index e31a0820..c26187ae 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -40,7 +40,7 @@ def data_callback(data) # @param [String] message The error message def fail(code, message) @error = ClientError.new - @error.code = code.is_a?(Symbol) ? Protobuf::Socketrpc::ErrorReason.values[code] : code + @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message log_debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } From ff310c81e9cf60ea09f8b71e8a4c09d619864a40 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 14 Nov 2013 13:42:56 -0700 Subject: [PATCH 0542/1191] First cut at an Enum API refactor == Aliases Extend Optionable module to get class-level option management. This allows us to support the allow_alias protobuf option in libprotoc v2.5.0. Adds methods to return an array of EnumValue objects corresponding to a given number "value". == "Value" The term "value" is used to mean multiple things in the Enum implementation: 1) an EnumValue object, and 2) an integer commonly called a tag number. This cut attempts to use the term "number" for arguments when the arg should be number-like, and use the term `enum_value` in methods and comments when we are referencing the actual object type. All method name changes are aliased to their old names. Ideally EnumValue would not be separate from Enum. I'm not willing to make that cut here, possibly in a future API refactor cut. --- lib/protobuf/enum.rb | 203 ++++++++++++++++++++++++++++----- spec/lib/protobuf/enum_spec.rb | 144 +++++++++++++++++------ 2 files changed, 283 insertions(+), 64 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index ec2b3d38..454fc5eb 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,62 +1,207 @@ require 'protobuf/enum_value' +require 'protobuf/optionable' module Protobuf class Enum + # Public: Allows setting Options on the Enum class. + include ::Protobuf::Optionable + def self.aliases_allowed? + self.get_option(:allow_alias) + end + + # Public: Get an array of EnumValue objects with the given value. + # + # number - An object that responds to to_i. + # + # Returns an array with zero or more EnumValue objects or nil. + # + def self.all_enum_values_by_value(number) + self.enum_values.values.select do |enum_value| + enum_value.to_i == number.to_i + end + end + + # Public: Get all integer tag values defined by this enum. + # + # Examples + # + # class StateMachine < ::Protobuf::Enum + # set_option :allow_alias + # define :ON, 1 + # define :STARTED, 1 + # define :OFF, 2 + # end + # + # StateMachine.all_values #=> [ 1, 2 ] + # + # Returns an array of unique integers. + # + def self.all_values + self.enum_values.values.map(&:to_i).uniq + end + + # Internal: DSL method to define a protobuf EnumValue. The given name will + # become a constant for this Enum which points to an EnumValue object. + # + # Examples + # + # class StateMachine < ::Protobuf::Enum + # define :ON, 1 + # define :OFF, 2 + # end + # StateMachine::ON #=> # + # StateMachine::OFF #=> # + # + # Returns nothing. + # def self.define(name, value) enum_value = ::Protobuf::EnumValue.new(self, name, value) + @enum_values ||= {} + @enum_values[name] = enum_value const_set(name, enum_value) - @values ||= {} - @names ||= {} - @values[name] = enum_value - @names[value] = name end - # Fetch the given enum by a variety of type-checking - # mechanisms. This is useful for the enum field setters - # as well as repeated enum field construction. + # Public: Get the EnumValue associated with the given name. + # + # name - An object that responds to to_sym. Case-sensitive. + # + # Example + # + # class StateMachine < ::Protobuf::Enum + # define :ON, 1 + # define :OFF, 2 + # end + # + # StateMachine.enum_value_by_name(:ON) # => # + # StateMachine.enum_value_by_name("ON") # => # + # StateMachine.enum_value_by_name(:on) # => nil + # StateMachine.enum_value_by_name(:FOO) # => nil + # + # Returns the EnumValue object with the given name. `nil` will be returned + # if the given name does not have a correlating value. + # + def self.enum_value_by_name(name) + self.const_get(name.to_sym) + rescue NameError, NoMethodError + nil + end + + # Public: Get the EnumValue object corresponding to the given number. + # + # number - An object that responds to to_i. + # + # Returns an EnumValue object or nil. If the number corresponds to multiple + # EnumValue objects an array of EnumValue objects will be returned. + # + def self.enum_value_by_value(number) + enum_value_by_name(name_by_value(number)) + end + + # Public: The internal values hash. + # + def self.enum_values + @enum_values + end + + # Public: Get an EnumValue by a variety of type-checking mechanisms. + # + # value - An EnumValue, Numeric, String, or Symbol object. + # + # Example + # + # class StateMachine < ::Protobuf::Enum + # set_option :allow_alias + # define :ON, 1 + # define :STARTED, 1 + # define :OFF, 2 + # end + # + # StateMachine.fetch(StateMachine::ON) # => # + # StateMachine.fetch(:ON) # => # + # StateMachine.fetch("http://github.com/STARTED") # => # + # StateMachine.fetch(1) # => [ #, # ] + # + # Returns an EnumValue object or nil. + # def self.fetch(value) case value when ::Protobuf::EnumValue then value when Numeric then - enum_by_value(value.to_i) + enum_value_by_value(value.to_i) when String, Symbol then - value_by_name(value.to_sym) + enum_value_by_name(value.to_sym) else nil end end - def self.enum_by_value(value) - value_by_name(name_by_value(value)) - end - - def self.integer_values - self.values.values.map(&:to_i) - end - - def self.name_by_value(value) - (!value.nil? && value.respond_to?(:to_i)) ? @names[value.to_i] : nil - end - - def self.valid_tag?(tag) - !! name_by_value(tag) - end - - def self.value_by_name(name) - @values[name] + # Public: Get the Symbol name associated with the given number. + # + # number - An object that responds to to_i. + # + # Examples + # + # # Without aliases + # class StateMachine < ::Protobuf::Enum + # define :ON, 1 + # define :OFF, 2 + # end + # + # StateMachine.name_by_value(1) # => :ON + # StateMachine.name_by_value(2) # => :OFF + # StateMachine.name_by_value(3) # => nil + # + # # With aliases + # class StateMachine < ::Protobuf::Enum + # set_option :allow_alias + # define :STARTED, 1 + # define :ON, 1 + # define :OFF, 2 + # end + # + # StateMachine.name_by_value(1) # => :STARTED + # StateMachine.name_by_value(2) # => :OFF + # + # Returns the symbol name of the enum constant given it's associated value. + # If the given value has multiple names associated (due to allow_alias) + # the first defined name will be returned. `nil` will be returned when + # the given value does not have a correlating name. + # + def self.name_by_value(number) + self.enum_values.values.detect { |enum_value| + enum_value.to_i == number.to_i + }.try(:name) end - def self.values - @values + # Public: Check if the given tag value is defined by this Enum. + # See name_by_value. + # + # number - An object that responds to to_i. + # + # Returns a boolean. + # + def self.valid_value?(number) + !! name_by_value(number) end ## # Class Aliases # class << self + # Deprecated: + alias_method :valid_tag?, :valid_value? + + # Deprecated: + alias_method :values, :enum_values + + # Deprecated: Alias of name_by_value. alias_method :get_name_by_tag, :name_by_value + + # Deprecated: Alias of enum_value_by_value. + alias_method :value_by_name, :enum_value_by_value end + end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index ac7fa603..3e6ea762 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -9,103 +9,176 @@ Test::EnumTestType.define(:THREE, 3) end + before(:all) do + EnumAliasTest = ::Class.new(::Protobuf::Enum) do + set_option :allow_alias + define :FOO, 1 + define :BAR, 1 + define :BAZ, 2 + end + end + + describe '.aliases_allowed?' do + it 'is false when the option is not set' do + expect(Test::EnumTestType.aliases_allowed?).to be_false + end + end + + describe '.all_enum_values_by_value' do + it 'returns an array of EnumValues for the given tag' do + expect(EnumAliasTest.all_enum_values_by_value(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) + expect(EnumAliasTest.all_enum_values_by_value(2)).to eq([ EnumAliasTest::BAZ ]) + expect(EnumAliasTest.all_enum_values_by_value(3)).to eq([]) + end + end + describe '.define' do it 'defines a constant enum value on the parent class' do - Test::EnumTestType.constants.should include(name) - Test::EnumTestType::THREE.should be_a(Protobuf::EnumValue) + expect(Test::EnumTestType.constants).to include(name) + expect(Test::EnumTestType::THREE).to be_a(Protobuf::EnumValue) + end + + context 'when enum allows aliases' do + before(:all) do + DefineEnumAlias = ::Class.new(::Protobuf::Enum) do + set_option :allow_alias + end + end + + it 'allows defining enum values with the same tag number' do + expect { + DefineEnumAlias.define(:FOO, 1) + DefineEnumAlias.define(:BAR, 1) + }.not_to raise_error + end end end describe '.fetch' do context 'when value is an EnumValue' do it 'responds with that object' do - Test::EnumTestType.fetch(Test::EnumTestType::THREE).name.should eq Test::EnumTestType::THREE.name + expect(Test::EnumTestType.fetch(Test::EnumTestType::THREE)).to eq(Test::EnumTestType::THREE) end end context 'when value can be coerced to a symbol' do it 'fetches based on the symbol name value' do - Test::EnumTestType.fetch("http://github.com/ONE").should eq Test::EnumTestType::ONE - Test::EnumTestType.fetch(:ONE).should eq Test::EnumTestType::ONE + expect(Test::EnumTestType.fetch("http://github.com/ONE")).to eq(Test::EnumTestType::ONE) + expect(Test::EnumTestType.fetch(:ONE)).to eq(Test::EnumTestType::ONE) end end context 'when value can be coerced to an integer' do it 'fetches based on the integer tag value' do - Test::EnumTestType.fetch(3.0).should eq Test::EnumTestType::THREE - Test::EnumTestType.fetch(3).should eq Test::EnumTestType::THREE + expect(Test::EnumTestType.fetch(3.0)).to eq(Test::EnumTestType::THREE) + expect(Test::EnumTestType.fetch(3)).to eq(Test::EnumTestType::THREE) + end + + context 'when enum allows aliases' do + it 'fetches the first defined EnumValue' do + expect(EnumAliasTest.fetch(1)).to eq(EnumAliasTest::FOO) + end end end context 'when value is not an applicable type' do it 'returns a nil' do - Test::EnumTestType.fetch(Test::Resource.new).should be_nil - Test::EnumTestType.fetch(nil).should be_nil - Test::EnumTestType.fetch(false).should be_nil + expect(Test::EnumTestType.fetch(Test::Resource.new)).to be_nil + expect(Test::EnumTestType.fetch(nil)).to be_nil + expect(Test::EnumTestType.fetch(false)).to be_nil end end end - describe '.enum_by_value' do + describe '.enum_value_by_value' do it 'gets the EnumValue corresponding to the given value (tag)' do - Test::EnumTestType.enum_by_value(tag).should eq Test::EnumTestType.const_get(name) + expect(Test::EnumTestType.enum_value_by_value(tag)).to eq(Test::EnumTestType.const_get(name)) end end describe '.name_by_value' do it 'get the name by value of the enum given the enum' do - Test::EnumTestType.name_by_value(::Test::EnumTestType::THREE).should eq name + expect(Test::EnumTestType.name_by_value(::Test::EnumTestType::THREE)).to eq(name) end it 'gets the name of the enum corresponding to the given value (tag)' do - Test::EnumTestType.name_by_value(tag).should eq name + expect(Test::EnumTestType.name_by_value(tag)).to eq(name) + end + + it 'gets the name when the tag is coercable to an int' do + expect(Test::EnumTestType.name_by_value("3")).to eq(name) + end + + it 'returns nil when tag does not correspond to a name' do + expect(Test::EnumTestType.name_by_value(12345)).to be_nil end context 'when given name is nil' do it 'returns a nil' do - Test::EnumTestType.name_by_value(nil).should be_nil + expect(Test::EnumTestType.name_by_value(nil)).to be_nil + end + end + + context 'when enum allows aliases' do + it 'returns the first defined name for that value' do + expect(EnumAliasTest.name_by_value(1)).to eq(:FOO) end end end - describe '.valid_tag?' do + describe '.valid_value?' do context 'when tag is defined' do - specify { Test::EnumTestType.valid_tag?(tag).should be_true } + specify { expect(Test::EnumTestType.valid_value?(tag)).to be_true } end context 'when tag is not defined' do - specify { Test::EnumTestType.valid_tag?(300).should be_false } + specify { expect(Test::EnumTestType.valid_value?(300)).to be_false } + end + + context 'when enum allows aliases' do + it 'treats aliased values as valid' do + expect(EnumAliasTest.valid_value?(1)).to be_true + end end end - describe '.value_by_name' do + describe '.enum_value_by_name' do it 'gets the EnumValue corresponding to the given name' do - Test::EnumTestType.value_by_name(name).should eq Test::EnumTestType::THREE + expect(Test::EnumTestType.enum_value_by_name(name)).to eq(Test::EnumTestType::THREE) end end - describe '.values' do - it 'provides a hash of defined EnumValues' do - Test::EnumTestType.values.should eq({ + describe '.enum_values' do + it 'provides a hash of defined EnumValue objects' do + expect(Test::EnumTestType.values).to eq({ :MINUS_ONE => Test::EnumTestType::MINUS_ONE, - :ONE => Test::EnumTestType::ONE, - :TWO => Test::EnumTestType::TWO, - :THREE => Test::EnumTestType::THREE + :ONE => Test::EnumTestType::ONE, + :TWO => Test::EnumTestType::TWO, + :THREE => Test::EnumTestType::THREE }) end - end - describe '.integer_values' do - before do - IntegerValuesEnumTest = ::Class.new(::Protobuf::Enum) do - define :FOO, 1 - define :BAR, 2 - define :BAZ, 5 + context 'when enum allows aliases' do + + it 'treats aliased values as valid' do + expect(EnumAliasTest.enum_values).to eq({ + :FOO => EnumAliasTest::FOO, + :BAR => EnumAliasTest::BAR, + :BAZ => EnumAliasTest::BAZ + }) end end + end + describe '.all_values' do it 'provides an array of the integer values' do - IntegerValuesEnumTest.integer_values.should eq([ 1, 2, 5 ]) + expect(Test::EnumTestType.all_values).to include(-1, 1, 2, 3) + end + + context 'when enum allows aliases' do + it 'returns a unique array of all defined enum values' do + expect(EnumAliasTest.all_values).to include(1, 2) + end end end @@ -115,6 +188,7 @@ end context 'when coercing from integer' do - specify { 0.should eq(Test::StatusType::PENDING) } + specify { expect(0).to eq(Test::StatusType::PENDING) } end + end From a67bcc47c163e71f94b241350d30b4eee178d189 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 14 Nov 2013 15:07:35 -0700 Subject: [PATCH 0543/1191] Bump version 2.8.8 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b9057fa6..5213f1e7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +2.8.8 +--------- + +- ServiceDirectory beacons broadcast on same ip as listening clients. [#133, @devin-c] + 2.8.7 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 44ef15f0..22fd7f05 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.7' + VERSION = '2.8.8' PROTOC_VERSION = '2.5.0' end From a560c3c3ab932c9b421addd8e95aa5d14cd172d4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 31 Jan 2014 09:11:27 -0700 Subject: [PATCH 0544/1191] Add gitter chat badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ee140706..72282c41 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) +[![Gitter chat](https://badges.gitter.im/localshred/protobuf.png)](https://gitter.im/localshred/protobuf) ___See [CHANGES.md](https://github.com/localshred/protobuf/blob/master/CHANGES.md) or [Release Notes](https://github.com/localshred/protobuf/releases) for significant version changes.___ From c91a8997a5997357d80246eff00462455b3db874 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 3 Feb 2014 18:19:46 -0700 Subject: [PATCH 0545/1191] Replace custom lifecycle with AS::Notifications --- lib/protobuf.rb | 1 + lib/protobuf/cli.rb | 3 +- lib/protobuf/lifecycle.rb | 38 ------- lib/protobuf/rpc/service_directory.rb | 3 +- spec/lib/protobuf/cli_spec.rb | 4 +- spec/lib/protobuf/lifecycle_spec.rb | 100 ------------------ .../protobuf/rpc/service_directory_spec.rb | 7 +- spec/support/test/google_unittest.pb.rb | 2 - 8 files changed, 8 insertions(+), 150 deletions(-) delete mode 100644 lib/protobuf/lifecycle.rb delete mode 100644 spec/lib/protobuf/lifecycle_spec.rb diff --git a/lib/protobuf.rb b/lib/protobuf.rb index a0c53441..8d6081df 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -4,6 +4,7 @@ require 'stringio' require 'active_support/core_ext/object/blank' require 'active_support/version' +require 'active_support/notifications' if ActiveSupport::VERSION::MAJOR > 2 require 'active_support/core_ext/object/try' diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index b973e434..c1dba849 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,6 +1,5 @@ require 'thor' require 'protobuf/version' -require 'protobuf/lifecycle' require 'protobuf/logger' require 'protobuf/rpc/servers/evented_runner' require 'protobuf/rpc/servers/socket_runner' @@ -244,7 +243,7 @@ def start_server "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" } - ::Protobuf::Lifecycle.trigger( "after_server_bind" ) + ::ActiveSupport::Notifications.instrument( "after_server_bind") end end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb deleted file mode 100644 index e0082307..00000000 --- a/lib/protobuf/lifecycle.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Protobuf - class Lifecycle - - def self.register( event_name, &blk ) - raise "Lifecycle register must have a block" unless block_given? - event_name = normalized_event_name( event_name ) - - lifecycle_events[ event_name ] ||= [] - lifecycle_events[ event_name ] << blk - end - - def self.trigger( event_name, *args ) - event_name = normalized_event_name( event_name ) - - if lifecycle_events.has_key?( event_name ) - lifecycle_events[ event_name ].each do |block| - if ! args.empty? && block.arity != 0 - block.call(*args) - else - block.call - end - end - end - end - - def self.normalized_event_name( event_name ) - return "#{event_name}".downcase - end - - class << self - attr_accessor :lifecycle_events - - alias_method :on, :register - end - - @lifecycle_events ||= {} - end -end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 0bd75a88..bc7874d4 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -5,7 +5,6 @@ require 'thread' require 'timeout' -require 'protobuf/lifecycle' require 'protobuf/rpc/dynamic_discovery.pb' module Protobuf @@ -239,7 +238,7 @@ def run end def trigger(action, listing) - ::Protobuf::Lifecycle.trigger("directory.listing.#{action}", listing) + ::ActiveSupport::Notifications.instrument("directory.listing.#{action}", :listing => listing) end end end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index e58f4bf0..3ed68e01 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -9,13 +9,13 @@ let(:sock_runner) { runner = double("SocketRunner", :register_signals => nil) - runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } + runner.stub(:run) { ::ActiveSupport::Notifications.publish( "after_server_bind" ) } runner } let(:zmq_runner) { runner = double "ZmqRunner", register_signals: nil - runner.stub(:run) { ::Protobuf::Lifecycle.trigger( "after_server_bind" ) } + runner.stub(:run) { ::ActiveSupport::Notifications.publish( "after_server_bind" ) } runner } diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb deleted file mode 100644 index e889ce82..00000000 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -require 'spec_helper' -require 'protobuf/lifecycle' - -describe ::Protobuf::Lifecycle do - subject { described_class } - - before(:each) do - described_class.lifecycle_events = {} - end - - it "registers a string as the event_name" do - expect { - subject.register("something") do - true - end - }.to change { subject.lifecycle_events.size }.by(1) - end - - it "registers a symbol as the event_name" do - expect { - subject.register("something") do - true - end - }.to change { subject.lifecycle_events.size }.by(1) - end - - it "only registers blocks for event callbacks" do - expect { - subject.register("something") - }.to raise_error( /block/ ) - end - - it "calls the registered block when triggered" do - this = nil - subject.register("this") do - this = "not nil" - end - - subject.trigger("this") - this.should_not be_nil - this.should eq("not nil") - end - - it "calls multiple registered blocks when triggered" do - this = nil - that = nil - - subject.register("this") do - this = "not nil" - end - - subject.register("this") do - that = "not nil" - end - - subject.trigger("this") - this.should_not be_nil - this.should eq("not nil") - that.should_not be_nil - that.should eq("not nil") - end - - context 'when the registered block has arity' do - context 'and the triggered event does not have args' do - it 'does not pass the args' do - outer_bar = nil - - subject.register('foo') do |bar| - bar.should be_nil - outer_bar = 'triggered' - end - - subject.trigger('foo') - outer_bar.should eq 'triggered' - end - end - - context 'and the triggered event has arguments' do - it 'does not pass the args' do - outer_bar = nil - - subject.register('foo') do |bar| - bar.should_not be_nil - outer_bar = bar - end - - subject.trigger('foo', 'baz') - outer_bar.should eq 'baz' - end - end - end - - context "normalized event names" do - specify { subject.normalized_event_name(:derp).should eq("derp") } - specify { subject.normalized_event_name(:Derp).should eq("derp") } - specify { subject.normalized_event_name("DERP").should eq("derp") } - specify { subject.normalized_event_name("derp").should eq("derp") } - end - -end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 9cc5d8b8..c7bae230 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -56,10 +56,9 @@ end def expect_event_trigger(event) - ::Protobuf::Lifecycle - .should_receive(:trigger) - .with(event, - an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing)) + ::ActiveSupport::Notifications + .should_receive(:instrument) + .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))) .once end diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index 8cd4c32c..b41bcc50 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - ## # This file is auto-generated. DO NOT EDIT! # From e37622895b4280fc3e7c31d94b157438c6fe03a8 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Feb 2014 12:39:52 -0700 Subject: [PATCH 0546/1191] Revert unintended change Not sure why this got deleted. It was not intentional --- spec/support/test/google_unittest.pb.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index b41bcc50..8cd4c32c 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # From aabd92f20aab6ee44e0dd701368d9193453caaea Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Feb 2014 14:42:47 -0700 Subject: [PATCH 0547/1191] Provide a friendly transition path This will warn users that Lifecycle events are being deprecated in favor of active support notifications. --- lib/protobuf/lifecycle.rb | 43 ++++++++++++++ spec/lib/protobuf/lifecycle_spec.rb | 89 +++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 lib/protobuf/lifecycle.rb create mode 100644 spec/lib/protobuf/lifecycle_spec.rb diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb new file mode 100644 index 00000000..56267ecd --- /dev/null +++ b/lib/protobuf/lifecycle.rb @@ -0,0 +1,43 @@ +module Protobuf + class Lifecycle + include ::Protobuf::Logger::LogMethods + + def self.register( event_name, &blk ) + raise "Lifecycle register must have a block" unless block_given? + + event_name = normalized_event_name( event_name ) + + log_warn { + message = "Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.subscribe('#{event_name}')" + sign_message(message) + } + + ::ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, args| + blk.call(*args) + end + end + + def self.trigger( event_name, *args ) + log_warn { + message = "Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.instrument(...)" + sign_message(message) + } + + event_name = normalized_event_name( event_name ) + + ::ActiveSupport::Notifications.instrument(event_name, args) + end + + def self.normalized_event_name( event_name ) + return "#{event_name}".downcase + end + + class << self + attr_accessor :lifecycle_events + + alias_method :on, :register + end + + @lifecycle_events ||= {} + end +end diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb new file mode 100644 index 00000000..f40a5fb2 --- /dev/null +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -0,0 +1,89 @@ +require 'spec_helper' +require 'protobuf/lifecycle' + +describe ::Protobuf::Lifecycle do + subject { described_class } + + before(:each) do + ::ActiveSupport::Notifications.notifier = ::ActiveSupport::Notifications::Fanout.new + end + + it "registers a string as the event_name" do + ::ActiveSupport::Notifications.should_receive(:subscribe).with("something") + subject.register("something") { true } + end + + it "only registers blocks for event callbacks" do + expect { + subject.register("something") + }.to raise_error( /block/ ) + end + + it "calls the registered block when triggered" do + this = nil + subject.register("this") do + this = "not nil" + end + + subject.trigger("this") + this.should_not be_nil + this.should eq("not nil") + end + + it "calls multiple registered blocks when triggered" do + this = nil + that = nil + + subject.register("this") do + this = "not nil" + end + + subject.register("this") do + that = "not nil" + end + + subject.trigger("this") + this.should_not be_nil + this.should eq("not nil") + that.should_not be_nil + that.should eq("not nil") + end + + context 'when the registered block has arity' do + context 'and the triggered event does not have args' do + it 'does not pass the args' do + outer_bar = nil + + subject.register('foo') do |bar| + bar.should be_nil + outer_bar = 'triggered' + end + + subject.trigger('foo') + outer_bar.should eq 'triggered' + end + end + + context 'and the triggered event has arguments' do + it 'does not pass the args' do + outer_bar = nil + + subject.register('foo') do |bar| + bar.should_not be_nil + outer_bar = bar + end + + subject.trigger('foo', 'baz') + outer_bar.should eq 'baz' + end + end + end + + context "normalized event names" do + specify { subject.normalized_event_name(:derp).should eq("derp") } + specify { subject.normalized_event_name(:Derp).should eq("derp") } + specify { subject.normalized_event_name("DERP").should eq("derp") } + specify { subject.normalized_event_name("derp").should eq("derp") } + end + +end From e48d533492d8d01f6927b36c46acf8cd313520e7 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Feb 2014 14:57:16 -0700 Subject: [PATCH 0548/1191] Make deprecation warnings more visible --- lib/protobuf/lifecycle.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 56267ecd..d0d93e15 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -8,7 +8,7 @@ def self.register( event_name, &blk ) event_name = normalized_event_name( event_name ) log_warn { - message = "Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.subscribe('#{event_name}')" + message = "[DEPRECATED] Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.subscribe('#{event_name}')" sign_message(message) } @@ -19,7 +19,7 @@ def self.register( event_name, &blk ) def self.trigger( event_name, *args ) log_warn { - message = "Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.instrument(...)" + message = "[DEPRECATED] Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.instrument(...)" sign_message(message) } From ecf736153cc8c41bfc5d811b8900a228adb95369 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Feb 2014 15:14:11 -0700 Subject: [PATCH 0549/1191] Fix whitespace error --- lib/protobuf/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index c1dba849..3af746d8 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -243,7 +243,7 @@ def start_server "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" } - ::ActiveSupport::Notifications.instrument( "after_server_bind") + ::ActiveSupport::Notifications.instrument("after_server_bind") end end end From b17149cce797774bcde9973da62811146da0e1e2 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 4 Feb 2014 16:35:02 -0700 Subject: [PATCH 0550/1191] Use $stderr to print deprecation warnings --- lib/protobuf/lifecycle.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index d0d93e15..5f5afd3c 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -7,10 +7,12 @@ def self.register( event_name, &blk ) event_name = normalized_event_name( event_name ) - log_warn { - message = "[DEPRECATED] Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.subscribe('#{event_name}')" - sign_message(message) - } + if ::Protobuf.print_deprecation_warnings? + $stderr.puts <<-ERROR + [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. + Use ::ActiveSupport::Notifications.subscribe('#{event_name}') + ERROR + end ::ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, args| blk.call(*args) @@ -18,10 +20,12 @@ def self.register( event_name, &blk ) end def self.trigger( event_name, *args ) - log_warn { - message = "[DEPRECATED] Lifecycle events have been deprecated. Use ::ActiveSupport::Notifications.instrument(...)" - sign_message(message) - } + if ::Protobuf.print_deprecation_warnings? + $stderr.puts <<-ERROR + [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. + Use ::ActiveSupport::Notifications.instrument(...) + ERROR + end event_name = normalized_event_name( event_name ) From 4a885778a5a6ca55d9387bdfd4f0aaa36ecae25e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 3 Feb 2014 16:13:50 -0700 Subject: [PATCH 0551/1191] Modify $LOAD_PATH in lib/protobuf/descriptors so that other plugins may use the descriptors in their own protoc-gen-foo compilers --- bin/protoc-gen-ruby | 11 +---------- lib/protobuf/descriptors.rb | 3 +++ 2 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 lib/protobuf/descriptors.rb diff --git a/bin/protoc-gen-ruby b/bin/protoc-gen-ruby index 37441c33..71e0be47 100755 --- a/bin/protoc-gen-ruby +++ b/bin/protoc-gen-ruby @@ -7,16 +7,7 @@ ENV['PB_NO_NETWORKING'] = '1' $LOAD_PATH << ::File.expand_path("../../lib", __FILE__) require 'protobuf' - -# Setup the loadpath so that plugin.pb will -# be able to require the descriptor.pb file. -# -$LOAD_PATH << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) -require 'google/protobuf/compiler/plugin.pb' - -# Read the request bytes from STDIN, pass to the CodeGenerator, and -# write to STDOUT the generated response_bytes. -# +require 'protobuf/descriptors' require 'protobuf/code_generator' request_bytes = STDIN.read diff --git a/lib/protobuf/descriptors.rb b/lib/protobuf/descriptors.rb new file mode 100644 index 00000000..947e41ec --- /dev/null +++ b/lib/protobuf/descriptors.rb @@ -0,0 +1,3 @@ +$LOAD_PATH << ::File.expand_path("../descriptors", __FILE__) +require 'google/protobuf/descriptor.pb' +require 'google/protobuf/compiler/plugin.pb' From dd0e394143021813f27968823967ca1df9c5feb4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 10:40:55 -0700 Subject: [PATCH 0552/1191] Add console task for development funsies --- Rakefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Rakefile b/Rakefile index e29f0219..42050c32 100644 --- a/Rakefile +++ b/Rakefile @@ -13,3 +13,10 @@ task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new(:spec) + +task :console do + require 'pry' + require 'protobuf' + ARGV.clear + ::Pry.start +end From 10d3208b79d49edbe5df5ec97ad1b0c069fe22c9 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 10:47:24 -0700 Subject: [PATCH 0553/1191] Add protobuf:compile rake task for external use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `protobuf:compile` task can be utilized in any project or gem that uses protobuf. Open up the Rakefile of the including project and add: ```ruby require ‘protobuf/tasks’ ``` The `compile` task accepts three arguments: package, source, and destination. Package does not have a default value and must be specified. Source’s default is ‘defintitions’. Destination’s default is `lib`. Plugin’s default is `ruby`, and is overridable in case you want to utilize the descriptors to make your own plugin generator. The composed command to protoc is printed to the terminal and then the process is exec’d with that command. --- lib/protobuf/tasks.rb | 1 + lib/protobuf/tasks/compile.rake | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 lib/protobuf/tasks.rb create mode 100644 lib/protobuf/tasks/compile.rake diff --git a/lib/protobuf/tasks.rb b/lib/protobuf/tasks.rb new file mode 100644 index 00000000..2a5b8052 --- /dev/null +++ b/lib/protobuf/tasks.rb @@ -0,0 +1 @@ +load 'protobuf/tasks/compile.rake' diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake new file mode 100644 index 00000000..202e258d --- /dev/null +++ b/lib/protobuf/tasks/compile.rake @@ -0,0 +1,26 @@ +namespace :protobuf do + + desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' + task :compile, [ :package, :source, :destination, :plugin ] do |tasks, args| + args.with_defaults(:destination => 'lib') + args.with_defaults(:source => 'definitions') + args.with_defaults(:plugin => 'ruby') + + unless do_not_clean? + force_clean! + ::Rake::Task[:clean].invoke(args[:package], args[:destination]) + end + + command = [] + command << "protoc" + command << "--#{args[:plugin]}_out=#{args[:destination]}" + command << "-I #{args[:source]}" + command << "#{args[:source]}/#{args[:package]}/*.proto" + command << "#{args[:source]}/#{args[:package]}/**/*.proto" + full_command = command.join(' ') + + puts full_command + exec(full_command) + end + +end From 7d3acb72d87ab14c2c70f16d488b53e5ee06d033 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 10:49:53 -0700 Subject: [PATCH 0554/1191] Add protobuf:clean task for external use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To get this task simply `require ‘protobuf/tasks’` in your Rakefile. Clean will ask for confirmation of removing previously compiled pb.rb source files. You can skip the confirmation step by providing PB_FORCE_CLEAN=1. A force clean is automatically invoked from the `compile` task unless PB_NO_CLEAN=1 is specified. The package argument must be specified. The destination argument defaults to `lib`. --- lib/protobuf/tasks/compile.rake | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index 202e258d..b40a32de 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -1,3 +1,5 @@ +require 'fileutils' + namespace :protobuf do desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' @@ -23,4 +25,34 @@ namespace :protobuf do exec(full_command) end + desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' + task :clean, [ :package, :destination ] do |task, args| + args.with_defaults(:destination => 'lib') + + files_to_clean = ::File.join(args[:destination], args[:package], '**', '*.pb.rb') + + if force_clean? || permission_to_clean?(files_to_clean) + ::Dir.glob(files_to_clean).each do |file| + ::FileUtils.rm(file) + end + end + end + + def do_not_clean? + ! ::ENV.key?('PB_NO_CLEAN') + end + + def force_clean? + ::ENV.key?('PB_FORCE_CLEAN') + end + + def force_clean! + ::ENV['PB_FORCE_CLEAN'] = '1' + end + + def permission_to_clean?(files_to_clean) + puts "Do you really want to remove files matching pattern #{files_to_clean}? (y/n)" + ::STDIN.gets.chomp =~ /y(es)?/i + end + end From fe9fd76283ce69e658c360165b20a4ca78fe3242 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 13:24:28 -0700 Subject: [PATCH 0555/1191] Change README to reference the github wiki for installation and usage --- README.md | 470 ++---------------------------------------------------- 1 file changed, 16 insertions(+), 454 deletions(-) diff --git a/README.md b/README.md index ee140706..a99ce639 100644 --- a/README.md +++ b/README.md @@ -2,468 +2,30 @@ [![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) - -___See [CHANGES.md](https://github.com/localshred/protobuf/blob/master/CHANGES.md) or [Release Notes](https://github.com/localshred/protobuf/releases) for significant version changes.___ +[![Gitter chat](https://badges.gitter.im/localshred/protobuf.png)](https://gitter.im/localshred/protobuf) Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. ---- - ## Install -You will need to install protobuf from your favorite package manager -or from source. This gem currently supports protobuf <= 2.5.0. - -### OSX Install - -```shell -$ brew install protobuf -``` - -### Ubuntu -```shell -$ sudo apt-get install -y protobuf -``` - -### Gem Install - -Once the protobuf package is installed, install this gem with rubygems/bundler. -_Please note that this will void your warranty as it were. If you compiled with -a custom protobuf package and are having issues it may be difficult to troubleshoot._ - -```shell -$ gem install protobuf -``` - ------- - -## Generating ruby classes from `.proto` files - -Protocol Buffers are great because they allow you to clearly define data storage -or data transfer packets. Google officially supports Java, C++, and Python for -compilation and usage. Let's make it ruby aware! - -Let's say you have a `defs.proto` file that defines a User message. - -```protobuf -package foo; -message User { - optional string first_name = 1; - optional string last_name = 2; -} -``` - -Now let's compile that definition to ruby: - -```shell -$ protoc defs.proto --ruby_out ./lib -``` - -The previous line will take whatever is defined in `defs.proto` and -output ruby classes to the `./lib` directory, obeying the package -directive. Your `./lib` should now look like this: - -``` -- lib - |- foo - |- defs.pb.rb -``` - -The generated file `defs.pb.rb` should look something like this: - -```ruby -module Foo - class User < ::Protobuf::Message; end - - class User - optional ::Protobuf::Field::StringField, :first_name, 1 - optional ::Protobuf::Field::StringField, :last_name, 2 - end -end -``` - -__Note:__ The generator will pre-define all message/enum classes empty and then -re-open to apply the defined fields. This is to prevent field dependency errors. - -The generated class is now just a plain old ruby object. You can use it however you wish. - -```ruby -require 'lib/foo/user.pb' - -# dot notation reading/writing fields -user = Foo::User.new -user.first_name = "Lloyd" -user.last_name = "Christmas" -user.first_name # => "Lloyd" - -# or pass in the fields as a hash to the initializer -user = Foo::User.new :first_name => "Lloyd", :last_name => "Christmas" -user.first_name # => Lloyd -user.last_name # => Christmas -``` - -### Message (de)serialization - -Every message object comes ready for serialization or deserialization. -Use `serialize_to_string` to write out the byte-string for the message. -Use `parse_from_string` on a new message instance to inflate the -byte-string back to a message in ruby. - -```ruby -user = Foo::User.new(:first_name => 'Bob') -bytes = user.serialize_to_string -puts bytes #=> binary representation of this message object - -inflated_user = Foo::User.new.parse_from_string(bytes) -inflated_user == user #=> true -``` - -## Callings Services with RPC - -Google's Protocol Buffers provides support for Services with RPC. - -For our purposes, we'll talk about a `Client` (process that is calling -the server/service), a `Service` (the remote procedure), and a `Server` -(the process that manages one or more services). We'll start with the Service first. - -### Services - -Services are simply classes that have endpoint methods defined. Here's what -one looks like in protobuf: - -```protobuf -package foo; -message UserRequest { - optional string email = 1; -} -message UserList { - repeated User users = 1; -} -service UserService { - rpc Find (UserRequest) returns (UserList); -} -``` - -And the equivalent ruby stub for the service (generated with `rprotoc`): - -```ruby -# lib/foo/user.pb.rb -module Foo - # UserRequest and UserList Class definitions not shown (see above for generated output of classes). - - class UserService < ::Protobuf::Rpc::Service - rpc :find, UserRequest, UserList - end -end -``` - -__Important Note: The UserService class here is a *stub*. You should not -provide your implementation in this generated file as subsequent generations -will wipe out your implmentation. Read on to learn how to use this stub.__ - -Now that you have a generated service stub, you'll want to require it -from `lib` and provide the implementation. Create a service implementation file -in your project. In rails I'd put this in `app/services/foo/user_service.rb`. - -```ruby -# app/services/foo/user_service.rb -require 'lib/foo/user.pb' - -# Reopen the class and provide the implementation for each rpc method defined. -module Foo - class UserService - - # request -> Foo::UserRequest - # response -> Foo::UserResponse - def find - # request.email will be the unpacked string that was sent by the client request - users = [] - User.find_by_email(request.email).each do |user| - users << user.to_proto - end - - respond_with(:users => users) - end - - end -end -``` - -Simply implement the instance method for the defined rpc. You can provide -any other methods in this class as helpers, but only those defined in the -proto file will be callable by remote clients. Every request made by a client -will provide a non-empty request of the defined type. The server creates a new -service instance for every request, so you should not be constrained to just -the endpoint method. This is similar to rails controllers where only methods -defined by the routes file are hooked up to HTTP requests, but it's very common -to implement private methods to aid in code quality and simpilicity. - -Every instance has a `request` and `response` object used for fulfilling the call, -again, similar to a rails controller action. You should never attempt to modify the -`request` object. The `response` object however should be modified or replaced -entirely. If you need to create your own response object (a valid case), simply use -`respond_with(new_response)`. The returned object should conform to one of three properties: - -1. Response should be of same type as defined by the rpc definition (in this case, `Foo::UserList`), or -2. Response should be a hash, respond to `to_hash`, or respond to `to_proto_hash`. The hash will be used to construct an instance of the defined type and should therefore conform to the appropriate fields for that type. -3. Response should respond to the `to_proto` method. The object returned by `to_proto` should be an instance of the defined response type. - -If at any time the implementation encounters an error, the client can be -instructed of the error using `rpc_failed`: - -```ruby -#... -def find - if request.email.blank? - rpc_failed 'Unable to find user without an email' - else - # query/populate response - end -end -#... -``` - -This means that the client's `on_failure` callback will be invoked instead -of the `on_success` callback. Read more below on client callbacks. One drawback -to the `rpc_failed` approach is that it does not short-circuit the rest of -the method. This means that you must explicitly return from the method if -you do not wish the remainder to be executed. - -### Service Filters - -Service Filters provides ActionController-style filter support to service -instances, specifically adding `before_filter`, `after_filter`, and `around_filter`. - -```ruby -require 'lib/foo/user.pb' - -class Foo::UserService - before_filter :start_request_timer - after_filter :end_request_timer - around_filter :benchmark_request - - # Provide a list of rpc methods to call (or exclude calling) for the given filter(s). - # The following two filters are essentially equivalent. - before_filter :verify_user_present, :only => [ :update, :delete ] - before_filter :verify_user_present, :except => [ :find, :create ] - - # Using if/unless filters options to achieve the same goal, reporting a login after the login has been processed. - # Note that you can provide a method name or lambda, but you must return a boolean value. - after_filter :report_login, :only => :login, :if => :user_found? - after_filter :report_login, :only => :login, :if => lambda { |service| service.response.user_guid.present? } - after_filter :report_login, :only => :login, :unless => :user_missing? - after_filter :report_login, :only => :login, :unless => lambda { |service| service.response.user_guid.empty? } - - #... rpc instance methods - - private - - def start_request_timer - @time_start = Time.now - end - - def end_request_timer - @time_end = Time.now - log_info { ... } - end - - def benchmark_request - Benchmark.benchmark do - yield - end - end -end -``` - -#### Halting execution of rpc request inside a filter - -__Around Filters__ – Inside of an around filter, if you wish to halt -request processing and return, simply do not `yield` the block. Since the -filter is implemented as an instance method, you can use `rpc_failed` -or `respond_with` just like you can in the endpoint methods. - -__Before Filters__ – Returning `false` from a before filter will cancel -any other filter calls which would run afterwards, as well as canceling -invocation of the service method. _Note: You must actually return `false`, -not just a "falsey" value such as `nil`._ - -__After Filters__ – No request shortcutting. - -#### Filter options - -The following options can be applied to any of the filters as the final -argument in the filter configuration. (See example above). - -__:if__ – The object supplied to `:if` can either be a symbol/string -indicating the instance method to call, or, an object that responds to `call`. -The method or callable should return true or false indicating if the -filter should be invoked or not. Akin to the `if` keyword. - -__:unless__ – The opposite of the `:if` option is `:unless`. Accepts -the same object types. The method or callable should return true or -false indicating if the filter should be invoked or not. Akin to the -`unless` keyword. - -__:only__ – A string/symbol or Array of strings/symbols values that -reference instance methods. The names of these methods should be the -rpc method you wish to invoke the filter for. Methods not identified -in this list would not have the filter applied. - -__:except__ – The opposite of the `:only` option. A string/symbol or -Array of strings/symbols values that reference instance methods. The -names of these methods should be the rpc method you wish to skip -invokation of the given filter. Methods not identified in this list -would have the filter applied. - -### Servers - -Services need to be hooked up to a socket to be called by clients. -Use the provided program `rpc_server`: - -``` -$ rpc_server -o myserver.com -p 9399 -l ./log/protobuf.log ./config/environment.rb -``` - -The previous call will start a Socket server running on the given -host and port which will load your application into memory. You -certainly don't have to run rails or any other framework, just -make sure you have some kind of file that will load your services -all into memory. The server doesn't know where you put your code, -so tell it. - -Be aware that the server needs to be able to translate the socket -stream of bytes into an actual protobuf request object. If the -definition for that request object aren't known to the server, -you're going to have a long day getting this going. It's necessary -to store all your definitions and their generated classes in a -shared repository (read: gem) so that both client and server have -access to the ruby classes in their respective load paths. - -Once the server starts, you should see it as a running process -with `ps`. Sending a KILL, QUIT, or TERM signal to the pid will -result in shutting the server down gracefully. - -``` -$ ps aux | grep rpc_server -1234 ... rpc_server myserver.com:9399 - -$ kill -QUIT 1234 -rpc_server shutdown -``` - -### Clients - -Calling a service with a clients feels very ajaxy. If you prefer -a simpler syntax I highly recommend using [ActiveRemote](https://github.com/liveh2o/active_remote) -which was developed in conjunction with this library to make -interacting with a remote service feel identical to using an -ActiveRecord model. Seriously, it's wicked cool. - -```ruby -# require the defs from the shared gem/repo -require 'sharedgem/foo/user.pb' - -# Create a request object for the method we are invoking -req = Foo::UserRequest.new(:email => 'jeff@gmail.com') - -# Use the UserService class to generate a client, invoke the rpc method -# while passing the request object. -# We could also simply pass a hash to find. -Foo::UserService.client.find(req) do |client| - # This block will be executed (registering the callbacks) - # before the request actualy occurs. - # the `client` param in this block is the object - # that is created by `Foo::UserService.client`. - - # Register a block for execution when the response - # is deemed successful from the service. Accepts - # the unpacked response as its only parameter. - c.on_success do |response| - response.users.each do |user| - puts user.inspect - end - end - - # Register a block for execution when the response - # is deemed a failure. This can be either a client-side - # or server-side failure. The object passed to the - # block has a `message` and a `code` attribute - # to aid in logging/diagnosing the failure. - c.on_failure do |error| - puts 'It failed: ' + error.message - end -end -``` - -Many different options can be passed to the `.client` call above -(such as `:timeout => 600`). See the `lib/protobuf/rpc/client.rb` -and `lib/protobuf/rpc/service.rb` files for more documentation. - -### Dynamic Service Discovery (ZMQ Only) -It is possible to setup the RPC server and client in a way that -allows servers/services to be dynamically discovered by client processes. - -#### In the client -```ruby -ServiceDirectory.start do |config| - config.port = 53000 -end - -# If your server also runs this code, it will default to the -# given port when sending beacons and have its own service -# directory. You can prevent this code from running on the -# server if needed: -unless defined?(::Protobuf::CLI) - ServiceDirectory.start do |config| - config.port = 53000 - end -end -``` - -#### Starting the server with dynamic discovery enabled -``` -$ rpc_server --broadcast-beacons --beacon-port 53000 ... -``` - -The client will listen on the specified port for beacons broadcast -by servers. Each beacon includes a list of services provided by the -broadcasting server. The client randomly selects a server for the -desired service each time a request is made. - -__CAUTION:__ When running multiple environments on a single network, -e.g., qa and staging, be sure that each environment is setup with -a unique beacon port; otherwise, clients in one environment ___will___ -make requests to servers in the other environment. - -Check out the source for Protobuf::ServiceDirectory for more details. - -## 3. RPC Interop - -The main reason I wrote this gem was to provide a ruby implementation -to google's protobuf that worked on the RPC layer with a Java Service -layer that was already running [protobuf-socket-rpc][], the supported -socket rpc library for protobuf from Google. Other ruby protobuf -implementations I've used did not provide this kind of support. +See our [Installation Guide][] on the [wiki][]. -## Accreditation & Caveats +## Usage -It must be noted that this gem was started originally as a fork of -the [ruby-protobuf][old gem] gem. Its authors and I were unable to -reach a communication point to be able to merge all of my RPC updates -in with their master. Unfortunately I just simply couldn't use their -RPC code and so I forked the code. Myself and others have significantly -changed the internals of the gem, including the rpc implementation, the -message/field implementation, and the compiler implementation. These -changes were made to address glaring performance and quality issues -in the code. The code was initially diverged at their 0.4.0 version. +The [wiki][] contains in-depth guides on the various ways to use this gem +including [compiling defintions][], [object APIs][], [services][], [clients][], and even +an [API roadmap][]. -It should also be noted that there are many more features I haven't -really shown here, so please let me know if you have any questions -on usage or support for various features. Happy protobufing. +## Changelog --- BJ Neilsen, [@localshred][] +See recent changes in the [release notes][] or the [changelog][]. [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" - [protobuf-socket-rpc]: http://code.google.com/p/protobuf-socket-rpc/ "Google's official Socket-RPC library for protobuf" - [old gem]: https://github.com/macks/ruby-protobuf "Macks ruby-protobuf on github" - [@localshred]: http://twitter.com/localshred "Follow on twitter @localshred" + [wiki]: https://github.com/localshred/protobuf/wiki/Protobuf-Wiki "Protobuf Wiki" + [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling definitions" + [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs" + [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API" + [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API" + [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap" + [release notes]: https://github.com/localshred/protobuf/releases "CHANGES.md" + [changelog]: https://github.com/localshred/protobuf/blob/master/CHANGES.md "CHANGES.md" From d52e8ba99c5d486b7c0a10c534ac1116f4b4510b Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 13:25:22 -0700 Subject: [PATCH 0556/1191] Bump version 2.8.9 --- CHANGES.md | 7 +++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 5213f1e7..c7ae20fa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +2.8.9 +--------- + +- Deprecated Protobuf::Lifecycle module in favor of using ActiveSupport::Notifications. [#139, @devin-c] +- 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] +- Add protobuf:clean and protobuf:compile rake tasks for use in external libraries to compile source definitions to a destination. [#142, @localshred] + 2.8.8 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 22fd7f05..3b235bfa 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.8' + VERSION = '2.8.9' PROTOC_VERSION = '2.5.0' end From a710643d8ad2b489758794ea9acc259d02819b62 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 13:31:09 -0700 Subject: [PATCH 0557/1191] Fix link references in README --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a99ce639..5b8df262 100644 --- a/README.md +++ b/README.md @@ -13,19 +13,20 @@ See our [Installation Guide][] on the [wiki][]. ## Usage The [wiki][] contains in-depth guides on the various ways to use this gem -including [compiling defintions][], [object APIs][], [services][], [clients][], and even +including [compiling definitions][], [object APIs][], [services][], [clients][], and even an [API roadmap][]. ## Changelog See recent changes in the [release notes][] or the [changelog][]. - [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" - [wiki]: https://github.com/localshred/protobuf/wiki/Protobuf-Wiki "Protobuf Wiki" + [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" + [wiki]: https://github.com/localshred/protobuf/wiki/Protobuf-Wiki "Protobuf Wiki" + [Installation Guide]: https://github.com/localshred/protobuf/wiki/Installation "Protobuf Wiki" [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling definitions" - [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs" - [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API" - [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API" - [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap" - [release notes]: https://github.com/localshred/protobuf/releases "CHANGES.md" - [changelog]: https://github.com/localshred/protobuf/blob/master/CHANGES.md "CHANGES.md" + [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs" + [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API" + [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API" + [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap" + [release notes]: https://github.com/localshred/protobuf/releases "CHANGES.md" + [changelog]: https://github.com/localshred/protobuf/blob/master/CHANGES.md "CHANGES.md" From 1c247424e532e83027c2ff458031511a90ed42d7 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 13:38:19 -0700 Subject: [PATCH 0558/1191] Reference 2-8-stable branch in CONTRIBUTING.md guide --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1a8af7d8..4cc6d5dd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,11 +6,11 @@ your code merged. 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. 2. For __compiler issues__, please provide both a gist for the __source definition(s)__ as well as the __generated output__ (if any). -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`. -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. +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`. +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. 5. Be patient with me as I work on your issue. Following these simple guidelines really will help me help you. And really, -that's what we're here for. :) +that's what we're here for. I'm on @localshred on twitter, let's be friends. :) ## Happy Contributing! From c4575fee3ec21945c44222c34fa936f07bcec19a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 13:44:37 -0700 Subject: [PATCH 0559/1191] Update README url to the wiki --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5b8df262..3e0e7ead 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,12 @@ an [API roadmap][]. See recent changes in the [release notes][] or the [changelog][]. [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" - [wiki]: https://github.com/localshred/protobuf/wiki/Protobuf-Wiki "Protobuf Wiki" - [Installation Guide]: https://github.com/localshred/protobuf/wiki/Installation "Protobuf Wiki" - [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling definitions" - [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs" - [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API" - [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API" - [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap" - [release notes]: https://github.com/localshred/protobuf/releases "CHANGES.md" + [wiki]: https://github.com/localshred/protobuf/wiki "Wiki home page" + [Installation Guide]: https://github.com/localshred/protobuf/wiki/Installation "Installation guide" + [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling guide" + [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs guide" + [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API guide" + [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API guide" + [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap guide" + [release notes]: https://github.com/localshred/protobuf/releases "Release notes" [changelog]: https://github.com/localshred/protobuf/blob/master/CHANGES.md "CHANGES.md" From 9931c30389295311de143b8b5415009dd4742377 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 13:44:37 -0700 Subject: [PATCH 0560/1191] Update README url to the wiki --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5b8df262..3e0e7ead 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,12 @@ an [API roadmap][]. See recent changes in the [release notes][] or the [changelog][]. [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" - [wiki]: https://github.com/localshred/protobuf/wiki/Protobuf-Wiki "Protobuf Wiki" - [Installation Guide]: https://github.com/localshred/protobuf/wiki/Installation "Protobuf Wiki" - [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling definitions" - [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs" - [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API" - [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API" - [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap" - [release notes]: https://github.com/localshred/protobuf/releases "CHANGES.md" + [wiki]: https://github.com/localshred/protobuf/wiki "Wiki home page" + [Installation Guide]: https://github.com/localshred/protobuf/wiki/Installation "Installation guide" + [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling guide" + [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs guide" + [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API guide" + [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API guide" + [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap guide" + [release notes]: https://github.com/localshred/protobuf/releases "Release notes" [changelog]: https://github.com/localshred/protobuf/blob/master/CHANGES.md "CHANGES.md" From a42e06c4e70090901649902958feda592c4f8203 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 14:22:16 -0700 Subject: [PATCH 0561/1191] Allow passing a file extension to the compile and clean rake tasks Allows external gems to use these tasks by specifying the types of files they intend on generating, such as `.h` or `.myaweomseplugin.rb`. The default is of course `.pb.rb` as that is the extension of files generated from this library. --- lib/protobuf/tasks/compile.rake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index b40a32de..756fdc44 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -3,14 +3,15 @@ require 'fileutils' namespace :protobuf do desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' - task :compile, [ :package, :source, :destination, :plugin ] do |tasks, args| + task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |tasks, args| args.with_defaults(:destination => 'lib') args.with_defaults(:source => 'definitions') args.with_defaults(:plugin => 'ruby') + args.with_defaults(:file_extension => '.pb.rb') unless do_not_clean? force_clean! - ::Rake::Task[:clean].invoke(args[:package], args[:destination]) + ::Rake::Task[:clean].invoke(args[:package], args[:destination], args[:file_extension]) end command = [] @@ -26,10 +27,12 @@ namespace :protobuf do end desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' - task :clean, [ :package, :destination ] do |task, args| + task :clean, [ :package, :destination, :file_extension ] do |task, args| args.with_defaults(:destination => 'lib') + args.with_defaults(:file_extension => '.pb.rb') - files_to_clean = ::File.join(args[:destination], args[:package], '**', '*.pb.rb') + file_extension = args[:file_extension].sub(/\*?\.+/, '') + files_to_clean = ::File.join(args[:destination], args[:package], '**', "*.#{file_extension}") if force_clean? || permission_to_clean?(files_to_clean) ::Dir.glob(files_to_clean).each do |file| From 49238fba2ae1e8817396b985d3edeea514aadf18 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 6 Feb 2014 14:25:18 -0700 Subject: [PATCH 0562/1191] Bump version 2.8.10 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c7ae20fa..08515050 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +2.8.10 +--------- + +- Allow passing a file extension to compile/clean rake tasks. [#143, @localshred] + 2.8.9 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 3b235bfa..910a4597 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.9' + VERSION = '2.8.10' PROTOC_VERSION = '2.5.0' end From f52b2eb1300f1cb8f13bc683698957814901499c Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Sun, 9 Feb 2014 14:49:25 -0700 Subject: [PATCH 0563/1191] Check busy workers before broadcasting heartbeats. --- lib/protobuf/rpc/servers/zmq/server.rb | 20 ++++++++++++++++++-- lib/protobuf/rpc/servers/zmq/worker.rb | 2 ++ lib/protobuf/rpc/servers/zmq_runner.rb | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 93edae11..7d8d0bc9 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -12,7 +12,8 @@ class Server DEFAULT_OPTIONS = { :beacon_interval => 5, - :broadcast_beacons => false + :broadcast_beacons => false, + :broadcast_busy => false } attr_accessor :options, :workers @@ -33,6 +34,10 @@ def add_worker @total_workers = total_workers + 1 end + def all_workers_busy? + workers.all? { |thread| !!thread.thread_variable_get(:busy) } + end + def backend_ip frontend_ip end @@ -103,6 +108,10 @@ def brokerless? !!options[:workers_only] end + def busy_worker_count + workers.all? { |thread| !!thread.thread_variable_get(:busy) } + end + def frontend_ip @frontend_ip ||= resolve_ip(options[:host]) end @@ -239,7 +248,14 @@ def wait_for_shutdown_signal start_missing_workers end - broadcast_heartbeat if broadcast_heartbeat? + if broadcast_heartbeat? + if all_workers_busy? && options[:broadcast_busy] + broadcast_flatline + else + broadcast_heartbeat + end + end + end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 964f823d..5be2fb51 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -51,8 +51,10 @@ def run break if rc == -1 if rc > 0 + ::Thread.current.thread_variable_set(:busy, true) initialize_request! process_request + ::Thread.current.thread_variable_set(:busy, false) end end ensure diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 95cf90d2..ca70cf0d 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -43,6 +43,7 @@ def register_signals trap(:TTOU) do log_info { "Current worker size: #{@server.workers.size}" } + log_info { "Current worker size: #{@server.busy_worker_count}" } end end end From f72852e4aabe7b015182451c35dda2ecc0ac17f2 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 10 Feb 2014 18:55:58 -0700 Subject: [PATCH 0564/1191] add ability to use inproc instead of tcp for server-broker-worker which enables zero-copy messaging --- lib/protobuf/cli.rb | 1 + lib/protobuf/rpc/servers/zmq/broker.rb | 10 +++++++++- lib/protobuf/rpc/servers/zmq/server.rb | 24 +++++++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3af746d8..e7fb79a7 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -37,6 +37,7 @@ class CLI < ::Thor option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' option :workers_only, :type => :boolean, :default => false, :desc => "Starts process with only workers (no broker/frontend is started) only relevant for Zmq Server" option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)" + option :zmq_inproc, :type => :boolean, :default => true, :desc => 'Use inproc protocol for zmq Server/Broker/Worker' def start(app_file) debug_say('Configuring the rpc_server process') diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 492ef44d..36ea0c58 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -64,7 +64,15 @@ def init_poller end def init_zmq_context - @zmq_context = ZMQ::Context.new + if inproc? + @zmq_context = ::Protobuf::Rpc::Zmq::Server.zmq_context + else + @zmq_context = ZMQ::Context.new + end + end + + def inproc? + @server.try(:inproc?) end def process_backend diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index ddc71f59..db3df2f3 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -12,11 +12,17 @@ class Server DEFAULT_OPTIONS = { :beacon_interval => 5, - :broadcast_beacons => false + :broadcast_beacons => false, + :zmq_inproc => true } attr_accessor :options, :workers + # Share zmq_context when using inproc + def self.zmq_context + @zmq_context ||= ZMQ::Context.new + end + def initialize(options) @options = DEFAULT_OPTIONS.merge(options) @workers = [] @@ -38,7 +44,11 @@ def backend_port end def backend_uri - "tcp://#{backend_ip}:#{backend_port}" + if inproc? + "inproc://#{backend_ip}:#{backend_port}" + else + "tcp://#{backend_ip}:#{backend_port}" + end end def beacon_interval @@ -260,7 +270,15 @@ def init_shutdown_pipe end def init_zmq_context - @zmq_context = ZMQ::Context.new + if inproc? + @zmq_context = self.class.zmq_context + else + @zmq_context = ZMQ::Context.new + end + end + + def inproc? + !!self.options[:zmq_inproc] end def start_broker From 2b905a3d5aed0e9b821ddc79f11d96c3d11dd911 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 10 Feb 2014 19:06:47 -0700 Subject: [PATCH 0565/1191] still use an instance context and make it avail to broker/worker and make inproc? public --- lib/protobuf/rpc/servers/zmq/broker.rb | 4 ++-- lib/protobuf/rpc/servers/zmq/server.rb | 20 ++++++-------------- lib/protobuf/rpc/servers/zmq/worker.rb | 10 +++++++++- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 36ea0c58..34ed5c1e 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -65,14 +65,14 @@ def init_poller def init_zmq_context if inproc? - @zmq_context = ::Protobuf::Rpc::Zmq::Server.zmq_context + @zmq_context = @server.zmq_context else @zmq_context = ZMQ::Context.new end end def inproc? - @server.try(:inproc?) + !!@server.try(:inproc?) end def process_backend diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index db3df2f3..2acd61f2 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -17,11 +17,7 @@ class Server } attr_accessor :options, :workers - - # Share zmq_context when using inproc - def self.zmq_context - @zmq_context ||= ZMQ::Context.new - end + attr_reader :zmq_context def initialize(options) @options = DEFAULT_OPTIONS.merge(options) @@ -122,6 +118,10 @@ def frontend_uri "tcp://#{frontend_ip}:#{frontend_port}" end + def inproc? + !!self.options[:zmq_inproc] + end + def maintenance_timeout next_maintenance - Time.now.to_i end @@ -270,15 +270,7 @@ def init_shutdown_pipe end def init_zmq_context - if inproc? - @zmq_context = self.class.zmq_context - else - @zmq_context = ZMQ::Context.new - end - end - - def inproc? - !!self.options[:zmq_inproc] + @zmq_context = ZMQ::Context.new end def start_broker diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 964f823d..7729410f 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -74,7 +74,11 @@ def send_data private def init_zmq_context - @zmq_context = ZMQ::Context.new + if inproc? + @zmq_context = @server.zmq_context + else + @zmq_context = ZMQ::Context.new + end end def init_backend_socket @@ -82,6 +86,10 @@ def init_backend_socket zmq_error_check(@backend_socket.connect(@server.backend_uri)) end + def inproc? + !!@server.try(:inproc?) + end + def read_from_backend frames = [] zmq_error_check(@backend_socket.recv_strings(frames)) From 1cb799ff724f2812b7a9731ad583f3181e7a9a54 Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Mon, 10 Feb 2014 20:36:04 -0700 Subject: [PATCH 0566/1191] Fix busy_worker_count. --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index cb338cb8..56466362 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -105,7 +105,7 @@ def brokerless? end def busy_worker_count - workers.all? { |thread| !!thread.thread_variable_get(:busy) } + workers.count { |thread| !!thread.thread_variable_get(:busy) } end def frontend_ip From 040aa4698b8e49f10d24c219fdf52b9f1f3fda8e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 10 Feb 2014 20:40:06 -0700 Subject: [PATCH 0567/1191] default inproc to true --- lib/protobuf/rpc/servers/zmq/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 2272b638..9e5cbd55 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -13,8 +13,8 @@ class Server DEFAULT_OPTIONS = { :beacon_interval => 5, :broadcast_beacons => false, - :zmq_inproc => true - :broadcast_busy => false + :broadcast_busy => false, + :zmq_inproc => true, } attr_accessor :options, :workers From f1a97d329b687132de5c471725b8c9bed9f71078 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 10 Feb 2014 20:44:03 -0700 Subject: [PATCH 0568/1191] put broadcast_busy in cli options --- lib/protobuf/cli.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index e7fb79a7..f0ad47e8 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -32,6 +32,7 @@ class CLI < ::Thor option :beacon_interval, :type => :numeric, :desc => 'Broadcast beacons every N seconds. (default: 5)' option :beacon_port, :type => :numeric, :desc => 'Broadcast beacons to this port (default: value of ServiceDirectory.port)' option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' + option :broadcast_busy, :type => :boolean, :default => false, :desc => 'Remove busy nodes from cluster when all workers are busy (Currently only available with ZeroMQ).' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' From 67cd34f3056a81214366a45889576cd7bf0b61a5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 10 Feb 2014 20:48:32 -0700 Subject: [PATCH 0569/1191] bump to 2.8.11 --- CHANGES.md | 8 ++++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 08515050..f6633d39 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +2.8.11 +--------- + +- Default ZMQ server to use inproc protocol instead of tcp (zero-copy between server-broker-worker) +- Add 'broadcast_busy' functionality that removes server from cluster if the workers are full +- Add cli option for --no-zmq_inproc +- Add cli option for --broadcast_busy + 2.8.10 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 910a4597..03144183 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.10' + VERSION = '2.8.11' PROTOC_VERSION = '2.5.0' end From 7e4f9dc8d7d1881cf3e9c10ddd156df6edcad648 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 11 Feb 2014 11:12:58 -0700 Subject: [PATCH 0570/1191] Rename enum methods from value -> number --- lib/protobuf/enum.rb | 16 ++++++++-------- spec/lib/protobuf/enum_spec.rb | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 454fc5eb..b3a80267 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -10,13 +10,13 @@ def self.aliases_allowed? self.get_option(:allow_alias) end - # Public: Get an array of EnumValue objects with the given value. + # Public: Get an array of EnumValue objects with the given number. # # number - An object that responds to to_i. # # Returns an array with zero or more EnumValue objects or nil. # - def self.all_enum_values_by_value(number) + def self.all_enum_values_by_number(number) self.enum_values.values.select do |enum_value| enum_value.to_i == number.to_i end @@ -33,12 +33,12 @@ def self.all_enum_values_by_value(number) # define :OFF, 2 # end # - # StateMachine.all_values #=> [ 1, 2 ] + # StateMachine.all_numbers #=> [ 1, 2 ] # # Returns an array of unique integers. # - def self.all_values - self.enum_values.values.map(&:to_i).uniq + def self.all_numbers + @all_numbers ||= self.enum_values.values.map(&:to_i).uniq end # Internal: DSL method to define a protobuf EnumValue. The given name will @@ -64,7 +64,7 @@ def self.define(name, value) # Public: Get the EnumValue associated with the given name. # - # name - An object that responds to to_sym. Case-sensitive. + # name - A string-like object. Case-sensitive. # # Example # @@ -82,7 +82,7 @@ def self.define(name, value) # if the given name does not have a correlating value. # def self.enum_value_by_name(name) - self.const_get(name.to_sym) + self.const_get(name) rescue NameError, NoMethodError nil end @@ -131,7 +131,7 @@ def self.fetch(value) when Numeric then enum_value_by_value(value.to_i) when String, Symbol then - enum_value_by_name(value.to_sym) + enum_value_by_name(value) else nil end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 3e6ea762..53c4b7bd 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -24,11 +24,11 @@ end end - describe '.all_enum_values_by_value' do + describe '.all_enum_values_by_number' do it 'returns an array of EnumValues for the given tag' do - expect(EnumAliasTest.all_enum_values_by_value(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) - expect(EnumAliasTest.all_enum_values_by_value(2)).to eq([ EnumAliasTest::BAZ ]) - expect(EnumAliasTest.all_enum_values_by_value(3)).to eq([]) + expect(EnumAliasTest.all_enum_values_by_number(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) + expect(EnumAliasTest.all_enum_values_by_number(2)).to eq([ EnumAliasTest::BAZ ]) + expect(EnumAliasTest.all_enum_values_by_number(3)).to eq([]) end end @@ -170,14 +170,14 @@ end end - describe '.all_values' do + describe '.all_numbers' do it 'provides an array of the integer values' do - expect(Test::EnumTestType.all_values).to include(-1, 1, 2, 3) + expect(Test::EnumTestType.all_numbers).to include(-1, 1, 2, 3) end context 'when enum allows aliases' do it 'returns a unique array of all defined enum values' do - expect(EnumAliasTest.all_values).to include(1, 2) + expect(EnumAliasTest.all_numbers).to include(1, 2) end end end From 9144a9f7654792373495a80078b3645b6478114f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 11 Feb 2014 11:22:24 -0700 Subject: [PATCH 0571/1191] add backwards compat for busy and Thread --- lib/protobuf/rpc/servers/zmq/server.rb | 5 +++-- lib/protobuf/rpc/servers/zmq/worker.rb | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 9e5cbd55..51a5d1ae 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -3,6 +3,7 @@ require 'protobuf/rpc/servers/zmq/broker' require 'protobuf/rpc/dynamic_discovery.pb' require 'securerandom' +require 'thread' module Protobuf module Rpc @@ -37,7 +38,7 @@ def add_worker end def all_workers_busy? - workers.all? { |thread| !!thread.thread_variable_get(:busy) } + workers.all? { |thread| !!thread[:busy] } end def backend_port @@ -111,7 +112,7 @@ def brokerless? end def busy_worker_count - workers.count { |thread| !!thread.thread_variable_get(:busy) } + workers.count { |thread| !!thread[:busy] } end def frontend_ip diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 18a1c38f..0ae08203 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -1,5 +1,6 @@ require 'protobuf/rpc/server' require 'protobuf/rpc/servers/zmq/util' +require 'thread' module Protobuf module Rpc @@ -51,10 +52,10 @@ def run break if rc == -1 if rc > 0 - ::Thread.current.thread_variable_set(:busy, true) + ::Thread.current[:busy] = true initialize_request! process_request - ::Thread.current.thread_variable_set(:busy, false) + ::Thread.current[:busy] = false end end ensure From faeb34f558fe7ac6b248b917829cbbdf7b82f4d1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 11 Feb 2014 11:29:28 -0700 Subject: [PATCH 0572/1191] Bump version 2.8.12 --- CHANGES.md | 13 +++++++++---- lib/protobuf/version.rb | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f6633d39..8da86cdc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,10 +1,15 @@ +2.8.12 +--------- + +- Fix thread busy access in zmq server/worker. [#151, @abrandoned] + 2.8.11 --------- -- Default ZMQ server to use inproc protocol instead of tcp (zero-copy between server-broker-worker) -- Add 'broadcast_busy' functionality that removes server from cluster if the workers are full -- Add cli option for --no-zmq_inproc -- Add cli option for --broadcast_busy +- Default ZMQ server to use inproc protocol instead of tcp (zero-copy between server-broker-worker). [#145, @brianstien] +- Add `broadcast_busy` functionality that removes server from cluster if the workers are full. [#149, @abrandoned] +- Add cli option for `--no-zmq_inproc`. [#149, @abrandoned] +- Add cli option for `--broadcast_busy`. [#149, @abrandoned] 2.8.10 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 03144183..dca37278 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.11' + VERSION = '2.8.12' PROTOC_VERSION = '2.5.0' end From 7ee042a9341025ac668f61b77a5f1404e8fd5f3d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 11 Feb 2014 16:18:27 -0700 Subject: [PATCH 0573/1191] Use sane names in Enum class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Get rid of all references to the word “value”. EnumValue’s are just called enums now. “value” objects when referring to an integer number are just now called tags. It’s not semantically correct, but there isn’t a semantically correct name and “tag” is short. Replace “by” in method names with “for” cause it reads nicer. --- lib/protobuf/enum.rb | 127 +++++++++++++++++++-------------- spec/lib/protobuf/enum_spec.rb | 80 +++++++++++++-------- 2 files changed, 125 insertions(+), 82 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index b3a80267..1d48944b 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -10,18 +10,6 @@ def self.aliases_allowed? self.get_option(:allow_alias) end - # Public: Get an array of EnumValue objects with the given number. - # - # number - An object that responds to to_i. - # - # Returns an array with zero or more EnumValue objects or nil. - # - def self.all_enum_values_by_number(number) - self.enum_values.values.select do |enum_value| - enum_value.to_i == number.to_i - end - end - # Public: Get all integer tag values defined by this enum. # # Examples @@ -33,12 +21,12 @@ def self.all_enum_values_by_number(number) # define :OFF, 2 # end # - # StateMachine.all_numbers #=> [ 1, 2 ] + # StateMachine.all_tags #=> [ 1, 2 ] # # Returns an array of unique integers. # - def self.all_numbers - @all_numbers ||= self.enum_values.values.map(&:to_i).uniq + def self.all_tags + @all_tags ||= self.enums.map(&:to_i).uniq end # Internal: DSL method to define a protobuf EnumValue. The given name will @@ -50,16 +38,47 @@ def self.all_numbers # define :ON, 1 # define :OFF, 2 # end + # # StateMachine::ON #=> # # StateMachine::OFF #=> # # # Returns nothing. # def self.define(name, value) - enum_value = ::Protobuf::EnumValue.new(self, name, value) - @enum_values ||= {} - @enum_values[name] = enum_value - const_set(name, enum_value) + enum = ::Protobuf::EnumValue.new(self, name, value) + @enums ||= [] + @enums << enum + const_set(name, enum) + end + + # Public: The internal values hash. + # + def self.enums + @enums + end + + # Public: Get an array of EnumValue objects with the given tag. + # + # tag - An object that responds to to_i. + # + # Examples + # + # class StateMachine < ::Protobuf::Enum + # set_option :allow_alias + # define :ON, 1 + # define :STARTED, 1 + # define :OFF, 2 + # end + # + # StateMachine.enums_for_tag(1) #=> [ #, # ] + # StateMachine.enums_for_tag(2) #=> [ # ] + # + # Returns an array with zero or more EnumValue objects or nil. + # + def self.enums_for_tag(tag) + self.enums.select { |enum| + enum.to_i == tag.to_i + } end # Public: Get the EnumValue associated with the given name. @@ -73,35 +92,29 @@ def self.define(name, value) # define :OFF, 2 # end # - # StateMachine.enum_value_by_name(:ON) # => # - # StateMachine.enum_value_by_name("ON") # => # - # StateMachine.enum_value_by_name(:on) # => nil - # StateMachine.enum_value_by_name(:FOO) # => nil + # StateMachine.enum_for_name(:ON) # => # + # StateMachine.enum_for_name("ON") # => # + # StateMachine.enum_for_name(:on) # => nil + # StateMachine.enum_for_name(:FOO) # => nil # # Returns the EnumValue object with the given name. `nil` will be returned # if the given name does not have a correlating value. # - def self.enum_value_by_name(name) + def self.enum_for_name(name) self.const_get(name) - rescue NameError, NoMethodError + rescue ::NameError nil end - # Public: Get the EnumValue object corresponding to the given number. + # Public: Get the EnumValue object corresponding to the given tag. # - # number - An object that responds to to_i. + # tag - An object that responds to to_i. # - # Returns an EnumValue object or nil. If the number corresponds to multiple + # Returns an EnumValue object or nil. If the tag corresponds to multiple # EnumValue objects an array of EnumValue objects will be returned. # - def self.enum_value_by_value(number) - enum_value_by_name(name_by_value(number)) - end - - # Public: The internal values hash. - # - def self.enum_values - @enum_values + def self.enum_for_tag(tag) + self.enums_for_tag(tag).first end # Public: Get an EnumValue by a variety of type-checking mechanisms. @@ -124,14 +137,14 @@ def self.enum_values # # Returns an EnumValue object or nil. # - def self.fetch(value) - case value + def self.fetch(candidate) + case candidate when ::Protobuf::EnumValue then - value + candidate when Numeric then - enum_value_by_value(value.to_i) + enum_for_tag(candidate.to_i) when String, Symbol then - enum_value_by_name(value) + enum_for_name(candidate) else nil end @@ -149,9 +162,9 @@ def self.fetch(value) # define :OFF, 2 # end # - # StateMachine.name_by_value(1) # => :ON - # StateMachine.name_by_value(2) # => :OFF - # StateMachine.name_by_value(3) # => nil + # StateMachine.name_for_tag(1) # => :ON + # StateMachine.name_for_tag(2) # => :OFF + # StateMachine.name_for_tag(3) # => nil # # # With aliases # class StateMachine < ::Protobuf::Enum @@ -161,40 +174,48 @@ def self.fetch(value) # define :OFF, 2 # end # - # StateMachine.name_by_value(1) # => :STARTED - # StateMachine.name_by_value(2) # => :OFF + # StateMachine.name_for_tag(1) # => :STARTED + # StateMachine.name_for_tag(2) # => :OFF # # Returns the symbol name of the enum constant given it's associated value. # If the given value has multiple names associated (due to allow_alias) # the first defined name will be returned. `nil` will be returned when # the given value does not have a correlating name. # - def self.name_by_value(number) - self.enum_values.values.detect { |enum_value| - enum_value.to_i == number.to_i - }.try(:name) + def self.name_for_tag(tag) + self.enum_for_tag(tag).try(:name) end # Public: Check if the given tag value is defined by this Enum. - # See name_by_value. # # number - An object that responds to to_i. # # Returns a boolean. # - def self.valid_value?(number) - !! name_by_value(number) + def self.valid_tag?(tag) + tag.respond_to?(:to_i) && self.all_tags.include?(tag.to_i) end ## # Class Aliases + # Public: [DEPRECATED] Return a hash of EnumValue objects keyed + # by their :name. # class << self # Deprecated: alias_method :valid_tag?, :valid_value? + def self.values + self.warn_deprecated(:values, :enums) # Deprecated: alias_method :values, :enum_values + @values ||= begin + self.enums.inject({}) do |hash, enum| + hash[enum.name] = enum + hash + end + end + end # Deprecated: Alias of name_by_value. alias_method :get_name_by_tag, :name_by_value diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 53c4b7bd..b71ea9ad 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -24,14 +24,6 @@ end end - describe '.all_enum_values_by_number' do - it 'returns an array of EnumValues for the given tag' do - expect(EnumAliasTest.all_enum_values_by_number(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) - expect(EnumAliasTest.all_enum_values_by_number(2)).to eq([ EnumAliasTest::BAZ ]) - expect(EnumAliasTest.all_enum_values_by_number(3)).to eq([]) - end - end - describe '.define' do it 'defines a constant enum value on the parent class' do expect(Test::EnumTestType.constants).to include(name) @@ -54,6 +46,36 @@ end end + describe '.enums' do + it 'provides an array of defined EnumValue objects' do + expect(Test::EnumTestType.enums).to eq([ + Test::EnumTestType::ONE, + Test::EnumTestType::TWO, + Test::EnumTestType::MINUS_ONE, + Test::EnumTestType::THREE + ]) + end + + context 'when enum allows aliases' do + it 'treats aliased values as valid' do + expect(EnumAliasTest.enums).to eq([ + EnumAliasTest::FOO, + EnumAliasTest::BAR, + EnumAliasTest::BAZ + ]) + end + end + end + + + describe '.enums_for_tag' do + it 'returns an array of EnumValues for the given tag, if any' do + expect(EnumAliasTest.enums_for_tag(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) + expect(EnumAliasTest.enums_for_tag(2)).to eq([ EnumAliasTest::BAZ ]) + expect(EnumAliasTest.enums_for_tag(3)).to eq([]) + end + end + describe '.fetch' do context 'when value is an EnumValue' do it 'responds with that object' do @@ -90,65 +112,66 @@ end end - describe '.enum_value_by_value' do + describe '.enum_for_tag' do it 'gets the EnumValue corresponding to the given value (tag)' do - expect(Test::EnumTestType.enum_value_by_value(tag)).to eq(Test::EnumTestType.const_get(name)) + expect(Test::EnumTestType.enum_for_tag(tag)).to eq(Test::EnumTestType.const_get(name)) + expect(Test::EnumTestType.enum_for_tag(-5)).to be_nil end end - describe '.name_by_value' do + describe '.name_for_tag' do it 'get the name by value of the enum given the enum' do - expect(Test::EnumTestType.name_by_value(::Test::EnumTestType::THREE)).to eq(name) + expect(Test::EnumTestType.name_for_tag(::Test::EnumTestType::THREE)).to eq(name) end it 'gets the name of the enum corresponding to the given value (tag)' do - expect(Test::EnumTestType.name_by_value(tag)).to eq(name) + expect(Test::EnumTestType.name_for_tag(tag)).to eq(name) end it 'gets the name when the tag is coercable to an int' do - expect(Test::EnumTestType.name_by_value("3")).to eq(name) + expect(Test::EnumTestType.name_for_tag("3")).to eq(name) end it 'returns nil when tag does not correspond to a name' do - expect(Test::EnumTestType.name_by_value(12345)).to be_nil + expect(Test::EnumTestType.name_for_tag(12345)).to be_nil end context 'when given name is nil' do it 'returns a nil' do - expect(Test::EnumTestType.name_by_value(nil)).to be_nil + expect(Test::EnumTestType.name_for_tag(nil)).to be_nil end end context 'when enum allows aliases' do it 'returns the first defined name for that value' do - expect(EnumAliasTest.name_by_value(1)).to eq(:FOO) + expect(EnumAliasTest.name_for_tag(1)).to eq(:FOO) end end end - describe '.valid_value?' do + describe '.valid_tag?' do context 'when tag is defined' do - specify { expect(Test::EnumTestType.valid_value?(tag)).to be_true } + specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_true } end context 'when tag is not defined' do - specify { expect(Test::EnumTestType.valid_value?(300)).to be_false } + specify { expect(Test::EnumTestType.valid_tag?(300)).to be_false } end context 'when enum allows aliases' do it 'treats aliased values as valid' do - expect(EnumAliasTest.valid_value?(1)).to be_true + expect(EnumAliasTest.valid_tag?(1)).to be_true end end end - describe '.enum_value_by_name' do + describe '.enum_for_name' do it 'gets the EnumValue corresponding to the given name' do - expect(Test::EnumTestType.enum_value_by_name(name)).to eq(Test::EnumTestType::THREE) + expect(Test::EnumTestType.enum_for_name(name)).to eq(Test::EnumTestType::THREE) end end - describe '.enum_values' do + describe '.values' do it 'provides a hash of defined EnumValue objects' do expect(Test::EnumTestType.values).to eq({ :MINUS_ONE => Test::EnumTestType::MINUS_ONE, @@ -159,9 +182,8 @@ end context 'when enum allows aliases' do - it 'treats aliased values as valid' do - expect(EnumAliasTest.enum_values).to eq({ + expect(EnumAliasTest.values).to eq({ :FOO => EnumAliasTest::FOO, :BAR => EnumAliasTest::BAR, :BAZ => EnumAliasTest::BAZ @@ -170,14 +192,14 @@ end end - describe '.all_numbers' do + describe '.all_tags' do it 'provides an array of the integer values' do - expect(Test::EnumTestType.all_numbers).to include(-1, 1, 2, 3) + expect(Test::EnumTestType.all_tags).to include(1, 2, -1, 3) end context 'when enum allows aliases' do it 'returns a unique array of all defined enum values' do - expect(EnumAliasTest.all_numbers).to include(1, 2) + expect(EnumAliasTest.all_tags).to include(1, 2) end end end From 4a9307cee27b92243a52e1b8803e06247f37e777 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 11 Feb 2014 16:19:26 -0700 Subject: [PATCH 0574/1191] Add Deprecator module and deprecate several existing enum class methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deprecator module simply prints a warning when the old method is called and then calls the new method, passing arguments if it’s expecting them. --- lib/protobuf/deprecator.rb | 26 ++++++++++++++++++++++++++ lib/protobuf/enum.rb | 28 ++++++++++++++++------------ 2 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 lib/protobuf/deprecator.rb diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb new file mode 100644 index 00000000..9a5c15d2 --- /dev/null +++ b/lib/protobuf/deprecator.rb @@ -0,0 +1,26 @@ +module Protobuf + module Deprecator + + def warn_deprecated(old_method, new_method) + $stderr.puts %Q{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. + Please use #{self.name}.#{new_method} instead.\n} + end + + # Given deprecations should be a hash whose keys are the new methods + # and values are a list of deprecated methods that should send to t + def deprecate_method(old_method, new_method) + instance_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) + def #{old_method}(*args) + warn_deprecated("#{old_method}", "#{new_method}") + new_meth = method("#{new_method}") + if new_meth.arity == 0 + __send__("#{new_method}") + else + __send__("#{new_method}", *args) + end + end + DEPRECATED + end + + end +end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 1d48944b..7d57ab67 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,8 +1,16 @@ require 'protobuf/enum_value' require 'protobuf/optionable' +require 'protobuf/deprecator' module Protobuf class Enum + + ## + # Deprecations + # + + extend ::Protobuf::Deprecator + # Public: Allows setting Options on the Enum class. include ::Protobuf::Optionable @@ -196,19 +204,12 @@ def self.valid_tag?(tag) tag.respond_to?(:to_i) && self.all_tags.include?(tag.to_i) end - ## - # Class Aliases # Public: [DEPRECATED] Return a hash of EnumValue objects keyed # by their :name. # - class << self - # Deprecated: - alias_method :valid_tag?, :valid_value? def self.values self.warn_deprecated(:values, :enums) - # Deprecated: - alias_method :values, :enum_values @values ||= begin self.enums.inject({}) do |hash, enum| hash[enum.name] = enum @@ -217,12 +218,15 @@ def self.values end end - # Deprecated: Alias of name_by_value. - alias_method :get_name_by_tag, :name_by_value + ## + # Deprecations + # - # Deprecated: Alias of enum_value_by_value. - alias_method :value_by_name, :enum_value_by_value - end + deprecate_method :enum_by_value, :enum_for_tag + deprecate_method :name_by_value, :name_for_tag + deprecate_method :get_name_by_tag, :name_for_tag + deprecate_method :value_by_name, :enum_for_name end end + From 86b5b9cfc83f7961c55fcd2ff15b42193809250a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 11 Feb 2014 16:22:58 -0700 Subject: [PATCH 0575/1191] Add unreleased section to top of CHANGES.md with info on Enum changes --- CHANGES.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 08515050..2bb75873 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,16 @@ +Unreleased (3.x) +--------- + +- Clean up the Enum class API with several methods deprecated. See #134 for more comprehensive +documentation about which methods are going and away and which are being renamed. [#134, @localshred] + + +-------- + + +Stable +-------- + 2.8.10 --------- From f23422550ea324b51fbea94e5042638672850f59 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 12 Feb 2014 10:56:36 -0700 Subject: [PATCH 0576/1191] Add change info on enum alias support --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 2bb75873..4f119360 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ Unreleased (3.x) --------- +- Add support for enum aliases. [#134, @localshred] - Clean up the Enum class API with several methods deprecated. See #134 for more comprehensive documentation about which methods are going and away and which are being renamed. [#134, @localshred] From 13fbdb9749b7e9b2119bc8ba3802b5f29bb590b0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 12 Feb 2014 11:05:37 -0700 Subject: [PATCH 0577/1191] Remove previously deprecated rprotoc executable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `protoc —ruby_out` instead. --- bin/rprotoc | 8 -------- 1 file changed, 8 deletions(-) delete mode 100755 bin/rprotoc diff --git a/bin/rprotoc b/bin/rprotoc deleted file mode 100755 index 4556c009..00000000 --- a/bin/rprotoc +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env ruby - -command = [ 'protoc', ARGV ].flatten.join(' ') - -$stderr.puts "[DEPRECATED] `rprotoc` is deprecated. Use `protoc --ruby_out ...` instead." -$stdout.puts command - -exec command From f3912940dcff051df8bd4669aa5d804f1463cd42 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 12 Feb 2014 11:06:15 -0700 Subject: [PATCH 0578/1191] Remove previously deprecated method `Service#rpc` Use `Service#method_name` instead. --- lib/protobuf/rpc/service.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 1f3f9f49..434ad70d 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -186,18 +186,6 @@ def respond_with(candidate) end alias_method :return_from_whence_you_came, :respond_with - # Renamed attribute from prior implementaiton due to lack of clarity - # in what the variable contained. DEPRECATED. - def rpc - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [WARNING] Service#rpc method has been deprecated - and will be removed in a future version of protobuf. - ERROR - end - @method_name - end - # Automatically fail a service method. # def rpc_failed(message) From fa61ed4b6d3dadb0965b111f802796c4660c5d88 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 12 Feb 2014 11:10:38 -0700 Subject: [PATCH 0579/1191] Document removal of previously deprecated code --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b3107097..4166018f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ Unreleased (3.x) - Add support for enum aliases. [#134, @localshred] - Clean up the Enum class API with several methods deprecated. See #134 for more comprehensive documentation about which methods are going and away and which are being renamed. [#134, @localshred] +- Remove previously deprecated `bin/rprotoc` executable. [13fbdb9] +- Remove previously deprecated `Service#rpc` method. [f391294] -------- @@ -22,7 +24,6 @@ Stable - Add `broadcast_busy` functionality that removes server from cluster if the workers are full. [#149, @abrandoned] - Add cli option for `--no-zmq_inproc`. [#149, @abrandoned] - Add cli option for `--broadcast_busy`. [#149, @abrandoned] ->>>>>>> 2-8-stable 2.8.10 --------- From 2cf437a831d41ee60fe8713c92f094d8cb7025c0 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 15:39:02 -0700 Subject: [PATCH 0580/1191] Send data from the servers, not the server module Instead of having the server module call send_data, which it does not define, have it return a response and call send_data from the servers themselves. --- lib/protobuf/rpc/server.rb | 2 +- lib/protobuf/rpc/servers/socket/worker.rb | 6 +++++- lib/protobuf/rpc/servers/zmq/worker.rb | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 765ccd9a..7c49aa81 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -46,6 +46,7 @@ def handle_client handle_error(error) ensure send_response + @response end # Client error handler. Receives an exception object and writes it into the @response @@ -78,7 +79,6 @@ def parse_request_from_buffer # Write the response wrapper to the client def send_response log_debug { sign_message("Sending response to client: #{@response.inspect}") } - send_data ensure @stats.stop log_info { @stats.to_s } diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index b6c7d13c..68119590 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -21,7 +21,11 @@ def initialize(sock, &complete_cb) @request_data = request_buffer.data log_debug { sign_message("handling request") } - handle_client if request_buffer.flushed? + + if request_buffer.flushed? + @response = handle_client + send_data + end end def read_data diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 0ae08203..19bf7419 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -30,7 +30,8 @@ def process_request unless @request_data.nil? log_debug { sign_message("handling request") } - handle_client + @response = handle_client + send_data end end From 7e66a9620430739dfaf6a6dc91ae8145bac60e6a Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 15:49:36 -0700 Subject: [PATCH 0581/1191] Conditionally pause GC with a block Now that the servers are responsible for sending data, they also need to handle pausing GC. Add a new gc_pause method that takes a block and conditionally pauses GC when yielding the block. Each server wraps the handle_client & send_data call in this method call. --- lib/protobuf/rpc/server.rb | 10 ++++++++-- lib/protobuf/rpc/servers/socket/worker.rb | 6 ++++-- lib/protobuf/rpc/servers/zmq/worker.rb | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 7c49aa81..fe5e0ed0 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -25,6 +25,14 @@ def enable_gc! ::GC.enable if ::Protobuf.gc_pause_server_request? end + def gc_pause + disable_gc! + + yield + + enable_gc! + end + # Invoke the service method dictated by the proto wrapper request object def handle_client parse_request_from_buffer @@ -34,7 +42,6 @@ def handle_client @stats.dispatcher = @dispatcher log_info { @stats.to_s } - disable_gc! @dispatcher.invoke! if @dispatcher.success? @response.response_proto = @dispatcher.response @@ -82,7 +89,6 @@ def send_response ensure @stats.stop log_info { @stats.to_s } - enable_gc! end end end diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 68119590..e2c4d3e9 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -23,8 +23,10 @@ def initialize(sock, &complete_cb) log_debug { sign_message("handling request") } if request_buffer.flushed? - @response = handle_client - send_data + gc_pause do + @response = handle_client + send_data + end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 19bf7419..11450004 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -30,8 +30,10 @@ def process_request unless @request_data.nil? log_debug { sign_message("handling request") } - @response = handle_client - send_data + gc_pause do + @response = handle_client + send_data + end end end From 14c0025e6178b11a43f2c305c569383bf4fa5922 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 16:41:45 -0700 Subject: [PATCH 0582/1191] Consolidate response encoding Instead of returning a response object and requiring each server to encode it, encode the response in handle_client and return it. That way, each server is simply responsible for streaming the data as it sees fit. It also allows stats tracking and logging to be centralized inside the server module. --- lib/protobuf/rpc/server.rb | 10 +++++++--- lib/protobuf/rpc/servers/socket/worker.rb | 12 ++++++------ lib/protobuf/rpc/servers/zmq/worker.rb | 10 +++------- spec/support/test/google_unittest.pb.rb | 2 -- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index fe5e0ed0..a43acc3a 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -52,8 +52,7 @@ def handle_client log_exception(error) handle_error(error) ensure - send_response - @response + send_encoded_response end # Client error handler. Receives an exception object and writes it into the @response @@ -84,11 +83,16 @@ def parse_request_from_buffer end # Write the response wrapper to the client - def send_response + def send_encoded_response + encoded_response = @response.encode + @stats.response_size = encoded_response.size + log_debug { sign_message("Sending response to client: #{@response.inspect}") } ensure @stats.stop log_info { @stats.to_s } + + encoded_response end end end diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index e2c4d3e9..7d4bbcde 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -24,8 +24,8 @@ def initialize(sock, &complete_cb) if request_buffer.flushed? gc_pause do - @response = handle_client - send_data + encoded_response = handle_client + send_data(encoded_response) end end end @@ -41,14 +41,14 @@ def read_data "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" end - def send_data + def send_data(data) raise 'Socket closed unexpectedly' unless socket_writable? response_buffer = Protobuf::Rpc::Buffer.new(:write) - response_buffer.set_data(@response) - @stats.response_size = response_buffer.size - log_debug { sign_message("sending data : #{response_buffer.data}") } + response_buffer.set_data(data) + @socket.write(response_buffer.write) @socket.flush + @complete_cb.call(@socket) end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 11450004..7ac3e6b0 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -31,8 +31,8 @@ def process_request unless @request_data.nil? log_debug { sign_message("handling request") } gc_pause do - @response = handle_client - send_data + encoded_response = handle_client + send_data(encoded_response) end end end @@ -69,11 +69,7 @@ def running? @server.running? end - def send_data - data = @response.encode - - @stats.response_size = data.size - + def send_data(data) write_to_backend([@client_address, "", data]) end diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index 8cd4c32c..b41bcc50 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - ## # This file is auto-generated. DO NOT EDIT! # From 414c73b68d2a8d55a570c47619eaf9273f56b744 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 16:54:06 -0700 Subject: [PATCH 0583/1191] Consolidate request/stat logging --- lib/protobuf/rpc/server.rb | 2 ++ lib/protobuf/rpc/servers/socket/worker.rb | 3 --- lib/protobuf/rpc/servers/zmq/worker.rb | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index a43acc3a..1175742b 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -35,6 +35,8 @@ def gc_pause # Invoke the service method dictated by the proto wrapper request object def handle_client + log_debug { sign_message("handling request") } + parse_request_from_buffer @stats.client = @request.caller diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 7d4bbcde..af8cc549 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -16,12 +16,9 @@ def initialize(sock, &complete_cb) request_buffer = Protobuf::Rpc::Buffer.new(:read) @complete_cb = complete_cb - log_debug { sign_message("stats are #{@stats.to_s}") } request_buffer << read_data @request_data = request_buffer.data - log_debug { sign_message("handling request") } - if request_buffer.flushed? gc_pause do encoded_response = handle_client diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 7ac3e6b0..4a0f2dc1 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -29,7 +29,6 @@ def process_request @client_address, _, @request_data = read_from_backend unless @request_data.nil? - log_debug { sign_message("handling request") } gc_pause do encoded_response = handle_client send_data(encoded_response) From 63db3d1e70006470fd053216da778c9416102d1b Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 17:45:30 -0700 Subject: [PATCH 0584/1191] Remove the read buffer from the socket worker Since the socket worker reads all of it's data from the socket, there's not need to keep the buffer in the mix. Instead, simply read the request data from the socket. --- lib/protobuf/rpc/servers/socket/worker.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index af8cc549..d626811b 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -4,22 +4,17 @@ module Protobuf module Rpc module Socket - class Worker include ::Protobuf::Rpc::Server include ::Protobuf::Logger::LogMethods def initialize(sock, &complete_cb) @socket = sock - initialize_request! - - request_buffer = Protobuf::Rpc::Buffer.new(:read) @complete_cb = complete_cb - request_buffer << read_data - @request_data = request_buffer.data + initialize_request! - if request_buffer.flushed? + if @request_data = read_data gc_pause do encoded_response = handle_client send_data(encoded_response) @@ -35,7 +30,7 @@ def read_data end str_size_io = size_io.string - "#{str_size_io}-#{@socket.read(str_size_io.to_i)}" + @socket.read(str_size_io.to_i) end def send_data(data) @@ -57,7 +52,6 @@ def socket_writable? ! @socket.nil? && ! @socket.closed? end end - end end end From 40a512278e99e61053a2c2b80fcd52df3f90bde0 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 17:53:20 -0700 Subject: [PATCH 0585/1191] Consolidate initializing request Instead of making each server responsible for initializing the request, response, and stats objects, just call it from inside handle_client. --- lib/protobuf/rpc/server.rb | 1 + lib/protobuf/rpc/servers/socket/worker.rb | 2 -- lib/protobuf/rpc/servers/zmq/worker.rb | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 1175742b..a9cafec0 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -36,6 +36,7 @@ def gc_pause # Invoke the service method dictated by the proto wrapper request object def handle_client log_debug { sign_message("handling request") } + initialize_request! parse_request_from_buffer @stats.client = @request.caller diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index d626811b..778699a3 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -12,8 +12,6 @@ def initialize(sock, &complete_cb) @socket = sock @complete_cb = complete_cb - initialize_request! - if @request_data = read_data gc_pause do encoded_response = handle_client diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 4a0f2dc1..a7734762 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -55,7 +55,6 @@ def run if rc > 0 ::Thread.current[:busy] = true - initialize_request! process_request ::Thread.current[:busy] = false end From 02d1417f56af479cb55b0f61a9fab9bac9ac5ded Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 18:10:58 -0700 Subject: [PATCH 0586/1191] Rework how requests are handled Continuing to solidify the server API, rework how requests are handled. - Rename handle_client to handle_request - Pass request data to handle_request (instead of using an ivar) - Rename parse_request_from_buffer to parse_request_data - Pass request data to parse_request_data --- lib/protobuf/rpc/server.rb | 13 +++++++------ lib/protobuf/rpc/servers/socket/worker.rb | 11 ++++++----- lib/protobuf/rpc/servers/zmq/worker.rb | 15 +++++---------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index a9cafec0..7d02ec0a 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -34,11 +34,11 @@ def gc_pause end # Invoke the service method dictated by the proto wrapper request object - def handle_client + def handle_request(data) log_debug { sign_message("handling request") } initialize_request! + parse_request_data(data) - parse_request_from_buffer @stats.client = @request.caller @dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(@request) @@ -46,6 +46,7 @@ def handle_client log_info { @stats.to_s } @dispatcher.invoke! + if @dispatcher.success? @response.response_proto = @dispatcher.response else @@ -75,10 +76,10 @@ def log_signature end # Parse the incoming request object into our expected request object - def parse_request_from_buffer - log_debug { sign_message("Parsing request from buffer: #{@request_data}") } - @stats.request_size = @request_data.size - @request.decode(@request_data) + def parse_request_data(data) + log_debug { sign_message("Parsing request from buffer: #{data}") } + @stats.request_size = data.size + @request.decode(data) rescue => error exc = ::Protobuf::Rpc::BadRequestData.new("Unable to parse request: #{error.message}") log_error { exc.message } diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 778699a3..aa443347 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -12,11 +12,12 @@ def initialize(sock, &complete_cb) @socket = sock @complete_cb = complete_cb - if @request_data = read_data - gc_pause do - encoded_response = handle_client - send_data(encoded_response) - end + data = read_data + return unless data + + gc_pause do + encoded_response = handle_request(data) + send_data(encoded_response) end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index a7734762..6b3d5582 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -26,13 +26,12 @@ def initialize(server) # Instance Methods # def process_request - @client_address, _, @request_data = read_from_backend + client_address, _, data = read_from_backend + return unless data - unless @request_data.nil? - gc_pause do - encoded_response = handle_client - send_data(encoded_response) - end + gc_pause do + encoded_response = handle_request(data) + write_to_backend([client_address, "", encoded_response]) end end @@ -67,10 +66,6 @@ def running? @server.running? end - def send_data(data) - write_to_backend([@client_address, "", data]) - end - private def init_zmq_context From 6d2ca3158e3ca9174965791dacc5cebc601f9b73 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 20:04:38 -0700 Subject: [PATCH 0587/1191] Rework the server module Solidify the server API even more. Instead of initializing a bunch of instance variables and simply accessing them whenever, create methods to handle decoding requests and encoding responses. Encoding responses got the most significant overhaul since errors and responses are handled differently. Now PB errors will simply initialize a new PB response wrapper with the error information instead of taking a pre-initialized response object and setting error values on it. --- lib/protobuf/rpc/error.rb | 9 ++- lib/protobuf/rpc/server.rb | 128 ++++++++++++++++++++++--------------- 2 files changed, 81 insertions(+), 56 deletions(-) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 37d0c6c0..f0c3ecea 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -8,14 +8,13 @@ module Rpc class PbError < StandardError attr_reader :error_type - def initialize message='An unknown RpcError occurred', error_type='RPC_ERROR' - @error_type = error_type.is_a?(String) ? ::Protobuf::Socketrpc::ErrorReason.const_get(error_type) : error_type + def initialize(message='An unknown RpcError occurred', error_type='RPC_ERROR') + @error_type = error_type.is_a?(String) ? Socketrpc::ErrorReason.const_get(error_type) : error_type super message end - def to_response response - response.error = message - response.error_reason = @error_type + def to_response + Socketrpc::Response.new(:error => message, :error_reason => error_type) end end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 7d02ec0a..02425acd 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -9,14 +9,6 @@ module Protobuf module Rpc module Server - - def initialize_request! - log_debug { sign_message('Post init') } - @request = ::Protobuf::Socketrpc::Request.new - @response = ::Protobuf::Socketrpc::Response.new - @stats = Protobuf::Rpc::Stat.new(:SERVER) - end - def disable_gc! ::GC.disable if ::Protobuf.gc_pause_server_request? end @@ -34,69 +26,103 @@ def gc_pause end # Invoke the service method dictated by the proto wrapper request object - def handle_request(data) - log_debug { sign_message("handling request") } - initialize_request! - parse_request_data(data) + # + def handle_request(request_data) + log_debug { sign_message("Handling request") } + + initialize_stats! + stats.request_size = request_data.size + + request = decode_request_data(request_data) + stats.client = request.caller + + response_data = dispatch_request(request) + rescue => error + log_exception(error) + response_data = handle_error(error) + ensure + encoded_response = encode_response_data(response_data) + stats.stop + + # Log the response stats + log_info { stats.to_s } + + encoded_response + end + + def log_signature + @_log_signature ||= "[server-#{self.class.name}]" + end + + private - @stats.client = @request.caller + # Decode the incoming request object into our expected request object + # + def decode_request_data(data) + log_debug { sign_message("Decoding request: #{data}") } - @dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(@request) - @stats.dispatcher = @dispatcher - log_info { @stats.to_s } + Socketrpc::Request.decode(data) + rescue => error + exception = BadRequestData.new("Unable to decode request: #{error.message}") + log_error { exception.message } + raise exception + end + + # Dispatch the request to the service + # + def dispatch_request(request) + dispatcher = ServiceDispatcher.new(request) + stats.dispatcher = dispatcher - @dispatcher.invoke! + # Log the request stats + log_info { stats.to_s } - if @dispatcher.success? - @response.response_proto = @dispatcher.response + dispatcher.invoke! + + if dispatcher.success? + Socketrpc::Response.new(:response_proto => response_data) else - handle_error(@dispatcher.error) + handle_error(dispatcher.error) end + end + + # Encode the response wrapper to return to the client + # + def encode_response_data(response) + log_debug { sign_message("Encoding response: #{response.inspect}") } + + encoded_response = response.encode rescue => error log_exception(error) - handle_error(error) + encoded_response = handle_error(error).encode ensure - send_encoded_response + stats.response_size = encoded_response.size + encoded_response end - # Client error handler. Receives an exception object and writes it into the @response + # Embed exceptions in a response wrapper + # def handle_error(error) log_debug { sign_message("handle_error: #{error.inspect}") } + if error.respond_to?(:to_response) - error.to_response(@response) + error.to_response else - message = error.respond_to?(:message) ? error.message : error.to_s - code = error.respond_to?(:code) ? error.code : 'RPC_ERROR' - ::Protobuf::Rpc::PbError.new(message, code).to_response(@response) + PbError.new(error.message).to_response end end - def log_signature - @_log_signature ||= "[server-#{self.class.name}]" - end - - # Parse the incoming request object into our expected request object - def parse_request_data(data) - log_debug { sign_message("Parsing request from buffer: #{data}") } - @stats.request_size = data.size - @request.decode(data) - rescue => error - exc = ::Protobuf::Rpc::BadRequestData.new("Unable to parse request: #{error.message}") - log_error { exc.message } - raise exc + # Initialize a new stats tracker + # + # NOTE: This has to be reinitialized with each request and can't be + # memoized since servers aren't reinitialized with each request + # + def initialize_stats! + @_stats = Stat.new(:SERVER) end - # Write the response wrapper to the client - def send_encoded_response - encoded_response = @response.encode - @stats.response_size = encoded_response.size - - log_debug { sign_message("Sending response to client: #{@response.inspect}") } - ensure - @stats.stop - log_info { @stats.to_s } - - encoded_response + def stats + @_stats end end end From 69c4086da7acc868677466fbf84cf45737532a84 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 8 Feb 2014 20:59:42 -0700 Subject: [PATCH 0588/1191] Conditionally pause GC in the pause_gc method --- lib/protobuf/rpc/server.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 02425acd..dbe0c396 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -9,20 +9,12 @@ module Protobuf module Rpc module Server - def disable_gc! - ::GC.disable if ::Protobuf.gc_pause_server_request? - end - - def enable_gc! - ::GC.enable if ::Protobuf.gc_pause_server_request? - end - def gc_pause - disable_gc! + ::GC.disable if ::Protobuf.gc_pause_server_request? yield - enable_gc! + ::GC.enable if ::Protobuf.gc_pause_server_request? end # Invoke the service method dictated by the proto wrapper request object From 6b1d3facf8c1a5d9de7de3ec95508612927fc2bc Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sun, 9 Feb 2014 10:41:44 -0700 Subject: [PATCH 0589/1191] Remove RPC::Server from the socket server Since the socket server spins up workers to handle requests, it doesn't need to include the server module. --- lib/protobuf/rpc/servers/socket/server.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 50298ad3..7efdd65b 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -4,9 +4,7 @@ module Protobuf module Rpc module Socket - class Server - include ::Protobuf::Rpc::Server include ::Protobuf::Logger::LogMethods AUTO_COLLECT_TIMEOUT = 5 # seconds From 976948b54e0678b0724c965bebc1ebff8dec9fce Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Mon, 10 Feb 2014 09:46:22 -0700 Subject: [PATCH 0590/1191] Use an explicit return in ensure block In order to override what is returned from a method when using ensure, an explicit return must be used. --- lib/protobuf/rpc/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index dbe0c396..a062aceb 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -39,7 +39,7 @@ def handle_request(request_data) # Log the response stats log_info { stats.to_s } - encoded_response + return encoded_response end def log_signature From 8aa4469bf701450ca4790b8743dc5f516c855b9b Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Mon, 10 Feb 2014 20:43:44 -0700 Subject: [PATCH 0591/1191] Introduce the concept of a middleware stack In order to make PB more extensible, this introduces the concept of a middleware stack. It is invoked from the server and terminates at the dispatcher. Add an env object used to pass stuff to/from the middleware: - Use it in the dispatcher store the response and return it instead - Use it in the server module to access stats, set the request, and process the response --- lib/protobuf/rpc/middleware.rb | 14 ++++++ lib/protobuf/rpc/middleware/runner.rb | 18 +++++++ lib/protobuf/rpc/server.rb | 67 ++++++++++++++------------ lib/protobuf/rpc/service_dispatcher.rb | 21 ++++++-- protobuf.gemspec | 1 + 5 files changed, 86 insertions(+), 35 deletions(-) create mode 100644 lib/protobuf/rpc/middleware.rb create mode 100644 lib/protobuf/rpc/middleware/runner.rb diff --git a/lib/protobuf/rpc/middleware.rb b/lib/protobuf/rpc/middleware.rb new file mode 100644 index 00000000..3c043514 --- /dev/null +++ b/lib/protobuf/rpc/middleware.rb @@ -0,0 +1,14 @@ +require 'middleware' + +require 'protobuf/rpc/middleware/runner' + +module Protobuf + module Rpc + def self.middleware + @middleware ||= ::Middleware::Builder.new(:runner_class => ::Protobuf::Rpc::Middleware::Runner) + end + + # Ensure the middleware stack is initialized + middleware + end +end diff --git a/lib/protobuf/rpc/middleware/runner.rb b/lib/protobuf/rpc/middleware/runner.rb new file mode 100644 index 00000000..4438dab4 --- /dev/null +++ b/lib/protobuf/rpc/middleware/runner.rb @@ -0,0 +1,18 @@ +require 'middleware/runner' + +module Protobuf + module Rpc + module Middleware + class Runner < ::Middleware::Runner + # Override the default middleware runner so we can ensure that the + # service dispatcher is the last thing called in the stack. + # + def initialize(stack) + stack << Protobuf::Rpc::ServiceDispatcher + + super(stack) + end + end + end + end +end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index a062aceb..4a1881da 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -3,6 +3,7 @@ require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' +require 'protobuf/rpc/middleware' require 'protobuf/rpc/stat' require 'protobuf/rpc/service_dispatcher' @@ -22,22 +23,29 @@ def gc_pause def handle_request(request_data) log_debug { sign_message("Handling request") } - initialize_stats! - stats.request_size = request_data.size + # Create an env object that holds different parts of the environment and + # is available to all of the middlewares. + initialize_env! + env['stats'].request_size = request_data.size - request = decode_request_data(request_data) - stats.client = request.caller + env['request'] = decode_request_data(request_data) + env['stats'].client = env['request'].caller - response_data = dispatch_request(request) + # Invoke the middleware stack, the last of which is the service + # dispatcher. The dispatcher sets either an error object or a + # protobuf response object to env['response']. + env = Rpc.middleware.call(env) + + response_data = handle_response(env['response']) rescue => error log_exception(error) response_data = handle_error(error) ensure encoded_response = encode_response_data(response_data) - stats.stop + env['stats'].stop # Log the response stats - log_info { stats.to_s } + log_info { env['stats'].to_s } return encoded_response end @@ -60,24 +68,6 @@ def decode_request_data(data) raise exception end - # Dispatch the request to the service - # - def dispatch_request(request) - dispatcher = ServiceDispatcher.new(request) - stats.dispatcher = dispatcher - - # Log the request stats - log_info { stats.to_s } - - dispatcher.invoke! - - if dispatcher.success? - Socketrpc::Response.new(:response_proto => response_data) - else - handle_error(dispatcher.error) - end - end - # Encode the response wrapper to return to the client # def encode_response_data(response) @@ -88,7 +78,7 @@ def encode_response_data(response) log_exception(error) encoded_response = handle_error(error).encode ensure - stats.response_size = encoded_response.size + env['stats'].response_size = encoded_response.size encoded_response end @@ -104,13 +94,30 @@ def handle_error(error) end end - # Initialize a new stats tracker + # The middleware stack returns either an error or response proto. Package + # it up so that it's in the correct spot in the respone wrapper + # + def handle_response(response) + if response < Protobuf::Rpc::PbError + handle_error(response) + else + Socketrpc::Response.new(:response_proto => response) + end + end + + # Initialize a new environment object # # NOTE: This has to be reinitialized with each request and can't be - # memoized since servers aren't reinitialized with each request + # memoized since servers aren't always reinitialized with each request # - def initialize_stats! - @_stats = Stat.new(:SERVER) + def initialize_env! + # TODO: Add extra info about the environment (i.e. variables) and other + # information that might be useful + @_env = { + 'request' => nil, + 'response' => nil, + 'stats' => Stat.new(:SERVER) + } end def stats diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 269563f1..355eae8d 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -3,19 +3,30 @@ module Protobuf module Rpc class ServiceDispatcher - include ::Protobuf::Logger::LogMethods attr_accessor :service, :service_klass, :callable_method, :outer_request attr_accessor :definition, :response, :error - def initialize(wrapper_request) - self.error = nil - self.outer_request = wrapper_request + def initialize(app) + @app = app + end + + def call(env) + self.outer_request = env['request'] + + env['stats'].dispatcher = self init_service init_method if service_klass.present? register_rpc_failed if service.present? + + # Log the request stats + log_info { env['stats'].to_s } + + invoke! + + env end # Call the given service method. If we get to this point and an error @@ -27,7 +38,7 @@ def invoke! validate_response end - return error || response + env['response'] = error || response end # We're successful if the error is not populated. diff --git a/protobuf.gemspec b/protobuf.gemspec index 8ed84944..72f5079a 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -20,6 +20,7 @@ require "protobuf/version" s.require_paths = ["lib"] s.add_dependency 'activesupport' + s.add_dependency 'middleware' s.add_dependency 'multi_json' s.add_dependency 'thor' From 572f1a667c996c457050ae08e37d77d33942f725 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 12 Feb 2014 13:29:08 -0700 Subject: [PATCH 0592/1191] Add a proper environment object w/ accessors --- lib/protobuf/rpc/env.rb | 41 ++++++++++++++++++++++++++ lib/protobuf/rpc/server.rb | 32 +++++++------------- lib/protobuf/rpc/service_dispatcher.rb | 8 ++--- 3 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 lib/protobuf/rpc/env.rb diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb new file mode 100644 index 00000000..664a819d --- /dev/null +++ b/lib/protobuf/rpc/env.rb @@ -0,0 +1,41 @@ +module Protobuf + module Rpc + class Env < Hash + # Creates an accessor that simply sets and reads a key in the hash: + # + # class Config < Hash + # hash_accessor :app + # end + # + # config = Config.new + # config.app = Foo + # config[:app] #=> Foo + # + # config[:app] = Bar + # config.app #=> Bar + # + def self.hash_accessor(*names) #:nodoc: + names.each do |name| + class_eval <<-METHOD, __FILE__, __LINE__ + 1 + def #{name} + self[:#{name}] + end + + def #{name}=(value) + self[:#{name}] = value + end + METHOD + end + end + + # TODO: Add extra info about the environment (i.e. variables) and other + # information that might be useful + hash_accessor :caller, + :method_name, + :request, + :response, + :service_name, + :stats + end + end +end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 4a1881da..36326bd2 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -25,27 +25,27 @@ def handle_request(request_data) # Create an env object that holds different parts of the environment and # is available to all of the middlewares. - initialize_env! - env['stats'].request_size = request_data.size + initialize_env!(request_data) + env.stats.request_size = request_data.size - env['request'] = decode_request_data(request_data) - env['stats'].client = env['request'].caller + env.request = decode_request_data(request_data) + env.stats.client = env.request.caller # Invoke the middleware stack, the last of which is the service # dispatcher. The dispatcher sets either an error object or a - # protobuf response object to env['response']. + # protobuf response object to env.response. env = Rpc.middleware.call(env) - response_data = handle_response(env['response']) + response_data = handle_response(env.response) rescue => error log_exception(error) response_data = handle_error(error) ensure encoded_response = encode_response_data(response_data) - env['stats'].stop + env.stats.stop # Log the response stats - log_info { env['stats'].to_s } + log_info { env.stats.to_s } return encoded_response end @@ -78,7 +78,7 @@ def encode_response_data(response) log_exception(error) encoded_response = handle_error(error).encode ensure - env['stats'].response_size = encoded_response.size + env.stats.response_size = encoded_response.size encoded_response end @@ -110,18 +110,8 @@ def handle_response(response) # NOTE: This has to be reinitialized with each request and can't be # memoized since servers aren't always reinitialized with each request # - def initialize_env! - # TODO: Add extra info about the environment (i.e. variables) and other - # information that might be useful - @_env = { - 'request' => nil, - 'response' => nil, - 'stats' => Stat.new(:SERVER) - } - end - - def stats - @_stats + def initialize_env!(request_data) + @_env = Env.new('request' => request_data, 'stats' => Stat.new(:SERVER)) end end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 355eae8d..68c8596e 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -13,16 +13,16 @@ def initialize(app) end def call(env) - self.outer_request = env['request'] + self.outer_request = env.request - env['stats'].dispatcher = self + env.stats.dispatcher = self init_service init_method if service_klass.present? register_rpc_failed if service.present? # Log the request stats - log_info { env['stats'].to_s } + log_info { env.stats.to_s } invoke! @@ -38,7 +38,7 @@ def invoke! validate_response end - env['response'] = error || response + env.response = error || response end # We're successful if the error is not populated. From b8460b2da00880c6413d182d5b181aa63f8870dd Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 12 Feb 2014 15:00:46 -0700 Subject: [PATCH 0593/1191] Fix a couple of issues with the env object - Env needs to provide an initializer in order to allow passing values on initialize - Env needs to be required in the server in order to use it --- lib/protobuf/rpc/env.rb | 8 ++++++-- lib/protobuf/rpc/server.rb | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index 664a819d..44d3b497 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -18,11 +18,11 @@ def self.hash_accessor(*names) #:nodoc: names.each do |name| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} - self[:#{name}] + self['#{name}'] end def #{name}=(value) - self[:#{name}] = value + self['#{name}'] = value end METHOD end @@ -36,6 +36,10 @@ def #{name}=(value) :response, :service_name, :stats + + def initialize(env = {}) + merge!(env) + end end end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 36326bd2..2f93cc1d 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -2,6 +2,7 @@ require 'protobuf/logger' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' +require 'protobuf/rpc/env' require 'protobuf/rpc/error' require 'protobuf/rpc/middleware' require 'protobuf/rpc/stat' From 4d4b709776284a3d1948e455a367275c0ff3f32e Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sun, 9 Feb 2014 14:38:20 -0700 Subject: [PATCH 0594/1191] Extract request decoding into a middleware Decode the request and populate the env before continuing up the stack. If a decoding error occurs, rescue it, set the response and don't continue up the stack. --- lib/protobuf/rpc/env.rb | 2 + lib/protobuf/rpc/middleware.rb | 3 + .../rpc/middleware/request_decoder.rb | 56 +++++++++++++ lib/protobuf/rpc/server.rb | 23 ++---- .../rpc/middleware/request_decoder_spec.rb | 78 +++++++++++++++++++ spec/spec_helper.rb | 1 + 6 files changed, 146 insertions(+), 17 deletions(-) create mode 100644 lib/protobuf/rpc/middleware/request_decoder.rb create mode 100644 spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index 44d3b497..07451c34 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -31,6 +31,8 @@ def #{name}=(value) # TODO: Add extra info about the environment (i.e. variables) and other # information that might be useful hash_accessor :caller, + :encoded_request, + :log_signature, :method_name, :request, :response, diff --git a/lib/protobuf/rpc/middleware.rb b/lib/protobuf/rpc/middleware.rb index 3c043514..58b8b0b4 100644 --- a/lib/protobuf/rpc/middleware.rb +++ b/lib/protobuf/rpc/middleware.rb @@ -1,5 +1,6 @@ require 'middleware' +require 'protobuf/rpc/middleware/request_decoder' require 'protobuf/rpc/middleware/runner' module Protobuf @@ -11,4 +12,6 @@ def self.middleware # Ensure the middleware stack is initialized middleware end + + Rpc.middleware.use(Rpc::Middleware::RequestDecoder) end diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb new file mode 100644 index 00000000..a80499d7 --- /dev/null +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -0,0 +1,56 @@ +module Protobuf + module Rpc + module Middleware + class RequestDecoder + include Logger::LogMethods + + attr_reader :app, :env + + def initialize(app) + @app = app + end + + def call(env) + @env = env + + if @env.request = decode_request_data(@env.encoded_request) + @env.caller = @env.request.caller + @env.service_name = @env.request.service_name + @env.method_name = @env.request.method_name + + # TODO: Figure out a better way to do stat tracking + @env.stats.request_size = @env.encoded_request.size + @env.stats.client = @env.request.caller + + @env = app.call(@env) + end + + @env + end + + def log_signature + env.signature || super + end + + private + + # Decode the incoming request object into our expected request object + # + def decode_request_data(data) + log_debug { sign_message("Decoding request: #{data}") } + + Socketrpc::Request.decode(data) + rescue => exception + log_exception(exception) + + # Rescue decoding exceptions, re-wrap them as bad request data errors, + # and set the response so we can safely short-curcuit the rest of the + # middleware call. + env.response = BadRequestData.new("Unable to decode request: #{exception.message}").to_response + + return nil # Explicitly return nil so we don't continue up the stack + end + end + end + end +end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 2f93cc1d..3592ba81 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -27,10 +27,6 @@ def handle_request(request_data) # Create an env object that holds different parts of the environment and # is available to all of the middlewares. initialize_env!(request_data) - env.stats.request_size = request_data.size - - env.request = decode_request_data(request_data) - env.stats.client = env.request.caller # Invoke the middleware stack, the last of which is the service # dispatcher. The dispatcher sets either an error object or a @@ -57,18 +53,6 @@ def log_signature private - # Decode the incoming request object into our expected request object - # - def decode_request_data(data) - log_debug { sign_message("Decoding request: #{data}") } - - Socketrpc::Request.decode(data) - rescue => error - exception = BadRequestData.new("Unable to decode request: #{error.message}") - log_error { exception.message } - raise exception - end - # Encode the response wrapper to return to the client # def encode_response_data(response) @@ -112,7 +96,12 @@ def handle_response(response) # memoized since servers aren't always reinitialized with each request # def initialize_env!(request_data) - @_env = Env.new('request' => request_data, 'stats' => Stat.new(:SERVER)) + # TODO: Figure out a better way to handle logging with signatures + @_env = Env.new( + 'encoded_request' => request_data, + 'log_signature' => log_signature, + 'stats' => Stat.new(:SERVER) + ) end end end diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb new file mode 100644 index 00000000..dd357a0f --- /dev/null +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -0,0 +1,78 @@ +require 'spec_helper' + +describe Protobuf::Rpc::Middleware::RequestDecoder do + let(:app) { Proc.new { |env| env } } + let(:caller) { 'caller.test.co' } + let(:env) { + Protobuf::Rpc::Env.new( + 'encoded_request' => encoded_request, + 'log_signature' => 'log_signature', + 'stats' => Protobuf::Rpc::Stat.new(:SERVER) + ) + } + let(:encoded_request) { request.encode } + let(:method_name) { 'bar' } + let(:request) { + Protobuf::Socketrpc::Request.new( + :caller => caller, + :service_name => service_name, + :method_name => method_name + ) + } + let(:service_name) { 'Foo' } + + subject { described_class.new(app) } + + describe "#call" do + it "decodes the request" do + stack_env = subject.call(env) + stack_env.request.should eq request + end + + it "calls the stack" do + app.should_receive(:call).with(env) + subject.call(env) + end + + it "sets Env#caller" do + stack_env = subject.call(env) + stack_env.caller.should eq caller + end + + it "sets Env#service_name" do + stack_env = subject.call(env) + stack_env.service_name.should eq service_name + end + + it "sets Env#method_name" do + stack_env = subject.call(env) + stack_env.method_name.should eq method_name + end + + it "sets Env#stats.request_size" do + stack_env = subject.call(env) + stack_env.stats.request_size.should eq encoded_request.size + end + + it "sets Env#stats.client" do + stack_env = subject.call(env) + stack_env.stats.client.should eq caller + end + + context "when decoding fails" do + let(:response) { Protobuf::Rpc::BadRequestData.new("Unable to decode request: Boom!").to_response } + + before { Protobuf::Socketrpc::Request.stub(:decode).and_raise(RuntimeError, 'Boom!') } + + it "does not call the stack" do + app.should_not_receive(:call) + subject.call(env) + end + + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq response + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aaa606ed..4102ead5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,6 +11,7 @@ $: << ::File.expand_path('../support', __FILE__) require 'protobuf' +require 'protobuf/rpc/server' require ::File.expand_path('../support/all', __FILE__) $: << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) From dbac8f2753256b46af38995d35c81b04377505b1 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sun, 9 Feb 2014 16:33:15 -0700 Subject: [PATCH 0595/1191] Extract response encoding into a middleware Invoke the stack, encode the response and store it in the env. If an encoding error occurs, a generic Protobuf error is encoded and returned. --- lib/protobuf/rpc/env.rb | 1 + lib/protobuf/rpc/middleware.rb | 2 + .../rpc/middleware/request_decoder.rb | 4 +- .../rpc/middleware/response_encoder.rb | 63 ++++++++++++++++ lib/protobuf/rpc/server.rb | 57 ++------------- .../rpc/middleware/request_decoder_spec.rb | 5 +- .../rpc/middleware/response_encoder_spec.rb | 73 +++++++++++++++++++ 7 files changed, 153 insertions(+), 52 deletions(-) create mode 100644 lib/protobuf/rpc/middleware/response_encoder.rb create mode 100644 spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index 07451c34..70db2cb2 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -32,6 +32,7 @@ def #{name}=(value) # information that might be useful hash_accessor :caller, :encoded_request, + :encoded_response, :log_signature, :method_name, :request, diff --git a/lib/protobuf/rpc/middleware.rb b/lib/protobuf/rpc/middleware.rb index 58b8b0b4..5823c179 100644 --- a/lib/protobuf/rpc/middleware.rb +++ b/lib/protobuf/rpc/middleware.rb @@ -1,6 +1,7 @@ require 'middleware' require 'protobuf/rpc/middleware/request_decoder' +require 'protobuf/rpc/middleware/response_encoder' require 'protobuf/rpc/middleware/runner' module Protobuf @@ -14,4 +15,5 @@ def self.middleware end Rpc.middleware.use(Rpc::Middleware::RequestDecoder) + Rpc.middleware.use(Rpc::Middleware::ResponseEncoder) end diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index a80499d7..791d8169 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -46,7 +46,9 @@ def decode_request_data(data) # Rescue decoding exceptions, re-wrap them as bad request data errors, # and set the response so we can safely short-curcuit the rest of the # middleware call. - env.response = BadRequestData.new("Unable to decode request: #{exception.message}").to_response + error = BadRequestData.new("Unable to decode request: #{exception.message}") + env.response = error + env.encoded_response = error.to_response.encode return nil # Explicitly return nil so we don't continue up the stack end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb new file mode 100644 index 00000000..9a905668 --- /dev/null +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -0,0 +1,63 @@ +module Protobuf + module Rpc + module Middleware + class ResponseEncoder + include Logger::LogMethods + + attr_reader :app, :env + + def initialize(app) + @app = app + end + + def call(env) + @env = app.call(env) + + @env.encoded_response = encode_response_data(@env.response) + + # TODO: Extract this when stats are moved to a middleware + @env.stats.response_size = @env.encoded_response.size + + @env + end + + def log_signature + env.signature || super + end + + private + + # Encode the response wrapper to return to the client + # + def encode_response_data(response) + log_debug { sign_message("Encoding response: #{response.inspect}") } + + response = wrap_response(response) + env.encoded_response = Socketrpc::Response.encode(response) + rescue => exception + log_exception(exception) + + # Rescue encoding exceptions, re-wrap them as generic protobuf errors, + # and set it as the encoded response so we always have something to + # send back + error = PbError.new(exception.message) + env.response = error + env.encoded_response = error.to_response.encode + ensure + return env.encoded_response + end + + # The middleware stack returns either an error or response proto. Package + # it up so that it's in the correct spot in the response wrapper + # + def wrap_response(response) + if response.is_a?(Protobuf::Rpc::PbError) + { :error => response.message, :error_reason => response.error_type } + else + { :response_proto => response.encode } + end + end + end + end + end +end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 3592ba81..ba61df06 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -25,26 +25,22 @@ def handle_request(request_data) log_debug { sign_message("Handling request") } # Create an env object that holds different parts of the environment and - # is available to all of the middlewares. + # is available to all of the middlewares initialize_env!(request_data) - # Invoke the middleware stack, the last of which is the service - # dispatcher. The dispatcher sets either an error object or a - # protobuf response object to env.response. + # Invoke the middleware stack, the last of which is the service dispatcher env = Rpc.middleware.call(env) - - response_data = handle_response(env.response) - rescue => error - log_exception(error) - response_data = handle_error(error) - ensure - encoded_response = encode_response_data(response_data) env.stats.stop # Log the response stats log_info { env.stats.to_s } - return encoded_response + env.encoded_response + rescue => exception + log_exception(exception) + + response = PbError.new(exception.message).to_response + response.encode end def log_signature @@ -53,43 +49,6 @@ def log_signature private - # Encode the response wrapper to return to the client - # - def encode_response_data(response) - log_debug { sign_message("Encoding response: #{response.inspect}") } - - encoded_response = response.encode - rescue => error - log_exception(error) - encoded_response = handle_error(error).encode - ensure - env.stats.response_size = encoded_response.size - encoded_response - end - - # Embed exceptions in a response wrapper - # - def handle_error(error) - log_debug { sign_message("handle_error: #{error.inspect}") } - - if error.respond_to?(:to_response) - error.to_response - else - PbError.new(error.message).to_response - end - end - - # The middleware stack returns either an error or response proto. Package - # it up so that it's in the correct spot in the respone wrapper - # - def handle_response(response) - if response < Protobuf::Rpc::PbError - handle_error(response) - else - Socketrpc::Response.new(:response_proto => response) - end - end - # Initialize a new environment object # # NOTE: This has to be reinitialized with each request and can't be diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index dd357a0f..2adc4682 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -60,7 +60,8 @@ end context "when decoding fails" do - let(:response) { Protobuf::Rpc::BadRequestData.new("Unable to decode request: Boom!").to_response } + let(:error) { Protobuf::Rpc::BadRequestData.new("Unable to decode request: Boom!") } + let(:response) { error.to_response } before { Protobuf::Socketrpc::Request.stub(:decode).and_raise(RuntimeError, 'Boom!') } @@ -71,7 +72,7 @@ it "sets Env#response" do stack_env = subject.call(env) - stack_env.response.should eq response + stack_env.response.should eq error end end end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb new file mode 100644 index 00000000..607f10d8 --- /dev/null +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe Protobuf::Rpc::Middleware::ResponseEncoder do + let(:app) { Proc.new { |env| env } } + let(:env) { + Protobuf::Rpc::Env.new( + 'response' => response_proto, + 'log_signature' => 'log_signature', + 'stats' => Protobuf::Rpc::Stat.new(:SERVER) + ) + } + let(:encoded_response) { response.encode } + let(:response) { + Protobuf::Socketrpc::Response.new( + :response_proto => response_proto + ) + } + let(:response_proto) { Test::Resource.new(:name => 'required') } + + subject { described_class.new(app) } + + describe "#call" do + it "encodes the response" do + stack_env = subject.call(env) + stack_env.encoded_response.should eq encoded_response + end + + it "calls the stack" do + app.should_receive(:call).with(env).and_return(env) + subject.call(env) + end + + it "sets Env#stats.request_size" do + stack_env = subject.call(env) + stack_env.stats.response_size.should eq encoded_response.size + end + + context "when response is a Protobuf error" do + let(:encoded_response) { response.encode } + let(:env) { + Protobuf::Rpc::Env.new( + 'response' => error, + 'log_signature' => 'log_signature', + 'stats' => Protobuf::Rpc::Stat.new(:SERVER) + ) + } + let(:error) { Protobuf::Rpc::RpcError.new } + let(:response) { error.to_response } + + it "encodes the response" do + stack_env = subject.call(env) + stack_env.encoded_response.should eq encoded_response + end + end + + context "when encoding fails" do + let(:error) { Protobuf::Rpc::PbError.new('Boom!') } + let(:response) { error.to_response } + + before { Protobuf::Socketrpc::Response.stub(:encode).and_raise(RuntimeError, 'Boom!') } + + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq error + end + + it "encodes the response" do + stack_env = subject.call(env) + stack_env.encoded_response.should eq encoded_response + end + end + end +end From 2e582f136187caed026026f50f3dd8733b0fc82c Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sun, 9 Feb 2014 15:05:12 -0700 Subject: [PATCH 0596/1191] Extract exception handling into a middleware Rescue exceptions that are raised and set the response. If the exception rescued is not a Protobuf error, it is wrapped in a generic Protobuf error. --- lib/protobuf/rpc/middleware.rb | 2 + .../rpc/middleware/exception_handler.rb | 35 +++++++++++++ lib/protobuf/rpc/server.rb | 11 ++-- .../rpc/middleware/exception_handler_spec.rb | 51 +++++++++++++++++++ 4 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 lib/protobuf/rpc/middleware/exception_handler.rb create mode 100644 spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb diff --git a/lib/protobuf/rpc/middleware.rb b/lib/protobuf/rpc/middleware.rb index 5823c179..02c50308 100644 --- a/lib/protobuf/rpc/middleware.rb +++ b/lib/protobuf/rpc/middleware.rb @@ -1,5 +1,6 @@ require 'middleware' +require 'protobuf/rpc/middleware/exception_handler' require 'protobuf/rpc/middleware/request_decoder' require 'protobuf/rpc/middleware/response_encoder' require 'protobuf/rpc/middleware/runner' @@ -16,4 +17,5 @@ def self.middleware Rpc.middleware.use(Rpc::Middleware::RequestDecoder) Rpc.middleware.use(Rpc::Middleware::ResponseEncoder) + Rpc.middleware.use(Rpc::Middleware::ExceptionHandler) end diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb new file mode 100644 index 00000000..cfc4c65b --- /dev/null +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -0,0 +1,35 @@ +module Protobuf + module Rpc + module Middleware + class ExceptionHandler + include Logger::LogMethods + + attr_reader :app + + def initialize(app) + @app = app + end + + def call(env) + app.call(env) + rescue => exception + log_exception(exception) + + # Rescue exceptions, re-wrap them as generic Protobuf errors, + # and set the response + env.response = wrap_exception(exception) + env + end + + private + + # Wrap exceptions in a generic Protobuf errors unless they already are + # + def wrap_exception(exception) + exception = PbError.new(exception.message) unless exception.is_a?(PbError) + exception + end + end + end + end +end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index ba61df06..387d2ede 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -36,11 +36,6 @@ def handle_request(request_data) log_info { env.stats.to_s } env.encoded_response - rescue => exception - log_exception(exception) - - response = PbError.new(exception.message).to_response - response.encode end def log_signature @@ -57,9 +52,9 @@ def log_signature def initialize_env!(request_data) # TODO: Figure out a better way to handle logging with signatures @_env = Env.new( - 'encoded_request' => request_data, - 'log_signature' => log_signature, - 'stats' => Stat.new(:SERVER) + 'encoded_request' => request_data, + 'log_signature' => log_signature, + 'stats' => Stat.new(:SERVER) ) end end diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb new file mode 100644 index 00000000..8780704b --- /dev/null +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +describe Protobuf::Rpc::Middleware::ExceptionHandler do + let(:app) { Proc.new { |env| env } } + let(:env) { Protobuf::Rpc::Env.new } + + subject { described_class.new(app) } + + describe "#call" do + it "calls the stack" do + app.should_receive(:call).with(env) + subject.call(env) + end + + it "returns the env" do + subject.call(env).should eq env + end + + context "when exceptions occur" do + let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } + + before { app.stub(:call).and_raise(error, 'Boom!') } + + it "rescues exceptions" do + expect { subject.call(env) }.not_to raise_exception + end + + context "when exception is a Protobuf error" do + let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } + + before { app.stub(:call).and_raise(error) } + + it "does not wrap the exception in a generic Protobuf error" do + stack_env = subject.call(env) + stack_env.response.should eq error + end + end + + context "when exception is not a Protobuf error" do + let(:error) { Protobuf::Rpc::PbError.new('Boom!') } + + before { app.stub(:call).and_raise(RuntimeError, 'Boom!') } + + it "wraps the exception in a generic Protobuf error" do + stack_env = subject.call(env) + stack_env.response.should eq error + end + end + end + end +end From d665ffc549632cdcfd7889ebc4d7600d85076854 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 12 Feb 2014 21:23:21 -0700 Subject: [PATCH 0597/1191] Move behavior into a method to avoid accessing ivars Accessing ivars is weird and the alternative (explicit self) is weirder. By moving the behavior into a method, we can avoid both. --- .../rpc/middleware/request_decoder.rb | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index a80499d7..2a7dadd1 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -13,19 +13,7 @@ def initialize(app) def call(env) @env = env - if @env.request = decode_request_data(@env.encoded_request) - @env.caller = @env.request.caller - @env.service_name = @env.request.service_name - @env.method_name = @env.request.method_name - - # TODO: Figure out a better way to do stat tracking - @env.stats.request_size = @env.encoded_request.size - @env.stats.client = @env.request.caller - - @env = app.call(@env) - end - - @env + call_app end def log_signature @@ -34,6 +22,22 @@ def log_signature private + def call_app + if env.request = decode_request_data(env.encoded_request) + env.caller = env.request.caller + env.service_name = env.request.service_name + env.method_name = env.request.method_name + + # TODO: Figure out a better way to do stat tracking + env.stats.request_size = env.encoded_request.size + env.stats.client = env.request.caller + + app.call(env) + else + env + end + end + # Decode the incoming request object into our expected request object # def decode_request_data(data) From 1543cae4324dcd2ada42c04110945275e64fc0b1 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Feb 2014 10:51:45 -0700 Subject: [PATCH 0598/1191] Extract logging and stats into a middleware Instead of capturing stats all over the place, rely on the env object and middleware placement to capture everything we need to log requests and responses. The logger middleware is loaded between the decoder and encoder. --- lib/protobuf/rpc/env.rb | 12 ++- lib/protobuf/rpc/middleware.rb | 2 + .../rpc/middleware/exception_handler.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 91 +++++++++++++++++++ .../rpc/middleware/request_decoder.rb | 6 +- .../rpc/middleware/response_encoder.rb | 6 +- lib/protobuf/rpc/server.rb | 25 +---- lib/protobuf/rpc/service_dispatcher.rb | 32 +++---- .../protobuf/rpc/middleware/logger_spec.rb | 19 ++++ .../rpc/middleware/request_decoder_spec.rb | 13 +-- .../rpc/middleware/response_encoder_spec.rb | 11 +-- 11 files changed, 142 insertions(+), 77 deletions(-) create mode 100644 lib/protobuf/rpc/middleware/logger.rb create mode 100644 spec/lib/protobuf/rpc/middleware/logger_spec.rb diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index 70db2cb2..d235af12 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -24,6 +24,10 @@ def #{name} def #{name}=(value) self['#{name}'] = value end + + def #{name}? + ! self['#{name}'].nil? + end METHOD end end @@ -38,10 +42,12 @@ def #{name}=(value) :request, :response, :service_name, - :stats + :worker_id + + def initialize(options={}) + merge!(options) - def initialize(env = {}) - merge!(env) + self['worker_id'] = ::Thread.current.object_id.to_s(16) end end end diff --git a/lib/protobuf/rpc/middleware.rb b/lib/protobuf/rpc/middleware.rb index 02c50308..eaf1697d 100644 --- a/lib/protobuf/rpc/middleware.rb +++ b/lib/protobuf/rpc/middleware.rb @@ -1,6 +1,7 @@ require 'middleware' require 'protobuf/rpc/middleware/exception_handler' +require 'protobuf/rpc/middleware/logger' require 'protobuf/rpc/middleware/request_decoder' require 'protobuf/rpc/middleware/response_encoder' require 'protobuf/rpc/middleware/runner' @@ -16,6 +17,7 @@ def self.middleware end Rpc.middleware.use(Rpc::Middleware::RequestDecoder) + Rpc.middleware.use(Rpc::Middleware::Logger) Rpc.middleware.use(Rpc::Middleware::ResponseEncoder) Rpc.middleware.use(Rpc::Middleware::ExceptionHandler) end diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index cfc4c65b..0195e23f 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class ExceptionHandler - include Logger::LogMethods + include ::Protobuf::Logger::LogMethods attr_reader :app diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb new file mode 100644 index 00000000..a0086c07 --- /dev/null +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -0,0 +1,91 @@ +module Protobuf + module Rpc + module Middleware + class Logger + def initialize(app) + @app = app + end + + # TODO: Figure out how to control when logs are flushed + def call(env) + instrumenter.start + instrumenter.flush(env) # Log request stats + + env = @app.call(env) + + instrumenter.stop + instrumenter.flush(env) # Log response stats + + env + end + + private + + def instrumenter + @instrumenter ||= Instrumenter.new + end + + # TODO: Replace this with ActiveSupport::Notifications and log subscribers + # TODO: Consider adopting Rails-style logging so we can track serialization + # time as well as ActiveRecord time, etc.: + # + # Started GET "/" for 127.0.0.1 at 2014-02-12 09:40:29 -0700 + # Processing by ReleasesController#index as HTML + # Rendered releases/_release.html.erb (0.0ms) + # Rendered releases/_release.html.erb (0.0ms) + # Rendered releases/_release.html.erb (0.0ms) + # Rendered releases/_release.html.erb (0.0ms) + # Rendered releases/index.html.erb within layouts/application (11.0ms) + # Completed 200 OK in 142ms (Views: 117.6ms | ActiveRecord: 1.7ms) + # + class Instrumenter + attr_reader :env + + def flush(env) + Protobuf::Logger.info { to_s(env) } + end + + def start + @start_time = ::Time.now.utc + end + + def stop + @end_time = ::Time.now.utc + end + + def to_s(env) + @env = env + + [ + "[SRV]", + env.caller, + env.worker_id, + rpc, + sizes, + elapsed_time, + @end_time.try(:iso8601) + ].compact.join(' - ') + end + + private + + def elapsed_time + (@start_time && @end_time ? "#{(@end_time - @start_time).round(4)}s" : nil) + end + + def rpc + env.service_name && env.method_name ? "#{env.service_name}##{env.method_name}" : nil + end + + def sizes + if env.encoded_response? + "#{env.encoded_request.size}B/#{env.encoded_response.size}B" + else + "#{env.encoded_request.size}B/-" + end + end + end + end + end + end +end diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 5f7e289d..94754ae0 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class RequestDecoder - include Logger::LogMethods + include ::Protobuf::Logger::LogMethods attr_reader :app, :env @@ -28,10 +28,6 @@ def call_app env.service_name = env.request.service_name env.method_name = env.request.method_name - # TODO: Figure out a better way to do stat tracking - env.stats.request_size = env.encoded_request.size - env.stats.client = env.request.caller - app.call(env) else env diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 9a905668..8dc83604 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class ResponseEncoder - include Logger::LogMethods + include ::Protobuf::Logger::LogMethods attr_reader :app, :env @@ -12,12 +12,8 @@ def initialize(app) def call(env) @env = app.call(env) - @env.encoded_response = encode_response_data(@env.response) - # TODO: Extract this when stats are moved to a middleware - @env.stats.response_size = @env.encoded_response.size - @env end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 387d2ede..f76bcd58 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -5,7 +5,6 @@ require 'protobuf/rpc/env' require 'protobuf/rpc/error' require 'protobuf/rpc/middleware' -require 'protobuf/rpc/stat' require 'protobuf/rpc/service_dispatcher' module Protobuf @@ -22,18 +21,12 @@ def gc_pause # Invoke the service method dictated by the proto wrapper request object # def handle_request(request_data) - log_debug { sign_message("Handling request") } - # Create an env object that holds different parts of the environment and # is available to all of the middlewares - initialize_env!(request_data) + env = Env.new('encoded_request' => request_data, 'log_signature' => log_signature) # Invoke the middleware stack, the last of which is the service dispatcher env = Rpc.middleware.call(env) - env.stats.stop - - # Log the response stats - log_info { env.stats.to_s } env.encoded_response end @@ -41,22 +34,6 @@ def handle_request(request_data) def log_signature @_log_signature ||= "[server-#{self.class.name}]" end - - private - - # Initialize a new environment object - # - # NOTE: This has to be reinitialized with each request and can't be - # memoized since servers aren't always reinitialized with each request - # - def initialize_env!(request_data) - # TODO: Figure out a better way to handle logging with signatures - @_env = Env.new( - 'encoded_request' => request_data, - 'log_signature' => log_signature, - 'stats' => Stat.new(:SERVER) - ) - end end end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 68c8596e..2fb9b27e 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -5,28 +5,28 @@ module Rpc class ServiceDispatcher include ::Protobuf::Logger::LogMethods - attr_accessor :service, :service_klass, :callable_method, :outer_request - attr_accessor :definition, :response, :error + attr_accessor :callable_method, :definition, :env, :error, :response, :service, :service_klass def initialize(app) - @app = app + # End of the line... end def call(env) - self.outer_request = env.request - - env.stats.dispatcher = self + @env = env init_service init_method if service_klass.present? register_rpc_failed if service.present? - # Log the request stats - log_info { env.stats.to_s } - invoke! - env + self.env + end + + # We're in error if the error is populated. + # + def error? + ! success? end # Call the given service method. If we get to this point and an error @@ -41,18 +41,16 @@ def invoke! env.response = error || response end + def outer_request + env.request + end + # We're successful if the error is not populated. # def success? error.nil? end - # We're in error if the error is populated. - # - def error? - ! success? - end - private def assign_error(error_klass, message) @@ -136,8 +134,6 @@ def validate_response assign_error(BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}") end end - end end end - diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb new file mode 100644 index 00000000..c6a3e323 --- /dev/null +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Protobuf::Rpc::Middleware::Logger do + let(:app) { Proc.new { |env| env } } + let(:env) { Protobuf::Rpc::Env.new } + + subject { described_class.new(app) } + + describe "#call" do + it "calls the stack" do + app.should_receive(:call).with(env) + subject.call(env) + end + + it "returns the env" do + subject.call(env).should eq env + end + end +end diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 2adc4682..4ae9abe4 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -6,8 +6,7 @@ let(:env) { Protobuf::Rpc::Env.new( 'encoded_request' => encoded_request, - 'log_signature' => 'log_signature', - 'stats' => Protobuf::Rpc::Stat.new(:SERVER) + 'log_signature' => 'log_signature' ) } let(:encoded_request) { request.encode } @@ -49,16 +48,6 @@ stack_env.method_name.should eq method_name end - it "sets Env#stats.request_size" do - stack_env = subject.call(env) - stack_env.stats.request_size.should eq encoded_request.size - end - - it "sets Env#stats.client" do - stack_env = subject.call(env) - stack_env.stats.client.should eq caller - end - context "when decoding fails" do let(:error) { Protobuf::Rpc::BadRequestData.new("Unable to decode request: Boom!") } let(:response) { error.to_response } diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 607f10d8..81dd2922 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -5,8 +5,7 @@ let(:env) { Protobuf::Rpc::Env.new( 'response' => response_proto, - 'log_signature' => 'log_signature', - 'stats' => Protobuf::Rpc::Stat.new(:SERVER) + 'log_signature' => 'log_signature' ) } let(:encoded_response) { response.encode } @@ -30,18 +29,12 @@ subject.call(env) end - it "sets Env#stats.request_size" do - stack_env = subject.call(env) - stack_env.stats.response_size.should eq encoded_response.size - end - context "when response is a Protobuf error" do let(:encoded_response) { response.encode } let(:env) { Protobuf::Rpc::Env.new( 'response' => error, - 'log_signature' => 'log_signature', - 'stats' => Protobuf::Rpc::Stat.new(:SERVER) + 'log_signature' => 'log_signature' ) } let(:error) { Protobuf::Rpc::RpcError.new } From c9ed831ac33d5adc0ddbb944cf41912ba9950609 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Feb 2014 13:15:35 -0700 Subject: [PATCH 0599/1191] Reorder middleware so exception handler is first Making the exception handler the first middleware ensures that all exceptions are rescued. It also greatly simplifies the other middleware since exceptions can simply be raised instead of returned in env.response and exceptions don't need to be encoded. --- lib/protobuf/rpc/error.rb | 4 ++ lib/protobuf/rpc/middleware.rb | 2 +- .../rpc/middleware/exception_handler.rb | 3 +- .../rpc/middleware/request_decoder.rb | 29 ++++------ .../rpc/middleware/response_encoder.rb | 17 +++--- lib/protobuf/rpc/service_dispatcher.rb | 55 +++++++++---------- .../rpc/middleware/exception_handler_spec.rb | 19 +++++-- .../rpc/middleware/request_decoder_spec.rb | 15 +---- .../rpc/middleware/response_encoder_spec.rb | 15 +---- 9 files changed, 70 insertions(+), 89 deletions(-) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index f0c3ecea..a834a9bc 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -13,6 +13,10 @@ def initialize(message='An unknown RpcError occurred', error_type='RPC_ERROR') super message end + def encode + to_response.encode + end + def to_response Socketrpc::Response.new(:error => message, :error_reason => error_type) end diff --git a/lib/protobuf/rpc/middleware.rb b/lib/protobuf/rpc/middleware.rb index eaf1697d..9d20ae96 100644 --- a/lib/protobuf/rpc/middleware.rb +++ b/lib/protobuf/rpc/middleware.rb @@ -16,8 +16,8 @@ def self.middleware middleware end + Rpc.middleware.use(Rpc::Middleware::ExceptionHandler) Rpc.middleware.use(Rpc::Middleware::RequestDecoder) Rpc.middleware.use(Rpc::Middleware::Logger) Rpc.middleware.use(Rpc::Middleware::ResponseEncoder) - Rpc.middleware.use(Rpc::Middleware::ExceptionHandler) end diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index 0195e23f..94dd94ed 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -16,8 +16,9 @@ def call(env) log_exception(exception) # Rescue exceptions, re-wrap them as generic Protobuf errors, - # and set the response + # and encode them env.response = wrap_exception(exception) + env.encoded_response = env.response.encode env end diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 94754ae0..1bde4ff8 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -13,7 +13,14 @@ def initialize(app) def call(env) @env = env - call_app + request_wrapper = decode_request_data(env.encoded_request) + + env.request = request_wrapper + env.caller = request_wrapper.caller + env.service_name = request_wrapper.service_name + env.method_name = request_wrapper.method_name + + app.call(env) end def log_signature @@ -22,18 +29,6 @@ def log_signature private - def call_app - if env.request = decode_request_data(env.encoded_request) - env.caller = env.request.caller - env.service_name = env.request.service_name - env.method_name = env.request.method_name - - app.call(env) - else - env - end - end - # Decode the incoming request object into our expected request object # def decode_request_data(data) @@ -44,13 +39,9 @@ def decode_request_data(data) log_exception(exception) # Rescue decoding exceptions, re-wrap them as bad request data errors, - # and set the response so we can safely short-curcuit the rest of the + # and re-raise so we can safely short-curcuit the rest of the # middleware call. - error = BadRequestData.new("Unable to decode request: #{exception.message}") - env.response = error - env.encoded_response = error.to_response.encode - - return nil # Explicitly return nil so we don't continue up the stack + raise BadRequestData.new("Unable to decode request: #{exception.message}") end end end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 8dc83604..9687e20c 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -11,10 +11,12 @@ def initialize(app) end def call(env) - @env = app.call(env) - @env.encoded_response = encode_response_data(@env.response) + @env = env - @env + env = app.call(env) + env.encoded_response = encode_response_data(env.response) + + env end def log_signature @@ -34,13 +36,8 @@ def encode_response_data(response) log_exception(exception) # Rescue encoding exceptions, re-wrap them as generic protobuf errors, - # and set it as the encoded response so we always have something to - # send back - error = PbError.new(exception.message) - env.response = error - env.encoded_response = error.to_response.encode - ensure - return env.encoded_response + # and re-raise them + raise PbError.new(exception.message) end # The middleware stack returns either an error or response proto. Package diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 2fb9b27e..1dd9ce26 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -14,10 +14,9 @@ def initialize(app) def call(env) @env = env - init_service - init_method if service_klass.present? - register_rpc_failed if service.present? - + init_service! + init_method! + register_rpc_failed invoke! self.env @@ -51,11 +50,7 @@ def success? error.nil? end - private - - def assign_error(error_klass, message) - self.error = error_klass.new(message) - end + private # Prod the object to see if we can produce a proto object as a response # candidate. Either way, return the candidate for validation. @@ -78,32 +73,31 @@ def coerced_response # Get the method for the current request. # - def init_method + def init_method! method_name = outer_request.method_name.underscore.to_sym request_proto = outer_request.has_field?(:request_proto) ? outer_request.request_proto : nil - if service_klass.rpc_method?(method_name) - self.service = service_klass.new(method_name, request_proto, outer_request.caller) - self.callable_method = service.callable_rpc_method(method_name) - self.definition = service.rpcs[method_name] - else - assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not a defined rpc method.") + self.service = service_klass.new(method_name, request_proto, outer_request.caller) + + unless service_klass.rpc_method?(method_name) + raise MethodNotFound, "#{service.class.name}##{method_name} is not a defined rpc method." end - rescue NameError => e - # FIXME I think this is no longer applicable since the method extract - # is now wrapped in a lambda (@see Service#callable_rpc_method). - log_exception(e) - assign_error(MethodNotFound, "#{service.class.name}##{method_name} is not implemented.") + + unless self.service.respond_to?(method_name) + raise MethodNotFound, "#{service.class.name}##{method_name} is not implemented." + end + + self.callable_method = service.callable_rpc_method(method_name) + self.definition = service.rpcs[method_name] end # Constantize the service for this request. Initialization of the service # happens when we verify that the method is callable for this service. # - def init_service + def init_service! self.service_klass = outer_request.service_name.constantize - rescue NameError => e - log_exception(e) - assign_error(ServiceNotFound, "Service class #{outer_request.service_name} is not defined.") + rescue NameError + raise ServiceNotFound, "Service class #{outer_request.service_name} is not defined." end # Make sure we get rpc errors back. @@ -116,7 +110,8 @@ def register_rpc_failed # as the callable to the service when an `rpc_failed` call is invoked. # def rpc_failed_callback(message) - assign_error(RpcFailed, (message.respond_to?(:message) ? message.message : message)) + self.error = RpcFailed.new(message.respond_to?(:message) ? message.message : message) + log_error { sign_message("RPC Failed: #{error.message}") } end @@ -128,11 +123,11 @@ def validate_response expected = definition.response_type actual = candidate.class - if expected == actual - self.response = candidate - else - assign_error(BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}") + if expected != actual + raise BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}" end + + self.response = candidate end end end diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index 8780704b..3b8eb6e4 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -17,6 +17,7 @@ end context "when exceptions occur" do + let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } before { app.stub(:call).and_raise(error, 'Boom!') } @@ -26,17 +27,22 @@ end context "when exception is a Protobuf error" do - let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } + it "does not wrap the exception in a generic Protobuf error" do + stack_env = subject.call(env) - before { app.stub(:call).and_raise(error) } + # Can't compare the error instances because the response has been + # raised and thus has a backtrace while the error does not. + stack_env.response.class.should eq error.class + end - it "does not wrap the exception in a generic Protobuf error" do + it "encodes the response" do stack_env = subject.call(env) - stack_env.response.should eq error + stack_env.encoded_response.should eq encoded_error end end context "when exception is not a Protobuf error" do + let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::PbError.new('Boom!') } before { app.stub(:call).and_raise(RuntimeError, 'Boom!') } @@ -45,6 +51,11 @@ stack_env = subject.call(env) stack_env.response.should eq error end + + it "encodes the wrapped exception" do + stack_env = subject.call(env) + stack_env.encoded_response.should eq encoded_error + end end end end diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 4ae9abe4..060444db 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -49,19 +49,10 @@ end context "when decoding fails" do - let(:error) { Protobuf::Rpc::BadRequestData.new("Unable to decode request: Boom!") } - let(:response) { error.to_response } + before { Protobuf::Socketrpc::Request.stub(:decode).and_raise(RuntimeError) } - before { Protobuf::Socketrpc::Request.stub(:decode).and_raise(RuntimeError, 'Boom!') } - - it "does not call the stack" do - app.should_not_receive(:call) - subject.call(env) - end - - it "sets Env#response" do - stack_env = subject.call(env) - stack_env.response.should eq error + it "raises a bad request data exception" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadRequestData) end end end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 81dd2922..f16e907c 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -47,19 +47,10 @@ end context "when encoding fails" do - let(:error) { Protobuf::Rpc::PbError.new('Boom!') } - let(:response) { error.to_response } - - before { Protobuf::Socketrpc::Response.stub(:encode).and_raise(RuntimeError, 'Boom!') } - - it "sets Env#response" do - stack_env = subject.call(env) - stack_env.response.should eq error - end + before { Protobuf::Socketrpc::Response.stub(:encode).and_raise(RuntimeError) } - it "encodes the response" do - stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_response + it "raises a bad request data exception" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError) end end end From 97940a807bfa3b2ce1942b0265e2720a1dc380ea Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 16:09:31 -0700 Subject: [PATCH 0600/1191] Delete deprecated message/message.rb file --- lib/protobuf/field/base_field.rb | 5 +++-- lib/protobuf/field/message_field.rb | 6 ++++-- lib/protobuf/message/message.rb | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) delete mode 100644 lib/protobuf/message/message.rb diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 2458e281..41eed43a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -16,7 +16,8 @@ class BaseField ## # Attributes # - attr_reader :message_class, :rule, :type, :name, :tag, :default, :default_value, :setter_method_name, :getter_method_name + attr_reader :default, :default_value, :getter_method_name, :message_class, + :name, :rule, :setter_method_name, :tag, :type ## # Class Methods @@ -35,7 +36,7 @@ def initialize(message_class, rule, type, name, tag, options) set_rule_predicates @getter_method_name = name - @setter_method_name = "#{name}=".to_sym + @setter_method_name = "#{name}=" @default = options.delete(:default) @extension = options.delete(:extension) @packed = repeated? && options.delete(:packed) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index ead5807a..f5566864 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -3,13 +3,15 @@ module Protobuf module Field class MessageField < BaseField - RAISE_TYPE = lambda { |field, val| raise TypeError, "Expected value of type '#{field.type}' for field #{field.name}, but got '#{val.class}'" } ## # Public Instance Methods # + def acceptable?(val) - RAISE_TYPE.call(self, val) unless val.instance_of?(type) || val.respond_to?(:to_hash) + unless val.instance_of?(type) || val.respond_to?(:to_hash) + raise TypeError, "Expected value of type '#{self.type}' for field #{self.name}, but got '#{val.class}'" + end true end diff --git a/lib/protobuf/message/message.rb b/lib/protobuf/message/message.rb deleted file mode 100644 index fafcd564..00000000 --- a/lib/protobuf/message/message.rb +++ /dev/null @@ -1 +0,0 @@ -require 'protobuf/message' # Need to get rid of this From f886939d817da055e6ccfe2f8dcc533db2fa070a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 16:10:39 -0700 Subject: [PATCH 0601/1191] Split up decoder into smaller methods, also invoking a block on each decoded field --- lib/protobuf/message/decoder.rb | 83 ++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/lib/protobuf/message/decoder.rb b/lib/protobuf/message/decoder.rb index ff21d284..b3c64d7b 100644 --- a/lib/protobuf/message/decoder.rb +++ b/lib/protobuf/message/decoder.rb @@ -2,14 +2,20 @@ require 'protobuf/exceptions' module Protobuf + class Message + module Decoder - module Decoder + # Read bytes from +stream+ and pass to +message+ object. + def self.decode_each_field(stream, &block) + until stream.eof? + tag, bytes = read_field(stream) + block.call(tag, bytes) + end + end - module_function + private - # Read bytes from +stream+ and pass to +message+ object. - def decode(stream, message) - until stream.eof? + def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type @@ -28,45 +34,46 @@ def decode(stream, message) else raise InvalidWireType, wire_type end - message.set_field(tag, bytes) + + return tag, bytes end - message - end - # Read key pair (tag and wire-type) from +stream+. - def read_key(stream) - bits = read_varint(stream) - wire_type = bits & 0x07 - tag = bits >> 3 - [tag, wire_type] - end + # Read key pair (tag and wire-type) from +stream+. + def self.read_key(stream) + bits = read_varint(stream) + wire_type = bits & 0x07 + tag = bits >> 3 + [tag, wire_type] + end - # Read varint integer value from +stream+. - def read_varint(stream) - value = index = 0 - begin - byte = stream.readbyte - value |= (byte & 0x7f) << (7 * index) - index += 1 - end while (byte & 0x80).nonzero? - value - end + # Read varint integer value from +stream+. + def self.read_varint(stream) + value = index = 0 + begin + byte = stream.readbyte + value |= (byte & 0x7f) << (7 * index) + index += 1 + end while (byte & 0x80).nonzero? + value + end - # Read 32-bit string value from +stream+. - def read_fixed32(stream) - stream.read(4) - end + # Read 32-bit string value from +stream+. + def self.read_fixed32(stream) + stream.read(4) + end - # Read 64-bit string value from +stream+. - def read_fixed64(stream) - stream.read(8) - end + # Read 64-bit string value from +stream+. + def self.read_fixed64(stream) + stream.read(8) + end - # Read length-delimited string value from +stream+. - def read_length_delimited(stream) - value_length = read_varint(stream) - stream.read(value_length) - end + # Read length-delimited string value from +stream+. + def self.read_length_delimited(stream) + value_length = read_varint(stream) + stream.read(value_length) + end + end end end + From 02d4095982d6d2275a4f54294c9d3cabd5c64ce0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 16:11:20 -0700 Subject: [PATCH 0602/1191] Make an Encoder module patterned after the Decoder, extract encoding logic from Message instance --- lib/protobuf/message/encoder.rb | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/protobuf/message/encoder.rb diff --git a/lib/protobuf/message/encoder.rb b/lib/protobuf/message/encoder.rb new file mode 100644 index 00000000..b53de4db --- /dev/null +++ b/lib/protobuf/message/encoder.rb @@ -0,0 +1,49 @@ +module Protobuf + class Message + module Encoder + + def self.encode(stream, message) + message.each_field_for_serialization do |field, value| + encode_field(field, value, stream) + end + + stream + end + + private + + def self.encode_field(field, value, stream) + if field.repeated? + encode_repeated_field(field, value, stream) + else + write_pair(stream, field, value) + end + end + + def self.encode_packed_field(field, value, stream) + key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED + packed_value = value.map { |val| field.encode(val) }.join + stream << ::Protobuf::Field::VarintField.encode(key) + stream << ::Protobuf::Field::VarintField.encode(packed_value.size) + stream << packed_value + end + + def self.encode_repeated_field(field, value, stream) + if field.packed? + encode_packed_field(field, value, stream) + else + value.each { |val| write_pair(stream, field, val) } + end + end + + # Encode key and value, and write to +stream+. + def self.write_pair(stream, field, value) + key = (field.tag << 3) | field.wire_type + stream << ::Protobuf::Field::VarintField.encode(key) + stream << field.encode(value) + end + + end + end +end + From aba60520c93c50ad049a6f749867b5efc383c864 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 16:13:34 -0700 Subject: [PATCH 0603/1191] Extract class-level message field handling to a DSL module --- lib/protobuf/message.rb | 113 ++------------------------ lib/protobuf/message/dsl/fields.rb | 124 +++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 107 deletions(-) create mode 100644 lib/protobuf/message/dsl/fields.rb diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index dbb2418a..2285de86 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,126 +1,26 @@ -require 'stringio' -require 'set' require 'protobuf/field' require 'protobuf/enum' require 'protobuf/exceptions' require 'protobuf/message/decoder' +require 'protobuf/message/dsl/fields' module Protobuf class Message ## - # Class Methods + # Includes & Extends # - def self.all_fields - @all_fields ||= begin - all_fields_array = [] - max_fields = fields.size > extension_fields.size ? fields.size : extension_fields.size - max_fields.times do |field_number| - all_fields_array << (fields[field_number] || extension_fields[field_number]) - end - all_fields_array.compact! - all_fields_array - end - end - def self.decode(bytes) self.new.decode(bytes) end - # Define a field. Don't use this method directly. - def self.define_field(rule, type, fname, tag, options) - field_array = options[:extension] ? extension_fields : fields - field_name_hash = options[:extension] ? extension_field_name_to_tag : field_name_to_tag - - previous_tag_field = get_field_by_tag(tag) || get_ext_field_by_tag(tag) - if previous_tag_field - raise TagCollisionError, %!Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".! - end - - previous_name_field = get_field_by_name(fname) || get_ext_field_by_name(fname) - if previous_name_field - raise DuplicateFieldNameError, %!Field name #{fname} has already been used in "#{self.name}".! - end - - field_definition = ::Protobuf::Field.build(self, rule, type, fname, tag, options) - field_name_hash[fname] = tag - field_array[tag] = field_definition - - define_method("#{fname}!") do - @values[fname] - end - end - # Create a new object with the given values and return the encoded bytes. def self.encode(values = {}) self.new(values).encode end - # Reserve field numbers for extensions. Don't use this method directly. - def self.extensions(range) - extension_fields.add_range(range) - end - - def self.extension_field_name_to_tag - @extension_fields_by_name ||= {} - end - - # An extension field object. - def self.extension_fields - @extension_fields ||= ::Protobuf::Field::ExtensionFields.new - end - - def self.extension_tag?(tag) - extension_fields.include_tag?(tag) - end - - # A collection of field object. - def self.fields - @fields ||= [] - end - - def self.field_name_to_tag - @field_name_to_tag ||= {} - end - - def self.get_ext_field_by_name(name) - tag = extension_field_name_to_tag[name.to_sym] - extension_fields[tag] unless tag.nil? - end - - def self.get_ext_field_by_tag(tag) - extension_fields[tag] - end - - # Find a field object by +name+. - def self.get_field_by_name(name) - name = name.to_sym if name.respond_to?(:to_sym) - tag = field_name_to_tag[name] - fields[tag] unless tag.nil? - end - # Find a field object by +tag+ number. - def self.get_field_by_tag(tag) - fields[tag] - rescue TypeError - tag = tag.nil? ? 'nil' : tag.to_s - raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") - end - - # Define a optional field. Don't use this method directly. - def self.optional(type, name, tag, options = {}) - define_field(:optional, type, name, tag, options) - end - - # Define a repeated field. Don't use this method directly. - def self.repeated(type, name, tag, options = {}) - define_field(:repeated, type, name, tag, options) - end - - # Define a required field. Don't use this method directly. - def self.required(type, name, tag, options = {}) - define_field(:required, type, name, tag, options) - end + extend ::Protobuf::Message::DSL::Fields ## # Constructor @@ -134,6 +34,7 @@ def initialize(values = {}) ## # Public Instance Methods # + def all_fields self.class.all_fields end @@ -225,20 +126,18 @@ def fields self.class.fields end - def get_ext_field_by_name(name) # :nodoc: + def get_ext_field_by_name(name) self.class.get_ext_field_by_name(name) end - def get_ext_field_by_tag(tag) # :nodoc: + def get_ext_field_by_tag(tag) self.class.get_ext_field_by_tag(tag) end - # Returns field object or +nil+. def get_field_by_name(name) self.class.get_field_by_name(name) end - # Returns field object or +nil+. def get_field_by_tag(tag) self.class.get_field_by_tag(tag) end diff --git a/lib/protobuf/message/dsl/fields.rb b/lib/protobuf/message/dsl/fields.rb new file mode 100644 index 00000000..214954ba --- /dev/null +++ b/lib/protobuf/message/dsl/fields.rb @@ -0,0 +1,124 @@ +module Protobuf + class Message + module DSL + module Fields + + ## + # Field Definition Methods + # + + # Define an optional field. + # + def optional(type, name, tag, options = {}) + define_field(:optional, type, name, tag, options) + end + + # Define a repeated field. + # + def repeated(type, name, tag, options = {}) + define_field(:repeated, type, name, tag, options) + end + + # Define a required field. + # + def required(type, name, tag, options = {}) + define_field(:required, type, name, tag, options) + end + + # Define an extension range. + # + def extensions(range) + extension_fields.add_range(range) + end + + ## + # Field Access Methods + # + + def all_fields + @all_fields ||= begin + all_fields_array = [] + max_fields = fields.size > extension_fields.size ? fields.size : extension_fields.size + max_fields.times do |field_number| + all_fields_array << (fields[field_number] || extension_fields[field_number]) + end + all_fields_array.compact! + all_fields_array + end + end + + def extension_fields + @extension_fields ||= ::Protobuf::Field::ExtensionFields.new + end + + def extension_field_name_to_tag + @extension_fields_by_name ||= {} + end + + def extension_tag?(tag) + extension_fields.include_tag?(tag) + end + + def fields + @fields ||= [] + end + + def field_name_to_tag + @field_name_to_tag ||= {} + end + + def get_ext_field_by_name(name) + tag = extension_field_name_to_tag[name.to_sym] + extension_fields[tag] unless tag.nil? + end + + def get_ext_field_by_tag(tag) + extension_fields[tag] + end + + def get_field_by_name(name) + name = name.to_sym if name.respond_to?(:to_sym) + tag = field_name_to_tag[name] + fields[tag] unless tag.nil? + end + + def get_field_by_tag(tag) + fields[tag] + rescue TypeError + tag = tag.try(:to_s) || 'nil' + raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") + end + + private + + # Define a field. Don't use this method directly. + def define_field(rule, type, fname, tag, options) + field_array = options[:extension] ? extension_fields : fields + field_name_hash = options[:extension] ? extension_field_name_to_tag : field_name_to_tag + + previous_tag_field = get_field_by_tag(tag) || get_ext_field_by_tag(tag) + if previous_tag_field + raise TagCollisionError, %!Field number #{tag} has already been used in "#{name}" by field "#{fname}".! + end + + previous_name_field = get_field_by_name(fname) || get_ext_field_by_name(fname) + if previous_name_field + raise DuplicateFieldNameError, %!Field name #{fname} has already been used in "#{name}".! + end + + field_definition = ::Protobuf::Field.build(self, rule, type, fname, tag, options) + field_name_hash[fname] = tag + field_array[tag] = field_definition + + class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) + define_method("#{fname}!") do + @values[:#{fname}] + end + RAW_GETTER + end + + end + end + end +end + From 371217f4967dcc1fae7701516452c98216a7f505 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 16:14:10 -0700 Subject: [PATCH 0604/1191] Extract encoding/decoding logic to an encoding module that is then included in the message class --- lib/protobuf/message.rb | 73 ++-------------------------- lib/protobuf/message/encoding.rb | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 69 deletions(-) create mode 100644 lib/protobuf/message/encoding.rb diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 2285de86..2939df2e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,8 +1,8 @@ require 'protobuf/field' require 'protobuf/enum' require 'protobuf/exceptions' -require 'protobuf/message/decoder' require 'protobuf/message/dsl/fields' +require 'protobuf/message/encoding' module Protobuf class Message @@ -10,17 +10,9 @@ class Message ## # Includes & Extends # - def self.decode(bytes) - self.new.decode(bytes) - end - - # Create a new object with the given values and return the encoded bytes. - def self.encode(values = {}) - self.new(values).encode - end - extend ::Protobuf::Message::DSL::Fields + include ::Protobuf::Message::Encoding ## # Constructor @@ -55,16 +47,6 @@ def clone copy_to(super, :clone) end - # Decode the given string bytes into this object. - def decode(string) - decode_from(::StringIO.new(string)) - end - - # Decode the given stream into this object. - def decode_from(stream) - Decoder.decode(stream, self) - end - def dup copy_to(super, :dup) end @@ -82,41 +64,18 @@ def each_field def each_field_for_serialization all_fields.each do |field| - next unless __field_must_be_serialized__?(field) + next unless field_must_be_serialized?(field) value = @values[field.name] if value.nil? - # Only way you can get here is if you are required and nil - raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}" + raise ::Protobuf::SerializationError, "Required field #{self.name}##{field.name} does not have a value." else yield(field, value) end end end - def encode - stream = "" - - each_field_for_serialization do |field, value| - if field.repeated? - if field.packed? - key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED - packed_value = value.map { |val| field.encode(val) }.join - stream << ::Protobuf::Field::VarintField.encode(key) - stream << ::Protobuf::Field::VarintField.encode(packed_value.size) - stream << packed_value - else - value.each { |val| write_pair(stream, field, val) } - end - else - write_pair(stream, field, value) - end - end - - return stream - end - # Returns extension fields. See Message#fields method. def extension_fields self.class.extension_fields @@ -159,11 +118,6 @@ def respond_to_has_and_present?(key) (self.__send__(key).present? || [true, false].include?(self.__send__(key))) end - def set_field(tag, bytes) - field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) - field.set(self, bytes) if field - end - # Return a hash-representation of the given fields for this message type. def to_hash result = Hash.new @@ -208,14 +162,6 @@ def []=(name, value) ## # Instance Aliases # - alias_method :parse_from_string, :decode - alias_method :deserialize, :decode - alias_method :parse_from, :decode_from - alias_method :deserialize_from, :decode_from - alias_method :to_s, :encode - alias_method :bytes, :encode - alias_method :serialize, :encode - alias_method :serialize_to_string, :encode alias_method :to_hash_value, :to_hash alias_method :to_proto_hash, :to_hash alias_method :responds_to_has?, :respond_to_has? @@ -252,16 +198,5 @@ def copy_to(object, method) object end - def __field_must_be_serialized__?(field) - field.required? || !@values[field.name].nil? - end - - # Encode key and value, and write to +stream+. - def write_pair(stream, field, value) - key = (field.tag << 3) | field.wire_type - stream << ::Protobuf::Field::VarintField.encode(key) - stream << field.encode(value) - end - end end diff --git a/lib/protobuf/message/encoding.rb b/lib/protobuf/message/encoding.rb new file mode 100644 index 00000000..d030fc2a --- /dev/null +++ b/lib/protobuf/message/encoding.rb @@ -0,0 +1,82 @@ +require 'stringio' +require 'protobuf/message/decoder' +require 'protobuf/message/encoder' + +module Protobuf + class Message + module Encoding + + module ClassMethods + def decode(bytes) + self.new.decode(bytes) + end + + # Create a new object with the given values and return the encoded bytes. + def encode(fields = {}) + self.new(fields).encode + end + end + + def self.included(other) + other.extend(ClassMethods) + end + + ## + # Instance Methods + # + + # Decode the given non-stream bytes into this message. + # + def decode(bytes) + decode_from(::StringIO.new(bytes)) + end + + # Decode the given stream into this message. + # + def decode_from(stream) + ::Protobuf::Message::Decoder.decode_each_field(stream) do |tag, bytes| + set_field_bytes(tag, bytes) + end + + self + end + + # Encode this message + # + def encode + encode_to(::StringIO.new).string + end + + # Encode this message to the given stream. + # + def encode_to(stream) + ::Protobuf::Message::Encoder.encode(stream, self) + end + + ## + # Instance Aliases + # + alias_method :parse_from_string, :decode + alias_method :deserialize, :decode + alias_method :parse_from, :decode_from + alias_method :deserialize_from, :decode_from + alias_method :to_s, :encode + alias_method :bytes, :encode + alias_method :serialize, :encode + alias_method :serialize_to_string, :encode + + private + + def field_must_be_serialized?(field) + field.required? || ! @values[field.name].nil? + end + + def set_field_bytes(tag, bytes) + field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) + field.set(self, bytes) if field + end + + end + end +end + From 6c61bf72b6fbe4bd56ece97577591175fdb0163a Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Feb 2014 17:48:39 -0700 Subject: [PATCH 0605/1191] Decode everything in the request decoder Before, the request wrapper was the only thing decoded in request decoder. The request was decoded inside the service and the service dispatcher handled parsing the service and method names into the RPC service and method. This made it impossible to interact with the request or various request meta data in middlewares without doing everything being done in the service dispatcher. It also made the dispatcher responsible for a lot of validation enforcement. Instead, the whole request wrapper, including the request is decoded in the request decoder and the env is populated with the meta data so it's available to other middlewares that might need it. Since the service is no longer decoding the request, it is initialized with the env object, which contains everything it needs. This has the added benefit of making the env available inside any RPC endpoint. --- lib/protobuf/rpc/env.rb | 4 + .../rpc/middleware/request_decoder.rb | 62 +++++-- lib/protobuf/rpc/service.rb | 80 ++++----- lib/protobuf/rpc/service_dispatcher.rb | 94 ++++------ .../rpc/middleware/request_decoder_spec.rb | 68 +++++++- .../protobuf/rpc/service_dispatcher_spec.rb | 165 +++++++++--------- spec/lib/protobuf/rpc/service_spec.rb | 39 +++-- spec/support/test/resource.pb.rb | 1 + spec/support/test/resource.proto | 1 + spec/support/test/resource_service.rb | 5 + 10 files changed, 292 insertions(+), 227 deletions(-) diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index d235af12..e3cc1b37 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -40,7 +40,11 @@ def #{name}? :log_signature, :method_name, :request, + :request_type, :response, + :response_type, + :rpc_method, + :rpc_service, :service_name, :worker_id diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 1bde4ff8..80191dc1 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -13,12 +13,15 @@ def initialize(app) def call(env) @env = env - request_wrapper = decode_request_data(env.encoded_request) - - env.request = request_wrapper + env.service_name = service_name + env.method_name = method_name + env.request = request env.caller = request_wrapper.caller - env.service_name = request_wrapper.service_name - env.method_name = request_wrapper.method_name + + env.rpc_service = service + env.rpc_method = rpc_method + env.request_type = rpc_method.request_type + env.response_type = rpc_method.response_type app.call(env) end @@ -29,20 +32,51 @@ def log_signature private - # Decode the incoming request object into our expected request object - # - def decode_request_data(data) - log_debug { sign_message("Decoding request: #{data}") } + def method_name + @method_name ||= begin + method_name = request_wrapper.method_name.underscore.to_sym + + unless service.rpc_method?(method_name) + raise MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.") + end - Socketrpc::Request.decode(data) + method_name + end + end + + def request + @request ||= begin + data = request_wrapper.request_proto + rpc_method.request_type.decode(data) + end rescue => exception - log_exception(exception) + raise BadRequestData.new("Unable to decode request: #{exception.message}") + end - # Rescue decoding exceptions, re-wrap them as bad request data errors, - # and re-raise so we can safely short-curcuit the rest of the - # middleware call. + # Decode the incoming request object into our expected request object + # + def request_wrapper + @request_wrapper ||= begin + log_debug { sign_message("Decoding request: #{env.encoded_request}") } + Socketrpc::Request.decode(env.encoded_request) + end + rescue => exception raise BadRequestData.new("Unable to decode request: #{exception.message}") end + + def rpc_method + @rpc_method ||= service.rpcs[method_name] + end + + def service + @service ||= service_name.constantize + rescue NameError + raise ServiceNotFound.new("Service class #{service_name} is not defined.") + end + + def service_name + @service_name ||= request_wrapper.service_name + end end end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 434ad70d..c253a3f0 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -11,17 +11,29 @@ module Rpc RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) class Service - include ::Protobuf::Rpc::ServiceFilters include ::Protobuf::Logger::LogMethods - + include ::Protobuf::Rpc::ServiceFilters DEFAULT_HOST = '127.0.0.1'.freeze DEFAULT_PORT = 9399 + attr_reader :client_host, :env, :method_name, :request + ## - # Class Methods + # Constructor! # + # Initialize a service with the rpc endpoint name and the bytes + # for the request. + def initialize(env) + @env = env.dup # Dup the env so it doesn't change out from under us + @method_name = env.method_name + @request = env.request + @client_host = env.caller + end + ## + # Class Methods + # # Create a new client for the given service. # See Client#initialize and ClientConnection::DEFAULT_OPTIONS # for all available options. @@ -54,6 +66,18 @@ def self.host=(new_host) @_host = new_host end + # An array of defined service classes that contain implementation + # code + def self.implemented_services + classes = (self.subclasses || []).select do |subclass| + subclass.rpcs.any? do |(name, _)| + subclass.method_defined? name + end + end + + classes.map(&:name) + end + # Shorthand call to configure, passing a string formatted as hostname:port # e.g. 127.0.0.1:9933 # e.g. localhost:0 @@ -96,30 +120,16 @@ def self.rpc_method?(name) rpcs.key?(name) end - # An array of defined service classes that contain implementation - # code - def self.implemented_services - classes = (self.subclasses || []).select do |subclass| - subclass.rpcs.any? do |(name, _)| - subclass.method_defined? name - end - end - - classes.map(&:name) - end - ## # Instance Methods # - - attr_reader :response, :method_name, :client_host - - # Initialize a service with the rpc endpoint name and the bytes - # for the request. - def initialize(method_name, request_bytes, client_host = nil) - @method_name = method_name - @client_host = client_host - @_request_bytes = request_bytes + # Get a callable object that will be used by the dispatcher + # to invoke the specified rpc method. Facilitates callback dispatch. + # The returned lambda is expected to be called at a later time (which + # is why we wrap the method call). + # + def callable_rpc_method(method_name) + lambda { run_filters(method_name) } end # Register a failure callback for use when rpc_failed is invoked. @@ -134,18 +144,6 @@ def response @_response ||= response_type.new end - # Request object for this rpc cycle. Not assignable. - # - def request - @_request ||= if @_request_bytes.present? - request_type.decode(@_request_bytes) - else - request_type.new - end - rescue => e - raise BadRequestProto, "Unable to parse request: #{e.message}" - end - # Convenience method to get back to class method. # def rpc_method?(name) @@ -158,15 +156,6 @@ def rpcs self.class.rpcs end - # Get a callable object that will be used by the dispatcher - # to invoke the specified rpc method. Facilitates callback dispatch. - # The returned lambda is expected to be called at a later time (which - # is why we wrap the method call). - # - def callable_rpc_method(method_name) - lambda { run_filters(method_name) } - end - private def response_type @@ -191,7 +180,6 @@ def respond_with(candidate) def rpc_failed(message) @_rpc_failed_callback.call(message) end - end if ActiveSupport::VERSION::MAJOR > 2 diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 1dd9ce26..a3ca44fd 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -5,7 +5,7 @@ module Rpc class ServiceDispatcher include ::Protobuf::Logger::LogMethods - attr_accessor :callable_method, :definition, :env, :error, :response, :service, :service_klass + attr_reader :env def initialize(app) # End of the line... @@ -14,48 +14,32 @@ def initialize(app) def call(env) @env = env - init_service! - init_method! register_rpc_failed - invoke! - self.env + env.response = dispatch_rpc_request + env end - # We're in error if the error is populated. - # - def error? - ! success? + def rpc_service + @rpc_service ||= env.rpc_service.new(env) end - # Call the given service method. If we get to this point and an error - # has already occurred, do not invoke the method and simply respond. + private + + # Get a callable RPC method for the current request. # - def invoke! - unless error? - callable_method.call - validate_response + def callable_rpc_method + unless rpc_service.respond_to?(method_name) + raise MethodNotFound.new("#{rpc_service.class.name}##{method_name} is not implemented.") end - env.response = error || response - end - - def outer_request - env.request + rpc_service.callable_rpc_method(method_name) end - # We're successful if the error is not populated. - # - def success? - error.nil? - end - - private - # Prod the object to see if we can produce a proto object as a response # candidate. Either way, return the candidate for validation. def coerced_response - candidate = service.response + candidate = rpc_service.response case when candidate.is_a?(::Protobuf::Message) then @@ -63,71 +47,55 @@ def coerced_response when candidate.respond_to?(:to_proto) then candidate = candidate.to_proto when candidate.respond_to?(:to_proto_hash) then - candidate = definition.response_type.new(candidate.to_proto_hash) + candidate = env.response_type.new(candidate.to_proto_hash) when candidate.respond_to?(:to_hash) then - candidate = definition.response_type.new(candidate.to_hash) + candidate = env.response_type.new(candidate.to_hash) end candidate end - # Get the method for the current request. - # - def init_method! - method_name = outer_request.method_name.underscore.to_sym - request_proto = outer_request.has_field?(:request_proto) ? outer_request.request_proto : nil - - self.service = service_klass.new(method_name, request_proto, outer_request.caller) - - unless service_klass.rpc_method?(method_name) - raise MethodNotFound, "#{service.class.name}##{method_name} is not a defined rpc method." - end - - unless self.service.respond_to?(method_name) - raise MethodNotFound, "#{service.class.name}##{method_name} is not implemented." - end - - self.callable_method = service.callable_rpc_method(method_name) - self.definition = service.rpcs[method_name] + def dispatch_rpc_request + # Call the given service method. + callable_rpc_method.call + validate_response! end - # Constantize the service for this request. Initialization of the service - # happens when we verify that the method is callable for this service. - # - def init_service! - self.service_klass = outer_request.service_name.constantize - rescue NameError - raise ServiceNotFound, "Service class #{outer_request.service_name} is not defined." + def method_name + env.method_name end # Make sure we get rpc errors back. # def register_rpc_failed - service.on_rpc_failed(method(:rpc_failed_callback)) + rpc_service.on_rpc_failed(method(:rpc_failed_callback)) end # Receive the failure message from the service. This method is registered # as the callable to the service when an `rpc_failed` call is invoked. # def rpc_failed_callback(message) - self.error = RpcFailed.new(message.respond_to?(:message) ? message.message : message) + message = message.message if message.respond_to?(:message) + raise RpcFailed.new(message) + end - log_error { sign_message("RPC Failed: #{error.message}") } + def rpc_method + env.rpc_method end # Ensure that the response candidate we've been given is of the type # we expect so that deserialization on the client side works. # - def validate_response + def validate_response! candidate = coerced_response - expected = definition.response_type actual = candidate.class + expected = env.response_type if expected != actual - raise BadResponseProto, "Response proto changed from #{expected.name} to #{actual.name}" + raise BadResponseProto.new("Response proto changed from #{expected.name} to #{actual.name}") end - self.response = candidate + candidate end end end diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 060444db..78b240ba 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -9,16 +9,22 @@ 'log_signature' => 'log_signature' ) } - let(:encoded_request) { request.encode } - let(:method_name) { 'bar' } - let(:request) { + let(:encoded_request) { request_wrapper.encode } + let(:method_name) { :find } + let(:request) { request_type.new(:name => 'required') } + let(:request_type) { rpc_method.request_type } + let(:request_wrapper) { Protobuf::Socketrpc::Request.new( :caller => caller, :service_name => service_name, - :method_name => method_name + :method_name => method_name.to_s, + :request_proto => request ) } - let(:service_name) { 'Foo' } + let(:response_type) { rpc_method.response_type } + let(:rpc_method) { rpc_service.rpcs[method_name] } + let(:rpc_service) { Test::ResourceService } + let(:service_name) { rpc_service.to_s } subject { described_class.new(app) } @@ -45,7 +51,27 @@ it "sets Env#method_name" do stack_env = subject.call(env) - stack_env.method_name.should eq method_name + stack_env.method_name.should eq method_name.to_sym + end + + it "sets Env#request_type" do + stack_env = subject.call(env) + stack_env.request_type.should eq request_type + end + + it "sets Env#response_type" do + stack_env = subject.call(env) + stack_env.response_type.should eq response_type + end + + it "sets Env#rpc_method" do + stack_env = subject.call(env) + stack_env.rpc_method.should eq rpc_method + end + + it "sets Env#rpc_service" do + stack_env = subject.call(env) + stack_env.rpc_service.should eq rpc_service end context "when decoding fails" do @@ -55,5 +81,35 @@ expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadRequestData) end end + + context "when the RPC service is not defined" do + let(:request_wrapper) { + Protobuf::Socketrpc::Request.new( + :caller => caller, + :service_name => 'Foo', + :method_name => method_name.to_s, + :request_proto => request + ) + } + + it "raises a bad request data exception" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::ServiceNotFound) + end + end + + context "when RPC method is not defined" do + let(:request_wrapper) { + Protobuf::Socketrpc::Request.new( + :caller => caller, + :service_name => service_name, + :method_name => 'foo', + :request_proto => request + ) + } + + it "raises a bad request data exception" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) + end + end end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 85b89248..2e365d95 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -2,115 +2,110 @@ require 'protobuf/rpc/service_dispatcher' describe Protobuf::Rpc::ServiceDispatcher do - let(:service_name) { 'Test::ResourceService' } - let(:method_name) { 'find' } - let(:request) { Test::ResourceFindRequest.new(:name => 'resource') } - let(:request_bytes) { request.to_s } - let(:response) { Test::Resource.new } - let(:wrapper) do - Protobuf::Socketrpc::Request.new({ :service_name => service_name, - :method_name => method_name, - :request_proto => request_bytes }) + let(:app) { Proc.new { |env| env } } + let(:caller) { 'caller.test.co' } + let(:env) { + Protobuf::Rpc::Env.new( + 'caller' => caller, + 'encoded_request' => encoded_request, + 'log_signature' => 'log_signature', + 'method_name' => method_name, + 'request' => request, + 'request_type' => request_type, + 'response_type' => response_type, + 'rpc_method' => rpc_method, + 'rpc_service' => service_class, + 'service_name' => service_name, + ) + } + let(:encoded_request) { request_wrapper.encode } + let(:method_name) { :find } + let(:request) { request_type.new(:name => 'required') } + let(:request_type) { rpc_method.request_type } + let(:request_wrapper) { + Protobuf::Socketrpc::Request.new( + :caller => caller, + :service_name => service_name, + :method_name => method_name.to_s, + :request_proto => request + ) + } + let(:response) { response_type.new(:name => 'required') } + let(:response_type) { rpc_method.response_type } + let(:rpc_method) { service_class.rpcs[method_name] } + let(:rpc_service) { service_class.new(env) } + let(:service_class) { Test::ResourceService } + let(:service_name) { service_class.to_s } + + subject { described_class.new(app) } + + before { subject.stub(:rpc_service).and_return(rpc_service) } + + describe '#call' do + before { rpc_service.stub(:callable_rpc_method).and_return(lambda {}) } - end - - subject { described_class.new(wrapper) } - - context 'creating a new dispatcher' do - its(:service) { should be_instance_of service_name.constantize } - its(:callable_method) { should respond_to(:call)} - its(:outer_request) { should eq wrapper } - its(:error) { should be_nil } - - context 'when service name is not a valid constant' do - let(:service_name) { 'FlibbityGibbit' } - its(:success?) { should be_false } - its(:error) { should be_instance_of(Protobuf::Rpc::ServiceNotFound) } - end - - context 'when method is not defined by the service' do - let(:method_name) { 'holly_hooby_whaty' } - its(:success?) { should be_false } - its(:error) { should be_instance_of(Protobuf::Rpc::MethodNotFound) } - end + context 'regular invocation' do + before { rpc_service.stub(:response).and_return(response) } - context 'when method is defined but is not an rpc method' do - before do - class Test::Resource - def non_rpc_method; end - end + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq response end - - let(:method_name) { 'non_rpc_method' } - its(:success?) { should be_false } - its(:error) { should be_instance_of(Protobuf::Rpc::MethodNotFound) } - end - end - - describe '#invoke!' do - context 'regular invocation' do - before { subject.callable_method.should_receive(:call) } - before { subject.service.stub(:response).and_return(response) } - before { subject.invoke! } - its(:response) { should be_instance_of Test::Resource } - its(:success?) { should be_true } end context 'when service responds with' do context 'a hash object' do - before { subject.callable_method.should_receive(:call) } - before { subject.service.stub(:response).and_return({ :name => 'returned' }) } - before { subject.invoke! } - its(:success?) { should be_true } - its(:response) { should eq Test::Resource.new(:name => 'returned') } + before { rpc_service.stub(:response).and_return(response.to_hash) } + + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq response + end end context 'an object that responds to to_hash but is not a hash' do - let(:hashable) do - double('hashable', :to_hash => { :name => 'hashable' }) + let(:hashable) { + double('hashable', :to_hash => response.to_hash) + } + + before { rpc_service.stub(:response).and_return(hashable) } + + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq response end - before { subject.callable_method.should_receive(:call) } - before { subject.service.stub(:response).and_return(hashable) } - before { subject.invoke! } - its(:success?) { should be_true } - its(:response) { should eq Test::Resource.new(:name => 'hashable') } end context 'an object that responds to to_proto' do - let(:protoable) do - double('protoable', :to_proto => Test::Resource.new(:name => 'protoable')) + let(:protoable) { + double('protoable', :to_proto => response) + } + + before { rpc_service.stub(:response).and_return(protoable) } + + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq response end - before { subject.callable_method.should_receive(:call) } - before { subject.service.stub(:response).and_return(protoable) } - before { subject.invoke! } - its(:success?) { should be_true } - its(:response) { should eq Test::Resource.new(:name => 'protoable') } end context 'a type not identified by the rpc definition' do - before { subject.callable_method.should_receive(:call) } - before { subject.service.stub(:response).and_return("I'm not a valid response") } - before { subject.invoke! } - its(:error) { should be_instance_of(Protobuf::Rpc::BadResponseProto) } + before { rpc_service.stub(:response).and_return("I'm not a valid response") } + + it "raises a bad response proto exception" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadResponseProto) + end end end context 'when service invokes rpc failed callback' do - before(:all) do - class Test::ResourceService - rpc :find_with_rpc_failed, Test::ResourceFindRequest, Test::Resource - def find_with_rpc_failed - rpc_failed('Find failed') - end - end - end + let(:method_name) { :find_with_rpc_failed } - let(:method_name) { 'find_with_rpc_failed' } - before { subject.service.find_with_rpc_failed } + before { rpc_service.stub(:callable_rpc_method).and_return(lambda { rpc_service.__send__(method_name) }) } - its(:success?) { should be_false } - its(:error) { should be_instance_of(Protobuf::Rpc::RpcFailed) } + it "sets Env#response to an error" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::RpcFailed) + end end end - end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index f9807b3d..c3db9d13 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -120,18 +120,19 @@ def find_with_rpc_failed end end - - let(:request) do - Test::ResourceFindRequest.new(:name => 'resource') - end - - let(:response) do - Test::Resource.new - end + let(:request) { Test::ResourceFindRequest.new(:name => 'resource') } + let(:response) { Test::Resource.new } context 'when calling the rpc method' do context 'when response is implied' do - subject { NewTestService.new(:find_with_implied_response, request.encode) } + let(:env) { + Protobuf::Rpc::Env.new( + 'method_name' => :find_with_implied_response, + 'request' => request + ) + } + + subject { NewTestService.new(env) } before { subject.find_with_implied_response } its(:response) { should be_a(Test::Resource) } @@ -139,7 +140,14 @@ def find_with_rpc_failed end context 'when using respond_with paradigm' do - subject { NewTestService.new(:find_with_respond_with, request.encode) } + let(:env) { + Protobuf::Rpc::Env.new( + 'method_name' => :find_with_respond_with, + 'request' => request + ) + } + + subject { NewTestService.new(env) } before { subject.find_with_respond_with } its(:response) { should be_a(Test::Resource) } @@ -148,7 +156,14 @@ def find_with_rpc_failed end context 'when calling rpc_failed in the method' do - subject { NewTestService.new(:find_with_rpc_failed, request.encode) } + let(:env) { + Protobuf::Rpc::Env.new( + 'method_name' => :find_with_rpc_failed, + 'request' => request + ) + } + + subject { NewTestService.new(env) } it 'invokes the rpc_failed callback with the error' do error = nil @@ -159,7 +174,5 @@ def find_with_rpc_failed end end end - end - end diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 0bca8a0c..f0c18fe4 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -103,6 +103,7 @@ class NestedLevelOne # class ResourceService < ::Protobuf::Rpc::Service rpc :find, ::Test::ResourceFindRequest, ::Test::Resource + rpc :find_with_rpc_failed, ::Test::ResourceFindRequest, ::Test::Resource rpc :find_with_sleep, ::Test::ResourceSleepRequest, ::Test::Resource end diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index 958ade6a..d97602f4 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -84,5 +84,6 @@ extend Nested.NestedLevelOne { service ResourceService { rpc Find (ResourceFindRequest) returns (Resource); + rpc FindWithRpcFailed (ResourceFindRequest) returns (Resource); rpc FindWithSleep (ResourceSleepRequest) returns (Resource); } diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index 33072ba4..226ea0da 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -17,5 +17,10 @@ def find_with_sleep response.name = 'Request should have timed out' end + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find_with_rpc_failed + rpc_failed('Find failed') + end end end From 6b340b576b9b07c26daa23214608270bbdbaaf95 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Feb 2014 20:53:31 -0700 Subject: [PATCH 0606/1191] Handle encoding/coercing/validation in the encoder Rather than having the dispatcher coerce and validate responses or handle that in a separate middleware, move it all into the encoder. --- .../rpc/middleware/response_encoder.rb | 52 ++++++++--- lib/protobuf/rpc/service.rb | 18 ++-- lib/protobuf/rpc/service_dispatcher.rb | 72 ++------------- .../rpc/middleware/response_encoder_spec.rb | 60 ++++++++----- .../protobuf/rpc/service_dispatcher_spec.rb | 90 +++---------------- 5 files changed, 111 insertions(+), 181 deletions(-) diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 9687e20c..5d6188ab 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -11,11 +11,10 @@ def initialize(app) end def call(env) - @env = env - - env = app.call(env) - env.encoded_response = encode_response_data(env.response) + @env = app.call(env) + env.response = response + env.encoded_response = encoded_response env end @@ -27,11 +26,10 @@ def log_signature # Encode the response wrapper to return to the client # - def encode_response_data(response) + def encoded_response log_debug { sign_message("Encoding response: #{response.inspect}") } - response = wrap_response(response) - env.encoded_response = Socketrpc::Response.encode(response) + env.encoded_response = wrapped_response.encode rescue => exception log_exception(exception) @@ -40,14 +38,48 @@ def encode_response_data(response) raise PbError.new(exception.message) end + # Prod the object to see if we can produce a proto object as a response + # candidate. Validate the candidate protos. + def response + @response ||= begin + candidate = env.response + case + when candidate.is_a?(Message) then + validate!(candidate) + when candidate.respond_to?(:to_proto) then + validate!(candidate.to_proto) + when candidate.respond_to?(:to_hash) then + env.response_type.new(candidate.to_hash) + when candidate.is_a?(PbError) then + candidate + else + validate!(candidate) + end + end + end + + # Ensure that the response candidate we've been given is of the type + # we expect so that deserialization on the client side works. + # + def validate!(candidate) + actual = candidate.class + expected = env.response_type + + if expected != actual + raise BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}") + end + + candidate + end + # The middleware stack returns either an error or response proto. Package # it up so that it's in the correct spot in the response wrapper # - def wrap_response(response) + def wrapped_response if response.is_a?(Protobuf::Rpc::PbError) - { :error => response.message, :error_reason => response.error_type } + Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) else - { :response_proto => response.encode } + Socketrpc::Response.new(:response_proto => response.encode) end end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index c253a3f0..b830e223 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -5,7 +5,6 @@ module Protobuf module Rpc - # Object to encapsulate the request/response types for a given service method # RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) @@ -29,6 +28,7 @@ def initialize(env) @method_name = env.method_name @request = env.request @client_host = env.caller + @_rpc_failed_callback = lambda { |message| __send__(:default_rpc_failed_callback, message) } end ## @@ -135,7 +135,7 @@ def callable_rpc_method(method_name) # Register a failure callback for use when rpc_failed is invoked. # def on_rpc_failed(callable) - @_rpc_failed_callback ||= callable + @_rpc_failed_callback = callable end # Response object for this rpc cycle. Not assignable. @@ -156,10 +156,14 @@ def rpcs self.class.rpcs end - private + private - def response_type - @_response_type ||= rpcs[@method_name].response_type + # Receive the failure message from the service. This method is registered + # as the callable to the service when an `rpc_failed` call is invoked. + # + def default_rpc_failed_callback(message) + message = message.message if message.respond_to?(:message) + raise RpcFailed.new(message) end def request_type @@ -175,6 +179,10 @@ def respond_with(candidate) end alias_method :return_from_whence_you_came, :respond_with + def response_type + @_response_type ||= rpcs[@method_name].response_type + end + # Automatically fail a service method. # def rpc_failed(message) diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index a3ca44fd..b3727252 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -14,8 +14,6 @@ def initialize(app) def call(env) @env = env - register_rpc_failed - env.response = dispatch_rpc_request env end @@ -26,76 +24,20 @@ def rpc_service private - # Get a callable RPC method for the current request. - # - def callable_rpc_method - unless rpc_service.respond_to?(method_name) - raise MethodNotFound.new("#{rpc_service.class.name}##{method_name} is not implemented.") - end - - rpc_service.callable_rpc_method(method_name) - end - - # Prod the object to see if we can produce a proto object as a response - # candidate. Either way, return the candidate for validation. - def coerced_response - candidate = rpc_service.response - - case - when candidate.is_a?(::Protobuf::Message) then - # no-op - when candidate.respond_to?(:to_proto) then - candidate = candidate.to_proto - when candidate.respond_to?(:to_proto_hash) then - candidate = env.response_type.new(candidate.to_proto_hash) - when candidate.respond_to?(:to_hash) then - candidate = env.response_type.new(candidate.to_hash) - end - - candidate - end - + # Call the given service method. def dispatch_rpc_request - # Call the given service method. - callable_rpc_method.call - validate_response! + rpc_service.callable_rpc_method(method_name).call + rpc_service.response + rescue NoMethodError + raise MethodNotFound.new("#{service_name}##{method_name} is not implemented.") end def method_name env.method_name end - # Make sure we get rpc errors back. - # - def register_rpc_failed - rpc_service.on_rpc_failed(method(:rpc_failed_callback)) - end - - # Receive the failure message from the service. This method is registered - # as the callable to the service when an `rpc_failed` call is invoked. - # - def rpc_failed_callback(message) - message = message.message if message.respond_to?(:message) - raise RpcFailed.new(message) - end - - def rpc_method - env.rpc_method - end - - # Ensure that the response candidate we've been given is of the type - # we expect so that deserialization on the client side works. - # - def validate_response! - candidate = coerced_response - actual = candidate.class - expected = env.response_type - - if expected != actual - raise BadResponseProto.new("Response proto changed from #{expected.name} to #{actual.name}") - end - - candidate + def service_name + env.service_name end end end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index f16e907c..dd58d7ba 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -1,20 +1,16 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::ResponseEncoder do - let(:app) { Proc.new { |env| env } } + let(:app) { Proc.new { |env| env.response = response; env } } let(:env) { Protobuf::Rpc::Env.new( - 'response' => response_proto, + 'response_type' => Test::Resource, 'log_signature' => 'log_signature' ) } - let(:encoded_response) { response.encode } - let(:response) { - Protobuf::Socketrpc::Response.new( - :response_proto => response_proto - ) - } - let(:response_proto) { Test::Resource.new(:name => 'required') } + let(:encoded_response) { response_wrapper.encode } + let(:response) { Test::Resource.new(:name => 'required') } + let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } subject { described_class.new(app) } @@ -25,29 +21,51 @@ end it "calls the stack" do - app.should_receive(:call).with(env).and_return(env) - subject.call(env) + stack_env = subject.call(env) + stack_env.response.should eq response + end + + context "when response is responds to :to_hash" do + let(:app) { proc { |env| env.response = hashable; env } } + let(:hashable) { double('hashable', :to_hash => response.to_hash) } + + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq response + end + end + + context "when response is responds to :to_proto" do + let(:app) { proc { |env| env.response = protoable; env } } + let(:protoable) { double('protoable', :to_proto => response) } + + it "sets Env#response" do + stack_env = subject.call(env) + stack_env.response.should eq response + end + end + + context "when response is not a valid response type" do + let(:app) { proc { |env| env.response = "I'm not a valid response"; env } } + + it "raises a bad response proto exception" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadResponseProto) + end end context "when response is a Protobuf error" do - let(:encoded_response) { response.encode } - let(:env) { - Protobuf::Rpc::Env.new( - 'response' => error, - 'log_signature' => 'log_signature' - ) - } + let(:app) { proc { |env| env.response = error; env } } let(:error) { Protobuf::Rpc::RpcError.new } - let(:response) { error.to_response } + let(:response_wrapper) { error.to_response } - it "encodes the response" do + it "wraps and encodes the response" do stack_env = subject.call(env) stack_env.encoded_response.should eq encoded_response end end context "when encoding fails" do - before { Protobuf::Socketrpc::Response.stub(:encode).and_raise(RuntimeError) } + before { Protobuf::Socketrpc::Response.any_instance.stub(:encode).and_raise(RuntimeError) } it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError) diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 2e365d95..c6087e19 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -2,37 +2,17 @@ require 'protobuf/rpc/service_dispatcher' describe Protobuf::Rpc::ServiceDispatcher do - let(:app) { Proc.new { |env| env } } - let(:caller) { 'caller.test.co' } + let(:app) { proc { |env| env } } let(:env) { Protobuf::Rpc::Env.new( - 'caller' => caller, - 'encoded_request' => encoded_request, - 'log_signature' => 'log_signature', 'method_name' => method_name, - 'request' => request, - 'request_type' => request_type, - 'response_type' => response_type, - 'rpc_method' => rpc_method, 'rpc_service' => service_class, 'service_name' => service_name, ) } - let(:encoded_request) { request_wrapper.encode } let(:method_name) { :find } - let(:request) { request_type.new(:name => 'required') } - let(:request_type) { rpc_method.request_type } - let(:request_wrapper) { - Protobuf::Socketrpc::Request.new( - :caller => caller, - :service_name => service_name, - :method_name => method_name.to_s, - :request_proto => request - ) - } let(:response) { response_type.new(:name => 'required') } - let(:response_type) { rpc_method.response_type } - let(:rpc_method) { service_class.rpcs[method_name] } + let(:response_type) { service_class.rpcs[method_name].response_type } let(:rpc_service) { service_class.new(env) } let(:service_class) { Test::ResourceService } let(:service_name) { service_class.to_s } @@ -43,68 +23,18 @@ describe '#call' do before { rpc_service.stub(:callable_rpc_method).and_return(lambda {}) } + before { rpc_service.stub(:response).and_return(response) } - context 'regular invocation' do - before { rpc_service.stub(:response).and_return(response) } - - it "sets Env#response" do - stack_env = subject.call(env) - stack_env.response.should eq response - end - end - - context 'when service responds with' do - context 'a hash object' do - before { rpc_service.stub(:response).and_return(response.to_hash) } - - it "sets Env#response" do - stack_env = subject.call(env) - stack_env.response.should eq response - end - end - - context 'an object that responds to to_hash but is not a hash' do - let(:hashable) { - double('hashable', :to_hash => response.to_hash) - } - - before { rpc_service.stub(:response).and_return(hashable) } - - it "sets Env#response" do - stack_env = subject.call(env) - stack_env.response.should eq response - end - end - - context 'an object that responds to to_proto' do - let(:protoable) { - double('protoable', :to_proto => response) - } - - before { rpc_service.stub(:response).and_return(protoable) } - - it "sets Env#response" do - stack_env = subject.call(env) - stack_env.response.should eq response - end - end - - context 'a type not identified by the rpc definition' do - before { rpc_service.stub(:response).and_return("I'm not a valid response") } - - it "raises a bad response proto exception" do - expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadResponseProto) - end - end + it "dispatches the request" do + stack_env = subject.call(env) + stack_env.response.should eq response end - context 'when service invokes rpc failed callback' do - let(:method_name) { :find_with_rpc_failed } - - before { rpc_service.stub(:callable_rpc_method).and_return(lambda { rpc_service.__send__(method_name) }) } + context "when the given RPC method is not implemented" do + before { rpc_service.stub(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } - it "sets Env#response to an error" do - expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::RpcFailed) + it "raises a method not found exception" do + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) end end end From 40b956755fa95e20dbd2dcce8ad2efa4a9d4847a Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Feb 2014 21:48:57 -0700 Subject: [PATCH 0607/1191] Remove the RPC failed callback Instead of providing a callback hook that is fired when rpc_failed is called, just take the given message and raise an RPC failed error. --- lib/protobuf/rpc/service.rb | 18 ++---------------- spec/lib/protobuf/rpc/service_spec.rb | 19 ------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index b830e223..cc514eef 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -28,7 +28,6 @@ def initialize(env) @method_name = env.method_name @request = env.request @client_host = env.caller - @_rpc_failed_callback = lambda { |message| __send__(:default_rpc_failed_callback, message) } end ## @@ -132,12 +131,6 @@ def callable_rpc_method(method_name) lambda { run_filters(method_name) } end - # Register a failure callback for use when rpc_failed is invoked. - # - def on_rpc_failed(callable) - @_rpc_failed_callback = callable - end - # Response object for this rpc cycle. Not assignable. # def response @@ -158,14 +151,6 @@ def rpcs private - # Receive the failure message from the service. This method is registered - # as the callable to the service when an `rpc_failed` call is invoked. - # - def default_rpc_failed_callback(message) - message = message.message if message.respond_to?(:message) - raise RpcFailed.new(message) - end - def request_type @_request_type ||= rpcs[@method_name].request_type end @@ -186,7 +171,8 @@ def response_type # Automatically fail a service method. # def rpc_failed(message) - @_rpc_failed_callback.call(message) + message = message.message if message.respond_to?(:message) + raise RpcFailed.new(message) end end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index c3db9d13..46d0a317 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -154,25 +154,6 @@ def find_with_rpc_failed specify { subject.response.name.should eq 'Custom response' } end end - - context 'when calling rpc_failed in the method' do - let(:env) { - Protobuf::Rpc::Env.new( - 'method_name' => :find_with_rpc_failed, - 'request' => request - ) - } - - subject { NewTestService.new(env) } - - it 'invokes the rpc_failed callback with the error' do - error = nil - subject.on_rpc_failed(lambda { |err| error = err }) - subject.find_with_rpc_failed - error.should eq 'This is a failed endpoint' - subject.response.name.should eq 'Name will still be set' - end - end end end end From 58ee58ed56e88e1a7aba5e9508e01f72ad059f2a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 23:03:25 -0700 Subject: [PATCH 0608/1191] Convert from array based field storage to hash based, store extension fields in same bucket Extension fields are now stored in the same bucket but we select them out if you really want them. `get_field` returns only non-extension fields based on tag or name. You can pass true as a second argument to get any field regardless of extension or not (similar to passing true to respond_to? to check for private methods). `get_extension_field` returns only extension fields based on tag or name. --- lib/protobuf/field/extension_fields.rb | 32 ------- lib/protobuf/message/dsl/fields.rb | 107 +++++++++++------------ spec/lib/protobuf/message_spec.rb | 112 ++++++++++++------------- 3 files changed, 106 insertions(+), 145 deletions(-) delete mode 100644 lib/protobuf/field/extension_fields.rb diff --git a/lib/protobuf/field/extension_fields.rb b/lib/protobuf/field/extension_fields.rb deleted file mode 100644 index 6d27bf8e..00000000 --- a/lib/protobuf/field/extension_fields.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Protobuf - module Field - class ExtensionFields < Array - ## - # Constructor - # - def initialize - @ranges = [] - end - - ## - # Public Instance Methods - # - - # Append a range to the list of ranges. - def add_range(range = (0..-1)) - @ranges << range - end - - # Set value at tag location, if tag is in a valid range. - def []=(key, value) - raise RangeError, "#{key} is not in #{@ranges.join(', ')}" unless include_tag?(key) - super - end - - # Check if the given tag exists in any of the defined ranges. - def include_tag?(tag) - @ranges.any? { |range| range.include?(tag) } - end - end - end -end diff --git a/lib/protobuf/message/dsl/fields.rb b/lib/protobuf/message/dsl/fields.rb index 214954ba..a149eb60 100644 --- a/lib/protobuf/message/dsl/fields.rb +++ b/lib/protobuf/message/dsl/fields.rb @@ -1,3 +1,5 @@ +require 'set' + module Protobuf class Message module DSL @@ -28,7 +30,7 @@ def required(type, name, tag, options = {}) # Define an extension range. # def extensions(range) - extension_fields.add_range(range) + extension_ranges << range end ## @@ -36,86 +38,85 @@ def extensions(range) # def all_fields - @all_fields ||= begin - all_fields_array = [] - max_fields = fields.size > extension_fields.size ? fields.size : extension_fields.size - max_fields.times do |field_number| - all_fields_array << (fields[field_number] || extension_fields[field_number]) - end - all_fields_array.compact! - all_fields_array - end + @all_fields ||= ::Set.new(field_store.values).to_a end def extension_fields - @extension_fields ||= ::Protobuf::Field::ExtensionFields.new + @extension_fields ||= all_fields.select(&:extension?) end - def extension_field_name_to_tag - @extension_fields_by_name ||= {} + def extension_ranges + @extension_ranges ||= [] end def extension_tag?(tag) - extension_fields.include_tag?(tag) + tag.respond_to?(:to_i) && get_extension_field(tag).present? end - def fields - @fields ||= [] + def field_store + @field_store ||= {} end - def field_name_to_tag - @field_name_to_tag ||= {} + def fields + @fields ||= all_fields.reject(&:extension?) end - def get_ext_field_by_name(name) - tag = extension_field_name_to_tag[name.to_sym] - extension_fields[tag] unless tag.nil? + def field_tag?(tag, allow_extension = false) + tag.respond_to?(:to_i) && get_field(tag, allow_extension).present? end - def get_ext_field_by_tag(tag) - extension_fields[tag] + def get_extension_field(name_or_tag) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] + field if field.try(:extension?) { false } end - def get_field_by_name(name) - name = name.to_sym if name.respond_to?(:to_sym) - tag = field_name_to_tag[name] - fields[tag] unless tag.nil? - end + def get_field(name_or_tag, allow_extension = false) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] - def get_field_by_tag(tag) - fields[tag] - rescue TypeError - tag = tag.try(:to_s) || 'nil' - raise FieldNotDefinedError.new("Tag '#{tag}' does not reference a message field for '#{self.name}'") + if field && (allow_extension || ! field.extension?) + field + else + nil + end end - private + def define_field(rule, type, field_name, tag, options) + raise_if_tag_collision(tag, field_name) + raise_if_name_collision(field_name) - # Define a field. Don't use this method directly. - def define_field(rule, type, fname, tag, options) - field_array = options[:extension] ? extension_fields : fields - field_name_hash = options[:extension] ? extension_field_name_to_tag : field_name_to_tag + field = ::Protobuf::Field.build(self, rule, type, field_name, tag, options) + field_store[field_name] = field + field_store[tag] = field + + class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) + define_method("#{field_name}!") do + @values[:#{field_name}] + end + RAW_GETTER + end - previous_tag_field = get_field_by_tag(tag) || get_ext_field_by_tag(tag) - if previous_tag_field - raise TagCollisionError, %!Field number #{tag} has already been used in "#{name}" by field "#{fname}".! + def raise_if_tag_collision(tag, field_name) + if get_field(tag, true) + raise TagCollisionError, %!Field number #{tag} has already been used in "#{name}" by field "#{field_name}".! end + end - previous_name_field = get_field_by_name(fname) || get_ext_field_by_name(fname) - if previous_name_field - raise DuplicateFieldNameError, %!Field name #{fname} has already been used in "#{name}".! + def raise_if_name_collision(field_name) + if get_field(field_name, true) + raise DuplicateFieldNameError, %!Field name #{field_name} has already been used in "#{name}".! end + end - field_definition = ::Protobuf::Field.build(self, rule, type, fname, tag, options) - field_name_hash[fname] = tag - field_array[tag] = field_definition + ## + # Instance aliases + # - class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) - define_method("#{fname}!") do - @values[:#{fname}] - end - RAW_GETTER - end + alias_method :get_ext_field_by_name, :get_extension_field + alias_method :get_ext_field_by_tag, :get_extension_field + alias_method :get_field_by_name, :get_field + alias_method :get_field_by_tag, :get_field end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index d4c198e1..bfe208b8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -10,13 +10,13 @@ end end - describe '.define_field' do + describe 'defining a new field' do context 'when defining a field with a tag that has already been used' do it 'raises a TagCollisionError' do expect { Class.new(Protobuf::Message) do - define_field :optional, ::Protobuf::Field::Int32Field, :foo, 1, {} - define_field :optional, ::Protobuf::Field::Int32Field, :bar, 1, {} + optional ::Protobuf::Field::Int32Field, :foo, 1 + optional ::Protobuf::Field::Int32Field, :bar, 1 end }.to raise_error(Protobuf::TagCollisionError, /Field number 1 has already been used/) end @@ -27,8 +27,8 @@ expect { Class.new(Protobuf::Message) do extensions 100...110 - define_field :optional, ::Protobuf::Field::Int32Field, :foo, 100, {} - define_field :optional, ::Protobuf::Field::Int32Field, :bar, 100, :extension => true + optional ::Protobuf::Field::Int32Field, :foo, 100 + optional ::Protobuf::Field::Int32Field, :bar, 100, :extension => true end }.to raise_error(Protobuf::TagCollisionError, /Field number 100 has already been used/) end @@ -38,8 +38,8 @@ it 'raises a DuplicateFieldNameError' do expect { Class.new(Protobuf::Message) do - define_field :optional, ::Protobuf::Field::Int32Field, :foo, 1, {} - define_field :optional, ::Protobuf::Field::Int32Field, :foo, 2, {} + optional ::Protobuf::Field::Int32Field, :foo, 1 + optional ::Protobuf::Field::Int32Field, :foo, 2 end }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) end @@ -50,8 +50,8 @@ expect { Class.new(Protobuf::Message) do extensions 100...110 - define_field :optional, ::Protobuf::Field::Int32Field, :foo, 1, {} - define_field :optional, ::Protobuf::Field::Int32Field, :foo, 100, :extension => true + optional ::Protobuf::Field::Int32Field, :foo, 1 + optional ::Protobuf::Field::Int32Field, :foo, 100, :extension => true end }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) end @@ -289,34 +289,9 @@ its(:to_json) { should eq '{"name":"Test Name","active":false}' } end - describe '#get_field_by_name' do - subject do - ::Test::Resource.new({ :name => 'Test Name', :date_created => Time.now.to_i }) - end - - context 'when name is a valid field' do - let(:valid_field) { subject.get_field_by_name(:name) } - specify { valid_field.should be_a ::Protobuf::Field::StringField } - specify { valid_field.name.should eq :name } - end - - context 'when name is not a valid field' do - specify do - subject.get_field_by_name(1).should be_nil - end - - specify do - subject.get_field_by_name(:nothere).should be_nil - end - - specify do - subject.get_field_by_name(nil).should be_nil - end - end - end - describe "#define_setter" do subject { ::Test::Resource.new } + it "allows string fields to be set to nil" do expect { subject.name = nil }.to_not raise_error end @@ -326,40 +301,57 @@ end end - describe '#get_ext_field_by_name' do - pending 'Need to get a proto compiled with extensions first' + describe '.get_extension_field' do + it 'fetches an extension field by its tag' do + field = ::Test::Resource.get_extension_field(100) + expect(field).to be_a(::Protobuf::Field::BoolField) + expect(field.tag).to eq(100) + expect(field.name).to eq(:ext_is_searchable) + expect(field).to be_extension + end + + it 'fetches an extension field by its symbolized name' do + expect(::Test::Resource.get_extension_field(:ext_is_searchable)).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_extension_field('ext_is_searchable')).to be_a(::Protobuf::Field::BoolField) + end + + it 'returns nil when attempting to get a non-extension field' do + expect(::Test::Resource.get_extension_field(1)).to be_nil + end + + it 'returns nil when field is not found' do + ::Test::Resource.get_extension_field(-1).should be_nil + ::Test::Resource.get_extension_field(nil).should be_nil + end end - describe '#get_field_by_tag' do - subject do - ::Test::Resource.new({ :name => 'Test Name', :date_created => Time.now.to_i }) + describe '.get_field' do + it 'fetches a non-extension field by its tag' do + field = ::Test::Resource.get_field(1) + expect(field).to be_a(::Protobuf::Field::StringField) + expect(field.tag).to eq(1) + expect(field.name).to eq(:name) + expect(field).not_to be_extension end - context 'when tag references a valid field' do - let(:valid_field) { subject.get_field_by_tag(1) } - specify { valid_field.should be_a ::Protobuf::Field::StringField } - specify { valid_field.name.should eq :name } + it 'fetches a non-extension field by its symbolized name' do + expect(::Test::Resource.get_field(:name)).to be_a(::Protobuf::Field::StringField) + expect(::Test::Resource.get_field('name')).to be_a(::Protobuf::Field::StringField) end - context 'when tag does not reference a field' do - it 'returns nil' do - pending 'need to implement a range-limiting array sub-class for field access' - subject.get_field_by_tag(-1).should be_nil - end + it 'fetches an extension field when forced' do + expect(::Test::Resource.get_field(100, true)).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_field(:ext_is_searchable, true)).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_field('ext_is_searchable', true)).to be_a(::Protobuf::Field::BoolField) end - context 'when tag is not numeric' do - specify do - expect { - subject.get_field_by_tag("not a number") - }.to raise_error(::Protobuf::FieldNotDefinedError, /.*not a number.*#{subject.class.name}/) - end + it 'returns nil when attempting to get an extension field' do + expect(::Test::Resource.get_field(100)).to be_nil + end - specify do - expect { - subject.get_field_by_tag(nil) - }.to raise_error(::Protobuf::FieldNotDefinedError, /.*nil.*#{subject.class.name}/) - end + it 'returns nil when field is not defined' do + ::Test::Resource.get_field(-1).should be_nil + ::Test::Resource.get_field(nil).should be_nil end end From db9a3839b97fee4af16c4bb41a40117d9d941492 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 23:04:32 -0700 Subject: [PATCH 0609/1191] Remove instance level field getters, self.class ain't that far away --- lib/protobuf/field.rb | 1 - lib/protobuf/message.rb | 43 ++++++-------------------------- lib/protobuf/message/encoding.rb | 2 +- spec/support/packed_field.rb | 9 +++---- 4 files changed, 12 insertions(+), 43 deletions(-) diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index f54b137d..9e2ff727 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -19,7 +19,6 @@ require 'protobuf/field/sfixed64_field' require 'protobuf/field/fixed32_field' require 'protobuf/field/fixed64_field' -require 'protobuf/field/extension_fields' module Protobuf module Field diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 2939df2e..56f49ffc 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -27,10 +27,6 @@ def initialize(values = {}) # Public Instance Methods # - def all_fields - self.class.all_fields - end - def clear! @values.delete_if do |_, value| if value.is_a?(::Protobuf::Field::FieldArray) @@ -56,14 +52,14 @@ def dup # # do something # end def each_field - all_fields.each do |field| + self.class.all_fields.each do |field| value = __send__(field.name) yield(field, value) end end def each_field_for_serialization - all_fields.each do |field| + self.class.all_fields.each do |field| next unless field_must_be_serialized?(field) value = @values[field.name] @@ -76,31 +72,6 @@ def each_field_for_serialization end end - # Returns extension fields. See Message#fields method. - def extension_fields - self.class.extension_fields - end - - def fields - self.class.fields - end - - def get_ext_field_by_name(name) - self.class.get_ext_field_by_name(name) - end - - def get_ext_field_by_tag(tag) - self.class.get_ext_field_by_tag(tag) - end - - def get_field_by_name(name) - self.class.get_field_by_name(name) - end - - def get_field_by_tag(tag) - self.class.get_field_by_tag(tag) - end - def has_field?(name) @values.has_key?(name) end @@ -110,12 +81,12 @@ def inspect end def respond_to_has?(key) - self.respond_to?(key) && self.has_field?(key) + respond_to?(key) && has_field?(key) end def respond_to_has_and_present?(key) - self.respond_to_has?(key) && - (self.__send__(key).present? || [true, false].include?(self.__send__(key))) + respond_to_has?(key) && + (__send__(key).present? || [true, false].include?(__send__(key))) end # Return a hash-representation of the given fields for this message type. @@ -148,13 +119,13 @@ def ==(obj) end def [](name) - if field = get_field_by_name(name) || get_ext_field_by_name(name) + if field = self.class.get_field(name, true) __send__(field.name) end end def []=(name, value) - if field = get_field_by_name(name) || get_ext_field_by_name(name) + if field = self.class.get_field(name, true) __send__(field.setter_method_name, value) end end diff --git a/lib/protobuf/message/encoding.rb b/lib/protobuf/message/encoding.rb index d030fc2a..f4144d8b 100644 --- a/lib/protobuf/message/encoding.rb +++ b/lib/protobuf/message/encoding.rb @@ -72,7 +72,7 @@ def field_must_be_serialized?(field) end def set_field_bytes(tag, bytes) - field = (get_field_by_tag(tag) || get_ext_field_by_tag(tag)) + field = self.class.get_field(tag, true) field.set(self, bytes) if field end diff --git a/spec/support/packed_field.rb b/spec/support/packed_field.rb index 3fef7350..84e46847 100644 --- a/spec/support/packed_field.rb +++ b/spec/support/packed_field.rb @@ -1,21 +1,20 @@ if defined?(RSpec) - shared_examples_for :packable_field do |klass| + shared_examples_for :packable_field do |field_klass| before(:all) do unless defined?(PackableFieldTest) class PackableFieldTest < ::Protobuf::Message; end end - field_klass = klass - field_name = "#{klass.name.split('::').last.underscore}_packed_field".to_sym + field_name = "#{field_klass.name.split('::').last.underscore}_packed_field".to_sym tag_num = PackableFieldTest.fields.size + 1 PackableFieldTest.repeated(field_klass, field_name, tag_num, :packed => true) end - let(:field_name) { "#{klass.name.split('::').last.underscore}_packed_field" } + let(:field_name) { "#{field_klass.name.split('::').last.underscore}_packed_field".to_sym } let(:message_instance) { PackableFieldTest.new(field_name => [100, 200, 300]) } - subject { message_instance.fields.last } + subject { PackableFieldTest.get_field(field_name) } it { should be_packed } From 822ae0d75a2efe87392afa410b54265adefc2a8e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 23:16:11 -0700 Subject: [PATCH 0610/1191] Rename module DSL::Fields to just Fields --- lib/protobuf/message.rb | 18 ++--- lib/protobuf/message/dsl/fields.rb | 125 ----------------------------- lib/protobuf/message/fields.rb | 123 ++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 134 deletions(-) delete mode 100644 lib/protobuf/message/dsl/fields.rb create mode 100644 lib/protobuf/message/fields.rb diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 56f49ffc..a4813b40 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,8 +1,8 @@ require 'protobuf/field' require 'protobuf/enum' require 'protobuf/exceptions' -require 'protobuf/message/dsl/fields' require 'protobuf/message/encoding' +require 'protobuf/message/fields' module Protobuf class Message @@ -11,16 +11,18 @@ class Message # Includes & Extends # - extend ::Protobuf::Message::DSL::Fields include ::Protobuf::Message::Encoding + extend ::Protobuf::Message::Fields ## # Constructor # - def initialize(values = {}) + def initialize(fields = {}) @values = {} - values = values.to_hash - values.each { |name, val| self[name] = val unless val.nil? } + + fields.to_hash.each_pair do |name, value| + self[name] = value unless value.nil? + end end ## @@ -47,10 +49,8 @@ def dup copy_to(super, :dup) end - # Iterate over a field collection. - # message.each_field do |field_object, value| - # # do something - # end + # Iterate over every field, invoking the given block + # def each_field self.class.all_fields.each do |field| value = __send__(field.name) diff --git a/lib/protobuf/message/dsl/fields.rb b/lib/protobuf/message/dsl/fields.rb deleted file mode 100644 index a149eb60..00000000 --- a/lib/protobuf/message/dsl/fields.rb +++ /dev/null @@ -1,125 +0,0 @@ -require 'set' - -module Protobuf - class Message - module DSL - module Fields - - ## - # Field Definition Methods - # - - # Define an optional field. - # - def optional(type, name, tag, options = {}) - define_field(:optional, type, name, tag, options) - end - - # Define a repeated field. - # - def repeated(type, name, tag, options = {}) - define_field(:repeated, type, name, tag, options) - end - - # Define a required field. - # - def required(type, name, tag, options = {}) - define_field(:required, type, name, tag, options) - end - - # Define an extension range. - # - def extensions(range) - extension_ranges << range - end - - ## - # Field Access Methods - # - - def all_fields - @all_fields ||= ::Set.new(field_store.values).to_a - end - - def extension_fields - @extension_fields ||= all_fields.select(&:extension?) - end - - def extension_ranges - @extension_ranges ||= [] - end - - def extension_tag?(tag) - tag.respond_to?(:to_i) && get_extension_field(tag).present? - end - - def field_store - @field_store ||= {} - end - - def fields - @fields ||= all_fields.reject(&:extension?) - end - - def field_tag?(tag, allow_extension = false) - tag.respond_to?(:to_i) && get_field(tag, allow_extension).present? - end - - def get_extension_field(name_or_tag) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] - field if field.try(:extension?) { false } - end - - def get_field(name_or_tag, allow_extension = false) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] - - if field && (allow_extension || ! field.extension?) - field - else - nil - end - end - - def define_field(rule, type, field_name, tag, options) - raise_if_tag_collision(tag, field_name) - raise_if_name_collision(field_name) - - field = ::Protobuf::Field.build(self, rule, type, field_name, tag, options) - field_store[field_name] = field - field_store[tag] = field - - class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) - define_method("#{field_name}!") do - @values[:#{field_name}] - end - RAW_GETTER - end - - def raise_if_tag_collision(tag, field_name) - if get_field(tag, true) - raise TagCollisionError, %!Field number #{tag} has already been used in "#{name}" by field "#{field_name}".! - end - end - - def raise_if_name_collision(field_name) - if get_field(field_name, true) - raise DuplicateFieldNameError, %!Field name #{field_name} has already been used in "#{name}".! - end - end - - ## - # Instance aliases - # - - alias_method :get_ext_field_by_name, :get_extension_field - alias_method :get_ext_field_by_tag, :get_extension_field - alias_method :get_field_by_name, :get_field - alias_method :get_field_by_tag, :get_field - - end - end - end -end - diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb new file mode 100644 index 00000000..6009da3d --- /dev/null +++ b/lib/protobuf/message/fields.rb @@ -0,0 +1,123 @@ +require 'set' + +module Protobuf + class Message + module Fields + + ## + # Field Definition Methods + # + + # Define an optional field. + # + def optional(type, name, tag, options = {}) + define_field(:optional, type, name, tag, options) + end + + # Define a repeated field. + # + def repeated(type, name, tag, options = {}) + define_field(:repeated, type, name, tag, options) + end + + # Define a required field. + # + def required(type, name, tag, options = {}) + define_field(:required, type, name, tag, options) + end + + # Define an extension range. + # + def extensions(range) + extension_ranges << range + end + + ## + # Field Access Methods + # + + def all_fields + @all_fields ||= ::Set.new(field_store.values).to_a + end + + def extension_fields + @extension_fields ||= all_fields.select(&:extension?) + end + + def extension_ranges + @extension_ranges ||= [] + end + + def extension_tag?(tag) + tag.respond_to?(:to_i) && get_extension_field(tag).present? + end + + def field_store + @field_store ||= {} + end + + def fields + @fields ||= all_fields.reject(&:extension?) + end + + def field_tag?(tag, allow_extension = false) + tag.respond_to?(:to_i) && get_field(tag, allow_extension).present? + end + + def get_extension_field(name_or_tag) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] + field if field.try(:extension?) { false } + end + + def get_field(name_or_tag, allow_extension = false) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] + + if field && (allow_extension || ! field.extension?) + field + else + nil + end + end + + def define_field(rule, type, field_name, tag, options) + raise_if_tag_collision(tag, field_name) + raise_if_name_collision(field_name) + + field = ::Protobuf::Field.build(self, rule, type, field_name, tag, options) + field_store[field_name] = field + field_store[tag] = field + + class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) + define_method("#{field_name}!") do + @values[:#{field_name}] + end + RAW_GETTER + end + + def raise_if_tag_collision(tag, field_name) + if get_field(tag, true) + raise TagCollisionError, %!Field number #{tag} has already been used in "#{name}" by field "#{field_name}".! + end + end + + def raise_if_name_collision(field_name) + if get_field(field_name, true) + raise DuplicateFieldNameError, %!Field name #{field_name} has already been used in "#{name}".! + end + end + + ## + # Instance aliases + # + + alias_method :get_ext_field_by_name, :get_extension_field + alias_method :get_ext_field_by_tag, :get_extension_field + alias_method :get_field_by_name, :get_field + alias_method :get_field_by_tag, :get_field + + end + end +end + From ede51f4d3458566d3e10c6aaad3b355c596e0a0c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Feb 2014 23:16:29 -0700 Subject: [PATCH 0611/1191] Rename Encoding module to Serialization --- lib/protobuf/message.rb | 4 ++-- lib/protobuf/message/{encoding.rb => serialization.rb} | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) rename lib/protobuf/message/{encoding.rb => serialization.rb} (96%) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a4813b40..7febfcb7 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,8 +1,8 @@ require 'protobuf/field' require 'protobuf/enum' require 'protobuf/exceptions' -require 'protobuf/message/encoding' require 'protobuf/message/fields' +require 'protobuf/message/serialization' module Protobuf class Message @@ -11,8 +11,8 @@ class Message # Includes & Extends # - include ::Protobuf::Message::Encoding extend ::Protobuf::Message::Fields + include ::Protobuf::Message::Serialization ## # Constructor diff --git a/lib/protobuf/message/encoding.rb b/lib/protobuf/message/serialization.rb similarity index 96% rename from lib/protobuf/message/encoding.rb rename to lib/protobuf/message/serialization.rb index f4144d8b..2e399c50 100644 --- a/lib/protobuf/message/encoding.rb +++ b/lib/protobuf/message/serialization.rb @@ -4,7 +4,7 @@ module Protobuf class Message - module Encoding + module Serialization module ClassMethods def decode(bytes) @@ -64,6 +64,7 @@ def encode_to(stream) alias_method :bytes, :encode alias_method :serialize, :encode alias_method :serialize_to_string, :encode + alias_method :serialize_to, :encode_to private From 70f21574d6785dad7db0072c30fd1035254ecd6b Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Feb 2014 23:23:09 -0700 Subject: [PATCH 0612/1191] Fix failing logger middleware specs --- .../protobuf/rpc/middleware/logger_spec.rb | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index c6a3e323..5f583db5 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -2,7 +2,37 @@ describe Protobuf::Rpc::Middleware::Logger do let(:app) { Proc.new { |env| env } } - let(:env) { Protobuf::Rpc::Env.new } + let(:env) { + Protobuf::Rpc::Env.new( + 'caller' => 'caller.test.co', + 'encoded_request' => request_wrapper.encode, + 'encoded_response' => response_wrapper.encode, + 'method_name' => method_name, + 'request' => request, + 'request_type' => rpc_method.request_type, + 'response' => response, + 'response_type' => rpc_method.response_type, + 'rpc_method' => rpc_method, + 'rpc_service' => service_class, + 'service_name' => service_name, + ) + } + let(:method_name) { :find } + let(:request) { request_type.new(:name => 'required') } + let(:request_type) { rpc_method.request_type } + let(:request_wrapper) { + Protobuf::Socketrpc::Request.new( + :service_name => service_name, + :method_name => method_name.to_s, + :request_proto => request + ) + } + let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } + let(:response) { rpc_method.response_type.new(:name => 'required') } + let(:rpc_method) { service_class.rpcs[method_name] } + let(:rpc_service) { service_class.new(env) } + let(:service_class) { Test::ResourceService } + let(:service_name) { service_class.to_s } subject { described_class.new(app) } From dcbb16fd4287647925808350ec60648bb20b88e4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 09:45:13 -0700 Subject: [PATCH 0613/1191] Use uniq for all_fields, set isn't any faster --- lib/protobuf/message/fields.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 6009da3d..627d5c69 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -1,5 +1,3 @@ -require 'set' - module Protobuf class Message module Fields @@ -37,7 +35,7 @@ def extensions(range) # def all_fields - @all_fields ||= ::Set.new(field_store.values).to_a + @all_fields ||= field_store.values.uniq end def extension_fields @@ -90,9 +88,9 @@ def define_field(rule, type, field_name, tag, options) field_store[tag] = field class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) - define_method("#{field_name}!") do - @values[:#{field_name}] - end + define_method("#{field_name}!") do + @values[:#{field_name}] + end RAW_GETTER end From 28406f11d28c8fe2f61efdaf72f94d40b0882a2c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 10:32:06 -0700 Subject: [PATCH 0614/1191] Pull EnumValue into Enum class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Basically removed every instance of the word “value” except in the Numeric extension and the deprecated instance method. --- lib/protobuf/enum.rb | 145 ++++++++++--- lib/protobuf/enum_value.rb | 85 -------- spec/lib/protobuf/enum_spec.rb | 305 ++++++++++++++------------- spec/lib/protobuf/enum_value_spec.rb | 29 --- 4 files changed, 280 insertions(+), 284 deletions(-) delete mode 100644 lib/protobuf/enum_value.rb delete mode 100644 spec/lib/protobuf/enum_value_spec.rb diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 7d57ab67..0a21516a 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,9 +1,26 @@ -require 'protobuf/enum_value' +require 'delegate' require 'protobuf/optionable' require 'protobuf/deprecator' +## +# Adding extension to Numeric until +# we can get people to stop calling #value +# on Enum instances. +# +class Numeric + unless method_defined?(:value) + def value + $stderr.puts <<-DEPRECATION +[DEPRECATED] Enum#value is deprecated and will be removed in the next release. + Use Enum#to_i instead. +DEPRECATION + self + end + end +end + module Protobuf - class Enum + class Enum < SimpleDelegator ## # Deprecations @@ -18,7 +35,7 @@ def self.aliases_allowed? self.get_option(:allow_alias) end - # Public: Get all integer tag values defined by this enum. + # Public: Get all integer tags defined by this enum. # # Examples # @@ -37,8 +54,8 @@ def self.all_tags @all_tags ||= self.enums.map(&:to_i).uniq end - # Internal: DSL method to define a protobuf EnumValue. The given name will - # become a constant for this Enum which points to an EnumValue object. + # Internal: DSL method to create a new Enum. The given name will + # become a constant for this Enum pointing to the new instance. # # Examples # @@ -52,20 +69,20 @@ def self.all_tags # # Returns nothing. # - def self.define(name, value) - enum = ::Protobuf::EnumValue.new(self, name, value) + def self.define(name, tag) + enum = self.new(self, name, tag) @enums ||= [] @enums << enum const_set(name, enum) end - # Public: The internal values hash. + # Public: All defined enums. # def self.enums @enums end - # Public: Get an array of EnumValue objects with the given tag. + # Public: Get an array of Enum objects with the given tag. # # tag - An object that responds to to_i. # @@ -81,7 +98,7 @@ def self.enums # StateMachine.enums_for_tag(1) #=> [ #, # ] # StateMachine.enums_for_tag(2) #=> [ # ] # - # Returns an array with zero or more EnumValue objects or nil. + # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) self.enums.select { |enum| @@ -89,7 +106,7 @@ def self.enums_for_tag(tag) } end - # Public: Get the EnumValue associated with the given name. + # Public: Get the Enum associated with the given name. # # name - A string-like object. Case-sensitive. # @@ -105,8 +122,7 @@ def self.enums_for_tag(tag) # StateMachine.enum_for_name(:on) # => nil # StateMachine.enum_for_name(:FOO) # => nil # - # Returns the EnumValue object with the given name. `nil` will be returned - # if the given name does not have a correlating value. + # Returns the Enum object with the given name or nil. # def self.enum_for_name(name) self.const_get(name) @@ -114,20 +130,20 @@ def self.enum_for_name(name) nil end - # Public: Get the EnumValue object corresponding to the given tag. + # Public: Get the Enum object corresponding to the given tag. # # tag - An object that responds to to_i. # - # Returns an EnumValue object or nil. If the tag corresponds to multiple - # EnumValue objects an array of EnumValue objects will be returned. + # Returns an Enum object or nil. If the tag corresponds to multiple + # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) self.enums_for_tag(tag).first end - # Public: Get an EnumValue by a variety of type-checking mechanisms. + # Public: Get an Enum by a variety of type-checking mechanisms. # - # value - An EnumValue, Numeric, String, or Symbol object. + # candidate - An Enum, Numeric, String, or Symbol object. # # Example # @@ -143,15 +159,15 @@ def self.enum_for_tag(tag) # StateMachine.fetch("http://github.com/STARTED") # => # # StateMachine.fetch(1) # => [ #, # ] # - # Returns an EnumValue object or nil. + # Returns an Enum object or nil. # def self.fetch(candidate) case candidate - when ::Protobuf::EnumValue then + when self then candidate - when Numeric then + when ::Numeric then enum_for_tag(candidate.to_i) - when String, Symbol then + when ::String, ::Symbol then enum_for_name(candidate) else nil @@ -185,16 +201,15 @@ def self.fetch(candidate) # StateMachine.name_for_tag(1) # => :STARTED # StateMachine.name_for_tag(2) # => :OFF # - # Returns the symbol name of the enum constant given it's associated value. - # If the given value has multiple names associated (due to allow_alias) - # the first defined name will be returned. `nil` will be returned when - # the given value does not have a correlating name. + # Returns the symbol name of the enum constant given it's associated tag or nil. + # If the given tag has multiple names associated (due to allow_alias) + # the first defined name will be returned. # def self.name_for_tag(tag) self.enum_for_tag(tag).try(:name) end - # Public: Check if the given tag value is defined by this Enum. + # Public: Check if the given tag is defined by this Enum. # # number - An object that responds to to_i. # @@ -204,7 +219,7 @@ def self.valid_tag?(tag) tag.respond_to?(:to_i) && self.all_tags.include?(tag.to_i) end - # Public: [DEPRECATED] Return a hash of EnumValue objects keyed + # Public: [DEPRECATED] Return a hash of Enum objects keyed # by their :name. # def self.values @@ -219,7 +234,7 @@ def self.values end ## - # Deprecations + # Class Deprecations # deprecate_method :enum_by_value, :enum_for_tag @@ -227,6 +242,78 @@ def self.values deprecate_method :get_name_by_tag, :name_for_tag deprecate_method :value_by_name, :enum_for_name + + ## + # Attributes + # + + attr_reader :parent_class, :name, :tag + + ## + # Instance Methods + # + + def initialize(parent_class, name, tag) + @parent_class = parent_class + @name = name + @tag = tag + super(@tag) + end + + # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum + # + def class + Fixnum + end + + def inspect + "\#" + end + + def to_i + tag + end + + def to_int + tag.to_int + end + + def to_s(format = :tag) + case format + when :tag then + self.to_i.to_s + when :name then + name.to_s + else + self.to_i.to_s + end + end + + # Re-implement `try` in order to fix the problem where + # the underlying fixnum doesn't respond to all methods (e.g. name or tag). + # If we respond to the first argument, `__send__` the args. Otherwise, + # delegate the `try` call to the underlying vlaue fixnum. + # + def try(*args, &block) + case + when args.empty? && block_given? + yield self + when respond_to?(args.first) + __send__(*args, &block) + else + @tag.try(*args, &block) + end + end + + def value + parent_class.warn_deprecated(:value, :to_i) + to_i + end + + ## + # Instance Aliases + # + alias_method :to_hash_value, :to_i end end diff --git a/lib/protobuf/enum_value.rb b/lib/protobuf/enum_value.rb deleted file mode 100644 index 8196034d..00000000 --- a/lib/protobuf/enum_value.rb +++ /dev/null @@ -1,85 +0,0 @@ -require 'delegate' -require 'protobuf/enum' - -## -# Adding extension to Numeric until -# we can get people to stop calling #value -# on EnumValue -class Numeric - unless method_defined?(:value) - def value - self - end - end -end - -module Protobuf - class EnumValue < SimpleDelegator - - attr_reader :parent_class, :name - - ## - # Constructor - # - def initialize(parent_class, name, value) - @parent_class = parent_class - @name = name - @value = value - super(@value) - end - - # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum - def class - Fixnum - end - - def inspect - "\#" - end - - def to_i - @value - end - - def to_int - @value.to_int - end - - def to_s(format = :value_string) - case format - when :value_string then - self.to_i.to_s - when :name then - name.to_s - else - self.to_i.to_s - end - end - - # Re-implement `try` in order to fix the problem where - # the underlying fixnum doesn't respond to all methods (e.g. name or value). - # If we respond to the first argument, `__send__` the args. Otherwise, - # delegate the `try` call to the underlying vlaue fixnum. - # - def try(*args, &block) - case - when args.empty? && block_given? - yield self - when respond_to?(args.first) - __send__(*args, &block) - else - @value.try(*args, &block) - end - end - - def value - @value - end - - ## - # Instance Aliases - # - alias_method :to_hash_value, :to_i - end -end - diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index b71ea9ad..fc03322f 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -1,188 +1,189 @@ require 'spec_helper' describe Protobuf::Enum do - let(:name) { :THREE } - let(:tag) { 3 } - before(:all) do - Test::EnumTestType.define(:MINUS_ONE, -1) - Test::EnumTestType.define(:THREE, 3) - end + describe 'class dsl' do + let(:name) { :THREE } + let(:tag) { 3 } - before(:all) do - EnumAliasTest = ::Class.new(::Protobuf::Enum) do - set_option :allow_alias - define :FOO, 1 - define :BAR, 1 - define :BAZ, 2 + before(:all) do + Test::EnumTestType.define(:MINUS_ONE, -1) + Test::EnumTestType.define(:THREE, 3) end - end - describe '.aliases_allowed?' do - it 'is false when the option is not set' do - expect(Test::EnumTestType.aliases_allowed?).to be_false + before(:all) do + EnumAliasTest = ::Class.new(::Protobuf::Enum) do + set_option :allow_alias + define :FOO, 1 + define :BAR, 1 + define :BAZ, 2 + end end - end - describe '.define' do - it 'defines a constant enum value on the parent class' do - expect(Test::EnumTestType.constants).to include(name) - expect(Test::EnumTestType::THREE).to be_a(Protobuf::EnumValue) + describe '.aliases_allowed?' do + it 'is false when the option is not set' do + expect(Test::EnumTestType.aliases_allowed?).to be_false + end end - context 'when enum allows aliases' do - before(:all) do - DefineEnumAlias = ::Class.new(::Protobuf::Enum) do - set_option :allow_alias - end + describe '.define' do + it 'defines a constant enum on the parent class' do + expect(Test::EnumTestType.constants).to include(name) + expect(Test::EnumTestType::THREE).to be_a(Protobuf::Enum) end - it 'allows defining enum values with the same tag number' do - expect { - DefineEnumAlias.define(:FOO, 1) - DefineEnumAlias.define(:BAR, 1) - }.not_to raise_error - end - end - end + context 'when enum allows aliases' do + before(:all) do + DefineEnumAlias = ::Class.new(::Protobuf::Enum) do + set_option :allow_alias + end + end - describe '.enums' do - it 'provides an array of defined EnumValue objects' do - expect(Test::EnumTestType.enums).to eq([ - Test::EnumTestType::ONE, - Test::EnumTestType::TWO, - Test::EnumTestType::MINUS_ONE, - Test::EnumTestType::THREE - ]) + it 'allows defining enums with the same tag number' do + expect { + DefineEnumAlias.define(:FOO, 1) + DefineEnumAlias.define(:BAR, 1) + }.not_to raise_error + end + end end - context 'when enum allows aliases' do - it 'treats aliased values as valid' do - expect(EnumAliasTest.enums).to eq([ - EnumAliasTest::FOO, - EnumAliasTest::BAR, - EnumAliasTest::BAZ + describe '.enums' do + it 'provides an array of defined Enums' do + expect(Test::EnumTestType.enums).to eq([ + Test::EnumTestType::ONE, + Test::EnumTestType::TWO, + Test::EnumTestType::MINUS_ONE, + Test::EnumTestType::THREE ]) end - end - end - - describe '.enums_for_tag' do - it 'returns an array of EnumValues for the given tag, if any' do - expect(EnumAliasTest.enums_for_tag(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) - expect(EnumAliasTest.enums_for_tag(2)).to eq([ EnumAliasTest::BAZ ]) - expect(EnumAliasTest.enums_for_tag(3)).to eq([]) + context 'when enum allows aliases' do + it 'treats aliased enums as valid' do + expect(EnumAliasTest.enums).to eq([ + EnumAliasTest::FOO, + EnumAliasTest::BAR, + EnumAliasTest::BAZ + ]) + end + end end - end - describe '.fetch' do - context 'when value is an EnumValue' do - it 'responds with that object' do - expect(Test::EnumTestType.fetch(Test::EnumTestType::THREE)).to eq(Test::EnumTestType::THREE) + + describe '.enums_for_tag' do + it 'returns an array of Enums for the given tag, if any' do + expect(EnumAliasTest.enums_for_tag(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) + expect(EnumAliasTest.enums_for_tag(2)).to eq([ EnumAliasTest::BAZ ]) + expect(EnumAliasTest.enums_for_tag(3)).to eq([]) end end - context 'when value can be coerced to a symbol' do - it 'fetches based on the symbol name value' do - expect(Test::EnumTestType.fetch("http://github.com/ONE")).to eq(Test::EnumTestType::ONE) - expect(Test::EnumTestType.fetch(:ONE)).to eq(Test::EnumTestType::ONE) + describe '.fetch' do + context 'when candidate is an Enum' do + it 'responds with the Enum' do + expect(Test::EnumTestType.fetch(Test::EnumTestType::THREE)).to eq(Test::EnumTestType::THREE) + end end - end - context 'when value can be coerced to an integer' do - it 'fetches based on the integer tag value' do - expect(Test::EnumTestType.fetch(3.0)).to eq(Test::EnumTestType::THREE) - expect(Test::EnumTestType.fetch(3)).to eq(Test::EnumTestType::THREE) + context 'when candidate can be coerced to a symbol' do + it 'fetches based on the symbol name' do + expect(Test::EnumTestType.fetch("http://github.com/ONE")).to eq(Test::EnumTestType::ONE) + expect(Test::EnumTestType.fetch(:ONE)).to eq(Test::EnumTestType::ONE) + end end - context 'when enum allows aliases' do - it 'fetches the first defined EnumValue' do - expect(EnumAliasTest.fetch(1)).to eq(EnumAliasTest::FOO) + context 'when candidate can be coerced to an integer' do + it 'fetches based on the integer tag' do + expect(Test::EnumTestType.fetch(3.0)).to eq(Test::EnumTestType::THREE) + expect(Test::EnumTestType.fetch(3)).to eq(Test::EnumTestType::THREE) + end + + context 'when enum allows aliases' do + it 'fetches the first defined Enum' do + expect(EnumAliasTest.fetch(1)).to eq(EnumAliasTest::FOO) + end end end - end - context 'when value is not an applicable type' do - it 'returns a nil' do - expect(Test::EnumTestType.fetch(Test::Resource.new)).to be_nil - expect(Test::EnumTestType.fetch(nil)).to be_nil - expect(Test::EnumTestType.fetch(false)).to be_nil + context 'when candidate is not an applicable type' do + it 'returns a nil' do + expect(Test::EnumTestType.fetch(EnumAliasTest::FOO)).to be_nil + expect(Test::EnumTestType.fetch(Test::Resource.new)).to be_nil + expect(Test::EnumTestType.fetch(nil)).to be_nil + expect(Test::EnumTestType.fetch(false)).to be_nil + expect(Test::EnumTestType.fetch(-10)).to be_nil + end end end - end - describe '.enum_for_tag' do - it 'gets the EnumValue corresponding to the given value (tag)' do - expect(Test::EnumTestType.enum_for_tag(tag)).to eq(Test::EnumTestType.const_get(name)) - expect(Test::EnumTestType.enum_for_tag(-5)).to be_nil + describe '.enum_for_tag' do + it 'gets the Enum corresponding to the given tag' do + expect(Test::EnumTestType.enum_for_tag(tag)).to eq(Test::EnumTestType.const_get(name)) + expect(Test::EnumTestType.enum_for_tag(-5)).to be_nil + end end - end - describe '.name_for_tag' do - it 'get the name by value of the enum given the enum' do - expect(Test::EnumTestType.name_for_tag(::Test::EnumTestType::THREE)).to eq(name) - end + describe '.name_for_tag' do + it 'get the name of the enum given the enum' do + expect(Test::EnumTestType.name_for_tag(::Test::EnumTestType::THREE)).to eq(name) + end - it 'gets the name of the enum corresponding to the given value (tag)' do - expect(Test::EnumTestType.name_for_tag(tag)).to eq(name) - end + it 'gets the name of the enum corresponding to the given tag' do + expect(Test::EnumTestType.name_for_tag(tag)).to eq(name) + end - it 'gets the name when the tag is coercable to an int' do - expect(Test::EnumTestType.name_for_tag("3")).to eq(name) - end + it 'gets the name when the tag is coercable to an int' do + expect(Test::EnumTestType.name_for_tag("3")).to eq(name) + end - it 'returns nil when tag does not correspond to a name' do - expect(Test::EnumTestType.name_for_tag(12345)).to be_nil - end + it 'returns nil when tag does not correspond to a name' do + expect(Test::EnumTestType.name_for_tag(12345)).to be_nil + end - context 'when given name is nil' do - it 'returns a nil' do - expect(Test::EnumTestType.name_for_tag(nil)).to be_nil + context 'when given name is nil' do + it 'returns a nil' do + expect(Test::EnumTestType.name_for_tag(nil)).to be_nil + end end - end - context 'when enum allows aliases' do - it 'returns the first defined name for that value' do - expect(EnumAliasTest.name_for_tag(1)).to eq(:FOO) + context 'when enum allows aliases' do + it 'returns the first defined name for the given tag' do + expect(EnumAliasTest.name_for_tag(1)).to eq(:FOO) + end end end - end - describe '.valid_tag?' do - context 'when tag is defined' do - specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_true } - end + describe '.valid_tag?' do + context 'when tag is defined' do + specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_true } + end - context 'when tag is not defined' do - specify { expect(Test::EnumTestType.valid_tag?(300)).to be_false } - end + context 'when tag is not defined' do + specify { expect(Test::EnumTestType.valid_tag?(300)).to be_false } + end - context 'when enum allows aliases' do - it 'treats aliased values as valid' do - expect(EnumAliasTest.valid_tag?(1)).to be_true + context 'is true for aliased enums' do + specify { expect(EnumAliasTest.valid_tag?(1)).to be_true } end end - end - describe '.enum_for_name' do - it 'gets the EnumValue corresponding to the given name' do - expect(Test::EnumTestType.enum_for_name(name)).to eq(Test::EnumTestType::THREE) + describe '.enum_for_name' do + it 'gets the Enum corresponding to the given name' do + expect(Test::EnumTestType.enum_for_name(name)).to eq(Test::EnumTestType::THREE) + end end - end - describe '.values' do - it 'provides a hash of defined EnumValue objects' do - expect(Test::EnumTestType.values).to eq({ - :MINUS_ONE => Test::EnumTestType::MINUS_ONE, - :ONE => Test::EnumTestType::ONE, - :TWO => Test::EnumTestType::TWO, - :THREE => Test::EnumTestType::THREE - }) - end + describe '.values' do + it 'provides a hash of defined Enums' do + expect(Test::EnumTestType.values).to eq({ + :MINUS_ONE => Test::EnumTestType::MINUS_ONE, + :ONE => Test::EnumTestType::ONE, + :TWO => Test::EnumTestType::TWO, + :THREE => Test::EnumTestType::THREE + }) + end - context 'when enum allows aliases' do - it 'treats aliased values as valid' do + it 'contains aliased Enums' do expect(EnumAliasTest.values).to eq({ :FOO => EnumAliasTest::FOO, :BAR => EnumAliasTest::BAR, @@ -190,20 +191,43 @@ }) end end - end - describe '.all_tags' do - it 'provides an array of the integer values' do - expect(Test::EnumTestType.all_tags).to include(1, 2, -1, 3) - end - - context 'when enum allows aliases' do - it 'returns a unique array of all defined enum values' do + describe '.all_tags' do + it 'provides a unique array of defined tags' do + expect(Test::EnumTestType.all_tags).to include(1, 2, -1, 3) expect(EnumAliasTest.all_tags).to include(1, 2) end end end + subject { Test::EnumTestType::ONE } + its(:class) { should eq(Fixnum) } + its(:parent_class) { should eq(Test::EnumTestType) } + its(:name) { should eq(:ONE) } + its(:tag) { should eq(1) } + its(:value) { should eq(1) } + its(:to_hash_value) { should eq(1) } + its(:to_s) { should eq("1") } + its(:inspect) { should eq('#') } + specify { subject.to_s(:tag).should eq("1") } + specify { subject.to_s(:name).should eq("ONE") } + + it "can be used as the index to an array" do + array = [0, 1, 2, 3] + array[::Test::EnumTestType::ONE].should eq(1) + end + + describe '#try' do + specify { subject.try(:parent_class).should eq(subject.parent_class) } + specify { subject.try(:class).should eq(subject.class) } + specify { subject.try(:name).should eq(subject.name) } + specify { subject.try(:tag).should eq(subject.tag) } + specify { subject.try(:value).should eq(subject.value) } + specify { subject.try(:to_i).should eq(subject.to_i) } + specify { subject.try(:to_int).should eq(subject.to_int) } + specify { subject.try { |yielded| yielded.should eq(subject) } } + end + context 'when coercing from enum' do subject { Test::StatusType::PENDING } it { should eq(0) } @@ -212,5 +236,4 @@ context 'when coercing from integer' do specify { expect(0).to eq(Test::StatusType::PENDING) } end - end diff --git a/spec/lib/protobuf/enum_value_spec.rb b/spec/lib/protobuf/enum_value_spec.rb deleted file mode 100644 index 63d590cb..00000000 --- a/spec/lib/protobuf/enum_value_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'spec_helper' - -describe Protobuf::EnumValue do - - subject { Test::EnumTestType::ONE } - its(:class) { should eq(Fixnum) } - its(:parent_class) { should eq(Test::EnumTestType) } - its(:name) { should eq(:ONE) } - its(:value) { should eq(1) } - its(:to_hash_value) { should eq(1) } - its(:to_s) { should eq("1") } - its(:inspect) { should eq('#') } - specify { subject.to_s(:name).should eq("ONE") } - - it "can be used as the index to an array" do - array = [0, 1, 2, 3] - array[::Test::EnumTestType::ONE].should eq(1) - end - - describe '#try' do - specify { subject.try(:class).should eq subject.class } - specify { subject.try(:name).should eq subject.name } - specify { subject.try(:value).should eq subject.value } - specify { subject.try(:to_i).should eq subject.to_i } - specify { subject.try(:to_int).should eq subject.to_int } - specify { subject.try { |yielded| yielded.should eq subject } } - end - -end From a1f89649a867cfbc7d40242d842ddb6496a0d20e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 10:58:43 -0700 Subject: [PATCH 0615/1191] Add support for explicit class deprecations --- lib/protobuf/deprecator.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index 9a5c15d2..9fbcbdc2 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -9,7 +9,7 @@ def warn_deprecated(old_method, new_method) # Given deprecations should be a hash whose keys are the new methods # and values are a list of deprecated methods that should send to t def deprecate_method(old_method, new_method) - instance_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) + class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) def #{old_method}(*args) warn_deprecated("#{old_method}", "#{new_method}") new_meth = method("#{new_method}") @@ -22,5 +22,21 @@ def #{old_method}(*args) DEPRECATED end + # Given deprecations should be a hash whose keys are the new methods + # and values are a list of deprecated methods that should send to t + def deprecate_class_method(old_method, new_method) + class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) + def self.#{old_method}(*args) + warn_deprecated("#{old_method}", "#{new_method}") + new_meth = method("#{new_method}") + if new_meth.arity == 0 + __send__("#{new_method}") + else + __send__("#{new_method}", *args) + end + end + DEPRECATED + end + end end From 46361a57d432a1f92e4cd898d3977833197357be Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 10:58:59 -0700 Subject: [PATCH 0616/1191] Explicitly deprecate class methods on Enum --- lib/protobuf/enum.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 7d57ab67..a206d084 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -222,10 +222,10 @@ def self.values # Deprecations # - deprecate_method :enum_by_value, :enum_for_tag - deprecate_method :name_by_value, :name_for_tag - deprecate_method :get_name_by_tag, :name_for_tag - deprecate_method :value_by_name, :enum_for_name + deprecate_class_method :enum_by_value, :enum_for_tag + deprecate_class_method :name_by_value, :name_for_tag + deprecate_class_method :get_name_by_tag, :name_for_tag + deprecate_class_method :value_by_name, :enum_for_name end end From 72430e186edf083f0330d66e91a4e5f2a30c5fa3 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 10:59:17 -0700 Subject: [PATCH 0617/1191] Mark aliased class methods as deprecated --- lib/protobuf/message/fields.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 627d5c69..15aa05d2 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -1,7 +1,17 @@ +require 'protobuf/deprecator' + module Protobuf class Message module Fields + def self.extended(other) + other.extend(::Protobuf::Deprecator) + other.deprecate_class_method(:get_ext_field_by_name, :get_extension_field) + other.deprecate_class_method(:get_ext_field_by_tag, :get_extension_field) + other.deprecate_class_method(:get_field_by_name, :get_field) + other.deprecate_class_method(:get_field_by_tag, :get_field) + end + ## # Field Definition Methods # @@ -106,15 +116,6 @@ def raise_if_name_collision(field_name) end end - ## - # Instance aliases - # - - alias_method :get_ext_field_by_name, :get_extension_field - alias_method :get_ext_field_by_tag, :get_extension_field - alias_method :get_field_by_name, :get_field - alias_method :get_field_by_tag, :get_field - end end end From a1967b3a9d1e5b339e4385140d0406cdda25f4a6 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 17:06:21 -0700 Subject: [PATCH 0618/1191] Fix encoding and method visibility issues --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/message/decoder.rb | 42 +++++++++++++-------------- lib/protobuf/message/serialization.rb | 3 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 41eed43a..440fa154 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -76,7 +76,7 @@ def set(message_instance, bytes) stream = StringIO.new(bytes) until stream.eof? - array << decode(::Protobuf::Decoder.__send__(method, stream)) + array << decode(::Protobuf::Message::Decoder.__send__(method, stream)) end else value = decode(bytes) diff --git a/lib/protobuf/message/decoder.rb b/lib/protobuf/message/decoder.rb index b3c64d7b..05fc282a 100644 --- a/lib/protobuf/message/decoder.rb +++ b/lib/protobuf/message/decoder.rb @@ -13,6 +13,27 @@ def self.decode_each_field(stream, &block) end end + # Read 32-bit string value from +stream+. + def self.read_fixed32(stream) + stream.read(4) + end + + # Read 64-bit string value from +stream+. + def self.read_fixed64(stream) + stream.read(8) + end + + # Read varint integer value from +stream+. + def self.read_varint(stream) + value = index = 0 + begin + byte = stream.readbyte + value |= (byte & 0x7f) << (7 * index) + index += 1 + end while (byte & 0x80).nonzero? + value + end + private def self.read_field(stream) @@ -46,27 +67,6 @@ def self.read_key(stream) [tag, wire_type] end - # Read varint integer value from +stream+. - def self.read_varint(stream) - value = index = 0 - begin - byte = stream.readbyte - value |= (byte & 0x7f) << (7 * index) - index += 1 - end while (byte & 0x80).nonzero? - value - end - - # Read 32-bit string value from +stream+. - def self.read_fixed32(stream) - stream.read(4) - end - - # Read 64-bit string value from +stream+. - def self.read_fixed64(stream) - stream.read(8) - end - # Read length-delimited string value from +stream+. def self.read_length_delimited(stream) value_length = read_varint(stream) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 2e399c50..76fa5ff9 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -44,7 +44,8 @@ def decode_from(stream) # Encode this message # def encode - encode_to(::StringIO.new).string + stream = ::StringIO.new.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream).string end # Encode this message to the given stream. From df8b91db49c884740ca6c4096caf3459127895f4 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 14:42:35 -0700 Subject: [PATCH 0619/1191] Use a primitive field mapping from symbol to field class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows us to generate “prettier” message code that use symbols for all the primitive types in the definition. ```ruby # old class Foo optional ::Protobuf::Field::StringField, :bar, 1 end # new class Bar optional :string, :foo, 1 end ``` --- lib/protobuf/field.rb | 55 ++++++----- spec/lib/protobuf/field_spec.rb | 162 ++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+), 24 deletions(-) create mode 100644 spec/lib/protobuf/field_spec.rb diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index f54b137d..7eaf2556 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -23,34 +23,41 @@ module Protobuf module Field - PREDEFINED_TYPES = [ - ::Protobuf::Field::DoubleField, - ::Protobuf::Field::FloatField, - ::Protobuf::Field::Int32Field, - ::Protobuf::Field::Int64Field, - ::Protobuf::Field::Uint32Field, - ::Protobuf::Field::Uint64Field, - ::Protobuf::Field::Sint32Field, - ::Protobuf::Field::Sint64Field, - ::Protobuf::Field::Fixed32Field, - ::Protobuf::Field::Fixed64Field, - ::Protobuf::Field::Sfixed32Field, - ::Protobuf::Field::Sfixed64Field, - ::Protobuf::Field::StringField, - ::Protobuf::Field::BytesField, - ::Protobuf::Field::BoolField - ].freeze + + PRIMITIVE_FIELD_MAP = { + :double => ::Protobuf::Field::DoubleField, + :float => ::Protobuf::Field::FloatField, + :int32 => ::Protobuf::Field::Int32Field, + :int64 => ::Protobuf::Field::Int64Field, + :uint32 => ::Protobuf::Field::Uint32Field, + :uint64 => ::Protobuf::Field::Uint64Field, + :sint32 => ::Protobuf::Field::Sint32Field, + :sint64 => ::Protobuf::Field::Sint64Field, + :fixed32 => ::Protobuf::Field::Fixed32Field, + :fixed64 => ::Protobuf::Field::Fixed64Field, + :sfixed32 => ::Protobuf::Field::Sfixed32Field, + :sfixed64 => ::Protobuf::Field::Sfixed64Field, + :string => ::Protobuf::Field::StringField, + :bytes => ::Protobuf::Field::BytesField, + :bool => ::Protobuf::Field::BoolField + }.freeze def self.build(message_class, rule, type, name, tag, options = {}) - field_class = type_message_or_enum(type) - field_class.new(message_class, rule, type, name, tag, options) + field_type(type).new(message_class, rule, type, name, tag, options) end - def self.type_message_or_enum(defined_type) - return defined_type if ::Protobuf::Field::PREDEFINED_TYPES.include?(defined_type) - return EnumField if defined_type < Enum - return MessageField if defined_type < Message - raise "lost in the wilderness #{defined_type}" + def self.field_type(type) + if PRIMITIVE_FIELD_MAP.key?(type) + PRIMITIVE_FIELD_MAP[type] + elsif type < ::Protobuf::Enum + EnumField + elsif type < ::Protobuf::Message + MessageField + elsif type < ::Protobuf::Field::BaseField + type + else + raise ArgumentError, "Invalid field type #{type}" + end end end diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb new file mode 100644 index 00000000..c498f834 --- /dev/null +++ b/spec/lib/protobuf/field_spec.rb @@ -0,0 +1,162 @@ +require 'spec_helper' +require 'protobuf/field' + +describe ::Protobuf::Field do + + describe '.build' do + pending + end + + describe '.field_type' do + context 'when type is an enum class' do + it 'returns an enum field' do + expect(subject.field_type(::Test::EnumTestType)).to eq(::Protobuf::Field::EnumField) + end + end + + context 'when type is a message class' do + it 'returns a message field' do + expect(subject.field_type(::Test::Resource)).to eq(::Protobuf::Field::MessageField) + end + end + + context 'when type is a base field class' do + it 'returns that class' do + expect(subject.field_type(::Protobuf::Field::BoolField)).to eq(::Protobuf::Field::BoolField) + end + end + + context 'when type is a double field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::DoubleField + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:double)).to eq(expected_field) + end + end + + context 'when type is a float field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::FloatField + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:float)).to eq(expected_field) + end + end + + context 'when type is a int32 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Int32Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:int32)).to eq(expected_field) + end + end + + context 'when type is a int64 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Int64Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:int64)).to eq(expected_field) + end + end + + context 'when type is a uint32 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Uint32Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:uint32)).to eq(expected_field) + end + end + + context 'when type is a uint64 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Uint64Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:uint64)).to eq(expected_field) + end + end + + context 'when type is a sint32 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Sint32Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:sint32)).to eq(expected_field) + end + end + + context 'when type is a sint64 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Sint64Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:sint64)).to eq(expected_field) + end + end + + context 'when type is a fixed32 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Fixed32Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:fixed32)).to eq(expected_field) + end + end + + context 'when type is a fixed64 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Fixed64Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:fixed64)).to eq(expected_field) + end + end + + context 'when type is a sfixed32 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Sfixed32Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:sfixed32)).to eq(expected_field) + end + end + + context 'when type is a sfixed64 field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::Sfixed64Field + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:sfixed64)).to eq(expected_field) + end + end + + + context 'when type is a string field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::StringField + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:string)).to eq(expected_field) + end + end + + + context 'when type is a bytes field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::BytesField + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:bytes)).to eq(expected_field) + end + end + + + context 'when type is a bool field class or symbol' do + it 'returns that class' do + expected_field = ::Protobuf::Field::BoolField + expect(subject.field_type(expected_field)).to eq(expected_field) + expect(subject.field_type(:bool)).to eq(expected_field) + end + end + + context 'when type is not mapped' do + it 'raises an ArgumentError' do + expect { + subject.field_type("boom") + }.to raise_error + end + end + + end + +end From 2b99aa6f2bd7e5060be7d1769aee948845bf17a0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 14:42:56 -0700 Subject: [PATCH 0620/1191] Change the generator to output the symbol type name for primitive field definitions --- lib/protobuf/generators/field_generator.rb | 2 +- spec/lib/protobuf/generators/field_generator_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 4c3a1d7c..5ff0295b 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -94,7 +94,7 @@ def type_name type_name = modulize(descriptor.type_name) else type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '') - type_name = "::Protobuf::Field::#{modulize(type_name)}Field" + type_name = ":#{type_name}" end end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 8f536143..5f97b412 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -27,7 +27,7 @@ describe '#compile' do subject { described_class.new(field).to_s } - it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3\n" } + it { should eq "optional :string, :foo_bar, 3\n" } context 'when the type is another message' do let(:type_enum) { :TYPE_MESSAGE } @@ -39,7 +39,7 @@ context 'when a default value is used' do let(:type_enum) { :TYPE_INT32 } let(:default_value) { '42' } - it { should eq "optional ::Protobuf::Field::Int32Field, :foo_bar, 3, :default => 42\n" } + it { should eq "optional :int32, :foo_bar, 3, :default => 42\n" } context 'when type is an enum' do let(:type_enum) { :TYPE_ENUM } @@ -53,7 +53,7 @@ let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - it { should eq %Q{optional ::Protobuf::Field::StringField, :foo_bar, 3, :default => "a default \"string\""\n} } + it { should eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } end context 'when float or double field type' do @@ -79,19 +79,19 @@ context 'when the field is an extension' do let(:extendee) { 'foo.bar.Baz' } - it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :extension => true\n" } + it { should eq "optional :string, :foo_bar, 3, :extension => true\n" } end context 'when field is packed' do let(:field_options) { { :packed => true } } - it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :packed => true\n" } + it { should eq "optional :string, :foo_bar, 3, :packed => true\n" } end context 'when field is deprecated' do let(:field_options) { { :deprecated => true } } - it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :deprecated => true\n" } + it { should eq "optional :string, :foo_bar, 3, :deprecated => true\n" } end end From b7ebfbb0ab9f7627536af0b69afca0a27754e546 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 17:07:28 -0700 Subject: [PATCH 0621/1191] Recompile all protos in the gem with the latest generator changes --- Rakefile | 48 +- .../google/protobuf/compiler/plugin.pb.rb | 33 +- .../google/protobuf/descriptor.pb.rb | 171 +++---- lib/protobuf/rpc/dynamic_discovery.pb.rb | 30 +- lib/protobuf/rpc/rpc.pb.rb | 31 +- spec/support/test/defaults.pb.rb | 8 +- spec/support/test/enum.pb.rb | 2 +- spec/support/test/extended.pb.rb | 2 +- spec/support/test/google_unittest.pb.rb | 478 +++++++++--------- .../support/test/google_unittest_import.pb.rb | 4 +- .../support/test/multi_field_extensions.pb.rb | 4 +- spec/support/test/resource.pb.rb | 36 +- 12 files changed, 437 insertions(+), 410 deletions(-) diff --git a/Rakefile b/Rakefile index 286f803c..5b7a51b3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,27 +1,55 @@ $: << ::File.expand_path('../', __FILE__) $: << ::File.expand_path('../spec', __FILE__) -require "rubygems" -require "rubygems/package_task" -require "bundler/gem_tasks" -require "benchmark/tasks" +require 'fileutils' +require 'rubygems' +require 'rubygems/package_task' +require 'bundler/gem_tasks' +require 'benchmark/tasks' -require "rspec/core/rake_task" +require 'rspec/core/rake_task' -desc "Default: run specs." +desc 'Default: run specs.' task :default => :spec RSpec::Core::RakeTask.new(:spec) -desc "Run specs" -namespace :spec do - desc "Compile Test Protos in spec/supprt/" - task :compile_test_protos do |task, args| +desc 'Run specs' +namespace :compile do + + desc 'Compile spec protos in spec/supprt/' + task :spec do |task, args| proto_path = ::File.expand_path('../spec/support/', __FILE__) cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} puts cmd exec cmd end + + desc "Compile spec protos in spec/supprt/" + task :rpc do |task, args| + proto_path = ::File.expand_path('../proto', __FILE__) + output_dir = ::File.expand_path('../tmp/rpc', __FILE__) + ::FileUtils.mkdir_p(output_dir) + + cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + + puts cmd + puts %x(#{cmd}) + + files = { + 'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc', + 'tmp/rpc/rpc.pb.rb' => 'lib/protobuf/rpc', + 'tmp/rpc/google/protobuf/descriptor.pb.rb' => 'lib/protobuf/descriptors/google/protobuf', + 'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler' + } + + files.each_pair do |source_file, destination_dir| + source_file = ::File.expand_path("../#{source_file}", __FILE__) + destination_dir = ::File.expand_path("../#{destination_dir}", __FILE__) + ::FileUtils::Verbose.cp(source_file, destination_dir) + end + end + end task :console do diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb index 886b9f88..5dd8eddf 100644 --- a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -3,49 +3,50 @@ # require 'protobuf/message' + ## # Imports # require 'google/protobuf/descriptor.pb' module Google - module Protobuf - module Compiler - + ## # Message Classes # class CodeGeneratorRequest < ::Protobuf::Message; end class CodeGeneratorResponse < ::Protobuf::Message class File < ::Protobuf::Message; end + end - + + + ## # Message Fields # class CodeGeneratorRequest - repeated ::Protobuf::Field::StringField, :file_to_generate, 1 - optional ::Protobuf::Field::StringField, :parameter, 2 + repeated :string, :file_to_generate, 1 + optional :string, :parameter, 2 repeated ::Google::Protobuf::FileDescriptorProto, :proto_file, 15 end - + class CodeGeneratorResponse class File - optional ::Protobuf::Field::StringField, :name, 1 - optional ::Protobuf::Field::StringField, :insertion_point, 2 - optional ::Protobuf::Field::StringField, :content, 15 + optional :string, :name, 1 + optional :string, :insertion_point, 2 + optional :string, :content, 15 end - - optional ::Protobuf::Field::StringField, :error, 1 + + optional :string, :error, 1 repeated ::Google::Protobuf::Compiler::CodeGeneratorResponse::File, :file, 15 end - - + end - + end - + end diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index 2da3c7a5..c4835c12 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -4,9 +4,8 @@ require 'protobuf/message' module Google - module Protobuf - + ## # Message Classes # @@ -14,7 +13,9 @@ class FileDescriptorSet < ::Protobuf::Message; end class FileDescriptorProto < ::Protobuf::Message; end class DescriptorProto < ::Protobuf::Message class ExtensionRange < ::Protobuf::Message; end + end + class FieldDescriptorProto < ::Protobuf::Message class Type < ::Protobuf::Enum define :TYPE_DOUBLE, 1 @@ -36,14 +37,15 @@ class Type < ::Protobuf::Enum define :TYPE_SINT32, 17 define :TYPE_SINT64, 18 end - + class Label < ::Protobuf::Enum define :LABEL_OPTIONAL, 1 define :LABEL_REQUIRED, 2 define :LABEL_REPEATED, 3 end - + end + class EnumDescriptorProto < ::Protobuf::Message; end class EnumValueDescriptorProto < ::Protobuf::Message; end class ServiceDescriptorProto < ::Protobuf::Message; end @@ -54,8 +56,9 @@ class OptimizeMode < ::Protobuf::Enum define :CODE_SIZE, 2 define :LITE_RUNTIME, 3 end - + end + class MessageOptions < ::Protobuf::Message; end class FieldOptions < ::Protobuf::Message class CType < ::Protobuf::Enum @@ -63,32 +66,38 @@ class CType < ::Protobuf::Enum define :CORD, 1 define :STRING_PIECE, 2 end - + end + class EnumOptions < ::Protobuf::Message; end class EnumValueOptions < ::Protobuf::Message; end class ServiceOptions < ::Protobuf::Message; end class MethodOptions < ::Protobuf::Message; end class UninterpretedOption < ::Protobuf::Message class NamePart < ::Protobuf::Message; end + end + class SourceCodeInfo < ::Protobuf::Message class Location < ::Protobuf::Message; end + end - + + + ## # Message Fields # class FileDescriptorSet repeated ::Google::Protobuf::FileDescriptorProto, :file, 1 end - + class FileDescriptorProto - optional ::Protobuf::Field::StringField, :name, 1 - optional ::Protobuf::Field::StringField, :package, 2 - repeated ::Protobuf::Field::StringField, :dependency, 3 - repeated ::Protobuf::Field::Int32Field, :public_dependency, 10 - repeated ::Protobuf::Field::Int32Field, :weak_dependency, 11 + optional :string, :name, 1 + optional :string, :package, 2 + repeated :string, :dependency, 3 + repeated :int32, :public_dependency, 10 + repeated :int32, :weak_dependency, 11 repeated ::Google::Protobuf::DescriptorProto, :message_type, 4 repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 5 repeated ::Google::Protobuf::ServiceDescriptorProto, :service, 6 @@ -96,14 +105,14 @@ class FileDescriptorProto optional ::Google::Protobuf::FileOptions, :options, 8 optional ::Google::Protobuf::SourceCodeInfo, :source_code_info, 9 end - + class DescriptorProto class ExtensionRange - optional ::Protobuf::Field::Int32Field, :start, 1 - optional ::Protobuf::Field::Int32Field, :end, 2 + optional :int32, :start, 1 + optional :int32, :end, 2 end - - optional ::Protobuf::Field::StringField, :name, 1 + + optional :string, :name, 1 repeated ::Google::Protobuf::FieldDescriptorProto, :field, 2 repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 6 repeated ::Google::Protobuf::DescriptorProto, :nested_type, 3 @@ -111,138 +120,130 @@ class ExtensionRange repeated ::Google::Protobuf::DescriptorProto::ExtensionRange, :extension_range, 5 optional ::Google::Protobuf::MessageOptions, :options, 7 end - + class FieldDescriptorProto - optional ::Protobuf::Field::StringField, :name, 1 - optional ::Protobuf::Field::Int32Field, :number, 3 + optional :string, :name, 1 + optional :int32, :number, 3 optional ::Google::Protobuf::FieldDescriptorProto::Label, :label, 4 optional ::Google::Protobuf::FieldDescriptorProto::Type, :type, 5 - optional ::Protobuf::Field::StringField, :type_name, 6 - optional ::Protobuf::Field::StringField, :extendee, 2 - optional ::Protobuf::Field::StringField, :default_value, 7 + optional :string, :type_name, 6 + optional :string, :extendee, 2 + optional :string, :default_value, 7 optional ::Google::Protobuf::FieldOptions, :options, 8 end - + class EnumDescriptorProto - optional ::Protobuf::Field::StringField, :name, 1 + optional :string, :name, 1 repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2 optional ::Google::Protobuf::EnumOptions, :options, 3 end - + class EnumValueDescriptorProto - optional ::Protobuf::Field::StringField, :name, 1 - optional ::Protobuf::Field::Int32Field, :number, 2 + optional :string, :name, 1 + optional :int32, :number, 2 optional ::Google::Protobuf::EnumValueOptions, :options, 3 end - + class ServiceDescriptorProto - optional ::Protobuf::Field::StringField, :name, 1 + optional :string, :name, 1 repeated ::Google::Protobuf::MethodDescriptorProto, :method, 2 optional ::Google::Protobuf::ServiceOptions, :options, 3 end - + class MethodDescriptorProto - optional ::Protobuf::Field::StringField, :name, 1 - optional ::Protobuf::Field::StringField, :input_type, 2 - optional ::Protobuf::Field::StringField, :output_type, 3 + optional :string, :name, 1 + optional :string, :input_type, 2 + optional :string, :output_type, 3 optional ::Google::Protobuf::MethodOptions, :options, 4 end - + class FileOptions - optional ::Protobuf::Field::StringField, :java_package, 1 - optional ::Protobuf::Field::StringField, :java_outer_classname, 8 - optional ::Protobuf::Field::BoolField, :java_multiple_files, 10, :default => false - optional ::Protobuf::Field::BoolField, :java_generate_equals_and_hash, 20, :default => false + optional :string, :java_package, 1 + optional :string, :java_outer_classname, 8 + optional :bool, :java_multiple_files, 10, :default => false + optional :bool, :java_generate_equals_and_hash, 20, :default => false optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED - optional ::Protobuf::Field::StringField, :go_package, 11 - optional ::Protobuf::Field::BoolField, :cc_generic_services, 16, :default => false - optional ::Protobuf::Field::BoolField, :java_generic_services, 17, :default => false - optional ::Protobuf::Field::BoolField, :py_generic_services, 18, :default => false + optional :string, :go_package, 11 + optional :bool, :cc_generic_services, 16, :default => false + optional :bool, :java_generic_services, 17, :default => false + optional :bool, :py_generic_services, 18, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 - # Extension Fields extensions 1000...536870912 end - + class MessageOptions - optional ::Protobuf::Field::BoolField, :message_set_wire_format, 1, :default => false - optional ::Protobuf::Field::BoolField, :no_standard_descriptor_accessor, 2, :default => false + optional :bool, :message_set_wire_format, 1, :default => false + optional :bool, :no_standard_descriptor_accessor, 2, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 - # Extension Fields extensions 1000...536870912 end - + class FieldOptions optional ::Google::Protobuf::FieldOptions::CType, :ctype, 1, :default => ::Google::Protobuf::FieldOptions::CType::STRING - optional ::Protobuf::Field::BoolField, :packed, 2 - optional ::Protobuf::Field::BoolField, :lazy, 5, :default => false - optional ::Protobuf::Field::BoolField, :deprecated, 3, :default => false - optional ::Protobuf::Field::StringField, :experimental_map_key, 9 - optional ::Protobuf::Field::BoolField, :weak, 10, :default => false + optional :bool, :packed, 2 + optional :bool, :lazy, 5, :default => false + optional :bool, :deprecated, 3, :default => false + optional :string, :experimental_map_key, 9 + optional :bool, :weak, 10, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 - # Extension Fields extensions 1000...536870912 end - + class EnumOptions - optional ::Protobuf::Field::BoolField, :allow_alias, 2, :default => true + optional :bool, :allow_alias, 2, :default => true repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 - # Extension Fields extensions 1000...536870912 end - + class EnumValueOptions repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 - # Extension Fields extensions 1000...536870912 end - + class ServiceOptions repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 - # Extension Fields extensions 1000...536870912 end - + class MethodOptions repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 - # Extension Fields extensions 1000...536870912 end - + class UninterpretedOption class NamePart - required ::Protobuf::Field::StringField, :name_part, 1 - required ::Protobuf::Field::BoolField, :is_extension, 2 + required :string, :name_part, 1 + required :bool, :is_extension, 2 end - + repeated ::Google::Protobuf::UninterpretedOption::NamePart, :name, 2 - optional ::Protobuf::Field::StringField, :identifier_value, 3 - optional ::Protobuf::Field::Uint64Field, :positive_int_value, 4 - optional ::Protobuf::Field::Int64Field, :negative_int_value, 5 - optional ::Protobuf::Field::DoubleField, :double_value, 6 - optional ::Protobuf::Field::BytesField, :string_value, 7 - optional ::Protobuf::Field::StringField, :aggregate_value, 8 - end - + optional :string, :identifier_value, 3 + optional :uint64, :positive_int_value, 4 + optional :int64, :negative_int_value, 5 + optional :double, :double_value, 6 + optional :bytes, :string_value, 7 + optional :string, :aggregate_value, 8 + end + class SourceCodeInfo class Location - repeated ::Protobuf::Field::Int32Field, :path, 1, :packed => true - repeated ::Protobuf::Field::Int32Field, :span, 2, :packed => true - optional ::Protobuf::Field::StringField, :leading_comments, 3 - optional ::Protobuf::Field::StringField, :trailing_comments, 4 + repeated :int32, :path, 1, :packed => true + repeated :int32, :span, 2, :packed => true + optional :string, :leading_comments, 3 + optional :string, :trailing_comments, 4 end - + repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1 end - - + end - + end diff --git a/lib/protobuf/rpc/dynamic_discovery.pb.rb b/lib/protobuf/rpc/dynamic_discovery.pb.rb index 51d0d79e..1ee963ca 100644 --- a/lib/protobuf/rpc/dynamic_discovery.pb.rb +++ b/lib/protobuf/rpc/dynamic_discovery.pb.rb @@ -4,11 +4,9 @@ require 'protobuf/message' module Protobuf - module Rpc - module DynamicDiscovery - + ## # Enum Classes # @@ -16,34 +14,34 @@ class BeaconType < ::Protobuf::Enum define :HEARTBEAT, 0 define :FLATLINE, 1 end - - + + ## # Message Classes # class Server < ::Protobuf::Message; end class Beacon < ::Protobuf::Message; end - + + ## # Message Fields # class Server - optional ::Protobuf::Field::StringField, :uuid, 1 - optional ::Protobuf::Field::StringField, :address, 2 - optional ::Protobuf::Field::StringField, :port, 3 - optional ::Protobuf::Field::Int32Field, :ttl, 4 - repeated ::Protobuf::Field::StringField, :services, 5 + optional :string, :uuid, 1 + optional :string, :address, 2 + optional :string, :port, 3 + optional :int32, :ttl, 4 + repeated :string, :services, 5 end - + class Beacon optional ::Protobuf::Rpc::DynamicDiscovery::BeaconType, :beacon_type, 1 optional ::Protobuf::Rpc::DynamicDiscovery::Server, :server, 2 end - - + end - + end - + end diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index fc3d69bb..1a5e7e21 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -4,9 +4,8 @@ require 'protobuf/message' module Protobuf - module Socketrpc - + ## # Enum Classes # @@ -22,33 +21,33 @@ class ErrorReason < ::Protobuf::Enum define :UNKNOWN_HOST, 8 define :IO_ERROR, 9 end - - + + ## # Message Classes # class Request < ::Protobuf::Message; end class Response < ::Protobuf::Message; end - + + ## # Message Fields # class Request - required ::Protobuf::Field::StringField, :service_name, 1 - required ::Protobuf::Field::StringField, :method_name, 2 - optional ::Protobuf::Field::BytesField, :request_proto, 3 - optional ::Protobuf::Field::StringField, :caller, 4 + required :string, :service_name, 1 + required :string, :method_name, 2 + optional :bytes, :request_proto, 3 + optional :string, :caller, 4 end - + class Response - optional ::Protobuf::Field::BytesField, :response_proto, 1 - optional ::Protobuf::Field::StringField, :error, 2 - optional ::Protobuf::Field::BoolField, :callback, 3, :default => false + optional :bytes, :response_proto, 1 + optional :string, :error, 2 + optional :bool, :callback, 3, :default => false optional ::Protobuf::Socketrpc::ErrorReason, :error_reason, 4 end - - + end - + end diff --git a/spec/support/test/defaults.pb.rb b/spec/support/test/defaults.pb.rb index 83497e9f..9849e8a5 100644 --- a/spec/support/test/defaults.pb.rb +++ b/spec/support/test/defaults.pb.rb @@ -15,10 +15,10 @@ class Defaults < ::Protobuf::Message; end # Message Fields # class Defaults - optional ::Protobuf::Field::BytesField, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" - optional ::Protobuf::Field::DoubleField, :infinity_default, 2, :default => ::Float::INFINITY - optional ::Protobuf::Field::FloatField, :neg_infinity_default, 3, :default => -::Float::INFINITY - optional ::Protobuf::Field::DoubleField, :nan_default, 4, :default => ::Float::NAN + optional :bytes, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" + optional :double, :infinity_default, 2, :default => ::Float::INFINITY + optional :float, :neg_infinity_default, 3, :default => -::Float::INFINITY + optional :double, :nan_default, 4, :default => ::Float::NAN end end diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index aa5c7b34..ae1bdb61 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -52,7 +52,7 @@ class EnumTestMessage # Extended Message Fields # class ::Test::Resource < ::Protobuf::Message - optional ::Protobuf::Field::Int32Field, :ext_other_file_defined_field, 200, :extension => true + optional :int32, :ext_other_file_defined_field, 200, :extension => true end end diff --git a/spec/support/test/extended.pb.rb b/spec/support/test/extended.pb.rb index 219ba88f..2f3a8602 100644 --- a/spec/support/test/extended.pb.rb +++ b/spec/support/test/extended.pb.rb @@ -15,7 +15,7 @@ module Test # Extended Message Fields # class ::Test::Resource < ::Protobuf::Message - optional ::Protobuf::Field::Int64Field, :deleted_at, 300, :extension => true + optional :int64, :deleted_at, 300, :extension => true end end diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index b41bcc50..eedebd32 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -110,205 +110,205 @@ class BarResponse < ::Protobuf::Message; end # class TestAllTypes class NestedMessage - optional ::Protobuf::Field::Int32Field, :bb, 1 + optional :int32, :bb, 1 end - optional ::Protobuf::Field::Int32Field, :optional_int32, 1 - optional ::Protobuf::Field::Int64Field, :optional_int64, 2 - optional ::Protobuf::Field::Uint32Field, :optional_uint32, 3 - optional ::Protobuf::Field::Uint64Field, :optional_uint64, 4 - optional ::Protobuf::Field::Sint32Field, :optional_sint32, 5 - optional ::Protobuf::Field::Sint64Field, :optional_sint64, 6 - optional ::Protobuf::Field::Fixed32Field, :optional_fixed32, 7 - optional ::Protobuf::Field::Fixed64Field, :optional_fixed64, 8 - optional ::Protobuf::Field::Sfixed32Field, :optional_sfixed32, 9 - optional ::Protobuf::Field::Sfixed64Field, :optional_sfixed64, 10 - optional ::Protobuf::Field::FloatField, :optional_float, 11 - optional ::Protobuf::Field::DoubleField, :optional_double, 12 - optional ::Protobuf::Field::BoolField, :optional_bool, 13 - optional ::Protobuf::Field::StringField, :optional_string, 14 - optional ::Protobuf::Field::BytesField, :optional_bytes, 15 + optional :int32, :optional_int32, 1 + optional :int64, :optional_int64, 2 + optional :uint32, :optional_uint32, 3 + optional :uint64, :optional_uint64, 4 + optional :sint32, :optional_sint32, 5 + optional :sint64, :optional_sint64, 6 + optional :fixed32, :optional_fixed32, 7 + optional :fixed64, :optional_fixed64, 8 + optional :sfixed32, :optional_sfixed32, 9 + optional :sfixed64, :optional_sfixed64, 10 + optional :float, :optional_float, 11 + optional :double, :optional_double, 12 + optional :bool, :optional_bool, 13 + optional :string, :optional_string, 14 + optional :bytes, :optional_bytes, 15 optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message, 18 optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message, 19 optional ::GoogleUnittestImport::ImportMessage, :optional_import_message, 20 optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21 optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum, 22 optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum, 23 - optional ::Protobuf::Field::StringField, :optional_string_piece, 24 - optional ::Protobuf::Field::StringField, :optional_cord, 25 + optional :string, :optional_string_piece, 24 + optional :string, :optional_cord, 25 optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message, 26 optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27 - repeated ::Protobuf::Field::Int32Field, :repeated_int32, 31 - repeated ::Protobuf::Field::Int64Field, :repeated_int64, 32 - repeated ::Protobuf::Field::Uint32Field, :repeated_uint32, 33 - repeated ::Protobuf::Field::Uint64Field, :repeated_uint64, 34 - repeated ::Protobuf::Field::Sint32Field, :repeated_sint32, 35 - repeated ::Protobuf::Field::Sint64Field, :repeated_sint64, 36 - repeated ::Protobuf::Field::Fixed32Field, :repeated_fixed32, 37 - repeated ::Protobuf::Field::Fixed64Field, :repeated_fixed64, 38 - repeated ::Protobuf::Field::Sfixed32Field, :repeated_sfixed32, 39 - repeated ::Protobuf::Field::Sfixed64Field, :repeated_sfixed64, 40 - repeated ::Protobuf::Field::FloatField, :repeated_float, 41 - repeated ::Protobuf::Field::DoubleField, :repeated_double, 42 - repeated ::Protobuf::Field::BoolField, :repeated_bool, 43 - repeated ::Protobuf::Field::StringField, :repeated_string, 44 - repeated ::Protobuf::Field::BytesField, :repeated_bytes, 45 + repeated :int32, :repeated_int32, 31 + repeated :int64, :repeated_int64, 32 + repeated :uint32, :repeated_uint32, 33 + repeated :uint64, :repeated_uint64, 34 + repeated :sint32, :repeated_sint32, 35 + repeated :sint64, :repeated_sint64, 36 + repeated :fixed32, :repeated_fixed32, 37 + repeated :fixed64, :repeated_fixed64, 38 + repeated :sfixed32, :repeated_sfixed32, 39 + repeated :sfixed64, :repeated_sfixed64, 40 + repeated :float, :repeated_float, 41 + repeated :double, :repeated_double, 42 + repeated :bool, :repeated_bool, 43 + repeated :string, :repeated_string, 44 + repeated :bytes, :repeated_bytes, 45 repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message, 48 repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message, 49 repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message, 50 repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51 repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum, 52 repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum, 53 - repeated ::Protobuf::Field::StringField, :repeated_string_piece, 54 - repeated ::Protobuf::Field::StringField, :repeated_cord, 55 + repeated :string, :repeated_string_piece, 54 + repeated :string, :repeated_cord, 55 repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57 - optional ::Protobuf::Field::Int32Field, :default_int32, 61, :default => 41 - optional ::Protobuf::Field::Int64Field, :default_int64, 62, :default => 42 - optional ::Protobuf::Field::Uint32Field, :default_uint32, 63, :default => 43 - optional ::Protobuf::Field::Uint64Field, :default_uint64, 64, :default => 44 - optional ::Protobuf::Field::Sint32Field, :default_sint32, 65, :default => -45 - optional ::Protobuf::Field::Sint64Field, :default_sint64, 66, :default => 46 - optional ::Protobuf::Field::Fixed32Field, :default_fixed32, 67, :default => 47 - optional ::Protobuf::Field::Fixed64Field, :default_fixed64, 68, :default => 48 - optional ::Protobuf::Field::Sfixed32Field, :default_sfixed32, 69, :default => 49 - optional ::Protobuf::Field::Sfixed64Field, :default_sfixed64, 70, :default => -50 - optional ::Protobuf::Field::FloatField, :default_float, 71, :default => 51.5 - optional ::Protobuf::Field::DoubleField, :default_double, 72, :default => 52000 - optional ::Protobuf::Field::BoolField, :default_bool, 73, :default => true - optional ::Protobuf::Field::StringField, :default_string, 74, :default => "hello" - optional ::Protobuf::Field::BytesField, :default_bytes, 75, :default => "world" + optional :int32, :default_int32, 61, :default => 41 + optional :int64, :default_int64, 62, :default => 42 + optional :uint32, :default_uint32, 63, :default => 43 + optional :uint64, :default_uint64, 64, :default => 44 + optional :sint32, :default_sint32, 65, :default => -45 + optional :sint64, :default_sint64, 66, :default => 46 + optional :fixed32, :default_fixed32, 67, :default => 47 + optional :fixed64, :default_fixed64, 68, :default => 48 + optional :sfixed32, :default_sfixed32, 69, :default => 49 + optional :sfixed64, :default_sfixed64, 70, :default => -50 + optional :float, :default_float, 71, :default => 51.5 + optional :double, :default_double, 72, :default => 52000 + optional :bool, :default_bool, 73, :default => true + optional :string, :default_string, 74, :default => "hello" + optional :bytes, :default_bytes, 75, :default => "world" optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR optional ::GoogleUnittestImport::ImportEnum, :default_import_enum, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR - optional ::Protobuf::Field::StringField, :default_string_piece, 84, :default => "abc" - optional ::Protobuf::Field::StringField, :default_cord, 85, :default => "123" + optional :string, :default_string_piece, 84, :default => "abc" + optional :string, :default_cord, 85, :default => "123" end class TestDeprecatedFields - optional ::Protobuf::Field::Int32Field, :deprecated_int32, 1, :deprecated => true + optional :int32, :deprecated_int32, 1, :deprecated => true end class ForeignMessage - optional ::Protobuf::Field::Int32Field, :c, 1 + optional :int32, :c, 1 end class TestAllExtensions # Extension Fields extensions 1...536870912 - optional ::Protobuf::Field::Int32Field, :optional_int32_extension, 1, :extension => true - optional ::Protobuf::Field::Int64Field, :optional_int64_extension, 2, :extension => true - optional ::Protobuf::Field::Uint32Field, :optional_uint32_extension, 3, :extension => true - optional ::Protobuf::Field::Uint64Field, :optional_uint64_extension, 4, :extension => true - optional ::Protobuf::Field::Sint32Field, :optional_sint32_extension, 5, :extension => true - optional ::Protobuf::Field::Sint64Field, :optional_sint64_extension, 6, :extension => true - optional ::Protobuf::Field::Fixed32Field, :optional_fixed32_extension, 7, :extension => true - optional ::Protobuf::Field::Fixed64Field, :optional_fixed64_extension, 8, :extension => true - optional ::Protobuf::Field::Sfixed32Field, :optional_sfixed32_extension, 9, :extension => true - optional ::Protobuf::Field::Sfixed64Field, :optional_sfixed64_extension, 10, :extension => true - optional ::Protobuf::Field::FloatField, :optional_float_extension, 11, :extension => true - optional ::Protobuf::Field::DoubleField, :optional_double_extension, 12, :extension => true - optional ::Protobuf::Field::BoolField, :optional_bool_extension, 13, :extension => true - optional ::Protobuf::Field::StringField, :optional_string_extension, 14, :extension => true - optional ::Protobuf::Field::BytesField, :optional_bytes_extension, 15, :extension => true + optional :int32, :optional_int32_extension, 1, :extension => true + optional :int64, :optional_int64_extension, 2, :extension => true + optional :uint32, :optional_uint32_extension, 3, :extension => true + optional :uint64, :optional_uint64_extension, 4, :extension => true + optional :sint32, :optional_sint32_extension, 5, :extension => true + optional :sint64, :optional_sint64_extension, 6, :extension => true + optional :fixed32, :optional_fixed32_extension, 7, :extension => true + optional :fixed64, :optional_fixed64_extension, 8, :extension => true + optional :sfixed32, :optional_sfixed32_extension, 9, :extension => true + optional :sfixed64, :optional_sfixed64_extension, 10, :extension => true + optional :float, :optional_float_extension, 11, :extension => true + optional :double, :optional_double_extension, 12, :extension => true + optional :bool, :optional_bool_extension, 13, :extension => true + optional :string, :optional_string_extension, 14, :extension => true + optional :bytes, :optional_bytes_extension, 15, :extension => true optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message_extension, 18, :extension => true optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message_extension, 19, :extension => true optional ::GoogleUnittestImport::ImportMessage, :optional_import_message_extension, 20, :extension => true optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum_extension, 21, :extension => true optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum_extension, 22, :extension => true optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum_extension, 23, :extension => true - optional ::Protobuf::Field::StringField, :optional_string_piece_extension, 24, :extension => true - optional ::Protobuf::Field::StringField, :optional_cord_extension, 25, :extension => true + optional :string, :optional_string_piece_extension, 24, :extension => true + optional :string, :optional_cord_extension, 25, :extension => true optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message_extension, 26, :extension => true optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message_extension, 27, :extension => true - repeated ::Protobuf::Field::Int32Field, :repeated_int32_extension, 31, :extension => true - repeated ::Protobuf::Field::Int64Field, :repeated_int64_extension, 32, :extension => true - repeated ::Protobuf::Field::Uint32Field, :repeated_uint32_extension, 33, :extension => true - repeated ::Protobuf::Field::Uint64Field, :repeated_uint64_extension, 34, :extension => true - repeated ::Protobuf::Field::Sint32Field, :repeated_sint32_extension, 35, :extension => true - repeated ::Protobuf::Field::Sint64Field, :repeated_sint64_extension, 36, :extension => true - repeated ::Protobuf::Field::Fixed32Field, :repeated_fixed32_extension, 37, :extension => true - repeated ::Protobuf::Field::Fixed64Field, :repeated_fixed64_extension, 38, :extension => true - repeated ::Protobuf::Field::Sfixed32Field, :repeated_sfixed32_extension, 39, :extension => true - repeated ::Protobuf::Field::Sfixed64Field, :repeated_sfixed64_extension, 40, :extension => true - repeated ::Protobuf::Field::FloatField, :repeated_float_extension, 41, :extension => true - repeated ::Protobuf::Field::DoubleField, :repeated_double_extension, 42, :extension => true - repeated ::Protobuf::Field::BoolField, :repeated_bool_extension, 43, :extension => true - repeated ::Protobuf::Field::StringField, :repeated_string_extension, 44, :extension => true - repeated ::Protobuf::Field::BytesField, :repeated_bytes_extension, 45, :extension => true + repeated :int32, :repeated_int32_extension, 31, :extension => true + repeated :int64, :repeated_int64_extension, 32, :extension => true + repeated :uint32, :repeated_uint32_extension, 33, :extension => true + repeated :uint64, :repeated_uint64_extension, 34, :extension => true + repeated :sint32, :repeated_sint32_extension, 35, :extension => true + repeated :sint64, :repeated_sint64_extension, 36, :extension => true + repeated :fixed32, :repeated_fixed32_extension, 37, :extension => true + repeated :fixed64, :repeated_fixed64_extension, 38, :extension => true + repeated :sfixed32, :repeated_sfixed32_extension, 39, :extension => true + repeated :sfixed64, :repeated_sfixed64_extension, 40, :extension => true + repeated :float, :repeated_float_extension, 41, :extension => true + repeated :double, :repeated_double_extension, 42, :extension => true + repeated :bool, :repeated_bool_extension, 43, :extension => true + repeated :string, :repeated_string_extension, 44, :extension => true + repeated :bytes, :repeated_bytes_extension, 45, :extension => true repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message_extension, 48, :extension => true repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message_extension, 49, :extension => true repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message_extension, 50, :extension => true repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum_extension, 51, :extension => true repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum_extension, 52, :extension => true repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum_extension, 53, :extension => true - repeated ::Protobuf::Field::StringField, :repeated_string_piece_extension, 54, :extension => true - repeated ::Protobuf::Field::StringField, :repeated_cord_extension, 55, :extension => true + repeated :string, :repeated_string_piece_extension, 54, :extension => true + repeated :string, :repeated_cord_extension, 55, :extension => true repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message_extension, 57, :extension => true - optional ::Protobuf::Field::Int32Field, :default_int32_extension, 61, :default => 41, :extension => true - optional ::Protobuf::Field::Int64Field, :default_int64_extension, 62, :default => 42, :extension => true - optional ::Protobuf::Field::Uint32Field, :default_uint32_extension, 63, :default => 43, :extension => true - optional ::Protobuf::Field::Uint64Field, :default_uint64_extension, 64, :default => 44, :extension => true - optional ::Protobuf::Field::Sint32Field, :default_sint32_extension, 65, :default => -45, :extension => true - optional ::Protobuf::Field::Sint64Field, :default_sint64_extension, 66, :default => 46, :extension => true - optional ::Protobuf::Field::Fixed32Field, :default_fixed32_extension, 67, :default => 47, :extension => true - optional ::Protobuf::Field::Fixed64Field, :default_fixed64_extension, 68, :default => 48, :extension => true - optional ::Protobuf::Field::Sfixed32Field, :default_sfixed32_extension, 69, :default => 49, :extension => true - optional ::Protobuf::Field::Sfixed64Field, :default_sfixed64_extension, 70, :default => -50, :extension => true - optional ::Protobuf::Field::FloatField, :default_float_extension, 71, :default => 51.5, :extension => true - optional ::Protobuf::Field::DoubleField, :default_double_extension, 72, :default => 52000, :extension => true - optional ::Protobuf::Field::BoolField, :default_bool_extension, 73, :default => true, :extension => true - optional ::Protobuf::Field::StringField, :default_string_extension, 74, :default => "hello", :extension => true - optional ::Protobuf::Field::BytesField, :default_bytes_extension, 75, :default => "world", :extension => true + optional :int32, :default_int32_extension, 61, :default => 41, :extension => true + optional :int64, :default_int64_extension, 62, :default => 42, :extension => true + optional :uint32, :default_uint32_extension, 63, :default => 43, :extension => true + optional :uint64, :default_uint64_extension, 64, :default => 44, :extension => true + optional :sint32, :default_sint32_extension, 65, :default => -45, :extension => true + optional :sint64, :default_sint64_extension, 66, :default => 46, :extension => true + optional :fixed32, :default_fixed32_extension, 67, :default => 47, :extension => true + optional :fixed64, :default_fixed64_extension, 68, :default => 48, :extension => true + optional :sfixed32, :default_sfixed32_extension, 69, :default => 49, :extension => true + optional :sfixed64, :default_sfixed64_extension, 70, :default => -50, :extension => true + optional :float, :default_float_extension, 71, :default => 51.5, :extension => true + optional :double, :default_double_extension, 72, :default => 52000, :extension => true + optional :bool, :default_bool_extension, 73, :default => true, :extension => true + optional :string, :default_string_extension, 74, :default => "hello", :extension => true + optional :bytes, :default_bytes_extension, 75, :default => "world", :extension => true optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum_extension, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, :extension => true optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum_extension, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, :extension => true optional ::GoogleUnittestImport::ImportEnum, :default_import_enum_extension, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, :extension => true - optional ::Protobuf::Field::StringField, :default_string_piece_extension, 84, :default => "abc", :extension => true - optional ::Protobuf::Field::StringField, :default_cord_extension, 85, :default => "123", :extension => true - optional ::Protobuf::Field::StringField, :test, 1002, :default => "test", :extension => true + optional :string, :default_string_piece_extension, 84, :default => "abc", :extension => true + optional :string, :default_cord_extension, 85, :default => "123", :extension => true + optional :string, :test, 1002, :default => "test", :extension => true optional ::GoogleUnittest::TestRequired, :single, 1000, :extension => true repeated ::GoogleUnittest::TestRequired, :multi, 1001, :extension => true end class TestRequired - required ::Protobuf::Field::Int32Field, :a, 1 - optional ::Protobuf::Field::Int32Field, :dummy2, 2 - required ::Protobuf::Field::Int32Field, :b, 3 - optional ::Protobuf::Field::Int32Field, :dummy4, 4 - optional ::Protobuf::Field::Int32Field, :dummy5, 5 - optional ::Protobuf::Field::Int32Field, :dummy6, 6 - optional ::Protobuf::Field::Int32Field, :dummy7, 7 - optional ::Protobuf::Field::Int32Field, :dummy8, 8 - optional ::Protobuf::Field::Int32Field, :dummy9, 9 - optional ::Protobuf::Field::Int32Field, :dummy10, 10 - optional ::Protobuf::Field::Int32Field, :dummy11, 11 - optional ::Protobuf::Field::Int32Field, :dummy12, 12 - optional ::Protobuf::Field::Int32Field, :dummy13, 13 - optional ::Protobuf::Field::Int32Field, :dummy14, 14 - optional ::Protobuf::Field::Int32Field, :dummy15, 15 - optional ::Protobuf::Field::Int32Field, :dummy16, 16 - optional ::Protobuf::Field::Int32Field, :dummy17, 17 - optional ::Protobuf::Field::Int32Field, :dummy18, 18 - optional ::Protobuf::Field::Int32Field, :dummy19, 19 - optional ::Protobuf::Field::Int32Field, :dummy20, 20 - optional ::Protobuf::Field::Int32Field, :dummy21, 21 - optional ::Protobuf::Field::Int32Field, :dummy22, 22 - optional ::Protobuf::Field::Int32Field, :dummy23, 23 - optional ::Protobuf::Field::Int32Field, :dummy24, 24 - optional ::Protobuf::Field::Int32Field, :dummy25, 25 - optional ::Protobuf::Field::Int32Field, :dummy26, 26 - optional ::Protobuf::Field::Int32Field, :dummy27, 27 - optional ::Protobuf::Field::Int32Field, :dummy28, 28 - optional ::Protobuf::Field::Int32Field, :dummy29, 29 - optional ::Protobuf::Field::Int32Field, :dummy30, 30 - optional ::Protobuf::Field::Int32Field, :dummy31, 31 - optional ::Protobuf::Field::Int32Field, :dummy32, 32 - required ::Protobuf::Field::Int32Field, :c, 33 + required :int32, :a, 1 + optional :int32, :dummy2, 2 + required :int32, :b, 3 + optional :int32, :dummy4, 4 + optional :int32, :dummy5, 5 + optional :int32, :dummy6, 6 + optional :int32, :dummy7, 7 + optional :int32, :dummy8, 8 + optional :int32, :dummy9, 9 + optional :int32, :dummy10, 10 + optional :int32, :dummy11, 11 + optional :int32, :dummy12, 12 + optional :int32, :dummy13, 13 + optional :int32, :dummy14, 14 + optional :int32, :dummy15, 15 + optional :int32, :dummy16, 16 + optional :int32, :dummy17, 17 + optional :int32, :dummy18, 18 + optional :int32, :dummy19, 19 + optional :int32, :dummy20, 20 + optional :int32, :dummy21, 21 + optional :int32, :dummy22, 22 + optional :int32, :dummy23, 23 + optional :int32, :dummy24, 24 + optional :int32, :dummy25, 25 + optional :int32, :dummy26, 26 + optional :int32, :dummy27, 27 + optional :int32, :dummy28, 28 + optional :int32, :dummy29, 29 + optional :int32, :dummy30, 30 + optional :int32, :dummy31, 31 + optional :int32, :dummy32, 32 + required :int32, :c, 33 end class TestRequiredForeign optional ::GoogleUnittest::TestRequired, :optional_message, 1 repeated ::GoogleUnittest::TestRequired, :repeated_message, 2 - optional ::Protobuf::Field::Int32Field, :dummy, 3 + optional :int32, :dummy, 3 end class TestForeignNested @@ -316,13 +316,13 @@ class TestForeignNested end class TestReallyLargeTagNumber - optional ::Protobuf::Field::Int32Field, :a, 1 - optional ::Protobuf::Field::Int32Field, :bb, 268435455 + optional :int32, :a, 1 + optional :int32, :bb, 268435455 end class TestRecursiveMessage optional ::GoogleUnittest::TestRecursiveMessage, :a, 1 - optional ::Protobuf::Field::Int32Field, :i, 2 + optional :int32, :i, 2 end class TestMutualRecursionA @@ -331,11 +331,11 @@ class TestMutualRecursionA class TestMutualRecursionB optional ::GoogleUnittest::TestMutualRecursionA, :a, 1 - optional ::Protobuf::Field::Int32Field, :optional_int32, 2 + optional :int32, :optional_int32, 2 end class TestDupFieldNumber - optional ::Protobuf::Field::Int32Field, :a, 1 + optional :int32, :a, 1 end class TestEagerMessage @@ -348,7 +348,7 @@ class TestLazyMessage class TestNestedMessageHasBits class NestedMessage - repeated ::Protobuf::Field::Int32Field, :nestedmessage_repeated_int32, 1 + repeated :int32, :nestedmessage_repeated_int32, 1 repeated ::GoogleUnittest::ForeignMessage, :nestedmessage_repeated_foreignmessage, 2 end @@ -356,58 +356,58 @@ class NestedMessage end class TestCamelCaseFieldNames - optional ::Protobuf::Field::Int32Field, :PrimitiveField, 1 - optional ::Protobuf::Field::StringField, :StringField, 2 + optional :int32, :PrimitiveField, 1 + optional :string, :StringField, 2 optional ::GoogleUnittest::ForeignEnum, :EnumField, 3 optional ::GoogleUnittest::ForeignMessage, :MessageField, 4 - optional ::Protobuf::Field::StringField, :StringPieceField, 5 - optional ::Protobuf::Field::StringField, :CordField, 6 - repeated ::Protobuf::Field::Int32Field, :RepeatedPrimitiveField, 7 - repeated ::Protobuf::Field::StringField, :RepeatedStringField, 8 + optional :string, :StringPieceField, 5 + optional :string, :CordField, 6 + repeated :int32, :RepeatedPrimitiveField, 7 + repeated :string, :RepeatedStringField, 8 repeated ::GoogleUnittest::ForeignEnum, :RepeatedEnumField, 9 repeated ::GoogleUnittest::ForeignMessage, :RepeatedMessageField, 10 - repeated ::Protobuf::Field::StringField, :RepeatedStringPieceField, 11 - repeated ::Protobuf::Field::StringField, :RepeatedCordField, 12 + repeated :string, :RepeatedStringPieceField, 11 + repeated :string, :RepeatedCordField, 12 end class TestFieldOrderings - optional ::Protobuf::Field::StringField, :my_string, 11 - optional ::Protobuf::Field::Int64Field, :my_int, 1 - optional ::Protobuf::Field::FloatField, :my_float, 101 + optional :string, :my_string, 11 + optional :int64, :my_int, 1 + optional :float, :my_float, 101 # Extension Fields extensions 2...11 extensions 12...101 - optional ::Protobuf::Field::StringField, :my_extension_string, 50, :extension => true - optional ::Protobuf::Field::Int32Field, :my_extension_int, 5, :extension => true + optional :string, :my_extension_string, 50, :extension => true + optional :int32, :my_extension_int, 5, :extension => true end class TestExtremeDefaultValues - optional ::Protobuf::Field::BytesField, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" - optional ::Protobuf::Field::Uint32Field, :large_uint32, 2, :default => 4294967295 - optional ::Protobuf::Field::Uint64Field, :large_uint64, 3, :default => 18446744073709551615 - optional ::Protobuf::Field::Int32Field, :small_int32, 4, :default => -2147483647 - optional ::Protobuf::Field::Int64Field, :small_int64, 5, :default => -9223372036854775807 - optional ::Protobuf::Field::Int32Field, :really_small_int32, 21, :default => -2147483648 - optional ::Protobuf::Field::Int64Field, :really_small_int64, 22, :default => -9223372036854775808 - optional ::Protobuf::Field::StringField, :utf8_string, 6, :default => "ሴ" - optional ::Protobuf::Field::FloatField, :zero_float, 7, :default => 0 - optional ::Protobuf::Field::FloatField, :one_float, 8, :default => 1 - optional ::Protobuf::Field::FloatField, :small_float, 9, :default => 1.5 - optional ::Protobuf::Field::FloatField, :negative_one_float, 10, :default => -1 - optional ::Protobuf::Field::FloatField, :negative_float, 11, :default => -1.5 - optional ::Protobuf::Field::FloatField, :large_float, 12, :default => 2e+08 - optional ::Protobuf::Field::FloatField, :small_negative_float, 13, :default => -8e-28 - optional ::Protobuf::Field::DoubleField, :inf_double, 14, :default => ::Float::INFINITY - optional ::Protobuf::Field::DoubleField, :neg_inf_double, 15, :default => -::Float::INFINITY - optional ::Protobuf::Field::DoubleField, :nan_double, 16, :default => ::Float::NAN - optional ::Protobuf::Field::FloatField, :inf_float, 17, :default => ::Float::INFINITY - optional ::Protobuf::Field::FloatField, :neg_inf_float, 18, :default => -::Float::INFINITY - optional ::Protobuf::Field::FloatField, :nan_float, 19, :default => ::Float::NAN - optional ::Protobuf::Field::StringField, :cpp_trigraph, 20, :default => "? ? ?? ?? ??? ??/ ??-" - optional ::Protobuf::Field::StringField, :string_with_zero, 23, :default => "hello" - optional ::Protobuf::Field::BytesField, :bytes_with_zero, 24, :default => "wor\000ld" - optional ::Protobuf::Field::StringField, :string_piece_with_zero, 25, :default => "abc" - optional ::Protobuf::Field::StringField, :cord_with_zero, 26, :default => "123" + optional :bytes, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" + optional :uint32, :large_uint32, 2, :default => 4294967295 + optional :uint64, :large_uint64, 3, :default => 18446744073709551615 + optional :int32, :small_int32, 4, :default => -2147483647 + optional :int64, :small_int64, 5, :default => -9223372036854775807 + optional :int32, :really_small_int32, 21, :default => -2147483648 + optional :int64, :really_small_int64, 22, :default => -9223372036854775808 + optional :string, :utf8_string, 6, :default => "ሴ" + optional :float, :zero_float, 7, :default => 0 + optional :float, :one_float, 8, :default => 1 + optional :float, :small_float, 9, :default => 1.5 + optional :float, :negative_one_float, 10, :default => -1 + optional :float, :negative_float, 11, :default => -1.5 + optional :float, :large_float, 12, :default => 2e+08 + optional :float, :small_negative_float, 13, :default => -8e-28 + optional :double, :inf_double, 14, :default => ::Float::INFINITY + optional :double, :neg_inf_double, 15, :default => -::Float::INFINITY + optional :double, :nan_double, 16, :default => ::Float::NAN + optional :float, :inf_float, 17, :default => ::Float::INFINITY + optional :float, :neg_inf_float, 18, :default => -::Float::INFINITY + optional :float, :nan_float, 19, :default => ::Float::NAN + optional :string, :cpp_trigraph, 20, :default => "? ? ?? ?? ??? ??/ ??-" + optional :string, :string_with_zero, 23, :default => "hello" + optional :bytes, :bytes_with_zero, 24, :default => "wor\000ld" + optional :string, :string_piece_with_zero, 25, :default => "abc" + optional :string, :cord_with_zero, 26, :default => "123" end class SparseEnumMessage @@ -415,95 +415,95 @@ class SparseEnumMessage end class OneString - optional ::Protobuf::Field::StringField, :data, 1 + optional :string, :data, 1 end class MoreString - repeated ::Protobuf::Field::StringField, :data, 1 + repeated :string, :data, 1 end class OneBytes - optional ::Protobuf::Field::BytesField, :data, 1 + optional :bytes, :data, 1 end class MoreBytes - repeated ::Protobuf::Field::BytesField, :data, 1 + repeated :bytes, :data, 1 end class TestPackedTypes - repeated ::Protobuf::Field::Int32Field, :packed_int32, 90, :packed => true - repeated ::Protobuf::Field::Int64Field, :packed_int64, 91, :packed => true - repeated ::Protobuf::Field::Uint32Field, :packed_uint32, 92, :packed => true - repeated ::Protobuf::Field::Uint64Field, :packed_uint64, 93, :packed => true - repeated ::Protobuf::Field::Sint32Field, :packed_sint32, 94, :packed => true - repeated ::Protobuf::Field::Sint64Field, :packed_sint64, 95, :packed => true - repeated ::Protobuf::Field::Fixed32Field, :packed_fixed32, 96, :packed => true - repeated ::Protobuf::Field::Fixed64Field, :packed_fixed64, 97, :packed => true - repeated ::Protobuf::Field::Sfixed32Field, :packed_sfixed32, 98, :packed => true - repeated ::Protobuf::Field::Sfixed64Field, :packed_sfixed64, 99, :packed => true - repeated ::Protobuf::Field::FloatField, :packed_float, 100, :packed => true - repeated ::Protobuf::Field::DoubleField, :packed_double, 101, :packed => true - repeated ::Protobuf::Field::BoolField, :packed_bool, 102, :packed => true + repeated :int32, :packed_int32, 90, :packed => true + repeated :int64, :packed_int64, 91, :packed => true + repeated :uint32, :packed_uint32, 92, :packed => true + repeated :uint64, :packed_uint64, 93, :packed => true + repeated :sint32, :packed_sint32, 94, :packed => true + repeated :sint64, :packed_sint64, 95, :packed => true + repeated :fixed32, :packed_fixed32, 96, :packed => true + repeated :fixed64, :packed_fixed64, 97, :packed => true + repeated :sfixed32, :packed_sfixed32, 98, :packed => true + repeated :sfixed64, :packed_sfixed64, 99, :packed => true + repeated :float, :packed_float, 100, :packed => true + repeated :double, :packed_double, 101, :packed => true + repeated :bool, :packed_bool, 102, :packed => true repeated ::GoogleUnittest::ForeignEnum, :packed_enum, 103, :packed => true end class TestUnpackedTypes - repeated ::Protobuf::Field::Int32Field, :unpacked_int32, 90 - repeated ::Protobuf::Field::Int64Field, :unpacked_int64, 91 - repeated ::Protobuf::Field::Uint32Field, :unpacked_uint32, 92 - repeated ::Protobuf::Field::Uint64Field, :unpacked_uint64, 93 - repeated ::Protobuf::Field::Sint32Field, :unpacked_sint32, 94 - repeated ::Protobuf::Field::Sint64Field, :unpacked_sint64, 95 - repeated ::Protobuf::Field::Fixed32Field, :unpacked_fixed32, 96 - repeated ::Protobuf::Field::Fixed64Field, :unpacked_fixed64, 97 - repeated ::Protobuf::Field::Sfixed32Field, :unpacked_sfixed32, 98 - repeated ::Protobuf::Field::Sfixed64Field, :unpacked_sfixed64, 99 - repeated ::Protobuf::Field::FloatField, :unpacked_float, 100 - repeated ::Protobuf::Field::DoubleField, :unpacked_double, 101 - repeated ::Protobuf::Field::BoolField, :unpacked_bool, 102 + repeated :int32, :unpacked_int32, 90 + repeated :int64, :unpacked_int64, 91 + repeated :uint32, :unpacked_uint32, 92 + repeated :uint64, :unpacked_uint64, 93 + repeated :sint32, :unpacked_sint32, 94 + repeated :sint64, :unpacked_sint64, 95 + repeated :fixed32, :unpacked_fixed32, 96 + repeated :fixed64, :unpacked_fixed64, 97 + repeated :sfixed32, :unpacked_sfixed32, 98 + repeated :sfixed64, :unpacked_sfixed64, 99 + repeated :float, :unpacked_float, 100 + repeated :double, :unpacked_double, 101 + repeated :bool, :unpacked_bool, 102 repeated ::GoogleUnittest::ForeignEnum, :unpacked_enum, 103 end class TestPackedExtensions # Extension Fields extensions 1...536870912 - repeated ::Protobuf::Field::Int32Field, :packed_int32_extension, 90, :packed => true, :extension => true - repeated ::Protobuf::Field::Int64Field, :packed_int64_extension, 91, :packed => true, :extension => true - repeated ::Protobuf::Field::Uint32Field, :packed_uint32_extension, 92, :packed => true, :extension => true - repeated ::Protobuf::Field::Uint64Field, :packed_uint64_extension, 93, :packed => true, :extension => true - repeated ::Protobuf::Field::Sint32Field, :packed_sint32_extension, 94, :packed => true, :extension => true - repeated ::Protobuf::Field::Sint64Field, :packed_sint64_extension, 95, :packed => true, :extension => true - repeated ::Protobuf::Field::Fixed32Field, :packed_fixed32_extension, 96, :packed => true, :extension => true - repeated ::Protobuf::Field::Fixed64Field, :packed_fixed64_extension, 97, :packed => true, :extension => true - repeated ::Protobuf::Field::Sfixed32Field, :packed_sfixed32_extension, 98, :packed => true, :extension => true - repeated ::Protobuf::Field::Sfixed64Field, :packed_sfixed64_extension, 99, :packed => true, :extension => true - repeated ::Protobuf::Field::FloatField, :packed_float_extension, 100, :packed => true, :extension => true - repeated ::Protobuf::Field::DoubleField, :packed_double_extension, 101, :packed => true, :extension => true - repeated ::Protobuf::Field::BoolField, :packed_bool_extension, 102, :packed => true, :extension => true + repeated :int32, :packed_int32_extension, 90, :packed => true, :extension => true + repeated :int64, :packed_int64_extension, 91, :packed => true, :extension => true + repeated :uint32, :packed_uint32_extension, 92, :packed => true, :extension => true + repeated :uint64, :packed_uint64_extension, 93, :packed => true, :extension => true + repeated :sint32, :packed_sint32_extension, 94, :packed => true, :extension => true + repeated :sint64, :packed_sint64_extension, 95, :packed => true, :extension => true + repeated :fixed32, :packed_fixed32_extension, 96, :packed => true, :extension => true + repeated :fixed64, :packed_fixed64_extension, 97, :packed => true, :extension => true + repeated :sfixed32, :packed_sfixed32_extension, 98, :packed => true, :extension => true + repeated :sfixed64, :packed_sfixed64_extension, 99, :packed => true, :extension => true + repeated :float, :packed_float_extension, 100, :packed => true, :extension => true + repeated :double, :packed_double_extension, 101, :packed => true, :extension => true + repeated :bool, :packed_bool_extension, 102, :packed => true, :extension => true repeated ::GoogleUnittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true end class TestDynamicExtensions class DynamicMessageType - optional ::Protobuf::Field::Int32Field, :dynamic_field, 2100 + optional :int32, :dynamic_field, 2100 end - optional ::Protobuf::Field::Fixed32Field, :scalar_extension, 2000 + optional :fixed32, :scalar_extension, 2000 optional ::GoogleUnittest::ForeignEnum, :enum_extension, 2001 optional ::GoogleUnittest::TestDynamicExtensions::DynamicEnumType, :dynamic_enum_extension, 2002 optional ::GoogleUnittest::ForeignMessage, :message_extension, 2003 optional ::GoogleUnittest::TestDynamicExtensions::DynamicMessageType, :dynamic_message_extension, 2004 - repeated ::Protobuf::Field::StringField, :repeated_extension, 2005 - repeated ::Protobuf::Field::Sint32Field, :packed_extension, 2006, :packed => true + repeated :string, :repeated_extension, 2005 + repeated :sint32, :packed_extension, 2006, :packed => true end class TestRepeatedScalarDifferentTagSizes - repeated ::Protobuf::Field::Fixed32Field, :repeated_fixed32, 12 - repeated ::Protobuf::Field::Int32Field, :repeated_int32, 13 - repeated ::Protobuf::Field::Fixed64Field, :repeated_fixed64, 2046 - repeated ::Protobuf::Field::Int64Field, :repeated_int64, 2047 - repeated ::Protobuf::Field::FloatField, :repeated_float, 262142 - repeated ::Protobuf::Field::Uint64Field, :repeated_uint64, 262143 + repeated :fixed32, :repeated_fixed32, 12 + repeated :int32, :repeated_int32, 13 + repeated :fixed64, :repeated_fixed64, 2046 + repeated :int64, :repeated_int64, 2047 + repeated :float, :repeated_float, 262142 + repeated :uint64, :repeated_uint64, 262143 end class TestParsingMerge @@ -525,7 +525,7 @@ class RepeatedFieldsGenerator end class TestCommentInjectionMessage - optional ::Protobuf::Field::StringField, :a, 1, :default => "*/ <- Neither should this." + optional :string, :a, 1, :default => "*/ <- Neither should this." end diff --git a/spec/support/test/google_unittest_import.pb.rb b/spec/support/test/google_unittest_import.pb.rb index f1b600f7..1c37587c 100644 --- a/spec/support/test/google_unittest_import.pb.rb +++ b/spec/support/test/google_unittest_import.pb.rb @@ -26,11 +26,11 @@ class ImportMessage < ::Protobuf::Message; end # Message Fields # class PublicImportMessage - optional ::Protobuf::Field::Int32Field, :e, 1 + optional :int32, :e, 1 end class ImportMessage - optional ::Protobuf::Field::Int32Field, :d, 1 + optional :int32, :d, 1 end end diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/test/multi_field_extensions.pb.rb index 8a3c03a2..15ae94ed 100644 --- a/spec/support/test/multi_field_extensions.pb.rb +++ b/spec/support/test/multi_field_extensions.pb.rb @@ -40,14 +40,14 @@ class Header class PayloadA class Foo - optional ::Protobuf::Field::StringField, :foo_a, 1 + optional :string, :foo_a, 1 end end class PayloadB class Foo - optional ::Protobuf::Field::StringField, :foo_b, 1 + optional :string, :foo_b, 1 end end diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index f0c18fe4..e580a312 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -47,54 +47,54 @@ class NestedLevelOne < ::Protobuf::Message; end # Message Fields # class ResourceFindRequest - required ::Protobuf::Field::StringField, :name, 1 - optional ::Protobuf::Field::BoolField, :active, 2 - repeated ::Protobuf::Field::StringField, :widgets, 3 - repeated ::Protobuf::Field::BytesField, :widget_bytes, 4 + required :string, :name, 1 + optional :bool, :active, 2 + repeated :string, :widgets, 3 + repeated :bytes, :widget_bytes, 4 end class ResourceSleepRequest - optional ::Protobuf::Field::Int32Field, :sleep, 1 + optional :int32, :sleep, 1 end class Resource - required ::Protobuf::Field::StringField, :name, 1 - optional ::Protobuf::Field::Int64Field, :date_created, 2 + required :string, :name, 1 + optional :int64, :date_created, 2 optional ::Test::StatusType, :status, 3 repeated ::Test::StatusType, :repeated_enum, 4 # Extension Fields extensions 100...536870912 - optional ::Protobuf::Field::BoolField, :ext_is_searchable, 100, :extension => true - optional ::Protobuf::Field::BoolField, :ext_is_hidden, 101, :extension => true + optional :bool, :ext_is_searchable, 100, :extension => true + optional :bool, :ext_is_hidden, 101, :extension => true optional ::Test::Searchable::SearchType, :ext_search_type, 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true - optional ::Protobuf::Field::BoolField, :ext_nested_in_level_one, 105, :extension => true - optional ::Protobuf::Field::BoolField, :ext_dup_field, 106, :extension => true + optional :bool, :ext_nested_in_level_one, 105, :extension => true + optional :bool, :ext_dup_field, 106, :extension => true end class MessageParent class MessageChild - optional ::Protobuf::Field::StringField, :child1, 1 + optional :string, :child1, 1 end end class Nested class NestedLevelOne - optional ::Protobuf::Field::BoolField, :level_one, 1, :default => true + optional :bool, :level_one, 1, :default => true # Extension Fields extensions 100...102 - optional ::Protobuf::Field::BoolField, :ext_nested_level_one_outer, 101, :extension => true - optional ::Protobuf::Field::BoolField, :ext_nested_level_one, 100, :extension => true + optional :bool, :ext_nested_level_one_outer, 101, :extension => true + optional :bool, :ext_nested_level_one, 100, :extension => true end - optional ::Protobuf::Field::StringField, :name, 1 + optional :string, :name, 1 optional ::Test::Resource, :resource, 2 repeated ::Test::Resource, :multiple_resources, 3 optional ::Test::StatusType, :status, 4 # Extension Fields extensions 100...111 - optional ::Protobuf::Field::StringField, :foo, 100, :extension => true - optional ::Protobuf::Field::Int64Field, :bar, 101, :extension => true + optional :string, :foo, 100, :extension => true + optional :int64, :bar, 101, :extension => true end From 7eb6de9629c60ed69dbd8a5ca03e897a08f02b4a Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Feb 2014 21:01:39 -0700 Subject: [PATCH 0622/1191] Cleanup rake task descriptions --- Rakefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 5b7a51b3..d32e29e3 100644 --- a/Rakefile +++ b/Rakefile @@ -17,15 +17,16 @@ RSpec::Core::RakeTask.new(:spec) desc 'Run specs' namespace :compile do - desc 'Compile spec protos in spec/supprt/' + desc 'Compile spec protos in spec/supprt/ directory' task :spec do |task, args| proto_path = ::File.expand_path('../spec/support/', __FILE__) cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + puts cmd - exec cmd + exec(cmd) end - desc "Compile spec protos in spec/supprt/" + desc 'Compile rpc protos in protos/ directory' task :rpc do |task, args| proto_path = ::File.expand_path('../proto', __FILE__) output_dir = ::File.expand_path('../tmp/rpc', __FILE__) @@ -34,7 +35,7 @@ namespace :compile do cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} puts cmd - puts %x(#{cmd}) + system(cmd) files = { 'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc', From 2e605c134a3c01624fdba59331840a8e6a681d9a Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Sat, 15 Feb 2014 14:54:14 -0700 Subject: [PATCH 0623/1191] Bump version to 3.0.0.alpha for development --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index dca37278..9517dec5 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,4 @@ module Protobuf - VERSION = '2.8.12' + VERSION = '3.0.0.alpha' PROTOC_VERSION = '2.5.0' end From eaa31fd2fff7efb4a0853acfb7e0597f0b409df7 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Mon, 17 Feb 2014 10:00:28 -0700 Subject: [PATCH 0624/1191] Add load hooks for the middleware Add Active Support load hooks for the middleware stack to make it easier to load middlewares into the stack. Bump the minimum version of AS up to 2.0 since it's (at least) what we need to load middlewares and older versions are no longer supported. --- lib/protobuf/rpc/client.rb | 4 +--- lib/protobuf/rpc/middleware.rb | 2 ++ lib/protobuf/rpc/service.rb | 4 +--- protobuf.gemspec | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index ea64547f..0d0c0d4e 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -163,8 +163,6 @@ def send_request end - if ActiveSupport::VERSION::MAJOR > 2 - ActiveSupport.run_load_hooks(:protobuf_rpc_client, Client) - end + ActiveSupport.run_load_hooks(:protobuf_rpc_client, Client) end end diff --git a/lib/protobuf/rpc/middleware.rb b/lib/protobuf/rpc/middleware.rb index 9d20ae96..3757b646 100644 --- a/lib/protobuf/rpc/middleware.rb +++ b/lib/protobuf/rpc/middleware.rb @@ -20,4 +20,6 @@ def self.middleware Rpc.middleware.use(Rpc::Middleware::RequestDecoder) Rpc.middleware.use(Rpc::Middleware::Logger) Rpc.middleware.use(Rpc::Middleware::ResponseEncoder) + + ActiveSupport.run_load_hooks(:protobuf_rpc_middleware, Rpc) end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index cc514eef..b537b7f4 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -176,8 +176,6 @@ def rpc_failed(message) end end - if ActiveSupport::VERSION::MAJOR > 2 - ActiveSupport.run_load_hooks(:protobuf_rpc_service, Service) - end + ActiveSupport.run_load_hooks(:protobuf_rpc_service, Service) end end diff --git a/protobuf.gemspec b/protobuf.gemspec index 72f5079a..cfd8b65d 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -19,7 +19,7 @@ require "protobuf/version" s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'activesupport' + s.add_dependency 'activesupport', '>= 2' s.add_dependency 'middleware' s.add_dependency 'multi_json' s.add_dependency 'thor' From 773bfcee507eff30b32803e2f4429e3e5853f153 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Feb 2014 12:42:53 -0700 Subject: [PATCH 0625/1191] Move decoder/encoder out of message namespace --- lib/protobuf/{message => }/decoder.rb | 0 lib/protobuf/{message => }/encoder.rb | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename lib/protobuf/{message => }/decoder.rb (100%) rename lib/protobuf/{message => }/encoder.rb (100%) diff --git a/lib/protobuf/message/decoder.rb b/lib/protobuf/decoder.rb similarity index 100% rename from lib/protobuf/message/decoder.rb rename to lib/protobuf/decoder.rb diff --git a/lib/protobuf/message/encoder.rb b/lib/protobuf/encoder.rb similarity index 100% rename from lib/protobuf/message/encoder.rb rename to lib/protobuf/encoder.rb From 5f3dcd3337f34c322b140592ec71dd59e8a35c41 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Feb 2014 12:48:15 -0700 Subject: [PATCH 0626/1191] Make the encoder a class so we can privatize methods --- lib/protobuf/encoder.rb | 77 ++++++++++++++++----------- lib/protobuf/message/serialization.rb | 4 +- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index b53de4db..714c40da 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -1,49 +1,62 @@ module Protobuf - class Message - module Encoder + class Encoder - def self.encode(stream, message) - message.each_field_for_serialization do |field, value| - encode_field(field, value, stream) - end + def self.encode(stream, message) + new(stream, message).encode + end + + attr_reader :message, :stream - stream + def initialize(message, stream) + unless message.respond_to?(:each_field_for_serialization) + raise ArgumentError, "Message instance must respond to :each_field_for_serialization" end - private + @message = message + @stream = stream + end - def self.encode_field(field, value, stream) - if field.repeated? - encode_repeated_field(field, value, stream) - else - write_pair(stream, field, value) - end + def encode + message.each_field_for_serialization do |field, value| + encode_field(field, value, stream) end - def self.encode_packed_field(field, value, stream) - key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED - packed_value = value.map { |val| field.encode(val) }.join - stream << ::Protobuf::Field::VarintField.encode(key) - stream << ::Protobuf::Field::VarintField.encode(packed_value.size) - stream << packed_value - end + stream + end + + private - def self.encode_repeated_field(field, value, stream) - if field.packed? - encode_packed_field(field, value, stream) - else - value.each { |val| write_pair(stream, field, val) } - end + def encode_field(field, value, stream) + if field.repeated? + encode_repeated_field(field, value, stream) + else + write_pair(stream, field, value) end + end + + def encode_packed_field(field, value, stream) + key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED + packed_value = value.map { |val| field.encode(val) }.join + stream << ::Protobuf::Field::VarintField.encode(key) + stream << ::Protobuf::Field::VarintField.encode(packed_value.size) + stream << packed_value + end - # Encode key and value, and write to +stream+. - def self.write_pair(stream, field, value) - key = (field.tag << 3) | field.wire_type - stream << ::Protobuf::Field::VarintField.encode(key) - stream << field.encode(value) + def encode_repeated_field(field, value, stream) + if field.packed? + encode_packed_field(field, value, stream) + else + value.each { |val| write_pair(stream, field, val) } end + end + # Encode key and value, and write to +stream+. + def write_pair(stream, field, value) + key = (field.tag << 3) | field.wire_type + stream << ::Protobuf::Field::VarintField.encode(key) + stream << field.encode(value) end + end end diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 76fa5ff9..8dabad07 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -1,6 +1,6 @@ require 'stringio' require 'protobuf/message/decoder' -require 'protobuf/message/encoder' +require 'protobuf/encoder' module Protobuf class Message @@ -51,7 +51,7 @@ def encode # Encode this message to the given stream. # def encode_to(stream) - ::Protobuf::Message::Encoder.encode(stream, self) + ::Protobuf::Encoder.encode(self, stream) end ## From 45e3a96a52b532e0521e2db7c74d23caf827d2b2 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Feb 2014 12:55:01 -0700 Subject: [PATCH 0627/1191] Use stream attr_reader in encoder instance --- lib/protobuf/encoder.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 714c40da..d455ecde 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -18,7 +18,7 @@ def initialize(message, stream) def encode message.each_field_for_serialization do |field, value| - encode_field(field, value, stream) + encode_field(field, value) end stream @@ -26,15 +26,15 @@ def encode private - def encode_field(field, value, stream) + def encode_field(field, value) if field.repeated? - encode_repeated_field(field, value, stream) + encode_repeated_field(field, value) else write_pair(stream, field, value) end end - def encode_packed_field(field, value, stream) + def encode_packed_field(field, value) key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED packed_value = value.map { |val| field.encode(val) }.join stream << ::Protobuf::Field::VarintField.encode(key) @@ -42,9 +42,9 @@ def encode_packed_field(field, value, stream) stream << packed_value end - def encode_repeated_field(field, value, stream) + def encode_repeated_field(field, value) if field.packed? - encode_packed_field(field, value, stream) + encode_packed_field(field, value) else value.each { |val| write_pair(stream, field, val) } end From c649edb8cdceb024a116bbdc0ee9c5e2c661cb39 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Feb 2014 12:55:26 -0700 Subject: [PATCH 0628/1191] De-privatize class methods in Decoder (as it doesn't work that way) --- lib/protobuf/decoder.rb | 119 ++++++++++++-------------- lib/protobuf/message/serialization.rb | 4 +- 2 files changed, 59 insertions(+), 64 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 05fc282a..b3b9eb0e 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -2,78 +2,73 @@ require 'protobuf/exceptions' module Protobuf - class Message - module Decoder + class Decoder - # Read bytes from +stream+ and pass to +message+ object. - def self.decode_each_field(stream, &block) - until stream.eof? - tag, bytes = read_field(stream) - block.call(tag, bytes) - end - end - - # Read 32-bit string value from +stream+. - def self.read_fixed32(stream) - stream.read(4) - end - - # Read 64-bit string value from +stream+. - def self.read_fixed64(stream) - stream.read(8) + # Read bytes from +stream+ and pass to +message+ object. + def self.decode_each_field(stream, &block) + until stream.eof? + tag, bytes = read_field(stream) + block.call(tag, bytes) end + end - # Read varint integer value from +stream+. - def self.read_varint(stream) - value = index = 0 - begin - byte = stream.readbyte - value |= (byte & 0x7f) << (7 * index) - index += 1 - end while (byte & 0x80).nonzero? - value - end + def self.read_field(stream) + tag, wire_type = read_key(stream) + bytes = case wire_type + when ::Protobuf::WireType::VARINT then + read_varint(stream) + when ::Protobuf::WireType::FIXED64 then + read_fixed64(stream) + when ::Protobuf::WireType::LENGTH_DELIMITED then + read_length_delimited(stream) + when ::Protobuf::WireType::FIXED32 then + read_fixed32(stream) + when ::Protobuf::WireType::START_GROUP then + raise NotImplementedError, 'Group is deprecated.' + when ::Protobuf::WireType::END_GROUP then + raise NotImplementedError, 'Group is deprecated.' + else + raise InvalidWireType, wire_type + end - private + return tag, bytes + end - def self.read_field(stream) - tag, wire_type = read_key(stream) - bytes = - case wire_type - when ::Protobuf::WireType::VARINT then - read_varint(stream) - when ::Protobuf::WireType::FIXED64 then - read_fixed64(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED then - read_length_delimited(stream) - when ::Protobuf::WireType::FIXED32 then - read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP then - raise NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP then - raise NotImplementedError, 'Group is deprecated.' - else - raise InvalidWireType, wire_type - end + # Read 32-bit string value from +stream+. + def self.read_fixed32(stream) + stream.read(4) + end - return tag, bytes - end + # Read 64-bit string value from +stream+. + def self.read_fixed64(stream) + stream.read(8) + end - # Read key pair (tag and wire-type) from +stream+. - def self.read_key(stream) - bits = read_varint(stream) - wire_type = bits & 0x07 - tag = bits >> 3 - [tag, wire_type] - end + # Read key pair (tag and wire-type) from +stream+. + def self.read_key(stream) + bits = read_varint(stream) + wire_type = bits & 0x07 + tag = bits >> 3 + [tag, wire_type] + end - # Read length-delimited string value from +stream+. - def self.read_length_delimited(stream) - value_length = read_varint(stream) - stream.read(value_length) - end + # Read length-delimited string value from +stream+. + def self.read_length_delimited(stream) + value_length = read_varint(stream) + stream.read(value_length) + end + # Read varint integer value from +stream+. + def self.read_varint(stream) + value = index = 0 + begin + byte = stream.readbyte + value |= (byte & 0x7f) << (7 * index) + index += 1 + end while (byte & 0x80).nonzero? + value end + end end diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 8dabad07..bfe58faf 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -1,5 +1,5 @@ require 'stringio' -require 'protobuf/message/decoder' +require 'protobuf/decoder' require 'protobuf/encoder' module Protobuf @@ -34,7 +34,7 @@ def decode(bytes) # Decode the given stream into this message. # def decode_from(stream) - ::Protobuf::Message::Decoder.decode_each_field(stream) do |tag, bytes| + ::Protobuf::Decoder.decode_each_field(stream) do |tag, bytes| set_field_bytes(tag, bytes) end From fb54c457dde672145833cd8cd59a3f1e6aacb25d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Feb 2014 15:29:35 -0700 Subject: [PATCH 0629/1191] Fix call to decoder in BaseField --- lib/protobuf/field/base_field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 440fa154..41eed43a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -76,7 +76,7 @@ def set(message_instance, bytes) stream = StringIO.new(bytes) until stream.eof? - array << decode(::Protobuf::Message::Decoder.__send__(method, stream)) + array << decode(::Protobuf::Decoder.__send__(method, stream)) end else value = decode(bytes) From b8c9fbde7bd96043fa2b5203f0c33bdcb0391945 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Feb 2014 15:30:10 -0700 Subject: [PATCH 0630/1191] Fix spec proto compile --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4102ead5..61e94631 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -35,7 +35,7 @@ require 'rake' load ::File.expand_path('../../Rakefile', __FILE__) $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - ::Rake::Task['spec:compile_test_protos'] + ::Rake::Task['compile:spec'] end end end From 16088e21efbe808944f7b77d3ec4c11acad1f791 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 17 Feb 2014 16:36:30 -0700 Subject: [PATCH 0631/1191] Resolve the DNS name to an ip address in the ZMQ util module When given a non-ip address hostname (e.g. localhost) the resolver will now return the detected ip address for that DNS name, if any. Fixes #46. --- lib/protobuf/rpc/servers/zmq/util.rb | 5 ++++- spec/lib/protobuf/rpc/servers/zmq/util_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index a684239b..1cef47d8 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -4,6 +4,7 @@ module Protobuf module Rpc module Zmq + ADDRESS_MATCH = /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/.freeze WORKER_READY_MESSAGE = "\1" module Util @@ -33,7 +34,9 @@ def log_signature end def resolve_ip(hostname) - ::Resolv.getaddress(hostname) + ::Resolv.getaddresses(hostname).detect do |address| + address =~ ADDRESS_MATCH + end end end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index dad46a46..7412d0d6 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -42,4 +42,14 @@ class UtilTest subject.log_signature.should include('server', 'UtilTest') end end + + describe '.resolve_ip' do + it 'resolves ips' do + expect(subject.resolve_ip('127.0.0.1')).to eq('127.0.0.1') + end + + it 'resolves non ips' do + expect(subject.resolve_ip('localhost')).to eq('127.0.0.1') + end + end end From a8864a218f12c9142b98ffb18ee3d8c27609aeb2 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Tue, 18 Feb 2014 10:09:47 -0700 Subject: [PATCH 0632/1191] Use the request/response types from the env Since the request decoder has already extracted the request and response types and stored them in the env, use those instead of fetching them directly. --- lib/protobuf/rpc/service.rb | 7 +++---- spec/lib/protobuf/rpc/service_spec.rb | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index b537b7f4..1dae0c9b 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -16,7 +16,7 @@ class Service DEFAULT_HOST = '127.0.0.1'.freeze DEFAULT_PORT = 9399 - attr_reader :client_host, :env, :method_name, :request + attr_reader :client_host, :env, :request ## # Constructor! @@ -25,7 +25,6 @@ class Service # for the request. def initialize(env) @env = env.dup # Dup the env so it doesn't change out from under us - @method_name = env.method_name @request = env.request @client_host = env.caller end @@ -152,7 +151,7 @@ def rpcs private def request_type - @_request_type ||= rpcs[@method_name].request_type + @_request_type ||= env.request_type end # Sugar to make an rpc method feel like a controller method. @@ -165,7 +164,7 @@ def respond_with(candidate) alias_method :return_from_whence_you_came, :respond_with def response_type - @_response_type ||= rpcs[@method_name].response_type + @_response_type ||= env.response_type end # Automatically fail a service method. diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 46d0a317..49b66a0e 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -127,10 +127,12 @@ def find_with_rpc_failed context 'when response is implied' do let(:env) { Protobuf::Rpc::Env.new( - 'method_name' => :find_with_implied_response, - 'request' => request + 'request' => request, + 'response_type' => response_type ) } + let(:response_type) { service.rpcs[:find_with_implied_response].response_type } + let(:service) { NewTestService } subject { NewTestService.new(env) } From 6e4994b2314430cde70b75cae4726031e0383180 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Feb 2014 15:19:02 -0700 Subject: [PATCH 0633/1191] Pass in the defined type when building a field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the field class is enum or message we need to pass the actual class as the type, not EnumField or MessageField (or symbol). This is because for messages and enums, we expect to be dealing with a message/enum instance instead of the field instance. Example ```ruby class Foo < ::Protobuf::Message optional :string, :name, 1 # expands to Protobuf::Field::StringField.new(Foo, :optional, Protobuf::FieldString, :name, 1, {}) end # Notice the difference between what we’re initializing and # what we’re passing as the type (Foo in this case, not MessageField) class Bar < Protobuf::Message optional Foo, :foo, 1 # expands to Protobuf::Field::MessageField.new(Bar, :optional, Foo, :foo, 1, {}) end --- lib/protobuf/field.rb | 15 ++++++++++-- spec/lib/protobuf/field_spec.rb | 42 +++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index e6ba6997..bbcd8c73 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -42,10 +42,14 @@ module Field }.freeze def self.build(message_class, rule, type, name, tag, options = {}) - field_type(type).new(message_class, rule, type, name, tag, options) + field_class(type).new(message_class, rule, field_type(type), name, tag, options) end - def self.field_type(type) + # Returns the field class for primitives, + # EnumField for types that inherit from Protobuf::Enum, + # and MessageField for types that inherit from Protobuf::Message. + # + def self.field_class(type) if PRIMITIVE_FIELD_MAP.key?(type) PRIMITIVE_FIELD_MAP[type] elsif type < ::Protobuf::Enum @@ -59,5 +63,12 @@ def self.field_type(type) end end + # Returns the mapped type for primitives, + # otherwise the given type is returned. + # + def self.field_type(type) + PRIMITIVE_FIELD_MAP.fetch(type) { type } + end + end end diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index c498f834..e9772588 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -7,28 +7,32 @@ pending end - describe '.field_type' do + describe '.field_class' do context 'when type is an enum class' do it 'returns an enum field' do - expect(subject.field_type(::Test::EnumTestType)).to eq(::Protobuf::Field::EnumField) + expect(subject.field_class(::Test::EnumTestType)).to eq(::Protobuf::Field::EnumField) + expect(subject.field_type(::Test::EnumTestType)).to eq(::Test::EnumTestType) end end context 'when type is a message class' do it 'returns a message field' do - expect(subject.field_type(::Test::Resource)).to eq(::Protobuf::Field::MessageField) + expect(subject.field_class(::Test::Resource)).to eq(::Protobuf::Field::MessageField) + expect(subject.field_type(::Test::Resource)).to eq(::Test::Resource) end end context 'when type is a base field class' do it 'returns that class' do - expect(subject.field_type(::Protobuf::Field::BoolField)).to eq(::Protobuf::Field::BoolField) + expect(subject.field_class(::Protobuf::Field::BoolField)).to eq(::Protobuf::Field::BoolField) end end context 'when type is a double field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::DoubleField + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:double)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:double)).to eq(expected_field) end @@ -37,6 +41,8 @@ context 'when type is a float field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::FloatField + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:float)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:float)).to eq(expected_field) end @@ -45,6 +51,8 @@ context 'when type is a int32 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Int32Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:int32)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:int32)).to eq(expected_field) end @@ -53,6 +61,8 @@ context 'when type is a int64 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Int64Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:int64)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:int64)).to eq(expected_field) end @@ -61,6 +71,8 @@ context 'when type is a uint32 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Uint32Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:uint32)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:uint32)).to eq(expected_field) end @@ -69,6 +81,8 @@ context 'when type is a uint64 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Uint64Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:uint64)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:uint64)).to eq(expected_field) end @@ -77,6 +91,8 @@ context 'when type is a sint32 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Sint32Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:sint32)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:sint32)).to eq(expected_field) end @@ -85,6 +101,8 @@ context 'when type is a sint64 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Sint64Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:sint64)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:sint64)).to eq(expected_field) end @@ -93,6 +111,8 @@ context 'when type is a fixed32 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Fixed32Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:fixed32)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:fixed32)).to eq(expected_field) end @@ -101,6 +121,8 @@ context 'when type is a fixed64 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Fixed64Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:fixed64)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:fixed64)).to eq(expected_field) end @@ -109,6 +131,8 @@ context 'when type is a sfixed32 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Sfixed32Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:sfixed32)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:sfixed32)).to eq(expected_field) end @@ -117,6 +141,8 @@ context 'when type is a sfixed64 field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::Sfixed64Field + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:sfixed64)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:sfixed64)).to eq(expected_field) end @@ -126,6 +152,8 @@ context 'when type is a string field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::StringField + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:string)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:string)).to eq(expected_field) end @@ -135,6 +163,8 @@ context 'when type is a bytes field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::BytesField + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:bytes)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:bytes)).to eq(expected_field) end @@ -144,6 +174,8 @@ context 'when type is a bool field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::BoolField + expect(subject.field_class(expected_field)).to eq(expected_field) + expect(subject.field_class(:bool)).to eq(expected_field) expect(subject.field_type(expected_field)).to eq(expected_field) expect(subject.field_type(:bool)).to eq(expected_field) end @@ -152,7 +184,7 @@ context 'when type is not mapped' do it 'raises an ArgumentError' do expect { - subject.field_type("boom") + subject.field_class("boom") }.to raise_error end end From 1a8bbd5c6620dfb75310c28279d2ae9a76c8e8e9 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Tue, 18 Feb 2014 16:39:35 -0700 Subject: [PATCH 0634/1191] Return RpcFailed instead of PbError when rescuing exceptions --- lib/protobuf/rpc/middleware/exception_handler.rb | 2 +- spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index 94dd94ed..010a1b8f 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -27,7 +27,7 @@ def call(env) # Wrap exceptions in a generic Protobuf errors unless they already are # def wrap_exception(exception) - exception = PbError.new(exception.message) unless exception.is_a?(PbError) + exception = RpcFailed.new(exception.message) unless exception.is_a?(PbError) exception end end diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index 3b8eb6e4..532164d6 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -43,7 +43,7 @@ context "when exception is not a Protobuf error" do let(:encoded_error) { error.encode } - let(:error) { Protobuf::Rpc::PbError.new('Boom!') } + let(:error) { Protobuf::Rpc::RpcFailed.new('Boom!') } before { app.stub(:call).and_raise(RuntimeError, 'Boom!') } From 237772ba9db0e9b8b7967b383ae7eab96edde51c Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Feb 2014 17:40:25 -0700 Subject: [PATCH 0635/1191] Field classes should use readers for all instance variable access --- lib/protobuf/field/base_field.rb | 61 ++++++++++++++++------------- lib/protobuf/field/bool_field.rb | 2 +- lib/protobuf/field/bytes_field.rb | 6 +-- lib/protobuf/field/enum_field.rb | 22 ++++++----- lib/protobuf/field/field_array.rb | 22 +++++------ lib/protobuf/field/message_field.rb | 14 ++++--- lib/protobuf/message/fields.rb | 16 ++++---- 7 files changed, 77 insertions(+), 66 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 41eed43a..9828cc12 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -4,9 +4,11 @@ module Protobuf module Field class BaseField + ## # Constants # + PACKED_TYPES = [ ::Protobuf::WireType::VARINT, ::Protobuf::WireType::FIXED32, @@ -16,12 +18,16 @@ class BaseField ## # Attributes # - attr_reader :default, :default_value, :getter_method_name, :message_class, - :name, :rule, :setter_method_name, :tag, :type + + attr_reader :default, :default_value, :deprecated, :extension, + :getter_method_name, :message_class, :name, :optional, + :packed, :repeated, :required, :rule, :setter_method_name, + :tag, :type_class ## # Class Methods # + def self.default nil end @@ -29,9 +35,10 @@ def self.default ## # Constructor # - def initialize(message_class, rule, type, name, tag, options) - @message_class, @rule, @type, @name, @tag = \ - message_class, rule, type, name, tag + + def initialize(message_class, rule, type_class, name, tag, options) + @message_class, @rule, @type_class, @name, @tag = \ + message_class, rule, type_class, name, tag set_rule_predicates @@ -51,6 +58,7 @@ def initialize(message_class, rule, type, name, tag, options) ## # Public Instance Methods # + def acceptable?(value) true end @@ -99,41 +107,41 @@ def encode(value) end def extension? - !! @extension + !! extension end # Is this a repeated field? def repeated? - !! @repeated + !! repeated end # Is this a required field? def required? - !! @required + !! required end # Is this a optional field? def optional? - !! @optional + !! optional end # Is this a deprecated field? def deprecated? - !! @deprecated + !! deprecated end # Is this a packed repeated field? def packed? - !! @packed + !! packed end def to_s - "#{@rule} #{@type} #{@name} = #{@tag} #{@default ? "[default=#{@default.inspect}]" : ''}" + "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end def warn_if_deprecated if ::Protobuf.print_deprecation_warnings? && deprecated? - $stderr.puts("[WARNING] #{@message_class.name}##{@name} field usage is deprecated.") + $stderr.puts("[WARNING] #{message_class.name}##{name} field usage is deprecated.") end end @@ -154,7 +162,7 @@ def define_accessor def define_array_getter field = self - @message_class.class_eval do + message_class.class_eval do define_method(field.getter_method_name) do field.warn_if_deprecated @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) @@ -164,7 +172,7 @@ def define_array_getter def define_array_setter field = self - @message_class.class_eval do + message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated @@ -172,12 +180,10 @@ def define_array_setter val = val.dup val.compact! else - error_text = <<-TYPE_ERROR - Expected repeated value of type '#{field.type}' + raise TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{field.type_class}' Got '#{val.class}' for repeated protobuf field #{field.name} TYPE_ERROR - - raise TypeError, error_text end if val.nil? || (val.respond_to?(:empty?) && val.empty?) @@ -192,7 +198,7 @@ def define_array_setter def define_getter field = self - @message_class.class_eval do + message_class.class_eval do define_method(field.getter_method_name) do field.warn_if_deprecated @values.fetch(field.name, field.default_value) @@ -202,7 +208,7 @@ def define_getter def define_setter field = self - @message_class.class_eval do + message_class.class_eval do define_method(field.setter_method_name) do |val| field.warn_if_deprecated @@ -211,7 +217,7 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = val else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type}" + raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end end @@ -226,7 +232,7 @@ def set_default_value end def set_rule_predicates - case @rule + case rule when :repeated then @required = @optional = false @repeated = true @@ -240,23 +246,24 @@ def set_rule_predicates end def typed_default_value - if @default.nil? + if default.nil? self.class.default else - @default + default end end def validate_packed_field if packed? && ! ::Protobuf::Field::BaseField::PACKED_TYPES.include?(wire_type) - raise "Can't use packed encoding for `#{@type}' type" + raise "Can't use packed encoding for '#{type_class}' type" end end def warn_excess_options(options) - warn "WARNING: Invalid options: #{options.inspect} (in #{@message_class.name.split('::').last}.#{@name})" + warn "WARNING: Invalid options: #{options.inspect} (in #{message_class.name}##{name})" end end end end + diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 8d16a112..3220ae69 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -19,7 +19,7 @@ def define_getter super field = self - @message_class.class_eval do + message_class.class_eval do define_method("#{field.getter_method_name}?") do field.warn_if_deprecated @values.fetch(field.name, field.default_value) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index e0803073..ba92a3ee 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -25,7 +25,7 @@ def decode(bytes) def define_setter field = self - @message_class.class_eval do + message_class.class_eval do define_method(field.setter_method_name) do |val| begin field.warn_if_deprecated @@ -35,12 +35,12 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = val.dup else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type}" + raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end rescue NoMethodError => ex ::Protobuf::Logger.error { ex.message } ::Protobuf::Logger.error { ex.backtrace.join("\n") } - raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type}: #{ex.message}" + raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" end end end diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 2a27c486..d1a80e1a 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -4,7 +4,7 @@ module Protobuf module Field class EnumField < VarintField def acceptable?(val) - ! @type.fetch(val).nil? + ! type_class.fetch(val).nil? end def encode(value) @@ -17,23 +17,16 @@ def enum? private - def typed_default_value - if @default.is_a?(Symbol) - @type.const_get(@default) - else - self.class.default - end - end def define_setter field = self - @message_class.class_eval do + message_class.class_eval do define_method("#{field.name}=") do |value| orig_value = value if value.nil? @values.delete(field.name) else - value = field.type.fetch(value) + value = field.type_class.fetch(value) raise TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value @values[field.name] = value @@ -41,6 +34,15 @@ def define_setter end end end + + def typed_default_value + if default.is_a?(Symbol) + type_class.const_get(default) + else + self.class.default + end + end + end end end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index cfb161c2..b00521a7 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -42,7 +42,7 @@ def to_hash_value end def to_s - "[#{@field.name}]" + "[#{field.name}]" end private @@ -52,25 +52,25 @@ def to_s # def normalize(value) value = value.to_proto if value.respond_to?(:to_proto) - raise TypeError, "Unacceptable value #{value} for field #{@field.name} of type #{@field.type}" unless @field.acceptable?(value) + raise TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) - if @field.is_a?(::Protobuf::Field::EnumField) - @field.type.fetch(value) - elsif @field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) - @field.type.new(value.to_hash) + if field.is_a?(::Protobuf::Field::EnumField) + field.type_class.fetch(value) + elsif field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) + field.type_class.new(value.to_hash) else value end end def raise_type_error(val) - error_text = <<-TYPE_ERROR - Expected repeated value of type '#{@field.type}' - Got '#{val.class}' for repeated protobuf field #{@field.name} + raise TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{field.type_class}' + Got '#{val.class}' for repeated protobuf field #{field.name} TYPE_ERROR - - raise TypeError, error_text end + end end end + diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index f5566864..272a5aa7 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,14 +9,15 @@ class MessageField < BaseField # def acceptable?(val) - unless val.instance_of?(type) || val.respond_to?(:to_hash) - raise TypeError, "Expected value of type '#{self.type}' for field #{self.name}, but got '#{val.class}'" + unless val.instance_of?(type_class) || val.respond_to?(:to_hash) + raise TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end + true end def decode(bytes) - type.decode(bytes) + type_class.decode(bytes) end def encode(value) @@ -37,18 +38,19 @@ def wire_type def define_setter field = self - @message_class.class_eval do + message_class.class_eval do define_method("#{field.name}=") do |val| case when val.nil? then @values.delete(field.name) - when val.is_a?(field.type) then + when val.is_a?(field.type_class) then @values[field.name] = val when val.respond_to?(:to_proto) then @values[field.name] = val.to_proto when val.respond_to?(:to_hash) then - @values[field.name] = field.type.new(val.to_hash) + @values[field.name] = field.type_class.new(val.to_hash) else + # FIXME I deleted this lambda from somehwere I don't remember where... RAISE_TYPE.call(field, val) end end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 15aa05d2..2e6afab8 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -18,20 +18,20 @@ def self.extended(other) # Define an optional field. # - def optional(type, name, tag, options = {}) - define_field(:optional, type, name, tag, options) + def optional(type_class, name, tag, options = {}) + define_field(:optional, type_class, name, tag, options) end # Define a repeated field. # - def repeated(type, name, tag, options = {}) - define_field(:repeated, type, name, tag, options) + def repeated(type_class, name, tag, options = {}) + define_field(:repeated, type_class, name, tag, options) end # Define a required field. # - def required(type, name, tag, options = {}) - define_field(:required, type, name, tag, options) + def required(type_class, name, tag, options = {}) + define_field(:required, type_class, name, tag, options) end # Define an extension range. @@ -89,11 +89,11 @@ def get_field(name_or_tag, allow_extension = false) end end - def define_field(rule, type, field_name, tag, options) + def define_field(rule, type_class, field_name, tag, options) raise_if_tag_collision(tag, field_name) raise_if_name_collision(field_name) - field = ::Protobuf::Field.build(self, rule, type, field_name, tag, options) + field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) field_store[field_name] = field field_store[tag] = field From 83aed9f818162e2545cd1d674aa9b39bb32e1f36 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Feb 2014 17:43:32 -0700 Subject: [PATCH 0636/1191] Alphabetize methods, add comment headers, add spaces around methods for readability --- lib/protobuf/field/base_field.rb | 1 + lib/protobuf/field/bool_field.rb | 24 ++++++++++-- lib/protobuf/field/bytes_field.rb | 45 ++++++++++++++++------ lib/protobuf/field/double_field.rb | 13 +++++-- lib/protobuf/field/enum_field.rb | 9 +++++ lib/protobuf/field/field_array.rb | 20 +++++++--- lib/protobuf/field/fixed32_field.rb | 14 +++++-- lib/protobuf/field/fixed64_field.rb | 13 +++++-- lib/protobuf/field/float_field.rb | 23 ++++++++--- lib/protobuf/field/int32_field.rb | 16 +++++++- lib/protobuf/field/int64_field.rb | 16 +++++++- lib/protobuf/field/integer_field.rb | 13 +++++-- lib/protobuf/field/message_field.rb | 6 +++ lib/protobuf/field/sfixed32_field.rb | 13 +++++-- lib/protobuf/field/sfixed64_field.rb | 19 +++++---- lib/protobuf/field/signed_integer_field.rb | 7 ++++ lib/protobuf/field/sint32_field.rb | 16 +++++++- lib/protobuf/field/sint64_field.rb | 16 +++++++- lib/protobuf/field/string_field.rb | 12 +++++- lib/protobuf/field/uint32_field.rb | 16 +++++++- lib/protobuf/field/uint64_field.rb | 16 +++++++- lib/protobuf/field/varint_field.rb | 8 ++++ 22 files changed, 274 insertions(+), 62 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 9828cc12..3dfeb624 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -150,6 +150,7 @@ def warn_if_deprecated ## # Private Instance Methods # + def define_accessor if repeated? define_array_getter diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 3220ae69..0827b17d 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -3,10 +3,20 @@ module Protobuf module Field class BoolField < VarintField + + ## + # Class Methods + # + def self.default false end + + ## + # Public Instance Methods + # # + def acceptable?(val) [true, false].include?(val) end @@ -15,6 +25,16 @@ def decode(value) value == 1 end + def encode(value) + [value ? 1 : 0].pack('C') + end + + private + + ## + # Private Instance Methods + # + def define_getter super @@ -27,9 +47,7 @@ def define_getter end end - def encode(value) - [value ? 1 : 0].pack('C') - end end end end + diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index ba92a3ee..e6561a7f 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -3,12 +3,25 @@ module Protobuf module Field class BytesField < BaseField + + ## + # Constants + # + BYTES_ENCODING = "ASCII-8BIT".freeze + ## + # Class Methods + # + def self.default '' end + ## + # Public Instance Methods + # + def acceptable?(val) if val.nil? || val.is_a?(::Protobuf::Message) || val.instance_of?(String) return true @@ -23,6 +36,25 @@ def decode(bytes) bytes_to_decode end + def encode(value) + value_to_encode = value.dup + value_to_encode = value.encode if value.is_a?(::Protobuf::Message) + value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + + string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) + string_size << value_to_encode + end + + def wire_type + ::Protobuf::WireType::LENGTH_DELIMITED + end + + private + + ## + # Private Instance Methods + # + def define_setter field = self message_class.class_eval do @@ -46,18 +78,7 @@ def define_setter end end - def encode(value) - value_to_encode = value.dup - value_to_encode = value.encode if value.is_a?(::Protobuf::Message) - value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - - string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) - string_size << value_to_encode - end - - def wire_type - ::Protobuf::WireType::LENGTH_DELIMITED - end end end end + diff --git a/lib/protobuf/field/double_field.rb b/lib/protobuf/field/double_field.rb index 28b8e395..b520fad1 100644 --- a/lib/protobuf/field/double_field.rb +++ b/lib/protobuf/field/double_field.rb @@ -3,9 +3,10 @@ module Protobuf module Field class DoubleField < FloatField - def wire_type - WireType::FIXED64 - end + + ## + # Public Instance Methods + # def decode(bytes) bytes.unpack('E').first @@ -14,6 +15,12 @@ def decode(bytes) def encode(value) [value].pack('E') end + + def wire_type + WireType::FIXED64 + end + end end end + diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index d1a80e1a..7322c21e 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -3,6 +3,11 @@ module Protobuf module Field class EnumField < VarintField + + ## + # Public Instance Methods + # + def acceptable?(val) ! type_class.fetch(val).nil? end @@ -17,6 +22,9 @@ def enum? private + ## + # Private Instance Methods + # def define_setter field = self @@ -46,3 +54,4 @@ def typed_default_value end end end + diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index b00521a7..afc2fef5 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -1,9 +1,17 @@ module Protobuf module Field class FieldArray < Array + + ## + # Attributes + # + + attr_reader :field + ## # Constructor # + def initialize(field) @field = field end @@ -11,6 +19,7 @@ def initialize(field) ## # Public Instance Methods # + def []=(nth, val) super(nth, normalize(val)) unless val.nil? end @@ -23,13 +32,9 @@ def push(val) super(normalize(val)) unless val.nil? end - def unshift(val) - super(normalize(val)) unless val.nil? - end - def replace(val) raise_type_error(val) unless val.is_a?(Array) - val = val.map! { |v| normalize(v) } + val.map! { |v| normalize(v) } super(val) end @@ -45,11 +50,16 @@ def to_s "[#{field.name}]" end + def unshift(val) + super(normalize(val)) unless val.nil? + end + private ## # Private Instance Methods # + def normalize(value) value = value.to_proto if value.respond_to?(:to_proto) raise TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) diff --git a/lib/protobuf/field/fixed32_field.rb b/lib/protobuf/field/fixed32_field.rb index 7311df82..4b07f3e4 100644 --- a/lib/protobuf/field/fixed32_field.rb +++ b/lib/protobuf/field/fixed32_field.rb @@ -1,11 +1,12 @@ -require 'protobuf/field/uint32_field.rb' +require 'protobuf/field/uint32_field' module Protobuf module Field class Fixed32Field < Uint32Field - def wire_type - ::Protobuf::WireType::FIXED32 - end + + ## + # Public Instance Methods + # def decode(bytes) bytes.unpack('V').first @@ -14,6 +15,11 @@ def decode(bytes) def encode(value) [value].pack('V') end + + def wire_type + ::Protobuf::WireType::FIXED32 + end + end end end diff --git a/lib/protobuf/field/fixed64_field.rb b/lib/protobuf/field/fixed64_field.rb index 7add6f2c..d47ad327 100644 --- a/lib/protobuf/field/fixed64_field.rb +++ b/lib/protobuf/field/fixed64_field.rb @@ -3,9 +3,10 @@ module Protobuf module Field class Fixed64Field < Uint64Field - def wire_type - ::Protobuf::WireType::FIXED64 - end + + ## + # Public Instance Methods + # def decode(bytes) # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. @@ -17,6 +18,12 @@ def encode(value) # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. [value & 0xffff_ffff, value >> 32].pack('VV') end + + def wire_type + ::Protobuf::WireType::FIXED64 + end + end end end + diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 71bd6c33..0480486b 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -3,10 +3,21 @@ module Protobuf module Field class FloatField < BaseField - def self.default; 0.0; end - def wire_type - WireType::FIXED32 + ## + # Class Methods + # + + def self.default + 0.0 + end + + ## + # Public Instance Methods + # + + def acceptable?(val) + val.respond_to?(:to_f) end def decode(bytes) @@ -17,9 +28,11 @@ def encode(value) [value].pack('e') end - def acceptable?(val) - val.respond_to?(:to_f) + def wire_type + WireType::FIXED32 end + end end end + diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb index 147e11b8..2c7dd6fd 100644 --- a/lib/protobuf/field/int32_field.rb +++ b/lib/protobuf/field/int32_field.rb @@ -3,10 +3,22 @@ module Protobuf module Field class Int32Field < IntegerField - def self.max; INT32_MAX; end - def self.min; INT32_MIN; end def max; INT32_MAX; end def min; INT32_MIN; end + + ## + # Class Methods + # + + def self.max + INT32_MAX + end + + def self.min + INT32_MIN + end + end end end + diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb index 669397d4..eeddee0b 100644 --- a/lib/protobuf/field/int64_field.rb +++ b/lib/protobuf/field/int64_field.rb @@ -3,10 +3,22 @@ module Protobuf module Field class Int64Field < IntegerField - def self.max; INT64_MAX; end - def self.min; INT64_MIN; end def max; INT64_MAX; end def min; INT64_MIN; end + + ## + # Class Methods + # + + def self.max + INT64_MAX + end + + def self.min + INT64_MIN + end + end end end + diff --git a/lib/protobuf/field/integer_field.rb b/lib/protobuf/field/integer_field.rb index b05e8866..49435f32 100644 --- a/lib/protobuf/field/integer_field.rb +++ b/lib/protobuf/field/integer_field.rb @@ -4,16 +4,21 @@ module Protobuf module Field class IntegerField < VarintField - def encode(value) - # original Google's library uses 64bits integer for negative value - VarintField.encode(value & 0xffff_ffff_ffff_ffff) - end + ## + # Public Instance Methods + # def decode(value) value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? value end + def encode(value) + # original Google's library uses 64bits integer for negative value + ::Protobuf::Field::VarintField.encode(value & 0xffff_ffff_ffff_ffff) + end + end end end + diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 272a5aa7..d0269b21 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -36,6 +36,10 @@ def wire_type private + ## + # Private Instance Methods + # + def define_setter field = self message_class.class_eval do @@ -56,6 +60,8 @@ def define_setter end end end + end end end + diff --git a/lib/protobuf/field/sfixed32_field.rb b/lib/protobuf/field/sfixed32_field.rb index 82c483a1..242a1850 100644 --- a/lib/protobuf/field/sfixed32_field.rb +++ b/lib/protobuf/field/sfixed32_field.rb @@ -3,9 +3,10 @@ module Protobuf module Field class Sfixed32Field < Int32Field - def wire_type - ::Protobuf::WireType::FIXED32 - end + + ## + # Public Instance Methods + # def decode(bytes) value = bytes.unpack('V').first @@ -16,6 +17,12 @@ def decode(bytes) def encode(value) [value].pack('V') end + + def wire_type + ::Protobuf::WireType::FIXED32 + end + end end end + diff --git a/lib/protobuf/field/sfixed64_field.rb b/lib/protobuf/field/sfixed64_field.rb index 99ad1430..f639cedd 100644 --- a/lib/protobuf/field/sfixed64_field.rb +++ b/lib/protobuf/field/sfixed64_field.rb @@ -3,22 +3,27 @@ module Protobuf module Field class Sfixed64Field < Int64Field - def wire_type - ::Protobuf::WireType::FIXED64 - end + + ## + # Public Instance Methods + # def decode(bytes) - # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. - values = bytes.unpack('VV') + values = bytes.unpack('VV') # 'Q' is machine-dependent, don't use value = values[0] + (values[1] << 32) value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? value end def encode(value) - # we don't use 'Q' for pack/unpack. 'Q' is machine-dependent. - [value & 0xffff_ffff, value >> 32].pack('VV') + [value & 0xffff_ffff, value >> 32].pack('VV') # 'Q' is machine-dependent, don't use + end + + def wire_type + ::Protobuf::WireType::FIXED64 end + end end end + diff --git a/lib/protobuf/field/signed_integer_field.rb b/lib/protobuf/field/signed_integer_field.rb index 1410213e..821db3bf 100644 --- a/lib/protobuf/field/signed_integer_field.rb +++ b/lib/protobuf/field/signed_integer_field.rb @@ -3,6 +3,11 @@ module Protobuf module Field class SignedIntegerField < VarintField + + ## + # Public Instance Methods + # + def decode(value) if (value & 1).zero? value >> 1 # positive value @@ -18,6 +23,8 @@ def encode(value) VarintField.encode(~(value << 1)) end end + end end end + diff --git a/lib/protobuf/field/sint32_field.rb b/lib/protobuf/field/sint32_field.rb index 4d71f244..96a5a6e8 100644 --- a/lib/protobuf/field/sint32_field.rb +++ b/lib/protobuf/field/sint32_field.rb @@ -3,10 +3,22 @@ module Protobuf module Field class Sint32Field < SignedIntegerField - def self.max; INT32_MAX; end - def self.min; INT32_MIN; end def max; INT32_MAX; end def min; INT32_MIN; end + + ## + # Class Methods + # + + def self.max + INT32_MAX + end + + def self.min + INT32_MIN + end + end end end + diff --git a/lib/protobuf/field/sint64_field.rb b/lib/protobuf/field/sint64_field.rb index 6b256eb2..7ec65485 100644 --- a/lib/protobuf/field/sint64_field.rb +++ b/lib/protobuf/field/sint64_field.rb @@ -3,10 +3,22 @@ module Protobuf module Field class Sint64Field < SignedIntegerField - def self.max; INT64_MAX; end - def self.min; INT64_MIN; end def max; INT64_MAX; end def min; INT64_MIN; end + + ## + # Class Methods + # + + def self.max + INT64_MAX + end + + def self.min + INT64_MIN + end + end end end + diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index ba6de481..7861e128 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -3,15 +3,23 @@ module Protobuf module Field class StringField < BytesField + + ## + # Constants + # + ENCODING = 'UTF-8'.freeze + ## + # Public Instance Methods + # + def decode(bytes) bytes_to_decode = bytes.dup bytes_to_decode.force_encoding(::Protobuf::Field::StringField::ENCODING) bytes_to_decode end - # TODO: make replace character configurable? def encode(value) value_to_encode = value.dup value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") @@ -20,6 +28,8 @@ def encode(value) string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) string_size << value_to_encode end + end end end + diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb index 39af71c3..e222a4f9 100644 --- a/lib/protobuf/field/uint32_field.rb +++ b/lib/protobuf/field/uint32_field.rb @@ -3,10 +3,22 @@ module Protobuf module Field class Uint32Field < VarintField - def self.max; UINT32_MAX; end - def self.min; 0; end def max; UINT32_MAX; end def min; 0; end + + ## + # Class Methods + # + + def self.max + UINT32_MAX + end + + def self.min + 0 + end + end end end + diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb index 051b2ffc..6ab9ab78 100644 --- a/lib/protobuf/field/uint64_field.rb +++ b/lib/protobuf/field/uint64_field.rb @@ -3,10 +3,22 @@ module Protobuf module Field class Uint64Field < VarintField - def self.max; UINT64_MAX; end - def self.min; 0; end def max; UINT64_MAX; end def min; 0; end + + ## + # Class Methods + # + + def self.max + UINT64_MAX + end + + def self.min + 0 + end + end end end + diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 7eba8d20..5da9f4ae 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -3,6 +3,11 @@ module Protobuf module Field class VarintField < BaseField + + ## + # Constants + # + INT32_MAX = 2**31 - 1 INT32_MIN = -2**31 INT64_MAX = 2**63 - 1 @@ -13,6 +18,7 @@ class VarintField < BaseField ## # Class Methods # + def self.default 0 end @@ -37,6 +43,7 @@ def self.encode(value) ## # Public Instance Methods # + def acceptable?(val) (val > min || val < max) rescue false end @@ -64,3 +71,4 @@ def wire_type end end end + From 992eb051c954d60c67a7d1051c156ddd6df640a1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Feb 2014 17:44:17 -0700 Subject: [PATCH 0637/1191] Get rid of instance level min/max methods on fields, acess the class-level methods from VarintField#acceptable? --- lib/protobuf/field/int32_field.rb | 2 -- lib/protobuf/field/int64_field.rb | 2 -- lib/protobuf/field/sint32_field.rb | 2 -- lib/protobuf/field/sint64_field.rb | 2 -- lib/protobuf/field/uint32_field.rb | 2 -- lib/protobuf/field/uint64_field.rb | 2 -- lib/protobuf/field/varint_field.rb | 4 +++- 7 files changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb index 2c7dd6fd..a95b75a8 100644 --- a/lib/protobuf/field/int32_field.rb +++ b/lib/protobuf/field/int32_field.rb @@ -3,8 +3,6 @@ module Protobuf module Field class Int32Field < IntegerField - def max; INT32_MAX; end - def min; INT32_MIN; end ## # Class Methods diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb index eeddee0b..b0080819 100644 --- a/lib/protobuf/field/int64_field.rb +++ b/lib/protobuf/field/int64_field.rb @@ -3,8 +3,6 @@ module Protobuf module Field class Int64Field < IntegerField - def max; INT64_MAX; end - def min; INT64_MIN; end ## # Class Methods diff --git a/lib/protobuf/field/sint32_field.rb b/lib/protobuf/field/sint32_field.rb index 96a5a6e8..95784c85 100644 --- a/lib/protobuf/field/sint32_field.rb +++ b/lib/protobuf/field/sint32_field.rb @@ -3,8 +3,6 @@ module Protobuf module Field class Sint32Field < SignedIntegerField - def max; INT32_MAX; end - def min; INT32_MIN; end ## # Class Methods diff --git a/lib/protobuf/field/sint64_field.rb b/lib/protobuf/field/sint64_field.rb index 7ec65485..a6d0056d 100644 --- a/lib/protobuf/field/sint64_field.rb +++ b/lib/protobuf/field/sint64_field.rb @@ -3,8 +3,6 @@ module Protobuf module Field class Sint64Field < SignedIntegerField - def max; INT64_MAX; end - def min; INT64_MIN; end ## # Class Methods diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb index e222a4f9..6b60b898 100644 --- a/lib/protobuf/field/uint32_field.rb +++ b/lib/protobuf/field/uint32_field.rb @@ -3,8 +3,6 @@ module Protobuf module Field class Uint32Field < VarintField - def max; UINT32_MAX; end - def min; 0; end ## # Class Methods diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb index 6ab9ab78..eafbda32 100644 --- a/lib/protobuf/field/uint64_field.rb +++ b/lib/protobuf/field/uint64_field.rb @@ -3,8 +3,6 @@ module Protobuf module Field class Uint64Field < VarintField - def max; UINT64_MAX; end - def min; 0; end ## # Class Methods diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 5da9f4ae..c46a3d0a 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -45,7 +45,9 @@ def self.encode(value) # def acceptable?(val) - (val > min || val < max) rescue false + (val > self.class.min || val < self.class.max) + rescue + false end def decode(value) From 290ed98bd658cd85f12edba03c55b46c1f3f0665 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Feb 2014 17:45:32 -0700 Subject: [PATCH 0638/1191] Remove unused VarintField.decode method (handled by Decoder) --- lib/protobuf/field/varint_field.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index c46a3d0a..35c68bab 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -23,14 +23,6 @@ def self.default 0 end - def self.decode(bytes) - value = 0 - bytes.each_with_index do |byte, index| - value |= byte << (7 * index) - end - value - end - def self.encode(value) bytes = [] until value < 128 From d30bd7fc4ebaf1f20b79e552fa35bfd9a8b936c2 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Feb 2014 17:45:51 -0700 Subject: [PATCH 0639/1191] Don't pass stream inside Encoder to write_pair, it's an instance variable --- lib/protobuf/encoder.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index d455ecde..202c672f 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -30,7 +30,7 @@ def encode_field(field, value) if field.repeated? encode_repeated_field(field, value) else - write_pair(stream, field, value) + write_pair(field, value) end end @@ -46,12 +46,12 @@ def encode_repeated_field(field, value) if field.packed? encode_packed_field(field, value) else - value.each { |val| write_pair(stream, field, val) } + value.each { |val| write_pair(field, val) } end end # Encode key and value, and write to +stream+. - def write_pair(stream, field, value) + def write_pair(field, value) key = (field.tag << 3) | field.wire_type stream << ::Protobuf::Field::VarintField.encode(key) stream << field.encode(value) From c78ca385b582f4ba6abf039ab39166e4180afa13 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 18 Feb 2014 17:50:15 -0700 Subject: [PATCH 0640/1191] Add back `BaseField#type` method with a deprecation warning --- lib/protobuf/field/base_field.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 3dfeb624..635e243d 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -139,6 +139,11 @@ def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end + def type + $stderr.puts("[DEPRECATED] #{self.class.name}#type usage is deprecated.\nPlease use #type_class instead.") + type_class + end + def warn_if_deprecated if ::Protobuf.print_deprecation_warnings? && deprecated? $stderr.puts("[WARNING] #{message_class.name}##{name} field usage is deprecated.") From a9085c0860a2d65772f95ff9ce787410f364f08b Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 10:18:42 -0700 Subject: [PATCH 0641/1191] Add Changelog info for all major 3.0.0.rc1 changes --- CHANGES.md | 84 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4166018f..bca32aca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,16 +1,72 @@ -Unreleased (3.x) ---------- - -- Add support for enum aliases. [#134, @localshred] -- Clean up the Enum class API with several methods deprecated. See #134 for more comprehensive -documentation about which methods are going and away and which are being renamed. [#134, @localshred] -- Remove previously deprecated `bin/rprotoc` executable. [13fbdb9] -- Remove previously deprecated `Service#rpc` method. [f391294] +# Unstable --------- +3.0.0.rc1 +--------- -Stable --------- +A lot has changed leading up to the release of 3.0. For all the relevant changes, +see the closed [pull requests and issues list in github](https://github.com/localshred/protobuf/issues?milestone=1&state=closed). +Below is a high-level list of fixes, deprecations, breaking changes, and new APIs. + +The server/dispatcher stack has been converted to the Middleware pattern! +Exception handling (#162, #164), Request decoding (#160, #166), Response encoding (#161, #167), +Logging and stats (#163), and Method dispatch (#159) have all been extracted into their +own Middlewares to greatly simplify testing and further development of the server +stack, furthering our preparations for removing the socket implementations (zmq, socket) +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). + +#### Bug Fixes + +- Resolve DNS names (e.g. localhost) when using ZMQ server. [#46, reported by @reddshack] +- Switched to hash based value storage for messages to fix large field tag memory issues. [#118, #165] +- Add `Protobuf::Deprecator` module to alias deprecated methods. [#165] +- `Enum.fetch` used to return an enum of any type if that is the value passed in. [#168] + +#### Deprecations + +__!! These deprecated methods will be removed in v3.1. !!__ + +- Deprecated `BaseField#type` in favor of `#type_class`. +- Deprecated `Message.get_ext_field_by_name` in favor of `.get_extension_field` or `.get_field(name_or_tag, true)`. +- Deprecated `Message.get_ext_field_by_tag,` in favor of `.get_extension_field` or `.get_field(name_or_tag, true)`. +- Deprecated `Message.get_field_by_name,` in favor of `.get_field`. +- Deprecated `Message.get_field_by_tag,` in favor of `.get_field`. +- Deprecated `Enum.enum_by_value` in favor of `.enum_for_tag`. +- Deprecated `Enum.name_by_value` in favor of `.name_for_tag`. +- Deprecated `Enum.get_name_by_tag` in favor of `.name_for_tag`. +- Deprecated `Enum.value_by_name` in favor of `.enum_for_name`. +- Deprecated `Enum.values` in favor of `.enums`. Beware that `.enums` returns an array where `.values` returns a hash. + 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`. + +#### Breaking Changes + +- Cleaned up the `Enum` class, deprecating/renaming most methods. tl;dr, just use `MyEnum.fetch`. + See #134 for more comprehensive documentation about which methods are going and away and which are being renamed. [#134] +- Pulled `EnumValue` into `Enum`. The `EnumValue` class no longer exists. Use `Enum` for type-checking instead. [#168]. +- Removed previously deprecated `bin/rprotoc` executable. Use `protoc --ruby_out=...` instead. [13fbdb9] +- Removed previously deprecated `Service#rpc` method. Use `Service#method_name` instead. [f391294] +- Removed `lib/protobuf/message/message.rb`. Use `lib/protobuf/message.rb` instead. +- Removed field getters from Message instances (e.g. `Message#get_field_by_name`). + Use class-level getters instead (see Deprecations section). +- Moved `lib/protobuf/message/decoder.rb` to `lib/protobuf/decoder.rb`. The module is still named `Protobuf::Decoder`. +- Removed `Protobuf::Field::ExtensionFields` class. +- Removed instance-level `max` and `min` methods from all relevant Field classes (e.g. Int32Field, Uint64Field, etc). + Use class-level methods of the same names instead. [#176, 992eb051] +- `PbError#to_response` no longer receives an argument, instead returning a new `Socketrpc::Response` object. [#147, @liveh2o] +- The Server module has been stripped of almost all methods, now simply invokes the Middleware stack for each request. [#159, @liveh2o] + +#### New APIs + +- Added support for [enum `allow_alias` option](https://developers.google.com/protocol-buffers/docs/proto#enum). [#134] +- `Enum.all_tags` returns an array of unique tags. Use it to replace `Enum.values.values.map(&:to_i)` (`Enum.values` is deprecated). +- `Enum.enums` returns an array of all defined enums for that class (including any aliased Enums). +- Reinstated support for symbol primitive field types in generated Message code. [#170] +- `Message.get_field` accepts a second boolean parameter (default false) to return an extension field if found. [#169] +- Mirror existing `Decoder#decode_from(stream)` with `Encoder#encode_to(stream)`. [#169] +- `Server` now invokes the [middleware stack](https://github.com/localshred/protobuf/tree/master/lib/protobuf/rpc/middleware) for request handling. [#159, @liveh2o] +- 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] + + +# Stable (2.x) 2.8.12 --------- @@ -28,14 +84,14 @@ Stable 2.8.10 --------- -- Allow passing a file extension to compile/clean rake tasks. [#143, @localshred] +- Allow passing a file extension to compile/clean rake tasks. [#143] 2.8.9 --------- - Deprecated Protobuf::Lifecycle module in favor of using ActiveSupport::Notifications. [#139, @devin-c] -- 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] -- Add protobuf:clean and protobuf:compile rake tasks for use in external libraries to compile source definitions to a destination. [#142, @localshred] +- 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] +- Add protobuf:clean and protobuf:compile rake tasks for use in external libraries to compile source definitions to a destination. [#142] 2.8.8 --------- From d8bb34ff5439483967ec4b19ba61f549e71217de Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 19 Feb 2014 10:30:08 -0700 Subject: [PATCH 0642/1191] Require Active Support 3.2+ Since this is a major version bump, and Rails is about to release v4.1, we should be able to safely require Active Support 3.2+. This eliminates all branching for versions less than 2.0. --- lib/protobuf.rb | 12 ++---------- protobuf.gemspec | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 20253933..913e6601 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -2,18 +2,10 @@ require 'socket' require 'pp' require 'stringio' + require 'active_support/core_ext/object/blank' -require 'active_support/version' +require 'active_support/core_ext/object/try' require 'active_support/notifications' - -if ActiveSupport::VERSION::MAJOR > 2 - require 'active_support/core_ext/object/try' -else - require 'active_support/core_ext/module/delegation' - require 'active_support/core_ext/kernel/reporting' - require 'active_support/core_ext/try' -end - require 'active_support/inflector' require 'active_support/json' diff --git a/protobuf.gemspec b/protobuf.gemspec index cfd8b65d..40bb70cb 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -19,7 +19,7 @@ require "protobuf/version" s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'activesupport', '>= 2' + s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'middleware' s.add_dependency 'multi_json' s.add_dependency 'thor' From 6638af045505d733a9ae56eda497db8e08758b64 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 10:37:07 -0700 Subject: [PATCH 0643/1191] Reinstate raise TypeError in message field setter --- lib/protobuf/field/message_field.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index d0269b21..447455e4 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -54,8 +54,7 @@ def define_setter when val.respond_to?(:to_hash) then @values[field.name] = field.type_class.new(val.to_hash) else - # FIXME I deleted this lambda from somehwere I don't remember where... - RAISE_TYPE.call(field, val) + raise TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" end end end From 24bbc062079d19382d6291ebdc2c835736e658ae Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 10:38:09 -0700 Subject: [PATCH 0644/1191] Minor corrects in the 3.0 changelog --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bca32aca..be7317c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,7 +18,6 @@ into their own gems in version 4.0. Major props to @liveh2o for [tackling this b - Resolve DNS names (e.g. localhost) when using ZMQ server. [#46, reported by @reddshack] - Switched to hash based value storage for messages to fix large field tag memory issues. [#118, #165] -- Add `Protobuf::Deprecator` module to alias deprecated methods. [#165] - `Enum.fetch` used to return an enum of any type if that is the value passed in. [#168] #### Deprecations @@ -43,7 +42,7 @@ __!! These deprecated methods will be removed in v3.1. !!__ See #134 for more comprehensive documentation about which methods are going and away and which are being renamed. [#134] - Pulled `EnumValue` into `Enum`. The `EnumValue` class no longer exists. Use `Enum` for type-checking instead. [#168]. - Removed previously deprecated `bin/rprotoc` executable. Use `protoc --ruby_out=...` instead. [13fbdb9] -- Removed previously deprecated `Service#rpc` method. Use `Service#method_name` instead. [f391294] +- Removed previously deprecated `Service#rpc` method. Use `Service#env#method_name` instead. [f391294] - Removed `lib/protobuf/message/message.rb`. Use `lib/protobuf/message.rb` instead. - Removed field getters from Message instances (e.g. `Message#get_field_by_name`). Use class-level getters instead (see Deprecations section). @@ -64,6 +63,7 @@ __!! These deprecated methods will be removed in v3.1. !!__ - Mirror existing `Decoder#decode_from(stream)` with `Encoder#encode_to(stream)`. [#169] - `Server` now invokes the [middleware stack](https://github.com/localshred/protobuf/tree/master/lib/protobuf/rpc/middleware) for request handling. [#159, @liveh2o] - 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] +- Add `Protobuf::Deprecator` module to alias deprecated methods. [#165] # Stable (2.x) From df46e389f7913c50ca3e522deea17639dbd73702 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 10:42:36 -0700 Subject: [PATCH 0645/1191] Remove PROTOC_VERSION constant --- CHANGES.md | 1 + lib/protobuf/cli.rb | 2 +- lib/protobuf/version.rb | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index be7317c4..e32f0223 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -52,6 +52,7 @@ __!! These deprecated methods will be removed in v3.1. !!__ Use class-level methods of the same names instead. [#176, 992eb051] - `PbError#to_response` no longer receives an argument, instead returning a new `Socketrpc::Response` object. [#147, @liveh2o] - The Server module has been stripped of almost all methods, now simply invokes the Middleware stack for each request. [#159, @liveh2o] +- Removed `Protobuf::PROTOC_VERSION` constant now that the compiler supports any protoc version. #### New APIs diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index fce93871..01f92af8 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -57,7 +57,7 @@ def start(app_file) desc 'version', 'Print ruby and protoc versions and exit.' def version - say("Ruby Protobuf v#{::Protobuf::VERSION}, protoc v#{::Protobuf::PROTOC_VERSION}") + say("Ruby Protobuf v#{::Protobuf::VERSION}") end no_tasks do diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9517dec5..31275e83 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,4 +1,3 @@ module Protobuf VERSION = '3.0.0.alpha' - PROTOC_VERSION = '2.5.0' end From 059b76ffb73181bc63f9792c9681b58946bb3f75 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 10:52:17 -0700 Subject: [PATCH 0646/1191] Add Adam to authors list --- protobuf.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index cfd8b65d..5887d737 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -8,8 +8,8 @@ require "protobuf/version" s.date = ::Time.now.strftime('%Y-%m-%d') s.license = 'WTFPL' - s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen'] - s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com'] + s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen', 'Adam Hutchison'] + s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com', 'liveh2o@gmail.com'] s.homepage = 'https://github.com/localshred/protobuf' s.summary = "Google Protocol Buffers serialization and RPC implementation for Ruby." s.description = s.summary From b75e1839432135adaf0fa786b6260fb34f4a355b Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 10:52:37 -0700 Subject: [PATCH 0647/1191] Reference the demise of EventMachine in Changelog --- CHANGES.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e32f0223..f099f663 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,16 @@ A lot has changed leading up to the release of 3.0. For all the relevant changes see the closed [pull requests and issues list in github](https://github.com/localshred/protobuf/issues?milestone=1&state=closed). Below is a high-level list of fixes, deprecations, breaking changes, and new APIs. +### EventMachine is dead, Long live EventMachine + +The EventMachine client and server have been removed from this gem. They code was far +too error prone and flawed to feasibly support going forward. It's recommended +to switch to the socket implementation (using `PB_CLIENT_TYPE` and `PB_SERVER_TYPE` of `socket`) +for a painless switchover. The ZMQ implementation is much more performant but +does have a dependency on libzmq. + +### Server Middlewares + The server/dispatcher stack has been converted to the Middleware pattern! Exception handling (#162, #164), Request decoding (#160, #166), Response encoding (#161, #167), Logging and stats (#163), and Method dispatch (#159) have all been extracted into their @@ -22,7 +32,7 @@ into their own gems in version 4.0. Major props to @liveh2o for [tackling this b #### Deprecations -__!! These deprecated methods will be removed in v3.1. !!__ +__!! NOTE: These deprecated methods will be removed in v3.1. !!__ - Deprecated `BaseField#type` in favor of `#type_class`. - Deprecated `Message.get_ext_field_by_name` in favor of `.get_extension_field` or `.get_field(name_or_tag, true)`. @@ -38,6 +48,7 @@ __!! These deprecated methods will be removed in v3.1. !!__ #### Breaking Changes +- All files/classes relating to the EventMachine client and server are gone. Use `PB_CLIENT_TYPE` and `PB_SERVER_TYPE` of `socket` instead. [#116] - Cleaned up the `Enum` class, deprecating/renaming most methods. tl;dr, just use `MyEnum.fetch`. See #134 for more comprehensive documentation about which methods are going and away and which are being renamed. [#134] - Pulled `EnumValue` into `Enum`. The `EnumValue` class no longer exists. Use `Enum` for type-checking instead. [#168]. From 1ddd2d276bc2f047153663c5a31fb9c8f89d117b Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 19 Feb 2014 11:16:56 -0700 Subject: [PATCH 0648/1191] Remove client_host attr_reader --- lib/protobuf/rpc/service.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 1dae0c9b..12efbc10 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -16,7 +16,7 @@ class Service DEFAULT_HOST = '127.0.0.1'.freeze DEFAULT_PORT = 9399 - attr_reader :client_host, :env, :request + attr_reader :env, :request ## # Constructor! @@ -26,7 +26,6 @@ class Service def initialize(env) @env = env.dup # Dup the env so it doesn't change out from under us @request = env.request - @client_host = env.caller end ## From 7130cb97d672546b78e280017c363c2f5752886e Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 19 Feb 2014 11:22:49 -0700 Subject: [PATCH 0649/1191] Rename Env#caller to Env#client_host --- lib/protobuf/rpc/env.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 2 +- lib/protobuf/rpc/middleware/request_decoder.rb | 2 +- spec/lib/protobuf/rpc/middleware/logger_spec.rb | 2 +- .../protobuf/rpc/middleware/request_decoder_spec.rb | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index e3cc1b37..2f648e74 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -34,7 +34,7 @@ def #{name}? # TODO: Add extra info about the environment (i.e. variables) and other # information that might be useful - hash_accessor :caller, + hash_accessor :client_host, :encoded_request, :encoded_response, :log_signature, diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index a0086c07..93dd17b1 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -58,7 +58,7 @@ def to_s(env) [ "[SRV]", - env.caller, + env.client_host, env.worker_id, rpc, sizes, diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 80191dc1..fa74ad5d 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -16,7 +16,7 @@ def call(env) env.service_name = service_name env.method_name = method_name env.request = request - env.caller = request_wrapper.caller + env.client_host = request_wrapper.caller env.rpc_service = service env.rpc_method = rpc_method diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index 5f583db5..210a9986 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -4,7 +4,7 @@ let(:app) { Proc.new { |env| env } } let(:env) { Protobuf::Rpc::Env.new( - 'caller' => 'caller.test.co', + 'client_host' => 'client_host.test.co', 'encoded_request' => request_wrapper.encode, 'encoded_response' => response_wrapper.encode, 'method_name' => method_name, diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 78b240ba..0572ace2 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -2,7 +2,7 @@ describe Protobuf::Rpc::Middleware::RequestDecoder do let(:app) { Proc.new { |env| env } } - let(:caller) { 'caller.test.co' } + let(:client_host) { 'client_host.test.co' } let(:env) { Protobuf::Rpc::Env.new( 'encoded_request' => encoded_request, @@ -15,7 +15,7 @@ let(:request_type) { rpc_method.request_type } let(:request_wrapper) { Protobuf::Socketrpc::Request.new( - :caller => caller, + :caller => client_host, :service_name => service_name, :method_name => method_name.to_s, :request_proto => request @@ -39,9 +39,9 @@ subject.call(env) end - it "sets Env#caller" do + it "sets Env#client_host" do stack_env = subject.call(env) - stack_env.caller.should eq caller + stack_env.client_host.should eq client_host end it "sets Env#service_name" do @@ -85,7 +85,7 @@ context "when the RPC service is not defined" do let(:request_wrapper) { Protobuf::Socketrpc::Request.new( - :caller => caller, + :caller => client_host, :service_name => 'Foo', :method_name => method_name.to_s, :request_proto => request @@ -100,7 +100,7 @@ context "when RPC method is not defined" do let(:request_wrapper) { Protobuf::Socketrpc::Request.new( - :caller => caller, + :caller => client_host, :service_name => service_name, :method_name => 'foo', :request_proto => request From bfcaa3da68a496d37f01e33576985db7e5796706 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 19 Feb 2014 11:23:04 -0700 Subject: [PATCH 0650/1191] Update the changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f099f663..e8d52f35 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -54,6 +54,8 @@ __!! NOTE: These deprecated methods will be removed in v3.1. !!__ - Pulled `EnumValue` into `Enum`. The `EnumValue` class no longer exists. Use `Enum` for type-checking instead. [#168]. - Removed previously deprecated `bin/rprotoc` executable. Use `protoc --ruby_out=...` instead. [13fbdb9] - Removed previously deprecated `Service#rpc` method. Use `Service#env#method_name` instead. [f391294] +- Changed the `Service#initialize` to take an `Env` object instead of separate request, method, and client parameters. [6c61bf72] +- Removed attribute readers for `Service#method_name` and `Service#client_host`. Use `Service#env` to get them instead. - Removed `lib/protobuf/message/message.rb`. Use `lib/protobuf/message.rb` instead. - Removed field getters from Message instances (e.g. `Message#get_field_by_name`). Use class-level getters instead (see Deprecations section). From 40c32cb66ed3a52cbe82995385079fd119bef6c1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 11:32:45 -0700 Subject: [PATCH 0651/1191] Bump version 3.0.0.rc1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 31275e83..f459210a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.0.alpha' + VERSION = '3.0.0.rc1' end From add87d031b2ac7f210c0656cd46ddad78abd4256 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 19 Feb 2014 11:34:37 -0700 Subject: [PATCH 0652/1191] Add note about AS 3.2 to the Changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index e8d52f35..f8c2636a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -48,6 +48,7 @@ __!! NOTE: These deprecated methods will be removed in v3.1. !!__ #### Breaking Changes +- Require Active Support 3.2+. [#177] - All files/classes relating to the EventMachine client and server are gone. Use `PB_CLIENT_TYPE` and `PB_SERVER_TYPE` of `socket` instead. [#116] - Cleaned up the `Enum` class, deprecating/renaming most methods. tl;dr, just use `MyEnum.fetch`. See #134 for more comprehensive documentation about which methods are going and away and which are being renamed. [#134] From 962a9f3a43badb214f627dc0602613ce4cf13813 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 13:20:54 -0700 Subject: [PATCH 0653/1191] Add back utf-8 encoding to google unittest proto --- spec/support/test/google_unittest.pb.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/test/google_unittest.pb.rb index eedebd32..c53c564b 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/test/google_unittest.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # From 50db6a64ea12a7c980acc775bedd5106cb1da70f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 13:21:44 -0700 Subject: [PATCH 0654/1191] Don't build 1.9.2 in travis (actvesupport doesn't support it). Also only run specs against lib, not functional --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9bf46467..b060aae3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,5 @@ language: ruby rvm: - - "1.9.2" - "1.9.3" - "2.0.0" -script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec -before_install: - - sudo apt-get install -qq libzmq3-dev +script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib From 4cd19a03c3e279f650f662b8a10f009b24e5f941 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 19 Feb 2014 14:10:28 -0700 Subject: [PATCH 0655/1191] Add gitter webhook to travis config --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index b060aae3..33c3265f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,10 @@ rvm: - "1.9.3" - "2.0.0" script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib +notifications: + webhooks: + urls: + - https://webhooks.gitter.im/e/51a956bcd2b1854d6756 + on_success: change # options: [always|never|change] default: always + on_failure: always # options: [always|never|change] default: always + on_start: false # default: false From 1b7ab6efa1a5f1d998cd9189157115b48abd5faa Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 22 Feb 2014 15:59:07 -0700 Subject: [PATCH 0656/1191] check if workers are avail in zmq client/server --- lib/protobuf/rpc/connectors/base.rb | 24 +++++++++++++--------- lib/protobuf/rpc/connectors/zmq.rb | 28 +++++++++++++++++++------- lib/protobuf/rpc/servers/zmq/broker.rb | 11 ++++++++-- lib/protobuf/rpc/servers/zmq/util.rb | 3 +++ 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 9b78ec25..f20382a6 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -10,15 +10,16 @@ module Protobuf module Rpc module Connectors DEFAULT_OPTIONS = { - :service => nil, # Fully-qualified Service class - :method => nil, # Service method to invoke - :host => '127.0.0.1', # The hostname or address of the service (usually overridden or pre-configured) - :port => '9399', # The port of the service (usually overridden or pre-configured) - :request => nil, # The request object sent by the client - :request_type => nil, # The request type expected by the client - :response_type => nil, # The response type expected by the client - :timeout => 300, # The default timeout for the request, also handled by client.rb - :client_host => nil # The hostname or address of this client + :service => nil, # Fully-qualified Service class + :method => nil, # Service method to invoke + :host => '127.0.0.1', # The hostname or address of the service (usually overridden) + :port => '9399', # The port of the service (usually overridden or pre-configured) + :request => nil, # The request object sent by the client + :request_type => nil, # The request type expected by the client + :response_type => nil, # The response type expected by the client + :timeout => 300, # The default timeout for the request, also handled by client.rb + :client_host => nil, # The hostname or address of this client + :check_workers_available => false, # Do we want to use check_avail frames before request } class Base @@ -31,6 +32,11 @@ def initialize(options) @options = DEFAULT_OPTIONS.merge(options) end + def check_workers_available? + ENV.has_key?("PB_CHECK_WORKERS_AVAILABLE") && + ENV['PB_CHECK_WORKERS_AVAILABLE'] != "false" + end + def send_request raise 'If you inherit a Connector from Base you must implement send_request' end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index fa25c4a8..6076e2b7 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -64,14 +64,28 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - server_uri = lookup_server_uri + socket = nil - socket = zmq_context.socket(::ZMQ::REQ) - socket.setsockopt(::ZMQ::LINGER, 0) + begin + server_uri = lookup_server_uri + + socket = zmq_context.socket(::ZMQ::REQ) + socket.setsockopt(::ZMQ::LINGER, 0) + + log_debug { sign_message("Establishing connection: #{server_uri}") } + zmq_error_check(socket.connect(server_uri), :socket_connect) + log_debug { sign_message("Connection established to #{server_uri}") } - log_debug { sign_message("Establishing connection: #{server_uri}") } - zmq_error_check(socket.connect(server_uri), :socket_connect) - log_debug { sign_message("Connection established to #{server_uri}") } + if check_workers_available? + check_available_response = "" + zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_error_check(socket.close, :socket_close) + end + end + end while socket.try(:socket).nil? socket end @@ -98,7 +112,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep 1 + sleep(1.0/20.0) # not sure why sleeping at all, but should be way less than 1 second end raise "Host not found for service #{service}" diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 34ed5c1e..3d91ef15 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -86,8 +86,15 @@ def process_backend end def process_frontend - if @idle_workers.any? - frames = read_from_frontend + frames = read_from_frontend + + if frames == [::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE] + if @idle_workers.any? + write_to_frontend([::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) + else + write_to_frontend([::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) + end + else write_to_backend([@idle_workers.shift, ""] + frames) end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 1cef47d8..b2dea22b 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -6,6 +6,9 @@ module Zmq ADDRESS_MATCH = /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/.freeze WORKER_READY_MESSAGE = "\1" + CHECK_AVAILABLE_MESSAGE = "CHECK_AVAILABLE" + NO_WORKERS_AVAILABLE = "NO_WORKERS_AVAILABLE" + WORKERS_AVAILABLE = "WORKERS_AVAILABLE" module Util include ::Protobuf::Logger::LogMethods From 83d754b40f4b176a0a043341b0bf05bcb53db403 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 22 Feb 2014 16:00:30 -0700 Subject: [PATCH 0657/1191] set uri lookup to 1/50 second --- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 6076e2b7..bc6a0252 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -101,7 +101,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 5.times do + 15.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -112,7 +112,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep(1.0/20.0) # not sure why sleeping at all, but should be way less than 1 second + sleep(1.0/50.0) # not sure why sleeping at all, but should be way less than 1 second end raise "Host not found for service #{service}" From ca9331b04efe1c17857c62650be77307ca269e51 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 23 Feb 2014 17:38:27 -0700 Subject: [PATCH 0658/1191] make val a string if we assign a symbol to a string field --- lib/protobuf/field/bytes_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index e6561a7f..6c87f878 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -61,6 +61,7 @@ def define_setter define_method(field.setter_method_name) do |val| begin field.warn_if_deprecated + val = "#{val}" if val.is_a?(Symbol) if val.nil? @values.delete(field.name) From 62f0318483ba76b7c75ab322559e0e74a11818b6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 23 Feb 2014 21:59:19 -0700 Subject: [PATCH 0659/1191] make sure the address frame is sent back to the router --- lib/protobuf/rpc/servers/zmq/broker.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 3d91ef15..b1f1dfab 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -86,16 +86,16 @@ def process_backend end def process_frontend - frames = read_from_frontend + address, _, message, *frames = read_from_frontend - if frames == [::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE] + if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE if @idle_workers.any? - write_to_frontend([::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) + write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else - write_to_frontend([::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) + write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) end else - write_to_backend([@idle_workers.shift, ""] + frames) + write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) end end From bf8e938bac037aaa9eb6509f8ff83efa85d26637 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Feb 2014 09:39:37 -0700 Subject: [PATCH 0660/1191] change to single byte message payloads for the protocol and call the feature "first alive load balancing" check all servers every 1/10th of second 50 times before failing out on requesting --- lib/protobuf/rpc/connectors/base.rb | 8 ++++---- lib/protobuf/rpc/connectors/zmq.rb | 6 +++--- lib/protobuf/rpc/servers/zmq/util.rb | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index f20382a6..d846d974 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -19,7 +19,7 @@ module Connectors :response_type => nil, # The response type expected by the client :timeout => 300, # The default timeout for the request, also handled by client.rb :client_host => nil, # The hostname or address of this client - :check_workers_available => false, # Do we want to use check_avail frames before request + :first_alive_load_balance => false, # Do we want to use check_avail frames before request } class Base @@ -32,9 +32,9 @@ def initialize(options) @options = DEFAULT_OPTIONS.merge(options) end - def check_workers_available? - ENV.has_key?("PB_CHECK_WORKERS_AVAILABLE") && - ENV['PB_CHECK_WORKERS_AVAILABLE'] != "false" + def first_alive_load_balance? + ENV.has_key?("PB_FIRST_ALIVE_LOAD_BALANCE") || + options[:first_alive_load_balance] end def send_request diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index bc6a0252..b8121a11 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -76,7 +76,7 @@ def create_socket zmq_error_check(socket.connect(server_uri), :socket_connect) log_debug { sign_message("Connection established to #{server_uri}") } - if check_workers_available? + if first_alive_load_balance? check_available_response = "" zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) @@ -101,7 +101,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 15.times do + 50.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -112,7 +112,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep(1.0/50.0) # not sure why sleeping at all, but should be way less than 1 second + sleep(1.0/10.0) # not sure why sleeping at all, but should be way less than 1 second end raise "Host not found for service #{service}" diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index b2dea22b..3d95ce0f 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -6,9 +6,9 @@ module Zmq ADDRESS_MATCH = /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/.freeze WORKER_READY_MESSAGE = "\1" - CHECK_AVAILABLE_MESSAGE = "CHECK_AVAILABLE" - NO_WORKERS_AVAILABLE = "NO_WORKERS_AVAILABLE" - WORKERS_AVAILABLE = "WORKERS_AVAILABLE" + CHECK_AVAILABLE_MESSAGE = "\3" + NO_WORKERS_AVAILABLE = "\4" + WORKERS_AVAILABLE = "\5" module Util include ::Protobuf::Logger::LogMethods From 146e5efd53ace25b042ce0d94118d89f9d540aa3 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Mon, 24 Feb 2014 10:32:32 -0700 Subject: [PATCH 0661/1191] Add repeated_message? predicate to BaseField --- lib/protobuf/field/base_field.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 635e243d..cb8bb9bb 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -115,6 +115,11 @@ def repeated? !! repeated end + # Is this a repeated message field? + def repeated_message? + repeated? && message? + end + # Is this a required field? def required? !! required From b2bffba56f3db2b5d02b2d34807bd7fca4531c30 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Feb 2014 10:57:19 -0700 Subject: [PATCH 0662/1191] make acceptable line up with encode rules --- lib/protobuf/field/bytes_field.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 6c87f878..7505d6e5 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -23,11 +23,7 @@ def self.default # def acceptable?(val) - if val.nil? || val.is_a?(::Protobuf::Message) || val.instance_of?(String) - return true - else - raise TypeError, "Cannot set field : #{name} to value : #{val}" - end + val.nil? || val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(::Protobuf::Message) end def decode(bytes) From 616d24a3f7aedae0c3424e45487be1e7847b674f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 24 Feb 2014 19:36:12 -0700 Subject: [PATCH 0663/1191] Bump version 2.0.0.rc2 --- CHANGES.md | 11 +++++++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f8c2636a..03f25b56 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,16 @@ # Unstable +3.0.0.rc2 +--------- + +Please read the [rc1 section below](#300rc1) for the greater changeset. + +- Add support for assigning a symbol to a string or bytes field. [#181, @abrandoned] +- Add `first_alive_load_balance` option to rpc server. Pass `PB_FIRST_ALIVE_LOAD_BALANCE` + as an env variable to the client process to ensure the client asks the server + if it is alive (able to server requests to clients). [#183, @abrandoned] + + 3.0.0.rc1 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f459210a..fbf2f45d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.0.rc1' + VERSION = '3.0.0.rc2' end From 621116c3dae2c8b0a05e2bc3b6f1d247f7a23d2d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 25 Feb 2014 16:31:45 -0700 Subject: [PATCH 0664/1191] Fix block shadowed var in logger middleware spec --- spec/lib/protobuf/rpc/middleware/logger_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index 210a9986..8220d416 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::Logger do - let(:app) { Proc.new { |env| env } } + let(:app) { Proc.new { |inner_env| inner_env } } let(:env) { Protobuf::Rpc::Env.new( 'client_host' => 'client_host.test.co', From d7674c738a21b50f07d66d2c8940451d0bedbbcf Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 25 Feb 2014 16:32:04 -0700 Subject: [PATCH 0665/1191] Make sure protobuf message's have required the full library --- lib/protobuf/message.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 7febfcb7..ab1417ad 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,3 +1,4 @@ +require 'protobuf' require 'protobuf/field' require 'protobuf/enum' require 'protobuf/exceptions' From eb890ccd1a7c751f5ad90051961d98b85d0a46bf Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 25 Feb 2014 17:17:36 -0700 Subject: [PATCH 0666/1191] Revert "Make sure protobuf message's have required the full library" This reverts commit d7674c738a21b50f07d66d2c8940451d0bedbbcf. --- lib/protobuf/message.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index ab1417ad..7febfcb7 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,4 +1,3 @@ -require 'protobuf' require 'protobuf/field' require 'protobuf/enum' require 'protobuf/exceptions' From 1cda5939d92b111ffc3cb5e12d16bb9a3ea436b5 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 26 Feb 2014 10:45:42 -0700 Subject: [PATCH 0667/1191] Bump version 3.0.0 --- CHANGES.md | 24 +++++++----------------- lib/protobuf/version.rb | 2 +- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 03f25b56..af6f6136 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,20 +1,9 @@ -# Unstable +# Stable (3.x) -3.0.0.rc2 +3.0.0 --------- -Please read the [rc1 section below](#300rc1) for the greater changeset. - -- Add support for assigning a symbol to a string or bytes field. [#181, @abrandoned] -- Add `first_alive_load_balance` option to rpc server. Pass `PB_FIRST_ALIVE_LOAD_BALANCE` - as an env variable to the client process to ensure the client asks the server - if it is alive (able to server requests to clients). [#183, @abrandoned] - - -3.0.0.rc1 ---------- - -A lot has changed leading up to the release of 3.0. For all the relevant changes, +A lot has changed since the last stable v2.8.12. For all the relevant changes, see the closed [pull requests and issues list in github](https://github.com/localshred/protobuf/issues?milestone=1&state=closed). Below is a high-level list of fixes, deprecations, breaking changes, and new APIs. @@ -90,9 +79,10 @@ __!! NOTE: These deprecated methods will be removed in v3.1. !!__ - `Server` now invokes the [middleware stack](https://github.com/localshred/protobuf/tree/master/lib/protobuf/rpc/middleware) for request handling. [#159, @liveh2o] - 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] - Add `Protobuf::Deprecator` module to alias deprecated methods. [#165] - - -# Stable (2.x) +- Add support for assigning a symbol to a string or bytes field. [#181, @abrandoned] +- Add `first_alive_load_balance` option to rpc server. Pass `PB_FIRST_ALIVE_LOAD_BALANCE` + as an env variable to the client process to ensure the client asks the server + if it is alive (able to server requests to clients). [#183, @abrandoned] 2.8.12 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index fbf2f45d..6c14737d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.0.rc2' + VERSION = '3.0.0' end From 885070a6c6e2b76601b7d494c39d26586eb53130 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 26 Feb 2014 15:50:45 -0700 Subject: [PATCH 0668/1191] instance level class access was removed, ask class for name instead of instance --- lib/protobuf/message.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 7febfcb7..cf909ef0 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -65,7 +65,7 @@ def each_field_for_serialization value = @values[field.name] if value.nil? - raise ::Protobuf::SerializationError, "Required field #{self.name}##{field.name} does not have a value." + raise ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." else yield(field, value) end From 8f8648296292d8a9f6d93ca99a791ebacaa998a2 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 26 Feb 2014 16:16:51 -0700 Subject: [PATCH 0669/1191] Ensure required fields raise the correct error during encoding when not assigned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spec existed to catch this issue, unfortunately it didn’t fail because the message we were testing against had a field named “name”, thus calling `self.name` in the raise string didn’t fail, it just returns nil (since the name value wasn’t set). The fix then is to create a message type with a required field named something other than `name`. --- spec/lib/protobuf/message_spec.rb | 2 +- spec/support/test/resource.pb.rb | 5 +++++ spec/support/test/resource.proto | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index bfe208b8..e5d0090b 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -128,7 +128,7 @@ end context "when there's no value for a required field" do - let(:message) { ::Test::Resource.new } + let(:message) { ::Test::ResourceWithRequiredField.new } it "raises a 'message not initialized' error" do expect { diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index e580a312..4e9b8523 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -23,6 +23,7 @@ class StatusType < ::Protobuf::Enum class ResourceFindRequest < ::Protobuf::Message; end class ResourceSleepRequest < ::Protobuf::Message; end class Resource < ::Protobuf::Message; end + class ResourceWithRequiredField < ::Protobuf::Message; end class Searchable < ::Protobuf::Message class SearchType < ::Protobuf::Enum define :FLAT, 1 @@ -71,6 +72,10 @@ class Resource optional :bool, :ext_dup_field, 106, :extension => true end + class ResourceWithRequiredField + required :string, :foo_is_required, 1 + end + class MessageParent class MessageChild optional :string, :child1, 1 diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index d97602f4..5e58c833 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -27,6 +27,10 @@ message Resource { repeated StatusType repeated_enum = 4; } +message ResourceWithRequiredField { + required string foo_is_required = 1; +} + message Searchable { enum SearchType { FLAT = 1; From 5b41a45856961bcd5bb829bb61c3a9c970b2b0f8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 26 Feb 2014 16:34:47 -0700 Subject: [PATCH 0670/1191] Bump version 3.0.1 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index af6f6136..09669618 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # Stable (3.x) +3.0.1 +--------- + +- Fix NoMethodError that can occur when serializing a message with a missing required field. [#187, @abrandoned] + 3.0.0 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6c14737d..f415d1ac 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.0' + VERSION = '3.0.1' end From 0d23541f2a364c085d0193df35ce501b836d3325 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 4 Mar 2014 14:05:02 -0700 Subject: [PATCH 0671/1191] requests can be "lost" because [].shift is nil this means that when all workers are busy they can lose a request that comes in when it tries to shift off a worker this PR adds a local queue that will queue that request until a worker is available to work that queue --- lib/protobuf/rpc/servers/zmq/broker.rb | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index b1f1dfab..f05307ca 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -1,13 +1,18 @@ +require 'thread' + module Protobuf module Rpc module Zmq class Broker include ::Protobuf::Rpc::Zmq::Util + attr_reader :local_queue + def initialize(server) @server = server init_zmq_context + init_local_queue init_backend_socket init_frontend_socket init_poller @@ -29,6 +34,10 @@ def run break if rc == -1 @poller.readables.each do |readable| + unless local_queue.empty? + process_local_queue + end + case readable when @frontend_socket process_frontend @@ -57,6 +66,10 @@ def init_frontend_socket zmq_error_check(@frontend_socket.bind(@server.frontend_uri)) end + def init_local_queue + @local_queue = ::Queue.new + end + def init_poller @poller = ZMQ::Poller.new @poller.register_readable(@frontend_socket) @@ -89,16 +102,28 @@ def process_frontend address, _, message, *frames = read_from_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE - if @idle_workers.any? + if @idle_workers.any? || local_queue.empty? write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) end else - write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) + if @idle_workers.any? + write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) + else + local_queue.push([address, "", message ] + frames) + end end end + def process_local_queue + return if local_queue.empty? + return if @idle_workers.empty? + + write_to_backend([@idle_workers.shift, ""] + local_queue.pop) + process_local_queue + end + def read_from_backend frames = [] zmq_error_check(@backend_socket.recv_strings(frames)) From f32a9c111b9210dfce0c556fdba695076e487205 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 4 Mar 2014 14:18:55 -0700 Subject: [PATCH 0672/1191] move process local before poll call --- lib/protobuf/rpc/servers/zmq/broker.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index f05307ca..9b77aa5c 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -25,6 +25,10 @@ def run @idle_workers = [] loop do + unless local_queue.empty? + process_local_queue + end + rc = @poller.poll(500) # The server was shutdown and no requests are pending @@ -34,10 +38,6 @@ def run break if rc == -1 @poller.readables.each do |readable| - unless local_queue.empty? - process_local_queue - end - case readable when @frontend_socket process_frontend From e87a656f37f942fe13a1d2c2c3b599f0465875b1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 4 Mar 2014 14:22:27 -0700 Subject: [PATCH 0673/1191] Bump version 3.0.2 --- CHANGES.md | 6 ++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 09669618..07e9d2a7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Stable (3.x) +3.0.2 +--------- + +- Queue requests at the broker when concurrent requests hit the ZMQ server, distribute to + worker threads on each turn of the read poll loop. [#189, @abrandoned, @liveh2o] + 3.0.1 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f415d1ac..959b1577 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.1' + VERSION = '3.0.2' end From 974f36197c5d51dc85950f026e578bfe4c844e62 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Mar 2014 10:50:05 -0600 Subject: [PATCH 0674/1191] Message.to_json returns the name of the class This fixes a long-standing bug caused by circular references in the way the Field system is implemented. The spec wraps the call to to_json in a timeout because the recursive checks are unbounded and will eat memory and cpu forever. The simplest solution is to simply return the name of the message when asked for the json representation at the class level. --- lib/protobuf/message.rb | 9 +++++++++ spec/lib/protobuf/message_spec.rb | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index cf909ef0..71caf733 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -14,9 +14,18 @@ class Message extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization + ## + # Class Methods + # + + def self.to_json + name + end + ## # Constructor # + def initialize(fields = {}) @values = {} diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e5d0090b..b9f4b2f8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -289,6 +289,16 @@ its(:to_json) { should eq '{"name":"Test Name","active":false}' } end + describe '.to_json' do + it 'returns the class name of the message for use in json encoding' do + expect { + ::Timeout.timeout(0.1) do + expect(::Test::Resource.to_json).to eq("Test::Resource") + end + }.not_to raise_error + end + end + describe "#define_setter" do subject { ::Test::Resource.new } From cc69c75ff9cfbefcb3a62050c0864866fd63a269 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Mar 2014 11:27:25 -0600 Subject: [PATCH 0675/1191] Bump version 3.0.3 --- CHANGES.md | 5 +++++ lib/protobuf/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 07e9d2a7..dbbb313e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # Stable (3.x) +3.0.3 +--------- + +- Fix recursive memory/cpu growth issue when calling class-level `Message.to_json`. [#190] + 3.0.2 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 959b1577..11b9d75a 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.2' + VERSION = '3.0.3' end From 9017e0cde57349185d08539a99b5b995984ee8f1 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 13 Mar 2014 12:02:36 -0600 Subject: [PATCH 0676/1191] Add changelog notes for backport 2.8.13 --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index dbbb313e..b298a021 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -100,6 +100,11 @@ __!! NOTE: These deprecated methods will be removed in v3.1. !!__ as an env variable to the client process to ensure the client asks the server if it is alive (able to server requests to clients). [#183, @abrandoned] +2.8.13 +--------- + +- Backport #190 to 2.8 stable series. [#192] + 2.8.12 --------- From 5ab03ff291d5ee1f04c8ee140404e1f44c1115df Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Mar 2014 15:04:45 -0600 Subject: [PATCH 0677/1191] Only rescue specific no method errors in the dispatcher In the service dispatcher, we're rescuing NoMethodError and returning an RPC MethodNotFound error assuming that the method has been defined, but not implmented. This is the correct behavior, but the implementation catches all NoMethodError exceptions that are raised, which masks real issues unrelated to the RPC method not being implemented. Instead, only re-wrap NoMethodError exceptions if the message contains the RPC method. Raise the original error if it doesn't. --- lib/protobuf/rpc/service_dispatcher.rb | 8 ++++++-- spec/lib/protobuf/rpc/service_dispatcher_spec.rb | 15 +++++++++++++-- spec/support/test/resource.pb.rb | 1 + spec/support/test/resource.proto | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index b3727252..2ce97588 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -28,8 +28,12 @@ def rpc_service def dispatch_rpc_request rpc_service.callable_rpc_method(method_name).call rpc_service.response - rescue NoMethodError - raise MethodNotFound.new("#{service_name}##{method_name} is not implemented.") + rescue NoMethodError => e + if e.message =~ /#{method_name}/ + raise MethodNotFound.new("#{service_name}##{method_name} is not implemented.") + end + + raise end def method_name diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index c6087e19..82616c82 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -6,13 +6,17 @@ let(:env) { Protobuf::Rpc::Env.new( 'method_name' => method_name, + 'request' => request, 'rpc_service' => service_class, 'service_name' => service_name, ) } let(:method_name) { :find } + let(:request) { request_type.new(:name => 'required') } + let(:request_type) { service_class.rpcs[method_name].request_type } let(:response) { response_type.new(:name => 'required') } let(:response_type) { service_class.rpcs[method_name].response_type } + let(:rpc_service) { service_class.new(env) } let(:service_class) { Test::ResourceService } let(:service_name) { service_class.to_s } @@ -22,7 +26,6 @@ before { subject.stub(:rpc_service).and_return(rpc_service) } describe '#call' do - before { rpc_service.stub(:callable_rpc_method).and_return(lambda {}) } before { rpc_service.stub(:response).and_return(response) } it "dispatches the request" do @@ -31,11 +34,19 @@ end context "when the given RPC method is not implemented" do - before { rpc_service.stub(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } + let(:method_name) { :find_not_implemented } it "raises a method not found exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) end end + + context "when the given RPC method is implemented and a NoMethodError is raised" do + before { rpc_service.stub(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } + + it "raises the exeception" do + expect { subject.call(env) }.to raise_exception(NoMethodError) + end + end end end diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 4e9b8523..0605bacc 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -110,6 +110,7 @@ class ResourceService < ::Protobuf::Rpc::Service rpc :find, ::Test::ResourceFindRequest, ::Test::Resource rpc :find_with_rpc_failed, ::Test::ResourceFindRequest, ::Test::Resource rpc :find_with_sleep, ::Test::ResourceSleepRequest, ::Test::Resource + rpc :find_not_implemented, ::Test::ResourceFindRequest, ::Test::Resource end end diff --git a/spec/support/test/resource.proto b/spec/support/test/resource.proto index 5e58c833..bf89859f 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/test/resource.proto @@ -90,4 +90,5 @@ service ResourceService { rpc Find (ResourceFindRequest) returns (Resource); rpc FindWithRpcFailed (ResourceFindRequest) returns (Resource); rpc FindWithSleep (ResourceSleepRequest) returns (Resource); + rpc FindNotImplemented (ResourceFindRequest) returns (Resource); } From ceb5673c50c51eeca50b085c8f07e0ada8c6c2c6 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 13 Mar 2014 19:31:07 -0600 Subject: [PATCH 0678/1191] Check if the service responds to the given method Instead of catching all NoMethodErrors and checking the message for the method name (which is brittle), simply check to see if the service responds to the method. If it's not a publicly defined instance method, raise an RPC MethodNotFound error. --- lib/protobuf/rpc/service_dispatcher.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 2ce97588..469af8e7 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -26,14 +26,12 @@ def rpc_service # Call the given service method. def dispatch_rpc_request - rpc_service.callable_rpc_method(method_name).call - rpc_service.response - rescue NoMethodError => e - if e.message =~ /#{method_name}/ - raise MethodNotFound.new("#{service_name}##{method_name} is not implemented.") + unless rpc_service.respond_to?(method_name) + raise MethodNotFound.new("#{service_name}##{method_name} is not a publicly defined method.") end - raise + rpc_service.callable_rpc_method(method_name).call + rpc_service.response end def method_name From 3e87a6c17a7b96804b79d9d81a8b0ce0d223c60d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 14 Mar 2014 08:57:31 -0600 Subject: [PATCH 0679/1191] Bump version 3.0.4 --- CHANGES.md | 7 +++++++ lib/protobuf/version.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b298a021..ad027618 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # Stable (3.x) +3.0.4 +-------- + +- Raise specific MethodNotFound when service class doesn't respond to (publicly implement) + the rpc method called from the client. Stop rescuing all NoMethodError's thrown + by service implementations. [#193, @liveh2o] + 3.0.3 --------- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 11b9d75a..36c544a6 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.3' + VERSION = '3.0.4' end From 851b4289c44c26cf635dccfbaee1748a268b8d9d Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 5 Jun 2014 11:44:26 -0700 Subject: [PATCH 0680/1191] Update float fields to cast strings more strongly --- lib/protobuf/field/float_field.rb | 21 ++++++++ spec/lib/protobuf/field/float_field_spec.rb | 55 +++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 spec/lib/protobuf/field/float_field_spec.rb diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 0480486b..5a335250 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -32,6 +32,27 @@ def wire_type WireType::FIXED32 end + ## + # Private Instance Methods + # + + def define_setter + field = self + message_class.class_eval do + define_method(field.setter_method_name) do |val| + field.warn_if_deprecated + + if val.nil? || (val.respond_to?(:empty?) && val.empty?) + @values.delete(field.name) + elsif field.acceptable?(val) + @values[field.name] = Float(val) + else + raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" + end + end + end + end + end end end diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb new file mode 100644 index 00000000..835885c0 --- /dev/null +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Protobuf::Field::FloatField do + + class SomeFloatMessage < ::Protobuf::Message + optional :float, :some_float, 1 + end + + let(:instance) { SomeFloatMessage.new } + + describe '#define_setter' do + subject { instance.some_float = value; instance.some_float } + + context 'when set with an int' do + let(:value) { 100 } + + it 'is readable as a float' do + expect(subject).to eq(100.0) + end + end + + context 'when set with a float' do + let(:value) { 100.1 } + + it 'is readable as a float' do + expect(subject).to eq(100.1) + end + end + + context 'when set with a string of a float' do + let(:value) { "101.1" } + + it 'is readable as a float' do + expect(subject).to eq(101.1) + end + end + + context 'when set with a non-numeric string' do + let(:value) { "aaaa" } + + it 'throws an error' do + expect { subject }.to raise_error(ArgumentError) + end + end + + context 'when set with something that is not a float' do + let(:value) { [ 1, 2, 3 ] } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + end + +end From 5ea34151acb541938afd7472086949917a8e0ace Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Fri, 6 Jun 2014 15:15:25 -0700 Subject: [PATCH 0681/1191] Add a coerce! method to share code with superclass --- lib/protobuf/field/base_field.rb | 6 +++++- lib/protobuf/field/float_field.rb | 25 ++++--------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index cb8bb9bb..739e1aaa 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -63,6 +63,10 @@ def acceptable?(value) true end + def coerce!(value) + value + end + def enum? false end @@ -226,7 +230,7 @@ def define_setter if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) - @values[field.name] = val + @values[field.name] = field.coerce!(val) else raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 5a335250..4d138972 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -20,6 +20,10 @@ def acceptable?(val) val.respond_to?(:to_f) end + def coerce!(val) + Float(val) + end + def decode(bytes) bytes.unpack('e').first end @@ -32,27 +36,6 @@ def wire_type WireType::FIXED32 end - ## - # Private Instance Methods - # - - def define_setter - field = self - message_class.class_eval do - define_method(field.setter_method_name) do |val| - field.warn_if_deprecated - - if val.nil? || (val.respond_to?(:empty?) && val.empty?) - @values.delete(field.name) - elsif field.acceptable?(val) - @values[field.name] = Float(val) - else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" - end - end - end - end - end end end From 59dfbb7ed12a8f181585a52a3db39f13967f9064 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Jun 2014 10:01:56 -0600 Subject: [PATCH 0682/1191] Update rspec 2.x syntax to 3.x to remove deprecations --- protobuf.gemspec | 2 +- spec/encoding/all_types_spec.rb | 2 +- spec/encoding/extreme_values_spec.rb | Bin 1352 -> 1357 bytes spec/functional/socket_server_spec.rb | 9 +- spec/functional/zmq_server_spec.rb | 14 +-- spec/lib/protobuf/cli_spec.rb | 78 ++++++++-------- spec/lib/protobuf/code_generator_spec.rb | 8 +- spec/lib/protobuf/enum_spec.rb | 46 +++++----- spec/lib/protobuf/field/string_field_spec.rb | 8 +- spec/lib/protobuf/generators/base_spec.rb | 11 +-- .../generators/enum_generator_spec.rb | 6 +- .../generators/extension_generator_spec.rb | 8 +- .../generators/field_generator_spec.rb | 22 ++--- .../generators/file_generator_spec.rb | 6 +- .../generators/service_generator_spec.rb | 4 +- spec/lib/protobuf/lifecycle_spec.rb | 32 +++---- spec/lib/protobuf/logger_spec.rb | 54 +++++------ spec/lib/protobuf/message_spec.rb | 84 +++++++++--------- spec/lib/protobuf/optionable_spec.rb | 2 +- spec/lib/protobuf/rpc/client_spec.rb | 26 +++--- spec/lib/protobuf/rpc/connector_spec.rb | 8 +- spec/lib/protobuf/rpc/connectors/base_spec.rb | 14 +-- .../protobuf/rpc/connectors/common_spec.rb | 64 +++++++------ .../protobuf/rpc/connectors/socket_spec.rb | 16 ++-- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 59 +++++------- .../rpc/middleware/exception_handler_spec.rb | 16 ++-- .../protobuf/rpc/middleware/logger_spec.rb | 4 +- .../rpc/middleware/request_decoder_spec.rb | 20 ++--- .../rpc/middleware/response_encoder_spec.rb | 12 +-- .../rpc/servers/socket_server_spec.rb | 6 +- .../protobuf/rpc/servers/zmq/server_spec.rb | 6 +- .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 4 +- .../protobuf/rpc/servers/zmq/worker_spec.rb | 10 +-- .../protobuf/rpc/service_directory_spec.rb | 53 ++++++----- .../protobuf/rpc/service_dispatcher_spec.rb | 8 +- spec/lib/protobuf/rpc/service_filters_spec.rb | 78 ++++++++-------- spec/lib/protobuf/rpc/service_spec.rb | 54 +++++------ spec/lib/protobuf/rpc/stat_spec.rb | 8 +- spec/lib/protobuf_spec.rb | 14 +-- spec/spec_helper.rb | 1 + spec/support/packed_field.rb | 2 +- 41 files changed, 432 insertions(+), 447 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index 026f0d06..da98eee5 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -27,7 +27,7 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' - s.add_development_dependency 'rspec' + s.add_development_dependency 'rspec', '>= 3.0' s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' s.add_development_dependency 'timecop' diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 3f278cbf..c202215a 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -86,6 +86,6 @@ file.read end - data.should eq message.serialize_to_string + expect(data).to eq(message.serialize_to_string) end end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 8f8c0b9d9328f9b024258fb5c398afa3ea9071c3..65f1c910a25e433add419fb72f73bcd988187706 100644 GIT binary patch delta 66 zcmX@Xb(U*`FsoH+ML}wEiAG9dNus7+NxnjAp+;_MadBdLs$OwwQD$OJW>so@Nq&5B TNl|8Ax+a%`LTX+L7YG9YBBB>p delta 61 zcmX@hb%JYyFso@wVo9Q2aYlY=PKrWmp+atIadBdLs$OwwQD$OJW>so@Nq&5BNl|8A OI+ub%YF-K#2m=7QQ5Ew5 diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 2af158d1..ffeecc7b 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -21,8 +21,8 @@ client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) + expect(succ.name).to eq("Test Name") + expect(succ.status).to eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -41,7 +41,8 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /name.*required/ + + expect(error.message).to match(/name.*required/) end it 'calls the on_failure callback when the request type is wrong' do @@ -53,7 +54,7 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i + expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 543835ce..053eb383 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -27,8 +27,8 @@ client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) + expect(succ.name).to eq("Test Name") + expect(succ.status).to eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -46,8 +46,8 @@ client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) + expect(succ.name).to eq("Test Name") + expect(succ.status).to eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -69,7 +69,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure {|e| error = e } end - error.message.should match(/name.*required/) + expect(error.message).to match(/name.*required/) end end @@ -83,7 +83,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure {|e| error = e} end - error.message.should match(/expected request.*ResourceFindRequest.*Resource instead/i) + expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end end @@ -96,7 +96,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure { |e| error = e } end - error.message.should match(/The server repeatedly failed to respond/) + expect(error.message).to match(/The server repeatedly failed to respond/) end end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 91fdef44..c33dba9a 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -9,19 +9,19 @@ let(:sock_runner) { runner = double("SocketRunner", :register_signals => nil) - runner.stub(:run) { ::ActiveSupport::Notifications.publish( "after_server_bind" ) } + allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner } let(:zmq_runner) { runner = double "ZmqRunner", register_signals: nil - runner.stub(:run) { ::ActiveSupport::Notifications.publish( "after_server_bind" ) } + allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner } before(:each) do - ::Protobuf::Rpc::SocketRunner.stub(:new) { sock_runner } - ::Protobuf::Rpc::ZmqRunner.stub(:new) { zmq_runner } + allow(::Protobuf::Rpc::SocketRunner).to receive(:new).and_return(sock_runner) + allow(::Protobuf::Rpc::ZmqRunner).to receive(:new).and_return(zmq_runner) end describe '#start' do @@ -33,8 +33,8 @@ let(:test_args) { [ '--host=123.123.123.123' ] } it 'sends the host option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:host].should eq '123.123.123.123' + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:host]).to eq '123.123.123.123' end.and_return(sock_runner) described_class.start(args) end @@ -44,8 +44,8 @@ let(:test_args) { [ '--port=12345' ] } it 'sends the port option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:port].should eq 12345 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:port]).to eq 12345 end.and_return(sock_runner) described_class.start(args) end @@ -55,8 +55,8 @@ let(:test_args) { [ '--threads=500' ] } it 'sends the threads option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:threads].should eq 500 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:threads]).to eq 500 end.and_return(sock_runner) described_class.start(args) end @@ -66,8 +66,8 @@ let(:test_args) { [ '--backlog=500' ] } it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:backlog].should eq 500 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:backlog]).to eq 500 end.and_return(sock_runner) described_class.start(args) end @@ -77,8 +77,8 @@ let(:test_args) { [ '--threshold=500' ] } it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:threshold].should eq 500 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:threshold]).to eq 500 end.and_return(sock_runner) described_class.start(args) end @@ -88,9 +88,9 @@ let(:test_args) { [ '--log=mylog.log', '--level=0' ] } it 'sends the log file and level options to the runner' do - ::Protobuf::Logger.should_receive(:configure) do |options| - options[:file].should eq 'mylog.log' - options[:level].should eq 0 + expect(::Protobuf::Logger).to receive(:configure) do |options| + expect(options[:file]).to eq 'mylog.log' + expect(options[:level]).to eq 0 end described_class.start(args) end @@ -103,7 +103,7 @@ it 'sets both request and serialization pausing to false' do described_class.start(args) - ::Protobuf.should_not be_gc_pause_server_request + expect(::Protobuf).to_not be_gc_pause_server_request end end @@ -113,7 +113,7 @@ it 'sets the configuration option to GC pause server request' do described_class.start(args) - ::Protobuf.should be_gc_pause_server_request + expect(::Protobuf).to be_gc_pause_server_request end end end @@ -128,7 +128,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + expect(::Protobuf.print_deprecation_warnings?).to be_truthy end end @@ -138,7 +138,7 @@ it 'sets the deprecation warning flag to false ' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_false + expect(::Protobuf.print_deprecation_warnings?).to be_falsey end end end @@ -148,7 +148,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + expect(::Protobuf.print_deprecation_warnings?).to be_truthy end end @@ -157,7 +157,7 @@ it 'sets the deprecation warning flag to false' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_false + expect(::Protobuf.print_deprecation_warnings?).to be_falsey end end end @@ -169,24 +169,24 @@ let(:runner) { ::Protobuf::Rpc::SocketRunner } before do - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::ZmqRunner).not_to receive(:new) end it 'is activated by the --socket switch' do - runner.should_receive(:new) + expect(runner).to receive(:new) described_class.start(args) end it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do ENV['PB_SERVER_TYPE'] = "Socket" - runner.should_receive(:new).and_return(sock_runner) + expect(runner).to receive(:new).and_return(sock_runner) described_class.start(args) ENV.delete('PB_SERVER_TYPE') end it 'configures the connector type to be socket' do load "protobuf/socket.rb" - ::Protobuf.connector_type.should == :socket + expect(::Protobuf.connector_type).to eq(:socket) end end @@ -195,12 +195,12 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new) end it 'is activated by the --workers_only switch' do - runner.should_receive(:new) do |options| - options[:workers_only].should be_true + expect(runner).to receive(:new) do |options| + expect(options[:workers_only]).to be_truthy end.and_return(zmq_runner) described_class.start(args) @@ -208,8 +208,8 @@ it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do ENV['PB_WORKERS_ONLY'] = "1" - runner.should_receive(:new) do |options| - options[:workers_only].should be_true + expect(runner).to receive(:new) do |options| + expect(options[:workers_only]).to be_truthy end.and_return(zmq_runner) described_class.start(args) @@ -222,12 +222,12 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new) end it 'is activated by the --worker_port switch' do - runner.should_receive(:new) do |options| - options[:worker_port].should eq(1234) + expect(runner).to receive(:new) do |options| + expect(options[:worker_port]).to eq(1234) end.and_return(zmq_runner) described_class.start(args) @@ -239,24 +239,24 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new) end it 'is activated by the --zmq switch' do - runner.should_receive(:new) + expect(runner).to receive(:new) described_class.start(args) end it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do ENV['PB_SERVER_TYPE'] = "Zmq" - runner.should_receive(:new) + expect(runner).to receive(:new) described_class.start(args) ENV.delete('PB_SERVER_TYPE') end it 'configures the connector type to be zmq' do load "protobuf/zmq.rb" - ::Protobuf.connector_type.should == :zmq + expect(::Protobuf.connector_type).to eq(:zmq) end end diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 65cace6a..ca31b278 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -27,13 +27,13 @@ end before do - ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file1).and_return(file_generator1) - ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file2).and_return(file_generator2) + expect(::Protobuf::Generators::FileGenerator).to receive(:new).with(input_file1).and_return(file_generator1) + expect(::Protobuf::Generators::FileGenerator).to receive(:new).with(input_file2).and_return(file_generator2) end it 'returns the serialized CodeGeneratorResponse which contains the generated file contents' do generator = described_class.new(request_bytes) - generator.response_bytes.should eq expected_response_bytes + expect(generator.response_bytes).to eq expected_response_bytes end end @@ -51,7 +51,7 @@ describe '.warn' do it 'prints a warning to stderr' do - STDERR.should_receive(:puts).with("[WARN] a warning") + expect(STDERR).to receive(:puts).with("[WARN] a warning") described_class.warn("a warning") end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index fc03322f..21ebfdd0 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -22,7 +22,7 @@ describe '.aliases_allowed?' do it 'is false when the option is not set' do - expect(Test::EnumTestType.aliases_allowed?).to be_false + expect(Test::EnumTestType.aliases_allowed?).to be_falsey end end @@ -155,15 +155,15 @@ describe '.valid_tag?' do context 'when tag is defined' do - specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_true } + specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_truthy } end context 'when tag is not defined' do - specify { expect(Test::EnumTestType.valid_tag?(300)).to be_false } + specify { expect(Test::EnumTestType.valid_tag?(300)).to be_falsey } end context 'is true for aliased enums' do - specify { expect(EnumAliasTest.valid_tag?(1)).to be_true } + specify { expect(EnumAliasTest.valid_tag?(1)).to be_truthy } end end @@ -201,31 +201,31 @@ end subject { Test::EnumTestType::ONE } - its(:class) { should eq(Fixnum) } - its(:parent_class) { should eq(Test::EnumTestType) } - its(:name) { should eq(:ONE) } - its(:tag) { should eq(1) } - its(:value) { should eq(1) } - its(:to_hash_value) { should eq(1) } - its(:to_s) { should eq("1") } - its(:inspect) { should eq('#') } - specify { subject.to_s(:tag).should eq("1") } - specify { subject.to_s(:name).should eq("ONE") } + specify { expect(subject.class).to eq(Fixnum) } + specify { expect(subject.parent_class).to eq(Test::EnumTestType) } + specify { expect(subject.name).to eq(:ONE) } + specify { expect(subject.tag).to eq(1) } + specify { expect(subject.value).to eq(1) } + specify { expect(subject.to_hash_value).to eq(1) } + specify { expect(subject.to_s).to eq("1") } + specify { expect(subject.inspect).to eq('#') } + specify { expect(subject.to_s(:tag)).to eq("1") } + specify { expect(subject.to_s(:name)).to eq("ONE") } it "can be used as the index to an array" do array = [0, 1, 2, 3] - array[::Test::EnumTestType::ONE].should eq(1) + expect(array[::Test::EnumTestType::ONE]).to eq(1) end describe '#try' do - specify { subject.try(:parent_class).should eq(subject.parent_class) } - specify { subject.try(:class).should eq(subject.class) } - specify { subject.try(:name).should eq(subject.name) } - specify { subject.try(:tag).should eq(subject.tag) } - specify { subject.try(:value).should eq(subject.value) } - specify { subject.try(:to_i).should eq(subject.to_i) } - specify { subject.try(:to_int).should eq(subject.to_int) } - specify { subject.try { |yielded| yielded.should eq(subject) } } + specify { expect(subject.try(:parent_class)).to eq(subject.parent_class) } + specify { expect(subject.try(:class)).to eq(subject.class) } + specify { expect(subject.try(:name)).to eq(subject.name) } + specify { expect(subject.try(:tag)).to eq(subject.tag) } + specify { expect(subject.try(:value)).to eq(subject.value) } + specify { expect(subject.try(:to_i)).to eq(subject.to_i) } + specify { expect(subject.try(:to_int)).to eq(subject.to_int) } + specify { subject.try { |yielded| expect(yielded).to eq(subject) } } end context 'when coercing from enum' do diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index 50ba13b9..887d8e57 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -27,18 +27,18 @@ source_string = "foo" proto = ::Test::Resource.new(:name => source_string) proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string end it 'does not alter unicode string values after encoding multiple times' do source_string = "¢" proto = ::Test::Resource.new(:name => source_string) proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string end end diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 27157b77..a7a303e4 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -10,8 +10,8 @@ context 'namespaces' do let(:descriptor) { double(:name => 'Baz') } subject { described_class.new(descriptor, 0, :namespace => [ :foo, :bar ]) } - its(:type_namespace) { should eq [ :foo, :bar, 'Baz' ] } - its(:fully_qualified_type_namespace) { should eq '.foo.bar.Baz' } + specify { expect(subject.type_namespace).to eq([ :foo, :bar, 'Baz' ]) } + specify { expect(subject.fully_qualified_type_namespace).to eq('.foo.bar.Baz') } end describe '#run_once' do @@ -67,17 +67,14 @@ def compile describe '#validate_tags' do context 'when tags are duplicated' do it 'fails with a GeneratorFatalError' do - ::Protobuf::CodeGenerator.should_receive(:fatal) - .with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/) - + expect(::Protobuf::CodeGenerator).to receive(:fatal).with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/) described_class.validate_tags("FooBar", [1,2,2,3]) end end context 'when tags are missing in the range' do it 'prints a warning' do - ::Protobuf::CodeGenerator.should_receive(:warn) - .with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) + expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) described_class.validate_tags("FooBar", [1,2,4,5]) end end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 9d7048f5..a2dbbb0d 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -33,7 +33,7 @@ it 'compiles the enum and it\'s field values' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end context 'when allow_alias option is set' do @@ -53,14 +53,14 @@ it 'sets the allow_alias option' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end end end describe '#build_value' do it 'returns a string identifying the given enum value' do - subject.build_value(enum.value.first).should eq("define :FOO, 1") + expect(subject.build_value(enum.value.first)).to eq("define :FOO, 1") end end diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index da072abe..5d0e21f7 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -15,9 +15,9 @@ let(:message_type) { 'FooBar' } before do - ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[0], 1).and_return(field_descriptors[0]) - ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[1], 1).and_return(field_descriptors[1]) - ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[2], 1).and_return(field_descriptors[2]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[0], 1).and_return(field_descriptors[0]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[1], 1).and_return(field_descriptors[1]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[2], 1).and_return(field_descriptors[2]) end subject { described_class.new(message_type, field_descriptors, 0) } @@ -35,7 +35,7 @@ it 'compiles the a class with the extension fields' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 5f97b412..714c864e 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -27,33 +27,33 @@ describe '#compile' do subject { described_class.new(field).to_s } - it { should eq "optional :string, :foo_bar, 3\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3\n" } context 'when the type is another message' do let(:type_enum) { :TYPE_MESSAGE } let(:type_name) { '.foo.bar.Baz' } - it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" } + specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" } end context 'when a default value is used' do let(:type_enum) { :TYPE_INT32 } let(:default_value) { '42' } - it { should eq "optional :int32, :foo_bar, 3, :default => 42\n" } + specify { expect(subject).to eq "optional :int32, :foo_bar, 3, :default => 42\n" } context 'when type is an enum' do let(:type_enum) { :TYPE_ENUM } let(:type_name) { '.foo.bar.Baz' } let(:default_value) { 'QUUX' } - it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } + specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } end context 'when the type is a string' do let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - it { should eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } + specify { expect(subject).to eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } end context 'when float or double field type' do @@ -61,17 +61,17 @@ context 'when the default value is "nan"' do let(:default_value) { 'nan' } - it { should match(/::Float::NAN/) } + specify { expect(subject).to match(/::Float::NAN/) } end context 'when the default value is "inf"' do let(:default_value) { 'inf' } - it { should match(/::Float::INFINITY/) } + specify { expect(subject).to match(/::Float::INFINITY/) } end context 'when the default value is "-inf"' do let(:default_value) { '-inf' } - it { should match(/-::Float::INFINITY/) } + specify { expect(subject).to match(/-::Float::INFINITY/) } end end end @@ -79,19 +79,19 @@ context 'when the field is an extension' do let(:extendee) { 'foo.bar.Baz' } - it { should eq "optional :string, :foo_bar, 3, :extension => true\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :extension => true\n" } end context 'when field is packed' do let(:field_options) { { :packed => true } } - it { should eq "optional :string, :foo_bar, 3, :packed => true\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :packed => true\n" } end context 'when field is deprecated' do let(:field_options) { { :deprecated => true } } - it { should eq "optional :string, :foo_bar, 3, :deprecated => true\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :deprecated => true\n" } end end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 19559c9a..9f666afa 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -9,7 +9,7 @@ let(:file_descriptor) { ::Google::Protobuf::FileDescriptorProto.new(descriptor_fields) } subject { described_class.new(file_descriptor) } - its(:file_name) { should eq 'test/foo.pb.rb' } + specify { expect(subject.file_name).to eq('test/foo.pb.rb') } describe '#print_import_requires' do let(:descriptor_fields) do @@ -18,8 +18,8 @@ end it 'prints a ruby require for each dependency' do - subject.should_receive(:print_require).with('test/bar.pb') - subject.should_receive(:print_require).with('test/baz.pb') + expect(subject).to receive(:print_require).with('test/bar.pb') + expect(subject).to receive(:print_require).with('test/baz.pb') subject.print_import_requires end diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index c10c6293..dae1fc02 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -29,13 +29,13 @@ it 'compiles the service and it\'s rpc methods' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end end describe '#build_method' do it 'returns a string identifying the given method descriptor' do - subject.build_method(service.method.first).should eq("rpc :search, FooRequest, FooResponse") + expect(subject.build_method(service.method.first)).to eq("rpc :search, FooRequest, FooResponse") end end diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index f40a5fb2..fce13162 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -9,8 +9,8 @@ end it "registers a string as the event_name" do - ::ActiveSupport::Notifications.should_receive(:subscribe).with("something") - subject.register("something") { true } + expect(::ActiveSupport::Notifications).to receive(:subscribe).with("something") + subject.register("something") { true } end it "only registers blocks for event callbacks" do @@ -26,8 +26,8 @@ end subject.trigger("this") - this.should_not be_nil - this.should eq("not nil") + expect(this).to_not be_nil + expect(this).to eq("not nil") end it "calls multiple registered blocks when triggered" do @@ -43,10 +43,10 @@ end subject.trigger("this") - this.should_not be_nil - this.should eq("not nil") - that.should_not be_nil - that.should eq("not nil") + expect(this).to_not be_nil + expect(this).to eq("not nil") + expect(that).to_not be_nil + expect(that).to eq("not nil") end context 'when the registered block has arity' do @@ -55,12 +55,12 @@ outer_bar = nil subject.register('foo') do |bar| - bar.should be_nil + expect(bar).to be_nil outer_bar = 'triggered' end subject.trigger('foo') - outer_bar.should eq 'triggered' + expect(outer_bar).to eq 'triggered' end end @@ -69,21 +69,21 @@ outer_bar = nil subject.register('foo') do |bar| - bar.should_not be_nil + expect(bar).to_not be_nil outer_bar = bar end subject.trigger('foo', 'baz') - outer_bar.should eq 'baz' + expect(outer_bar).to eq 'baz' end end end context "normalized event names" do - specify { subject.normalized_event_name(:derp).should eq("derp") } - specify { subject.normalized_event_name(:Derp).should eq("derp") } - specify { subject.normalized_event_name("DERP").should eq("derp") } - specify { subject.normalized_event_name("derp").should eq("derp") } + specify { expect(subject.normalized_event_name(:derp)).to eq("derp") } + specify { expect(subject.normalized_event_name(:Derp)).to eq("derp") } + specify { expect(subject.normalized_event_name("DERP")).to eq("derp") } + specify { expect(subject.normalized_event_name("derp")).to eq("derp") } end end diff --git a/spec/lib/protobuf/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb index 04ce7dbe..15eaaebe 100644 --- a/spec/lib/protobuf/logger_spec.rb +++ b/spec/lib/protobuf/logger_spec.rb @@ -20,22 +20,22 @@ it 'doesn\'t create a logger if the file was not set' do subject.file = nil - subject.instance.should be_nil + expect(subject.instance).to be_nil end it 'doesn\'t create a logger if the level was not set' do subject.level = nil - subject.instance.should be_nil + expect(subject.instance).to be_nil end it 'gets a new instance of the logger when file and level are set' do - subject.file.should_not be_nil - subject.level.should_not be_nil - subject.instance.should_not be_nil + expect(subject.file).to_not be_nil + expect(subject.level).to_not be_nil + expect(subject.instance).to_not be_nil end it 'keeps the same object from multiple calls to instance' do - subject.instance === subject.instance + expect(subject.instance).to equal(subject.instance) end end @@ -43,13 +43,13 @@ describe '.configure' do before(:each) { subject.reset_device! } it 'sets the file and level in one call' do - subject.file.should_not be - subject.level.should_not be - subject.instance.should_not be + expect(subject.file).to_not be + expect(subject.level).to_not be + expect(subject.instance).to_not be subject.configure :file => 'myfile.log', :level => ::Logger::WARN - subject.file.should == 'myfile.log' - subject.level.should == ::Logger::WARN - subject.instance.level.should == ::Logger::WARN + expect(subject.file).to eq('myfile.log') + expect(subject.level).to eq(::Logger::WARN) + expect(subject.instance.level).to eq(::Logger::WARN) end end @@ -57,13 +57,13 @@ describe '.reset_device!' do it 'resets the logger instance, file, and level' do - subject.instance.should be - subject.file.should be - subject.level.should be + expect(subject.instance).to be + expect(subject.file).to be + expect(subject.level).to be subject.reset_device! - subject.instance.should_not be - subject.file.should_not be - subject.level.should_not be + expect(subject.instance).to_not be + expect(subject.file).to_not be + expect(subject.level).to_not be end end @@ -72,7 +72,7 @@ it 'doesn\'t raise errors when log instance is nil' do subject.reset_device! - subject.instance.should be_nil + expect(subject.instance).to be_nil expect { subject.debug 'No errors here' subject.info 'No errors here' @@ -85,8 +85,8 @@ end it 'logs correctly when instance is valid' do - subject.instance.should_not be_nil - subject.instance.should_receive(:info).with('Should log great') + expect(subject.instance).to_not be_nil + expect(subject.instance).to receive(:info).with('Should log great') subject.info 'Should log great' end @@ -114,20 +114,20 @@ class MyTestClass context '#log_exception' do it 'logs the exception message as an error and backtrace as debug' do - subject.should_receive(:log_error).twice - subject.should_receive(:log_debug) + expect(subject).to receive(:log_error).twice + expect(subject).to receive(:log_debug) subject.log_exception(RuntimeError.new('this is an exception')) end end - its(:log_signature) { should eq "[MyTestClass]" } + specify { expect(subject.log_signature).to eq "[MyTestClass]" } describe '#sign_message' do - specify { subject.sign_message("this is a test").should eq "[MyTestClass] this is a test" } - specify { subject.class.sign_message("this is a test").should eq "[MyTestClass] this is a test" } + specify { expect(subject.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } + specify { expect(subject.class.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } end it 'passes all embedded log calls to Logger instance' do - Protobuf::Logger.instance.should_receive(:debug).with('[MyTestClass] log this') + expect(Protobuf::Logger.instance).to receive(:debug).with('[MyTestClass] log this') subject.log_debug('log this') end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index b9f4b2f8..67e173bf 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -6,7 +6,7 @@ let(:message) { ::Test::Resource.new(:name => "Jim") } it 'creates a new message object decoded from the given bytes' do - ::Test::Resource.decode(message.encode).should eq message + expect(::Test::Resource.decode(message.encode)).to eq message end end @@ -62,41 +62,41 @@ let(:values) { { :name => "Jim" } } it 'creates a new message object with the given values and returns the encoded bytes' do - ::Test::Resource.encode(values).should eq ::Test::Resource.new(values).encode + expect(::Test::Resource.encode(values)).to eq ::Test::Resource.new(values).encode end end describe '#initialize' do it "initializes the enum getter to 0" do test_enum = Test::EnumTestMessage.new - test_enum.non_default_enum.should eq(0) + expect(test_enum.non_default_enum).to eq(0) end it "exposes the enum getter raw value through ! method" do test_enum = Test::EnumTestMessage.new - test_enum.non_default_enum!.should be_nil + expect(test_enum.non_default_enum!).to be_nil end it "exposes the enum getter raw value through ! method (when set)" do test_enum = Test::EnumTestMessage.new test_enum.non_default_enum = 1 - test_enum.non_default_enum!.should eq(1) + expect(test_enum.non_default_enum!).to eq(1) end it "does not try to set attributes which have nil values" do - Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=") + expect_any_instance_of(Test::EnumTestMessage).not_to receive("non_default_enum=") Test::EnumTestMessage.new(:non_default_enum => nil) end it "takes a hash as an initialization argument" do test_enum = Test::EnumTestMessage.new(:non_default_enum => 2) - test_enum.non_default_enum.should eq(2) + expect(test_enum.non_default_enum).to eq(2) end it "initializes with an object that responds to #to_hash" do hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) test_enum = Test::EnumTestMessage.new(hashie_object) - test_enum.non_default_enum.should eq(2) + expect(test_enum.non_default_enum).to eq(2) end end @@ -114,7 +114,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - (new_message.name == name).should be_true + expect(new_message.name == name).to be_truthy end it "trims binary when binary is input for string fields" do @@ -123,7 +123,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - (new_message.name == "my name").should be_true + expect(new_message.name == "my name").to be_truthy end end @@ -149,19 +149,19 @@ it "sets the value to nil when empty array is passed" do message.repeated_enum = [] - message.instance_variable_get("@values")[:repeated_enum].should be_nil + expect(message.instance_variable_get("@values")[:repeated_enum]).to be_nil end it "does not compact the edit original array" do a = [nil].freeze message.repeated_enum = a - message.repeated_enum.should eq([]) - a.should eq([nil].freeze) + expect(message.repeated_enum).to eq([]) + expect(a).to eq([nil].freeze) end it "compacts the set array" do message.repeated_enum = [nil] - message.repeated_enum.should eq([]) + expect(message.repeated_enum).to eq([]) end it "raises TypeError when a non-array replaces it" do @@ -179,16 +179,16 @@ it "sets the predicate to true when the boolean value is true" do subject.active = true - subject.active?.should be_true + expect(subject.active?).to be_truthy end it "sets the predicate to false when the boolean value is false" do subject.active = false - subject.active?.should be_false + expect(subject.active?).to be_falsey end it "does not put predicate methods on non-boolean fields" do - Test::ResourceFindRequest.new(:name => "resource").should_not respond_to(:name?) + expect(Test::ResourceFindRequest.new(:name => "resource")).to_not respond_to(:name?) end end @@ -196,11 +196,11 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - subject.respond_to_and_has?(:other_field).should be_false + expect(subject.respond_to_and_has?(:other_field)).to be_falsey end it "is true when the message has the field" do - subject.respond_to_and_has?(:non_default_enum).should be_true + expect(subject.respond_to_and_has?(:non_default_enum)).to be_truthy end end @@ -208,38 +208,38 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - subject.respond_to_and_has_and_present?(:other_field).should be_false + expect(subject.respond_to_and_has_and_present?(:other_field)).to be_falsey end it "is false when the field is repeated and a value is not present" do - subject.respond_to_and_has_and_present?(:repeated_enums).should be_false + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey end it "is false when the field is repeated and the value is empty array" do subject.repeated_enums = [] - subject.respond_to_and_has_and_present?(:repeated_enums).should be_false + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey end it "is true when the field is repeated and a value is present" do subject.repeated_enums = [2] - subject.respond_to_and_has_and_present?(:repeated_enums).should be_true + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_truthy end it "is true when the message has the field" do - subject.respond_to_and_has_and_present?(:non_default_enum).should be_true + expect(subject.respond_to_and_has_and_present?(:non_default_enum)).to be_truthy end context "#API" do subject { Test::EnumTestMessage.new(:non_default_enum => 2) } - it { should respond_to(:respond_to_and_has_and_present?) } - it { should respond_to(:responds_to_and_has_and_present?) } - it { should respond_to(:responds_to_has?) } - it { should respond_to(:respond_to_has?) } - it { should respond_to(:respond_to_has_present?) } - it { should respond_to(:responds_to_has_present?) } - it { should respond_to(:respond_to_and_has_present?) } - it { should respond_to(:responds_to_and_has_present?) } + specify { expect(subject).to respond_to(:respond_to_and_has_and_present?) } + specify { expect(subject).to respond_to(:responds_to_and_has_and_present?) } + specify { expect(subject).to respond_to(:responds_to_has?) } + specify { expect(subject).to respond_to(:respond_to_has?) } + specify { expect(subject).to respond_to(:respond_to_has_present?) } + specify { expect(subject).to respond_to(:responds_to_has_present?) } + specify { expect(subject).to respond_to(:respond_to_and_has_present?) } + specify { expect(subject).to respond_to(:responds_to_and_has_present?) } end end @@ -248,24 +248,24 @@ context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do hash = Test::EnumTestMessage.new(:non_default_enum => :TWO).to_hash - hash.should eq({ :non_default_enum => 2 }) + expect(hash).to eq({ :non_default_enum => 2 }) end it 'does not populate default values' do hash = Test::EnumTestMessage.new.to_hash - hash.should eq(Hash.new) + expect(hash).to eq(Hash.new) end it 'converts repeated enum fields to an array of the tags' do hash = Test::EnumTestMessage.new(:repeated_enums => [ :ONE, :TWO, :TWO, :ONE ]).to_hash - hash.should eq({ :repeated_enums => [ 1, 2, 2, 1 ] }) + expect(hash).to eq({ :repeated_enums => [ 1, 2, 2, 1 ] }) end end context 'generating values for a Message field' do it 'recursively hashes field messages' do hash = Test::Nested.new({ :resource => { :name => 'Nested' } }).to_hash - hash.should eq({ :resource => { :name => 'Nested' } }) + expect(hash).to eq({ :resource => { :name => 'Nested' } }) end it 'recursively hashes a repeated set of messages' do @@ -274,7 +274,7 @@ Test::Resource.new(:name => 'Resource 2') ]) - proto.to_hash.should eq({ :multiple_resources => [ { :name => 'Resource 1' }, + expect(proto.to_hash).to eq({ :multiple_resources => [ { :name => 'Resource 1' }, { :name => 'Resource 2' } ] }) end @@ -286,7 +286,7 @@ ::Test::ResourceFindRequest.new({ :name => 'Test Name', :active => false }) end - its(:to_json) { should eq '{"name":"Test Name","active":false}' } + specify { expect(subject.to_json).to eq '{"name":"Test Name","active":false}' } end describe '.to_json' do @@ -330,8 +330,8 @@ end it 'returns nil when field is not found' do - ::Test::Resource.get_extension_field(-1).should be_nil - ::Test::Resource.get_extension_field(nil).should be_nil + expect(::Test::Resource.get_extension_field(-1)).to be_nil + expect(::Test::Resource.get_extension_field(nil)).to be_nil end end @@ -360,8 +360,8 @@ end it 'returns nil when field is not defined' do - ::Test::Resource.get_field(-1).should be_nil - ::Test::Resource.get_field(nil).should be_nil + expect(::Test::Resource.get_field(-1)).to be_nil + expect(::Test::Resource.get_field(nil)).to be_nil end end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 6de32c34..f65eca6c 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -20,7 +20,7 @@ it 'defaults the value to true' do OptionableSetOptionTest.set_option(:baz_enabled) - expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_true + expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_truthy end end diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 6046386a..14b8ba34 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -10,29 +10,29 @@ before { reset_service_location(Test::ResourceService) } it 'should be able to get a client through the Service#client helper method' do - Test::ResourceService.client(:port => 9191).should eq(Protobuf::Rpc::Client.new(:service => Test::ResourceService, :port => 9191)) + expect(::Test::ResourceService.client(:port => 9191)).to eq(Protobuf::Rpc::Client.new(:service => Test::ResourceService, :port => 9191)) end it "should be able to override a service location's host and port" do Test::ResourceService.located_at 'somewheregreat.com:12345' clean_client = Test::ResourceService.client - clean_client.options[:host].should eq('somewheregreat.com') - clean_client.options[:port].should eq(12345) + expect(clean_client.options[:host]).to eq('somewheregreat.com') + expect(clean_client.options[:port]).to eq(12345) updated_client = Test::ResourceService.client(:host => 'amazing.com', :port => 54321) - updated_client.options[:host].should eq('amazing.com') - updated_client.options[:port].should eq(54321) + expect(updated_client.options[:host]).to eq('amazing.com') + expect(updated_client.options[:port]).to eq(54321) end it 'should be able to define which service to create itself for' do client = Protobuf::Rpc::Client.new :service => Test::ResourceService - client.options[:service].should eq(Test::ResourceService) + expect(client.options[:service]).to eq(Test::ResourceService) end it 'should have a hard default for host and port on a service that has not been configured' do client = Test::ResourceService.client - client.options[:host].should eq(Protobuf::Rpc::Service::DEFAULT_HOST) - client.options[:port].should eq(Protobuf::Rpc::Service::DEFAULT_PORT) + expect(client.options[:host]).to eq(Protobuf::Rpc::Service::DEFAULT_HOST) + expect(client.options[:port]).to eq(Protobuf::Rpc::Service::DEFAULT_PORT) end end @@ -45,7 +45,7 @@ it 'should respond to defined service methods' do client = Test::ResourceService.client - client.should_receive(:send_request).and_return(nil) + expect(client).to receive(:send_request).and_return(nil) expect { client.find(nil) }.to_not raise_error end end @@ -54,11 +54,11 @@ it 'should be able to create the correct request object if passed a hash' do client = Test::ResourceService.client - client.should_receive(:send_request) + expect(client).to receive(:send_request) client.find({:name => 'Test Name', :active => false}) - client.options[:request].should be_a(Test::ResourceFindRequest) - client.options[:request].name.should eq('Test Name') - client.options[:request].active.should eq(false) + expect(client.options[:request]).to be_a(Test::ResourceFindRequest) + expect(client.options[:request].name).to eq('Test Name') + expect(client.options[:request].active).to eq(false) end end diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index 92637452..4092ce0f 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -9,17 +9,17 @@ context 'Protobuf.connector_type is socket' do before { ::Protobuf.connector_type = :socket } - it { should eq ::Protobuf::Rpc::Connectors::Socket } + specify { expect(subject).to eq ::Protobuf::Rpc::Connectors::Socket } end context 'Protobuf.connector_type is not a known value' do - before { ::Protobuf.stub(:connector_type) { :foo } } - it { should eq ::Protobuf::Rpc::Connectors::Socket } + before { allow(::Protobuf).to receive(:connector_type).and_return(:foo) } + specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Socket) } end context 'Protobuf.connector_type is zmq' do before { ::Protobuf.connector_type = :zmq } - it { should eq ::Protobuf::Rpc::Connectors::Zmq } + specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Zmq) } end end diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 5dae92f6..fad03f4f 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -21,28 +21,28 @@ describe '.new' do it 'assigns passed options and initializes success/failure callbacks' do - subject.options.should eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(options)) - subject.success_cb.should be_nil - subject.failure_cb.should be_nil + expect(subject.options).to eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(options)) + expect(subject.success_cb).to be_nil + expect(subject.failure_cb).to be_nil end end describe '#success_cb' do it 'allows setting the success callback and calling it' do - subject.success_cb.should be_nil + expect(subject.success_cb).to be_nil cb = proc {|res| raise res } subject.success_cb = cb - subject.success_cb.should eq(cb) + expect(subject.success_cb).to eq(cb) expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb' end end describe '#failure_cb' do it 'allows setting the failure callback and calling it' do - subject.failure_cb.should be_nil + expect(subject.failure_cb).to be_nil cb = proc {|res| raise res } subject.failure_cb = cb - subject.failure_cb.should eq(cb) + expect(subject.failure_cb).to eq(cb) expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb' end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 9d75ce03..8f814a7f 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -15,15 +15,15 @@ subject { @subject ||= common_class.new(subject_options) } context "API" do - specify { subject.respond_to?(:any_callbacks?).should be_true } - specify { subject.respond_to?(:request_caller).should be_true } - specify { subject.respond_to?(:data_callback).should be_true } - specify { subject.respond_to?(:error).should be_true } - specify { subject.respond_to?(:fail).should be_true } - specify { subject.respond_to?(:complete).should be_true } - specify { subject.respond_to?(:parse_response).should be_true } - specify { subject.respond_to?(:verify_options!).should be_true } - specify { subject.respond_to?(:verify_callbacks).should be_true } + specify { expect(subject.respond_to?(:any_callbacks?)).to be_truthy } + specify { expect(subject.respond_to?(:request_caller)).to be_truthy } + specify { expect(subject.respond_to?(:data_callback)).to be_truthy } + specify { expect(subject.respond_to?(:error)).to be_truthy } + specify { expect(subject.respond_to?(:fail)).to be_truthy } + specify { expect(subject.respond_to?(:complete)).to be_truthy } + specify { expect(subject.respond_to?(:parse_response)).to be_truthy } + specify { expect(subject.respond_to?(:verify_options!)).to be_truthy } + specify { expect(subject.respond_to?(:verify_callbacks)).to be_truthy } end describe "#any_callbacks?" do @@ -31,7 +31,7 @@ [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| it "returns true if #{cb} is provided" do subject.instance_variable_set(cb, "something") - subject.any_callbacks?.should be_true + expect(subject.any_callbacks?).to be_truthy end end @@ -40,32 +40,32 @@ subject.instance_variable_set(:@success_cb, nil) subject.instance_variable_set(:@failure_cb, nil) - subject.any_callbacks?.should be_false + expect(subject.any_callbacks?).to be_falsey end end describe '#request_caller' do - its(:request_caller) { should eq ::Protobuf.client_host } + specify { expect(subject.request_caller).to eq ::Protobuf.client_host } context 'when "client_host" option is given to initializer' do let(:hostname) { 'myhost.myserver.com' } let(:subject_options) { { :client_host => hostname } } - its(:request_caller) { should_not eq ::Protobuf.client_host } - its(:request_caller) { should eq hostname } + specify { expect(subject.request_caller).to_not eq ::Protobuf.client_host } + specify { expect(subject.request_caller).to eq hostname } end end describe "#data_callback" do it "changes state to use the data callback" do subject.data_callback("data") - subject.instance_variable_get(:@used_data_callback).should be_true + expect(subject.instance_variable_get(:@used_data_callback)).to be_truthy end it "sets the data var when using the data_callback" do subject.data_callback("data") - subject.instance_variable_get(:@data).should eq("data") + expect(subject.instance_variable_get(:@data)).to eq("data") end end @@ -84,38 +84,38 @@ :request_proto => '', :caller => client_host }) } - before { subject.stub(:validate_request_type!).and_return(true) } - before { subject.should_not_receive(:fail) } + before { allow(subject).to receive(:validate_request_type!).and_return(true) } + before { expect(subject).not_to receive(:fail) } - its(:request_bytes) { should eq expected.encode } + specify { expect(subject.request_bytes).to eq expected.encode } end describe "#verify_callbacks" do it "sets @failure_cb to #data_callback when no callbacks are defined" do subject.verify_callbacks - subject.instance_variable_get(:@failure_cb).should eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@failure_cb)).to eq(subject.method(:data_callback)) end it "sets @success_cb to #data_callback when no callbacks are defined" do subject.verify_callbacks - subject.instance_variable_get(:@success_cb).should eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@success_cb)).to eq(subject.method(:data_callback)) end it "doesn't set @failure_cb when already defined" do set_cb = lambda{ true } subject.instance_variable_set(:@failure_cb, set_cb) subject.verify_callbacks - subject.instance_variable_get(:@failure_cb).should eq(set_cb) - subject.instance_variable_get(:@failure_cb).should_not eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) + expect(subject.instance_variable_get(:@failure_cb)).to_not eq(subject.method(:data_callback)) end it "doesn't set @success_cb when already defined" do set_cb = lambda{ true } subject.instance_variable_set(:@success_cb, set_cb) subject.verify_callbacks - subject.instance_variable_get(:@success_cb).should eq(set_cb) - subject.instance_variable_get(:@success_cb).should_not eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) + expect(subject.instance_variable_get(:@success_cb)).to_not eq(subject.method(:data_callback)) end end @@ -123,33 +123,31 @@ shared_examples "a ConnectorDisposition" do |meth, cb, *args| it "calls #complete before exit" do - stats = double("Object") - stats.stub(:stop) { true } - subject.stats = stats + subject.stats = double("Object", :stop => true) - subject.should_receive(:complete) + expect(subject).to receive(:complete) subject.method(meth).call(*args) end it "calls the #{cb} callback when provided" do stats = double("Object") - stats.stub(:stop) { true } + allow(stats).to receive(:stop).and_return(true) subject.stats = stats _cb = double("Object") subject.instance_variable_set("@#{cb}", _cb) - _cb.should_receive(:call).and_return(true) + expect(_cb).to receive(:call).and_return(true) subject.method(meth).call(*args) end it "calls the complete callback when provided" do stats = double("Object") - stats.stub(:stop) { true } + allow(stats).to receive(:stop).and_return(true) subject.stats = stats comp_cb = double("Object") subject.instance_variable_set(:@complete_cb, comp_cb) - comp_cb.should_receive(:call).and_return(true) + expect(comp_cb).to receive(:call).and_return(true) subject.method(meth).call(*args) end diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 131d274a..ff18c2ee 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -6,10 +6,10 @@ context "API" do # Check the API - specify{ subject.respond_to?(:send_request, true).should be_true } - specify{ subject.respond_to?(:post_init, true).should be_true } - specify{ subject.respond_to?(:close_connection, true).should be_true } - specify{ subject.respond_to?(:error?, true).should be_true } + specify { expect(subject.respond_to?(:send_request, true)).to be_truthy } + specify { expect(subject.respond_to?(:post_init, true)).to be_truthy } + specify { expect(subject.respond_to?(:close_connection, true)).to be_truthy } + specify { expect(subject.respond_to?(:error?, true)).to be_truthy } end end @@ -18,19 +18,19 @@ it_behaves_like "a Protobuf Connector" - specify{ described_class.include?(Protobuf::Rpc::Connectors::Common).should be_true } + specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be_truthy } context "#read_response" do - let(:data){ "New data" } + let(:data) { "New data" } it "fills the buffer with data from the socket" do socket = StringIO.new("#{data.bytesize}-#{data}") subject.instance_variable_set(:@socket, socket) subject.instance_variable_set(:@stats, OpenStruct.new) - subject.should_receive(:parse_response).and_return(true) + expect(subject).to receive(:parse_response).and_return(true) subject.__send__(:read_response) - subject.instance_variable_get(:@response_data).should eq(data) + expect(subject.instance_variable_get(:@response_data)).to eq(data) end end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index cff17ca1..707033c8 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -12,20 +12,11 @@ :port => "9400" }} - let(:socket_double) do - sm = double(::ZMQ::Socket) - sm.stub(:connect).and_return(0) - sm - end - - let(:zmq_context_double) do - zc = double(::ZMQ::Context) - zc.stub(:socket).and_return(socket_double) - zc - end + let(:socket_double) { double(::ZMQ::Socket, :connect => 0) } + let(:zmq_context_double) { double(::ZMQ::Context, :socket => socket_double) } before do - ::ZMQ::Context.stub(:new).and_return(zmq_context_double) + allow(::ZMQ::Context).to receive(:new).and_return(zmq_context_double) end before(:all) do @@ -42,19 +33,17 @@ let(:listings) { [listing] } let(:running?) { true } - before do - subject.stub(:service_directory) { service_directory } - end + before { allow(subject).to receive(:service_directory).and_return(service_directory) } context "when the service directory is running" do it "searches the service directory" do - service_directory.stub(:all_listings_for).and_return(listings) - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.2:9399" + allow(service_directory).to receive(:all_listings_for).and_return(listings) + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.2:9399" end it "defaults to the options" do - service_directory.stub(:all_listings_for).and_return([]) - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" + allow(service_directory).to receive(:all_listings_for).and_return([]) + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.1:9400" end end @@ -62,21 +51,21 @@ let(:running?) { false } it "defaults to the options" do - service_directory.stub(:all_listings_for).and_return([]) - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" + allow(service_directory).to receive(:all_listings_for).and_return([]) + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.1:9400" end end it "checks if the server is alive" do - service_directory.stub(:all_listings_for).and_return([]) - subject.should_receive(:host_alive?).with("127.0.0.1") { true } - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" + allow(service_directory).to receive(:all_listings_for).and_return([]) + expect(subject).to receive(:host_alive?).with("127.0.0.1") { true } + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.1:9400" end context "when no host is alive" do it "raises an error" do - service_directory.stub(:all_listings_for).and_return(listings) - subject.stub(:host_alive?).and_return(false) + allow(service_directory).to receive(:all_listings_for).and_return(listings) + allow(subject).to receive(:host_alive?).and_return(false) expect { subject.send(:lookup_server_uri) }.to raise_error end end @@ -90,11 +79,11 @@ end it "returns true" do - subject.send(:host_alive?, "yip.yip").should be_true + expect(subject.send(:host_alive?, "yip.yip")).to be_truthy end it "does not attempt a connection" do - TCPSocket.should_not_receive(:new) + expect(TCPSocket).not_to receive(:new) subject.send(:host_alive?, "blargh.com") end end @@ -105,20 +94,20 @@ end it "returns true when the connection succeeds" do - TCPSocket.should_receive(:new).with("huzzah.com", 3307) { double(:close => nil) } - subject.send(:host_alive?, "huzzah.com").should be_true + expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil)) + expect(subject.send(:host_alive?, "huzzah.com")).to be_truthy end it "returns false when the connection fails" do - TCPSocket.should_receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) - subject.send(:host_alive?, "hayoob.com").should be_false + expect(TCPSocket).to receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) + expect(subject.send(:host_alive?, "hayoob.com")).to be_falsey end it "closes the socket" do socket = double("TCPSocket") - socket.should_receive(:close) - TCPSocket.should_receive(:new).with("absorbalof.com", 3307) { socket } - subject.send(:host_alive?, "absorbalof.com").should be_true + expect(socket).to receive(:close) + expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) + expect(subject.send(:host_alive?, "absorbalof.com")).to be_truthy end end end diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index 532164d6..e7d3a79f 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -8,19 +8,19 @@ describe "#call" do it "calls the stack" do - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end it "returns the env" do - subject.call(env).should eq env + expect(subject.call(env)).to eq env end context "when exceptions occur" do let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } - before { app.stub(:call).and_raise(error, 'Boom!') } + before { allow(app).to receive(:call).and_raise(error, 'Boom!') } it "rescues exceptions" do expect { subject.call(env) }.not_to raise_exception @@ -32,12 +32,12 @@ # Can't compare the error instances because the response has been # raised and thus has a backtrace while the error does not. - stack_env.response.class.should eq error.class + expect(stack_env.response.class).to eq error.class end it "encodes the response" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_error + expect(stack_env.encoded_response).to eq encoded_error end end @@ -45,16 +45,16 @@ let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::RpcFailed.new('Boom!') } - before { app.stub(:call).and_raise(RuntimeError, 'Boom!') } + before { allow(app).to receive(:call).and_raise(RuntimeError, 'Boom!') } it "wraps the exception in a generic Protobuf error" do stack_env = subject.call(env) - stack_env.response.should eq error + expect(stack_env.response).to eq error end it "encodes the wrapped exception" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_error + expect(stack_env.encoded_response).to eq encoded_error end end end diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index 8220d416..fa938aa1 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -38,12 +38,12 @@ describe "#call" do it "calls the stack" do - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env).and_return(env) subject.call(env) end it "returns the env" do - subject.call(env).should eq env + expect(subject.call(env)).to eq env end end end diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 0572ace2..ae33afe8 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -31,51 +31,51 @@ describe "#call" do it "decodes the request" do stack_env = subject.call(env) - stack_env.request.should eq request + expect(stack_env.request).to eq request end it "calls the stack" do - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end it "sets Env#client_host" do stack_env = subject.call(env) - stack_env.client_host.should eq client_host + expect(stack_env.client_host).to eq client_host end it "sets Env#service_name" do stack_env = subject.call(env) - stack_env.service_name.should eq service_name + expect(stack_env.service_name).to eq service_name end it "sets Env#method_name" do stack_env = subject.call(env) - stack_env.method_name.should eq method_name.to_sym + expect(stack_env.method_name).to eq method_name.to_sym end it "sets Env#request_type" do stack_env = subject.call(env) - stack_env.request_type.should eq request_type + expect(stack_env.request_type).to eq request_type end it "sets Env#response_type" do stack_env = subject.call(env) - stack_env.response_type.should eq response_type + expect(stack_env.response_type).to eq response_type end it "sets Env#rpc_method" do stack_env = subject.call(env) - stack_env.rpc_method.should eq rpc_method + expect(stack_env.rpc_method).to eq rpc_method end it "sets Env#rpc_service" do stack_env = subject.call(env) - stack_env.rpc_service.should eq rpc_service + expect(stack_env.rpc_service).to eq rpc_service end context "when decoding fails" do - before { Protobuf::Socketrpc::Request.stub(:decode).and_raise(RuntimeError) } + before { allow(Protobuf::Socketrpc::Request).to receive(:decode).and_raise(RuntimeError) } it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadRequestData) diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index dd58d7ba..9b9bb429 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -17,12 +17,12 @@ describe "#call" do it "encodes the response" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_response + expect(stack_env.encoded_response).to eq encoded_response end it "calls the stack" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end context "when response is responds to :to_hash" do @@ -31,7 +31,7 @@ it "sets Env#response" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end end @@ -41,7 +41,7 @@ it "sets Env#response" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end end @@ -60,12 +60,12 @@ it "wraps and encodes the response" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_response + expect(stack_env.encoded_response).to eq encoded_response end end context "when encoding fails" do - before { Protobuf::Socketrpc::Response.any_instance.stub(:encode).and_raise(RuntimeError) } + before { allow_any_instance_of(Protobuf::Socketrpc::Response).to receive(:encode).and_raise(RuntimeError) } it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError) diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 5257291b..6497641c 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -24,15 +24,15 @@ end it "Runner provides a stop method" do - @runner.should respond_to(:stop) + expect(@runner).to respond_to(:stop) end it "provides a stop method" do - @server.should respond_to(:stop) + expect(@server).to respond_to(:stop) end it "signals the Server is running" do - @server.should be_running + expect(@server).to be_running end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 17d6aaf9..9a8df8ce 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -22,12 +22,12 @@ describe '.running?' do it 'returns true if running' do subject.instance_variable_set(:@running, true) - subject.running?.should be_true + expect(subject.running?).to be_truthy end it 'returns false if not running' do subject.instance_variable_set(:@running, false) - subject.running?.should be_false + expect(subject.running?).to be_falsey end end @@ -35,7 +35,7 @@ it 'sets running to false' do subject.instance_variable_set(:@workers, []) subject.stop - subject.instance_variable_get(:@running).should be_false + expect(subject.instance_variable_get(:@running)).to be_falsey end end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index 7412d0d6..523297f8 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -18,7 +18,7 @@ class UtilTest end it 'retrieves the error string from ZeroMQ' do - ZMQ::Util.stub(:error_string).and_return('an error from zmq') + allow(ZMQ::Util).to receive(:error_string).and_return('an error from zmq') expect { subject.zmq_error_check(-1, :test) }.to raise_error(RuntimeError, /an error from zmq/i) @@ -39,7 +39,7 @@ class UtilTest describe '#log_signature' do it 'returns the signature for the log' do - subject.log_signature.should include('server', 'UtilTest') + expect(subject.log_signature).to include('server', 'UtilTest') end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index ada0adfc..1da51f5e 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' describe ::Protobuf::Rpc::Zmq::Worker do - before(:each) do + before(:each) do load 'protobuf/zmq.rb' fake_socket = double - fake_socket.should_receive(:connect).and_return(0) - fake_socket.should_receive(:send_string).and_return(0) + expect(fake_socket).to receive(:connect).and_return(0) + expect(fake_socket).to receive(:send_string).and_return(0) fake_context = double - fake_context.should_receive(:socket).and_return( fake_socket ) - ::ZMQ::Context.should_receive(:new).and_return( fake_context ) + expect(fake_context).to receive(:socket).and_return(fake_socket) + expect(::ZMQ::Context).to receive(:new).and_return(fake_context) end subject do diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index c7bae230..350f9f74 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -56,10 +56,9 @@ end def expect_event_trigger(event) - ::ActiveSupport::Notifications - .should_receive(:instrument) - .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))) - .once + expect(::ActiveSupport::Notifications).to receive(:instrument) + .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))) + .once end def send_beacon(type, server) @@ -74,29 +73,29 @@ def send_beacon(type, server) end it "should be a singleton" do - subject.should be_a_kind_of(Singleton) + expect(subject).to be_a_kind_of(Singleton) end it "should be configured to listen to address 127.0.0.1" do - described_class.address.should eq '127.0.0.1' + expect(described_class.address).to eq '127.0.0.1' end it "should be configured to listen to port 33333" do - described_class.port.should eq 33333 + expect(described_class.port).to eq 33333 end it "should defer .start to the instance#start" do - described_class.instance.should_receive(:start) + expect(described_class.instance).to receive(:start) described_class.start end it "should yeild itself to blocks passed to .start" do - described_class.instance.stub(:start) + allow(described_class.instance).to receive(:start) expect { |b| described_class.start(&b) }.to yield_with_args(described_class) end it "should defer .stop to the instance#stop" do - described_class.instance.should_receive(:stop) + expect(described_class.instance).to receive(:stop) described_class.stop end @@ -106,20 +105,20 @@ def send_beacon(type, server) describe "#lookup" do it "should return nil" do send_beacon(:heartbeat, echo_server) - subject.lookup("EchoService").should be_nil + expect(subject.lookup("EchoService")).to be_nil end end describe "#restart" do it "should start the service" do subject.restart - subject.should be_running + expect(subject).to be_running end end describe "#running" do it "should be false" do - subject.should_not be_running + expect(subject).to_not be_running end end @@ -134,7 +133,7 @@ def send_beacon(type, server) before { subject.start } after { subject.stop } - it { should be_running } + specify { expect(subject).to be_running } it "should trigger added events" do expect_event_trigger("directory.listing.added") @@ -159,13 +158,13 @@ def send_beacon(type, server) send_beacon(:heartbeat, hello_server) send_beacon(:heartbeat, combo_server) - subject.all_listings_for("HelloService").size.should eq(2) + expect(subject.all_listings_for("HelloService").size).to eq(2) end end context "when no listings are present" do it "returns and empty array" do - subject.all_listings_for("HelloService").size.should eq(0) + expect(subject.all_listings_for("HelloService").size).to eq(0) end end end @@ -185,7 +184,7 @@ def send_beacon(type, server) describe "#lookup" do it "should provide listings by service" do send_beacon(:heartbeat, hello_server) - subject.lookup("HelloService").to_hash.should eq hello_server.to_hash + expect(subject.lookup("HelloService").to_hash).to eq hello_server.to_hash end it "should return random listings" do @@ -193,14 +192,14 @@ def send_beacon(type, server) send_beacon(:heartbeat, combo_server) uuids = 100.times.map { subject.lookup("HelloService").uuid } - uuids.count("hello").should be_within(25).of(50) - uuids.count("combo").should be_within(25).of(50) + expect(uuids.count("hello")).to be_within(25).of(50) + expect(uuids.count("combo")).to be_within(25).of(50) end it "should not return expired listings" do send_beacon(:heartbeat, hello_server_with_short_ttl) sleep 1 - subject.lookup("HelloService").should be_nil + expect(subject.lookup("HelloService")).to be_nil end it "should not return flatlined servers" do @@ -209,7 +208,7 @@ def send_beacon(type, server) send_beacon(:flatline, echo_server) uuids = 100.times.map { subject.lookup("EchoService").uuid } - uuids.count("combo").should eq 100 + expect(uuids.count("combo")).to eq 100 end it "should return up-to-date listings" do @@ -217,13 +216,13 @@ def send_beacon(type, server) echo_server.port = "7777" send_beacon(:heartbeat, echo_server) - subject.lookup("EchoService").port.should eq "7777" + expect(subject.lookup("EchoService").port).to eq "7777" end context 'when given service identifier is a class name' do it 'returns the listing corresponding to the class name' do send_beacon(:heartbeat, echo_server) - subject.lookup(EchoService).uuid.should eq echo_server.uuid + expect(subject.lookup(EchoService).uuid).to eq echo_server.uuid end end end @@ -233,13 +232,13 @@ def send_beacon(type, server) send_beacon(:heartbeat, echo_server) send_beacon(:heartbeat, combo_server) subject.restart - subject.lookup("EchoService").should be_nil + expect(subject.lookup("EchoService")).to be_nil end end describe "#running" do it "should be true" do - subject.should be_running + expect(subject).to be_running end end @@ -248,12 +247,12 @@ def send_beacon(type, server) send_beacon(:heartbeat, echo_server) send_beacon(:heartbeat, combo_server) subject.stop - subject.lookup("EchoService").should be_nil + expect(subject.lookup("EchoService")).to be_nil end it "should stop the server" do subject.stop - subject.should_not be_running + expect(subject).to_not be_running end end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 82616c82..1582b44c 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -23,14 +23,14 @@ subject { described_class.new(app) } - before { subject.stub(:rpc_service).and_return(rpc_service) } + before { allow(subject).to receive(:rpc_service).and_return(rpc_service) } describe '#call' do - before { rpc_service.stub(:response).and_return(response) } + before { allow(rpc_service).to receive(:response).and_return(response) } it "dispatches the request" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end context "when the given RPC method is not implemented" do @@ -42,7 +42,7 @@ end context "when the given RPC method is implemented and a NoMethodError is raised" do - before { rpc_service.stub(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } + before { allow(rpc_service).to receive(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } it "raises the exeception" do expect { subject.call(env) }.to raise_exception(NoMethodError) diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index fd991822..14ce7ac7 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -55,13 +55,13 @@ def foo FilterTest.before_filter(:foo) end - specify { subject.class.should respond_to(:before_filter) } - specify { subject.class.should respond_to(:before_action) } + specify { expect(subject.class).to respond_to(:before_filter) } + specify { expect(subject.class).to respond_to(:before_action) } it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :foo, :endpoint ] - subject.before_filter_calls.should eq 1 + expect(subject.called).to eq [ :verify_before, :foo, :endpoint ] + expect(subject.before_filter_calls).to eq 1 end context 'when filter is configured with "only"' do @@ -82,14 +82,14 @@ def endpoint_with_verify context 'when invoking a method defined in "only" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint_with_verify) - subject.called.should eq [ :verify_before, :endpoint_with_verify ] + expect(subject.called).to eq [ :verify_before, :endpoint_with_verify ] end end context 'when invoking a method not defined by "only" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end end @@ -112,14 +112,14 @@ def endpoint_without_verify context 'when invoking a method not defined in "except" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end context 'when invoking a method defined by "except" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint_without_verify) - subject.called.should eq [ :endpoint_without_verify ] + expect(subject.called).to eq [ :endpoint_without_verify ] end end end @@ -142,7 +142,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -154,7 +154,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -166,7 +166,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end @@ -178,7 +178,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end end @@ -201,7 +201,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -213,7 +213,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -225,7 +225,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end @@ -237,7 +237,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end end @@ -259,9 +259,9 @@ def short_circuit_filter end it 'does not invoke the rpc method' do - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :short_circuit_filter ] + expect(subject.called).to eq [ :short_circuit_filter ] end end end @@ -289,13 +289,13 @@ def foo FilterTest.after_filter(:foo) end - specify { subject.class.should respond_to(:after_filter) } - specify { subject.class.should respond_to(:after_action) } + specify { expect(subject.class).to respond_to(:after_filter) } + specify { expect(subject.class).to respond_to(:after_action) } it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint, :verify_after, :foo ] - subject.after_filter_calls.should eq 1 + expect(subject.called).to eq [ :endpoint, :verify_after, :foo ] + expect(subject.after_filter_calls).to eq 1 end end @@ -326,12 +326,12 @@ def inner_around FilterTest.around_filter(:inner_around) end - specify { subject.class.should respond_to(:around_filter) } - specify { subject.class.should respond_to(:around_action) } + specify { expect(subject.class).to respond_to(:around_filter) } + specify { expect(subject.class).to respond_to(:around_action) } it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :outer_around_top, + expect(subject.called).to eq([ :outer_around_top, :inner_around_top, :endpoint, :inner_around_bottom, @@ -354,9 +354,9 @@ def inner_around end it 'cancels calling the rest of the filters and the endpoint' do - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :outer_around_top, + expect(subject.called).to eq([ :outer_around_top, :inner_around, :outer_around_bottom ]) end @@ -412,10 +412,10 @@ def custom_error_occurred(ex) it 'short-circuits the call stack' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_error3, :custom_error_occurred ]) - subject.ex_class.should eq CustomError3 + expect(subject.called).to eq([ :filter_with_error3, :custom_error_occurred ]) + expect(subject.ex_class).to eq CustomError3 }.not_to raise_error end end @@ -433,10 +433,10 @@ def custom_error_occurred(ex) it 'short-circuits the call stack' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_error1, :custom_error_occurred ]) - subject.ex_class.should eq CustomError1 + expect(subject.called).to eq([ :filter_with_error1, :custom_error_occurred ]) + expect(subject.ex_class).to eq CustomError1 }.not_to raise_error end end @@ -453,10 +453,10 @@ def custom_error_occurred(ex) it 'short-circuits the call stack' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_error1, :block_rescue_handler ]) - subject.ex_class.should eq CustomError1 + expect(subject.called).to eq([ :filter_with_error1, :block_rescue_handler ]) + expect(subject.ex_class).to eq CustomError1 }.not_to raise_error end end @@ -472,10 +472,10 @@ def custom_error_occurred(ex) it 'rescues with the given callable' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) - subject.ex_class.should eq RuntimeError + expect(subject.called).to eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) + expect(subject.ex_class).to eq RuntimeError }.not_to raise_error end end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 49b66a0e..1cef20be 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -11,73 +11,73 @@ end describe '.host' do - its(:host) { should eq described_class::DEFAULT_HOST } + specify { expect(subject.host).to eq described_class::DEFAULT_HOST } end describe '.host=' do before { subject.host = 'mynewhost.com' } - its(:host) { should eq 'mynewhost.com' } + specify { expect(subject.host).to eq 'mynewhost.com' } end describe '.port' do - its(:port) { should eq described_class::DEFAULT_PORT } + specify { expect(subject.port).to eq described_class::DEFAULT_PORT } end describe '.port=' do before { subject.port = 12345 } - its(:port) { should eq 12345 } + specify { expect(subject.port).to eq 12345 } end describe '.configure' do context 'when providing a host' do before { subject.configure(:host => 'mynewhost.com') } - its(:host) { should eq 'mynewhost.com' } + specify { expect(subject.host).to eq 'mynewhost.com' } end context 'when providing a port' do before { subject.configure(:port => 12345) } - its(:port) { should eq 12345 } + specify { expect(subject.port).to eq 12345 } end end describe '.located_at' do context 'when given location is empty' do before { subject.located_at(nil) } - its(:host) { should eq described_class::DEFAULT_HOST } - its(:port) { should eq described_class::DEFAULT_PORT } + specify { expect(subject.host).to eq described_class::DEFAULT_HOST } + specify { expect(subject.port).to eq described_class::DEFAULT_PORT } end context 'when given location is invalid' do before { subject.located_at('i like pie') } - its(:host) { should eq described_class::DEFAULT_HOST } - its(:port) { should eq described_class::DEFAULT_PORT } + specify { expect(subject.host).to eq described_class::DEFAULT_HOST } + specify { expect(subject.port).to eq described_class::DEFAULT_PORT } end context 'when given location contains a host and port' do before { subject.located_at('mynewdomain.com:12345') } - its(:host) { should eq 'mynewdomain.com' } - its(:port) { should eq 12345 } + specify { expect(subject.host).to eq 'mynewdomain.com' } + specify { expect(subject.port).to eq 12345 } end end describe '.client' do it 'initializes a client object for this service' do client = double('client') - ::Protobuf::Rpc::Client.should_receive(:new) - .with(hash_including({ :service => subject, - :host => subject.host, - :port => subject.port })) - .and_return(client) - subject.client.should eq client + expect(::Protobuf::Rpc::Client).to receive(:new) + .with(hash_including({ :service => subject, + :host => subject.host, + :port => subject.port })) + .and_return(client) + expect(subject.client).to eq client end end describe '.rpc' do before { Test::ResourceService.rpc(:update, Test::ResourceFindRequest, Test::Resource) } subject { Test::ResourceService.rpcs[:update] } - its(:method) { should eq :update } - its(:request_type) { should eq Test::ResourceFindRequest } - its(:response_type) { should eq Test::Resource } + specify { expect(subject.method).to eq :update } + specify { expect(subject.request_type).to eq Test::ResourceFindRequest } + specify { expect(subject.response_type).to eq Test::Resource } end describe '.rpc_method?' do @@ -85,13 +85,13 @@ context 'when given name is a pre-defined rpc method' do it 'returns true' do - subject.rpc_method?(:delete).should be_true + expect(subject.rpc_method?(:delete)).to be_truthy end end context 'when given name is not a pre-defined rpc method' do it 'returns false' do - subject.rpc_method?(:zoobaboo).should be_false + expect(subject.rpc_method?(:zoobaboo)).to be_falsey end end end @@ -137,8 +137,8 @@ def find_with_rpc_failed subject { NewTestService.new(env) } before { subject.find_with_implied_response } - its(:response) { should be_a(Test::Resource) } - specify { subject.response.name.should eq 'Implicit response' } + specify { expect(subject.response).to be_a(Test::Resource) } + specify { expect(subject.response.name).to eq 'Implicit response' } end context 'when using respond_with paradigm' do @@ -152,8 +152,8 @@ def find_with_rpc_failed subject { NewTestService.new(env) } before { subject.find_with_respond_with } - its(:response) { should be_a(Test::Resource) } - specify { subject.response.name.should eq 'Custom response' } + specify { expect(subject.response).to be_a(Test::Resource) } + specify { expect(subject.response.name).to eq 'Custom response' } end end end diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index ad6b7f8d..eafb3dd7 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -21,7 +21,7 @@ class BarService < ::Struct.new(:method_name); end ::Timecop.freeze(1.62.seconds.from_now) do stats.stop - stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}" + expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}" end end end @@ -32,7 +32,7 @@ class BarService < ::Struct.new(:method_name); end stats.client = 'myserver1' stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars)) stats.request_size = 43 - stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-" + expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-" end end end @@ -49,7 +49,7 @@ class BarService < ::Struct.new(:method_name); end ::Timecop.freeze(0.832.seconds.from_now) do stats.stop - stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}" + expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}" end end @@ -62,7 +62,7 @@ class BarService < ::Struct.new(:method_name); end stats.service = 'Foo::BarService' stats.method_name = 'find_bars' stats.request_size = 37 - stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-" + expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-" end end end diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index e2f50e8e..458bcde8 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -23,13 +23,13 @@ before { described_class.instance_variable_set(:@_connector_type, nil) } it 'defaults to socket' do - described_class.connector_type.should eq :socket + expect(described_class.connector_type).to eq :socket end it 'accepts socket or zmq' do [:socket, :zmq].each do |type| described_class.connector_type = type - described_class.connector_type.should eq type + expect(described_class.connector_type).to eq type end end @@ -46,12 +46,12 @@ before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) } it 'defaults to a false value' do - described_class.gc_pause_server_request?.should be_false + expect(described_class.gc_pause_server_request?).to be_falsey end it 'is settable' do described_class.gc_pause_server_request = true - described_class.gc_pause_server_request?.should be_true + expect(described_class.gc_pause_server_request?).to be_truthy end end @@ -59,18 +59,18 @@ before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) } it 'defaults to a true value' do - described_class.print_deprecation_warnings?.should be_true + expect(described_class.print_deprecation_warnings?).to be_truthy end it 'is settable' do described_class.print_deprecation_warnings = false - described_class.print_deprecation_warnings?.should be_false + expect(described_class.print_deprecation_warnings?).to be_falsey end context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do it 'defaults to a false value' do ENV['PB_IGNORE_DEPRECATIONS'] = '1' - described_class.print_deprecation_warnings?.should be_false + expect(described_class.print_deprecation_warnings?).to be_falsey end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61e94631..f2e3efbf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,7 @@ require 'bundler' Bundler.setup :default, :development, :test require 'pry' +# require 'rspec/its' $: << ::File.expand_path('../..', __FILE__) $: << ::File.expand_path('../support', __FILE__) diff --git a/spec/support/packed_field.rb b/spec/support/packed_field.rb index 84e46847..79bb7655 100644 --- a/spec/support/packed_field.rb +++ b/spec/support/packed_field.rb @@ -16,7 +16,7 @@ class PackableFieldTest < ::Protobuf::Message; end subject { PackableFieldTest.get_field(field_name) } - it { should be_packed } + specify { expect(subject).to be_packed } end end From f015c5597b16a6b9add91282743c39808eb01e46 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 29 Jun 2014 20:52:59 -0600 Subject: [PATCH 0683/1191] Add ruby 2.1.1 to travis yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 33c3265f..b2e5e625 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby rvm: - "1.9.3" - "2.0.0" + - "2.1.1" script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib notifications: webhooks: From a1e9a677820dd9a5f4dc909e5d7234fb9827c1eb Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 7 Jul 2014 16:41:53 -0600 Subject: [PATCH 0684/1191] check the socket after we get it from the context so it is actually usable, any network failures will cause the context to not issue a socket and it should be re-created also go to only 5 iterations through servers before failing out and no wait time between, the entire server cluster is traversed each time so 5 should be enough also added timeouts to snd/rcv of the first alive ping as it should be very quick to determine which server the work is for and fail quickly to move on --- lib/protobuf/rpc/connectors/zmq.rb | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b8121a11..e7966761 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -68,21 +68,26 @@ def create_socket begin server_uri = lookup_server_uri - socket = zmq_context.socket(::ZMQ::REQ) - socket.setsockopt(::ZMQ::LINGER, 0) - log_debug { sign_message("Establishing connection: #{server_uri}") } - zmq_error_check(socket.connect(server_uri), :socket_connect) - log_debug { sign_message("Connection established to #{server_uri}") } + if socket # Make sure the context builds the socket + socket.setsockopt(::ZMQ::LINGER, 0) + + log_debug { sign_message("Establishing connection: #{server_uri}") } + zmq_error_check(socket.connect(server_uri), :socket_connect) + log_debug { sign_message("Connection established to #{server_uri}") } - if first_alive_load_balance? - check_available_response = "" - zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) + if first_alive_load_balance? + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, 100) + socket.setsockopt(::ZMQ::SNDTIMEO, 100) - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_error_check(socket.close, :socket_close) + zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_error_check(socket.close, :socket_close) + end end end end while socket.try(:socket).nil? @@ -101,7 +106,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 50.times do + 5.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -111,8 +116,6 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - - sleep(1.0/10.0) # not sure why sleeping at all, but should be way less than 1 second end raise "Host not found for service #{service}" From 8ffe90109d703077da39f47d3b2690a1dc2a9022 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 7 Jul 2014 18:29:51 -0600 Subject: [PATCH 0685/1191] add the idea of a recoverable error check as zmq should not crash on the timeouts --- lib/protobuf/rpc/connectors/zmq.rb | 34 +++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index e7966761..957ddc1d 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -5,8 +5,8 @@ module Protobuf module Rpc module Connectors class Zmq < Base - RequestTimeout = Class.new(RuntimeError) + ZmqRecoverableError = Class.new(RuntimeError) ## # Included Modules @@ -78,15 +78,19 @@ def create_socket log_debug { sign_message("Connection established to #{server_uri}") } if first_alive_load_balance? - check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 100) - socket.setsockopt(::ZMQ::SNDTIMEO, 100) - - zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) - - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_error_check(socket.close, :socket_close) + begin + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, 50) + socket.setsockopt(::ZMQ::SNDTIMEO, 50) + + zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_recoverable_error_check(socket.close, :socket_close) + end + rescue ZmqRecoverableError + socket = nil # couldn't make a connection and need to try again end end end @@ -202,6 +206,16 @@ def zmq_error_check(return_code, source) ERROR end end + + def zmq_recoverable_error_check(return_code, source) + unless ::ZMQ::Util.resultcode_ok?(return_code || -1) + raise ZmqRecoverableError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + end + end end end end From 1bb42ac9095c3a19f217dc9f38142e765444b599 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 7 Jul 2014 18:52:24 -0600 Subject: [PATCH 0686/1191] add back a sleep and no linger on host_live --- lib/protobuf/rpc/connectors/zmq.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 957ddc1d..15a4766c 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -110,7 +110,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 5.times do + 10.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -120,6 +120,8 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) + + sleep(1.0/60.0) end raise "Host not found for service #{service}" @@ -129,6 +131,8 @@ def host_alive?(host) return true unless ping_port_enabled? socket = TCPSocket.new(host, ping_port.to_i) + linger = [1,0].pack('ii') + socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, linger) true rescue From 4ac09dbdab7e2b15cb548d26edbe80ac87f268f7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 12:58:14 -0600 Subject: [PATCH 0687/1191] remove sleeping and set timeo to 10ms --- lib/protobuf/rpc/connectors/zmq.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 15a4766c..756c5baa 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -11,15 +11,14 @@ class Zmq < Base ## # Included Modules # - include Protobuf::Rpc::Connectors::Common include Protobuf::Logger::LogMethods ## # Class Constants # - CLIENT_RETRIES = (ENV['PB_CLIENT_RETRIES'] || 3) + LINGER = [0,0].pack('ii') ## # Class Methods @@ -80,8 +79,8 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 50) - socket.setsockopt(::ZMQ::SNDTIMEO, 50) + socket.setsockopt(::ZMQ::RCVTIMEO, 10) + socket.setsockopt(::ZMQ::SNDTIMEO, 10) zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) @@ -110,7 +109,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 10.times do + 5.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -120,8 +119,6 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - - sleep(1.0/60.0) end raise "Host not found for service #{service}" @@ -130,9 +127,13 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? - socket = TCPSocket.new(host, ping_port.to_i) - linger = [1,0].pack('ii') - socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, linger) + socket = Socket.new(:INET, :STREAM) + socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, LINGER) + socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) + socket.setsockopt(:SOCKET, :SNDBUF, 1) + socket.setsockopt(:SOCKET, :REUSEADDR, true) + address = Socket.sockaddr_in(ping_port.to_i, host) + socket.connect(address) true rescue From ab333dd41109c6f817ee93122755b50ae2ce36b5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 14:19:16 -0600 Subject: [PATCH 0688/1191] remove rcv and snd timeout as to not change too much and let the local queue expand to 5 entries --- lib/protobuf/rpc/connectors/zmq.rb | 3 --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 756c5baa..3123dacf 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -79,9 +79,6 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 10) - socket.setsockopt(::ZMQ::SNDTIMEO, 10) - zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 9b77aa5c..4b6be48f 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -102,7 +102,7 @@ def process_frontend address, _, message, *frames = read_from_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE - if @idle_workers.any? || local_queue.empty? + if @idle_workers.any? || local_queue.size < 5 # Should make queue a SizedQueue and allow users to configure queue size write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) From 2decd6457c14f074092322503788f34a8df0a51e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 14:23:24 -0600 Subject: [PATCH 0689/1191] use plain tcpsocket for now --- lib/protobuf/rpc/connectors/zmq.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 3123dacf..916608c2 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -123,14 +123,7 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? - - socket = Socket.new(:INET, :STREAM) - socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, LINGER) - socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) - socket.setsockopt(:SOCKET, :SNDBUF, 1) - socket.setsockopt(:SOCKET, :REUSEADDR, true) - address = Socket.sockaddr_in(ping_port.to_i, host) - socket.connect(address) + socket = TCPSocket.new(host, ping_port.to_i) true rescue From 58d86e50f487e9a12f935d5b414498ebbbbb5f4f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 15:48:58 -0600 Subject: [PATCH 0690/1191] remove old linger --- lib/protobuf/rpc/connectors/zmq.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 916608c2..7097759f 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -18,7 +18,6 @@ class Zmq < Base # Class Constants # CLIENT_RETRIES = (ENV['PB_CLIENT_RETRIES'] || 3) - LINGER = [0,0].pack('ii') ## # Class Methods From fc9b239f380c66f10397c9467a3ccaac903e74f1 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 16:04:52 -0600 Subject: [PATCH 0691/1191] bump to 3.0.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 36c544a6..18f0a4c9 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.4' + VERSION = '3.0.5' end From cf6264d7fb5fdf674cd4db6cb9d912d8b52d49fe Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Sat, 19 Jul 2014 16:25:08 -0700 Subject: [PATCH 0692/1191] Elide unknown enum values when decoding --- lib/protobuf/field/enum_field.rb | 6 ++++ spec/lib/protobuf/message_spec.rb | 59 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 7322c21e..fb386a98 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -16,6 +16,12 @@ def encode(value) super(value.to_i) end + def decode(value) + if acceptable?(value) + value + end + end + def enum? true end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 67e173bf..17fdbce0 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -8,6 +8,65 @@ it 'creates a new message object decoded from the given bytes' do expect(::Test::Resource.decode(message.encode)).to eq message end + + context 'with a new enum value' do + let(:older_message) do + Class.new(Protobuf::Message) do + enum_class = Class.new(::Protobuf::Enum) do + define :YAY, 1 + end + + optional enum_class, :enum_field, 1 + repeated enum_class, :enum_list, 2 + end + end + + let(:newer_message) do + Class.new(Protobuf::Message) do + enum_class = Class.new(::Protobuf::Enum) do + define :YAY, 1 + define :HOORAY, 2 + end + + optional enum_class, :enum_field, 1 + repeated enum_class, :enum_list, 2 + end + end + + context 'with a singular field' do + it 'treats the field as if it was unset when decoding' do + newer = newer_message.new(:enum_field => :HOORAY).serialize + + expect(older_message.decode(newer).enum_field!).to be_nil + end + + it 'rejects an unknown value when using the constructor' do + expect { older_message.new(:enum_field => :HOORAY) }.to raise_error + end + + it 'rejects an unknown value when the setter' do + older = older_message.new + expect { older.enum_field = :HOORAY }.to raise_error + end + end + + context 'with a repeated field' do + it 'treats the field as if it was unset when decoding' do + newer = newer_message.new(:enum_list => [ :HOORAY ]).serialize + + expect(older_message.decode(newer).enum_list).to eq([]) + end + + it 'rejects an unknown value when using the constructor' do + expect { older_message.new(:enum_list => [ :HOORAY ]) }.to raise_error + end + + it 'rejects an unknown value when the setter' do + older = older_message.new + expect { older.enum_field = [ :HOORAY ] }.to raise_error + end + end + end end describe 'defining a new field' do From 66d82bcb1e1367043ccb15c624cdc89684e5d205 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jul 2014 09:50:37 -0600 Subject: [PATCH 0693/1191] Bump version 3.1.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 18f0a4c9..d7d20206 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.5' + VERSION = '3.1.0' end From 9e4a43f37c996196b84f350e8fc982c8d29ddf4d Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 30 Jul 2014 17:22:35 -0700 Subject: [PATCH 0694/1191] Make sure all enum values have names (including defaults) --- lib/protobuf/field/enum_field.rb | 3 ++- spec/lib/protobuf/message_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index fb386a98..c9b90f57 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -53,7 +53,8 @@ def typed_default_value if default.is_a?(Symbol) type_class.const_get(default) else - self.class.default + tag = self.class.default + type_class.new(self.class.default, type_class.name_for_tag(tag), tag) end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 17fdbce0..1dd0df4a 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -131,6 +131,11 @@ expect(test_enum.non_default_enum).to eq(0) end + it "initializes the enum getter with a name" do + test_enum = Test::EnumTestMessage.new + expect { test_enum.non_default_enum.name }.to_not raise_error + end + it "exposes the enum getter raw value through ! method" do test_enum = Test::EnumTestMessage.new expect(test_enum.non_default_enum!).to be_nil From 49ac6acec462cf0a40f57634f495abe75313eed3 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 30 Jul 2014 18:13:26 -0700 Subject: [PATCH 0695/1191] Per protobuf spec, unset enums default to first enum value > For enums, the default value is the first value listed in the > enum's type definition. Source: https://developers.google.com/protocol-buffers/docs/proto#optional --- lib/protobuf/field/enum_field.rb | 3 +-- spec/lib/protobuf/message_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index c9b90f57..ae6dc51b 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -53,8 +53,7 @@ def typed_default_value if default.is_a?(Symbol) type_class.const_get(default) else - tag = self.class.default - type_class.new(self.class.default, type_class.name_for_tag(tag), tag) + type_class.enums.first end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 1dd0df4a..4ea9fb33 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -126,14 +126,14 @@ end describe '#initialize' do - it "initializes the enum getter to 0" do + it "defaults to the first value listed in the enum's type definition" do test_enum = Test::EnumTestMessage.new - expect(test_enum.non_default_enum).to eq(0) + expect(test_enum.non_default_enum).to eq(1) end - it "initializes the enum getter with a name" do + it "defaults to a a value with a name" do test_enum = Test::EnumTestMessage.new - expect { test_enum.non_default_enum.name }.to_not raise_error + expect(test_enum.non_default_enum.name).to eq(:ONE) end it "exposes the enum getter raw value through ! method" do From 5bdc9d1047c11ba30a12669c8582751a6d721f18 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 31 Jul 2014 09:56:30 -0700 Subject: [PATCH 0696/1191] Use type_class.fetch to get a default value if it exists --- lib/protobuf/field/enum_field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index ae6dc51b..5f0c65e1 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -53,7 +53,7 @@ def typed_default_value if default.is_a?(Symbol) type_class.const_get(default) else - type_class.enums.first + type_class.fetch(default) || type_class.enums.first end end From be8882ee916f09aac23e007b00724cb68aea858a Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 31 Jul 2014 09:56:44 -0700 Subject: [PATCH 0697/1191] Prevent using Protobuf::Enum.default, it must be on an instance --- lib/protobuf/field/enum_field.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 5f0c65e1..15bfd94c 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -4,6 +4,14 @@ module Protobuf module Field class EnumField < VarintField + ## + # Class Methods + # + + def self.default + raise NoMethodError, "#{self}.#{__method__} must be called on an instance" + end + ## # Public Instance Methods # From 2d6e1c3623fb39b90321e8ac4fdf239c3e89711a Mon Sep 17 00:00:00 2001 From: Wesley Kim Date: Fri, 1 Aug 2014 10:53:01 -0700 Subject: [PATCH 0698/1191] Add ignore_unknown_fields config to explicitly configure permitting an unknown field on Message initialization --- lib/protobuf.rb | 13 ++++++++ lib/protobuf/message.rb | 8 +++-- spec/lib/protobuf/message_spec.rb | 49 +++++++++++++++++++++++++++++++ spec/lib/protobuf_spec.rb | 20 +++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 913e6601..4520ae06 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -83,6 +83,19 @@ def self.print_deprecation_warnings=(value) @_print_deprecation_warnings = !!value end + # Permit unknown field on Message initialization + # + # Default: true + # + # Simple boolean to define whether we want to permit unknown fields + # on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown. + def self.ignore_unknown_fields? + !defined?(@_ignore_unknown_fields) || @_ignore_unknown_fields + end + + def self.ignore_unknown_fields=(value) + @_ignore_unknown_fields = !!value + end end unless ENV.key?('PB_NO_NETWORKING') diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 71caf733..c7aad381 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -30,7 +30,7 @@ def initialize(fields = {}) @values = {} fields.to_hash.each_pair do |name, value| - self[name] = value unless value.nil? + self[name] = value end end @@ -135,7 +135,11 @@ def [](name) def []=(name, value) if field = self.class.get_field(name, true) - __send__(field.setter_method_name, value) + __send__(field.setter_method_name, value) unless value.nil? + else + unless ::Protobuf.ignore_unknown_fields? + raise ::Protobuf::FieldNotDefinedError, name + end end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 17fdbce0..2ec20ac3 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -157,6 +157,55 @@ test_enum = Test::EnumTestMessage.new(hashie_object) expect(test_enum.non_default_enum).to eq(2) end + + context 'ignoring unknown fields' do + before { ::Protobuf.ignore_unknown_fields = true } + + context 'with valid fields' do + let(:values) { { :name => "Jim" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + + context 'with non-existent field' do + let(:values) { { :name => "Jim", :othername => "invalid" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + end + + context 'not ignoring unknown fields' do + before { ::Protobuf.ignore_unknown_fields = false } + after { ::Protobuf.ignore_unknown_fields = true } + + context 'with valid fields' do + let(:values) { { :name => "Jim" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + + context 'with non-existent field' do + let(:values) { { :name => "Jim", :othername => "invalid" } } + + it "raises an error and mentions the erroneous field" do + expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) + end + + context 'with a nil value' do + let(:values) { { :name => "Jim", :othername => nil } } + + it "raises an error and mentions the erroneous field" do + expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) + end + end + end + end end describe '#encode' do diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 458bcde8..a484dc57 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -75,4 +75,24 @@ end end + describe '.ignore_unknown_fields?' do + before do + if described_class.instance_variable_defined?(:@_ignore_unknown_fields) + described_class.send(:remove_instance_variable, :@_ignore_unknown_fields) + end + end + + it 'defaults to a true value' do + expect(described_class.ignore_unknown_fields?).to be true + end + + it 'is settable' do + expect { + described_class.ignore_unknown_fields = false + }.to change { + described_class.ignore_unknown_fields? + }.from(true).to(false) + end + end + end From 1864c9b19b13640ae3655a67cd612cb5164f1447 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 1 Aug 2014 17:02:55 -0600 Subject: [PATCH 0699/1191] Bump version 3.2.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index d7d20206..9a30eed9 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.1.0' + VERSION = '3.2.0' end From 7a2e36ce58373971cb1ca87541426ab87cbbc732 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:00:40 -0700 Subject: [PATCH 0700/1191] use stronger boolean rspec matchers --- spec/lib/protobuf/cli_spec.rb | 12 +++++----- spec/lib/protobuf/enum_spec.rb | 10 ++++---- spec/lib/protobuf/message_spec.rb | 22 ++++++++--------- spec/lib/protobuf/optionable_spec.rb | 2 +- .../protobuf/rpc/connectors/common_spec.rb | 24 +++++++++---------- .../protobuf/rpc/connectors/socket_spec.rb | 10 ++++---- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 8 +++---- .../protobuf/rpc/servers/zmq/server_spec.rb | 6 ++--- spec/lib/protobuf/rpc/service_spec.rb | 4 ++-- spec/lib/protobuf_spec.rb | 10 ++++---- 10 files changed, 54 insertions(+), 54 deletions(-) diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index c33dba9a..9d8280c1 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -128,7 +128,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_truthy + expect(::Protobuf.print_deprecation_warnings?).to be true end end @@ -138,7 +138,7 @@ it 'sets the deprecation warning flag to false ' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_falsey + expect(::Protobuf.print_deprecation_warnings?).to be false end end end @@ -148,7 +148,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_truthy + expect(::Protobuf.print_deprecation_warnings?).to be true end end @@ -157,7 +157,7 @@ it 'sets the deprecation warning flag to false' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_falsey + expect(::Protobuf.print_deprecation_warnings?).to be false end end end @@ -200,7 +200,7 @@ it 'is activated by the --workers_only switch' do expect(runner).to receive(:new) do |options| - expect(options[:workers_only]).to be_truthy + expect(options[:workers_only]).to be true end.and_return(zmq_runner) described_class.start(args) @@ -209,7 +209,7 @@ it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do ENV['PB_WORKERS_ONLY'] = "1" expect(runner).to receive(:new) do |options| - expect(options[:workers_only]).to be_truthy + expect(options[:workers_only]).to be true end.and_return(zmq_runner) described_class.start(args) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 21ebfdd0..3c280fbd 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -21,8 +21,8 @@ end describe '.aliases_allowed?' do - it 'is false when the option is not set' do - expect(Test::EnumTestType.aliases_allowed?).to be_falsey + it 'is nil when the option is not set' do + expect(Test::EnumTestType.aliases_allowed?).to be nil end end @@ -155,15 +155,15 @@ describe '.valid_tag?' do context 'when tag is defined' do - specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_truthy } + specify { expect(Test::EnumTestType.valid_tag?(tag)).to be true } end context 'when tag is not defined' do - specify { expect(Test::EnumTestType.valid_tag?(300)).to be_falsey } + specify { expect(Test::EnumTestType.valid_tag?(300)).to be false } end context 'is true for aliased enums' do - specify { expect(EnumAliasTest.valid_tag?(1)).to be_truthy } + specify { expect(EnumAliasTest.valid_tag?(1)).to be true } end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 2ec20ac3..3a3ea913 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -222,7 +222,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - expect(new_message.name == name).to be_truthy + expect(new_message.name == name).to be true end it "trims binary when binary is input for string fields" do @@ -231,7 +231,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - expect(new_message.name == "my name").to be_truthy + expect(new_message.name == "my name").to be true end end @@ -287,12 +287,12 @@ it "sets the predicate to true when the boolean value is true" do subject.active = true - expect(subject.active?).to be_truthy + expect(subject.active?).to be true end it "sets the predicate to false when the boolean value is false" do subject.active = false - expect(subject.active?).to be_falsey + expect(subject.active?).to be false end it "does not put predicate methods on non-boolean fields" do @@ -304,11 +304,11 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - expect(subject.respond_to_and_has?(:other_field)).to be_falsey + expect(subject.respond_to_and_has?(:other_field)).to be false end it "is true when the message has the field" do - expect(subject.respond_to_and_has?(:non_default_enum)).to be_truthy + expect(subject.respond_to_and_has?(:non_default_enum)).to be true end end @@ -316,25 +316,25 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - expect(subject.respond_to_and_has_and_present?(:other_field)).to be_falsey + expect(subject.respond_to_and_has_and_present?(:other_field)).to be false end it "is false when the field is repeated and a value is not present" do - expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be false end it "is false when the field is repeated and the value is empty array" do subject.repeated_enums = [] - expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be false end it "is true when the field is repeated and a value is present" do subject.repeated_enums = [2] - expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_truthy + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be true end it "is true when the message has the field" do - expect(subject.respond_to_and_has_and_present?(:non_default_enum)).to be_truthy + expect(subject.respond_to_and_has_and_present?(:non_default_enum)).to be true end context "#API" do diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index f65eca6c..d6237f14 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -20,7 +20,7 @@ it 'defaults the value to true' do OptionableSetOptionTest.set_option(:baz_enabled) - expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_truthy + expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be true end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 8f814a7f..ce839263 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -15,15 +15,15 @@ subject { @subject ||= common_class.new(subject_options) } context "API" do - specify { expect(subject.respond_to?(:any_callbacks?)).to be_truthy } - specify { expect(subject.respond_to?(:request_caller)).to be_truthy } - specify { expect(subject.respond_to?(:data_callback)).to be_truthy } - specify { expect(subject.respond_to?(:error)).to be_truthy } - specify { expect(subject.respond_to?(:fail)).to be_truthy } - specify { expect(subject.respond_to?(:complete)).to be_truthy } - specify { expect(subject.respond_to?(:parse_response)).to be_truthy } - specify { expect(subject.respond_to?(:verify_options!)).to be_truthy } - specify { expect(subject.respond_to?(:verify_callbacks)).to be_truthy } + specify { expect(subject.respond_to?(:any_callbacks?)).to be true } + specify { expect(subject.respond_to?(:request_caller)).to be true } + specify { expect(subject.respond_to?(:data_callback)).to be true } + specify { expect(subject.respond_to?(:error)).to be true } + specify { expect(subject.respond_to?(:fail)).to be true } + specify { expect(subject.respond_to?(:complete)).to be true } + specify { expect(subject.respond_to?(:parse_response)).to be true } + specify { expect(subject.respond_to?(:verify_options!)).to be true } + specify { expect(subject.respond_to?(:verify_callbacks)).to be true } end describe "#any_callbacks?" do @@ -31,7 +31,7 @@ [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| it "returns true if #{cb} is provided" do subject.instance_variable_set(cb, "something") - expect(subject.any_callbacks?).to be_truthy + expect(subject.any_callbacks?).to be true end end @@ -40,7 +40,7 @@ subject.instance_variable_set(:@success_cb, nil) subject.instance_variable_set(:@failure_cb, nil) - expect(subject.any_callbacks?).to be_falsey + expect(subject.any_callbacks?).to be false end end @@ -60,7 +60,7 @@ describe "#data_callback" do it "changes state to use the data callback" do subject.data_callback("data") - expect(subject.instance_variable_get(:@used_data_callback)).to be_truthy + expect(subject.instance_variable_get(:@used_data_callback)).to be true end it "sets the data var when using the data_callback" do diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index ff18c2ee..38aeea2a 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -6,10 +6,10 @@ context "API" do # Check the API - specify { expect(subject.respond_to?(:send_request, true)).to be_truthy } - specify { expect(subject.respond_to?(:post_init, true)).to be_truthy } - specify { expect(subject.respond_to?(:close_connection, true)).to be_truthy } - specify { expect(subject.respond_to?(:error?, true)).to be_truthy } + specify { expect(subject.respond_to?(:send_request, true)).to be true } + specify { expect(subject.respond_to?(:post_init, true)).to be true } + specify { expect(subject.respond_to?(:close_connection, true)).to be true } + specify { expect(subject.respond_to?(:error?, true)).to be true } end end @@ -18,7 +18,7 @@ it_behaves_like "a Protobuf Connector" - specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be_truthy } + specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be true } context "#read_response" do let(:data) { "New data" } diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 707033c8..16bd8ca4 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -79,7 +79,7 @@ end it "returns true" do - expect(subject.send(:host_alive?, "yip.yip")).to be_truthy + expect(subject.send(:host_alive?, "yip.yip")).to be true end it "does not attempt a connection" do @@ -95,19 +95,19 @@ it "returns true when the connection succeeds" do expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil)) - expect(subject.send(:host_alive?, "huzzah.com")).to be_truthy + expect(subject.send(:host_alive?, "huzzah.com")).to be true end it "returns false when the connection fails" do expect(TCPSocket).to receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) - expect(subject.send(:host_alive?, "hayoob.com")).to be_falsey + expect(subject.send(:host_alive?, "hayoob.com")).to be false end it "closes the socket" do socket = double("TCPSocket") expect(socket).to receive(:close) expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) - expect(subject.send(:host_alive?, "absorbalof.com")).to be_truthy + expect(subject.send(:host_alive?, "absorbalof.com")).to be true end end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 9a8df8ce..0fbb0024 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -22,12 +22,12 @@ describe '.running?' do it 'returns true if running' do subject.instance_variable_set(:@running, true) - expect(subject.running?).to be_truthy + expect(subject.running?).to be true end it 'returns false if not running' do subject.instance_variable_set(:@running, false) - expect(subject.running?).to be_falsey + expect(subject.running?).to be false end end @@ -35,7 +35,7 @@ it 'sets running to false' do subject.instance_variable_set(:@workers, []) subject.stop - expect(subject.instance_variable_get(:@running)).to be_falsey + expect(subject.instance_variable_get(:@running)).to be false end end end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 1cef20be..545e90ee 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -85,13 +85,13 @@ context 'when given name is a pre-defined rpc method' do it 'returns true' do - expect(subject.rpc_method?(:delete)).to be_truthy + expect(subject.rpc_method?(:delete)).to be true end end context 'when given name is not a pre-defined rpc method' do it 'returns false' do - expect(subject.rpc_method?(:zoobaboo)).to be_falsey + expect(subject.rpc_method?(:zoobaboo)).to be false end end end diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index a484dc57..3c79956f 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -46,12 +46,12 @@ before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) } it 'defaults to a false value' do - expect(described_class.gc_pause_server_request?).to be_falsey + expect(described_class.gc_pause_server_request?).to be false end it 'is settable' do described_class.gc_pause_server_request = true - expect(described_class.gc_pause_server_request?).to be_truthy + expect(described_class.gc_pause_server_request?).to be true end end @@ -59,18 +59,18 @@ before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) } it 'defaults to a true value' do - expect(described_class.print_deprecation_warnings?).to be_truthy + expect(described_class.print_deprecation_warnings?).to be true end it 'is settable' do described_class.print_deprecation_warnings = false - expect(described_class.print_deprecation_warnings?).to be_falsey + expect(described_class.print_deprecation_warnings?).to be false end context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do it 'defaults to a false value' do ENV['PB_IGNORE_DEPRECATIONS'] = '1' - expect(described_class.print_deprecation_warnings?).to be_falsey + expect(described_class.print_deprecation_warnings?).to be false end end end From bdede9a660703764edda987b048d24fcc9456abd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:03:50 -0700 Subject: [PATCH 0701/1191] remove unneeded custom matcher --- spec/spec_helper.rb | 1 - spec/support/all.rb | 1 - spec/support/tolerance_matcher.rb | 40 ------------------------------- 3 files changed, 42 deletions(-) delete mode 100644 spec/support/tolerance_matcher.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f2e3efbf..07b4c16b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,6 @@ ENV.delete("PB_IGNORE_DEPRECATIONS") ::RSpec.configure do |c| - c.include(::Sander6::CustomMatchers) c.mock_with :rspec c.before(:suite) do diff --git a/spec/support/all.rb b/spec/support/all.rb index 8cde33a9..889143a5 100644 --- a/spec/support/all.rb +++ b/spec/support/all.rb @@ -1,5 +1,4 @@ require 'support/packed_field' -require 'support/tolerance_matcher' require 'support/server' def now diff --git a/spec/support/tolerance_matcher.rb b/spec/support/tolerance_matcher.rb deleted file mode 100644 index 50eba4eb..00000000 --- a/spec/support/tolerance_matcher.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# courtesy of sander 6 -# - http://github.com/sander6/custom_matchers/blob/master/lib/matchers/tolerance_matchers.rb -# -module Sander6 - module CustomMatchers - - class ToleranceMatcher - def initialize(tolerance) - @tolerance = tolerance - @target = 0 - end - - def of(target) - @target = target - self - end - - def matches?(value) - @value = value - ((@target - @tolerance)..(@target + @tolerance)).include?(@value) - end - - def failure_message - "Expected #{@value.inspect} to be within #{@tolerance.inspect} of #{@target.inspect}, but it wasn't.\n" + - "Difference: #{@value - @target}" - end - - def negative_failure_message - "Expected #{@value.inspect} not to be within #{@tolerance.inspect} of #{@target.inspect}, but it was.\n" + - "Difference: #{@value - @target}" - end - end - - def be_within(value) - Sander6::CustomMatchers::ToleranceMatcher.new(value) - end - - end -end From 0887cf4f8a575323b5d7fbdcab65e99e3ca87718 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:07:53 -0700 Subject: [PATCH 0702/1191] remove unused dependency --- protobuf.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index da98eee5..bfec5bdb 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -21,7 +21,6 @@ require "protobuf/version" s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'middleware' - s.add_dependency 'multi_json' s.add_dependency 'thor' s.add_development_dependency 'ffi-rzmq' From c4eda8e9862b4734172c92f76e264ccebbe120d5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:09:49 -0700 Subject: [PATCH 0703/1191] Convert specs to RSpec 3.0.3 syntax with Transpec This conversion is done by Transpec 2.3.6 with the following command: transpec -b true,false -f -s * 11 conversions from: it { should ... } to: it { is_expected.to ... } * 1 conversion from: obj.should to: expect(obj).to For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/bin/protoc-gen-ruby_spec.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 2 +- spec/lib/protobuf/logger_spec.rb | 14 +++++++------- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf_spec.rb | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb index a38f165f..36cd7add 100644 --- a/spec/bin/protoc-gen-ruby_spec.rb +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -11,7 +11,7 @@ it 'reads the serialized request bytes and outputs serialized response bytes' do ::IO.popen(binpath, 'w+') do |pipe| pipe.write(request_bytes) - pipe.read(expected_response_bytes.size).should eq expected_response_bytes + expect(pipe.read(expected_response_bytes.size)).to eq expected_response_bytes end end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 3c280fbd..3de2ab40 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -230,7 +230,7 @@ context 'when coercing from enum' do subject { Test::StatusType::PENDING } - it { should eq(0) } + it { is_expected.to eq(0) } end context 'when coercing from integer' do diff --git a/spec/lib/protobuf/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb index 15eaaebe..6a28aa3f 100644 --- a/spec/lib/protobuf/logger_spec.rb +++ b/spec/lib/protobuf/logger_spec.rb @@ -104,13 +104,13 @@ class MyTestClass subject { MyTestClass.new } - it { should respond_to(:log_debug) } - it { should respond_to(:log_info) } - it { should respond_to(:log_warn) } - it { should respond_to(:log_error) } - it { should respond_to(:log_fatal) } - it { should respond_to(:log_add) } - it { should respond_to(:log_log) } + it { is_expected.to respond_to(:log_debug) } + it { is_expected.to respond_to(:log_info) } + it { is_expected.to respond_to(:log_warn) } + it { is_expected.to respond_to(:log_error) } + it { is_expected.to respond_to(:log_fatal) } + it { is_expected.to respond_to(:log_add) } + it { is_expected.to respond_to(:log_log) } context '#log_exception' do it 'logs the exception message as an error and backtrace as debug' do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 3a3ea913..313cc886 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -283,7 +283,7 @@ describe "boolean predicate methods" do subject { Test::ResourceFindRequest.new(:name => "resource") } - it { should respond_to(:active?) } + it { is_expected.to respond_to(:active?) } it "sets the predicate to true when the boolean value is true" do subject.active = true diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 3c79956f..b828f53c 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -9,13 +9,13 @@ subject { ::Protobuf.client_host } context 'when client_host is not pre-configured' do - it { should eq `hostname`.chomp } + it { is_expected.to eq `hostname`.chomp } end context 'when client_host is pre-configured' do let(:hostname) { 'override.myhost.com' } before { ::Protobuf.client_host = hostname } - it { should eq hostname } + it { is_expected.to eq hostname } end end From c26af1441f28571adeb9ec5228bb45e89d1a61b8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:39:03 -0700 Subject: [PATCH 0704/1191] prefer constants to strings --- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/field/string_field.rb | 2 +- spec/lib/protobuf/message_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 7505d6e5..ae669e64 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -8,7 +8,7 @@ class BytesField < BaseField # Constants # - BYTES_ENCODING = "ASCII-8BIT".freeze + BYTES_ENCODING = Encoding::BINARY ## # Class Methods diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 7861e128..83fbd4ae 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -8,7 +8,7 @@ class StringField < BytesField # Constants # - ENCODING = 'UTF-8'.freeze + ENCODING = Encoding::UTF_8 ## # Public Instance Methods diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 2ec20ac3..777eb373 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -218,7 +218,7 @@ it "keeps utf-8 when utf-8 is input for string fields" do name = "my name\xC3" - name.force_encoding("UTF-8") + name.force_encoding(Encoding::UTF_8) message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) @@ -227,7 +227,7 @@ it "trims binary when binary is input for string fields" do name = "my name\xC3" - name.force_encoding("ASCII-8BIT") + name.force_encoding(Encoding::BINARY) message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) From e706e76c9e2f1ed888e03df1735723cbdceb37fd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:39:20 -0700 Subject: [PATCH 0705/1191] Use valid UTF-8 in UTF-8 spec Fixes #191 --- spec/lib/protobuf/message_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 777eb373..e4346623 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require 'spec_helper' describe Protobuf::Message do @@ -217,7 +219,7 @@ end it "keeps utf-8 when utf-8 is input for string fields" do - name = "my name\xC3" + name = 'my name💩' name.force_encoding(Encoding::UTF_8) message = ::Test::Resource.new(:name => name) From c037b007702f15f18a40f73874d6be26c966ddea Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 12:07:00 -0700 Subject: [PATCH 0706/1191] use methods instead of mutable state --- lib/protobuf/field/base_field.rb | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 739e1aaa..c650b498 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -20,8 +20,8 @@ class BaseField # attr_reader :default, :default_value, :deprecated, :extension, - :getter_method_name, :message_class, :name, :optional, - :packed, :repeated, :required, :rule, :setter_method_name, + :getter_method_name, :message_class, :name, + :packed, :rule, :setter_method_name, :tag, :type_class ## @@ -40,8 +40,6 @@ def initialize(message_class, rule, type_class, name, tag, options) @message_class, @rule, @type_class, @name, @tag = \ message_class, rule, type_class, name, tag - set_rule_predicates - @getter_method_name = name @setter_method_name = "#{name}=" @default = options.delete(:default) @@ -116,7 +114,7 @@ def extension? # Is this a repeated field? def repeated? - !! repeated + rule == :repeated end # Is this a repeated message field? @@ -126,12 +124,12 @@ def repeated_message? # Is this a required field? def required? - !! required + rule == :required end - # Is this a optional field? + # Is this an optional field? def optional? - !! optional + rule == :optional end # Is this a deprecated field? @@ -246,20 +244,6 @@ def set_default_value end end - def set_rule_predicates - case rule - when :repeated then - @required = @optional = false - @repeated = true - when :required then - @repeated = @optional = false - @required = true - when :optional then - @repeated = @required = false - @optional = true - end - end - def typed_default_value if default.nil? self.class.default From f809b9c52e25fb2eea69d0151076ecabe1198cd8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 12:07:19 -0700 Subject: [PATCH 0707/1191] use default method instead of mutable state --- lib/protobuf/field/base_field.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index c650b498..78f63576 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -19,7 +19,7 @@ class BaseField # Attributes # - attr_reader :default, :default_value, :deprecated, :extension, + attr_reader :default, :deprecated, :extension, :getter_method_name, :message_class, :name, :packed, :rule, :setter_method_name, :tag, :type_class @@ -47,7 +47,6 @@ def initialize(message_class, rule, type_class, name, tag, options) @packed = repeated? && options.delete(:packed) @deprecated = options.delete(:deprecated) - set_default_value warn_excess_options(options) unless options.empty? validate_packed_field if packed? define_accessor @@ -73,6 +72,14 @@ def message? false end + def default_value + @default_value ||= case + when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze + when required? then nil + when optional? then typed_default_value + end + end + # Decode +bytes+ and pass to +message_instance+. def set(message_instance, bytes) if packed? @@ -236,14 +243,6 @@ def define_setter end end - def set_default_value - @default_value = case - when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze - when required? then nil - when optional? then typed_default_value - end - end - def typed_default_value if default.nil? self.class.default From 1610fbfe07ce071d8778556d8905d662c9e4ce35 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 4 Aug 2014 16:17:39 -0600 Subject: [PATCH 0708/1191] More state cleanup in BaseField, alphabetizing Alphabetize all methods in BaseField. Rather than deleting values out of the options hash, reference the hash from predicate functions. Rename `getter_method_name` and `setter_method_name` to simpler `getter` and `setter`. Remove the excess options warning since we are generating all field definitions. --- lib/protobuf/field/base_field.rb | 135 +++++++++++++++--------------- lib/protobuf/field/bool_field.rb | 2 +- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/message.rb | 8 +- 4 files changed, 72 insertions(+), 75 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 78f63576..6a13e6d9 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -19,10 +19,7 @@ class BaseField # Attributes # - attr_reader :default, :deprecated, :extension, - :getter_method_name, :message_class, :name, - :packed, :rule, :setter_method_name, - :tag, :type_class + attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## # Class Methods @@ -37,17 +34,13 @@ def self.default # def initialize(message_class, rule, type_class, name, tag, options) - @message_class, @rule, @type_class, @name, @tag = \ - message_class, rule, type_class, name, tag + @message_class = message_class + @name = name + @rule = rule + @tag = tag + @type_class = type_class + @options = options - @getter_method_name = name - @setter_method_name = "#{name}=" - @default = options.delete(:default) - @extension = options.delete(:extension) - @packed = repeated? && options.delete(:packed) - @deprecated = options.delete(:deprecated) - - warn_excess_options(options) unless options.empty? validate_packed_field if packed? define_accessor end @@ -64,12 +57,12 @@ def coerce!(value) value end - def enum? - false + def decode(bytes) + raise NotImplementedError, "#{self.class.name}\#decode" end - def message? - false + def default + options[:default] end def default_value @@ -80,73 +73,77 @@ def default_value end end - # Decode +bytes+ and pass to +message_instance+. - def set(message_instance, bytes) - if packed? - array = message_instance.__send__(getter_method_name) - method = \ - case wire_type - when ::Protobuf::WireType::FIXED32 then :read_fixed32 - when ::Protobuf::WireType::FIXED64 then :read_fixed64 - when ::Protobuf::WireType::VARINT then :read_varint - end - stream = StringIO.new(bytes) - - until stream.eof? - array << decode(::Protobuf::Decoder.__send__(method, stream)) - end - else - value = decode(bytes) - if repeated? - message_instance.__send__(getter_method_name) << value - else - message_instance.__send__(setter_method_name, value) - end - end - end - - # Decode +bytes+ and return a field value. - def decode(bytes) - raise NotImplementedError, "#{self.class.name}\#decode" + def deprecated? + options.key?(:deprecated) end - # Encode +value+ and return a byte string. def encode(value) raise NotImplementedError, "#{self.class.name}\#encode" end def extension? - !! extension + options.key?(:extension) + end + + def enum? + false + end + + def getter + name + end + + def message? + false + end + + def optional? + rule == :optional + end + + def packed? + repeated? && options.key?(:packed) end - # Is this a repeated field? def repeated? rule == :repeated end - # Is this a repeated message field? def repeated_message? repeated? && message? end - # Is this a required field? def required? rule == :required end - # Is this an optional field? - def optional? - rule == :optional - end + # Decode +bytes+ and pass to +message_instance+. + def set(message_instance, bytes) + if packed? + array = message_instance.__send__(getter) + method = \ + case wire_type + when ::Protobuf::WireType::FIXED32 then :read_fixed32 + when ::Protobuf::WireType::FIXED64 then :read_fixed64 + when ::Protobuf::WireType::VARINT then :read_varint + end + stream = StringIO.new(bytes) - # Is this a deprecated field? - def deprecated? - !! deprecated + until stream.eof? + array << decode(::Protobuf::Decoder.__send__(method, stream)) + end + else + value = decode(bytes) + if repeated? + message_instance.__send__(getter) << value + else + message_instance.__send__(setter, value) + end + end end - # Is this a packed repeated field? - def packed? - !! packed + def setter + @setter ||= "#{name}=" end def to_s @@ -164,6 +161,10 @@ def warn_if_deprecated end end + def wire_type + ::Protobuf::WireType::VARINT + end + private ## @@ -183,7 +184,7 @@ def define_accessor def define_array_getter field = self message_class.class_eval do - define_method(field.getter_method_name) do + define_method(field.getter) do field.warn_if_deprecated @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) end @@ -193,7 +194,7 @@ def define_array_getter def define_array_setter field = self message_class.class_eval do - define_method(field.setter_method_name) do |val| + define_method(field.setter) do |val| field.warn_if_deprecated if val.is_a?(Array) @@ -219,7 +220,7 @@ def define_array_setter def define_getter field = self message_class.class_eval do - define_method(field.getter_method_name) do + define_method(field.getter) do field.warn_if_deprecated @values.fetch(field.name, field.default_value) end @@ -229,7 +230,7 @@ def define_getter def define_setter field = self message_class.class_eval do - define_method(field.setter_method_name) do |val| + define_method(field.setter) do |val| field.warn_if_deprecated if val.nil? || (val.respond_to?(:empty?) && val.empty?) @@ -257,10 +258,6 @@ def validate_packed_field end end - def warn_excess_options(options) - warn "WARNING: Invalid options: #{options.inspect} (in #{message_class.name}##{name})" - end - end end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 0827b17d..a002bbf7 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -40,7 +40,7 @@ def define_getter field = self message_class.class_eval do - define_method("#{field.getter_method_name}?") do + define_method("#{field.getter}?") do field.warn_if_deprecated @values.fetch(field.name, field.default_value) end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index ae669e64..6f7c86c4 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -54,7 +54,7 @@ def wire_type def define_setter field = self message_class.class_eval do - define_method(field.setter_method_name) do |val| + define_method(field.setter) do |val| begin field.warn_if_deprecated val = "#{val}" if val.is_a?(Symbol) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c7aad381..4d1df27c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -62,7 +62,7 @@ def dup # def each_field self.class.all_fields.each do |field| - value = __send__(field.name) + value = __send__(field.getter) yield(field, value) end end @@ -71,7 +71,7 @@ def each_field_for_serialization self.class.all_fields.each do |field| next unless field_must_be_serialized?(field) - value = @values[field.name] + value = @values[field.getter] if value.nil? raise ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." @@ -129,13 +129,13 @@ def ==(obj) def [](name) if field = self.class.get_field(name, true) - __send__(field.name) + __send__(field.getter) end end def []=(name, value) if field = self.class.get_field(name, true) - __send__(field.setter_method_name, value) unless value.nil? + __send__(field.setter, value) unless value.nil? else unless ::Protobuf.ignore_unknown_fields? raise ::Protobuf::FieldNotDefinedError, name From c6e013dfba52d76d5a149b403e9bb0e1ee0f069f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 4 Aug 2014 16:37:10 -0600 Subject: [PATCH 0709/1191] Add FIXME comments to BaseField --- lib/protobuf/field/base_field.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 6a13e6d9..378daa1c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -117,7 +117,7 @@ def required? rule == :required end - # Decode +bytes+ and pass to +message_instance+. + # FIXME need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) if packed? array = message_instance.__send__(getter) @@ -146,6 +146,7 @@ def setter @setter ||= "#{name}=" end + # FIXME add packed, deprecated, extension options to to_s output def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end From 9486341f0a32e908dba325deb2216b7059f7e94e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 4 Aug 2014 16:37:58 -0600 Subject: [PATCH 0710/1191] Bump version 3.2.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9a30eed9..da2f061f 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.2.0' + VERSION = '3.2.1' end From 406ce63e10175ccfb9199167e41400aea811ce36 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Sat, 23 Aug 2014 14:06:39 -0600 Subject: [PATCH 0711/1191] Make logging a pluggable component of Protobuf This refactors logging to make the logger a pluggable component of Protobuf. The logger can be changed by using `::Protobuf::Logging.logger = new_logger`. Any object that complies with the API of the ruby standard logger may be used. All the spec's in spec/lib are passing. I had some errors in the zmq library when trying to run the others. I also uncovered a bug that appears when running specs with DEBUG=1. The `RequestDecoder` and the `ResponseDecoder` referred to `env.signature` when they should have been referring to `env.log_signature`. That is now fixed. I used the logging in [mperham's sidekiq](https://github.com/mperham/sidekiq) as a reference. --- lib/protobuf/cli.rb | 30 ++-- lib/protobuf/field/base_field.rb | 4 +- lib/protobuf/field/bytes_field.rb | 4 +- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/logger.rb | 86 ----------- lib/protobuf/logging.rb | 49 +++++++ lib/protobuf/rpc/client.rb | 20 +-- lib/protobuf/rpc/connectors/base.rb | 4 +- lib/protobuf/rpc/connectors/common.rb | 24 ++-- lib/protobuf/rpc/connectors/socket.rb | 12 +- lib/protobuf/rpc/connectors/zmq.rb | 18 +-- .../rpc/middleware/exception_handler.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 2 +- .../rpc/middleware/request_decoder.rb | 6 +- .../rpc/middleware/response_encoder.rb | 6 +- lib/protobuf/rpc/server.rb | 2 +- lib/protobuf/rpc/servers/socket/server.rb | 14 +- lib/protobuf/rpc/servers/socket/worker.rb | 4 +- lib/protobuf/rpc/servers/zmq/server.rb | 6 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- lib/protobuf/rpc/servers/zmq_runner.rb | 8 +- lib/protobuf/rpc/service.rb | 4 +- lib/protobuf/rpc/service_directory.rb | 16 +-- lib/protobuf/rpc/service_dispatcher.rb | 4 +- lib/protobuf/rpc/stat.rb | 2 +- spec/benchmark/tasks.rb | 4 +- spec/lib/protobuf/cli_spec.rb | 12 +- spec/lib/protobuf/logger_spec.rb | 136 ------------------ spec/spec_helper.rb | 11 +- spec/support/server.rb | 6 +- 30 files changed, 170 insertions(+), 330 deletions(-) delete mode 100644 lib/protobuf/logger.rb create mode 100644 lib/protobuf/logging.rb delete mode 100644 spec/lib/protobuf/logger_spec.rb diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 01f92af8..ad0716c6 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,12 +1,13 @@ require 'thor' require 'protobuf/version' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq_runner' module Protobuf class CLI < ::Thor include ::Thor::Actions + include ::Protobuf::Logging attr_accessor :runner, :mode @@ -21,7 +22,7 @@ class CLI < ::Thor option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' option :threads, :type => :numeric, :default => 5, :aliases => %w(-r), :desc => 'Number of worker threads to run. Only applicable in --zmq mode.' - option :log, :type => :string, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' + option :log, :type => :string, :default => STDOUT, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' 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/)' option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.' @@ -86,12 +87,14 @@ def configure_gc # Setup the protobuf logger. def configure_logger debug_say('Configuring logger') - ::Protobuf::Logger.configure({ :file => options.log || STDOUT, - :level => options.debug? ? ::Logger::DEBUG : options.level }) + + log_level = options.debug? ? ::Logger::DEBUG : options.level + + ::Protobuf::Logging.initialize_logger(options.log, log_level) # Debug output the server options to the log file. - ::Protobuf::Logger.debug { 'Debugging options:' } - ::Protobuf::Logger.debug { options.inspect } + logger.debug { 'Debugging options:' } + logger.debug { options.inspect } end # Re-write the $0 var to have a nice process name in ps. @@ -185,15 +188,16 @@ def runner_options end def say_and_exit(message, exception = nil) - message = set_color(message, :red) if ::Protobuf::Logger.file == STDOUT + message = set_color(message, :red) if options.log == STDOUT + + logger.error { message } - ::Protobuf::Logger.error { message } if exception $stderr.puts "[#{exception.class.name}] #{exception.message}" $stderr.puts exception.backtrace.join("\n") - ::Protobuf::Logger.error { "[#{exception.class.name}] #{exception.message}" } - ::Protobuf::Logger.debug { exception.backtrace.join("\n") } + logger.error { "[#{exception.class.name}] #{exception.message}" } + logger.debug { exception.backtrace.join("\n") } end exit(1) @@ -212,10 +216,10 @@ def create_zmq_runner end def shutdown_server - ::Protobuf::Logger.info { 'RPC Server shutting down...' } + logger.info { 'RPC Server shutting down...' } @runner.try(:stop) ::Protobuf::Rpc::ServiceDirectory.instance.stop - ::Protobuf::Logger.info { 'Shutdown complete' } + logger.info { 'Shutdown complete' } end # Start the runner and log the relevant options. @@ -223,7 +227,7 @@ def start_server debug_say('Running server') @runner.run do - ::Protobuf::Logger.info { + logger.info { "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" } diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 378daa1c..b688f180 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,9 +1,11 @@ -require 'protobuf/wire_type' require 'protobuf/field/field_array' +require 'protobuf/logging' +require 'protobuf/wire_type' module Protobuf module Field class BaseField + include ::Protobuf::Logging ## # Constants diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 6f7c86c4..6b7e6c17 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -67,8 +67,8 @@ def define_setter raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end rescue NoMethodError => ex - ::Protobuf::Logger.error { ex.message } - ::Protobuf::Logger.error { ex.backtrace.join("\n") } + logger.error { ex.message } + logger.error { ex.backtrace.join("\n") } raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 145784b6..b1c2fa2c 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -1,6 +1,6 @@ module Protobuf class Lifecycle - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def self.register(event_name, &blk) raise "Lifecycle register must have a block" unless block_given? diff --git a/lib/protobuf/logger.rb b/lib/protobuf/logger.rb deleted file mode 100644 index 30397c27..00000000 --- a/lib/protobuf/logger.rb +++ /dev/null @@ -1,86 +0,0 @@ -require 'logger' - -module Protobuf - class Logger < ::Logger - - class << self - attr_accessor :file, :level - - # Stub out the log methods for Protobuf::Logger as singleton methods - [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| - define_method(m) do |*params, &block| - instance && instance.__send__(m, *params, &block) - end - end - end - - # One-line file/level configuration - def self.configure(options) - self.file = options.fetch(:file, false) - self.level = options.fetch(:level, false) - end - - # Use to reset the instance - def self.reset_device! - self.file = self.level = @__instance = nil - end - - # Singleton instance - def self.instance - @__instance ||= begin - log = nil - - if @file && @level - log = new(self.file) - log.level = self.level - end - - log - end - end - - # - # LogMethods module for log method including, e.g.: - # - # class MyClass - # include Protobuf::Logger::LogMethods - # ... - # end - # - # Produce a module to allow "include" in other classes to avoid - # cluttering the namespace of the including class with the other methods defined above - # - module LogMethods - [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| - define_method("log_#{m}") do |*params, &block| - params.map! { |message| sign_message(message) } - ::Protobuf::Logger.__send__(m, *params, &block) - end - end - - # When included, also extend the LogMethods module for class access. - def self.included(base) - base.extend(LogMethods) - end - - # We often want to log an exception, so let's make that a core - # concern of the logger. - # - def log_exception(ex) - log_error { ex.message } - log_error { ex.backtrace[0..5].join("\n") } - log_debug { ex.backtrace.join("\n") } - end - - def log_signature - @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]" - end - - def sign_message(message) - "#{log_signature} #{message}" - end - - end - - end -end diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb new file mode 100644 index 00000000..47f5b8f3 --- /dev/null +++ b/lib/protobuf/logging.rb @@ -0,0 +1,49 @@ +module Protobuf + module Logging + def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) + @counter ||= 0 + @counter = @counter + 1 + old_logger = defined?(@logger) ? @logger : nil + @logger = Logger.new(log_target) + @logger.level = log_level + old_logger.close if old_logger and close_old_logger? + @logger + end + + def self.close_old_logger=(boolean) + @close_old_logger = !!boolean + end + + def self.close_old_logger? + defined?(@close_old_logger) ? @close_old_logger : true + end + + def self.logger + defined?(@logger) ? @logger : initialize_logger + end + + def self.logger=(new_logger) + @logger = new_logger + end + + def logger + ::Protobuf::Logging.logger + end + + def log_exception(ex) + logger.error { ex.message } + logger.error { ex.backtrace[0..5].join("\n") } + logger.debug { ex.backtrace.join("\n") } + end + + def log_signature + @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]" + end + + def sign_message(message) + "#{log_signature} #{message}" + end + end +end + +# Inspired by [mperham](https://github.com/mperham/sidekiq) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 0d0c0d4e..373e3b0e 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -1,6 +1,6 @@ require 'forwardable' require 'protobuf' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/error' require 'protobuf/rpc/connector' @@ -8,7 +8,7 @@ module Protobuf module Rpc class Client extend Forwardable - include Protobuf::Logger::LogMethods + include Protobuf::Logging def_delegators :@connector, :options, :complete_cb, :success_cb, :failure_cb attr_reader :connector @@ -29,7 +29,7 @@ class Client def initialize(options = {}) raise "Invalid client configuration. Service must be defined." if options[:service].nil? @connector = Connector.connector_for_client.new(options) - log_debug { sign_message("Initialized with options: #{options.inspect}") } + logger.debug { sign_message("Initialized with options: #{options.inspect}") } end def log_signature @@ -106,28 +106,28 @@ def on_success=(callable) def method_missing(method_name, *params) service = options[:service] unless service.rpc_method?(method_name) - log_error { sign_message("#{service.name}##{method_name.to_s} not rpc method, passing to super") } + logger.error { sign_message("#{service.name}##{method_name.to_s} not rpc method, passing to super") } super(method_name, *params) else - log_debug { sign_message("#{service.name}##{method_name.to_s}") } + logger.debug { sign_message("#{service.name}##{method_name.to_s}") } rpc = service.rpcs[method_name.to_sym] options[:request_type] = rpc.request_type - log_debug { sign_message("Request Type: #{options[:request_type].name}") } + logger.debug { sign_message("Request Type: #{options[:request_type].name}") } options[:response_type] = rpc.response_type - log_debug { sign_message("Response Type: #{options[:response_type].name}") } + logger.debug { sign_message("Response Type: #{options[:response_type].name}") } options[:method] = method_name.to_s options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0] - log_debug { sign_message("Request Data: #{options[:request].inspect}") } + logger.debug { sign_message("Request Data: #{options[:request].inspect}") } # Call client to setup on_success and on_failure event callbacks if block_given? - log_debug { sign_message("client setup callback given, invoking") } + logger.debug { sign_message("client setup callback given, invoking") } yield(self) else - log_debug { sign_message("no block given for callbacks") } + logger.debug { sign_message("no block given for callbacks") } end send_request diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index d846d974..9f7735ab 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -1,5 +1,5 @@ require 'timeout' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' @@ -23,7 +23,7 @@ module Connectors } class Base - include Protobuf::Logger::LogMethods + include Protobuf::Logging attr_reader :options attr_accessor :success_cb, :failure_cb, :complete_cb diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 4db2bc28..8c7a84cd 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -19,17 +19,17 @@ def request_caller def complete @stats.stop - log_info { @stats.to_s } - log_debug { sign_message('Response proceessing complete') } + logger.info { @stats.to_s } + logger.debug { sign_message('Response proceessing complete') } @complete_cb.call(self) unless @complete_cb.nil? rescue => e - log_error { sign_message('Complete callback error encountered') } + logger.error { sign_message('Complete callback error encountered') } log_exception(e) raise end def data_callback(data) - log_debug { sign_message('Using data_callback') } + logger.debug { sign_message('Using data_callback') } @used_data_callback = true @data = data end @@ -42,11 +42,11 @@ def fail(code, message) @error = ClientError.new @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message - log_debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } + logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } @failure_cb.call(@error) unless @failure_cb.nil? rescue => e - log_error { sign_message("Failure callback error encountered") } + logger.error { sign_message("Failure callback error encountered") } log_exception(e) raise ensure @@ -71,7 +71,7 @@ def parse_response # Close up the connection as we no longer need it close_connection - log_debug { sign_message("Parsing response from server (connection closed)") } + logger.debug { sign_message("Parsing response from server (connection closed)") } # Parse out the raw response @stats.response_size = @response_data.size unless @response_data.nil? @@ -79,13 +79,13 @@ def parse_response # Determine success or failure based on parsed data if response_wrapper.has_field?(:error_reason) - log_debug { sign_message("Error response parsed") } + logger.debug { sign_message("Error response parsed") } # fail the call if we already know the client is failed # (don't try to parse out the response payload) fail(response_wrapper.error_reason, response_wrapper.error) else - log_debug { sign_message("Successful response parsed") } + logger.debug { sign_message("Successful response parsed") } # Ensure client_response is an instance parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) @@ -125,10 +125,10 @@ def setup_connection end def succeed(response) - log_debug { sign_message("Server succeeded request (invoking on_success)") } + logger.debug { sign_message("Server succeeded request (invoking on_success)") } @success_cb.call(response) unless @success_cb.nil? rescue => e - log_error { sign_message("Success callback error encountered") } + logger.error { sign_message("Success callback error encountered") } log_exception(e) fail(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") ensure @@ -153,7 +153,7 @@ def validate_request_type! def verify_callbacks unless any_callbacks? - log_debug { sign_message("No callbacks set, using data_callback") } + logger.debug { sign_message("No callbacks set, using data_callback") } @success_cb = @failure_cb = self.method(:data_callback) end end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 1507acc7..26fd0e97 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -5,7 +5,7 @@ module Rpc module Connectors class Socket < Base include Protobuf::Rpc::Connectors::Common - include Protobuf::Logger::LogMethods + include Protobuf::Logging def send_request timeout_wrap do @@ -24,18 +24,18 @@ def log_signature def close_connection @socket.close - log_debug { sign_message('Connector closed') } + logger.debug { sign_message('Connector closed') } end def connect_to_rpc_server @socket = TCPSocket.new(options[:host], options[:port]) - log_debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } + logger.debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } end # Method to determine error state, must be used with Connector api def error? return true if @error - log_debug { sign_message("Error state : #{@socket.closed?}") } + logger.debug { sign_message("Error state : #{@socket.closed?}") } @socket.closed? end @@ -51,7 +51,7 @@ def read_data end def read_response - log_debug { sign_message("error? is #{error?}") } + logger.debug { sign_message("error? is #{error?}") } return if error? response_buffer = ::Protobuf::Rpc::Buffer.new(:read) response_buffer << read_data @@ -65,7 +65,7 @@ def send_data request_buffer.set_data(@request_data) @socket.write(request_buffer.write) @socket.flush - log_debug { sign_message("write closed") } + logger.debug { sign_message("write closed") } end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 7097759f..84a4f190 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -12,7 +12,7 @@ class Zmq < Base # Included Modules # include Protobuf::Rpc::Connectors::Common - include Protobuf::Logger::LogMethods + include Protobuf::Logging ## # Class Constants @@ -71,9 +71,9 @@ def create_socket if socket # Make sure the context builds the socket socket.setsockopt(::ZMQ::LINGER, 0) - log_debug { sign_message("Establishing connection: #{server_uri}") } + logger.debug { sign_message("Establishing connection: #{server_uri}") } zmq_error_check(socket.connect(server_uri), :socket_connect) - log_debug { sign_message("Connection established to #{server_uri}") } + logger.debug { sign_message("Connection established to #{server_uri}") } if first_alive_load_balance? begin @@ -155,21 +155,21 @@ def send_request_with_timeout(timeout, attempt = 0) poller = ::ZMQ::Poller.new poller.register_readable(socket) - log_debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } zmq_error_check(socket.send_string(@request_data), :socket_send_string) - log_debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } if poller.poll(timeout * 1000) == 1 zmq_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) - log_debug { sign_message("Response received (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } else - log_debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } raise RequestTimeout end ensure - log_debug { sign_message("Closing Socket") } + logger.debug { sign_message("Closing Socket") } zmq_error_check(socket.close, :socket_close) if socket - log_debug { sign_message("Socket closed") } + logger.debug { sign_message("Socket closed") } end # The service we're attempting to connect to diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index 010a1b8f..b29ea29b 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class ExceptionHandler - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :app diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index 93dd17b1..9f4bd308 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -42,7 +42,7 @@ class Instrumenter attr_reader :env def flush(env) - Protobuf::Logger.info { to_s(env) } + ::Protobuf::Logging.logger.info { to_s(env) } end def start diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index fa74ad5d..de42a77b 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class RequestDecoder - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :app, :env @@ -27,7 +27,7 @@ def call(env) end def log_signature - env.signature || super + env.log_signature || super end private @@ -57,7 +57,7 @@ def request # def request_wrapper @request_wrapper ||= begin - log_debug { sign_message("Decoding request: #{env.encoded_request}") } + logger.debug { sign_message("Decoding request: #{env.encoded_request}") } Socketrpc::Request.decode(env.encoded_request) end rescue => exception diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 5d6188ab..11c53613 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class ResponseEncoder - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :app, :env @@ -19,7 +19,7 @@ def call(env) end def log_signature - env.signature || super + env.log_signature || super end private @@ -27,7 +27,7 @@ def log_signature # Encode the response wrapper to return to the client # def encoded_response - log_debug { sign_message("Encoding response: #{response.inspect}") } + logger.debug { sign_message("Encoding response: #{response.inspect}") } env.encoded_response = wrapped_response.encode rescue => exception diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index f76bcd58..27dbaf8a 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -1,5 +1,5 @@ require 'protobuf' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' require 'protobuf/rpc/env' diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 7efdd65b..e184c9d8 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -5,7 +5,7 @@ module Protobuf module Rpc module Socket class Server - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging AUTO_COLLECT_TIMEOUT = 5 # seconds @@ -19,7 +19,7 @@ def cleanup? end def cleanup_threads - log_debug { sign_message("Thread cleanup - #{@threads.size} - start") } + logger.debug { sign_message("Thread cleanup - #{@threads.size} - start") } @threads = @threads.select do |t| if t[:thread].alive? @@ -31,7 +31,7 @@ def cleanup_threads end end - log_debug { sign_message("Thread cleanup - #{@threads.size} - complete") } + logger.debug { sign_message("Thread cleanup - #{@threads.size} - complete") } end def log_signature @@ -47,7 +47,7 @@ def new_worker(socket) end def run - log_debug { sign_message("Run") } + logger.debug { sign_message("Run") } host = @options[:host] port = @options[:port] backlog = @options[:backlog] @@ -63,7 +63,7 @@ def run @running = true while running? - log_debug { sign_message("Waiting for connections") } + logger.debug { sign_message("Waiting for connections") } ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) rescue nil if ready_cnxns @@ -73,13 +73,13 @@ def run when !running? then # no-op when client == @server then - log_debug { sign_message("Accepted new connection") } + logger.debug { sign_message("Accepted new connection") } client, sockaddr = @server.accept @listen_fds << client else unless @working.include?(client) @working << @listen_fds.delete(client) - log_debug { sign_message("Working") } + logger.debug { sign_message("Working") } @threads << { :thread => new_worker(client), :socket => client } cleanup_threads if cleanup? diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index aa443347..984ae01e 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -1,12 +1,12 @@ require 'protobuf/rpc/server' -require 'protobuf/logger' +require 'protobuf/logging' module Protobuf module Rpc module Socket class Worker include ::Protobuf::Rpc::Server - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def initialize(sock, &complete_cb) @socket = sock diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 51a5d1ae..c45c487f 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -100,7 +100,7 @@ def broadcast_heartbeat @beacon_socket.send(heartbeat.encode, 0) - log_debug { sign_message("sent heartbeat to #{beacon_uri}") } + logger.debug { sign_message("sent heartbeat to #{beacon_uri}") } end def broadcast_heartbeat? @@ -204,7 +204,7 @@ def start_missing_workers if missing_workers > 0 missing_workers.times { start_worker } - log_debug { sign_message("#{total_workers} workers started") } + logger.debug { sign_message("#{total_workers} workers started") } end end @@ -303,7 +303,7 @@ def start_worker rescue => e message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" $stderr.puts(message) - log_error { message } + logger.error { message } end end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 3d95ce0f..af7dcde5 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -11,7 +11,7 @@ module Zmq WORKERS_AVAILABLE = "\5" module Util - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def self.included(base) base.extend(::Protobuf::Rpc::Zmq::Util) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 2ed1ab52..70b53548 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -3,7 +3,7 @@ module Protobuf module Rpc class ZmqRunner - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def initialize(options) @options = case @@ -38,12 +38,12 @@ def stop def register_signals trap(:TTIN) do @server.add_worker - log_info { "Increased worker size to: #{@server.total_workers}" } + logger.info { "Increased worker size to: #{@server.total_workers}" } end trap(:TTOU) do - log_info { "Current worker size: #{@server.workers.size}" } - log_info { "Current worker size: #{@server.busy_worker_count}" } + logger.info { "Current worker size: #{@server.workers.size}" } + logger.info { "Current worker size: #{@server.busy_worker_count}" } end end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 12efbc10..1c5f1e8c 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,4 +1,4 @@ -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/client' require 'protobuf/rpc/error' require 'protobuf/rpc/service_filters' @@ -10,7 +10,7 @@ module Rpc RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) class Service - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging include ::Protobuf::Rpc::ServiceFilters DEFAULT_HOST = '127.0.0.1'.freeze diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index bc7874d4..868e53be 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -11,7 +11,7 @@ module Protobuf module Rpc class ServiceDirectory include ::Singleton - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging DEFAULT_ADDRESS = "0.0.0.0" DEFAULT_PORT = 53000 @@ -116,7 +116,7 @@ def running? def start unless running? init_socket - log_info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } + logger.info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } @thread = Thread.new { self.send(:run) } end @@ -124,7 +124,7 @@ def start end def stop - log_info { sign_message("Stopping directory") } + logger.info { sign_message("Stopping directory") } @thread.try(:kill).try(:join) @socket.try(:close) @@ -151,7 +151,7 @@ def add_or_update_listing(uuid, server) end trigger(action, listing) - log_debug { sign_message("#{action} server: #{server.inspect}") } + logger.debug { sign_message("#{action} server: #{server.inspect}") } end def init_socket @@ -177,7 +177,7 @@ def process_beacon(beacon) remove_listing(uuid) end else - log_info { sign_message("Ignoring incomplete beacon: #{beacon.inspect}") } + logger.info { sign_message("Ignoring incomplete beacon: #{beacon.inspect}") } end end @@ -193,7 +193,7 @@ def read_beacon end def remove_expired_listings - log_debug { sign_message("Removing expired listings") } + logger.debug { sign_message("Removing expired listings") } @listings_by_uuid.each do |uuid, listing| remove_listing(uuid) if listing.expired? end @@ -202,7 +202,7 @@ def remove_expired_listings def remove_listing(uuid) listing = @listings_by_uuid[uuid] or return - log_debug { sign_message("Removing listing: #{listing.inspect}") } + logger.debug { sign_message("Removing listing: #{listing.inspect}") } @listings_by_service.each do |service, listings| listings.delete(listing) @@ -233,7 +233,7 @@ def run end end rescue => e - log_debug { sign_message("ERROR: (#{e.class}) #{e.message}\n#{e.backtrace.join("\n")}") } + logger.debug { sign_message("ERROR: (#{e.class}) #{e.message}\n#{e.backtrace.join("\n")}") } retry end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 469af8e7..91dacb42 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -1,9 +1,9 @@ -require 'protobuf/logger' +require 'protobuf/logging' module Protobuf module Rpc class ServiceDispatcher - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :env diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 5dd504ca..5ab9407e 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -1,6 +1,6 @@ require 'date' require 'time' -require 'protobuf/logger' +require 'protobuf/logging' module Protobuf module Rpc diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 8c45d685..f90554fd 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -13,8 +13,8 @@ # Including a way to turn on debug logger for spec runs if ENV["DEBUG"] puts 'debugging' - debug_log = File.expand_path('../debug_bench.log', File.dirname(__FILE__) ) - Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) + debug_log = File.expand_path('../../../debug_bench.log', __FILE__) + Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG) end namespace :benchmark do diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 9d8280c1..24fde5e0 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -19,6 +19,12 @@ runner } + around(:each) do |example| + logger = ::Protobuf::Logging.logger + example.run + ::Protobuf::Logging.logger = logger + end + before(:each) do allow(::Protobuf::Rpc::SocketRunner).to receive(:new).and_return(sock_runner) allow(::Protobuf::Rpc::ZmqRunner).to receive(:new).and_return(zmq_runner) @@ -88,9 +94,9 @@ let(:test_args) { [ '--log=mylog.log', '--level=0' ] } it 'sends the log file and level options to the runner' do - expect(::Protobuf::Logger).to receive(:configure) do |options| - expect(options[:file]).to eq 'mylog.log' - expect(options[:level]).to eq 0 + expect(::Protobuf::Logging).to receive(:initialize_logger) do |file, level| + expect(file).to eq 'mylog.log' + expect(level).to eq 0 end described_class.start(args) end diff --git a/spec/lib/protobuf/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb deleted file mode 100644 index 6a28aa3f..00000000 --- a/spec/lib/protobuf/logger_spec.rb +++ /dev/null @@ -1,136 +0,0 @@ -require 'protobuf/logger' -require 'stringio' -require 'fileutils' - -describe Protobuf::Logger do - - subject { Protobuf::Logger } - - before(:each) do - Protobuf::Logger.reset_device! - Protobuf::Logger.file = '/dev/null' - Protobuf::Logger.level = ::Logger::INFO - end - - after(:all) do - ::FileUtils.rm_f('myfile.log') - end - - describe '.instance' do - - it 'doesn\'t create a logger if the file was not set' do - subject.file = nil - expect(subject.instance).to be_nil - end - - it 'doesn\'t create a logger if the level was not set' do - subject.level = nil - expect(subject.instance).to be_nil - end - - it 'gets a new instance of the logger when file and level are set' do - expect(subject.file).to_not be_nil - expect(subject.level).to_not be_nil - expect(subject.instance).to_not be_nil - end - - it 'keeps the same object from multiple calls to instance' do - expect(subject.instance).to equal(subject.instance) - end - - end - - describe '.configure' do - before(:each) { subject.reset_device! } - it 'sets the file and level in one call' do - expect(subject.file).to_not be - expect(subject.level).to_not be - expect(subject.instance).to_not be - subject.configure :file => 'myfile.log', :level => ::Logger::WARN - expect(subject.file).to eq('myfile.log') - expect(subject.level).to eq(::Logger::WARN) - expect(subject.instance.level).to eq(::Logger::WARN) - end - - end - - describe '.reset_device!' do - - it 'resets the logger instance, file, and level' do - expect(subject.instance).to be - expect(subject.file).to be - expect(subject.level).to be - subject.reset_device! - expect(subject.instance).to_not be - expect(subject.file).to_not be - expect(subject.level).to_not be - end - - end - - context 'when logging' do - - it 'doesn\'t raise errors when log instance is nil' do - subject.reset_device! - expect(subject.instance).to be_nil - expect { - subject.debug 'No errors here' - subject.info 'No errors here' - subject.warn 'No errors here' - subject.error 'No errors here' - subject.fatal 'No errors here' - subject.add 'No errors here' - subject.log 'No errors here' - }.to_not raise_error - end - - it 'logs correctly when instance is valid' do - expect(subject.instance).to_not be_nil - expect(subject.instance).to receive(:info).with('Should log great') - subject.info 'Should log great' - end - - end - - describe Protobuf::Logger::LogMethods do - - context 'when included in another class' do - - before(:all) do - class MyTestClass - include Protobuf::Logger::LogMethods - end - end - - subject { MyTestClass.new } - - it { is_expected.to respond_to(:log_debug) } - it { is_expected.to respond_to(:log_info) } - it { is_expected.to respond_to(:log_warn) } - it { is_expected.to respond_to(:log_error) } - it { is_expected.to respond_to(:log_fatal) } - it { is_expected.to respond_to(:log_add) } - it { is_expected.to respond_to(:log_log) } - - context '#log_exception' do - it 'logs the exception message as an error and backtrace as debug' do - expect(subject).to receive(:log_error).twice - expect(subject).to receive(:log_debug) - subject.log_exception(RuntimeError.new('this is an exception')) - end - end - - specify { expect(subject.log_signature).to eq "[MyTestClass]" } - describe '#sign_message' do - specify { expect(subject.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } - specify { expect(subject.class.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } - end - - it 'passes all embedded log calls to Logger instance' do - expect(Protobuf::Logger.instance).to receive(:debug).with('[MyTestClass] log this') - subject.log_debug('log this') - end - - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07b4c16b..414f80d5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,3 @@ -require 'simplecov' -SimpleCov.start - require 'timeout' require 'rubygems' require 'bundler' @@ -20,10 +17,14 @@ # Including a way to turn on debug logger for spec runs if ENV.key?('DEBUG') - debug_log = ::File.expand_path('../debug_specs.log', File.dirname(__FILE__) ) - ::Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) + debug_log = ::File.expand_path('../../debug_specs.log', __FILE__ ) + ::Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG) +else + ::Protobuf::Logging.initialize_logger('/dev/null') end +::Protobuf::Logging.close_old_logger = false + # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") diff --git a/spec/support/server.rb b/spec/support/server.rb index a88db354..55e4dbea 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,5 +1,5 @@ require 'ostruct' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/servers/socket_runner' @@ -33,7 +33,7 @@ def post_init end class StubServer - include Protobuf::Logger::LogMethods + include Protobuf::Logging attr_accessor :options @@ -58,7 +58,7 @@ def start else start_socket_server end - log_debug { sign_message("Server started #{@options.host}:#{@options.port}") } + logger.debug { sign_message("Server started #{@options.host}:#{@options.port}") } end def start_socket_server From 623c05bb47e38d4a176dd0794a2d0d1f59666c98 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 24 Aug 2014 12:44:46 -0600 Subject: [PATCH 0712/1191] allow queue size to be configurable and use an array as local queue as the broker is single threaded --- lib/protobuf/rpc/connectors/zmq.rb | 2 ++ lib/protobuf/rpc/servers/zmq/broker.rb | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 7097759f..015f83b0 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -123,6 +123,8 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? socket = TCPSocket.new(host, ping_port.to_i) + socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) + socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1,0].pack('ii')) true rescue diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 4b6be48f..717b1dd0 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -67,7 +67,7 @@ def init_frontend_socket end def init_local_queue - @local_queue = ::Queue.new + @local_queue = [] end def init_poller @@ -88,6 +88,10 @@ def inproc? !!@server.try(:inproc?) end + def local_queue_max_size + @local_queue_max_size ||= [ENV["PB_LOCAL_QUEUE_MAX_SIZE"].to_i, 5].max + end + def process_backend worker, ignore, *frames = read_from_backend @@ -102,16 +106,16 @@ def process_frontend address, _, message, *frames = read_from_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE - if @idle_workers.any? || local_queue.size < 5 # Should make queue a SizedQueue and allow users to configure queue size + if local_queue.size < local_queue_max_size write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) end else - if @idle_workers.any? - write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) - else + if @idle_workers.empty? local_queue.push([address, "", message ] + frames) + else + write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) end end end From 492f950443ca67ad4687d8cc69c4269c510f15c5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 26 Aug 2014 15:26:18 -0600 Subject: [PATCH 0713/1191] updating name to reflect zmq serverness --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 717b1dd0..93ef6e5e 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -89,7 +89,7 @@ def inproc? end def local_queue_max_size - @local_queue_max_size ||= [ENV["PB_LOCAL_QUEUE_MAX_SIZE"].to_i, 5].max + @local_queue_max_size ||= [ENV["PB_ZMQ_SERVER_QUEUE_MAX_SIZE"].to_i, 5].max end def process_backend From e942d61767c722a744378f27ab3ba422a320a3e7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 26 Aug 2014 16:46:00 -0600 Subject: [PATCH 0714/1191] bump to 3.3.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index da2f061f..155fcc11 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.2.1' + VERSION = '3.3.0' end From dc9647b40529e64fa71f75cbdb350d2c36fd2867 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 27 Aug 2014 14:09:16 -0600 Subject: [PATCH 0715/1191] Never close $stdout --- lib/protobuf/logging.rb | 10 +--------- spec/spec_helper.rb | 2 -- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 47f5b8f3..5ee649b9 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -6,18 +6,10 @@ def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) old_logger = defined?(@logger) ? @logger : nil @logger = Logger.new(log_target) @logger.level = log_level - old_logger.close if old_logger and close_old_logger? + old_logger.close if old_logger and log_target != $stdout @logger end - def self.close_old_logger=(boolean) - @close_old_logger = !!boolean - end - - def self.close_old_logger? - defined?(@close_old_logger) ? @close_old_logger : true - end - def self.logger defined?(@logger) ? @logger : initialize_logger end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 414f80d5..fa22f2ce 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,8 +23,6 @@ ::Protobuf::Logging.initialize_logger('/dev/null') end -::Protobuf::Logging.close_old_logger = false - # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") From a8e071c80621fd9ab463b6672b9e46e8acc036cd Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 27 Aug 2014 14:22:54 -0600 Subject: [PATCH 0716/1191] Never close old logger There's not a great way to handle automatically closing old file descriptors, so I'm just going to leave it out for now. --- lib/protobuf/logging.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 5ee649b9..78a5aea6 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -3,10 +3,8 @@ module Logging def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) @counter ||= 0 @counter = @counter + 1 - old_logger = defined?(@logger) ? @logger : nil @logger = Logger.new(log_target) @logger.level = log_level - old_logger.close if old_logger and log_target != $stdout @logger end From 8b62b4260bc275d7af085484bffc550b081f4714 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 27 Aug 2014 16:27:05 -0600 Subject: [PATCH 0717/1191] Bump version to 3.3.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 155fcc11..d0ad3c81 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.0' + VERSION = '3.3.1' end From 1e55916e3a258042bc48bc824d51ee4b0ecc0d50 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 27 Aug 2014 17:35:19 -0600 Subject: [PATCH 0718/1191] Ensure Logger (Stdlib) is properly required Since we're referencing Logger::INFO in the Protobuf::Logging module, we need to ensure that Logger is properly required to avoid any load order issues. --- lib/protobuf/logging.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 78a5aea6..273d159d 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -1,3 +1,5 @@ +require 'logger' + module Protobuf module Logging def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) From 3105a05a287264e5e2bc47ff6c6421ec26dcdc71 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 27 Aug 2014 17:40:10 -0600 Subject: [PATCH 0719/1191] fix setsockopt use in specs --- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 16bd8ca4..7bec5332 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -17,6 +17,7 @@ before do allow(::ZMQ::Context).to receive(:new).and_return(zmq_context_double) + allow(socket_double).to receive(:setsockopt) end before(:all) do @@ -94,7 +95,7 @@ end it "returns true when the connection succeeds" do - expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil)) + expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil, :setsockopt => nil)) expect(subject.send(:host_alive?, "huzzah.com")).to be true end @@ -104,7 +105,7 @@ end it "closes the socket" do - socket = double("TCPSocket") + socket = double("TCPSocket", :setsockopt => nil) expect(socket).to receive(:close) expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) expect(subject.send(:host_alive?, "absorbalof.com")).to be true From 27b38676a677d0f9fd7029f7259a53bc014ef136 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 27 Aug 2014 17:40:30 -0600 Subject: [PATCH 0720/1191] bump to 3.3.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index d0ad3c81..44438e84 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.1' + VERSION = '3.3.2' end From c4f1badaa7859aab2ac1ae08359668e84fa2e1f0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 28 Aug 2014 14:37:02 -0600 Subject: [PATCH 0721/1191] Update to MIT license --- LICENSE.txt | 26 +++++++++++++++++--------- protobuf.gemspec | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index dd94252a..cddcfe29 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,14 +1,22 @@ - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - Version 2, December 2004 +The MIT License (MIT) -Copyright (C) 2004 Sam Hocevar +Copyright (c) 2014 BJ Neilsen -Everyone is permitted to copy and distribute verbatim or modified -copies of this license document, and changing it is allowed as long -as the name is changed. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. - 0. You just DO WHAT THE FUCK YOU WANT TO. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/protobuf.gemspec b/protobuf.gemspec index bfec5bdb..0071c58a 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -6,7 +6,7 @@ require "protobuf/version" s.name = 'protobuf' s.version = ::Protobuf::VERSION s.date = ::Time.now.strftime('%Y-%m-%d') - s.license = 'WTFPL' + s.license = 'MIT' s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen', 'Adam Hutchison'] s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com', 'liveh2o@gmail.com'] From f7d0bbd4d4dcfcc4ecb6937943c12b9152fa61ca Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 12 Sep 2014 17:53:36 -0600 Subject: [PATCH 0722/1191] try to cut down on ping port traffic with health check interval --- lib/protobuf/rpc/connectors/zmq.rb | 25 ++++++++++++++++++++++++- protobuf.gemspec | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a8499b1c..f097c450 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -1,3 +1,4 @@ +require 'thread_safe' require 'protobuf/rpc/connectors/base' require 'protobuf/rpc/service_directory' @@ -30,6 +31,10 @@ def self.zmq_context @zmq_contexts[Process.pid] end + def self.ping_port_responses + @ping_port_responses ||= ::ThreadSafe::Cache.new + end + ## # Instance methods # @@ -105,7 +110,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 5.times do + 15.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -115,6 +120,8 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) + + sleep (5.0/100.0) end raise "Host not found for service #{service}" @@ -122,6 +129,22 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? + + if (last_response = self.class.ping_port_responses[host]) + if (Time.now.to_i - last_response[:at]) <= 2 + return last_response[:ping_port_open] + end + end + + ping_port_open = ping_port_open?(host) + self.class.ping_port_responses[host] = { + :at => Time.now.to_i, + :ping_port_open => ping_port_open + } + ping_port_open + end + + def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1,0].pack('ii')) diff --git a/protobuf.gemspec b/protobuf.gemspec index 0071c58a..2e3b254f 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -22,6 +22,7 @@ require "protobuf/version" s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'middleware' s.add_dependency 'thor' + s.add_dependency 'thread_safe' s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'pry-nav' From 646e5a13fa9e7727f00d18ea8af0ead749cabab2 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 12 Sep 2014 18:33:43 -0600 Subject: [PATCH 0723/1191] sweep every 5 instead of 1 and check backend before frontend and local_queue in between --- lib/protobuf/rpc/servers/zmq/broker.rb | 17 ++++------------- lib/protobuf/rpc/service_directory.rb | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 93ef6e5e..0b759ae7 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -25,26 +25,17 @@ def run @idle_workers = [] loop do - unless local_queue.empty? - process_local_queue - end - + process_local_queue rc = @poller.poll(500) # The server was shutdown and no requests are pending break if rc == 0 && !running? - # Something went wrong break if rc == -1 - @poller.readables.each do |readable| - case readable - when @frontend_socket - process_frontend - when @backend_socket - process_backend - end - end + process_backend if @poller.readables.include?(@backend_socket) + process_local_queue # Fair ordering so queued requests get in before new requests + process_frontend if @poller.readables.include?(@frontend_socket) end ensure teardown diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 868e53be..cddc7a53 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -219,7 +219,7 @@ def reset end def run - sweep_interval = 1 # sweep expired listings every 1 second + sweep_interval = 5 # sweep expired listings every 5 seconds next_sweep = Time.now.to_i + sweep_interval loop do From 0987d524601964e372c750e7f62d87335d451196 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 10:18:21 -0600 Subject: [PATCH 0724/1191] shift off of local queue for ordered processing and concat instead of + for less copy --- lib/protobuf/rpc/servers/zmq/broker.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 0b759ae7..474217ff 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -104,9 +104,9 @@ def process_frontend end else if @idle_workers.empty? - local_queue.push([address, "", message ] + frames) + local_queue << [address, "", message ].concat(frames) else - write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) + write_to_backend([@idle_workers.shift, ""].concat([address, "", message ]).concat(frames)) end end end @@ -115,7 +115,7 @@ def process_local_queue return if local_queue.empty? return if @idle_workers.empty? - write_to_backend([@idle_workers.shift, ""] + local_queue.pop) + write_to_backend([@idle_workers.shift, ""].concat(local_queue.shift)) process_local_queue end From 71e59a99c344e019604548fa1c06652683a325dc Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 10:31:40 -0600 Subject: [PATCH 0725/1191] constantize the empty string --- lib/protobuf/rpc/servers/zmq/broker.rb | 10 +++++----- lib/protobuf/rpc/servers/zmq/util.rb | 1 + lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 474217ff..ce110592 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -98,15 +98,15 @@ def process_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE if local_queue.size < local_queue_max_size - write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) + write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else - write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) + write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) end else if @idle_workers.empty? - local_queue << [address, "", message ].concat(frames) + local_queue << [address, , message ].concat(frames) else - write_to_backend([@idle_workers.shift, ""].concat([address, "", message ]).concat(frames)) + write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ]).concat(frames)) end end end @@ -115,7 +115,7 @@ def process_local_queue return if local_queue.empty? return if @idle_workers.empty? - write_to_backend([@idle_workers.shift, ""].concat(local_queue.shift)) + write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat(local_queue.shift)) process_local_queue end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index af7dcde5..f16bbcfd 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -9,6 +9,7 @@ module Zmq CHECK_AVAILABLE_MESSAGE = "\3" NO_WORKERS_AVAILABLE = "\4" WORKERS_AVAILABLE = "\5" + EMPTY_STRING = "" module Util include ::Protobuf::Logging diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 6b3d5582..7ee35afc 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -31,7 +31,7 @@ def process_request gc_pause do encoded_response = handle_request(data) - write_to_backend([client_address, "", encoded_response]) + write_to_backend([client_address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, encoded_response]) end end From 278a297a57197110195928b3993df6982fb5a337 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 10:41:58 -0600 Subject: [PATCH 0726/1191] add empty to broker --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index ce110592..83eb41ab 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -104,7 +104,7 @@ def process_frontend end else if @idle_workers.empty? - local_queue << [address, , message ].concat(frames) + local_queue << [address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ].concat(frames) else write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ]).concat(frames)) end From 6df180f88552a067337e62ce5090483d79928380 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 11:42:09 -0600 Subject: [PATCH 0727/1191] let server shutdown the context when using a shared context via inproc --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 83eb41ab..5e86148c 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -134,7 +134,7 @@ def read_from_frontend def teardown @frontend_socket.try(:close) @backend_socket.try(:close) - @zmq_context.try(:terminate) + @zmq_context.try(:terminate) unless inproc? end def write_to_backend(frames) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 7ee35afc..e0c28357 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -93,7 +93,7 @@ def read_from_backend def teardown @backend_socket.try(:close) - @zmq_context.try(:terminate) + @zmq_context.try(:terminate) unless inproc? end def write_to_backend(frames) From c5d73e91ed272f0e2225614a744b91778d421648 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 12:10:05 -0600 Subject: [PATCH 0728/1191] bump to 3.3.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 44438e84..68723b0d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.2' + VERSION = '3.3.3' end From 7452e8a7f0d49fceb1421cafa84d1a764bec8115 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 10:40:19 -0600 Subject: [PATCH 0729/1191] add configuration ENV vars for the values that have been hard-coded in the connector for zmq and the broker for zmq the poll weight influences how many messages will be pulled from the polling socket before it moves on to check the other socket, this is currently 2/1 weighted in favor of the backend socket (the work complete) Also made a configuration value of the number of attempts to make on getting the server uri on the client side --- lib/protobuf/rpc/connectors/zmq.rb | 17 +++++++++------ lib/protobuf/rpc/servers/zmq/broker.rb | 29 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index f097c450..f4fd0c67 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -75,10 +75,7 @@ def create_socket if socket # Make sure the context builds the socket socket.setsockopt(::ZMQ::LINGER, 0) - - logger.debug { sign_message("Establishing connection: #{server_uri}") } zmq_error_check(socket.connect(server_uri), :socket_connect) - logger.debug { sign_message("Connection established to #{server_uri}") } if first_alive_load_balance? begin @@ -110,7 +107,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 15.times do + server_lookup_attempts.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -121,7 +118,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep (5.0/100.0) + sleep (1.0/100.0) end raise "Host not found for service #{service}" @@ -131,7 +128,7 @@ def host_alive?(host) return true unless ping_port_enabled? if (last_response = self.class.ping_port_responses[host]) - if (Time.now.to_i - last_response[:at]) <= 2 + if (Time.now.to_i - last_response[:at]) <= host_alive_check_interval return last_response[:ping_port_open] end end @@ -144,6 +141,10 @@ def host_alive?(host) ping_port_open end + def host_alive_check_interval + @host_alive_check_interval ||= [ENV["PB_ZMQ_CLIENT_HOST_ALIVE_CHECK_INTERVAL"].to_i, 1].max + end + def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) @@ -197,6 +198,10 @@ def send_request_with_timeout(timeout, attempt = 0) logger.debug { sign_message("Socket closed") } end + def server_lookup_attempts + @server_lookup_attempts ||= [ENV["PB_ZMQ_CLIENT_SERVER_LOOKUP_ATTEMPTS"].to_i, 5].max + end + # The service we're attempting to connect to # def service diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 5e86148c..2fed7b85 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -33,9 +33,26 @@ def run # Something went wrong break if rc == -1 - process_backend if @poller.readables.include?(@backend_socket) + readables_include_backend = @poller.readables.include?(@backend_socket) + message_count_read_from_backend = 0 + + while readables_include_backend && message_count_read_from_backend < backend_poll_weight do + message_count_read_from_backend = message_count_read_from_backend + 1 + process_backend + @poller.poll_nonblock + readables_include_backend = @poller.readables.include?(@backend_socket) + end + process_local_queue # Fair ordering so queued requests get in before new requests - process_frontend if @poller.readables.include?(@frontend_socket) + readables_include_frontend = @poller.readables.include?(@frontend_socket) + message_count_read_from_frontend = 0 + + while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do + message_count_read_from_frontend = message_count_read_from_frontend + 1 + process_frontend + @poller.poll_nonblock + readables_include_frontend = @poller.readables.include?(@frontend_socket) + end end ensure teardown @@ -47,6 +64,14 @@ def running? private + def backend_poll_weight + @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 2].max + end + + def frontend_poll_weight + @frontend_poll_weight ||= [ENV["PB_ZMQ_SERVER_FRONTEND_POLL_WEIGHT"].to_i, 1].max + end + def init_backend_socket @backend_socket = @zmq_context.socket(ZMQ::ROUTER) zmq_error_check(@backend_socket.bind(@server.backend_uri)) From f11bc3faeadd67acfcfdb498855609b34e62b47d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 13:25:58 -0600 Subject: [PATCH 0730/1191] set default backend poll weight to 1 to not change behavior of current --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 2fed7b85..e398dfe5 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -65,7 +65,7 @@ def running? private def backend_poll_weight - @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 2].max + @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 1].max end def frontend_poll_weight From 0a6a86e32ca9bba8aaa676bb76d3546bfa42e5e4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 14:29:41 -0600 Subject: [PATCH 0731/1191] break from frontend poll if queue is full --- lib/protobuf/rpc/servers/zmq/broker.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index e398dfe5..140e4bda 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -50,6 +50,7 @@ def run while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do message_count_read_from_frontend = message_count_read_from_frontend + 1 process_frontend + break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full @poller.poll_nonblock readables_include_frontend = @poller.readables.include?(@frontend_socket) end @@ -104,6 +105,10 @@ def inproc? !!@server.try(:inproc?) end + def local_queue_available? + local_queue.size < local_queue_max_size + end + def local_queue_max_size @local_queue_max_size ||= [ENV["PB_ZMQ_SERVER_QUEUE_MAX_SIZE"].to_i, 5].max end @@ -122,7 +127,7 @@ def process_frontend address, _, message, *frames = read_from_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE - if local_queue.size < local_queue_max_size + if local_queue_available? write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) From eeb4e2977323071c61eb4526e8e1847bcb0d2a5a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 17:12:15 -0600 Subject: [PATCH 0732/1191] clean up the `run` method --- lib/protobuf/rpc/servers/zmq/broker.rb | 47 +++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 140e4bda..89333742 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -33,27 +33,9 @@ def run # Something went wrong break if rc == -1 - readables_include_backend = @poller.readables.include?(@backend_socket) - message_count_read_from_backend = 0 - - while readables_include_backend && message_count_read_from_backend < backend_poll_weight do - message_count_read_from_backend = message_count_read_from_backend + 1 - process_backend - @poller.poll_nonblock - readables_include_backend = @poller.readables.include?(@backend_socket) - end - + check_and_process_backend process_local_queue # Fair ordering so queued requests get in before new requests - readables_include_frontend = @poller.readables.include?(@frontend_socket) - message_count_read_from_frontend = 0 - - while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do - message_count_read_from_frontend = message_count_read_from_frontend + 1 - process_frontend - break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full - @poller.poll_nonblock - readables_include_frontend = @poller.readables.include?(@frontend_socket) - end + check_and_process_frontend end ensure teardown @@ -69,6 +51,31 @@ def backend_poll_weight @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 1].max end + def check_and_process_backend + readables_include_backend = @poller.readables.include?(@backend_socket) + message_count_read_from_backend = 0 + + while readables_include_backend && message_count_read_from_backend < backend_poll_weight do + message_count_read_from_backend += 1 + process_backend + @poller.poll_nonblock + readables_include_backend = @poller.readables.include?(@backend_socket) + end + end + + def check_and_process_frontend + readables_include_frontend = @poller.readables.include?(@frontend_socket) + message_count_read_from_frontend = 0 + + while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do + message_count_read_from_frontend += 1 + process_frontend + break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full + @poller.poll_nonblock + readables_include_frontend = @poller.readables.include?(@frontend_socket) + end + end + def frontend_poll_weight @frontend_poll_weight ||= [ENV["PB_ZMQ_SERVER_FRONTEND_POLL_WEIGHT"].to_i, 1].max end From 7fd71e34b6fe6e4019c256340038121cab719aae Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 18:29:07 -0600 Subject: [PATCH 0733/1191] bump to 3.3.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 68723b0d..bd177730 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.3' + VERSION = '3.3.4' end From c096805c688d8c79639863b8c88aeaee98f7034e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 21:28:19 -0600 Subject: [PATCH 0734/1191] set timeout on socket when checking work avail --- lib/protobuf/rpc/connectors/zmq.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index f4fd0c67..efbc99d4 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -80,6 +80,8 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, 200) + socket.setsockopt(::ZMQ::SNDTIMEO, 200) zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) @@ -88,6 +90,9 @@ def create_socket end rescue ZmqRecoverableError socket = nil # couldn't make a connection and need to try again + else + socket.setsockopt(::ZMQ::RCVTIMEO, -1) + socket.setsockopt(::ZMQ::SNDTIMEO, -1) end end end From 811f727e510fc57658eda753dd04072aa8374daf Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 22:52:00 -0600 Subject: [PATCH 0735/1191] add a global timeout that can be set for connections and move timeout mgmt to zeromq as it has facilities to handle timeout --- lib/protobuf/rpc/connectors/zmq.rb | 70 ++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index efbc99d4..58331536 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -8,6 +8,7 @@ module Connectors class Zmq < Base RequestTimeout = Class.new(RuntimeError) ZmqRecoverableError = Class.new(RuntimeError) + ZmqEagainError = Class.new(RuntimeError) ## # Included Modules @@ -58,6 +59,13 @@ def log_signature ## # Private Instance methods # + def check_available_rcv_timeout + @check_available_rcv_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT"].to_i, 200].max + end + + def check_available_snd_timeout + @check_available_snd_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT"].to_i, 200].max + end def close_connection # The socket is automatically closed after every request. @@ -80,8 +88,8 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 200) - socket.setsockopt(::ZMQ::SNDTIMEO, 200) + socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) @@ -180,23 +188,39 @@ def send_request_with_lazy_pirate end end + def rcv_timeout + @rcv_timeout ||= begin + if ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") + ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + + def snd_timeout + @snd_timeout ||= begin + if ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") + ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + def send_request_with_timeout(timeout, attempt = 0) socket = create_socket - - poller = ::ZMQ::Poller.new - poller.register_readable(socket) + socket.setsockopt(::ZMQ::RCVTIMEO, rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, snd_timeout) logger.debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } - zmq_error_check(socket.send_string(@request_data), :socket_send_string) + zmq_eagain_error_check(socket.send_string(@request_data), :socket_send_string) logger.debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } - - if poller.poll(timeout * 1000) == 1 - zmq_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) - logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } - else - logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } - raise RequestTimeout - end + zmq_eagain_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) + logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } + rescue ZmqEagainError + logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } + raise RequestTimeout ensure logger.debug { sign_message("Closing Socket") } zmq_error_check(socket.close, :socket_close) if socket @@ -226,6 +250,24 @@ def zmq_context self.class.zmq_context end + def zmq_eagain_error_check(return_code, source) + unless ::ZMQ::Util.resultcode_ok?(return_code || -1) + if ::ZMQ::Util.errno == ::ZMQ::EAGAIN + raise ZmqEagainError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + else + raise <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + end + end + end + def zmq_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) raise <<-ERROR From 68bac991e4060eba29702f241d924a66eff8365c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 16 Sep 2014 09:48:41 -0600 Subject: [PATCH 0736/1191] move "default timeout" out of options and have it be env and overridable --- lib/protobuf/rpc/connectors/base.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 12 ++++++++++-- lib/protobuf/rpc/connectors/zmq.rb | 17 +++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 9f7735ab..c2a6b9d6 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -17,9 +17,9 @@ module Connectors :request => nil, # The request object sent by the client :request_type => nil, # The request type expected by the client :response_type => nil, # The response type expected by the client - :timeout => 300, # The default timeout for the request, also handled by client.rb + :timeout => nil, # The timeout for the request, also handled by client.rb :client_host => nil, # The hostname or address of this client - :first_alive_load_balance => false, # Do we want to use check_avail frames before request + :first_alive_load_balance => false, # Do we want to use check_avail frames before request } class Base diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 8c7a84cd..2ef5b9a1 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -135,12 +135,20 @@ def succeed(response) complete end + def timeout + if options[:timeout] + options[:timeout] + else + 300 # seconds + end + end + # Wrap the given block in a timeout of the configured number of seconds. # def timeout_wrap(&block) - ::Timeout.timeout(options[:timeout], &block) + ::Timeout.timeout(timeout, &block) rescue ::Timeout::Error - fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond") + fail(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") end def validate_request_type! diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 58331536..da7e9cd3 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -176,11 +176,10 @@ def ping_port_open?(host) # def send_request_with_lazy_pirate attempt = 0 - timeout = options[:timeout].to_f begin attempt += 1 - send_request_with_timeout(timeout, attempt) + send_request_with_timeout(attempt) parse_response rescue RequestTimeout retry if attempt < CLIENT_RETRIES @@ -190,7 +189,10 @@ def send_request_with_lazy_pirate def rcv_timeout @rcv_timeout ||= begin - if ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") + case + when options[:timeout] then + options[:timeout] + when ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i else 300_000 # 300 seconds @@ -200,7 +202,10 @@ def rcv_timeout def snd_timeout @snd_timeout ||= begin - if ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") + case + when options[:timeout] then + options[:timeout] + when ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i else 300_000 # 300 seconds @@ -208,14 +213,14 @@ def snd_timeout end end - def send_request_with_timeout(timeout, attempt = 0) + def send_request_with_timeout(attempt = 0) socket = create_socket socket.setsockopt(::ZMQ::RCVTIMEO, rcv_timeout) socket.setsockopt(::ZMQ::SNDTIMEO, snd_timeout) logger.debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } zmq_eagain_error_check(socket.send_string(@request_data), :socket_send_string) - logger.debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Waiting #{rcv_timeout}ms for response (attempt #{attempt}, #{socket})") } zmq_eagain_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } rescue ZmqEagainError From dbf700a05b394e26da31b38ecb8697ec975d1240 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 16 Sep 2014 11:26:00 -0600 Subject: [PATCH 0737/1191] bump to 3.3.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index bd177730..b5918f09 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.4' + VERSION = '3.3.5' end From 720a8624293c815ac7b8ba25cc2219c145aae731 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 09:56:28 -0700 Subject: [PATCH 0738/1191] Travis tests latest 2.1 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2e5e625..58ed2fde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: ruby rvm: - - "1.9.3" - - "2.0.0" - - "2.1.1" + - 1.9.3 + - 2.0.0 + - 2.1 script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib notifications: webhooks: From 731f61b8902aea758eb42b63ff83c5e5b71b708f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 09:56:45 -0700 Subject: [PATCH 0739/1191] PerfTools is dead, long live RubyProf --- protobuf.gemspec | 8 +++++--- spec/benchmark/tasks.rb | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index 2e3b254f..0a105c7d 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -25,11 +25,13 @@ require "protobuf/version" s.add_dependency 'thread_safe' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'pry-nav' + s.add_development_dependency 'pry' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' s.add_development_dependency 'simplecov' - s.add_development_dependency 'yard' s.add_development_dependency 'timecop' - s.add_development_dependency 'perftools.rb' + s.add_development_dependency 'yard' + + s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby + s.add_development_dependency 'pry-nav' unless RUBY_ENGINE.to_sym == :rbx end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index f90554fd..313a9da8 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -3,11 +3,13 @@ require 'support/all' require 'support/test/resource_service' -begin - require 'perftools' -rescue LoadError - $stderr.puts 'perftools must be uncommented in the gemspec before you can run this benchmark task' - exit(1) +case RUBY_ENGINE.to_sym +when :ruby + require 'ruby-prof' +when :rbx + require 'rubinius/profiler' +when :jruby + require 'jruby/profiler' end # Including a way to turn on debug logger for spec runs @@ -66,7 +68,8 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) desc "benchmark ZMQ client with ZMQ server and profile" task :zmq_profile, [:number, :length, :profile_output] do |t, args| args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}") - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + + profile_code(args[:profile_output]) do zmq_client_zmq_server(args[:number], args[:length]) end @@ -77,7 +80,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) task :profile_protobuf_new, [:number, :profile_output] do |t, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + profile_code(args[:profile_output]) do args[:number].to_i.times { Test::Resource.new(create_params) } end @@ -88,13 +91,32 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) task :profile_protobuf_serialize, [:number, :profile_output] do |t, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + profile_code(args[:profile_output]) do args[:number].to_i.times { Test::Resource.new(create_params).serialize } end puts args[:profile_output] end + def profile_code(output, &block) + case RUBY_ENGINE.to_sym + when :ruby + profile_data = RubyProf.profile(&block) + RubyProf::FlatPrinter.new(profile_data).print(:path => output) + when :rbx + profiler = Rubinius::Profiler::Instrumenter.new + profiler.profile(false, &block) + File.open(output, 'w') do |f| + profiler.show(f) + end + when :jruby + profile_data = JRuby::Profiler.profile(&block) + File.open(output, 'w') do |f| + JRuby::Profiler::FlatProfilePrinter.new(profile_data).printProfile(f) + end + end + end + desc "benchmark Socket client with Socket server" task :sock_client_sock_server, [:number, :length] do |t, args| args.with_defaults(:number => 1000, :length => 100) From 78940bc8e3e1aeaebe941457046e82084335118a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 10:04:48 -0700 Subject: [PATCH 0740/1191] Actually run tests in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 58ed2fde..ba6460cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ rvm: - 1.9.3 - 2.0.0 - 2.1 -script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib +script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake notifications: webhooks: urls: From 3bd041450a1e09c700c566e8b3967de87235430c Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 10:08:36 -0700 Subject: [PATCH 0741/1191] These error messages were updated --- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index ffeecc7b..51784817 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -42,7 +42,7 @@ c.on_failure {|e| error = e} end - expect(error.message).to match(/name.*required/) + expect(error.message).to match(/Required field.*does not have a value/) end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 053eb383..c2fbcd79 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -69,7 +69,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure {|e| error = e } end - expect(error.message).to match(/name.*required/) + expect(error.message).to match(/Required field.*does not have a value/) end end From 1dc660deec27728ad244e39c9b00b5405405e85d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 11:26:57 -0700 Subject: [PATCH 0742/1191] 646e5a1 changed this check interval to 5 seconds --- spec/lib/protobuf/rpc/service_directory_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 350f9f74..577fbe8e 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -198,7 +198,7 @@ def send_beacon(type, server) it "should not return expired listings" do send_beacon(:heartbeat, hello_server_with_short_ttl) - sleep 1 + sleep 5 expect(subject.lookup("HelloService")).to be_nil end From 6dcb0fa3c94ef2ff2fbe85c1bdeff74acbbb5923 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 22:37:06 -0700 Subject: [PATCH 0743/1191] Order matters! --- lib/protobuf/message/fields.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 2e6afab8..30023e6a 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -45,7 +45,7 @@ def extensions(range) # def all_fields - @all_fields ||= field_store.values.uniq + @all_fields ||= field_store.values.uniq.sort_by(&:tag) end def extension_fields From 8e087ce31b472d4b3bc8c86f0852dc703f3fe188 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 22:45:41 -0700 Subject: [PATCH 0744/1191] Need some libzmq --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ba6460cf..63fdd050 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +before_install: sudo apt-get install libzmq3-dev language: ruby rvm: - 1.9.3 From aeb77c17218053d0316703f0eca5a4b243150c2a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 22:48:38 -0700 Subject: [PATCH 0745/1191] More rubies --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 63fdd050..8cbe3331 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,12 @@ rvm: - 1.9.3 - 2.0.0 - 2.1 + - jruby + - rbx-2 +matrix: + allow_failures: + - rvm: jruby + - rvm: rbx-2 script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake notifications: webhooks: From b378b738b2f529936ea8b346f9ef15c245bab102 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 30 Sep 2014 00:05:31 -0700 Subject: [PATCH 0746/1191] `StringIO#set_encoding` returns a string in RBX --- lib/protobuf/message/serialization.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index bfe58faf..05e3c1b8 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -44,8 +44,10 @@ def decode_from(stream) # Encode this message # def encode - stream = ::StringIO.new.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream).string + ::StringIO.new.tap do |stream| + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + end.string end # Encode this message to the given stream. @@ -81,4 +83,3 @@ def set_field_bytes(tag, bytes) end end end - From c5572080e7d9d643c4922e9b289282cc39bea987 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 1 Oct 2014 23:20:57 -0600 Subject: [PATCH 0747/1191] Fix flakey spec by closing write pipe, generating an empty test module Signed-off-by: Tamir Duberstein --- spec/bin/protoc-gen-ruby_spec.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb index 36cd7add..cbbce0da 100644 --- a/spec/bin/protoc-gen-ruby_spec.rb +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -4,15 +4,20 @@ describe 'protoc-gen-ruby' do let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) } - let(:request_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:file_to_generate => [ "test/foo.proto" ]) } - let(:expected_file) { ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') } - let(:expected_response_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(:files => [ expected_file ]) } + let(:package) { 'test' } + let(:request_bytes) do + ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode( + :proto_file => [{ :package => package }], + ) + end it 'reads the serialized request bytes and outputs serialized response bytes' do ::IO.popen(binpath, 'w+') do |pipe| pipe.write(request_bytes) - expect(pipe.read(expected_response_bytes.size)).to eq expected_response_bytes + pipe.close_write # needed so we can implicitly read until EOF + response_bytes = pipe.read + response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(response_bytes) + expect(response.file.first.content).to include("module #{package.titleize}") end end end - From 432e68b87adc3e70379e1fd17e792b090fc3c568 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 2 Oct 2014 22:43:15 -0600 Subject: [PATCH 0748/1191] Cleanup shutdown procedure --- lib/protobuf/rpc/servers/zmq/broker.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 89333742..7f79e5be 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -29,7 +29,7 @@ def run rc = @poller.poll(500) # The server was shutdown and no requests are pending - break if rc == 0 && !running? + break if rc == 0 && !running? && @server.workers.empty? # Something went wrong break if rc == -1 @@ -42,7 +42,7 @@ def run end def running? - @server.running? || @server.workers.any? + @server.running? end private @@ -113,7 +113,7 @@ def inproc? end def local_queue_available? - local_queue.size < local_queue_max_size + local_queue.size < local_queue_max_size && running? end def local_queue_max_size From 4aa9f04e19d6d8305462c345c152914c6d475cef Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 8 Oct 2014 18:36:30 -0600 Subject: [PATCH 0749/1191] Force exit after clean shutdown --- lib/protobuf/cli.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index ad0716c6..2eb72218 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -219,7 +219,6 @@ def shutdown_server logger.info { 'RPC Server shutting down...' } @runner.try(:stop) ::Protobuf::Rpc::ServiceDirectory.instance.stop - logger.info { 'Shutdown complete' } end # Start the runner and log the relevant options. @@ -233,6 +232,10 @@ def start_server ::ActiveSupport::Notifications.instrument("after_server_bind") end + + logger.info { 'Shutdown complete' } + + exit 0 end end end From 0a357a5f11aa5bc5ef0792cc36c7f6535fd6676f Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Fri, 10 Oct 2014 15:45:42 -0600 Subject: [PATCH 0750/1191] Bump version to v3.3.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b5918f09..8dfbb929 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.5' + VERSION = '3.3.6' end From 96248f5667fa63a947452b4200a66eb668d664db Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:42:27 -0700 Subject: [PATCH 0751/1191] actually compile the protos --- .travis.yml | 6 ++++-- install-protobuf.sh | 8 ++++++++ spec/spec_helper.rb | 11 +++-------- 3 files changed, 15 insertions(+), 10 deletions(-) create mode 100755 install-protobuf.sh diff --git a/.travis.yml b/.travis.yml index 8cbe3331..61185537 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ -before_install: sudo apt-get install libzmq3-dev +before_install: + - sudo apt-get update -qq + - sudo apt-get install -y libzmq3-dev + - sudo ./install-protobuf.sh language: ruby rvm: - 1.9.3 @@ -10,7 +13,6 @@ matrix: allow_failures: - rvm: jruby - rvm: rbx-2 -script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake notifications: webhooks: urls: diff --git a/install-protobuf.sh b/install-protobuf.sh new file mode 100755 index 00000000..22488b28 --- /dev/null +++ b/install-protobuf.sh @@ -0,0 +1,8 @@ +set -ex + +basename=protobuf-2.6.0 +tarball=$basename.tar.bz2 + +wget https://protobuf.googlecode.com/svn/rc/$tarball +tar -xvf $tarball +cd $basename && ./configure --prefix=/usr && make && make install diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fa22f2ce..20cd2fe4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,15 +27,10 @@ ENV.delete("PB_IGNORE_DEPRECATIONS") ::RSpec.configure do |c| - c.mock_with :rspec - c.before(:suite) do - unless ENV['NO_COMPILE_TEST_PROTOS'] - require 'rake' - load ::File.expand_path('../../Rakefile', __FILE__) - $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - ::Rake::Task['compile:spec'] - end + require 'rake' + load ::File.expand_path('../../Rakefile', __FILE__) + ::Rake::Task['compile:spec'].invoke end end From f4d14bd86df9f7d40c9791602b2f30411b16caab Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:21:34 -0700 Subject: [PATCH 0752/1191] Add RuboCop --- .rubocop.yml | 13 ++ .rubocop_todo.yml | 422 ++++++++++++++++++++++++++++++++++++++++++++++ Rakefile | 7 +- protobuf.gemspec | 1 + 4 files changed, 440 insertions(+), 3 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..20b78655 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,13 @@ +inherit_from: .rubocop_todo.yml + +Lint/Loop: + Enabled: false + +Style/CaseIndentation: + IndentWhenRelativeTo: end + +Style/IndentHash: + EnforcedStyle: consistent + +Style/TrailingComma: + EnforcedStyleForMultiline: comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..8ffb2799 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,422 @@ +# This configuration was generated by `rubocop --auto-gen-config` +# on 2014-10-14 08:30:47 -0700 using RuboCop version 0.26.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/BlockAlignment: + Enabled: false + +# Offense count: 2 +Lint/ParenthesesAsGroupedExpression: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/StringConversionInInterpolation: + Enabled: false + +# Offense count: 1 +Lint/UnderscorePrefixedVariableName: + Enabled: false + +# Offense count: 27 +# Cop supports --auto-correct. +Lint/UnusedBlockArgument: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Lint/UnusedMethodArgument: + Enabled: false + +# Offense count: 8 +Lint/UselessAssignment: + Enabled: false + +# Offense count: 3 +Metrics/BlockNesting: + Max: 5 + +# Offense count: 9 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 236 + +# Offense count: 3 +Metrics/CyclomaticComplexity: + Max: 11 + +# Offense count: 515 +# Configuration parameters: AllowURI, URISchemes. +Metrics/LineLength: + Max: 196 + +# Offense count: 45 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 41 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 6 + +# Offense count: 2 +Metrics/PerceivedComplexity: + Max: 12 + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/AccessModifierIndentation: + Enabled: false + +# Offense count: 2 +Style/AccessorMethodName: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/AlignArray: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/AndOr: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/BarePercentLiterals: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +Style/BlockEndNewline: + Enabled: false + +# Offense count: 67 +# Cop supports --auto-correct. +Style/Blocks: + Enabled: false + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/BracesAroundHashParameters: + Enabled: false + +# Offense count: 4 +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/ClassAndModuleChildren: + Enabled: false + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: PreferredMethods. +Style/CollectionMethods: + Enabled: false + +# Offense count: 5 +# Configuration parameters: Keywords. +Style/CommentAnnotation: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +Style/DeprecatedHashMethods: + Enabled: false + +# Offense count: 191 +Style/Documentation: + Enabled: false + +# Offense count: 15 +Style/DoubleNegation: + Enabled: false + +# Offense count: 2 +Style/EachWithObject: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs. +Style/EmptyLineBetweenDefs: + Enabled: false + +# Offense count: 35 +# Cop supports --auto-correct. +Style/EmptyLines: + Enabled: false + +# Offense count: 10 +# Cop supports --auto-correct. +Style/EmptyLinesAroundAccessModifier: + Enabled: false + +# Offense count: 146 +# Cop supports --auto-correct. +Style/EmptyLinesAroundBody: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EmptyLiteral: + Enabled: false + +# Offense count: 2 +# Configuration parameters: Exclude. +Style/FileName: + Enabled: false + +# Offense count: 20 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Enabled: false + +# Offense count: 672 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/HashSyntax: + Enabled: false + +# Offense count: 2 +# Configuration parameters: MaxLineLength. +Style/IfUnlessModifier: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/IndentationConsistency: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/IndentationWidth: + Enabled: false + +# Offense count: 14 +Style/Lambda: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/LeadingCommentSpace: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/MethodDefParentheses: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/MultilineBlockLayout: + Enabled: false + +# Offense count: 3 +# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. +Style/Next: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: IncludeSemanticChanges. +Style/NonNilCheck: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/Not: + Enabled: false + +# Offense count: 46 +# Cop supports --auto-correct. +Style/NumericLiterals: + MinDigits: 21 + +# Offense count: 1 +Style/OpMethod: + Enabled: false + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Enabled: false + +# Offense count: 7 +# Configuration parameters: NamePrefix, NamePrefixBlacklist. +Style/PredicateName: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +Style/Proc: + Enabled: false + +# Offense count: 8 +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/RaiseArgs: + Enabled: false + +# Offense count: 1 +Style/RedundantException: + Enabled: false + +# Offense count: 20 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Enabled: false + +# Offense count: 26 +# Cop supports --auto-correct. +Style/RedundantSelf: + Enabled: false + +# Offense count: 2 +Style/RescueModifier: + Enabled: false + +# Offense count: 1 +Style/SelfAssignment: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AllowAsExpressionSeparator. +Style/Semicolon: + Enabled: false + +# Offense count: 66 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SignalException: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowIfMethodIsEmpty. +Style/SingleLineMethods: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/SpaceAfterColon: + Enabled: false + +# Offense count: 9 +# Cop supports --auto-correct. +Style/SpaceAfterComma: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/SpaceAfterNot: + Enabled: false + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SpaceAroundEqualsInParameterDefault: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/SpaceAroundOperators: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SpaceBeforeBlockBraces: + Enabled: false + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +Style/SpaceInsideBlockBraces: + Enabled: false + +# Offense count: 134 +# Cop supports --auto-correct. +Style/SpaceInsideBrackets: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. +Style/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 8 +# Cop supports --auto-correct. +Style/SpaceInsideParens: + Enabled: false + +# Offense count: 12 +# Cop supports --auto-correct. +Style/SpecialGlobalVars: + Enabled: false + +# Offense count: 464 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/StringLiterals: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/Tab: + Enabled: false + +# Offense count: 57 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/TrailingBlankLines: + Enabled: false + +# Offense count: 35 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. +Style/TrailingComma: + Enabled: false + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. +Style/TrivialAccessors: + Enabled: false + +# Offense count: 1 +Style/UnlessElse: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/UnneededPercentQ: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/WhileUntilDo: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +Style/WordArray: + MinSize: 2 diff --git a/Rakefile b/Rakefile index d32e29e3..d5feb73f 100644 --- a/Rakefile +++ b/Rakefile @@ -8,11 +8,12 @@ require 'bundler/gem_tasks' require 'benchmark/tasks' require 'rspec/core/rake_task' - -desc 'Default: run specs.' -task :default => :spec +require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) +RuboCop::RakeTask.new + +task :default => [:spec, :rubocop] desc 'Run specs' namespace :compile do diff --git a/protobuf.gemspec b/protobuf.gemspec index 0a105c7d..495a8aa7 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -28,6 +28,7 @@ require "protobuf/version" s.add_development_dependency 'pry' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' + s.add_development_dependency 'rubocop' s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' s.add_development_dependency 'yard' From 3f8587a617479737e298541619228d3fe9955642 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:27:25 -0700 Subject: [PATCH 0753/1191] Lint/AssignmentInCondition --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 4 ++-- lib/protobuf/rpc/servers/zmq/server.rb | 13 ++++--------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8ffb2799..bbb5b46a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Enabled: false - # Offense count: 1 # Cop supports --auto-correct. Lint/BlockAlignment: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 4d1df27c..a608898a 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -128,13 +128,13 @@ def ==(obj) end def [](name) - if field = self.class.get_field(name, true) + if (field = self.class.get_field(name, true)) __send__(field.getter) end end def []=(name, value) - if field = self.class.get_field(name, true) + if (field = self.class.get_field(name, true)) __send__(field.setter, value) unless value.nil? else unless ::Protobuf.ignore_unknown_fields? diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c45c487f..2264f44b 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -62,15 +62,10 @@ def beacon_ip end def beacon_port - unless @beacon_port - unless port = options[:beacon_port] - port = ::Protobuf::Rpc::ServiceDirectory.port - end - - @beacon_port = port.to_i - end - - @beacon_port + @beacon_port ||= options.fetch( + :beacon_port, + ::Protobuf::Rpc::ServiceDirectory.port, + ).to_i end def beacon_uri From 2d89a19582847ed425fef93dcd38fffcc655d00c Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:28:41 -0700 Subject: [PATCH 0754/1191] Lint/BlockAlignment --- .rubocop_todo.yml | 5 ----- .../protobuf/generators/enum_generator_spec.rb | 15 ++++++++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bbb5b46a..45bf1278 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -Lint/BlockAlignment: - Enabled: false - # Offense count: 2 Lint/ParenthesesAsGroupedExpression: Enabled: false diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index a2dbbb0d..1521ced4 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -22,23 +22,25 @@ describe '#compile' do let(:compiled) { - %q{class TestEnum < ::Protobuf::Enum + <<-RUBY +class TestEnum < ::Protobuf::Enum define :FOO, 1 define :BAR, 2 define :BAZ, 3 end -} + RUBY } - it 'compiles the enum and it\'s field values' do + it 'compiles the enum and its field values' do subject.compile expect(subject.to_s).to eq(compiled) end context 'when allow_alias option is set' do let(:compiled) { - %q{class TestEnum < ::Protobuf::Enum + <<-RUBY +class TestEnum < ::Protobuf::Enum set_option :allow_alias define :FOO, 1 @@ -46,8 +48,8 @@ define :BAZ, 3 end -} - } + RUBY + } let(:options) { { :allow_alias => true } } @@ -65,4 +67,3 @@ end end - From 8c5a073b7d5b2d3e61141496fc150a4b2c5e5aad Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:31:37 -0700 Subject: [PATCH 0755/1191] Lint/ParenthesesAsGroupedExpression --- .rubocop_todo.yml | 4 ---- lib/protobuf/rpc/connectors/zmq.rb | 2 +- spec/support/test/resource_service.rb | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 45bf1278..87ea6d32 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,10 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -Lint/ParenthesesAsGroupedExpression: - Enabled: false - # Offense count: 2 # Cop supports --auto-correct. Lint/StringConversionInInterpolation: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index da7e9cd3..5b2dbd24 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -131,7 +131,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep (1.0/100.0) + sleep(1.0/100.0) end raise "Host not found for service #{service}" diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index 226ea0da..41e2f93a 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -13,7 +13,7 @@ def find # request -> Test::ResourceSleepRequest # response -> Test::Resource def find_with_sleep - sleep (request.sleep || 1) + sleep(request.sleep || 1) response.name = 'Request should have timed out' end From c01eccf18d8cb1dd37a99a0ee172688be0f2faf1 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:32:04 -0700 Subject: [PATCH 0756/1191] Lint/StringConversionInInterpolation --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/client.rb | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 87ea6d32..dc358eec 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# Cop supports --auto-correct. -Lint/StringConversionInInterpolation: - Enabled: false - # Offense count: 1 Lint/UnderscorePrefixedVariableName: Enabled: false diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 373e3b0e..57fc6b57 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -106,10 +106,10 @@ def on_success=(callable) def method_missing(method_name, *params) service = options[:service] unless service.rpc_method?(method_name) - logger.error { sign_message("#{service.name}##{method_name.to_s} not rpc method, passing to super") } + logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } super(method_name, *params) else - logger.debug { sign_message("#{service.name}##{method_name.to_s}") } + logger.debug { sign_message("#{service.name}##{method_name}") } rpc = service.rpcs[method_name.to_sym] options[:request_type] = rpc.request_type From 1c568743e8a9b9f65077e8b182c21d936d83075f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:33:06 -0700 Subject: [PATCH 0757/1191] Lint/UnderscorePrefixedVariableName --- .rubocop_todo.yml | 4 ---- spec/lib/protobuf/rpc/connectors/common_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dc358eec..6e1bb454 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,10 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/UnderscorePrefixedVariableName: - Enabled: false - # Offense count: 27 # Cop supports --auto-correct. Lint/UnusedBlockArgument: diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index ce839263..1b945222 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -133,10 +133,10 @@ stats = double("Object") allow(stats).to receive(:stop).and_return(true) subject.stats = stats - _cb = double("Object") + some_cb = double("Object") - subject.instance_variable_set("@#{cb}", _cb) - expect(_cb).to receive(:call).and_return(true) + subject.instance_variable_set("@#{cb}", some_cb) + expect(some_cb).to receive(:call).and_return(true) subject.method(meth).call(*args) end From 2d72baafe11b4635734495bcb5a2e01199521123 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:39:00 -0700 Subject: [PATCH 0758/1191] Lint/UnusedBlockArgument --- .rubocop_todo.yml | 5 ----- Rakefile | 4 ++-- lib/protobuf/generators/file_generator.rb | 9 ++++----- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- lib/protobuf/tasks/compile.rake | 4 ++-- spec/benchmark/tasks.rb | 14 +++++++------- spec/functional/zmq_server_spec.rb | 4 ++-- spec/lib/protobuf/rpc/service_filters_spec.rb | 8 ++++---- 10 files changed, 25 insertions(+), 31 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6e1bb454..4799377e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 27 -# Cop supports --auto-correct. -Lint/UnusedBlockArgument: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. Lint/UnusedMethodArgument: diff --git a/Rakefile b/Rakefile index d5feb73f..30f57c70 100644 --- a/Rakefile +++ b/Rakefile @@ -19,7 +19,7 @@ desc 'Run specs' namespace :compile do desc 'Compile spec protos in spec/supprt/ directory' - task :spec do |task, args| + task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} @@ -28,7 +28,7 @@ namespace :compile do end desc 'Compile rpc protos in protos/ directory' - task :rpc do |task, args| + task :rpc do proto_path = ::File.expand_path('../proto', __FILE__) output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 86ee0b44..63fb9412 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -23,7 +23,6 @@ def file_name def compile run_once(:compile) do map_extensions(descriptor, [ descriptor.package ]) - extract_dangling_extensions print_file_comment print_generic_requires @@ -34,7 +33,7 @@ def compile group.add_enums(descriptor.enum_type, :namespace => [ descriptor.package ]) group.add_message_declarations(descriptor.message_type) group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [ descriptor.package ]) - group.add_extended_messages(@unknown_extensions) + group.add_extended_messages(unknown_extensions) group.add_services(descriptor.service) group.add_header(:enum, 'Enum Classes') @@ -48,9 +47,9 @@ def compile end end - def extract_dangling_extensions - @unknown_extensions = @extension_fields.select do |k, v| - ! @known_messages.include?(k) + def unknown_extensions + @unknown_extensions ||= @extension_fields.reject do |k, _| + @known_messages.include?(k) end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index b1c2fa2c..a4d6e9a4 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -13,7 +13,7 @@ def self.register(event_name, &blk) ERROR end - ::ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, args| + ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| blk.call(*args) end end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index cddc7a53..10735e25 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -204,7 +204,7 @@ def remove_listing(uuid) logger.debug { sign_message("Removing listing: #{listing.inspect}") } - @listings_by_service.each do |service, listings| + @listings_by_service.each_value do |listings| listings.delete(listing) end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 6eab5654..14be45b2 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -120,7 +120,7 @@ def invoke_via_except?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_if?(rpc_method, filter) - if_check = filter.fetch(:if) { lambda { |service| return true } } + if_check = filter.fetch(:if) { lambda { |_service| return true } } do_invoke = case when if_check.nil? then true @@ -150,7 +150,7 @@ def invoke_via_only?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_unless?(rpc_method, filter) - unless_check = filter.fetch(:unless) { lambda { |service| return false } } + unless_check = filter.fetch(:unless) { lambda { |_service| return false } } skip_invoke = case when unless_check.nil? then false diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index 756fdc44..603a3efc 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -3,7 +3,7 @@ require 'fileutils' namespace :protobuf do desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' - task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |tasks, args| + task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |_tasks, args| args.with_defaults(:destination => 'lib') args.with_defaults(:source => 'definitions') args.with_defaults(:plugin => 'ruby') @@ -27,7 +27,7 @@ namespace :protobuf do end desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' - task :clean, [ :package, :destination, :file_extension ] do |task, args| + task :clean, [ :package, :destination, :file_extension ] do |_task, args| args.with_defaults(:destination => 'lib') args.with_defaults(:file_extension => '.pb.rb') diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 313a9da8..899e882a 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -34,7 +34,7 @@ def benchmark_wrapper(global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |_server| client = ::Test::ResourceService.client(:port => 9399) benchmark_wrapper(global_bench) do |bench| @@ -60,13 +60,13 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) end desc "benchmark ZMQ client with ZMQ server" - task :zmq_client_zmq_server, [:number, :length] do |t, args| + task :zmq_client_zmq_server, [:number, :length] do |_task, args| args.with_defaults(:number => 1000, :length => 100) zmq_client_zmq_server(args[:number], args[:length]) end desc "benchmark ZMQ client with ZMQ server and profile" - task :zmq_profile, [:number, :length, :profile_output] do |t, args| + task :zmq_profile, [:number, :length, :profile_output] do |_task, args| args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}") profile_code(args[:profile_output]) do @@ -77,7 +77,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) end desc "benchmark Protobuf Message #new" - task :profile_protobuf_new, [:number, :profile_output] do |t, args| + task :profile_protobuf_new, [:number, :profile_output] do |_task, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do @@ -88,7 +88,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) end desc "benchmark Protobuf Message #serialize" - task :profile_protobuf_serialize, [:number, :profile_output] do |t, args| + task :profile_protobuf_serialize, [:number, :profile_output] do |_task, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do @@ -118,13 +118,13 @@ def profile_code(output, &block) end desc "benchmark Socket client with Socket server" - task :sock_client_sock_server, [:number, :length] do |t, args| + task :sock_client_sock_server, [:number, :length] do |_task, args| args.with_defaults(:number => 1000, :length => 100) sock_client_sock_server(args[:number], args[:length]) end desc "benchmark server performance" - task :servers, [:number, :length] do |t, args| + task :servers, [:number, :length] do |_task, args| args.with_defaults(:number => 1000, :length => 100) Benchmark.bm(10) do |bench| diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index c2fbcd79..a138024a 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -39,8 +39,8 @@ end it 'runs under heavy load' do - 10.times do |x| - 5.times.map do |y| + 10.times do + 5.times do Thread.new do client = ::Test::ResourceService.client diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 14ce7ac7..cc6e7b1b 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -149,7 +149,7 @@ def verify_before; @called << :verify_before; end context 'when "if" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |service| true }) + FilterTest.before_filter(:verify_before, :if => lambda { |_service| true }) end it 'invokes the filter' do @@ -173,7 +173,7 @@ def verify_before; @called << :verify_before; end context 'when "if" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |service| false }) + FilterTest.before_filter(:verify_before, :if => lambda { |_service| false }) end it 'skips the filter' do @@ -208,7 +208,7 @@ def verify_before; @called << :verify_before; end context 'when "unless" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |service| false }) + FilterTest.before_filter(:verify_before, :unless => lambda { |_service| false }) end it 'invokes the filter' do @@ -232,7 +232,7 @@ def verify_before; @called << :verify_before; end context 'when "unless" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |service| true }) + FilterTest.before_filter(:verify_before, :unless => lambda { |_service| true }) end it 'skips the filter' do From 29bb6c9f7033c91deb448bc465784add71bdccd2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:42:54 -0700 Subject: [PATCH 0759/1191] Lint/UnusedMethodArgument --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/base_field.rb | 10 +++++----- lib/protobuf/rpc/service_dispatcher.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4799377e..aa53b447 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 6 -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Enabled: false - # Offense count: 8 Lint/UselessAssignment: Enabled: false diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index b688f180..902dda63 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -51,7 +51,7 @@ def initialize(message_class, rule, type_class, name, tag, options) # Public Instance Methods # - def acceptable?(value) + def acceptable?(_value) true end @@ -59,8 +59,8 @@ def coerce!(value) value end - def decode(bytes) - raise NotImplementedError, "#{self.class.name}\#decode" + def decode(_bytes) + raise NotImplementedError, "#{self.class.name}##{__method__}" end def default @@ -79,8 +79,8 @@ def deprecated? options.key?(:deprecated) end - def encode(value) - raise NotImplementedError, "#{self.class.name}\#encode" + def encode(_value) + raise NotImplementedError, "#{self.class.name}##{__method__}" end def extension? diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 91dacb42..70aa476e 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -7,7 +7,7 @@ class ServiceDispatcher attr_reader :env - def initialize(app) + def initialize(_app) # End of the line... end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 14be45b2..12e45e97 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -119,7 +119,7 @@ def invoke_via_except?(rpc_method, filter) # Value can either be a symbol/string indicating an instance method to call # or an object that responds to `call`. # - def invoke_via_if?(rpc_method, filter) + def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { lambda { |_service| return true } } do_invoke = case when if_check.nil? then @@ -149,7 +149,7 @@ def invoke_via_only?(rpc_method, filter) # Value can either be a symbol/string indicating an instance method to call # or an object that responds to `call`. # - def invoke_via_unless?(rpc_method, filter) + def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { lambda { |_service| return false } } skip_invoke = case when unless_check.nil? then From c5c55fccda2f59d834a60c52ed7938d6bb800abb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:43:44 -0700 Subject: [PATCH 0760/1191] Lint/UselessAssignment --- .rubocop_todo.yml | 4 ---- lib/protobuf/generators/field_generator.rb | 4 ++-- lib/protobuf/rpc/buffer.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 2 -- lib/protobuf/rpc/servers/socket/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 7 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index aa53b447..892c87bc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,10 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 8 -Lint/UselessAssignment: - Enabled: false - # Offense count: 3 Metrics/BlockNesting: Max: 5 diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 5ff0295b..b2a4117e 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -91,10 +91,10 @@ def type_name @type_name ||= begin case descriptor.type.name when :TYPE_MESSAGE, :TYPE_ENUM, :TYPE_GROUP then - type_name = modulize(descriptor.type_name) + modulize(descriptor.type_name) else type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '') - type_name = ":#{type_name}" + ":#{type_name}" end end end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 1281e697..e6509bed 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -26,9 +26,9 @@ def mode=(mode) def write(force_mode=true) if force_mode and reading? - mode = :write + self.mode = :write elsif not force_mode and reading? - raise = 'You chose to write the buffer when in read mode' + raise 'You chose to write the buffer when in read mode' end @size = @data.length diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 2ef5b9a1..747eef3b 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -9,7 +9,7 @@ module Common def any_callbacks? return [@complete_cb, @failure_cb, @success_cb].inject(false) do |reduction, cb| - reduction = (reduction || !cb.nil?) + reduction || !cb.nil? end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 5b2dbd24..ab65f7cd 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -75,8 +75,6 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - socket = nil - begin server_uri = lookup_server_uri socket = zmq_context.socket(::ZMQ::REQ) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index e184c9d8..01fa55d6 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -74,7 +74,7 @@ def run # no-op when client == @server then logger.debug { sign_message("Accepted new connection") } - client, sockaddr = @server.accept + client, _sockaddr = @server.accept @listen_fds << client else unless @working.include?(client) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 89333742..3be992db 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -121,7 +121,7 @@ def local_queue_max_size end def process_backend - worker, ignore, *frames = read_from_backend + worker, _ignore, *frames = read_from_backend @idle_workers << worker From e82087d2909d2d0c76e1902f94ba77b80cb551e7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:49:04 -0700 Subject: [PATCH 0761/1191] Style/AccessModifierIndentation --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/middleware/exception_handler.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 4 ++-- lib/protobuf/rpc/middleware/request_decoder.rb | 2 +- lib/protobuf/rpc/middleware/response_encoder.rb | 2 +- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_dispatcher.rb | 2 +- 8 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 892c87bc..ba694e74 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AccessModifierIndentation: - Enabled: false - # Offense count: 2 Style/AccessorMethodName: Enabled: false diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index e6509bed..21b7e218 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -67,7 +67,7 @@ def get_data_size end end - private + private def check_for_flush if !@size.nil? && @data.length == @size diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index b29ea29b..4f3757a6 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -22,7 +22,7 @@ def call(env) env end - private + private # Wrap exceptions in a generic Protobuf errors unless they already are # diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index 9f4bd308..08a2c801 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -19,7 +19,7 @@ def call(env) env end - private + private def instrumenter @instrumenter ||= Instrumenter.new @@ -67,7 +67,7 @@ def to_s(env) ].compact.join(' - ') end - private + private def elapsed_time (@start_time && @end_time ? "#{(@end_time - @start_time).round(4)}s" : nil) diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index de42a77b..c142a586 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -30,7 +30,7 @@ def log_signature env.log_signature || super end - private + private def method_name @method_name ||= begin diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 11c53613..ec30bafa 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -22,7 +22,7 @@ def log_signature env.log_signature || super end - private + private # Encode the response wrapper to return to the client # diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 1c5f1e8c..48148231 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -147,7 +147,7 @@ def rpcs self.class.rpcs end - private + private def request_type @_request_type ||= env.request_type diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 70aa476e..991fd657 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -22,7 +22,7 @@ def rpc_service @rpc_service ||= env.rpc_service.new(env) end - private + private # Call the given service method. def dispatch_rpc_request From b528b60a04c9a88a14d7f451048c5d309e170890 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:53:22 -0700 Subject: [PATCH 0762/1191] Style/AccessorMethodName --- .rubocop_todo.yml | 4 ---- lib/protobuf/rpc/buffer.rb | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ba694e74..5b7a8fd9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,10 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 2 -Style/AccessorMethodName: - Enabled: false - # Offense count: 7 # Cop supports --auto-correct. Style/AlignArray: diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 21b7e218..4d628c34 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -43,7 +43,7 @@ def <<(data) end end - def set_data(data) + def set_data(data) # rubocop:disable Style/AccessorMethodName @data = data.to_s @size = @data.size end @@ -60,7 +60,7 @@ def flushed? @flush end - def get_data_size + def get_data_size # rubocop:disable Style/AccessorMethodName if @size == 0 || @data.match(SIZE_REGEX) sliced_size = @data.slice!(SIZE_REGEX) @size = sliced_size.gsub('-', '').to_i unless sliced_size.nil? From 1042d99b9e27fe277a01029904f1453579024f89 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:55:36 -0700 Subject: [PATCH 0763/1191] Style/AlignArray --- .rubocop_todo.yml | 5 ---- spec/lib/protobuf/message_spec.rb | 11 ++++++--- spec/lib/protobuf/rpc/service_filters_spec.rb | 24 ++++++++++++------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5b7a8fd9..efc71076 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 7 -# Cop supports --auto-correct. -Style/AlignArray: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 7d64f1ea..e67f1b18 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -389,9 +389,14 @@ Test::Resource.new(:name => 'Resource 2') ]) - expect(proto.to_hash).to eq({ :multiple_resources => [ { :name => 'Resource 1' }, - { :name => 'Resource 2' } ] }) - + expect(proto.to_hash).to eq( + { + :multiple_resources => [ + { :name => 'Resource 1' }, + { :name => 'Resource 2' }, + ], + } + ) end end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index cc6e7b1b..c147ced5 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -331,11 +331,15 @@ def inner_around it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :outer_around_top, - :inner_around_top, - :endpoint, - :inner_around_bottom, - :outer_around_bottom ]) + expect(subject.called).to eq( + [ + :outer_around_top, + :inner_around_top, + :endpoint, + :inner_around_bottom, + :outer_around_bottom, + ] + ) end context 'when around_filter does not yield' do @@ -356,9 +360,13 @@ def inner_around it 'cancels calling the rest of the filters and the endpoint' do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :outer_around_top, - :inner_around, - :outer_around_bottom ]) + expect(subject.called).to eq( + [ + :outer_around_top, + :inner_around, + :outer_around_bottom, + ] + ) end end From 77b8d1bf7a5aba872bcc171bfccb742835d6a5c8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:13:23 -0700 Subject: [PATCH 0764/1191] Style/AndOr --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/buffer.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index efc71076..092b2510 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AndOr: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 4d628c34..bec96248 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -25,9 +25,9 @@ def mode=(mode) end def write(force_mode=true) - if force_mode and reading? + if force_mode && reading? self.mode = :write - elsif not force_mode and reading? + elsif !force_mode && reading? raise 'You chose to write the buffer when in read mode' end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 747eef3b..4b33b3ed 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -90,7 +90,7 @@ def parse_response # Ensure client_response is an instance parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) - if parsed.nil? and not response_wrapper.has_field?(:error_reason) + if parsed.nil? && !response_wrapper.has_field?(:error_reason) fail(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') else verify_callbacks diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 2264f44b..2fe3066b 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -162,7 +162,7 @@ def reap_dead_workers @last_reaping = Time.now.to_i @workers.keep_if do |worker| - worker.alive? or worker.join && false + worker.alive? || worker.join && false end end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 10735e25..a2aef5e4 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -200,7 +200,7 @@ def remove_expired_listings end def remove_listing(uuid) - listing = @listings_by_uuid[uuid] or return + listing = @listings_by_uuid[uuid] || return logger.debug { sign_message("Removing listing: #{listing.inspect}") } From b4efb3a9bb4b7250fecd0703296994085f338d82 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:14:40 -0700 Subject: [PATCH 0765/1191] Style/BarePercentLiterals --- .rubocop_todo.yml | 6 ------ Rakefile | 4 ++-- lib/protobuf/deprecator.rb | 2 +- lib/protobuf/generators/field_generator.rb | 2 +- spec/lib/protobuf/generators/field_generator_spec.rb | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 092b2510..6855f1fa 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BarePercentLiterals: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. Style/BlockEndNewline: diff --git a/Rakefile b/Rakefile index 30f57c70..77ab62e9 100644 --- a/Rakefile +++ b/Rakefile @@ -21,7 +21,7 @@ namespace :compile do desc 'Compile spec protos in spec/supprt/ directory' task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) - cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} puts cmd exec(cmd) @@ -33,7 +33,7 @@ namespace :compile do output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) - cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} puts cmd system(cmd) diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index 9fbcbdc2..b19773c0 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -2,7 +2,7 @@ module Protobuf module Deprecator def warn_deprecated(old_method, new_method) - $stderr.puts %Q{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. + $stderr.puts %{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. Please use #{self.name}.#{new_method} instead.\n} end diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index b2a4117e..a252a445 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -119,7 +119,7 @@ def float_double_default_value end def string_default_value - %Q{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"} + %{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"} end def verbatim_default_value diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 714c864e..6daa5a23 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -53,7 +53,7 @@ let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - specify { expect(subject).to eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } + specify { expect(subject).to eq %{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } end context 'when float or double field type' do From 55d37ab500a00024f2cd7710cd2ea90733fadacc Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:15:34 -0700 Subject: [PATCH 0766/1191] Style/BlockEndNewline --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/generators/enum_generator_spec.rb | 3 ++- spec/lib/protobuf/generators/field_generator_spec.rb | 3 ++- spec/lib/protobuf/generators/service_generator_spec.rb | 3 ++- spec/lib/protobuf/rpc/connectors/common_spec.rb | 6 ++++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6855f1fa..e5b46008 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -Style/BlockEndNewline: - Enabled: false - # Offense count: 67 # Cop supports --auto-correct. Style/Blocks: diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 1521ced4..3c176409 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -14,7 +14,8 @@ let(:options) { nil } let(:enum_fields) { { :name => 'TestEnum', :value => values, - :options => options } } + :options => options } + } let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) } diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 6daa5a23..a6d9742e 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -20,7 +20,8 @@ :type_name => type_name, :default_value => default_value, :extendee => extendee, - :options => field_options } } + :options => field_options } + } let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) } diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index dae1fc02..166b8318 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -11,7 +11,8 @@ ] } let(:service_fields) { { :name => 'TestService', - :method => methods } } + :method => methods } + } let(:service) { ::Google::Protobuf::ServiceDescriptorProto.new(service_fields) } diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 1b945222..8ab486df 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -77,12 +77,14 @@ let(:subject_options) { { :service => service, :method => method, :request => request, - :client_host => client_host } } + :client_host => client_host } + } let(:expected) { ::Protobuf::Socketrpc::Request.new({ :service_name => service.name, :method_name => 'find', :request_proto => '', - :caller => client_host }) } + :caller => client_host }) + } before { allow(subject).to receive(:validate_request_type!).and_return(true) } before { expect(subject).not_to receive(:fail) } From b0eeabc250db74f4f618cf628ddfe9696a9de564 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:20:40 -0700 Subject: [PATCH 0767/1191] Style/Blocks --- .rubocop_todo.yml | 5 --- lib/protobuf.rb | 4 +-- lib/protobuf/cli.rb | 4 +-- lib/protobuf/enum.rb | 4 +-- lib/protobuf/generators/file_generator.rb | 4 +-- lib/protobuf/message.rb | 4 +-- lib/protobuf/rpc/connectors/zmq.rb | 4 +-- lib/protobuf/rpc/service_filters.rb | 8 ++--- spec/functional/socket_server_spec.rb | 4 +-- spec/functional/zmq_server_spec.rb | 4 +-- spec/lib/protobuf/cli_spec.rb | 8 ++--- spec/lib/protobuf/code_generator_spec.rb | 4 +-- spec/lib/protobuf/enum_spec.rb | 4 +-- spec/lib/protobuf/field/string_field_spec.rb | 8 ++--- spec/lib/protobuf/field_spec.rb | 4 +-- .../generators/enum_generator_spec.rb | 23 +++++++------ .../generators/extension_generator_spec.rb | 8 ++--- .../generators/field_generator_spec.rb | 21 ++++++------ .../generators/service_generator_spec.rb | 17 ++++++---- spec/lib/protobuf/lifecycle_spec.rb | 4 +-- spec/lib/protobuf/message_spec.rb | 32 +++++++++---------- spec/lib/protobuf/optionable_spec.rb | 4 +-- .../protobuf/rpc/connectors/common_spec.rb | 28 +++++++++------- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 16 ++++++---- .../protobuf/rpc/middleware/logger_spec.rb | 8 ++--- .../rpc/middleware/request_decoder_spec.rb | 16 +++++----- .../rpc/middleware/response_encoder_spec.rb | 4 +-- .../protobuf/rpc/servers/zmq/server_spec.rb | 14 ++++---- .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 16 +++++----- .../protobuf/rpc/service_directory_spec.rb | 24 +++++++------- .../protobuf/rpc/service_dispatcher_spec.rb | 4 +-- spec/lib/protobuf/rpc/service_filters_spec.rb | 16 +++++----- spec/lib/protobuf/rpc/service_spec.rb | 8 ++--- spec/lib/protobuf_spec.rb | 8 ++--- 34 files changed, 179 insertions(+), 165 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e5b46008..f1a04247 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 67 -# Cop supports --auto-correct. -Style/Blocks: - Enabled: false - # Offense count: 15 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 4520ae06..38bae844 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -102,9 +102,9 @@ def self.ignore_unknown_fields=(value) require 'protobuf/rpc/client' require 'protobuf/rpc/service' - env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') { + env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') do ::Protobuf::DEFAULT_CONNECTOR - }.to_s.downcase.strip.to_sym + end.to_s.downcase.strip.to_sym if ::Protobuf::CONNECTORS.include?(env_connector_type) require "protobuf/#{env_connector_type}" diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index ad0716c6..6e543c7a 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -227,9 +227,9 @@ def start_server debug_say('Running server') @runner.run do - logger.info { + logger.info do "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" - } + end ::ActiveSupport::Notifications.instrument("after_server_bind") end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index bff48979..f179f634 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -101,9 +101,9 @@ def self.enums # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - self.enums.select { |enum| + self.enums.select do |enum| enum.to_i == tag.to_i - } + end end # Public: Get the Enum associated with the given name. diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 63fb9412..92ac87ca 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -118,9 +118,9 @@ def print_import_requires def print_package(&block) final = lambda { block.call } namespaces = descriptor.package.split('.') - namespaces.reverse.inject(final) { |previous, namespace| + namespaces.reverse.inject(final) do |previous, namespace| lambda { print_module(namespace, &previous) } - }.call + end.call end private diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a608898a..3f95ab6e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -164,12 +164,12 @@ def []=(name, value) private def copy_to(object, method) - duplicate = proc { |obj| + duplicate = proc do |obj| case obj when Message, String then obj.__send__(method) else obj end - } + end object.__send__(:initialize) @values.each do |name, value| diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index ab65f7cd..598e068c 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -25,9 +25,9 @@ class Zmq < Base # Class Methods # def self.zmq_context - @zmq_contexts ||= Hash.new { |hash, key| + @zmq_contexts ||= Hash.new do |hash, key| hash[key] = ZMQ::Context.new - } + end @zmq_contexts[Process.pid] end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 12e45e97..acd05e22 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -210,13 +210,13 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = # def run_around_filters(rpc_method) final = lambda { __send__(rpc_method) } - filters[:around].reverse.inject(final) { |previous, filter| + filters[:around].reverse.inject(final) do |previous, filter| if invoke_filter?(rpc_method, filter) lambda { call_or_send(filter[:callable], &previous) } else previous end - }.call + end.call end @@ -240,10 +240,10 @@ def run_rescue_filters begin yield rescue *rescue_filters.keys => ex - callable = rescue_filters.fetch(ex.class) { + callable = rescue_filters.fetch(ex.class) do mapped_klass = rescue_filters.keys.detect { |child_klass| ex.class < child_klass } rescue_filters[mapped_klass] - } + end call_or_send(callable, ex) end diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 51784817..bf0c283a 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -16,7 +16,7 @@ end it 'runs fine when required fields are set' do - expect { + expect do client = ::Test::ResourceService.client client.find(:name => 'Test Name', :active => true) do |c| @@ -29,7 +29,7 @@ raise err.inspect end end - }.to_not raise_error + end.to_not raise_error end it 'calls the on_failure callback when a message is malformed' do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index a138024a..fe69b3a8 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -22,7 +22,7 @@ end it 'runs fine when required fields are set' do - expect { + expect do client = ::Test::ResourceService.client client.find(:name => 'Test Name', :active => true) do |c| @@ -35,7 +35,7 @@ raise err.inspect end end - }.to_not raise_error + end.to_not raise_error end it 'runs under heavy load' do diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 24fde5e0..b1767bf7 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -7,17 +7,17 @@ File.expand_path('../../../support/test_app_file.rb', __FILE__) end - let(:sock_runner) { + let(:sock_runner) do runner = double("SocketRunner", :register_signals => nil) allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner - } + end - let(:zmq_runner) { + let(:zmq_runner) do runner = double "ZmqRunner", register_signals: nil allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner - } + end around(:each) do |example| logger = ::Protobuf::Logging.logger diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index ca31b278..5cc77e38 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -40,9 +40,9 @@ context 'class-level printing methods' do describe '.fatal' do it 'raises a CodeGeneratorFatalError error' do - expect { + expect do described_class.fatal("something is wrong") - }.to raise_error( + end.to raise_error( ::Protobuf::CodeGenerator::CodeGeneratorFatalError, "something is wrong" ) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 3de2ab40..fd121933 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -40,10 +40,10 @@ end it 'allows defining enums with the same tag number' do - expect { + expect do DefineEnumAlias.define(:FOO, 1) DefineEnumAlias.define(:BAR, 1) - }.not_to raise_error + end.not_to raise_error end end end diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index 887d8e57..b25ccc95 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -7,19 +7,19 @@ describe '#encode' do context 'when a repeated string field contains frozen strings' do it 'does not raise an encoding error' do - expect { + expect do frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] ::Test::ResourceFindRequest.encode(:name => 'resource', :widgets => frozen_strings) - }.not_to raise_error + end.not_to raise_error end end context 'when a repeated bytes field contains frozen strings' do it 'does not raise an encoding error' do - expect { + expect do frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] ::Test::ResourceFindRequest.encode(:name => 'resource', :widget_bytes => frozen_strings) - }.not_to raise_error + end.not_to raise_error end end diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index e9772588..7b7537a6 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -183,9 +183,9 @@ context 'when type is not mapped' do it 'raises an ArgumentError' do - expect { + expect do subject.field_class("boom") - }.to raise_error + end.to raise_error end end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 3c176409..6c3d8476 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -4,25 +4,28 @@ describe ::Protobuf::Generators::EnumGenerator do - let(:values) { + let(:values) do [ { :name => 'FOO', :number => 1 }, { :name => 'BAR', :number => 2 }, { :name => 'BAZ', :number => 3 } ] - } + end let(:options) { nil } - let(:enum_fields) { { :name => 'TestEnum', - :value => values, - :options => options } - } + let(:enum_fields) do + { + :name => 'TestEnum', + :value => values, + :options => options + } + end let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) } subject { described_class.new(enum) } describe '#compile' do - let(:compiled) { + let(:compiled) do <<-RUBY class TestEnum < ::Protobuf::Enum define :FOO, 1 @@ -31,7 +34,7 @@ class TestEnum < ::Protobuf::Enum end RUBY - } + end it 'compiles the enum and its field values' do subject.compile @@ -39,7 +42,7 @@ class TestEnum < ::Protobuf::Enum end context 'when allow_alias option is set' do - let(:compiled) { + let(:compiled) do <<-RUBY class TestEnum < ::Protobuf::Enum set_option :allow_alias @@ -50,7 +53,7 @@ class TestEnum < ::Protobuf::Enum end RUBY - } + end let(:options) { { :allow_alias => true } } diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 5d0e21f7..1afc8b98 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -5,13 +5,13 @@ describe ::Protobuf::Generators::ExtensionGenerator do - let(:field_descriptors) { + let(:field_descriptors) do [ double('field descriptor 1', :to_s => " field 1\n"), double('field descriptor 2', :to_s => " field 2\n"), double('field descriptor 3', :to_s => " field 3\n") ] - } + end let(:message_type) { 'FooBar' } before do @@ -23,7 +23,7 @@ subject { described_class.new(message_type, field_descriptors, 0) } describe '#compile' do - let(:compiled) { + let(:compiled) do %q{class FooBar < ::Protobuf::Message field 1 field 2 @@ -31,7 +31,7 @@ end } - } + end it 'compiles the a class with the extension fields' do subject.compile diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index a6d9742e..e03ee487 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -13,15 +13,18 @@ let(:extendee) { nil } let(:field_options) { {} } - let(:field_fields) { { :label => label_enum, - :name => name, - :number => number, - :type => type_enum, - :type_name => type_name, - :default_value => default_value, - :extendee => extendee, - :options => field_options } - } + let(:field_fields) do + { + :label => label_enum, + :name => name, + :number => number, + :type => type_enum, + :type_name => type_name, + :default_value => default_value, + :extendee => extendee, + :options => field_options + } + end let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) } diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 166b8318..0611e4be 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -4,29 +4,32 @@ describe ::Protobuf::Generators::ServiceGenerator do - let(:methods) { + let(:methods) do [ { :name => 'Search', :input_type => 'FooRequest', :output_type => 'FooResponse' }, { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' } ] - } - let(:service_fields) { { :name => 'TestService', - :method => methods } - } + end + let(:service_fields) do + { + :name => 'TestService', + :method => methods + } + end let(:service) { ::Google::Protobuf::ServiceDescriptorProto.new(service_fields) } subject { described_class.new(service) } describe '#compile' do - let(:compiled) { + let(:compiled) do %q{class TestService < ::Protobuf::Rpc::Service rpc :search, FooRequest, FooResponse rpc :foo_bar, ::Foo::Request, ::Bar::Response end } - } + end it 'compiles the service and it\'s rpc methods' do subject.compile diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index fce13162..f5e098f9 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -14,9 +14,9 @@ end it "only registers blocks for event callbacks" do - expect { + expect do subject.register("something") - }.to raise_error( /block/ ) + end.to raise_error( /block/ ) end it "calls the registered block when triggered" do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e67f1b18..47b81fe8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -74,47 +74,47 @@ describe 'defining a new field' do context 'when defining a field with a tag that has already been used' do it 'raises a TagCollisionError' do - expect { + expect do Class.new(Protobuf::Message) do optional ::Protobuf::Field::Int32Field, :foo, 1 optional ::Protobuf::Field::Int32Field, :bar, 1 end - }.to raise_error(Protobuf::TagCollisionError, /Field number 1 has already been used/) + end.to raise_error(Protobuf::TagCollisionError, /Field number 1 has already been used/) end end context 'when defining an extension field with a tag that has already been used' do it 'raises a TagCollisionError' do - expect { + expect do Class.new(Protobuf::Message) do extensions 100...110 optional ::Protobuf::Field::Int32Field, :foo, 100 optional ::Protobuf::Field::Int32Field, :bar, 100, :extension => true end - }.to raise_error(Protobuf::TagCollisionError, /Field number 100 has already been used/) + end.to raise_error(Protobuf::TagCollisionError, /Field number 100 has already been used/) end end context 'when defining a field with a name that has already been used' do it 'raises a DuplicateFieldNameError' do - expect { + expect do Class.new(Protobuf::Message) do optional ::Protobuf::Field::Int32Field, :foo, 1 optional ::Protobuf::Field::Int32Field, :foo, 2 end - }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) + end.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) end end context 'when defining an extension field with a name that has already been used' do it 'raises a DuplicateFieldNameError' do - expect { + expect do Class.new(Protobuf::Message) do extensions 100...110 optional ::Protobuf::Field::Int32Field, :foo, 1 optional ::Protobuf::Field::Int32Field, :foo, 100, :extension => true end - }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) + end.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) end end end @@ -246,9 +246,9 @@ let(:message) { ::Test::ResourceWithRequiredField.new } it "raises a 'message not initialized' error" do - expect { + expect do message.encode - }.to raise_error(Protobuf::SerializationError, /required/i) + end.to raise_error(Protobuf::SerializationError, /required/i) end end @@ -256,10 +256,10 @@ let(:message) { ::Test::Resource.new(:name => "something") } it "does not raise an error when repeated fields are []" do - expect { + expect do message.repeated_enum = [] message.encode - }.to_not raise_error + end.to_not raise_error end it "sets the value to nil when empty array is passed" do @@ -280,9 +280,9 @@ end it "raises TypeError when a non-array replaces it" do - expect { + expect do message.repeated_enum = 2 - }.to raise_error(/value of type/) + end.to raise_error(/value of type/) end end end @@ -411,11 +411,11 @@ describe '.to_json' do it 'returns the class name of the message for use in json encoding' do - expect { + expect do ::Timeout.timeout(0.1) do expect(::Test::Resource.to_json).to eq("Test::Resource") end - }.not_to raise_error + end.not_to raise_error end end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index d6237f14..056f9092 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -13,9 +13,9 @@ it 'stores the given option and value' do expect(OptionableSetOptionTest).to respond_to(:set_option) expect(OptionableSetOptionTest.method(:set_option).arity).to eq(-2) - expect { + expect do OptionableSetOptionTest.set_option(:foo, :bar) - }.to_not raise_error + end.to_not raise_error end it 'defaults the value to true' do diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 8ab486df..0710d6ab 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -74,17 +74,23 @@ let(:method) { :find } let(:request) { '' } let(:client_host) { 'myhost.myservice.com' } - let(:subject_options) { { :service => service, - :method => method, - :request => request, - :client_host => client_host } - } - - let(:expected) { ::Protobuf::Socketrpc::Request.new({ :service_name => service.name, - :method_name => 'find', - :request_proto => '', - :caller => client_host }) - } + let(:subject_options) do + { + :service => service, + :method => method, + :request => request, + :client_host => client_host + } + end + + let(:expected) do + ::Protobuf::Socketrpc::Request.new( + :service_name => service.name, + :method_name => 'find', + :request_proto => '', + :caller => client_host + ) + end before { allow(subject).to receive(:validate_request_type!).and_return(true) } before { expect(subject).not_to receive(:fail) } diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 7bec5332..03734958 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -4,13 +4,15 @@ describe ::Protobuf::Rpc::Connectors::Zmq do subject { described_class.new(options) } - let(:options) {{ - :service => "Test::Service", - :method => "find", - :timeout => 3, - :host => "127.0.0.1", - :port => "9400" - }} + let(:options) do + { + :service => "Test::Service", + :method => "find", + :timeout => 3, + :host => "127.0.0.1", + :port => "9400" + } + end let(:socket_double) { double(::ZMQ::Socket, :connect => 0) } let(:zmq_context_double) { double(::ZMQ::Context, :socket => socket_double) } diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index fa938aa1..e3621a76 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -2,7 +2,7 @@ describe Protobuf::Rpc::Middleware::Logger do let(:app) { Proc.new { |inner_env| inner_env } } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'client_host' => 'client_host.test.co', 'encoded_request' => request_wrapper.encode, @@ -16,17 +16,17 @@ 'rpc_service' => service_class, 'service_name' => service_name, ) - } + end let(:method_name) { :find } let(:request) { request_type.new(:name => 'required') } let(:request_type) { rpc_method.request_type } - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :service_name => service_name, :method_name => method_name.to_s, :request_proto => request ) - } + end let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } let(:response) { rpc_method.response_type.new(:name => 'required') } let(:rpc_method) { service_class.rpcs[method_name] } diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index ae33afe8..f7f4a485 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -3,24 +3,24 @@ describe Protobuf::Rpc::Middleware::RequestDecoder do let(:app) { Proc.new { |env| env } } let(:client_host) { 'client_host.test.co' } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'encoded_request' => encoded_request, 'log_signature' => 'log_signature' ) - } + end let(:encoded_request) { request_wrapper.encode } let(:method_name) { :find } let(:request) { request_type.new(:name => 'required') } let(:request_type) { rpc_method.request_type } - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => service_name, :method_name => method_name.to_s, :request_proto => request ) - } + end let(:response_type) { rpc_method.response_type } let(:rpc_method) { rpc_service.rpcs[method_name] } let(:rpc_service) { Test::ResourceService } @@ -83,14 +83,14 @@ end context "when the RPC service is not defined" do - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => 'Foo', :method_name => method_name.to_s, :request_proto => request ) - } + end it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::ServiceNotFound) @@ -98,14 +98,14 @@ end context "when RPC method is not defined" do - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => service_name, :method_name => 'foo', :request_proto => request ) - } + end it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 9b9bb429..f9d47ebe 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -2,12 +2,12 @@ describe Protobuf::Rpc::Middleware::ResponseEncoder do let(:app) { Proc.new { |env| env.response = response; env } } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'response_type' => Test::Resource, 'log_signature' => 'log_signature' ) - } + end let(:encoded_response) { response_wrapper.encode } let(:response) { Test::Resource.new(:name => 'required') } let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 0fbb0024..e8f0eacf 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -4,12 +4,14 @@ describe Protobuf::Rpc::Zmq::Server do subject { described_class.new(options) } - let(:options) {{ - :host => '127.0.0.1', - :port => 9399, - :worker_port => 9400, - :workers_only => true - }} + let(:options) do + { + :host => '127.0.0.1', + :port => 9399, + :worker_port => 9400, + :workers_only => true + } + end before do load 'protobuf/zmq.rb' diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index 523297f8..be2bdf62 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -12,28 +12,28 @@ class UtilTest subject { UtilTest.new } describe '#zmq_error_check' do it 'raises when the error code is less than 0' do - expect { + expect do subject.zmq_error_check(-1, :test) - }.to raise_error(/test/) + end.to raise_error(/test/) end it 'retrieves the error string from ZeroMQ' do allow(ZMQ::Util).to receive(:error_string).and_return('an error from zmq') - expect { + expect do subject.zmq_error_check(-1, :test) - }.to raise_error(RuntimeError, /an error from zmq/i) + end.to raise_error(RuntimeError, /an error from zmq/i) end it 'does nothing if the error code is > 0' do - expect { + expect do subject.zmq_error_check(1, :test) - }.to_not raise_error + end.to_not raise_error end it 'does nothing if the error code is == 0' do - expect { + expect do subject.zmq_error_check(0, :test) - }.to_not raise_error + end.to_not raise_error end end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 577fbe8e..4798e6e5 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -5,7 +5,7 @@ describe ::Protobuf::Rpc::ServiceDirectory do subject { described_class.instance } - let(:echo_server) { + let(:echo_server) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => 'echo', :address => '127.0.0.1', @@ -13,9 +13,9 @@ :ttl => 10, :services => %w[EchoService] ) - } + end - let(:hello_server) { + let(:hello_server) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "hello", :address => '127.0.0.1', @@ -23,9 +23,9 @@ :ttl => 10, :services => %w[HelloService] ) - } + end - let(:hello_server_with_short_ttl) { + let(:hello_server_with_short_ttl) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "hello_server_with_short_ttl", :address => '127.0.0.1', @@ -33,9 +33,9 @@ :ttl => 1, :services => %w[HelloService] ) - } + end - let(:combo_server) { + let(:combo_server) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "combo", :address => '127.0.0.1', @@ -43,7 +43,7 @@ :ttl => 10, :services => %w[HelloService EchoService] ) - } + end before(:all) do @address = "127.0.0.1" @@ -175,9 +175,9 @@ def send_beacon(type, server) send_beacon(:heartbeat, echo_server) send_beacon(:heartbeat, combo_server) - expect { |block| + expect do |block| subject.each_listing(&block) - }.to yield_control.exactly(3).times + end.to yield_control.exactly(3).times end end @@ -259,7 +259,7 @@ def send_beacon(type, server) if ENV.key?("BENCH") context "performance" do - let(:servers) { + let(:servers) do 100.times.collect do |x| ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "performance_server#{x + 1}", @@ -269,7 +269,7 @@ def send_beacon(type, server) :services => 10.times.collect { |y| "PerformanceService#{y}" } ) end - } + end before do require 'benchmark' diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 1582b44c..585b3b05 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -3,14 +3,14 @@ describe Protobuf::Rpc::ServiceDispatcher do let(:app) { proc { |env| env } } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'method_name' => method_name, 'request' => request, 'rpc_service' => service_class, 'service_name' => service_name, ) - } + end let(:method_name) { :find } let(:request) { request_type.new(:name => 'required') } let(:request_type) { service_class.rpcs[method_name].request_type } diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index c147ced5..538dfcc1 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -419,12 +419,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_error3) } it 'short-circuits the call stack' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_error3, :custom_error_occurred ]) expect(subject.ex_class).to eq CustomError3 - }.not_to raise_error + end.not_to raise_error end end @@ -440,12 +440,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_error1) } it 'short-circuits the call stack' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_error1, :custom_error_occurred ]) expect(subject.ex_class).to eq CustomError1 - }.not_to raise_error + end.not_to raise_error end end end @@ -460,12 +460,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_error1) } it 'short-circuits the call stack' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_error1, :block_rescue_handler ]) expect(subject.ex_class).to eq CustomError1 - }.not_to raise_error + end.not_to raise_error end end @@ -479,12 +479,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_runtime_error) } it 'rescues with the given callable' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) expect(subject.ex_class).to eq RuntimeError - }.not_to raise_error + end.not_to raise_error end end end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 545e90ee..2c44876e 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -125,12 +125,12 @@ def find_with_rpc_failed context 'when calling the rpc method' do context 'when response is implied' do - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'request' => request, 'response_type' => response_type ) - } + end let(:response_type) { service.rpcs[:find_with_implied_response].response_type } let(:service) { NewTestService } @@ -142,12 +142,12 @@ def find_with_rpc_failed end context 'when using respond_with paradigm' do - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'method_name' => :find_with_respond_with, 'request' => request ) - } + end subject { NewTestService.new(env) } diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index b828f53c..f2a3a528 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -35,9 +35,9 @@ it 'does not accept other types' do [:hello, :world, :evented].each do |type| - expect { + expect do described_class.connector_type = type - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end end end @@ -87,9 +87,9 @@ end it 'is settable' do - expect { + expect do described_class.ignore_unknown_fields = false - }.to change { + end.to change { described_class.ignore_unknown_fields? }.from(true).to(false) end From 052a4fc9b0176bb4c9bf078691a56b134d380ca0 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:23:53 -0700 Subject: [PATCH 0768/1191] Style/BracesAroundHashParameters --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/service_filters.rb | 2 +- spec/functional/zmq_server_spec.rb | 14 +++++++------ spec/lib/protobuf/enum_spec.rb | 8 ++++---- .../generators/file_generator_spec.rb | 8 ++++++-- spec/lib/protobuf/message_spec.rb | 20 +++++++++---------- spec/lib/protobuf/rpc/client_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/worker_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 9 +++++---- 9 files changed, 35 insertions(+), 36 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f1a04247..90b35c33 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BracesAroundHashParameters: - Enabled: false - # Offense count: 4 # Configuration parameters: EnforcedStyle, SupportedStyles. Style/ClassAndModuleChildren: diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index acd05e22..b67a7d45 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -45,7 +45,7 @@ def rescue_from(*ex_klasses, &block) def define_filter(type, filter, options = {}) return if filter_defined?(type, filter) - filters[type] << options.merge({ :callable => filter }) + filters[type] << options.merge(:callable => filter) remember_filter(type, filter) end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index fe69b3a8..1b52d68f 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -6,12 +6,14 @@ describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" - @runner = ::Protobuf::Rpc::ZmqRunner.new({ :host => "127.0.0.1", - :port => 9399, - :worker_port => 9408, - :backlog => 100, - :threshold => 100, - :threads => 5 }) + @runner = ::Protobuf::Rpc::ZmqRunner.new( + :host => "127.0.0.1", + :port => 9399, + :worker_port => 9408, + :backlog => 100, + :threshold => 100, + :threads => 5 + ) @server_thread = Thread.new(@runner) { |runner| runner.run } Thread.pass until @runner.running? end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index fd121933..17718801 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -175,20 +175,20 @@ describe '.values' do it 'provides a hash of defined Enums' do - expect(Test::EnumTestType.values).to eq({ + expect(Test::EnumTestType.values).to eq( :MINUS_ONE => Test::EnumTestType::MINUS_ONE, :ONE => Test::EnumTestType::ONE, :TWO => Test::EnumTestType::TWO, :THREE => Test::EnumTestType::THREE - }) + ) end it 'contains aliased Enums' do - expect(EnumAliasTest.values).to eq({ + expect(EnumAliasTest.values).to eq( :FOO => EnumAliasTest::FOO, :BAR => EnumAliasTest::BAR, :BAZ => EnumAliasTest::BAZ - }) + ) end end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 9f666afa..56b05e37 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -13,8 +13,12 @@ describe '#print_import_requires' do let(:descriptor_fields) do - base_descriptor_fields.merge!({ :dependency => [ 'test/bar.proto', - 'test/baz.proto' ] }) + base_descriptor_fields.merge( + :dependency => [ + 'test/bar.proto', + 'test/baz.proto' + ] + ) end it 'prints a ruby require for each dependency' do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 47b81fe8..97acbb4d 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -363,7 +363,7 @@ context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do hash = Test::EnumTestMessage.new(:non_default_enum => :TWO).to_hash - expect(hash).to eq({ :non_default_enum => 2 }) + expect(hash).to eq(:non_default_enum => 2) end it 'does not populate default values' do @@ -373,14 +373,14 @@ it 'converts repeated enum fields to an array of the tags' do hash = Test::EnumTestMessage.new(:repeated_enums => [ :ONE, :TWO, :TWO, :ONE ]).to_hash - expect(hash).to eq({ :repeated_enums => [ 1, 2, 2, 1 ] }) + expect(hash).to eq(:repeated_enums => [ 1, 2, 2, 1 ]) end end context 'generating values for a Message field' do it 'recursively hashes field messages' do - hash = Test::Nested.new({ :resource => { :name => 'Nested' } }).to_hash - expect(hash).to eq({ :resource => { :name => 'Nested' } }) + hash = Test::Nested.new(:resource => { :name => 'Nested' }).to_hash + expect(hash).to eq(:resource => { :name => 'Nested' }) end it 'recursively hashes a repeated set of messages' do @@ -390,12 +390,10 @@ ]) expect(proto.to_hash).to eq( - { - :multiple_resources => [ - { :name => 'Resource 1' }, - { :name => 'Resource 2' }, - ], - } + :multiple_resources => [ + { :name => 'Resource 1' }, + { :name => 'Resource 2' }, + ] ) end end @@ -403,7 +401,7 @@ describe '#to_json' do subject do - ::Test::ResourceFindRequest.new({ :name => 'Test Name', :active => false }) + ::Test::ResourceFindRequest.new(:name => 'Test Name', :active => false) end specify { expect(subject.to_json).to eq '{"name":"Test Name","active":false}' } diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 14b8ba34..cd2bfe13 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -55,7 +55,7 @@ it 'should be able to create the correct request object if passed a hash' do client = Test::ResourceService.client expect(client).to receive(:send_request) - client.find({:name => 'Test Name', :active => false}) + client.find(:name => 'Test Name', :active => false) expect(client.options[:request]).to be_a(Test::ResourceFindRequest) expect(client.options[:request].name).to eq('Test Name') expect(client.options[:request].active).to eq(false) diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 1da51f5e..1f779917 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -14,7 +14,7 @@ end subject do - described_class.new({ :host => '127.0.0.1', :port => 9400 }) + described_class.new(:host => '127.0.0.1', :port => 9400) end describe '#run' do diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 2c44876e..9260e567 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -64,10 +64,11 @@ it 'initializes a client object for this service' do client = double('client') expect(::Protobuf::Rpc::Client).to receive(:new) - .with(hash_including({ :service => subject, - :host => subject.host, - :port => subject.port })) - .and_return(client) + .with(hash_including( + :service => subject, + :host => subject.host, + :port => subject.port + )).and_return(client) expect(subject.client).to eq client end end From f4601511d2cdff7a13b5f30218611235e134b136 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:57:56 -0700 Subject: [PATCH 0769/1191] Refresh RuboCop config --- .rubocop_todo.yml | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 90b35c33..b6353d88 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,5 +1,5 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-10-14 08:30:47 -0700 using RuboCop version 0.26.1. +# on 2014-10-15 12:57:34 -0700 using RuboCop version 0.26.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -9,21 +9,21 @@ Metrics/BlockNesting: Max: 5 -# Offense count: 9 +# Offense count: 8 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 236 + Max: 233 # Offense count: 3 Metrics/CyclomaticComplexity: Max: 11 -# Offense count: 515 +# Offense count: 505 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 45 +# Offense count: 47 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 41 @@ -122,7 +122,7 @@ Style/IfUnlessModifier: Style/IndentationConsistency: Enabled: false -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. Style/IndentationWidth: Enabled: false @@ -142,11 +142,6 @@ Style/LeadingCommentSpace: Style/MethodDefParentheses: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -Style/MultilineBlockLayout: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: @@ -158,11 +153,6 @@ Style/Next: Style/NonNilCheck: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/Not: - Enabled: false - # Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: @@ -172,7 +162,7 @@ Style/NumericLiterals: Style/OpMethod: Enabled: false -# Offense count: 15 +# Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: @@ -222,7 +212,7 @@ Style/SelfAssignment: Style/Semicolon: Enabled: false -# Offense count: 66 +# Offense count: 67 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/SignalException: @@ -272,12 +262,12 @@ Style/SpaceBeforeBlockBraces: Style/SpaceInsideBlockBraces: Enabled: false -# Offense count: 134 +# Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: Enabled: false -# Offense count: 4 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. Style/SpaceInsideHashLiteralBraces: @@ -304,13 +294,13 @@ Style/StringLiterals: Style/Tab: Enabled: false -# Offense count: 57 +# Offense count: 56 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/TrailingBlankLines: Enabled: false -# Offense count: 35 +# Offense count: 47 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. Style/TrailingComma: @@ -326,7 +316,7 @@ Style/TrivialAccessors: Style/UnlessElse: Enabled: false -# Offense count: 6 +# Offense count: 2 # Cop supports --auto-correct. Style/UnneededPercentQ: Enabled: false From 592717ad5795a1ceee916131499751efe427cb23 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:50:28 -0700 Subject: [PATCH 0770/1191] Actually run the tests again. Damnit, `#exec`! Also generate encoding comments for all the files, needed for 1.9.3. --- Rakefile | 10 ++++++---- .../descriptors/google/protobuf/compiler/plugin.pb.rb | 2 ++ .../descriptors/google/protobuf/descriptor.pb.rb | 2 ++ lib/protobuf/generators/file_generator.rb | 2 ++ lib/protobuf/rpc/dynamic_discovery.pb.rb | 2 ++ lib/protobuf/rpc/rpc.pb.rb | 2 ++ spec/functional/zmq_server_spec.rb | 2 +- spec/spec_helper.rb | 8 -------- spec/support/test/defaults.pb.rb | 2 ++ spec/support/test/enum.pb.rb | 2 ++ spec/support/test/extended.pb.rb | 2 ++ spec/support/test/google_unittest_import.pb.rb | 2 ++ spec/support/test/google_unittest_import_public.pb.rb | 2 ++ spec/support/test/multi_field_extensions.pb.rb | 2 ++ spec/support/test/resource.pb.rb | 2 ++ 15 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Rakefile b/Rakefile index 77ab62e9..6423d7ad 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,7 @@ require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) RuboCop::RakeTask.new -task :default => [:spec, :rubocop] +task :default => ['compile:spec', 'compile:rpc', :spec, :rubocop] desc 'Run specs' namespace :compile do @@ -21,19 +21,21 @@ namespace :compile do desc 'Compile spec protos in spec/supprt/ directory' task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + proto_files = Dir[File.join(proto_path, '**', '*.proto')] + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}} puts cmd - exec(cmd) + system(cmd) end desc 'Compile rpc protos in protos/ directory' task :rpc do proto_path = ::File.expand_path('../proto', __FILE__) + proto_files = Dir[File.join(proto_path, '**', '*.proto')] output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}} puts cmd system(cmd) diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb index 5dd8eddf..4d3f72bb 100644 --- a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index c4835c12..54de4e2e 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 92ac87ca..097cd818 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -92,6 +92,8 @@ def map_extensions(descriptor, namespaces) end def print_file_comment + puts "# encoding: utf-8" + puts puts "##" puts "# This file is auto-generated. DO NOT EDIT!" puts "#" diff --git a/lib/protobuf/rpc/dynamic_discovery.pb.rb b/lib/protobuf/rpc/dynamic_discovery.pb.rb index 1ee963ca..2070b475 100644 --- a/lib/protobuf/rpc/dynamic_discovery.pb.rb +++ b/lib/protobuf/rpc/dynamic_discovery.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index 1a5e7e21..d302de54 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 1b52d68f..72b4d72b 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -42,7 +42,7 @@ it 'runs under heavy load' do 10.times do - 5.times do + 5.times.map do Thread.new do client = ::Test::ResourceService.client diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 20cd2fe4..07b108ea 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,14 +26,6 @@ # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") -::RSpec.configure do |c| - c.before(:suite) do - require 'rake' - load ::File.expand_path('../../Rakefile', __FILE__) - ::Rake::Task['compile:spec'].invoke - end -end - support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) Dir[support_proto_glob].each { |proto_file| require proto_file } diff --git a/spec/support/test/defaults.pb.rb b/spec/support/test/defaults.pb.rb index 9849e8a5..24c6c4bf 100644 --- a/spec/support/test/defaults.pb.rb +++ b/spec/support/test/defaults.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index ae1bdb61..8f68cb80 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/extended.pb.rb b/spec/support/test/extended.pb.rb index 2f3a8602..a9edae82 100644 --- a/spec/support/test/extended.pb.rb +++ b/spec/support/test/extended.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/google_unittest_import.pb.rb b/spec/support/test/google_unittest_import.pb.rb index 1c37587c..1e49a5c3 100644 --- a/spec/support/test/google_unittest_import.pb.rb +++ b/spec/support/test/google_unittest_import.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/google_unittest_import_public.pb.rb b/spec/support/test/google_unittest_import_public.pb.rb index 68a35d5c..18434960 100644 --- a/spec/support/test/google_unittest_import_public.pb.rb +++ b/spec/support/test/google_unittest_import_public.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/test/multi_field_extensions.pb.rb index 15ae94ed..276041ad 100644 --- a/spec/support/test/multi_field_extensions.pb.rb +++ b/spec/support/test/multi_field_extensions.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 0605bacc..622f33e4 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # From fe75516b59c241c93273618afa9365b93740b2ec Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:45:24 -0700 Subject: [PATCH 0771/1191] Style/WhileUntilDo --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/servers/zmq/broker.rb | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b6353d88..05781c3b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -321,11 +321,6 @@ Style/UnlessElse: Style/UnneededPercentQ: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/WhileUntilDo: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 3be992db..4f70fbb5 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -55,7 +55,7 @@ def check_and_process_backend readables_include_backend = @poller.readables.include?(@backend_socket) message_count_read_from_backend = 0 - while readables_include_backend && message_count_read_from_backend < backend_poll_weight do + while readables_include_backend && message_count_read_from_backend < backend_poll_weight message_count_read_from_backend += 1 process_backend @poller.poll_nonblock @@ -67,7 +67,7 @@ def check_and_process_frontend readables_include_frontend = @poller.readables.include?(@frontend_socket) message_count_read_from_frontend = 0 - while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do + while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight message_count_read_from_frontend += 1 process_frontend break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full From 725e09f3339bedc09416340756e408525536f862 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:46:02 -0700 Subject: [PATCH 0772/1191] Style/UnneededPercentQ --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/generators/extension_generator_spec.rb | 4 ++-- spec/lib/protobuf/generators/service_generator_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 05781c3b..c643c17b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -316,11 +316,6 @@ Style/TrivialAccessors: Style/UnlessElse: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/UnneededPercentQ: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 1afc8b98..5c742480 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -24,13 +24,13 @@ describe '#compile' do let(:compiled) do - %q{class FooBar < ::Protobuf::Message + 'class FooBar < ::Protobuf::Message field 1 field 2 field 3 end -} +' end it 'compiles the a class with the extension fields' do diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 0611e4be..33894dc9 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -23,12 +23,12 @@ describe '#compile' do let(:compiled) do - %q{class TestService < ::Protobuf::Rpc::Service + 'class TestService < ::Protobuf::Rpc::Service rpc :search, FooRequest, FooResponse rpc :foo_bar, ::Foo::Request, ::Bar::Response end -} +' end it 'compiles the service and it\'s rpc methods' do From 92e7c09d7a5bad46d2c82a073fa26bb5ba677ed5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:49:14 -0700 Subject: [PATCH 0773/1191] Style/UnlessElse --- .rubocop_todo.yml | 4 ---- lib/protobuf/rpc/client.rb | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c643c17b..c871d0d8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -312,10 +312,6 @@ Style/TrailingComma: Style/TrivialAccessors: Enabled: false -# Offense count: 1 -Style/UnlessElse: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 57fc6b57..d8ebe349 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -105,10 +105,7 @@ def on_success=(callable) # def method_missing(method_name, *params) service = options[:service] - unless service.rpc_method?(method_name) - logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } - super(method_name, *params) - else + if service.rpc_method?(method_name) logger.debug { sign_message("#{service.name}##{method_name}") } rpc = service.rpcs[method_name.to_sym] @@ -131,6 +128,9 @@ def method_missing(method_name, *params) end send_request + else + logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } + super(method_name, *params) end end From b02146cf1416a6db611650b4d825acbc5f40c27e Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Mon, 27 Oct 2014 09:17:39 -0700 Subject: [PATCH 0774/1191] Inspect looks like an object, not a hash --- lib/protobuf/message.rb | 6 +++++- spec/lib/protobuf/message_spec.rb | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 3f95ab6e..2d72cfcd 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -86,7 +86,11 @@ def has_field?(name) end def inspect - to_hash.inspect + attrs = self.class.fields.map do |field| + [ field.name, send(field.name).inspect ].join('=') + end.join(' ') + + "#<#{self.class} #{attrs}>" end def respond_to_has?(key) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 97acbb4d..6a8efc0c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -359,6 +359,24 @@ end + describe '#inspect' do + before do + MyMessage = Class.new(Protobuf::Message) do + optional :string, :name, 1 + repeated :int, :counts, 2 + optional :int, :timestamp, 2 + end + end + + after { remove_const(:MyMessage) } + + it 'lists the fields' do + proto = message.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) + expect(proto.inspect).to eq \ + '#' + end + end + describe '#to_hash' do context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do From 3e3f10702d656330b57bb23c14a0e14278d2cc32 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Mon, 27 Oct 2014 09:48:50 -0700 Subject: [PATCH 0775/1191] Use stub_const --- spec/lib/protobuf/message_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 6a8efc0c..a45337bb 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -360,18 +360,18 @@ end describe '#inspect' do - before do - MyMessage = Class.new(Protobuf::Message) do + let(:klass) do + Class.new(Protobuf::Message) do optional :string, :name, 1 repeated :int, :counts, 2 optional :int, :timestamp, 2 end end - after { remove_const(:MyMessage) } + before { stub_const('MyMessage', klass) } it 'lists the fields' do - proto = message.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) + proto = klass.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) expect(proto.inspect).to eq \ '#' end From 6728ee3e5dff354f2f83616a93e149c5a2b89a9f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:50:34 -0700 Subject: [PATCH 0776/1191] Style/TrivialAccessors --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 6 ----- lib/protobuf.rb | 34 +++++++++++++-------------- lib/protobuf/enum.rb | 4 ++-- lib/protobuf/generators/printable.rb | 16 ++++++------- lib/protobuf/logging.rb | 4 ++-- lib/protobuf/rpc/service.rb | 22 ++++++++--------- lib/protobuf/rpc/service_directory.rb | 8 ++----- lib/protobuf/rpc/stat.rb | 4 +--- spec/lib/protobuf_spec.rb | 8 +++---- spec/support/server.rb | 8 ++----- 11 files changed, 52 insertions(+), 66 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 20b78655..24b47ee2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,3 +11,7 @@ Style/IndentHash: Style/TrailingComma: EnforcedStyleForMultiline: comma + +Style/TrivialAccessors: + AllowDSLWriters: true + AllowPredicates: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c871d0d8..84841a89 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -306,12 +306,6 @@ Style/TrailingBlankLines: Style/TrailingComma: Enabled: false -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. -Style/TrivialAccessors: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 38bae844..fb3129ec 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -19,18 +19,16 @@ module Protobuf module_function - # Client Host - # - # Default: `hostname` of the system - # - # The name or address of the host to use during client RPC calls. - def self.client_host - @_client_host ||= `hostname`.chomp + class << self + # Client Host + # + # Default: `hostname` of the system + # + # The name or address of the host to use during client RPC calls. + attr_accessor :client_host end - def self.client_host=(host) - @_client_host = host - end + self.client_host = Socket.gethostname # Connector Type # @@ -39,12 +37,12 @@ def self.client_host=(host) # Symbol value which denotes the type of connector to use # during client requests to an RPC server. def self.connector_type - @_connector_type ||= DEFAULT_CONNECTOR + @connector_type ||= DEFAULT_CONNECTOR end def self.connector_type=(type) raise ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) - @_connector_type = type + @connector_type = type end # GC Pause during server requests @@ -56,12 +54,12 @@ def self.connector_type=(type) # Once the request is completed, the GC is enabled again. # This optomization provides a huge boost in speed to rpc requests. def self.gc_pause_server_request? - return @_gc_pause_server_request unless @_gc_pause_server_request.nil? + return @gc_pause_server_request unless @gc_pause_server_request.nil? self.gc_pause_server_request = false end def self.gc_pause_server_request=(value) - @_gc_pause_server_request = !!value + @gc_pause_server_request = !!value end # Print Deprecation Warnings @@ -75,12 +73,12 @@ def self.gc_pause_server_request=(value) # # The rpc_server option will override the ENV setting. def self.print_deprecation_warnings? - return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil? + return @print_deprecation_warnings unless @print_deprecation_warnings.nil? self.print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true end def self.print_deprecation_warnings=(value) - @_print_deprecation_warnings = !!value + @print_deprecation_warnings = !!value end # Permit unknown field on Message initialization @@ -90,11 +88,11 @@ def self.print_deprecation_warnings=(value) # Simple boolean to define whether we want to permit unknown fields # on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown. def self.ignore_unknown_fields? - !defined?(@_ignore_unknown_fields) || @_ignore_unknown_fields + !defined?(@ignore_unknown_fields) || @ignore_unknown_fields end def self.ignore_unknown_fields=(value) - @_ignore_unknown_fields = !!value + @ignore_unknown_fields = !!value end end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index f179f634..62e9b423 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -78,8 +78,8 @@ def self.define(name, tag) # Public: All defined enums. # - def self.enums - @enums + class << self + attr_reader :enums end # Public: Get an array of Enum objects with the given tag. diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 34440ad0..31874b7f 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -11,9 +11,13 @@ module Printable # def init_printer(indent_level) @io = ::StringIO.new - @_indent_level = indent_level.to_i || 0 + self.current_indent = indent_level.to_i end + protected + + attr_accessor :current_indent + private # Print a one-line comment. @@ -22,10 +26,6 @@ def comment(message) puts "# #{message}" end - def current_indent - @_indent_level - end - # Print a "header" comment. # # header("Lorem ipsum dolor") @@ -43,7 +43,7 @@ def header(message) # (after the block is finished). # def indent - @_indent_level += 1 + self.current_indent += 1 yield outdent end @@ -68,7 +68,7 @@ def modulize(name) # Decrease the indent level. Cannot be negative. # def outdent - @_indent_level -= 1 unless @_indent_level == 0 + self.current_indent -= 1 unless current_indent.zero? end # Return the parent class for a given type. @@ -136,7 +136,7 @@ def print_require(file) # def puts(message = nil) if message - @io.puts((" " * @_indent_level) + message) + @io.puts((" " * current_indent) + message) else @io.puts end diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 273d159d..bdaea254 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -14,8 +14,8 @@ def self.logger defined?(@logger) ? @logger : initialize_logger end - def self.logger=(new_logger) - @logger = new_logger + class << self + attr_writer :logger end def logger diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 48148231..54d6f8a6 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -54,13 +54,13 @@ def self.configure(config = {}) # The host location of the service. # def self.host - @_host ||= DEFAULT_HOST + @host ||= DEFAULT_HOST end # The host location setter. # - def self.host=(new_host) - @_host = new_host + class << self + attr_writer :host end # An array of defined service classes that contain implementation @@ -88,13 +88,13 @@ def self.located_at(location) # The port of the service on the destination server. # def self.port - @_port ||= DEFAULT_PORT + @port ||= DEFAULT_PORT end # The port location setter. # - def self.port=(new_port) - @_port = new_port + class << self + attr_writer :port end # Define an rpc method with the given request and response types. @@ -108,7 +108,7 @@ def self.rpc(method, request_type, response_type) # Hash containing the set of methods defined via `rpc`. # def self.rpcs - @_rpcs ||= {} + @rpcs ||= {} end # Check if the given method name is a known rpc endpoint. @@ -132,7 +132,7 @@ def callable_rpc_method(method_name) # Response object for this rpc cycle. Not assignable. # def response - @_response ||= response_type.new + @response ||= response_type.new end # Convenience method to get back to class method. @@ -150,7 +150,7 @@ def rpcs private def request_type - @_request_type ||= env.request_type + @request_type ||= env.request_type end # Sugar to make an rpc method feel like a controller method. @@ -158,12 +158,12 @@ def request_type # object returned by the response reader. # def respond_with(candidate) - @_response = candidate + @response = candidate end alias_method :return_from_whence_you_came, :respond_with def response_type - @_response_type ||= env.response_type + @response_type ||= env.response_type end # Automatically fail a service method. diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index a2aef5e4..d293f4a3 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -17,7 +17,7 @@ class ServiceDirectory DEFAULT_PORT = 53000 DEFAULT_TIMEOUT = 1 - class Listing < Delegator + class Listing < SimpleDelegator attr_reader :expires_at def initialize(server) @@ -45,13 +45,9 @@ def ttl end def update(server) - @server = server + __setobj__(server) @expires_at = Time.now.to_i + ttl end - - def __getobj__ - @server - end end # Class Methods diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 5ab9407e..eea4c273 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -17,9 +17,7 @@ def initialize(mode = :SERVER) start end - def client=(client_host) - @client = client_host - end + attr_writer :client def client @client || nil diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index f2a3a528..0f238013 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -4,7 +4,7 @@ describe ::Protobuf do describe '.client_host' do - after { ::Protobuf.instance_variable_set(:@_client_host, nil) } + after { ::Protobuf.client_host = nil } subject { ::Protobuf.client_host } @@ -20,7 +20,7 @@ end describe '.connector_type' do - before { described_class.instance_variable_set(:@_connector_type, nil) } + before { described_class.instance_variable_set(:@connector_type, nil) } it 'defaults to socket' do expect(described_class.connector_type).to eq :socket @@ -43,7 +43,7 @@ end describe '.gc_pause_server_request?' do - before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) } + before { described_class.instance_variable_set(:@gc_pause_server_request, nil) } it 'defaults to a false value' do expect(described_class.gc_pause_server_request?).to be false @@ -56,7 +56,7 @@ end describe '.print_deprecation_warnings?' do - before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) } + before { described_class.instance_variable_set(:@print_deprecation_warnings, nil) } it 'defaults to a true value' do expect(described_class.print_deprecation_warnings?).to be true diff --git a/spec/support/server.rb b/spec/support/server.rb index 55e4dbea..d572b1db 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -13,12 +13,8 @@ module StubProtobufServerFactory def self.build(delay) new_server = Class.new(Protobuf::Rpc::Socket::Server) do - def self.sleep_interval - @sleep_interval - end - - def self.sleep_interval=(si) - @sleep_interval = si + class << self + attr_accessor :sleep_interval end def post_init From e351f581c3e9602d548ed0b099113bac7a95688b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:50:58 -0700 Subject: [PATCH 0777/1191] Style/Tab --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/enum_spec.rb | 14 +++++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 84841a89..fd395013 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -289,11 +289,6 @@ Style/SpecialGlobalVars: Style/StringLiterals: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -Style/Tab: - Enabled: false - # Offense count: 56 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 17718801..f532627a 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -200,15 +200,15 @@ end end - subject { Test::EnumTestType::ONE } + subject { Test::EnumTestType::ONE } specify { expect(subject.class).to eq(Fixnum) } specify { expect(subject.parent_class).to eq(Test::EnumTestType) } - specify { expect(subject.name).to eq(:ONE) } - specify { expect(subject.tag).to eq(1) } - specify { expect(subject.value).to eq(1) } - specify { expect(subject.to_hash_value).to eq(1) } - specify { expect(subject.to_s).to eq("1") } - specify { expect(subject.inspect).to eq('#') } + specify { expect(subject.name).to eq(:ONE) } + specify { expect(subject.tag).to eq(1) } + specify { expect(subject.value).to eq(1) } + specify { expect(subject.to_hash_value).to eq(1) } + specify { expect(subject.to_s).to eq("1") } + specify { expect(subject.inspect).to eq('#') } specify { expect(subject.to_s(:tag)).to eq("1") } specify { expect(subject.to_s(:name)).to eq("ONE") } From 079a78bf47d3476e506a1694eacfff64bc7e947f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:52:23 -0700 Subject: [PATCH 0778/1191] Style/TrailingBlankLines --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 6 ------ bin/protoc-gen-ruby | 1 - lib/protobuf/code_generator.rb | 1 - lib/protobuf/decoder.rb | 1 - lib/protobuf/encoder.rb | 1 - lib/protobuf/enum.rb | 1 - lib/protobuf/field/base_field.rb | 1 - lib/protobuf/field/bool_field.rb | 1 - lib/protobuf/field/bytes_field.rb | 1 - lib/protobuf/field/double_field.rb | 1 - lib/protobuf/field/enum_field.rb | 1 - lib/protobuf/field/field_array.rb | 1 - lib/protobuf/field/fixed64_field.rb | 1 - lib/protobuf/field/float_field.rb | 1 - lib/protobuf/field/int32_field.rb | 1 - lib/protobuf/field/int64_field.rb | 1 - lib/protobuf/field/integer_field.rb | 1 - lib/protobuf/field/message_field.rb | 1 - lib/protobuf/field/sfixed32_field.rb | 1 - lib/protobuf/field/sfixed64_field.rb | 1 - lib/protobuf/field/signed_integer_field.rb | 1 - lib/protobuf/field/sint32_field.rb | 1 - lib/protobuf/field/sint64_field.rb | 1 - lib/protobuf/field/string_field.rb | 1 - lib/protobuf/field/uint32_field.rb | 1 - lib/protobuf/field/uint64_field.rb | 1 - lib/protobuf/field/varint_field.rb | 1 - lib/protobuf/generators/base.rb | 1 - lib/protobuf/generators/enum_generator.rb | 1 - lib/protobuf/generators/extension_generator.rb | 1 - lib/protobuf/generators/field_generator.rb | 1 - lib/protobuf/generators/file_generator.rb | 1 - lib/protobuf/generators/group_generator.rb | 1 - lib/protobuf/generators/message_generator.rb | 1 - lib/protobuf/generators/printable.rb | 1 - lib/protobuf/generators/service_generator.rb | 1 - lib/protobuf/message/fields.rb | 1 - lib/protobuf/rpc/stat.rb | 1 - lib/protobuf/socket.rb | 1 - spec/functional/socket_server_spec.rb | 1 - spec/lib/protobuf/generators/base_spec.rb | 1 - spec/lib/protobuf/generators/extension_generator_spec.rb | 1 - spec/lib/protobuf/generators/field_generator_spec.rb | 1 - spec/lib/protobuf/generators/file_generator_spec.rb | 1 - spec/lib/protobuf/generators/service_generator_spec.rb | 1 - 46 files changed, 4 insertions(+), 50 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 24b47ee2..ad64da6e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,6 +9,10 @@ Style/CaseIndentation: Style/IndentHash: EnforcedStyle: consistent +Style/TrailingBlankLines: + Exclude: + - '**/*.pb.rb' + Style/TrailingComma: EnforcedStyleForMultiline: comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fd395013..b327328b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -289,12 +289,6 @@ Style/SpecialGlobalVars: Style/StringLiterals: Enabled: false -# Offense count: 56 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/TrailingBlankLines: - Enabled: false - # Offense count: 47 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. diff --git a/bin/protoc-gen-ruby b/bin/protoc-gen-ruby index 71e0be47..c0f7d37b 100755 --- a/bin/protoc-gen-ruby +++ b/bin/protoc-gen-ruby @@ -14,4 +14,3 @@ request_bytes = STDIN.read code_generator = ::Protobuf::CodeGenerator.new(request_bytes) response_bytes = code_generator.response_bytes STDOUT.print(response_bytes) - diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index df4b5ccf..e44fe2ac 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -38,4 +38,3 @@ def response_bytes end end - diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index b3b9eb0e..67e5f8ec 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -71,4 +71,3 @@ def self.read_varint(stream) end end - diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 202c672f..1eec5cf7 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -59,4 +59,3 @@ def write_pair(field, value) end end - diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 62e9b423..d2d8646a 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -316,4 +316,3 @@ def value alias_method :to_hash_value, :to_i end end - diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 902dda63..9d6efe75 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -264,4 +264,3 @@ def validate_packed_field end end end - diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index a002bbf7..6e789ed3 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -50,4 +50,3 @@ def define_getter end end end - diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 6b7e6c17..c095629f 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -78,4 +78,3 @@ def define_setter end end end - diff --git a/lib/protobuf/field/double_field.rb b/lib/protobuf/field/double_field.rb index b520fad1..31eb1b34 100644 --- a/lib/protobuf/field/double_field.rb +++ b/lib/protobuf/field/double_field.rb @@ -23,4 +23,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 15bfd94c..4b362248 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -68,4 +68,3 @@ def typed_default_value end end end - diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index afc2fef5..cf46323f 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -83,4 +83,3 @@ def raise_type_error(val) end end end - diff --git a/lib/protobuf/field/fixed64_field.rb b/lib/protobuf/field/fixed64_field.rb index d47ad327..ef825433 100644 --- a/lib/protobuf/field/fixed64_field.rb +++ b/lib/protobuf/field/fixed64_field.rb @@ -26,4 +26,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 4d138972..3c6ac8a4 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -39,4 +39,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb index a95b75a8..4a7865f9 100644 --- a/lib/protobuf/field/int32_field.rb +++ b/lib/protobuf/field/int32_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb index b0080819..18538f4b 100644 --- a/lib/protobuf/field/int64_field.rb +++ b/lib/protobuf/field/int64_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/integer_field.rb b/lib/protobuf/field/integer_field.rb index 49435f32..5eb3b064 100644 --- a/lib/protobuf/field/integer_field.rb +++ b/lib/protobuf/field/integer_field.rb @@ -21,4 +21,3 @@ def encode(value) end end end - diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 447455e4..5161edbe 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -63,4 +63,3 @@ def define_setter end end end - diff --git a/lib/protobuf/field/sfixed32_field.rb b/lib/protobuf/field/sfixed32_field.rb index 242a1850..9f9b64e9 100644 --- a/lib/protobuf/field/sfixed32_field.rb +++ b/lib/protobuf/field/sfixed32_field.rb @@ -25,4 +25,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/sfixed64_field.rb b/lib/protobuf/field/sfixed64_field.rb index f639cedd..fc296483 100644 --- a/lib/protobuf/field/sfixed64_field.rb +++ b/lib/protobuf/field/sfixed64_field.rb @@ -26,4 +26,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/signed_integer_field.rb b/lib/protobuf/field/signed_integer_field.rb index 821db3bf..8945f771 100644 --- a/lib/protobuf/field/signed_integer_field.rb +++ b/lib/protobuf/field/signed_integer_field.rb @@ -27,4 +27,3 @@ def encode(value) end end end - diff --git a/lib/protobuf/field/sint32_field.rb b/lib/protobuf/field/sint32_field.rb index 95784c85..3af0ce98 100644 --- a/lib/protobuf/field/sint32_field.rb +++ b/lib/protobuf/field/sint32_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/sint64_field.rb b/lib/protobuf/field/sint64_field.rb index a6d0056d..2aba7dfa 100644 --- a/lib/protobuf/field/sint64_field.rb +++ b/lib/protobuf/field/sint64_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 83fbd4ae..d1045a03 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -32,4 +32,3 @@ def encode(value) end end end - diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb index 6b60b898..50fa8fef 100644 --- a/lib/protobuf/field/uint32_field.rb +++ b/lib/protobuf/field/uint32_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb index eafbda32..8a060f14 100644 --- a/lib/protobuf/field/uint64_field.rb +++ b/lib/protobuf/field/uint64_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 35c68bab..448610dd 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -65,4 +65,3 @@ def wire_type end end end - diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 4981488f..800e63fe 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -68,4 +68,3 @@ def type_namespace end end end - diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 90b70221..57b7416b 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -39,4 +39,3 @@ def build_value(enum_value_descriptor) end end end - diff --git a/lib/protobuf/generators/extension_generator.rb b/lib/protobuf/generators/extension_generator.rb index 57e34117..36c5c581 100644 --- a/lib/protobuf/generators/extension_generator.rb +++ b/lib/protobuf/generators/extension_generator.rb @@ -25,4 +25,3 @@ def compile end end end - diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index a252a445..7797afbf 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -129,4 +129,3 @@ def verbatim_default_value end end end - diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 097cd818..5f62f7d1 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -138,4 +138,3 @@ def fully_qualified_token?(token) end end end - diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index 84d95176..8c6a90c3 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -110,4 +110,3 @@ def to_s end end end - diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index c9ea7af1..81505f71 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -96,4 +96,3 @@ def message_extension_fields end end end - diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 31874b7f..268ce42f 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -158,4 +158,3 @@ def print_contents end end end - diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb index 2c5a4891..bc2f5d8d 100644 --- a/lib/protobuf/generators/service_generator.rb +++ b/lib/protobuf/generators/service_generator.rb @@ -24,4 +24,3 @@ def build_method(method_descriptor) end end end - diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 30023e6a..a89596cc 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -119,4 +119,3 @@ def raise_if_name_collision(field_name) end end end - diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index eea4c273..36a9c2e6 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -95,4 +95,3 @@ def trace_id end end end - diff --git a/lib/protobuf/socket.rb b/lib/protobuf/socket.rb index 7731cfa0..a8feb2fe 100644 --- a/lib/protobuf/socket.rb +++ b/lib/protobuf/socket.rb @@ -19,4 +19,3 @@ require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/connectors/socket' - diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index bf0c283a..7d1b7277 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -57,4 +57,3 @@ expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end end - diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index a7a303e4..6feab2b1 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -81,4 +81,3 @@ def compile end end - diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 5c742480..559f21b8 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -40,4 +40,3 @@ end end - diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index e03ee487..c329ea04 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -100,4 +100,3 @@ end end - diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 56b05e37..bfb699d6 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -30,4 +30,3 @@ end end - diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 33894dc9..0748ced2 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -44,4 +44,3 @@ end end - From b8505e0498ccefa585afb99ca4075bc7ccc7f22b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:15:29 -0700 Subject: [PATCH 0779/1191] Style/SpecialGlobalVars --- .rubocop_todo.yml | 5 ----- Rakefile | 4 ++-- lib/protobuf/rpc/connectors/zmq.rb | 8 ++++---- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- protobuf.gemspec | 2 +- spec/spec_helper.rb | 6 +++--- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b327328b..a621c9b6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -278,11 +278,6 @@ Style/SpaceInsideHashLiteralBraces: Style/SpaceInsideParens: Enabled: false -# Offense count: 12 -# Cop supports --auto-correct. -Style/SpecialGlobalVars: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/Rakefile b/Rakefile index 6423d7ad..7c8ce81a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ -$: << ::File.expand_path('../', __FILE__) -$: << ::File.expand_path('../spec', __FILE__) +$LOAD_PATH << ::File.expand_path('../', __FILE__) +$LOAD_PATH << ::File.expand_path('../spec', __FILE__) require 'fileutils' require 'rubygems' diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 598e068c..4e331c7b 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -259,13 +259,13 @@ def zmq_eagain_error_check(return_code, source) raise ZmqEagainError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR else raise <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end @@ -276,7 +276,7 @@ def zmq_error_check(return_code, source) raise <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end @@ -286,7 +286,7 @@ def zmq_recoverable_error_check(return_code, source) raise ZmqRecoverableError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 2fe3066b..c548722c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -296,7 +296,7 @@ def start_worker begin ::Protobuf::Rpc::Zmq::Worker.new(server).run rescue => e - message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" + message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}" $stderr.puts(message) logger.error { message } end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index f16bbcfd..4a991ab0 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -23,7 +23,7 @@ def zmq_error_check(return_code, source = nil) raise <<-ERROR Last ZMQ API call #{source ? "to #{source}" : ""} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end diff --git a/protobuf.gemspec b/protobuf.gemspec index 495a8aa7..3549a82f 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -1,5 +1,5 @@ # encoding: UTF-8 -$:.push ::File.expand_path("../lib", __FILE__) +$LOAD_PATH.push ::File.expand_path("../lib", __FILE__) require "protobuf/version" ::Gem::Specification.new do |s| diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07b108ea..d588e54e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,14 +5,14 @@ require 'pry' # require 'rspec/its' -$: << ::File.expand_path('../..', __FILE__) -$: << ::File.expand_path('../support', __FILE__) +$LOAD_PATH << ::File.expand_path('../..', __FILE__) +$LOAD_PATH << ::File.expand_path('../support', __FILE__) require 'protobuf' require 'protobuf/rpc/server' require ::File.expand_path('../support/all', __FILE__) -$: << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) +$LOAD_PATH << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) require 'google/protobuf/compiler/plugin.pb' # Including a way to turn on debug logger for spec runs From e6152abf68e85bd40cad12cee0c64fe2012eeaae Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:16:13 -0700 Subject: [PATCH 0780/1191] Style/SpaceInsideParens --- .rubocop_todo.yml | 5 ----- lib/protobuf/lifecycle.rb | 4 ++-- spec/lib/protobuf/lifecycle_spec.rb | 2 +- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a621c9b6..37279b2a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -273,11 +273,6 @@ Style/SpaceInsideBrackets: Style/SpaceInsideHashLiteralBraces: Enabled: false -# Offense count: 8 -# Cop supports --auto-correct. -Style/SpaceInsideParens: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index a4d6e9a4..bc035145 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -18,7 +18,7 @@ def self.register(event_name, &blk) end end - def self.trigger( event_name, *args ) + def self.trigger(event_name, *args) if ::Protobuf.print_deprecation_warnings? $stderr.puts <<-ERROR [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. @@ -26,7 +26,7 @@ def self.trigger( event_name, *args ) ERROR end - event_name = normalized_event_name( event_name ) + event_name = normalized_event_name(event_name) ::ActiveSupport::Notifications.instrument(event_name, args) end diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index f5e098f9..de42520f 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -16,7 +16,7 @@ it "only registers blocks for event callbacks" do expect do subject.register("something") - end.to raise_error( /block/ ) + end.to raise_error(/block/) end it "calls the registered block when triggered" do diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 03734958..45142662 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -31,7 +31,7 @@ end describe "#lookup_server_uri" do - let(:service_directory) { double('ServiceDirectory', :running? => running? ) } + let(:service_directory) { double('ServiceDirectory', :running? => running?) } let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) } let(:listings) { [listing] } let(:running?) { true } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d588e54e..831fd671 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,7 @@ # Including a way to turn on debug logger for spec runs if ENV.key?('DEBUG') - debug_log = ::File.expand_path('../../debug_specs.log', __FILE__ ) + debug_log = ::File.expand_path('../../debug_specs.log', __FILE__) ::Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG) else ::Protobuf::Logging.initialize_logger('/dev/null') From 4506cc53a4ab8effe705ae519e8614ec87627f73 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:16:41 -0700 Subject: [PATCH 0781/1191] Style/SpaceInsideHashLiteralBraces --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/stat.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 37279b2a..1b962b21 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -267,12 +267,6 @@ Style/SpaceInsideBlockBraces: Style/SpaceInsideBrackets: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -Style/SpaceInsideHashLiteralBraces: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 36a9c2e6..7f6d063b 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -32,7 +32,7 @@ def method_name end def server=(peer) - @server = {:port => peer[0], :ip => peer[1]} + @server = { :port => peer[0], :ip => peer[1] } end def server From 1d9ff260f8baa400e78544666c593cdf498b93a3 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:17:21 -0700 Subject: [PATCH 0782/1191] Style/SpaceInsideBlockBraces --- .rubocop_todo.yml | 6 ------ lib/protobuf/message.rb | 2 +- spec/functional/socket_server_spec.rb | 8 ++++---- spec/functional/zmq_server_spec.rb | 4 ++-- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf/rpc/connectors/base_spec.rb | 4 ++-- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b962b21..5293138b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -256,12 +256,6 @@ Style/SpaceAroundOperators: Style/SpaceBeforeBlockBraces: Enabled: false -# Offense count: 14 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -Style/SpaceInsideBlockBraces: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 3f95ab6e..da3dfbea 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -174,7 +174,7 @@ def copy_to(object, method) object.__send__(:initialize) @values.each do |name, value| if value.is_a?(::Protobuf::Field::FieldArray) - object.__send__(name).replace(value.map {|v| duplicate.call(v)}) + object.__send__(name).replace(value.map { |v| duplicate.call(v) }) else object.__send__("#{name}=", duplicate.call(value)) end diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 7d1b7277..c6098b6c 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -38,8 +38,8 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + c.on_success { raise "shouldn't pass" } + c.on_failure { |e| error = e } end expect(error.message).to match(/Required field.*does not have a value/) @@ -51,8 +51,8 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + c.on_success { raise "shouldn't pass" } + c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 72b4d72b..31b627d2 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -69,7 +69,7 @@ client.find(request) do |c| c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e } + c.on_failure { |e| error = e } end expect(error.message).to match(/Required field.*does not have a value/) end @@ -83,7 +83,7 @@ client.find(request) do |c| c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e} + c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 97acbb4d..d2e06024 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -425,7 +425,7 @@ end it "does not allow string fields to be set to Numeric" do - expect { subject.name = 1}.to raise_error(/name/) + expect { subject.name = 1 }.to raise_error(/name/) end end diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index fad03f4f..fb1f0df1 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -30,7 +30,7 @@ describe '#success_cb' do it 'allows setting the success callback and calling it' do expect(subject.success_cb).to be_nil - cb = proc {|res| raise res } + cb = proc { |res| raise res } subject.success_cb = cb expect(subject.success_cb).to eq(cb) expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb' @@ -40,7 +40,7 @@ describe '#failure_cb' do it 'allows setting the failure callback and calling it' do expect(subject.failure_cb).to be_nil - cb = proc {|res| raise res } + cb = proc { |res| raise res } subject.failure_cb = cb expect(subject.failure_cb).to eq(cb) expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb' From 8dbf693ebc32650971917b2a335f2fde9859ac5d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:17:53 -0700 Subject: [PATCH 0783/1191] Style/SpaceBeforeBlockBraces --- .rubocop_todo.yml | 6 ------ spec/lib/protobuf/rpc/connectors/base_spec.rb | 6 +++--- spec/lib/protobuf/rpc/connectors/common_spec.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/socket_spec.rb | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5293138b..59e2846e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -250,12 +250,6 @@ Style/SpaceAroundEqualsInParameterDefault: Style/SpaceAroundOperators: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceBeforeBlockBraces: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index fb1f0df1..5d911d2c 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -10,12 +10,12 @@ describe "#send_request" do it "raising an error when 'send_request' is not overridden" do - expect{ subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/) + expect { subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/) end it "does not raise error when 'send_request' is overridden" do - new_sub = Class.new(subject.class){ def send_request; end }.new(options) - expect{ new_sub.send_request }.to_not raise_error + new_sub = Class.new(subject.class) { def send_request; end }.new(options) + expect { new_sub.send_request }.to_not raise_error end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 0710d6ab..029c9b46 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -111,7 +111,7 @@ end it "doesn't set @failure_cb when already defined" do - set_cb = lambda{ true } + set_cb = lambda { true } subject.instance_variable_set(:@failure_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) @@ -119,7 +119,7 @@ end it "doesn't set @success_cb when already defined" do - set_cb = lambda{ true } + set_cb = lambda { true } subject.instance_variable_set(:@success_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 38aeea2a..635c6590 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/socket' shared_examples "a Protobuf Connector" do - subject{ described_class.new({}) } + subject { described_class.new({}) } context "API" do # Check the API @@ -14,7 +14,7 @@ end describe Protobuf::Rpc::Connectors::Socket do - subject{ described_class.new({}) } + subject { described_class.new({}) } it_behaves_like "a Protobuf Connector" From fbaa7f158947a2e86a51e46d6c4f4750eec047e2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:18:15 -0700 Subject: [PATCH 0784/1191] Style/SpaceAroundOperators --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/connectors/zmq.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 59e2846e..5593d1b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -245,11 +245,6 @@ Style/SpaceAfterNot: Style/SpaceAroundEqualsInParameterDefault: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/SpaceAroundOperators: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 4e331c7b..520fc034 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -129,7 +129,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep(1.0/100.0) + sleep(1.0 / 100.0) end raise "Host not found for service #{service}" From 9e632efce7222e5d8349a80a0b26cffe8bc52711 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:18:57 -0700 Subject: [PATCH 0785/1191] Style/SpaceAroundEqualsInParameterDefault --- .rubocop_todo.yml | 6 ------ lib/protobuf/logging.rb | 2 +- lib/protobuf/rpc/buffer.rb | 4 ++-- lib/protobuf/rpc/env.rb | 2 +- lib/protobuf/rpc/error.rb | 2 +- lib/protobuf/rpc/error/client_error.rb | 8 ++++---- lib/protobuf/rpc/error/server_error.rb | 12 ++++++------ 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5593d1b3..ae4c812b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -239,12 +239,6 @@ Style/SpaceAfterComma: Style/SpaceAfterNot: Enabled: false -# Offense count: 17 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index bdaea254..904d77d5 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -2,7 +2,7 @@ module Protobuf module Logging - def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) + def self.initialize_logger(log_target = $stdout, log_level = ::Logger::INFO) @counter ||= 0 @counter = @counter + 1 @logger = Logger.new(log_target) diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index bec96248..97587a00 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -9,7 +9,7 @@ class Buffer # constantize this so we don't re-initialize the regex every time we need it SIZE_REGEX = /^\d+-/ - def initialize(mode=:read) + def initialize(mode = :read) @flush = false @data = "" @size = 0 @@ -24,7 +24,7 @@ def mode=(mode) end end - def write(force_mode=true) + def write(force_mode = true) if force_mode && reading? self.mode = :write elsif !force_mode && reading? diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index 2f648e74..c719cadf 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -48,7 +48,7 @@ def #{name}? :service_name, :worker_id - def initialize(options={}) + def initialize(options = {}) merge!(options) self['worker_id'] = ::Thread.current.object_id.to_s(16) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index a834a9bc..9a3f8569 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -8,7 +8,7 @@ module Rpc class PbError < StandardError attr_reader :error_type - def initialize(message='An unknown RpcError occurred', error_type='RPC_ERROR') + def initialize(message = 'An unknown RpcError occurred', error_type = 'RPC_ERROR') @error_type = error_type.is_a?(String) ? Socketrpc::ErrorReason.const_get(error_type) : error_type super message end diff --git a/lib/protobuf/rpc/error/client_error.rb b/lib/protobuf/rpc/error/client_error.rb index 19d161af..7efe27f5 100644 --- a/lib/protobuf/rpc/error/client_error.rb +++ b/lib/protobuf/rpc/error/client_error.rb @@ -4,25 +4,25 @@ module Protobuf module Rpc class InvalidRequestProto < PbError - def initialize(message='Invalid request type given') + def initialize(message = 'Invalid request type given') super message, 'INVALID_REQUEST_PROTO' end end class BadResponseProto < PbError - def initialize(message='Bad response type from server') + def initialize(message = 'Bad response type from server') super message, 'BAD_RESPONSE_PROTO' end end class UnkownHost < PbError - def initialize(message='Unknown host or port') + def initialize(message = 'Unknown host or port') super message, 'UNKNOWN_HOST' end end class IOError < PbError - def initialize(message='IO Error occurred') + def initialize(message = 'IO Error occurred') super message, 'IO_ERROR' end end diff --git a/lib/protobuf/rpc/error/server_error.rb b/lib/protobuf/rpc/error/server_error.rb index a37f0a37..7c516221 100644 --- a/lib/protobuf/rpc/error/server_error.rb +++ b/lib/protobuf/rpc/error/server_error.rb @@ -4,37 +4,37 @@ module Protobuf module Rpc class BadRequestData < PbError - def initialize message='Unable to parse request' + def initialize message = 'Unable to parse request' super message, 'BAD_REQUEST_DATA' end end class BadRequestProto < PbError - def initialize message='Request is of wrong type' + def initialize message = 'Request is of wrong type' super message, 'BAD_REQUEST_PROTO' end end class ServiceNotFound < PbError - def initialize message='Service class not found' + def initialize message = 'Service class not found' super message, 'SERVICE_NOT_FOUND' end end class MethodNotFound < PbError - def initialize message='Service method not found' + def initialize message = 'Service method not found' super message, 'METHOD_NOT_FOUND' end end class RpcError < PbError - def initialize message='RPC exception occurred' + def initialize message = 'RPC exception occurred' super message, 'RPC_ERROR' end end class RpcFailed < PbError - def initialize message='RPC failed' + def initialize message = 'RPC failed' super message, 'RPC_FAILED' end end From bcbe2df116c0849be452812c5b1260998ef6fbc3 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:19:45 -0700 Subject: [PATCH 0786/1191] Style/RedundantException --- .rubocop_todo.yml | 4 ---- spec/lib/protobuf/rpc/service_filters_spec.rb | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ae4c812b..295ffad9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -183,10 +183,6 @@ Style/Proc: Style/RaiseArgs: Enabled: false -# Offense count: 1 -Style/RedundantException: - Enabled: false - # Offense count: 20 # Cop supports --auto-correct. # Configuration parameters: AllowMultipleReturnValues. diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 538dfcc1..93781f2f 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -400,7 +400,7 @@ def filter_with_error3 def filter_with_runtime_error @called << :filter_with_runtime_error - raise RuntimeError, 'Filter with runtime error failed' + raise 'Filter with runtime error failed' end def custom_error_occurred(ex) From 2bb5f1f7450cd33d108799284635b37a023c8f94 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:21:53 -0700 Subject: [PATCH 0787/1191] Style/EmptyLineBetweenDefs --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ad64da6e..796150c8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,9 @@ Lint/Loop: Style/CaseIndentation: IndentWhenRelativeTo: end +Style/EmptyLineBetweenDefs: + AllowAdjacentOneLineDefs: true + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 295ffad9..ccff0678 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -70,12 +70,6 @@ Style/DoubleNegation: Style/EachWithObject: Enabled: false -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs. -Style/EmptyLineBetweenDefs: - Enabled: false - # Offense count: 35 # Cop supports --auto-correct. Style/EmptyLines: From 4b1ec197c603dc4235eb88c5189a29b1f73e2570 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:25:31 -0700 Subject: [PATCH 0788/1191] Style/ClassAndModuleChildren --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 5 ----- spec/lib/protobuf/rpc/service_spec.rb | 6 +++--- spec/spec_helper.rb | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 796150c8..689fbd6b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,10 @@ Lint/Loop: Style/CaseIndentation: IndentWhenRelativeTo: end +Style/ClassAndModuleChildren: + Exclude: + - '**/*.pb.rb' + Style/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ccff0678..36dae6ab 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 4 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/ClassAndModuleChildren: - Enabled: false - # Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: PreferredMethods. diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 9260e567..2d01202e 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -100,8 +100,8 @@ context 'instance methods' do context 'when invoking a service call' do - before(:all) do - class ::NewTestService < Protobuf::Rpc::Service + before do + stub_const('NewTestService', Class.new(Protobuf::Rpc::Service) do rpc :find_with_implied_response, Test::ResourceFindRequest, Test::Resource def find_with_implied_response response.name = 'Implicit response' @@ -118,7 +118,7 @@ def find_with_rpc_failed rpc_failed('This is a failed endpoint') response.name = 'Name will still be set' end - end + end) end let(:request) { Test::ResourceFindRequest.new(:name => 'resource') } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 831fd671..216c9415 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,7 +29,7 @@ support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) Dir[support_proto_glob].each { |proto_file| require proto_file } -class ::Protobuf::Rpc::Client +::Protobuf::Rpc::Client.class_eval do def ==(other) connector.options == other.options && \ success_cb == other.success_cb && \ From 6a85590ecb49284f1e24cc9ec4919b07353981d8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:37:13 -0700 Subject: [PATCH 0789/1191] Style/CollectionMethods --- .rubocop_todo.yml | 6 ------ lib/protobuf/cli.rb | 2 +- lib/protobuf/enum.rb | 2 +- lib/protobuf/generators/file_generator.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- spec/lib/protobuf/rpc/service_directory_spec.rb | 4 ++-- 8 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 36dae6ab..b56926e7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: PreferredMethods. -Style/CollectionMethods: - Enabled: false - # Offense count: 5 # Configuration parameters: Keywords. Style/CommentAnnotation: diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 6e543c7a..3bacac65 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -180,7 +180,7 @@ def require_application(app_file) def runner_options # Symbolize keys - opt = options.inject({}) { |h, (k, v)| h[k.to_sym] = v; h } + opt = options.reduce({}) { |h, (k, v)| h[k.to_sym] = v; h } opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index d2d8646a..4e234ce9 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -226,7 +226,7 @@ def self.values self.warn_deprecated(:values, :enums) @values ||= begin - self.enums.inject({}) do |hash, enum| + self.enums.reduce({}) do |hash, enum| hash[enum.name] = enum hash end diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 5f62f7d1..77580bfd 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -120,7 +120,7 @@ def print_import_requires def print_package(&block) final = lambda { block.call } namespaces = descriptor.package.split('.') - namespaces.reverse.inject(final) do |previous, namespace| + namespaces.reverse.reduce(final) do |previous, namespace| lambda { print_module(namespace, &previous) } end.call end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 4b33b3ed..552610d2 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -8,7 +8,7 @@ module Common attr_reader :error def any_callbacks? - return [@complete_cb, @failure_cb, @success_cb].inject(false) do |reduction, cb| + return [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| reduction || !cb.nil? end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 4a991ab0..bdaaee96 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -38,7 +38,7 @@ def log_signature end def resolve_ip(hostname) - ::Resolv.getaddresses(hostname).detect do |address| + ::Resolv.getaddresses(hostname).find do |address| address =~ ADDRESS_MATCH end end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index b67a7d45..27484fda 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -210,7 +210,7 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = # def run_around_filters(rpc_method) final = lambda { __send__(rpc_method) } - filters[:around].reverse.inject(final) do |previous, filter| + filters[:around].reverse.reduce(final) do |previous, filter| if invoke_filter?(rpc_method, filter) lambda { call_or_send(filter[:callable], &previous) } else @@ -241,7 +241,7 @@ def run_rescue_filters yield rescue *rescue_filters.keys => ex callable = rescue_filters.fetch(ex.class) do - mapped_klass = rescue_filters.keys.detect { |child_klass| ex.class < child_klass } + mapped_klass = rescue_filters.keys.find { |child_klass| ex.class < child_klass } rescue_filters[mapped_klass] end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 4798e6e5..3fcfbcc2 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -260,13 +260,13 @@ def send_beacon(type, server) if ENV.key?("BENCH") context "performance" do let(:servers) do - 100.times.collect do |x| + 100.times.map do |x| ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "performance_server#{x + 1}", :address => '127.0.0.1', :port => (5555 + x).to_s, :ttl => rand(1..5), - :services => 10.times.collect { |y| "PerformanceService#{y}" } + :services => 10.times.map { |y| "PerformanceService#{y}" } ) end end From 51eac3a11486e04958f7e8fc2ca0eeefdeb20258 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:38:21 -0700 Subject: [PATCH 0790/1191] Style/CommentAnnotation --- .rubocop_todo.yml | 5 ----- lib/protobuf/cli.rb | 2 +- lib/protobuf/field/base_field.rb | 4 ++-- lib/protobuf/rpc/service_filters.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b56926e7..d9e44b94 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Configuration parameters: Keywords. -Style/CommentAnnotation: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. Style/DeprecatedHashMethods: diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3bacac65..a4f55a01 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -126,7 +126,7 @@ def configure_runner_mode end # Configure signal traps. - # TODO add signal handling for hot-reloading the application. + # TODO: add signal handling for hot-reloading the application. def configure_traps debug_say('Configuring traps') diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 9d6efe75..4c69025e 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -119,7 +119,7 @@ def required? rule == :required end - # FIXME need to cleanup (rename) this warthog of a method. + # FIXME: need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) if packed? array = message_instance.__send__(getter) @@ -148,7 +148,7 @@ def setter @setter ||= "#{name}=" end - # FIXME add packed, deprecated, extension options to to_s output + # FIXME: add packed, deprecated, extension options to to_s output def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 27484fda..ed9bcfa2 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -66,8 +66,8 @@ def remember_filter(type, filter) end # Takes a list of actually (or potentially) callable objects. - # TODO add support for if/unless - # TODO add support for only/except sub-filters + # TODO: add support for if/unless + # TODO: add support for only/except sub-filters # def set_filters(type, *args) options = args.last.is_a?(Hash) ? args.pop : {} From d6b33d7e6888c36c9932fb6507bcc99cb340523c Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:39:00 -0700 Subject: [PATCH 0791/1191] Style/DeprecatedHashMethods --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 2 +- lib/protobuf/rpc/connectors/base.rb | 4 ++-- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d9e44b94..36760a53 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -Style/DeprecatedHashMethods: - Enabled: false - # Offense count: 191 Style/Documentation: Enabled: false diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index da3dfbea..18d314f9 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -82,7 +82,7 @@ def each_field_for_serialization end def has_field?(name) - @values.has_key?(name) + @values.key?(name) end def inspect diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index c2a6b9d6..81326cd1 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -33,7 +33,7 @@ def initialize(options) end def first_alive_load_balance? - ENV.has_key?("PB_FIRST_ALIVE_LOAD_BALANCE") || + ENV.key?("PB_FIRST_ALIVE_LOAD_BALANCE") || options[:first_alive_load_balance] end @@ -46,7 +46,7 @@ def ping_port end def ping_port_enabled? - ENV.has_key?("PB_RPC_PING_PORT") + ENV.key?("PB_RPC_PING_PORT") end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 520fc034..a6310a02 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -190,7 +190,7 @@ def rcv_timeout case when options[:timeout] then options[:timeout] - when ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then + when ENV.key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i else 300_000 # 300 seconds @@ -203,7 +203,7 @@ def snd_timeout case when options[:timeout] then options[:timeout] - when ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then + when ENV.key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i else 300_000 # 300 seconds From 855467bf75d7c9b59b8656bda957ef33c33da37f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:46:15 -0700 Subject: [PATCH 0792/1191] Style/EachWithObject --- .rubocop_todo.yml | 4 ---- lib/protobuf/cli.rb | 5 +++-- lib/protobuf/enum.rb | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 36760a53..9c099391 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -45,10 +45,6 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 2 -Style/EachWithObject: - Enabled: false - # Offense count: 35 # Cop supports --auto-correct. Style/EmptyLines: diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index a4f55a01..90990e2c 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/hash/keys' + require 'thor' require 'protobuf/version' require 'protobuf/logging' @@ -179,8 +181,7 @@ def require_application(app_file) end def runner_options - # Symbolize keys - opt = options.reduce({}) { |h, (k, v)| h[k.to_sym] = v; h } + opt = options.symbolize_keys opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 4e234ce9..cb6bc31f 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -226,9 +226,8 @@ def self.values self.warn_deprecated(:values, :enums) @values ||= begin - self.enums.reduce({}) do |hash, enum| + self.enums.each_with_object({}) do |enum, hash| hash[enum.name] = enum - hash end end end From d83fb0471ec9b7ff387bc7ff90ec91a5bcd32ee1 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:49:55 -0700 Subject: [PATCH 0793/1191] Style/EmptyLines --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 5 ----- lib/protobuf/enum.rb | 1 - lib/protobuf/field/bool_field.rb | 1 - lib/protobuf/rpc/service_filters.rb | 1 - spec/lib/protobuf/enum_spec.rb | 1 - spec/lib/protobuf/field/string_field_spec.rb | 1 - spec/lib/protobuf/field_spec.rb | 3 --- 8 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 689fbd6b..54aee5d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,10 @@ Style/ClassAndModuleChildren: Style/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true +Style/EmptyLines: + Exclude: + - '**/*.pb.rb' + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9c099391..d4a6b8b8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -45,11 +45,6 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 35 -# Cop supports --auto-correct. -Style/EmptyLines: - Enabled: false - # Offense count: 10 # Cop supports --auto-correct. Style/EmptyLinesAroundAccessModifier: diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index cb6bc31f..e6bfd422 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -241,7 +241,6 @@ def self.values deprecate_class_method :get_name_by_tag, :name_for_tag deprecate_class_method :value_by_name, :enum_for_name - ## # Attributes # diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 6e789ed3..182d6295 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -12,7 +12,6 @@ def self.default false end - ## # Public Instance Methods # # diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index ed9bcfa2..f7de8ad9 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -219,7 +219,6 @@ def run_around_filters(rpc_method) end.call end - # Entry method to call each filter type in the appropriate order. This should # be used instead of the other run methods directly. # diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index f532627a..645bf424 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -69,7 +69,6 @@ end end - describe '.enums_for_tag' do it 'returns an array of Enums for the given tag, if any' do expect(EnumAliasTest.enums_for_tag(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index b25ccc95..f1ad1a7e 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -42,5 +42,4 @@ end end - end diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index 7b7537a6..4dafd9f5 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -148,7 +148,6 @@ end end - context 'when type is a string field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::StringField @@ -159,7 +158,6 @@ end end - context 'when type is a bytes field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::BytesField @@ -170,7 +168,6 @@ end end - context 'when type is a bool field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::BoolField From 90b393cd1f923095b84685437d18809650e700ab Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:51:07 -0700 Subject: [PATCH 0794/1191] Style/EmptyLinesAroundAccessModifier --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 1 + spec/lib/protobuf/rpc/service_filters_spec.rb | 9 +++++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d4a6b8b8..c5affee2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -45,11 +45,6 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 10 -# Cop supports --auto-correct. -Style/EmptyLinesAroundAccessModifier: - Enabled: false - # Offense count: 146 # Cop supports --auto-correct. Style/EmptyLinesAroundBody: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 18d314f9..8320861d 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -161,6 +161,7 @@ def []=(name, value) ## # Private Instance Methods # + private def copy_to(object, method) diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 93781f2f..0040e356 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -38,6 +38,7 @@ def self.clear_filters! before(:all) do class FilterTest private + def verify_before @called << :verify_before @before_filter_calls += 1 @@ -68,6 +69,7 @@ def foo before(:all) do class FilterTest private + def endpoint_with_verify @called << :endpoint_with_verify end @@ -98,6 +100,7 @@ def endpoint_with_verify before(:all) do class FilterTest private + def endpoint_without_verify @called << :endpoint_without_verify end @@ -128,6 +131,7 @@ def endpoint_without_verify before(:all) do class FilterTest private + def check_true; return true; end def check_false; return false; end def verify_before; @called << :verify_before; end @@ -187,6 +191,7 @@ def verify_before; @called << :verify_before; end before(:all) do class FilterTest private + def check_true; return true; end def check_false; return false; end def verify_before; @called << :verify_before; end @@ -246,6 +251,7 @@ def verify_before; @called << :verify_before; end before(:all) do class FilterTest private + def short_circuit_filter @called << :short_circuit_filter return false @@ -272,6 +278,7 @@ def short_circuit_filter before(:all) do class FilterTest private + def verify_after @called << :verify_after @after_filter_calls += 1 @@ -305,6 +312,7 @@ def foo before(:all) do class FilterTest private + def outer_around @called << :outer_around_top yield @@ -346,6 +354,7 @@ def inner_around before do class FilterTest private + def inner_around @called << :inner_around end From ff67c4eff1272545c2abda2d26923de941d9aae2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:53:14 -0700 Subject: [PATCH 0795/1191] Style/EmptyLiteral --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c5affee2..31e62fdc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,11 +50,6 @@ Style/DoubleNegation: Style/EmptyLinesAroundBody: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/EmptyLiteral: - Enabled: false - # Offense count: 2 # Configuration parameters: Exclude. Style/FileName: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 8320861d..83345493 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -100,7 +100,7 @@ def respond_to_has_and_present?(key) # Return a hash-representation of the given fields for this message type. def to_hash - result = Hash.new + result = {} @values.keys.each do |field_name| value = __send__(field_name) From c990afce1a7467d9ae8884da19d2808fea229e05 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:53:58 -0700 Subject: [PATCH 0796/1191] Style/IndentationConsistency --- .rubocop_todo.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 31e62fdc..afac0e85 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -71,11 +71,6 @@ Style/HashSyntax: Style/IfUnlessModifier: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -Style/IndentationConsistency: - Enabled: false - # Offense count: 1 # Cop supports --auto-correct. Style/IndentationWidth: From d5aa15fa2d86df13501f66e0740590e714a8ddf7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:54:40 -0700 Subject: [PATCH 0797/1191] Style/IndentationWidth --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/fixed32_field.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index afac0e85..0c685eb8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -71,11 +71,6 @@ Style/HashSyntax: Style/IfUnlessModifier: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/IndentationWidth: - Enabled: false - # Offense count: 14 Style/Lambda: Enabled: false diff --git a/lib/protobuf/field/fixed32_field.rb b/lib/protobuf/field/fixed32_field.rb index 4b07f3e4..74d0f384 100644 --- a/lib/protobuf/field/fixed32_field.rb +++ b/lib/protobuf/field/fixed32_field.rb @@ -17,7 +17,7 @@ def encode(value) end def wire_type - ::Protobuf::WireType::FIXED32 + ::Protobuf::WireType::FIXED32 end end From 2dacbe128984e81262b60c426e97acb43503003a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:55:24 -0700 Subject: [PATCH 0798/1191] Style/LeadingCommentSpace --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/servers/socket/server.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0c685eb8..cd602d92 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -75,11 +75,6 @@ Style/IfUnlessModifier: Style/Lambda: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/LeadingCommentSpace: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 01fa55d6..4353c0a5 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -96,7 +96,7 @@ def run raise rescue # Closing the server causes the loop to raise an exception here - raise #if running? + raise # if running? end def running? From 712b93bc4e2d1eed19571cdc7acce18321f02e37 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:55:53 -0700 Subject: [PATCH 0799/1191] Style/MethodDefParentheses --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/error/server_error.rb | 12 ++++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cd602d92..49935059 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -75,12 +75,6 @@ Style/IfUnlessModifier: Style/Lambda: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MethodDefParentheses: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: diff --git a/lib/protobuf/rpc/error/server_error.rb b/lib/protobuf/rpc/error/server_error.rb index 7c516221..990c858b 100644 --- a/lib/protobuf/rpc/error/server_error.rb +++ b/lib/protobuf/rpc/error/server_error.rb @@ -4,37 +4,37 @@ module Protobuf module Rpc class BadRequestData < PbError - def initialize message = 'Unable to parse request' + def initialize(message = 'Unable to parse request') super message, 'BAD_REQUEST_DATA' end end class BadRequestProto < PbError - def initialize message = 'Request is of wrong type' + def initialize(message = 'Request is of wrong type') super message, 'BAD_REQUEST_PROTO' end end class ServiceNotFound < PbError - def initialize message = 'Service class not found' + def initialize(message = 'Service class not found') super message, 'SERVICE_NOT_FOUND' end end class MethodNotFound < PbError - def initialize message = 'Service method not found' + def initialize(message = 'Service method not found') super message, 'METHOD_NOT_FOUND' end end class RpcError < PbError - def initialize message = 'RPC exception occurred' + def initialize(message = 'RPC exception occurred') super message, 'RPC_ERROR' end end class RpcFailed < PbError - def initialize message = 'RPC failed' + def initialize(message = 'RPC failed') super message, 'RPC_FAILED' end end From 4416cd094d792c2f0cf5212bdb8b55315f71d4dd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:56:43 -0700 Subject: [PATCH 0800/1191] Style/NonNilCheck --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/client.rb | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 49935059..81320ec4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -80,12 +80,6 @@ Style/Lambda: Style/Next: Enabled: false -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: IncludeSemanticChanges. -Style/NonNilCheck: - Enabled: false - # Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index d8ebe349..e810530a 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -46,7 +46,7 @@ def on_complete(&complete_cb) end def on_complete=(callable) - if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 + if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 raise "callable must take a single argument and respond to :call" end @@ -65,7 +65,7 @@ def on_failure(&failure_cb) end def on_failure=(callable) - if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 + if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 raise "Callable must take a single argument and respond to :call" end @@ -84,7 +84,7 @@ def on_success(&success_cb) end def on_success=(callable) - if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 + if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 raise "Callable must take a single argument and respond to :call" end From 8ba592177161f9968a6cfd815cf86733e23a120d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:04:01 -0700 Subject: [PATCH 0801/1191] Style/OpMethod --- .rubocop_todo.yml | 4 ---- lib/protobuf/message.rb | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 81320ec4..1b8c0ce0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -85,10 +85,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 1 -Style/OpMethod: - Enabled: false - # Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 83345493..62741a39 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -119,10 +119,10 @@ def to_proto self end - def ==(obj) - return false unless obj.is_a?(self.class) + def ==(other) + return false unless other.is_a?(self.class) each_field do |field, value| - return false unless value == obj.__send__(field.name) + return false unless value == other.__send__(field.name) end true end From b5f40594a595726a93ff087f950563d2652054df Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:06:21 -0700 Subject: [PATCH 0802/1191] Style/PercentLiteralDelimiters --- .rubocop_todo.yml | 6 ------ Rakefile | 4 ++-- lib/protobuf/deprecator.rb | 4 ++-- lib/protobuf/generators/field_generator.rb | 2 +- lib/protobuf/message/fields.rb | 4 ++-- spec/lib/protobuf/generators/field_generator_spec.rb | 2 +- spec/lib/protobuf/rpc/service_directory_spec.rb | 8 ++++---- 7 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b8c0ce0..7c8b5c8d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -85,12 +85,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Enabled: false - # Offense count: 7 # Configuration parameters: NamePrefix, NamePrefixBlacklist. Style/PredicateName: diff --git a/Rakefile b/Rakefile index 7c8ce81a..57f3e75c 100644 --- a/Rakefile +++ b/Rakefile @@ -22,7 +22,7 @@ namespace :compile do task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) proto_files = Dir[File.join(proto_path, '**', '*.proto')] - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}} + cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}) puts cmd system(cmd) @@ -35,7 +35,7 @@ namespace :compile do output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}} + cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}) puts cmd system(cmd) diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index b19773c0..f7d5df84 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -2,8 +2,8 @@ module Protobuf module Deprecator def warn_deprecated(old_method, new_method) - $stderr.puts %{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. - Please use #{self.name}.#{new_method} instead.\n} + $stderr.puts %([DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. + Please use #{self.name}.#{new_method} instead.\n) end # Given deprecations should be a hash whose keys are the new methods diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 7797afbf..91684914 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -119,7 +119,7 @@ def float_double_default_value end def string_default_value - %{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"} + %("#{verbatim_default_value.gsub(/'/, '\\\\\'')}") end def verbatim_default_value diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index a89596cc..7e92f606 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -106,13 +106,13 @@ def define_field(rule, type_class, field_name, tag, options) def raise_if_tag_collision(tag, field_name) if get_field(tag, true) - raise TagCollisionError, %!Field number #{tag} has already been used in "#{name}" by field "#{field_name}".! + raise TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) end end def raise_if_name_collision(field_name) if get_field(field_name, true) - raise DuplicateFieldNameError, %!Field name #{field_name} has already been used in "#{name}".! + raise DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index c329ea04..0e72dde5 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -57,7 +57,7 @@ let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - specify { expect(subject).to eq %{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :default => \"a default \"string\"\"\n" } end context 'when float or double field type' do diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 3fcfbcc2..32cb3b4f 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -11,7 +11,7 @@ :address => '127.0.0.1', :port => '1111', :ttl => 10, - :services => %w[EchoService] + :services => %w(EchoService) ) end @@ -21,7 +21,7 @@ :address => '127.0.0.1', :port => "1112", :ttl => 10, - :services => %w[HelloService] + :services => %w(HelloService) ) end @@ -31,7 +31,7 @@ :address => '127.0.0.1', :port => '1113', :ttl => 1, - :services => %w[HelloService] + :services => %w(HelloService) ) end @@ -41,7 +41,7 @@ :address => '127.0.0.1', :port => '1114', :ttl => 10, - :services => %w[HelloService EchoService] + :services => %w(HelloService EchoService) ) end From 3bd24d5b6436ab8969d78fc25fb5900a558745f5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:07:06 -0700 Subject: [PATCH 0803/1191] Style/Proc --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb | 2 +- spec/lib/protobuf/rpc/middleware/logger_spec.rb | 2 +- spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb | 2 +- spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb | 2 +- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7c8b5c8d..48fdf8cf 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -90,11 +90,6 @@ Style/NumericLiterals: Style/PredicateName: Enabled: false -# Offense count: 4 -# Cop supports --auto-correct. -Style/Proc: - Enabled: false - # Offense count: 8 # Configuration parameters: EnforcedStyle, SupportedStyles. Style/RaiseArgs: diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index e7d3a79f..8ebe422b 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::ExceptionHandler do - let(:app) { Proc.new { |env| env } } + let(:app) { proc { |env| env } } let(:env) { Protobuf::Rpc::Env.new } subject { described_class.new(app) } diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index e3621a76..db42a8f0 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::Logger do - let(:app) { Proc.new { |inner_env| inner_env } } + let(:app) { proc { |inner_env| inner_env } } let(:env) do Protobuf::Rpc::Env.new( 'client_host' => 'client_host.test.co', diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index f7f4a485..1fd5fb4e 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::RequestDecoder do - let(:app) { Proc.new { |env| env } } + let(:app) { proc { |env| env } } let(:client_host) { 'client_host.test.co' } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index f9d47ebe..83694083 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::ResponseEncoder do - let(:app) { Proc.new { |env| env.response = response; env } } + let(:app) { proc { |env| env.response = response; env } } let(:env) do Protobuf::Rpc::Env.new( 'response_type' => Test::Resource, From c7a06bc8e59ce64dc7087690e0584520b73b7c33 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:07:46 -0700 Subject: [PATCH 0804/1191] Style/RedundantReturn --- .rubocop_todo.yml | 6 ------ lib/protobuf/code_generator.rb | 2 +- lib/protobuf/decoder.rb | 2 +- lib/protobuf/generators/enum_generator.rb | 2 +- lib/protobuf/generators/service_generator.rb | 2 +- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/message.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 14 +++++++------- spec/lib/protobuf/rpc/service_filters_spec.rb | 10 +++++----- spec/support/server.rb | 2 +- 11 files changed, 20 insertions(+), 26 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 48fdf8cf..6b2367a1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -95,12 +95,6 @@ Style/PredicateName: Style/RaiseArgs: Enabled: false -# Offense count: 20 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Enabled: false - # Offense count: 26 # Cop supports --auto-correct. Style/RedundantSelf: diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index e44fe2ac..7aa96272 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -33,7 +33,7 @@ def response_bytes generate_file(file_descriptor) end - return ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files) + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files) end end diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 67e5f8ec..ddcc4ac3 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -31,7 +31,7 @@ def self.read_field(stream) raise InvalidWireType, wire_type end - return tag, bytes + [tag, bytes] end # Read 32-bit string value from +stream+. diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 57b7416b..c45c6985 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -33,7 +33,7 @@ def compile def build_value(enum_value_descriptor) name = enum_value_descriptor.name number = enum_value_descriptor.number - return "define :#{name}, #{number}" + "define :#{name}, #{number}" end end diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb index bc2f5d8d..801dd0bb 100644 --- a/lib/protobuf/generators/service_generator.rb +++ b/lib/protobuf/generators/service_generator.rb @@ -18,7 +18,7 @@ def build_method(method_descriptor) name = method_descriptor.name request_klass = modulize(method_descriptor.input_type) response_klass = modulize(method_descriptor.output_type) - return "rpc :#{name.underscore}, #{request_klass}, #{response_klass}" + "rpc :#{name.underscore}, #{request_klass}, #{response_klass}" end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index bc035145..60c2bd95 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -32,7 +32,7 @@ def self.trigger(event_name, *args) end def self.normalized_event_name(event_name) - return "#{event_name}".downcase + "#{event_name}".downcase end class << self diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 62741a39..622e2942 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -108,7 +108,7 @@ def to_hash result.merge!(field_name => hashed_value) end - return result + result end def to_json(options = {}) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 552610d2..5e69336a 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -8,7 +8,7 @@ module Common attr_reader :error def any_callbacks? - return [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| + [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| reduction || !cb.nil? end end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index f7de8ad9..45dc6923 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -94,7 +94,7 @@ def filters # if the filter should not be invoked, true if invocation should occur. # def invoke_filter?(rpc_method, filter) - return invoke_via_only?(rpc_method, filter) \ + invoke_via_only?(rpc_method, filter) \ && invoke_via_except?(rpc_method, filter) \ && invoke_via_if?(rpc_method, filter) \ && invoke_via_unless?(rpc_method, filter) @@ -109,7 +109,7 @@ def invoke_filter?(rpc_method, filter) # def invoke_via_except?(rpc_method, filter) except = [ filter.fetch(:except) { [] } ].flatten - return except.empty? || ! except.include?(rpc_method) + except.empty? || ! except.include?(rpc_method) end # Invoke the given :if callable (if any) and return its return value. @@ -128,7 +128,7 @@ def invoke_via_if?(_rpc_method, filter) call_or_send(if_check) end - return do_invoke + do_invoke end # If the target rpc endpoint method is listed in the :only option, @@ -139,7 +139,7 @@ def invoke_via_if?(_rpc_method, filter) # def invoke_via_only?(rpc_method, filter) only = [ filter.fetch(:only) { [] } ].flatten - return only.empty? || only.include?(rpc_method) + only.empty? || only.include?(rpc_method) end # Invoke the given :unless callable (if any) and return the opposite @@ -158,7 +158,7 @@ def invoke_via_unless?(_rpc_method, filter) call_or_send(unless_check) end - return ! skip_invoke + ! skip_invoke end def rescue_filters @@ -176,7 +176,7 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = end end - return true + true end # Reverse build a chain of around filters. To implement an around chain, @@ -262,7 +262,7 @@ def call_or_send(callable, *args, &block) raise "Object #{callable} is not callable" end - return return_value + return_value end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 0040e356..0542ef8c 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -132,8 +132,8 @@ def endpoint_without_verify class FilterTest private - def check_true; return true; end - def check_false; return false; end + def check_true; true; end + def check_false; false; end def verify_before; @called << :verify_before; end end end @@ -192,8 +192,8 @@ def verify_before; @called << :verify_before; end class FilterTest private - def check_true; return true; end - def check_false; return false; end + def check_true; true; end + def check_false; false; end def verify_before; @called << :verify_before; end end end @@ -254,7 +254,7 @@ class FilterTest def short_circuit_filter @called << :short_circuit_filter - return false + false end end end diff --git a/spec/support/server.rb b/spec/support/server.rb index d572b1db..dd0817a9 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -24,7 +24,7 @@ def post_init end new_server.sleep_interval = delay - return new_server + new_server end end From 8275f87f509126d4a82e62ca3ceebc824d2e6414 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:08:19 -0700 Subject: [PATCH 0805/1191] Style/RedundantSelf --- .rubocop_todo.yml | 5 ----- lib/protobuf/deprecator.rb | 4 ++-- lib/protobuf/enum.rb | 24 ++++++++++++------------ lib/protobuf/field/field_array.rb | 2 +- lib/protobuf/logging.rb | 2 +- lib/protobuf/message/serialization.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++--- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 6 +++--- 10 files changed, 26 insertions(+), 31 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6b2367a1..1ef443da 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -95,11 +95,6 @@ Style/PredicateName: Style/RaiseArgs: Enabled: false -# Offense count: 26 -# Cop supports --auto-correct. -Style/RedundantSelf: - Enabled: false - # Offense count: 2 Style/RescueModifier: Enabled: false diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index f7d5df84..856f8480 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -2,8 +2,8 @@ module Protobuf module Deprecator def warn_deprecated(old_method, new_method) - $stderr.puts %([DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. - Please use #{self.name}.#{new_method} instead.\n) + $stderr.puts %([DEPRECATED] #{name}.#{old_method} is deprecated and will disappear in a future version. + Please use #{name}.#{new_method} instead.\n) end # Given deprecations should be a hash whose keys are the new methods diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index e6bfd422..f85665f8 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -32,7 +32,7 @@ class Enum < SimpleDelegator include ::Protobuf::Optionable def self.aliases_allowed? - self.get_option(:allow_alias) + get_option(:allow_alias) end # Public: Get all integer tags defined by this enum. @@ -51,7 +51,7 @@ def self.aliases_allowed? # Returns an array of unique integers. # def self.all_tags - @all_tags ||= self.enums.map(&:to_i).uniq + @all_tags ||= enums.map(&:to_i).uniq end # Internal: DSL method to create a new Enum. The given name will @@ -70,7 +70,7 @@ def self.all_tags # Returns nothing. # def self.define(name, tag) - enum = self.new(self, name, tag) + enum = new(self, name, tag) @enums ||= [] @enums << enum const_set(name, enum) @@ -101,7 +101,7 @@ class << self # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - self.enums.select do |enum| + enums.select do |enum| enum.to_i == tag.to_i end end @@ -125,7 +125,7 @@ def self.enums_for_tag(tag) # Returns the Enum object with the given name or nil. # def self.enum_for_name(name) - self.const_get(name) + const_get(name) rescue ::NameError nil end @@ -138,7 +138,7 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - self.enums_for_tag(tag).first + enums_for_tag(tag).first end # Public: Get an Enum by a variety of type-checking mechanisms. @@ -206,7 +206,7 @@ def self.fetch(candidate) # the first defined name will be returned. # def self.name_for_tag(tag) - self.enum_for_tag(tag).try(:name) + enum_for_tag(tag).try(:name) end # Public: Check if the given tag is defined by this Enum. @@ -216,17 +216,17 @@ def self.name_for_tag(tag) # Returns a boolean. # def self.valid_tag?(tag) - tag.respond_to?(:to_i) && self.all_tags.include?(tag.to_i) + tag.respond_to?(:to_i) && all_tags.include?(tag.to_i) end # Public: [DEPRECATED] Return a hash of Enum objects keyed # by their :name. # def self.values - self.warn_deprecated(:values, :enums) + warn_deprecated(:values, :enums) @values ||= begin - self.enums.each_with_object({}) do |enum, hash| + enums.each_with_object({}) do |enum, hash| hash[enum.name] = enum end end @@ -279,11 +279,11 @@ def to_int def to_s(format = :tag) case format when :tag then - self.to_i.to_s + to_i.to_s when :name then name.to_s else - self.to_i.to_s + to_i.to_s end end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index cf46323f..14eacd34 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -41,7 +41,7 @@ def replace(val) # Return a hash-representation of the given values for this field type. # The value in this case would be an array. def to_hash_value - self.map do |value| + map do |value| value.respond_to?(:to_hash_value) ? value.to_hash_value : value end end diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 904d77d5..f75e79e5 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -29,7 +29,7 @@ def log_exception(ex) end def log_signature - @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]" + @_log_signature ||= "[#{self.class == Class ? name : self.class.name}]" end def sign_message(message) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 05e3c1b8..22457b96 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -8,12 +8,12 @@ module Serialization module ClassMethods def decode(bytes) - self.new.decode(bytes) + new.decode(bytes) end # Create a new object with the given values and return the encoded bytes. def encode(fields = {}) - self.new(fields).encode + new(fields).encode end end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 5e69336a..0bcb310d 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -162,7 +162,7 @@ def validate_request_type! def verify_callbacks unless any_callbacks? logger.debug { sign_message("No callbacks set, using data_callback") } - @success_cb = @failure_cb = self.method(:data_callback) + @success_cb = @failure_cb = method(:data_callback) end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c548722c..57945758 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -79,7 +79,7 @@ def broadcast_beacons? def broadcast_flatline flatline = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE, - :server => self.to_proto + :server => to_proto ) @beacon_socket.send(flatline.encode, 0) @@ -90,7 +90,7 @@ def broadcast_heartbeat heartbeat = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT, - :server => self.to_proto + :server => to_proto ) @beacon_socket.send(heartbeat.encode, 0) @@ -124,7 +124,7 @@ def frontend_uri end def inproc? - !!self.options[:zmq_inproc] + !!options[:zmq_inproc] end def maintenance_timeout diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 54d6f8a6..dea0eda2 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -66,7 +66,7 @@ class << self # An array of defined service classes that contain implementation # code def self.implemented_services - classes = (self.subclasses || []).select do |subclass| + classes = (subclasses || []).select do |subclass| subclass.rpcs.any? do |(name, _)| subclass.method_defined? name end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index d293f4a3..6aec7b4d 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -66,11 +66,11 @@ def self.port def self.start yield(self) if block_given? - self.instance.start + instance.start end def self.stop - self.instance.stop + instance.stop end # @@ -113,7 +113,7 @@ def start unless running? init_socket logger.info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } - @thread = Thread.new { self.send(:run) } + @thread = Thread.new { send(:run) } end self From 797e86328bc8d4c69126d5a8145d421f7cc405bb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:09:51 -0700 Subject: [PATCH 0806/1191] Style/SelfAssignment --- .rubocop_todo.yml | 4 ---- lib/protobuf/logging.rb | 2 -- 2 files changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1ef443da..ac728d5a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,10 +99,6 @@ Style/RaiseArgs: Style/RescueModifier: Enabled: false -# Offense count: 1 -Style/SelfAssignment: - Enabled: false - # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: AllowAsExpressionSeparator. diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index f75e79e5..59fc9997 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -3,8 +3,6 @@ module Protobuf module Logging def self.initialize_logger(log_target = $stdout, log_level = ::Logger::INFO) - @counter ||= 0 - @counter = @counter + 1 @logger = Logger.new(log_target) @logger.level = log_level @logger From 2d7fa3b94f9d9eb329f1bb7f8ef7a4ad26f2c9f6 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:10:39 -0700 Subject: [PATCH 0807/1191] Style/SpaceAfterColon --- .rubocop_todo.yml | 5 ----- spec/encoding/all_types_spec.rb | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ac728d5a..71c909f1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -117,11 +117,6 @@ Style/SignalException: Style/SingleLineMethods: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/SpaceAfterColon: - Enabled: false - # Offense count: 9 # Cop supports --auto-correct. Style/SpaceAfterComma: diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index c202215a..411a7a55 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -57,8 +57,8 @@ ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ], repeated_string_piece: ["224", "324"], repeated_cord: ["225", "325"], - repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:227), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:327)], + repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 227), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 327)], default_int32: 401, default_int64: 402, default_uint32: 403, From 0cdef2fd4c9a0992da067e8babac5c8873323722 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:13:19 -0700 Subject: [PATCH 0808/1191] Style/Semicolon --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 54aee5d2..77a6182c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,6 +20,9 @@ Style/EmptyLines: Style/IndentHash: EnforcedStyle: consistent +Style/Semicolon: + AllowAsExpressionSeparator: true + Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 71c909f1..428750a0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,12 +99,6 @@ Style/RaiseArgs: Style/RescueModifier: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Enabled: false - # Offense count: 67 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. From 96e0298c9205e7a6b7458864e0e788276631b2be Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:14:06 -0700 Subject: [PATCH 0809/1191] Style/SingleLineMethods --- .rubocop_todo.yml | 6 ---- spec/lib/protobuf/rpc/service_filters_spec.rb | 28 +++++++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 428750a0..ac9d7ada 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -105,12 +105,6 @@ Style/RescueModifier: Style/SignalException: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: AllowIfMethodIsEmpty. -Style/SingleLineMethods: - Enabled: false - # Offense count: 9 # Cop supports --auto-correct. Style/SpaceAfterComma: diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 0542ef8c..27f5d356 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -132,9 +132,17 @@ def endpoint_without_verify class FilterTest private - def check_true; true; end - def check_false; false; end - def verify_before; @called << :verify_before; end + def check_true + true + end + + def check_false + false + end + + def verify_before + @called << :verify_before + end end end @@ -192,9 +200,17 @@ def verify_before; @called << :verify_before; end class FilterTest private - def check_true; true; end - def check_false; false; end - def verify_before; @called << :verify_before; end + def check_true + true + end + + def check_false + false + end + + def verify_before + @called << :verify_before + end end end From f85b7fb4b35b8828f23988449cd810ed92133877 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:15:17 -0700 Subject: [PATCH 0810/1191] Style/SpaceAfterComma --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- spec/lib/protobuf/generators/base_spec.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ac9d7ada..9a4095b2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -105,11 +105,6 @@ Style/RescueModifier: Style/SignalException: Enabled: false -# Offense count: 9 -# Cop supports --auto-correct. -Style/SpaceAfterComma: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. Style/SpaceAfterNot: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a6310a02..1eaf9037 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -159,7 +159,7 @@ def host_alive_check_interval def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) - socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1,0].pack('ii')) + socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1, 0].pack('ii')) true rescue diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 45dc6923..c042b58f 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -24,7 +24,7 @@ module ClassMethods # whose values are Sets. # def filters - @filters ||= Hash.new { |h,k| h[k] = [] } + @filters ||= Hash.new { |h, k| h[k] = [] } end # Filters hash keyed based on filter type (e.g. :before, :after, :around), @@ -50,7 +50,7 @@ def define_filter(type, filter, options = {}) end def defined_filters - @defined_filters ||= Hash.new { |h,k| h[k] = Set.new } + @defined_filters ||= Hash.new { |h, k| h[k] = Set.new } end # Check to see if the filter has been defined. diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 6feab2b1..0162b1b2 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -68,14 +68,14 @@ def compile context 'when tags are duplicated' do it 'fails with a GeneratorFatalError' do expect(::Protobuf::CodeGenerator).to receive(:fatal).with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/) - described_class.validate_tags("FooBar", [1,2,2,3]) + described_class.validate_tags("FooBar", [1, 2, 2, 3]) end end context 'when tags are missing in the range' do it 'prints a warning' do expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) - described_class.validate_tags("FooBar", [1,2,4,5]) + described_class.validate_tags("FooBar", [1, 2, 4, 5]) end end end From b8fc83bede97a3b7b78d59551ea46ff9677b8181 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:15:43 -0700 Subject: [PATCH 0811/1191] Style/SpaceAfterNot --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/enum_field.rb | 2 +- lib/protobuf/generators/message_generator.rb | 2 +- lib/protobuf/message/fields.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- lib/protobuf/rpc/stat.rb | 2 +- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9a4095b2..e15afba1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -105,11 +105,6 @@ Style/RescueModifier: Style/SignalException: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -Style/SpaceAfterNot: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 4b362248..23b593e0 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -17,7 +17,7 @@ def self.default # def acceptable?(val) - ! type_class.fetch(val).nil? + !type_class.fetch(val).nil? end def encode(value) diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index 81505f71..cdfecf7d 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -62,7 +62,7 @@ def compile_message private def has_extensions? - ! message_extension_fields.empty? + !message_extension_fields.empty? end def has_fields? diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 7e92f606..9d28d4fe 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -82,7 +82,7 @@ def get_field(name_or_tag, allow_extension = false) name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) field = field_store[name_or_tag] - if field && (allow_extension || ! field.extension?) + if field && (allow_extension || !field.extension?) field else nil diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index c042b58f..add710e9 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -109,7 +109,7 @@ def invoke_filter?(rpc_method, filter) # def invoke_via_except?(rpc_method, filter) except = [ filter.fetch(:except) { [] } ].flatten - except.empty? || ! except.include?(rpc_method) + except.empty? || !except.include?(rpc_method) end # Invoke the given :if callable (if any) and return its return value. @@ -158,7 +158,7 @@ def invoke_via_unless?(_rpc_method, filter) call_or_send(unless_check) end - ! skip_invoke + !skip_invoke end def rescue_filters diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 7f6d063b..2fe80205 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -61,7 +61,7 @@ def stop end def stopped? - ! end_time.nil? + !end_time.nil? end def rpc From 344d54c3bdd26975ce6269cb673595f24d0a25a0 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:16:54 -0700 Subject: [PATCH 0812/1191] Style/TrailingComma --- .rubocop_todo.yml | 6 ------ Rakefile | 2 +- lib/protobuf/field.rb | 2 +- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++--- lib/protobuf/rpc/stat.rb | 2 +- spec/encoding/extreme_values_spec.rb | Bin 1357 -> 1358 bytes spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/code_generator_spec.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 8 ++++---- .../generators/enum_generator_spec.rb | 4 ++-- .../generators/extension_generator_spec.rb | 2 +- .../generators/field_generator_spec.rb | 2 +- .../generators/file_generator_spec.rb | 4 ++-- .../generators/service_generator_spec.rb | 4 ++-- spec/lib/protobuf/message_spec.rb | 4 ++-- .../protobuf/rpc/connectors/common_spec.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- .../protobuf/rpc/middleware/logger_spec.rb | 2 +- .../rpc/middleware/request_decoder_spec.rb | 8 ++++---- .../rpc/middleware/response_encoder_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/server_spec.rb | 2 +- .../protobuf/rpc/service_directory_spec.rb | 12 ++++++------ spec/lib/protobuf/rpc/service_filters_spec.rb | 4 ++-- spec/lib/protobuf/rpc/service_spec.rb | 6 +++--- 27 files changed, 46 insertions(+), 52 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e15afba1..988e786b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -116,12 +116,6 @@ Style/SpaceInsideBrackets: Style/StringLiterals: Enabled: false -# Offense count: 47 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. -Style/TrailingComma: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/Rakefile b/Rakefile index 57f3e75c..8df9895f 100644 --- a/Rakefile +++ b/Rakefile @@ -44,7 +44,7 @@ namespace :compile do 'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc', 'tmp/rpc/rpc.pb.rb' => 'lib/protobuf/rpc', 'tmp/rpc/google/protobuf/descriptor.pb.rb' => 'lib/protobuf/descriptors/google/protobuf', - 'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler' + 'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler', } files.each_pair do |source_file, destination_dir| diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index bbcd8c73..abe30a54 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -38,7 +38,7 @@ module Field :sfixed64 => ::Protobuf::Field::Sfixed64Field, :string => ::Protobuf::Field::StringField, :bytes => ::Protobuf::Field::BytesField, - :bool => ::Protobuf::Field::BoolField + :bool => ::Protobuf::Field::BoolField, }.freeze def self.build(message_class, rule, type, name, tag, options = {}) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 4c69025e..f6a0fc8e 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -14,7 +14,7 @@ class BaseField PACKED_TYPES = [ ::Protobuf::WireType::VARINT, ::Protobuf::WireType::FIXED32, - ::Protobuf::WireType::FIXED64 + ::Protobuf::WireType::FIXED64, ].freeze ## diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 1eaf9037..15fe47b0 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -147,7 +147,7 @@ def host_alive?(host) ping_port_open = ping_port_open?(host) self.class.ping_port_responses[host] = { :at => Time.now.to_i, - :ping_port_open => ping_port_open + :ping_port_open => ping_port_open, } ping_port_open end diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index 08a2c801..a5d30e36 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -63,7 +63,7 @@ def to_s(env) rpc, sizes, elapsed_time, - @end_time.try(:iso8601) + @end_time.try(:iso8601), ].compact.join(' - ') end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 57945758..87f663cb 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -79,7 +79,7 @@ def broadcast_beacons? def broadcast_flatline flatline = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE, - :server => to_proto + :server => to_proto, ) @beacon_socket.send(flatline.encode, 0) @@ -90,7 +90,7 @@ def broadcast_heartbeat heartbeat = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT, - :server => to_proto + :server => to_proto, ) @beacon_socket.send(heartbeat.encode, 0) @@ -234,7 +234,7 @@ def to_proto :address => frontend_ip, :port => frontend_port.to_s, :ttl => (beacon_interval * 1.5).ceil, - :services => ::Protobuf::Rpc::Service.implemented_services + :services => ::Protobuf::Rpc::Service.implemented_services, ) end diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 2fe80205..a4c7e8d1 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -84,7 +84,7 @@ def to_s rpc, sizes, elapsed_time, - @end_time.try(:iso8601) + @end_time.try(:iso8601), ].compact.join(' - ') end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 65f1c910a25e433add419fb72f73bcd988187706..39aa70d11d5507e16d460101de0cd74c967d8655 100644 GIT binary patch delta 13 UcmX@hb&hL8Gz+87 9408, :backlog => 100, :threshold => 100, - :threads => 5 + :threads => 5, ) @server_thread = Thread.new(@runner) { |runner| runner.run } Thread.pass until @runner.running? diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 5cc77e38..956d05ae 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -44,7 +44,7 @@ described_class.fatal("something is wrong") end.to raise_error( ::Protobuf::CodeGenerator::CodeGeneratorFatalError, - "something is wrong" + "something is wrong", ) end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 645bf424..55a73602 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -54,7 +54,7 @@ Test::EnumTestType::ONE, Test::EnumTestType::TWO, Test::EnumTestType::MINUS_ONE, - Test::EnumTestType::THREE + Test::EnumTestType::THREE, ]) end @@ -63,7 +63,7 @@ expect(EnumAliasTest.enums).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR, - EnumAliasTest::BAZ + EnumAliasTest::BAZ, ]) end end @@ -178,7 +178,7 @@ :MINUS_ONE => Test::EnumTestType::MINUS_ONE, :ONE => Test::EnumTestType::ONE, :TWO => Test::EnumTestType::TWO, - :THREE => Test::EnumTestType::THREE + :THREE => Test::EnumTestType::THREE, ) end @@ -186,7 +186,7 @@ expect(EnumAliasTest.values).to eq( :FOO => EnumAliasTest::FOO, :BAR => EnumAliasTest::BAR, - :BAZ => EnumAliasTest::BAZ + :BAZ => EnumAliasTest::BAZ, ) end end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 6c3d8476..086cb4a2 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -8,7 +8,7 @@ [ { :name => 'FOO', :number => 1 }, { :name => 'BAR', :number => 2 }, - { :name => 'BAZ', :number => 3 } + { :name => 'BAZ', :number => 3 }, ] end let(:options) { nil } @@ -16,7 +16,7 @@ { :name => 'TestEnum', :value => values, - :options => options + :options => options, } end diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 559f21b8..b3f68c8d 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -9,7 +9,7 @@ [ double('field descriptor 1', :to_s => " field 1\n"), double('field descriptor 2', :to_s => " field 2\n"), - double('field descriptor 3', :to_s => " field 3\n") + double('field descriptor 3', :to_s => " field 3\n"), ] end let(:message_type) { 'FooBar' } diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 0e72dde5..7ba88536 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -22,7 +22,7 @@ :type_name => type_name, :default_value => default_value, :extendee => extendee, - :options => field_options + :options => field_options, } end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index bfb699d6..6560cf8d 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -16,8 +16,8 @@ base_descriptor_fields.merge( :dependency => [ 'test/bar.proto', - 'test/baz.proto' - ] + 'test/baz.proto', + ], ) end diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 0748ced2..03622318 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -7,13 +7,13 @@ let(:methods) do [ { :name => 'Search', :input_type => 'FooRequest', :output_type => 'FooResponse' }, - { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' } + { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' }, ] end let(:service_fields) do { :name => 'TestService', - :method => methods + :method => methods, } end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index d2e06024..56012dd6 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -386,14 +386,14 @@ it 'recursively hashes a repeated set of messages' do proto = Test::Nested.new(:multiple_resources => [ Test::Resource.new(:name => 'Resource 1'), - Test::Resource.new(:name => 'Resource 2') + Test::Resource.new(:name => 'Resource 2'), ]) expect(proto.to_hash).to eq( :multiple_resources => [ { :name => 'Resource 1' }, { :name => 'Resource 2' }, - ] + ], ) end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 029c9b46..69205eb1 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -79,7 +79,7 @@ :service => service, :method => method, :request => request, - :client_host => client_host + :client_host => client_host, } end @@ -88,7 +88,7 @@ :service_name => service.name, :method_name => 'find', :request_proto => '', - :caller => client_host + :caller => client_host, ) end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 45142662..53a918b0 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -10,7 +10,7 @@ :method => "find", :timeout => 3, :host => "127.0.0.1", - :port => "9400" + :port => "9400", } end diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index db42a8f0..8ae5959d 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -24,7 +24,7 @@ Protobuf::Socketrpc::Request.new( :service_name => service_name, :method_name => method_name.to_s, - :request_proto => request + :request_proto => request, ) end let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 1fd5fb4e..f95a05ab 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -6,7 +6,7 @@ let(:env) do Protobuf::Rpc::Env.new( 'encoded_request' => encoded_request, - 'log_signature' => 'log_signature' + 'log_signature' => 'log_signature', ) end let(:encoded_request) { request_wrapper.encode } @@ -18,7 +18,7 @@ :caller => client_host, :service_name => service_name, :method_name => method_name.to_s, - :request_proto => request + :request_proto => request, ) end let(:response_type) { rpc_method.response_type } @@ -88,7 +88,7 @@ :caller => client_host, :service_name => 'Foo', :method_name => method_name.to_s, - :request_proto => request + :request_proto => request, ) end @@ -103,7 +103,7 @@ :caller => client_host, :service_name => service_name, :method_name => 'foo', - :request_proto => request + :request_proto => request, ) end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 83694083..00ab46cd 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -5,7 +5,7 @@ let(:env) do Protobuf::Rpc::Env.new( 'response_type' => Test::Resource, - 'log_signature' => 'log_signature' + 'log_signature' => 'log_signature', ) end let(:encoded_response) { response_wrapper.encode } diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index e8f0eacf..215230ba 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -9,7 +9,7 @@ :host => '127.0.0.1', :port => 9399, :worker_port => 9400, - :workers_only => true + :workers_only => true, } end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 32cb3b4f..6f39ae20 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -11,7 +11,7 @@ :address => '127.0.0.1', :port => '1111', :ttl => 10, - :services => %w(EchoService) + :services => %w(EchoService), ) end @@ -21,7 +21,7 @@ :address => '127.0.0.1', :port => "1112", :ttl => 10, - :services => %w(HelloService) + :services => %w(HelloService), ) end @@ -31,7 +31,7 @@ :address => '127.0.0.1', :port => '1113', :ttl => 1, - :services => %w(HelloService) + :services => %w(HelloService), ) end @@ -41,7 +41,7 @@ :address => '127.0.0.1', :port => '1114', :ttl => 10, - :services => %w(HelloService EchoService) + :services => %w(HelloService EchoService), ) end @@ -65,7 +65,7 @@ def send_beacon(type, server) type = type.to_s.upcase beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :server => server, - :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType.fetch(type) + :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType.fetch(type), ) @socket.send(beacon.encode, 0, @address, @port) @@ -266,7 +266,7 @@ def send_beacon(type, server) :address => '127.0.0.1', :port => (5555 + x).to_s, :ttl => rand(1..5), - :services => 10.times.map { |y| "PerformanceService#{y}" } + :services => 10.times.map { |y| "PerformanceService#{y}" }, ) end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 27f5d356..0694533d 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -362,7 +362,7 @@ def inner_around :endpoint, :inner_around_bottom, :outer_around_bottom, - ] + ], ) end @@ -390,7 +390,7 @@ def inner_around :outer_around_top, :inner_around, :outer_around_bottom, - ] + ], ) end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 2d01202e..27518464 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -67,7 +67,7 @@ .with(hash_including( :service => subject, :host => subject.host, - :port => subject.port + :port => subject.port, )).and_return(client) expect(subject.client).to eq client end @@ -129,7 +129,7 @@ def find_with_rpc_failed let(:env) do Protobuf::Rpc::Env.new( 'request' => request, - 'response_type' => response_type + 'response_type' => response_type, ) end let(:response_type) { service.rpcs[:find_with_implied_response].response_type } @@ -146,7 +146,7 @@ def find_with_rpc_failed let(:env) do Protobuf::Rpc::Env.new( 'method_name' => :find_with_respond_with, - 'request' => request + 'request' => request, ) end From 58ca57e2aac6d5f9860e64534d5ef2d23c934ed2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:17:35 -0700 Subject: [PATCH 0813/1191] Style/SignalException --- .rubocop_todo.yml | 6 ------ lib/protobuf.rb | 2 +- lib/protobuf/code_generator.rb | 2 +- lib/protobuf/decoder.rb | 6 +++--- lib/protobuf/encoder.rb | 2 +- lib/protobuf/field.rb | 2 +- lib/protobuf/field/base_field.rb | 10 +++++----- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/field/enum_field.rb | 4 ++-- lib/protobuf/field/field_array.rb | 4 ++-- lib/protobuf/field/message_field.rb | 4 ++-- lib/protobuf/generators/printable.rb | 2 +- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/message.rb | 4 ++-- lib/protobuf/message/fields.rb | 4 ++-- lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/client.rb | 8 ++++---- lib/protobuf/rpc/connectors/base.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 20 +++++++++---------- lib/protobuf/rpc/connectors/zmq.rb | 12 +++++------ .../rpc/middleware/request_decoder.rb | 2 +- .../rpc/middleware/response_encoder.rb | 2 +- lib/protobuf/rpc/servers/socket/server.rb | 2 +- lib/protobuf/rpc/servers/socket/worker.rb | 2 +- lib/protobuf/rpc/servers/socket_runner.rb | 2 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_dispatcher.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- spec/functional/socket_server_spec.rb | 6 +++--- spec/functional/zmq_server_spec.rb | 10 +++++----- spec/lib/protobuf/rpc/connectors/base_spec.rb | 4 ++-- .../protobuf/rpc/connectors/common_spec.rb | 8 ++++---- spec/lib/protobuf/rpc/service_filters_spec.rb | 8 ++++---- 35 files changed, 76 insertions(+), 82 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 988e786b..cd9d0cb8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,12 +99,6 @@ Style/RaiseArgs: Style/RescueModifier: Enabled: false -# Offense count: 67 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SignalException: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf.rb b/lib/protobuf.rb index fb3129ec..ca3c311c 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -41,7 +41,7 @@ def self.connector_type end def self.connector_type=(type) - raise ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) + fail ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) @connector_type = type end diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 7aa96272..cf39b0df 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -6,7 +6,7 @@ class CodeGenerator CodeGeneratorFatalError = Class.new(RuntimeError) def self.fatal(message) - raise CodeGeneratorFatalError, message + fail CodeGeneratorFatalError, message end def self.print_tag_warning_suppress diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index ddcc4ac3..601e06f5 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -24,11 +24,11 @@ def self.read_field(stream) when ::Protobuf::WireType::FIXED32 then read_fixed32(stream) when ::Protobuf::WireType::START_GROUP then - raise NotImplementedError, 'Group is deprecated.' + fail NotImplementedError, 'Group is deprecated.' when ::Protobuf::WireType::END_GROUP then - raise NotImplementedError, 'Group is deprecated.' + fail NotImplementedError, 'Group is deprecated.' else - raise InvalidWireType, wire_type + fail InvalidWireType, wire_type end [tag, bytes] diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 1eec5cf7..4c19ab08 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -9,7 +9,7 @@ def self.encode(stream, message) def initialize(message, stream) unless message.respond_to?(:each_field_for_serialization) - raise ArgumentError, "Message instance must respond to :each_field_for_serialization" + fail ArgumentError, "Message instance must respond to :each_field_for_serialization" end @message = message diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index abe30a54..02cc14f4 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -59,7 +59,7 @@ def self.field_class(type) elsif type < ::Protobuf::Field::BaseField type else - raise ArgumentError, "Invalid field type #{type}" + fail ArgumentError, "Invalid field type #{type}" end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index f6a0fc8e..8b722e8a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -60,7 +60,7 @@ def coerce!(value) end def decode(_bytes) - raise NotImplementedError, "#{self.class.name}##{__method__}" + fail NotImplementedError, "#{self.class.name}##{__method__}" end def default @@ -80,7 +80,7 @@ def deprecated? end def encode(_value) - raise NotImplementedError, "#{self.class.name}##{__method__}" + fail NotImplementedError, "#{self.class.name}##{__method__}" end def extension? @@ -204,7 +204,7 @@ def define_array_setter val = val.dup val.compact! else - raise TypeError, <<-TYPE_ERROR + fail TypeError, <<-TYPE_ERROR Expected repeated value of type '#{field.type_class}' Got '#{val.class}' for repeated protobuf field #{field.name} TYPE_ERROR @@ -241,7 +241,7 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = field.coerce!(val) else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" + fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end end @@ -257,7 +257,7 @@ def typed_default_value def validate_packed_field if packed? && ! ::Protobuf::Field::BaseField::PACKED_TYPES.include?(wire_type) - raise "Can't use packed encoding for '#{type_class}' type" + fail "Can't use packed encoding for '#{type_class}' type" end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index c095629f..733e391e 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -64,7 +64,7 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = val.dup else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" + fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end rescue NoMethodError => ex logger.error { ex.message } diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 23b593e0..4f31316f 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -9,7 +9,7 @@ class EnumField < VarintField # def self.default - raise NoMethodError, "#{self}.#{__method__} must be called on an instance" + fail NoMethodError, "#{self}.#{__method__} must be called on an instance" end ## @@ -49,7 +49,7 @@ def define_setter @values.delete(field.name) else value = field.type_class.fetch(value) - raise TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value + fail TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value @values[field.name] = value end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 14eacd34..65447a31 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -62,7 +62,7 @@ def unshift(val) def normalize(value) value = value.to_proto if value.respond_to?(:to_proto) - raise TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) + fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) if field.is_a?(::Protobuf::Field::EnumField) field.type_class.fetch(value) @@ -74,7 +74,7 @@ def normalize(value) end def raise_type_error(val) - raise TypeError, <<-TYPE_ERROR + fail TypeError, <<-TYPE_ERROR Expected repeated value of type '#{field.type_class}' Got '#{val.class}' for repeated protobuf field #{field.name} TYPE_ERROR diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 5161edbe..45dec389 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -10,7 +10,7 @@ class MessageField < BaseField def acceptable?(val) unless val.instance_of?(type_class) || val.respond_to?(:to_hash) - raise TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end true @@ -54,7 +54,7 @@ def define_setter when val.respond_to?(:to_hash) then @values[field.name] = field.type_class.new(val.to_hash) else - raise TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" + fail TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" end end end diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 268ce42f..6347afe2 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -84,7 +84,7 @@ def parent_class(type) when :service then PARENT_CLASS_SERVICE else - raise "Unknown parent class type #{type}: #{caller[0..5].join("\n")}" + fail "Unknown parent class type #{type}: #{caller[0..5].join("\n")}" end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 60c2bd95..fd688820 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -3,7 +3,7 @@ class Lifecycle include ::Protobuf::Logging def self.register(event_name, &blk) - raise "Lifecycle register must have a block" unless block_given? + fail "Lifecycle register must have a block" unless block_given? event_name = normalized_event_name(event_name) if ::Protobuf.print_deprecation_warnings? diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 622e2942..c5b901ed 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -74,7 +74,7 @@ def each_field_for_serialization value = @values[field.getter] if value.nil? - raise ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." else yield(field, value) end @@ -138,7 +138,7 @@ def []=(name, value) __send__(field.setter, value) unless value.nil? else unless ::Protobuf.ignore_unknown_fields? - raise ::Protobuf::FieldNotDefinedError, name + fail ::Protobuf::FieldNotDefinedError, name end end end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 9d28d4fe..234c0dfa 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -106,13 +106,13 @@ def define_field(rule, type_class, field_name, tag, options) def raise_if_tag_collision(tag, field_name) if get_field(tag, true) - raise TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) + fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) end end def raise_if_name_collision(field_name) if get_field(field_name, true) - raise DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) + fail DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) end end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 97587a00..dc63dbd6 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -28,7 +28,7 @@ def write(force_mode = true) if force_mode && reading? self.mode = :write elsif !force_mode && reading? - raise 'You chose to write the buffer when in read mode' + fail 'You chose to write the buffer when in read mode' end @size = @data.length diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index e810530a..618aa503 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -27,7 +27,7 @@ class Client # }) # def initialize(options = {}) - raise "Invalid client configuration. Service must be defined." if options[:service].nil? + fail "Invalid client configuration. Service must be defined." if options[:service].nil? @connector = Connector.connector_for_client.new(options) logger.debug { sign_message("Initialized with options: #{options.inspect}") } end @@ -47,7 +47,7 @@ def on_complete(&complete_cb) def on_complete=(callable) if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 - raise "callable must take a single argument and respond to :call" + fail "callable must take a single argument and respond to :call" end @connector.complete_cb = callable @@ -66,7 +66,7 @@ def on_failure(&failure_cb) def on_failure=(callable) if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 - raise "Callable must take a single argument and respond to :call" + fail "Callable must take a single argument and respond to :call" end @connector.failure_cb = callable @@ -85,7 +85,7 @@ def on_success(&success_cb) def on_success=(callable) if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 - raise "Callable must take a single argument and respond to :call" + fail "Callable must take a single argument and respond to :call" end @connector.success_cb = callable diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 81326cd1..8f6d43c5 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -38,7 +38,7 @@ def first_alive_load_balance? end def send_request - raise 'If you inherit a Connector from Base you must implement send_request' + fail 'If you inherit a Connector from Base you must implement send_request' end def ping_port diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 0bcb310d..dd02b34f 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -38,7 +38,7 @@ def data_callback(data) # # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) # @param [String] message The error message - def fail(code, message) + def failure(code, message) @error = ClientError.new @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message @@ -60,7 +60,7 @@ def initialize_stats @stats.method_name = @options[:method].to_s rescue => ex log_exception(ex) - fail(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") + failure(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") end def log_signature @@ -83,7 +83,7 @@ def parse_response # fail the call if we already know the client is failed # (don't try to parse out the response payload) - fail(response_wrapper.error_reason, response_wrapper.error) + failure(response_wrapper.error_reason, response_wrapper.error) else logger.debug { sign_message("Successful response parsed") } @@ -91,7 +91,7 @@ def parse_response parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) if parsed.nil? && !response_wrapper.has_field?(:error_reason) - fail(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') + failure(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') else verify_callbacks succeed(parsed) @@ -103,7 +103,7 @@ def parse_response def post_init send_data unless error? rescue => e - fail(:RPC_ERROR, "Connection error: #{e.message}") + failure(:RPC_ERROR, "Connection error: #{e.message}") end def request_bytes @@ -115,7 +115,7 @@ def request_bytes return ::Protobuf::Socketrpc::Request.encode(fields) rescue => e - fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") + failure(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") end def setup_connection @@ -130,7 +130,7 @@ def succeed(response) rescue => e logger.error { sign_message("Success callback error encountered") } log_exception(e) - fail(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") + failure(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") ensure complete end @@ -148,14 +148,14 @@ def timeout def timeout_wrap(&block) ::Timeout.timeout(timeout, &block) rescue ::Timeout::Error - fail(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") + failure(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") end def validate_request_type! unless @options[:request].class == @options[:request_type] expected = @options[:request_type].name actual = @options[:request].class.name - fail(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead") + failure(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead") end end @@ -169,7 +169,7 @@ def verify_callbacks def verify_options! # Verify the options that are necessary and merge them in [:service, :method, :host, :port].each do |opt| - fail(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? + failure(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 15fe47b0..2af45f7d 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -132,7 +132,7 @@ def lookup_server_uri sleep(1.0 / 100.0) end - raise "Host not found for service #{service}" + fail "Host not found for service #{service}" end def host_alive?(host) @@ -181,7 +181,7 @@ def send_request_with_lazy_pirate parse_response rescue RequestTimeout retry if attempt < CLIENT_RETRIES - fail(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds") + failure(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds") end end @@ -256,13 +256,13 @@ def zmq_context def zmq_eagain_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) if ::ZMQ::Util.errno == ::ZMQ::EAGAIN - raise ZmqEagainError, <<-ERROR + fail ZmqEagainError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR else - raise <<-ERROR + fail <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} @@ -273,7 +273,7 @@ def zmq_eagain_error_check(return_code, source) def zmq_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - raise <<-ERROR + fail <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} @@ -283,7 +283,7 @@ def zmq_error_check(return_code, source) def zmq_recoverable_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - raise ZmqRecoverableError, <<-ERROR + fail ZmqRecoverableError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index c142a586..61bc6d3b 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -37,7 +37,7 @@ def method_name method_name = request_wrapper.method_name.underscore.to_sym unless service.rpc_method?(method_name) - raise MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.") + fail MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.") end method_name diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index ec30bafa..a4e652ea 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -66,7 +66,7 @@ def validate!(candidate) expected = env.response_type if expected != actual - raise BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}") + fail BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}") end candidate diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 4353c0a5..e096b7c7 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -55,7 +55,7 @@ def run @threads = [] @server = ::TCPServer.new(host, port) - raise "The server was unable to start properly." if @server.closed? + fail "The server was unable to start properly." if @server.closed? @server.listen(backlog) @working = [] diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 984ae01e..b64ee8db 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -33,7 +33,7 @@ def read_data end def send_data(data) - raise 'Socket closed unexpectedly' unless socket_writable? + fail 'Socket closed unexpectedly' unless socket_writable? response_buffer = Protobuf::Rpc::Buffer.new(:write) response_buffer.set_data(data) diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index bd70aad2..e81159aa 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -11,7 +11,7 @@ def initialize(options) when options.respond_to?(:to_hash) then options.to_hash else - raise "Cannot parser Socket Server - server options" + fail "Cannot parser Socket Server - server options" end @server = ::Protobuf::Rpc::Socket::Server.new(@options) diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index bdaaee96..ee5e0f83 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -20,7 +20,7 @@ def self.included(base) def zmq_error_check(return_code, source = nil) unless ::ZMQ::Util.resultcode_ok?(return_code) - raise <<-ERROR + fail <<-ERROR Last ZMQ API call #{source ? "to #{source}" : ""} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 70b53548..5d213640 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -12,7 +12,7 @@ def initialize(options) when options.respond_to?(:to_hash) then options.to_hash else - raise "Cannot parser Zmq Server - server options" + fail "Cannot parser Zmq Server - server options" end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index dea0eda2..dea54723 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -170,7 +170,7 @@ def response_type # def rpc_failed(message) message = message.message if message.respond_to?(:message) - raise RpcFailed.new(message) + fail RpcFailed.new(message) end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 991fd657..5c1f151c 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -27,7 +27,7 @@ def rpc_service # Call the given service method. def dispatch_rpc_request unless rpc_service.respond_to?(method_name) - raise MethodNotFound.new("#{service_name}##{method_name} is not a publicly defined method.") + fail MethodNotFound.new("#{service_name}##{method_name} is not a publicly defined method.") end rpc_service.callable_rpc_method(method_name).call diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index add710e9..2c6b9b09 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -37,7 +37,7 @@ def rescue_filters def rescue_from(*ex_klasses, &block) options = ex_klasses.last.is_a?(Hash) ? ex_klasses.pop : {} callable = options.delete(:with) { block } - raise ArgumentError, 'Option :with missing from rescue_from options' if callable.nil? + fail ArgumentError, 'Option :with missing from rescue_from options' if callable.nil? ex_klasses.each { |ex_klass| rescue_filters[ex_klass] = callable } end @@ -259,7 +259,7 @@ def call_or_send(callable, *args, &block) when respond_to?(callable, true) then __send__(callable, *args, &block) else - raise "Object #{callable} is not callable" + fail "Object #{callable} is not callable" end return_value diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index c6098b6c..6b034845 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -26,7 +26,7 @@ end c.on_failure do |err| - raise err.inspect + fail err.inspect end end end.to_not raise_error @@ -38,7 +38,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end @@ -51,7 +51,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 0c37a573..18d1941b 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -34,7 +34,7 @@ end c.on_failure do |err| - raise err.inspect + fail err.inspect end end end.to_not raise_error @@ -53,7 +53,7 @@ end c.on_failure do |err| - raise err.inspect + fail err.inspect end end end @@ -68,7 +68,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/Required field.*does not have a value/) @@ -82,7 +82,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) @@ -95,7 +95,7 @@ client = ::Test::ResourceService.client(:timeout => 1) client.find_with_sleep(:sleep => 2) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/The server repeatedly failed to respond/) diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 5d911d2c..5a9945ae 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -30,7 +30,7 @@ describe '#success_cb' do it 'allows setting the success callback and calling it' do expect(subject.success_cb).to be_nil - cb = proc { |res| raise res } + cb = proc { |res| fail res } subject.success_cb = cb expect(subject.success_cb).to eq(cb) expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb' @@ -40,7 +40,7 @@ describe '#failure_cb' do it 'allows setting the failure callback and calling it' do expect(subject.failure_cb).to be_nil - cb = proc { |res| raise res } + cb = proc { |res| fail res } subject.failure_cb = cb expect(subject.failure_cb).to eq(cb) expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb' diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 69205eb1..47ff900b 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -19,7 +19,7 @@ specify { expect(subject.respond_to?(:request_caller)).to be true } specify { expect(subject.respond_to?(:data_callback)).to be true } specify { expect(subject.respond_to?(:error)).to be true } - specify { expect(subject.respond_to?(:fail)).to be true } + specify { expect(subject.respond_to?(:failure)).to be true } specify { expect(subject.respond_to?(:complete)).to be true } specify { expect(subject.respond_to?(:parse_response)).to be true } specify { expect(subject.respond_to?(:verify_options!)).to be true } @@ -93,7 +93,7 @@ end before { allow(subject).to receive(:validate_request_type!).and_return(true) } - before { expect(subject).not_to receive(:fail) } + before { expect(subject).not_to receive(:failure) } specify { expect(subject.request_bytes).to eq expected.encode } end @@ -161,8 +161,8 @@ end - it_behaves_like("a ConnectorDisposition", :fail, "failure_cb", "code", "message") - it_behaves_like("a ConnectorDisposition", :fail, "complete_cb", "code", "message") + it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message") + it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message") it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response") it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response") it_behaves_like("a ConnectorDisposition", :complete, "complete_cb") diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 0694533d..caae7b43 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -410,22 +410,22 @@ class FilterTest def filter_with_error1 @called << :filter_with_error1 - raise CustomError1, 'Filter 1 failed' + fail CustomError1, 'Filter 1 failed' end def filter_with_error2 @called << :filter_with_error2 - raise CustomError1, 'Filter 2 failed' + fail CustomError1, 'Filter 2 failed' end def filter_with_error3 @called << :filter_with_error3 - raise CustomError3, 'Filter 3 failed' + fail CustomError3, 'Filter 3 failed' end def filter_with_runtime_error @called << :filter_with_runtime_error - raise 'Filter with runtime error failed' + fail 'Filter with runtime error failed' end def custom_error_occurred(ex) From b51ca10d8ada9936385216d30183534e9c8e9a7f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:19:12 -0700 Subject: [PATCH 0814/1191] Style/RaiseArgs --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/middleware/request_decoder.rb | 8 ++++---- lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++-- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_dispatcher.rb | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cd9d0cb8..c2754be4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -90,11 +90,6 @@ Style/NumericLiterals: Style/PredicateName: Enabled: false -# Offense count: 8 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/RaiseArgs: - Enabled: false - # Offense count: 2 Style/RescueModifier: Enabled: false diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 61bc6d3b..111d0c0d 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -37,7 +37,7 @@ def method_name method_name = request_wrapper.method_name.underscore.to_sym unless service.rpc_method?(method_name) - fail MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.") + fail MethodNotFound, "#{service.name}##{method_name} is not a defined RPC method." end method_name @@ -50,7 +50,7 @@ def request rpc_method.request_type.decode(data) end rescue => exception - raise BadRequestData.new("Unable to decode request: #{exception.message}") + raise BadRequestData, "Unable to decode request: #{exception.message}" end # Decode the incoming request object into our expected request object @@ -61,7 +61,7 @@ def request_wrapper Socketrpc::Request.decode(env.encoded_request) end rescue => exception - raise BadRequestData.new("Unable to decode request: #{exception.message}") + raise BadRequestData, "Unable to decode request: #{exception.message}" end def rpc_method @@ -71,7 +71,7 @@ def rpc_method def service @service ||= service_name.constantize rescue NameError - raise ServiceNotFound.new("Service class #{service_name} is not defined.") + raise ServiceNotFound, "Service class #{service_name} is not defined." end def service_name diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index a4e652ea..d303a9b2 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -35,7 +35,7 @@ def encoded_response # Rescue encoding exceptions, re-wrap them as generic protobuf errors, # and re-raise them - raise PbError.new(exception.message) + raise PbError, exception.message end # Prod the object to see if we can produce a proto object as a response @@ -66,7 +66,7 @@ def validate!(candidate) expected = env.response_type if expected != actual - fail BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}") + fail BadResponseProto, "Expected response to be of type #{expected.name} but was #{actual.name}" end candidate diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index dea54723..9b952b29 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -170,7 +170,7 @@ def response_type # def rpc_failed(message) message = message.message if message.respond_to?(:message) - fail RpcFailed.new(message) + fail RpcFailed, message end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 5c1f151c..6e00523e 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -27,7 +27,7 @@ def rpc_service # Call the given service method. def dispatch_rpc_request unless rpc_service.respond_to?(method_name) - fail MethodNotFound.new("#{service_name}##{method_name} is not a publicly defined method.") + fail MethodNotFound, "#{service_name}##{method_name} is not a publicly defined method." end rpc_service.callable_rpc_method(method_name).call From ed29436e205215614f701a3a3ea47db40682e3d8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:20:24 -0700 Subject: [PATCH 0815/1191] Style/IfUnlessModifier --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/enum_field.rb | 4 +--- lib/protobuf/rpc/buffer.rb | 4 +--- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c2754be4..8f489f57 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -66,11 +66,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 2 -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Enabled: false - # Offense count: 14 Style/Lambda: Enabled: false diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 4f31316f..ac26ea0e 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -25,9 +25,7 @@ def encode(value) end def decode(value) - if acceptable?(value) - value - end + value if acceptable?(value) end def enum? diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index dc63dbd6..aa4b4d1e 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -70,9 +70,7 @@ def get_data_size # rubocop:disable Style/AccessorMethodName private def check_for_flush - if !@size.nil? && @data.length == @size - @flush = true - end + @flush = true if !@size.nil? && @data.length == @size end end end From 272e075da02bdee8780d75993e09ef874a7e37ed Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:22:52 -0700 Subject: [PATCH 0816/1191] Style/PredicateName --- .rubocop_todo.yml | 5 ----- lib/protobuf/deprecator.rb | 2 +- lib/protobuf/generators/message_generator.rb | 22 ++++++++++---------- lib/protobuf/message.rb | 7 +++++-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8f489f57..37b1d224 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -80,11 +80,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 7 -# Configuration parameters: NamePrefix, NamePrefixBlacklist. -Style/PredicateName: - Enabled: false - # Offense count: 2 Style/RescueModifier: Enabled: false diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index 856f8480..68167378 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -11,7 +11,7 @@ def warn_deprecated(old_method, new_method) def deprecate_method(old_method, new_method) class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) def #{old_method}(*args) - warn_deprecated("#{old_method}", "#{new_method}") + self.class.warn_deprecated("#{old_method}", "#{new_method}") new_meth = method("#{new_method}") if new_meth.arity == 0 __send__("#{new_method}") diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index cdfecf7d..c68b3ad0 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -23,7 +23,7 @@ def compile def compile_declaration run_once(:compile_declaration) do - if is_printable? + if printable? print_class(descriptor.name, :message) do group = GroupGenerator.new(current_indent) group.add_enums(descriptor.enum_type, :namespace => type_namespace) @@ -38,7 +38,7 @@ def compile_declaration def compile_message run_once(:compile_message) do - if is_printable? + if printable? print_class(descriptor.name, nil) do group = GroupGenerator.new(current_indent) group.add_messages(descriptor.nested_type, :extension_fields => @extension_fields, :namespace => type_namespace) @@ -61,31 +61,31 @@ def compile_message private - def has_extensions? + def extensions? !message_extension_fields.empty? end - def has_fields? + def fields? descriptor.field.count > 0 end - def has_nested_enums? + def nested_enums? descriptor.enum_type.count > 0 end - def has_nested_messages? + def nested_messages? descriptor.nested_type.count > 0 end - def has_nested_types? - has_nested_enums? || has_nested_messages? + def nested_types? + nested_enums? || nested_messages? end - def is_printable? + def printable? if @only_declarations - has_nested_types? + nested_types? else - has_fields? || has_nested_messages? || has_extensions? + fields? || nested_messages? || extensions? end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c5b901ed..51cd5863 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -11,6 +11,8 @@ class Message # Includes & Extends # + extend ::Protobuf::Deprecator + extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization @@ -81,16 +83,17 @@ def each_field_for_serialization end end - def has_field?(name) + def field?(name) @values.key?(name) end + deprecate_method(:has_field?, :field?) def inspect to_hash.inspect end def respond_to_has?(key) - respond_to?(key) && has_field?(key) + respond_to?(key) && field?(key) end def respond_to_has_and_present?(key) From 9e8dca096d8bb92802c6a2b0ac820751e1c08f2e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:37:35 -0700 Subject: [PATCH 0817/1191] Style/RescueModifier --- .rubocop_todo.yml | 6 +----- lib/protobuf/rpc/connectors/zmq.rb | 6 +++++- lib/protobuf/rpc/servers/socket/server.rb | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 37b1d224..fa2a0bc0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -26,7 +26,7 @@ Metrics/LineLength: # Offense count: 47 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 41 + Max: 45 # Offense count: 2 # Configuration parameters: CountKeywordArgs. @@ -80,10 +80,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 2 -Style/RescueModifier: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 2af45f7d..8ed87637 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -165,7 +165,11 @@ def ping_port_open?(host) rescue false ensure - socket.close rescue nil + begin + socket && socket.close + rescue IOError + nil + end end # Trying a number of times, attempt to get a response from the server. diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index e096b7c7..b9e9c708 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -64,7 +64,11 @@ def run while running? logger.debug { sign_message("Waiting for connections") } - ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) rescue nil + ready_cnxns = begin + IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) + rescue IOError + nil + end if ready_cnxns cnxns = ready_cnxns.first From 09e5f7ab5bf08a66582404643d00e449f22a05fc Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:28:05 -0700 Subject: [PATCH 0818/1191] Style/FileName --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 77a6182c..33450227 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,6 +17,10 @@ Style/EmptyLines: Exclude: - '**/*.pb.rb' +Style/FileName: + Exclude: + - '**/protoc-gen-ruby*' + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fa2a0bc0..453b7653 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,11 +50,6 @@ Style/DoubleNegation: Style/EmptyLinesAroundBody: Enabled: false -# Offense count: 2 -# Configuration parameters: Exclude. -Style/FileName: - Enabled: false - # Offense count: 20 # Configuration parameters: MinBodyLength. Style/GuardClause: From eaf4a885b277bdae7cf7e0d21c5c5c760f70475a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:41:31 -0700 Subject: [PATCH 0819/1191] Style/Lambda --- .rubocop_todo.yml | 4 ---- lib/protobuf/generators/file_generator.rb | 5 ++--- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 8 ++++---- spec/lib/protobuf/rpc/connectors/common_spec.rb | 4 ++-- spec/lib/protobuf/rpc/service_dispatcher_spec.rb | 2 +- spec/lib/protobuf/rpc/service_filters_spec.rb | 8 ++++---- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 453b7653..442f5ea3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,10 +61,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 14 -Style/Lambda: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 77580bfd..afeb5207 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -118,10 +118,9 @@ def print_import_requires end def print_package(&block) - final = lambda { block.call } namespaces = descriptor.package.split('.') - namespaces.reverse.reduce(final) do |previous, namespace| - lambda { print_module(namespace, &previous) } + namespaces.reverse.reduce(block) do |previous, namespace| + -> { print_module(namespace, &previous) } end.call end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 9b952b29..327586ed 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -126,7 +126,7 @@ def self.rpc_method?(name) # is why we wrap the method call). # def callable_rpc_method(method_name) - lambda { run_filters(method_name) } + -> { run_filters(method_name) } end # Response object for this rpc cycle. Not assignable. diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 2c6b9b09..df09098e 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -120,7 +120,7 @@ def invoke_via_except?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_if?(_rpc_method, filter) - if_check = filter.fetch(:if) { lambda { |_service| return true } } + if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case when if_check.nil? then true @@ -150,7 +150,7 @@ def invoke_via_only?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_unless?(_rpc_method, filter) - unless_check = filter.fetch(:unless) { lambda { |_service| return false } } + unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case when unless_check.nil? then false @@ -209,10 +209,10 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = # end # def run_around_filters(rpc_method) - final = lambda { __send__(rpc_method) } + final = -> { __send__(rpc_method) } filters[:around].reverse.reduce(final) do |previous, filter| if invoke_filter?(rpc_method, filter) - lambda { call_or_send(filter[:callable], &previous) } + -> { call_or_send(filter[:callable], &previous) } else previous end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 47ff900b..54ab8c33 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -111,7 +111,7 @@ end it "doesn't set @failure_cb when already defined" do - set_cb = lambda { true } + set_cb = -> { true } subject.instance_variable_set(:@failure_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) @@ -119,7 +119,7 @@ end it "doesn't set @success_cb when already defined" do - set_cb = lambda { true } + set_cb = -> { true } subject.instance_variable_set(:@success_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 585b3b05..ca6f08df 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -42,7 +42,7 @@ end context "when the given RPC method is implemented and a NoMethodError is raised" do - before { allow(rpc_service).to receive(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } + before { allow(rpc_service).to receive(:callable_rpc_method).and_return(-> { rpc_service.__send__(:foo) }) } it "raises the exeception" do expect { subject.call(env) }.to raise_exception(NoMethodError) diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index caae7b43..b4830ab4 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -161,7 +161,7 @@ def verify_before context 'when "if" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |_service| true }) + FilterTest.before_filter(:verify_before, :if => ->(_service) { true }) end it 'invokes the filter' do @@ -185,7 +185,7 @@ def verify_before context 'when "if" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |_service| false }) + FilterTest.before_filter(:verify_before, :if => ->(_service) { false }) end it 'skips the filter' do @@ -229,7 +229,7 @@ def verify_before context 'when "unless" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |_service| false }) + FilterTest.before_filter(:verify_before, :unless => ->(_service) { false }) end it 'invokes the filter' do @@ -253,7 +253,7 @@ def verify_before context 'when "unless" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |_service| true }) + FilterTest.before_filter(:verify_before, :unless => ->(_service) { true }) end it 'skips the filter' do From e11737d306f53b90f0dbe80f85a36524da38e7fd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:42:25 -0700 Subject: [PATCH 0820/1191] Style/SpaceInsideBrackets --- .rubocop_todo.yml | 5 --- lib/protobuf.rb | 2 +- lib/protobuf/generators/base.rb | 2 +- .../generators/extension_generator.rb | 2 +- lib/protobuf/generators/field_generator.rb | 2 +- lib/protobuf/generators/file_generator.rb | 10 ++--- lib/protobuf/generators/group_generator.rb | 2 +- lib/protobuf/generators/message_generator.rb | 2 +- lib/protobuf/rpc/servers/zmq/broker.rb | 4 +- lib/protobuf/rpc/service_filters.rb | 4 +- lib/protobuf/tasks/compile.rake | 4 +- spec/lib/protobuf/cli_spec.rb | 28 +++++++------- spec/lib/protobuf/code_generator_spec.rb | 4 +- spec/lib/protobuf/enum_spec.rb | 4 +- spec/lib/protobuf/field/float_field_spec.rb | 2 +- spec/lib/protobuf/field/string_field_spec.rb | 4 +- spec/lib/protobuf/generators/base_spec.rb | 4 +- spec/lib/protobuf/message_spec.rb | 10 ++--- spec/lib/protobuf/rpc/service_filters_spec.rb | 38 +++++++++---------- 19 files changed, 64 insertions(+), 69 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 442f5ea3..66a5aaa5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -71,11 +71,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 126 -# Cop supports --auto-correct. -Style/SpaceInsideBrackets: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf.rb b/lib/protobuf.rb index ca3c311c..4ee58bda 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -12,7 +12,7 @@ module Protobuf # See Protobuf#connector_type documentation. - CONNECTORS = [ :socket, :zmq ].freeze + CONNECTORS = [:socket, :zmq].freeze # Default is Socket as it has no external dependencies. DEFAULT_CONNECTOR = :socket diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 800e63fe..e2f5ff5d 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -62,7 +62,7 @@ def to_s end def type_namespace - @type_namespace ||= @namespace + [ descriptor.name ] + @type_namespace ||= @namespace + [descriptor.name] end end diff --git a/lib/protobuf/generators/extension_generator.rb b/lib/protobuf/generators/extension_generator.rb index 36c5c581..632753ee 100644 --- a/lib/protobuf/generators/extension_generator.rb +++ b/lib/protobuf/generators/extension_generator.rb @@ -16,7 +16,7 @@ def compile print_class(@message_type, :message) do group = GroupGenerator.new(current_indent) group.add_extension_fields(@field_descriptors) - group.order = [ :extension_field ] + group.order = [:extension_field] print group.to_s end end diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 91684914..0c92bc4c 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -54,7 +54,7 @@ def extension? def compile run_once(:compile) do - field_definition = [ "#{label} #{type_name}", name, number, applicable_options ] + field_definition = ["#{label} #{type_name}", name, number, applicable_options] puts field_definition.flatten.compact.join(', ') end end diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index afeb5207..3a81e1f2 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -22,7 +22,7 @@ def file_name def compile run_once(:compile) do - map_extensions(descriptor, [ descriptor.package ]) + map_extensions(descriptor, [descriptor.package]) print_file_comment print_generic_requires @@ -30,9 +30,9 @@ def compile print_package do group = GroupGenerator.new(current_indent) - group.add_enums(descriptor.enum_type, :namespace => [ descriptor.package ]) + group.add_enums(descriptor.enum_type, :namespace => [descriptor.package]) group.add_message_declarations(descriptor.message_type) - group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [ descriptor.package ]) + group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [descriptor.package]) group.add_extended_messages(unknown_extensions) group.add_services(descriptor.service) @@ -80,13 +80,13 @@ def map_extensions(descriptor, namespaces) if descriptor.respond_to_has_and_present?(:message_type) descriptor.message_type.each do |message_descriptor| - map_extensions(message_descriptor, (namespaces + [ message_descriptor.name ])) + map_extensions(message_descriptor, (namespaces + [message_descriptor.name])) end end if descriptor.respond_to_has_and_present?(:nested_type) descriptor.nested_type.each do |nested_descriptor| - map_extensions(nested_descriptor, (namespaces + [ nested_descriptor.name ])) + map_extensions(nested_descriptor, (namespaces + [nested_descriptor.name])) end end end diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index 8c6a90c3..ddff717f 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -18,7 +18,7 @@ def initialize(indent_level = 0) @comments = {} @handlers = {} @indent_level = indent_level - @order = [ :enum, :message_declaration, :message, :extended_message, :service ] + @order = [:enum, :message_declaration, :message, :extended_message, :service] init_printer(indent_level) end diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index c68b3ad0..6d7bba0c 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -52,7 +52,7 @@ def compile_message group.add_extension_fields(message_extension_fields) - group.order = [ :message, :field, :extension_range, :extension_field ] + group.order = [:message, :field, :extension_range, :extension_field] print group.to_s end end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 4f70fbb5..bd98ff32 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -141,9 +141,9 @@ def process_frontend end else if @idle_workers.empty? - local_queue << [address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ].concat(frames) + local_queue << [address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message].concat(frames) else - write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ]).concat(frames)) + write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message]).concat(frames)) end end end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index df09098e..b1413ef3 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -108,7 +108,7 @@ def invoke_filter?(rpc_method, filter) # Value should be a symbol/string or an array of symbols/strings. # def invoke_via_except?(rpc_method, filter) - except = [ filter.fetch(:except) { [] } ].flatten + except = [filter.fetch(:except) { [] }].flatten except.empty? || !except.include?(rpc_method) end @@ -138,7 +138,7 @@ def invoke_via_if?(_rpc_method, filter) # Value should be a symbol/string or an array of symbols/strings. # def invoke_via_only?(rpc_method, filter) - only = [ filter.fetch(:only) { [] } ].flatten + only = [filter.fetch(:only) { [] }].flatten only.empty? || only.include?(rpc_method) end diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index 603a3efc..cd46e3ab 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -3,7 +3,7 @@ require 'fileutils' namespace :protobuf do desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' - task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |_tasks, args| + task :compile, [:package, :source, :destination, :plugin, :file_extension] do |_tasks, args| args.with_defaults(:destination => 'lib') args.with_defaults(:source => 'definitions') args.with_defaults(:plugin => 'ruby') @@ -27,7 +27,7 @@ namespace :protobuf do end desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' - task :clean, [ :package, :destination, :file_extension ] do |_task, args| + task :clean, [:package, :destination, :file_extension] do |_task, args| args.with_defaults(:destination => 'lib') args.with_defaults(:file_extension => '.pb.rb') diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index b1767bf7..b0bcb5af 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -31,12 +31,12 @@ end describe '#start' do - let(:base_args) { [ 'start', app_file ] } + let(:base_args) { ['start', app_file] } let(:test_args) { [] } let(:args) { base_args + test_args } context 'host option' do - let(:test_args) { [ '--host=123.123.123.123' ] } + let(:test_args) { ['--host=123.123.123.123'] } it 'sends the host option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -47,7 +47,7 @@ end context 'port option' do - let(:test_args) { [ '--port=12345' ] } + let(:test_args) { ['--port=12345'] } it 'sends the port option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -58,7 +58,7 @@ end context 'threads option' do - let(:test_args) { [ '--threads=500' ] } + let(:test_args) { ['--threads=500'] } it 'sends the threads option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -69,7 +69,7 @@ end context 'backlog option' do - let(:test_args) { [ '--backlog=500' ] } + let(:test_args) { ['--backlog=500'] } it 'sends the backlog option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -80,7 +80,7 @@ end context 'threshold option' do - let(:test_args) { [ '--threshold=500' ] } + let(:test_args) { ['--threshold=500'] } it 'sends the backlog option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -91,7 +91,7 @@ end context 'log options' do - let(:test_args) { [ '--log=mylog.log', '--level=0' ] } + let(:test_args) { ['--log=mylog.log', '--level=0'] } it 'sends the log file and level options to the runner' do expect(::Protobuf::Logging).to receive(:initialize_logger) do |file, level| @@ -115,7 +115,7 @@ unless defined?(JRUBY_VERSION) context 'request pausing' do - let(:test_args) { [ '--gc_pause_request' ] } + let(:test_args) { ['--gc_pause_request'] } it 'sets the configuration option to GC pause server request' do described_class.start(args) @@ -150,7 +150,7 @@ end context 'when enabled' do - let(:test_args) { [ '--print_deprecation_warnings' ] } + let(:test_args) { ['--print_deprecation_warnings'] } it 'sets the deprecation warning flag to true' do described_class.start(args) @@ -159,7 +159,7 @@ end context 'when disabled' do - let(:test_args) { [ '--no-print_deprecation_warnings' ] } + let(:test_args) { ['--no-print_deprecation_warnings'] } it 'sets the deprecation warning flag to false' do described_class.start(args) @@ -171,7 +171,7 @@ context 'run modes' do context 'socket' do - let(:test_args) { [ '--socket' ] } + let(:test_args) { ['--socket'] } let(:runner) { ::Protobuf::Rpc::SocketRunner } before do @@ -197,7 +197,7 @@ end context 'zmq workers only' do - let(:test_args) { [ '--workers_only', '--zmq' ] } + let(:test_args) { ['--workers_only', '--zmq'] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do @@ -224,7 +224,7 @@ end context 'zmq worker port' do - let(:test_args) { [ '--worker_port=1234', '--zmq' ] } + let(:test_args) { ['--worker_port=1234', '--zmq'] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do @@ -241,7 +241,7 @@ end context 'zmq' do - let(:test_args) { [ '--zmq' ] } + let(:test_args) { ['--zmq'] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 956d05ae..b41849d2 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -19,11 +19,11 @@ let(:file_generator2) { double('file generator 2', :generate_output_file => output_file2) } let(:request_bytes) do - COMPILER::CodeGeneratorRequest.encode(:proto_file => [ input_file1, input_file2 ]) + COMPILER::CodeGeneratorRequest.encode(:proto_file => [input_file1, input_file2]) end let(:expected_response_bytes) do - COMPILER::CodeGeneratorResponse.encode(:file => [ output_file1, output_file2 ]) + COMPILER::CodeGeneratorResponse.encode(:file => [output_file1, output_file2]) end before do diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 55a73602..036693a9 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -71,8 +71,8 @@ describe '.enums_for_tag' do it 'returns an array of Enums for the given tag, if any' do - expect(EnumAliasTest.enums_for_tag(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) - expect(EnumAliasTest.enums_for_tag(2)).to eq([ EnumAliasTest::BAZ ]) + expect(EnumAliasTest.enums_for_tag(1)).to eq([EnumAliasTest::FOO, EnumAliasTest::BAR]) + expect(EnumAliasTest.enums_for_tag(2)).to eq([EnumAliasTest::BAZ]) expect(EnumAliasTest.enums_for_tag(3)).to eq([]) end end diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb index 835885c0..7bda8a33 100644 --- a/spec/lib/protobuf/field/float_field_spec.rb +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -44,7 +44,7 @@ class SomeFloatMessage < ::Protobuf::Message end context 'when set with something that is not a float' do - let(:value) { [ 1, 2, 3 ] } + let(:value) { [1, 2, 3] } it 'throws an error' do expect { subject }.to raise_error(TypeError) diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index f1ad1a7e..24318531 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -8,7 +8,7 @@ context 'when a repeated string field contains frozen strings' do it 'does not raise an encoding error' do expect do - frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] + frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze] ::Test::ResourceFindRequest.encode(:name => 'resource', :widgets => frozen_strings) end.not_to raise_error end @@ -17,7 +17,7 @@ context 'when a repeated bytes field contains frozen strings' do it 'does not raise an encoding error' do expect do - frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] + frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze] ::Test::ResourceFindRequest.encode(:name => 'resource', :widget_bytes => frozen_strings) end.not_to raise_error end diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 0162b1b2..82ffd269 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -9,8 +9,8 @@ context 'namespaces' do let(:descriptor) { double(:name => 'Baz') } - subject { described_class.new(descriptor, 0, :namespace => [ :foo, :bar ]) } - specify { expect(subject.type_namespace).to eq([ :foo, :bar, 'Baz' ]) } + subject { described_class.new(descriptor, 0, :namespace => [:foo, :bar]) } + specify { expect(subject.type_namespace).to eq([:foo, :bar, 'Baz']) } specify { expect(subject.fully_qualified_type_namespace).to eq('.foo.bar.Baz') } end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 56012dd6..d8e6fd90 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -54,18 +54,18 @@ context 'with a repeated field' do it 'treats the field as if it was unset when decoding' do - newer = newer_message.new(:enum_list => [ :HOORAY ]).serialize + newer = newer_message.new(:enum_list => [:HOORAY]).serialize expect(older_message.decode(newer).enum_list).to eq([]) end it 'rejects an unknown value when using the constructor' do - expect { older_message.new(:enum_list => [ :HOORAY ]) }.to raise_error + expect { older_message.new(:enum_list => [:HOORAY]) }.to raise_error end it 'rejects an unknown value when the setter' do older = older_message.new - expect { older.enum_field = [ :HOORAY ] }.to raise_error + expect { older.enum_field = [:HOORAY] }.to raise_error end end end @@ -372,8 +372,8 @@ end it 'converts repeated enum fields to an array of the tags' do - hash = Test::EnumTestMessage.new(:repeated_enums => [ :ONE, :TWO, :TWO, :ONE ]).to_hash - expect(hash).to eq(:repeated_enums => [ 1, 2, 2, 1 ]) + hash = Test::EnumTestMessage.new(:repeated_enums => [:ONE, :TWO, :TWO, :ONE]).to_hash + expect(hash).to eq(:repeated_enums => [1, 2, 2, 1]) end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index b4830ab4..ebedd21b 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -61,7 +61,7 @@ def foo it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :foo, :endpoint ] + expect(subject.called).to eq [:verify_before, :foo, :endpoint] expect(subject.before_filter_calls).to eq 1 end @@ -84,14 +84,14 @@ def endpoint_with_verify context 'when invoking a method defined in "only" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint_with_verify) - expect(subject.called).to eq [ :verify_before, :endpoint_with_verify ] + expect(subject.called).to eq [:verify_before, :endpoint_with_verify] end end context 'when invoking a method not defined by "only" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end end @@ -115,14 +115,14 @@ def endpoint_without_verify context 'when invoking a method not defined in "except" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end context 'when invoking a method defined by "except" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint_without_verify) - expect(subject.called).to eq [ :endpoint_without_verify ] + expect(subject.called).to eq [:endpoint_without_verify] end end end @@ -154,7 +154,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -166,7 +166,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -178,7 +178,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end @@ -190,7 +190,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end end @@ -222,7 +222,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -234,7 +234,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -246,7 +246,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end @@ -258,7 +258,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end end @@ -283,7 +283,7 @@ def short_circuit_filter it 'does not invoke the rpc method' do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :short_circuit_filter ] + expect(subject.called).to eq [:short_circuit_filter] end end end @@ -317,7 +317,7 @@ def foo it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint, :verify_after, :foo ] + expect(subject.called).to eq [:endpoint, :verify_after, :foo] expect(subject.after_filter_calls).to eq 1 end end @@ -447,7 +447,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_error3, :custom_error_occurred ]) + expect(subject.called).to eq([:filter_with_error3, :custom_error_occurred]) expect(subject.ex_class).to eq CustomError3 end.not_to raise_error end @@ -468,7 +468,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_error1, :custom_error_occurred ]) + expect(subject.called).to eq([:filter_with_error1, :custom_error_occurred]) expect(subject.ex_class).to eq CustomError1 end.not_to raise_error end @@ -488,7 +488,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_error1, :block_rescue_handler ]) + expect(subject.called).to eq([:filter_with_error1, :block_rescue_handler]) expect(subject.ex_class).to eq CustomError1 end.not_to raise_error end @@ -507,7 +507,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) + expect(subject.called).to eq([:filter_with_runtime_error, :standard_error_rescue_handler]) expect(subject.ex_class).to eq RuntimeError end.not_to raise_error end From aa2daa230114995eab59c87ba533d7f20726c6a5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 27 Oct 2014 16:41:33 -0700 Subject: [PATCH 0821/1191] `int` is not a protobuf primitive --- lib/protobuf/message.rb | 2 +- spec/lib/protobuf/message_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 5076d0d9..788f92b6 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -90,7 +90,7 @@ def field?(name) def inspect attrs = self.class.fields.map do |field| - [ field.name, send(field.name).inspect ].join('=') + [field.name, send(field.name).inspect].join('=') end.join(' ') "#<#{self.class} #{attrs}>" diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 83f99e17..b8e1da86 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -363,15 +363,15 @@ let(:klass) do Class.new(Protobuf::Message) do optional :string, :name, 1 - repeated :int, :counts, 2 - optional :int, :timestamp, 2 + repeated :int32, :counts, 2 + optional :int32, :timestamp, 3 end end before { stub_const('MyMessage', klass) } it 'lists the fields' do - proto = klass.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) + proto = klass.new(:name => 'wooo', :counts => [1, 2, 3]) expect(proto.inspect).to eq \ '#' end From b17aaae0c529712b8b7b1537b11fcbc6e2560ea3 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 09:28:34 -0800 Subject: [PATCH 0822/1191] Make the tests pass --- lib/protobuf/cli.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 592d7f09..222a55de 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -235,8 +235,6 @@ def start_server end logger.info { 'Shutdown complete' } - - exit 0 end end end From e7081e7cc595e00c409cf15fbe441db3fd12e2dc Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 09:45:09 -0800 Subject: [PATCH 0823/1191] Update autogenerated RuboCop config --- .rubocop_todo.yml | 49 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 66a5aaa5..600b1fc8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,15 +1,19 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-10-15 12:57:34 -0700 using RuboCop version 0.26.1. +# on 2014-11-24 09:44:26 -0800 using RuboCop version 0.27.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 28 +Metrics/AbcSize: + Max: 59 + # Offense count: 3 Metrics/BlockNesting: Max: 5 -# Offense count: 8 +# Offense count: 9 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 233 @@ -18,12 +22,12 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 11 -# Offense count: 505 +# Offense count: 508 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 47 +# Offense count: 48 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 45 @@ -37,7 +41,7 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 191 +# Offense count: 216 Style/Documentation: Enabled: false @@ -45,28 +49,46 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 146 +# Offense count: 100 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/EmptyLinesAroundClassBody: + Enabled: false + +# Offense count: 1 # Cop supports --auto-correct. -Style/EmptyLinesAroundBody: +Style/EmptyLinesAroundMethodBody: + Enabled: false + +# Offense count: 66 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/EmptyLinesAroundModuleBody: Enabled: false -# Offense count: 20 +# Offense count: 18 # Configuration parameters: MinBodyLength. Style/GuardClause: Enabled: false -# Offense count: 672 +# Offense count: 690 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/HashSyntax: Enabled: false +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/MultilineOperationIndentation: + Enabled: false + # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: Enabled: false -# Offense count: 46 +# Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: MinDigits: 21 @@ -77,7 +99,14 @@ Style/NumericLiterals: Style/StringLiterals: Enabled: false +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/StringLiteralsInInterpolation: + Enabled: false + # Offense count: 4 # Cop supports --auto-correct. +# Configuration parameters: WordRegex. Style/WordArray: MinSize: 2 From 1172fdd84198503b3eb56f945579225fb78801bb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 15:17:19 -0800 Subject: [PATCH 0824/1191] Force exit after rpc_server does its thing --- bin/rpc_server | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/rpc_server b/bin/rpc_server index 18d8724b..7aed6c92 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -2,3 +2,4 @@ require 'protobuf/cli' ::Protobuf::CLI.start(ARGV) +exit From 2310e59145564905afc6d2cc4b394cdc67e6b3fb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 30 Sep 2014 08:46:30 -0700 Subject: [PATCH 0825/1191] Remove uses of class_eval --- lib/protobuf/deprecator.rb | 30 ++++++++---------------------- lib/protobuf/message/fields.rb | 8 +++----- lib/protobuf/rpc/env.rb | 22 +++++++++++----------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index 68167378..b7333324 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -9,33 +9,19 @@ def warn_deprecated(old_method, new_method) # Given deprecations should be a hash whose keys are the new methods # and values are a list of deprecated methods that should send to t def deprecate_method(old_method, new_method) - class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) - def #{old_method}(*args) - self.class.warn_deprecated("#{old_method}", "#{new_method}") - new_meth = method("#{new_method}") - if new_meth.arity == 0 - __send__("#{new_method}") - else - __send__("#{new_method}", *args) - end - end - DEPRECATED + define_method old_method do |*args| + self.class.warn_deprecated(old_method, new_method) + public_send(new_method, *args) + end end # Given deprecations should be a hash whose keys are the new methods # and values are a list of deprecated methods that should send to t def deprecate_class_method(old_method, new_method) - class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) - def self.#{old_method}(*args) - warn_deprecated("#{old_method}", "#{new_method}") - new_meth = method("#{new_method}") - if new_meth.arity == 0 - __send__("#{new_method}") - else - __send__("#{new_method}", *args) - end - end - DEPRECATED + define_singleton_method old_method do |*args| + warn_deprecated(old_method, new_method) + public_send(new_method, *args) + end end end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 234c0dfa..808e7393 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -97,11 +97,9 @@ def define_field(rule, type_class, field_name, tag, options) field_store[field_name] = field field_store[tag] = field - class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) - define_method("#{field_name}!") do - @values[:#{field_name}] - end - RAW_GETTER + define_method("#{field_name}!") do + @values[field_name] + end end def raise_if_tag_collision(tag, field_name) diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index c719cadf..f89b2a1e 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -16,19 +16,19 @@ class Env < Hash # def self.hash_accessor(*names) #:nodoc: names.each do |name| - class_eval <<-METHOD, __FILE__, __LINE__ + 1 - def #{name} - self['#{name}'] - end + name_str = name.to_s.freeze - def #{name}=(value) - self['#{name}'] = value - end + define_method name do + self[name_str] + end - def #{name}? - ! self['#{name}'].nil? - end - METHOD + define_method "#{name}=" do |value| + self[name_str] = value + end + + define_method "#{name}?" do + !self[name_str].nil? + end end end From d5b713b039baf4dcd07fc65920e51da25fd1008c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 10:16:31 -0700 Subject: [PATCH 0826/1191] add backtrace output to logger when SIGTRAP --- lib/protobuf/rpc/servers/zmq_runner.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 5d213640..e4e5eaf7 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -1,4 +1,5 @@ require 'ostruct' +require 'thread' module Protobuf module Rpc @@ -36,6 +37,17 @@ def stop private def register_signals + trap(:TRAP) do + ::Thread.list.each do |thread| + logger.info do + <<-THREAD_TRACE + #{thread.inspect}: + #{thread.backtrace.join($/)}" + THREAD_TRACE + end + end + end + trap(:TTIN) do @server.add_worker logger.info { "Increased worker size to: #{@server.total_workers}" } @@ -43,7 +55,7 @@ def register_signals trap(:TTOU) do logger.info { "Current worker size: #{@server.workers.size}" } - logger.info { "Current worker size: #{@server.busy_worker_count}" } + logger.info { "Current busy worker size: #{@server.busy_worker_count}" } end end end From 903c630e05618a6f8fcbe34e76bf2c06a5fc873d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 10:42:11 -0700 Subject: [PATCH 0827/1191] extract the socket availability check for zmq connector --- lib/protobuf/rpc/connectors/zmq.rb | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 8ed87637..ac13efa2 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -82,25 +82,7 @@ def create_socket if socket # Make sure the context builds the socket socket.setsockopt(::ZMQ::LINGER, 0) zmq_error_check(socket.connect(server_uri), :socket_connect) - - if first_alive_load_balance? - begin - check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) - socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) - zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) - - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_recoverable_error_check(socket.close, :socket_close) - end - rescue ZmqRecoverableError - socket = nil # couldn't make a connection and need to try again - else - socket.setsockopt(::ZMQ::RCVTIMEO, -1) - socket.setsockopt(::ZMQ::SNDTIMEO, -1) - end - end + socket = socket_to_available_server(socket) if first_alive_load_balance? end end while socket.try(:socket).nil? @@ -189,6 +171,24 @@ def send_request_with_lazy_pirate end end + def socket_to_available_server(socket) + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) + zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_recoverable_error_check(socket.close, :socket_close) + end + + socket.setsockopt(::ZMQ::RCVTIMEO, -1) + socket.setsockopt(::ZMQ::SNDTIMEO, -1) + socket + rescue ZmqRecoverableError + return nil # couldn't make a connection and need to try again + end + def rcv_timeout @rcv_timeout ||= begin case From ef72415dbedd980edf279f349aec6b0a48d95ba0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 10:48:40 -0700 Subject: [PATCH 0828/1191] set socket before begin block --- lib/protobuf/rpc/connectors/zmq.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index ac13efa2..dc86de6b 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -75,6 +75,8 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket + socket = nil + begin server_uri = lookup_server_uri socket = zmq_context.socket(::ZMQ::REQ) From 73f58e784d791b4085eb92b771ad31f96640211f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:01:22 -0700 Subject: [PATCH 0829/1191] alpha the methods in zmq connector --- lib/protobuf/rpc/connectors/zmq.rb | 145 ++++++++++++++--------------- 1 file changed, 72 insertions(+), 73 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index dc86de6b..b4b2fa46 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -24,6 +24,10 @@ class Zmq < Base ## # Class Methods # + def self.ping_port_responses + @ping_port_responses ||= ::ThreadSafe::Cache.new + end + def self.zmq_context @zmq_contexts ||= Hash.new do |hash, key| hash[key] = ZMQ::Context.new @@ -32,13 +36,12 @@ def self.zmq_context @zmq_contexts[Process.pid] end - def self.ping_port_responses - @ping_port_responses ||= ::ThreadSafe::Cache.new - end - ## # Instance methods # + def log_signature + @_log_signature ||= "[client-#{self.class}]" + end # Start the request/response cycle. We implement the Lazy Pirate # req/reply reliability pattern as laid out in the ZMQ Guide, Chapter 4. @@ -50,10 +53,6 @@ def send_request send_request_with_lazy_pirate unless error? end - def log_signature - @_log_signature ||= "[client-#{self.class}]" - end - private ## @@ -97,6 +96,27 @@ def error? !! @error end + def host_alive?(host) + return true unless ping_port_enabled? + + if (last_response = self.class.ping_port_responses[host]) + if (Time.now.to_i - last_response[:at]) <= host_alive_check_interval + return last_response[:ping_port_open] + end + end + + ping_port_open = ping_port_open?(host) + self.class.ping_port_responses[host] = { + :at => Time.now.to_i, + :ping_port_open => ping_port_open, + } + ping_port_open + end + + def host_alive_check_interval + @host_alive_check_interval ||= [ENV["PB_ZMQ_CLIENT_HOST_ALIVE_CHECK_INTERVAL"].to_i, 1].max + end + # Lookup a server uri for the requested service in the service # directory. If the service directory is not running, default # to the host and port in the options @@ -119,27 +139,6 @@ def lookup_server_uri fail "Host not found for service #{service}" end - def host_alive?(host) - return true unless ping_port_enabled? - - if (last_response = self.class.ping_port_responses[host]) - if (Time.now.to_i - last_response[:at]) <= host_alive_check_interval - return last_response[:ping_port_open] - end - end - - ping_port_open = ping_port_open?(host) - self.class.ping_port_responses[host] = { - :at => Time.now.to_i, - :ping_port_open => ping_port_open, - } - ping_port_open - end - - def host_alive_check_interval - @host_alive_check_interval ||= [ENV["PB_ZMQ_CLIENT_HOST_ALIVE_CHECK_INTERVAL"].to_i, 1].max - end - def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) @@ -156,6 +155,19 @@ def ping_port_open?(host) end end + def rcv_timeout + @rcv_timeout ||= begin + case + when options[:timeout] then + options[:timeout] + when ENV.key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + # Trying a number of times, attempt to get a response from the server. # If we haven't received a legitimate response in the CLIENT_RETRIES number # of retries, fail the request. @@ -173,50 +185,6 @@ def send_request_with_lazy_pirate end end - def socket_to_available_server(socket) - check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) - socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) - zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) - - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_recoverable_error_check(socket.close, :socket_close) - end - - socket.setsockopt(::ZMQ::RCVTIMEO, -1) - socket.setsockopt(::ZMQ::SNDTIMEO, -1) - socket - rescue ZmqRecoverableError - return nil # couldn't make a connection and need to try again - end - - def rcv_timeout - @rcv_timeout ||= begin - case - when options[:timeout] then - options[:timeout] - when ENV.key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then - ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i - else - 300_000 # 300 seconds - end - end - end - - def snd_timeout - @snd_timeout ||= begin - case - when options[:timeout] then - options[:timeout] - when ENV.key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then - ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i - else - 300_000 # 300 seconds - end - end - end - def send_request_with_timeout(attempt = 0) socket = create_socket socket.setsockopt(::ZMQ::RCVTIMEO, rcv_timeout) @@ -251,6 +219,37 @@ def service_directory ::Protobuf::Rpc::ServiceDirectory.instance end + def snd_timeout + @snd_timeout ||= begin + case + when options[:timeout] then + options[:timeout] + when ENV.key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + + def socket_to_available_server(socket) + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) + zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_recoverable_error_check(socket.close, :socket_close) + end + + socket.setsockopt(::ZMQ::RCVTIMEO, -1) + socket.setsockopt(::ZMQ::SNDTIMEO, -1) + socket + rescue ZmqRecoverableError + return nil # couldn't make a connection and need to try again + end + # Return the ZMQ Context to use for this process. # If the context does not exist, create it, then register # an exit block to ensure the context is terminated correctly. From 33d2800e798aca3f556b1cb19af596ed34776fec Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:07:50 -0700 Subject: [PATCH 0830/1191] cause tap is weird --- lib/protobuf/message/serialization.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 22457b96..5850b5a6 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -44,10 +44,10 @@ def decode_from(stream) # Encode this message # def encode - ::StringIO.new.tap do |stream| - stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream) - end.string + stream = ::StringIO.new + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + stream.string end # Encode this message to the given stream. From b5333fdce5b0ea80bb1d1df8973b507583a0ce11 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:21:01 -0700 Subject: [PATCH 0831/1191] use any? instead of reduce --- lib/protobuf/rpc/connectors/common.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index dd02b34f..f881fd27 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -8,9 +8,7 @@ module Common attr_reader :error def any_callbacks? - [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| - reduction || !cb.nil? - end + [@complete_cb, @failure_cb, @success_cb].any? end def request_caller From dc863f82ae85acf9690b58e9a2b464897241caa4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:37:28 -0700 Subject: [PATCH 0832/1191] use $INPUT_RECORD_SEPARATOR and alpha methods --- lib/protobuf/rpc/servers/zmq/server.rb | 8 ++++---- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 87f663cb..c6fe5927 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -216,10 +216,6 @@ def teardown @last_reaping = @last_beacon = @timeout = nil end - def total_workers - @total_workers ||= [@options[:threads].to_i, 1].max - end - def timeout if @timeout.nil? @timeout = 0 @@ -228,6 +224,10 @@ def timeout end end + def total_workers + @total_workers ||= [@options[:threads].to_i, 1].max + end + def to_proto @proto ||= ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => uuid, diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index e4e5eaf7..e3396861 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -42,7 +42,7 @@ def register_signals logger.info do <<-THREAD_TRACE #{thread.inspect}: - #{thread.backtrace.join($/)}" + #{thread.backtrace.join($INPUT_RECORD_SEPARATOR)}" THREAD_TRACE end end From b48615dde30b63911b4687a8ae52ab52b9e3104b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:53:39 -0700 Subject: [PATCH 0833/1191] elevate broker polling milliseconds to env var --- lib/protobuf/rpc/servers/zmq/broker.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index aab79929..abb2ccad 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -26,7 +26,7 @@ def run loop do process_local_queue - rc = @poller.poll(500) + rc = @poller.poll(broker_polling_milliseconds) # The server was shutdown and no requests are pending break if rc == 0 && !running? && @server.workers.empty? @@ -51,6 +51,10 @@ def backend_poll_weight @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 1].max end + def broker_polling_milliseconds + @broker_polling_milliseconds ||= [ENV["PB_ZMQ_BROKER_POLLING_MILLISECONDS"].to_i, 500].max + end + def check_and_process_backend readables_include_backend = @poller.readables.include?(@backend_socket) message_count_read_from_backend = 0 From 964ee36ecf309754c2123e638def1444e412d8f9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 14:29:27 -0700 Subject: [PATCH 0834/1191] check options before checking worker count --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c6fe5927..993eecad 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -252,7 +252,7 @@ def wait_for_shutdown_signal end if broadcast_heartbeat? - if all_workers_busy? && options[:broadcast_busy] + if options[:broadcast_busy] && all_workers_busy? broadcast_flatline else broadcast_heartbeat From 8528015c72e2efcb54476c39ae3269587139e383 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 14:40:53 -0700 Subject: [PATCH 0835/1191] set the server for logging/stats that is chosen in zmq host_live choice so all log lines are not the same --- lib/protobuf/rpc/connectors/zmq.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b4b2fa46..027c2ccf 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -126,12 +126,21 @@ def lookup_server_uri service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) - return "tcp://#{host}:#{port}" if host_alive?(host) + + if host_alive?(host) + # @stats from Common, need to get a better public interface for it + @stats.server = [port, host] + return "tcp://#{host}:#{port}" + end end host = options[:host] port = options[:port] - return "tcp://#{host}:#{port}" if host_alive?(host) + + if host_alive?(host) + @stats.server = [port, host] + return "tcp://#{host}:#{port}" + end sleep(1.0 / 100.0) end From 1e68d79eebaa54814f7303e516c107f375ab29a2 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Nov 2014 16:07:19 -0700 Subject: [PATCH 0836/1191] initialize the @stats in the initialize method and fix rubycop warnings --- lib/protobuf/rpc/connectors/base.rb | 1 + lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 8 +++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 8f6d43c5..b2b0c98c 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -30,6 +30,7 @@ class Base def initialize(options) @options = DEFAULT_OPTIONS.merge(options) + @stats = ::Protobuf::Rpc::Stat.new(:CLIENT) end def first_alive_load_balance? diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index f881fd27..9d43dd17 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -52,7 +52,7 @@ def failure(code, message) end def initialize_stats - @stats = Protobuf::Rpc::Stat.new(:CLIENT) + @stats ||= ::Protobuf::Rpc::Stat.new(:CLIENT) @stats.server = [@options[:port], @options[:host]] @stats.service = @options[:service].name @stats.method_name = @options[:method].to_s diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 027c2ccf..422ef8b9 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -74,13 +74,11 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - socket = nil + socket = zmq_context.socket(::ZMQ::REQ) begin - server_uri = lookup_server_uri - socket = zmq_context.socket(::ZMQ::REQ) - if socket # Make sure the context builds the socket + server_uri = lookup_server_uri socket.setsockopt(::ZMQ::LINGER, 0) zmq_error_check(socket.connect(server_uri), :socket_connect) socket = socket_to_available_server(socket) if first_alive_load_balance? @@ -258,7 +256,7 @@ def socket_to_available_server(socket) rescue ZmqRecoverableError return nil # couldn't make a connection and need to try again end - + # Return the ZMQ Context to use for this process. # If the context does not exist, create it, then register # an exit block to ensure the context is terminated correctly. From 1caaa6e3aa1b583fc67b163519d0954ea28b47d5 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Tue, 28 Oct 2014 11:14:14 -0400 Subject: [PATCH 0837/1191] Test enum inspect display, and fix the failing test --- spec/lib/protobuf/message_spec.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index b8e1da86..48458e95 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -362,18 +362,22 @@ describe '#inspect' do let(:klass) do Class.new(Protobuf::Message) do + EnumKlass = Class.new(Protobuf::Enum) do + define :YAY, 1 + end + optional :string, :name, 1 repeated :int32, :counts, 2 - optional :int32, :timestamp, 3 + optional EnumKlass, :enum, 3 end end before { stub_const('MyMessage', klass) } it 'lists the fields' do - proto = klass.new(:name => 'wooo', :counts => [1, 2, 3]) + proto = klass.new(:name => 'wooo', :counts => [1, 2, 3], :enum => klass::EnumKlass::YAY) expect(proto.inspect).to eq \ - '#' + '#>' end end From afa32a9f3dfe5c4f043a7e568a7671dcdf162497 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 14:49:44 -0800 Subject: [PATCH 0838/1191] DRY class methods --- lib/protobuf/lifecycle.rb | 63 +++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index fd688820..74f09ea9 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -1,46 +1,39 @@ module Protobuf class Lifecycle - include ::Protobuf::Logging + class << self + def register(event_name, &blk) + fail "Lifecycle register must have a block" unless block_given? + event_name = normalized_event_name(event_name) + + if ::Protobuf.print_deprecation_warnings? + $stderr.puts <<-ERROR + [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. + Use ::ActiveSupport::Notifications.subscribe('#{event_name}') + ERROR + end + + ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| + blk.call(*args) + end + end + alias_method :on, :register - def self.register(event_name, &blk) - fail "Lifecycle register must have a block" unless block_given? - event_name = normalized_event_name(event_name) + def trigger(event_name, *args) + if ::Protobuf.print_deprecation_warnings? + $stderr.puts <<-ERROR + [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. + Use ::ActiveSupport::Notifications.instrument(...) + ERROR + end - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.subscribe('#{event_name}') - ERROR - end + event_name = normalized_event_name(event_name) - ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| - blk.call(*args) + ::ActiveSupport::Notifications.instrument(event_name, args) end - end - def self.trigger(event_name, *args) - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.instrument(...) - ERROR + def normalized_event_name(event_name) + "#{event_name}".downcase end - - event_name = normalized_event_name(event_name) - - ::ActiveSupport::Notifications.instrument(event_name, args) end - - def self.normalized_event_name(event_name) - "#{event_name}".downcase - end - - class << self - attr_accessor :lifecycle_events - - alias_method :on, :register - end - - @lifecycle_events ||= {} end end From c38ad93adcdd0dcd545bba6d482853e87053825f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 14:56:58 -0800 Subject: [PATCH 0839/1191] interpolation -> `#to_s` --- lib/protobuf/lifecycle.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 74f09ea9..68804828 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -32,7 +32,7 @@ def trigger(event_name, *args) end def normalized_event_name(event_name) - "#{event_name}".downcase + event_name.to_s.downcase end end end From 48047302f0311037ed27cf536423f6277bd6fcfb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:05:27 -0800 Subject: [PATCH 0840/1191] Protobuf::Deprecation is now much thinner We use the much better functionality from AS::Deprecation --- lib/protobuf.rb | 16 +++++++++--- lib/protobuf/deprecation.rb | 20 +++++++++++++++ lib/protobuf/deprecator.rb | 28 --------------------- lib/protobuf/enum.rb | 41 +++++++++---------------------- lib/protobuf/field/base_field.rb | 37 +++++++++++++--------------- lib/protobuf/field/bool_field.rb | 6 +++-- lib/protobuf/field/bytes_field.rb | 6 +++-- lib/protobuf/lifecycle.rb | 22 ++++++----------- lib/protobuf/message.rb | 4 +-- lib/protobuf/message/fields.rb | 14 +++++------ 10 files changed, 85 insertions(+), 109 deletions(-) create mode 100644 lib/protobuf/deprecation.rb delete mode 100644 lib/protobuf/deprecator.rb diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 4ee58bda..7a8d3c12 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -5,9 +5,11 @@ require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/try' -require 'active_support/notifications' require 'active_support/inflector' require 'active_support/json' +require 'active_support/notifications' + +require 'protobuf/deprecation' module Protobuf @@ -62,6 +64,13 @@ def self.gc_pause_server_request=(value) @gc_pause_server_request = !!value end + def self.deprecator + @deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr + end + end + # Print Deprecation Warnings # # Default: true @@ -73,12 +82,11 @@ def self.gc_pause_server_request=(value) # # The rpc_server option will override the ENV setting. def self.print_deprecation_warnings? - return @print_deprecation_warnings unless @print_deprecation_warnings.nil? - self.print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true + !deprecator.silenced end def self.print_deprecation_warnings=(value) - @print_deprecation_warnings = !!value + deprecator.silenced = !value end # Permit unknown field on Message initialization diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb new file mode 100644 index 00000000..24cad832 --- /dev/null +++ b/lib/protobuf/deprecation.rb @@ -0,0 +1,20 @@ +require 'active_support/deprecation' + +module Protobuf + class Deprecation < ::ActiveSupport::Deprecation + def deprecate_methods(*args) + args.last.merge!(:deprecator => self) if args.last.is_a?(Hash) + super + end + + def define_deprecated_methods(target_module, method_hash) + target_module.module_eval do + method_hash.each do |old_method, new_method| + alias_method old_method, new_method + end + end + + deprecate_methods(target_module, method_hash) + end + end +end diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb deleted file mode 100644 index b7333324..00000000 --- a/lib/protobuf/deprecator.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Protobuf - module Deprecator - - def warn_deprecated(old_method, new_method) - $stderr.puts %([DEPRECATED] #{name}.#{old_method} is deprecated and will disappear in a future version. - Please use #{name}.#{new_method} instead.\n) - end - - # Given deprecations should be a hash whose keys are the new methods - # and values are a list of deprecated methods that should send to t - def deprecate_method(old_method, new_method) - define_method old_method do |*args| - self.class.warn_deprecated(old_method, new_method) - public_send(new_method, *args) - end - end - - # Given deprecations should be a hash whose keys are the new methods - # and values are a list of deprecated methods that should send to t - def deprecate_class_method(old_method, new_method) - define_singleton_method old_method do |*args| - warn_deprecated(old_method, new_method) - public_send(new_method, *args) - end - end - - end -end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index f85665f8..c83e8215 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,33 +1,15 @@ require 'delegate' require 'protobuf/optionable' -require 'protobuf/deprecator' ## # Adding extension to Numeric until # we can get people to stop calling #value # on Enum instances. # -class Numeric - unless method_defined?(:value) - def value - $stderr.puts <<-DEPRECATION -[DEPRECATED] Enum#value is deprecated and will be removed in the next release. - Use Enum#to_i instead. -DEPRECATION - self - end - end -end +::Protobuf.deprecator.define_deprecated_methods(Numeric, :value => :to_int) module Protobuf class Enum < SimpleDelegator - - ## - # Deprecations - # - - extend ::Protobuf::Deprecator - # Public: Allows setting Options on the Enum class. include ::Protobuf::Optionable @@ -223,8 +205,6 @@ def self.valid_tag?(tag) # by their :name. # def self.values - warn_deprecated(:values, :enums) - @values ||= begin enums.each_with_object({}) do |enum, hash| hash[enum.name] = enum @@ -235,11 +215,17 @@ def self.values ## # Class Deprecations # + class << self + ::Protobuf.deprecator.define_deprecated_methods( + self, + :enum_by_value => :enum_for_tag, + :name_by_value => :name_for_tag, + :get_name_by_tag => :name_for_tag, + :value_by_name => :enum_for_name, + ) - deprecate_class_method :enum_by_value, :enum_for_tag - deprecate_class_method :name_by_value, :name_for_tag - deprecate_class_method :get_name_by_tag, :name_for_tag - deprecate_class_method :value_by_name, :enum_for_name + ::Protobuf.deprecator.deprecate_methods(self, :values => :enums) + end ## # Attributes @@ -303,10 +289,7 @@ def try(*args, &block) end end - def value - parent_class.warn_deprecated(:value, :to_i) - to_i - end + ::Protobuf.deprecator.define_deprecated_methods(self, :value => :to_i) ## # Instance Aliases diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 8b722e8a..85cbc90a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -153,16 +153,7 @@ def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end - def type - $stderr.puts("[DEPRECATED] #{self.class.name}#type usage is deprecated.\nPlease use #type_class instead.") - type_class - end - - def warn_if_deprecated - if ::Protobuf.print_deprecation_warnings? && deprecated? - $stderr.puts("[WARNING] #{message_class.name}##{name} field usage is deprecated.") - end - end + ::Protobuf.deprecator.define_deprecated_methods(self, :type => :type_class) def wire_type ::Protobuf::WireType::VARINT @@ -186,20 +177,22 @@ def define_accessor def define_array_getter field = self + method_name = field.getter + message_class.class_eval do - define_method(field.getter) do - field.warn_if_deprecated + define_method(method_name) do @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) end + ::Protobuf.deprecator.deprecate_methods(method_name) end end def define_array_setter field = self - message_class.class_eval do - define_method(field.setter) do |val| - field.warn_if_deprecated + method_name = field.setter + message_class.class_eval do + define_method(method_name) do |val| if val.is_a?(Array) val = val.dup val.compact! @@ -217,25 +210,28 @@ def define_array_setter @values[field.name].replace(val) end end + ::Protobuf.deprecator.deprecate_methods(method_name) end end def define_getter field = self + method_name = field.getter + message_class.class_eval do - define_method(field.getter) do - field.warn_if_deprecated + define_method(method_name) do @values.fetch(field.name, field.default_value) end + ::Protobuf.deprecator.deprecate_methods(method_name) end end def define_setter field = self - message_class.class_eval do - define_method(field.setter) do |val| - field.warn_if_deprecated + method_name = field.setter + message_class.class_eval do + define_method(method_name) do |val| if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) @@ -244,6 +240,7 @@ def define_setter fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end + ::Protobuf.deprecator.deprecate_methods(method_name) end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 182d6295..a2534ef0 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -38,11 +38,13 @@ def define_getter super field = self + method_name = "#{field.getter}?" + message_class.class_eval do - define_method("#{field.getter}?") do - field.warn_if_deprecated + define_method(method_name) do @values.fetch(field.name, field.default_value) end + ::Protobuf.deprecator.deprecate_methods(method_name) end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 733e391e..a943745c 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -53,10 +53,11 @@ def wire_type def define_setter field = self + method_name = field.setter + message_class.class_eval do - define_method(field.setter) do |val| + define_method(method_name) do |val| begin - field.warn_if_deprecated val = "#{val}" if val.is_a?(Symbol) if val.nil? @@ -72,6 +73,7 @@ def define_setter raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" end end + ::Protobuf.deprecator.deprecate_methods(method_name) end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 68804828..5e96b444 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -5,13 +5,6 @@ def register(event_name, &blk) fail "Lifecycle register must have a block" unless block_given? event_name = normalized_event_name(event_name) - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.subscribe('#{event_name}') - ERROR - end - ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| blk.call(*args) end @@ -19,18 +12,19 @@ def register(event_name, &blk) alias_method :on, :register def trigger(event_name, *args) - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.instrument(...) - ERROR - end - event_name = normalized_event_name(event_name) ::ActiveSupport::Notifications.instrument(event_name, args) end + replacement = ::ActiveSupport::Notifications + + ::Protobuf.deprecator.deprecate_methods( + self, + :register => "#{replacement}.#{replacement.method(:subscribe).name}".to_sym, + :trigger => "#{replacement}.#{replacement.method(:instrument).name}".to_sym, + ) + def normalized_event_name(event_name) event_name.to_s.downcase end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 788f92b6..b024c957 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -11,8 +11,6 @@ class Message # Includes & Extends # - extend ::Protobuf::Deprecator - extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization @@ -86,7 +84,7 @@ def each_field_for_serialization def field?(name) @values.key?(name) end - deprecate_method(:has_field?, :field?) + ::Protobuf.deprecator.define_deprecated_methods(self, :has_field? => :field?) def inspect attrs = self.class.fields.map do |field| diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 808e7393..eea33128 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -1,15 +1,15 @@ -require 'protobuf/deprecator' - module Protobuf class Message module Fields def self.extended(other) - other.extend(::Protobuf::Deprecator) - other.deprecate_class_method(:get_ext_field_by_name, :get_extension_field) - other.deprecate_class_method(:get_ext_field_by_tag, :get_extension_field) - other.deprecate_class_method(:get_field_by_name, :get_field) - other.deprecate_class_method(:get_field_by_tag, :get_field) + ::Protobuf.deprecator.define_deprecated_methods( + other.singleton_class, + :get_ext_field_by_name => :get_extension_field, + :get_ext_field_by_tag => :get_extension_field, + :get_field_by_name => :get_field, + :get_field_by_tag => :get_field, + ) end ## From 2f607ee1765909fbf238aca3f0e4ffbb51b55e55 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:11:18 -0800 Subject: [PATCH 0841/1191] Style --- spec/lib/protobuf/enum_spec.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 036693a9..79913247 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -50,21 +50,25 @@ describe '.enums' do it 'provides an array of defined Enums' do - expect(Test::EnumTestType.enums).to eq([ - Test::EnumTestType::ONE, - Test::EnumTestType::TWO, - Test::EnumTestType::MINUS_ONE, - Test::EnumTestType::THREE, - ]) + expect(Test::EnumTestType.enums).to eq( + [ + Test::EnumTestType::ONE, + Test::EnumTestType::TWO, + Test::EnumTestType::MINUS_ONE, + Test::EnumTestType::THREE, + ], + ) end context 'when enum allows aliases' do it 'treats aliased enums as valid' do - expect(EnumAliasTest.enums).to eq([ - EnumAliasTest::FOO, - EnumAliasTest::BAR, - EnumAliasTest::BAZ, - ]) + expect(EnumAliasTest.enums).to eq( + [ + EnumAliasTest::FOO, + EnumAliasTest::BAR, + EnumAliasTest::BAZ, + ], + ) end end end From f96ab05df15b180cbccdcabcd72cf76e0bb5842d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:40:47 -0800 Subject: [PATCH 0842/1191] Silence deprecation warnings in tests --- lib/protobuf/rpc/connectors/common.rb | 4 ++-- spec/lib/protobuf/enum_spec.rb | 27 +++++++++++++++++++++++++-- spec/lib/protobuf/lifecycle_spec.rb | 7 ++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index dd02b34f..3133131d 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -78,7 +78,7 @@ def parse_response response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) # Determine success or failure based on parsed data - if response_wrapper.has_field?(:error_reason) + if response_wrapper.field?(:error_reason) logger.debug { sign_message("Error response parsed") } # fail the call if we already know the client is failed @@ -90,7 +90,7 @@ def parse_response # Ensure client_response is an instance parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) - if parsed.nil? && !response_wrapper.has_field?(:error_reason) + if parsed.nil? && !response_wrapper.field?(:error_reason) failure(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') else verify_callbacks diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 79913247..d2f3ef27 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -177,6 +177,11 @@ end describe '.values' do + around do |example| + # this method is deprecated + ::Protobuf.deprecator.silence(&example) + end + it 'provides a hash of defined Enums' do expect(Test::EnumTestType.values).to eq( :MINUS_ONE => Test::EnumTestType::MINUS_ONE, @@ -208,7 +213,16 @@ specify { expect(subject.parent_class).to eq(Test::EnumTestType) } specify { expect(subject.name).to eq(:ONE) } specify { expect(subject.tag).to eq(1) } - specify { expect(subject.value).to eq(1) } + + context 'deprecated' do + around do |example| + # this method is deprecated + ::Protobuf.deprecator.silence(&example) + end + + specify { expect(subject.value).to eq(1) } + end + specify { expect(subject.to_hash_value).to eq(1) } specify { expect(subject.to_s).to eq("1") } specify { expect(subject.inspect).to eq('#') } @@ -225,7 +239,16 @@ specify { expect(subject.try(:class)).to eq(subject.class) } specify { expect(subject.try(:name)).to eq(subject.name) } specify { expect(subject.try(:tag)).to eq(subject.tag) } - specify { expect(subject.try(:value)).to eq(subject.value) } + + context 'deprecated' do + around do |example| + # this method is deprecated + ::Protobuf.deprecator.silence(&example) + end + + specify { expect(subject.try(:value)).to eq(subject.value) } + end + specify { expect(subject.try(:to_i)).to eq(subject.to_i) } specify { expect(subject.try(:to_int)).to eq(subject.to_int) } specify { subject.try { |yielded| expect(yielded).to eq(subject) } } diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index de42520f..e882433b 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -4,7 +4,12 @@ describe ::Protobuf::Lifecycle do subject { described_class } - before(:each) do + around do |example| + # this entire class is deprecated + ::Protobuf.deprecator.silence(&example) + end + + before do ::ActiveSupport::Notifications.notifier = ::ActiveSupport::Notifications::Fanout.new end From 9c615958324cd3c11e6b1b93b637304199bb3711 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:42:45 -0800 Subject: [PATCH 0843/1191] Add pry debugger gems --- .rubocop.yml | 3 +++ protobuf.gemspec | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 33450227..b509a16c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ inherit_from: .rubocop_todo.yml +Lint/EndAlignment: + AlignWith: variable + Lint/Loop: Enabled: false diff --git a/protobuf.gemspec b/protobuf.gemspec index 3549a82f..463c0224 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -25,7 +25,6 @@ require "protobuf/version" s.add_dependency 'thread_safe' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'pry' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' s.add_development_dependency 'rubocop' @@ -33,6 +32,18 @@ require "protobuf/version" s.add_development_dependency 'timecop' s.add_development_dependency 'yard' + # debuggers only work in MRI + if RUBY_ENGINE.to_sym == :ruby + # we don't support MRI < 1.9.3 + pry_debugger = if RUBY_VERSION < '2.0.0' + 'pry-debugger' + else + 'pry-byebug' + end + + s.add_development_dependency pry_debugger + s.add_development_dependency 'pry-stack_explorer' + end + s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby - s.add_development_dependency 'pry-nav' unless RUBY_ENGINE.to_sym == :rbx end From db4fd435293ff2d7263b1d128d2f0222b3a13a6e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 16:39:46 -0800 Subject: [PATCH 0844/1191] Suppress more noisy test output --- spec/lib/protobuf/generators/base_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 82ffd269..668b3b1d 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -74,6 +74,7 @@ def compile context 'when tags are missing in the range' do it 'prints a warning' do + expect(::Protobuf::CodeGenerator).to receive(:print_tag_warning_suppress) expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) described_class.validate_tags("FooBar", [1, 2, 4, 5]) end From 4e383bfe3ab249a3381141fd9133dfb6f3eb515e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:02:20 -0800 Subject: [PATCH 0845/1191] Disable RSpec monkey patching --- spec/bin/protoc-gen-ruby_spec.rb | 2 +- spec/encoding/all_types_spec.rb | 2 +- spec/encoding/extreme_values_spec.rb | Bin 1358 -> 1364 bytes spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/cli_spec.rb | 2 +- spec/lib/protobuf/code_generator_spec.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 2 +- spec/lib/protobuf/field/float_field_spec.rb | 2 +- spec/lib/protobuf/field/int32_field_spec.rb | 2 +- spec/lib/protobuf/field/string_field_spec.rb | 2 +- spec/lib/protobuf/field_spec.rb | 2 +- spec/lib/protobuf/generators/base_spec.rb | 2 +- .../generators/enum_generator_spec.rb | 2 +- .../generators/extension_generator_spec.rb | 2 +- .../generators/field_generator_spec.rb | 2 +- .../generators/file_generator_spec.rb | 2 +- .../generators/service_generator_spec.rb | 2 +- spec/lib/protobuf/lifecycle_spec.rb | 2 +- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf/optionable_spec.rb | 2 +- spec/lib/protobuf/rpc/client_spec.rb | 2 +- spec/lib/protobuf/rpc/connector_spec.rb | 2 +- spec/lib/protobuf/rpc/connectors/base_spec.rb | 2 +- .../protobuf/rpc/connectors/common_spec.rb | 2 +- .../protobuf/rpc/connectors/socket_spec.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- .../rpc/middleware/exception_handler_spec.rb | 2 +- .../protobuf/rpc/middleware/logger_spec.rb | 2 +- .../rpc/middleware/request_decoder_spec.rb | 2 +- .../rpc/middleware/response_encoder_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/server_spec.rb | 2 +- .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/worker_spec.rb | 2 +- .../protobuf/rpc/service_directory_spec.rb | 2 +- .../protobuf/rpc/service_dispatcher_spec.rb | 2 +- spec/lib/protobuf/rpc/service_filters_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 2 +- spec/lib/protobuf/rpc/stat_spec.rb | 2 +- spec/lib/protobuf_spec.rb | 2 +- spec/spec_helper.rb | 2 ++ 42 files changed, 43 insertions(+), 41 deletions(-) diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb index cbbce0da..1df8b155 100644 --- a/spec/bin/protoc-gen-ruby_spec.rb +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/code_generator' -describe 'protoc-gen-ruby' do +RSpec.describe 'protoc-gen-ruby' do let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) } let(:package) { 'test' } let(:request_bytes) do diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 411a7a55..d56970fb 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ::Protobuf do +RSpec.describe ::Protobuf do it "correctly encodes all types" do message = GoogleUnittest::TestAllTypes.new( optional_int32: 101, diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 39aa70d11d5507e16d460101de0cd74c967d8655..ded4fb02c2df33c6fb8798d5846630806c33659a 100644 GIT binary patch delta 17 YcmX@db%kq!I9pI~L29zzMsagi05=l_a{vGU delta 10 Rcmcb@b&hL-_(oZCRsa^m184vM diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 6b034845..e46c36ae 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'spec/support/test/resource_service' -describe 'Functional Socket Client' do +RSpec.describe 'Functional Socket Client' do before(:all) do load "protobuf/socket.rb" @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 18d1941b..8996973d 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -3,7 +3,7 @@ require 'spec/support/test/resource_service' require 'protobuf/rpc/service_directory' -describe 'Functional ZMQ Client' do +RSpec.describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" @runner = ::Protobuf::Rpc::ZmqRunner.new( diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index b0bcb5af..0c716bf2 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/cli' -describe ::Protobuf::CLI do +RSpec.describe ::Protobuf::CLI do let(:app_file) do File.expand_path('../../../support/test_app_file.rb', __FILE__) diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index b41849d2..48115829 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/code_generator' -describe ::Protobuf::CodeGenerator do +RSpec.describe ::Protobuf::CodeGenerator do # Some constants to shorten things up DESCRIPTOR = ::Google::Protobuf diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index d2f3ef27..399bd814 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Enum do +RSpec.describe Protobuf::Enum do describe 'class dsl' do let(:name) { :THREE } diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb index 7bda8a33..a007871f 100644 --- a/spec/lib/protobuf/field/float_field_spec.rb +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Field::FloatField do +RSpec.describe Protobuf::Field::FloatField do class SomeFloatMessage < ::Protobuf::Message optional :float, :some_float, 1 diff --git a/spec/lib/protobuf/field/int32_field_spec.rb b/spec/lib/protobuf/field/int32_field_spec.rb index 53281e23..5c1ff70b 100644 --- a/spec/lib/protobuf/field/int32_field_spec.rb +++ b/spec/lib/protobuf/field/int32_field_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Field::Int32Field do +RSpec.describe Protobuf::Field::Int32Field do it_behaves_like :packable_field, described_class diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index 24318531..f403c027 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ::Protobuf::Field::StringField do +RSpec.describe ::Protobuf::Field::StringField do describe '#encode' do context 'when a repeated string field contains frozen strings' do diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index 4dafd9f5..a8efb781 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/field' -describe ::Protobuf::Field do +RSpec.describe ::Protobuf::Field do describe '.build' do pending diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 668b3b1d..f6bb027b 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -3,7 +3,7 @@ require 'protobuf/code_generator' require 'protobuf/generators/base' -describe ::Protobuf::Generators::Base do +RSpec.describe ::Protobuf::Generators::Base do subject { described_class.new(double) } diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 086cb4a2..0d63ff2d 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/enum_generator' -describe ::Protobuf::Generators::EnumGenerator do +RSpec.describe ::Protobuf::Generators::EnumGenerator do let(:values) do [ diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index b3f68c8d..55eb98ad 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -3,7 +3,7 @@ require 'protobuf/code_generator' require 'protobuf/generators/extension_generator' -describe ::Protobuf::Generators::ExtensionGenerator do +RSpec.describe ::Protobuf::Generators::ExtensionGenerator do let(:field_descriptors) do [ diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 7ba88536..246e4649 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/field_generator' -describe ::Protobuf::Generators::FieldGenerator do +RSpec.describe ::Protobuf::Generators::FieldGenerator do let(:label_enum) { :LABEL_OPTIONAL } let(:name) { 'foo_bar' } diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 6560cf8d..3374d75e 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/file_generator' -describe ::Protobuf::Generators::FileGenerator do +RSpec.describe ::Protobuf::Generators::FileGenerator do let(:base_descriptor_fields) { { :name => 'test/foo.proto' } } let(:descriptor_fields) { base_descriptor_fields } diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 03622318..c3500877 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/service_generator' -describe ::Protobuf::Generators::ServiceGenerator do +RSpec.describe ::Protobuf::Generators::ServiceGenerator do let(:methods) do [ diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index e882433b..d1414477 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/lifecycle' -describe ::Protobuf::Lifecycle do +RSpec.describe ::Protobuf::Lifecycle do subject { described_class } around do |example| diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 48458e95..8581fa50 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Protobuf::Message do +RSpec.describe Protobuf::Message do describe '.decode' do let(:message) { ::Test::Resource.new(:name => "Jim") } diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 056f9092..e3428f64 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/optionable' -describe 'Optionable' do +RSpec.describe 'Optionable' do describe '.set_option' do before(:all) do diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index cd2bfe13..8bdefc02 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'spec/support/test/resource_service' -describe Protobuf::Rpc::Client do +RSpec.describe Protobuf::Rpc::Client do before(:each) do load 'protobuf/socket.rb' end diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index 4092ce0f..1d433b49 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/socket' require 'protobuf/zmq' -describe ::Protobuf::Rpc::Connector do +RSpec.describe ::Protobuf::Rpc::Connector do describe '.connector_for_client(true)' do subject { described_class.connector_for_client } diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 5a9945ae..2c5fc98d 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Connectors::Base do +RSpec.describe Protobuf::Rpc::Connectors::Base do let(:options) do { :timeout => 60 } diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 54ab8c33..de98c551 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/rpc/service' -describe Protobuf::Rpc::Connectors::Common do +RSpec.describe Protobuf::Rpc::Connectors::Common do let(:common_class) do Class.new(Protobuf::Rpc::Connectors::Base) do include Protobuf::Rpc::Connectors::Common diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 635c6590..12bd15d9 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/socket' -shared_examples "a Protobuf Connector" do +RSpec.shared_examples "a Protobuf Connector" do subject { described_class.new({}) } context "API" do @@ -13,7 +13,7 @@ end end -describe Protobuf::Rpc::Connectors::Socket do +RSpec.describe Protobuf::Rpc::Connectors::Socket do subject { described_class.new({}) } it_behaves_like "a Protobuf Connector" diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 53a918b0..b15e94be 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/zmq' -describe ::Protobuf::Rpc::Connectors::Zmq do +RSpec.describe ::Protobuf::Rpc::Connectors::Zmq do subject { described_class.new(options) } let(:options) do diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index 8ebe422b..0a71e43d 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::ExceptionHandler do +RSpec.describe Protobuf::Rpc::Middleware::ExceptionHandler do let(:app) { proc { |env| env } } let(:env) { Protobuf::Rpc::Env.new } diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index 8ae5959d..1c5ddd66 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::Logger do +RSpec.describe Protobuf::Rpc::Middleware::Logger do let(:app) { proc { |inner_env| inner_env } } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index f95a05ab..3132c85c 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::RequestDecoder do +RSpec.describe Protobuf::Rpc::Middleware::RequestDecoder do let(:app) { proc { |env| env } } let(:client_host) { 'client_host.test.co' } let(:env) do diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 00ab46cd..7189a31a 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::ResponseEncoder do +RSpec.describe Protobuf::Rpc::Middleware::ResponseEncoder do let(:app) { proc { |env| env.response = response; env } } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 6497641c..d4947ea3 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -3,7 +3,7 @@ require 'protobuf/rpc/servers/socket_runner' require 'protobuf/socket' -describe Protobuf::Rpc::Socket::Server do +RSpec.describe Protobuf::Rpc::Socket::Server do before(:each) do load 'protobuf/socket.rb' end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 215230ba..97736064 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/rpc/servers/zmq/server' -describe Protobuf::Rpc::Zmq::Server do +RSpec.describe Protobuf::Rpc::Zmq::Server do subject { described_class.new(options) } let(:options) do diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index be2bdf62..002ac056 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -4,7 +4,7 @@ class UtilTest include ::Protobuf::Rpc::Zmq::Util end -describe ::Protobuf::Rpc::Zmq::Util do +RSpec.describe ::Protobuf::Rpc::Zmq::Util do before(:each) do load 'protobuf/zmq.rb' end diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 1f779917..71c89282 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ::Protobuf::Rpc::Zmq::Worker do +RSpec.describe ::Protobuf::Rpc::Zmq::Worker do before(:each) do load 'protobuf/zmq.rb' diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 6f39ae20..d1d2aea4 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/rpc/service_directory' -describe ::Protobuf::Rpc::ServiceDirectory do +RSpec.describe ::Protobuf::Rpc::ServiceDirectory do subject { described_class.instance } let(:echo_server) do diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index ca6f08df..5bf27318 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/rpc/service_dispatcher' -describe Protobuf::Rpc::ServiceDispatcher do +RSpec.describe Protobuf::Rpc::ServiceDispatcher do let(:app) { proc { |env| env } } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index ebedd21b..97cc5b2d 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -27,7 +27,7 @@ def self.clear_filters! end end -describe Protobuf::Rpc::ServiceFilters do +RSpec.describe Protobuf::Rpc::ServiceFilters do let(:params) { {} } subject { FilterTest.new(params) } after(:each) { FilterTest.clear_filters! } diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 27518464..365d3c5f 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'spec/support/test/resource_service' -describe Protobuf::Rpc::Service do +RSpec.describe Protobuf::Rpc::Service do context 'class methods' do subject { Test::ResourceService } diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index eafb3dd7..f23ce783 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -2,7 +2,7 @@ require 'timecop' require 'active_support/core_ext/numeric/time' -describe ::Protobuf::Rpc::Stat do +RSpec.describe ::Protobuf::Rpc::Stat do before(:all) do unless defined?(BarService) diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 0f238013..314909c6 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf' -describe ::Protobuf do +RSpec.describe ::Protobuf do describe '.client_host' do after { ::Protobuf.client_host = nil } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 216c9415..17a01a55 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,6 +29,8 @@ support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) Dir[support_proto_glob].each { |proto_file| require proto_file } +RSpec.configure(&:disable_monkey_patching!) + ::Protobuf::Rpc::Client.class_eval do def ==(other) connector.options == other.options && \ From fd0315a6b2dfc1d597d42b073019cfebbba67085 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:04:42 -0800 Subject: [PATCH 0846/1191] Remove old comment --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 17a01a55..ddee0881 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,6 @@ require 'bundler' Bundler.setup :default, :development, :test require 'pry' -# require 'rspec/its' $LOAD_PATH << ::File.expand_path('../..', __FILE__) $LOAD_PATH << ::File.expand_path('../support', __FILE__) From 6e5de44d094949b8aa779db0a1d17e7d1d82e8b7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 09:47:52 -0800 Subject: [PATCH 0847/1191] Style/StringLiteralsInInterpolation --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/servers/zmq/util.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 600b1fc8..ba1c7755 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,12 +99,6 @@ Style/NumericLiterals: Style/StringLiterals: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/StringLiteralsInInterpolation: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: WordRegex. diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index ee5e0f83..931cc0af 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -21,7 +21,7 @@ def self.included(base) def zmq_error_check(return_code, source = nil) unless ::ZMQ::Util.resultcode_ok?(return_code) fail <<-ERROR - Last ZMQ API call #{source ? "to #{source}" : ""} failed with "#{::ZMQ::Util.error_string}". + Last ZMQ API call #{source ? "to #{source}" : ''} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR From ff5a48f5c0de875e5ceb5bd37824928b1b5dd40b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 10:00:21 -0800 Subject: [PATCH 0848/1191] Style/MultilineOperationIndentation --- .rubocop_todo.yml | 6 ------ spec/lib/protobuf/rpc/service_directory_spec.rb | 5 +++-- spec/lib/protobuf/rpc/service_spec.rb | 10 +++++----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ba1c7755..21b3d144 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -77,12 +77,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MultilineOperationIndentation: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index d1d2aea4..ea039ec8 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -57,8 +57,9 @@ def expect_event_trigger(event) expect(::ActiveSupport::Notifications).to receive(:instrument) - .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))) - .once + .with(event, hash_including( + :listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing), + )).once end def send_beacon(type, server) diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 365d3c5f..4c1fcf37 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -64,11 +64,11 @@ it 'initializes a client object for this service' do client = double('client') expect(::Protobuf::Rpc::Client).to receive(:new) - .with(hash_including( - :service => subject, - :host => subject.host, - :port => subject.port, - )).and_return(client) + .with(hash_including( + :service => subject, + :host => subject.host, + :port => subject.port, + )).and_return(client) expect(subject.client).to eq client end end From ddf7e0a54d31d72ad7961ef6b317d00ed55cd9d1 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 10:01:42 -0800 Subject: [PATCH 0849/1191] Style/EmptyLinesAroundMethodBody --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/servers/zmq_runner.rb | 1 - 2 files changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 21b3d144..db40205b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -55,11 +55,6 @@ Style/DoubleNegation: Style/EmptyLinesAroundClassBody: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/EmptyLinesAroundMethodBody: - Enabled: false - # Offense count: 66 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 5d213640..657986a7 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -14,7 +14,6 @@ def initialize(options) else fail "Cannot parser Zmq Server - server options" end - end def run From 335e2ab3ad08dee7ef92f2617650a32b175dc457 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:01:13 -0800 Subject: [PATCH 0850/1191] Style/Next --- .rubocop_todo.yml | 5 ---- lib/protobuf/generators/group_generator.rb | 28 +++++++++++----------- lib/protobuf/rpc/servers/zmq/server.rb | 13 +++++----- lib/protobuf/rpc/servers/zmq/worker.rb | 12 ++++------ 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index db40205b..6ba6256f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -72,11 +72,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 3 -# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. -Style/Next: - Enabled: false - # Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index ddff717f..67eeb688 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -80,25 +80,25 @@ def add_services(service_descriptors) def compile @order.each do |type| items = @groups[type] - if items.count > 0 - item_handler = @handlers[type] + next if items.empty? - item_header = @headers[type] - header(item_header) if item_header + item_handler = @handlers[type] - item_comment = @comments[type] - comment(item_comment) if item_comment + item_header = @headers[type] + header(item_header) if item_header - items.each do |item| - if item_handler - puts item_handler.call(item) - else - print item.to_s - end - end + item_comment = @comments[type] + comment(item_comment) if item_comment - puts if type == :message_declaration + items.each do |item| + if item_handler + puts item_handler.call(item) + else + print item.to_s + end end + + puts if type == :message_declaration end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 87f663cb..1e1e12bf 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -251,14 +251,13 @@ def wait_for_shutdown_signal start_missing_workers end - if broadcast_heartbeat? - if all_workers_busy? && options[:broadcast_busy] - broadcast_flatline - else - broadcast_heartbeat - end - end + next unless broadcast_heartbeat? + if all_workers_busy? && options[:broadcast_busy] + broadcast_flatline + else + broadcast_heartbeat + end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index e0c28357..63f1df3c 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -46,13 +46,11 @@ def run loop do rc = poller.poll(500) - # The server was shutdown and no requests are pending - break if rc == 0 && !running? - - # Something went wrong - break if rc == -1 - - if rc > 0 + if rc == 0 && !running? + break # The server was shutdown and no requests are pending + elsif rc == -1 + break # Something went wrong + elsif rc > 0 ::Thread.current[:busy] = true process_request ::Thread.current[:busy] = false From e2b50d6182b3db0485ee8ebe34d1e2cbbc728fc2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:09:21 -0800 Subject: [PATCH 0851/1191] Style/HashSyntax Standardize on hash_rockets --- .rubocop.yml | 3 + .rubocop_todo.yml | 6 -- spec/encoding/all_types_spec.rb | 166 +++++++++++++++++--------------- spec/lib/protobuf/cli_spec.rb | 2 +- 4 files changed, 94 insertions(+), 83 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b509a16c..2f36863f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,9 @@ Style/FileName: Exclude: - '**/protoc-gen-ruby*' +Style/HashSyntax: + EnforcedStyle: hash_rockets + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6ba6256f..23cc0689 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -66,12 +66,6 @@ Style/EmptyLinesAroundModuleBody: Style/GuardClause: Enabled: false -# Offense count: 690 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/HashSyntax: - Enabled: false - # Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index d56970fb..01b772a3 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -3,82 +3,96 @@ RSpec.describe ::Protobuf do it "correctly encodes all types" do message = GoogleUnittest::TestAllTypes.new( - optional_int32: 101, - optional_int64: 102, - optional_uint32: 103, - optional_uint64: 104, - optional_sint32: 105, - optional_sint64: 106, - optional_fixed32: 107, - optional_fixed64: 108, - optional_sfixed32: 109, - optional_sfixed64: 110, - optional_float: 111, - optional_double: 112, - optional_bool: true, - optional_string: "115", - optional_bytes: "116", - optional_nested_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 118), - optional_foreign_message: GoogleUnittest::ForeignMessage.new(c: 119), - optional_import_message: GoogleUnittestImport::ImportMessage.new(d: 120), - optional_nested_enum: GoogleUnittest::TestAllTypes::NestedEnum::BAZ, - optional_foreign_enum: GoogleUnittest::ForeignEnum::FOREIGN_BAZ, - optional_import_enum: GoogleUnittestImport::ImportEnum::IMPORT_BAZ, - optional_string_piece: "124", - optional_cord: "125", - optional_public_import_message: GoogleUnittestImport::PublicImportMessage.new(e: 126), - optional_lazy_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 127), - repeated_int32: [201, 301], - repeated_int64: [202, 302], - repeated_uint32: [203, 303], - repeated_uint64: [204, 304], - repeated_sint32: [205, 305], - repeated_sint64: [206, 306], - repeated_fixed32: [207, 307], - repeated_fixed64: [208, 308], - repeated_sfixed32: [209, 309], - repeated_sfixed64: [210, 310], - repeated_float: [211, 311], - repeated_double: [212, 312], - repeated_bool: [true, false], - repeated_string: ["215", "315"], - repeated_bytes: ["216", "316"], - repeated_nested_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 218), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 318)], - repeated_foreign_message: [::GoogleUnittest::ForeignMessage.new(c: 219), - ::GoogleUnittest::ForeignMessage.new(c: 319)], - repeated_import_message: [::GoogleUnittestImport::ImportMessage.new(d: 220), - ::GoogleUnittestImport::ImportMessage.new(d: 320)], - repeated_nested_enum: [::GoogleUnittest::TestAllTypes::NestedEnum::BAR, - ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ], - repeated_foreign_enum: [::GoogleUnittest::ForeignEnum::FOREIGN_BAR, - ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ], - repeated_import_enum: [::GoogleUnittestImport::ImportEnum::IMPORT_BAR, - ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ], - repeated_string_piece: ["224", "324"], - repeated_cord: ["225", "325"], - repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 227), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 327)], - default_int32: 401, - default_int64: 402, - default_uint32: 403, - default_uint64: 404, - default_sint32: 405, - default_sint64: 406, - default_fixed32: 407, - default_fixed64: 408, - default_sfixed32: 409, - default_sfixed64: 410, - default_float: 411, - default_double: 412, - default_bool: false, - default_string: "415", - default_bytes: "416", - default_nested_enum: ::GoogleUnittest::TestAllTypes::NestedEnum::FOO, - default_foreign_enum: ::GoogleUnittest::ForeignEnum::FOREIGN_FOO, - default_import_enum: ::GoogleUnittestImport::ImportEnum::IMPORT_FOO, - default_string_piece: "424", - default_cord: "425", + :optional_int32 => 101, + :optional_int64 => 102, + :optional_uint32 => 103, + :optional_uint64 => 104, + :optional_sint32 => 105, + :optional_sint64 => 106, + :optional_fixed32 => 107, + :optional_fixed64 => 108, + :optional_sfixed32 => 109, + :optional_sfixed64 => 110, + :optional_float => 111, + :optional_double => 112, + :optional_bool => true, + :optional_string => "115", + :optional_bytes => "116", + :optional_nested_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 118), + :optional_foreign_message => GoogleUnittest::ForeignMessage.new(:c => 119), + :optional_import_message => GoogleUnittestImport::ImportMessage.new(:d => 120), + :optional_nested_enum => GoogleUnittest::TestAllTypes::NestedEnum::BAZ, + :optional_foreign_enum => GoogleUnittest::ForeignEnum::FOREIGN_BAZ, + :optional_import_enum => GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + :optional_string_piece => "124", + :optional_cord => "125", + :optional_public_import_message => GoogleUnittestImport::PublicImportMessage.new(:e => 126), + :optional_lazy_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 127), + :repeated_int32 => [201, 301], + :repeated_int64 => [202, 302], + :repeated_uint32 => [203, 303], + :repeated_uint64 => [204, 304], + :repeated_sint32 => [205, 305], + :repeated_sint64 => [206, 306], + :repeated_fixed32 => [207, 307], + :repeated_fixed64 => [208, 308], + :repeated_sfixed32 => [209, 309], + :repeated_sfixed64 => [210, 310], + :repeated_float => [211, 311], + :repeated_double => [212, 312], + :repeated_bool => [true, false], + :repeated_string => ["215", "315"], + :repeated_bytes => ["216", "316"], + :repeated_nested_message => [ + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 218), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 318), + ], + :repeated_foreign_message => [ + ::GoogleUnittest::ForeignMessage.new(:c => 219), + ::GoogleUnittest::ForeignMessage.new(:c => 319), + ], + :repeated_import_message => [ + ::GoogleUnittestImport::ImportMessage.new(:d => 220), + ::GoogleUnittestImport::ImportMessage.new(:d => 320), + ], + :repeated_nested_enum => [ + ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, + ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ, + ], + :repeated_foreign_enum => [ + ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, + ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ, + ], + :repeated_import_enum => [ + ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, + ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + ], + :repeated_string_piece => ["224", "324"], + :repeated_cord => ["225", "325"], + :repeated_lazy_message => [ + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 227), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 327), + ], + :default_int32 => 401, + :default_int64 => 402, + :default_uint32 => 403, + :default_uint64 => 404, + :default_sint32 => 405, + :default_sint64 => 406, + :default_fixed32 => 407, + :default_fixed64 => 408, + :default_sfixed32 => 409, + :default_sfixed64 => 410, + :default_float => 411, + :default_double => 412, + :default_bool => false, + :default_string => "415", + :default_bytes => "416", + :default_nested_enum => ::GoogleUnittest::TestAllTypes::NestedEnum::FOO, + :default_foreign_enum => ::GoogleUnittest::ForeignEnum::FOREIGN_FOO, + :default_import_enum => ::GoogleUnittestImport::ImportEnum::IMPORT_FOO, + :default_string_piece => "424", + :default_cord => "425", ) data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__) diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 0c716bf2..0ff3a36e 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -14,7 +14,7 @@ end let(:zmq_runner) do - runner = double "ZmqRunner", register_signals: nil + runner = double("ZmqRunner", :register_signals => nil) allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner end From fd8b03b22d4caaca0697978bd65631313df3df7e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:26:29 -0800 Subject: [PATCH 0852/1191] Style/GuardClause --- .rubocop.yml | 3 ++ .rubocop_todo.yml | 5 --- lib/protobuf/generators/file_generator.rb | 24 +++++------- lib/protobuf/rpc/connectors/zmq.rb | 46 +++++++++++------------ lib/protobuf/rpc/servers/zmq/util.rb | 12 +++--- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2f36863f..a2e37f1f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,9 @@ Style/FileName: Exclude: - '**/protoc-gen-ruby*' +Style/GuardClause: + MinBodyLength: 4 + Style/HashSyntax: EnforcedStyle: hash_rockets diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 23cc0689..463ec257 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,11 +61,6 @@ Style/EmptyLinesAroundClassBody: Style/EmptyLinesAroundModuleBody: Enabled: false -# Offense count: 18 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Enabled: false - # Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 3a81e1f2..32016e0d 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -78,15 +78,11 @@ def map_extensions(descriptor, namespaces) @extension_fields[field_descriptor.extendee] << field_descriptor end - if descriptor.respond_to_has_and_present?(:message_type) - descriptor.message_type.each do |message_descriptor| - map_extensions(message_descriptor, (namespaces + [message_descriptor.name])) - end - end + [:message_type, :nested_type].each do |type| + next unless descriptor.respond_to_has_and_present?(type) - if descriptor.respond_to_has_and_present?(:nested_type) - descriptor.nested_type.each do |nested_descriptor| - map_extensions(nested_descriptor, (namespaces + [nested_descriptor.name])) + descriptor.public_send(type).each do |type_descriptor| + map_extensions(type_descriptor, (namespaces + [type_descriptor.name])) end end end @@ -106,15 +102,15 @@ def print_generic_requires end def print_import_requires - if descriptor.dependency.count > 0 - header "Imports" + return if descriptor.dependency.empty? - descriptor.dependency.each do |dependency| - print_require(convert_filename(dependency)) - end + header "Imports" - puts + descriptor.dependency.each do |dependency| + print_require(convert_filename(dependency)) end + + puts end def print_package(&block) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 8ed87637..5403541e 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -258,25 +258,15 @@ def zmq_context end def zmq_eagain_error_check(return_code, source) - unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - if ::ZMQ::Util.errno == ::ZMQ::EAGAIN - fail ZmqEagainError, <<-ERROR - Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + return if ::ZMQ::Util.resultcode_ok?(return_code || -1) - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - else - fail <<-ERROR - Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - end - end - end + if ::ZMQ::Util.errno == ::ZMQ::EAGAIN + fail ZmqEagainError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - def zmq_error_check(return_code, source) - unless ::ZMQ::Util.resultcode_ok?(return_code || -1) + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR + else fail <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". @@ -285,14 +275,24 @@ def zmq_error_check(return_code, source) end end + def zmq_error_check(return_code, source) + return if ::ZMQ::Util.resultcode_ok?(return_code || -1) + + fail <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR + end + def zmq_recoverable_error_check(return_code, source) - unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - fail ZmqRecoverableError, <<-ERROR - Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + return if ::ZMQ::Util.resultcode_ok?(return_code || -1) - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - end + fail ZmqRecoverableError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR end end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 931cc0af..2d0c9c8b 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -19,13 +19,13 @@ def self.included(base) end def zmq_error_check(return_code, source = nil) - unless ::ZMQ::Util.resultcode_ok?(return_code) - fail <<-ERROR - Last ZMQ API call #{source ? "to #{source}" : ''} failed with "#{::ZMQ::Util.error_string}". + return if ::ZMQ::Util.resultcode_ok?(return_code) - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - end + fail <<-ERROR + Last ZMQ API call #{source ? "to #{source}" : ''} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR end def log_signature From 0675eb49426a4c4cf8c0820276e793a86093f475 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:33:25 -0800 Subject: [PATCH 0853/1191] Remove spurious `begin` --- lib/protobuf/enum.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index c83e8215..16d414ab 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -205,11 +205,9 @@ def self.valid_tag?(tag) # by their :name. # def self.values - @values ||= begin - enums.each_with_object({}) do |enum, hash| - hash[enum.name] = enum - end - end + @values ||= enums.each_with_object({}) do |enum, hash| + hash[enum.name] = enum + end end ## From d0791796fbd02d1fadf7ee6bd283a91b5f462ca4 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 18:08:03 -0800 Subject: [PATCH 0854/1191] Remove unused module --- spec/support/server.rb | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/spec/support/server.rb b/spec/support/server.rb index dd0817a9..d78c4617 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -10,24 +10,6 @@ # Want to abort if server dies? Thread.abort_on_exception = true -module StubProtobufServerFactory - def self.build(delay) - new_server = Class.new(Protobuf::Rpc::Socket::Server) do - class << self - attr_accessor :sleep_interval - end - - def post_init - sleep self.class.sleep_interval - super - end - end - - new_server.sleep_interval = delay - new_server - end -end - class StubServer include Protobuf::Logging From 577db2d5cc55fcd90eb56c566d035650415ddbae Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 19:08:08 -0800 Subject: [PATCH 0855/1191] Clarify that this is a monkeypatch --- spec/support/test/resource_service.rb | 37 ++++++++++++--------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index 41e2f93a..d8642381 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -1,26 +1,23 @@ require ::File.expand_path('../resource.pb', __FILE__) -module Test - class ResourceService - - # request -> Test::ResourceFindRequest - # response -> Test::Resource - def find - response.name = request.name - response.status = request.active ? 1 : 0 - end +Test::ResourceService.class_eval do + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find + response.name = request.name + response.status = request.active ? 1 : 0 + end - # request -> Test::ResourceSleepRequest - # response -> Test::Resource - def find_with_sleep - sleep(request.sleep || 1) - response.name = 'Request should have timed out' - end + # request -> Test::ResourceSleepRequest + # response -> Test::Resource + def find_with_sleep + sleep(request.sleep || 1) + response.name = 'Request should have timed out' + end - # request -> Test::ResourceFindRequest - # response -> Test::Resource - def find_with_rpc_failed - rpc_failed('Find failed') - end + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find_with_rpc_failed + rpc_failed('Find failed') end end From 88f73d91d2a13db8dffb4bba376be7fbfa060337 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 00:02:50 -0800 Subject: [PATCH 0856/1191] Fix top-level constant warning --- spec/lib/protobuf/message_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 8581fa50..db4cd261 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -361,14 +361,16 @@ describe '#inspect' do let(:klass) do - Class.new(Protobuf::Message) do - EnumKlass = Class.new(Protobuf::Enum) do + Class.new(Protobuf::Message) do |klass| + enum_class = Class.new(Protobuf::Enum) do define :YAY, 1 end + klass.const_set(:EnumKlass, enum_class) + optional :string, :name, 1 repeated :int32, :counts, 2 - optional EnumKlass, :enum, 3 + optional enum_class, :enum, 3 end end @@ -376,8 +378,7 @@ it 'lists the fields' do proto = klass.new(:name => 'wooo', :counts => [1, 2, 3], :enum => klass::EnumKlass::YAY) - expect(proto.inspect).to eq \ - '#>' + expect(proto.inspect).to eq('#>') end end From 70efd5e8f55b11c7a62b0b5b56360785be502e56 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 00:04:10 -0800 Subject: [PATCH 0857/1191] Style --- spec/lib/protobuf/message_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index db4cd261..052b570e 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -407,10 +407,12 @@ end it 'recursively hashes a repeated set of messages' do - proto = Test::Nested.new(:multiple_resources => [ - Test::Resource.new(:name => 'Resource 1'), - Test::Resource.new(:name => 'Resource 2'), - ]) + proto = Test::Nested.new( + :multiple_resources => [ + Test::Resource.new(:name => 'Resource 1'), + Test::Resource.new(:name => 'Resource 2'), + ], + ) expect(proto.to_hash).to eq( :multiple_resources => [ From 98681adc59c85700b20e1d4161a0e3130922e3f4 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 19:07:53 -0800 Subject: [PATCH 0858/1191] Stricter params parsing --- spec/benchmark/tasks.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 899e882a..6a81bedf 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -39,7 +39,7 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) } end end end @@ -52,7 +52,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) } end end server.stop @@ -81,7 +81,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do - args[:number].to_i.times { Test::Resource.new(create_params) } + Integer(args[:number]).times { Test::Resource.new(create_params) } end puts args[:profile_output] @@ -92,7 +92,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do - args[:number].to_i.times { Test::Resource.new(create_params).serialize } + Integer(args[:number]).times { Test::Resource.new(create_params).serialize } end puts args[:profile_output] From 17ce496c60fe9d164d4ff46f861f928c2e66ac75 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:03:21 -0800 Subject: [PATCH 0859/1191] Consistent log signatures --- lib/protobuf/rpc/servers/socket/server.rb | 2 +- lib/protobuf/rpc/servers/socket/worker.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index b9e9c708..f912bc20 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -35,7 +35,7 @@ def cleanup_threads end def log_signature - @_log_signature ||= "server-#{self.class.name}" + @_log_signature ||= "[server-#{self.class.name}]" end def new_worker(socket) diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index b64ee8db..6297d20a 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -44,7 +44,7 @@ def send_data(data) end def log_signature - @_log_signature ||= "server-#{self.class}-#{object_id}" + @_log_signature ||= "[server-#{self.class}-#{object_id}]" end def socket_writable? From ead37315f2cb59c5465725eb07dce8d044e2821d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 00:53:28 -0800 Subject: [PATCH 0860/1191] Randomize ports --- spec/benchmark/tasks.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 6a81bedf..53c3c322 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -34,8 +34,10 @@ def benchmark_wrapper(global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |_server| - client = ::Test::ResourceService.client(:port => 9399) + port = 1000 + Kernel.rand(2**16 - 1000) + + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do |_server| + client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do @@ -47,8 +49,11 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" - StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - client = ::Test::ResourceService.client(:port => 9399) + + port = 1000 + Kernel.rand(2**16 - 1000) + + StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do |server| + client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do From 0095cd651f2efbd86356a51fe4c1623197347c3b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:22:44 -0800 Subject: [PATCH 0861/1191] Fix the benchmarks --- lib/protobuf/rpc/connectors/socket.rb | 4 +- lib/protobuf/rpc/servers/socket/server.rb | 140 +++++++++++----------- spec/benchmark/tasks.rb | 5 +- spec/support/server.rb | 66 +++++----- 4 files changed, 106 insertions(+), 109 deletions(-) diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 26fd0e97..4c060f3e 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -28,8 +28,8 @@ def close_connection end def connect_to_rpc_server - @socket = TCPSocket.new(options[:host], options[:port]) - logger.debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } + @socket ||= TCPSocket.new(options[:host], options[:port]) + logger.debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } end # Method to determine error state, must be used with Connector api diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index f912bc20..72b07a87 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -1,4 +1,5 @@ -require 'protobuf/rpc/server' +require 'set' + require 'protobuf/rpc/servers/socket/worker' module Protobuf @@ -9,29 +10,48 @@ class Server AUTO_COLLECT_TIMEOUT = 5 # seconds + private + + attr_accessor :threshold, :host, :port, :backlog + attr_writer :running + + public + + attr_reader :running + alias_method :running?, :running + def initialize(options) - @options = options + self.running = false + self.host = options.fetch(:host) + self.port = options.fetch(:port) + self.backlog = options.fetch(:backlog, 100) + self.threshold = options.fetch(:threshold, 100) + end + + def threads + @threads ||= [] + end + + def working + @working ||= Set.new end def cleanup? - # every 10 connections run a cleanup routine after closing the response - @threads.size > (@threshold - 1) && (@threads.size % @threshold) == 0 + # every `threshold` connections run a cleanup routine after closing the response + threads.size > 0 && threads.size % threshold == 0 end def cleanup_threads - logger.debug { sign_message("Thread cleanup - #{@threads.size} - start") } - - @threads = @threads.select do |t| - if t[:thread].alive? - true - else - t[:thread].join - @working.delete(t[:socket]) - false + logger.debug { sign_message("Thread cleanup - #{threads.size} - start") } + + threads.delete_if do |hash| + unless (thread = hash.fetch(:thread)).alive? + thread.join + working.delete(hash.fetch(:socket)) end end - logger.debug { sign_message("Thread cleanup - #{@threads.size} - complete") } + logger.debug { sign_message("Thread cleanup - #{threads.size} - complete") } end def log_signature @@ -48,68 +68,54 @@ def new_worker(socket) def run logger.debug { sign_message("Run") } - host = @options[:host] - port = @options[:port] - backlog = @options[:backlog] - @threshold = @options[:threshold] - - @threads = [] - @server = ::TCPServer.new(host, port) - fail "The server was unable to start properly." if @server.closed? - - @server.listen(backlog) - @working = [] - @listen_fds = [@server] - @running = true - - while running? - logger.debug { sign_message("Waiting for connections") } - ready_cnxns = begin - IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) - rescue IOError - nil - end - if ready_cnxns - cnxns = ready_cnxns.first - cnxns.each do |client| - case - when !running? then - # no-op - when client == @server then - logger.debug { sign_message("Accepted new connection") } - client, _sockaddr = @server.accept - @listen_fds << client - else - unless @working.include?(client) - @working << @listen_fds.delete(client) - logger.debug { sign_message("Working") } - @threads << { :thread => new_worker(client), :socket => client } - - cleanup_threads if cleanup? + server = ::TCPServer.new(host, port) + fail "The server was unable to start properly." if server.closed? + + begin + server.listen(backlog) + listen_fds = [server] + self.running = true + + while running? + logger.debug { sign_message("Waiting for connections") } + ready_cnxns = begin + IO.select(listen_fds, [], [], AUTO_COLLECT_TIMEOUT) + rescue IOError + nil + end + + if ready_cnxns + ready_cnxns.first.each do |client| + case + when !running? + # no-op + when client == server + logger.debug { sign_message("Accepted new connection") } + client, _sockaddr = server.accept + listen_fds << client + else + unless working.include?(client) + working << listen_fds.delete(client) + logger.debug { sign_message("Working") } + threads << { :thread => new_worker(client), :socket => client } + + cleanup_threads if cleanup? + end end end + else + # Run a cleanup if select times out while waiting + cleanup_threads if threads.size > 1 end - else - # Run a cleanup if select times out while waiting - cleanup_threads if @threads.size > 1 end + ensure + server.close end - - rescue Errno::EADDRINUSE - raise - rescue - # Closing the server causes the loop to raise an exception here - raise # if running? - end - - def running? - !!@running end def stop - @running = false - @server.try(:close) + self.running = false end end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 53c3c322..e6710d6c 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -36,7 +36,7 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) port = 1000 + Kernel.rand(2**16 - 1000) - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do |_server| + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| @@ -52,7 +52,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) port = 1000 + Kernel.rand(2**16 - 1000) - StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do |server| + StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| @@ -60,7 +60,6 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) } end end - server.stop end end diff --git a/spec/support/server.rb b/spec/support/server.rb index d78c4617..d4f30c7d 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,4 +1,7 @@ require 'ostruct' + +require 'active_support/core_ext/hash/reverse_merge' + require 'protobuf/logging' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/server' @@ -13,57 +16,46 @@ class StubServer include Protobuf::Logging - attr_accessor :options + private + + attr_accessor :options, :runner, :runner_thread + + public def initialize(options = {}) - @running = true - @options = OpenStruct.new({ :host => "127.0.0.1", - :port => 9399, - :worker_port => 9400, - :delay => 0, - :server => Protobuf::Rpc::Socket::Server }.merge(options)) + self.options = OpenStruct.new( + options.reverse_merge( + :host => '127.0.0.1', + :port => 9399, + :worker_port => 9400, + :delay => 0, + :server => Protobuf::Rpc::Socket::Server, + ), + ) start yield self ensure - stop if @running + stop end def start - case - when @options.server == Protobuf::Rpc::Zmq::Server - start_zmq_server - else - start_socket_server - end - logger.debug { sign_message("Server started #{@options.host}:#{@options.port}") } - end + runner_class = { + ::Protobuf::Rpc::Zmq::Server => ::Protobuf::Rpc::ZmqRunner, + ::Protobuf::Rpc::Socket::Server => ::Protobuf::Rpc::SocketRunner, + }.fetch(options.server) - def start_socket_server - @sock_runner = ::Protobuf::Rpc::SocketRunner.new(options) - @sock_thread = Thread.new(@sock_runner) { |runner| runner.run } - @sock_thread.abort_on_exception = true # Set for testing purposes - Thread.pass until @sock_runner.running? - end + self.runner = runner_class.new(options) + self.runner_thread = Thread.new(runner, &:run) + runner_thread.abort_on_exception = true # Set for testing purposes + Thread.pass until runner.running? - def start_zmq_server - @zmq_runner = ::Protobuf::Rpc::ZmqRunner.new(options) - @zmq_thread = Thread.new(@zmq_runner) { |runner| runner.run } - @zmq_thread.abort_on_exception = true # Set for testing purposes - Thread.pass until @zmq_runner.running? + logger.debug { sign_message("Server started #{options.host}:#{options.port}") } end def stop - case - when @options.server == Protobuf::Rpc::Zmq::Server then - @zmq_runner.try :stop - @zmq_thread.join if @zmq_thread - else - @sock_runner.stop - @sock_thread.join if @sock_thread - end - - @running = false + runner.stop + runner_thread.join end def log_signature From 37119ca2ee962b8f4f143aa0300f7422648ac2b9 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:36:21 -0800 Subject: [PATCH 0862/1191] Other rubies need pry too --- protobuf.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protobuf.gemspec b/protobuf.gemspec index 463c0224..e2b4b5df 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -43,6 +43,8 @@ require "protobuf/version" s.add_development_dependency pry_debugger s.add_development_dependency 'pry-stack_explorer' + else + s.add_development_dependency 'pry' end s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby From 4cbb1f7cb98bb5a63875f4fc0cdf0c8109feffa7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:22:25 -0800 Subject: [PATCH 0863/1191] Remove useless ivars --- lib/protobuf/cli.rb | 57 ++++++++++++----------- lib/protobuf/code_generator.rb | 16 ++++--- lib/protobuf/encoder.rb | 10 +++- lib/protobuf/enum.rb | 14 ++++-- lib/protobuf/rpc/servers/socket_runner.rb | 16 +++++-- 5 files changed, 68 insertions(+), 45 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 222a55de..3fe340bf 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -11,7 +11,11 @@ class CLI < ::Thor include ::Thor::Actions include ::Protobuf::Logging - attr_accessor :runner, :mode + attr_accessor :runner, :mode, :exit_requested + + no_commands do + alias_method :exit_requested?, :exit_requested + end default_task :start @@ -102,27 +106,28 @@ def configure_logger # Re-write the $0 var to have a nice process name in ps. def configure_process_name(app_file) debug_say('Configuring process name') - $0 = "rpc_server --#{@runner_mode} #{options.host}:#{options.port} #{app_file}" + $0 = "rpc_server --#{mode} #{options.host}:#{options.port} #{app_file}" end # Configure the mode of the server and the runner class. def configure_runner_mode debug_say('Configuring runner mode') - if multi_mode? + self.mode = if multi_mode? say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) - @runner_mode = :socket + :socket elsif options.zmq? - @runner_mode = :zmq - else + :zmq + else # rubocop:disable Style/ElseAlignment + # above: https://github.com/bbatsov/rubocop/pull/1470/files case server_type = ENV["PB_SERVER_TYPE"] when nil, /socket/i - @runner_mode = :socket + :socket when /zmq/i - @runner_mode = :zmq + :zmq else say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow - @runner_mode = :socket + :socket end end end @@ -139,7 +144,7 @@ def configure_traps debug_say("Registering trap for exit signal #{signal}", :blue) trap(signal) do - @exit_requested = true + self.exit_requested = true shutdown_server end end @@ -147,15 +152,15 @@ def configure_traps # Create the runner for the configured mode def create_runner - debug_say("Creating #{@runner_mode} runner") - @runner = case @runner_mode - when :zmq - create_zmq_runner - when :socket - create_socket_runner - else - say_and_exit("Unknown runner mode: #{@runner_mode}") - end + debug_say("Creating #{mode} runner") + self.runner = case mode + when :zmq + create_zmq_runner + when :socket + create_socket_runner + else + say_and_exit("Unknown runner mode: #{mode}") + end end # Say something if we're in debug mode. @@ -163,10 +168,6 @@ def debug_say(message, color = :yellow) say(message, color) if options.debug? end - def exit_requested? - !!@exit_requested - end - # Internal helper to determine if the modes are multi-set which is not valid. def multi_mode? options.zmq? && options.socket? @@ -207,18 +208,18 @@ def say_and_exit(message, exception = nil) def create_socket_runner require 'protobuf/socket' - @runner = ::Protobuf::Rpc::SocketRunner.new(runner_options) + self.runner = ::Protobuf::Rpc::SocketRunner.new(runner_options) end def create_zmq_runner require 'protobuf/zmq' - @runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) + self.runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) end def shutdown_server logger.info { 'RPC Server shutting down...' } - @runner.try(:stop) + runner.stop ::Protobuf::Rpc::ServiceDirectory.instance.stop end @@ -226,9 +227,9 @@ def shutdown_server def start_server debug_say('Running server') - @runner.run do + runner.run do logger.info do - "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" + "pid #{::Process.pid} -- #{mode} RPC Server listening at #{options.host}:#{options.port}" end ::ActiveSupport::Notifications.instrument("after_server_bind") diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index cf39b0df..3ab75b72 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -18,22 +18,26 @@ def self.warn(message) STDERR.puts("[WARN] #{message}") end + private + + attr_accessor :request + + public + def initialize(request_bytes) - @request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes) - @generated_files = [] + self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes) end def generate_file(file_descriptor) - file_generator = ::Protobuf::Generators::FileGenerator.new(file_descriptor) - @generated_files << file_generator.generate_output_file + ::Protobuf::Generators::FileGenerator.new(file_descriptor).generate_output_file end def response_bytes - @request.proto_file.each do |file_descriptor| + generated_files = request.proto_file.map do |file_descriptor| generate_file(file_descriptor) end - ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files) + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files) end end diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 4c19ab08..d9d19a26 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -5,6 +5,12 @@ def self.encode(stream, message) new(stream, message).encode end + private + + attr_writer :message, :stream + + public + attr_reader :message, :stream def initialize(message, stream) @@ -12,8 +18,8 @@ def initialize(message, stream) fail ArgumentError, "Message instance must respond to :each_field_for_serialization" end - @message = message - @stream = stream + self.message = message + self.stream = stream end def encode diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 16d414ab..3fc171ac 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -229,6 +229,12 @@ class << self # Attributes # + private + + attr_writer :parent_class, :name, :tag + + public + attr_reader :parent_class, :name, :tag ## @@ -236,10 +242,10 @@ class << self # def initialize(parent_class, name, tag) - @parent_class = parent_class - @name = name - @tag = tag - super(@tag) + self.parent_class = parent_class + self.name = name + self.tag = tag + super(tag) end # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index e81159aa..782ae70e 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -2,8 +2,14 @@ module Protobuf module Rpc class SocketRunner + private + + attr_accessor :server + + public + def initialize(options) - @options = case + options = case when options.is_a?(OpenStruct) then options.marshal_dump when options.is_a?(Hash) then @@ -14,20 +20,20 @@ def initialize(options) fail "Cannot parser Socket Server - server options" end - @server = ::Protobuf::Rpc::Socket::Server.new(@options) + self.server = ::Protobuf::Rpc::Socket::Server.new(options) end def run yield if block_given? - @server.run + server.run end def running? - @server.running? + server.running? end def stop - @server.stop + server.stop end end end From 76b4aac4096a420b57539b515b48b02fe5456c13 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 02:20:27 -0800 Subject: [PATCH 0864/1191] Specs pass under JRuby now! --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 61185537..1f98e3da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ rvm: - rbx-2 matrix: allow_failures: - - rvm: jruby - rvm: rbx-2 notifications: webhooks: From 9a46d8098ff322372b853c029e0ca8c4942b2fc1 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Dec 2014 11:16:06 -0700 Subject: [PATCH 0865/1191] don't memoize the @stats on a client --- lib/protobuf/rpc/connectors/common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index b0795787..f5067b75 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -52,7 +52,7 @@ def failure(code, message) end def initialize_stats - @stats ||= ::Protobuf::Rpc::Stat.new(:CLIENT) + @stats = ::Protobuf::Rpc::Stat.new(:CLIENT) @stats.server = [@options[:port], @options[:host]] @stats.service = @options[:service].name @stats.method_name = @options[:method].to_s From 4bd3ae88cbc86c21a5026f4e53cb8f279a8a6f1c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Dec 2014 16:54:10 -0700 Subject: [PATCH 0866/1191] make rubocop happy --- lib/protobuf/rpc/connectors/zmq.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index fef8489d..b3b2dc26 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -121,15 +121,15 @@ def host_alive_check_interval # def lookup_server_uri server_lookup_attempts.times do - service_directory.all_listings_for(service).each do |listing| - host = listing.try(:address) - port = listing.try(:port) - - if host_alive?(host) - # @stats from Common, need to get a better public interface for it - @stats.server = [port, host] - return "tcp://#{host}:#{port}" - end + first_alive_listing = service_directory.all_listings_for(service).find do |listing| + host_alive?(listing.try(:address)) + end + + if first_alive_listing + host = first_alive_listing.try(:address) + port = first_alive_listing.try(:port) + @stats.server = [port, host] + return "tcp://#{host}:#{port}" end host = options[:host] From f0023e517ad0a810e2d0c737180c19c607231424 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 4 Dec 2014 13:49:19 -0700 Subject: [PATCH 0867/1191] bump to 3.4.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 8dfbb929..41df5a37 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.6' + VERSION = '3.4.0' end From fb70f1fd9a3e1585946892010d371db2d7f132da Mon Sep 17 00:00:00 2001 From: Igor Kapkov Date: Fri, 5 Dec 2014 18:36:26 +0800 Subject: [PATCH 0868/1191] Start using svg in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e0e7ead..7bdd0f2e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # protobuf -[![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) -[![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) -[![Gitter chat](https://badges.gitter.im/localshred/protobuf.png)](https://gitter.im/localshred/protobuf) +[![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) +[![Build Status](https://secure.travis-ci.org/localshred/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) +[![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. From c1055b4399697b6b32a80c2a20355a2466ce6831 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 9 Dec 2014 00:45:22 -0700 Subject: [PATCH 0869/1191] reset the zmq socket inside the loop block to prevent infinite loop when context returns nil instead of socket --- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b3b2dc26..9c561894 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -74,9 +74,9 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - socket = zmq_context.socket(::ZMQ::REQ) - begin + socket = zmq_context.socket(::ZMQ::REQ) + if socket # Make sure the context builds the socket server_uri = lookup_server_uri socket.setsockopt(::ZMQ::LINGER, 0) From 34ce9245b909d022a6af2615881faeef239863db Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 9 Dec 2014 00:46:54 -0700 Subject: [PATCH 0870/1191] bump to 3.4.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 41df5a37..f21b2565 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.4.0' + VERSION = '3.4.1' end From 5d6df9de2a94907c5bac0a280435d343a2d8af91 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 12:50:58 -0800 Subject: [PATCH 0871/1191] Fix deprecation warning logic - `ENV['PB_IGNORE_DEPRECATIONS']` now only controls field deprecations, as indicated in the documentation. Protobuf internal deprecations are always printed. - Field deprecations now only print when the field is actually deprecated, and provide a more useful message. --- lib/protobuf.rb | 11 +++++++++-- lib/protobuf/deprecation.rb | 27 +++++++++++++++++++++++++-- lib/protobuf/field/base_field.rb | 12 ++++++++---- lib/protobuf/field/bool_field.rb | 6 +----- lib/protobuf/field/bytes_field.rb | 4 ++-- 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 7a8d3c12..04b5c9ba 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -71,6 +71,13 @@ def self.deprecator end end + def self.field_deprecator + @field_deprecator ||= FieldDeprecation.new.tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr + end + end + # Print Deprecation Warnings # # Default: true @@ -82,11 +89,11 @@ def self.deprecator # # The rpc_server option will override the ENV setting. def self.print_deprecation_warnings? - !deprecator.silenced + !field_deprecator.silenced end def self.print_deprecation_warnings=(value) - deprecator.silenced = !value + field_deprecator.silenced = !value end # Permit unknown field on Message initialization diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index 24cad832..088519da 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -1,12 +1,21 @@ require 'active_support/deprecation' module Protobuf - class Deprecation < ::ActiveSupport::Deprecation + class DeprecationBase < ::ActiveSupport::Deprecation def deprecate_methods(*args) - args.last.merge!(:deprecator => self) if args.last.is_a?(Hash) + deprecation_options = { :deprecator => self } + + if args.last.is_a?(Hash) + args.last.merge!(deprecation_options) + else + args.push(deprecation_options) + end + super end + end + class Deprecation < DeprecationBase def define_deprecated_methods(target_module, method_hash) target_module.module_eval do method_hash.each do |old_method, new_method| @@ -17,4 +26,18 @@ def define_deprecated_methods(target_module, method_hash) deprecate_methods(target_module, method_hash) end end + + class FieldDeprecation < DeprecationBase + # this is a convenience deprecator for deprecated proto fields + + def deprecate_method(target_module, method_name) + deprecate_methods(target_module, method_name => target_module) + end + + private + + def deprecated_method_warning(method_name, target_module) + "#{target_module.name}##{method_name} field usage is deprecated" + end + end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 85cbc90a..440bbd72 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -183,8 +183,9 @@ def define_array_getter define_method(method_name) do @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def define_array_setter @@ -210,8 +211,9 @@ def define_array_setter @values[field.name].replace(val) end end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def define_getter @@ -222,8 +224,9 @@ def define_getter define_method(method_name) do @values.fetch(field.name, field.default_value) end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def define_setter @@ -240,8 +243,9 @@ def define_setter fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def typed_default_value diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index a2534ef0..57f20906 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -38,13 +38,9 @@ def define_getter super field = self - method_name = "#{field.getter}?" message_class.class_eval do - define_method(method_name) do - @values.fetch(field.name, field.default_value) - end - ::Protobuf.deprecator.deprecate_methods(method_name) + alias_method "#{field.getter}?", field.getter end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index a943745c..851daee1 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -73,10 +73,10 @@ def define_setter raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" end end - ::Protobuf.deprecator.deprecate_methods(method_name) end - end + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? + end end end end From d4d414dff7ec77252083c491b66861b6ded0877d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 23 Dec 2014 08:22:26 -0800 Subject: [PATCH 0872/1191] Refresh RuboCop config --- .rubocop_todo.yml | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 463ec257..93749c19 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,11 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-11-24 09:44:26 -0800 using RuboCop version 0.27.1. +# on 2014-12-23 08:21:59 -0800 using RuboCop version 0.28.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 28 +# Offense count: 29 Metrics/AbcSize: Max: 59 @@ -13,60 +13,70 @@ Metrics/AbcSize: Metrics/BlockNesting: Max: 5 -# Offense count: 9 +# Offense count: 8 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 233 + Max: 232 # Offense count: 3 Metrics/CyclomaticComplexity: - Max: 11 + Max: 10 -# Offense count: 508 +# Offense count: 491 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 48 +# Offense count: 43 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 45 + Max: 38 # Offense count: 2 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 6 -# Offense count: 2 +# Offense count: 3 Metrics/PerceivedComplexity: - Max: 12 + Max: 11 -# Offense count: 216 +# Offense count: 189 Style/Documentation: Enabled: false -# Offense count: 15 +# Offense count: 12 Style/DoubleNegation: Enabled: false -# Offense count: 100 +# Offense count: 2 +Style/EmptyElse: + Enabled: false + +# Offense count: 73 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/EmptyLinesAroundBlockBody: + Enabled: false + +# Offense count: 90 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyLinesAroundClassBody: Enabled: false -# Offense count: 66 +# Offense count: 50 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyLinesAroundModuleBody: Enabled: false -# Offense count: 53 +# Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: MinDigits: 21 -# Offense count: 464 +# Offense count: 463 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/StringLiterals: From 5be7e59990937ee5eaf61ff18101eb0cf02fec17 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Thu, 18 Dec 2014 14:49:59 -0800 Subject: [PATCH 0873/1191] Restore Rails 3.2 compatibility Closes #239. --- lib/protobuf.rb | 32 ---------- lib/protobuf/deprecation.rb | 115 ++++++++++++++++++++++++++++-------- 2 files changed, 92 insertions(+), 55 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 04b5c9ba..18564148 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -64,38 +64,6 @@ def self.gc_pause_server_request=(value) @gc_pause_server_request = !!value end - def self.deprecator - @deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation| - deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') - deprecation.behavior = :stderr - end - end - - def self.field_deprecator - @field_deprecator ||= FieldDeprecation.new.tap do |deprecation| - deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') - deprecation.behavior = :stderr - end - end - - # Print Deprecation Warnings - # - # Default: true - # - # Simple boolean to define whether we want field deprecation warnings to - # be printed to stderr or not. The rpc_server has an option to set this value - # explicitly, or you can turn this option off by setting - # ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value. - # - # The rpc_server option will override the ENV setting. - def self.print_deprecation_warnings? - !field_deprecator.silenced - end - - def self.print_deprecation_warnings=(value) - field_deprecator.silenced = !value - end - # Permit unknown field on Message initialization # # Default: true diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index 088519da..eac6e4b1 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -1,43 +1,112 @@ require 'active_support/deprecation' module Protobuf - class DeprecationBase < ::ActiveSupport::Deprecation - def deprecate_methods(*args) - deprecation_options = { :deprecator => self } + if ::ActiveSupport::Deprecation.is_a?(Class) + class DeprecationBase < ::ActiveSupport::Deprecation + def deprecate_methods(*args) + deprecation_options = { :deprecator => self } - if args.last.is_a?(Hash) - args.last.merge!(deprecation_options) - else - args.push(deprecation_options) + if args.last.is_a?(Hash) + args.last.merge!(deprecation_options) + else + args.push(deprecation_options) + end + + super end + end - super + class Deprecation < DeprecationBase + def define_deprecated_methods(target_module, method_hash) + target_module.module_eval do + method_hash.each do |old_method, new_method| + alias_method old_method, new_method + end + end + + deprecate_methods(target_module, method_hash) + end end - end - class Deprecation < DeprecationBase - def define_deprecated_methods(target_module, method_hash) - target_module.module_eval do - method_hash.each do |old_method, new_method| - alias_method old_method, new_method + class FieldDeprecation < DeprecationBase + # this is a convenience deprecator for deprecated proto fields + + def deprecate_method(target_module, method_name) + deprecate_methods(target_module, method_name => target_module) + end + + private + + def deprecated_method_warning(method_name, target_module) + "#{target_module.name}##{method_name} field usage is deprecated" + end + end + else + # TODO: remove this clause when Rails < 4 support is no longer needed + deprecator = ::ActiveSupport::Deprecation.clone + deprecator.instance_eval do + def new(deprecation_horizon = nil, *) + self.deprecation_horizon = deprecation_horizon if deprecation_horizon + self + end + end + Deprecation = deprecator.clone + FieldDeprecation = deprecator.clone + + Deprecation.instance_eval do + def define_deprecated_methods(target_module, method_hash) + target_module.module_eval do + method_hash.each do |old_method, new_method| + alias_method old_method, new_method + end end + + deprecate_methods(target_module, method_hash) end + end + + FieldDeprecation.instance_eval do + def deprecate_method(target_module, method_name) + deprecate_methods(target_module, method_name => target_module) + end + + private - deprecate_methods(target_module, method_hash) + def deprecated_method_warning(method_name, target_module) + "#{target_module.name}##{method_name} field usage is deprecated" + end end end - class FieldDeprecation < DeprecationBase - # this is a convenience deprecator for deprecated proto fields + def self.deprecator + @deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr + end + end - def deprecate_method(target_module, method_name) - deprecate_methods(target_module, method_name => target_module) + def self.field_deprecator + @field_deprecator ||= FieldDeprecation.new.tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr end + end - private + # Print Deprecation Warnings + # + # Default: true + # + # Simple boolean to define whether we want field deprecation warnings to + # be printed to stderr or not. The rpc_server has an option to set this value + # explicitly, or you can turn this option off by setting + # ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value. + # + # The rpc_server option will override the ENV setting. + def self.print_deprecation_warnings? + !field_deprecator.silenced + end - def deprecated_method_warning(method_name, target_module) - "#{target_module.name}##{method_name} field usage is deprecated" - end + def self.print_deprecation_warnings=(value) + field_deprecator.silenced = !value end end From 09f2193ac723001e43f8e5eada93791441924d42 Mon Sep 17 00:00:00 2001 From: Brian Ferris Date: Mon, 5 Jan 2015 21:06:40 -0800 Subject: [PATCH 0874/1191] Support for Foo::SomeMessage.decode_from(stream) The Serialization documentation: https://github.com/localshred/protobuf/wiki/Serialization implies that the following idioms should work for decoding an object: Foo::User.decode(bytes) Foo::User.decode_from(stream) However, in practice, decode_from(...) only seems to be supported as an instance method, not a class method. By comparison, decode(...) is supported as both an instance method and a class method. Let's fix that. --- lib/protobuf/message/serialization.rb | 4 ++++ spec/lib/protobuf/message_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 5850b5a6..5528c10a 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -11,6 +11,10 @@ def decode(bytes) new.decode(bytes) end + def decode_from(stream) + new.decode_from(stream) + end + # Create a new object with the given values and return the encoded bytes. def encode(fields = {}) new(fields).encode diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 052b570e..e6ff7b96 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -1,5 +1,6 @@ # encoding: utf-8 +require 'stringio' require 'spec_helper' RSpec.describe Protobuf::Message do @@ -71,6 +72,15 @@ end end + describe '.decode_from' do + let(:message) { ::Test::Resource.new(:name => "Jim") } + + it 'creates a new message object decoded from the given byte stream' do + stream = ::StringIO.new(message.encode) + expect(::Test::Resource.decode_from(stream)).to eq message + end + end + describe 'defining a new field' do context 'when defining a field with a tag that has already been used' do it 'raises a TagCollisionError' do From b21661bddabcff1a16494aa5346ed35d922a2a08 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Jan 2015 20:27:16 -0700 Subject: [PATCH 0875/1191] make snd and rcv timeout on check avail actually work with env vars add functionality to recover from broker exception or not starting up correctly, will now wait for broker to start and will restart on crash --- lib/protobuf/rpc/connectors/zmq.rb | 18 ++++++++++++-- lib/protobuf/rpc/servers/zmq/broker.rb | 4 +++- lib/protobuf/rpc/servers/zmq/server.rb | 33 +++++++++++++++----------- lib/protobuf/rpc/servers/zmq/worker.rb | 5 ++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 9c561894..0059c07d 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -59,11 +59,25 @@ def send_request # Private Instance methods # def check_available_rcv_timeout - @check_available_rcv_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT"].to_i, 200].max + @check_available_rcv_timeout ||= begin + case + when ENV.key?("PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT"].to_i + else + 200 # ms + end + end end def check_available_snd_timeout - @check_available_snd_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT"].to_i, 200].max + @check_available_snd_timeout ||= begin + case + when ENV.key?("PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT"].to_i + else + 200 # ms + end + end end def close_connection diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index abb2ccad..84017e57 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -23,6 +23,7 @@ def initialize(server) def run @idle_workers = [] + @running = true loop do process_local_queue @@ -39,10 +40,11 @@ def run end ensure teardown + @running = false end def running? - @server.running? + @running && @server.running? end private diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index bd187ffb..df6be786 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -76,6 +76,10 @@ def broadcast_beacons? !brokerless? && options[:broadcast_beacons] end + def broadcast_busy? + broadcast_beacons? && options[:broadcast_busy] + end + def broadcast_flatline flatline = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE, @@ -176,15 +180,11 @@ def reaping_interval def run @running = true - - start_broker unless brokerless? - start_missing_workers - yield if block_given? # runs on startup wait_for_shutdown_signal broadcast_flatline if broadcast_beacons? Thread.pass until reap_dead_workers.empty? - @broker.join unless brokerless? + @broker_thread.join unless brokerless? ensure @running = false teardown @@ -246,14 +246,13 @@ def wait_for_shutdown_signal loop do break if IO.select([@shutdown_r], nil, nil, timeout) - if reap_dead_workers? - reap_dead_workers - start_missing_workers - end + start_broker unless brokerless? + reap_dead_workers if reap_dead_workers? + start_missing_workers next unless broadcast_heartbeat? - if options[:broadcast_busy] && all_workers_busy? + if broadcast_busy? && all_workers_busy? broadcast_flatline else broadcast_heartbeat @@ -285,15 +284,21 @@ def init_zmq_context end def start_broker - @broker = Thread.new(self) do |server| - ::Protobuf::Rpc::Zmq::Broker.new(server).run + return if @broker && @broker.running? && !@broker_thread.stop? + broadcast_flatline if broadcast_busy? + @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) + + @broker_thread = Thread.new(@broker) do |broker| + broker.run end + + ::Thread.pass until @broker.running? end def start_worker - @workers << Thread.new(self) do |server| + @workers << Thread.new(self, @broker) do |server, broker| begin - ::Protobuf::Rpc::Zmq::Worker.new(server).run + ::Protobuf::Rpc::Zmq::Worker.new(server, broker).run rescue => e message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}" $stderr.puts(message) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 63f1df3c..cf606615 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -12,8 +12,9 @@ class Worker ## # Constructor # - def initialize(server) + def initialize(server, broker) @server = server + @broker = broker init_zmq_context init_backend_socket @@ -61,7 +62,7 @@ def run end def running? - @server.running? + @broker.running? && @server.running? end private From cd3964c06bdd5fcb53ddf2013ea4ea7131d13cb3 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Jan 2015 20:33:47 -0700 Subject: [PATCH 0876/1191] catch and report if error in broker thread --- lib/protobuf/rpc/servers/zmq/server.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index df6be786..1333bb4f 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -289,7 +289,13 @@ def start_broker @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) @broker_thread = Thread.new(@broker) do |broker| - broker.run + begin + broker.run + rescue => e + message = "Broker failed: #{e.inspect}\n #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}" + $stderr.puts(message) + logger.error { message } + end end ::Thread.pass until @broker.running? From 10bcc3b877767ea303ae593b13aa84aa427c078c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Jan 2015 22:02:52 -0700 Subject: [PATCH 0877/1191] restart context and join broker thread if broker dies --- lib/protobuf/rpc/servers/zmq/server.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 1333bb4f..83e21d2d 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -285,9 +285,13 @@ def init_zmq_context def start_broker return if @broker && @broker.running? && !@broker_thread.stop? - broadcast_flatline if broadcast_busy? - @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) + if @broker && !@broker.running? + broadcast_flatline if broadcast_busy? + @broker_thread.join if @broker_thread + init_zmq_context # need a new context to restart the broker + end + @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) @broker_thread = Thread.new(@broker) do |broker| begin broker.run @@ -297,8 +301,6 @@ def start_broker logger.error { message } end end - - ::Thread.pass until @broker.running? end def start_worker From b9fb942f3fa33ac1bb7c38e0de980e60951562aa Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Jan 2015 09:17:45 -0700 Subject: [PATCH 0878/1191] disable Metrics/ClassLength in rubocop --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index a2e37f1f..c4311848 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,9 @@ Lint/EndAlignment: Lint/Loop: Enabled: false +Metrics/ClassLength: + Enabled: false + Style/CaseIndentation: IndentWhenRelativeTo: end From 9eb9520ab8dc8240622c9af3f4c2a8d65961b4a3 Mon Sep 17 00:00:00 2001 From: Adam Greene Date: Mon, 2 Feb 2015 12:45:36 -0800 Subject: [PATCH 0879/1191] allow Protobuf::Message based classes to be inherited --- lib/protobuf/message/fields.rb | 168 ++++++++++++---------- spec/functional/class_inheritance_spec.rb | 52 +++++++ 2 files changed, 143 insertions(+), 77 deletions(-) create mode 100644 spec/functional/class_inheritance_spec.rb diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index eea33128..5b081ffc 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -3,6 +3,7 @@ class Message module Fields def self.extended(other) + other.extend(ClassMethods) ::Protobuf.deprecator.define_deprecated_methods( other.singleton_class, :get_ext_field_by_name => :get_extension_field, @@ -10,110 +11,123 @@ def self.extended(other) :get_field_by_name => :get_field, :get_field_by_tag => :get_field, ) + + def inherited(subclass) + inherit_fields!(subclass) + end end - ## - # Field Definition Methods - # + module ClassMethods - # Define an optional field. - # - def optional(type_class, name, tag, options = {}) - define_field(:optional, type_class, name, tag, options) - end + ## + # Field Definition Methods + # - # Define a repeated field. - # - def repeated(type_class, name, tag, options = {}) - define_field(:repeated, type_class, name, tag, options) - end + # Define an optional field. + # + def optional(type_class, name, tag, options = {}) + define_field(:optional, type_class, name, tag, options) + end - # Define a required field. - # - def required(type_class, name, tag, options = {}) - define_field(:required, type_class, name, tag, options) - end + # Define a repeated field. + # + def repeated(type_class, name, tag, options = {}) + define_field(:repeated, type_class, name, tag, options) + end - # Define an extension range. - # - def extensions(range) - extension_ranges << range - end + # Define a required field. + # + def required(type_class, name, tag, options = {}) + define_field(:required, type_class, name, tag, options) + end - ## - # Field Access Methods - # + # Define an extension range. + # + def extensions(range) + extension_ranges << range + end - def all_fields - @all_fields ||= field_store.values.uniq.sort_by(&:tag) - end + ## + # Field Access Methods + # + def all_fields + @all_fields ||= field_store.values.uniq.sort_by(&:tag) + end - def extension_fields - @extension_fields ||= all_fields.select(&:extension?) - end + def extension_fields + @extension_fields ||= all_fields.select(&:extension?) + end - def extension_ranges - @extension_ranges ||= [] - end + def extension_ranges + @extension_ranges ||= [] + end - def extension_tag?(tag) - tag.respond_to?(:to_i) && get_extension_field(tag).present? - end + def extension_tag?(tag) + tag.respond_to?(:to_i) && get_extension_field(tag).present? + end - def field_store - @field_store ||= {} - end + def field_store + @field_store ||= {} + end - def fields - @fields ||= all_fields.reject(&:extension?) - end + def fields + @fields ||= all_fields.reject(&:extension?) + end - def field_tag?(tag, allow_extension = false) - tag.respond_to?(:to_i) && get_field(tag, allow_extension).present? - end + def field_tag?(tag, allow_extension = false) + tag.respond_to?(:to_i) && get_field(tag, allow_extension).present? + end - def get_extension_field(name_or_tag) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] - field if field.try(:extension?) { false } - end + def get_extension_field(name_or_tag) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] + field if field.try(:extension?) { false } + end - def get_field(name_or_tag, allow_extension = false) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] + def get_field(name_or_tag, allow_extension = false) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] - if field && (allow_extension || !field.extension?) - field - else - nil + if field && (allow_extension || !field.extension?) + field + else + nil + end end - end - def define_field(rule, type_class, field_name, tag, options) - raise_if_tag_collision(tag, field_name) - raise_if_name_collision(field_name) + def define_field(rule, type_class, field_name, tag, options) + raise_if_tag_collision(tag, field_name) + raise_if_name_collision(field_name) - field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) - field_store[field_name] = field - field_store[tag] = field + field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) + field_store[field_name] = field + field_store[tag] = field - define_method("#{field_name}!") do - @values[field_name] + define_method("#{field_name}!") do + @values[field_name] + end end - end - def raise_if_tag_collision(tag, field_name) - if get_field(tag, true) - fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) + def raise_if_tag_collision(tag, field_name) + if get_field(tag, true) + fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) + end end - end - def raise_if_name_collision(field_name) - if get_field(field_name, true) - fail DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) + def raise_if_name_collision(field_name) + if get_field(field_name, true) + fail DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) + end end - end + def inherit_fields!(subclass) + instance_variables.each do |iv| + subclass.instance_variable_set(iv, instance_variable_get(iv)) + end + end + private :inherit_fields! + + end end end end diff --git a/spec/functional/class_inheritance_spec.rb b/spec/functional/class_inheritance_spec.rb new file mode 100644 index 00000000..513d7210 --- /dev/null +++ b/spec/functional/class_inheritance_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' +require 'spec/support/test/resource_service' + +RSpec.describe 'works through class inheritance' do + module Corp + module Protobuf + class Error < ::Protobuf::Message + required :string, :foo, 1 + end + end + end + module Corp + class ErrorHandler < Corp::Protobuf::Error + end + end + + let(:args) { { :foo => 'bar' } } + let(:parent_class) { Corp::Protobuf::Error } + let(:inherited_class) { Corp::ErrorHandler } + + specify '#encode' do + expected_result = "\n\x03bar" + expected_result.force_encoding(Encoding::BINARY) + expect(parent_class.new(args).encode).to eq(expected_result) + expect(inherited_class.new(args).encode).to eq(expected_result) + end + + specify '#to_hash' do + expect(parent_class.new(args).to_hash).to eq(args) + expect(inherited_class.new(args).to_hash).to eq(args) + end + + specify '#to_json' do + expect(parent_class.new(args).to_json).to eq(args.to_json) + expect(inherited_class.new(args).to_json).to eq(args.to_json) + end + + specify '.encode' do + expected_result = "\n\x03bar" + expected_result.force_encoding(Encoding::BINARY) + expect(parent_class.encode(args)).to eq(expected_result) + expect(inherited_class.encode(args)).to eq(expected_result) + end + + specify '.decode' do + raw_value = "\n\x03bar" + raw_value.force_encoding(Encoding::BINARY) + expect(parent_class.decode(raw_value).to_hash).to eq(args) + expect(inherited_class.decode(raw_value).to_hash).to eq(args) + end + +end From c3cb5f9d49cd5b75860e3197acc206afe411ca4d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Feb 2015 21:45:22 -0700 Subject: [PATCH 0880/1191] Bump version 3.4.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f21b2565..86b92f42 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.4.1' + VERSION = '3.4.4' end From bf3729bc582406c5591af21089334dccf023eaf7 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Feb 2015 22:03:55 -0700 Subject: [PATCH 0881/1191] Trying to get rubocop to shut the fuck up --- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf/rpc/service_directory_spec.rb | 4 +--- spec/lib/protobuf/rpc/stat_spec.rb | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e6ff7b96..e645c355 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -401,7 +401,7 @@ it 'does not populate default values' do hash = Test::EnumTestMessage.new.to_hash - expect(hash).to eq(Hash.new) + expect(hash).to eq({}) end it 'converts repeated enum fields to an array of the tags' do diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index ea039ec8..c15af6a3 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -57,9 +57,7 @@ def expect_event_trigger(event) expect(::ActiveSupport::Notifications).to receive(:instrument) - .with(event, hash_including( - :listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing), - )).once + .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))).once end def send_beacon(type, server) diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index f23ce783..14c4556d 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -5,9 +5,7 @@ RSpec.describe ::Protobuf::Rpc::Stat do before(:all) do - unless defined?(BarService) - class BarService < ::Struct.new(:method_name); end - end + BarService = ::Struct.new(:method_name) unless defined?(BarService) end describe 'server mode' do From 65cc475c9ee0005809f3ab3e00aa0a59aeb56282 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Feb 2015 22:14:06 -0700 Subject: [PATCH 0882/1191] Again, rubocop. I hate it --- spec/lib/protobuf/rpc/service_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 4c1fcf37..514f35e2 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -65,9 +65,9 @@ client = double('client') expect(::Protobuf::Rpc::Client).to receive(:new) .with(hash_including( - :service => subject, - :host => subject.host, - :port => subject.port, + :service => subject, + :host => subject.host, + :port => subject.port, )).and_return(client) expect(subject.client).to eq client end From 2ea42e846a429beed8de75a8d797164bafc11de8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 19 Feb 2015 10:21:14 -0700 Subject: [PATCH 0883/1191] Add omniref doc badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7bdd0f2e..2a7d16b1 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) [![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) +[![protobuf API Documentation](https://www.omniref.com/ruby/gems/protobuf.png)](https://www.omniref.com/ruby/gems/protobuf) Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. From 12aa393d5d61a8125455a5e96bd19bfa8be126cd Mon Sep 17 00:00:00 2001 From: Richard Heycock Date: Fri, 27 Feb 2015 00:25:27 +1100 Subject: [PATCH 0884/1191] Allow the Message to be constructed with a block. Allow Messages to be constructed in the following manner: Protobuf::Message.new do |p| p.field = x ... end --- lib/protobuf/message.rb | 10 +++++++--- spec/lib/protobuf/message_spec.rb | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index b024c957..32379824 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,11 +26,15 @@ def self.to_json # Constructor # - def initialize(fields = {}) + def initialize(fields = {}, &blk) @values = {} - fields.to_hash.each_pair do |name, value| - self[name] = value + if blk + blk.call(self) + else + fields.to_hash.each_pair do |name, value| + self[name] = value + end end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e645c355..bd6c4909 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -175,6 +175,12 @@ expect(test_enum.non_default_enum).to eq(2) end + it "initializes with an object with a block" do + hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) + test_enum = Test::EnumTestMessage.new { |p| p.non_default_enum = 2 } + expect(test_enum.non_default_enum).to eq(2) + end + context 'ignoring unknown fields' do before { ::Protobuf.ignore_unknown_fields = true } From 216fe1fca473d4eb417c2d9ea0a3bb2d828fbc6c Mon Sep 17 00:00:00 2001 From: Richard Heycock Date: Fri, 27 Feb 2015 01:02:07 +1100 Subject: [PATCH 0885/1191] Remove unused variable. --- spec/lib/protobuf/message_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index bd6c4909..79c3f331 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -176,7 +176,6 @@ end it "initializes with an object with a block" do - hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) test_enum = Test::EnumTestMessage.new { |p| p.non_default_enum = 2 } expect(test_enum.non_default_enum).to eq(2) end From 6cd68498d4f4a779839fa34ad17278f174f51905 Mon Sep 17 00:00:00 2001 From: Adam Greene Date: Tue, 3 Mar 2015 22:25:32 -0800 Subject: [PATCH 0886/1191] don't downcast when assigning to a field_array --- lib/protobuf/field/field_array.rb | 2 + lib/protobuf/field/message_field.rb | 2 +- spec/lib/protobuf/field/field_array_spec.rb | 75 +++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 spec/lib/protobuf/field/field_array_spec.rb diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 65447a31..78bb79e0 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -66,6 +66,8 @@ def normalize(value) if field.is_a?(::Protobuf::Field::EnumField) field.type_class.fetch(value) + elsif field.is_a?(::Protobuf::Field::MessageField) && value.is_a?(field.type_class) + value elsif field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) field.type_class.new(value.to_hash) else diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 45dec389..eb6e8fa1 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,7 +9,7 @@ class MessageField < BaseField # def acceptable?(val) - unless val.instance_of?(type_class) || val.respond_to?(:to_hash) + unless val.is_a?(type_class) || val.is_a?(Hash) fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end diff --git a/spec/lib/protobuf/field/field_array_spec.rb b/spec/lib/protobuf/field/field_array_spec.rb new file mode 100644 index 00000000..cec33885 --- /dev/null +++ b/spec/lib/protobuf/field/field_array_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::FieldArray do + + class SomeBasicMessage < ::Protobuf::Message + optional :string, :field, 1 + end + + class MoreComplexMessage < SomeBasicMessage + end + + class OtherBasicMessage < ::Protobuf::Message + optional :string, :other_field, 1 + end + + class SomeRepeatMessage < ::Protobuf::Message + optional :string, :some_string, 1 + repeated :string, :multiple_strings, 2 + repeated SomeBasicMessage, :multiple_basic_msgs, 3 + end + + let(:instance) { SomeRepeatMessage.new } + + %w(<< push).each do |method| + describe "\##{method}" do + context 'when applied to a string field array' do + it 'adds a string' do + expect(instance.multiple_strings).to be_empty + instance.multiple_strings.send(method, 'string 1') + expect(instance.multiple_strings).to eq(['string 1']) + instance.multiple_strings.send(method, 'string 2') + expect(instance.multiple_strings).to eq(['string 1', 'string 2']) + end + + it 'fails if not adding a string' do + expect { instance.multiple_strings.send(method, 100.0) }.to raise_error(TypeError) + end + end + + context 'when applied to a MessageField field array' do + it 'adds a MessageField object' do + expect(instance.multiple_basic_msgs).to be_empty + basic_msg1 = SomeBasicMessage.new + instance.multiple_basic_msgs.send(method, basic_msg1) + expect(instance.multiple_basic_msgs).to eq([basic_msg1]) + basic_msg2 = SomeBasicMessage.new + instance.multiple_basic_msgs.send(method, basic_msg2) + expect(instance.multiple_basic_msgs).to eq([basic_msg1, basic_msg2]) + end + + it 'adds a Hash from a MessageField object' do + expect(instance.multiple_basic_msgs).to be_empty + basic_msg1 = SomeBasicMessage.new + basic_msg1.field = 'my value' + instance.multiple_basic_msgs.send(method, basic_msg1.to_hash) + expect(instance.multiple_basic_msgs).to eq([basic_msg1]) + end + + it 'does not downcast a MessageField' do + expect(instance.multiple_basic_msgs).to be_empty + basic_msg1 = MoreComplexMessage.new + instance.multiple_basic_msgs.send(method, basic_msg1) + expect(instance.multiple_basic_msgs).to eq([basic_msg1]) + expect(instance.multiple_basic_msgs.first).to be_a(MoreComplexMessage) + end + + it 'fails if not adding the expected MessageField object' do + expect { instance.multiple_basic_msgs.send(method, 100.0) }.to raise_error(TypeError) + expect { instance.multiple_basic_msgs.send(method, OtherBasicMessage.new) }.to raise_error(TypeError) + end + end + end + + end +end From f4ade201e4160b4bc9752c4a8db11ee5f64d343d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 26 Jan 2015 16:57:47 -0800 Subject: [PATCH 0887/1191] Update `protobuf` to 2.6.1 and simplify the install --- install-protobuf.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/install-protobuf.sh b/install-protobuf.sh index 22488b28..d9ad119e 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -1,8 +1,10 @@ +#!/usr/bin/env sh + set -ex -basename=protobuf-2.6.0 -tarball=$basename.tar.bz2 +version=2.6.1 +basename=protobuf-$version + +curl -sL https://github.com/google/protobuf/releases/download/v$version/$basename.tar.bz2 | tar jx -wget https://protobuf.googlecode.com/svn/rc/$tarball -tar -xvf $tarball cd $basename && ./configure --prefix=/usr && make && make install From 06a66fb0d583831689f340e2594d35743ac2598f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 16 Mar 2015 09:32:46 -0700 Subject: [PATCH 0888/1191] Test against protobuf 3 --- .travis.yml | 6 +++++- install-protobuf.sh | 26 ++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f98e3da..3b77fb78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y libzmq3-dev - - sudo ./install-protobuf.sh + - sudo -E ./install-protobuf.sh language: ruby rvm: - 1.9.3 @@ -9,9 +9,13 @@ rvm: - 2.1 - jruby - rbx-2 +env: + - PROTOBUF_VERSION=2.6.1 + - PROTOBUF_VERSION=3.0.0-alpha-2 matrix: allow_failures: - rvm: rbx-2 + - env: PROTOBUF_VERSION=3.0.0-alpha-2 notifications: webhooks: urls: diff --git a/install-protobuf.sh b/install-protobuf.sh index d9ad119e..b3872fd0 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -2,9 +2,27 @@ set -ex -version=2.6.1 -basename=protobuf-$version +gdie() { + echo "$@" >&2 + exit 1 +} -curl -sL https://github.com/google/protobuf/releases/download/v$version/$basename.tar.bz2 | tar jx +test -n "$PROTOBUF_VERSION" || die "PROTOBUF_VERSION env var is undefined" -cd $basename && ./configure --prefix=/usr && make && make install +case "$PROTOBUF_VERSION" in +2*) + basename=protobuf-$PROTOBUF_VERSION + ;; +3*) + basename=protobuf-cpp-$PROTOBUF_VERSION + ;; +*) + die "unknown protobuf version: $PROTOBUF_VERSION" + ;; +esac + +curl -sL https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename.tar.gz | tar zx + +cd protobuf-$PROTOBUF_VERSION + +./configure --prefix=/usr && make -j2 && make install From 74f1e39d63974e13f99b24a5f1cb4e002c451f61 Mon Sep 17 00:00:00 2001 From: Harshit Chopra Date: Mon, 30 Mar 2015 16:02:27 -0400 Subject: [PATCH 0889/1191] Adds support to specify integer and bool proto fields as string. Also fixes the range check for integer types. --- lib/protobuf/field/bool_field.rb | 12 ++- lib/protobuf/field/varint_field.rb | 8 +- spec/lib/protobuf/field/bool_field_spec.rb | 51 +++++++++++++ spec/lib/protobuf/field/int32_field_spec.rb | 82 +++++++++++++++++++++ 4 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 spec/lib/protobuf/field/bool_field_spec.rb diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 57f20906..d1b9efc8 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -17,7 +17,17 @@ def self.default # # def acceptable?(val) - [true, false].include?(val) + [true, false].include?(val) || %w(true false).include?(val) + end + + def coerce!(val) + if val == 'true' + true + elsif val == 'false' + false + else + val + end end def decode(value) diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 448610dd..affaf393 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -37,11 +37,17 @@ def self.encode(value) # def acceptable?(val) - (val > self.class.min || val < self.class.max) + int_val = coerce!(val) + int_val >= self.class.min && int_val <= self.class.max rescue false end + def coerce!(val) + return val.to_i if val.is_a?(Numeric) + Integer(val, 10) + end + def decode(value) value end diff --git a/spec/lib/protobuf/field/bool_field_spec.rb b/spec/lib/protobuf/field/bool_field_spec.rb new file mode 100644 index 00000000..af254716 --- /dev/null +++ b/spec/lib/protobuf/field/bool_field_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Int32Field do + + class SomeBoolMessage < ::Protobuf::Message + optional :bool, :some_bool, 1 + end + + let(:instance) { SomeBoolMessage.new } + + describe '#define_setter' do + subject { instance.some_bool = value; instance.some_bool } + + [true, false].each do |val| + context "when set with #{val}" do + let(:value) { val } + + it 'is readable as a bool' do + expect(subject).to eq(val) + end + end + end + + [['true', true], ['false', false]].each do |val, expected| + context "when set with a string of #{val}" do + let(:value) { val } + + it 'is readable as a bool' do + expect(subject).to eq(expected) + end + end + end + + context 'when set with a non-bool string' do + let(:value) { "aaaa" } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with something that is not a bool' do + let(:value) { [1, 2, 3] } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + end + +end diff --git a/spec/lib/protobuf/field/int32_field_spec.rb b/spec/lib/protobuf/field/int32_field_spec.rb index 5c1ff70b..b65a778c 100644 --- a/spec/lib/protobuf/field/int32_field_spec.rb +++ b/spec/lib/protobuf/field/int32_field_spec.rb @@ -4,4 +4,86 @@ it_behaves_like :packable_field, described_class + class SomeInt32Message < ::Protobuf::Message + optional :int32, :some_int, 1 + end + + let(:instance) { SomeInt32Message.new } + + describe '#define_setter' do + subject { instance.some_int = value; instance.some_int } + + context 'when set with an int' do + let(:value) { 100 } + + it 'is readable as an int' do + expect(subject).to eq(100) + end + end + + context 'when set with a float' do + let(:value) { 100.1 } + + it 'is readable as an int' do + expect(subject).to eq(100) + end + end + + context 'when set with a string of an int' do + let(:value) { "101" } + + it 'is readable as an int' do + expect(subject).to eq(101) + end + end + + context 'when set with a negative representation of an int as string' do + let(:value) { "-101" } + + it 'is readable as a negative int' do + expect(subject).to eq(-101) + end + end + + context 'when set with a non-numeric string' do + let(:value) { "aaaa" } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with a string of an int in hex format' do + let(:value) { "0x101" } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with a string of an int larger than int32 max' do + let(:value) { (described_class.max + 1).to_s } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with something that is not an int' do + let(:value) { [1, 2, 3] } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with a timestamp' do + let(:value) { Time.now } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + end + end From 3321da5d4ce08466a51d3e19be8beec351229fd7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 6 Apr 2015 21:09:41 -0600 Subject: [PATCH 0890/1191] restart service listener if it dies --- lib/protobuf/rpc/service_directory.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 6aec7b4d..802ab082 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -82,6 +82,7 @@ def initialize def all_listings_for(service) if running? && @listings_by_service.key?(service.to_s) + start_listener_thread if listener_dead? @listings_by_service[service.to_s].entries.shuffle else [] @@ -89,39 +90,53 @@ def all_listings_for(service) end def each_listing(&block) + start_listener_thread if listener_dead? @listings_by_uuid.each_value(&block) end def lookup(service) if running? + start_listener_thread if listener_dead? + if @listings_by_service.key?(service.to_s) @listings_by_service[service.to_s].entries.sample end end end + def listener_dead? + @thread.nil? || !@thread.alive? + end + def restart stop start end def running? - !!@thread.try(:alive?) + !!@running end def start unless running? init_socket logger.info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } - @thread = Thread.new { send(:run) } + @running = true end + start_listener_thread if listener_dead? self end + def start_listener_thread + return if @thread.try(:alive?) + @thread = Thread.new { send(:run) } + end + def stop logger.info { sign_message("Stopping directory") } + @running = false @thread.try(:kill).try(:join) @socket.try(:close) From 37d3ed9d08abda05ad352d9a54ed7203af716fc4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 7 Apr 2015 11:33:56 -0600 Subject: [PATCH 0891/1191] use guard clause and make the cops happy --- lib/protobuf/rpc/service_directory.rb | 11 ++++------- lib/protobuf/rpc/service_filters.rb | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 802ab082..81696853 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -95,13 +95,10 @@ def each_listing(&block) end def lookup(service) - if running? - start_listener_thread if listener_dead? - - if @listings_by_service.key?(service.to_s) - @listings_by_service[service.to_s].entries.sample - end - end + return unless running? + start_listener_thread if listener_dead? + return unless @listings_by_service.key?(service.to_s) + @listings_by_service[service.to_s].entries.sample end def listener_dead? diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index b1413ef3..5d76460f 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -94,10 +94,10 @@ def filters # if the filter should not be invoked, true if invocation should occur. # def invoke_filter?(rpc_method, filter) - invoke_via_only?(rpc_method, filter) \ - && invoke_via_except?(rpc_method, filter) \ - && invoke_via_if?(rpc_method, filter) \ - && invoke_via_unless?(rpc_method, filter) + invoke_via_only?(rpc_method, filter) && + invoke_via_except?(rpc_method, filter) && + invoke_via_if?(rpc_method, filter) && + invoke_via_unless?(rpc_method, filter) end # If the target rpc endpoint method is listed under an :except option, From f572eff4550ee724601a472cea8c8843eae892c2 Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Wed, 8 Apr 2015 12:51:37 -0600 Subject: [PATCH 0892/1191] Fix unhandled error in trap signal handler Thread#backtrace can be nil. If this is the case, this signal handler will throw an error and terminate the process. In the case of nil here, we will just print nothing and continue on. --- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index a867c2d4..33d2030d 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -41,7 +41,7 @@ def register_signals logger.info do <<-THREAD_TRACE #{thread.inspect}: - #{thread.backtrace.join($INPUT_RECORD_SEPARATOR)}" + #{thread.backtrace.try(:join, $INPUT_RECORD_SEPARATOR)}" THREAD_TRACE end end From 0077acddba3eab5e74007b644ee6ea4bff093d97 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 13 Apr 2015 20:29:41 -0600 Subject: [PATCH 0893/1191] clean up block syntax --- lib/protobuf/message.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 32379824..0e8f95df 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,16 +26,13 @@ def self.to_json # Constructor # - def initialize(fields = {}, &blk) + def initialize(fields = {}) @values = {} - - if blk - blk.call(self) - else - fields.to_hash.each_pair do |name, value| - self[name] = value - end + fields.to_hash.each_pair do |name, value| + self[name] = value end + + yield self if block_given? end ## From 83f599e0ec05eed4243c692755e476b74c2b09be Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 13 Apr 2015 20:35:35 -0600 Subject: [PATCH 0894/1191] keep check to to_hash in message_field as it is a valid use-case --- lib/protobuf/field/message_field.rb | 2 +- spec/lib/protobuf/field/field_array_spec.rb | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index eb6e8fa1..2d9f3c92 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,7 +9,7 @@ class MessageField < BaseField # def acceptable?(val) - unless val.is_a?(type_class) || val.is_a?(Hash) + unless val.is_a?(type_class) || val.respond_to?(:to_hash) fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end diff --git a/spec/lib/protobuf/field/field_array_spec.rb b/spec/lib/protobuf/field/field_array_spec.rb index cec33885..48133381 100644 --- a/spec/lib/protobuf/field/field_array_spec.rb +++ b/spec/lib/protobuf/field/field_array_spec.rb @@ -63,13 +63,7 @@ class SomeRepeatMessage < ::Protobuf::Message expect(instance.multiple_basic_msgs).to eq([basic_msg1]) expect(instance.multiple_basic_msgs.first).to be_a(MoreComplexMessage) end - - it 'fails if not adding the expected MessageField object' do - expect { instance.multiple_basic_msgs.send(method, 100.0) }.to raise_error(TypeError) - expect { instance.multiple_basic_msgs.send(method, OtherBasicMessage.new) }.to raise_error(TypeError) - end end end - end end From 474897be311f56db5b21a932eba2ac9bb1320d40 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 13 Apr 2015 20:39:32 -0600 Subject: [PATCH 0895/1191] bump to 3.5.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 86b92f42..4a7a8256 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.4.4' + VERSION = '3.5.0' end From a2e448e1f6f2f1ea3568f9e607e1e4d4d2d6b09e Mon Sep 17 00:00:00 2001 From: Bob Bonifield Date: Thu, 23 Apr 2015 13:29:40 -0600 Subject: [PATCH 0896/1191] Move input file expansion into Ruby --- lib/protobuf/tasks/compile.rake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index cd46e3ab..65c09576 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -18,8 +18,7 @@ namespace :protobuf do command << "protoc" command << "--#{args[:plugin]}_out=#{args[:destination]}" command << "-I #{args[:source]}" - command << "#{args[:source]}/#{args[:package]}/*.proto" - command << "#{args[:source]}/#{args[:package]}/**/*.proto" + command << Dir["#{args[:source]}/#{args[:package]}/**/*.proto"].join(" ") full_command = command.join(' ') puts full_command From 329ac77e97d7ef5f99f3df82a2ba8de24dd6df42 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 24 Apr 2015 10:09:33 -0600 Subject: [PATCH 0897/1191] Fix wording around stable branches --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4cc6d5dd..beb902ad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ your code merged. 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. 2. For __compiler issues__, please provide both a gist for the __source definition(s)__ as well as the __generated output__ (if any). -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`. +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`. 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. 5. Be patient with me as I work on your issue. From d4bb25701f7d1920d8a93074d353a55f5f07f95b Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 10:30:06 -0600 Subject: [PATCH 0898/1191] Move symbolize_keys to the constructors of socket and zmq runners Thor's HashWithIndifferentAccess has no `symbolize_keys` method. This moves the symbolize_keys call to the constructor of socket_runner and zmq_runner. The tests were also updated to use string hash keys to reflect the type of keys found in HashWithIndifferentAccess. --- lib/protobuf/cli.rb | 2 +- lib/protobuf/rpc/servers/socket_runner.rb | 4 +--- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- spec/functional/zmq_server_spec.rb | 12 ++++++------ 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3fe340bf..b522b5e6 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -182,7 +182,7 @@ def require_application(app_file) end def runner_options - opt = options.symbolize_keys + opt = options.to_hash opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 782ae70e..53cfc964 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -12,10 +12,8 @@ def initialize(options) options = case when options.is_a?(OpenStruct) then options.marshal_dump - when options.is_a?(Hash) then - options when options.respond_to?(:to_hash) then - options.to_hash + options.to_hash.symbolize_keys else fail "Cannot parser Socket Server - server options" end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 33d2030d..50f26a15 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -11,7 +11,7 @@ def initialize(options) when options.is_a?(OpenStruct) then options.marshal_dump when options.respond_to?(:to_hash) then - options.to_hash + options.to_hash.symbolize_keys else fail "Cannot parser Zmq Server - server options" end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 8996973d..a764dc1d 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -7,12 +7,12 @@ before(:all) do load "protobuf/zmq.rb" @runner = ::Protobuf::Rpc::ZmqRunner.new( - :host => "127.0.0.1", - :port => 9399, - :worker_port => 9408, - :backlog => 100, - :threshold => 100, - :threads => 5, + 'host' => '127.0.0.1', + 'port' => 9399, + 'worker_port' => 9408, + 'backlog' => 100, + 'threshold' => 100, + 'threads' => 5, ) @server_thread = Thread.new(@runner) { |runner| runner.run } Thread.pass until @runner.running? From bd0084fcb433927079d2dd2819752ad6a95f6976 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 11:04:17 -0600 Subject: [PATCH 0899/1191] Require active_support/core_ext/class to use subclasses in Rpc::Service --- lib/protobuf/rpc/service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 327586ed..017acdb0 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/class' + require 'protobuf/logging' require 'protobuf/rpc/client' require 'protobuf/rpc/error' From 29194138e85ed00ef897aaa6d16ab0d4515060d4 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 11:21:36 -0600 Subject: [PATCH 0900/1191] Force cli to symbolize keys so mocked constructor tests pass --- lib/protobuf/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index b522b5e6..3e485b88 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -182,7 +182,7 @@ def require_application(app_file) end def runner_options - opt = options.to_hash + opt = options.to_hash.symbolize_keys opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only From 23e1a181be2bec07d9517e2235f506ee68a12b98 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 11:38:47 -0600 Subject: [PATCH 0901/1191] Update readme to point at correct travis project --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a7d16b1..5308e37f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # protobuf [![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) -[![Build Status](https://secure.travis-ci.org/localshred/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) +[![Build Status](https://secure.travis-ci.org/ruby-protobuf/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) [![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) [![protobuf API Documentation](https://www.omniref.com/ruby/gems/protobuf.png)](https://www.omniref.com/ruby/gems/protobuf) From bf9b0276554841ba2afe18dbb933d642eb693de8 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 1 Jul 2015 15:58:08 -0600 Subject: [PATCH 0902/1191] a newer rubocop was released and this updates the code to stay inline with new cops/updates --- .rubocop.yml | 3 +++ lib/protobuf/cli.rb | 3 +-- lib/protobuf/message/fields.rb | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c4311848..1fc5df61 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,6 +9,9 @@ Lint/Loop: Metrics/ClassLength: Enabled: false +Metrics/ModuleLength: + Enabled: false + Style/CaseIndentation: IndentWhenRelativeTo: end diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3fe340bf..a0c2c307 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -118,8 +118,7 @@ def configure_runner_mode :socket elsif options.zmq? :zmq - else # rubocop:disable Style/ElseAlignment - # above: https://github.com/bbatsov/rubocop/pull/1470/files + else case server_type = ENV["PB_SERVER_TYPE"] when nil, /socket/i :socket diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 5b081ffc..906d46fc 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -12,8 +12,10 @@ def self.extended(other) :get_field_by_tag => :get_field, ) - def inherited(subclass) - inherit_fields!(subclass) + other.class_eval do + def self.inherited(subclass) + inherit_fields!(subclass) + end end end From a5b69ce0b5e195bd4ce6b97314b2943acea7a728 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 21:45:01 -0600 Subject: [PATCH 0903/1191] Thread can be sleeping under MRI, fix by using alive? For some reason, the broker thread will be sleeping under MRI and therefore will fail the !@broker_thread.stop? condition. Switching to @broker_thread.alive? fixes this and allows protobuf to function normally. --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 83e21d2d..f2c2d9e8 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -284,7 +284,7 @@ def init_zmq_context end def start_broker - return if @broker && @broker.running? && !@broker_thread.stop? + return if @broker && @broker.running? && @broker_thread.alive? if @broker && !@broker.running? broadcast_flatline if broadcast_busy? @broker_thread.join if @broker_thread From 71fd6ae9185c53764dd665da7e45e8fbb73853da Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 2 Jul 2015 08:40:15 -0600 Subject: [PATCH 0904/1191] move inherited hook to ClassMethods --- lib/protobuf/message/fields.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 906d46fc..32cbb90b 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -11,15 +11,12 @@ def self.extended(other) :get_field_by_name => :get_field, :get_field_by_tag => :get_field, ) - - other.class_eval do - def self.inherited(subclass) - inherit_fields!(subclass) - end - end end module ClassMethods + def inherited(subclass) + inherit_fields!(subclass) + end ## # Field Definition Methods From b5c07d11453a9ae5664aa60e91b7a573a0b18797 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 2 Jul 2015 10:10:00 -0600 Subject: [PATCH 0905/1191] bump to 3.5.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 4a7a8256..5408793c 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.0' + VERSION = '3.5.1' end From 580efd65ae7108f1fd2d5f901bb3a8bf0dd5e870 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 2 Jul 2015 10:11:32 -0600 Subject: [PATCH 0906/1191] add changes for 3.5.1 --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ad027618..aba3d531 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Stable (3.x) +3.5.1 +-------- +- Adds compatibility for Rails 4.2+ as CLI options were broken +- Fixes bug with MRI and "dead" thread in zmq broker +- Fixes Rubocop compatability with new version + 3.0.4 -------- From 095e7197743430fa5a73133619b721b83610ce07 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Fri, 25 Sep 2015 10:47:30 -0700 Subject: [PATCH 0907/1191] Optimized valid_tag?, enums_for_tag and enums_for_tags --- lib/protobuf/enum.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 3fc171ac..fdf0725d 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -58,6 +58,15 @@ def self.define(name, tag) const_set(name, enum) end + # Internal: A mapping of enum number -> enums defined + # used for speeding up our internal enum methods. + def self.mapped_enums + @mapped_enums ||= enums.each_with_object({}) do |enum, hash| + list = hash[enum.to_i] ||= [] + list << enum + end + end + # Public: All defined enums. # class << self @@ -83,9 +92,7 @@ class << self # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - enums.select do |enum| - enum.to_i == tag.to_i - end + mapped_enums[tag.to_i] || [] end # Public: Get the Enum associated with the given name. @@ -120,7 +127,8 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - enums_for_tag(tag).first + value = mapped_enums[tag.to_i] + value ? value.first : nil end # Public: Get an Enum by a variety of type-checking mechanisms. @@ -198,7 +206,7 @@ def self.name_for_tag(tag) # Returns a boolean. # def self.valid_tag?(tag) - tag.respond_to?(:to_i) && all_tags.include?(tag.to_i) + tag.respond_to?(:to_i) && mapped_enums.key?(tag.to_i) end # Public: [DEPRECATED] Return a hash of Enum objects keyed From a08db9dea9ff73754c4c219ca2ab0188da48e6a1 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Fri, 25 Sep 2015 12:35:32 -0700 Subject: [PATCH 0908/1191] Updated rubocop_todo.yml --- .rubocop_todo.yml | 92 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 93749c19..bda0f0ee 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,33 +1,35 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2014-12-23 08:21:59 -0800 using RuboCop version 0.28.0. +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2015-09-25 12:31:31 -0700 using RuboCop version 0.34.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 29 +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect. +Lint/EndAlignment: + Enabled: false + +# Offense count: 31 Metrics/AbcSize: Max: 59 -# Offense count: 3 +# Offense count: 1 Metrics/BlockNesting: Max: 5 -# Offense count: 8 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 232 - -# Offense count: 3 +# Offense count: 6 Metrics/CyclomaticComplexity: Max: 10 -# Offense count: 491 +# Offense count: 493 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 43 +# Offense count: 44 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 38 @@ -37,23 +39,41 @@ Metrics/MethodLength: Metrics/ParameterLists: Max: 6 -# Offense count: 3 +# Offense count: 6 Metrics/PerceivedComplexity: Max: 11 -# Offense count: 189 +# Offense count: 1 +# Cop supports --auto-correct. +Performance/StringReplacement: + Exclude: + - 'lib/protobuf/rpc/buffer.rb' + +# Offense count: 127 +# Configuration parameters: Exclude. Style/Documentation: Enabled: false # Offense count: 12 Style/DoubleNegation: - Enabled: false + Exclude: + - 'lib/protobuf.rb' + - 'lib/protobuf/cli.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + - 'lib/protobuf/rpc/servers/zmq/broker.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + - 'lib/protobuf/rpc/servers/zmq/worker.rb' + - 'lib/protobuf/rpc/service_directory.rb' # Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyElse: - Enabled: false + Exclude: + - 'lib/protobuf/enum.rb' + - 'lib/protobuf/message/fields.rb' -# Offense count: 73 +# Offense count: 77 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyLinesAroundBlockBody: @@ -71,17 +91,53 @@ Style/EmptyLinesAroundClassBody: Style/EmptyLinesAroundModuleBody: Enabled: false +# Offense count: 2 +Style/IndentationWidth: + Exclude: + - 'protobuf.gemspec' + - 'lib/protobuf/cli.rb' + +# Offense count: 3 +Style/ElseAlignment: + Exclude: + - 'protobuf.gemspec' + - 'lib/protobuf/cli.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Style/ExtraSpacing: + Exclude: + - 'lib/protobuf/rpc/connectors/common.rb' + - 'lib/protobuf/rpc/connectors/socket.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + - 'lib/protobuf/rpc/servers/socket/server.rb' + - 'spec/lib/protobuf/rpc/service_directory_spec.rb' + # Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: MinDigits: 21 -# Offense count: 463 +# Offense count: 473 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/StringLiterals: Enabled: false +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +Style/SymbolProc: + Exclude: + - 'lib/protobuf/generators/printable.rb' + - 'lib/protobuf/rpc/servers/socket/server.rb' + - 'spec/encoding/all_types_spec.rb' + - 'spec/encoding/extreme_values_spec.rb' + - 'spec/functional/socket_server_spec.rb' + - 'spec/functional/zmq_server_spec.rb' + - 'spec/lib/protobuf/rpc/servers/socket_server_spec.rb' + # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: WordRegex. From f04d6706f1b4b337d57a6bcd314802b5e7cb4416 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 25 Sep 2015 17:13:52 -0600 Subject: [PATCH 0909/1191] bump to 3.5.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5408793c..8badc1e3 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.1' + VERSION = '3.5.2' end From 5bac686b7ba9dda4e6c1892515cd53b36ce263b0 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Fri, 25 Sep 2015 14:03:44 -0700 Subject: [PATCH 0910/1191] Optimized get_extension_field and get_field calls --- lib/protobuf/message/fields.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 32cbb90b..bc0309a4 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -78,14 +78,12 @@ def field_tag?(tag, allow_extension = false) end def get_extension_field(name_or_tag) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] + field = field_store[name_or_tag] || str_field_store[name_or_tag] field if field.try(:extension?) { false } end def get_field(name_or_tag, allow_extension = false) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] + field = field_store[name_or_tag] || str_field_store[name_or_tag] if field && (allow_extension || !field.extension?) field @@ -102,6 +100,8 @@ def define_field(rule, type_class, field_name, tag, options) field_store[field_name] = field field_store[tag] = field + str_field_store[field_name.to_s] = field + define_method("#{field_name}!") do @values[field_name] end @@ -126,6 +126,10 @@ def inherit_fields!(subclass) end private :inherit_fields! + def str_field_store + @str_field_store ||= {} + end + private :str_field_store end end end From e44e4ce911e8aabdcddf8649e2c9e969b1fede3e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 27 Sep 2015 11:49:20 -0600 Subject: [PATCH 0911/1191] bump to 3.5.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 8badc1e3..483c12cc 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.2' + VERSION = '3.5.3' end From 654d1946a51d6c35ed3f609e79d0fc116eb21bee Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Sun, 27 Sep 2015 21:05:30 -0700 Subject: [PATCH 0912/1191] Run tests against MRI 2.2 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3b77fb78..e868f214 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ rvm: - 1.9.3 - 2.0.0 - 2.1 + - 2.2 - jruby - rbx-2 env: From 7f68087c8c10914ba5c18634658d0bbb203d6341 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Sun, 27 Sep 2015 19:50:59 -0700 Subject: [PATCH 0913/1191] Optimized varint decoding when varint is available --- lib/protobuf/decoder.rb | 11 ++--------- lib/protobuf/message.rb | 11 +++++++++++ lib/protobuf/varint.rb | 11 +++++++++++ lib/protobuf/varint_pure.rb | 13 +++++++++++++ protobuf.gemspec | 5 +++-- spec/lib/protobuf/varint_spec.rb | 29 +++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 lib/protobuf/varint.rb create mode 100644 lib/protobuf/varint_pure.rb create mode 100644 spec/lib/protobuf/varint_spec.rb diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 601e06f5..ce1255d2 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -16,7 +16,7 @@ def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type when ::Protobuf::WireType::VARINT then - read_varint(stream) + Varint.decode(stream) when ::Protobuf::WireType::FIXED64 then read_fixed64(stream) when ::Protobuf::WireType::LENGTH_DELIMITED then @@ -60,14 +60,7 @@ def self.read_length_delimited(stream) # Read varint integer value from +stream+. def self.read_varint(stream) - value = index = 0 - begin - byte = stream.readbyte - value |= (byte & 0x7f) << (7 * index) - index += 1 - end while (byte & 0x80).nonzero? - value + Varint.decode(stream) end - end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 0e8f95df..6aa70047 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -4,6 +4,17 @@ require 'protobuf/message/fields' require 'protobuf/message/serialization' +# Under MRI, this optimizes proto decoding by around 15% in tests. +# When unavailable, we fall to pure Ruby. +# rubocop:disable Lint/HandleExceptions +begin + require 'varint/varint' +rescue LoadError +end +# rubocop:enable Lint/HandleExceptions + +require 'protobuf/varint' + module Protobuf class Message diff --git a/lib/protobuf/varint.rb b/lib/protobuf/varint.rb new file mode 100644 index 00000000..cfdd1857 --- /dev/null +++ b/lib/protobuf/varint.rb @@ -0,0 +1,11 @@ +require 'protobuf/varint_pure' + +module Protobuf + class Varint + if defined?(::Varint) + extend ::Varint + else + extend VarintPure + end + end +end diff --git a/lib/protobuf/varint_pure.rb b/lib/protobuf/varint_pure.rb new file mode 100644 index 00000000..eeffbecc --- /dev/null +++ b/lib/protobuf/varint_pure.rb @@ -0,0 +1,13 @@ +module Protobuf + module VarintPure + def decode(stream) + value = index = 0 + begin + byte = stream.readbyte + value |= (byte & 0x7f) << (7 * index) + index += 1 + end while (byte & 0x80).nonzero? + value + end + end +end diff --git a/protobuf.gemspec b/protobuf.gemspec index e2b4b5df..ecde63dc 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -43,9 +43,10 @@ require "protobuf/version" s.add_development_dependency pry_debugger s.add_development_dependency 'pry-stack_explorer' + + s.add_development_dependency 'varint' + s.add_development_dependency 'ruby-prof' else s.add_development_dependency 'pry' end - - s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby end diff --git a/spec/lib/protobuf/varint_spec.rb b/spec/lib/protobuf/varint_spec.rb new file mode 100644 index 00000000..3a03d306 --- /dev/null +++ b/spec/lib/protobuf/varint_spec.rb @@ -0,0 +1,29 @@ +require 'base64' +require 'spec_helper' + +RSpec.describe Protobuf::Varint do + VALUES = { + 0 => "AA==", + 5 => "BQ==", + 51 => "Mw==", + 9_192 => "6Ec=", + 80_389 => "hfQE", + 913_389 => "7d83", + 516_192_829_912_693 => "9eyMkpivdQ==", + 9_999_999_999_999_999_999 => "//+fz8jgyOOKAQ==", + } + + [defined?(::Varint) ? ::Varint : nil, Protobuf::VarintPure].compact.each do |klass| + context "with #{klass}" do + before { described_class.extend(klass) } + after { load ::File.expand_path('../../../../lib/protobuf/varint.rb', __FILE__) } + + VALUES.each do |number, encoded| + it "decodes #{number}" do + io = StringIO.new(Base64.decode64(encoded)) + expect(described_class.decode(io)).to eq(number) + end + end + end + end +end From 620a9376dc2e12a442cc89ac0abf927fc996df58 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 28 Sep 2015 10:56:12 -0600 Subject: [PATCH 0914/1191] Ensure ActiveSupport::Deprecation doesn't look for a caller when we have PB_IGNORE_DEPRECATIONS set to true. This turns out to be very expensive --- lib/protobuf/deprecation.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index eac6e4b1..012a3435 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -14,6 +14,15 @@ def deprecate_methods(*args) super end + + def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil) + if ENV.key?('PB_IGNORE_DEPRECATIONS') + # This ensures ActiveSupport::Deprecation doesn't look for the caller, which is very costly. + super(deprecated_method_name, message, ["IGNORING TRACE"]) + else + super(deprecated_method_name, message, caller_backtrace) + end + end end class Deprecation < DeprecationBase From d803c96fafc40fee14a4db4c0983345b229418b2 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 28 Sep 2015 11:16:03 -0600 Subject: [PATCH 0915/1191] Refactor deprecation caller trace to not call super --- lib/protobuf/deprecation.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index 012a3435..8c0d415e 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -16,12 +16,8 @@ def deprecate_methods(*args) end def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil) - if ENV.key?('PB_IGNORE_DEPRECATIONS') - # This ensures ActiveSupport::Deprecation doesn't look for the caller, which is very costly. - super(deprecated_method_name, message, ["IGNORING TRACE"]) - else - super(deprecated_method_name, message, caller_backtrace) - end + # This ensures ActiveSupport::Deprecation doesn't look for the caller, which is very costly. + super(deprecated_method_name, message, caller_backtrace) unless ENV.key?('PB_IGNORE_DEPRECATIONS') end end From 01002f7266b0481ba39b49474c0b58144e58e350 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 28 Sep 2015 11:22:17 -0600 Subject: [PATCH 0916/1191] bump to 3.5.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 483c12cc..c3f26808 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.3' + VERSION = '3.5.4' end From 2e0081f754faf8a2263d84689093feb7c78d67ce Mon Sep 17 00:00:00 2001 From: Michael Ries Date: Fri, 25 Sep 2015 13:50:59 -0600 Subject: [PATCH 0917/1191] resolve rubocop issues --- lib/protobuf/decoder.rb | 30 ++++++++-------- lib/protobuf/field/base_field.rb | 8 ++--- lib/protobuf/generators/printable.rb | 2 +- lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/connectors/socket.rb | 4 +-- lib/protobuf/rpc/connectors/zmq.rb | 4 +-- lib/protobuf/rpc/servers/socket/server.rb | 6 ++-- lib/protobuf/rpc/servers/socket_runner.rb | 14 ++++---- lib/protobuf/rpc/servers/zmq_runner.rb | 14 ++++---- lib/protobuf/rpc/service_filters.rb | 34 +++++++++--------- spec/encoding/all_types_spec.rb | 5 +-- spec/encoding/extreme_values_spec.rb | Bin 1364 -> 1337 bytes spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- .../protobuf/rpc/service_directory_spec.rb | 4 +-- 17 files changed, 65 insertions(+), 70 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 601e06f5..5b29e6aa 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -15,21 +15,21 @@ def self.decode_each_field(stream, &block) def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type - when ::Protobuf::WireType::VARINT then - read_varint(stream) - when ::Protobuf::WireType::FIXED64 then - read_fixed64(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED then - read_length_delimited(stream) - when ::Protobuf::WireType::FIXED32 then - read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP then - fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP then - fail NotImplementedError, 'Group is deprecated.' - else - fail InvalidWireType, wire_type - end + when ::Protobuf::WireType::VARINT then + read_varint(stream) + when ::Protobuf::WireType::FIXED64 then + read_fixed64(stream) + when ::Protobuf::WireType::LENGTH_DELIMITED then + read_length_delimited(stream) + when ::Protobuf::WireType::FIXED32 then + read_fixed32(stream) + when ::Protobuf::WireType::START_GROUP then + fail NotImplementedError, 'Group is deprecated.' + when ::Protobuf::WireType::END_GROUP then + fail NotImplementedError, 'Group is deprecated.' + else + fail InvalidWireType, wire_type + end [tag, bytes] end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 440bbd72..993f06f7 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -69,10 +69,10 @@ def default def default_value @default_value ||= case - when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze - when required? then nil - when optional? then typed_default_value - end + when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze + when required? then nil + when optional? then typed_default_value + end end def deprecated? diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 6347afe2..065ee11d 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -61,7 +61,7 @@ def indent # def modulize(name) name = name.gsub(/\./, '::') - name = name.gsub(/(^(?:::)?[a-z]|::[a-z])/) { |match| match.upcase } + name = name.gsub(/(^(?:::)?[a-z]|::[a-z])/, &:upcase) name end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index aa4b4d1e..92309c04 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -63,7 +63,7 @@ def flushed? def get_data_size # rubocop:disable Style/AccessorMethodName if @size == 0 || @data.match(SIZE_REGEX) sliced_size = @data.slice!(SIZE_REGEX) - @size = sliced_size.gsub('-', '').to_i unless sliced_size.nil? + @size = sliced_size.delete('-').to_i unless sliced_size.nil? end end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index f5067b75..c0fc26bd 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -37,7 +37,7 @@ def data_callback(data) # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) # @param [String] message The error message def failure(code, message) - @error = ClientError.new + @error = ClientError.new @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 4c060f3e..d570e7e0 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -24,7 +24,7 @@ def log_signature def close_connection @socket.close - logger.debug { sign_message('Connector closed') } + logger.debug { sign_message('Connector closed') } end def connect_to_rpc_server @@ -35,7 +35,7 @@ def connect_to_rpc_server # Method to determine error state, must be used with Connector api def error? return true if @error - logger.debug { sign_message("Error state : #{@socket.closed?}") } + logger.debug { sign_message("Error state : #{@socket.closed?}") } @socket.closed? end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 0059c07d..d34239e6 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -220,9 +220,9 @@ def send_request_with_timeout(attempt = 0) logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } raise RequestTimeout ensure - logger.debug { sign_message("Closing Socket") } + logger.debug { sign_message("Closing Socket") } zmq_error_check(socket.close, :socket_close) if socket - logger.debug { sign_message("Socket closed") } + logger.debug { sign_message("Socket closed") } end def server_lookup_attempts diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 72b07a87..eabbbd61 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -60,9 +60,7 @@ def log_signature def new_worker(socket) Thread.new(socket) do |sock| - ::Protobuf::Rpc::Socket::Worker.new(sock) do |s| - s.close - end + ::Protobuf::Rpc::Socket::Worker.new(sock, &:close) end end @@ -97,7 +95,7 @@ def run else unless working.include?(client) working << listen_fds.delete(client) - logger.debug { sign_message("Working") } + logger.debug { sign_message("Working") } threads << { :thread => new_worker(client), :socket => client } cleanup_threads if cleanup? diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 53cfc964..1edb4ab7 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -10,13 +10,13 @@ class SocketRunner def initialize(options) options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Socket Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Socket Server - server options" + end self.server = ::Protobuf::Rpc::Socket::Server.new(options) end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 50f26a15..e4d22838 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -8,13 +8,13 @@ class ZmqRunner def initialize(options) @options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Zmq Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Zmq Server - server options" + end end def run diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 5d76460f..d0c1cace 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -122,11 +122,11 @@ def invoke_via_except?(rpc_method, filter) def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case - when if_check.nil? then - true - else - call_or_send(if_check) - end + when if_check.nil? then + true + else + call_or_send(if_check) + end do_invoke end @@ -152,11 +152,11 @@ def invoke_via_only?(rpc_method, filter) def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case - when unless_check.nil? then - false - else - call_or_send(unless_check) - end + when unless_check.nil? then + false + else + call_or_send(unless_check) + end !skip_invoke end @@ -254,13 +254,13 @@ def run_rescue_filters # def call_or_send(callable, *args, &block) return_value = case - when callable.respond_to?(:call) then - callable.call(self, *args, &block) - when respond_to?(callable, true) then - __send__(callable, *args, &block) - else - fail "Object #{callable} is not callable" - end + when callable.respond_to?(:call) then + callable.call(self, *args, &block) + when respond_to?(callable, true) then + __send__(callable, *args, &block) + else + fail "Object #{callable} is not callable" + end return_value end diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 01b772a3..29122478 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -96,10 +96,7 @@ ) data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__) - data = File.open(data_file_path, 'rb') do |file| - file.read - end - + data = File.open(data_file_path, 'rb', &:read) expect(data).to eq(message.serialize_to_string) end end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index ded4fb02c2df33c6fb8798d5846630806c33659a..a81a4c3d0706b131d0599e2f1e5798440995815f 100644 GIT binary patch delta 21 ccmcb@wUcYZM;1;U1vRUp)Wj6c$)c?G08^F*tpET3 delta 48 ucmdnVb%krgM-~-Lg_L}SnzYQE)EX`YFaWXjic%9(!2Hy_6t2m?SnL6Uiw_O} diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index e46c36ae..9f8b1ec0 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -6,7 +6,7 @@ load "protobuf/socket.rb" @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @runner = ::Protobuf::Rpc::SocketRunner.new(@options) - @server_thread = Thread.new(@runner) { |runner| runner.run } + @server_thread = Thread.new(@runner, &:run) Thread.pass until @runner.running? end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index a764dc1d..bb90974a 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -14,7 +14,7 @@ 'threshold' => 100, 'threads' => 5, ) - @server_thread = Thread.new(@runner) { |runner| runner.run } + @server_thread = Thread.new(@runner, &:run) Thread.pass until @runner.running? end diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index d4947ea3..eccfe5eb 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -14,7 +14,7 @@ @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @runner = ::Protobuf::Rpc::SocketRunner.new(@options) @server = @runner.instance_variable_get(:@server) - @server_thread = Thread.new(@runner) { |runner| runner.run } + @server_thread = Thread.new(@runner, &:run) Thread.pass until @server.running? end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index c15af6a3..268bb021 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -283,8 +283,8 @@ def send_beacon(type, server) it "should perform lookups in constant time" do print "\n\n" Benchmark.bm(17) do |x| - x.report(" 1_000 lookups:") { 1_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } - x.report(" 10_000 lookups:") { 10_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } + x.report(" 1_000 lookups:") { 1_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } + x.report(" 10_000 lookups:") { 10_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } x.report("100_000 lookups:") { 100_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } end end From 86ef9075a2115904b59612c6152717c475164ea9 Mon Sep 17 00:00:00 2001 From: Michael Ries Date: Mon, 28 Sep 2015 22:47:10 -0600 Subject: [PATCH 0918/1191] peg the rubocop version, use keyword version of EndAlignment --- .rubocop.yml | 2 +- lib/protobuf/cli.rb | 44 +++++++++++------------ lib/protobuf/decoder.rb | 30 ++++++++-------- lib/protobuf/field/base_field.rb | 8 ++--- lib/protobuf/rpc/servers/socket_runner.rb | 14 ++++---- lib/protobuf/rpc/servers/zmq_runner.rb | 14 ++++---- lib/protobuf/rpc/service_filters.rb | 34 +++++++++--------- protobuf.gemspec | 10 +++--- 8 files changed, 78 insertions(+), 78 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1fc5df61..9f5f9e92 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ inherit_from: .rubocop_todo.yml Lint/EndAlignment: - AlignWith: variable + AlignWith: keyword Lint/Loop: Enabled: false diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 08ec236c..df4d3bc8 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -114,21 +114,21 @@ def configure_runner_mode debug_say('Configuring runner mode') self.mode = if multi_mode? - say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) - :socket - elsif options.zmq? - :zmq - else - case server_type = ENV["PB_SERVER_TYPE"] - when nil, /socket/i - :socket - when /zmq/i - :zmq - else - say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow - :socket - end - end + say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) + :socket + elsif options.zmq? + :zmq + else + case server_type = ENV["PB_SERVER_TYPE"] + when nil, /socket/i + :socket + when /zmq/i + :zmq + else + say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow + :socket + end + end end # Configure signal traps. @@ -153,13 +153,13 @@ def configure_traps def create_runner debug_say("Creating #{mode} runner") self.runner = case mode - when :zmq - create_zmq_runner - when :socket - create_socket_runner - else - say_and_exit("Unknown runner mode: #{mode}") - end + when :zmq + create_zmq_runner + when :socket + create_socket_runner + else + say_and_exit("Unknown runner mode: #{mode}") + end end # Say something if we're in debug mode. diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 5b29e6aa..601e06f5 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -15,21 +15,21 @@ def self.decode_each_field(stream, &block) def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type - when ::Protobuf::WireType::VARINT then - read_varint(stream) - when ::Protobuf::WireType::FIXED64 then - read_fixed64(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED then - read_length_delimited(stream) - when ::Protobuf::WireType::FIXED32 then - read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP then - fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP then - fail NotImplementedError, 'Group is deprecated.' - else - fail InvalidWireType, wire_type - end + when ::Protobuf::WireType::VARINT then + read_varint(stream) + when ::Protobuf::WireType::FIXED64 then + read_fixed64(stream) + when ::Protobuf::WireType::LENGTH_DELIMITED then + read_length_delimited(stream) + when ::Protobuf::WireType::FIXED32 then + read_fixed32(stream) + when ::Protobuf::WireType::START_GROUP then + fail NotImplementedError, 'Group is deprecated.' + when ::Protobuf::WireType::END_GROUP then + fail NotImplementedError, 'Group is deprecated.' + else + fail InvalidWireType, wire_type + end [tag, bytes] end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 993f06f7..440bbd72 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -69,10 +69,10 @@ def default def default_value @default_value ||= case - when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze - when required? then nil - when optional? then typed_default_value - end + when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze + when required? then nil + when optional? then typed_default_value + end end def deprecated? diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 1edb4ab7..881daa4c 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -10,13 +10,13 @@ class SocketRunner def initialize(options) options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Socket Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Socket Server - server options" + end self.server = ::Protobuf::Rpc::Socket::Server.new(options) end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index e4d22838..50f26a15 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -8,13 +8,13 @@ class ZmqRunner def initialize(options) @options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Zmq Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Zmq Server - server options" + end end def run diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index d0c1cace..5d76460f 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -122,11 +122,11 @@ def invoke_via_except?(rpc_method, filter) def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case - when if_check.nil? then - true - else - call_or_send(if_check) - end + when if_check.nil? then + true + else + call_or_send(if_check) + end do_invoke end @@ -152,11 +152,11 @@ def invoke_via_only?(rpc_method, filter) def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case - when unless_check.nil? then - false - else - call_or_send(unless_check) - end + when unless_check.nil? then + false + else + call_or_send(unless_check) + end !skip_invoke end @@ -254,13 +254,13 @@ def run_rescue_filters # def call_or_send(callable, *args, &block) return_value = case - when callable.respond_to?(:call) then - callable.call(self, *args, &block) - when respond_to?(callable, true) then - __send__(callable, *args, &block) - else - fail "Object #{callable} is not callable" - end + when callable.respond_to?(:call) then + callable.call(self, *args, &block) + when respond_to?(callable, true) then + __send__(callable, *args, &block) + else + fail "Object #{callable} is not callable" + end return_value end diff --git a/protobuf.gemspec b/protobuf.gemspec index e2b4b5df..055076f7 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -27,7 +27,7 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' - s.add_development_dependency 'rubocop' + s.add_development_dependency 'rubocop', '0.34.2' s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' s.add_development_dependency 'yard' @@ -36,10 +36,10 @@ require "protobuf/version" if RUBY_ENGINE.to_sym == :ruby # we don't support MRI < 1.9.3 pry_debugger = if RUBY_VERSION < '2.0.0' - 'pry-debugger' - else - 'pry-byebug' - end + 'pry-debugger' + else + 'pry-byebug' + end s.add_development_dependency pry_debugger s.add_development_dependency 'pry-stack_explorer' From fb26609dd20ba47b897916c89f260a208e7daff1 Mon Sep 17 00:00:00 2001 From: Michael Ries Date: Mon, 28 Sep 2015 22:51:19 -0600 Subject: [PATCH 0919/1191] remove EndAlignment from the TODO list --- .rubocop_todo.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bda0f0ee..880dd05c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect. -Lint/EndAlignment: - Enabled: false - # Offense count: 31 Metrics/AbcSize: Max: 59 From 07b298656ef4a75278b9892c769b188337811538 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 1 Oct 2015 15:33:59 -0400 Subject: [PATCH 0920/1191] bump to 3.5.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c3f26808..e76a9845 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.4' + VERSION = '3.5.5' end From 3addd6071b0a3ee875e9a312ecaa471894d94074 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Tue, 27 Oct 2015 22:50:00 -0600 Subject: [PATCH 0921/1191] Deprecate gc_pause_request with a plan to remove this in 4.0 I think this was an MRI relic that was never removed. In a threaded environment, it doesn't make sense to start and stop the GC per request. It just doesn't work. --- lib/protobuf/cli.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index df4d3bc8..31da71b4 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -39,7 +39,7 @@ class CLI < ::Thor option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' option :broadcast_busy, :type => :boolean, :default => false, :desc => 'Remove busy nodes from cluster when all workers are busy (Currently only available with ZeroMQ).' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' - option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' + option :gc_pause_request, :type => :boolean, :default => false, :desc => 'DEPRECATED: Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' option :workers_only, :type => :boolean, :default => false, :desc => "Starts process with only workers (no broker/frontend is started) only relevant for Zmq Server" option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)" @@ -80,6 +80,8 @@ def configure_deprecation_warnings # If we pause during request we don't need to pause in serialization def configure_gc + say "DEPRECATED: The gc_pause_request option is deprecated and will be removed in 4.0." if options.gc_pause_request? + debug_say('Configuring gc') if defined?(JRUBY_VERSION) From e9f9a30b43328e8aa299f7ed2c074990a2c4a200 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 16 Jan 2016 23:05:10 -0700 Subject: [PATCH 0922/1191] Ensure the ping port is timed out after a reasonable amount of time Should a server's ping port get jammed, overwhelmed, or access a port that is not open, then the ping port check will block until the TCPSocket default timeout rescues the blocked request. Instead, we can wrap Socket to add a reasonable timeout to ping port checks. By default, the timeout is set to 5 seconds, but you can customize this by setting the "PB_RPC_PING_PORT_TIMEOUT" environment variable. --- lib/protobuf/rpc/connectors/ping.rb | 87 +++++++++++++++++++ lib/protobuf/rpc/connectors/zmq.rb | 21 ++--- spec/lib/protobuf/rpc/connectors/ping_spec.rb | 69 +++++++++++++++ spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 17 ++-- 4 files changed, 166 insertions(+), 28 deletions(-) create mode 100644 lib/protobuf/rpc/connectors/ping.rb create mode 100644 spec/lib/protobuf/rpc/connectors/ping_spec.rb diff --git a/lib/protobuf/rpc/connectors/ping.rb b/lib/protobuf/rpc/connectors/ping.rb new file mode 100644 index 00000000..0b8e085d --- /dev/null +++ b/lib/protobuf/rpc/connectors/ping.rb @@ -0,0 +1,87 @@ +require "socket" + +module Protobuf + module Rpc + module Connectors + class Ping + attr_reader :host, :port + + def initialize(host, port) + @host = host + @port = port + end + + def online? + socket = tcp_socket + socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1, 0].pack('ii')) + + true + rescue + false + ensure + begin + socket && socket.close + rescue IOError + nil + end + end + + def timeout + @timeout ||= begin + if ::ENV.key?("PB_RPC_PING_PORT_TIMEOUT") + ::ENV["PB_RPC_PING_PORT_TIMEOUT"].to_i + else + 5 # 5 seconds + end + end + end + + private + + def tcp_socket + # Reference: http://stackoverflow.com/a/21014439/1457934 + socket = ::Socket.new(family, ::Socket::SOCK_STREAM, 0) + socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) + socket.connect_nonblock(sockaddr) + rescue ::IO::WaitWritable + # IO.select will block until the socket is writable or the timeout + # is exceeded - whichever comes first. + if ::IO.select(nil, [socket], nil, timeout) + begin + # Verify there is now a good connection + socket.connect_nonblock(sockaddr) + rescue ::Errno::EISCONN + # Socket is connected. + socket + rescue + # An unexpected exception was raised - the connection is no good. + socket.close + raise + end + else + # IO.select returns nil when the socket is not ready before timeout + # seconds have elapsed + socket.close + raise "Connection Timeout" + end + end + + def family + @family ||= ::Socket.const_get(addrinfo[0][0]) + end + + def addrinfo + @addrinfo ||= ::Socket.getaddrinfo(host, nil) + end + + def ip + @ip ||= addrinfo[0][3] + end + + def sockaddr + @sockaddr ||= ::Socket.pack_sockaddr_in(port, ip) + end + end + end + end +end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index d34239e6..8605f488 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -1,6 +1,7 @@ -require 'thread_safe' -require 'protobuf/rpc/connectors/base' -require 'protobuf/rpc/service_directory' +require "thread_safe" +require "protobuf/rpc/connectors/base" +require "protobuf/rpc/connectors/ping" +require "protobuf/rpc/service_directory" module Protobuf module Rpc @@ -161,19 +162,7 @@ def lookup_server_uri end def ping_port_open?(host) - socket = TCPSocket.new(host, ping_port.to_i) - socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) - socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1, 0].pack('ii')) - - true - rescue - false - ensure - begin - socket && socket.close - rescue IOError - nil - end + Ping.new(host, ping_port.to_i).online? end def rcv_timeout diff --git a/spec/lib/protobuf/rpc/connectors/ping_spec.rb b/spec/lib/protobuf/rpc/connectors/ping_spec.rb new file mode 100644 index 00000000..0f0473b3 --- /dev/null +++ b/spec/lib/protobuf/rpc/connectors/ping_spec.rb @@ -0,0 +1,69 @@ +require "spec_helper" +require "protobuf/zmq" + +::RSpec.describe ::Protobuf::Rpc::Connectors::Ping do + subject { described_class.new("google.com", 80) } + + let(:host) { "google.com" } + let(:port) { 80 } + + describe ".new" do + it "assigns host" do + expect(subject.host).to eq(host) + end + + it "assigns port" do + expect(subject.port).to eq(port) + end + end + + describe "#online?" do + it "closes the socket" do + socket = double(:close => nil, :setsockopt => nil) + allow(subject).to receive(:tcp_socket).and_return(socket) + expect(socket).to receive(:close) + expect(subject).to be_online + end + + context "when a socket can connect" do + let(:socket) { double(:close => nil, :setsockopt => nil) } + before { allow(subject).to receive(:tcp_socket).and_return(socket) } + + it "returns true" do + expect(subject).to be_online + end + end + + context "when a socket error is raised" do + before { allow(subject).to receive(:tcp_socket).and_raise(::Errno::ECONNREFUSED) } + + it "returns false" do + expect(subject).to_not be_online + end + end + + context "when a select timeout is fired" do + let(:wait_writable_class) { ::Class.new(StandardError) { include ::IO::WaitWritable } } + before { expect_any_instance_of(::Socket).to receive(:connect_nonblock).and_raise(wait_writable_class) } + + it "returns false" do + expect(::IO).to receive(:select).and_return(false) + expect(subject).to_not be_online + end + end + end + + describe "#timeout" do + it "uses the default value" do + expect(subject.timeout).to eq(5) + end + + context "when environment variable is set" do + before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "1" } + + it "uses the environmet variable" do + expect(subject.timeout).to eq(1) + end + end + end +end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index b15e94be..abf0a89f 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -93,24 +93,17 @@ context "when the PB_RPC_PING_PORT is set" do before do - ENV["PB_RPC_PING_PORT"] = "3307" + ::ENV["PB_RPC_PING_PORT"] = "3307" end it "returns true when the connection succeeds" do - expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil, :setsockopt => nil)) - expect(subject.send(:host_alive?, "huzzah.com")).to be true + allow_any_instance_of(::Protobuf::Rpc::Connectors::Ping).to receive(:online?).and_return(true) + expect(subject.send(:host_alive?, "huzzah1.com")).to eq(true) end it "returns false when the connection fails" do - expect(TCPSocket).to receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) - expect(subject.send(:host_alive?, "hayoob.com")).to be false - end - - it "closes the socket" do - socket = double("TCPSocket", :setsockopt => nil) - expect(socket).to receive(:close) - expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) - expect(subject.send(:host_alive?, "absorbalof.com")).to be true + allow_any_instance_of(::Protobuf::Rpc::Connectors::Ping).to receive(:online?).and_return(false) + expect(subject.send(:host_alive?, "huzzah2.com")).to eq(false) end end end From c332f1891d4587e13b698459f370be18f2351c2c Mon Sep 17 00:00:00 2001 From: RKushnir Date: Wed, 20 Jan 2016 17:33:32 +0100 Subject: [PATCH 0923/1191] Allow Message#each_field to return an enumerator --- lib/protobuf/message.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6aa70047..f98c33c5 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -73,6 +73,8 @@ def dup # Iterate over every field, invoking the given block # def each_field + return to_enum(:each_field) unless block_given? + self.class.all_fields.each do |field| value = __send__(field.getter) yield(field, value) From 63f46f4a800c5a31efa3861c6f9782171e9a32b6 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 20 Jan 2016 16:12:52 -0700 Subject: [PATCH 0924/1191] Ensure bundler is at the latest version to make travis pass --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e868f214..0f1c54b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y libzmq3-dev - sudo -E ./install-protobuf.sh + - gem update bundler language: ruby rvm: - 1.9.3 From 49aa220e0d9424d24dd40189d382eb63f1bfec5e Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Thu, 21 Jan 2016 09:47:50 -0700 Subject: [PATCH 0925/1191] hostname can be different than ruby's gethostname --- spec/lib/protobuf_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 314909c6..0203f369 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -9,7 +9,7 @@ subject { ::Protobuf.client_host } context 'when client_host is not pre-configured' do - it { is_expected.to eq `hostname`.chomp } + it { is_expected.to eq ::Socket.gethostname } end context 'when client_host is pre-configured' do From deb67728503593dca8845b8ead9cc7e269116e7c Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Mon, 25 Jan 2016 16:55:32 -0800 Subject: [PATCH 0926/1191] fix raise_error rspec warnings --- spec/lib/protobuf/field_spec.rb | 2 +- spec/lib/protobuf/message_spec.rb | 8 ++++---- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index a8efb781..c0eb24d8 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -182,7 +182,7 @@ it 'raises an ArgumentError' do expect do subject.field_class("boom") - end.to raise_error + end.to raise_error(ArgumentError) end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 79c3f331..cadf2528 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -44,12 +44,12 @@ end it 'rejects an unknown value when using the constructor' do - expect { older_message.new(:enum_field => :HOORAY) }.to raise_error + expect { older_message.new(:enum_field => :HOORAY) }.to raise_error(TypeError) end it 'rejects an unknown value when the setter' do older = older_message.new - expect { older.enum_field = :HOORAY }.to raise_error + expect { older.enum_field = :HOORAY }.to raise_error(TypeError) end end @@ -61,12 +61,12 @@ end it 'rejects an unknown value when using the constructor' do - expect { older_message.new(:enum_list => [:HOORAY]) }.to raise_error + expect { older_message.new(:enum_list => [:HOORAY]) }.to raise_error(TypeError) end it 'rejects an unknown value when the setter' do older = older_message.new - expect { older.enum_field = [:HOORAY] }.to raise_error + expect { older.enum_field = [:HOORAY] }.to raise_error(TypeError) end end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index b15e94be..af6cba97 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -69,7 +69,7 @@ it "raises an error" do allow(service_directory).to receive(:all_listings_for).and_return(listings) allow(subject).to receive(:host_alive?).and_return(false) - expect { subject.send(:lookup_server_uri) }.to raise_error + expect { subject.send(:lookup_server_uri) }.to raise_error(RuntimeError) end end From a7016ab6f01c52ced6e3f270066aae3c7c939e74 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 27 Jan 2016 10:37:34 -0800 Subject: [PATCH 0927/1191] fix spec failure with PB_NO_TAG_WARNINGS=1 --- spec/lib/protobuf/generators/base_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index f6bb027b..df29fd2a 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -74,6 +74,8 @@ def compile context 'when tags are missing in the range' do it 'prints a warning' do + allow(ENV).to receive(:key?).and_call_original + allow(ENV).to receive(:key?).with("PB_NO_TAG_WARNINGS").and_return(false) expect(::Protobuf::CodeGenerator).to receive(:print_tag_warning_suppress) expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) described_class.validate_tags("FooBar", [1, 2, 4, 5]) From 39224bef4989b3762f03f7e4b2b579ec638ce452 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 27 Jan 2016 10:42:33 -0800 Subject: [PATCH 0928/1191] consolidate test protos to spec/support/protos - add SUPPORT_PATH, PROTOS_PATH helpers in specs - refresh unittest protos from upstream --- spec/benchmark/tasks.rb | 2 +- spec/data/data.bin | 3 - spec/data/types.bin | Bin 10999 -> 0 bytes spec/encoding/all_types_spec.rb | 55 +-- spec/encoding/extreme_values_spec.rb | Bin 1337 -> 1358 bytes spec/functional/class_inheritance_spec.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/message_spec.rb | 2 + spec/lib/protobuf/rpc/client_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 2 +- spec/spec_helper.rb | 10 +- .../{test => protos}/all_types.data.bin | Bin .../{test => protos}/all_types.data.txt | 0 spec/support/{test => protos}/enum.pb.rb | 2 +- spec/support/{test => protos}/enum.proto | 4 +- .../{test => protos}/extreme_values.data.bin | Bin spec/support/protos/google_unittest.bin | Bin 0 -> 87504 bytes .../{test => protos}/google_unittest.pb.rb | 395 ++++++++++++++---- .../{test => protos}/google_unittest.proto | 296 ++++++++++--- .../google_unittest_import.pb.rb | 19 +- .../google_unittest_import.proto | 29 +- .../google_unittest_import_public.pb.rb | 24 ++ .../google_unittest_import_public.proto | 13 +- .../multi_field_extensions.pb.rb | 0 .../multi_field_extensions.proto | 2 + spec/support/{test => protos}/resource.pb.rb | 0 spec/support/{test => protos}/resource.proto | 2 + spec/support/{test => }/resource_service.rb | 2 +- spec/support/server.rb | 2 +- spec/support/test/defaults.pb.rb | 27 -- spec/support/test/defaults.proto | 9 - spec/support/test/extended.pb.rb | 24 -- spec/support/test/extended.proto | 10 - .../test/google_unittest_import_public.pb.rb | 10 - 36 files changed, 664 insertions(+), 290 deletions(-) delete mode 100644 spec/data/data.bin delete mode 100644 spec/data/types.bin rename spec/support/{test => protos}/all_types.data.bin (100%) rename spec/support/{test => protos}/all_types.data.txt (100%) rename spec/support/{test => protos}/enum.pb.rb (97%) rename spec/support/{test => protos}/enum.proto (92%) rename spec/support/{test => protos}/extreme_values.data.bin (100%) create mode 100644 spec/support/protos/google_unittest.bin rename spec/support/{test => protos}/google_unittest.pb.rb (54%) rename spec/support/{test => protos}/google_unittest.proto (77%) rename spec/support/{test => protos}/google_unittest_import.pb.rb (67%) rename spec/support/{test => protos}/google_unittest_import.proto (80%) create mode 100644 spec/support/protos/google_unittest_import_public.pb.rb rename spec/support/{test => protos}/google_unittest_import_public.proto (88%) rename spec/support/{test => protos}/multi_field_extensions.pb.rb (100%) rename spec/support/{test => protos}/multi_field_extensions.proto (96%) rename spec/support/{test => protos}/resource.pb.rb (100%) rename spec/support/{test => protos}/resource.proto (98%) rename spec/support/{test => }/resource_service.rb (90%) delete mode 100644 spec/support/test/defaults.pb.rb delete mode 100644 spec/support/test/defaults.proto delete mode 100644 spec/support/test/extended.pb.rb delete mode 100644 spec/support/test/extended.proto delete mode 100644 spec/support/test/google_unittest_import_public.pb.rb diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index e6710d6c..aa184cd8 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,7 +1,7 @@ require 'benchmark' require 'protobuf/socket' require 'support/all' -require 'support/test/resource_service' +require SUPPORT_PATH.join('resource_service') case RUBY_ENGINE.to_sym when :ruby diff --git a/spec/data/data.bin b/spec/data/data.bin deleted file mode 100644 index 42632981..00000000 --- a/spec/data/data.bin +++ /dev/null @@ -1,3 +0,0 @@ - -John Doe� jdoe@example.com" -555-4321 \ No newline at end of file diff --git a/spec/data/types.bin b/spec/data/types.bin deleted file mode 100644 index 07e0f18d29188fb0fa5569b53b5226db90c8ec09..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10999 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 diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 29122478..fbd38b46 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper' +require PROTOS_PATH.join('google_unittest.pb') RSpec.describe ::Protobuf do it "correctly encodes all types" do - message = GoogleUnittest::TestAllTypes.new( + message = Protobuf_unittest::TestAllTypes.new( :optional_int32 => 101, :optional_int64 => 102, :optional_uint32 => 103, @@ -18,16 +19,16 @@ :optional_bool => true, :optional_string => "115", :optional_bytes => "116", - :optional_nested_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 118), - :optional_foreign_message => GoogleUnittest::ForeignMessage.new(:c => 119), - :optional_import_message => GoogleUnittestImport::ImportMessage.new(:d => 120), - :optional_nested_enum => GoogleUnittest::TestAllTypes::NestedEnum::BAZ, - :optional_foreign_enum => GoogleUnittest::ForeignEnum::FOREIGN_BAZ, - :optional_import_enum => GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + :optional_nested_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 118), + :optional_foreign_message => Protobuf_unittest::ForeignMessage.new(:c => 119), + :optional_import_message => Protobuf_unittest_import::ImportMessage.new(:d => 120), + :optional_nested_enum => Protobuf_unittest::TestAllTypes::NestedEnum::BAZ, + :optional_foreign_enum => Protobuf_unittest::ForeignEnum::FOREIGN_BAZ, + :optional_import_enum => Protobuf_unittest_import::ImportEnum::IMPORT_BAZ, :optional_string_piece => "124", :optional_cord => "125", - :optional_public_import_message => GoogleUnittestImport::PublicImportMessage.new(:e => 126), - :optional_lazy_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 127), + :optional_public_import_message => Protobuf_unittest_import::PublicImportMessage.new(:e => 126), + :optional_lazy_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 127), :repeated_int32 => [201, 301], :repeated_int64 => [202, 302], :repeated_uint32 => [203, 303], @@ -44,34 +45,34 @@ :repeated_string => ["215", "315"], :repeated_bytes => ["216", "316"], :repeated_nested_message => [ - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 218), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 318), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 218), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 318), ], :repeated_foreign_message => [ - ::GoogleUnittest::ForeignMessage.new(:c => 219), - ::GoogleUnittest::ForeignMessage.new(:c => 319), + ::Protobuf_unittest::ForeignMessage.new(:c => 219), + ::Protobuf_unittest::ForeignMessage.new(:c => 319), ], :repeated_import_message => [ - ::GoogleUnittestImport::ImportMessage.new(:d => 220), - ::GoogleUnittestImport::ImportMessage.new(:d => 320), + ::Protobuf_unittest_import::ImportMessage.new(:d => 220), + ::Protobuf_unittest_import::ImportMessage.new(:d => 320), ], :repeated_nested_enum => [ - ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, - ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ, + ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, + ::Protobuf_unittest::TestAllTypes::NestedEnum::BAZ, ], :repeated_foreign_enum => [ - ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, - ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ, + ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, + ::Protobuf_unittest::ForeignEnum::FOREIGN_BAZ, ], :repeated_import_enum => [ - ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, - ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, + ::Protobuf_unittest_import::ImportEnum::IMPORT_BAZ, ], :repeated_string_piece => ["224", "324"], :repeated_cord => ["225", "325"], :repeated_lazy_message => [ - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 227), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 327), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 227), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 327), ], :default_int32 => 401, :default_int64 => 402, @@ -88,14 +89,14 @@ :default_bool => false, :default_string => "415", :default_bytes => "416", - :default_nested_enum => ::GoogleUnittest::TestAllTypes::NestedEnum::FOO, - :default_foreign_enum => ::GoogleUnittest::ForeignEnum::FOREIGN_FOO, - :default_import_enum => ::GoogleUnittestImport::ImportEnum::IMPORT_FOO, + :default_nested_enum => ::Protobuf_unittest::TestAllTypes::NestedEnum::FOO, + :default_foreign_enum => ::Protobuf_unittest::ForeignEnum::FOREIGN_FOO, + :default_import_enum => ::Protobuf_unittest_import::ImportEnum::IMPORT_FOO, :default_string_piece => "424", :default_cord => "425", ) - data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__) + data_file_path = PROTOS_PATH.join('all_types.data.bin') data = File.open(data_file_path, 'rb', &:read) expect(data).to eq(message.serialize_to_string) end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index a81a4c3d0706b131d0599e2f1e5798440995815f..477e695aa37676462eb7cbcd5cc355e2f7fc387d 100644 GIT binary patch delta 118 zcmdnVb&hL-m|jt8VQFSjszN}Je~5o@e1Kz!hhA2GW}b$6dVYR-PHKE&2YH^8P zL6W-WM9~PYfTH}8{G`&f_|lCf+$>s{8dEDuic)h^hvVQW8rN^^!94)F&Tf GDFy(ra4Hi3 delta 97 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

ryA329Tc?_O$b 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 Bcq{+_ literal 0 HcmV?d00001 diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb similarity index 54% rename from spec/support/test/google_unittest.pb.rb rename to spec/support/protos/google_unittest.pb.rb index c53c564b..d009abd5 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -10,9 +10,9 @@ ## # Imports # -require 'test/google_unittest_import.pb' +require 'protos/google_unittest_import.pb' -module GoogleUnittest +module Protobuf_unittest ## # Enum Classes @@ -23,6 +23,16 @@ class ForeignEnum < ::Protobuf::Enum define :FOREIGN_BAZ, 6 end + class TestEnumWithDupValue < ::Protobuf::Enum + set_option :allow_alias + + define :FOO1, 1 + define :BAR1, 2 + define :BAZ, 3 + define :FOO2, 1 + define :BAR2, 2 + end + class TestSparseEnum < ::Protobuf::Enum define :SPARSE_A, 123 define :SPARSE_B, 62374 @@ -42,15 +52,22 @@ class NestedEnum < ::Protobuf::Enum define :FOO, 1 define :BAR, 2 define :BAZ, 3 + define :NEG, -1 end class NestedMessage < ::Protobuf::Message; end + class OptionalGroup < ::Protobuf::Message; end + class RepeatedGroup < ::Protobuf::Message; end end + class NestedTestAllTypes < ::Protobuf::Message; end class TestDeprecatedFields < ::Protobuf::Message; end class ForeignMessage < ::Protobuf::Message; end + class TestReservedFields < ::Protobuf::Message; end class TestAllExtensions < ::Protobuf::Message; end + class OptionalGroup_extension < ::Protobuf::Message; end + class RepeatedGroup_extension < ::Protobuf::Message; end class TestNestedExtension < ::Protobuf::Message; end class TestRequired < ::Protobuf::Message; end class TestRequiredForeign < ::Protobuf::Message; end @@ -62,7 +79,12 @@ class TestReallyLargeTagNumber < ::Protobuf::Message; end class TestRecursiveMessage < ::Protobuf::Message; end class TestMutualRecursionA < ::Protobuf::Message; end class TestMutualRecursionB < ::Protobuf::Message; end - class TestDupFieldNumber < ::Protobuf::Message; end + class TestDupFieldNumber < ::Protobuf::Message + class Foo < ::Protobuf::Message; end + class Bar < ::Protobuf::Message; end + + end + class TestEagerMessage < ::Protobuf::Message; end class TestLazyMessage < ::Protobuf::Message; end class TestNestedMessageHasBits < ::Protobuf::Message @@ -71,16 +93,53 @@ class NestedMessage < ::Protobuf::Message; end end class TestCamelCaseFieldNames < ::Protobuf::Message; end - class TestFieldOrderings < ::Protobuf::Message; end + class TestFieldOrderings < ::Protobuf::Message + class NestedMessage < ::Protobuf::Message; end + + end + class TestExtremeDefaultValues < ::Protobuf::Message; end class SparseEnumMessage < ::Protobuf::Message; end class OneString < ::Protobuf::Message; end class MoreString < ::Protobuf::Message; end class OneBytes < ::Protobuf::Message; end class MoreBytes < ::Protobuf::Message; end + class Int32Message < ::Protobuf::Message; end + class Uint32Message < ::Protobuf::Message; end + class Int64Message < ::Protobuf::Message; end + class Uint64Message < ::Protobuf::Message; end + class BoolMessage < ::Protobuf::Message; end + class TestOneof < ::Protobuf::Message + class FooGroup < ::Protobuf::Message; end + + end + + class TestOneofBackwardsCompatible < ::Protobuf::Message + class FooGroup < ::Protobuf::Message; end + + end + + class TestOneof2 < ::Protobuf::Message + class NestedEnum < ::Protobuf::Enum + define :FOO, 1 + define :BAR, 2 + define :BAZ, 3 + end + + class FooGroup < ::Protobuf::Message; end + class NestedMessage < ::Protobuf::Message; end + + end + + class TestRequiredOneof < ::Protobuf::Message + class NestedMessage < ::Protobuf::Message; end + + end + class TestPackedTypes < ::Protobuf::Message; end class TestUnpackedTypes < ::Protobuf::Message; end class TestPackedExtensions < ::Protobuf::Message; end + class TestUnpackedExtensions < ::Protobuf::Message; end class TestDynamicExtensions < ::Protobuf::Message class DynamicEnumType < ::Protobuf::Enum define :DYNAMIC_FOO, 2200 @@ -94,7 +153,14 @@ class DynamicMessageType < ::Protobuf::Message; end class TestRepeatedScalarDifferentTagSizes < ::Protobuf::Message; end class TestParsingMerge < ::Protobuf::Message - class RepeatedFieldsGenerator < ::Protobuf::Message; end + class RepeatedFieldsGenerator < ::Protobuf::Message + class Group1 < ::Protobuf::Message; end + class Group2 < ::Protobuf::Message; end + + end + + class OptionalGroup < ::Protobuf::Message; end + class RepeatedGroup < ::Protobuf::Message; end end @@ -115,6 +181,14 @@ class NestedMessage optional :int32, :bb, 1 end + class OptionalGroup + optional :int32, :a, 17 + end + + class RepeatedGroup + optional :int32, :a, 47 + end + optional :int32, :optional_int32, 1 optional :int64, :optional_int64, 2 optional :uint32, :optional_uint32, 3 @@ -130,16 +204,17 @@ class NestedMessage optional :bool, :optional_bool, 13 optional :string, :optional_string, 14 optional :bytes, :optional_bytes, 15 - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message, 18 - optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message, 19 - optional ::GoogleUnittestImport::ImportMessage, :optional_import_message, 20 - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21 - optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum, 22 - optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum, 23 + optional ::Protobuf_unittest::TestAllTypes::OptionalGroup, :optionalgroup, 16 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_nested_message, 18 + optional ::Protobuf_unittest::ForeignMessage, :optional_foreign_message, 19 + optional ::Protobuf_unittest_import::ImportMessage, :optional_import_message, 20 + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21 + optional ::Protobuf_unittest::ForeignEnum, :optional_foreign_enum, 22 + optional ::Protobuf_unittest_import::ImportEnum, :optional_import_enum, 23 optional :string, :optional_string_piece, 24 optional :string, :optional_cord, 25 - optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message, 26 - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27 + optional ::Protobuf_unittest_import::PublicImportMessage, :optional_public_import_message, 26 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27 repeated :int32, :repeated_int32, 31 repeated :int64, :repeated_int64, 32 repeated :uint32, :repeated_uint32, 33 @@ -155,15 +230,16 @@ class NestedMessage repeated :bool, :repeated_bool, 43 repeated :string, :repeated_string, 44 repeated :bytes, :repeated_bytes, 45 - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message, 48 - repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message, 49 - repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message, 50 - repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51 - repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum, 52 - repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum, 53 + repeated ::Protobuf_unittest::TestAllTypes::RepeatedGroup, :repeatedgroup, 46 + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_nested_message, 48 + repeated ::Protobuf_unittest::ForeignMessage, :repeated_foreign_message, 49 + repeated ::Protobuf_unittest_import::ImportMessage, :repeated_import_message, 50 + repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51 + repeated ::Protobuf_unittest::ForeignEnum, :repeated_foreign_enum, 52 + repeated ::Protobuf_unittest_import::ImportEnum, :repeated_import_enum, 53 repeated :string, :repeated_string_piece, 54 repeated :string, :repeated_cord, 55 - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57 + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57 optional :int32, :default_int32, 61, :default => 41 optional :int64, :default_int64, 62, :default => 42 optional :uint32, :default_uint32, 63, :default => 43 @@ -179,11 +255,21 @@ class NestedMessage optional :bool, :default_bool, 73, :default => true optional :string, :default_string, 74, :default => "hello" optional :bytes, :default_bytes, 75, :default => "world" - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR - optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR - optional ::GoogleUnittestImport::ImportEnum, :default_import_enum, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR + optional ::Protobuf_unittest::ForeignEnum, :default_foreign_enum, 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR + optional ::Protobuf_unittest_import::ImportEnum, :default_import_enum, 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR optional :string, :default_string_piece, 84, :default => "abc" optional :string, :default_cord, 85, :default => "123" + optional :uint32, :oneof_uint32, 111 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :oneof_nested_message, 112 + optional :string, :oneof_string, 113 + optional :bytes, :oneof_bytes, 114 + end + + class NestedTestAllTypes + optional ::Protobuf_unittest::NestedTestAllTypes, :child, 1 + optional ::Protobuf_unittest::TestAllTypes, :payload, 2 + repeated ::Protobuf_unittest::NestedTestAllTypes, :repeated_child, 3 end class TestDeprecatedFields @@ -212,16 +298,17 @@ class TestAllExtensions optional :bool, :optional_bool_extension, 13, :extension => true optional :string, :optional_string_extension, 14, :extension => true optional :bytes, :optional_bytes_extension, 15, :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message_extension, 18, :extension => true - optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message_extension, 19, :extension => true - optional ::GoogleUnittestImport::ImportMessage, :optional_import_message_extension, 20, :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum_extension, 21, :extension => true - optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum_extension, 22, :extension => true - optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum_extension, 23, :extension => true + optional ::Protobuf_unittest::OptionalGroup_extension, :optionalgroup_extension, 16, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_nested_message_extension, 18, :extension => true + optional ::Protobuf_unittest::ForeignMessage, :optional_foreign_message_extension, 19, :extension => true + optional ::Protobuf_unittest_import::ImportMessage, :optional_import_message_extension, 20, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :optional_nested_enum_extension, 21, :extension => true + optional ::Protobuf_unittest::ForeignEnum, :optional_foreign_enum_extension, 22, :extension => true + optional ::Protobuf_unittest_import::ImportEnum, :optional_import_enum_extension, 23, :extension => true optional :string, :optional_string_piece_extension, 24, :extension => true optional :string, :optional_cord_extension, 25, :extension => true - optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message_extension, 26, :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message_extension, 27, :extension => true + optional ::Protobuf_unittest_import::PublicImportMessage, :optional_public_import_message_extension, 26, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message_extension, 27, :extension => true repeated :int32, :repeated_int32_extension, 31, :extension => true repeated :int64, :repeated_int64_extension, 32, :extension => true repeated :uint32, :repeated_uint32_extension, 33, :extension => true @@ -237,15 +324,16 @@ class TestAllExtensions repeated :bool, :repeated_bool_extension, 43, :extension => true repeated :string, :repeated_string_extension, 44, :extension => true repeated :bytes, :repeated_bytes_extension, 45, :extension => true - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message_extension, 48, :extension => true - repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message_extension, 49, :extension => true - repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message_extension, 50, :extension => true - repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum_extension, 51, :extension => true - repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum_extension, 52, :extension => true - repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum_extension, 53, :extension => true + repeated ::Protobuf_unittest::RepeatedGroup_extension, :repeatedgroup_extension, 46, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_nested_message_extension, 48, :extension => true + repeated ::Protobuf_unittest::ForeignMessage, :repeated_foreign_message_extension, 49, :extension => true + repeated ::Protobuf_unittest_import::ImportMessage, :repeated_import_message_extension, 50, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :repeated_nested_enum_extension, 51, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :repeated_foreign_enum_extension, 52, :extension => true + repeated ::Protobuf_unittest_import::ImportEnum, :repeated_import_enum_extension, 53, :extension => true repeated :string, :repeated_string_piece_extension, 54, :extension => true repeated :string, :repeated_cord_extension, 55, :extension => true - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message_extension, 57, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message_extension, 57, :extension => true optional :int32, :default_int32_extension, 61, :default => 41, :extension => true optional :int64, :default_int64_extension, 62, :default => 42, :extension => true optional :uint32, :default_uint32_extension, 63, :default => 43, :extension => true @@ -261,14 +349,27 @@ class TestAllExtensions optional :bool, :default_bool_extension, 73, :default => true, :extension => true optional :string, :default_string_extension, 74, :default => "hello", :extension => true optional :bytes, :default_bytes_extension, 75, :default => "world", :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum_extension, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, :extension => true - optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum_extension, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, :extension => true - optional ::GoogleUnittestImport::ImportEnum, :default_import_enum_extension, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :default_nested_enum_extension, 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, :extension => true + optional ::Protobuf_unittest::ForeignEnum, :default_foreign_enum_extension, 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, :extension => true + optional ::Protobuf_unittest_import::ImportEnum, :default_import_enum_extension, 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, :extension => true optional :string, :default_string_piece_extension, 84, :default => "abc", :extension => true optional :string, :default_cord_extension, 85, :default => "123", :extension => true + optional :uint32, :oneof_uint32_extension, 111, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :oneof_nested_message_extension, 112, :extension => true + optional :string, :oneof_string_extension, 113, :extension => true + optional :bytes, :oneof_bytes_extension, 114, :extension => true optional :string, :test, 1002, :default => "test", :extension => true - optional ::GoogleUnittest::TestRequired, :single, 1000, :extension => true - repeated ::GoogleUnittest::TestRequired, :multi, 1001, :extension => true + optional :string, :nested_string_extension, 1003, :extension => true + optional ::Protobuf_unittest::TestRequired, :single, 1000, :extension => true + repeated ::Protobuf_unittest::TestRequired, :multi, 1001, :extension => true + end + + class OptionalGroup_extension + optional :int32, :a, 17 + end + + class RepeatedGroup_extension + optional :int32, :a, 47 end class TestRequired @@ -308,13 +409,13 @@ class TestRequired end class TestRequiredForeign - optional ::GoogleUnittest::TestRequired, :optional_message, 1 - repeated ::GoogleUnittest::TestRequired, :repeated_message, 2 + optional ::Protobuf_unittest::TestRequired, :optional_message, 1 + repeated ::Protobuf_unittest::TestRequired, :repeated_message, 2 optional :int32, :dummy, 3 end class TestForeignNested - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :foreign_nested, 1 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :foreign_nested, 1 end class TestReallyLargeTagNumber @@ -323,59 +424,75 @@ class TestReallyLargeTagNumber end class TestRecursiveMessage - optional ::GoogleUnittest::TestRecursiveMessage, :a, 1 + optional ::Protobuf_unittest::TestRecursiveMessage, :a, 1 optional :int32, :i, 2 end class TestMutualRecursionA - optional ::GoogleUnittest::TestMutualRecursionB, :bb, 1 + optional ::Protobuf_unittest::TestMutualRecursionB, :bb, 1 end class TestMutualRecursionB - optional ::GoogleUnittest::TestMutualRecursionA, :a, 1 + optional ::Protobuf_unittest::TestMutualRecursionA, :a, 1 optional :int32, :optional_int32, 2 end class TestDupFieldNumber + class Foo + optional :int32, :a, 1 + end + + class Bar + optional :int32, :a, 1 + end + optional :int32, :a, 1 + optional ::Protobuf_unittest::TestDupFieldNumber::Foo, :foo, 2 + optional ::Protobuf_unittest::TestDupFieldNumber::Bar, :bar, 3 end class TestEagerMessage - optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 + optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1 end class TestLazyMessage - optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 + optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1 end class TestNestedMessageHasBits class NestedMessage repeated :int32, :nestedmessage_repeated_int32, 1 - repeated ::GoogleUnittest::ForeignMessage, :nestedmessage_repeated_foreignmessage, 2 + repeated ::Protobuf_unittest::ForeignMessage, :nestedmessage_repeated_foreignmessage, 2 end - optional ::GoogleUnittest::TestNestedMessageHasBits::NestedMessage, :optional_nested_message, 1 + optional ::Protobuf_unittest::TestNestedMessageHasBits::NestedMessage, :optional_nested_message, 1 end class TestCamelCaseFieldNames optional :int32, :PrimitiveField, 1 optional :string, :StringField, 2 - optional ::GoogleUnittest::ForeignEnum, :EnumField, 3 - optional ::GoogleUnittest::ForeignMessage, :MessageField, 4 + optional ::Protobuf_unittest::ForeignEnum, :EnumField, 3 + optional ::Protobuf_unittest::ForeignMessage, :MessageField, 4 optional :string, :StringPieceField, 5 optional :string, :CordField, 6 repeated :int32, :RepeatedPrimitiveField, 7 repeated :string, :RepeatedStringField, 8 - repeated ::GoogleUnittest::ForeignEnum, :RepeatedEnumField, 9 - repeated ::GoogleUnittest::ForeignMessage, :RepeatedMessageField, 10 + repeated ::Protobuf_unittest::ForeignEnum, :RepeatedEnumField, 9 + repeated ::Protobuf_unittest::ForeignMessage, :RepeatedMessageField, 10 repeated :string, :RepeatedStringPieceField, 11 repeated :string, :RepeatedCordField, 12 end class TestFieldOrderings + class NestedMessage + optional :int64, :oo, 2 + optional :int32, :bb, 1 + end + optional :string, :my_string, 11 optional :int64, :my_int, 1 optional :float, :my_float, 101 + optional ::Protobuf_unittest::TestFieldOrderings::NestedMessage, :optional_nested_message, 200 # Extension Fields extensions 2...11 extensions 12...101 @@ -410,10 +527,11 @@ class TestExtremeDefaultValues optional :bytes, :bytes_with_zero, 24, :default => "wor\000ld" optional :string, :string_piece_with_zero, 25, :default => "abc" optional :string, :cord_with_zero, 26, :default => "123" + optional :string, :replacement_string, 27, :default => "${unknown}" end class SparseEnumMessage - optional ::GoogleUnittest::TestSparseEnum, :sparse_enum, 1 + optional ::Protobuf_unittest::TestSparseEnum, :sparse_enum, 1 end class OneString @@ -432,6 +550,90 @@ class MoreBytes repeated :bytes, :data, 1 end + class Int32Message + optional :int32, :data, 1 + end + + class Uint32Message + optional :uint32, :data, 1 + end + + class Int64Message + optional :int64, :data, 1 + end + + class Uint64Message + optional :uint64, :data, 1 + end + + class BoolMessage + optional :bool, :data, 1 + end + + class TestOneof + class FooGroup + optional :int32, :a, 5 + optional :string, :b, 6 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional ::Protobuf_unittest::TestAllTypes, :foo_message, 3 + optional ::Protobuf_unittest::TestOneof::FooGroup, :foogroup, 4 + end + + class TestOneofBackwardsCompatible + class FooGroup + optional :int32, :a, 5 + optional :string, :b, 6 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional ::Protobuf_unittest::TestAllTypes, :foo_message, 3 + optional ::Protobuf_unittest::TestOneofBackwardsCompatible::FooGroup, :foogroup, 4 + end + + class TestOneof2 + class FooGroup + optional :int32, :a, 9 + optional :string, :b, 10 + end + + class NestedMessage + optional :int64, :qux_int, 1 + repeated :int32, :corge_int, 2 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional :string, :foo_cord, 3 + optional :string, :foo_string_piece, 4 + optional :bytes, :foo_bytes, 5 + optional ::Protobuf_unittest::TestOneof2::NestedEnum, :foo_enum, 6 + optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_message, 7 + optional ::Protobuf_unittest::TestOneof2::FooGroup, :foogroup, 8 + optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_lazy_message, 11 + optional :int32, :bar_int, 12, :default => 5 + optional :string, :bar_string, 13, :default => "STRING" + optional :string, :bar_cord, 14, :default => "CORD" + optional :string, :bar_string_piece, 15, :default => "SPIECE" + optional :bytes, :bar_bytes, 16, :default => "BYTES" + optional ::Protobuf_unittest::TestOneof2::NestedEnum, :bar_enum, 17, :default => ::Protobuf_unittest::TestOneof2::NestedEnum::BAR + optional :int32, :baz_int, 18 + optional :string, :baz_string, 19, :default => "BAZ" + end + + class TestRequiredOneof + class NestedMessage + required :double, :required_double, 1 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional ::Protobuf_unittest::TestRequiredOneof::NestedMessage, :foo_message, 3 + end + class TestPackedTypes repeated :int32, :packed_int32, 90, :packed => true repeated :int64, :packed_int64, 91, :packed => true @@ -446,7 +648,7 @@ class TestPackedTypes repeated :float, :packed_float, 100, :packed => true repeated :double, :packed_double, 101, :packed => true repeated :bool, :packed_bool, 102, :packed => true - repeated ::GoogleUnittest::ForeignEnum, :packed_enum, 103, :packed => true + repeated ::Protobuf_unittest::ForeignEnum, :packed_enum, 103, :packed => true end class TestUnpackedTypes @@ -463,7 +665,7 @@ class TestUnpackedTypes repeated :float, :unpacked_float, 100 repeated :double, :unpacked_double, 101 repeated :bool, :unpacked_bool, 102 - repeated ::GoogleUnittest::ForeignEnum, :unpacked_enum, 103 + repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum, 103 end class TestPackedExtensions @@ -482,7 +684,26 @@ class TestPackedExtensions repeated :float, :packed_float_extension, 100, :packed => true, :extension => true repeated :double, :packed_double_extension, 101, :packed => true, :extension => true repeated :bool, :packed_bool_extension, 102, :packed => true, :extension => true - repeated ::GoogleUnittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true + end + + class TestUnpackedExtensions + # Extension Fields + extensions 1...536870912 + repeated :int32, :unpacked_int32_extension, 90, :extension => true + repeated :int64, :unpacked_int64_extension, 91, :extension => true + repeated :uint32, :unpacked_uint32_extension, 92, :extension => true + repeated :uint64, :unpacked_uint64_extension, 93, :extension => true + repeated :sint32, :unpacked_sint32_extension, 94, :extension => true + repeated :sint64, :unpacked_sint64_extension, 95, :extension => true + repeated :fixed32, :unpacked_fixed32_extension, 96, :extension => true + repeated :fixed64, :unpacked_fixed64_extension, 97, :extension => true + repeated :sfixed32, :unpacked_sfixed32_extension, 98, :extension => true + repeated :sfixed64, :unpacked_sfixed64_extension, 99, :extension => true + repeated :float, :unpacked_float_extension, 100, :extension => true + repeated :double, :unpacked_double_extension, 101, :extension => true + repeated :bool, :unpacked_bool_extension, 102, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum_extension, 103, :extension => true end class TestDynamicExtensions @@ -491,10 +712,10 @@ class DynamicMessageType end optional :fixed32, :scalar_extension, 2000 - optional ::GoogleUnittest::ForeignEnum, :enum_extension, 2001 - optional ::GoogleUnittest::TestDynamicExtensions::DynamicEnumType, :dynamic_enum_extension, 2002 - optional ::GoogleUnittest::ForeignMessage, :message_extension, 2003 - optional ::GoogleUnittest::TestDynamicExtensions::DynamicMessageType, :dynamic_message_extension, 2004 + optional ::Protobuf_unittest::ForeignEnum, :enum_extension, 2001 + optional ::Protobuf_unittest::TestDynamicExtensions::DynamicEnumType, :dynamic_enum_extension, 2002 + optional ::Protobuf_unittest::ForeignMessage, :message_extension, 2003 + optional ::Protobuf_unittest::TestDynamicExtensions::DynamicMessageType, :dynamic_message_extension, 2004 repeated :string, :repeated_extension, 2005 repeated :sint32, :packed_extension, 2006, :packed => true end @@ -510,20 +731,40 @@ class TestRepeatedScalarDifferentTagSizes class TestParsingMerge class RepeatedFieldsGenerator - repeated ::GoogleUnittest::TestAllTypes, :field1, 1 - repeated ::GoogleUnittest::TestAllTypes, :field2, 2 - repeated ::GoogleUnittest::TestAllTypes, :field3, 3 - repeated ::GoogleUnittest::TestAllTypes, :ext1, 1000 - repeated ::GoogleUnittest::TestAllTypes, :ext2, 1001 + class Group1 + optional ::Protobuf_unittest::TestAllTypes, :field1, 11 + end + + class Group2 + optional ::Protobuf_unittest::TestAllTypes, :field1, 21 + end + + repeated ::Protobuf_unittest::TestAllTypes, :field1, 1 + repeated ::Protobuf_unittest::TestAllTypes, :field2, 2 + repeated ::Protobuf_unittest::TestAllTypes, :field3, 3 + repeated ::Protobuf_unittest::TestParsingMerge::RepeatedFieldsGenerator::Group1, :group1, 10 + repeated ::Protobuf_unittest::TestParsingMerge::RepeatedFieldsGenerator::Group2, :group2, 20 + repeated ::Protobuf_unittest::TestAllTypes, :ext1, 1000 + repeated ::Protobuf_unittest::TestAllTypes, :ext2, 1001 + end + + class OptionalGroup + optional ::Protobuf_unittest::TestAllTypes, :optional_group_all_types, 11 + end + + class RepeatedGroup + optional ::Protobuf_unittest::TestAllTypes, :repeated_group_all_types, 21 end - required ::GoogleUnittest::TestAllTypes, :required_all_types, 1 - optional ::GoogleUnittest::TestAllTypes, :optional_all_types, 2 - repeated ::GoogleUnittest::TestAllTypes, :repeated_all_types, 3 + required ::Protobuf_unittest::TestAllTypes, :required_all_types, 1 + optional ::Protobuf_unittest::TestAllTypes, :optional_all_types, 2 + repeated ::Protobuf_unittest::TestAllTypes, :repeated_all_types, 3 + optional ::Protobuf_unittest::TestParsingMerge::OptionalGroup, :optionalgroup, 10 + repeated ::Protobuf_unittest::TestParsingMerge::RepeatedGroup, :repeatedgroup, 20 # Extension Fields extensions 1000...536870912 - optional ::GoogleUnittest::TestAllTypes, :optional_ext, 1000, :extension => true - repeated ::GoogleUnittest::TestAllTypes, :repeated_ext, 1001, :extension => true + optional ::Protobuf_unittest::TestAllTypes, :optional_ext, 1000, :extension => true + repeated ::Protobuf_unittest::TestAllTypes, :repeated_ext, 1001, :extension => true end class TestCommentInjectionMessage @@ -535,8 +776,8 @@ class TestCommentInjectionMessage # Service Classes # class TestService < ::Protobuf::Rpc::Service - rpc :foo, ::GoogleUnittest::FooRequest, ::GoogleUnittest::FooResponse - rpc :bar, ::GoogleUnittest::BarRequest, ::GoogleUnittest::BarResponse + rpc :foo, ::Protobuf_unittest::FooRequest, ::Protobuf_unittest::FooResponse + rpc :bar, ::Protobuf_unittest::BarRequest, ::Protobuf_unittest::BarResponse end end diff --git a/spec/support/test/google_unittest.proto b/spec/support/protos/google_unittest.proto similarity index 77% rename from spec/support/test/google_unittest.proto rename to spec/support/protos/google_unittest.proto index f97e882c..002f70dc 100644 --- a/spec/support/test/google_unittest.proto +++ b/spec/support/protos/google_unittest.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -34,12 +34,28 @@ // // A proto file we will use for unit testing. -import "test/google_unittest_import.proto"; +syntax = "proto2"; + +// Some generic_services option(s) added automatically. +// See: http://go/proto2-generic-services-default +option cc_generic_services = true; // auto-added +option java_generic_services = true; // auto-added +option py_generic_services = true; // auto-added +option cc_enable_arenas = true; + +import "protos/google_unittest_import.proto"; // We don't put this in a package within proto2 because we need to make sure // that the generated code doesn't depend on being in the proto2 namespace. -// In test_util.h we do "using namespace unittest = google_unittest". -package googleUnittest; +// In test_util.h we do "using namespace unittest = protobuf_unittest". +package protobuf_unittest; + +// Protos optimized for SPEED use a strict superset of the generated code +// of equivalent ones optimized for CODE_SIZE, so we should optimize all our +// tests for speed unless explicitly testing code size optimization. +option optimize_for = SPEED; + +option java_outer_classname = "UnittestProto"; // This proto includes every type of field in both singular and repeated // forms. @@ -55,6 +71,7 @@ message TestAllTypes { FOO = 1; BAR = 2; BAZ = 3; + NEG = -1; // Intentionally negative. } // Singular @@ -74,27 +91,26 @@ message TestAllTypes { optional string optional_string = 14; optional bytes optional_bytes = 15; - // TODO: Support groups - //optional group OptionalGroup = 16 { - // optional int32 a = 17; - //} + optional group OptionalGroup = 16 { + optional int32 a = 17; + } optional NestedMessage optional_nested_message = 18; optional ForeignMessage optional_foreign_message = 19; - optional googleUnittestImport.ImportMessage optional_import_message = 20; + optional protobuf_unittest_import.ImportMessage optional_import_message = 20; optional NestedEnum optional_nested_enum = 21; optional ForeignEnum optional_foreign_enum = 22; - optional googleUnittestImport.ImportEnum optional_import_enum = 23; + optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; optional string optional_string_piece = 24 [ctype=STRING_PIECE]; optional string optional_cord = 25 [ctype=CORD]; // Defined in unittest_import_public.proto - optional googleUnittestImport.PublicImportMessage + optional protobuf_unittest_import.PublicImportMessage optional_public_import_message = 26; - optional NestedMessage optional_lazy_message = 27; // [lazy=true]; + optional NestedMessage optional_lazy_message = 27 [lazy=true]; // Repeated repeated int32 repeated_int32 = 31; @@ -113,23 +129,22 @@ message TestAllTypes { repeated string repeated_string = 44; repeated bytes repeated_bytes = 45; - // TODO: Support groups - //repeated group RepeatedGroup = 46 { - // optional int32 a = 47; - //} + repeated group RepeatedGroup = 46 { + optional int32 a = 47; + } repeated NestedMessage repeated_nested_message = 48; repeated ForeignMessage repeated_foreign_message = 49; - repeated googleUnittestImport.ImportMessage repeated_import_message = 50; + repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; repeated NestedEnum repeated_nested_enum = 51; repeated ForeignEnum repeated_foreign_enum = 52; - repeated googleUnittestImport.ImportEnum repeated_import_enum = 53; + repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; repeated string repeated_cord = 55 [ctype=CORD]; - repeated NestedMessage repeated_lazy_message = 57; // [lazy=true]; + repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; // Singular with defaults optional int32 default_int32 = 61 [default = 41 ]; @@ -150,11 +165,26 @@ message TestAllTypes { optional NestedEnum default_nested_enum = 81 [default = BAR ]; optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; - optional googleUnittestImport.ImportEnum + optional protobuf_unittest_import.ImportEnum default_import_enum = 83 [default = IMPORT_BAR]; optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; optional string default_cord = 85 [ctype=CORD,default="123"]; + + // For oneof test + oneof oneof_field { + uint32 oneof_uint32 = 111; + NestedMessage oneof_nested_message = 112; + string oneof_string = 113; + bytes oneof_bytes = 114; + } +} + +// This proto includes a recusively nested message. +message NestedTestAllTypes { + optional NestedTestAllTypes child = 1; + optional TestAllTypes payload = 2; + repeated NestedTestAllTypes repeated_child = 3; } message TestDeprecatedFields { @@ -173,6 +203,11 @@ enum ForeignEnum { FOREIGN_BAZ = 6; } +message TestReservedFields { + reserved 2, 15, 9 to 11; + reserved "bar", "baz"; +} + message TestAllExtensions { extensions 1 to max; } @@ -195,29 +230,28 @@ extend TestAllExtensions { optional string optional_string_extension = 14; optional bytes optional_bytes_extension = 15; - // TODO: Support groups - //optional group OptionalGroup_extension = 16 { - // optional int32 a = 17; - //} + optional group OptionalGroup_extension = 16 { + optional int32 a = 17; + } optional TestAllTypes.NestedMessage optional_nested_message_extension = 18; optional ForeignMessage optional_foreign_message_extension = 19; - optional googleUnittestImport.ImportMessage + optional protobuf_unittest_import.ImportMessage optional_import_message_extension = 20; optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21; optional ForeignEnum optional_foreign_enum_extension = 22; - optional googleUnittestImport.ImportEnum + optional protobuf_unittest_import.ImportEnum optional_import_enum_extension = 23; optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE]; optional string optional_cord_extension = 25 [ctype=CORD]; - optional googleUnittestImport.PublicImportMessage + optional protobuf_unittest_import.PublicImportMessage optional_public_import_message_extension = 26; optional TestAllTypes.NestedMessage - optional_lazy_message_extension = 27; // [lazy=true]; + optional_lazy_message_extension = 27 [lazy=true]; // Repeated repeated int32 repeated_int32_extension = 31; @@ -236,26 +270,25 @@ extend TestAllExtensions { repeated string repeated_string_extension = 44; repeated bytes repeated_bytes_extension = 45; - // TODO: Support groups - //repeated group RepeatedGroup_extension = 46 { - // optional int32 a = 47; - //} + repeated group RepeatedGroup_extension = 46 { + optional int32 a = 47; + } repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48; repeated ForeignMessage repeated_foreign_message_extension = 49; - repeated googleUnittestImport.ImportMessage + repeated protobuf_unittest_import.ImportMessage repeated_import_message_extension = 50; repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51; repeated ForeignEnum repeated_foreign_enum_extension = 52; - repeated googleUnittestImport.ImportEnum + repeated protobuf_unittest_import.ImportEnum repeated_import_enum_extension = 53; repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE]; repeated string repeated_cord_extension = 55 [ctype=CORD]; repeated TestAllTypes.NestedMessage - repeated_lazy_message_extension = 57; // [lazy=true]; + repeated_lazy_message_extension = 57 [lazy=true]; // Singular with defaults optional int32 default_int32_extension = 61 [default = 41 ]; @@ -278,12 +311,18 @@ extend TestAllExtensions { default_nested_enum_extension = 81 [default = BAR]; optional ForeignEnum default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; - optional googleUnittestImport.ImportEnum + optional protobuf_unittest_import.ImportEnum default_import_enum_extension = 83 [default = IMPORT_BAR]; optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, default="abc"]; optional string default_cord_extension = 85 [ctype=CORD, default="123"]; + + // For oneof test + optional uint32 oneof_uint32_extension = 111; + optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112; + optional string oneof_string_extension = 113; + optional bytes oneof_bytes_extension = 114; } message TestNestedExtension { @@ -291,6 +330,9 @@ message TestNestedExtension { // Check for bug where string extensions declared in tested scope did not // compile. optional string test = 1002 [default="test"]; + // Used to test if generated extension name is correct when there are + // underscores. + optional string nested_string_extension = 1003; } } @@ -395,22 +437,21 @@ message TestMutualRecursionB { } // Test that groups have disjoint field numbers from their siblings and -// parents. This is NOT possible in proto1; only proto2. When attempting +// parents. This is NOT possible in proto1; only google.protobuf. When attempting // to compile with proto1, this will emit an error; so we only include it -// in google_unittest_proto. +// in protobuf_unittest_proto. message TestDupFieldNumber { // NO_PROTO1 optional int32 a = 1; // NO_PROTO1 - // TODO: Support groups - //optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 - //optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 + optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 + optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 } // NO_PROTO1 // Additional messages for testing lazy fields. message TestEagerMessage { - optional TestAllTypes sub_message = 1; // [lazy=false]; + optional TestAllTypes sub_message = 1 [lazy=false]; } message TestLazyMessage { - optional TestAllTypes sub_message = 1; // [lazy=true]; + optional TestAllTypes sub_message = 1 [lazy=true]; } // Needed for a Python test. @@ -424,15 +465,15 @@ message TestNestedMessageHasBits { // Test an enum that has multiple values with the same number. -// TODO: update and test this when the new compiler is released -// enum TestEnumWithDupValue { -// option allow_alias = true; -// FOO1 = 1; -// BAR1 = 2; -// BAZ = 3; -// FOO2 = 1; -// BAR2 = 2; -// } +enum TestEnumWithDupValue { + option allow_alias = true; + + FOO1 = 1; + BAR1 = 2; + BAZ = 3; + FOO2 = 1; + BAR2 = 2; +} // Test an enum with large, unordered values. enum TestSparseEnum { @@ -472,6 +513,15 @@ message TestFieldOrderings { optional int64 my_int = 1; extensions 12 to 100; optional float my_float = 101; + message NestedMessage { + optional int64 oo = 2; + // The field name "b" fails to compile in proto1 because it conflicts with + // a local variable named "b" in one of the generated methods. Doh. + // This file needs to compile in proto1 to test backwards-compatibility. + optional int32 bb = 1; + } + + optional NestedMessage optional_nested_message = 200; } @@ -527,6 +577,7 @@ message TestExtremeDefaultValues { default="ab\000c"]; optional string cord_with_zero = 26 [ctype=CORD, default="12\0003"]; + optional string replacement_string = 27 [default="${unknown}"]; } message SparseEnumMessage { @@ -550,6 +601,100 @@ message MoreBytes { repeated bytes data = 1; } +// Test int32, uint32, int64, uint64, and bool are all compatible +message Int32Message { + optional int32 data = 1; +} + +message Uint32Message { + optional uint32 data = 1; +} + +message Int64Message { + optional int64 data = 1; +} + +message Uint64Message { + optional uint64 data = 1; +} + +message BoolMessage { + optional bool data = 1; +} + +// Test oneofs. +message TestOneof { + oneof foo { + int32 foo_int = 1; + string foo_string = 2; + TestAllTypes foo_message = 3; + group FooGroup = 4 { + optional int32 a = 5; + optional string b = 6; + } + } +} + +message TestOneofBackwardsCompatible { + optional int32 foo_int = 1; + optional string foo_string = 2; + optional TestAllTypes foo_message = 3; + optional group FooGroup = 4 { + optional int32 a = 5; + optional string b = 6; + } +} + +message TestOneof2 { + oneof foo { + int32 foo_int = 1; + string foo_string = 2; + string foo_cord = 3 [ctype=CORD]; + string foo_string_piece = 4 [ctype=STRING_PIECE]; + bytes foo_bytes = 5; + NestedEnum foo_enum = 6; + NestedMessage foo_message = 7; + group FooGroup = 8 { + optional int32 a = 9; + optional string b = 10; + } + NestedMessage foo_lazy_message = 11 [lazy=true]; + } + + oneof bar { + int32 bar_int = 12 [default = 5]; + string bar_string = 13 [default = "STRING"]; + string bar_cord = 14 [ctype=CORD, default = "CORD"]; + string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"]; + bytes bar_bytes = 16 [default = "BYTES"]; + NestedEnum bar_enum = 17 [default = BAR]; + } + + optional int32 baz_int = 18; + optional string baz_string = 19 [default = "BAZ"]; + + message NestedMessage { + optional int64 qux_int = 1; + repeated int32 corge_int = 2; + } + + enum NestedEnum { + FOO = 1; + BAR = 2; + BAZ = 3; + } +} + +message TestRequiredOneof { + oneof foo { + int32 foo_int = 1; + string foo_string = 2; + NestedMessage foo_message = 3; + } + message NestedMessage { + required double required_double = 1; + } +} // Test messages for packed fields @@ -610,6 +755,27 @@ extend TestPackedExtensions { repeated ForeignEnum packed_enum_extension = 103 [packed = true]; } +message TestUnpackedExtensions { + extensions 1 to max; +} + +extend TestUnpackedExtensions { + repeated int32 unpacked_int32_extension = 90 [packed = false]; + repeated int64 unpacked_int64_extension = 91 [packed = false]; + repeated uint32 unpacked_uint32_extension = 92 [packed = false]; + repeated uint64 unpacked_uint64_extension = 93 [packed = false]; + repeated sint32 unpacked_sint32_extension = 94 [packed = false]; + repeated sint64 unpacked_sint64_extension = 95 [packed = false]; + repeated fixed32 unpacked_fixed32_extension = 96 [packed = false]; + repeated fixed64 unpacked_fixed64_extension = 97 [packed = false]; + repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false]; + repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false]; + repeated float unpacked_float_extension = 100 [packed = false]; + repeated double unpacked_double_extension = 101 [packed = false]; + repeated bool unpacked_bool_extension = 102 [packed = false]; + repeated ForeignEnum unpacked_enum_extension = 103 [packed = false]; +} + // Used by ExtensionSetTest/DynamicExtensions. The test actually builds // a set of extensions to TestAllExtensions dynamically, based on the fields // of this message type. @@ -663,26 +829,24 @@ message TestParsingMerge { repeated TestAllTypes field1 = 1; repeated TestAllTypes field2 = 2; repeated TestAllTypes field3 = 3; - // TODO: Support groups - //repeated group Group1 = 10 { - // optional TestAllTypes field1 = 11; - //} - //repeated group Group2 = 20 { - // optional TestAllTypes field1 = 21; - //} + repeated group Group1 = 10 { + optional TestAllTypes field1 = 11; + } + repeated group Group2 = 20 { + optional TestAllTypes field1 = 21; + } repeated TestAllTypes ext1 = 1000; repeated TestAllTypes ext2 = 1001; } required TestAllTypes required_all_types = 1; optional TestAllTypes optional_all_types = 2; repeated TestAllTypes repeated_all_types = 3; - // TODO: Support groups - //optional group OptionalGroup = 10 { - // optional TestAllTypes optional_group_all_types = 11; - //} - //repeated group RepeatedGroup = 20 { - // optional TestAllTypes repeated_group_all_types = 21; - //} + optional group OptionalGroup = 10 { + optional TestAllTypes optional_group_all_types = 11; + } + repeated group RepeatedGroup = 20 { + optional TestAllTypes repeated_group_all_types = 21; + } extensions 1000 to max; extend TestParsingMerge { optional TestAllTypes optional_ext = 1000; diff --git a/spec/support/test/google_unittest_import.pb.rb b/spec/support/protos/google_unittest_import.pb.rb similarity index 67% rename from spec/support/test/google_unittest_import.pb.rb rename to spec/support/protos/google_unittest_import.pb.rb index 1e49a5c3..b81b3f7b 100644 --- a/spec/support/test/google_unittest_import.pb.rb +++ b/spec/support/protos/google_unittest_import.pb.rb @@ -5,7 +5,13 @@ # require 'protobuf/message' -module GoogleUnittestImport + +## +# Imports +# +require 'protos/google_unittest_import_public.pb' + +module Protobuf_unittest_import ## # Enum Classes @@ -16,21 +22,22 @@ class ImportEnum < ::Protobuf::Enum define :IMPORT_BAZ, 9 end + class ImportEnumForMap < ::Protobuf::Enum + define :UNKNOWN, 0 + define :FOO, 1 + define :BAR, 2 + end + ## # Message Classes # - class PublicImportMessage < ::Protobuf::Message; end class ImportMessage < ::Protobuf::Message; end ## # Message Fields # - class PublicImportMessage - optional :int32, :e, 1 - end - class ImportMessage optional :int32, :d, 1 end diff --git a/spec/support/test/google_unittest_import.proto b/spec/support/protos/google_unittest_import.proto similarity index 80% rename from spec/support/test/google_unittest_import.proto rename to spec/support/protos/google_unittest_import.proto index 2814e46f..b64f9cdb 100644 --- a/spec/support/test/google_unittest_import.proto +++ b/spec/support/protos/google_unittest_import.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -34,23 +34,25 @@ // // A proto file which is imported by unittest.proto to test importing. +syntax = "proto2"; // We don't put this in a package within proto2 because we need to make sure // that the generated code doesn't depend on being in the proto2 namespace. // In test_util.h we do // "using namespace unittest_import = protobuf_unittest_import". -package googleUnittestImport; +package protobuf_unittest_import; -//############################## Test public import -// TODO: This will be supported in the next release of the -// compiler -// import public "test/google_unittest_import_public.proto"; +option optimize_for = SPEED; +option cc_enable_arenas = true; -message PublicImportMessage { - optional int32 e = 1; -} +// Exercise the java_package option. +option java_package = "com.google.protobuf.test"; + +// Do not set a java_outer_classname here to verify that Proto2 works without +// one. -//############################### +// Test public import +import public "protos/google_unittest_import_public.proto"; message ImportMessage { optional int32 d = 1; @@ -62,3 +64,10 @@ enum ImportEnum { IMPORT_BAZ = 9; } + +// To use an enum in a map, it must has the first value as 0. +enum ImportEnumForMap { + UNKNOWN = 0; + FOO = 1; + BAR = 2; +} diff --git a/spec/support/protos/google_unittest_import_public.pb.rb b/spec/support/protos/google_unittest_import_public.pb.rb new file mode 100644 index 00000000..8453bfbb --- /dev/null +++ b/spec/support/protos/google_unittest_import_public.pb.rb @@ -0,0 +1,24 @@ +# encoding: utf-8 + +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Protobuf_unittest_import + + ## + # Message Classes + # + class PublicImportMessage < ::Protobuf::Message; end + + + ## + # Message Fields + # + class PublicImportMessage + optional :int32, :e, 1 + end + +end + diff --git a/spec/support/test/google_unittest_import_public.proto b/spec/support/protos/google_unittest_import_public.proto similarity index 88% rename from spec/support/test/google_unittest_import_public.proto rename to spec/support/protos/google_unittest_import_public.proto index 9a57a4f5..ffaf7736 100644 --- a/spec/support/test/google_unittest_import_public.proto +++ b/spec/support/protos/google_unittest_import_public.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -30,9 +30,12 @@ // Author: liujisi@google.com (Pherl Liu) +syntax = "proto2"; -package googleUnittestImport; +package protobuf_unittest_import; -//message PublicImportMessage { -// optional int32 e = 1; -//} +option java_package = "com.google.protobuf.test"; + +message PublicImportMessage { + optional int32 e = 1; +} diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/protos/multi_field_extensions.pb.rb similarity index 100% rename from spec/support/test/multi_field_extensions.pb.rb rename to spec/support/protos/multi_field_extensions.pb.rb diff --git a/spec/support/test/multi_field_extensions.proto b/spec/support/protos/multi_field_extensions.proto similarity index 96% rename from spec/support/test/multi_field_extensions.proto rename to spec/support/protos/multi_field_extensions.proto index 200d74f3..3a9a834d 100644 --- a/spec/support/test/multi_field_extensions.proto +++ b/spec/support/protos/multi_field_extensions.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package test; message Header { diff --git a/spec/support/test/resource.pb.rb b/spec/support/protos/resource.pb.rb similarity index 100% rename from spec/support/test/resource.pb.rb rename to spec/support/protos/resource.pb.rb diff --git a/spec/support/test/resource.proto b/spec/support/protos/resource.proto similarity index 98% rename from spec/support/test/resource.proto rename to spec/support/protos/resource.proto index bf89859f..9cfe79cf 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/protos/resource.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package test; enum StatusType { diff --git a/spec/support/test/resource_service.rb b/spec/support/resource_service.rb similarity index 90% rename from spec/support/test/resource_service.rb rename to spec/support/resource_service.rb index d8642381..8f246b30 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/resource_service.rb @@ -1,4 +1,4 @@ -require ::File.expand_path('../resource.pb', __FILE__) +require PROTOS_PATH.join('resource.pb') Test::ResourceService.class_eval do # request -> Test::ResourceFindRequest diff --git a/spec/support/server.rb b/spec/support/server.rb index d4f30c7d..79881cd4 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -8,7 +8,7 @@ require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/servers/zmq_runner' -require 'spec/support/test/resource_service' +require SUPPORT_PATH.join('resource_service') # Want to abort if server dies? Thread.abort_on_exception = true diff --git a/spec/support/test/defaults.pb.rb b/spec/support/test/defaults.pb.rb deleted file mode 100644 index 24c6c4bf..00000000 --- a/spec/support/test/defaults.pb.rb +++ /dev/null @@ -1,27 +0,0 @@ -# encoding: utf-8 - -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' - -module Test - - ## - # Message Classes - # - class Defaults < ::Protobuf::Message; end - - - ## - # Message Fields - # - class Defaults - optional :bytes, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" - optional :double, :infinity_default, 2, :default => ::Float::INFINITY - optional :float, :neg_infinity_default, 3, :default => -::Float::INFINITY - optional :double, :nan_default, 4, :default => ::Float::NAN - end - -end - diff --git a/spec/support/test/defaults.proto b/spec/support/test/defaults.proto deleted file mode 100644 index 1a657e92..00000000 --- a/spec/support/test/defaults.proto +++ /dev/null @@ -1,9 +0,0 @@ -package test; - -message Defaults { - optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; - optional double infinity_default = 2 [default = inf]; - optional float neg_infinity_default = 3 [default = -inf]; - optional double nan_default = 4 [default = nan]; -} - diff --git a/spec/support/test/extended.pb.rb b/spec/support/test/extended.pb.rb deleted file mode 100644 index a9edae82..00000000 --- a/spec/support/test/extended.pb.rb +++ /dev/null @@ -1,24 +0,0 @@ -# encoding: utf-8 - -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' - - -## -# Imports -# -require 'test/resource.pb' - -module Test - - ## - # Extended Message Fields - # - class ::Test::Resource < ::Protobuf::Message - optional :int64, :deleted_at, 300, :extension => true - end - -end - diff --git a/spec/support/test/extended.proto b/spec/support/test/extended.proto deleted file mode 100644 index f12e60cb..00000000 --- a/spec/support/test/extended.proto +++ /dev/null @@ -1,10 +0,0 @@ -package test; -import 'test/resource.proto'; - -// Test that we will re-open a class and add -// extension fields to it even if there are no -// message or enum definitions in this FileDescriptor. - -extend test.Resource { - optional int64 deleted_at = 300; -} diff --git a/spec/support/test/google_unittest_import_public.pb.rb b/spec/support/test/google_unittest_import_public.pb.rb deleted file mode 100644 index 18434960..00000000 --- a/spec/support/test/google_unittest_import_public.pb.rb +++ /dev/null @@ -1,10 +0,0 @@ -# encoding: utf-8 - -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' - -module GoogleUnittestImport -end - From 008dd9a85891f2e04a29852e580a629c92354be2 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 27 Jan 2016 10:49:12 -0800 Subject: [PATCH 0929/1191] add missing deprecation require --- lib/protobuf/enum.rb | 1 + lib/protobuf/field/base_field.rb | 1 + lib/protobuf/message.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index fdf0725d..4496aaf3 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,4 +1,5 @@ require 'delegate' +require 'protobuf/deprecation' require 'protobuf/optionable' ## diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 440bbd72..0388917f 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,3 +1,4 @@ +require 'protobuf/deprecation' require 'protobuf/field/field_array' require 'protobuf/logging' require 'protobuf/wire_type' diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6aa70047..af53238e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,4 +1,5 @@ require 'protobuf/field' +require 'protobuf/deprecation' require 'protobuf/enum' require 'protobuf/exceptions' require 'protobuf/message/fields' From 7830b4e2c04e4b9a2835ab4cff7cf304bb43d725 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 31 Jan 2016 19:33:09 -0700 Subject: [PATCH 0930/1191] only fetch value once on serialization and cache the varint encoding for most common cases (< 1024) --- lib/protobuf/field/varint_field.rb | 17 ++++++++++++++++- lib/protobuf/message.rb | 10 +++------- lib/protobuf/message/serialization.rb | 4 ---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index affaf393..4f8736fe 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -8,6 +8,7 @@ class VarintField < BaseField # Constants # + CACHE_LIMIT = 1024 INT32_MAX = 2**31 - 1 INT32_MIN = -2**31 INT64_MAX = 2**63 - 1 @@ -23,7 +24,16 @@ def self.default 0 end - def self.encode(value) + # Because all tags and enums are calculated as VarInt it is "most common" to have + # values < CACHE_LIMIT (low numbers) which is defaulting to 1024 + def self.cached_varint(value) + @_varint_cache ||= {} + (@_varint_cache[value] ||= encode(value, false)).dup + end + + def self.encode(value, use_cache = true) + return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT + bytes = [] until value < 128 bytes << (0x80 | (value & 0x7f)) @@ -32,6 +42,11 @@ def self.encode(value) (bytes << value).pack('C*') end + # Load the cache of VarInts on load of file + (0..CACHE_LIMIT).to_a.each do |cached_value| + cached_varint(cached_value) + end + ## # Public Instance Methods # diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6aa70047..d1b22f6f 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -81,15 +81,11 @@ def each_field def each_field_for_serialization self.class.all_fields.each do |field| - next unless field_must_be_serialized?(field) - value = @values[field.getter] + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if value.nil? && field.required? + next if value.nil? - if value.nil? - fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." - else - yield(field, value) - end + yield(field, value) end end diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 5528c10a..6526a95c 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -75,10 +75,6 @@ def encode_to(stream) private - def field_must_be_serialized?(field) - field.required? || ! @values[field.name].nil? - end - def set_field_bytes(tag, bytes) field = self.class.get_field(tag, true) field.set(self, bytes) if field From b4ff74ba3bebbb4bd8dd23e32ab22179278cde1e Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sun, 31 Jan 2016 20:07:21 -0700 Subject: [PATCH 0931/1191] Update changelog for last few releases --- CHANGES.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index aba3d531..918fba91 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,21 @@ # Stable (3.x) +3.5.5 +-------- +- Add native Varint for MRI. + +3.5.4 +-------- +- Ensures ActiveSupport::Deprecation does not get a stack trace when deprecations are disabled. + +3.5.3 +-------- +- Optimized get_extension_field and get_field calls. + +3.5.2 +-------- +- Optimized valid_tag?, enums_for_tag and enums_for_tags + 3.5.1 -------- - Adds compatibility for Rails 4.2+ as CLI options were broken From a28ca82ed1a69a69eca36a3aeed62960842d1b5f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 31 Jan 2016 22:37:39 -0700 Subject: [PATCH 0932/1191] clean up ordered require of SUPPORT_PATH --- spec/benchmark/tasks.rb | 1 + spec/spec_helper.rb | 2 -- spec/support/server.rb | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index aa184cd8..0f7603e1 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,6 +1,7 @@ require 'benchmark' require 'protobuf/socket' require 'support/all' +require 'spec_helper' require SUPPORT_PATH.join('resource_service') case RUBY_ENGINE.to_sym diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2d4fb4f1..bb6c43d1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,8 +28,6 @@ # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") -RSpec.configure(&:disable_monkey_patching!) - ::Protobuf::Rpc::Client.class_eval do def ==(other) connector.options == other.options && \ diff --git a/spec/support/server.rb b/spec/support/server.rb index 79881cd4..8a0203b6 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -2,6 +2,7 @@ require 'active_support/core_ext/hash/reverse_merge' +require 'spec_helper' require 'protobuf/logging' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/server' From b1ea86d0dd9585ce1dc1a9efd26744e296e15328 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 31 Jan 2016 22:43:37 -0700 Subject: [PATCH 0933/1191] bump to 3.6.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index e76a9845..889460e6 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.5' + VERSION = '3.6.0' end From e72d098730b4fc7ccde3514ae75cf26d27762a5b Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Mon, 1 Feb 2016 09:37:04 -0800 Subject: [PATCH 0934/1191] rubocop: exclude generated proto code --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 9f5f9e92..1f6c8f57 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,6 +19,10 @@ Style/ClassAndModuleChildren: Exclude: - '**/*.pb.rb' +Style/ClassAndModuleCamelCase: + Exclude: + - '**/*.pb.rb' + Style/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true From 3b7bf97a2caffbcbfcf6b34d40019771ab173539 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 1 Feb 2016 11:22:12 -0700 Subject: [PATCH 0935/1191] Fix for new ping port check Always return the socket instance after a successful nonblock connect. --- lib/protobuf/rpc/connectors/ping.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/connectors/ping.rb b/lib/protobuf/rpc/connectors/ping.rb index 0b8e085d..66456bd3 100644 --- a/lib/protobuf/rpc/connectors/ping.rb +++ b/lib/protobuf/rpc/connectors/ping.rb @@ -43,6 +43,7 @@ def tcp_socket socket = ::Socket.new(family, ::Socket::SOCK_STREAM, 0) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) socket.connect_nonblock(sockaddr) + socket rescue ::IO::WaitWritable # IO.select will block until the socket is writable or the timeout # is exceeded - whichever comes first. @@ -50,6 +51,7 @@ def tcp_socket begin # Verify there is now a good connection socket.connect_nonblock(sockaddr) + socket rescue ::Errno::EISCONN # Socket is connected. socket From d34849edef1efb39dc820107cadcc4e2d197c81f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 1 Feb 2016 11:26:01 -0700 Subject: [PATCH 0936/1191] bump to 3.6.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 889460e6..c5924004 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.0' + VERSION = '3.6.1' end From 7ee47ad1966f7483b9c843f782a46ff6b24310c8 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Mon, 1 Feb 2016 09:38:25 -0800 Subject: [PATCH 0937/1191] update README links localshred => ruby-protobuf --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5308e37f..45d6a762 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # protobuf [![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) -[![Build Status](https://secure.travis-ci.org/ruby-protobuf/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) -[![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) +[![Build Status](https://secure.travis-ci.org/ruby-protobuf/protobuf.svg?branch=master)](https://travis-ci.org/ruby-protobuf/protobuf) +[![Gitter chat](https://badges.gitter.im/ruby-protobuf/protobuf.svg)](https://gitter.im/ruby-protobuf/protobuf) [![protobuf API Documentation](https://www.omniref.com/ruby/gems/protobuf.png)](https://www.omniref.com/ruby/gems/protobuf) Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. @@ -22,12 +22,12 @@ an [API roadmap][]. See recent changes in the [release notes][] or the [changelog][]. [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" - [wiki]: https://github.com/localshred/protobuf/wiki "Wiki home page" - [Installation Guide]: https://github.com/localshred/protobuf/wiki/Installation "Installation guide" - [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling guide" - [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs guide" - [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API guide" - [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API guide" - [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap guide" - [release notes]: https://github.com/localshred/protobuf/releases "Release notes" - [changelog]: https://github.com/localshred/protobuf/blob/master/CHANGES.md "CHANGES.md" + [wiki]: https://github.com/ruby-protobuf/protobuf/wiki "Wiki home page" + [Installation Guide]: https://github.com/ruby-protobuf/protobuf/wiki/Installation "Installation guide" + [compiling definitions]: https://github.com/ruby-protobuf/protobuf/wiki/Compiling-Definitions "Compiling guide" + [object APIs]: https://github.com/ruby-protobuf/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs guide" + [services]: https://github.com/ruby-protobuf/protobuf/wiki/Services "Services object API guide" + [clients]: https://github.com/ruby-protobuf/protobuf/wiki/Clients "Client object API guide" + [API roadmap]: https://github.com/ruby-protobuf/protobuf/wiki/API-Roadmap "API Roadmap guide" + [release notes]: https://github.com/ruby-protobuf/protobuf/releases "Release notes" + [changelog]: https://github.com/ruby-protobuf/protobuf/blob/master/CHANGES.md "CHANGES.md" From 6209f04817ad8742d52753da96931571a3ef2291 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Tue, 2 Feb 2016 17:51:46 -0800 Subject: [PATCH 0938/1191] fix test failures when running with --order random --- lib/protobuf.rb | 8 ++++---- lib/protobuf/enum.rb | 3 +++ lib/protobuf/message/fields.rb | 3 +++ spec/lib/protobuf/code_generator_spec.rb | 1 - spec/lib/protobuf/enum_spec.rb | 1 + spec/lib/protobuf/message_spec.rb | 15 ++++++++++++--- spec/lib/protobuf_spec.rb | 22 ++++++++++++++++------ 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 18564148..04a95890 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -19,18 +19,18 @@ module Protobuf # Default is Socket as it has no external dependencies. DEFAULT_CONNECTOR = :socket - module_function - class << self # Client Host # # Default: `hostname` of the system # # The name or address of the host to use during client RPC calls. - attr_accessor :client_host + attr_writer :client_host end - self.client_host = Socket.gethostname + def self.client_host + @client_host ||= Socket.gethostname + end # Connector Type # diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 4496aaf3..e42fed90 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -56,6 +56,9 @@ def self.define(name, tag) enum = new(self, name, tag) @enums ||= [] @enums << enum + # defining a new field for the enum will cause cached @values and @mapped_enums + # to be incorrect; reset them + @mapped_enums = @values = nil const_set(name, enum) end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index bc0309a4..d5fda5e6 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -99,6 +99,9 @@ def define_field(rule, type_class, field_name, tag, options) field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) field_store[field_name] = field field_store[tag] = field + # defining a new field for the message will cause cached @all_fields, @extension_fields, + # and @fields to be incorrect; reset them + @all_fields = @extension_fields = @fields = nil str_field_store[field_name.to_s] = field diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 48115829..33038006 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -56,5 +56,4 @@ end end end - end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 399bd814..94d75cbb 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require PROTOS_PATH.join('enum.pb') RSpec.describe Protobuf::Enum do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 525f79b3..f4b345c8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -183,7 +183,12 @@ end context 'ignoring unknown fields' do - before { ::Protobuf.ignore_unknown_fields = true } + around do |example| + orig = ::Protobuf.ignore_unknown_fields? + ::Protobuf.ignore_unknown_fields = true + example.call + ::Protobuf.ignore_unknown_fields = orig + end context 'with valid fields' do let(:values) { { :name => "Jim" } } @@ -203,8 +208,12 @@ end context 'not ignoring unknown fields' do - before { ::Protobuf.ignore_unknown_fields = false } - after { ::Protobuf.ignore_unknown_fields = true } + around do |example| + orig = ::Protobuf.ignore_unknown_fields? + ::Protobuf.ignore_unknown_fields = false + example.call + ::Protobuf.ignore_unknown_fields = orig + end context 'with valid fields' do let(:values) { { :name => "Jim" } } diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 0203f369..a330d9e5 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -56,9 +56,15 @@ end describe '.print_deprecation_warnings?' do - before { described_class.instance_variable_set(:@print_deprecation_warnings, nil) } + around do |example| + orig = described_class.print_deprecation_warnings? + example.call + described_class.print_deprecation_warnings = orig + end it 'defaults to a true value' do + allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(false) + described_class.instance_variable_set('@field_deprecator', nil) expect(described_class.print_deprecation_warnings?).to be true end @@ -69,20 +75,24 @@ context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do it 'defaults to a false value' do - ENV['PB_IGNORE_DEPRECATIONS'] = '1' + allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(true) + described_class.instance_variable_set('@field_deprecator', nil) expect(described_class.print_deprecation_warnings?).to be false end end end describe '.ignore_unknown_fields?' do - before do - if described_class.instance_variable_defined?(:@_ignore_unknown_fields) - described_class.send(:remove_instance_variable, :@_ignore_unknown_fields) - end + around do |example| + orig = described_class.ignore_unknown_fields? + example.call + described_class.ignore_unknown_fields = orig end it 'defaults to a true value' do + if described_class.instance_variable_defined?('@ignore_unknown_fields') + described_class.send(:remove_instance_variable, '@ignore_unknown_fields') + end expect(described_class.ignore_unknown_fields?).to be true end From b49836113d609c6e459d2ea5265c842d20640888 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Feb 2016 19:40:57 -0700 Subject: [PATCH 0939/1191] bump to 3.6.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c5924004..de0faa90 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.1' + VERSION = '3.6.2' end From c5727c03fa0823b1f22877bf6457ac55e7443c37 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:17:39 -0700 Subject: [PATCH 0940/1191] reduce encoder to class method as object instantiation here (#new) was problem of creating new and collecting objects for a small function --- lib/protobuf/encoder.rb | 76 ++++++++++------------------------------- 1 file changed, 18 insertions(+), 58 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index d9d19a26..30581116 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -1,67 +1,27 @@ module Protobuf class Encoder - - def self.encode(stream, message) - new(stream, message).encode - end - - private - - attr_writer :message, :stream - - public - - attr_reader :message, :stream - - def initialize(message, stream) - unless message.respond_to?(:each_field_for_serialization) - fail ArgumentError, "Message instance must respond to :each_field_for_serialization" - end - - self.message = message - self.stream = stream - end - - def encode + def self.encode(message, stream) message.each_field_for_serialization do |field, value| - encode_field(field, value) + if field.repeated? + if field.packed? + key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED + packed_value = value.map { |val| field.encode(val) }.join + stream << ::Protobuf::Field::VarintField.encode(key) + stream << ::Protobuf::Field::VarintField.encode(packed_value.size) + stream << packed_value + else + value.each do |val| + key = (field.tag << 3) | field.wire_type + stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + end + end + else + key = (field.tag << 3) | field.wire_type + stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + end end stream end - - private - - def encode_field(field, value) - if field.repeated? - encode_repeated_field(field, value) - else - write_pair(field, value) - end - end - - def encode_packed_field(field, value) - key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED - packed_value = value.map { |val| field.encode(val) }.join - stream << ::Protobuf::Field::VarintField.encode(key) - stream << ::Protobuf::Field::VarintField.encode(packed_value.size) - stream << packed_value - end - - def encode_repeated_field(field, value) - if field.packed? - encode_packed_field(field, value) - else - value.each { |val| write_pair(field, val) } - end - end - - # Encode key and value, and write to +stream+. - def write_pair(field, value) - key = (field.tag << 3) | field.wire_type - stream << ::Protobuf::Field::VarintField.encode(key) - stream << field.encode(value) - end - end end From 05aa7756e489e792c7bb0785ef2979931a4879a6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:19:34 -0700 Subject: [PATCH 0941/1191] create strings as combination of key size and serialized data as << is not necessary when we have both elements already; also fix RubyProf outputter for MRI; check nil? in String serialization after checking is_a?(String) as assigning String is probably most common case --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/field/bool_field.rb | 11 +++++++---- lib/protobuf/field/bytes_field.rb | 11 ++++++----- lib/protobuf/field/message_field.rb | 6 +----- lib/protobuf/field/string_field.rb | 3 +-- lib/protobuf/field/varint_field.rb | 14 +++----------- lib/protobuf/message.rb | 2 +- lib/protobuf/message/fields.rb | 18 +++++++++--------- spec/benchmark/tasks.rb | 4 +++- 9 files changed, 32 insertions(+), 39 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 0388917f..b1055b65 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -223,7 +223,7 @@ def define_getter message_class.class_eval do define_method(method_name) do - @values.fetch(field.name, field.default_value) + @values[field.name] || field.default_value end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index d1b9efc8..ff5e4885 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -21,10 +21,13 @@ def acceptable?(val) end def coerce!(val) - if val == 'true' - true - elsif val == 'false' - false + case val + when String then + if val == 'true' + true + elsif val == 'false' + false + end else val end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 851daee1..f7755f5e 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -23,7 +23,7 @@ def self.default # def acceptable?(val) - val.nil? || val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(::Protobuf::Message) + val.is_a?(String) || val.nil? || val.is_a?(Symbol) || val.is_a?(::Protobuf::Message) end def decode(bytes) @@ -58,11 +58,12 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| begin - val = "#{val}" if val.is_a?(Symbol) - - if val.nil? + case val + when String, Symbol then + @values[field.name] = "#{val}" + when NilClass then @values.delete(field.name) - elsif field.acceptable?(val) + when ::Protobuf::Message then @values[field.name] = val.dup else fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 2d9f3c92..ec0d0f1e 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,11 +9,7 @@ class MessageField < BaseField # def acceptable?(val) - unless val.is_a?(type_class) || val.respond_to?(:to_hash) - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" - end - - true + val.is_a?(type_class) || val.respond_to?(:to_hash) end def decode(bytes) diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index d1045a03..ac36ea70 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -25,8 +25,7 @@ def encode(value) value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) - string_size << value_to_encode + "#{::Protobuf::Field::VarintField.encode(value_to_encode.size)}#{value_to_encode}" end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 4f8736fe..59fabdcb 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -8,7 +8,7 @@ class VarintField < BaseField # Constants # - CACHE_LIMIT = 1024 + CACHE_LIMIT = 2048 INT32_MAX = 2**31 - 1 INT32_MIN = -2**31 INT64_MAX = 2**63 - 1 @@ -43,7 +43,7 @@ def self.encode(value, use_cache = true) end # Load the cache of VarInts on load of file - (0..CACHE_LIMIT).to_a.each do |cached_value| + (0..CACHE_LIMIT).each do |cached_value| cached_varint(cached_value) end @@ -68,15 +68,7 @@ def decode(value) end def encode(value) - return [value].pack('C') if value < 128 - - bytes = [] - until value == 0 - bytes << (0x80 | (value & 0x7f)) - value >>= 7 - end - bytes[-1] &= 0x7f - bytes.pack('C*') + ::Protobuf::Field::VarintField.encode(value) end def wire_type diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index b20cd4b0..1e3bdd32 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -40,7 +40,7 @@ def self.to_json def initialize(fields = {}) @values = {} - fields.to_hash.each_pair do |name, value| + fields.to_hash.each do |name, value| self[name] = value end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index d5fda5e6..635b7039 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -78,12 +78,12 @@ def field_tag?(tag, allow_extension = false) end def get_extension_field(name_or_tag) - field = field_store[name_or_tag] || str_field_store[name_or_tag] + field = field_store[name_or_tag] field if field.try(:extension?) { false } end def get_field(name_or_tag, allow_extension = false) - field = field_store[name_or_tag] || str_field_store[name_or_tag] + field = field_store[name_or_tag] if field && (allow_extension || !field.extension?) field @@ -97,19 +97,23 @@ def define_field(rule, type_class, field_name, tag, options) raise_if_name_collision(field_name) field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) - field_store[field_name] = field field_store[tag] = field + field_store[field_name] = field + field_store[field_name.to_s] = field # defining a new field for the message will cause cached @all_fields, @extension_fields, # and @fields to be incorrect; reset them @all_fields = @extension_fields = @fields = nil - str_field_store[field_name.to_s] = field - define_method("#{field_name}!") do @values[field_name] end end + def field_name_store + @field_name_store ||= {} + end + private :field_name_store + def raise_if_tag_collision(tag, field_name) if get_field(tag, true) fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) @@ -129,10 +133,6 @@ def inherit_fields!(subclass) end private :inherit_fields! - def str_field_store - @str_field_store ||= {} - end - private :str_field_store end end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 0f7603e1..a939d668 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -107,7 +107,9 @@ def profile_code(output, &block) case RUBY_ENGINE.to_sym when :ruby profile_data = RubyProf.profile(&block) - RubyProf::FlatPrinter.new(profile_data).print(:path => output) + ::File.open(output, "w") do |output_file| + RubyProf::FlatPrinter.new(profile_data).print(output_file) + end when :rbx profiler = Rubinius::Profiler::Instrumenter.new profiler.profile(false, &block) From 7425971e91b308e9311508e89b2023c52d5c1e5d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:31:06 -0700 Subject: [PATCH 0942/1191] unused field_name_store --- lib/protobuf/message/fields.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 635b7039..bb41a2ed 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -109,11 +109,6 @@ def define_field(rule, type_class, field_name, tag, options) end end - def field_name_store - @field_name_store ||= {} - end - private :field_name_store - def raise_if_tag_collision(tag, field_name) if get_field(tag, true) fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) From 036967c7f81a26b7b41b806da841ad9f8aefa29b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:36:45 -0700 Subject: [PATCH 0943/1191] copy type; should encode val for repeated fields --- lib/protobuf/encoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 30581116..97cc2443 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -12,7 +12,7 @@ def self.encode(message, stream) else value.each do |val| key = (field.tag << 3) | field.wire_type - stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(val)}" end end else From 7b9ab5e9484186eeb7f68bca460b2ce9b0a7d463 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:47:52 -0700 Subject: [PATCH 0944/1191] move boolean strings to constants and not checking 2nd case --- lib/protobuf/field/bool_field.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index ff5e4885..71dd5dc4 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -3,6 +3,8 @@ module Protobuf module Field class BoolField < VarintField + FALSE_STRING = "false".freeze + TRUE_STRING = "true".freeze ## # Class Methods @@ -23,9 +25,9 @@ def acceptable?(val) def coerce!(val) case val when String then - if val == 'true' + if val == TRUE_STRING true - elsif val == 'false' + else # acceptable? is called before coerce, so we don't need to check for now false end else From b8188c6a546d735a4229b7c8729467e13b5c3591 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 13:19:39 -0700 Subject: [PATCH 0945/1191] remove some stylistic "then" and do not need to explicitly return false --- lib/protobuf/decoder.rb | 12 ++++++------ lib/protobuf/enum.rb | 13 ++++++------- lib/protobuf/field/bool_field.rb | 8 ++------ lib/protobuf/field/bytes_field.rb | 6 +++--- lib/protobuf/field/message_field.rb | 8 ++++---- lib/protobuf/generators/field_generator.rb | 6 +++--- lib/protobuf/rpc/service_filters.rb | 8 ++++---- spec/benchmark/tasks.rb | 2 +- 8 files changed, 29 insertions(+), 34 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index ce1255d2..aa1f30bf 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -15,17 +15,17 @@ def self.decode_each_field(stream, &block) def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type - when ::Protobuf::WireType::VARINT then + when ::Protobuf::WireType::VARINT Varint.decode(stream) - when ::Protobuf::WireType::FIXED64 then + when ::Protobuf::WireType::FIXED64 read_fixed64(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED then + when ::Protobuf::WireType::LENGTH_DELIMITED read_length_delimited(stream) - when ::Protobuf::WireType::FIXED32 then + when ::Protobuf::WireType::FIXED32 read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP then + when ::Protobuf::WireType::START_GROUP fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP then + when ::Protobuf::WireType::END_GROUP fail NotImplementedError, 'Group is deprecated.' else fail InvalidWireType, wire_type diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index e42fed90..781a4c0e 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -131,8 +131,7 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - value = mapped_enums[tag.to_i] - value ? value.first : nil + (mapped_enums[tag.to_i] || []).first end # Public: Get an Enum by a variety of type-checking mechanisms. @@ -157,11 +156,11 @@ def self.enum_for_tag(tag) # def self.fetch(candidate) case candidate - when self then + when self candidate - when ::Numeric then + when ::Numeric enum_for_tag(candidate.to_i) - when ::String, ::Symbol then + when ::String, ::Symbol enum_for_name(candidate) else nil @@ -280,9 +279,9 @@ def to_int def to_s(format = :tag) case format - when :tag then + when :tag to_i.to_s - when :name then + when :name name.to_s else to_i.to_s diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 71dd5dc4..8b4ee651 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -24,12 +24,8 @@ def acceptable?(val) def coerce!(val) case val - when String then - if val == TRUE_STRING - true - else # acceptable? is called before coerce, so we don't need to check for now - false - end + when String + val == TRUE_STRING else val end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index f7755f5e..518282c8 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -59,11 +59,11 @@ def define_setter define_method(method_name) do |val| begin case val - when String, Symbol then + when String, Symbol @values[field.name] = "#{val}" - when NilClass then + when NilClass @values.delete(field.name) - when ::Protobuf::Message then + when ::Protobuf::Message @values[field.name] = val.dup else fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index ec0d0f1e..6e62cdf4 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -41,13 +41,13 @@ def define_setter message_class.class_eval do define_method("#{field.name}=") do |val| case - when val.nil? then + when val.nil? @values.delete(field.name) - when val.is_a?(field.type_class) then + when val.is_a?(field.type_class) @values[field.name] = val - when val.respond_to?(:to_proto) then + when val.respond_to?(:to_proto) @values[field.name] = val.to_proto - when val.respond_to?(:to_hash) then + when val.respond_to?(:to_hash) @values[field.name] = field.type_class.new(val.to_hash) else fail TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 0c92bc4c..3cd6c553 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -27,11 +27,11 @@ def default_value @default_value ||= begin if defaulted? case descriptor.type.name - when :TYPE_ENUM then + when :TYPE_ENUM enum_default_value - when :TYPE_STRING, :TYPE_BYTES then + when :TYPE_STRING, :TYPE_BYTES string_default_value - when :TYPE_FLOAT, :TYPE_DOUBLE then + when :TYPE_FLOAT, :TYPE_DOUBLE float_double_default_value else verbatim_default_value diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 5d76460f..19593eae 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -122,7 +122,7 @@ def invoke_via_except?(rpc_method, filter) def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case - when if_check.nil? then + when if_check.nil? true else call_or_send(if_check) @@ -152,7 +152,7 @@ def invoke_via_only?(rpc_method, filter) def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case - when unless_check.nil? then + when unless_check.nil? false else call_or_send(unless_check) @@ -254,9 +254,9 @@ def run_rescue_filters # def call_or_send(callable, *args, &block) return_value = case - when callable.respond_to?(:call) then + when callable.respond_to?(:call) callable.call(self, *args, &block) - when respond_to?(callable, true) then + when respond_to?(callable, true) __send__(callable, *args, &block) else fail "Object #{callable} is not callable" diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index a939d668..631439d6 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -97,7 +97,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do - Integer(args[:number]).times { Test::Resource.new(create_params).serialize } + Integer(args[:number]).times { Test::Resource.decode(Test::Resource.new(create_params).serialize) } end puts args[:profile_output] From 6c9c8e34d7080b60691db95d89fa83a0f5f6984d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 4 Feb 2016 08:45:56 -0700 Subject: [PATCH 0946/1191] bump to 3.6.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index de0faa90..e89859d3 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.2' + VERSION = '3.6.3' end From cf5dcfcf725852bdc2c921119943da9026482fca Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:31:31 -0700 Subject: [PATCH 0947/1191] Add memoization to Serialization#encode --- lib/protobuf/message/serialization.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 6526a95c..6fdabf73 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -48,10 +48,12 @@ def decode_from(stream) # Encode this message # def encode - stream = ::StringIO.new - stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream) - stream.string + @memoized_encoded ||= begin + stream = ::StringIO.new + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + stream.string + end end # Encode this message to the given stream. From 35557891c17a149baa799e3c8299d3e3ea06c79d Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:32:17 -0700 Subject: [PATCH 0948/1191] Add @memoized_encoded to setter in message_field.rb --- lib/protobuf/field/message_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 6e62cdf4..ecdd851a 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -40,6 +40,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |val| + @memoized_encoded = nil case when val.nil? @values.delete(field.name) From f4c2fd649c1e457b7a878367ab4a8724dd98e38c Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:32:29 -0700 Subject: [PATCH 0949/1191] Add @memoized_encoded to setter in enum_field.rb --- lib/protobuf/field/enum_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index ac26ea0e..76f4ea60 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -42,6 +42,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |value| + @memoized_encoded = nil orig_value = value if value.nil? @values.delete(field.name) From 7b53903ff3d1cecba9b9d7f37d47bbaa5e8e97af Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:33:16 -0700 Subject: [PATCH 0950/1191] Set @memoized_encoded to eq nil in setter in base_field.rb --- lib/protobuf/field/base_field.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index b1055b65..d83c4d7d 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -21,7 +21,6 @@ class BaseField ## # Attributes # - attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## @@ -195,6 +194,7 @@ def define_array_setter message_class.class_eval do define_method(method_name) do |val| + @memoized_encoded = nil if val.is_a?(Array) val = val.dup val.compact! @@ -236,6 +236,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| + @memoized_encoded = nil if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) From 80864b922a3a401a834277aae68a1f5eb02b768a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:33:29 -0700 Subject: [PATCH 0951/1191] Set @memoized_encoded to eq nil in setter in bytes_field.rb --- lib/protobuf/field/bytes_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 518282c8..69bb89f4 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -57,6 +57,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| + @memoized_encoded = nil begin case val when String, Symbol From 20acff780b41456ded9a12a60de2f9150798a36a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:50:07 -0700 Subject: [PATCH 0952/1191] Add attr_accessor for memoized_encoded --- lib/protobuf/field/base_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d83c4d7d..e973b613 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -21,6 +21,7 @@ class BaseField ## # Attributes # + attr_accessor :memoized_encoded attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## From 09f67ebdb28bb8dd747a5c91fa1d8e4a4fc6a15a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 15:46:38 -0700 Subject: [PATCH 0953/1191] Add memoized_encoded attr_accessor to Message.rb --- lib/protobuf/message.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1e3bdd32..74d335ef 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,6 +26,11 @@ class Message extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization + ## + # Attributes + # + attr_accessor :memoized_encoded + ## # Class Methods # From 0602cbf617206f879117fbf0443943dacc935c2b Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 15:48:10 -0700 Subject: [PATCH 0954/1191] Add specs for Message memoization --- spec/lib/protobuf/message_spec.rb | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index f4b345c8..3e36519c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -268,6 +268,64 @@ end end + describe 'memoization' do + it "should memoize enum message" do + test_enum = Test::EnumTestMessage.new + test_enum.encode + expect(test_enum.instance_variable_get(:@memoized_encoded)).to eq("") + test_enum.non_default_enum = 2 + expect(test_enum.instance_variable_get(:@memoized_encoded)).to be_nil + end + + context "boolean fields" do + let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after bool values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.ext_is_searchable = false + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + + context "string" do + let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after bool values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.name = "MVP" + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + + context "string" do + let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after string values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.name = "MVP" + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + + context "Int64" do + let(:values) { { :name => "STEPH CURRY", :date_created => 1454712125 } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after Int64 values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.date_created = 5554712127 + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + end + context "when there's no value for a required field" do let(:message) { ::Test::ResourceWithRequiredField.new } From 384071af7980c5632032447c45c8eb9ce7e26243 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 15:52:30 -0700 Subject: [PATCH 0955/1191] Yield to block instead of calling block.call in #decode_each_field --- lib/protobuf/decoder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index aa1f30bf..9166b3d1 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -5,10 +5,10 @@ module Protobuf class Decoder # Read bytes from +stream+ and pass to +message+ object. - def self.decode_each_field(stream, &block) + def self.decode_each_field(stream) until stream.eof? tag, bytes = read_field(stream) - block.call(tag, bytes) + yield(tag, bytes) end end From 7ac9207a191dc9434682628e9adea033cbc86870 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 16:00:47 -0700 Subject: [PATCH 0956/1191] Replace @memoized_encoded with @encode --- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/field/enum_field.rb | 2 +- lib/protobuf/field/message_field.rb | 2 +- lib/protobuf/message/serialization.rb | 2 +- spec/lib/protobuf/message_spec.rb | 20 ++++++++++---------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 69bb89f4..30ae4351 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -57,7 +57,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @memoized_encoded = nil + @encode = nil begin case val when String, Symbol diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 76f4ea60..71632cde 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -42,7 +42,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |value| - @memoized_encoded = nil + @encode = nil orig_value = value if value.nil? @values.delete(field.name) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index ecdd851a..8cb37bd7 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -40,7 +40,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |val| - @memoized_encoded = nil + @encode = nil case when val.nil? @values.delete(field.name) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 6fdabf73..668b6cea 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -48,7 +48,7 @@ def decode_from(stream) # Encode this message # def encode - @memoized_encoded ||= begin + @encode ||= begin stream = ::StringIO.new stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) encode_to(stream) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 3e36519c..cc60357c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -272,9 +272,9 @@ it "should memoize enum message" do test_enum = Test::EnumTestMessage.new test_enum.encode - expect(test_enum.instance_variable_get(:@memoized_encoded)).to eq("") + expect(test_enum.instance_variable_get(:@encode)).to eq("") test_enum.non_default_enum = 2 - expect(test_enum.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_enum.instance_variable_get(:@encode)).to be_nil end context "boolean fields" do @@ -283,9 +283,9 @@ it "should memoize after bool values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.ext_is_searchable = false - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end @@ -295,9 +295,9 @@ it "should memoize after bool values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end @@ -307,9 +307,9 @@ it "should memoize after string values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end @@ -319,9 +319,9 @@ it "should memoize after Int64 values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.date_created = 5554712127 - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end end From 50cf59912c2746302f1f7ce9144337ff825a9e4a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 16:31:34 -0700 Subject: [PATCH 0957/1191] Remove attr_accessor for memoized_encoded --- lib/protobuf/field/base_field.rb | 1 - lib/protobuf/message.rb | 5 ----- 2 files changed, 6 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index e973b613..d83c4d7d 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -21,7 +21,6 @@ class BaseField ## # Attributes # - attr_accessor :memoized_encoded attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 74d335ef..1e3bdd32 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,11 +26,6 @@ class Message extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization - ## - # Attributes - # - attr_accessor :memoized_encoded - ## # Class Methods # From 2f8b1fe4ad235ea8e0d84a821038c63074dca9ef Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 16:31:51 -0700 Subject: [PATCH 0958/1191] Change @memoized_encoded to @encode --- lib/protobuf/field/base_field.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d83c4d7d..bed83794 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -194,7 +194,7 @@ def define_array_setter message_class.class_eval do define_method(method_name) do |val| - @memoized_encoded = nil + @encode = nil if val.is_a?(Array) val = val.dup val.compact! @@ -236,7 +236,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @memoized_encoded = nil + @encode = nil if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) From 86cec14a7a5939c6288e2b45d2bd7b09193a65ef Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 13:28:17 -0700 Subject: [PATCH 0959/1191] fix rubocop --- spec/lib/protobuf/message_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index cc60357c..1ac3bff0 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -320,7 +320,7 @@ it "should memoize after Int64 values change " do test_resource.encode expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.date_created = 5554712127 + test_resource.date_created = 5554712127 expect(test_resource.instance_variable_get(:@encode)).to be_nil end end From c13c5fab7eed3f3860456fb5ed72e1130166cba4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 13:56:50 -0700 Subject: [PATCH 0960/1191] already loading field on define and should not need to calcualte the tag encoding at runtime --- lib/protobuf/encoder.rb | 11 +++-------- lib/protobuf/field/base_field.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 97cc2443..8038ae1f 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -4,20 +4,15 @@ def self.encode(message, stream) message.each_field_for_serialization do |field, value| if field.repeated? if field.packed? - key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED packed_value = value.map { |val| field.encode(val) }.join - stream << ::Protobuf::Field::VarintField.encode(key) - stream << ::Protobuf::Field::VarintField.encode(packed_value.size) - stream << packed_value + stream << "#{field.tag_encoded}#{::Protobuf::Field::VarintField.encode(packed_value.size)}#{packed_value}" else value.each do |val| - key = (field.tag << 3) | field.wire_type - stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(val)}" + stream << "#{field.tag_encoded}#{field.encode(val)}" end end else - key = (field.tag << 3) | field.wire_type - stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + stream << "#{field.tag_encoded}#{field.encode(value)}" end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index bed83794..51a39b8c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -45,6 +45,7 @@ def initialize(message_class, rule, type_class, name, tag, options) validate_packed_field if packed? define_accessor + tag_encoded end ## @@ -148,6 +149,17 @@ def setter @setter ||= "#{name}=" end + def tag_encoded + @tag_encoded ||= begin + case + when repeated? && packed? + ::Protobuf::Field::VarintField.encode((self.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED) + else + ::Protobuf::Field::VarintField.encode((self.tag << 3) | self.wire_type) + end + end + end + # FIXME: add packed, deprecated, extension options to to_s output def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" From 08eeded0f26d527badbf406006cc6852dedbca2b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 14:54:15 -0700 Subject: [PATCH 0961/1191] order case calls on probability string > fixed --- lib/protobuf/decoder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 9166b3d1..89d76989 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -17,10 +17,10 @@ def self.read_field(stream) bytes = case wire_type when ::Protobuf::WireType::VARINT Varint.decode(stream) - when ::Protobuf::WireType::FIXED64 - read_fixed64(stream) when ::Protobuf::WireType::LENGTH_DELIMITED read_length_delimited(stream) + when ::Protobuf::WireType::FIXED64 + read_fixed64(stream) when ::Protobuf::WireType::FIXED32 read_fixed32(stream) when ::Protobuf::WireType::START_GROUP From 49af35245b07a44bf839aebb33a961c740f25ef6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 14:55:30 -0700 Subject: [PATCH 0962/1191] keepin the cops happy --- lib/protobuf/field/base_field.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 51a39b8c..c3b949a8 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -153,9 +153,9 @@ def tag_encoded @tag_encoded ||= begin case when repeated? && packed? - ::Protobuf::Field::VarintField.encode((self.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED) + ::Protobuf::Field::VarintField.encode((tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED) else - ::Protobuf::Field::VarintField.encode((self.tag << 3) | self.wire_type) + ::Protobuf::Field::VarintField.encode((tag << 3) | wire_type) end end end From 26898aeaf5076762b6da03cf6e986f1bcb7eec5d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 15:02:38 -0700 Subject: [PATCH 0963/1191] a few fasterer recommendations --- lib/protobuf/field/bytes_field.rb | 24 +++++++++--------------- lib/protobuf/lifecycle.rb | 4 ++-- lib/protobuf/message.rb | 4 ++-- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 30ae4351..b12e1286 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -58,21 +58,15 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| @encode = nil - begin - case val - when String, Symbol - @values[field.name] = "#{val}" - when NilClass - @values.delete(field.name) - when ::Protobuf::Message - @values[field.name] = val.dup - else - fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" - end - rescue NoMethodError => ex - logger.error { ex.message } - logger.error { ex.backtrace.join("\n") } - raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" + case val + when String, Symbol + @values[field.name] = "#{val}" + when NilClass + @values.delete(field.name) + when ::Protobuf::Message + @values[field.name] = val.dup + else + fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 5e96b444..230b99ea 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -1,12 +1,12 @@ module Protobuf class Lifecycle class << self - def register(event_name, &blk) + def register(event_name) fail "Lifecycle register must have a block" unless block_given? event_name = normalized_event_name(event_name) ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| - blk.call(*args) + yield(*args) end end alias_method :on, :register diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1e3bdd32..a240f54b 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -118,10 +118,10 @@ def respond_to_has_and_present?(key) def to_hash result = {} - @values.keys.each do |field_name| + @values.each_key do |field_name| value = __send__(field_name) hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value - result.merge!(field_name => hashed_value) + result[field_name] = hashed_value end result From fe00c64885792a91f02a77815a5dac4eb3a44257 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 15:43:10 -0700 Subject: [PATCH 0964/1191] bump to 3.6.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index e89859d3..eda6ed49 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.3' + VERSION = '3.6.4' end From 39fd8ed60e77f5b6457cec38c611ef65166df2b9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Feb 2016 14:25:30 -0700 Subject: [PATCH 0965/1191] compress decoder to single method; only check nil? once on serialization during required? check; add decoding optimization for enum values in "fetch" --- lib/protobuf/decoder.rb | 69 ++++++++----------------------- lib/protobuf/enum.rb | 2 + lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/field/bytes_field.rb | 13 ++++-- lib/protobuf/message.rb | 6 ++- 5 files changed, 33 insertions(+), 59 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 89d76989..20538595 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -7,60 +7,25 @@ class Decoder # Read bytes from +stream+ and pass to +message+ object. def self.decode_each_field(stream) until stream.eof? - tag, bytes = read_field(stream) + bits = Varint.decode(stream) + wire_type = bits & 0x07 + tag = bits >> 3 + + bytes = if wire_type == ::Protobuf::WireType::VARINT + Varint.decode(stream) + elsif wire_type == ::Protobuf::WireType::LENGTH_DELIMITED + value_length = Varint.decode(stream) + stream.read(value_length) + elsif wire_type == ::Protobuf::WireType::FIXED64 + stream.read(8) + elsif wire_type == ::Protobuf::WireType::FIXED32 + stream.read(4) + else + fail InvalidWireType, wire_type + end + yield(tag, bytes) end end - - def self.read_field(stream) - tag, wire_type = read_key(stream) - bytes = case wire_type - when ::Protobuf::WireType::VARINT - Varint.decode(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED - read_length_delimited(stream) - when ::Protobuf::WireType::FIXED64 - read_fixed64(stream) - when ::Protobuf::WireType::FIXED32 - read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP - fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP - fail NotImplementedError, 'Group is deprecated.' - else - fail InvalidWireType, wire_type - end - - [tag, bytes] - end - - # Read 32-bit string value from +stream+. - def self.read_fixed32(stream) - stream.read(4) - end - - # Read 64-bit string value from +stream+. - def self.read_fixed64(stream) - stream.read(8) - end - - # Read key pair (tag and wire-type) from +stream+. - def self.read_key(stream) - bits = read_varint(stream) - wire_type = bits & 0x07 - tag = bits >> 3 - [tag, wire_type] - end - - # Read length-delimited string value from +stream+. - def self.read_length_delimited(stream) - value_length = read_varint(stream) - stream.read(value_length) - end - - # Read varint integer value from +stream+. - def self.read_varint(stream) - Varint.decode(stream) - end end end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 781a4c0e..961cc1b2 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -155,6 +155,8 @@ def self.enum_for_tag(tag) # Returns an Enum object or nil. # def self.fetch(candidate) + return enum_for_tag(candidate) if candidate.is_a?(::Integer) + case candidate when self candidate diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index c3b949a8..90efcb76 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -70,9 +70,9 @@ def default def default_value @default_value ||= case + when optional? then typed_default_value when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze when required? then nil - when optional? then typed_default_value end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index b12e1286..d7f4aee4 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -33,12 +33,17 @@ def decode(bytes) end def encode(value) - value_to_encode = value.dup - value_to_encode = value.encode if value.is_a?(::Protobuf::Message) - value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + value_to_encode = "" + if value.is_a?(::Protobuf::Message) + value_to_encode = value.encode + else + value_to_encode = value.dup + end + value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) - string_size << value_to_encode + + "#{string_size}#{value_to_encode}" end def wire_type diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a240f54b..9ac1332e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -85,8 +85,10 @@ def each_field def each_field_for_serialization self.class.all_fields.each do |field| value = @values[field.getter] - fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if value.nil? && field.required? - next if value.nil? + if value.nil? + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if field.required? + next + end yield(field, value) end From 3d4ed9b0768e7bf035bfdcccef1aa4ffac0be403 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Feb 2016 15:33:16 -0700 Subject: [PATCH 0966/1191] remove __send__ of method to decoder and optimize to optional fields --- lib/protobuf/field/base_field.rb | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 90efcb76..3ae505a4 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -122,26 +122,18 @@ def required? # FIXME: need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) - if packed? - array = message_instance.__send__(getter) - method = \ - case wire_type - when ::Protobuf::WireType::FIXED32 then :read_fixed32 - when ::Protobuf::WireType::FIXED64 then :read_fixed64 - when ::Protobuf::WireType::VARINT then :read_varint - end - stream = StringIO.new(bytes) - - until stream.eof? - array << decode(::Protobuf::Decoder.__send__(method, stream)) - end - else - value = decode(bytes) - if repeated? - message_instance.__send__(getter) << value - else - message_instance.__send__(setter, value) - end + return message_instance.__send__(setter, decode(bytes)) unless repeated? + return message_instance.__send__(getter) << decode(bytes) unless packed? + + array = message_instance.__send__(getter) + stream = StringIO.new(bytes) + + if wire_type == ::Protobuf::WireType::VARINT + array << Varint.decode(stream) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED64 + array << stream.read(8) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED32 + array << stream.read(4) until stream.eof? end end From a91da395bb2a647698c4cf2db42ec6f8563743f6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Feb 2016 16:03:44 -0700 Subject: [PATCH 0967/1191] bump to 3.6.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index eda6ed49..0f3c9517 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.4' + VERSION = '3.6.5' end From dad7b00c71040c26a2730e3421c8dfd7c549ca60 Mon Sep 17 00:00:00 2001 From: akihiro17 Date: Mon, 8 Feb 2016 17:29:43 +0900 Subject: [PATCH 0968/1191] Fix #define_getter method If a required bool field is set to `false`, #define_getter returns its default value(=nil) wrongly because of the following code. https://github.com/ruby-protobuf/protobuf/blob/master/lib/protobuf/field/base_field.rb#L230 ```ruby def define_getter --- @values[field.name] || field.default_value ``` This behavor was introduced by [this commit](https://github.com/ruby-protobuf/protobuf/commit/05aa7756e489e792c7bb0785ef2979931a4879a6) This commit fixes the above issue --- lib/protobuf/field/base_field.rb | 2 +- spec/lib/protobuf/field/bool_field_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 3ae505a4..674bff4a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -227,7 +227,7 @@ def define_getter message_class.class_eval do define_method(method_name) do - @values[field.name] || field.default_value + @values.fetch(field.name, field.default_value) end end diff --git a/spec/lib/protobuf/field/bool_field_spec.rb b/spec/lib/protobuf/field/bool_field_spec.rb index af254716..aeb27b55 100644 --- a/spec/lib/protobuf/field/bool_field_spec.rb +++ b/spec/lib/protobuf/field/bool_field_spec.rb @@ -4,6 +4,7 @@ class SomeBoolMessage < ::Protobuf::Message optional :bool, :some_bool, 1 + required :bool, :required_bool, 2 end let(:instance) { SomeBoolMessage.new } @@ -48,4 +49,13 @@ class SomeBoolMessage < ::Protobuf::Message end end + describe '#define_getter' do + context 'when required bool field is set to false' do + subject { instance.required_bool = false; instance.required_bool } + + it 'returns false' do + expect(subject).to eq(false) + end + end + end end From 79fd4852b577e199f2201452140940e8226e8307 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 8 Feb 2016 08:58:17 -0700 Subject: [PATCH 0969/1191] Pull bool getter edge case into BoolField class This is a small change, but let's us keep the optimization in base field. --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/field/bool_field.rb | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 674bff4a..3ae505a4 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -227,7 +227,7 @@ def define_getter message_class.class_eval do define_method(method_name) do - @values.fetch(field.name, field.default_value) + @values[field.name] || field.default_value end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 8b4ee651..afe6c112 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -46,13 +46,20 @@ def encode(value) # def define_getter - super - field = self + method_name = field.getter message_class.class_eval do - alias_method "#{field.getter}?", field.getter + define_method(method_name) do + @values.fetch(field.name, field.default_value) + end end + + message_class.class_eval do + alias_method "#{method_name}?", method_name + end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end end From 2970c0d662ce5619c3f52b6d5f2f6a833603d8ad Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 8 Feb 2016 09:26:12 -0700 Subject: [PATCH 0970/1191] Bump version to 3.6.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 0f3c9517..6e6da081 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.5' + VERSION = '3.6.6' end From ad4d8523f76364db5614243f7cd12ec66fa102f5 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 17 Feb 2016 20:12:50 -0700 Subject: [PATCH 0971/1191] Remove memoization on encode Changing values in repeated fields does not clear the memoized encoded value. This means that changes to repated fields after the memoized encoding has been computed will never be encoded. The pattern works for other field types because the memoized value is being cleared in the setter on the message before we call into the field. The field itself is not involved in clearing the memoized value at all. Repeated fields are a different story. If we were completely resetting a repeated field to a new array, the memoized encoding would be correctly cleared, but because the field array we are pushing into doesn't have any concept of a message, let alone the specific message instance the field belongs to, there is no way to clear the memoized encoded message. We need to remove the memoization until we can find a better approach. Fixes #304. --- lib/protobuf/field/base_field.rb | 2 - lib/protobuf/field/bytes_field.rb | 1 - lib/protobuf/field/enum_field.rb | 1 - lib/protobuf/field/message_field.rb | 1 - lib/protobuf/message/serialization.rb | 10 ++--- spec/lib/protobuf/message_spec.rb | 58 --------------------------- 6 files changed, 4 insertions(+), 69 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 3ae505a4..e50895ae 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -198,7 +198,6 @@ def define_array_setter message_class.class_eval do define_method(method_name) do |val| - @encode = nil if val.is_a?(Array) val = val.dup val.compact! @@ -240,7 +239,6 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @encode = nil if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index d7f4aee4..6c017558 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -62,7 +62,6 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @encode = nil case val when String, Symbol @values[field.name] = "#{val}" diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 71632cde..ac26ea0e 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -42,7 +42,6 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |value| - @encode = nil orig_value = value if value.nil? @values.delete(field.name) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 8cb37bd7..6e62cdf4 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -40,7 +40,6 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |val| - @encode = nil case when val.nil? @values.delete(field.name) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 668b6cea..6526a95c 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -48,12 +48,10 @@ def decode_from(stream) # Encode this message # def encode - @encode ||= begin - stream = ::StringIO.new - stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream) - stream.string - end + stream = ::StringIO.new + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + stream.string end # Encode this message to the given stream. diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 1ac3bff0..f4b345c8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -268,64 +268,6 @@ end end - describe 'memoization' do - it "should memoize enum message" do - test_enum = Test::EnumTestMessage.new - test_enum.encode - expect(test_enum.instance_variable_get(:@encode)).to eq("") - test_enum.non_default_enum = 2 - expect(test_enum.instance_variable_get(:@encode)).to be_nil - end - - context "boolean fields" do - let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after bool values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.ext_is_searchable = false - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - - context "string" do - let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after bool values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - - context "string" do - let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after string values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - - context "Int64" do - let(:values) { { :name => "STEPH CURRY", :date_created => 1454712125 } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after Int64 values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.date_created = 5554712127 - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - end - context "when there's no value for a required field" do let(:message) { ::Test::ResourceWithRequiredField.new } From dee8a9d506c75c3c018c8ea78c97f263405b93b3 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 18 Feb 2016 21:39:42 -0700 Subject: [PATCH 0972/1191] Bump version to 3.6.7 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6e6da081..cd372fee 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.6' + VERSION = '3.6.7' end From 154fbad0cc6c199af7e4a5ec7bd7fb1602c32c37 Mon Sep 17 00:00:00 2001 From: Embark Date: Thu, 11 Feb 2016 17:03:41 -0800 Subject: [PATCH 0973/1191] Clean up dynamic code generation in prep for extension namespacing --- .rubocop_todo.yml | 6 +- lib/protobuf/field.rb | 4 +- lib/protobuf/field/base_field.rb | 102 ++++--------------- lib/protobuf/field/bool_field.rb | 16 +-- lib/protobuf/field/bytes_field.rb | 36 ++----- lib/protobuf/field/enum_field.rb | 23 ++--- lib/protobuf/field/message_field.rb | 34 ++----- lib/protobuf/message.rb | 50 +++++++-- lib/protobuf/message/fields.rb | 54 +++++++++- spec/lib/protobuf/field/bool_field_spec.rb | 40 ++++++-- spec/lib/protobuf/field/float_field_spec.rb | 33 +++++- spec/lib/protobuf/field/int32_field_spec.rb | 33 +++++- spec/lib/protobuf/field/string_field_spec.rb | 34 +++++++ spec/lib/protobuf/field_spec.rb | 1 + 14 files changed, 279 insertions(+), 187 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 880dd05c..2a18fb8a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -16,7 +16,7 @@ Metrics/BlockNesting: # Offense count: 6 Metrics/CyclomaticComplexity: - Max: 10 + Max: 12 # Offense count: 493 # Configuration parameters: AllowURI, URISchemes. @@ -31,11 +31,11 @@ Metrics/MethodLength: # Offense count: 2 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: - Max: 6 + Max: 7 # Offense count: 6 Metrics/PerceivedComplexity: - Max: 11 + Max: 17 # Offense count: 1 # Cop supports --auto-correct. diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index 02cc14f4..f13aa9d4 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -41,8 +41,8 @@ module Field :bool => ::Protobuf::Field::BoolField, }.freeze - def self.build(message_class, rule, type, name, tag, options = {}) - field_class(type).new(message_class, rule, field_type(type), name, tag, options) + def self.build(message_class, rule, type, name, tag, simple_name, options = {}) + field_class(type).new(message_class, rule, field_type(type), name, tag, simple_name, options) end # Returns the field class for primitives, diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index e50895ae..5faad284 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -35,7 +35,7 @@ def self.default # Constructor # - def initialize(message_class, rule, type_class, name, tag, options) + def initialize(message_class, rule, type_class, name, tag, simple_name, options) @message_class = message_class @name = name @rule = rule @@ -44,7 +44,7 @@ def initialize(message_class, rule, type_class, name, tag, options) @options = options validate_packed_field if packed? - define_accessor + define_accessor(simple_name, name) if simple_name tag_encoded end @@ -69,10 +69,12 @@ def default end def default_value - @default_value ||= case - when optional? then typed_default_value - when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze - when required? then nil + @default_value ||= if optional? || required? + typed_default_value + elsif repeated? + ::Protobuf::Field::FieldArray.new(self).freeze + else + fail "Unknown field label -- something went very wrong" end end @@ -122,10 +124,10 @@ def required? # FIXME: need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) - return message_instance.__send__(setter, decode(bytes)) unless repeated? - return message_instance.__send__(getter) << decode(bytes) unless packed? + return message_instance[name] = decode(bytes) unless repeated? + return message_instance[name] << decode(bytes) unless packed? - array = message_instance.__send__(getter) + array = message_instance[name] stream = StringIO.new(bytes) if wire_type == ::Protobuf::WireType::VARINT @@ -169,87 +171,23 @@ def wire_type # Private Instance Methods # - def define_accessor - if repeated? - define_array_getter - define_array_setter - else - define_getter - define_setter - end - end - - def define_array_getter - field = self - method_name = field.getter - + def define_accessor(simple_field_name, fully_qualified_field_name) message_class.class_eval do - define_method(method_name) do - @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) + define_method("#{simple_field_name}!") do + @values[fully_qualified_field_name] end end - ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? - end - - def define_array_setter - field = self - method_name = field.setter - message_class.class_eval do - define_method(method_name) do |val| - if val.is_a?(Array) - val = val.dup - val.compact! - else - fail TypeError, <<-TYPE_ERROR - Expected repeated value of type '#{field.type_class}' - Got '#{val.class}' for repeated protobuf field #{field.name} - TYPE_ERROR - end - - if val.nil? || (val.respond_to?(:empty?) && val.empty?) - @values.delete(field.name) - else - @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) - @values[field.name].replace(val) - end - end + define_method(simple_field_name) { self[fully_qualified_field_name] } + define_method("#{simple_field_name}=") { |v| self[fully_qualified_field_name] = v } end - ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? - end - - def define_getter - field = self - method_name = field.getter - - message_class.class_eval do - define_method(method_name) do - @values[field.name] || field.default_value - end - end - - ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? - end - - def define_setter - field = self - method_name = field.setter - - message_class.class_eval do - define_method(method_name) do |val| - if val.nil? || (val.respond_to?(:empty?) && val.empty?) - @values.delete(field.name) - elsif field.acceptable?(val) - @values[field.name] = field.coerce!(val) - else - fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" - end - end - end + return unless deprecated? - ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? + ::Protobuf.field_deprecator.deprecate_method(message_class, simple_field_name) + ::Protobuf.field_deprecator.deprecate_method(message_class, "#{simple_field_name}!") + ::Protobuf.field_deprecator.deprecate_method(message_class, "#{simple_field_name}=") end def typed_default_value diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index afe6c112..97f81557 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -45,21 +45,11 @@ def encode(value) # Private Instance Methods # - def define_getter - field = self - method_name = field.getter - + def define_accessor(simple_field_name, _fully_qualified_field_name) + super message_class.class_eval do - define_method(method_name) do - @values.fetch(field.name, field.default_value) - end + alias_method "#{simple_field_name}?", simple_field_name end - - message_class.class_eval do - alias_method "#{method_name}?", method_name - end - - ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 6c017558..033a083e 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -33,7 +33,6 @@ def decode(bytes) end def encode(value) - value_to_encode = "" if value.is_a?(::Protobuf::Message) value_to_encode = value.encode else @@ -50,32 +49,17 @@ def wire_type ::Protobuf::WireType::LENGTH_DELIMITED end - private - - ## - # Private Instance Methods - # - - def define_setter - field = self - method_name = field.setter - - message_class.class_eval do - define_method(method_name) do |val| - case val - when String, Symbol - @values[field.name] = "#{val}" - when NilClass - @values.delete(field.name) - when ::Protobuf::Message - @values[field.name] = val.dup - else - fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" - end - end + def coerce!(value) + case value + when String, Symbol + "#{value}" + when NilClass + nil + when ::Protobuf::Message + value.dup + else + fail TypeError, "Unacceptable value #{value} for field #{name} of type #{type_class}" end - - ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end end end diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index ac26ea0e..1f97913e 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -32,29 +32,18 @@ def enum? true end + def coerce!(value) + enum_value = type_class.fetch(value) + fail TypeError, "Invalid Enum value: #{value.inspect} for #{name}" unless enum_value + enum_value + end + private ## # Private Instance Methods # - def define_setter - field = self - message_class.class_eval do - define_method("#{field.name}=") do |value| - orig_value = value - if value.nil? - @values.delete(field.name) - else - value = field.type_class.fetch(value) - fail TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value - - @values[field.name] = value - end - end - end - end - def typed_default_value if default.is_a?(Symbol) type_class.const_get(default) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 6e62cdf4..e79379f0 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -30,29 +30,17 @@ def wire_type ::Protobuf::WireType::LENGTH_DELIMITED end - private - - ## - # Private Instance Methods - # - - def define_setter - field = self - message_class.class_eval do - define_method("#{field.name}=") do |val| - case - when val.nil? - @values.delete(field.name) - when val.is_a?(field.type_class) - @values[field.name] = val - when val.respond_to?(:to_proto) - @values[field.name] = val.to_proto - when val.respond_to?(:to_hash) - @values[field.name] = field.type_class.new(val.to_hash) - else - fail TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" - end - end + def coerce!(value) + if value.nil? + nil + elsif value.is_a?(type_class) + value + elsif value.respond_to?(:to_proto) + value.to_proto + elsif value.respond_to?(:to_hash) + type_class.new(value.to_hash) + else + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{value.class}'" end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 9ac1332e..507b03ef 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -77,7 +77,7 @@ def each_field return to_enum(:each_field) unless block_given? self.class.all_fields.each do |field| - value = __send__(field.getter) + value = self[field.name] yield(field, value) end end @@ -101,7 +101,7 @@ def field?(name) def inspect attrs = self.class.fields.map do |field| - [field.name, send(field.name).inspect].join('=') + [field.name, self[field.name].inspect].join('=') end.join(' ') "#<#{self.class} #{attrs}>" @@ -113,7 +113,7 @@ def respond_to_has?(key) def respond_to_has_and_present?(key) respond_to_has?(key) && - (__send__(key).present? || [true, false].include?(__send__(key))) + (self[key].present? || [true, false].include?(self[key])) end # Return a hash-representation of the given fields for this message type. @@ -121,7 +121,7 @@ def to_hash result = {} @values.each_key do |field_name| - value = __send__(field_name) + value = self[field_name] hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value result[field_name] = hashed_value end @@ -140,20 +140,52 @@ def to_proto def ==(other) return false unless other.is_a?(self.class) each_field do |field, value| - return false unless value == other.__send__(field.name) + return false unless value == other[field.name] end true end def [](name) if (field = self.class.get_field(name, true)) - __send__(field.getter) + if field.repeated? + @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) + elsif @values.key?(field.name) + @values[field.name] + else + field.default_value + end + else + fail ArgumentError, "invalid field name=#{name.inspect}" end end def []=(name, value) if (field = self.class.get_field(name, true)) - __send__(field.setter, value) unless value.nil? + if field.repeated? + if value.is_a?(Array) + value = value.compact + else + fail TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{field.type_class}' + Got '#{value.class}' for repeated protobuf field #{field.name} + TYPE_ERROR + end + + if value.empty? + @values.delete(field.name) + else + @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) + @values[field.name].replace(value) + end + else + if value.nil? || (value.respond_to?(:empty?) && value.empty?) + @values.delete(field.name) + elsif field.acceptable?(value) + @values[field.name] = field.coerce!(value) + else + fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" + end + end else unless ::Protobuf.ignore_unknown_fields? fail ::Protobuf::FieldNotDefinedError, name @@ -193,9 +225,9 @@ def copy_to(object, method) object.__send__(:initialize) @values.each do |name, value| if value.is_a?(::Protobuf::Field::FieldArray) - object.__send__(name).replace(value.map { |v| duplicate.call(v) }) + object[name].replace(value.map { |v| duplicate.call(v) }) else - object.__send__("#{name}=", duplicate.call(value)) + object[name] = duplicate.call(value) end end object diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index bb41a2ed..ccb2cbdb 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -1,7 +1,11 @@ +require "set" + module Protobuf class Message module Fields + ACCESSOR_SUFFIXES = ["", "=", "!", "?"].freeze + def self.extended(other) other.extend(ClassMethods) ::Protobuf.deprecator.define_deprecated_methods( @@ -92,20 +96,64 @@ def get_field(name_or_tag, allow_extension = false) end end + def extension_shortcuts + @extension_shortcuts ||= Set.new + end + def define_field(rule, type_class, field_name, tag, options) raise_if_tag_collision(tag, field_name) raise_if_name_collision(field_name) - field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) + # Determine appropirate accessor for fields depending on name collisions via extensions: + + # Case 1: Base field = "string_field" and no extensions of the same name + # Result: message.string_field #=> @values["string_field"] + + # Case 2: Base field = "string_field" and extension 1 = ".my_package.string_field", extension N = ".package_N.string_field"... + # Result: message.string_field #=> @values["string_field"] + + # Case 3: No base field, extension 1 = ".my_package.string_field", extension 2 = ".other_package.string_field", extension N... + # Result: message.string_field #=> raise NoMethodError (no simple accessor allowed) + + # Case 4: No base field, extension = ".my_package.string_field", no other extensions + # Result: message.string_field #=> @values[".my_package.string_field"] + + if options[:extension] + base_name = field_name.to_s.split('.').last + # Case 2 + if field_store[base_name] + simple_name = nil + # Case 3 + elsif extension_shortcuts.include?(base_name) + remove_existing_accessors(base_name) + simple_name = nil + # Case 4 + else + extension_shortcuts << base_name + simple_name = base_name + end + else + # Case 1 + simple_name = field_name + end + + field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, simple_name, options) field_store[tag] = field field_store[field_name] = field field_store[field_name.to_s] = field # defining a new field for the message will cause cached @all_fields, @extension_fields, # and @fields to be incorrect; reset them @all_fields = @extension_fields = @fields = nil + end - define_method("#{field_name}!") do - @values[field_name] + def remove_existing_accessors(accessor) + ACCESSOR_SUFFIXES.each do |modifier| + begin + remove_method("#{accessor}#{modifier}") + # rubocop: disable Lint/HandleExceptions + rescue NameError + # Do not remove the method + end end end diff --git a/spec/lib/protobuf/field/bool_field_spec.rb b/spec/lib/protobuf/field/bool_field_spec.rb index aeb27b55..d95d397f 100644 --- a/spec/lib/protobuf/field/bool_field_spec.rb +++ b/spec/lib/protobuf/field/bool_field_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -RSpec.describe Protobuf::Field::Int32Field do +RSpec.describe Protobuf::Field::BoolField do class SomeBoolMessage < ::Protobuf::Message optional :bool, :some_bool, 1 @@ -9,7 +9,7 @@ class SomeBoolMessage < ::Protobuf::Message let(:instance) { SomeBoolMessage.new } - describe '#define_setter' do + describe 'setting and getting field' do subject { instance.some_bool = value; instance.some_bool } [true, false].each do |val| @@ -49,12 +49,38 @@ class SomeBoolMessage < ::Protobuf::Message end end - describe '#define_getter' do - context 'when required bool field is set to false' do - subject { instance.required_bool = false; instance.required_bool } + it 'defines ? method' do + instance.required_bool = false + expect(instance.required_bool?).to be(false) + end + + describe '#default_value' do + context 'optional and required fields' do + it 'returns the class default' do + expect(SomeBoolMessage.get_field('some_bool').default).to be nil + expect(::Protobuf::Field::BoolField.default).to be false + expect(instance.some_bool).to be false + end + + context 'with field default' do + class AnotherBoolMessage < ::Protobuf::Message + optional :bool, :set_bool, 1, :default => true + end + + it 'returns the set default' do + expect(AnotherBoolMessage.get_field('set_bool').default).to be true + expect(AnotherBoolMessage.new.set_bool).to be true + end + end + end + + context 'repeated field' do + class RepeatedBoolMessage < ::Protobuf::Message + repeated :bool, :repeated_bool, 1 + end - it 'returns false' do - expect(subject).to eq(false) + it 'returns the set default' do + expect(RepeatedBoolMessage.new.repeated_bool).to eq [] end end end diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb index a007871f..0620c93c 100644 --- a/spec/lib/protobuf/field/float_field_spec.rb +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -8,7 +8,7 @@ class SomeFloatMessage < ::Protobuf::Message let(:instance) { SomeFloatMessage.new } - describe '#define_setter' do + describe 'setting and getting field' do subject { instance.some_float = value; instance.some_float } context 'when set with an int' do @@ -52,4 +52,35 @@ class SomeFloatMessage < ::Protobuf::Message end end + describe '#default_value' do + context 'optional and required fields' do + it 'returns the class default' do + expect(SomeFloatMessage.get_field('some_float').default).to be nil + expect(::Protobuf::Field::FloatField.default).to eq 0.0 + expect(instance.some_float).to eq 0.0 + end + + context 'with field default' do + class AnotherFloatMessage < ::Protobuf::Message + optional :float, :set_float, 1, :default => 3.6 + end + + it 'returns the set default' do + expect(AnotherFloatMessage.get_field('set_float').default).to eq 3.6 + expect(AnotherFloatMessage.new.set_float).to eq 3.6 + end + end + end + + context 'repeated field' do + class RepeatedFloatMessage < ::Protobuf::Message + repeated :float, :repeated_float, 1 + end + + it 'returns the set default' do + expect(RepeatedFloatMessage.new.repeated_float).to eq [] + end + end + end + end diff --git a/spec/lib/protobuf/field/int32_field_spec.rb b/spec/lib/protobuf/field/int32_field_spec.rb index b65a778c..d851e019 100644 --- a/spec/lib/protobuf/field/int32_field_spec.rb +++ b/spec/lib/protobuf/field/int32_field_spec.rb @@ -10,7 +10,7 @@ class SomeInt32Message < ::Protobuf::Message let(:instance) { SomeInt32Message.new } - describe '#define_setter' do + describe 'setting and getting a field' do subject { instance.some_int = value; instance.some_int } context 'when set with an int' do @@ -86,4 +86,35 @@ class SomeInt32Message < ::Protobuf::Message end end + describe '#default_value' do + context 'optional and required fields' do + it 'returns the class default' do + expect(SomeInt32Message.get_field('some_int').default).to be nil + expect(::Protobuf::Field::Int32Field.default).to eq 0 + expect(instance.some_int).to eq 0 + end + + context 'with field default' do + class AnotherIntMessage < ::Protobuf::Message + optional :int32, :set_int, 1, :default => 3 + end + + it 'returns the set default' do + expect(AnotherIntMessage.get_field('set_int').default).to eq 3 + expect(AnotherIntMessage.new.set_int).to eq 3 + end + end + end + + context 'repeated field' do + class RepeatedIntMessage < ::Protobuf::Message + repeated :int32, :repeated_int, 1 + end + + it 'returns the set default' do + expect(RepeatedIntMessage.new.repeated_int).to eq [] + end + end + end + end diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index f403c027..f666907a 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -42,4 +42,38 @@ end end + describe '#default_value' do + context 'optional and required fields' do + it 'returns the class default' do + class SomeStringMessage < ::Protobuf::Message + optional :string, :some_string, 1 + end + expect(SomeStringMessage.get_field('some_string').default).to be nil + expect(::Protobuf::Field::StringField.default).to eq "" + expect(SomeStringMessage.new.some_string).to eq "" + end + + context 'with field default' do + class AnotherStringMessage < ::Protobuf::Message + optional :string, :set_string, 1, :default => "default value this is" + end + + it 'returns the set default' do + expect(AnotherStringMessage.get_field('set_string').default).to eq "default value this is" + expect(AnotherStringMessage.new.set_string).to eq "default value this is" + end + end + end + + context 'repeated field' do + class RepeatedStringMessage < ::Protobuf::Message + repeated :string, :repeated_string, 1 + end + + it 'returns the set default' do + expect(RepeatedStringMessage.new.repeated_string).to eq [] + end + end + end + end diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index c0eb24d8..37e82087 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' require 'protobuf/field' +require PROTOS_PATH.join('resource.pb') RSpec.describe ::Protobuf::Field do From 48d19060ed0f762aa9474d7407c65983231c8ba6 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 27 Jan 2016 13:13:47 -0800 Subject: [PATCH 0974/1191] refresh google/protobuf/descriptor.{proto,pb.rb} from: https://raw.githubusercontent.com/google/protobuf/master/src/google/protobuf/descriptor.proto --- .../google/protobuf/descriptor.pb.rb | 41 +++- proto/google/protobuf/descriptor.proto | 221 +++++++++++++++--- 2 files changed, 229 insertions(+), 33 deletions(-) diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index 54de4e2e..6395a14d 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -15,6 +15,7 @@ class FileDescriptorSet < ::Protobuf::Message; end class FileDescriptorProto < ::Protobuf::Message; end class DescriptorProto < ::Protobuf::Message class ExtensionRange < ::Protobuf::Message; end + class ReservedRange < ::Protobuf::Message; end end @@ -48,6 +49,7 @@ class Label < ::Protobuf::Enum end + class OneofDescriptorProto < ::Protobuf::Message; end class EnumDescriptorProto < ::Protobuf::Message; end class EnumValueDescriptorProto < ::Protobuf::Message; end class ServiceDescriptorProto < ::Protobuf::Message; end @@ -69,6 +71,12 @@ class CType < ::Protobuf::Enum define :STRING_PIECE, 2 end + class JSType < ::Protobuf::Enum + define :JS_NORMAL, 0 + define :JS_STRING, 1 + define :JS_NUMBER, 2 + end + end class EnumOptions < ::Protobuf::Message; end @@ -106,6 +114,7 @@ class FileDescriptorProto repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 7 optional ::Google::Protobuf::FileOptions, :options, 8 optional ::Google::Protobuf::SourceCodeInfo, :source_code_info, 9 + optional :string, :syntax, 12 end class DescriptorProto @@ -114,13 +123,21 @@ class ExtensionRange optional :int32, :end, 2 end + class ReservedRange + optional :int32, :start, 1 + optional :int32, :end, 2 + end + optional :string, :name, 1 repeated ::Google::Protobuf::FieldDescriptorProto, :field, 2 repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 6 repeated ::Google::Protobuf::DescriptorProto, :nested_type, 3 repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 4 repeated ::Google::Protobuf::DescriptorProto::ExtensionRange, :extension_range, 5 + repeated ::Google::Protobuf::OneofDescriptorProto, :oneof_decl, 8 optional ::Google::Protobuf::MessageOptions, :options, 7 + repeated ::Google::Protobuf::DescriptorProto::ReservedRange, :reserved_range, 9 + repeated :string, :reserved_name, 10 end class FieldDescriptorProto @@ -131,9 +148,14 @@ class FieldDescriptorProto optional :string, :type_name, 6 optional :string, :extendee, 2 optional :string, :default_value, 7 + optional :int32, :oneof_index, 9 optional ::Google::Protobuf::FieldOptions, :options, 8 end + class OneofDescriptorProto + optional :string, :name, 1 + end + class EnumDescriptorProto optional :string, :name, 1 repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2 @@ -157,6 +179,8 @@ class MethodDescriptorProto optional :string, :input_type, 2 optional :string, :output_type, 3 optional ::Google::Protobuf::MethodOptions, :options, 4 + optional :bool, :client_streaming, 5, :default => false + optional :bool, :server_streaming, 6, :default => false end class FileOptions @@ -164,11 +188,17 @@ class FileOptions optional :string, :java_outer_classname, 8 optional :bool, :java_multiple_files, 10, :default => false optional :bool, :java_generate_equals_and_hash, 20, :default => false + optional :bool, :java_string_check_utf8, 27, :default => false optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED optional :string, :go_package, 11 optional :bool, :cc_generic_services, 16, :default => false optional :bool, :java_generic_services, 17, :default => false optional :bool, :py_generic_services, 18, :default => false + optional :bool, :deprecated, 23, :default => false + optional :bool, :cc_enable_arenas, 31, :default => false + optional :string, :objc_class_prefix, 36 + optional :string, :csharp_namespace, 37 + optional :bool, :javanano_use_deprecated_package, 38 repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 @@ -177,6 +207,8 @@ class FileOptions class MessageOptions optional :bool, :message_set_wire_format, 1, :default => false optional :bool, :no_standard_descriptor_accessor, 2, :default => false + optional :bool, :deprecated, 3, :default => false + optional :bool, :map_entry, 7 repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 @@ -185,9 +217,9 @@ class MessageOptions class FieldOptions optional ::Google::Protobuf::FieldOptions::CType, :ctype, 1, :default => ::Google::Protobuf::FieldOptions::CType::STRING optional :bool, :packed, 2 + optional ::Google::Protobuf::FieldOptions::JSType, :jstype, 6, :default => ::Google::Protobuf::FieldOptions::JSType::JS_NORMAL optional :bool, :lazy, 5, :default => false optional :bool, :deprecated, 3, :default => false - optional :string, :experimental_map_key, 9 optional :bool, :weak, 10, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields @@ -195,25 +227,29 @@ class FieldOptions end class EnumOptions - optional :bool, :allow_alias, 2, :default => true + optional :bool, :allow_alias, 2 + optional :bool, :deprecated, 3, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 end class EnumValueOptions + optional :bool, :deprecated, 1, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 end class ServiceOptions + optional :bool, :deprecated, 33, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 end class MethodOptions + optional :bool, :deprecated, 33, :default => false repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 @@ -240,6 +276,7 @@ class Location repeated :int32, :span, 2, :packed => true optional :string, :leading_comments, 3 optional :string, :trailing_comments, 4 + repeated :string, :leading_detached_comments, 6 end repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1 diff --git a/proto/google/protobuf/descriptor.proto b/proto/google/protobuf/descriptor.proto index a785f79f..c59a6022 100644 --- a/proto/google/protobuf/descriptor.proto +++ b/proto/google/protobuf/descriptor.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -37,10 +37,14 @@ // without any other information (e.g. without reading its imports). +syntax = "proto2"; package google.protobuf; +option go_package = "descriptor"; option java_package = "com.google.protobuf"; option java_outer_classname = "DescriptorProtos"; +option csharp_namespace = "Google.Protobuf.Reflection"; +option objc_class_prefix = "GPB"; // descriptor.proto must be optimized for speed because reflection-based // algorithms don't work during bootstrapping. @@ -74,10 +78,14 @@ message FileDescriptorProto { optional FileOptions options = 8; // This field contains optional information about the original source code. - // You may safely remove this entire field whithout harming runtime + // You may safely remove this entire field without harming runtime // functionality of the descriptors -- the information is needed only by // development tools. optional SourceCodeInfo source_code_info = 9; + + // The syntax of the proto file. + // The supported values are "proto2" and "proto3". + optional string syntax = 12; } // Describes a message type. @@ -96,7 +104,21 @@ message DescriptorProto { } repeated ExtensionRange extension_range = 5; + repeated OneofDescriptorProto oneof_decl = 8; + optional MessageOptions options = 7; + + // Range of reserved tag numbers. Reserved tag numbers may not be used by + // fields or extension ranges in the same message. Reserved ranges may + // not overlap. + message ReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. + } + repeated ReservedRange reserved_range = 9; + // Reserved field names, which may not be used by fields in the same message. + // A given name may only be reserved once. + repeated string reserved_name = 10; } // Describes a field within a message. @@ -143,7 +165,7 @@ message FieldDescriptorProto { optional Label label = 4; // If type_name is set, this need not be set. If both this and type_name - // are set, this must be either TYPE_ENUM or TYPE_MESSAGE. + // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. optional Type type = 5; // For message and enum types, this is the name of the type. If the name @@ -164,9 +186,24 @@ message FieldDescriptorProto { // TODO(kenton): Base-64 encode? optional string default_value = 7; + // If set, gives the index of a oneof in the containing type's oneof_decl + // list. This field is a member of that oneof. + optional int32 oneof_index = 9; + + // JSON name of this field. The value is set by protocol compiler. If the + // user has set a "json_name" option on this field, that option's value + // will be used. Otherwise, it's deduced from the field's name by converting + // it to camelCase. + optional string json_name = 10; + optional FieldOptions options = 8; } +// Describes a oneof. +message OneofDescriptorProto { + optional string name = 1; +} + // Describes an enum type. message EnumDescriptorProto { optional string name = 1; @@ -202,6 +239,11 @@ message MethodDescriptorProto { optional string output_type = 3; optional MethodOptions options = 4; + + // Identifies if client streams multiple client messages + optional bool client_streaming = 5 [default=false]; + // Identifies if server streams multiple server messages + optional bool server_streaming = 6 [default=false]; } @@ -228,12 +270,12 @@ message MethodDescriptorProto { // * For options which will be published and used publicly by multiple // independent entities, e-mail protobuf-global-extension-registry@google.com // to reserve extension numbers. Simply provide your project name (e.g. -// Object-C plugin) and your porject website (if available) -- there's no need -// to explain how you intend to use them. Usually you only need one extension -// number. You can declare multiple options with only one extension number by -// putting them in a sub-message. See the Custom Options section of the docs -// for examples: -// http://code.google.com/apis/protocolbuffers/docs/proto.html#options +// Objective-C plugin) and your project website (if available) -- there's no +// need to explain how you intend to use them. Usually you only need one +// extension number. You can declare multiple options with only one extension +// number by putting them in a sub-message. See the Custom Options section of +// the docs for examples: +// https://developers.google.com/protocol-buffers/docs/proto#options // If this turns out to be popular, a web service will be set up // to automatically assign option numbers. @@ -263,11 +305,28 @@ message FileOptions { optional bool java_multiple_files = 10 [default=false]; // If set true, then the Java code generator will generate equals() and - // hashCode() methods for all messages defined in the .proto file. This is - // purely a speed optimization, as the AbstractMessage base class includes - // reflection-based implementations of these methods. + // hashCode() methods for all messages defined in the .proto file. + // This increases generated code size, potentially substantially for large + // protos, which may harm a memory-constrained application. + // - In the full runtime this is a speed optimization, as the + // AbstractMessage base class includes reflection-based implementations of + // these methods. + // - In the lite runtime, setting this option changes the semantics of + // equals() and hashCode() to more closely match those of the full runtime; + // the generated methods compute their results based on field values rather + // than object identity. (Implementations should not assume that hashcodes + // will be consistent across runtimes or versions of the protocol compiler.) optional bool java_generate_equals_and_hash = 20 [default=false]; + // If set true, then the Java2 code generator will generate code that + // throws an exception whenever an attempt is made to assign a non-UTF-8 + // byte sequence to a string field. + // Message reflection will do the same. + // However, an extension field still accepts non-UTF-8 byte sequences. + // This option has no effect on when used with the lite runtime. + optional bool java_string_check_utf8 = 27 [default=false]; + + // Generated classes can be optimized for speed or code size. enum OptimizeMode { SPEED = 1; // Generate complete code for parsing, serialization, @@ -278,7 +337,10 @@ message FileOptions { optional OptimizeMode optimize_for = 9 [default=SPEED]; // Sets the Go package where structs generated from this .proto will be - // placed. There is no default. + // placed. If omitted, the Go package will be derived from the following: + // - The basename of the package import path, if provided. + // - Otherwise, the package statement in the .proto file, if present. + // - Otherwise, the basename of the .proto file, without extension. optional string go_package = 11; @@ -287,7 +349,7 @@ message FileOptions { // are not specific to any particular RPC system. They are generated by the // main code generators in each language (without additional plugins). // Generic services were the only kind of service generation supported by - // early versions of proto2. + // early versions of google.protobuf. // // Generic services are now considered deprecated in favor of using plugins // that generate code specific to your particular RPC system. Therefore, @@ -297,6 +359,28 @@ message FileOptions { optional bool java_generic_services = 17 [default=false]; optional bool py_generic_services = 18 [default=false]; + // Is this file deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for everything in the file, or it will be completely ignored; in the very + // least, this is a formalization for deprecating files. + optional bool deprecated = 23 [default=false]; + + // Enables the use of arenas for the proto messages in this file. This applies + // only to generated classes for C++. + optional bool cc_enable_arenas = 31 [default=false]; + + + // Sets the objective c class prefix which is prepended to all objective c + // generated classes from this .proto. There is no default. + optional string objc_class_prefix = 36; + + // Namespace for generated classes; defaults to the package. + optional string csharp_namespace = 37; + + // Whether the nano proto compiler should generate in the deprecated non-nano + // suffixed package. + optional bool javanano_use_deprecated_package = 38; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -330,6 +414,35 @@ message MessageOptions { // from proto1 easier; new code should avoid fields named "descriptor". optional bool no_standard_descriptor_accessor = 2 [default=false]; + // Is this message deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the message, or it will be completely ignored; in the very least, + // this is a formalization for deprecating messages. + optional bool deprecated = 3 [default=false]; + + // Whether the message is an automatically generated map entry type for the + // maps field. + // + // For maps fields: + // map map_field = 1; + // The parsed descriptor looks like: + // message MapFieldEntry { + // option map_entry = true; + // optional KeyType key = 1; + // optional ValueType value = 2; + // } + // repeated MapFieldEntry map_field = 1; + // + // Implementations may choose not to generate the map_entry=true message, but + // use a native map in the target language to hold the keys and values. + // The reflection APIs in such implementions still need to work as + // if the field is a repeated message field. + // + // NOTE: Do not set the option in .proto files. Always use the maps syntax + // instead. The option should only be implicitly set by the proto compiler + // parser. + optional bool map_entry = 7; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -354,10 +467,31 @@ message FieldOptions { // The packed option can be enabled for repeated primitive fields to enable // a more efficient representation on the wire. Rather than repeatedly // writing the tag and type for each element, the entire array is encoded as - // a single length-delimited blob. + // a single length-delimited blob. In proto3, only explicit setting it to + // false will avoid using packed encoding. optional bool packed = 2; + // The jstype option determines the JavaScript type used for values of the + // field. The option is permitted only for 64 bit integral and fixed types + // (int64, uint64, sint64, fixed64, sfixed64). By default these types are + // represented as JavaScript strings. This avoids loss of precision that can + // happen when a large value is converted to a floating point JavaScript + // numbers. Specifying JS_NUMBER for the jstype causes the generated + // JavaScript code to use the JavaScript "number" type instead of strings. + // This option is an enum to permit additional types to be added, + // e.g. goog.math.Integer. + optional JSType jstype = 6 [default = JS_NORMAL]; + enum JSType { + // Use the default type. + JS_NORMAL = 0; + + // Use JavaScript strings. + JS_STRING = 1; + + // Use JavaScript numbers. + JS_NUMBER = 2; + } // Should this field be parsed lazily? Lazy applies only to message-type // fields. It means that when the outer message is initially parsed, the @@ -395,23 +529,10 @@ message FieldOptions { // is a formalization for deprecating fields. optional bool deprecated = 3 [default=false]; - // EXPERIMENTAL. DO NOT USE. - // For "map" fields, the name of the field in the enclosed type that - // is the key for this map. For example, suppose we have: - // message Item { - // required string name = 1; - // required string value = 2; - // } - // message Config { - // repeated Item items = 1 [experimental_map_key="name"]; - // } - // In this situation, the map key for Item will be set to "name". - // TODO: Fully-implement this, then remove the "experimental_" prefix. - optional string experimental_map_key = 9; - // For Google-internal migration only. Do not use. optional bool weak = 10 [default=false]; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -421,9 +542,15 @@ message FieldOptions { message EnumOptions { - // Set this option to false to disallow mapping different tag names to a same + // Set this option to true to allow mapping different tag names to the same // value. - optional bool allow_alias = 2 [default=true]; + optional bool allow_alias = 2; + + // Is this enum deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum, or it will be completely ignored; in the very least, this + // is a formalization for deprecating enums. + optional bool deprecated = 3 [default=false]; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -433,6 +560,12 @@ message EnumOptions { } message EnumValueOptions { + // Is this enum value deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum value, or it will be completely ignored; in the very least, + // this is a formalization for deprecating enum values. + optional bool deprecated = 1 [default=false]; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -447,6 +580,12 @@ message ServiceOptions { // we were already using them long before we decided to release Protocol // Buffers. + // Is this service deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the service, or it will be completely ignored; in the very least, + // this is a formalization for deprecating services. + optional bool deprecated = 33 [default=false]; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -461,6 +600,12 @@ message MethodOptions { // we were already using them long before we decided to release Protocol // Buffers. + // Is this method deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the method, or it will be completely ignored; in the very least, + // this is a formalization for deprecating methods. + optional bool deprecated = 33 [default=false]; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -587,6 +732,11 @@ message SourceCodeInfo { // A series of line comments appearing on consecutive lines, with no other // tokens appearing on those lines, will be treated as a single comment. // + // leading_detached_comments will keep paragraphs of comments that appear + // before (but not connected to) the current element. Each paragraph, + // separated by empty lines, will be one comment element in the repeated + // field. + // // Only the comment content is provided; comment markers (e.g. //) are // stripped out. For block comments, leading whitespace and an asterisk // will be stripped from the beginning of each line other than the first. @@ -607,6 +757,12 @@ message SourceCodeInfo { // // Another line attached to qux. // optional double qux = 4; // + // // Detached comment for corge. This is not leading or trailing comments + // // to qux or corge because there are blank lines separating it from + // // both. + // + // // Detached comment for corge paragraph 2. + // // optional string corge = 5; // /* Block comment attached // * to corge. Leading asterisks @@ -614,7 +770,10 @@ message SourceCodeInfo { // /* Block comment attached to // * grault. */ // optional int32 grault = 6; + // + // // ignored detached comments. optional string leading_comments = 3; optional string trailing_comments = 4; + repeated string leading_detached_comments = 6; } } From 48fb343f7d86140d5a730bc2b6acea1083fb8096 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Tue, 16 Feb 2016 11:18:57 -0800 Subject: [PATCH 0975/1191] namespace extension fields --- lib/protobuf/generators/field_generator.rb | 8 ++- lib/protobuf/generators/file_generator.rb | 8 +++ spec/lib/protobuf/message_spec.rb | 75 ++++++++++++++++++++-- spec/support/protos/enum.pb.rb | 2 +- spec/support/protos/google_unittest.proto | 7 ++ spec/support/protos/resource.pb.rb | 18 +++--- 6 files changed, 100 insertions(+), 18 deletions(-) diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 3cd6c553..28595a7a 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -20,7 +20,7 @@ class FieldGenerator < Base attr_reader :field_options def applicable_options - @applicable_options ||= field_options.map { |k, v| ":#{k} => #{v}" } + @applicable_options ||= field_options.map { |k, v| "#{k.inspect} => #{v}" } end def default_value @@ -64,7 +64,11 @@ def label end def name - @name ||= ":#{descriptor.name}" + @name ||= if descriptor.name.include?('.') + ":#{descriptor.name.inspect}" + else + ":#{descriptor.name}" + end end def number diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 32016e0d..f4035ac6 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -64,6 +64,11 @@ def generate_output_file # the value is an array of field descriptors. # def map_extensions(descriptor, namespaces) + if fully_qualified_token?(descriptor.name) + fully_qualified_namespace = descriptor.name + elsif !(namespace = namespaces.reject(&:empty?).join(".")).empty? + fully_qualified_namespace = ".#{namespace}" + end # Record all the message descriptor name's we encounter (should be the whole tree). if descriptor.is_a?(::Google::Protobuf::DescriptorProto) if fully_qualified_token?(descriptor.name) @@ -75,6 +80,9 @@ def map_extensions(descriptor, namespaces) end descriptor.extension.each do |field_descriptor| + unless fully_qualified_token?(field_descriptor.name) && fully_qualified_namespace + field_descriptor.name = "#{fully_qualified_namespace}.#{field_descriptor.name}" + end @extension_fields[field_descriptor.extendee] << field_descriptor end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index f4b345c8..fa7cd16b 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -468,7 +468,7 @@ end end - describe "#define_setter" do + describe "#define_accessor" do subject { ::Test::Resource.new } it "allows string fields to be set to nil" do @@ -485,13 +485,13 @@ field = ::Test::Resource.get_extension_field(100) expect(field).to be_a(::Protobuf::Field::BoolField) expect(field.tag).to eq(100) - expect(field.name).to eq(:ext_is_searchable) + expect(field.name).to eq(:'.test.Searchable.ext_is_searchable') expect(field).to be_extension end it 'fetches an extension field by its symbolized name' do - expect(::Test::Resource.get_extension_field(:ext_is_searchable)).to be_a(::Protobuf::Field::BoolField) - expect(::Test::Resource.get_extension_field('ext_is_searchable')).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_extension_field(:'.test.Searchable.ext_is_searchable')).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_extension_field('.test.Searchable.ext_is_searchable')).to be_a(::Protobuf::Field::BoolField) end it 'returns nil when attempting to get a non-extension field' do @@ -520,8 +520,8 @@ it 'fetches an extension field when forced' do expect(::Test::Resource.get_field(100, true)).to be_a(::Protobuf::Field::BoolField) - expect(::Test::Resource.get_field(:ext_is_searchable, true)).to be_a(::Protobuf::Field::BoolField) - expect(::Test::Resource.get_field('ext_is_searchable', true)).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_field(:'.test.Searchable.ext_is_searchable', true)).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_field('.test.Searchable.ext_is_searchable', true)).to be_a(::Protobuf::Field::BoolField) end it 'returns nil when attempting to get an extension field' do @@ -534,4 +534,67 @@ end end + describe 'defining a field' do + context 'single base field' do + let(:klass) do + Class.new(Protobuf::Message) do + optional :string, :foo, 1 + end + end + + it 'has an accessor for foo' do + message = klass.new(:foo => 'bar') + expect(message.foo).to eq('bar') + expect(message[:foo]).to eq('bar') + end + end + + context 'base field and extension field name collision' do + let(:klass) do + Class.new(Protobuf::Message) do + optional :string, :foo, 1 + optional :string, :".boom.foo", 2, :extension => true + end + end + + it 'has an accessor for foo that refers to the base field' do + message = klass.new(:foo => 'bar', '.boom.foo' => 'bam') + expect(message.foo).to eq('bar') + expect(message[:foo]).to eq('bar') + expect(message[:'.boom.foo']).to eq('bam') + end + end + + context 'no base field with an extension field' do + let(:klass) do + Class.new(Protobuf::Message) do + optional :string, :".boom.foo", 2, :extension => true + end + end + + it 'has an accessor for foo that refers to the extension field' do + message = klass.new('.boom.foo' => 'bam') + expect(message.foo).to eq('bam') + expect { message[:foo] }.to raise_error(ArgumentError) + expect(message[:'.boom.foo']).to eq('bam') + end + end + + context 'no base field with extension fields with name collision' do + let(:klass) do + Class.new(Protobuf::Message) do + optional :string, :".boom.foo", 2, :extension => true + optional :string, :".goat.foo", 3, :extension => true + end + end + + it 'has an accessor for foo that refers to the extension field' do + message = klass.new('.boom.foo' => 'bam', '.goat.foo' => 'red') + expect { message.foo }.to raise_error(NoMethodError) + expect { message[:foo] }.to raise_error(ArgumentError) + expect(message[:'.boom.foo']).to eq('bam') + expect(message[:'.goat.foo']).to eq('red') + end + end + end end diff --git a/spec/support/protos/enum.pb.rb b/spec/support/protos/enum.pb.rb index 035d20d8..3b4a0375 100644 --- a/spec/support/protos/enum.pb.rb +++ b/spec/support/protos/enum.pb.rb @@ -54,7 +54,7 @@ class EnumTestMessage # Extended Message Fields # class ::Test::Resource < ::Protobuf::Message - optional :int32, :ext_other_file_defined_field, 200, :extension => true + optional :int32, :".test.ext_other_file_defined_field", 200, :extension => true end end diff --git a/spec/support/protos/google_unittest.proto b/spec/support/protos/google_unittest.proto index 002f70dc..43169c75 100644 --- a/spec/support/protos/google_unittest.proto +++ b/spec/support/protos/google_unittest.proto @@ -336,6 +336,13 @@ message TestNestedExtension { } } +message TestMoreNestedExtension { + extend TestAllExtensions { + // Check that duplicate field names in different namespaces work + optional string test = 1004 [default="a different test"]; + } +} + // We have separate messages for testing required fields because it's // annoying to have to fill in required fields in TestProto in order to // do anything with it. Note that we don't need to test every type of diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index 622f33e4..09d8a4e3 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -67,11 +67,11 @@ class Resource repeated ::Test::StatusType, :repeated_enum, 4 # Extension Fields extensions 100...536870912 - optional :bool, :ext_is_searchable, 100, :extension => true - optional :bool, :ext_is_hidden, 101, :extension => true - optional ::Test::Searchable::SearchType, :ext_search_type, 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true - optional :bool, :ext_nested_in_level_one, 105, :extension => true - optional :bool, :ext_dup_field, 106, :extension => true + optional :bool, :".test.Searchable.ext_is_searchable", 100, :extension => true + optional :bool, :".test.Searchable.ext_is_hidden", 101, :extension => true + optional ::Test::Searchable::SearchType, :".test.Searchable.ext_search_type", 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true + optional :bool, :".test.Nested.NestedLevelOne.ext_nested_in_level_one", 105, :extension => true + optional :bool, :".test.Nested.NestedLevelOne.ext_dup_field", 106, :extension => true end class ResourceWithRequiredField @@ -90,8 +90,8 @@ class NestedLevelOne optional :bool, :level_one, 1, :default => true # Extension Fields extensions 100...102 - optional :bool, :ext_nested_level_one_outer, 101, :extension => true - optional :bool, :ext_nested_level_one, 100, :extension => true + optional :bool, :".test.ext_nested_level_one_outer", 101, :extension => true + optional :bool, :".test.Nested.ext_nested_level_one", 100, :extension => true end optional :string, :name, 1 @@ -100,8 +100,8 @@ class NestedLevelOne optional ::Test::StatusType, :status, 4 # Extension Fields extensions 100...111 - optional :string, :foo, 100, :extension => true - optional :int64, :bar, 101, :extension => true + optional :string, :".test.foo", 100, :extension => true + optional :int64, :".test.bar", 101, :extension => true end From 45426590cea0af41d1092b6debe5968f3756d0cb Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Thu, 3 Mar 2016 11:28:38 -0800 Subject: [PATCH 0976/1191] update generated spec proto code --- spec/support/protos/google_unittest.pb.rb | 224 +++++++++--------- .../protos/multi_field_extensions.pb.rb | 2 +- 2 files changed, 114 insertions(+), 112 deletions(-) diff --git a/spec/support/protos/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb index d009abd5..46c611f7 100644 --- a/spec/support/protos/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -69,6 +69,7 @@ class TestAllExtensions < ::Protobuf::Message; end class OptionalGroup_extension < ::Protobuf::Message; end class RepeatedGroup_extension < ::Protobuf::Message; end class TestNestedExtension < ::Protobuf::Message; end + class TestMoreNestedExtension < ::Protobuf::Message; end class TestRequired < ::Protobuf::Message; end class TestRequiredForeign < ::Protobuf::Message; end class TestForeignNested < ::Protobuf::Message; end @@ -283,85 +284,86 @@ class ForeignMessage class TestAllExtensions # Extension Fields extensions 1...536870912 - optional :int32, :optional_int32_extension, 1, :extension => true - optional :int64, :optional_int64_extension, 2, :extension => true - optional :uint32, :optional_uint32_extension, 3, :extension => true - optional :uint64, :optional_uint64_extension, 4, :extension => true - optional :sint32, :optional_sint32_extension, 5, :extension => true - optional :sint64, :optional_sint64_extension, 6, :extension => true - optional :fixed32, :optional_fixed32_extension, 7, :extension => true - optional :fixed64, :optional_fixed64_extension, 8, :extension => true - optional :sfixed32, :optional_sfixed32_extension, 9, :extension => true - optional :sfixed64, :optional_sfixed64_extension, 10, :extension => true - optional :float, :optional_float_extension, 11, :extension => true - optional :double, :optional_double_extension, 12, :extension => true - optional :bool, :optional_bool_extension, 13, :extension => true - optional :string, :optional_string_extension, 14, :extension => true - optional :bytes, :optional_bytes_extension, 15, :extension => true - optional ::Protobuf_unittest::OptionalGroup_extension, :optionalgroup_extension, 16, :extension => true - optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_nested_message_extension, 18, :extension => true - optional ::Protobuf_unittest::ForeignMessage, :optional_foreign_message_extension, 19, :extension => true - optional ::Protobuf_unittest_import::ImportMessage, :optional_import_message_extension, 20, :extension => true - optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :optional_nested_enum_extension, 21, :extension => true - optional ::Protobuf_unittest::ForeignEnum, :optional_foreign_enum_extension, 22, :extension => true - optional ::Protobuf_unittest_import::ImportEnum, :optional_import_enum_extension, 23, :extension => true - optional :string, :optional_string_piece_extension, 24, :extension => true - optional :string, :optional_cord_extension, 25, :extension => true - optional ::Protobuf_unittest_import::PublicImportMessage, :optional_public_import_message_extension, 26, :extension => true - optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message_extension, 27, :extension => true - repeated :int32, :repeated_int32_extension, 31, :extension => true - repeated :int64, :repeated_int64_extension, 32, :extension => true - repeated :uint32, :repeated_uint32_extension, 33, :extension => true - repeated :uint64, :repeated_uint64_extension, 34, :extension => true - repeated :sint32, :repeated_sint32_extension, 35, :extension => true - repeated :sint64, :repeated_sint64_extension, 36, :extension => true - repeated :fixed32, :repeated_fixed32_extension, 37, :extension => true - repeated :fixed64, :repeated_fixed64_extension, 38, :extension => true - repeated :sfixed32, :repeated_sfixed32_extension, 39, :extension => true - repeated :sfixed64, :repeated_sfixed64_extension, 40, :extension => true - repeated :float, :repeated_float_extension, 41, :extension => true - repeated :double, :repeated_double_extension, 42, :extension => true - repeated :bool, :repeated_bool_extension, 43, :extension => true - repeated :string, :repeated_string_extension, 44, :extension => true - repeated :bytes, :repeated_bytes_extension, 45, :extension => true - repeated ::Protobuf_unittest::RepeatedGroup_extension, :repeatedgroup_extension, 46, :extension => true - repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_nested_message_extension, 48, :extension => true - repeated ::Protobuf_unittest::ForeignMessage, :repeated_foreign_message_extension, 49, :extension => true - repeated ::Protobuf_unittest_import::ImportMessage, :repeated_import_message_extension, 50, :extension => true - repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :repeated_nested_enum_extension, 51, :extension => true - repeated ::Protobuf_unittest::ForeignEnum, :repeated_foreign_enum_extension, 52, :extension => true - repeated ::Protobuf_unittest_import::ImportEnum, :repeated_import_enum_extension, 53, :extension => true - repeated :string, :repeated_string_piece_extension, 54, :extension => true - repeated :string, :repeated_cord_extension, 55, :extension => true - repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message_extension, 57, :extension => true - optional :int32, :default_int32_extension, 61, :default => 41, :extension => true - optional :int64, :default_int64_extension, 62, :default => 42, :extension => true - optional :uint32, :default_uint32_extension, 63, :default => 43, :extension => true - optional :uint64, :default_uint64_extension, 64, :default => 44, :extension => true - optional :sint32, :default_sint32_extension, 65, :default => -45, :extension => true - optional :sint64, :default_sint64_extension, 66, :default => 46, :extension => true - optional :fixed32, :default_fixed32_extension, 67, :default => 47, :extension => true - optional :fixed64, :default_fixed64_extension, 68, :default => 48, :extension => true - optional :sfixed32, :default_sfixed32_extension, 69, :default => 49, :extension => true - optional :sfixed64, :default_sfixed64_extension, 70, :default => -50, :extension => true - optional :float, :default_float_extension, 71, :default => 51.5, :extension => true - optional :double, :default_double_extension, 72, :default => 52000, :extension => true - optional :bool, :default_bool_extension, 73, :default => true, :extension => true - optional :string, :default_string_extension, 74, :default => "hello", :extension => true - optional :bytes, :default_bytes_extension, 75, :default => "world", :extension => true - optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :default_nested_enum_extension, 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, :extension => true - optional ::Protobuf_unittest::ForeignEnum, :default_foreign_enum_extension, 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, :extension => true - optional ::Protobuf_unittest_import::ImportEnum, :default_import_enum_extension, 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, :extension => true - optional :string, :default_string_piece_extension, 84, :default => "abc", :extension => true - optional :string, :default_cord_extension, 85, :default => "123", :extension => true - optional :uint32, :oneof_uint32_extension, 111, :extension => true - optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :oneof_nested_message_extension, 112, :extension => true - optional :string, :oneof_string_extension, 113, :extension => true - optional :bytes, :oneof_bytes_extension, 114, :extension => true - optional :string, :test, 1002, :default => "test", :extension => true - optional :string, :nested_string_extension, 1003, :extension => true - optional ::Protobuf_unittest::TestRequired, :single, 1000, :extension => true - repeated ::Protobuf_unittest::TestRequired, :multi, 1001, :extension => true + optional :int32, :".protobuf_unittest.optional_int32_extension", 1, :extension => true + optional :int64, :".protobuf_unittest.optional_int64_extension", 2, :extension => true + optional :uint32, :".protobuf_unittest.optional_uint32_extension", 3, :extension => true + optional :uint64, :".protobuf_unittest.optional_uint64_extension", 4, :extension => true + optional :sint32, :".protobuf_unittest.optional_sint32_extension", 5, :extension => true + optional :sint64, :".protobuf_unittest.optional_sint64_extension", 6, :extension => true + optional :fixed32, :".protobuf_unittest.optional_fixed32_extension", 7, :extension => true + optional :fixed64, :".protobuf_unittest.optional_fixed64_extension", 8, :extension => true + optional :sfixed32, :".protobuf_unittest.optional_sfixed32_extension", 9, :extension => true + optional :sfixed64, :".protobuf_unittest.optional_sfixed64_extension", 10, :extension => true + optional :float, :".protobuf_unittest.optional_float_extension", 11, :extension => true + optional :double, :".protobuf_unittest.optional_double_extension", 12, :extension => true + optional :bool, :".protobuf_unittest.optional_bool_extension", 13, :extension => true + optional :string, :".protobuf_unittest.optional_string_extension", 14, :extension => true + optional :bytes, :".protobuf_unittest.optional_bytes_extension", 15, :extension => true + optional ::Protobuf_unittest::OptionalGroup_extension, :".protobuf_unittest.optionalgroup_extension", 16, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.optional_nested_message_extension", 18, :extension => true + optional ::Protobuf_unittest::ForeignMessage, :".protobuf_unittest.optional_foreign_message_extension", 19, :extension => true + optional ::Protobuf_unittest_import::ImportMessage, :".protobuf_unittest.optional_import_message_extension", 20, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.optional_nested_enum_extension", 21, :extension => true + optional ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.optional_foreign_enum_extension", 22, :extension => true + optional ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.optional_import_enum_extension", 23, :extension => true + optional :string, :".protobuf_unittest.optional_string_piece_extension", 24, :extension => true + optional :string, :".protobuf_unittest.optional_cord_extension", 25, :extension => true + optional ::Protobuf_unittest_import::PublicImportMessage, :".protobuf_unittest.optional_public_import_message_extension", 26, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.optional_lazy_message_extension", 27, :extension => true + repeated :int32, :".protobuf_unittest.repeated_int32_extension", 31, :extension => true + repeated :int64, :".protobuf_unittest.repeated_int64_extension", 32, :extension => true + repeated :uint32, :".protobuf_unittest.repeated_uint32_extension", 33, :extension => true + repeated :uint64, :".protobuf_unittest.repeated_uint64_extension", 34, :extension => true + repeated :sint32, :".protobuf_unittest.repeated_sint32_extension", 35, :extension => true + repeated :sint64, :".protobuf_unittest.repeated_sint64_extension", 36, :extension => true + repeated :fixed32, :".protobuf_unittest.repeated_fixed32_extension", 37, :extension => true + repeated :fixed64, :".protobuf_unittest.repeated_fixed64_extension", 38, :extension => true + repeated :sfixed32, :".protobuf_unittest.repeated_sfixed32_extension", 39, :extension => true + repeated :sfixed64, :".protobuf_unittest.repeated_sfixed64_extension", 40, :extension => true + repeated :float, :".protobuf_unittest.repeated_float_extension", 41, :extension => true + repeated :double, :".protobuf_unittest.repeated_double_extension", 42, :extension => true + repeated :bool, :".protobuf_unittest.repeated_bool_extension", 43, :extension => true + repeated :string, :".protobuf_unittest.repeated_string_extension", 44, :extension => true + repeated :bytes, :".protobuf_unittest.repeated_bytes_extension", 45, :extension => true + repeated ::Protobuf_unittest::RepeatedGroup_extension, :".protobuf_unittest.repeatedgroup_extension", 46, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.repeated_nested_message_extension", 48, :extension => true + repeated ::Protobuf_unittest::ForeignMessage, :".protobuf_unittest.repeated_foreign_message_extension", 49, :extension => true + repeated ::Protobuf_unittest_import::ImportMessage, :".protobuf_unittest.repeated_import_message_extension", 50, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.repeated_nested_enum_extension", 51, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.repeated_foreign_enum_extension", 52, :extension => true + repeated ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.repeated_import_enum_extension", 53, :extension => true + repeated :string, :".protobuf_unittest.repeated_string_piece_extension", 54, :extension => true + repeated :string, :".protobuf_unittest.repeated_cord_extension", 55, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.repeated_lazy_message_extension", 57, :extension => true + optional :int32, :".protobuf_unittest.default_int32_extension", 61, :default => 41, :extension => true + optional :int64, :".protobuf_unittest.default_int64_extension", 62, :default => 42, :extension => true + optional :uint32, :".protobuf_unittest.default_uint32_extension", 63, :default => 43, :extension => true + optional :uint64, :".protobuf_unittest.default_uint64_extension", 64, :default => 44, :extension => true + optional :sint32, :".protobuf_unittest.default_sint32_extension", 65, :default => -45, :extension => true + optional :sint64, :".protobuf_unittest.default_sint64_extension", 66, :default => 46, :extension => true + optional :fixed32, :".protobuf_unittest.default_fixed32_extension", 67, :default => 47, :extension => true + optional :fixed64, :".protobuf_unittest.default_fixed64_extension", 68, :default => 48, :extension => true + optional :sfixed32, :".protobuf_unittest.default_sfixed32_extension", 69, :default => 49, :extension => true + optional :sfixed64, :".protobuf_unittest.default_sfixed64_extension", 70, :default => -50, :extension => true + optional :float, :".protobuf_unittest.default_float_extension", 71, :default => 51.5, :extension => true + optional :double, :".protobuf_unittest.default_double_extension", 72, :default => 52000, :extension => true + optional :bool, :".protobuf_unittest.default_bool_extension", 73, :default => true, :extension => true + optional :string, :".protobuf_unittest.default_string_extension", 74, :default => "hello", :extension => true + optional :bytes, :".protobuf_unittest.default_bytes_extension", 75, :default => "world", :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.default_nested_enum_extension", 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, :extension => true + optional ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.default_foreign_enum_extension", 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, :extension => true + optional ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.default_import_enum_extension", 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, :extension => true + optional :string, :".protobuf_unittest.default_string_piece_extension", 84, :default => "abc", :extension => true + optional :string, :".protobuf_unittest.default_cord_extension", 85, :default => "123", :extension => true + optional :uint32, :".protobuf_unittest.oneof_uint32_extension", 111, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.oneof_nested_message_extension", 112, :extension => true + optional :string, :".protobuf_unittest.oneof_string_extension", 113, :extension => true + optional :bytes, :".protobuf_unittest.oneof_bytes_extension", 114, :extension => true + optional :string, :".protobuf_unittest.TestNestedExtension.test", 1002, :default => "test", :extension => true + optional :string, :".protobuf_unittest.TestNestedExtension.nested_string_extension", 1003, :extension => true + optional :string, :".protobuf_unittest.TestMoreNestedExtension.test", 1004, :default => "a different test", :extension => true + optional ::Protobuf_unittest::TestRequired, :".protobuf_unittest.TestRequired.single", 1000, :extension => true + repeated ::Protobuf_unittest::TestRequired, :".protobuf_unittest.TestRequired.multi", 1001, :extension => true end class OptionalGroup_extension @@ -496,8 +498,8 @@ class NestedMessage # Extension Fields extensions 2...11 extensions 12...101 - optional :string, :my_extension_string, 50, :extension => true - optional :int32, :my_extension_int, 5, :extension => true + optional :string, :".protobuf_unittest.my_extension_string", 50, :extension => true + optional :int32, :".protobuf_unittest.my_extension_int", 5, :extension => true end class TestExtremeDefaultValues @@ -671,39 +673,39 @@ class TestUnpackedTypes class TestPackedExtensions # Extension Fields extensions 1...536870912 - repeated :int32, :packed_int32_extension, 90, :packed => true, :extension => true - repeated :int64, :packed_int64_extension, 91, :packed => true, :extension => true - repeated :uint32, :packed_uint32_extension, 92, :packed => true, :extension => true - repeated :uint64, :packed_uint64_extension, 93, :packed => true, :extension => true - repeated :sint32, :packed_sint32_extension, 94, :packed => true, :extension => true - repeated :sint64, :packed_sint64_extension, 95, :packed => true, :extension => true - repeated :fixed32, :packed_fixed32_extension, 96, :packed => true, :extension => true - repeated :fixed64, :packed_fixed64_extension, 97, :packed => true, :extension => true - repeated :sfixed32, :packed_sfixed32_extension, 98, :packed => true, :extension => true - repeated :sfixed64, :packed_sfixed64_extension, 99, :packed => true, :extension => true - repeated :float, :packed_float_extension, 100, :packed => true, :extension => true - repeated :double, :packed_double_extension, 101, :packed => true, :extension => true - repeated :bool, :packed_bool_extension, 102, :packed => true, :extension => true - repeated ::Protobuf_unittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true + repeated :int32, :".protobuf_unittest.packed_int32_extension", 90, :packed => true, :extension => true + repeated :int64, :".protobuf_unittest.packed_int64_extension", 91, :packed => true, :extension => true + repeated :uint32, :".protobuf_unittest.packed_uint32_extension", 92, :packed => true, :extension => true + repeated :uint64, :".protobuf_unittest.packed_uint64_extension", 93, :packed => true, :extension => true + repeated :sint32, :".protobuf_unittest.packed_sint32_extension", 94, :packed => true, :extension => true + repeated :sint64, :".protobuf_unittest.packed_sint64_extension", 95, :packed => true, :extension => true + repeated :fixed32, :".protobuf_unittest.packed_fixed32_extension", 96, :packed => true, :extension => true + repeated :fixed64, :".protobuf_unittest.packed_fixed64_extension", 97, :packed => true, :extension => true + repeated :sfixed32, :".protobuf_unittest.packed_sfixed32_extension", 98, :packed => true, :extension => true + repeated :sfixed64, :".protobuf_unittest.packed_sfixed64_extension", 99, :packed => true, :extension => true + repeated :float, :".protobuf_unittest.packed_float_extension", 100, :packed => true, :extension => true + repeated :double, :".protobuf_unittest.packed_double_extension", 101, :packed => true, :extension => true + repeated :bool, :".protobuf_unittest.packed_bool_extension", 102, :packed => true, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.packed_enum_extension", 103, :packed => true, :extension => true end class TestUnpackedExtensions # Extension Fields extensions 1...536870912 - repeated :int32, :unpacked_int32_extension, 90, :extension => true - repeated :int64, :unpacked_int64_extension, 91, :extension => true - repeated :uint32, :unpacked_uint32_extension, 92, :extension => true - repeated :uint64, :unpacked_uint64_extension, 93, :extension => true - repeated :sint32, :unpacked_sint32_extension, 94, :extension => true - repeated :sint64, :unpacked_sint64_extension, 95, :extension => true - repeated :fixed32, :unpacked_fixed32_extension, 96, :extension => true - repeated :fixed64, :unpacked_fixed64_extension, 97, :extension => true - repeated :sfixed32, :unpacked_sfixed32_extension, 98, :extension => true - repeated :sfixed64, :unpacked_sfixed64_extension, 99, :extension => true - repeated :float, :unpacked_float_extension, 100, :extension => true - repeated :double, :unpacked_double_extension, 101, :extension => true - repeated :bool, :unpacked_bool_extension, 102, :extension => true - repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum_extension, 103, :extension => true + repeated :int32, :".protobuf_unittest.unpacked_int32_extension", 90, :extension => true + repeated :int64, :".protobuf_unittest.unpacked_int64_extension", 91, :extension => true + repeated :uint32, :".protobuf_unittest.unpacked_uint32_extension", 92, :extension => true + repeated :uint64, :".protobuf_unittest.unpacked_uint64_extension", 93, :extension => true + repeated :sint32, :".protobuf_unittest.unpacked_sint32_extension", 94, :extension => true + repeated :sint64, :".protobuf_unittest.unpacked_sint64_extension", 95, :extension => true + repeated :fixed32, :".protobuf_unittest.unpacked_fixed32_extension", 96, :extension => true + repeated :fixed64, :".protobuf_unittest.unpacked_fixed64_extension", 97, :extension => true + repeated :sfixed32, :".protobuf_unittest.unpacked_sfixed32_extension", 98, :extension => true + repeated :sfixed64, :".protobuf_unittest.unpacked_sfixed64_extension", 99, :extension => true + repeated :float, :".protobuf_unittest.unpacked_float_extension", 100, :extension => true + repeated :double, :".protobuf_unittest.unpacked_double_extension", 101, :extension => true + repeated :bool, :".protobuf_unittest.unpacked_bool_extension", 102, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.unpacked_enum_extension", 103, :extension => true end class TestDynamicExtensions @@ -763,8 +765,8 @@ class RepeatedGroup repeated ::Protobuf_unittest::TestParsingMerge::RepeatedGroup, :repeatedgroup, 20 # Extension Fields extensions 1000...536870912 - optional ::Protobuf_unittest::TestAllTypes, :optional_ext, 1000, :extension => true - repeated ::Protobuf_unittest::TestAllTypes, :repeated_ext, 1001, :extension => true + optional ::Protobuf_unittest::TestAllTypes, :".protobuf_unittest.TestParsingMerge.optional_ext", 1000, :extension => true + repeated ::Protobuf_unittest::TestAllTypes, :".protobuf_unittest.TestParsingMerge.repeated_ext", 1001, :extension => true end class TestCommentInjectionMessage diff --git a/spec/support/protos/multi_field_extensions.pb.rb b/spec/support/protos/multi_field_extensions.pb.rb index 276041ad..e01f5abe 100644 --- a/spec/support/protos/multi_field_extensions.pb.rb +++ b/spec/support/protos/multi_field_extensions.pb.rb @@ -37,7 +37,7 @@ class Header required ::Test::Header::Type, :type, 1 # Extension Fields extensions 100...536870912 - optional ::Test::PayloadA, :payload, 100, :extension => true + optional ::Test::PayloadA, :".test.PayloadA.payload", 100, :extension => true end class PayloadA From 1fa3b5e2cb110bc18724500cf69db3f2fdc03287 Mon Sep 17 00:00:00 2001 From: Embark Date: Tue, 1 Mar 2016 15:42:05 -0800 Subject: [PATCH 0977/1191] Messages fields should be able to be set with to_proto A prior commit introduced a bug so that you would get `Failure/Error: fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}"` when trying to set a message field with a class that defined a #to_proto method. --- lib/protobuf/field/message_field.rb | 26 +++--- spec/lib/protobuf/field/message_field_spec.rb | 79 +++++++++++++++++++ 2 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 spec/lib/protobuf/field/message_field_spec.rb diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index e79379f0..304a201f 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,7 +9,7 @@ class MessageField < BaseField # def acceptable?(val) - val.is_a?(type_class) || val.respond_to?(:to_hash) + val.is_a?(type_class) || val.respond_to?(:to_hash) || val.respond_to?(:to_proto) end def decode(bytes) @@ -31,17 +31,19 @@ def wire_type end def coerce!(value) - if value.nil? - nil - elsif value.is_a?(type_class) - value - elsif value.respond_to?(:to_proto) - value.to_proto - elsif value.respond_to?(:to_hash) - type_class.new(value.to_hash) - else - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{value.class}'" - end + return nil if value.nil? + + coerced_value = if value.respond_to?(:to_proto) + value.to_proto + elsif value.respond_to?(:to_hash) + type_class.new(value.to_hash) + else + value + end + + return coerced_value if coerced_value.is_a?(type_class) + + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{value.class}'" end end diff --git a/spec/lib/protobuf/field/message_field_spec.rb b/spec/lib/protobuf/field/message_field_spec.rb new file mode 100644 index 00000000..b7fdf442 --- /dev/null +++ b/spec/lib/protobuf/field/message_field_spec.rb @@ -0,0 +1,79 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::MessageField do + let(:field_message) do + Class.new(::Protobuf::Message) do + optional :int32, :field, 1 + end + end + + let(:message) do + Class.new(::Protobuf::Message) do + optional FieldMessage, :message_field, 1 + end + end + + before do + stub_const('FieldMessage', field_message) + stub_const('Message', message) + end + + let(:instance) { message.new } + + describe 'setting and getting field' do + context "when set with the message type" do + it 'is readable as a message' do + value = field_message.new(:field => 34) + instance.message_field = value + expect(instance.message_field).to eq(value) + end + end + + context "when set with #to_proto" do + let(:to_proto_message) do + Class.new do + def to_proto + FieldMessage.new(:field => 42) + end + end + end + + it 'is readable as a message' do + value = to_proto_message.new + instance.message_field = value + expect(instance.message_field).to eq(value.to_proto) + end + end + + context "when set with #to_proto that returns the wrong message type" do + let(:to_proto_is_wrong_message) do + Class.new do + def to_proto + Message.new + end + end + end + + it 'fails' do + value = to_proto_is_wrong_message.new + expect { instance.message_field = value }.to raise_error TypeError + end + end + + context "when set with #to_hash" do + let(:to_hash_message) do + Class.new do + def to_hash + { :field => 989 } + end + end + end + + it 'is readable as a message' do + value = to_hash_message.new + instance.message_field = value + expect(instance.message_field).to eq(field_message.new(value.to_hash)) + end + end + end +end From f52b2764f35565258ebab37bab5a70958cadf020 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Fri, 26 Feb 2016 12:47:01 -0800 Subject: [PATCH 0978/1191] PR feedback --- .rubocop_todo.yml | 2 +- lib/protobuf/field/base_field.rb | 13 ++-- lib/protobuf/generators/field_generator.rb | 12 ++-- lib/protobuf/message/fields.rb | 70 +++++++++++++++------- spec/lib/protobuf/message_spec.rb | 36 +++++++---- 5 files changed, 90 insertions(+), 43 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2a18fb8a..b3c35e05 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -21,7 +21,7 @@ Metrics/CyclomaticComplexity: # Offense count: 493 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: - Max: 196 + Max: 199 # Offense count: 44 # Configuration parameters: CountComments. diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 5faad284..7ad4802b 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -21,7 +21,7 @@ class BaseField ## # Attributes # - attr_reader :message_class, :name, :options, :rule, :tag, :type_class + attr_reader :message_class, :name, :fully_qualified_name, :options, :rule, :tag, :type_class ## # Class Methods @@ -35,16 +35,17 @@ def self.default # Constructor # - def initialize(message_class, rule, type_class, name, tag, simple_name, options) + def initialize(message_class, rule, type_class, fully_qualified_name, tag, simple_name, options) @message_class = message_class - @name = name + @name = simple_name || fully_qualified_name + @fully_qualified_name = fully_qualified_name @rule = rule @tag = tag @type_class = type_class @options = options validate_packed_field if packed? - define_accessor(simple_name, name) if simple_name + define_accessor(simple_name, fully_qualified_name) if simple_name tag_encoded end @@ -165,6 +166,10 @@ def wire_type ::Protobuf::WireType::VARINT end + def fully_qualified_name_only! + @name = @fully_qualified_name + end + private ## diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 28595a7a..88e2be1b 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -20,6 +20,12 @@ class FieldGenerator < Base attr_reader :field_options def applicable_options + # Note on the strange use of `#inspect`: + # :boom.inspect #=> ":boom" + # :".boom.foo".inspect #=> ":\".boom.foo\"" + # An alternative to `#inspect` would be always adding double quotes, + # but the generatated code looks un-idiomatic: + # ":\"#{:boom}\"" #=> ":\"boom\"" <-- Note the unnecessary double quotes @applicable_options ||= field_options.map { |k, v| "#{k.inspect} => #{v}" } end @@ -64,11 +70,7 @@ def label end def name - @name ||= if descriptor.name.include?('.') - ":#{descriptor.name.inspect}" - else - ":#{descriptor.name}" - end + @name ||= descriptor.name.to_sym.inspect end def number diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index ccb2cbdb..4692ab22 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -96,57 +96,81 @@ def get_field(name_or_tag, allow_extension = false) end end - def extension_shortcuts - @extension_shortcuts ||= Set.new - end - - def define_field(rule, type_class, field_name, tag, options) - raise_if_tag_collision(tag, field_name) - raise_if_name_collision(field_name) + def define_field(rule, type_class, fully_qualified_field_name, tag, options) + raise_if_tag_collision(tag, fully_qualified_field_name) + raise_if_name_collision(fully_qualified_field_name) # Determine appropirate accessor for fields depending on name collisions via extensions: # Case 1: Base field = "string_field" and no extensions of the same name - # Result: message.string_field #=> @values["string_field"] + # Result: + # message.string_field #=> @values["string_field"] + # message[:string_field] #=> @values["string_field"] + # message['string_field'] #=> @values["string_field"] # Case 2: Base field = "string_field" and extension 1 = ".my_package.string_field", extension N = ".package_N.string_field"... - # Result: message.string_field #=> @values["string_field"] + # Result: + # message.string_field #=> @values["string_field"] + # message[:string_field] #=> @values["string_field"] + # message['string_field'] #=> @values["string_field"] + # message[:'.my_package.string_field'] #=> @values[".my_package.string_field"] + # message['.my_package.string_field'] #=> @values[".my_package.string_field"] # Case 3: No base field, extension 1 = ".my_package.string_field", extension 2 = ".other_package.string_field", extension N... - # Result: message.string_field #=> raise NoMethodError (no simple accessor allowed) + # Result: + # message.string_field #=> raise NoMethodError (no simple accessor allowed) + # message[:string_field] #=> raise NoMethodError (no simple accessor allowed) + # message['string_field'] #=> raise NoMethodError (no simple accessor allowed) + # message[:'.my_package.string_field'] #=> @values[".my_package.string_field"] + # message['.my_package.string_field'] #=> @values[".my_package.string_field"] + # message[:'.other_package.string_field'] #=> @values[".other_package.string_field"] + # message['.other_package.string_field'] #=> @values[".other_package.string_field"] # Case 4: No base field, extension = ".my_package.string_field", no other extensions - # Result: message.string_field #=> @values[".my_package.string_field"] + # Result: + # message.string_field #=> @values[".my_package.string_field"] + # message[:string_field] #=> @values[".my_package.string_field"] + # message['string_field'] #=> @values[".my_package.string_field"] + # message[:'.my_package.string_field'] #=> @values[".my_package.string_field"] + # message[:'.my_package.string_field'] #=> @values[".my_package.string_field"] if options[:extension] - base_name = field_name.to_s.split('.').last - # Case 2 + base_name = fully_qualified_field_name.to_s.split('.').last.to_sym if field_store[base_name] - simple_name = nil - # Case 3 - elsif extension_shortcuts.include?(base_name) - remove_existing_accessors(base_name) - simple_name = nil + # Case 3 + if field_store[base_name].extension? + remove_existing_accessors(base_name) + simple_name = nil + # Case 2 + else + simple_name = nil + end # Case 4 else - extension_shortcuts << base_name simple_name = base_name end else # Case 1 - simple_name = field_name + simple_name = fully_qualified_field_name end - field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, simple_name, options) + field = ::Protobuf::Field.build(self, rule, type_class, fully_qualified_field_name, + tag, simple_name, options) field_store[tag] = field - field_store[field_name] = field - field_store[field_name.to_s] = field + field_store[fully_qualified_field_name.to_sym] = field + field_store[fully_qualified_field_name.to_s] = field + if simple_name && simple_name != fully_qualified_field_name + field_store[simple_name.to_sym] = field + field_store[simple_name.to_s] = field + end # defining a new field for the message will cause cached @all_fields, @extension_fields, # and @fields to be incorrect; reset them @all_fields = @extension_fields = @fields = nil end def remove_existing_accessors(accessor) + field_store.delete(accessor.to_sym).try(:fully_qualified_name_only!) + field_store.delete(accessor.to_s) ACCESSOR_SUFFIXES.each do |modifier| begin remove_method("#{accessor}#{modifier}") diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index fa7cd16b..4abc7dc3 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -485,11 +485,14 @@ field = ::Test::Resource.get_extension_field(100) expect(field).to be_a(::Protobuf::Field::BoolField) expect(field.tag).to eq(100) - expect(field.name).to eq(:'.test.Searchable.ext_is_searchable') + expect(field.name).to eq(:ext_is_searchable) + expect(field.fully_qualified_name).to eq(:'.test.Searchable.ext_is_searchable') expect(field).to be_extension end it 'fetches an extension field by its symbolized name' do + expect(::Test::Resource.get_extension_field(:ext_is_searchable)).to be_a(::Protobuf::Field::BoolField) + expect(::Test::Resource.get_extension_field('ext_is_searchable')).to be_a(::Protobuf::Field::BoolField) expect(::Test::Resource.get_extension_field(:'.test.Searchable.ext_is_searchable')).to be_a(::Protobuf::Field::BoolField) expect(::Test::Resource.get_extension_field('.test.Searchable.ext_is_searchable')).to be_a(::Protobuf::Field::BoolField) end @@ -510,6 +513,7 @@ expect(field).to be_a(::Protobuf::Field::StringField) expect(field.tag).to eq(1) expect(field.name).to eq(:name) + expect(field.fully_qualified_name).to eq(:name) expect(field).not_to be_extension end @@ -535,6 +539,7 @@ end describe 'defining a field' do + # Case 1 context 'single base field' do let(:klass) do Class.new(Protobuf::Message) do @@ -546,9 +551,11 @@ message = klass.new(:foo => 'bar') expect(message.foo).to eq('bar') expect(message[:foo]).to eq('bar') + expect(message['foo']).to eq('bar') end end + # Case 2 context 'base field and extension field name collision' do let(:klass) do Class.new(Protobuf::Message) do @@ -561,39 +568,48 @@ message = klass.new(:foo => 'bar', '.boom.foo' => 'bam') expect(message.foo).to eq('bar') expect(message[:foo]).to eq('bar') + expect(message['foo']).to eq('bar') expect(message[:'.boom.foo']).to eq('bam') + expect(message['.boom.foo']).to eq('bam') end end - context 'no base field with an extension field' do + # Case 3 + context 'no base field with extension fields with name collision' do let(:klass) do Class.new(Protobuf::Message) do optional :string, :".boom.foo", 2, :extension => true + optional :string, :".goat.foo", 3, :extension => true end end it 'has an accessor for foo that refers to the extension field' do - message = klass.new('.boom.foo' => 'bam') - expect(message.foo).to eq('bam') + message = klass.new('.boom.foo' => 'bam', '.goat.foo' => 'red') + expect { message.foo }.to raise_error(NoMethodError) expect { message[:foo] }.to raise_error(ArgumentError) + expect { message['foo'] }.to raise_error(ArgumentError) expect(message[:'.boom.foo']).to eq('bam') + expect(message['.boom.foo']).to eq('bam') + expect(message[:'.goat.foo']).to eq('red') + expect(message['.goat.foo']).to eq('red') end end - context 'no base field with extension fields with name collision' do + # Case 4 + context 'no base field with an extension field' do let(:klass) do Class.new(Protobuf::Message) do optional :string, :".boom.foo", 2, :extension => true - optional :string, :".goat.foo", 3, :extension => true end end it 'has an accessor for foo that refers to the extension field' do - message = klass.new('.boom.foo' => 'bam', '.goat.foo' => 'red') - expect { message.foo }.to raise_error(NoMethodError) - expect { message[:foo] }.to raise_error(ArgumentError) + message = klass.new('.boom.foo' => 'bam') + expect(message.foo).to eq('bam') + expect(message[:foo]).to eq('bam') + expect(message['foo']).to eq('bam') expect(message[:'.boom.foo']).to eq('bam') - expect(message[:'.goat.foo']).to eq('red') + expect(message['.boom.foo']).to eq('bam') end end end From 9a99921f3cf1b600ae5f094c4496cf3477e34424 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Tue, 2 Feb 2016 18:11:57 -0800 Subject: [PATCH 0979/1191] add PB_UPCASE_ENUMS option enum names are not required to be Capitalized, but ruby constants are. Add option to UPCASE all enum names --- lib/protobuf/generators/enum_generator.rb | 1 + spec/lib/protobuf/generators/enum_generator_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index c45c6985..3c1e5ffa 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -32,6 +32,7 @@ def compile def build_value(enum_value_descriptor) name = enum_value_descriptor.name + name.upcase! if ENV.key?('PB_UPCASE_ENUMS') number = enum_value_descriptor.number "define :#{name}, #{number}" end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 0d63ff2d..74976f34 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -68,6 +68,15 @@ class TestEnum < ::Protobuf::Enum it 'returns a string identifying the given enum value' do expect(subject.build_value(enum.value.first)).to eq("define :FOO, 1") end + + context 'with PB_UPCASE_ENUMS set' do + before { allow(ENV).to receive(:key?).with('PB_UPCASE_ENUMS').and_return(true) } + let(:values) { [{ :name => 'boom', :number => 1 }] } + + it 'returns a string with the given enum name in ALL CAPS' do + expect(subject.build_value(enum.value.first)).to eq("define :BOOM, 1") + end + end end end From 089845d1096066dd24dc805a9515486348a41275 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 2 Mar 2016 11:31:27 -0800 Subject: [PATCH 0980/1191] Empty values should not clear a protobuf field Before a recent commit, empty? values never cleared a proto field unless the field was a Fixnum or Boolean type (which didn't make any sense, and was probably unused, anyway). --- lib/protobuf/message.rb | 2 +- spec/lib/protobuf/message_spec.rb | 197 +++++++++++++++++++++--------- 2 files changed, 140 insertions(+), 59 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 507b03ef..d17ebcbf 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -178,7 +178,7 @@ def []=(name, value) @values[field.name].replace(value) end else - if value.nil? || (value.respond_to?(:empty?) && value.empty?) + if value.nil? @values.delete(field.name) elsif field.acceptable?(value) @values[field.name] = field.coerce!(value) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 4abc7dc3..500f8262 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -181,64 +181,6 @@ test_enum = Test::EnumTestMessage.new { |p| p.non_default_enum = 2 } expect(test_enum.non_default_enum).to eq(2) end - - context 'ignoring unknown fields' do - around do |example| - orig = ::Protobuf.ignore_unknown_fields? - ::Protobuf.ignore_unknown_fields = true - example.call - ::Protobuf.ignore_unknown_fields = orig - end - - context 'with valid fields' do - let(:values) { { :name => "Jim" } } - - it "does not raise an error" do - expect { ::Test::Resource.new(values) }.to_not raise_error - end - end - - context 'with non-existent field' do - let(:values) { { :name => "Jim", :othername => "invalid" } } - - it "does not raise an error" do - expect { ::Test::Resource.new(values) }.to_not raise_error - end - end - end - - context 'not ignoring unknown fields' do - around do |example| - orig = ::Protobuf.ignore_unknown_fields? - ::Protobuf.ignore_unknown_fields = false - example.call - ::Protobuf.ignore_unknown_fields = orig - end - - context 'with valid fields' do - let(:values) { { :name => "Jim" } } - - it "does not raise an error" do - expect { ::Test::Resource.new(values) }.to_not raise_error - end - end - - context 'with non-existent field' do - let(:values) { { :name => "Jim", :othername => "invalid" } } - - it "raises an error and mentions the erroneous field" do - expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) - end - - context 'with a nil value' do - let(:values) { { :name => "Jim", :othername => nil } } - - it "raises an error and mentions the erroneous field" do - expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) - end - end - end - end end describe '#encode' do @@ -613,4 +555,143 @@ end end end + + describe '.[]=' do + context 'clearing fields' do + it 'clears repeated fields with an empty array' do + instance = ::Test::Resource.new(:repeated_enum => [::Test::StatusType::ENABLED]) + expect(instance.field?(:repeated_enum)).to be(true) + instance[:repeated_enum] = [] + expect(instance.field?(:repeated_enum)).to be(false) + end + + it 'clears optional fields with nil' do + instance = ::Test::Resource.new(:name => "Joe") + expect(instance.field?(:name)).to be(true) + instance[:name] = nil + expect(instance.field?(:name)).to be(false) + end + + it 'clears optional extenstion fields with nil' do + instance = ::Test::Resource.new(:ext_is_searchable => true) + expect(instance.field?(:ext_is_searchable)).to be(true) + instance[:ext_is_searchable] = nil + expect(instance.field?(:ext_is_searchable)).to be(false) + end + end + + context 'setting fields' do + let(:instance) { ::Test::Resource.new } + + it 'sets and replaces repeated fields' do + initial = [::Test::StatusType::ENABLED, ::Test::StatusType::DISABLED] + instance[:repeated_enum] = initial + expect(instance[:repeated_enum]).to eq(initial) + replacement = [::Test::StatusType::DELETED] + instance[:repeated_enum] = replacement + expect(instance[:repeated_enum]).to eq(replacement) + end + + it 'sets acceptable optional field values' do + instance[:name] = "Joe" + expect(instance[:name]).to eq("Joe") + instance[1] = "Tom" + expect(instance[:name]).to eq("Tom") + end + + it 'sets acceptable empty string field values' do + instance[:name] = "" + expect(instance.name!).to eq("") + end + + it 'sets acceptable empty message field values' do + instance = ::Test::Nested.new + instance[:resource] = {} + expect(instance.resource!).to eq(::Test::Resource.new) + end + + it 'sets acceptable extension field values' do + instance[:ext_is_searchable] = true + expect(instance[:ext_is_searchable]).to eq(true) + instance[:".test.Searchable.ext_is_searchable"] = false + expect(instance[:ext_is_searchable]).to eq(false) + instance[100] = true + expect(instance[:ext_is_searchable]).to eq(true) + end + end + + context 'throwing TypeError' do + let(:instance) { ::Test::Resource.new } + + it 'throws when a repeated value is set with a non array' do + expect { instance[:repeated_enum] = "string" }.to raise_error(TypeError) + end + + it 'throws when a repeated value is set with an array of the wrong type' do + expect { instance[:repeated_enum] = [true, false] }.to raise_error(TypeError) + end + + it 'throws when an optional value is not #acceptable?' do + expect { instance[:name] = 1 }.to raise_error(TypeError) + end + end + + context 'ignoring unknown fields' do + around do |example| + orig = ::Protobuf.ignore_unknown_fields? + ::Protobuf.ignore_unknown_fields = true + example.call + ::Protobuf.ignore_unknown_fields = orig + end + + context 'with valid fields' do + let(:values) { { :name => "Jim" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + + context 'with non-existent field' do + let(:values) { { :name => "Jim", :othername => "invalid" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + end + + context 'not ignoring unknown fields' do + around do |example| + orig = ::Protobuf.ignore_unknown_fields? + ::Protobuf.ignore_unknown_fields = false + example.call + ::Protobuf.ignore_unknown_fields = orig + end + + context 'with valid fields' do + let(:values) { { :name => "Jim" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + + context 'with non-existent field' do + let(:values) { { :name => "Jim", :othername => "invalid" } } + + it "raises an error and mentions the erroneous field" do + expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) + end + + context 'with a nil value' do + let(:values) { { :name => "Jim", :othername => nil } } + + it "raises an error and mentions the erroneous field" do + expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) + end + end + end + end + end end From 646bec85a4b7559308f01d166395808f3baad5e7 Mon Sep 17 00:00:00 2001 From: Embark Date: Thu, 24 Mar 2016 13:48:32 -0700 Subject: [PATCH 0981/1191] Properly encode and decode negative enum values From proto2 guide: Enumerator constants must be in the range of a 32-bit integer. Since enum values use varint encoding on the wire, negative values are inefficient and thus not recommended. Before this change, enum values were incorrectly treated as uint values, and negative values would cause this error in the Varint gem: `no implicit conversion from nil to integer` --- lib/protobuf/field/enum_field.rb | 7 +++--- spec/lib/protobuf/field/enum_field_spec.rb | 26 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 spec/lib/protobuf/field/enum_field_spec.rb diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 1f97913e..e2c8c311 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -1,8 +1,8 @@ -require 'protobuf/field/varint_field' +require 'protobuf/field/integer_field' module Protobuf module Field - class EnumField < VarintField + class EnumField < IntegerField ## # Class Methods @@ -25,7 +25,8 @@ def encode(value) end def decode(value) - value if acceptable?(value) + decoded = super(value) + decoded if acceptable?(decoded) end def enum? diff --git a/spec/lib/protobuf/field/enum_field_spec.rb b/spec/lib/protobuf/field/enum_field_spec.rb new file mode 100644 index 00000000..cd72760d --- /dev/null +++ b/spec/lib/protobuf/field/enum_field_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::EnumField do + let(:message) do + Class.new(::Protobuf::Message) do + enum_class = Class.new(::Protobuf::Enum) do + define :POSITIVE, 22 + define :NEGATIVE, -33 + end + + optional enum_class, :enum, 1 + end + end + + describe '.{encode, decode}' do + it 'handles positive enum constants' do + instance = message.new(:enum => :POSITIVE) + expect(message.decode(instance.encode).enum).to eq(22) + end + + it 'handles negative enum constants' do + instance = message.new(:enum => :NEGATIVE) + expect(message.decode(instance.encode).enum).to eq(-33) + end + end +end From c1b1c479c771206bb2aeeea0f8023d797bf9e657 Mon Sep 17 00:00:00 2001 From: Embark Date: Sun, 20 Mar 2016 22:09:14 -0700 Subject: [PATCH 0982/1191] Field values should be stored via their fully qualified names This fixes a bug where ::Protobuf::Message#{simple_field_name}! would return nil rather than the value of the field, if the field was an extension. This also fixes a bug where ::Protobuf::Message.field?(name) would always return false if name was the fully qualified name of an extension. --- lib/protobuf/message.rb | 25 ++++--- spec/lib/protobuf/message_spec.rb | 109 +++++++++++++++++++++++++++++- 2 files changed, 121 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index d17ebcbf..1f30d348 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -84,7 +84,7 @@ def each_field def each_field_for_serialization self.class.all_fields.each do |field| - value = @values[field.getter] + value = @values[field.fully_qualified_name] if value.nil? fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if field.required? next @@ -95,7 +95,9 @@ def each_field_for_serialization end def field?(name) - @values.key?(name) + field = self.class.get_field(name, true) + return false if field.nil? + @values.key?(field.fully_qualified_name) end ::Protobuf.deprecator.define_deprecated_methods(self, :has_field? => :field?) @@ -122,8 +124,9 @@ def to_hash @values.each_key do |field_name| value = self[field_name] + field = self.class.get_field(field_name, true) hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value - result[field_name] = hashed_value + result[field.name] = hashed_value end result @@ -148,9 +151,9 @@ def ==(other) def [](name) if (field = self.class.get_field(name, true)) if field.repeated? - @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) - elsif @values.key?(field.name) - @values[field.name] + @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) + elsif @values.key?(field.fully_qualified_name) + @values[field.fully_qualified_name] else field.default_value end @@ -172,16 +175,16 @@ def []=(name, value) end if value.empty? - @values.delete(field.name) + @values.delete(field.fully_qualified_name) else - @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) - @values[field.name].replace(value) + @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) + @values[field.fully_qualified_name].replace(value) end else if value.nil? - @values.delete(field.name) + @values.delete(field.fully_qualified_name) elsif field.acceptable?(value) - @values[field.name] = field.coerce!(value) + @values[field.fully_qualified_name] = field.coerce!(value) else fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 500f8262..30c14874 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -390,6 +390,29 @@ ) end end + + it 'uses simple field names as keys when possible and fully qualified names otherwise' do + message = Class.new(::Protobuf::Message) do + optional :int32, :field, 1 + optional :int32, :colliding_field, 2 + extensions 100...200 + optional :int32, :".ext.normal_ext_field", 100, :extension => true + optional :int32, :".ext.colliding_field", 101, :extension => true + optional :int32, :".ext.colliding_field2", 102, :extension => true + optional :int32, :".ext2.colliding_field2", 103, :extension => true + end + + hash = { + :field => 1, + :colliding_field => 2, + :normal_ext_field => 3, + :".ext.colliding_field" => 4, + :".ext.colliding_field2" => 5, + :".ext2.colliding_field2" => 6, + } + instance = message.new(hash) + expect(instance.to_hash).to eq(hash) + end end describe '#to_json' do @@ -413,13 +436,37 @@ describe "#define_accessor" do subject { ::Test::Resource.new } - it "allows string fields to be set to nil" do + it 'allows string fields to be set to nil' do expect { subject.name = nil }.to_not raise_error end - it "does not allow string fields to be set to Numeric" do + it 'does not allow string fields to be set to Numeric' do expect { subject.name = 1 }.to raise_error(/name/) end + + context '#{simple_field_name}!' do + it 'returns value of set field' do + expect(::Test::Resource.new(:name => "Joe").name!).to eq("Joe") + end + + it 'returns value of set field with default' do + expect(::Test::Resource.new(:name => "").name!).to eq("") + end + + it 'returns nil if extension field is unset' do + expect(subject.ext_is_searchable!).to be_nil + end + + it 'returns value of set extension field' do + message = ::Test::Resource.new(:ext_is_searchable => true) + expect(message.ext_is_searchable!).to be(true) + end + + it 'returns value of set extension field with default' do + message = ::Test::Resource.new(:ext_is_searchable => false) + expect(message.ext_is_searchable!).to be(false) + end + end end describe '.get_extension_field' do @@ -449,6 +496,64 @@ end end + describe '#field?' do + it 'returns false for non-existent field' do + expect(::Test::Resource.get_field('doesnotexist')).to be_nil + expect(::Test::Resource.new.field?('doesnotexist')).to be(false) + end + + it 'returns false for unset field' do + expect(::Test::Resource.get_field('name')).to be + expect(::Test::Resource.new.field?('name')).to be(false) + end + + it 'returns false for unset field from tag' do + expect(::Test::Resource.get_field(1)).to be + expect(::Test::Resource.new.field?(1)).to be(false) + end + + it 'returns true for set field' do + expect(::Test::Resource.new(:name => "Joe").field?('name')).to be(true) + end + + it 'returns true for set field with default' do + expect(::Test::Resource.new(:name => "").field?('name')).to be(true) + end + + it 'returns true from field tag value' do + expect(::Test::Resource.new(:name => "Joe").field?(1)).to be(true) + end + + it 'returns false for unset extension field' do + ext_field = :".test.Searchable.ext_is_searchable" + expect(::Test::Resource.get_extension_field(ext_field)).to be + expect(::Test::Resource.new.field?(ext_field)).to be(false) + end + + it 'returns false for unset extension field from tag' do + expect(::Test::Resource.get_extension_field(100)).to be + expect(::Test::Resource.new.field?(100)).to be(false) + end + + it 'returns true for set extension field' do + ext_field = :".test.Searchable.ext_is_searchable" + message = ::Test::Resource.new(ext_field => true) + expect(message.field?(ext_field)).to be(true) + end + + it 'returns true for set extension field with default' do + ext_field = :".test.Searchable.ext_is_searchable" + message = ::Test::Resource.new(ext_field => false) + expect(message.field?(ext_field)).to be(true) + end + + it 'returns true for set extension field from tag' do + ext_field = :".test.Searchable.ext_is_searchable" + message = ::Test::Resource.new(ext_field => false) + expect(message.field?(100)).to be(true) + end + end + describe '.get_field' do it 'fetches a non-extension field by its tag' do field = ::Test::Resource.get_field(1) From afb00db53ccacf5f75c5ad04c763d741b911d57a Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 17 Mar 2016 15:30:03 -0700 Subject: [PATCH 0983/1191] Add ENV variable to preserve raw RPC name (since #underscore can be lossy) --- lib/protobuf/generators/service_generator.rb | 4 ++-- spec/lib/protobuf/generators/service_generator_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb index 801dd0bb..5e449768 100644 --- a/lib/protobuf/generators/service_generator.rb +++ b/lib/protobuf/generators/service_generator.rb @@ -15,10 +15,10 @@ def compile end def build_method(method_descriptor) - name = method_descriptor.name request_klass = modulize(method_descriptor.input_type) response_klass = modulize(method_descriptor.output_type) - "rpc :#{name.underscore}, #{request_klass}, #{response_klass}" + name = ENV.key?('PB_USE_RAW_RPC_NAMES') ? method_descriptor.name : method_descriptor.name.underscore + "rpc :#{name}, #{request_klass}, #{response_klass}" end end diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index c3500877..141085c2 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -41,6 +41,15 @@ it 'returns a string identifying the given method descriptor' do expect(subject.build_method(service.method.first)).to eq("rpc :search, FooRequest, FooResponse") end + + context 'with PB_USE_RAW_RPC_NAMES in the environemnt' do + before { allow(ENV).to receive(:key?).with('PB_USE_RAW_RPC_NAMES').and_return(true) } + + it 'uses the raw RPC name and does not underscore it' do + expect(subject.build_method(service.method.first)).to eq("rpc :Search, FooRequest, FooResponse") + expect(subject.build_method(service.method.last)).to eq("rpc :FooBar, ::Foo::Request, ::Bar::Response") + end + end end end From 33322af27794b6b2a9c981290346533a64e79797 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 28 Mar 2016 12:01:15 -0600 Subject: [PATCH 0984/1191] Update changelog for 3.6.7 and 3.7.0 pre0 --- CHANGES.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 918fba91..b12f5793 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,20 @@ # Stable (3.x) +3.7.0 (pre0) +----------- +- Add `PB_USE_RAW_RPC_NAMES` option to preserve raw RPC name (since #underscore can be lossy). +- Add `PB_ENUM_UPCASE` option to generate enum values as upcased. +- Clean up dynamic code generation in prep for extension namespacing. +- Namespace extension fields. +- Field values should be stored via their fully qualified names +- Refresh google/protobuf/descriptor.{proto,pb.rb} +- Properly encode and decode negative enum values. + +3.6.7 +----- +- An issue was reported with the encode memoization added in #293 with using any array modification +method on repeated fields. Remove memoization on encode (#305) until we can find a better solution. + 3.5.5 -------- - Add native Varint for MRI. From 8ba2e005c9e8ec5c6c8db273651c52c335cc40a0 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Tue, 29 Mar 2016 11:57:43 -0600 Subject: [PATCH 0985/1191] Fix rubocop: lock down the parser version / upgrade rubocop to 0.35 --- .rubocop.yml | 3 +++ protobuf.gemspec | 3 ++- spec/lib/protobuf/enum_spec.rb | 4 ++-- spec/lib/protobuf/rpc/service_filters_spec.rb | 4 ++-- spec/support/server.rb | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1f6c8f57..ea1b98f2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ inherit_from: .rubocop_todo.yml +AllCops: + DisplayCopNames: true + Lint/EndAlignment: AlignWith: keyword diff --git a/protobuf.gemspec b/protobuf.gemspec index 1e84a09d..ad9076a3 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -27,7 +27,8 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' - s.add_development_dependency 'rubocop', '0.34.2' + s.add_development_dependency "rubocop", "~> 0.35.0" + s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984 s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' s.add_development_dependency 'yard' diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 94d75cbb..b3c2b1ce 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -57,7 +57,7 @@ Test::EnumTestType::TWO, Test::EnumTestType::MINUS_ONE, Test::EnumTestType::THREE, - ], + ] ) end @@ -68,7 +68,7 @@ EnumAliasTest::FOO, EnumAliasTest::BAR, EnumAliasTest::BAZ, - ], + ] ) end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 97cc5b2d..f63c41c0 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -362,7 +362,7 @@ def inner_around :endpoint, :inner_around_bottom, :outer_around_bottom, - ], + ] ) end @@ -390,7 +390,7 @@ def inner_around :outer_around_top, :inner_around, :outer_around_bottom, - ], + ] ) end diff --git a/spec/support/server.rb b/spec/support/server.rb index 8a0203b6..ecc6a6cd 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -31,7 +31,7 @@ def initialize(options = {}) :worker_port => 9400, :delay => 0, :server => Protobuf::Rpc::Socket::Server, - ), + ) ) start From 0fc823feb7420a5f00793c5573fa260683801d4a Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 16 Mar 2016 10:35:46 -0700 Subject: [PATCH 0986/1191] Add option to name a package from file name if necessary --- lib/protobuf/generators/file_generator.rb | 3 ++ .../generators/file_generator_spec.rb | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index f4035ac6..6b50631b 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -123,6 +123,9 @@ def print_import_requires def print_package(&block) namespaces = descriptor.package.split('.') + if namespaces.empty? && ENV.key?('PB_ALLOW_DEFAULT_PACKAGE_NAME') + namespaces = [File.basename(descriptor.name).sub('.proto', '')] + end namespaces.reverse.reduce(block) do |previous, namespace| -> { print_module(namespace, &previous) } end.call diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 3374d75e..22f98c14 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -29,4 +29,37 @@ end + describe '#compile' do + it 'generates the file contents' do + subject.compile + expect(subject.to_s).to eq < Date: Tue, 12 Apr 2016 17:59:53 -0700 Subject: [PATCH 0987/1191] Revert to old behavior for setting repeated fields to nil The direct setter for repeated fields didn't allow nil values, but everything else did (and ignored nils). We accidentally changed that behavior, even though it's awful behavior and should probably be intentionally changed in the future. --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/message.rb | 52 ++++++++++++++++++------------- spec/lib/protobuf/message_spec.rb | 21 +++++++++++++ 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 7ad4802b..a28f8fcc 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -185,7 +185,7 @@ def define_accessor(simple_field_name, fully_qualified_field_name) message_class.class_eval do define_method(simple_field_name) { self[fully_qualified_field_name] } - define_method("#{simple_field_name}=") { |v| self[fully_qualified_field_name] = v } + define_method("#{simple_field_name}=") { |v| set_field(fully_qualified_field_name, v, false) } end return unless deprecated? diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1f30d348..75cf83c8 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -41,7 +41,7 @@ def self.to_json def initialize(fields = {}) @values = {} fields.to_hash.each do |name, value| - self[name] = value + set_field(name, value, true) end yield self if block_given? @@ -163,8 +163,37 @@ def [](name) end def []=(name, value) + set_field(name, value, true) + end + + ## + # Instance Aliases + # + alias_method :to_hash_value, :to_hash + alias_method :to_proto_hash, :to_hash + alias_method :responds_to_has?, :respond_to_has? + alias_method :respond_to_and_has?, :respond_to_has? + alias_method :responds_to_and_has?, :respond_to_has? + alias_method :respond_to_has_present?, :respond_to_has_and_present? + alias_method :respond_to_and_has_present?, :respond_to_has_and_present? + alias_method :respond_to_and_has_and_present?, :respond_to_has_and_present? + alias_method :responds_to_has_present?, :respond_to_has_and_present? + alias_method :responds_to_and_has_present?, :respond_to_has_and_present? + alias_method :responds_to_and_has_and_present?, :respond_to_has_and_present? + + ## + # Private Instance Methods + # + + private + + def set_field(name, value, ignore_nil_for_repeated) if (field = self.class.get_field(name, true)) if field.repeated? + if value.nil? && ignore_nil_for_repeated + ::Protobuf.deprecator.deprecation_warning("#{self.class}#[#{name}]=nil", "use an empty array instead of nil") + return + end if value.is_a?(Array) value = value.compact else @@ -196,27 +225,6 @@ def []=(name, value) end end - ## - # Instance Aliases - # - alias_method :to_hash_value, :to_hash - alias_method :to_proto_hash, :to_hash - alias_method :responds_to_has?, :respond_to_has? - alias_method :respond_to_and_has?, :respond_to_has? - alias_method :responds_to_and_has?, :respond_to_has? - alias_method :respond_to_has_present?, :respond_to_has_and_present? - alias_method :respond_to_and_has_present?, :respond_to_has_and_present? - alias_method :respond_to_and_has_and_present?, :respond_to_has_and_present? - alias_method :responds_to_has_present?, :respond_to_has_and_present? - alias_method :responds_to_and_has_present?, :respond_to_has_and_present? - alias_method :responds_to_and_has_and_present?, :respond_to_has_and_present? - - ## - # Private Instance Methods - # - - private - def copy_to(object, method) duplicate = proc do |obj| case obj diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 30c14874..ed8ac001 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -181,6 +181,12 @@ test_enum = Test::EnumTestMessage.new { |p| p.non_default_enum = 2 } expect(test_enum.non_default_enum).to eq(2) end + + # to be deprecated + it "allows you to pass nil to repeated fields" do + test = Test::Resource.new(:repeated_enum => nil) + expect(test.repeated_enum).to eq([]) + end end describe '#encode' do @@ -444,6 +450,10 @@ expect { subject.name = 1 }.to raise_error(/name/) end + it 'does not allow a repeated field is set to nil' do + expect { subject.repeated_enum = nil }.to raise_error(TypeError) + end + context '#{simple_field_name}!' do it 'returns value of set field' do expect(::Test::Resource.new(:name => "Joe").name!).to eq("Joe") @@ -723,6 +733,17 @@ instance[100] = true expect(instance[:ext_is_searchable]).to eq(true) end + + # to be deprecated + it 'does nothing when sent an empty array' do + instance[:repeated_enum] = nil + expect(instance[:repeated_enum]).to eq([]) + instance[:repeated_enum] = [1, 2] + expect(instance[:repeated_enum]).to eq([1, 2]) + instance[:repeated_enum] = nil + # Yes this is very silly, but backwards compatible + expect(instance[:repeated_enum]).to eq([1, 2]) + end end context 'throwing TypeError' do From 6147908b4c0bc18657ca45195dc957723adfd97d Mon Sep 17 00:00:00 2001 From: Ben Jansen Date: Fri, 15 Apr 2016 17:08:03 -0700 Subject: [PATCH 0988/1191] Set binmode for protoc-gen-ruby STDIN and STDOUT This fixes #320 --- bin/protoc-gen-ruby | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/protoc-gen-ruby b/bin/protoc-gen-ruby index c0f7d37b..fe055720 100755 --- a/bin/protoc-gen-ruby +++ b/bin/protoc-gen-ruby @@ -10,6 +10,12 @@ require 'protobuf' require 'protobuf/descriptors' require 'protobuf/code_generator' +# Ensure that no encoding conversions are done on STDIN and STDOUT since +# we are passing binary data back and forth. Otherwise these streams +# will be mangled on Windows. +STDIN.binmode +STDOUT.binmode + request_bytes = STDIN.read code_generator = ::Protobuf::CodeGenerator.new(request_bytes) response_bytes = code_generator.response_bytes From 6ec6ec7a4d2e533ef768415f2a833820364a30b0 Mon Sep 17 00:00:00 2001 From: Embark Date: Mon, 9 May 2016 16:10:30 -0700 Subject: [PATCH 0989/1191] Flatten require structure to prevent circular requires --- lib/protobuf.rb | 17 +++++++++++++++++ lib/protobuf/decoder.rb | 3 --- lib/protobuf/enum.rb | 2 -- lib/protobuf/field/base_field.rb | 4 ---- lib/protobuf/generators/file_generator.rb | 2 +- lib/protobuf/message.rb | 4 ---- lib/protobuf/varint.rb | 2 -- .../protobuf/generators/file_generator_spec.rb | 4 ++-- spec/support/protos/enum.pb.rb | 2 +- spec/support/protos/google_unittest.pb.rb | 2 +- .../support/protos/google_unittest_import.pb.rb | 2 +- .../protos/google_unittest_import_public.pb.rb | 2 +- .../support/protos/multi_field_extensions.pb.rb | 2 +- spec/support/protos/resource.pb.rb | 2 +- 14 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 04a95890..efceecb9 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -9,7 +9,24 @@ require 'active_support/json' require 'active_support/notifications' +# All top-level run time code requires, ordered by necessity +require 'protobuf/wire_type' + +require 'protobuf/varint_pure' +require 'protobuf/varint' + +require 'protobuf/exceptions' require 'protobuf/deprecation' +require 'protobuf/logging' + +require 'protobuf/encoder' +require 'protobuf/decoder' + +require 'protobuf/optionable' +require 'protobuf/field' +require 'protobuf/enum' +require 'protobuf/message' +require 'protobuf/descriptors' module Protobuf diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 20538595..a77495d7 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -1,6 +1,3 @@ -require 'protobuf/wire_type' -require 'protobuf/exceptions' - module Protobuf class Decoder diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 961cc1b2..705c4fd2 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,6 +1,4 @@ require 'delegate' -require 'protobuf/deprecation' -require 'protobuf/optionable' ## # Adding extension to Numeric until diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 7ad4802b..93a1f418 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,8 +1,4 @@ -require 'protobuf/deprecation' require 'protobuf/field/field_array' -require 'protobuf/logging' -require 'protobuf/wire_type' - module Protobuf module Field class BaseField diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 6b50631b..2d82e6ad 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -104,7 +104,7 @@ def print_file_comment end def print_generic_requires - print_require("protobuf/message") + print_require("protobuf") print_require("protobuf/rpc/service") if descriptor.service.count > 0 puts end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1f30d348..326bf2c8 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,7 +1,3 @@ -require 'protobuf/field' -require 'protobuf/deprecation' -require 'protobuf/enum' -require 'protobuf/exceptions' require 'protobuf/message/fields' require 'protobuf/message/serialization' diff --git a/lib/protobuf/varint.rb b/lib/protobuf/varint.rb index cfdd1857..fef5e953 100644 --- a/lib/protobuf/varint.rb +++ b/lib/protobuf/varint.rb @@ -1,5 +1,3 @@ -require 'protobuf/varint_pure' - module Protobuf class Varint if defined?(::Varint) diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 22f98c14..84391c4b 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -38,7 +38,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' EOF end @@ -53,7 +53,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' module Foo end diff --git a/spec/support/protos/enum.pb.rb b/spec/support/protos/enum.pb.rb index 3b4a0375..74287073 100644 --- a/spec/support/protos/enum.pb.rb +++ b/spec/support/protos/enum.pb.rb @@ -3,7 +3,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' ## diff --git a/spec/support/protos/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb index 46c611f7..5cb59121 100644 --- a/spec/support/protos/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -3,7 +3,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' require 'protobuf/rpc/service' diff --git a/spec/support/protos/google_unittest_import.pb.rb b/spec/support/protos/google_unittest_import.pb.rb index b81b3f7b..b0257e7a 100644 --- a/spec/support/protos/google_unittest_import.pb.rb +++ b/spec/support/protos/google_unittest_import.pb.rb @@ -3,7 +3,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' ## diff --git a/spec/support/protos/google_unittest_import_public.pb.rb b/spec/support/protos/google_unittest_import_public.pb.rb index 8453bfbb..ab8908c7 100644 --- a/spec/support/protos/google_unittest_import_public.pb.rb +++ b/spec/support/protos/google_unittest_import_public.pb.rb @@ -3,7 +3,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' module Protobuf_unittest_import diff --git a/spec/support/protos/multi_field_extensions.pb.rb b/spec/support/protos/multi_field_extensions.pb.rb index e01f5abe..7954323e 100644 --- a/spec/support/protos/multi_field_extensions.pb.rb +++ b/spec/support/protos/multi_field_extensions.pb.rb @@ -3,7 +3,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' module Test diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index 09d8a4e3..9d43f380 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -3,7 +3,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' require 'protobuf/rpc/service' module Test From 80f2186522a80695a0e5de1ea5698a9b3ede7967 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 16 Mar 2016 11:43:30 -0700 Subject: [PATCH 0990/1191] Make all things Optionable In prep for adding field, enum, message, file, service, and method options get_option! -> return explicitly set options only --- .rubocop.yml | 3 + lib/protobuf/enum.rb | 2 +- lib/protobuf/field/base_field.rb | 1 + lib/protobuf/generators/file_generator.rb | 5 + lib/protobuf/message.rb | 1 + lib/protobuf/optionable.rb | 59 +++++- lib/protobuf/rpc/service.rb | 4 +- spec/lib/protobuf/enum_spec.rb | 4 +- .../generators/file_generator_spec.rb | 2 +- spec/lib/protobuf/optionable_spec.rb | 175 +++++++++++++++--- spec/support/protos/enum.pb.rb | 1 + spec/support/protos/google_unittest.pb.rb | 1 + .../protos/google_unittest_import.pb.rb | 1 + .../google_unittest_import_public.pb.rb | 1 + .../protos/multi_field_extensions.pb.rb | 1 + spec/support/protos/resource.pb.rb | 1 + 16 files changed, 224 insertions(+), 38 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ea1b98f2..1ed3b0d4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -49,6 +49,9 @@ Style/IndentHash: Style/Semicolon: AllowAsExpressionSeparator: true +Style/SingleLineBlockParams: + Enabled: false + Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 705c4fd2..1640a040 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -10,7 +10,7 @@ module Protobuf class Enum < SimpleDelegator # Public: Allows setting Options on the Enum class. - include ::Protobuf::Optionable + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::EnumOptions } def self.aliases_allowed? get_option(:allow_alias) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 93a1f418..89764b78 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -3,6 +3,7 @@ module Protobuf module Field class BaseField include ::Protobuf::Logging + ::Protobuf::Optionable.inject(self, false) { ::Google::Protobuf::FieldOptions } ## # Constants diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 2d82e6ad..561a5d33 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -29,6 +29,7 @@ def compile print_import_requires print_package do + inject_optionable group = GroupGenerator.new(current_indent) group.add_enums(descriptor.enum_type, :namespace => [descriptor.package]) group.add_message_declarations(descriptor.message_type) @@ -141,6 +142,10 @@ def fully_qualified_token?(token) token[0] == '.' end + def inject_optionable + return if descriptor.package.empty? && !ENV.key?('PB_ALLOW_DEFAULT_PACKAGE_NAME') + puts "::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }" + end end end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 326bf2c8..4e4d31e5 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -21,6 +21,7 @@ class Message extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::MessageOptions } ## # Class Methods diff --git a/lib/protobuf/optionable.rb b/lib/protobuf/optionable.rb index 964884e9..c1d794f2 100644 --- a/lib/protobuf/optionable.rb +++ b/lib/protobuf/optionable.rb @@ -1,17 +1,36 @@ -require 'active_support/concern' - module Protobuf module Optionable - extend ::ActiveSupport::Concern - module ClassMethods def get_option(name) - @_optionable_options.try(:[], name) + name = name.to_s + option = optionable_descriptor_class.get_field(name, true) + fail ArgumentError, "invalid option=#{name}" unless option + unless option.fully_qualified_name.to_s == name + # Eventually we'll deprecate the use of simple names of fields completely, but for now make sure people + # are accessing options correctly. We allow simple names in other places for backwards compatibility. + fail ArgumentError, "must access option using its fully qualified name: #{option.fully_qualified_name.inspect}" + end + if @_optionable_options.try(:key?, name) + value = @_optionable_options[name] + else + value = option.default_value + end + if option.type_class < ::Protobuf::Message + option.type_class.new(value) + else + value + end + end + + def get_option!(name) + get_option(name) if @_optionable_options.try(:key?, name.to_s) end + private + def set_option(name, value = true) @_optionable_options ||= {} - @_optionable_options[name] = value + @_optionable_options[name.to_s] = value end end @@ -19,5 +38,33 @@ def get_option(name) self.class.get_option(name) end + def get_option!(name) + self.class.get_option!(name) + end + + def self.inject(base_class, extend_class = true, &block) + unless block_given? + fail ArgumentError, 'missing option class block (e.g: ::Google::Protobuf::MessageOptions)' + end + if extend_class + # Check if optionable_descriptor_class is already defined and short circuit if so. + # File options are injected per module, and since a module can be defined more than once, + # we will get a warning if we try to define optionable_descriptor_class twice. + if base_class.respond_to?(:optionable_descriptor_class) + if base_class.optionable_descriptor_class != block.call + fail 'A class is being defined with two different descriptor classes, something is very wrong' + else + return # Don't define optionable_descriptor_class twice + end + end + + base_class.extend(ClassMethods) + base_class.__send__(:include, self) + base_class.define_singleton_method(:optionable_descriptor_class, block) + else + base_class.__send__(:include, ClassMethods) + base_class.module_eval { define_method(:optionable_descriptor_class, block) } + end + end end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 017acdb0..46b27423 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,6 +1,5 @@ -require 'active_support/core_ext/class' - require 'protobuf/logging' +require 'protobuf/message' require 'protobuf/rpc/client' require 'protobuf/rpc/error' require 'protobuf/rpc/service_filters' @@ -14,6 +13,7 @@ module Rpc class Service include ::Protobuf::Logging include ::Protobuf::Rpc::ServiceFilters + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::ServiceOptions } DEFAULT_HOST = '127.0.0.1'.freeze DEFAULT_PORT = 9399 diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index b3c2b1ce..5ec3ad06 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -22,8 +22,8 @@ end describe '.aliases_allowed?' do - it 'is nil when the option is not set' do - expect(Test::EnumTestType.aliases_allowed?).to be nil + it 'is false when the option is not set' do + expect(Test::EnumTestType.aliases_allowed?).to be false end end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 84391c4b..b6a7640a 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -56,10 +56,10 @@ require 'protobuf' module Foo + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } end EOF end end - end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index e3428f64..76b35194 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -1,46 +1,169 @@ require 'spec_helper' require 'protobuf/optionable' +require 'protobuf/field/message_field' RSpec.describe 'Optionable' do + describe '.{get,get!}_option' do + before do + stub_const("OptionableGetOptionTest", Class.new(::Protobuf::Message) do + set_option :deprecated, true + set_option :".package.message_field", :field => 33 - describe '.set_option' do - before(:all) do - OptionableSetOptionTest = ::Class.new do - include ::Protobuf::Optionable - end + optional :int32, :field, 1 + end) + end + + it '.get_option retrieves the option as a symbol' do + expect(OptionableGetOptionTest.get_option(:deprecated)).to be(true) + end + + it '.get_option returns the default value for unset options' do + expect(OptionableGetOptionTest.get_option(:message_set_wire_format)).to be(false) + end + + it '.get_option retrieves the option as a string' do + expect(OptionableGetOptionTest.get_option('deprecated')).to be(true) + end + + it '.get_option errors if the option does not exist' do + expect { OptionableGetOptionTest.get_option(:baz) }.to raise_error(ArgumentError) + end + + it '.get_option errors if the option is not accessed by its fully qualified name' do + message_field = ::Protobuf::Field::MessageField.new( + OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, '.message_field', {}) + allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field) + expect { OptionableGetOptionTest.get_option(message_field.name) }.to raise_error(ArgumentError) + end + + it '.get_option can return an option representing a message' do + message_field = ::Protobuf::Field::MessageField.new( + OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, 'message_field', {}) + allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field) + expect(OptionableGetOptionTest.get_option(message_field.fully_qualified_name)).to eq(OptionableGetOptionTest.new(:field => 33)) + end + + it '.get_option! retrieves explicitly an set option' do + expect(OptionableGetOptionTest.get_option!(:deprecated)).to be(true) + end + + it '.get_option! returns nil for unset options' do + expect(OptionableGetOptionTest.get_option!(:message_set_wire_format)).to be(nil) + end + + it '.get_option! errors if the option does not exist' do + expect { OptionableGetOptionTest.get_option(:baz) }.to raise_error(ArgumentError) + end + + it '#get_option retrieves the option as a symbol' do + expect(OptionableGetOptionTest.new.get_option(:deprecated)).to be(true) + end + + it '#get_option returns the default value for unset options' do + expect(OptionableGetOptionTest.new.get_option(:message_set_wire_format)).to be(false) end - it 'stores the given option and value' do - expect(OptionableSetOptionTest).to respond_to(:set_option) - expect(OptionableSetOptionTest.method(:set_option).arity).to eq(-2) - expect do - OptionableSetOptionTest.set_option(:foo, :bar) - end.to_not raise_error + it '#get_option retrieves the option as a string' do + expect(OptionableGetOptionTest.new.get_option('deprecated')).to be(true) end - it 'defaults the value to true' do - OptionableSetOptionTest.set_option(:baz_enabled) - expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be true + it '#get_option errors if the option is not accessed by its fully qualified name' do + message_field = ::Protobuf::Field::MessageField.new( + OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, 'message_field', {}) + allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field) + expect { OptionableGetOptionTest.new.get_option(message_field.name) }.to raise_error(ArgumentError) + end + + it '#get_option can return an option representing a message' do + message_field = ::Protobuf::Field::MessageField.new( + OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, 'message_field', {}) + allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field) + expect(OptionableGetOptionTest.new.get_option(message_field.fully_qualified_name)).to eq(OptionableGetOptionTest.new(:field => 33)) + end + + it '#get_option errors if the option does not exist' do + expect { OptionableGetOptionTest.new.get_option(:baz) }.to raise_error(ArgumentError) + end + + it '#get_option! retrieves explicitly an set option' do + expect(OptionableGetOptionTest.new.get_option!(:deprecated)).to be(true) + end + + it '#get_option! returns nil for unset options' do + expect(OptionableGetOptionTest.new.get_option!(:message_set_wire_format)).to be(nil) + end + + it '#get_option! errors if the option does not exist' do + expect { OptionableGetOptionTest.new.get_option(:baz) }.to raise_error(ArgumentError) end end - describe '.get_option' do - before(:all) do - OptionableGetOptionTest = ::Class.new do - include ::Protobuf::Optionable - set_option :foo, :bar + describe '.inject' do + let(:klass) { Class.new } + + it 'adds klass.{set,get}_option' do + expect { klass.get_option(:deprecated) }.to raise_error(NoMethodError) + expect { klass.__send__(:set_option, :deprecated, true) }.to raise_error(NoMethodError) + ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions } + expect(klass.get_option(:deprecated)).to eq(false) + expect { klass.set_option(:deprecated, true) }.to raise_error(NoMethodError) + klass.__send__(:set_option, :deprecated, true) + expect(klass.get_option(:deprecated)).to eq(true) + end + + it 'adds klass#get_option' do + expect { klass.new.get_option(:deprecated) }.to raise_error(NoMethodError) + ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions } + expect(klass.new.get_option(:deprecated)).to eq(false) + end + + it 'adds klass.optionable_descriptor_class' do + expect { klass.optionable_descriptor_class }.to raise_error(NoMethodError) + ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions } + expect(klass.optionable_descriptor_class).to eq(::Google::Protobuf::MessageOptions) + end + + it 'does not add klass.optionable_descriptor_class twice' do + expect(klass).to receive(:define_singleton_method).once + ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions } + klass.instance_eval do + def optionable_descriptor_class + ::Google::Protobuf::MessageOptions + end end + ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions } end - it 'retrieves the option for the given name, if any' do - expect(OptionableGetOptionTest.get_option(:foo)).to eq(:bar) - expect(OptionableGetOptionTest.get_option(:baz)).to be_nil + it 'throws error when klass.optionable_descriptor_class defined twice with different args' do + ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions } + expect { ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::FileOptions } } + .to raise_error('A class is being defined with two different descriptor classes, something is very wrong') end - it 'retrieves the option in the context of an instance' do - expect(OptionableGetOptionTest.new.get_option(:foo)).to eq(:bar) - expect(OptionableGetOptionTest.new.get_option(:baz)).to be_nil + context 'extend_class = false' do + let(:object) { klass.new } + it 'adds object.{get,set}_option' do + expect { object.get_option(:deprecated) }.to raise_error(NoMethodError) + expect { object.__send__(:set_option, :deprecated, true) }.to raise_error(NoMethodError) + ::Protobuf::Optionable.inject(klass, false) { ::Google::Protobuf::MessageOptions } + expect(object.get_option(:deprecated)).to eq(false) + expect { object.set_option(:deprecated, true) }.to raise_error(NoMethodError) + object.__send__(:set_option, :deprecated, true) + expect(object.get_option(:deprecated)).to eq(true) + end + + it 'does not add klass.{get,set}_option' do + expect { object.get_option(:deprecated) }.to raise_error(NoMethodError) + ::Protobuf::Optionable.inject(klass, false) { ::Google::Protobuf::MessageOptions } + expect { klass.get_option(:deprecated) }.to raise_error(NoMethodError) + expect { klass.__send__(:set_option, :deprecated) }.to raise_error(NoMethodError) + end + + it 'creates an instance method optionable_descriptor_class' do + expect { object.optionable_descriptor_class }.to raise_error(NoMethodError) + ::Protobuf::Optionable.inject(klass, false) { ::Google::Protobuf::MessageOptions } + expect(object.optionable_descriptor_class).to eq(::Google::Protobuf::MessageOptions) + end end end - end diff --git a/spec/support/protos/enum.pb.rb b/spec/support/protos/enum.pb.rb index 74287073..7442ec69 100644 --- a/spec/support/protos/enum.pb.rb +++ b/spec/support/protos/enum.pb.rb @@ -12,6 +12,7 @@ require 'protos/resource.pb' module Test + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Enum Classes diff --git a/spec/support/protos/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb index 5cb59121..a1fe072a 100644 --- a/spec/support/protos/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -13,6 +13,7 @@ require 'protos/google_unittest_import.pb' module Protobuf_unittest + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Enum Classes diff --git a/spec/support/protos/google_unittest_import.pb.rb b/spec/support/protos/google_unittest_import.pb.rb index b0257e7a..cbef3673 100644 --- a/spec/support/protos/google_unittest_import.pb.rb +++ b/spec/support/protos/google_unittest_import.pb.rb @@ -12,6 +12,7 @@ require 'protos/google_unittest_import_public.pb' module Protobuf_unittest_import + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Enum Classes diff --git a/spec/support/protos/google_unittest_import_public.pb.rb b/spec/support/protos/google_unittest_import_public.pb.rb index ab8908c7..7a230268 100644 --- a/spec/support/protos/google_unittest_import_public.pb.rb +++ b/spec/support/protos/google_unittest_import_public.pb.rb @@ -6,6 +6,7 @@ require 'protobuf' module Protobuf_unittest_import + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Message Classes diff --git a/spec/support/protos/multi_field_extensions.pb.rb b/spec/support/protos/multi_field_extensions.pb.rb index 7954323e..5e48581d 100644 --- a/spec/support/protos/multi_field_extensions.pb.rb +++ b/spec/support/protos/multi_field_extensions.pb.rb @@ -6,6 +6,7 @@ require 'protobuf' module Test + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Message Classes diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index 9d43f380..ae90309e 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -7,6 +7,7 @@ require 'protobuf/rpc/service' module Test + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Enum Classes From 7c9411b2e8aef6785191e7ba2d890ed40f218ef2 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Tue, 17 May 2016 22:13:48 -0600 Subject: [PATCH 0991/1191] Update changelog --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b12f5793..2ec23d22 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Stable (3.x) +3.7.0 (pre1) +----------- +- BUG: Revert to old behavior for setting repeated fields to nil +- BUG: Set binmode for protoc-gen-ruby STDIN and STDOUT to compile proto files on Windows +- Make all things Optionable and fix requires + 3.7.0 (pre0) ----------- - Add `PB_USE_RAW_RPC_NAMES` option to preserve raw RPC name (since #underscore can be lossy). From ddac25d7364aba0500be9cfd8679ff7ad5585935 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 11 May 2016 20:31:11 -0600 Subject: [PATCH 0992/1191] Allow user defined service directories Currently, ZMQ assumes that UDP broadcast based service discovery will fit all needs. This change allows a user to create their own service directory and plug it into the ZMQ connector. --- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 8605f488..5bb3079b 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -226,7 +226,7 @@ def service # Alias for ::Protobuf::Rpc::ServiceDirectory.instance def service_directory - ::Protobuf::Rpc::ServiceDirectory.instance + ::Protobuf::Rpc.service_directory end def snd_timeout diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 81696853..272c3e85 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -9,6 +9,14 @@ module Protobuf module Rpc + def self.service_directory + @service_directory ||= ::Protobuf::Rpc::ServiceDirectory.instance + end + + def self.service_directory=(directory) + @service_directory = directory + end + class ServiceDirectory include ::Singleton include ::Protobuf::Logging From 573df7793f4963373d321dc6303e3c5085806d64 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 20 May 2016 12:05:40 -0600 Subject: [PATCH 0993/1191] Bump version to 3.6.8 --- CHANGES.md | 4 ++++ lib/protobuf/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 918fba91..59efd534 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Stable (3.x) +3.6.8 +-------- +- Make protobuf serivce directory pluggable. + 3.5.5 -------- - Add native Varint for MRI. diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index cd372fee..264bfa63 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.7' + VERSION = '3.6.8' end From ebf7d343870021c34b7533cec1bd160829f98f8f Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 20 May 2016 12:07:23 -0600 Subject: [PATCH 0994/1191] bump version to 3.6.9 because 3.6.8 is a yanked version --- CHANGES.md | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 59efd534..42bd416c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Stable (3.x) -3.6.8 +3.6.9 -------- - Make protobuf serivce directory pluggable. diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 264bfa63..7d30e936 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.8' + VERSION = '3.6.9' end From c1fa6bbf9d6dd90044416b1d8ebb20790298b50e Mon Sep 17 00:00:00 2001 From: Embark Date: Tue, 22 Mar 2016 13:01:01 -0700 Subject: [PATCH 0995/1191] Track if a repeated field has been deliberately set Before, if an unset repeated field was ever read, we would make an empty field array for it. As a consequence, .field? and #{field}! methods would indicate that the field had been set, even though it had only been read from. This was a weird side effect of reading an unset repeated field and has been corrected. --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/message.rb | 6 ++++- spec/lib/protobuf/message_spec.rb | 44 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index fab29db8..180209f3 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -176,7 +176,7 @@ def fully_qualified_name_only! def define_accessor(simple_field_name, fully_qualified_field_name) message_class.class_eval do define_method("#{simple_field_name}!") do - @values[fully_qualified_field_name] + @values[fully_qualified_field_name] if field?(fully_qualified_field_name) end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 32d8b0e4..a0d4234a 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -94,7 +94,11 @@ def each_field_for_serialization def field?(name) field = self.class.get_field(name, true) return false if field.nil? - @values.key?(field.fully_qualified_name) + if field.repeated? + @values.key?(field.fully_qualified_name) && @values[field.fully_qualified_name].present? + else + @values.key?(field.fully_qualified_name) + end end ::Protobuf.deprecator.define_deprecated_methods(self, :has_field? => :field?) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index ed8ac001..e76fa269 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -476,6 +476,25 @@ message = ::Test::Resource.new(:ext_is_searchable => false) expect(message.ext_is_searchable!).to be(false) end + + it 'returns nil for an unset repeated field that has only be read' do + message = ::Test::Resource.new + expect(message.repeated_enum!).to be_nil + message.repeated_enum + expect(message.repeated_enum!).to be_nil + end + + it 'returns value for an unset repeated field has been read and appended to' do + message = ::Test::Resource.new + message.repeated_enum << 1 + expect(message.repeated_enum!).to eq([1]) + end + + it 'returns value for an unset repeated field has been explicitly set' do + message = ::Test::Resource.new + message.repeated_enum = [1] + expect(message.repeated_enum!).to eq([1]) + end end end @@ -562,6 +581,31 @@ message = ::Test::Resource.new(ext_field => false) expect(message.field?(100)).to be(true) end + + it 'returns false for repeated field that has been read from' do + message = ::Test::Resource.new + expect(message.field?(:repeated_enum)).to be(false) + message.repeated_enum + expect(message.field?(:repeated_enum)).to be(false) + end + + it 'returns true for a repeated field that has been read from and appended to' do + message = ::Test::Resource.new + message.repeated_enum << 1 + expect(message.field?(:repeated_enum)).to be(true) + end + + it 'returns true for a repeated field that has been set with the setter' do + message = ::Test::Resource.new + message.repeated_enum = [1] + expect(message.field?(:repeated_enum)).to be(true) + end + + it 'returns false for a repeated field that has been replaced with []' do + message = ::Test::Resource.new + message.repeated_enum.replace([]) + expect(message.field?(:repeated_enum)).to be(false) + end end describe '.get_field' do From afc02fccc3985968d051ad884de31927ee1737f1 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 20 Jun 2016 07:19:05 -0600 Subject: [PATCH 0996/1191] Update changelog for 3.7.0 pre2 --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5d1fb8e2..44cfae2e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Stable (3.x) +3.7.0 (pre2) +----------- +- BUG: Track if a repeated field has been deliberately set (#325) + 3.7.0 (pre1) ----------- - BUG: Revert to old behavior for setting repeated fields to nil From 59f5bda6a6778c7513faf2642e6d4863b9ba522c Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 15 Jul 2016 12:17:09 -0600 Subject: [PATCH 0997/1191] Change the ping port to use ms timeout and make the default 200ms --- lib/protobuf/rpc/connectors/ping.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/ping_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/ping.rb b/lib/protobuf/rpc/connectors/ping.rb index 66456bd3..93c75868 100644 --- a/lib/protobuf/rpc/connectors/ping.rb +++ b/lib/protobuf/rpc/connectors/ping.rb @@ -29,9 +29,9 @@ def online? def timeout @timeout ||= begin if ::ENV.key?("PB_RPC_PING_PORT_TIMEOUT") - ::ENV["PB_RPC_PING_PORT_TIMEOUT"].to_i + ::ENV["PB_RPC_PING_PORT_TIMEOUT"].to_f / 1000 else - 5 # 5 seconds + 0.2 # 200 ms end end end diff --git a/spec/lib/protobuf/rpc/connectors/ping_spec.rb b/spec/lib/protobuf/rpc/connectors/ping_spec.rb index 0f0473b3..35931f61 100644 --- a/spec/lib/protobuf/rpc/connectors/ping_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/ping_spec.rb @@ -55,14 +55,14 @@ describe "#timeout" do it "uses the default value" do - expect(subject.timeout).to eq(5) + expect(subject.timeout).to eq(0.2) end context "when environment variable is set" do - before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "1" } + before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "100" } it "uses the environmet variable" do - expect(subject.timeout).to eq(1) + expect(subject.timeout).to eq(0.1) end end end From 5c5409c1d2c1a564614737dde3345fbdc5349e59 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 15 Jul 2016 12:17:09 -0600 Subject: [PATCH 0998/1191] Change the ping port to use ms timeout and make the default 200ms --- lib/protobuf/rpc/connectors/ping.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/ping_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/ping.rb b/lib/protobuf/rpc/connectors/ping.rb index 66456bd3..93c75868 100644 --- a/lib/protobuf/rpc/connectors/ping.rb +++ b/lib/protobuf/rpc/connectors/ping.rb @@ -29,9 +29,9 @@ def online? def timeout @timeout ||= begin if ::ENV.key?("PB_RPC_PING_PORT_TIMEOUT") - ::ENV["PB_RPC_PING_PORT_TIMEOUT"].to_i + ::ENV["PB_RPC_PING_PORT_TIMEOUT"].to_f / 1000 else - 5 # 5 seconds + 0.2 # 200 ms end end end diff --git a/spec/lib/protobuf/rpc/connectors/ping_spec.rb b/spec/lib/protobuf/rpc/connectors/ping_spec.rb index 0f0473b3..35931f61 100644 --- a/spec/lib/protobuf/rpc/connectors/ping_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/ping_spec.rb @@ -55,14 +55,14 @@ describe "#timeout" do it "uses the default value" do - expect(subject.timeout).to eq(5) + expect(subject.timeout).to eq(0.2) end context "when environment variable is set" do - before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "1" } + before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "100" } it "uses the environmet variable" do - expect(subject.timeout).to eq(1) + expect(subject.timeout).to eq(0.1) end end end From 91bddc4be8f1e44cfea18e3e0cc8dd4254a295ec Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 15 Jul 2016 12:26:43 -0600 Subject: [PATCH 0999/1191] Bump version to 3.6.10 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 7d30e936..dc8c8290 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.9' + VERSION = '3.6.10' end From 67c35a251958e094bf473b6f68dc3ed81736261e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 14 Aug 2016 22:26:59 -0600 Subject: [PATCH 1000/1191] remove double serialize and some extra blocks that wrapped calls --- lib/protobuf/rpc/connectors/common.rb | 2 +- .../rpc/middleware/request_decoder.rb | 23 ++++------- .../rpc/middleware/response_encoder.rb | 30 +++++---------- lib/protobuf/rpc/service.rb | 12 +----- lib/protobuf/rpc/service_dispatcher.rb | 8 ++-- lib/protobuf/rpc/service_filters.rb | 38 ++++--------------- .../protobuf/rpc/service_dispatcher_spec.rb | 4 +- 7 files changed, 33 insertions(+), 84 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index c0fc26bd..84222429 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -119,7 +119,7 @@ def request_bytes def setup_connection initialize_stats @request_data = request_bytes - @stats.request_size = request_bytes.size + @stats.request_size = @request_data.size end def succeed(response) diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 111d0c0d..78a1dee0 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -13,6 +13,7 @@ def initialize(app) def call(env) @env = env + logger.debug { sign_message("Decoding request: #{env.encoded_request}") } env.service_name = service_name env.method_name = method_name env.request = request @@ -33,22 +34,15 @@ def log_signature private def method_name - @method_name ||= begin - method_name = request_wrapper.method_name.underscore.to_sym + return @method_name unless @method_name.nil? - unless service.rpc_method?(method_name) - fail MethodNotFound, "#{service.name}##{method_name} is not a defined RPC method." - end - - method_name - end + @method_name = request_wrapper.method_name.underscore.to_sym + fail MethodNotFound, "#{service.name}##{@method_name} is not a defined RPC method." unless service.rpc_method?(@method_name) + @method_name end def request - @request ||= begin - data = request_wrapper.request_proto - rpc_method.request_type.decode(data) - end + @request ||= rpc_method.request_type.decode(request_wrapper.request_proto) rescue => exception raise BadRequestData, "Unable to decode request: #{exception.message}" end @@ -56,10 +50,7 @@ def request # Decode the incoming request object into our expected request object # def request_wrapper - @request_wrapper ||= begin - logger.debug { sign_message("Decoding request: #{env.encoded_request}") } - Socketrpc::Request.decode(env.encoded_request) - end + @request_wrapper ||= Socketrpc::Request.decode(env.encoded_request) rescue => exception raise BadRequestData, "Unable to decode request: #{exception.message}" end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index d303a9b2..e3f4eb04 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -41,32 +41,22 @@ def encoded_response # Prod the object to see if we can produce a proto object as a response # candidate. Validate the candidate protos. def response - @response ||= begin - candidate = env.response - case - when candidate.is_a?(Message) then - validate!(candidate) - when candidate.respond_to?(:to_proto) then - validate!(candidate.to_proto) - when candidate.respond_to?(:to_hash) then - env.response_type.new(candidate.to_hash) - when candidate.is_a?(PbError) then - candidate - else - validate!(candidate) - end - end + return @response unless @response.nil? + + candidate = env.response + return @response = validate!(candidate) if candidate.is_a?(Message) + return @response = validate!(candidate.to_proto) if candidate.respond_to?(:to_proto) + return @response = env.response_type.new(candidate.to_hash) if candidate.respond_to?(:to_hash) + return @response = candidate if candidate.is_a?(PbError) + return @response = validate!(candidate) end # Ensure that the response candidate we've been given is of the type # we expect so that deserialization on the client side works. # def validate!(candidate) - actual = candidate.class - expected = env.response_type - - if expected != actual - fail BadResponseProto, "Expected response to be of type #{expected.name} but was #{actual.name}" + if candidate.class != env.response_type + fail BadResponseProto, "Expected response to be of type #{env.response_type.name} but was #{candidate.class.name}" end candidate diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 017acdb0..9d46cbdc 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -119,16 +119,8 @@ def self.rpc_method?(name) rpcs.key?(name) end - ## - # Instance Methods - # - # Get a callable object that will be used by the dispatcher - # to invoke the specified rpc method. Facilitates callback dispatch. - # The returned lambda is expected to be called at a later time (which - # is why we wrap the method call). - # - def callable_rpc_method(method_name) - -> { run_filters(method_name) } + def call(method_name) + run_filters(method_name) end # Response object for this rpc cycle. Not assignable. diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 6e00523e..927be125 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -26,12 +26,10 @@ def rpc_service # Call the given service method. def dispatch_rpc_request - unless rpc_service.respond_to?(method_name) - fail MethodNotFound, "#{service_name}##{method_name} is not a publicly defined method." - end - - rpc_service.callable_rpc_method(method_name).call + rpc_service.call(method_name) rpc_service.response + rescue NoMethodError + fail MethodNotFound, "#{service_name}##{method_name} is not a defined RPC method." end def method_name diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 19593eae..482a15e7 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -120,15 +120,9 @@ def invoke_via_except?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_if?(_rpc_method, filter) - if_check = filter.fetch(:if) { ->(_service) { return true } } - do_invoke = case - when if_check.nil? - true - else - call_or_send(if_check) - end - - do_invoke + if_check = filter.fetch(:if, nil) + return true if if_check.nil? + call_or_send(if_check) end # If the target rpc endpoint method is listed in the :only option, @@ -150,15 +144,9 @@ def invoke_via_only?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_unless?(_rpc_method, filter) - unless_check = filter.fetch(:unless) { ->(_service) { return false } } - skip_invoke = case - when unless_check.nil? - false - else - call_or_send(unless_check) - end - - !skip_invoke + unless_check = filter.fetch(:unless, nil) + return true if unless_check.nil? + !call_or_send(unless_check) end def rescue_filters @@ -253,20 +241,10 @@ def run_rescue_filters # __send__ assuming that we respond_to it. Return the call's return value. # def call_or_send(callable, *args, &block) - return_value = case - when callable.respond_to?(:call) - callable.call(self, *args, &block) - when respond_to?(callable, true) - __send__(callable, *args, &block) - else - fail "Object #{callable} is not callable" - end - - return_value + return callable.call(self, *args, &block) if callable.respond_to?(:call) + return __send__(callable, *args, &block) end - end - end end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 5bf27318..d6a03b6e 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -42,10 +42,10 @@ end context "when the given RPC method is implemented and a NoMethodError is raised" do - before { allow(rpc_service).to receive(:callable_rpc_method).and_return(-> { rpc_service.__send__(:foo) }) } + before { allow(rpc_service).to receive(:call).and_raise(NoMethodError) } it "raises the exeception" do - expect { subject.call(env) }.to raise_exception(NoMethodError) + expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) end end end From 6646d3046b9631343bab96b9af99b3c965b23c71 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 14 Aug 2016 23:03:37 -0600 Subject: [PATCH 1001/1191] make sure use of middlewares is threadsafe --- lib/protobuf/rpc/middleware/exception_handler.rb | 4 ++++ lib/protobuf/rpc/middleware/logger.rb | 4 ++++ lib/protobuf/rpc/middleware/request_decoder.rb | 4 ++++ lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++++ lib/protobuf/rpc/service_dispatcher.rb | 4 ++++ spec/lib/protobuf/rpc/service_dispatcher_spec.rb | 2 +- 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index 4f3757a6..9592c049 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -11,6 +11,10 @@ def initialize(app) end def call(env) + dup._call(env) + end + + def _call(env) app.call(env) rescue => exception log_exception(exception) diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index a5d30e36..2c02b9a4 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -8,6 +8,10 @@ def initialize(app) # TODO: Figure out how to control when logs are flushed def call(env) + dup._call(env) + end + + def _call(env) instrumenter.start instrumenter.flush(env) # Log request stats diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 78a1dee0..eebaf931 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -11,6 +11,10 @@ def initialize(app) end def call(env) + dup._call(env) + end + + def _call(env) @env = env logger.debug { sign_message("Decoding request: #{env.encoded_request}") } diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index e3f4eb04..c5a508e6 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -11,6 +11,10 @@ def initialize(app) end def call(env) + dup._call(env) + end + + def _call(env) @env = app.call(env) env.response = response diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 927be125..58d3e30b 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -12,6 +12,10 @@ def initialize(_app) end def call(env) + dup._call(env) + end + + def _call(env) @env = env env.response = dispatch_rpc_request diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index d6a03b6e..7170b344 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -29,7 +29,7 @@ before { allow(rpc_service).to receive(:response).and_return(response) } it "dispatches the request" do - stack_env = subject.call(env) + stack_env = subject._call(env) expect(stack_env.response).to eq response end From e02f561b290349f5f2cabc0436d7f766c2657ff4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Aug 2016 12:18:51 -0600 Subject: [PATCH 1002/1191] update for the cops --- lib/protobuf/rpc/middleware/response_encoder.rb | 3 ++- lib/protobuf/rpc/service_dispatcher.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index c5a508e6..45f21aea 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -52,7 +52,8 @@ def response return @response = validate!(candidate.to_proto) if candidate.respond_to?(:to_proto) return @response = env.response_type.new(candidate.to_hash) if candidate.respond_to?(:to_hash) return @response = candidate if candidate.is_a?(PbError) - return @response = validate!(candidate) + + @response = validate!(candidate) end # Ensure that the response candidate we've been given is of the type diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 58d3e30b..f74f1b20 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -33,7 +33,7 @@ def dispatch_rpc_request rpc_service.call(method_name) rpc_service.response rescue NoMethodError - fail MethodNotFound, "#{service_name}##{method_name} is not a defined RPC method." + raise MethodNotFound, "#{service_name}##{method_name} is not a defined RPC method." end def method_name diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 482a15e7..c461512d 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -242,7 +242,7 @@ def run_rescue_filters # def call_or_send(callable, *args, &block) return callable.call(self, *args, &block) if callable.respond_to?(:call) - return __send__(callable, *args, &block) + __send__(callable, *args, &block) end end end From 9068de95f221bd5f97a7092a31e07326b62ee693 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 15 Aug 2016 15:07:35 -0400 Subject: [PATCH 1003/1191] Bump version to 3.6.11 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index dc8c8290..96b4ffdb 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.10' + VERSION = '3.6.11' end From 6425ecbbf9fdc519121efb5550d4e04b57fcfb7a Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 17 Aug 2016 07:59:55 -0600 Subject: [PATCH 1004/1191] Remove superfluous rescue from service dispatcher Likely a relic of pre-middleware days, the service dispatcher was rescuing all NoMethodError exceptions and re-raising it's own MethodNotFound exception. The request decoder middleware now handles this case, and it was way too broad, so it has been removed. --- lib/protobuf/rpc/service_dispatcher.rb | 3 --- .../lib/protobuf/rpc/service_dispatcher_spec.rb | 17 ----------------- 2 files changed, 20 deletions(-) diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index f74f1b20..8144b41d 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -28,12 +28,9 @@ def rpc_service private - # Call the given service method. def dispatch_rpc_request rpc_service.call(method_name) rpc_service.response - rescue NoMethodError - raise MethodNotFound, "#{service_name}##{method_name} is not a defined RPC method." end def method_name diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 7170b344..4e11f24b 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -16,7 +16,6 @@ let(:request_type) { service_class.rpcs[method_name].request_type } let(:response) { response_type.new(:name => 'required') } let(:response_type) { service_class.rpcs[method_name].response_type } - let(:rpc_service) { service_class.new(env) } let(:service_class) { Test::ResourceService } let(:service_name) { service_class.to_s } @@ -32,21 +31,5 @@ stack_env = subject._call(env) expect(stack_env.response).to eq response end - - context "when the given RPC method is not implemented" do - let(:method_name) { :find_not_implemented } - - it "raises a method not found exception" do - expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) - end - end - - context "when the given RPC method is implemented and a NoMethodError is raised" do - before { allow(rpc_service).to receive(:call).and_raise(NoMethodError) } - - it "raises the exeception" do - expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) - end - end end end From 8e277002e92b68b6debdb75fc49edb27d311c79b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 17 Aug 2016 08:39:05 -0600 Subject: [PATCH 1005/1191] bump to 3.6.12 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 96b4ffdb..ba3f909b 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.11' + VERSION = '3.6.12' end From cfe1461d63149f7cc31b804d88356335e9a423ee Mon Sep 17 00:00:00 2001 From: Embark Date: Mon, 21 Nov 2016 14:38:33 -0800 Subject: [PATCH 1006/1191] Fix build failures caused by Rails 5 requirement of Ruby 2.2.2 --- .travis.yml | 1 + protobuf.gemspec | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0f1c54b4..156f4dea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ rvm: - 2.0.0 - 2.1 - 2.2 + - 2.2.2 - jruby - rbx-2 env: diff --git a/protobuf.gemspec b/protobuf.gemspec index ad9076a3..38602c4f 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -19,7 +19,9 @@ require "protobuf/version" s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'activesupport', '>= 3.2' + # Hack, as Rails 5 requires Ruby version >= 2.2.2. + active_support_max_version = "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2") + s.add_dependency "activesupport", '>= 3.2', active_support_max_version s.add_dependency 'middleware' s.add_dependency 'thor' s.add_dependency 'thread_safe' From 51f21014ca5a78af0017702c45e95a0e4ba9125e Mon Sep 17 00:00:00 2001 From: Embark Date: Tue, 22 Nov 2016 09:07:07 -0800 Subject: [PATCH 1007/1191] Catch up Travis builds to Ruby 2.3 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 156f4dea..4ae400be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ rvm: - 2.1 - 2.2 - 2.2.2 + - 2.3 - jruby - rbx-2 env: From 7f75f45a7b1d7528a115ef345249409640053f5b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 29 Jan 2017 14:39:23 -0700 Subject: [PATCH 1008/1191] newly compiled classes --- .../descriptors/google/protobuf/compiler/plugin.pb.rb | 3 ++- lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb | 4 +++- lib/protobuf/rpc/dynamic_discovery.pb.rb | 3 ++- lib/protobuf/rpc/rpc.pb.rb | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb index 4d3f72bb..91cfe185 100644 --- a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -3,7 +3,7 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' ## @@ -14,6 +14,7 @@ module Google module Protobuf module Compiler + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Message Classes diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index 6395a14d..379e9493 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -3,10 +3,11 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' module Google module Protobuf + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Message Classes @@ -149,6 +150,7 @@ class FieldDescriptorProto optional :string, :extendee, 2 optional :string, :default_value, 7 optional :int32, :oneof_index, 9 + optional :string, :json_name, 10 optional ::Google::Protobuf::FieldOptions, :options, 8 end diff --git a/lib/protobuf/rpc/dynamic_discovery.pb.rb b/lib/protobuf/rpc/dynamic_discovery.pb.rb index 2070b475..b8dd5869 100644 --- a/lib/protobuf/rpc/dynamic_discovery.pb.rb +++ b/lib/protobuf/rpc/dynamic_discovery.pb.rb @@ -3,11 +3,12 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' module Protobuf module Rpc module DynamicDiscovery + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Enum Classes diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index d302de54..900f1324 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -3,10 +3,11 @@ ## # This file is auto-generated. DO NOT EDIT! # -require 'protobuf/message' +require 'protobuf' module Protobuf module Socketrpc + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } ## # Enum Classes From c26d071bbf894ae4ed559e1c69a963da42ada6dd Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 30 Jan 2017 08:30:27 -0700 Subject: [PATCH 1009/1191] load extension server if configured --- lib/protobuf/cli.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 31da71b4..2d768a13 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/hash/keys' +require 'active_support/inflector' require 'thor' require 'protobuf/version' @@ -114,6 +115,7 @@ def configure_process_name(app_file) # Configure the mode of the server and the runner class. def configure_runner_mode debug_say('Configuring runner mode') + server_type = ENV["PB_SERVER_TYPE"] self.mode = if multi_mode? say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) @@ -121,14 +123,19 @@ def configure_runner_mode elsif options.zmq? :zmq else - case server_type = ENV["PB_SERVER_TYPE"] + case server_type when nil, /socket/i :socket when /zmq/i :zmq else - say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow - :socket + begin + require "#{server_type}" + server_type + rescue LoadError + say "WARNING: Could not load 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow + :socket + end end end end @@ -160,7 +167,8 @@ def create_runner when :socket create_socket_runner else - say_and_exit("Unknown runner mode: #{mode}") + say("Extension runner mode: #{mode}") + create_extension_server_runner end end @@ -206,6 +214,13 @@ def say_and_exit(message, exception = nil) exit(1) end + def create_extension_server_runner + classified = self.mode.classify + extension_server_class = classified.constantize + + self.runner = extension_server_class.new(runner_options) + end + def create_socket_runner require 'protobuf/socket' From d6e647facc0b4fe03df7cd084b185b6bee3cd959 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 30 Jan 2017 13:20:37 -0700 Subject: [PATCH 1010/1191] update connectors to allow an extension connector to be loaded --- lib/protobuf.rb | 32 ++++++++++++++++++++++++-------- lib/protobuf/rpc/client.rb | 2 +- lib/protobuf/rpc/connector.rb | 10 ---------- spec/benchmark/tasks.rb | 1 + 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index efceecb9..3c724412 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -60,10 +60,17 @@ def self.connector_type end def self.connector_type=(type) - fail ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) @connector_type = type end + def self.connector_type_class + @connector_type_class ||= ::Protobuf::Rpc::Connectors::Socket + end + + def self.connector_type_class=(type_class) + @connector_type_class = type_class + end + # GC Pause during server requests # # Default: false @@ -102,16 +109,25 @@ def self.ignore_unknown_fields=(value) env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') do ::Protobuf::DEFAULT_CONNECTOR - end.to_s.downcase.strip.to_sym - - if ::Protobuf::CONNECTORS.include?(env_connector_type) - require "protobuf/#{env_connector_type}" + end + + symbolized_connector_type = env_connector_type.to_s.downcase.strip.to_sym + if ::Protobuf::CONNECTORS.include?(symbolized_connector_type) + require "protobuf/#{symbolized_connector_type}" + + case symbolized_connector_type + when :zmq + ::Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Zmq + else + ::Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Socket + end else $stderr.puts <<-WARN - [WARNING] Require attempted on an invalid connector type '#{env_connector_type}'. - Falling back to default '#{::Protobuf::DEFAULT_CONNECTOR}' connector. + [INFO] Attempting require on an extension connector type '#{env_connector_type}'. WARN - require "protobuf/#{::Protobuf::DEFAULT_CONNECTOR}" + require "#{env_connector_type}" + classified = env_connector_type.classify + ::Protobuf.connector_type_class = classified.constantize end end diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 618aa503..2732b696 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -28,7 +28,7 @@ class Client # def initialize(options = {}) fail "Invalid client configuration. Service must be defined." if options[:service].nil? - @connector = Connector.connector_for_client.new(options) + @connector = ::Protobuf.connector_type_class.new(options) logger.debug { sign_message("Initialized with options: #{options.inspect}") } end diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb index b3f15453..8f1d6912 100644 --- a/lib/protobuf/rpc/connector.rb +++ b/lib/protobuf/rpc/connector.rb @@ -4,16 +4,6 @@ module Protobuf module Rpc class Connector - # Returns a connector class for the pre-defined connector_type. - def self.connector_for_client - case ::Protobuf.connector_type - when :zmq then - ::Protobuf::Rpc::Connectors::Zmq - else - ::Protobuf::Rpc::Connectors::Socket - end - end - end end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 631439d6..5d7f93a3 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,4 +1,5 @@ require 'benchmark' +require 'protobuf' require 'protobuf/socket' require 'support/all' require 'spec_helper' From e7e1dfa5299d81cd1ff383766c926856fe8f7382 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 30 Jan 2017 13:30:15 -0700 Subject: [PATCH 1011/1191] update rubocop, will probably have to refactor later --- .rubocop.yml | 2 +- protobuf.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1ed3b0d4..d8e7f963 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,7 +56,7 @@ Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' -Style/TrailingComma: +Style/TrailingCommaInLiteral: EnforcedStyleForMultiline: comma Style/TrivialAccessors: diff --git a/protobuf.gemspec b/protobuf.gemspec index 38602c4f..961783b3 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -29,7 +29,7 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' - s.add_development_dependency "rubocop", "~> 0.35.0" + s.add_development_dependency "rubocop" s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984 s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' From 0ab3886b93ca7b1075010a695376065917829835 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 30 Jan 2017 17:16:17 -0700 Subject: [PATCH 1012/1191] remove connector specs that are not used with new connector setup --- spec/lib/protobuf/rpc/connector_spec.rb | 19 ------------------- spec/lib/protobuf_spec.rb | 10 ++++------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index 1d433b49..6b46c0ce 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -4,23 +4,4 @@ RSpec.describe ::Protobuf::Rpc::Connector do - describe '.connector_for_client(true)' do - subject { described_class.connector_for_client } - - context 'Protobuf.connector_type is socket' do - before { ::Protobuf.connector_type = :socket } - specify { expect(subject).to eq ::Protobuf::Rpc::Connectors::Socket } - end - - context 'Protobuf.connector_type is not a known value' do - before { allow(::Protobuf).to receive(:connector_type).and_return(:foo) } - specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Socket) } - end - - context 'Protobuf.connector_type is zmq' do - before { ::Protobuf.connector_type = :zmq } - specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Zmq) } - end - end - end diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index a330d9e5..77f48e6f 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -32,13 +32,11 @@ expect(described_class.connector_type).to eq type end end + end - it 'does not accept other types' do - [:hello, :world, :evented].each do |type| - expect do - described_class.connector_type = type - end.to raise_error(ArgumentError) - end + describe '.connector_type_class' do + it "defaults to Socket" do + expect(described_class.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Socket) end end From d9d6591a88df6569fcfd7906a6dffee988c2413d Mon Sep 17 00:00:00 2001 From: Embark Date: Mon, 4 Apr 2016 14:25:00 -0700 Subject: [PATCH 1013/1191] Evaluate extension fields in code generation This will allow us to access descriptor extensions during code generation in order to define custom options. --- .rubocop.yml | 5 +- bin/protoc-gen-ruby | 4 +- lib/protobuf/code_generator.rb | 8 ++ lib/protobuf/generators/file_generator.rb | 128 +++++++++++++++++++-- lib/protobuf/generators/group_generator.rb | 3 +- spec/lib/protobuf/code_generator_spec.rb | 28 +++++ 6 files changed, 162 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1ed3b0d4..b0906fdb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,9 +56,12 @@ Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' -Style/TrailingComma: +Style/TrailingCommaInLiteral: EnforcedStyleForMultiline: comma +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: no_comma + Style/TrivialAccessors: AllowDSLWriters: true AllowPredicates: true diff --git a/bin/protoc-gen-ruby b/bin/protoc-gen-ruby index fe055720..a84b1c1c 100755 --- a/bin/protoc-gen-ruby +++ b/bin/protoc-gen-ruby @@ -18,5 +18,5 @@ STDOUT.binmode request_bytes = STDIN.read code_generator = ::Protobuf::CodeGenerator.new(request_bytes) -response_bytes = code_generator.response_bytes -STDOUT.print(response_bytes) +code_generator.eval_unknown_extensions! +STDOUT.print(code_generator.response_bytes) diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 3ab75b72..70ec1303 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -25,9 +25,17 @@ def self.warn(message) public def initialize(request_bytes) + @request_bytes = request_bytes self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes) end + def eval_unknown_extensions! + request.proto_file.each do |file_descriptor| + ::Protobuf::Generators::FileGenerator.new(file_descriptor).eval_unknown_extensions! + end + self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(@request_bytes) + end + def generate_file(file_descriptor) ::Protobuf::Generators::FileGenerator.new(file_descriptor).generate_output_file end diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 561a5d33..f181ad5f 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -12,7 +12,8 @@ def initialize(*args) super @output_file = ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => file_name) @extension_fields = Hash.new { |h, k| h[k] = [] } - @known_messages = [] + @known_messages = {} + @known_enums = {} @dangling_messages = {} end @@ -49,8 +50,16 @@ def compile end def unknown_extensions - @unknown_extensions ||= @extension_fields.reject do |k, _| - @known_messages.include?(k) + @unknown_extensions ||= @extension_fields.map do |message_name, fields| + message_klass = modulize(message_name).safe_constantize + if message_klass + unknown_fields = fields.reject do |field| + @known_messages[message_name] && message_klass.get_field(field.name, true) + end + [message_name, unknown_fields] + else + [message_name, fields] + end end end @@ -72,12 +81,10 @@ def map_extensions(descriptor, namespaces) end # Record all the message descriptor name's we encounter (should be the whole tree). if descriptor.is_a?(::Google::Protobuf::DescriptorProto) - if fully_qualified_token?(descriptor.name) - @known_messages << descriptor.name - else - fully_qualified_namespace = ".#{namespaces.join('.')}" - @known_messages << fully_qualified_namespace - end + @known_messages[fully_qualified_namespace || descriptor.name] = descriptor + elsif descriptor.is_a?(::Google::Protobuf::EnumDescriptorProto) + @known_enums[fully_qualified_namespace || descriptor.name] = descriptor + return end descriptor.extension.each do |field_descriptor| @@ -87,7 +94,7 @@ def map_extensions(descriptor, namespaces) @extension_fields[field_descriptor.extendee] << field_descriptor end - [:message_type, :nested_type].each do |type| + [:message_type, :nested_type, :enum_type].each do |type| next unless descriptor.respond_to_has_and_present?(type) descriptor.public_send(type).each do |type_descriptor| @@ -132,6 +139,38 @@ def print_package(&block) end.call end + def eval_unknown_extensions! + @evaled_dependencies ||= Set.new + @all_messages ||= {} + @all_enums ||= {} + + map_extensions(descriptor, [descriptor.package]) + @known_messages.each do |name, descriptor| + @all_messages[name] = descriptor + end + @known_enums.each do |name, descriptor| + @all_enums[name] = descriptor + end + + # create package namespace + print_package {} + eval_code + + unknown_extensions.each do |extendee, fields| + eval_dependencies(extendee) + fields.each do |field| + eval_dependencies(field.type_name) + end + end + group = GroupGenerator.new(0) + group.add_extended_messages(unknown_extensions, false) + print group.to_s + eval_code + rescue => e + warn "Error loading unknown extensions #{descriptor.name.inspect} error=#{e}" + raise e + end + private def convert_filename(filename, for_require = true) @@ -142,6 +181,75 @@ def fully_qualified_token?(token) token[0] == '.' end + def eval_dependencies(name, namespace = nil) + name = "#{namespace}.#{name}" if namespace && !fully_qualified_token?(name) + return if name.empty? || @evaled_dependencies.include?(name) || modulize(name).safe_constantize + + # if name = .foo.bar.Baz look for classes / modules named ::Foo::Bar and ::Foo + # module == pure namespace (e.g. the descriptor package name) + # class == nested messages + create_ruby_namespace_heiarchy(name) + + if (message = @all_messages[name]) + # Create the blank namespace in case there are nested types + eval_message_code(name) + + message.nested_type.each do |nested_type| + eval_dependencies(nested_type.name, name) unless nested_type.name.empty? + end + message.field.each do |field| + eval_dependencies(field.type_name, name) unless field.type_name.empty? + end + message.enum_type.each do |enum_type| + eval_dependencies(enum_type.name, name) + end + + # Check @evaled_dependencies again in case there was a dependency + # loop that already loaded this message + return if @evaled_dependencies.include?(name) + eval_message_code(name, message.field) + @evaled_dependencies << name + + elsif (enum = @all_enums[name]) + # Check @evaled_dependencies again in case there was a dependency + # loop that already loaded this enum + return if @evaled_dependencies.include?(name) + namespace = name.split(".") + eval_enum_code(enum, namespace[0..-2].join(".")) + @evaled_dependencies << name + else + raise "Error loading unknown dependencies, could not find message or enum #{name.inspect}" + end + end + + def eval_message_code(fully_qualified_namespace, fields = []) + group = GroupGenerator.new(0) + group.add_extended_messages({ fully_qualified_namespace => fields }, false) + print group.to_s + eval_code + end + + def eval_enum_code(enum, fully_qualified_namespace) + group = GroupGenerator.new(0) + group.add_enums([enum], :namespace => [fully_qualified_namespace]) + print group.to_s + eval_code(modulize(fully_qualified_namespace).safe_constantize || Object) + end + + def eval_code(context = Object) + warn "#{context.inspect}.module_eval #{print_contents.inspect}" if ENV['PB_DEBUG'] + context.module_eval print_contents.to_s + @io.truncate(0) + @io.rewind + end + + def create_ruby_namespace_heiarchy(name) + i = name.size + while (i = name[0...i].rindex(".")) && i > 0 + eval_dependencies(name[0...i]) + end + end + def inject_optionable return if descriptor.package.empty? && !ENV.key?('PB_ALLOW_DEFAULT_PACKAGE_NAME') puts "::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }" diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index 67eeb688..1578176a 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -32,8 +32,9 @@ def add_comment(type, message) @comments[type] = message end - def add_extended_messages(extended_messages) + def add_extended_messages(extended_messages, skip_empty_fields = true) extended_messages.each do |message_type, field_descriptors| + next if skip_empty_fields && field_descriptors.empty? @groups[:extended_message] << ExtensionGenerator.new(message_type, field_descriptors, indent_level) end end diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 33038006..230029c0 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -37,6 +37,34 @@ end end + describe '#eval_unknown_extensions' do + let(:input_file) do + DESCRIPTOR::FileDescriptorProto.new( + :name => 'test/boom.proto', + :package => 'test.pkg.code_generator_spec', + :extension => [{ + :name => 'boom', + :number => 20100, + :label => Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL, + :type => Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING, + :extendee => '.google.protobuf.FieldOptions', + }], + ) + end + let(:request_bytes) { COMPILER::CodeGeneratorRequest.encode(:proto_file => [input_file]) } + + it 'evals files as they are generated' do + described_class.new(request_bytes).eval_unknown_extensions! + expect(Google::Protobuf::FieldOptions.extension_fields.map(&:fully_qualified_name)).to include(:'.test.pkg.code_generator_spec.boom') + expect(Google::Protobuf::FieldOptions.extension_fields.map(&:name)).to include(:boom) + added_extension = Google::Protobuf::FieldOptions.extension_fields.detect { |f| f.fully_qualified_name == :'.test.pkg.code_generator_spec.boom' } + expect(added_extension.name).to eq(:boom) + expect(added_extension.rule).to eq(:optional) + expect(added_extension.type_class).to eq(::Protobuf::Field::StringField) + expect(added_extension.tag).to eq(20100) + end + end + context 'class-level printing methods' do describe '.fatal' do it 'raises a CodeGeneratorFatalError error' do From 0e61e7b28e945bb98900a0447fd61df129be3022 Mon Sep 17 00:00:00 2001 From: Embark Date: Thu, 21 Jul 2016 20:14:16 -0700 Subject: [PATCH 1014/1191] Improve readability of namespace hierarchy code --- lib/protobuf/generators/file_generator.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index f181ad5f..e75d1b2e 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -243,10 +243,11 @@ def eval_code(context = Object) @io.rewind end - def create_ruby_namespace_heiarchy(name) - i = name.size - while (i = name[0...i].rindex(".")) && i > 0 - eval_dependencies(name[0...i]) + def create_ruby_namespace_heiarchy(namespace) + loop do + namespace, _match, _tail = namespace.rpartition(".") + break if namespace.empty? + eval_dependencies(namespace) end end From 1e69aace3c30ff27d083101bb196b57c4108343e Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 1 Feb 2017 13:47:51 -0800 Subject: [PATCH 1015/1191] Fix undefined method 'last_comment' error --- protobuf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index 38602c4f..5bbfb621 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -27,7 +27,7 @@ require "protobuf/version" s.add_dependency 'thread_safe' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'rake' + s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses s.add_development_dependency 'rspec', '>= 3.0' s.add_development_dependency "rubocop", "~> 0.35.0" s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984 From a43d3e4f954902b22a9d6896d450ea4ddd9dbcb2 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 1 Feb 2017 16:21:26 -0800 Subject: [PATCH 1016/1191] Fix rubocop errors --- .rubocop.yml | 5 +---- lib/protobuf/generators/file_generator.rb | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b0906fdb..1ed3b0d4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,12 +56,9 @@ Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' -Style/TrailingCommaInLiteral: +Style/TrailingComma: EnforcedStyleForMultiline: comma -Style/TrailingCommaInArguments: - EnforcedStyleForMultiline: no_comma - Style/TrivialAccessors: AllowDSLWriters: true AllowPredicates: true diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index e75d1b2e..662f9b67 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -218,7 +218,7 @@ def eval_dependencies(name, namespace = nil) eval_enum_code(enum, namespace[0..-2].join(".")) @evaled_dependencies << name else - raise "Error loading unknown dependencies, could not find message or enum #{name.inspect}" + fail "Error loading unknown dependencies, could not find message or enum #{name.inspect}" end end From 1bb401c1539f29568f68e45b497c941ee689710b Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 1 Feb 2017 16:37:00 -0800 Subject: [PATCH 1017/1191] Fix rainbow install issue based on old gem version --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4ae400be..d544210a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y libzmq3-dev - sudo -E ./install-protobuf.sh + # Required for rainbow installation issue, https://github.com/sickill/rainbow/issues/44 + - gem update --system - gem update bundler language: ruby rvm: From 8e3a0af7d92b563680042149d579c23b39d66fe2 Mon Sep 17 00:00:00 2001 From: Embark Date: Mon, 6 Feb 2017 11:39:30 -0800 Subject: [PATCH 1018/1191] Add functional tests --- .travis.yml | 3 + lib/protobuf/generators/file_generator.rb | 28 +- spec/functional/code_generator_spec.rb | 38 ++ .../protos/google_unittest_custom_options.bin | Bin 0 -> 71840 bytes .../google_unittest_custom_options.pb.rb | 252 +++++++++++ .../google_unittest_custom_options.proto | 424 ++++++++++++++++++ 6 files changed, 731 insertions(+), 14 deletions(-) create mode 100644 spec/functional/code_generator_spec.rb create mode 100644 spec/support/protos/google_unittest_custom_options.bin create mode 100644 spec/support/protos/google_unittest_custom_options.pb.rb create mode 100644 spec/support/protos/google_unittest_custom_options.proto diff --git a/.travis.yml b/.travis.yml index d544210a..44ff5447 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y libzmq3-dev - sudo -E ./install-protobuf.sh + - java -Xmx1g -version + - javac -J-Xmx1g -version + - export JRUBY_OPTS=-J-Xmx1g # Required for rainbow installation issue, https://github.com/sickill/rainbow/issues/44 - gem update --system - gem update bundler diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 662f9b67..6806eecb 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -140,16 +140,16 @@ def print_package(&block) end def eval_unknown_extensions! - @evaled_dependencies ||= Set.new - @all_messages ||= {} - @all_enums ||= {} + @@evaled_dependencies ||= Set.new # rubocop:disable Style/ClassVars + @@all_messages ||= {} # rubocop:disable Style/ClassVars + @@all_enums ||= {} # rubocop:disable Style/ClassVars map_extensions(descriptor, [descriptor.package]) @known_messages.each do |name, descriptor| - @all_messages[name] = descriptor + @@all_messages[name] = descriptor end @known_enums.each do |name, descriptor| - @all_enums[name] = descriptor + @@all_enums[name] = descriptor end # create package namespace @@ -183,14 +183,14 @@ def fully_qualified_token?(token) def eval_dependencies(name, namespace = nil) name = "#{namespace}.#{name}" if namespace && !fully_qualified_token?(name) - return if name.empty? || @evaled_dependencies.include?(name) || modulize(name).safe_constantize + return if name.empty? || @@evaled_dependencies.include?(name) || modulize(name).safe_constantize # if name = .foo.bar.Baz look for classes / modules named ::Foo::Bar and ::Foo # module == pure namespace (e.g. the descriptor package name) # class == nested messages create_ruby_namespace_heiarchy(name) - if (message = @all_messages[name]) + if (message = @@all_messages[name]) # Create the blank namespace in case there are nested types eval_message_code(name) @@ -204,19 +204,19 @@ def eval_dependencies(name, namespace = nil) eval_dependencies(enum_type.name, name) end - # Check @evaled_dependencies again in case there was a dependency + # Check @@evaled_dependencies again in case there was a dependency # loop that already loaded this message - return if @evaled_dependencies.include?(name) + return if @@evaled_dependencies.include?(name) eval_message_code(name, message.field) - @evaled_dependencies << name + @@evaled_dependencies << name - elsif (enum = @all_enums[name]) - # Check @evaled_dependencies again in case there was a dependency + elsif (enum = @@all_enums[name]) + # Check @@evaled_dependencies again in case there was a dependency # loop that already loaded this enum - return if @evaled_dependencies.include?(name) + return if @@evaled_dependencies.include?(name) namespace = name.split(".") eval_enum_code(enum, namespace[0..-2].join(".")) - @evaled_dependencies << name + @@evaled_dependencies << name else fail "Error loading unknown dependencies, could not find message or enum #{name.inspect}" end diff --git a/spec/functional/code_generator_spec.rb b/spec/functional/code_generator_spec.rb new file mode 100644 index 00000000..0e23dc78 --- /dev/null +++ b/spec/functional/code_generator_spec.rb @@ -0,0 +1,38 @@ +# encoding: binary + +require 'spec_helper' +require 'protobuf/code_generator' + +RSpec.describe 'code generation' do + it "generates code for google's unittest.proto" do + bytes = IO.read(PROTOS_PATH.join('google_unittest.bin'), :mode => 'rb') + + expected_files = + ["google_unittest_import_public.pb.rb", "google_unittest_import.pb.rb", "google_unittest.pb.rb"] + + expected_file_descriptors = expected_files.map do |file_name| + file_content = File.open(PROTOS_PATH.join(file_name), "r:UTF-8", &:read) + ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new( + :name => "protos/" + file_name, :content => file_content) + end + + expected_output = + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => expected_file_descriptors) + + code_generator = ::Protobuf::CodeGenerator.new(bytes) + code_generator.eval_unknown_extensions! + expect(code_generator.response_bytes).to eq(expected_output) + end + + it "generates code (including service stubs) with custom field and method options" do + expected_unittest_custom_options = + File.open(PROTOS_PATH.join('google_unittest_custom_options.pb.rb'), "r:UTF-8", &:read) + + bytes = IO.read(PROTOS_PATH.join('google_unittest_custom_options.bin'), :mode => 'rb') + code_generator = ::Protobuf::CodeGenerator.new(bytes) + code_generator.eval_unknown_extensions! + response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(code_generator.response_bytes) + expect(response.file.find { |f| f.name == 'protos/google_unittest_custom_options.pb.rb' }.content) + .to eq(expected_unittest_custom_options) + end +end diff --git a/spec/support/protos/google_unittest_custom_options.bin b/spec/support/protos/google_unittest_custom_options.bin new file mode 100644 index 0000000000000000000000000000000000000000..897044311d5280ee3649a452de5c9a014c3c7ab6 GIT binary patch literal 71840 zcmd?S3wT{ub?>XS_tuuQ4k-Q zbK%hBVsoJ}d#G_@VY)Hb?6X?W`{L&dapG$3u$;q-M|Moro0Id?Cl(s>u2yBOtKm}A z=-C&q+ciB?A5JTd*B2_+#-$@E9b}YRQ*JKZmK>vd1_M;EIO*WoXTbKx)Y0s zXQn3)<*LP0Ypr&Fhsm1rRg!F~^40 zP`NT1cQqS}^ON;MlZ~nRq3O9JjZGZ};DXZtj9bMa>WxyZy2dpO>B`2q+&ne6P`hK( zD&r8J>iL(}cc8Te#nGLNasGRV~qYdB21%F{AdYkM3{+2=&_G;TW>ubHn)ULdg>S%)Ff_k<&> z`etrms{<4_u8ZO{Eo=HO zJB?H;_0YFhO{%VC<>_(Blw_+x*mhm??_ivSrf;Wv1{+x z;6zs;O^@!MxcaKDV%p%K%P8e5T-o2%3Ja}r07joRGE9^5(j4lvRaVCxR%hqf*xs)8 z6z2Fub#(vku8tJu?&{dV16^?nVc*F3_~7o5uFkZ^&RZu&#=BOfAcPiOtWLWa*?(|f z*P6<@c(wI7zDsCPW9_mmFzrgAj5{dnmSj+)(lZpd8h63PYxWNA9NBwl?7+n6*#5!2 z&@RoZj{MBQ(dx)B^vmTP7#W-(uh_FK-msFMSxGW_?vLX2E3CpR)vY`uZgrgI7Ll!| zF@pdZ-!0d0u3dg1l^m|LkP5_U?DV22-t>5|SHv`vcNtWfykD0wv_s&+#~;IKSo~HL zZ(P~lSP_S($K~1j!m&nJbDwfrSNp7ZIjwxF{8Hd>UBPH@*3W5}zO)dZwIc8p5#1ce z({m>l7u>?^EYJ?iF%gyuSzJiVg$qWg%d!gBW<-@5?d(7QaYniv&&uU-*W}D}eQx1U zb78(-o1LCJ%5ofSX&-1kQk!Ykt7~2Hcqmm1TjJ((Eu=KF7OpsL(eoE=aiT|Wj%zbU1AI(h{kx2`Oy9BTVp?=m*Q&r+>wslfwgS9)tTunb7U?F8TiSii=vnaw_Sti=IVCdN zHN9-2zTtLJryJe}^R>kwjk)UjB_Ld8&p^CNzXJbMI%3B`tZ*#cLu11uhsH;rJ;LI~ zTEBO6V&qWu;QooxeIs4PZ5{33Z0ov{ze3NS7UDHaZQ;uG@!5V03QsK@IypUWEInIu zW@xG;Huzd>@o%9H3`>>D-uME@hSfSZRhyrJcEM$Es5S|AHjxb}#}vwWbB%FdIn&{T zzG`JD=SXX&4fC9X{WV)V0qZQxpE3)sz1mL3h|-lOZ4UBu{CqK9WoE9Mo~DfANm-y~ zy07WK=rnDfuiZDKHDI9ZY^$nksqHFkdK{54idB6Ig;&0APv% zfOp(9erW$#b>HCLs&8I7Coav@o_A{LYGGMtN_Zg1?XgrxTh^0D_MRPatI?|x$DU$c zEtU4TG&EKnhW+7pN5?}4Mn{H_fS#wuWk&>wMoI=6xumyfO>k6taNo|6YF8mYz3+?S z&YV%D9YJkorg8F6ZDtxR<>n{0tU=|RDgFMp@aBC{+?5)Bfj^f@me%hTCF_3+f^UrC zHGX+o8NCbtUq$Z?QM}q2g8yH{?)AlZ{R*oF3ds3L-8Q55H2t$en?9|92kr$sA zF0S^O29}V_0Ot|ka@yQ1ZPK^b*RQ56yFVVq?ID|mqI9CRaLmB9?ksdgRZA-$i)IeQ z@MXJvrDY4v)N4~_Z+v0CHa)YXuBNr4+7$}Y$^-E^0q#_N zp@soHh11q|AeU!H^=w~Z*q4X4J%1j>>&$MHjhK3D_r-B-ZmzMAC)eq$d|JD{!L(5| z2cUa4j?F7Mjm`qAk*?+0@U)*W-pi8#(JxAR#T=#AOs zv%9k^Gjz=5-`o>D8*3&QO7|CvyASMqYoU9$9n|z$9S&Fes`Vo?^+_?#O&|R2Lflqq zy|m?laumOHZ5*wt6fbS5^nY+wV$~-bGs(`yBS-4<&7?PRfG%w&Q?-R!V&>@NG5KE; zwkjBHaWd36acX}0=&^;Q|MJVP^$n8IxyimH8Jw9(tgM*?cV%Ck99vj8(Hz*pnb7U^ znZ^k^3gcwR?#Kuvdcj*r?1Hl|QUPI|T{>=6=rp4CCtRB~dzaXV^hDp@#ITi`z$oz`erH<@hA zO`)7P-%=ys)E5RoNq^gxA=XS9M*>DVaY$x4A7kVTH82&_+Tq6Sbs&0*#R>e$#%nu; z)6HatF$zMyM@G679SFgOczU)z4<%Pdg3fZZ2uLu-sl~~9hDV$s@*lz@);tKwsmA1@ zG=fQ-rep{7Z%{Iyz$x|lX|~oGscnKNjFbG_ri0pFX98&{z*3tcjAKT}TXVn;Wk&bu zg{DS?-7Yq1z`e7zQ_11FI0Yg$61?5y0%%@H%r+L_0HetQ+zod4?UN%E#K2`XnvEk1 zC&ea06b?$7C+d^pAX-g}vF61)bB>FeI^XJpEhhGijwj<|yC!ZKtd1o7K2ROId31PW zIN5nCg(Jz(*nwNCqr3M^Bzwm84v$pFlfnJN>ULf;H!gd%0|YwC!_m^_8uI@v${P2Lb88sB2M;>?qlONoJ@>u zw{A~wmyGR7_Kj4B_5fyZ=P3KUTdl)gqZ9kp*{-o_oD3!h2CEaJLkIT`R+9qstX@9T}R?fU;jh5Dx_RZjTe(97Ci0f*vD~VX%7Zb`NwMe=M~qOoj*d;XxixwmcD4 zn3$o1)scO|8d8iO+&MlmI&pAfB-uSSHf+QmAF19vIy5qVU9xvflzr4i*g3A^B`Vj5f0z-NVR&<+{Rm(Wq=wc&vAQO_-8~uSjiapu#Ov_4cW^-TLit^f7lVqaL8>|s1@0rsVAeOf2qo}h} zR3ER+-G)T(K31QtovbZvPj0FoIg$+5Yjdb`^rUH;rU@ZB!+RK-PB|gZ@(3d5S}IWr zQXL%BOcTjqs{Ke~5fCUc7m#4JfrS8I6;4m(vy;gh7y*JqzUGW<4m22Eo`soHQZuzg z3;nWnI!?7nZSIuUi8_wf5~>w#OTF)CUs?xOtSqbqm6lA;o@mT3G`BLY_Bbk3id);y z*01(Taa+rUac5j=|3+JjORS1pm7vnLHV#DMvZYi=a!uUkl95aM%59`JBp%{rE!#ar zDk zqSC%H5VxOyxrf->a*c;rtQ3`Sm5M;@Z9CgTEDEBM4kAe)D(x!+vA6qb53w($W2sV9 z!c{5(v9E2DhgcFsB^^YPKvddS24dg2fsXwx=fy9GY-(C7MN-`hp7pW_7`HCNM-A_b zWA$NKVU>ZQ4&(5Yg@Xgq+iksvB`tAMn>mWOEF7C<(Q3?Hx{#b~%pXst7Ufe;4mTPL z*h#e$CrH6D4!2eY(w|OWs|KQ^8wg1TqO`9JRr@!d8{ZZeN-dSr)h*XX-OouT5EmB9 zg@&v{g!u$4K5v4+%E-~gXzvZH}+9K466#3m0}@n(SvpW;aPM1~ntj zLy5`!QFhu}f!=ORdn?e}jcIQMdb_c5p6{(dZ#Q0$#6M%bk=R+-(mjmH##y)PPpsfV zqr7gTQ;&l;Bh!c}XA#$AG^eN(L1kx(N)c3ccH*`(auz{l=enMdQty{s8b8laq1i~` zDc!TnQIQYw%n)HUz)|gu&|cdLY0a9QKFZONlz3xq=2TxY+>kXbt24#9WSs~0D1q}x ziZgs#99frmoJ-(5a?vI6)rK<__Y}5wvw*XYT4&5<6*>U2F9p&8kbRv&3_Ad_?`)@1s0omL7xu*ei~R1i) z^;zu;P42LfFeZ=)brZH896sr6Hkn_fbe1jCk;OUN&10J^U{4&e&YW?h6{eZ=_F7gR zE0CXKZ9&|`sAg079k@1a@K<9-%Gilg47tWra>bBqyfbK&7;=qwZwoac*LZJV{PRYw z&Pwr?!uj0?Y{hU9a{)bDKfGRX#fv9o+kg-@)*{+LyR9Cp*56|$ol9KVlcLoLTDPQV zbs`|Qq>88$v~D4m(+!{#v~D?fb9^aFL7`Im*_KmL_qj`!0&gKEIu4-&Eke>|KZ|{( zMaYbjpDUOVq69tvobQT^6N zQ>L29C5ApJfIMf*Ru2TNeaMSLp&(^^CFcWry9wnqudg?|%+;r>`nl)H zY_l}QM@nW|x+LI^N zok=l~nw{x(O1DsG1IWz9m&9+Ca??zgo?BQbcE2G?EZR`A8a#E$LhWecqV}47c)BdG z15ZkpYdTDe9agM)S+q|x&4pr|Pg3`G!cOU^j10HHH|5Up(w775E8(>+WmI)sK_L{GPp6qQGdG`3GiiX$r(8oC zy3E5h0XW6Y(zyU1x#M);GQOHQ;NqcX4!AIFraXkP2JmLeL#%C!1>0JoR#VnQdpW7wWr4oCEO6xBcUKcq9;Adcty`>Hpxd+pT%e3KSq3d$pcW^63(~(NM2{x>5u#^LAAL5m z#Z3c@gekn|`~5jr5JE)ncs;q|a+YpxUr^y7J46@tXu+Dv^bsT{G|H{1Gt{V5BL?$cE2;n~dCGN|n+}erkicvj5Bnqn#c-XM@pt|C0P* zS}UcO<_CjvRz_DkGwhJb$PK?-DZMP;0!^%ptVNj?FUz-RtCa4_w?OSGV|Cg`8!hh2 zw`i}FUY>7(xGN(gaXT$ut`^%ozjRbezY?MHx|508(cY>03^6=1pVCvv+!P~!s+>`! z18Bbzb)OgadT4Q_^a?@Sob0X79bGu~1OT!6R6ip@48T_i;6)x_XQgyE0K3=2xhJLU zQQ-26C;d6Ru+mg3!>bc8cMD9Aqg9pCs{oS{ZWS%a$mp_)7O%>;SY0XoTE4|^ zel;zAE#G2IrF2ie#Tr_Wu`ca&4K41;w^&;#y*l4wEiK5%TCAnTtJUICPmZoi={2MmV`O2Qr*6?3E0VuoCB*M?Gt_F&YtAtY@q zXK#vspIZzJjkfQI3Q6~a1#`fJeVeeYW1kwzm^`+9X1LmShZ95nw*8%rG?c`NU5#Pw z*CBB&xwP-n?Q%%c_{ieS%&A_*_9}8ktMC}D=1)#H@&657c3H31(xk}|E;1amA(!(^ zgfjaVzaU2n?#Nc%CR?Wa>V4$RbFyo_+YKy-vGs0t*fb}X>8On8wRuHAXiQjR!qVGo zxJ=orZ)Xyc#S?Nv3aDI>Ec`P32>Pq*sK8O3{h272CSlEYWK6Dg^Boa!D!wvQe@Arw z1@V6|qEq+XQQ?B_6GrpYlz##`vlEb?!m2wXW>jQ_Q1xbGMklO(AZ`ypfCffbjX4Ya zn&QspN(cnpTMeI7K(&IuJK}nd!=3#V$<61-?{pjkd%Z6zT-<%X;~1EP^WDk7C^{s@ zFYP!b_0TMUG-wiR+l0j4qvsqeW=eVYA1-#{Q0AaR&%*p-y+;h+W5M!xDU4Pwa)=5` z`ti4d66;1Kbka<=X!nGBx^}{mMyEq3Yp0k(17(KZGC)IVeTPWE!5`-GUdi&DD27n|o7;mf()5Kiq1 zbcxJ)l!(-@7AecH3lN|IG~nYwSZB!rw*7P2-%< zW*S6VLEgANb6OeEy;ha8{IpXM&clssVyT4rglhz%2)Os8_q<>la~n#GO=}r^NxQ~m zMUcaK(!n9lU%$cb%WI?Q1%>6*71Y80g}?<<1_p`(!yo)0GiKO=X)9D5Dq|8wF*C$z zQc5^Bp&EQ3TswsOP&W6nOFxw93HG5R&zHwq${CyV!-$$^47{vL21vMBNp^jp`lCD3h)l=@l)=K#kQOjrO`kZ{%bJ^+wrPRN)&L<*{h}6H%(Mpeo z{z=h4N!LF~`hPU^Z-;Coeg7os|IuJkv}$SpWQ1Qy(nShLBm*Segd{sJ3Z+*0;;kVG zq)$fpmK;u46rYZ8dOJv3I!OjdvM4?s;r8~WK>Boq-`gjF^yvu4_Z85jTq*x$)bih< z$whgZIHn9M66fGrfIW4jBmOdKcZ^XMbv_rULkdhtI!s7HozDg8kfiD70(D4&$>#!f z%A(F+1$&DWkVpndvbX*!NI9ie+1pzrf%I3w-YUx?{Cvc@q6SO~NF)O!QRnkfr&|vx z1=8oE^BgHj0_pP+XNwm@owiE(i&4whpw7l6)RB{fcrH&6X`C-c?K)Q|mD)s*F9m{- zqH~h2bCL|>OMxIHY5Ju=5R!EMr9hB2VfN(+7m|iS3P>aaB(ckvqs}ChTICBb4M`w< zIl_(PaDpITjc_A6NFoTy07(S-YJ?-vmjdal5uQY!1kzU{T#1)MkoHRXn^DX6AV|*= zf)Fgn1w5zyml8)><(pCaW<#W1#Q9br4k-{J=@20aalRFZLz1T73dA7^BHt2mUMo%B zF6w++n*1eL!n#)Hf5U`m0_i&uSHK)3aqf4bL>^#4BJ~eZ;Sygc!<=M*#6bW_Jdm!bygvUBo#S|k zrq=eNi{lZ4MAPp^g{O93lZ=K??CbV&P@Z)D=*`dq@%#9D*<&$xE&ZNeq$iMtxU$1cCI}N(h=SlTeH02>Sfx2+9-% zPC!tm=wlgzS`;435R@tUScYIL2tJk}*b0J=3Bh-)L25cG<<}QleyJGs?@w;{kN@G+ zG~1yW_dmKi86k+;8A|mfC&qT1p2)d-tj3{ZkFz(L9JnpGxa+)R#K~<6Va)=m*)ye{ zWf!7ifvzw;CdyHNH*zXz&L|?7Q$}KL5ejVG8NB+K%Ieo!ehHfzOkjCs9Sm7Nv$eVD z6N`$fYG$TYm=Gi>8M6DTa20?ofQxuqdxgduPEBnmvh7Nsz&1~su+NeUc;cAkKUY^U zWssl3USl}N=Ncz*MY}*1vr{>H-A-Vr8Cn*-Vlgl@(T=jg&Q04fv)d2^JM5T+nxk_( zyHR87Lky{EnO!`q3N>e029r1-ne7JgMbBW}ExE<#F9OOO4W_BnKQ^Djz&2OXa_r$J z=NnCEf(;pHh#d#W?v>j<3tv8K7rp6qE;B%tzh(h&ry90r_q*#_(qxJW5hQqu_k8^RZ(cFhjrpT+JV2_cg|4=3 z?%^Xgs6-tsOzT*w-aE^U4kww!=l33+X&kQ2^rkb|%Ox2_>YvI5e%jy(m~ux**=z?A z^(Es3If4Paq9}X~-9of)Bc?L3eT;=i3eMPJWwN*I9ZF8jED|-k)rPX9$;tX*t`o`m z!lv_f@YSv0tv)1TUOUaXhJcwjOk}^~1QGRf$+5;sBfCO-|>4DoCr`ld_SZ<3-C~ws5Z0W>E-ie7PJEdj0}LG<)&AA%f$t4+%)-KT{IUD_j+vz z+3HT=3^|Di8m{RsdZ76PP5OYqe5YsYchsPCUBZ$4q}MP6#9hv~$TORO*j^Vkw6Hjj zL&d^gY$i${;F<479*qfMgl+2`_^FruZd@wu!irUTAC%;_=aUbvNciE_? znHu|PACruNE_RS#M zTw|EEVVg(NvBhDK=jOo_w&xUtfis=O>I@J@jXlD!(dT6MuuyS3Dk?+$2Ma{cyrpQ=$BcidP0z+q;7F+iu7<}H8y0$6Hn810WEs)e^&-f#I!~^hq8YhWkL^mvJ z>3V4{IENQ+2&U#Fj1i1RwGl(0#gEn(vTfOxt=KiT*~A7oSqEMI#huD+o-}YW)zgTd zV*ed02Z(;3)?t1DW+}|Dc2^G-{9y&9%HMLaA~k;a5g-Wb`AF(_{}*SC-kRv^95;8QZlSm2Jb44Qs}ZLgi22>22Nl61O`R(&ivViU>=NSX|&G#(zC5$)M)f zD0d;!5TcwN3`>~ z;tbX%zhp`>o7j9(;C{E^sRa$@LkxiEAsRb2$=@RA+ZqH-z6hivO(J&>XL2WB#KVQI zUN2elMLb-%ygww7yN3%`?hHwtNEEIgjKA(yJs^L$P`JMPvtiX+N$>W%edyyUUK0or zK{T9ioRoTD-I%O9U%oa*Qfta(D_x&GVFvzeO)3&2$C))XY|pvggA==YuZ=B^2ab8} zA~8R%l6(@f_-y9j!ob!U3p=v2GY~Pg(W6$XPz@nw!lEwR>^pT@<5iRsutwVX(!Skp zIOAv?TFhY>vv-F}IHj;%U%FkgzVmXCs!sWGAas~QT=fj2V*M%fg_~F7+2jacboWy*UA1M?*Q7Cp_pX^Q-hG4SzD_LGgpkbt#+*KNW zq^d07soN%{M+#he87A%k;Ibq?S}3jQxhe&2!ev)QthoSc>&om%3+OUyP)05W!Jq&Z zFdY^VVHqs=A1$m}9rN&t^+Sb^;l1lFyW1Q+J1mGRyPiFE!fcjQLy6RRy_74TPXB&f2xp~`@8W~EHUW|;@H-wG< z(;MQpnd-H}L9ITvVGYX8W5#q6=nkR_#|Shy5_Y;%$Zo<)lM69073o{C&Z0)7SJ?un zAh&XRF!09Q!pcyV?2uUGag_!4Fz$mX**>C?aOpoVmTUY zEc~5sf{pBgC_WzNZqP+cCr|l7ozyNE&^eG8*PQD$Pcdg+EZKL- zCje-Uv02>M6{RexbA8wW{>M!|7)2&-iAi`TBcFjj6=~VIt%HL zvHtZ!A*?t$1}7Q%(J}bfvwn17_4PuRJ2;^!{d~Q!Wt-P}?FQ2 z_g6Xll0nLnuFX=8L7u_&b#v@#5nyJ-wY(F|UP`Wy1*Vv-qBYc-T1P9YzJJ6HsY4FU z1jhi>k|>Mk6x9I+=LwklGcPGEGZRtP<$_FIu5-ghQ`d#+YEQTayN?j02G01!%`f6t zSnDb9xVlmw3eI*e4(=*x)M*lWemkS5;#R+1=yIV#PzZW{yRg~CAdrNf-!3FO0x0PD z?E*6Xd?P0jt^ZgkT;2WL#62G9Y<%n>Nf&a+GlPbk#%(g2ZMuvap8Vcb?_D6cOmzPW zF3;3cuwz70qRi5vaof*`5k*Y zAQzWHOSk@r6jGLCU|@P3k`8wj!v(1@+*J(sd)eZnK;Z8c^zO2GwpKCR?@2O7ZLSCc z{?`JRO|NrTTNMdsb8{MzuM6FprDap+7Tgq#)t~{afW~Uj_}2^#MHl~Tq2kVBI|{2o z<6jHhGo3Xwh%EkLp)lHgD7obr{sEcCn6(vHF!803eAr|yZn;&yb$ z8hc29oU3=o>*9`(gRMu_jWJK=rCC_ZmbX6c%<`-+D(2c+e?z4u>=%)E`S+L^YiXS!SDR7uU9D&VVx^TB?h&>!t$Qr7f z#e=;i{#LBl?eZxkN9x#6{I|wIf)1LrB@vO$O9EDQB!^#KPwX&sPkeXoiAfpUc^q)q zI~=B$^@5W->Il_$H5$n;$mZry&+XcM$@1q)lN*fMI9~LZkubSR6EIu5!%BWJ*2Nu7 z2A&bkNazP%lD%pNvLZu3&$i^v>vGd2>qtlARyFHK;~Yf0W;t4M%tEsemJp1st(@7v zzGq zC6Y+)y+vY{B-bQSTlW^dpMWIm+Py{m1b?S>E!JlBzG7jx`}0vUJl)jMpIf!Pp0$hm z&J`s;re2y&da^_8En5kM@K4AFUnX?4m!*!tgpx0d8F$_lCPf2H58Q3@0pY~DLayqAoO@xyg6Gj0$1ZmMumnjWjXf=N7{O@MBy_wl zqoaHT_Z7YRhceLdzGA;qh$NxoeZ{MW0x0NsU-5>W@pl{@QBw~Tx%mD!nJF3AJ6ocD z%GP8~hJHd5(p!+?J4gN}G9iP&q@+|#6$1{Wlvm?{jFe)l2a4W`jLqx+K#_oR$CBDe zJW#yA1#nUdDIX|q>5cD`*FV+~!TXEcihpH!iBS;9=>%=*DQK_?kk8r)9l-Olok_kl zD`e767FUsRh$MFx*;$U$dWmwbe`fvE1ZOzgd3T9R_WJpBqafb&lFeYF$2)Oy6w@(NXoGAPyXpz=~Rn$=)C?a|_$s8b#Z z73Y7rq*?8a;x}j;8b)mg zhZfY$_GFG#5-XXS!EEz;sNl&E&|_Ml#nOyXx-`6VVCyhv3hA*#GI(Iryb#SroFS?2 z4^`E~K9U0}geur$KMG33i6qEw62(9nF~TgRyupKTBLm@G62Hq1Q-y7la}05*bkH54 z1{;GBf`fheNC(>%$YeHr0N@ptZE3X7*ivohsOrhNU6xtCJ_d*f488cs@sEI{Nks4c zndr&!|Ndf^3qwViOqzJmMn)wj6psF%qEQJz2QeT+Bs3j(qmojPc{muABthokU{uE7 z{lO>6sElP)elQr7q`-ruGb%}Hj%BGw9KTUbZELV>|0sEW%=r2}2%Jq|n}8Xf`_Hu5FZ745@=@$;ux z#Os$LL8d?(G_gZLyX|H1cZ)JOgAeXPH|r1yCV)z55+?Xa(O<=*6q0_V=&$0Dgb6-U zBmh~90ZA5vj}*^!2UR3l3_enP%69IzLVi2PC>H*_Sah}BNkowwm=|zDK(XfMzZFYs zyVv4(v9Am1y-4P#nM@61%V*Lx%>q}0mzRQaryt1<08sGTP&R0{ZYq7+LkgQe!8@kLKom3!TNG% zF{!F1Dh8jDl&5is?ZI6|#c`OupKc9KV=d=l(hjGO_bT8~t%YbcF3yv=Zkyz0)T<%c#*wfT7#1^CQgzvsM8`1qJWqEnV$kUmV@8y9_e{ZnBq zS7NNlr4xck@YT9gVmN<+-MjfmoiofCcHS}Th-N*4u~&zk7GVN$1M?}upRAgEi0jEo8eu(Jd5ReHC$%{$J>8 zX{)4yrvJ4S4Uk1(30rM?1w?+goYDbfHhZ~|xD!-8k6@c!BRE!!qF@=1JekvWJZhUZ zGwqKls>z>m)?7G)w>aPjyzICrwNXO%VN}jESo&cv7vh@rOW2FW?WyB&^Qxaxwe+I^ z#(v^SKO+_twq$3b*ZnehPV;(wt9H4f9@kZmn>D{GYjk1kexskwm0YGf~2$?0Ds5Z9edXG}45q)g*kM)geM)l;d*Kt~QVY4)ee*8+&hoHfOu;^EcJjLV` zqU_(V6zxeK=|>sMUny>OC-)@Lk6$Tnxx(v5Zm55?Son6TAI0upEw-(;YxSKayP^Jd z42EvIR&Q+Vy@*DQR8P9=>C|*5q}CGI_F5Uj&8CC3k>PHv=ZA{d)oX2RV>BMXWdrKUuCIqT2l-IwhYu0cDxKk{n=yeq&Ch2`w%4$rgpc3ERQ`z^RIe!~7hK3~ z2G61pq+hi0(UoeqQx9$-A?^Gr2&yg@Xtc}1T6B1Jgtr|)!X-d*1)UBB>^caFMaN4dAD`Y#0=HgMFLxN^D1%j1&O4tSR ze6Eb3X^vK04Q)Dv!V-M!=*9@4Z5%(?8hCeIPPDnLeEfL5?k=nAL8W85hyX|UU|a1g zoN7z$Doi7U$SF^+K;)4%1FYr(LJVX3>@5?=igHB0cBmp(SGIALKZE_64hei@o&tNF zgAa1rNvt4Q5KEHmS_FSqC!H}u7<`6Py?P%necw*J7dm6SVl{^k1F(HYIt$l{D`Afi zCgnR5G+U1qXzbiDX5Q82YPi-LEFx&46n_FJ>^nalyi1=n&2gq0UK#RE$2_3tLp_tZ;Lso?+xeT6V zQ3$!o3F>kw8V1_GY`@J#D{n&&2@O5=>{%%g*nD8yEUIi99>~Y9wp2LlqbKX_*4q4VC7OcBU{(%mXwm$Jdhg;u^Ea-QY&T&CJ zl(L}TRqDAk{-zv>oiY{fF5yW0T;@o03)z$AMhp&I=jmp_IKy-3{4q4zMqU-MU>fOV zHeA43Z0NQyDG}v5V5otJihjF0BcfafcbB{i5wbwUyG!1MND?C6UGgqOk`VFk5-!AN z7!84RPpPo2`wDaPx$hvH;S;oOjue#zgn*jvFy51)rl_oYviVh1);*=OoyVoKps1{S zN<3!hL4n#mrHi(h1Ey1#gkM+s>7D8U5LAH}P~}NPlHLJBDX6}#a-%dU99$WfqNO<^lhr&57{A`KFaSbGEq07YX{rFvuc6V`qwZHlzm#NEeQP zB%#XvVXjGn&i$n>cg>w71iZh*voBwhw62nA`k0s;X#S29FnVK%D?TWC=UQ+ zI)NCbQv&z4APf3@mkObAY1$j{X#M_@Fc~~WRczcisQs6<-$pcBq@b(}Nt1IPq zmRkPM%Y))4-dSqj6#t7jZnXsBJ>s};F5@_7Uq9)5=Y;3UK5jA@a&8sRgAAOBW#n#R zNitjS2|P#=GQB78AW0_nJ%I;F!h`P#JV+8Ad{5xP)#8cw{uFr-fS?M*fU4e@cyHiA zO07SylSzW=djk(Dc;*975)ZBx4}Ku3EPNJotgYgKH|~KPt8Sx#vLz#{5x< zNQ=+uUe+4%;3FmC=5mLfA$s#kWkBD_lg)j;8_xLqk+S{7ED(&b%MJj&cOtn$doH`6 z%-fsVCHwoj*rMoVXK}FIw=I~Sy(i#Shj2&cS&eimg=Nfb^4f{UOyj6xcGT)vgDtZ+ z*D=&XS1euJ@a5tQ8(e>?mgr?ai=wT~XyWA0G))MiNGNBuE)aSoe{Vj}9b>ls!`N(San9vPVip z2TIegk(7Pxrzm9r1XUmgR3&8}3sOd@_2;FGB&dEYNSWfk9(|IeY>lMs(I91{z=Ncd zGLlHyqe05nR?43$wS3J>ncm3!RH^-}_%9@7Yb9l0kdzUcF)G&vrjPdwJgGwF`gpQs z%sU(Y|0iP1D}2kuI=&?dGkzh67)iL`3qiz4!na=tB1RGs`$7;gl8D$Bf{3k^h<)j& zC}IEvRUigbC1PI+B1Wn8=S7SpsD3Gk*jh&Q)h9{B)=I>_8bpi~c#w1=MiLSGszmIr zB1g_$mGXB=EiY`1x_?mM#qO}RPmf`xaCvLb#kZNG#6?=BUc5B0(#IvsVT^x?Ll7#W z;eA{G01G}bG_npr{9%3wU>z7Z-~d~!FV3LhG<4(uk0fdV(UXr7bRFK9^VVJs5rSD= zA3=<3dIFD8xMSeZPf-A=TwsceId1x|W;s8W!!H9nFyKLK*~)PSixDnX_f#Ik$XC<% zD<>LTwr+J^0(Xbc!tqx4%&j6X><}_MdZxE~zfakN9OC!x>tjaPF(#J}x*Jl}kc&xO+y(VofctjO)Md$}f&94h?j*H+(uw{y+q?k5_kG2(8{FaVH%JuaEM< zDaxTnm>*N7pcjTFLj9oRPXWQ*koR%&BpKQdN|)%96(SNU?S~w3c`|5^OEN%G@ZAqH zNFu`zOBHu%kfuQTVTntF4ic#!mHeZAT?IKZNd`!AWd5k+BR41o(vM2(F7n;Vk@=$% zkNP=CH2rbOKc3iSfj}e!Bzg0GoZ%#I-j7TEnGGrf>BkuhQ1{N(g1aKnRgm+IWPl{+ z+nuc`PIA88*}5+9i=1zFw)*GVy0qJWL92hEj}(wd21vS{_kz}x;_{8Xpp}nHJKmCS z>;uzLJ27uhu;3te@WyLfkE z7q@USO=>nc4{9{CBOq*{|Mb&**oq6x4mp;5MK=w-qNGMNMU&_m?mG&W z`&^Sbg#Eidgimm;!xqT}p5vb8^eTjE_)0#XrG|_o{vc*x{*RO9sa$5Z> zLVdF!wy;e4%15^!JFW7SX=V3#)Rrr#>`os=re4G#kjEP%#eSf_}nBv%~SlfvWi#6U#>a)cCd0EN^#;f6DM zlYQYW%mAJpFe00Bxm_esUxA=5Hi^@HJ-ZjElcS%!A?O1;Q9l>Bb^qZ|-FG#E$w4fo<;Zp8UvHXFRZVkhd$YYNA7W2d+t5ZC#% z1o_>Q*}iI+GzDMSIyatT5UN0G$$dGA9yd%aK@zmsi+h& z1C%Y8l0YvoruYQb0o5<4%)>R>QDSbUQAFvNzmS+At&WaqSfkv*S8DfWodye)UEX1$ zPK`g=F%odXv?vCXt&-h5rc23lpi;PO$k(3{ZCwarokb{h?@ahwv`?5Fg@+Kn?Dzta zXOwb8x*Z{(j!-DEH;%DEFx4d|i{ah3PkYn-acwj=>CCV= zT_0!&W7M)?8&a>Z#od7ooC8;z=~SuNDtO9{$*E>qQbwZg;ow5nH*#095==ZWX;^ML#zLl znm_&Z86R%Bh7$ir1q_30(h6F738KmVsKA?bVW|tTE-MUiN$2Qye^tl(z>}*C%dlwV z{1MKI&SQ>2c9p`Ykd|e}w!{B);QdR1?~({FYwAVN-KY`hl`8d_<#8JBR~YzU@dVS+ z>YD8+`UIumZVVb*WM6~`tY)g%W1{9vIuEg6zPj(B%3y{mc)O9Sg)U^f`eKRe4n&_CYF2Y}KV_&-11dfryMUu`hlHSCYKZr&2>es!A1 zj+xAhVxHZ}Wtt)&_pEqzKG*ssdkF;V`{FI}CktMSQ0p_&A|J$&=hTc4VS$`5m!XcK{LKPXzV=;mQKW{tj+nw-fl1yl%U#A54o+qq$n@+@@-5c;nP*c-Q6qiMJ8%`L!3XBdDD*q8g&6q-N zk> zVT#{e<(UGIFD{q1cHhI7H6;}+0OK&gWL-<~D9!@pEa#-u;%(1l#jJZ9?R< zfu5BolcmJG%rXi*HKlxNyql_<9Co&sTC?8IU=1_}hc%=Ajq+epk@iHKBSUwv}XZlS0edu!Qg7@3Y)wY$b)mdDoOC}lXL^|AA?f%SyE+;4Dm%ALMb zA;euI9e^I<;sqR3pE{HxWQ?ZJT-mQRZcCgvX0}FJ!7LO`0X&s$~i@0zxj; z@j_#(QO-xL1~J8tCzefNBb%A;7&BGR)16vA7`gm>{{c=gZo*O(E`u<(F?+>?NefN1 z=VFp&F<^$-`vQu@wV7wnFn?T|Cwt17m6-P{wSm(%m>ISmi(B;lmLt$%d!V6=K-^XK zu7@!VHYwK;=ck*;v$qISaHs2dsdy7(V+?0ZLt}TP$im6dJAAm%CfGRF-xW&@JT_Il zwy0?xN#9YHsgN#(C@Bul*{Pco#q5nCKm0u7%Hyqe7!xZM%NM=^ShC#>*d=A&af82| z!Yl21?BjxcUg&iY7D6XG5y@i)7!B`nQNug$Vfadq3n|o0X*1OzV7#7??+h9bVAu;r z$|q9l*wsg|27;L-hWCP`)ku$sGD$~66WeewXjFuthxW*f+g)j>P8A*IcJ6V<^g$W~ zhs~0+S#8{Uoj4`JZVdHi) zrIE6?4Uj6PGSE5RJnBof?Jz1n9%Nv8;HVcI51~OiCyrlTA&6dmU6_0SND~IRQ(FOP zJrWVtIl1gvC$e=;PWu;^{n?AG7P;+TT;6bT)`Yd@#bq4#I(tzK(!X3TZA&Z2c~3?L zQ||j;&cl=g|Ch@fF3Fl048D{eU;^SLWH9B(e@PyuT=_34Z|KdM0P`i~ z%dgN=2n@4Qer37k0UYN<2RS?Xu=b&7KH^VYH2<;b6Y$%@NkvvKy#Zl{yWAA%hvuBa zS&EcB3QN}R@S0`1z6MXNwqDI=*RAbpfpdU4n-~|H z+c~G#c0;3_vs;s^S7<7bal^Bp@h@LS@C9VizL31WH5&ZXz2Wco|!qiPLu4QUsdkJrg5d9`Kt0p z_hA?+GiR?V^I;h6pex!z|5~~57QcfgP3>PRV>`bxg7-*kT(5!mx}TrlKxemCJVzR_kQ^}C5Q4=e9AWp6lUnXanaP2_T|UvD_3 z+159PPP2Ev){?nBS>otsektGepj3Bb4?+ub`HLTAK z7ntN)21wmo?zzZ5v8@b-`KB`8B<5yJ<|ffB+ulQ**En)S&O~_DeM8ZEbCxo&cA2PnX^&3+P>Ad#-@;TklyX(_Y zd>KaOLZi9Ey_tE4<8UOexp2sR4#ladR09l-CXE7CqDbM5}jK%>pkbk=PfI8 zpHlLJTcLcMk9O4OL-}mnJ-j$Od&;MW(gPNat7j};B}(b{1n#yK#Gm|ZMf5-i+-@p4S_WRCz|KdR_BkRtdyO$$VyJIOb&lNI}kP+ZE z;h`V;d%n=nkF`QYKkP3OPCw$O;iMn-XE^DXaB^8c{;_c4_w$95&wGB)+){2BLwEye z#)ZfmL+j|Vzj@2%Z~XGe;I}@1|K|UB>&tgO^2gtO##{NlW)ELdXz;DuTN?8-Q$6qc z-2Iz7Evv;cUP3xIXII7Njk`Oq)jF|0yKn>_Xz(c>UVDHR&4CT-rlsXZ>qeApxpDHw zo)uc{=d$f-tv)E^e5*h1nTacGp71=}k#WQom9DtR?#iUGwW^<$N?hWf{!Il0w6$u# zecqLuifP`JKJThcrKITVUA3*feX2`rQt0{p;tJjMSFVYRY|E^>&i+fB*2wFazSB{x zs)g`mujP@_&&po#g>PvOknk&4*n`e2$af!xJ);5^;0&U{|Gz}r~7Tu3KY1i zvLS9gS(}*(BzKAa=f|ri-Q-9OUsbuF&nfA2RDE8HctyJDWsm*2CgVSXXs7QHkolQ= z$_i*-Df+Wl41B`R9v;v=>*m_L4nvnrT65rY(fwb3_2xqRHvLon%l~@c<_{J0v;9?% zy=il?{qM_GoJ_iZp7qur{_5sp*I&2k-}3jr{@Ts2Xw}cwxY+&;`_&#BkWZ{tb{u;! ze`(3~Klz>40`qHDu~P}F`*AB=t+cQHk*-fZ_)2QN+e%uyi|rpQ2wthD&|bIxdW!9z zj{fZnzY69ZcmB<>Er zM|HjLmH~`}=Q?}dScp5)PK4^TpY&+jAuhep0pgXuxX8J(m%sD=y{@aOSh*a5#jr)d z#JA_2#^E{?^6ZUJlBf*CrCChPO|91A49QWoHvI?Vvis^z<=^dT({KIxLyma={s=s< zo~gJirH-Hf%2jcP88teRam3oW@t=Oe*U`173J1n~P zkX2b7cZ}^FmgUHhT6&%*3ZDGQI$P4Te{fF`6|(K>INoPpXQJea3gNl?Mke-*4PzZ%5e(teGBJj??Tc5Z{Asg$ zN!%J{wEK}Cy!5)WD(jVR24BW;-Dkb()i1fOtFlIAS$6*`yg@I^mhUv5ZqQH0MXc${ zO4F3LG^yh)?(S_X%;;%Vy$Rm>#eaMG`GxL|UwzkI=YQ(2@BHX!|Gh{?IzW$A<#=3n z#Hw7h0`RoDmz(Z0snm1!BY*aq>nfEl2RI{1_ohew=PRyTUs>ln&q@ZammZj@YX!gJ z3AD~D-t?Cej8e5-Ei}giBk`(PzYG|FCo}=x_`3$9wc6?18JK6pu_+^m#pV^XEQj0F z)LV(0Uh)A0QTBSt01V{-^jDq$zT0zOB}Uh#<6Z~pbh`SP3~=s$&zCf& zO10CsGn{HMWF{15%0W5*G<;HVHOl_ZCk)7%{>>|JWLou#YV3eo7dOQ1JU=s|4xZQm z{M)zvg|KX|wy6#62c8jkn1A}r+JE~&Yu{RJw?-L&tFJmU03ZG>15h*oS6?LngK?~P z%C77`GYAjeZxB{jJ6x+Ah%-gvZ(d;_N)AMd1*hI;jKv?n#6Ya8cDPm^3nk7Jiyyzx zKvWzEhs99bX)m*#DKS3vqt9qQ+p35!@77=0FFXQ}GezXfKQtg^55!@DVsVeeohd4x z`A37Y76HiNl7cx?WWMq;1Jf12IBeijdlK%Z9_We^8W#OuP-Y`hHbHUcY*V;TFr@?)Rqw44{rY3-~HpSUHor<|6i}0X`iaB*@a+a8@29@l?~4Su{6Kud^I?ya<;Nl z7e&@?Tk@{I`QE^}@i`;2hwFOw)uS)}nRD&k^uU{878 z^lOlSIxEvNc$!*0>-m#@q@DnlYMlU03>!k_5Mm3zAVO2;yFN}r!DEN{Mmvuc>byP# z{}DH&AV7k=cmc3Mpaj>G1cCbigb!tp9f#01cOtCw(DX}?iivQq>Jqr2=r(wAz+!3? z;jX=RKq2$@ti=iCYG%BMH9`RL5@SPUvv5^HvH+lA*B!w^m1Y@0m#U;P)G;jwgfr zhsoVPQ61fRaAK@F&i(npahmp6$>9E5laXf~sE&+}Cu7xQbl-u!qd)_Eb#VX0=*al? zWOV<~-h;!V`*&|ofROATo8X$~=)O_>rOCwDcI)=^cFEYTWZy`2Xb)fpcaH8Iow(IH z+%-CZuXQ}xHC9#d?SaAS#OTn$y@S={z`^Q)vGI{aBO4waAKE)Ox^HBdC)4-SXEJj0 z$o`3Be9z$Cy-Np5ROv1IN2=G@$I)5X1w)y#%|C z9~c=L?H z3{B*#(ILFTL}%kn_K)n|JGy&h|Imo=855XWM#o3CGGU|Owp%bo=355o6h@(AaU^&# zMf#m%U5LzlCZoHO!Qq<$G8}5d0pp{dU1&6ZaA=RGIXA;U6(xiA*zo|NA#=B#y3rpI za*UU3*{K}v|4z>xt`iG7zZLzplg~O3C#)x8rwJwDs__B;>{Gf15y3&|A|WYMAFs{b z#y!Q|ydYIOSzFki+{9f0;`eIO=%`9lHulx4LHGQ!1<<+cs|u0fyuy@5&m=k#oUklp z6!wIVlu7$8Kh@+kFD7=sxTU2hej%^hS=7E##2<|-OwOW;rYAWWGY2%v$e?cF8mhg# zo-Fwa5DJd(Wbjniv4w>b13QRxaltD6y&ewlfjBt5T%A&gXWX;OK=c~4n0F0Yg+l?9 z+Vp*jvZY#Fa!uUkl95aM%0*I}FZ3hX+H!GxjtzuLBvynU0e@?o?y?C!FR#0#gHKXT zDR%I=>`>f#!9^baHYn9;@PVO(t3=#Zaa)RUK@gR65J>`2X3(&jE9_GZea(=_ako~m;_9N@4~Vk;$SD=w$yJR4z70) z2~92z0&$w5@^hFkYCI4_a;T22LX^E1P4{>U z_W&Eb-jJR+2DJiJg@Twbphk?N7hd%WR}?^A0+p#Bgl} zg%PxwUy*c&SGUgn+XuvF`T*l*vc)dS%n+QZAZ>+!y01n0mR!^FpC^=t(Q3yhaI|gX z{$Dc3W@F}*^dji#GeyPcwA*k>ywO%XWKZ{$`K|b3OQIoNl93TF2QbbX#qd5um&ErWS9^n!ql#?#=Nv zM22hnOH+mVHQie=iiXDqP|vz@8uYFIKzm}J#kyf=tUAmIB&?!_%;FTY=u-flf(LyH zET{P3iBB<{sdL@kZrTx(J+--hwL_VtQEck`Ee>Uu!KkLrzld+=#_B1o(#ooE2Q2|EakuqFDX>Z8_LRGi7D49o6a=Y|S@h!1c?X%AlZ|c=Bjr zrs#%f{BV@7ve5YWq`%8&W#QWp95bg%diMppnq)DS^0(# z`q(*o9SMH0`77R5+TbQvNgCW%TAQWm=Qbh?LUoFdm-^CTiShAVbrI({)s4LXC+p-m zS3ztdENx>se%AJYCRNB%v$LMU_1aa2l*?m0%G|(JTw&@n)#JuXmNtj7$9b3T9tk@^ z&hstJsQZ^wVdrgC?kAaL=eEAfmgF-Kc-;!Y-uzz|coAy8U3#^^Qc+rLx!rVWNsHuS z`vsOyH1-`Wr(C{Pr8`VP*uz=B(DI*MzSfXmAipy%lv^sT|E1-ZA}c6s;{J=%C}r`_ z^X-wVGQW-DN-`-f3ALZ^WZtKtv@&3?kO8#kJDGPmaLx0(F9AfU43kvKFNg{+itIfF zrJ?x?qH+gZ(yAl_d_ff3RT3o`*9)S{c7{^o)L$5tE~B@0m6n8`%i&YkAqNmIj5;?l z&2gG#)yU%#c9uuiFN{{54Tq&|>FB^T!C8_c@m!<+4-B||1etE=uxuFFWekCehm{!nTXEL%D2pk!k z6EsJmRIZfoj#^#?M+iGTUv_uYeklnI!}2{*%l~1#QfNbizB(%GP_4Fh0NfK{6o>gZCfWrem5ZoULy9eH3K0HeeK(-*>D6IC3r z4uHKTI@bZ~0N85+u((osZ2%VMfyDr$!~xTnAzvGS=_}u_4Zvc6y*2>r!NOlStr0=7l5teCQJafDi3TGz$kIR^hEr<0hqp2aBl#% z3SjpJV5=*o*9Ty$^T1XEj1mV-Z+*W$0Mj$?uMfah1MKwy*cv{S5P+@81JlRsDRIE` zr12X9Fum9Ph5&30z}^sm@lp9V24HLR!1Qr=N*pjf-ulL<%h62F62CDz$I)ypz}^^u zb#VbF0PD&F>jD@h4p+-no)<2Vm>- zz}5qd5(jKOz}_5~c0It}9GG@Jz}_5yZK#xfBLLfw2etuVlsI4;0QMVUHa7t5H^OXg z0N8H?U}tf^CjdJu59};}QR0A|1+e=Au(JSme*ktC!0r#gHdab+3BWeyfo%jBB@Wm| zfW0LQb0fgs5{9`EU~dV)&aRXmhzh$*ot&Kqb~eB$alp>zj^YDRXTPfkum>V8WlIH} z4X_8Ir;nHl+Egk1W&pM+4{Q^_C~?3x0qi%U&TZCy6Tp5my37IF1hC%}Fey<~<%3bn z|LK(|dy3M7kuA8zQXBj0-;N40w96!H;j*+8x~1v-x1-fsN!xt}I^S|wpF$2Ge>+;^ zu3=d#y8rE{`vM_Gol5Dgk*(IQ4{BRF^dXJ^R;_rU51F4XC-h;~Ct0hrK6Kabtr07D z=;LisL1vum1CW*uedwOw+wy(LW#n=~ALcb8E7ymvM@fBHPUwRiDEzzm zKG?sLk?Z5_`T1awmJWTePbVWcj#l+yIiU}7=;Q7AKJ;km+w=4Bj{JPUsg@3XuyZFP z*GE}>SWf7J9Qt@iz7IWT`i}g3Jd~#ud}is;2Rm#s;%q+J)Q9DSKFFbuhaxr^X)9>; zP@Y!r%=dwzVd+p?#>PAIeYC3&%L#puLm%(V_t8!t@67k{uKavpe^@&7Asggfky*1& z20PS;<%B-Sp^tY(7`SOGX!WlAe7rk9ADAVU4z*>PygT0q_Y-|i=z|>kcz3=JnJw?u zd`Qi-^Cnr;@+V%+v{UyzLCv%?HNPJfoE6ya)QqLoy`|~?_k)^o8FX(s>fYx7^7n(9 zu`DF;_oMFfO?1@9A4CON^kr*6ZA*tfq-Opgr~oxLHDfuU52t4SAgBPV#8mx(Up)X@ zDZMu;^rn3P($b+1shRiY`!F?QIiU}yX5O3cLsx;{8+C6_$ML@WI2fd*LmyHz?+cmJWSL&AdO~hp8FM34J&<^ZtAvQZw(*kK+UR zalk8<4t+??d?4S4sTs=&eKQk$BwoY03;GY# z|4(OU7Nl2k-SO|9`)NksjD*lgLbFLT8tuXoAPKVwVfM{cPAY*s#1ARr5d7d2RBTtu zZ$@K-Ku#G+Xy1?klP5#U#<Hhk5pI(lJnP-|Ze3)@gmJ!3uGff#9W}a!*V}G+A3^Pt=85(Bx=OI8U`Y_|1 zEF*@Q{doxROvu>ZtjDv>dN9m5on>g4dA2FThZ*N&88OT}+mxZD(zB|EhM7)Z*Yic| z-_tOoh1c^1?go85J2cIKf``==zqdmT7(+yl4UFELHte+hx3qGuv)+?to)ygwa5c>* zA;Iv{aHLt{AnicWJH0MNr#?{h4_D$}D0m)RBajM^+vzMrBhU*?89o9zC(DQt=!K>X zg`jw$=+`z_RPn`ZVaWi}=`2Gd(2GTy#*0ONj6gEuO9f8* zTn|Pdr*m$NKrc0A_z2{jEF(ssmzpvZ_VJ~n-)F0sr>}jmu!WTjn%L_d}tvhWz1UM?opM%2UXFBkpGyqos)bsZ{NM^iV|lKxQs8ggQ)eYmh8uX|5)Q>RsT zrxAZR*F6~YMdwI-;sAL#*WFo|@Nm&T=yjKjBYEPYRB}6=WvDM6$!+Kv^uc#dmJxmN zNNz*Vgp4Ca|BzR)msmbU>pxNzXx6*YBL3K_2y_>&pt ztWBiG-xjU^EQ-Ou{?c|pegQCV2WY>RtztGuzDxK+1xLSB$E4!zH@NZa*GfHYHTunz zd3D6USk<%qubQ5`bWOR6+af0(XVBPu;c}?QOCbkmvJj`;8z0Q#m087k^b5+ovj2np zT914-zbz(eFI>?FvGQw$MdVH>+7mKf(1E1xuN5iq03=0UE2iSEW`6^c{{31(RM$Wv z@%6%VXh4a2iv=&4V~nup9Fyz7*XymqQdPBA_?Bj;UR4ji z19^5PQU9%C`b_^%5Xta&MeC#VpOA~|ciHv?;p=O^t%<&1pwJF7w1Z>_e!J+6C=ZYn zeY=<)p&B63?(Kq54YIw*?|Ub=Vg%oV%t*5RJGq__eD9syiV=M89krrdyp#0~((em9 zm0Y~g$o)OHAboIxl+y1O?TC-!G-|_$S6Q5axOa>63XwB_c(+LJ);I&@-!0hhnxcxA z)U@l5Mf<&CLKcGKzkRaky2Ss4${>gPAB*0_H3O;SIICu0u9L--a3p&Xq@FB@4WmD@ zGmv_+xZvVsG7#U_2PcfLP6nAxrYIWk*Tz>Td%u_+;W;LIJdyW{6q#hQy4(jvicA6p z5@bdyLHeLZQYZVMm>rQx$n0f#;7pxN-q6#zlTB79JDocj6a^uplR={X>DK-Jfiq@h^7;J(K z0!B)J4PwYIWJu2j*cSyGn@#}sMX^9$8EpgHWvw4ss5!(wi4j#rxrRW#3(bQ7nUp{t zLd`Xn)EokNjU{LK5Xft6aE{k`xUW5KX-{Fe2{sHEDFHT&n&Xz#90qLMXl*Gl4A{7_ zrx0r1ZLOaqHD~ceo!RxCYZl0NTiUId1u`jtJPYJ|tT#3_W`TTb;0&E1Z zdo$PwVE1OQ5y0-vV596M8UGVW8Et}%0!B)JjnW$T<<=Ml>^__7EBfwH!0xj+uF*Y* zohP#!9BfV#Yz|n!u>Nig{D!qHBACuPw;^nPPOqd81ua?ZKS8kzKUz29I}(AeaDyI_TC?ux88 zyQxxy+)n4*nkTKd&efF+pC`dtT*-)e(t7LBnS@ZJ&>*?qmR#M)Bt_O68>1C8imbQm zZmbm9VD@K~BFJ?*=hoU~gLQ7GWcbiQnw$R z%&MSKWMi}a9%w2;qSHCImP!va74fAKoLZ4sDm~CtL>u)KYbXLIvnptp)#yl@G`wnE zsJ_TQ*Xf*F%cf1%8LHaPmrZbdGdqg-H)oTjS-GP~kxj;|K6m>Gu86ZLXcXCGOowuh z-fU^{C3 z$1}mI+tF(pV znP64&(RRBn^ofBtzz(ykss`Znfzvs+P9W^C&ZU)%UQIsX)Y`&9#*U`8y^^}4sVy95 zHMH%OwmWRjrIogDJkwY#5@bCcde~vBudHml)7XE_gA>OaoX*(4e=OnEgcG{}T8%XLd&Z?B8 zN;~b!YpW{lGW&W}B@S6QopbA;#jfUun{}ddR#!4&A-T(XE~~Wl)#EO^y#8><8qrx5 zG>Yu9>u#zP*{zvewk-!VoX)v*NMm<%;9xD`oZ7ar*x22)Eg`Cv3GZnh_#=k3vvR*Z zOFdyXKHNs8CqoEtrH{@ z=rCl=SK(w<1x?fJHJ-}OAMSmIgFbg8POUhdbL-^FKI`;Xiu6el=VTdhkg?C$*R4t+ zW1rz)$TA*k%HS}I(>b>ev^><5F-=W-oX#?I&gJ2z zjOmi$oGb$lG9GTqm`mdJ1L){g{!>s#sgqRv|V z+z7U;j&L^Pz+-vTI-9YadOEE}avD=SmS>5<@GQ(5Ws1ZB(lb@17{(tn&Z4^vrofMz z-vJr0 z4gaL!)%*TU&wWY zZ{PMEE<;C*xO`pK51#(1mi48(zbgM5^NUmLBTKiZ%);dgg>I0c8zj0tC7*#bj{)H+ zo2n~WPNLgWHbXZ!goFv6&b5RB2{I$eSNe3WC8?e{)e;hDM#OX-t2|c z_xjZL4p=*)FhgO1=QTg|8hGC$HToW@$T?sfpGv7z_khg|hc>CmIbfrU*o{-GpyENZ zMS}y18gN^BV4&Lb;1$fQJ(-oWA`x=XdUgFnZLP!c2aVf;iA2ajBVP00`_-{S*1Bcz zn|e9mj(-}x^7izOsV=n;CByrs!t&&J_J8`GOm!nH+-FD5#U1qhsvt*^Ah3mt+L1get~hyBJ-{E)2(58fDRAF|cgL^hN@WHT;m?exbxV<%eeEvJ!0H@Q-OKlk`lP{z&(<2 z=Ye~~R{OlPdmgw)YTTn4cYa^{XvUon?$K<;B_(hdfqNq3E&}(2t&Y>9 zi@-f0TpY(7s(RI0f1v;0>{nL#hXy^!b$pza-`A(H?%Hu7KpnaEUfy|!b|o1zw1t>% zGJ6LmO0@nq+$E9+=~e4KTk|p}`P)0qM=xmfd(|dRVH)B2U9D+<;Pa&;8Poc@PFm}~ z(#K3Eflt~*?IM)zX?%p=%g(E5@ey`fpHrt1{hoEE`iw6a2zQP?!ifXqdq$S36!Vey zZ2Afx;(h*hN^3t20#KM4GDZwYhWJzYV*v@)DVrMmmXH|xl+B9q1QOs=HgavK6E~>D z84d5EGBA-qXIQ!()gyV%LTl$KpkBpuS#x3*otQ3Q=`}JO_ZhlAu-3<6xGsHsK1hb^ z(x>OcG-rqK*^ASdAZV2M(Bhy+VxWR^FkI#U`Ju%@k6SPmStIv#km2_VSx0Tb_ zDrl7W%sPG2G%--YIY`SKAU`w2SEUgDnawy?oooVXvh8K&l@~>B$Zpv}BofXT+9VQ< z&e)`jLm-B8ozB?gi&Q=37sty?9#A)`SS|$~rm1-@>#Y7}S#&#N!xwRr-P+Upx_(%; z{<$m$7mVJlX9@n#buisSPV*Hl4ANv-hwOh?@;}u^@N{hi-&NX=$_Ob7P4ZnOt1SJg zAo(M&DY>|#MYBk+k#nd~=1`+GWv|z$Vo@XK>5q{Ly7ktSle|WmNpD(H4#!b+^2y%g zW&2Y9&pS;97_sr}4F1^TW!iXl1}cx2)587f44PrQf z|6&h?S@Ea|%nSJIOiCryV6GEf#Z9cU%2ea!g7d$O;OeftILxc7R6j25-fUjKO7-Ki zduo`M%Z+RUmVO};^Tu7r#BuYc+mB+!e<^2@O3rih)|Vt<#(ybiM4h`!jbs-Az~uRWu$Ykk?;%wPL& zMz4-{M)FPXu~3bF7+q-RB!T*m5bKf6lt;F{1DN;~hjv z{ej*}B3?DYC2#vXw!HPZ)?JzP<-{4@X=kX@ZYb@6)M=qf-cWYyGHq8IQk`fcs|Ig= zr^x_ga?PNbHkhZ>R@(WWv*zz!$GrgC~5Rf41$HkHG( zdRAeUbNafrm90IPW$EZGck-MVhoQIt>G9gxsMSR0OJm^Zt$$0*@HFu04$rn+$#Yc6 z?WOHXm4qgFd#)s;D!C(9(rGflh)OzxO72i4Wfn2Wu(Mf0Un>}O32nLV%w{=95_V^^ zKw%chFbgDR*`3V-3D)jx7D&vpTV{z<27AlaLp;T%WyxZkVx?WAcI{q_yuD>QWw020 zQoO~x7lXd9xZ*Swc(lapq0dh+Fq(7puS*;t SA1!+#cCxehuRdCitoUEkiCaYg literal 0 HcmV?d00001 diff --git a/spec/support/protos/google_unittest_custom_options.pb.rb b/spec/support/protos/google_unittest_custom_options.pb.rb new file mode 100644 index 00000000..9d6b94f2 --- /dev/null +++ b/spec/support/protos/google_unittest_custom_options.pb.rb @@ -0,0 +1,252 @@ +# encoding: utf-8 + +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf' +require 'protobuf/rpc/service' + + +## +# Imports +# +require 'google/protobuf/descriptor.pb' + +module Protobuf_unittest + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } + + ## + # Enum Classes + # + class MethodOpt1 < ::Protobuf::Enum + define :METHODOPT1_VAL1, 1 + define :METHODOPT1_VAL2, 2 + end + + class AggregateEnum < ::Protobuf::Enum + define :VALUE, 1 + end + + + ## + # Message Classes + # + class TestMessageWithCustomOptions < ::Protobuf::Message + class AnEnum < ::Protobuf::Enum + define :ANENUM_VAL1, 1 + define :ANENUM_VAL2, 2 + end + + end + + class CustomOptionFooRequest < ::Protobuf::Message; end + class CustomOptionFooResponse < ::Protobuf::Message; end + class CustomOptionFooClientMessage < ::Protobuf::Message; end + class CustomOptionFooServerMessage < ::Protobuf::Message; end + class DummyMessageContainingEnum < ::Protobuf::Message + class TestEnumType < ::Protobuf::Enum + define :TEST_OPTION_ENUM_TYPE1, 22 + define :TEST_OPTION_ENUM_TYPE2, -23 + end + + end + + class DummyMessageInvalidAsOptionType < ::Protobuf::Message; end + class CustomOptionMinIntegerValues < ::Protobuf::Message; end + class CustomOptionMaxIntegerValues < ::Protobuf::Message; end + class CustomOptionOtherValues < ::Protobuf::Message; end + class SettingRealsFromPositiveInts < ::Protobuf::Message; end + class SettingRealsFromNegativeInts < ::Protobuf::Message; end + class ComplexOptionType1 < ::Protobuf::Message; end + class ComplexOptionType2 < ::Protobuf::Message + class ComplexOptionType4 < ::Protobuf::Message; end + + end + + class ComplexOptionType3 < ::Protobuf::Message; end + class VariousComplexOptions < ::Protobuf::Message; end + class AggregateMessageSet < ::Protobuf::Message; end + class AggregateMessageSetElement < ::Protobuf::Message; end + class Aggregate < ::Protobuf::Message; end + class AggregateMessage < ::Protobuf::Message; end + class NestedOptionType < ::Protobuf::Message + class NestedEnum < ::Protobuf::Enum + define :NESTED_ENUM_VALUE, 1 + end + + class NestedMessage < ::Protobuf::Message; end + + end + + class OldOptionType < ::Protobuf::Message + class TestEnum < ::Protobuf::Enum + define :OLD_VALUE, 0 + end + + end + + class NewOptionType < ::Protobuf::Message + class TestEnum < ::Protobuf::Enum + define :OLD_VALUE, 0 + define :NEW_VALUE, 1 + end + + end + + class TestMessageWithRequiredEnumOption < ::Protobuf::Message; end + + + ## + # Message Fields + # + class TestMessageWithCustomOptions + optional :string, :field1, 1 + end + + class ComplexOptionType1 + optional :int32, :foo, 1 + optional :int32, :foo2, 2 + optional :int32, :foo3, 3 + repeated :int32, :foo4, 4 + # Extension Fields + extensions 100...536870912 + optional :int32, :".protobuf_unittest.quux", 7663707, :extension => true + optional ::Protobuf_unittest::ComplexOptionType3, :".protobuf_unittest.corge", 7663442, :extension => true + end + + class ComplexOptionType2 + class ComplexOptionType4 + optional :int32, :waldo, 1 + end + + optional ::Protobuf_unittest::ComplexOptionType1, :bar, 1 + optional :int32, :baz, 2 + optional ::Protobuf_unittest::ComplexOptionType2::ComplexOptionType4, :fred, 3 + repeated ::Protobuf_unittest::ComplexOptionType2::ComplexOptionType4, :barney, 4 + # Extension Fields + extensions 100...536870912 + optional :int32, :".protobuf_unittest.grault", 7650927, :extension => true + optional ::Protobuf_unittest::ComplexOptionType1, :".protobuf_unittest.garply", 7649992, :extension => true + end + + class ComplexOptionType3 + optional :int32, :qux, 1 + end + + class AggregateMessageSet + # Extension Fields + extensions 4...536870912 + optional ::Protobuf_unittest::AggregateMessageSetElement, :".protobuf_unittest.AggregateMessageSetElement.message_set_extension", 15447542, :extension => true + end + + class AggregateMessageSetElement + optional :string, :s, 1 + end + + class Aggregate + optional :int32, :i, 1 + optional :string, :s, 2 + optional ::Protobuf_unittest::Aggregate, :sub, 3 + optional ::Google::Protobuf::FileOptions, :file, 4 + optional ::Protobuf_unittest::AggregateMessageSet, :mset, 5 + end + + class AggregateMessage + optional :int32, :fieldname, 1 + end + + class NestedOptionType + class NestedMessage + optional :int32, :nested_field, 1 + end + + end + + class OldOptionType + required ::Protobuf_unittest::OldOptionType::TestEnum, :value, 1 + end + + class NewOptionType + required ::Protobuf_unittest::NewOptionType::TestEnum, :value, 1 + end + + + ## + # Extended Message Fields + # + class ::Google::Protobuf::FileOptions < ::Protobuf::Message + optional :uint64, :".protobuf_unittest.file_opt1", 7736974, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.fileopt", 15478479, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.Aggregate.nested", 15476903, :extension => true + optional :int32, :".protobuf_unittest.NestedOptionType.nested_extension", 7912573, :extension => true + end + + class ::Google::Protobuf::MessageOptions < ::Protobuf::Message + optional :int32, :".protobuf_unittest.message_opt1", 7739036, :extension => true + optional :bool, :".protobuf_unittest.bool_opt", 7706090, :extension => true + optional :int32, :".protobuf_unittest.int32_opt", 7705709, :extension => true + optional :int64, :".protobuf_unittest.int64_opt", 7705542, :extension => true + optional :uint32, :".protobuf_unittest.uint32_opt", 7704880, :extension => true + optional :uint64, :".protobuf_unittest.uint64_opt", 7702367, :extension => true + optional :sint32, :".protobuf_unittest.sint32_opt", 7701568, :extension => true + optional :sint64, :".protobuf_unittest.sint64_opt", 7700863, :extension => true + optional :fixed32, :".protobuf_unittest.fixed32_opt", 7700307, :extension => true + optional :fixed64, :".protobuf_unittest.fixed64_opt", 7700194, :extension => true + optional :sfixed32, :".protobuf_unittest.sfixed32_opt", 7698645, :extension => true + optional :sfixed64, :".protobuf_unittest.sfixed64_opt", 7685475, :extension => true + optional :float, :".protobuf_unittest.float_opt", 7675390, :extension => true + optional :double, :".protobuf_unittest.double_opt", 7673293, :extension => true + optional :string, :".protobuf_unittest.string_opt", 7673285, :extension => true + optional :bytes, :".protobuf_unittest.bytes_opt", 7673238, :extension => true + optional ::Protobuf_unittest::DummyMessageContainingEnum::TestEnumType, :".protobuf_unittest.enum_opt", 7673233, :extension => true + optional ::Protobuf_unittest::DummyMessageInvalidAsOptionType, :".protobuf_unittest.message_type_opt", 7665967, :extension => true + optional ::Protobuf_unittest::ComplexOptionType1, :".protobuf_unittest.complex_opt1", 7646756, :extension => true + optional ::Protobuf_unittest::ComplexOptionType2, :".protobuf_unittest.complex_opt2", 7636949, :extension => true + optional ::Protobuf_unittest::ComplexOptionType3, :".protobuf_unittest.complex_opt3", 7636463, :extension => true + repeated :int32, :".protobuf_unittest.repeated_opt1", 7636464, :extension => true + repeated ::Protobuf_unittest::ComplexOptionType3, :".protobuf_unittest.repeated_opt2", 7636465, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.msgopt", 15480088, :extension => true + optional ::Protobuf_unittest::OldOptionType, :".protobuf_unittest.required_enum_opt", 106161807, :extension => true + optional ::Protobuf_unittest::ComplexOptionType2::ComplexOptionType4, :".protobuf_unittest.ComplexOptionType2.ComplexOptionType4.complex_opt4", 7633546, :extension => true + end + + class ::Google::Protobuf::FieldOptions < ::Protobuf::Message + optional :fixed64, :".protobuf_unittest.field_opt1", 7740936, :extension => true + optional :int32, :".protobuf_unittest.field_opt2", 7753913, :default => 42, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.fieldopt", 15481374, :extension => true + end + + class ::Google::Protobuf::EnumOptions < ::Protobuf::Message + optional :sfixed32, :".protobuf_unittest.enum_opt1", 7753576, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.enumopt", 15483218, :extension => true + end + + class ::Google::Protobuf::EnumValueOptions < ::Protobuf::Message + optional :int32, :".protobuf_unittest.enum_value_opt1", 1560678, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.enumvalopt", 15486921, :extension => true + end + + class ::Google::Protobuf::ServiceOptions < ::Protobuf::Message + optional :sint64, :".protobuf_unittest.service_opt1", 7887650, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.serviceopt", 15497145, :extension => true + end + + class ::Google::Protobuf::MethodOptions < ::Protobuf::Message + optional ::Protobuf_unittest::MethodOpt1, :".protobuf_unittest.method_opt1", 7890860, :extension => true + optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.methodopt", 15512713, :extension => true + end + + + ## + # Service Classes + # + class TestServiceWithCustomOptions < ::Protobuf::Rpc::Service + rpc :foo, ::Protobuf_unittest::CustomOptionFooRequest, ::Protobuf_unittest::CustomOptionFooResponse + end + + class AggregateService < ::Protobuf::Rpc::Service + rpc :method, ::Protobuf_unittest::AggregateMessage, ::Protobuf_unittest::AggregateMessage + end + +end + diff --git a/spec/support/protos/google_unittest_custom_options.proto b/spec/support/protos/google_unittest_custom_options.proto new file mode 100644 index 00000000..08fd9ed1 --- /dev/null +++ b/spec/support/protos/google_unittest_custom_options.proto @@ -0,0 +1,424 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: benjy@google.com (Benjy Weinberger) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// A proto file used to test the "custom options" feature of google.protobuf. + +syntax = "proto2"; + +// Some generic_services option(s) added automatically. +// See: http://go/proto2-generic-services-default +option cc_generic_services = true; // auto-added +option java_generic_services = true; // auto-added +option py_generic_services = true; + +// A custom file option (defined below). +option (file_opt1) = 9876543210; + +import "google/protobuf/descriptor.proto"; + +// We don't put this in a package within proto2 because we need to make sure +// that the generated code doesn't depend on being in the proto2 namespace. +package protobuf_unittest; + + +// Some simple test custom options of various types. + +extend google.protobuf.FileOptions { + optional uint64 file_opt1 = 7736974; +} + +extend google.protobuf.MessageOptions { + optional int32 message_opt1 = 7739036; +} + +extend google.protobuf.FieldOptions { + optional fixed64 field_opt1 = 7740936; + // This is useful for testing that we correctly register default values for + // extension options. + optional int32 field_opt2 = 7753913 [default=42]; +} + +extend google.protobuf.EnumOptions { + optional sfixed32 enum_opt1 = 7753576; +} + +extend google.protobuf.EnumValueOptions { + optional int32 enum_value_opt1 = 1560678; +} + +extend google.protobuf.ServiceOptions { + optional sint64 service_opt1 = 7887650; +} + +enum MethodOpt1 { + METHODOPT1_VAL1 = 1; + METHODOPT1_VAL2 = 2; +} + +extend google.protobuf.MethodOptions { + optional MethodOpt1 method_opt1 = 7890860; +} + +// A test message with custom options at all possible locations (and also some +// regular options, to make sure they interact nicely). +message TestMessageWithCustomOptions { + option message_set_wire_format = false; + + option (message_opt1) = -56; + + optional string field1 = 1 [ctype=CORD, + (field_opt1)=8765432109]; + + enum AnEnum { + option (enum_opt1) = -789; + + ANENUM_VAL1 = 1; + ANENUM_VAL2 = 2 [(enum_value_opt1) = 123]; + } +} + + +// A test RPC service with custom options at all possible locations (and also +// some regular options, to make sure they interact nicely). +message CustomOptionFooRequest { +} + +message CustomOptionFooResponse { +} + +message CustomOptionFooClientMessage { +} + +message CustomOptionFooServerMessage { +} + +service TestServiceWithCustomOptions { + option (service_opt1) = -9876543210; + + rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) { + option (method_opt1) = METHODOPT1_VAL2; + } +} + + + +// Options of every possible field type, so we can test them all exhaustively. + +message DummyMessageContainingEnum { + enum TestEnumType { + TEST_OPTION_ENUM_TYPE1 = 22; + TEST_OPTION_ENUM_TYPE2 = -23; + } +} + +message DummyMessageInvalidAsOptionType { +} + +extend google.protobuf.MessageOptions { + optional bool bool_opt = 7706090; + optional int32 int32_opt = 7705709; + optional int64 int64_opt = 7705542; + optional uint32 uint32_opt = 7704880; + optional uint64 uint64_opt = 7702367; + optional sint32 sint32_opt = 7701568; + optional sint64 sint64_opt = 7700863; + optional fixed32 fixed32_opt = 7700307; + optional fixed64 fixed64_opt = 7700194; + optional sfixed32 sfixed32_opt = 7698645; + optional sfixed64 sfixed64_opt = 7685475; + optional float float_opt = 7675390; + optional double double_opt = 7673293; + optional string string_opt = 7673285; + optional bytes bytes_opt = 7673238; + optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233; + optional DummyMessageInvalidAsOptionType message_type_opt = 7665967; +} + +message CustomOptionMinIntegerValues { + option (bool_opt) = false; + option (int32_opt) = -0x80000000; + option (int64_opt) = -0x8000000000000000; + option (uint32_opt) = 0; + option (uint64_opt) = 0; + option (sint32_opt) = -0x80000000; + option (sint64_opt) = -0x8000000000000000; + option (fixed32_opt) = 0; + option (fixed64_opt) = 0; + option (sfixed32_opt) = -0x80000000; + option (sfixed64_opt) = -0x8000000000000000; +} + +message CustomOptionMaxIntegerValues { + option (bool_opt) = true; + option (int32_opt) = 0x7FFFFFFF; + option (int64_opt) = 0x7FFFFFFFFFFFFFFF; + option (uint32_opt) = 0xFFFFFFFF; + option (uint64_opt) = 0xFFFFFFFFFFFFFFFF; + option (sint32_opt) = 0x7FFFFFFF; + option (sint64_opt) = 0x7FFFFFFFFFFFFFFF; + option (fixed32_opt) = 0xFFFFFFFF; + option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF; + option (sfixed32_opt) = 0x7FFFFFFF; + option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF; +} + +message CustomOptionOtherValues { + option (int32_opt) = -100; // To test sign-extension. + option (float_opt) = 12.3456789; + option (double_opt) = 1.234567890123456789; + option (string_opt) = "Hello, \"World\""; + option (bytes_opt) = "Hello\0World"; + option (enum_opt) = TEST_OPTION_ENUM_TYPE2; +} + +message SettingRealsFromPositiveInts { + option (float_opt) = 12; + option (double_opt) = 154; +} + +message SettingRealsFromNegativeInts { + option (float_opt) = -12; + option (double_opt) = -154; +} + +// Options of complex message types, themselves combined and extended in +// various ways. + +// TODO: do we want to support packed ints? +// e.g.: repeated int32 foo4 = 4 [packed = true]; +message ComplexOptionType1 { + optional int32 foo = 1; + optional int32 foo2 = 2; + optional int32 foo3 = 3; + repeated int32 foo4 = 4; + + extensions 100 to max; +} + +message ComplexOptionType2 { + optional ComplexOptionType1 bar = 1; + optional int32 baz = 2; + + message ComplexOptionType4 { + optional int32 waldo = 1; + + extend google.protobuf.MessageOptions { + optional ComplexOptionType4 complex_opt4 = 7633546; + } + } + + optional ComplexOptionType4 fred = 3; + repeated ComplexOptionType4 barney = 4; + + extensions 100 to max; +} + +message ComplexOptionType3 { + optional int32 qux = 1; +} + +extend ComplexOptionType1 { + optional int32 quux = 7663707; + optional ComplexOptionType3 corge = 7663442; +} + +extend ComplexOptionType2 { + optional int32 grault = 7650927; + optional ComplexOptionType1 garply = 7649992; +} + +extend google.protobuf.MessageOptions { + optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756; + optional ComplexOptionType2 complex_opt2 = 7636949; + optional ComplexOptionType3 complex_opt3 = 7636463; + repeated int32 repeated_opt1 = 7636464; + repeated protobuf_unittest.ComplexOptionType3 repeated_opt2 = 7636465; +} + +// Note that we try various different ways of naming the same extension. +message VariousComplexOptions { + option (.protobuf_unittest.complex_opt1).foo = 42; + option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324; + option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876; + option (protobuf_unittest.complex_opt1).foo4 = 99; + option (protobuf_unittest.complex_opt1).foo4 = 88; + option (complex_opt2).baz = 987; + option (complex_opt2).(grault) = 654; + option (complex_opt2).bar.foo = 743; + option (complex_opt2).bar.(quux) = 1999; + option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008; + option (complex_opt2).(garply).foo = 741; + option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998; + option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121; + option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971; + option (complex_opt2).fred.waldo = 321; + option (complex_opt2).barney = { waldo: 101 }; + option (complex_opt2).barney = { waldo: 212 }; + option (protobuf_unittest.complex_opt3).qux = 9; + option (repeated_opt1) = 1; + option (repeated_opt1) = 2; + option (repeated_opt2) = { qux: 3 }; + option (repeated_opt2) = { qux: 4 }; + /*option (complex_opt3).complexoptiontype5.plugh = 22;*/ + /*option (complexopt6).xyzzy = 24;*/ +} + +// ------------------------------------------------------ +// Definitions for testing aggregate option parsing. +// See descriptor_unittest.cc. + +message AggregateMessageSet { + option message_set_wire_format = false; + extensions 4 to max; +} + +message AggregateMessageSetElement { + extend AggregateMessageSet { + optional AggregateMessageSetElement message_set_extension = 15447542; + } + optional string s = 1; +} + +// A helper type used to test aggregate option parsing +message Aggregate { + optional int32 i = 1; + optional string s = 2; + + // A nested object + optional Aggregate sub = 3; + + // To test the parsing of extensions inside aggregate values + optional google.protobuf.FileOptions file = 4; + extend google.protobuf.FileOptions { + optional Aggregate nested = 15476903; + } + + // An embedded message set + optional AggregateMessageSet mset = 5; +} + +// Allow Aggregate to be used as an option at all possible locations +// in the .proto grammer. +extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; } +extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; } +extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; } +extend google.protobuf.EnumOptions { optional Aggregate enumopt = 15483218; } +extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; } +extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; } +extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; } + +// Try using AggregateOption at different points in the proto grammar +option (fileopt) = { + s: 'FileAnnotation' + // Also test the handling of comments + /* of both types */ i: 100 + + sub { s: 'NestedFileAnnotation' } + + // Include a google.protobuf.FileOptions and recursively extend it with + // another fileopt. + file { + [protobuf_unittest.fileopt] { + s:'FileExtensionAnnotation' + } + } + + // A message set inside an option value + mset { + [protobuf_unittest.AggregateMessageSetElement.message_set_extension] { + s: 'EmbeddedMessageSetElement' + } + } +}; + +message AggregateMessage { + option (msgopt) = { i:101 s:'MessageAnnotation' }; + optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }]; +} + +service AggregateService { + option (serviceopt) = { s:'ServiceAnnotation' }; + rpc Method (AggregateMessage) returns (AggregateMessage) { + option (methodopt) = { s:'MethodAnnotation' }; + } +} + +enum AggregateEnum { + option (enumopt) = { s:'EnumAnnotation' }; + // TODO: support enum value options + VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }]; +} + +// Test custom options for nested type. +message NestedOptionType { + message NestedMessage { + option (message_opt1) = 1001; + optional int32 nested_field = 1 [(field_opt1) = 1002]; + } + enum NestedEnum { + option (enum_opt1) = 1003; + // TODO: support enum value options + NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004]; + } + extend google.protobuf.FileOptions { + optional int32 nested_extension = 7912573 [(field_opt2) = 1005]; + } +} + +// Custom message option that has a required enum field. +// WARNING: this is strongly discouraged! +message OldOptionType { + enum TestEnum { + OLD_VALUE = 0; + } + required TestEnum value = 1; +} + +// Updated version of the custom option above. +message NewOptionType { + enum TestEnum { + OLD_VALUE = 0; + NEW_VALUE = 1; + } + required TestEnum value = 1; +} + +extend google.protobuf.MessageOptions { + optional OldOptionType required_enum_opt = 106161807; +} + +// Test message using the "required_enum_opt" option defined above. +message TestMessageWithRequiredEnumOption { + option (required_enum_opt) = { value: OLD_VALUE }; +} From 863fcf860226d700997105b5c2b5524bab52aef5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 10 Feb 2017 14:24:34 -0700 Subject: [PATCH 1019/1191] fix specs and connector loaders to load correct connectors and reset them --- lib/protobuf/socket.rb | 2 ++ lib/protobuf/zmq.rb | 2 ++ spec/lib/protobuf_spec.rb | 1 + 3 files changed, 5 insertions(+) diff --git a/lib/protobuf/socket.rb b/lib/protobuf/socket.rb index a8feb2fe..44394547 100644 --- a/lib/protobuf/socket.rb +++ b/lib/protobuf/socket.rb @@ -19,3 +19,5 @@ require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/connectors/socket' + +::Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Socket diff --git a/lib/protobuf/zmq.rb b/lib/protobuf/zmq.rb index e2adbf5e..89b0ee87 100644 --- a/lib/protobuf/zmq.rb +++ b/lib/protobuf/zmq.rb @@ -19,3 +19,5 @@ require 'ffi-rzmq' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/connectors/zmq' + +Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Zmq diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 77f48e6f..5d630b1e 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -36,6 +36,7 @@ describe '.connector_type_class' do it "defaults to Socket" do + described_class.connector_type_class = nil expect(described_class.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Socket) end end From 64b0098b20a3a19aaab6dd566e0245d32ca03b9c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 10 Feb 2017 18:26:09 -0700 Subject: [PATCH 1020/1191] add specs for server and client extensions --- lib/protobuf.rb | 18 -------------- lib/protobuf/cli.rb | 13 ++++------ lib/protobuf/rpc/servers/socket_runner.rb | 4 ++++ lib/protobuf/rpc/servers/zmq_runner.rb | 4 ++++ lib/protobuf/socket.rb | 2 -- lib/protobuf/zmq.rb | 2 -- spec/lib/protobuf/cli_spec.rb | 29 +++++++++++++++-------- spec/lib/protobuf_spec.rb | 28 ++++++++++------------ 8 files changed, 44 insertions(+), 56 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 3c724412..68337a91 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -49,20 +49,6 @@ def self.client_host @client_host ||= Socket.gethostname end - # Connector Type - # - # Default: socket - # - # Symbol value which denotes the type of connector to use - # during client requests to an RPC server. - def self.connector_type - @connector_type ||= DEFAULT_CONNECTOR - end - - def self.connector_type=(type) - @connector_type = type - end - def self.connector_type_class @connector_type_class ||= ::Protobuf::Rpc::Connectors::Socket end @@ -122,10 +108,6 @@ def self.ignore_unknown_fields=(value) ::Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Socket end else - $stderr.puts <<-WARN - [INFO] Attempting require on an extension connector type '#{env_connector_type}'. - WARN - require "#{env_connector_type}" classified = env_connector_type.classify ::Protobuf.connector_type_class = classified.constantize diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 2d768a13..db0b5d6e 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -124,18 +124,13 @@ def configure_runner_mode :zmq else case server_type - when nil, /socket/i + when nil, /\Asocket[[:space:]]*\z/i :socket - when /zmq/i + when /\Azmq[[:space:]]*\z/i :zmq else - begin - require "#{server_type}" - server_type - rescue LoadError - say "WARNING: Could not load 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow - :socket - end + require "#{server_type}" + server_type end end end diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 881daa4c..5be7ae59 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -36,3 +36,7 @@ def stop end end end + +module ::Protobuf::Rpc::Servers # bad file namespacing + SocketRunner = ::Protobuf::Rpc::SocketRunner +end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 50f26a15..ed2dff5a 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -60,3 +60,7 @@ def register_signals end end end + +module ::Protobuf::Rpc::Servers # bad file namespacing + ZmqRunner = ::Protobuf::Rpc::ZmqRunner +end diff --git a/lib/protobuf/socket.rb b/lib/protobuf/socket.rb index 44394547..6bc49e7e 100644 --- a/lib/protobuf/socket.rb +++ b/lib/protobuf/socket.rb @@ -15,8 +15,6 @@ # gem 'protobuf', :require => 'protobuf/socket' # require 'protobuf' -::Protobuf.connector_type = :socket - require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/connectors/socket' diff --git a/lib/protobuf/zmq.rb b/lib/protobuf/zmq.rb index 89b0ee87..e469c8c8 100644 --- a/lib/protobuf/zmq.rb +++ b/lib/protobuf/zmq.rb @@ -14,8 +14,6 @@ # gem 'protobuf', :require => 'protobuf/zmq' # require 'protobuf' -Protobuf.connector_type = :zmq - require 'ffi-rzmq' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/connectors/zmq' diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 0ff3a36e..99fdb960 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -170,6 +170,25 @@ context 'run modes' do + context "extension" do + let(:runner) { ::Protobuf::Rpc::Servers::SocketRunner } + + it "loads the runner specified by PB_SERVER_TYPE" do + ENV['PB_SERVER_TYPE'] = "protobuf/rpc/servers/socket_runner" + expect(runner).to receive(:new).and_return(sock_runner) + described_class.start(args) + ENV.delete('PB_SERVER_TYPE') + end + + context "without extension loaded" do + it "will throw a LoadError when extension is not loaded" do + ENV['PB_SERVER_TYPE'] = "socket_to_load" + expect { described_class.start(args) }.to raise_error(LoadError, /socket_to_load/) + ENV.delete("PB_SERVER_TYPE") + end + end + end + context 'socket' do let(:test_args) { ['--socket'] } let(:runner) { ::Protobuf::Rpc::SocketRunner } @@ -189,11 +208,6 @@ described_class.start(args) ENV.delete('PB_SERVER_TYPE') end - - it 'configures the connector type to be socket' do - load "protobuf/socket.rb" - expect(::Protobuf.connector_type).to eq(:socket) - end end context 'zmq workers only' do @@ -259,11 +273,6 @@ described_class.start(args) ENV.delete('PB_SERVER_TYPE') end - - it 'configures the connector type to be zmq' do - load "protobuf/zmq.rb" - expect(::Protobuf.connector_type).to eq(:zmq) - end end end diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 5d630b1e..f55e4358 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -19,26 +19,24 @@ end end - describe '.connector_type' do - before { described_class.instance_variable_set(:@connector_type, nil) } - - it 'defaults to socket' do - expect(described_class.connector_type).to eq :socket - end - - it 'accepts socket or zmq' do - [:socket, :zmq].each do |type| - described_class.connector_type = type - expect(described_class.connector_type).to eq type - end - end - end - describe '.connector_type_class' do it "defaults to Socket" do described_class.connector_type_class = nil expect(described_class.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Socket) end + + it 'fails if fails to load the PB_CLIENT_TYPE' do + ENV['PB_CLIENT_TYPE'] = "something_to_autoload" + expect { load 'protobuf.rb' }.to raise_error(LoadError, /something_to_autoload/) + ENV.delete('PB_CLIENT_TYPE') + end + + it 'loads the connector type class from PB_CLIENT_TYPE' do + ENV['PB_CLIENT_TYPE'] = "protobuf/rpc/connectors/zmq" + load 'protobuf.rb' + expect(::Protobuf.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Zmq) + ENV.delete('PB_CLIENT_TYPE') + end end describe '.gc_pause_server_request?' do From ee058dcbb1725271e2c8f7f8ee86b0ac0fcb26b6 Mon Sep 17 00:00:00 2001 From: Embark Date: Fri, 10 Feb 2017 20:48:01 -0800 Subject: [PATCH 1021/1191] Don't turn range into an array If there is a sparse enum (tags ranging from -(very-low-number) to +(very-high-number)), then you're going to use up all your memory allocating integers. --- lib/protobuf/generators/base.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index e2f5ff5d..6e7304c5 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -15,16 +15,10 @@ def self.validate_tags(type_name, tags) end unless ENV.key?('PB_NO_TAG_WARNINGS') - range = (tags.min)..(tags.max) - if range.respond_to?(:size) - expected_size = range.size - else - expected_size = range.to_a.size - end - + expected_size = tags.max - tags.min + 1 if tags.size < expected_size ::Protobuf::CodeGenerator.print_tag_warning_suppress - ::Protobuf::CodeGenerator.warn("#{type_name} object should have #{expected_size} tags (#{range.begin}..#{range.end}), but found #{tags.size} tags.") + ::Protobuf::CodeGenerator.warn("#{type_name} object should have #{expected_size} tags (#{tags.min}..#{tags.max}), but found #{tags.size} tags.") end end end From 44fef9a424ed81b2eb31bb0a51ea46d4e0418ea6 Mon Sep 17 00:00:00 2001 From: Embark Date: Fri, 10 Feb 2017 20:49:34 -0800 Subject: [PATCH 1022/1191] Test newer jruby Travis was testing 1.7.19 by default, which is very old. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 44ff5447..3c6b3d87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,8 @@ rvm: - 2.2 - 2.2.2 - 2.3 - - jruby + - jruby-1.7 + - jruby-9.1.7.0 - rbx-2 env: - PROTOBUF_VERSION=2.6.1 From 9e297d284f0cf4c1c8cbff6d27b4a746c2dc0667 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 11 Feb 2017 10:08:40 -0700 Subject: [PATCH 1023/1191] compat with rubocop and master and style fixes --- .rubocop.yml | 2 +- lib/protobuf.rb | 2 +- lib/protobuf/cli.rb | 2 +- lib/protobuf/rpc/servers/socket_runner.rb | 8 ++++++-- lib/protobuf/rpc/servers/zmq_runner.rb | 8 ++++++-- protobuf.gemspec | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d8e7f963..1ed3b0d4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,7 +56,7 @@ Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' -Style/TrailingCommaInLiteral: +Style/TrailingComma: EnforcedStyleForMultiline: comma Style/TrivialAccessors: diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 68337a91..834faf95 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -96,7 +96,7 @@ def self.ignore_unknown_fields=(value) env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') do ::Protobuf::DEFAULT_CONNECTOR end - + symbolized_connector_type = env_connector_type.to_s.downcase.strip.to_sym if ::Protobuf::CONNECTORS.include?(symbolized_connector_type) require "protobuf/#{symbolized_connector_type}" diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index db0b5d6e..1a7bbecd 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -210,7 +210,7 @@ def say_and_exit(message, exception = nil) end def create_extension_server_runner - classified = self.mode.classify + classified = mode.classify extension_server_class = classified.constantize self.runner = extension_server_class.new(runner_options) diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 5be7ae59..8d36182d 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -37,6 +37,10 @@ def stop end end -module ::Protobuf::Rpc::Servers # bad file namespacing - SocketRunner = ::Protobuf::Rpc::SocketRunner +module Protobuf + module Rpc + module Servers # bad file namespacing + SocketRunner = ::Protobuf::Rpc::SocketRunner + end + end end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index ed2dff5a..bfab6738 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -61,6 +61,10 @@ def register_signals end end -module ::Protobuf::Rpc::Servers # bad file namespacing - ZmqRunner = ::Protobuf::Rpc::ZmqRunner +module Protobuf + module Rpc + module Servers # bad file namespacing + ZmqRunner = ::Protobuf::Rpc::ZmqRunner + end + end end diff --git a/protobuf.gemspec b/protobuf.gemspec index e86d5523..5bbfb621 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -29,7 +29,7 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses s.add_development_dependency 'rspec', '>= 3.0' - s.add_development_dependency "rubocop" + s.add_development_dependency "rubocop", "~> 0.35.0" s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984 s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' From 8f4786e2282833ee507d8516713dc5bb4a2a80da Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 11 Feb 2017 10:12:42 -0700 Subject: [PATCH 1024/1191] remove connector class --- lib/protobuf/rpc/client.rb | 1 - lib/protobuf/rpc/connector.rb | 9 --------- spec/lib/protobuf/rpc/connector_spec.rb | 7 ------- 3 files changed, 17 deletions(-) delete mode 100644 lib/protobuf/rpc/connector.rb delete mode 100644 spec/lib/protobuf/rpc/connector_spec.rb diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 2732b696..42184058 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -2,7 +2,6 @@ require 'protobuf' require 'protobuf/logging' require 'protobuf/rpc/error' -require 'protobuf/rpc/connector' module Protobuf module Rpc diff --git a/lib/protobuf/rpc/connector.rb b/lib/protobuf/rpc/connector.rb deleted file mode 100644 index 8f1d6912..00000000 --- a/lib/protobuf/rpc/connector.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'protobuf' - -module Protobuf - module Rpc - class Connector - - end - end -end diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb deleted file mode 100644 index 6b46c0ce..00000000 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' -require 'protobuf/socket' -require 'protobuf/zmq' - -RSpec.describe ::Protobuf::Rpc::Connector do - -end From f3680c38779d711368591942be81955a1c83d8b0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 11 Feb 2017 12:24:21 -0700 Subject: [PATCH 1025/1191] remove constants that are not necessary as we move to extension mechanism --- lib/protobuf.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 834faf95..b39108c7 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -30,12 +30,6 @@ module Protobuf - # See Protobuf#connector_type documentation. - CONNECTORS = [:socket, :zmq].freeze - - # Default is Socket as it has no external dependencies. - DEFAULT_CONNECTOR = :socket - class << self # Client Host # @@ -94,11 +88,11 @@ def self.ignore_unknown_fields=(value) require 'protobuf/rpc/service' env_connector_type = ENV.fetch('http://github.com/PB_CLIENT_TYPE') do - ::Protobuf::DEFAULT_CONNECTOR + :socket end symbolized_connector_type = env_connector_type.to_s.downcase.strip.to_sym - if ::Protobuf::CONNECTORS.include?(symbolized_connector_type) + if [:zmq, :socket].include?(symbolized_connector_type) require "protobuf/#{symbolized_connector_type}" case symbolized_connector_type From 46944653e441817a86903484f93e50f7076af0c0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 12 Feb 2017 10:17:58 -0700 Subject: [PATCH 1026/1191] remove idea of "including" Common into connectors and consolidate all into the Base class and add the close_connection interface to base (which is required) --- lib/protobuf/rpc/client.rb | 29 +-- lib/protobuf/rpc/connectors/base.rb | 172 ++++++++++++++++- lib/protobuf/rpc/connectors/common.rb | 176 ------------------ lib/protobuf/rpc/connectors/socket.rb | 7 +- lib/protobuf/rpc/connectors/zmq.rb | 1 - spec/lib/protobuf/rpc/connectors/base_spec.rb | 151 +++++++++++++++ .../protobuf/rpc/connectors/common_spec.rb | 170 ----------------- .../protobuf/rpc/connectors/socket_spec.rb | 2 - 8 files changed, 325 insertions(+), 383 deletions(-) delete mode 100644 lib/protobuf/rpc/connectors/common.rb delete mode 100644 spec/lib/protobuf/rpc/connectors/common_spec.rb diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 42184058..74791d23 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -9,7 +9,7 @@ class Client extend Forwardable include Protobuf::Logging - def_delegators :@connector, :options, :complete_cb, :success_cb, :failure_cb + def_delegators :@connector, :options, :complete_cb, :success_cb, :failure_cb, :send_request attr_reader :connector # Create a new client with default options (defined in ClientConnection) @@ -133,33 +133,6 @@ def method_missing(method_name, *params) end end - # Send the request to the service. - # This method is usually never called directly - # but is invoked by method_missing (see docs above). - # - # request = WidgetFindRequest.new - # client = Client.new({ - # :service => WidgetService, - # :method => "find", - # :request_type => "WidgetFindRequest", - # :response_type => "WidgetList", - # :request => request - # }) - # - # client.on_success do |res| - # res.widgets.each{|w| puts w.inspect } - # end - # - # client.on_failure do |err| - # puts err.message - # end - # - # client.send_request - # - def send_request - @connector.send_request - end - end ActiveSupport.run_load_hooks(:protobuf_rpc_client, Client) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index b2b0c98c..45198f4e 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -4,7 +4,6 @@ require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' require 'protobuf/rpc/stat' -require 'protobuf/rpc/connectors/common' module Protobuf module Rpc @@ -25,21 +24,108 @@ module Connectors class Base include Protobuf::Logging - attr_reader :options - attr_accessor :success_cb, :failure_cb, :complete_cb + attr_reader :options, :error + attr_accessor :success_cb, :failure_cb, :complete_cb, :stats def initialize(options) @options = DEFAULT_OPTIONS.merge(options) @stats = ::Protobuf::Rpc::Stat.new(:CLIENT) end + def any_callbacks? + [@complete_cb, @failure_cb, @success_cb].any? + end + + def close_connection + fail 'If you inherit a Connector from Base you must implement close_connection' + end + + def complete + @stats.stop + logger.info { @stats.to_s } + logger.debug { sign_message('Response proceessing complete') } + @complete_cb.call(self) unless @complete_cb.nil? + rescue => e + logger.error { sign_message('Complete callback error encountered') } + log_exception(e) + raise + end + + def data_callback(data) + logger.debug { sign_message('Using data_callback') } + @used_data_callback = true + @data = data + end + + # All failures should be routed through this method. + # + # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) + # @param [String] message The error message + def failure(code, message) + @error = ClientError.new + @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) + @error.message = message + logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } + + @failure_cb.call(@error) unless @failure_cb.nil? + rescue => e + logger.error { sign_message("Failure callback error encountered") } + log_exception(e) + raise + ensure + complete + end + def first_alive_load_balance? ENV.key?("PB_FIRST_ALIVE_LOAD_BALANCE") || options[:first_alive_load_balance] end - def send_request - fail 'If you inherit a Connector from Base you must implement send_request' + def initialize_stats + @stats = ::Protobuf::Rpc::Stat.new(:CLIENT) + @stats.server = [@options[:port], @options[:host]] + @stats.service = @options[:service].name + @stats.method_name = @options[:method].to_s + rescue => ex + log_exception(ex) + failure(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") + end + + def log_signature + @_log_signature ||= "[client-#{self.class}]" + end + + def parse_response + # Close up the connection as we no longer need it + close_connection + + logger.debug { sign_message("Parsing response from server (connection closed)") } + + # Parse out the raw response + @stats.response_size = @response_data.size unless @response_data.nil? + response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) + + # Determine success or failure based on parsed data + if response_wrapper.field?(:error_reason) + logger.debug { sign_message("Error response parsed") } + + # fail the call if we already know the client is failed + # (don't try to parse out the response payload) + failure(response_wrapper.error_reason, response_wrapper.error) + else + logger.debug { sign_message("Successful response parsed") } + + # Ensure client_response is an instance + parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) + + if parsed.nil? && !response_wrapper.field?(:error_reason) + failure(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') + else + verify_callbacks + succeed(parsed) + return @data if @used_data_callback + end + end end def ping_port @@ -49,6 +135,82 @@ def ping_port def ping_port_enabled? ENV.key?("PB_RPC_PING_PORT") end + + def request_bytes + validate_request_type! + fields = { :service_name => @options[:service].name, + :method_name => @options[:method].to_s, + :request_proto => @options[:request], + :caller => request_caller } + + return ::Protobuf::Socketrpc::Request.encode(fields) + rescue => e + failure(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") + end + + def request_caller + @options[:client_host] || ::Protobuf.client_host + end + + def send_request + fail 'If you inherit a Connector from Base you must implement send_request' + end + + def setup_connection + initialize_stats + @request_data = request_bytes + @stats.request_size = @request_data.size + end + + def succeed(response) + logger.debug { sign_message("Server succeeded request (invoking on_success)") } + @success_cb.call(response) unless @success_cb.nil? + rescue => e + logger.error { sign_message("Success callback error encountered") } + log_exception(e) + failure(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") + ensure + complete + end + + def timeout + if options[:timeout] + options[:timeout] + else + 300 # seconds + end + end + + # Wrap the given block in a timeout of the configured number of seconds. + # + def timeout_wrap(&block) + ::Timeout.timeout(timeout, &block) + rescue ::Timeout::Error + failure(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") + end + + def validate_request_type! + unless @options[:request].class == @options[:request_type] + expected = @options[:request_type].name + actual = @options[:request].class.name + failure(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead") + end + end + + def verify_callbacks + unless any_callbacks? + logger.debug { sign_message("No callbacks set, using data_callback") } + @success_cb = @failure_cb = method(:data_callback) + end + end + + def verify_options! + # Verify the options that are necessary and merge them in + [:service, :method, :host, :port].each do |opt| + failure(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? + end + end + end end end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb deleted file mode 100644 index 84222429..00000000 --- a/lib/protobuf/rpc/connectors/common.rb +++ /dev/null @@ -1,176 +0,0 @@ -require 'protobuf' - -module Protobuf - module Rpc - module Connectors - module Common - - attr_reader :error - - def any_callbacks? - [@complete_cb, @failure_cb, @success_cb].any? - end - - def request_caller - @options[:client_host] || ::Protobuf.client_host - end - - def complete - @stats.stop - logger.info { @stats.to_s } - logger.debug { sign_message('Response proceessing complete') } - @complete_cb.call(self) unless @complete_cb.nil? - rescue => e - logger.error { sign_message('Complete callback error encountered') } - log_exception(e) - raise - end - - def data_callback(data) - logger.debug { sign_message('Using data_callback') } - @used_data_callback = true - @data = data - end - - # All failures should be routed through this method. - # - # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) - # @param [String] message The error message - def failure(code, message) - @error = ClientError.new - @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) - @error.message = message - logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } - - @failure_cb.call(@error) unless @failure_cb.nil? - rescue => e - logger.error { sign_message("Failure callback error encountered") } - log_exception(e) - raise - ensure - complete - end - - def initialize_stats - @stats = ::Protobuf::Rpc::Stat.new(:CLIENT) - @stats.server = [@options[:port], @options[:host]] - @stats.service = @options[:service].name - @stats.method_name = @options[:method].to_s - rescue => ex - log_exception(ex) - failure(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") - end - - def log_signature - @_log_signature ||= "[client-#{self.class}]" - end - - def parse_response - # Close up the connection as we no longer need it - close_connection - - logger.debug { sign_message("Parsing response from server (connection closed)") } - - # Parse out the raw response - @stats.response_size = @response_data.size unless @response_data.nil? - response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) - - # Determine success or failure based on parsed data - if response_wrapper.field?(:error_reason) - logger.debug { sign_message("Error response parsed") } - - # fail the call if we already know the client is failed - # (don't try to parse out the response payload) - failure(response_wrapper.error_reason, response_wrapper.error) - else - logger.debug { sign_message("Successful response parsed") } - - # Ensure client_response is an instance - parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) - - if parsed.nil? && !response_wrapper.field?(:error_reason) - failure(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') - else - verify_callbacks - succeed(parsed) - return @data if @used_data_callback - end - end - end - - def post_init - send_data unless error? - rescue => e - failure(:RPC_ERROR, "Connection error: #{e.message}") - end - - def request_bytes - validate_request_type! - fields = { :service_name => @options[:service].name, - :method_name => @options[:method].to_s, - :request_proto => @options[:request], - :caller => request_caller } - - return ::Protobuf::Socketrpc::Request.encode(fields) - rescue => e - failure(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") - end - - def setup_connection - initialize_stats - @request_data = request_bytes - @stats.request_size = @request_data.size - end - - def succeed(response) - logger.debug { sign_message("Server succeeded request (invoking on_success)") } - @success_cb.call(response) unless @success_cb.nil? - rescue => e - logger.error { sign_message("Success callback error encountered") } - log_exception(e) - failure(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") - ensure - complete - end - - def timeout - if options[:timeout] - options[:timeout] - else - 300 # seconds - end - end - - # Wrap the given block in a timeout of the configured number of seconds. - # - def timeout_wrap(&block) - ::Timeout.timeout(timeout, &block) - rescue ::Timeout::Error - failure(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") - end - - def validate_request_type! - unless @options[:request].class == @options[:request_type] - expected = @options[:request_type].name - actual = @options[:request].class.name - failure(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead") - end - end - - def verify_callbacks - unless any_callbacks? - logger.debug { sign_message("No callbacks set, using data_callback") } - @success_cb = @failure_cb = method(:data_callback) - end - end - - def verify_options! - # Verify the options that are necessary and merge them in - [:service, :method, :host, :port].each do |opt| - failure(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? - end - end - end - end - end -end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index d570e7e0..2e3e6022 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -4,7 +4,6 @@ module Protobuf module Rpc module Connectors class Socket < Base - include Protobuf::Rpc::Connectors::Common include Protobuf::Logging def send_request @@ -39,6 +38,12 @@ def error? @socket.closed? end + def post_init + send_data unless error? + rescue => e + failure(:RPC_ERROR, "Connection error: #{e.message}") + end + def read_data size_io = StringIO.new diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 5bb3079b..a5f5722e 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -14,7 +14,6 @@ class Zmq < Base ## # Included Modules # - include Protobuf::Rpc::Connectors::Common include Protobuf::Logging ## diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 2c5fc98d..254b3fa8 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -8,6 +8,47 @@ subject { Protobuf::Rpc::Connectors::Base.new(options) } + context "API" do + specify { expect(subject.respond_to?(:any_callbacks?)).to be true } + specify { expect(subject.respond_to?(:request_caller)).to be true } + specify { expect(subject.respond_to?(:data_callback)).to be true } + specify { expect(subject.respond_to?(:error)).to be true } + specify { expect(subject.respond_to?(:failure)).to be true } + specify { expect(subject.respond_to?(:complete)).to be true } + specify { expect(subject.respond_to?(:parse_response)).to be true } + specify { expect(subject.respond_to?(:verify_options!)).to be true } + specify { expect(subject.respond_to?(:verify_callbacks)).to be true } + end + + describe "#any_callbacks?" do + [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| + it "returns true if #{cb} is provided" do + subject.instance_variable_set(cb, "something") + expect(subject.any_callbacks?).to be true + end + end + + it "returns false when all callbacks are not provided" do + subject.instance_variable_set(:@complete_cb, nil) + subject.instance_variable_set(:@success_cb, nil) + subject.instance_variable_set(:@failure_cb, nil) + + expect(subject.any_callbacks?).to be false + end + end + + describe "#data_callback" do + it "changes state to use the data callback" do + subject.data_callback("data") + expect(subject.instance_variable_get(:@used_data_callback)).to be true + end + + it "sets the data var when using the data_callback" do + subject.data_callback("data") + expect(subject.instance_variable_get(:@data)).to eq("data") + end + end + describe "#send_request" do it "raising an error when 'send_request' is not overridden" do expect { subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/) @@ -47,4 +88,114 @@ end end + describe '#request_bytes' do + let(:service) { Test::ResourceService } + let(:method) { :find } + let(:request) { '' } + let(:client_host) { 'myhost.myservice.com' } + let(:options) do + { + :service => service, + :method => method, + :request => request, + :client_host => client_host, + :timeout => 60, + } + end + + let(:expected) do + ::Protobuf::Socketrpc::Request.new( + :service_name => service.name, + :method_name => 'find', + :request_proto => '', + :caller => client_host, + ) + end + + before { allow(subject).to receive(:validate_request_type!).and_return(true) } + before { expect(subject).not_to receive(:failure) } + + specify { expect(subject.request_bytes).to eq expected.encode } + end + + describe '#request_caller' do + specify { expect(subject.request_caller).to eq ::Protobuf.client_host } + + context 'when "client_host" option is given to initializer' do + let(:hostname) { 'myhost.myserver.com' } + let(:options) { { :client_host => hostname, :timeout => 60 } } + + specify { expect(subject.request_caller).to_not eq ::Protobuf.client_host } + specify { expect(subject.request_caller).to eq hostname } + end + end + + describe "#verify_callbacks" do + it "sets @failure_cb to #data_callback when no callbacks are defined" do + subject.verify_callbacks + expect(subject.instance_variable_get(:@failure_cb)).to eq(subject.method(:data_callback)) + end + + it "sets @success_cb to #data_callback when no callbacks are defined" do + subject.verify_callbacks + expect(subject.instance_variable_get(:@success_cb)).to eq(subject.method(:data_callback)) + end + + it "doesn't set @failure_cb when already defined" do + set_cb = -> { true } + subject.instance_variable_set(:@failure_cb, set_cb) + subject.verify_callbacks + expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) + expect(subject.instance_variable_get(:@failure_cb)).to_not eq(subject.method(:data_callback)) + end + + it "doesn't set @success_cb when already defined" do + set_cb = -> { true } + subject.instance_variable_set(:@success_cb, set_cb) + subject.verify_callbacks + expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) + expect(subject.instance_variable_get(:@success_cb)).to_not eq(subject.method(:data_callback)) + end + + end + + shared_examples "a ConnectorDisposition" do |meth, cb, *args| + + it "calls #complete before exit" do + subject.stats = double("Object", :stop => true) + + expect(subject).to receive(:complete) + subject.method(meth).call(*args) + end + + it "calls the #{cb} callback when provided" do + stats = double("Object") + allow(stats).to receive(:stop).and_return(true) + subject.stats = stats + some_cb = double("Object") + + subject.instance_variable_set("@#{cb}", some_cb) + expect(some_cb).to receive(:call).and_return(true) + subject.method(meth).call(*args) + end + + it "calls the complete callback when provided" do + stats = double("Object") + allow(stats).to receive(:stop).and_return(true) + subject.stats = stats + comp_cb = double("Object") + + subject.instance_variable_set(:@complete_cb, comp_cb) + expect(comp_cb).to receive(:call).and_return(true) + subject.method(meth).call(*args) + end + + end + + it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message") + it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message") + it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response") + it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response") + it_behaves_like("a ConnectorDisposition", :complete, "complete_cb") + end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb deleted file mode 100644 index de98c551..00000000 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ /dev/null @@ -1,170 +0,0 @@ -require 'spec_helper' -require 'protobuf/rpc/service' - -RSpec.describe Protobuf::Rpc::Connectors::Common do - let(:common_class) do - Class.new(Protobuf::Rpc::Connectors::Base) do - include Protobuf::Rpc::Connectors::Common - attr_accessor :options - attr_accessor :stats - end - end - - let(:subject_options) { {} } - - subject { @subject ||= common_class.new(subject_options) } - - context "API" do - specify { expect(subject.respond_to?(:any_callbacks?)).to be true } - specify { expect(subject.respond_to?(:request_caller)).to be true } - specify { expect(subject.respond_to?(:data_callback)).to be true } - specify { expect(subject.respond_to?(:error)).to be true } - specify { expect(subject.respond_to?(:failure)).to be true } - specify { expect(subject.respond_to?(:complete)).to be true } - specify { expect(subject.respond_to?(:parse_response)).to be true } - specify { expect(subject.respond_to?(:verify_options!)).to be true } - specify { expect(subject.respond_to?(:verify_callbacks)).to be true } - end - - describe "#any_callbacks?" do - - [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| - it "returns true if #{cb} is provided" do - subject.instance_variable_set(cb, "something") - expect(subject.any_callbacks?).to be true - end - end - - it "returns false when all callbacks are not provided" do - subject.instance_variable_set(:@complete_cb, nil) - subject.instance_variable_set(:@success_cb, nil) - subject.instance_variable_set(:@failure_cb, nil) - - expect(subject.any_callbacks?).to be false - end - - end - - describe '#request_caller' do - specify { expect(subject.request_caller).to eq ::Protobuf.client_host } - - context 'when "client_host" option is given to initializer' do - let(:hostname) { 'myhost.myserver.com' } - let(:subject_options) { { :client_host => hostname } } - - specify { expect(subject.request_caller).to_not eq ::Protobuf.client_host } - specify { expect(subject.request_caller).to eq hostname } - end - end - - describe "#data_callback" do - it "changes state to use the data callback" do - subject.data_callback("data") - expect(subject.instance_variable_get(:@used_data_callback)).to be true - end - - it "sets the data var when using the data_callback" do - subject.data_callback("data") - expect(subject.instance_variable_get(:@data)).to eq("data") - end - end - - describe '#request_bytes' do - let(:service) { Test::ResourceService } - let(:method) { :find } - let(:request) { '' } - let(:client_host) { 'myhost.myservice.com' } - let(:subject_options) do - { - :service => service, - :method => method, - :request => request, - :client_host => client_host, - } - end - - let(:expected) do - ::Protobuf::Socketrpc::Request.new( - :service_name => service.name, - :method_name => 'find', - :request_proto => '', - :caller => client_host, - ) - end - - before { allow(subject).to receive(:validate_request_type!).and_return(true) } - before { expect(subject).not_to receive(:failure) } - - specify { expect(subject.request_bytes).to eq expected.encode } - end - - describe "#verify_callbacks" do - - it "sets @failure_cb to #data_callback when no callbacks are defined" do - subject.verify_callbacks - expect(subject.instance_variable_get(:@failure_cb)).to eq(subject.method(:data_callback)) - end - - it "sets @success_cb to #data_callback when no callbacks are defined" do - subject.verify_callbacks - expect(subject.instance_variable_get(:@success_cb)).to eq(subject.method(:data_callback)) - end - - it "doesn't set @failure_cb when already defined" do - set_cb = -> { true } - subject.instance_variable_set(:@failure_cb, set_cb) - subject.verify_callbacks - expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) - expect(subject.instance_variable_get(:@failure_cb)).to_not eq(subject.method(:data_callback)) - end - - it "doesn't set @success_cb when already defined" do - set_cb = -> { true } - subject.instance_variable_set(:@success_cb, set_cb) - subject.verify_callbacks - expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) - expect(subject.instance_variable_get(:@success_cb)).to_not eq(subject.method(:data_callback)) - end - - end - - shared_examples "a ConnectorDisposition" do |meth, cb, *args| - - it "calls #complete before exit" do - subject.stats = double("Object", :stop => true) - - expect(subject).to receive(:complete) - subject.method(meth).call(*args) - end - - it "calls the #{cb} callback when provided" do - stats = double("Object") - allow(stats).to receive(:stop).and_return(true) - subject.stats = stats - some_cb = double("Object") - - subject.instance_variable_set("@#{cb}", some_cb) - expect(some_cb).to receive(:call).and_return(true) - subject.method(meth).call(*args) - end - - it "calls the complete callback when provided" do - stats = double("Object") - allow(stats).to receive(:stop).and_return(true) - subject.stats = stats - comp_cb = double("Object") - - subject.instance_variable_set(:@complete_cb, comp_cb) - expect(comp_cb).to receive(:call).and_return(true) - subject.method(meth).call(*args) - end - - end - - it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message") - it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message") - it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response") - it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response") - it_behaves_like("a ConnectorDisposition", :complete, "complete_cb") - -end diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 12bd15d9..1d0d3187 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -18,8 +18,6 @@ it_behaves_like "a Protobuf Connector" - specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be true } - context "#read_response" do let(:data) { "New data" } From 977b54d149e63f5aef29206f4fb7b0a6c8a426ca Mon Sep 17 00:00:00 2001 From: Teppei Fujii Date: Thu, 16 Feb 2017 18:31:52 +0900 Subject: [PATCH 1027/1191] Add tests for packed fields --- spec/lib/protobuf/field/bool_field_spec.rb | 4 ++++ spec/lib/protobuf/field/double_field_spec.rb | 9 +++++++++ spec/lib/protobuf/field/fixed32_field_spec.rb | 7 +++++++ spec/lib/protobuf/field/fixed64_field_spec.rb | 7 +++++++ spec/lib/protobuf/field/float_field_spec.rb | 4 ++++ spec/lib/protobuf/field/int64_field_spec.rb | 7 +++++++ spec/lib/protobuf/field/sfixed32_field_spec.rb | 9 +++++++++ spec/lib/protobuf/field/sfixed64_field_spec.rb | 9 +++++++++ spec/lib/protobuf/field/sint32_field_spec.rb | 9 +++++++++ spec/lib/protobuf/field/sint64_field_spec.rb | 9 +++++++++ spec/lib/protobuf/field/uint32_field_spec.rb | 7 +++++++ spec/lib/protobuf/field/uint64_field_spec.rb | 7 +++++++ spec/support/packed_field.rb | 5 +++-- 13 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 spec/lib/protobuf/field/double_field_spec.rb create mode 100644 spec/lib/protobuf/field/fixed32_field_spec.rb create mode 100644 spec/lib/protobuf/field/fixed64_field_spec.rb create mode 100644 spec/lib/protobuf/field/int64_field_spec.rb create mode 100644 spec/lib/protobuf/field/sfixed32_field_spec.rb create mode 100644 spec/lib/protobuf/field/sfixed64_field_spec.rb create mode 100644 spec/lib/protobuf/field/sint32_field_spec.rb create mode 100644 spec/lib/protobuf/field/sint64_field_spec.rb create mode 100644 spec/lib/protobuf/field/uint32_field_spec.rb create mode 100644 spec/lib/protobuf/field/uint64_field_spec.rb diff --git a/spec/lib/protobuf/field/bool_field_spec.rb b/spec/lib/protobuf/field/bool_field_spec.rb index d95d397f..abe25369 100644 --- a/spec/lib/protobuf/field/bool_field_spec.rb +++ b/spec/lib/protobuf/field/bool_field_spec.rb @@ -2,6 +2,10 @@ RSpec.describe Protobuf::Field::BoolField do + it_behaves_like :packable_field, described_class do + let(:value) { [true, false] } + end + class SomeBoolMessage < ::Protobuf::Message optional :bool, :some_bool, 1 required :bool, :required_bool, 2 diff --git a/spec/lib/protobuf/field/double_field_spec.rb b/spec/lib/protobuf/field/double_field_spec.rb new file mode 100644 index 00000000..e6ae9fd1 --- /dev/null +++ b/spec/lib/protobuf/field/double_field_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::DoubleField do + + it_behaves_like :packable_field, described_class do + let(:value) { [1.0, 2.0, 3.0] } + end + +end diff --git a/spec/lib/protobuf/field/fixed32_field_spec.rb b/spec/lib/protobuf/field/fixed32_field_spec.rb new file mode 100644 index 00000000..751b0bdb --- /dev/null +++ b/spec/lib/protobuf/field/fixed32_field_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Fixed32Field do + + it_behaves_like :packable_field, described_class + +end diff --git a/spec/lib/protobuf/field/fixed64_field_spec.rb b/spec/lib/protobuf/field/fixed64_field_spec.rb new file mode 100644 index 00000000..d7feb120 --- /dev/null +++ b/spec/lib/protobuf/field/fixed64_field_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Fixed64Field do + + it_behaves_like :packable_field, described_class + +end diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb index 0620c93c..5fa76247 100644 --- a/spec/lib/protobuf/field/float_field_spec.rb +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -2,6 +2,10 @@ RSpec.describe Protobuf::Field::FloatField do + it_behaves_like :packable_field, described_class do + let(:value) { [1.0, 2.0, 3.0] } + end + class SomeFloatMessage < ::Protobuf::Message optional :float, :some_float, 1 end diff --git a/spec/lib/protobuf/field/int64_field_spec.rb b/spec/lib/protobuf/field/int64_field_spec.rb new file mode 100644 index 00000000..1bbe7c04 --- /dev/null +++ b/spec/lib/protobuf/field/int64_field_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Int64Field do + + it_behaves_like :packable_field, described_class + +end diff --git a/spec/lib/protobuf/field/sfixed32_field_spec.rb b/spec/lib/protobuf/field/sfixed32_field_spec.rb new file mode 100644 index 00000000..9d582fee --- /dev/null +++ b/spec/lib/protobuf/field/sfixed32_field_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Sfixed32Field do + + it_behaves_like :packable_field, described_class do + let(:value) { [-1, 0, 1] } + end + +end diff --git a/spec/lib/protobuf/field/sfixed64_field_spec.rb b/spec/lib/protobuf/field/sfixed64_field_spec.rb new file mode 100644 index 00000000..f380ed5d --- /dev/null +++ b/spec/lib/protobuf/field/sfixed64_field_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Sfixed64Field do + + it_behaves_like :packable_field, described_class do + let(:value) { [-1, 0, 1] } + end + +end diff --git a/spec/lib/protobuf/field/sint32_field_spec.rb b/spec/lib/protobuf/field/sint32_field_spec.rb new file mode 100644 index 00000000..f19d934a --- /dev/null +++ b/spec/lib/protobuf/field/sint32_field_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Sint32Field do + + it_behaves_like :packable_field, described_class do + let(:value) { [-1, 0, 1] } + end + +end diff --git a/spec/lib/protobuf/field/sint64_field_spec.rb b/spec/lib/protobuf/field/sint64_field_spec.rb new file mode 100644 index 00000000..84ca7304 --- /dev/null +++ b/spec/lib/protobuf/field/sint64_field_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Sint64Field do + + it_behaves_like :packable_field, described_class do + let(:value) { [-1, 0, 1] } + end + +end diff --git a/spec/lib/protobuf/field/uint32_field_spec.rb b/spec/lib/protobuf/field/uint32_field_spec.rb new file mode 100644 index 00000000..af484a47 --- /dev/null +++ b/spec/lib/protobuf/field/uint32_field_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Uint32Field do + + it_behaves_like :packable_field, described_class + +end diff --git a/spec/lib/protobuf/field/uint64_field_spec.rb b/spec/lib/protobuf/field/uint64_field_spec.rb new file mode 100644 index 00000000..61b8d1b9 --- /dev/null +++ b/spec/lib/protobuf/field/uint64_field_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Uint64Field do + + it_behaves_like :packable_field, described_class + +end diff --git a/spec/support/packed_field.rb b/spec/support/packed_field.rb index 79bb7655..9b18efee 100644 --- a/spec/support/packed_field.rb +++ b/spec/support/packed_field.rb @@ -12,11 +12,12 @@ class PackableFieldTest < ::Protobuf::Message; end end let(:field_name) { "#{field_klass.name.split('::').last.underscore}_packed_field".to_sym } - let(:message_instance) { PackableFieldTest.new(field_name => [100, 200, 300]) } + let(:value) { [100, 200, 300] } + let(:message_instance) { PackableFieldTest.new(field_name => value) } subject { PackableFieldTest.get_field(field_name) } specify { expect(subject).to be_packed } - + specify { expect(PackableFieldTest.decode(message_instance.encode).send(field_name)).to eq value } end end From e7609fabc4b6f5d013b2f99049835adee961fc7f Mon Sep 17 00:00:00 2001 From: Teppei Fujii Date: Thu, 16 Feb 2017 20:16:43 +0900 Subject: [PATCH 1028/1191] Fix decoding of packed fields --- lib/protobuf/field/base_field.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 180209f3..a7b7c4dd 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -129,11 +129,11 @@ def set(message_instance, bytes) stream = StringIO.new(bytes) if wire_type == ::Protobuf::WireType::VARINT - array << Varint.decode(stream) until stream.eof? + array << decode(Varint.decode(stream)) until stream.eof? elsif wire_type == ::Protobuf::WireType::FIXED64 - array << stream.read(8) until stream.eof? + array << decode(stream.read(8)) until stream.eof? elsif wire_type == ::Protobuf::WireType::FIXED32 - array << stream.read(4) until stream.eof? + array << decode(stream.read(4)) until stream.eof? end end From 835c6109c2446ead78f5bb5a57387553717a8a4a Mon Sep 17 00:00:00 2001 From: Embark Date: Fri, 17 Feb 2017 09:20:59 -0800 Subject: [PATCH 1029/1191] Remove support for jruby 1.7 It is not supported anymore and has divergent NameError#name behavior that activesupport relies on. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3c6b3d87..34d330d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ rvm: - 2.2 - 2.2.2 - 2.3 - - jruby-1.7 - jruby-9.1.7.0 - rbx-2 env: From de7f76136b9a587c6d49c808f5e1b36de9662a04 Mon Sep 17 00:00:00 2001 From: Embark Date: Fri, 17 Feb 2017 12:54:36 -0800 Subject: [PATCH 1030/1191] Add support for custom file options --- .rubocop.yml | 2 + lib/protobuf/code_generator.rb | 40 +++++++++++++ .../google/protobuf/descriptor.pb.rb | 12 ++++ lib/protobuf/field/base_field.rb | 9 --- lib/protobuf/generators/base.rb | 21 +++++++ lib/protobuf/generators/file_generator.rb | 2 + lib/protobuf/generators/group_generator.rb | 9 ++- lib/protobuf/generators/option_generator.rb | 17 ++++++ spec/lib/protobuf/field/message_field_spec.rb | 53 ++++++++++++++++++ spec/lib/protobuf/generators/base_spec.rb | 56 ++++++++++++++++++- .../generators/file_generator_spec.rb | 47 ++++++++++++++++ spec/lib/protobuf/optionable_spec.rb | 18 ++++++ spec/support/protos/google_unittest.pb.rb | 11 ++++ .../google_unittest_custom_options.pb.rb | 10 ++++ .../protos/google_unittest_import.pb.rb | 8 +++ .../google_unittest_import_public.pb.rb | 6 ++ spec/support/protos/resource.pb.rb | 21 +++++++ spec/support/protos/resource.proto | 9 +++ 18 files changed, 339 insertions(+), 12 deletions(-) create mode 100644 lib/protobuf/generators/option_generator.rb diff --git a/.rubocop.yml b/.rubocop.yml index 1ed3b0d4..2542751c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,8 @@ inherit_from: .rubocop_todo.yml AllCops: DisplayCopNames: true + Exclude: + - 'spec/support/protos/*.pb.rb' Lint/EndAlignment: AlignWith: keyword diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 70ec1303..e9da081e 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/module/aliasing' require 'protobuf/generators/file_generator' module Protobuf @@ -48,5 +49,44 @@ def response_bytes ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files) end + Protobuf::Field::BaseField.module_eval do + # Sets a MessageField that is known to be an option. + # We must allow fields to be set one at a time, as option syntax allows us to + # set each field within the option using a separate "option" line. + def set_with_options(message_instance, bytes) + if message_instance[name].is_a?(::Protobuf::Message) + gp = Google::Protobuf + if message_instance.is_a?(gp::EnumOptions) || message_instance.is_a?(gp::EnumValueOptions) || + message_instance.is_a?(gp::FieldOptions) || message_instance.is_a?(gp::FileOptions) || + message_instance.is_a?(gp::MethodOptions) || message_instance.is_a?(gp::ServiceOptions) || + message_instance.is_a?(gp::MessageOptions) + + original_field = message_instance[name] + decoded_field = decode(bytes) + decoded_field.each_field do |subfield, subvalue| + option_set(original_field, subfield, subvalue) { decoded_field.field?(subfield.tag) } + end + return + end + end + + set_without_options(message_instance, bytes) + end + + def option_set(message_field, subfield, subvalue) + return unless yield + if subfield.repeated? + message_field[subfield.tag].concat(subvalue) + elsif message_field[subfield.tag] && subvalue.is_a?(::Protobuf::Message) + subvalue.each_field do |f, v| + option_set(message_field[subfield.tag], f, v) { subvalue.field?(f.tag) } + end + else + message_field[subfield.tag] = subvalue + end + end + + alias_method_chain :set, :options + end end end diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index 379e9493..56ebbed5 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -96,6 +96,17 @@ class Location < ::Protobuf::Message; end + ## + # File Options + # + set_option :java_package, "com.google.protobuf" + set_option :java_outer_classname, "DescriptorProtos" + set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED + set_option :go_package, "descriptor" + set_option :objc_class_prefix, "GPB" + set_option :csharp_namespace, "Google.Protobuf.Reflection" + + ## # Message Fields # @@ -284,6 +295,7 @@ class Location repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1 end + end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 180209f3..912b191e 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -92,10 +92,6 @@ def enum? false end - def getter - name - end - def message? false end @@ -137,10 +133,6 @@ def set(message_instance, bytes) end end - def setter - @setter ||= "#{name}=" - end - def tag_encoded @tag_encoded ||= begin case @@ -205,7 +197,6 @@ def validate_packed_field fail "Can't use packed encoding for '#{type_class}' type" end end - end end end diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 6e7304c5..c529d6c6 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -59,6 +59,27 @@ def type_namespace @type_namespace ||= @namespace + [descriptor.name] end + def serialize_value(value) + case value + when Message + fields = value.each_field.map do |field, inner_value| + next unless value.field?(field.name) + serialized_inner_value = serialize_value(inner_value) + "#{field.fully_qualified_name.inspect} => #{serialized_inner_value}" + end.compact + "{ #{fields.join(', ')} }" + when Enum + "::#{value.parent_class}::#{value.name}" + when String + value.inspect + when nil + "nil" + when Array + '[' + value.map { |x| serialize_value(x) }.join(', ') + ']' + else + value + end + end end end end diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 6806eecb..6382d708 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -32,6 +32,7 @@ def compile print_package do inject_optionable group = GroupGenerator.new(current_indent) + group.add_options(descriptor.options) if descriptor.options group.add_enums(descriptor.enum_type, :namespace => [descriptor.package]) group.add_message_declarations(descriptor.message_type) group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [descriptor.package]) @@ -40,6 +41,7 @@ def compile group.add_header(:enum, 'Enum Classes') group.add_header(:message_declaration, 'Message Classes') + group.add_header(:options, 'File Options') group.add_header(:message, 'Message Fields') group.add_header(:extended_message, 'Extended Message Fields') group.add_header(:service, 'Service Classes') diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index 1578176a..0bb0cd34 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -2,6 +2,7 @@ require 'protobuf/generators/extension_generator' require 'protobuf/generators/field_generator' require 'protobuf/generators/message_generator' +require 'protobuf/generators/option_generator' require 'protobuf/generators/service_generator' module Protobuf @@ -18,10 +19,14 @@ def initialize(indent_level = 0) @comments = {} @handlers = {} @indent_level = indent_level - @order = [:enum, :message_declaration, :message, :extended_message, :service] + @order = [:enum, :message_declaration, :options, :message, :extended_message, :service] init_printer(indent_level) end + def add_options(option_descriptor) + @groups[:options] << OptionGenerator.new(option_descriptor, indent_level) + end + def add_enums(enum_descriptors, options) enum_descriptors.each do |enum_descriptor| @groups[:enum] << EnumGenerator.new(enum_descriptor, indent_level, options) @@ -99,7 +104,7 @@ def compile end end - puts if type == :message_declaration + puts if type == :message_declaration || type == :options end end diff --git a/lib/protobuf/generators/option_generator.rb b/lib/protobuf/generators/option_generator.rb new file mode 100644 index 00000000..71cec42e --- /dev/null +++ b/lib/protobuf/generators/option_generator.rb @@ -0,0 +1,17 @@ +require 'protobuf/generators/base' + +module Protobuf + module Generators + class OptionGenerator < Base + def compile + run_once(:compile) do + descriptor.each_field.map do |field, value| + next unless descriptor.field?(field.name) + serialized_value = serialize_value(value) + puts "set_option #{field.fully_qualified_name.inspect}, #{serialized_value}" + end + end + end + end + end +end diff --git a/spec/lib/protobuf/field/message_field_spec.rb b/spec/lib/protobuf/field/message_field_spec.rb index b7fdf442..cfc4f8b4 100644 --- a/spec/lib/protobuf/field/message_field_spec.rb +++ b/spec/lib/protobuf/field/message_field_spec.rb @@ -1,9 +1,18 @@ require 'spec_helper' RSpec.describe Protobuf::Field::MessageField do + let(:inner_message) do + Class.new(::Protobuf::Message) do + optional :int32, :field, 0 + optional :int32, :field2, 1 + end + end + let(:field_message) do Class.new(::Protobuf::Message) do optional :int32, :field, 1 + repeated :int64, :repeated_field, 2 + optional InnerMessage, :message_field, 3 end end @@ -14,6 +23,7 @@ end before do + stub_const('InnerMessage', inner_message) stub_const('FieldMessage', field_message) stub_const('Message', message) end @@ -76,4 +86,47 @@ def to_hash end end end + + describe '#option_set' do + let(:message_field) { Message.fields[0] } + it 'returns unless yield' do + # No Error thrown + message_field.__send__(:option_set, nil, nil, nil) { false } + expect do + message_field.__send__(:option_set, nil, nil, nil) { true } + end.to raise_error StandardError + end + + it 'sets repeated fields' do + repeated = field_message.fields[1] + instance = field_message.new + expect(instance.repeated_field!).to eq(nil) + message_field.__send__(:option_set, instance, repeated, [53]) { true } + expect(instance.repeated_field!).to eq([53]) + message_field.__send__(:option_set, instance, repeated, [54]) { true } + expect(instance.repeated_field!).to eq([53, 54]) + end + + it 'sets optional non-message fields' do + optional = field_message.fields[0] + instance = field_message.new + expect(instance.field!).to eq(nil) + message_field.__send__(:option_set, instance, optional, 53) { true } + expect(instance.field!).to eq(53) + message_field.__send__(:option_set, instance, optional, 52) { true } + expect(instance.field!).to eq(52) + end + + it 'sets nested inner messages fields one at a time' do + inner = field_message.fields[2] + inner_val = InnerMessage.new(:field => 21) + inner_val2 = InnerMessage.new(:field2 => 9) + instance = field_message.new + expect(instance.message_field!).to eq(nil) + message_field.__send__(:option_set, instance, inner, inner_val) { true } + expect(instance.message_field!).to eq(InnerMessage.new(:field => 21)) + message_field.__send__(:option_set, instance, inner, inner_val2) { true } + expect(instance.message_field!).to eq(InnerMessage.new(:field => 21, :field2 => 9)) + end + end end diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index df29fd2a..43d25e84 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -5,7 +5,7 @@ RSpec.describe ::Protobuf::Generators::Base do - subject { described_class.new(double) } + subject(:generator) { described_class.new(double) } context 'namespaces' do let(:descriptor) { double(:name => 'Baz') } @@ -83,4 +83,58 @@ def compile end end + describe '#serialize_value' do + before do + stub_const("MyEnum", Class.new(::Protobuf::Enum) do + define :FOO, 1 + define :BOO, 2 + end) + stub_const("MyMessage1", Class.new(Protobuf::Message) do + optional :string, :foo, 1 + end) + stub_const("MyMessage2", Class.new(Protobuf::Message) do + optional :string, :foo, 1 + optional MyMessage1, :bar, 2 + optional :int32, :boom, 3 + optional MyEnum, :goat, 4 + optional :bool, :bam, 5 + optional :float, :fire, 6 + end) + stub_const("MyMessage3", Class.new(Protobuf::Message) do + optional :string, :foo, 1 + repeated MyMessage2, :bar, 2 + optional :int32, :boom, 3 + optional MyEnum, :goat, 4 + optional :bool, :bam, 5 + optional :float, :fire, 6 + end) + end + + it 'serializes messages' do + expect(generator.serialize_value(MyMessage3.new( + :foo => 'space', + :bar => [MyMessage2.new( + :foo => 'station', + :bar => MyMessage1.new(:foo => 'orbit'), + :boom => 123, + :goat => MyEnum::FOO, + :bam => false, + :fire => 3.5, + )], + :boom => 456, + :goat => MyEnum::BOO, + :bam => true, + :fire => 1.2, + ))).to eq( + '{ :foo => "space", :bar => [{ '\ + ':foo => "station", :bar => { :foo => "orbit" }, :boom => 123, :goat => ::MyEnum::FOO, :bam => false, :fire => 3.5 '\ + '}], :boom => 456, :goat => ::MyEnum::BOO, :bam => true, :fire => 1.2 }' + ) + end + + it 'serializes enums' do + expect(generator.serialize_value(MyEnum::FOO)).to eq("::MyEnum::FOO") + expect(generator.serialize_value(MyEnum::BOO)).to eq("::MyEnum::BOO") + end + end end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index b6a7640a..b1eb0d64 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -61,5 +61,52 @@ module Foo EOF end + + context 'with extended messages' do + let(:descriptor_fields) do + base_descriptor_fields.merge( + :package => 'test.pkg.file_generator_spec', + :extension => [{ + :name => 'boom', + :number => 20_000, + :label => Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL, + :type => Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING, + :extendee => '.google.protobuf.FieldOptions', + }], + ) + end + + it 'generates the file contents that include the namespaced extension name' do + subject.compile + expect(subject.to_s).to eq < true + end + + end + + end + +end + +EOF + end + end + end end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 76b35194..888db6ec 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' require 'protobuf/optionable' require 'protobuf/field/message_field' +require PROTOS_PATH.join('resource.pb') RSpec.describe 'Optionable' do describe '.{get,get!}_option' do @@ -166,4 +167,21 @@ def optionable_descriptor_class end end end + + describe 'getting options from generated code' do + context 'file options' do + it 'gets base options' do + expect(::Test.get_option!(:cc_generic_services)).to eq(true) + end + + it 'gets unset options' do + expect(::Test.get_option!(:java_multiple_files)).to eq(nil) + expect(::Test.get_option(:java_multiple_files)).to eq(false) + end + + it 'gets custom options' do + expect(::Test.get_option!(:".test.file_option")).to eq(9876543210) + end + end + end end diff --git a/spec/support/protos/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb index a1fe072a..3ce016fd 100644 --- a/spec/support/protos/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -175,6 +175,17 @@ class BarRequest < ::Protobuf::Message; end class BarResponse < ::Protobuf::Message; end + ## + # File Options + # + set_option :java_outer_classname, "UnittestProto" + set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED + set_option :cc_generic_services, true + set_option :java_generic_services, true + set_option :py_generic_services, true + set_option :cc_enable_arenas, true + + ## # Message Fields # diff --git a/spec/support/protos/google_unittest_custom_options.pb.rb b/spec/support/protos/google_unittest_custom_options.pb.rb index 9d6b94f2..e1f2576b 100644 --- a/spec/support/protos/google_unittest_custom_options.pb.rb +++ b/spec/support/protos/google_unittest_custom_options.pb.rb @@ -96,6 +96,16 @@ class TestEnum < ::Protobuf::Enum class TestMessageWithRequiredEnumOption < ::Protobuf::Message; end + ## + # File Options + # + set_option :cc_generic_services, true + set_option :java_generic_services, true + set_option :py_generic_services, true + set_option :".protobuf_unittest.file_opt1", 9876543210 + set_option :".protobuf_unittest.fileopt", { :i => 100, :s => "FileAnnotation", :sub => { :s => "NestedFileAnnotation" }, :file => { :".protobuf_unittest.fileopt" => { :s => "FileExtensionAnnotation" } }, :mset => { :".protobuf_unittest.AggregateMessageSetElement.message_set_extension" => { :s => "EmbeddedMessageSetElement" } } } + + ## # Message Fields # diff --git a/spec/support/protos/google_unittest_import.pb.rb b/spec/support/protos/google_unittest_import.pb.rb index cbef3673..99beaf06 100644 --- a/spec/support/protos/google_unittest_import.pb.rb +++ b/spec/support/protos/google_unittest_import.pb.rb @@ -36,6 +36,14 @@ class ImportEnumForMap < ::Protobuf::Enum class ImportMessage < ::Protobuf::Message; end + ## + # File Options + # + set_option :java_package, "com.google.protobuf.test" + set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED + set_option :cc_enable_arenas, true + + ## # Message Fields # diff --git a/spec/support/protos/google_unittest_import_public.pb.rb b/spec/support/protos/google_unittest_import_public.pb.rb index 7a230268..c6c295d2 100644 --- a/spec/support/protos/google_unittest_import_public.pb.rb +++ b/spec/support/protos/google_unittest_import_public.pb.rb @@ -14,6 +14,12 @@ module Protobuf_unittest_import class PublicImportMessage < ::Protobuf::Message; end + ## + # File Options + # + set_option :java_package, "com.google.protobuf.test" + + ## # Message Fields # diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index ae90309e..c13a5420 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -6,6 +6,12 @@ require 'protobuf' require 'protobuf/rpc/service' + +## +# Imports +# +require 'google/protobuf/descriptor.pb' + module Test ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } @@ -47,6 +53,13 @@ class NestedLevelOne < ::Protobuf::Message; end + ## + # File Options + # + set_option :cc_generic_services, true + set_option :".test.file_option", 9876543210 + + ## # Message Fields # @@ -106,6 +119,14 @@ class NestedLevelOne end + ## + # Extended Message Fields + # + class ::Google::Protobuf::FileOptions < ::Protobuf::Message + optional :uint64, :".test.file_option", 9585869, :extension => true + end + + ## # Service Classes # diff --git a/spec/support/protos/resource.proto b/spec/support/protos/resource.proto index 9cfe79cf..537e66cd 100644 --- a/spec/support/protos/resource.proto +++ b/spec/support/protos/resource.proto @@ -1,7 +1,16 @@ syntax = "proto2"; +import "google/protobuf/descriptor.proto"; + package test; +option cc_generic_services = true; +option (file_option) = 9876543210; + +extend google.protobuf.FileOptions { + optional uint64 file_option = 9585869; +} + enum StatusType { PENDING = 0; ENABLED = 1; From 33579846b20d92dd25f99a5600ba2027ceeeb9f9 Mon Sep 17 00:00:00 2001 From: Evan Kuchar Date: Fri, 17 Feb 2017 15:23:24 -0800 Subject: [PATCH 1031/1191] Bugfix: enum_for_tags returns nil if tag nil This fixes https://github.com/ruby-protobuf/protobuf/issues/265 Bug: calling to_i on nil returns 0, and so will return an erroneous value if the enum is zero-indexed. --- lib/protobuf/enum.rb | 4 ++-- spec/lib/protobuf/enum_spec.rb | 4 ++++ spec/lib/protobuf/message_spec.rb | 4 ++-- spec/support/protos/enum.pb.rb | 1 + spec/support/protos/enum.proto | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 1640a040..35bfa226 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -94,7 +94,7 @@ class << self # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - mapped_enums[tag.to_i] || [] + tag && mapped_enums[tag.to_i] || [] end # Public: Get the Enum associated with the given name. @@ -129,7 +129,7 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - (mapped_enums[tag.to_i] || []).first + tag && (mapped_enums[tag.to_i] || []).first end # Public: Get an Enum by a variety of type-checking mechanisms. diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 5ec3ad06..f294ee6c 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -53,6 +53,7 @@ it 'provides an array of defined Enums' do expect(Test::EnumTestType.enums).to eq( [ + Test::EnumTestType::ZERO, Test::EnumTestType::ONE, Test::EnumTestType::TWO, Test::EnumTestType::MINUS_ONE, @@ -76,6 +77,7 @@ describe '.enums_for_tag' do it 'returns an array of Enums for the given tag, if any' do + expect(EnumAliasTest.enums_for_tag(nil)).to eq([]) expect(EnumAliasTest.enums_for_tag(1)).to eq([EnumAliasTest::FOO, EnumAliasTest::BAR]) expect(EnumAliasTest.enums_for_tag(2)).to eq([EnumAliasTest::BAZ]) expect(EnumAliasTest.enums_for_tag(3)).to eq([]) @@ -124,6 +126,7 @@ it 'gets the Enum corresponding to the given tag' do expect(Test::EnumTestType.enum_for_tag(tag)).to eq(Test::EnumTestType.const_get(name)) expect(Test::EnumTestType.enum_for_tag(-5)).to be_nil + expect(Test::EnumTestType.enum_for_tag(nil)).to be_nil end end @@ -186,6 +189,7 @@ it 'provides a hash of defined Enums' do expect(Test::EnumTestType.values).to eq( :MINUS_ONE => Test::EnumTestType::MINUS_ONE, + :ZERO => Test::EnumTestType::ZERO, :ONE => Test::EnumTestType::ONE, :TWO => Test::EnumTestType::TWO, :THREE => Test::EnumTestType::THREE, diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e76fa269..471727dc 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -142,12 +142,12 @@ describe '#initialize' do it "defaults to the first value listed in the enum's type definition" do test_enum = Test::EnumTestMessage.new - expect(test_enum.non_default_enum).to eq(1) + expect(test_enum.non_default_enum).to eq(Test::EnumTestType.enums.first) end it "defaults to a a value with a name" do test_enum = Test::EnumTestMessage.new - expect(test_enum.non_default_enum.name).to eq(:ONE) + expect(test_enum.non_default_enum.name).to eq(Test::EnumTestType.enums.first.name) end it "exposes the enum getter raw value through ! method" do diff --git a/spec/support/protos/enum.pb.rb b/spec/support/protos/enum.pb.rb index 7442ec69..53f9cccd 100644 --- a/spec/support/protos/enum.pb.rb +++ b/spec/support/protos/enum.pb.rb @@ -18,6 +18,7 @@ module Test # Enum Classes # class EnumTestType < ::Protobuf::Enum + define :ZERO, 0 define :ONE, 1 define :TWO, 2 end diff --git a/spec/support/protos/enum.proto b/spec/support/protos/enum.proto index f3f08647..1d1abb32 100644 --- a/spec/support/protos/enum.proto +++ b/spec/support/protos/enum.proto @@ -6,6 +6,7 @@ import 'protos/resource.proto'; // Test extending another message from an imported file. enum EnumTestType { + ZERO = 0; ONE = 1; TWO = 2; } From 0889c27be588fee0757024326d1161e84bd278f7 Mon Sep 17 00:00:00 2001 From: Evan Kuchar Date: Fri, 17 Feb 2017 15:23:24 -0800 Subject: [PATCH 1032/1191] Bugfix: enum_for_tags returns nil if tag nil This fixes https://github.com/ruby-protobuf/protobuf/issues/265 Bug: calling to_i on nil returns 0, and so will return an erroneous value if the enum is zero-indexed. --- lib/protobuf/enum.rb | 4 ++-- spec/lib/protobuf/enum_spec.rb | 4 ++++ spec/lib/protobuf/message_spec.rb | 4 ++-- spec/support/protos/enum.pb.rb | 1 + spec/support/protos/enum.proto | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 1640a040..35bfa226 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -94,7 +94,7 @@ class << self # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - mapped_enums[tag.to_i] || [] + tag && mapped_enums[tag.to_i] || [] end # Public: Get the Enum associated with the given name. @@ -129,7 +129,7 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - (mapped_enums[tag.to_i] || []).first + tag && (mapped_enums[tag.to_i] || []).first end # Public: Get an Enum by a variety of type-checking mechanisms. diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 5ec3ad06..f294ee6c 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -53,6 +53,7 @@ it 'provides an array of defined Enums' do expect(Test::EnumTestType.enums).to eq( [ + Test::EnumTestType::ZERO, Test::EnumTestType::ONE, Test::EnumTestType::TWO, Test::EnumTestType::MINUS_ONE, @@ -76,6 +77,7 @@ describe '.enums_for_tag' do it 'returns an array of Enums for the given tag, if any' do + expect(EnumAliasTest.enums_for_tag(nil)).to eq([]) expect(EnumAliasTest.enums_for_tag(1)).to eq([EnumAliasTest::FOO, EnumAliasTest::BAR]) expect(EnumAliasTest.enums_for_tag(2)).to eq([EnumAliasTest::BAZ]) expect(EnumAliasTest.enums_for_tag(3)).to eq([]) @@ -124,6 +126,7 @@ it 'gets the Enum corresponding to the given tag' do expect(Test::EnumTestType.enum_for_tag(tag)).to eq(Test::EnumTestType.const_get(name)) expect(Test::EnumTestType.enum_for_tag(-5)).to be_nil + expect(Test::EnumTestType.enum_for_tag(nil)).to be_nil end end @@ -186,6 +189,7 @@ it 'provides a hash of defined Enums' do expect(Test::EnumTestType.values).to eq( :MINUS_ONE => Test::EnumTestType::MINUS_ONE, + :ZERO => Test::EnumTestType::ZERO, :ONE => Test::EnumTestType::ONE, :TWO => Test::EnumTestType::TWO, :THREE => Test::EnumTestType::THREE, diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e76fa269..471727dc 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -142,12 +142,12 @@ describe '#initialize' do it "defaults to the first value listed in the enum's type definition" do test_enum = Test::EnumTestMessage.new - expect(test_enum.non_default_enum).to eq(1) + expect(test_enum.non_default_enum).to eq(Test::EnumTestType.enums.first) end it "defaults to a a value with a name" do test_enum = Test::EnumTestMessage.new - expect(test_enum.non_default_enum.name).to eq(:ONE) + expect(test_enum.non_default_enum.name).to eq(Test::EnumTestType.enums.first.name) end it "exposes the enum getter raw value through ! method" do diff --git a/spec/support/protos/enum.pb.rb b/spec/support/protos/enum.pb.rb index 7442ec69..53f9cccd 100644 --- a/spec/support/protos/enum.pb.rb +++ b/spec/support/protos/enum.pb.rb @@ -18,6 +18,7 @@ module Test # Enum Classes # class EnumTestType < ::Protobuf::Enum + define :ZERO, 0 define :ONE, 1 define :TWO, 2 end diff --git a/spec/support/protos/enum.proto b/spec/support/protos/enum.proto index f3f08647..1d1abb32 100644 --- a/spec/support/protos/enum.proto +++ b/spec/support/protos/enum.proto @@ -6,6 +6,7 @@ import 'protos/resource.proto'; // Test extending another message from an imported file. enum EnumTestType { + ZERO = 0; ONE = 1; TWO = 2; } From b78a8895a294be0828c4c526beda993e2ad8324e Mon Sep 17 00:00:00 2001 From: Evan Kuchar Date: Tue, 21 Feb 2017 13:10:23 -0800 Subject: [PATCH 1033/1191] Update rubocop and fix cops --- .rubocop.yml | 5 +- .rubocop_todo.yml | 8 +++- lib/protobuf.rb | 15 +++--- lib/protobuf/cli.rb | 26 +++++----- lib/protobuf/code_generator.rb | 2 +- lib/protobuf/enum.rb | 2 +- lib/protobuf/field/bytes_field.rb | 13 ++--- lib/protobuf/generators/base.rb | 12 ++--- lib/protobuf/generators/field_generator.rb | 6 +-- lib/protobuf/generators/printable.rb | 4 +- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/message.rb | 48 +++++++++---------- lib/protobuf/message/fields.rb | 28 +++++------ lib/protobuf/message/serialization.rb | 18 +++---- lib/protobuf/optionable.rb | 20 ++++---- lib/protobuf/rpc/buffer.rb | 13 ++--- lib/protobuf/rpc/connectors/base.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/servers/socket/server.rb | 8 ++-- lib/protobuf/rpc/servers/zmq/broker.rb | 13 ++--- lib/protobuf/rpc/servers/zmq/server.rb | 15 +++--- lib/protobuf/rpc/servers/zmq/util.rb | 12 ++--- lib/protobuf/rpc/servers/zmq/worker.rb | 13 ++--- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 2 +- lib/protobuf/version.rb | 2 +- protobuf.gemspec | 2 +- spec/lib/protobuf/enum_spec.rb | 4 +- spec/lib/protobuf/rpc/service_filters_spec.rb | 4 +- spec/lib/protobuf/varint_spec.rb | 2 +- spec/support/server.rb | 2 +- 31 files changed, 161 insertions(+), 146 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1ed3b0d4..9e7ff4bd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,7 +56,10 @@ Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' -Style/TrailingComma: +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInLiteral: EnforcedStyleForMultiline: comma Style/TrivialAccessors: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b3c35e05..611730ad 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -43,6 +43,9 @@ Performance/StringReplacement: Exclude: - 'lib/protobuf/rpc/buffer.rb' +Performance/TimesMap: + Enabled: false + # Offense count: 127 # Configuration parameters: Exclude. Style/Documentation: @@ -113,6 +116,9 @@ Style/ExtraSpacing: Style/NumericLiterals: MinDigits: 21 +Style/SignalException: + Enabled: false + # Offense count: 473 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. @@ -136,4 +142,4 @@ Style/SymbolProc: # Cop supports --auto-correct. # Configuration parameters: WordRegex. Style/WordArray: - MinSize: 2 + MinSize: 4 diff --git a/lib/protobuf.rb b/lib/protobuf.rb index b39108c7..5efb8780 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -95,14 +95,15 @@ def self.ignore_unknown_fields=(value) if [:zmq, :socket].include?(symbolized_connector_type) require "protobuf/#{symbolized_connector_type}" - case symbolized_connector_type - when :zmq - ::Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Zmq - else - ::Protobuf.connector_type_class = ::Protobuf::Rpc::Connectors::Socket - end + ::Protobuf.connector_type_class = + case symbolized_connector_type + when :zmq + ::Protobuf::Rpc::Connectors::Zmq + else + ::Protobuf::Rpc::Connectors::Socket + end else - require "#{env_connector_type}" + require "#{env_connector_type}" # rubocop:disable Style/UnneededInterpolation classified = env_connector_type.classify ::Protobuf.connector_type_class = classified.constantize end diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 1a7bbecd..3432a0dd 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -72,11 +72,12 @@ def version # Tell protobuf how to handle the printing of deprecated field usage. def configure_deprecation_warnings - if options.print_deprecation_warnings.nil? - ::Protobuf.print_deprecation_warnings = !ENV.key?("PB_IGNORE_DEPRECATIONS") - else - ::Protobuf.print_deprecation_warnings = options.print_deprecation_warnings? - end + ::Protobuf.print_deprecation_warnings = + if options.print_deprecation_warnings.nil? + !ENV.key?("PB_IGNORE_DEPRECATIONS") + else + options.print_deprecation_warnings? + end end # If we pause during request we don't need to pause in serialization @@ -85,12 +86,13 @@ def configure_gc debug_say('Configuring gc') - if defined?(JRUBY_VERSION) - # GC.enable/disable are noop's on Jruby - ::Protobuf.gc_pause_server_request = false - else - ::Protobuf.gc_pause_server_request = options.gc_pause_request? - end + ::Protobuf.gc_pause_server_request = + if defined?(JRUBY_VERSION) + # GC.enable/disable are noop's on Jruby + false + else + options.gc_pause_request? + end end # Setup the protobuf logger. @@ -129,7 +131,7 @@ def configure_runner_mode when /\Azmq[[:space:]]*\z/i :zmq else - require "#{server_type}" + require server_type.to_s server_type end end diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 70ec1303..978cf412 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -11,7 +11,7 @@ def self.fatal(message) def self.print_tag_warning_suppress STDERR.puts "Suppress tag warning output with PB_NO_TAG_WARNINGS=1." - def self.print_tag_warning_suppress; end + def self.print_tag_warning_suppress; end # rubocop:disable Lint/DuplicateMethods, Lint/NestedMethodDefinition end def self.warn(message) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 35bfa226..c0e012c6 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -309,6 +309,6 @@ def try(*args, &block) ## # Instance Aliases # - alias_method :to_hash_value, :to_i + alias :to_hash_value to_i end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 033a083e..b5950ed6 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -33,11 +33,12 @@ def decode(bytes) end def encode(value) - if value.is_a?(::Protobuf::Message) - value_to_encode = value.encode - else - value_to_encode = value.dup - end + value_to_encode = + if value.is_a?(::Protobuf::Message) + value.encode + else + value.dup + end value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) @@ -52,7 +53,7 @@ def wire_type def coerce!(value) case value when String, Symbol - "#{value}" + value.to_s when NilClass nil when ::Protobuf::Message diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 6e7304c5..ef7b2ea5 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -36,18 +36,18 @@ def fully_qualified_type_namespace ".#{type_namespace.join('.')}" end - def run_once(label, &block) + def run_once(label) tracker_ivar = "@_#{label}_compiled" value_ivar = "@_#{label}_compiled_value" if instance_variable_get(tracker_ivar) return instance_variable_get(value_ivar) - else - return_value = block.call - instance_variable_set(tracker_ivar, true) - instance_variable_set(value_ivar, return_value) - return return_value end + + return_value = yield + instance_variable_set(tracker_ivar, true) + instance_variable_set(value_ivar, return_value) + return_value end def to_s diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 88e2be1b..9f4e11f0 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -7,9 +7,9 @@ class FieldGenerator < Base ## # Constants # - PROTO_INFINITY_DEFAULT = /^inf$/i.freeze - PROTO_NEGATIVE_INFINITY_DEFAULT = /^-inf$/i.freeze - PROTO_NAN_DEFAULT = /^nan$/i.freeze + PROTO_INFINITY_DEFAULT = /^inf$/i + PROTO_NEGATIVE_INFINITY_DEFAULT = /^-inf$/i + PROTO_NAN_DEFAULT = /^nan$/i RUBY_INFINITY_DEFAULT = '::Float::INFINITY'.freeze RUBY_NEGATIVE_INFINITY_DEFAULT = '-::Float::INFINITY'.freeze RUBY_NAN_DEFAULT = '::Float::NAN'.freeze diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 065ee11d..4a4f4dee 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -93,14 +93,14 @@ def parent_class(type) # If a block is given, call the block from within an indent block. # Otherwise, end the block on the same line. # - def print_block(name, parent_klass, type, &block) + def print_block(name, parent_klass, type) name = modulize(name) block_def = "#{type} #{name}" block_def += " < #{parent_class(parent_klass)}" if parent_klass if block_given? puts block_def - indent { block.call } + indent { yield } puts "end" puts else diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 230b99ea..a17aac5c 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -9,7 +9,7 @@ def register(event_name) yield(*args) end end - alias_method :on, :register + alias :on register def trigger(event_name, *args) event_name = normalized_event_name(event_name) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a0d4234a..5fc39f2c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -150,16 +150,16 @@ def ==(other) end def [](name) - if (field = self.class.get_field(name, true)) - if field.repeated? - @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) - elsif @values.key?(field.fully_qualified_name) - @values[field.fully_qualified_name] - else - field.default_value - end + field = self.class.get_field(name, true) + + fail ArgumentError, "invalid field name=#{name.inspect}" unless field + + if field.repeated? + @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) + elsif @values.key?(field.fully_qualified_name) + @values[field.fully_qualified_name] else - fail ArgumentError, "invalid field name=#{name.inspect}" + field.default_value end end @@ -170,17 +170,17 @@ def []=(name, value) ## # Instance Aliases # - alias_method :to_hash_value, :to_hash - alias_method :to_proto_hash, :to_hash - alias_method :responds_to_has?, :respond_to_has? - alias_method :respond_to_and_has?, :respond_to_has? - alias_method :responds_to_and_has?, :respond_to_has? - alias_method :respond_to_has_present?, :respond_to_has_and_present? - alias_method :respond_to_and_has_present?, :respond_to_has_and_present? - alias_method :respond_to_and_has_and_present?, :respond_to_has_and_present? - alias_method :responds_to_has_present?, :respond_to_has_and_present? - alias_method :responds_to_and_has_present?, :respond_to_has_and_present? - alias_method :responds_to_and_has_and_present?, :respond_to_has_and_present? + alias :to_hash_value to_hash + alias :to_proto_hash to_hash + alias :responds_to_has? respond_to_has? + alias :respond_to_and_has? respond_to_has? + alias :responds_to_and_has? respond_to_has? + alias :respond_to_has_present? respond_to_has_and_present? + alias :respond_to_and_has_present? respond_to_has_and_present? + alias :respond_to_and_has_and_present? respond_to_has_and_present? + alias :responds_to_has_present? respond_to_has_and_present? + alias :responds_to_and_has_present? respond_to_has_and_present? + alias :responds_to_and_has_and_present? respond_to_has_and_present? ## # Private Instance Methods @@ -195,15 +195,15 @@ def set_field(name, value, ignore_nil_for_repeated) ::Protobuf.deprecator.deprecation_warning("#{self.class}#[#{name}]=nil", "use an empty array instead of nil") return end - if value.is_a?(Array) - value = value.compact - else + unless value.is_a?(Array) fail TypeError, <<-TYPE_ERROR Expected repeated value of type '#{field.type_class}' Got '#{value.class}' for repeated protobuf field #{field.name} TYPE_ERROR end + value = value.compact + if value.empty? @values.delete(field.fully_qualified_name) else @@ -211,7 +211,7 @@ def set_field(name, value, ignore_nil_for_repeated) @values[field.fully_qualified_name].replace(value) end else - if value.nil? + if value.nil? # rubocop:disable Style/IfInsideElse @values.delete(field.fully_qualified_name) elsif field.acceptable?(value) @values[field.fully_qualified_name] = field.coerce!(value) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 4692ab22..296ba482 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -134,25 +134,23 @@ def define_field(rule, type_class, fully_qualified_field_name, tag, options) # message[:'.my_package.string_field'] #=> @values[".my_package.string_field"] # message[:'.my_package.string_field'] #=> @values[".my_package.string_field"] - if options[:extension] - base_name = fully_qualified_field_name.to_s.split('.').last.to_sym - if field_store[base_name] - # Case 3 - if field_store[base_name].extension? - remove_existing_accessors(base_name) - simple_name = nil - # Case 2 + simple_name = + if options[:extension] + base_name = fully_qualified_field_name.to_s.split('.').last.to_sym + if field_store[base_name] + # Case 3 + if field_store[base_name].extension? + remove_existing_accessors(base_name) + end + nil + # Case 4 else - simple_name = nil + base_name end - # Case 4 else - simple_name = base_name + # Case 1 + fully_qualified_field_name end - else - # Case 1 - simple_name = fully_qualified_field_name - end field = ::Protobuf::Field.build(self, rule, type_class, fully_qualified_field_name, tag, simple_name, options) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 6526a95c..de6aa40d 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -63,15 +63,15 @@ def encode_to(stream) ## # Instance Aliases # - alias_method :parse_from_string, :decode - alias_method :deserialize, :decode - alias_method :parse_from, :decode_from - alias_method :deserialize_from, :decode_from - alias_method :to_s, :encode - alias_method :bytes, :encode - alias_method :serialize, :encode - alias_method :serialize_to_string, :encode - alias_method :serialize_to, :encode_to + alias :parse_from_string decode + alias :deserialize decode + alias :parse_from decode_from + alias :deserialize_from decode_from + alias :to_s encode + alias :bytes encode + alias :serialize encode + alias :serialize_to_string encode + alias :serialize_to encode_to private diff --git a/lib/protobuf/optionable.rb b/lib/protobuf/optionable.rb index c1d794f2..34b00c93 100644 --- a/lib/protobuf/optionable.rb +++ b/lib/protobuf/optionable.rb @@ -10,11 +10,12 @@ def get_option(name) # are accessing options correctly. We allow simple names in other places for backwards compatibility. fail ArgumentError, "must access option using its fully qualified name: #{option.fully_qualified_name.inspect}" end - if @_optionable_options.try(:key?, name) - value = @_optionable_options[name] - else - value = option.default_value - end + value = + if @_optionable_options.try(:key?, name) + @_optionable_options[name] + else + option.default_value + end if option.type_class < ::Protobuf::Message option.type_class.new(value) else @@ -51,11 +52,10 @@ def self.inject(base_class, extend_class = true, &block) # File options are injected per module, and since a module can be defined more than once, # we will get a warning if we try to define optionable_descriptor_class twice. if base_class.respond_to?(:optionable_descriptor_class) - if base_class.optionable_descriptor_class != block.call - fail 'A class is being defined with two different descriptor classes, something is very wrong' - else - return # Don't define optionable_descriptor_class twice - end + # Don't define optionable_descriptor_class twice + return if base_class.optionable_descriptor_class == block.call + + fail 'A class is being defined with two different descriptor classes, something is very wrong' end base_class.extend(ClassMethods) diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 92309c04..53f163f2 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -4,7 +4,7 @@ class Buffer attr_accessor :mode, :data, :size - MODES = [:read, :write] + MODES = [:read, :write].freeze # constantize this so we don't re-initialize the regex every time we need it SIZE_REGEX = /^\d+-/ @@ -17,11 +17,12 @@ def initialize(mode = :read) end def mode=(mode) - if MODES.include?(mode) - @mode = mode - else - @mode = :read - end + @mode = + if MODES.include?(mode) + mode + else + :read + end end def write(force_mode = true) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 45198f4e..7d9529db 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -19,7 +19,7 @@ module Connectors :timeout => nil, # The timeout for the request, also handled by client.rb :client_host => nil, # The hostname or address of this client :first_alive_load_balance => false, # Do we want to use check_avail frames before request - } + }.freeze class Base include Protobuf::Logging diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a5f5722e..a81edb81 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -270,7 +270,7 @@ def zmq_context def zmq_eagain_error_check(return_code, source) return if ::ZMQ::Util.resultcode_ok?(return_code || -1) - if ::ZMQ::Util.errno == ::ZMQ::EAGAIN + if ::ZMQ::Util.errno == ::ZMQ::EAGAIN # rubocop:disable Style/GuardClause fail ZmqEagainError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index eabbbd61..28cde2eb 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -18,7 +18,7 @@ class Server public attr_reader :running - alias_method :running?, :running + alias :running? running def initialize(options) self.running = false @@ -38,7 +38,7 @@ def working def cleanup? # every `threshold` connections run a cleanup routine after closing the response - threads.size > 0 && threads.size % threshold == 0 + !threads.empty? && threads.size % threshold == 0 end def cleanup_threads @@ -102,9 +102,9 @@ def run end end end - else + elsif threads.size > 1 # Run a cleanup if select times out while waiting - cleanup_threads if threads.size > 1 + cleanup_threads end end ensure diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 84017e57..2b12aee8 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -107,11 +107,12 @@ def init_poller end def init_zmq_context - if inproc? - @zmq_context = @server.zmq_context - else - @zmq_context = ZMQ::Context.new - end + @zmq_context = + if inproc? + @server.zmq_context + else + ZMQ::Context.new + end end def inproc? @@ -146,7 +147,7 @@ def process_frontend write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) end else - if @idle_workers.empty? + if @idle_workers.empty? # rubocop:disable Style/IfInsideElse local_queue << [address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message].concat(frames) else write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message]).concat(frames)) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index f2c2d9e8..b5dce25a 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -16,7 +16,7 @@ class Server :broadcast_beacons => false, :broadcast_busy => false, :zmq_inproc => true, - } + }.freeze attr_accessor :options, :workers attr_reader :zmq_context @@ -117,7 +117,7 @@ def busy_worker_count def frontend_ip @frontend_ip ||= resolve_ip(options[:host]) end - alias_method :backend_ip, :frontend_ip + alias :backend_ip frontend_ip def frontend_port options[:port] @@ -217,11 +217,12 @@ def teardown end def timeout - if @timeout.nil? - @timeout = 0 - else - @timeout = [minimum_timeout, maintenance_timeout].max - end + @timeout = + if @timeout.nil? + 0 + else + [minimum_timeout, maintenance_timeout].max + end end def total_workers diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 2d0c9c8b..37926464 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -4,12 +4,12 @@ module Protobuf module Rpc module Zmq - ADDRESS_MATCH = /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/.freeze - WORKER_READY_MESSAGE = "\1" - CHECK_AVAILABLE_MESSAGE = "\3" - NO_WORKERS_AVAILABLE = "\4" - WORKERS_AVAILABLE = "\5" - EMPTY_STRING = "" + ADDRESS_MATCH = /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/ + WORKER_READY_MESSAGE = "\1".freeze + CHECK_AVAILABLE_MESSAGE = "\3".freeze + NO_WORKERS_AVAILABLE = "\4".freeze + WORKERS_AVAILABLE = "\5".freeze + EMPTY_STRING = "".freeze module Util include ::Protobuf::Logging diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index cf606615..85e4aa2a 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -47,7 +47,7 @@ def run loop do rc = poller.poll(500) - if rc == 0 && !running? + if rc == 0 && !running? # rubocop:disable Style/GuardClause break # The server was shutdown and no requests are pending elsif rc == -1 break # Something went wrong @@ -68,11 +68,12 @@ def running? private def init_zmq_context - if inproc? - @zmq_context = @server.zmq_context - else - @zmq_context = ZMQ::Context.new - end + @zmq_context = + if inproc? + @server.zmq_context + else + ZMQ::Context.new + end end def init_backend_socket diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 35ae255a..8a4ff3c8 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -154,7 +154,7 @@ def request_type def respond_with(candidate) @response = candidate end - alias_method :return_from_whence_you_came, :respond_with + alias :return_from_whence_you_came respond_with def response_type @response_type ||= env.response_type diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 272c3e85..7c467358 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -21,7 +21,7 @@ class ServiceDirectory include ::Singleton include ::Protobuf::Logging - DEFAULT_ADDRESS = "0.0.0.0" + DEFAULT_ADDRESS = '0.0.0.0'.freeze DEFAULT_PORT = 53000 DEFAULT_TIMEOUT = 1 diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index ba3f909b..a1fb101d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.12' + VERSION = '3.6.12' # rubocop:disable Style/MutableConstant end diff --git a/protobuf.gemspec b/protobuf.gemspec index 5bbfb621..624a43eb 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -29,7 +29,7 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses s.add_development_dependency 'rspec', '>= 3.0' - s.add_development_dependency "rubocop", "~> 0.35.0" + s.add_development_dependency "rubocop", "~> 0.38.0" s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984 s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index f294ee6c..3084647f 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -58,7 +58,7 @@ Test::EnumTestType::TWO, Test::EnumTestType::MINUS_ONE, Test::EnumTestType::THREE, - ] + ], ) end @@ -69,7 +69,7 @@ EnumAliasTest::FOO, EnumAliasTest::BAR, EnumAliasTest::BAZ, - ] + ], ) end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index f63c41c0..97cc5b2d 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -362,7 +362,7 @@ def inner_around :endpoint, :inner_around_bottom, :outer_around_bottom, - ] + ], ) end @@ -390,7 +390,7 @@ def inner_around :outer_around_top, :inner_around, :outer_around_bottom, - ] + ], ) end diff --git a/spec/lib/protobuf/varint_spec.rb b/spec/lib/protobuf/varint_spec.rb index 3a03d306..78c2206e 100644 --- a/spec/lib/protobuf/varint_spec.rb +++ b/spec/lib/protobuf/varint_spec.rb @@ -11,7 +11,7 @@ 913_389 => "7d83", 516_192_829_912_693 => "9eyMkpivdQ==", 9_999_999_999_999_999_999 => "//+fz8jgyOOKAQ==", - } + }.freeze [defined?(::Varint) ? ::Varint : nil, Protobuf::VarintPure].compact.each do |klass| context "with #{klass}" do diff --git a/spec/support/server.rb b/spec/support/server.rb index ecc6a6cd..8a0203b6 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -31,7 +31,7 @@ def initialize(options = {}) :worker_port => 9400, :delay => 0, :server => Protobuf::Rpc::Socket::Server, - ) + ), ) start From 9ec8205107359d6161dd6cbd7482611821b89727 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 1 Mar 2017 11:58:49 -0800 Subject: [PATCH 1034/1191] pull in acceptable? optimization for varint and fix rubocop for previously merged PR --- .../google/protobuf/compiler/plugin.pb.rb | 7 ++++++ .../google/protobuf/descriptor.pb.rb | 1 - lib/protobuf/field/varint_field.rb | 9 +++++-- spec/lib/protobuf/generators/base_spec.rb | 24 +++++++++++++++---- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb index 91cfe185..354aa845 100644 --- a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -27,6 +27,13 @@ class File < ::Protobuf::Message; end + ## + # File Options + # + set_option :java_package, "com.google.protobuf.compiler" + set_option :java_outer_classname, "PluginProtos" + + ## # Message Fields # diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index 56ebbed5..534d83a5 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -295,7 +295,6 @@ class Location repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1 end - end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 59fabdcb..f1d7ffbd 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -50,9 +50,14 @@ def self.encode(value, use_cache = true) ## # Public Instance Methods # - def acceptable?(val) - int_val = coerce!(val) + int_val = if val.is_a?(Integer) + return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path + val + else + coerce!(val) + end + int_val >= self.class.min && int_val <= self.class.max rescue false diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 43d25e84..d6128ac1 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -111,6 +111,24 @@ def compile end it 'serializes messages' do + output_string = <<-STRING + { :foo => "space", + :bar => [{ + :foo => "station", + :bar => { :foo => "orbit" }, + :boom => 123, + :goat => ::MyEnum::FOO, + :bam => false, + :fire => 3.5 }], + :boom => 456, + :goat => ::MyEnum::BOO, + :bam => true, :fire => 1.2 } + STRING + + output_string.lstrip! + output_string.rstrip! + output_string.delete!("\n") + output_string.squeeze!(" ") expect(generator.serialize_value(MyMessage3.new( :foo => 'space', :bar => [MyMessage2.new( @@ -125,11 +143,7 @@ def compile :goat => MyEnum::BOO, :bam => true, :fire => 1.2, - ))).to eq( - '{ :foo => "space", :bar => [{ '\ - ':foo => "station", :bar => { :foo => "orbit" }, :boom => 123, :goat => ::MyEnum::FOO, :bam => false, :fire => 3.5 '\ - '}], :boom => 456, :goat => ::MyEnum::BOO, :bam => true, :fire => 1.2 }' - ) + ))).to eq(output_string) end it 'serializes enums' do From 709a5ee6561e3ee5d603a5b8e788da061412006b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 1 Mar 2017 14:02:10 -0800 Subject: [PATCH 1035/1191] cache the boolean encoded values and compare static values instead of using array methods --- lib/protobuf/field/bool_field.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 97f81557..6eb8e5a2 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -3,7 +3,9 @@ module Protobuf module Field class BoolField < VarintField + FALSE_ENCODE = [0].pack('C') FALSE_STRING = "false".freeze + TRUE_ENCODE = [1].pack('C') TRUE_STRING = "true".freeze ## @@ -19,16 +21,16 @@ def self.default # # def acceptable?(val) - [true, false].include?(val) || %w(true false).include?(val) + val == true || val == false || val == TRUE_STRING || val == FALSE_STRING end def coerce!(val) - case val - when String - val == TRUE_STRING - else - val - end + return true if val == true + return false if val == false + return true if val == TRUE_STRING + return false if val == FALSE_STRING + + val end def decode(value) @@ -36,7 +38,7 @@ def decode(value) end def encode(value) - [value ? 1 : 0].pack('C') + value ? TRUE_ENCODE : FALSE_ENCODE end private From 0ccc40b5c5dd08e8f0d2f458cd64dc27f399baf2 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 1 Mar 2017 16:39:07 -0800 Subject: [PATCH 1036/1191] Add support for custom field options --- lib/protobuf/field/base_field.rb | 8 +- lib/protobuf/generators/field_generator.rb | 7 ++ .../generators/field_generator_spec.rb | 49 ++++++++ spec/lib/protobuf/optionable_spec.rb | 18 +++ spec/support/protos/google_unittest.pb.rb | 114 +++++++++--------- .../google_unittest_custom_options.pb.rb | 8 +- spec/support/protos/resource.pb.rb | 6 +- spec/support/protos/resource.proto | 6 +- 8 files changed, 152 insertions(+), 64 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 111f8be7..f58edca7 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/hash/slice' require 'protobuf/field/field_array' module Protobuf module Field @@ -39,7 +40,12 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl @rule = rule @tag = tag @type_class = type_class - @options = options + # Populate the option hash with all the original default field options, for backwards compatibility. + # However, both default and custom options should ideally be accessed through the Optionable .{get,get!}_option functions. + @options = options.slice(:ctype, :packed, :deprecated, :lazy, :jstype, :weak, :uninterpreted_option, :default, :extension) + options.each do |option_name, value| + set_option(option_name, value) + end validate_packed_field if packed? define_accessor(simple_name, fully_qualified_name) if simple_name diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 9f4e11f0..11e2a448 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -84,6 +84,13 @@ def field_options opts[:packed] = 'true' if packed? opts[:deprecated] = 'true' if deprecated? opts[:extension] = 'true' if extension? + if descriptor.options + descriptor.options.each_field do |field_option| + next unless descriptor.options.field?(field_option.name) + option_value = descriptor.options[field_option.name] + opts[field_option.fully_qualified_name] = serialize_value(option_value) + end + end opts end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 246e4649..9e5f5676 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -97,6 +97,55 @@ specify { expect(subject).to eq "optional :string, :foo_bar, 3, :deprecated => true\n" } end + + context 'when field uses a custom option that is an extension' do + class ::CustomFieldEnum < ::Protobuf::Enum + define :BOOM, 1 + define :BAM, 2 + end + + class ::CustomFieldMessage < ::Protobuf::Message + optional :string, :foo, 1 + end + + class ::Google::Protobuf::FieldOptions < ::Protobuf::Message + optional :string, :custom_string_option, 22000, :extension => true + optional :bool, :custom_bool_option, 22001, :extension => true + optional :int32, :custom_int32_option, 22002, :extension => true + optional ::CustomFieldEnum, :custom_enum_option, 22003, :extension => true + optional ::CustomFieldMessage, :custom_message_option, 22004, :extension => true + end + + describe 'option has a string value' do + let(:field_options) { { :custom_string_option => 'boom' } } + + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_string_option => \"boom\"\n" } + end + + describe 'option has a bool value' do + let(:field_options) { { :custom_bool_option => true } } + + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_bool_option => true\n" } + end + + describe 'option has a int32 value' do + let(:field_options) { { :custom_int32_option => 123 } } + + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_int32_option => 123\n" } + end + + describe 'option has a message value' do + let(:field_options) { { :custom_message_option => CustomFieldMessage.new(:foo => 'boom') } } + + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_message_option => { :foo => \"boom\" }\n" } + end + + describe 'option has a enum value' do + let(:field_options) { { :custom_enum_option => CustomFieldEnum::BAM } } + + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_enum_option => ::CustomFieldEnum::BAM\n" } + end + end end end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 888db6ec..8f2b1432 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -183,5 +183,23 @@ def optionable_descriptor_class expect(::Test.get_option!(:".test.file_option")).to eq(9876543210) end end + + context 'field options' do + subject { ::Test::Resource.fields[0] } + + it 'gets base options' do + expect(subject.get_option!(:ctype)) + .to eq(::Google::Protobuf::FieldOptions::CType::CORD) + end + + it 'gets unset options' do + expect(subject.get_option!(:lazy)).to eq(nil) + expect(subject.get_option(:lazy)).to eq(false) + end + + it 'gets custom options' do + expect(subject.get_option!(:".test.field_option")).to eq(8765432109) + end + end end end diff --git a/spec/support/protos/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb index 3ce016fd..c6d86022 100644 --- a/spec/support/protos/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -224,10 +224,10 @@ class RepeatedGroup optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21 optional ::Protobuf_unittest::ForeignEnum, :optional_foreign_enum, 22 optional ::Protobuf_unittest_import::ImportEnum, :optional_import_enum, 23 - optional :string, :optional_string_piece, 24 - optional :string, :optional_cord, 25 + optional :string, :optional_string_piece, 24, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + optional :string, :optional_cord, 25, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD optional ::Protobuf_unittest_import::PublicImportMessage, :optional_public_import_message, 26 - optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27, :lazy => true repeated :int32, :repeated_int32, 31 repeated :int64, :repeated_int64, 32 repeated :uint32, :repeated_uint32, 33 @@ -250,9 +250,9 @@ class RepeatedGroup repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51 repeated ::Protobuf_unittest::ForeignEnum, :repeated_foreign_enum, 52 repeated ::Protobuf_unittest_import::ImportEnum, :repeated_import_enum, 53 - repeated :string, :repeated_string_piece, 54 - repeated :string, :repeated_cord, 55 - repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57 + repeated :string, :repeated_string_piece, 54, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + repeated :string, :repeated_cord, 55, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57, :lazy => true optional :int32, :default_int32, 61, :default => 41 optional :int64, :default_int64, 62, :default => 42 optional :uint32, :default_uint32, 63, :default => 43 @@ -271,8 +271,8 @@ class RepeatedGroup optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR optional ::Protobuf_unittest::ForeignEnum, :default_foreign_enum, 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR optional ::Protobuf_unittest_import::ImportEnum, :default_import_enum, 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR - optional :string, :default_string_piece, 84, :default => "abc" - optional :string, :default_cord, 85, :default => "123" + optional :string, :default_string_piece, 84, :default => "abc", :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + optional :string, :default_cord, 85, :default => "123", :ctype => ::Google::Protobuf::FieldOptions::CType::CORD optional :uint32, :oneof_uint32, 111 optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :oneof_nested_message, 112 optional :string, :oneof_string, 113 @@ -318,10 +318,10 @@ class TestAllExtensions optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.optional_nested_enum_extension", 21, :extension => true optional ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.optional_foreign_enum_extension", 22, :extension => true optional ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.optional_import_enum_extension", 23, :extension => true - optional :string, :".protobuf_unittest.optional_string_piece_extension", 24, :extension => true - optional :string, :".protobuf_unittest.optional_cord_extension", 25, :extension => true + optional :string, :".protobuf_unittest.optional_string_piece_extension", 24, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + optional :string, :".protobuf_unittest.optional_cord_extension", 25, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD optional ::Protobuf_unittest_import::PublicImportMessage, :".protobuf_unittest.optional_public_import_message_extension", 26, :extension => true - optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.optional_lazy_message_extension", 27, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.optional_lazy_message_extension", 27, :extension => true, :lazy => true repeated :int32, :".protobuf_unittest.repeated_int32_extension", 31, :extension => true repeated :int64, :".protobuf_unittest.repeated_int64_extension", 32, :extension => true repeated :uint32, :".protobuf_unittest.repeated_uint32_extension", 33, :extension => true @@ -344,9 +344,9 @@ class TestAllExtensions repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.repeated_nested_enum_extension", 51, :extension => true repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.repeated_foreign_enum_extension", 52, :extension => true repeated ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.repeated_import_enum_extension", 53, :extension => true - repeated :string, :".protobuf_unittest.repeated_string_piece_extension", 54, :extension => true - repeated :string, :".protobuf_unittest.repeated_cord_extension", 55, :extension => true - repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.repeated_lazy_message_extension", 57, :extension => true + repeated :string, :".protobuf_unittest.repeated_string_piece_extension", 54, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + repeated :string, :".protobuf_unittest.repeated_cord_extension", 55, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.repeated_lazy_message_extension", 57, :extension => true, :lazy => true optional :int32, :".protobuf_unittest.default_int32_extension", 61, :default => 41, :extension => true optional :int64, :".protobuf_unittest.default_int64_extension", 62, :default => 42, :extension => true optional :uint32, :".protobuf_unittest.default_uint32_extension", 63, :default => 43, :extension => true @@ -365,8 +365,8 @@ class TestAllExtensions optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.default_nested_enum_extension", 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, :extension => true optional ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.default_foreign_enum_extension", 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, :extension => true optional ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.default_import_enum_extension", 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, :extension => true - optional :string, :".protobuf_unittest.default_string_piece_extension", 84, :default => "abc", :extension => true - optional :string, :".protobuf_unittest.default_cord_extension", 85, :default => "123", :extension => true + optional :string, :".protobuf_unittest.default_string_piece_extension", 84, :default => "abc", :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + optional :string, :".protobuf_unittest.default_cord_extension", 85, :default => "123", :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD optional :uint32, :".protobuf_unittest.oneof_uint32_extension", 111, :extension => true optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.oneof_nested_message_extension", 112, :extension => true optional :string, :".protobuf_unittest.oneof_string_extension", 113, :extension => true @@ -466,11 +466,11 @@ class Bar end class TestEagerMessage - optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1 + optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1, :lazy => false end class TestLazyMessage - optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1 + optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1, :lazy => true end class TestNestedMessageHasBits @@ -487,14 +487,14 @@ class TestCamelCaseFieldNames optional :string, :StringField, 2 optional ::Protobuf_unittest::ForeignEnum, :EnumField, 3 optional ::Protobuf_unittest::ForeignMessage, :MessageField, 4 - optional :string, :StringPieceField, 5 - optional :string, :CordField, 6 + optional :string, :StringPieceField, 5, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + optional :string, :CordField, 6, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD repeated :int32, :RepeatedPrimitiveField, 7 repeated :string, :RepeatedStringField, 8 repeated ::Protobuf_unittest::ForeignEnum, :RepeatedEnumField, 9 repeated ::Protobuf_unittest::ForeignMessage, :RepeatedMessageField, 10 - repeated :string, :RepeatedStringPieceField, 11 - repeated :string, :RepeatedCordField, 12 + repeated :string, :RepeatedStringPieceField, 11, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + repeated :string, :RepeatedCordField, 12, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD end class TestFieldOrderings @@ -539,8 +539,8 @@ class TestExtremeDefaultValues optional :string, :cpp_trigraph, 20, :default => "? ? ?? ?? ??? ??/ ??-" optional :string, :string_with_zero, 23, :default => "hello" optional :bytes, :bytes_with_zero, 24, :default => "wor\000ld" - optional :string, :string_piece_with_zero, 25, :default => "abc" - optional :string, :cord_with_zero, 26, :default => "123" + optional :string, :string_piece_with_zero, 25, :default => "abc", :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE + optional :string, :cord_with_zero, 26, :default => "123", :ctype => ::Google::Protobuf::FieldOptions::CType::CORD optional :string, :replacement_string, 27, :default => "${unknown}" end @@ -621,17 +621,17 @@ class NestedMessage optional :int32, :foo_int, 1 optional :string, :foo_string, 2 - optional :string, :foo_cord, 3 - optional :string, :foo_string_piece, 4 + optional :string, :foo_cord, 3, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD + optional :string, :foo_string_piece, 4, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE optional :bytes, :foo_bytes, 5 optional ::Protobuf_unittest::TestOneof2::NestedEnum, :foo_enum, 6 optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_message, 7 optional ::Protobuf_unittest::TestOneof2::FooGroup, :foogroup, 8 - optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_lazy_message, 11 + optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_lazy_message, 11, :lazy => true optional :int32, :bar_int, 12, :default => 5 optional :string, :bar_string, 13, :default => "STRING" - optional :string, :bar_cord, 14, :default => "CORD" - optional :string, :bar_string_piece, 15, :default => "SPIECE" + optional :string, :bar_cord, 14, :default => "CORD", :ctype => ::Google::Protobuf::FieldOptions::CType::CORD + optional :string, :bar_string_piece, 15, :default => "SPIECE", :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE optional :bytes, :bar_bytes, 16, :default => "BYTES" optional ::Protobuf_unittest::TestOneof2::NestedEnum, :bar_enum, 17, :default => ::Protobuf_unittest::TestOneof2::NestedEnum::BAR optional :int32, :baz_int, 18 @@ -666,20 +666,20 @@ class TestPackedTypes end class TestUnpackedTypes - repeated :int32, :unpacked_int32, 90 - repeated :int64, :unpacked_int64, 91 - repeated :uint32, :unpacked_uint32, 92 - repeated :uint64, :unpacked_uint64, 93 - repeated :sint32, :unpacked_sint32, 94 - repeated :sint64, :unpacked_sint64, 95 - repeated :fixed32, :unpacked_fixed32, 96 - repeated :fixed64, :unpacked_fixed64, 97 - repeated :sfixed32, :unpacked_sfixed32, 98 - repeated :sfixed64, :unpacked_sfixed64, 99 - repeated :float, :unpacked_float, 100 - repeated :double, :unpacked_double, 101 - repeated :bool, :unpacked_bool, 102 - repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum, 103 + repeated :int32, :unpacked_int32, 90, :packed => false + repeated :int64, :unpacked_int64, 91, :packed => false + repeated :uint32, :unpacked_uint32, 92, :packed => false + repeated :uint64, :unpacked_uint64, 93, :packed => false + repeated :sint32, :unpacked_sint32, 94, :packed => false + repeated :sint64, :unpacked_sint64, 95, :packed => false + repeated :fixed32, :unpacked_fixed32, 96, :packed => false + repeated :fixed64, :unpacked_fixed64, 97, :packed => false + repeated :sfixed32, :unpacked_sfixed32, 98, :packed => false + repeated :sfixed64, :unpacked_sfixed64, 99, :packed => false + repeated :float, :unpacked_float, 100, :packed => false + repeated :double, :unpacked_double, 101, :packed => false + repeated :bool, :unpacked_bool, 102, :packed => false + repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum, 103, :packed => false end class TestPackedExtensions @@ -704,20 +704,20 @@ class TestPackedExtensions class TestUnpackedExtensions # Extension Fields extensions 1...536870912 - repeated :int32, :".protobuf_unittest.unpacked_int32_extension", 90, :extension => true - repeated :int64, :".protobuf_unittest.unpacked_int64_extension", 91, :extension => true - repeated :uint32, :".protobuf_unittest.unpacked_uint32_extension", 92, :extension => true - repeated :uint64, :".protobuf_unittest.unpacked_uint64_extension", 93, :extension => true - repeated :sint32, :".protobuf_unittest.unpacked_sint32_extension", 94, :extension => true - repeated :sint64, :".protobuf_unittest.unpacked_sint64_extension", 95, :extension => true - repeated :fixed32, :".protobuf_unittest.unpacked_fixed32_extension", 96, :extension => true - repeated :fixed64, :".protobuf_unittest.unpacked_fixed64_extension", 97, :extension => true - repeated :sfixed32, :".protobuf_unittest.unpacked_sfixed32_extension", 98, :extension => true - repeated :sfixed64, :".protobuf_unittest.unpacked_sfixed64_extension", 99, :extension => true - repeated :float, :".protobuf_unittest.unpacked_float_extension", 100, :extension => true - repeated :double, :".protobuf_unittest.unpacked_double_extension", 101, :extension => true - repeated :bool, :".protobuf_unittest.unpacked_bool_extension", 102, :extension => true - repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.unpacked_enum_extension", 103, :extension => true + repeated :int32, :".protobuf_unittest.unpacked_int32_extension", 90, :extension => true, :packed => false + repeated :int64, :".protobuf_unittest.unpacked_int64_extension", 91, :extension => true, :packed => false + repeated :uint32, :".protobuf_unittest.unpacked_uint32_extension", 92, :extension => true, :packed => false + repeated :uint64, :".protobuf_unittest.unpacked_uint64_extension", 93, :extension => true, :packed => false + repeated :sint32, :".protobuf_unittest.unpacked_sint32_extension", 94, :extension => true, :packed => false + repeated :sint64, :".protobuf_unittest.unpacked_sint64_extension", 95, :extension => true, :packed => false + repeated :fixed32, :".protobuf_unittest.unpacked_fixed32_extension", 96, :extension => true, :packed => false + repeated :fixed64, :".protobuf_unittest.unpacked_fixed64_extension", 97, :extension => true, :packed => false + repeated :sfixed32, :".protobuf_unittest.unpacked_sfixed32_extension", 98, :extension => true, :packed => false + repeated :sfixed64, :".protobuf_unittest.unpacked_sfixed64_extension", 99, :extension => true, :packed => false + repeated :float, :".protobuf_unittest.unpacked_float_extension", 100, :extension => true, :packed => false + repeated :double, :".protobuf_unittest.unpacked_double_extension", 101, :extension => true, :packed => false + repeated :bool, :".protobuf_unittest.unpacked_bool_extension", 102, :extension => true, :packed => false + repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.unpacked_enum_extension", 103, :extension => true, :packed => false end class TestDynamicExtensions diff --git a/spec/support/protos/google_unittest_custom_options.pb.rb b/spec/support/protos/google_unittest_custom_options.pb.rb index e1f2576b..27e6218a 100644 --- a/spec/support/protos/google_unittest_custom_options.pb.rb +++ b/spec/support/protos/google_unittest_custom_options.pb.rb @@ -110,7 +110,7 @@ class TestMessageWithRequiredEnumOption < ::Protobuf::Message; end # Message Fields # class TestMessageWithCustomOptions - optional :string, :field1, 1 + optional :string, :field1, 1, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD, :".protobuf_unittest.field_opt1" => 8765432109 end class ComplexOptionType1 @@ -162,12 +162,12 @@ class Aggregate end class AggregateMessage - optional :int32, :fieldname, 1 + optional :int32, :fieldname, 1, :".protobuf_unittest.fieldopt" => { :s => "FieldAnnotation" } end class NestedOptionType class NestedMessage - optional :int32, :nested_field, 1 + optional :int32, :nested_field, 1, :".protobuf_unittest.field_opt1" => 1002 end end @@ -188,7 +188,7 @@ class ::Google::Protobuf::FileOptions < ::Protobuf::Message optional :uint64, :".protobuf_unittest.file_opt1", 7736974, :extension => true optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.fileopt", 15478479, :extension => true optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.Aggregate.nested", 15476903, :extension => true - optional :int32, :".protobuf_unittest.NestedOptionType.nested_extension", 7912573, :extension => true + optional :int32, :".protobuf_unittest.NestedOptionType.nested_extension", 7912573, :extension => true, :".protobuf_unittest.field_opt2" => 1005 end class ::Google::Protobuf::MessageOptions < ::Protobuf::Message diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index c13a5420..19f7d8c7 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -75,7 +75,7 @@ class ResourceSleepRequest end class Resource - required :string, :name, 1 + required :string, :name, 1, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD, :".test.field_option" => 8765432109 optional :int64, :date_created, 2 optional ::Test::StatusType, :status, 3 repeated ::Test::StatusType, :repeated_enum, 4 @@ -126,6 +126,10 @@ class ::Google::Protobuf::FileOptions < ::Protobuf::Message optional :uint64, :".test.file_option", 9585869, :extension => true end + class ::Google::Protobuf::FieldOptions < ::Protobuf::Message + optional :uint64, :".test.field_option", 858769, :extension => true + end + ## # Service Classes diff --git a/spec/support/protos/resource.proto b/spec/support/protos/resource.proto index 537e66cd..2e1d30ef 100644 --- a/spec/support/protos/resource.proto +++ b/spec/support/protos/resource.proto @@ -11,6 +11,10 @@ extend google.protobuf.FileOptions { optional uint64 file_option = 9585869; } +extend google.protobuf.FieldOptions { + optional uint64 field_option = 858769; +} + enum StatusType { PENDING = 0; ENABLED = 1; @@ -32,7 +36,7 @@ message ResourceSleepRequest { message Resource { extensions 100 to max; - required string name = 1; + required string name = 1 [(field_option) = 8765432109, ctype = CORD]; optional int64 date_created = 2; optional StatusType status = 3; repeated StatusType repeated_enum = 4; From 3c529321645b3c730187a44f82fafbd8acd1be62 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 2 Mar 2017 11:26:16 -0700 Subject: [PATCH 1037/1191] apply fixes from #344 --- lib/protobuf/rpc/connectors/base.rb | 4 ++-- lib/protobuf/rpc/error.rb | 4 ++-- lib/protobuf/rpc/middleware/request_decoder.rb | 2 +- lib/protobuf/rpc/middleware/response_encoder.rb | 6 +++--- spec/lib/protobuf/rpc/middleware/logger_spec.rb | 4 ++-- spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb | 8 ++++---- spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 7d9529db..e7e9195a 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -63,7 +63,7 @@ def data_callback(data) # @param [String] message The error message def failure(code, message) @error = ClientError.new - @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) + @error.code = ::Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } @@ -103,7 +103,7 @@ def parse_response # Parse out the raw response @stats.response_size = @response_data.size unless @response_data.nil? - response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) + response_wrapper = ::Protobuf::Socketrpc::Response.decode(@response_data) # Determine success or failure based on parsed data if response_wrapper.field?(:error_reason) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 9a3f8569..343d1889 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -9,7 +9,7 @@ class PbError < StandardError attr_reader :error_type def initialize(message = 'An unknown RpcError occurred', error_type = 'RPC_ERROR') - @error_type = error_type.is_a?(String) ? Socketrpc::ErrorReason.const_get(error_type) : error_type + @error_type = error_type.is_a?(String) ? ::Protobuf::Socketrpc::ErrorReason.const_get(error_type) : error_type super message end @@ -18,7 +18,7 @@ def encode end def to_response - Socketrpc::Response.new(:error => message, :error_reason => error_type) + ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type) end end end diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index eebaf931..45469883 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -54,7 +54,7 @@ def request # Decode the incoming request object into our expected request object # def request_wrapper - @request_wrapper ||= Socketrpc::Request.decode(env.encoded_request) + @request_wrapper ||= ::Protobuf::Socketrpc::Request.decode(env.encoded_request) rescue => exception raise BadRequestData, "Unable to decode request: #{exception.message}" end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 45f21aea..e7a9f2c4 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -71,10 +71,10 @@ def validate!(candidate) # it up so that it's in the correct spot in the response wrapper # def wrapped_response - if response.is_a?(Protobuf::Rpc::PbError) - Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) + if response.is_a?(::Protobuf::Rpc::PbError) + ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) else - Socketrpc::Response.new(:response_proto => response.encode) + ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode) end end end diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index 1c5ddd66..c30c9c19 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -21,13 +21,13 @@ let(:request) { request_type.new(:name => 'required') } let(:request_type) { rpc_method.request_type } let(:request_wrapper) do - Protobuf::Socketrpc::Request.new( + ::Protobuf::Socketrpc::Request.new( :service_name => service_name, :method_name => method_name.to_s, :request_proto => request, ) end - let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } + let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) } let(:response) { rpc_method.response_type.new(:name => 'required') } let(:rpc_method) { service_class.rpcs[method_name] } let(:rpc_service) { service_class.new(env) } diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 3132c85c..7c291053 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -14,7 +14,7 @@ let(:request) { request_type.new(:name => 'required') } let(:request_type) { rpc_method.request_type } let(:request_wrapper) do - Protobuf::Socketrpc::Request.new( + ::Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => service_name, :method_name => method_name.to_s, @@ -75,7 +75,7 @@ end context "when decoding fails" do - before { allow(Protobuf::Socketrpc::Request).to receive(:decode).and_raise(RuntimeError) } + before { allow(::Protobuf::Socketrpc::Request).to receive(:decode).and_raise(RuntimeError) } it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadRequestData) @@ -84,7 +84,7 @@ context "when the RPC service is not defined" do let(:request_wrapper) do - Protobuf::Socketrpc::Request.new( + ::Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => 'Foo', :method_name => method_name.to_s, @@ -99,7 +99,7 @@ context "when RPC method is not defined" do let(:request_wrapper) do - Protobuf::Socketrpc::Request.new( + ::Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => service_name, :method_name => 'foo', diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 7189a31a..106de050 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -10,7 +10,7 @@ end let(:encoded_response) { response_wrapper.encode } let(:response) { Test::Resource.new(:name => 'required') } - let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } + let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) } subject { described_class.new(app) } @@ -65,7 +65,7 @@ end context "when encoding fails" do - before { allow_any_instance_of(Protobuf::Socketrpc::Response).to receive(:encode).and_raise(RuntimeError) } + before { allow_any_instance_of(::Protobuf::Socketrpc::Response).to receive(:encode).and_raise(RuntimeError) } it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError) From aaabcb62a09bb15292be74d335e8b340dcdc1a34 Mon Sep 17 00:00:00 2001 From: Embark Date: Thu, 2 Mar 2017 13:59:45 -0800 Subject: [PATCH 1038/1191] Add support for custom enum options --- lib/protobuf/generators/enum_generator.rb | 11 ++++------- .../protobuf/generators/enum_generator_spec.rb | 2 +- spec/lib/protobuf/optionable_spec.rb | 17 +++++++++++++++++ spec/support/protos/enum.pb.rb | 2 +- spec/support/protos/google_unittest.pb.rb | 2 +- .../protos/google_unittest_custom_options.pb.rb | 6 ++++++ spec/support/protos/resource.pb.rb | 8 ++++++++ spec/support/protos/resource.proto | 8 ++++++++ 8 files changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 3c1e5ffa..1088e3ed 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -1,20 +1,17 @@ require 'protobuf/generators/base' +require 'protobuf/generators/option_generator' module Protobuf module Generators class EnumGenerator < Base - def allow_alias? - descriptor.options.try(:allow_alias!) { false } - end - def compile run_once(:compile) do tags = [] print_class(descriptor.name, :enum) do - if allow_alias? - puts "set_option :allow_alias" + if descriptor.options + print OptionGenerator.new(descriptor.options, current_indent).to_s puts end @@ -24,7 +21,7 @@ def compile end end - unless allow_alias? + unless descriptor.options.try(:allow_alias) self.class.validate_tags(fully_qualified_type_namespace, tags) end end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 74976f34..1c263188 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -45,7 +45,7 @@ class TestEnum < ::Protobuf::Enum let(:compiled) do <<-RUBY class TestEnum < ::Protobuf::Enum - set_option :allow_alias + set_option :allow_alias, true define :FOO, 1 define :BAR, 2 diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 8f2b1432..8d1f9988 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -201,5 +201,22 @@ def optionable_descriptor_class expect(subject.get_option!(:".test.field_option")).to eq(8765432109) end end + + context 'enum options' do + subject { ::Test::StatusType } + + it 'gets base options' do + expect(subject.get_option!(:allow_alias)).to eq(true) + end + + it 'gets unset options' do + expect(subject.get_option!(:deprecated)).to eq(nil) + expect(subject.get_option(:deprecated)).to eq(false) + end + + it 'gets custom options' do + expect(subject.get_option!(:".test.enum_option")).to eq(-789) + end + end end end diff --git a/spec/support/protos/enum.pb.rb b/spec/support/protos/enum.pb.rb index 53f9cccd..9366beb0 100644 --- a/spec/support/protos/enum.pb.rb +++ b/spec/support/protos/enum.pb.rb @@ -24,7 +24,7 @@ class EnumTestType < ::Protobuf::Enum end class AliasedEnum < ::Protobuf::Enum - set_option :allow_alias + set_option :allow_alias, true define :THREE, 3 define :TRES, 3 diff --git a/spec/support/protos/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb index c6d86022..c2c7d650 100644 --- a/spec/support/protos/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -25,7 +25,7 @@ class ForeignEnum < ::Protobuf::Enum end class TestEnumWithDupValue < ::Protobuf::Enum - set_option :allow_alias + set_option :allow_alias, true define :FOO1, 1 define :BAR1, 2 diff --git a/spec/support/protos/google_unittest_custom_options.pb.rb b/spec/support/protos/google_unittest_custom_options.pb.rb index 27e6218a..5ada386d 100644 --- a/spec/support/protos/google_unittest_custom_options.pb.rb +++ b/spec/support/protos/google_unittest_custom_options.pb.rb @@ -24,6 +24,8 @@ class MethodOpt1 < ::Protobuf::Enum end class AggregateEnum < ::Protobuf::Enum + set_option :".protobuf_unittest.enumopt", { :s => "EnumAnnotation" } + define :VALUE, 1 end @@ -33,6 +35,8 @@ class AggregateEnum < ::Protobuf::Enum # class TestMessageWithCustomOptions < ::Protobuf::Message class AnEnum < ::Protobuf::Enum + set_option :".protobuf_unittest.enum_opt1", -789 + define :ANENUM_VAL1, 1 define :ANENUM_VAL2, 2 end @@ -71,6 +75,8 @@ class Aggregate < ::Protobuf::Message; end class AggregateMessage < ::Protobuf::Message; end class NestedOptionType < ::Protobuf::Message class NestedEnum < ::Protobuf::Enum + set_option :".protobuf_unittest.enum_opt1", 1003 + define :NESTED_ENUM_VALUE, 1 end diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index 19f7d8c7..9e4ccb85 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -19,10 +19,14 @@ module Test # Enum Classes # class StatusType < ::Protobuf::Enum + set_option :allow_alias, true + set_option :".test.enum_option", -789 + define :PENDING, 0 define :ENABLED, 1 define :DISABLED, 2 define :DELETED, 3 + define :ALIASED, 3 end @@ -130,6 +134,10 @@ class ::Google::Protobuf::FieldOptions < ::Protobuf::Message optional :uint64, :".test.field_option", 858769, :extension => true end + class ::Google::Protobuf::EnumOptions < ::Protobuf::Message + optional :int64, :".test.enum_option", 590284, :extension => true + end + ## # Service Classes diff --git a/spec/support/protos/resource.proto b/spec/support/protos/resource.proto index 2e1d30ef..7ab353a0 100644 --- a/spec/support/protos/resource.proto +++ b/spec/support/protos/resource.proto @@ -15,11 +15,19 @@ extend google.protobuf.FieldOptions { optional uint64 field_option = 858769; } +extend google.protobuf.EnumOptions { + optional int64 enum_option = 590284; +} + enum StatusType { + option allow_alias = true; + option (enum_option) = -789; + PENDING = 0; ENABLED = 1; DISABLED = 2; DELETED = 3; + ALIASED = 3; } message ResourceFindRequest { From cb3d5bea79980fd693157614e6db1d3a47cc8eeb Mon Sep 17 00:00:00 2001 From: Embark Date: Fri, 3 Mar 2017 14:26:10 -0800 Subject: [PATCH 1039/1191] Add support for custom message options --- lib/protobuf/generators/message_generator.rb | 10 ++- spec/lib/protobuf/optionable_spec.rb | 17 ++++ .../google_unittest_custom_options.pb.rb | 87 +++++++++++++++++++ spec/support/protos/resource.pb.rb | 8 ++ spec/support/protos/resource.proto | 7 ++ 5 files changed, 127 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index 6d7bba0c..a58986c1 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -42,6 +42,8 @@ def compile_message print_class(descriptor.name, nil) do group = GroupGenerator.new(current_indent) group.add_messages(descriptor.nested_type, :extension_fields => @extension_fields, :namespace => type_namespace) + group.add_comment(:options, 'Message Options') + group.add_options(descriptor.options) if options? group.add_message_fields(descriptor.field) self.class.validate_tags(fully_qualified_type_namespace, descriptor.field.map(&:number)) @@ -52,7 +54,7 @@ def compile_message group.add_extension_fields(message_extension_fields) - group.order = [:message, :field, :extension_range, :extension_field] + group.order = [:message, :options, :field, :extension_range, :extension_field] print group.to_s end end @@ -69,6 +71,10 @@ def fields? descriptor.field.count > 0 end + def options? + descriptor.options + end + def nested_enums? descriptor.enum_type.count > 0 end @@ -85,7 +91,7 @@ def printable? if @only_declarations nested_types? else - fields? || nested_messages? || extensions? + fields? || nested_messages? || extensions? || options? end end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 8d1f9988..4c134277 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -218,5 +218,22 @@ def optionable_descriptor_class expect(subject.get_option!(:".test.enum_option")).to eq(-789) end end + + context 'message options' do + subject { ::Test::Resource } + + it 'gets base options' do + expect(subject.get_option!(:map_entry)).to eq(false) + end + + it 'gets unset options' do + expect(subject.get_option!(:deprecated)).to eq(nil) + expect(subject.get_option(:deprecated)).to eq(false) + end + + it 'gets custom options' do + expect(subject.get_option!(:".test.message_option")).to eq(-56) + end + end end end diff --git a/spec/support/protos/google_unittest_custom_options.pb.rb b/spec/support/protos/google_unittest_custom_options.pb.rb index 5ada386d..531c2ad8 100644 --- a/spec/support/protos/google_unittest_custom_options.pb.rb +++ b/spec/support/protos/google_unittest_custom_options.pb.rb @@ -116,9 +116,70 @@ class TestMessageWithRequiredEnumOption < ::Protobuf::Message; end # Message Fields # class TestMessageWithCustomOptions + # Message Options + set_option :message_set_wire_format, false + set_option :".protobuf_unittest.message_opt1", -56 + optional :string, :field1, 1, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD, :".protobuf_unittest.field_opt1" => 8765432109 end + class CustomOptionMinIntegerValues + # Message Options + set_option :".protobuf_unittest.sfixed64_opt", -9223372036854775808 + set_option :".protobuf_unittest.sfixed32_opt", -2147483648 + set_option :".protobuf_unittest.fixed64_opt", 0 + set_option :".protobuf_unittest.fixed32_opt", 0 + set_option :".protobuf_unittest.sint64_opt", -9223372036854775808 + set_option :".protobuf_unittest.sint32_opt", -2147483648 + set_option :".protobuf_unittest.uint64_opt", 0 + set_option :".protobuf_unittest.uint32_opt", 0 + set_option :".protobuf_unittest.int64_opt", -9223372036854775808 + set_option :".protobuf_unittest.int32_opt", -2147483648 + set_option :".protobuf_unittest.bool_opt", false + + end + + class CustomOptionMaxIntegerValues + # Message Options + set_option :".protobuf_unittest.sfixed64_opt", 9223372036854775807 + set_option :".protobuf_unittest.sfixed32_opt", 2147483647 + set_option :".protobuf_unittest.fixed64_opt", 18446744073709551615 + set_option :".protobuf_unittest.fixed32_opt", 4294967295 + set_option :".protobuf_unittest.sint64_opt", 9223372036854775807 + set_option :".protobuf_unittest.sint32_opt", 2147483647 + set_option :".protobuf_unittest.uint64_opt", 18446744073709551615 + set_option :".protobuf_unittest.uint32_opt", 4294967295 + set_option :".protobuf_unittest.int64_opt", 9223372036854775807 + set_option :".protobuf_unittest.int32_opt", 2147483647 + set_option :".protobuf_unittest.bool_opt", true + + end + + class CustomOptionOtherValues + # Message Options + set_option :".protobuf_unittest.enum_opt", ::Protobuf_unittest::DummyMessageContainingEnum::TestEnumType::TEST_OPTION_ENUM_TYPE2 + set_option :".protobuf_unittest.bytes_opt", "Hello\x00World" + set_option :".protobuf_unittest.string_opt", "Hello, \"World\"" + set_option :".protobuf_unittest.double_opt", 1.2345678901234567 + set_option :".protobuf_unittest.float_opt", 12.34567928314209 + set_option :".protobuf_unittest.int32_opt", -100 + + end + + class SettingRealsFromPositiveInts + # Message Options + set_option :".protobuf_unittest.double_opt", 154.0 + set_option :".protobuf_unittest.float_opt", 12.0 + + end + + class SettingRealsFromNegativeInts + # Message Options + set_option :".protobuf_unittest.double_opt", -154.0 + set_option :".protobuf_unittest.float_opt", -12.0 + + end + class ComplexOptionType1 optional :int32, :foo, 1 optional :int32, :foo2, 2 @@ -149,7 +210,21 @@ class ComplexOptionType3 optional :int32, :qux, 1 end + class VariousComplexOptions + # Message Options + set_option :".protobuf_unittest.ComplexOptionType2.ComplexOptionType4.complex_opt4", { :waldo => 1971 } + set_option :".protobuf_unittest.complex_opt3", { :qux => 9 } + set_option :".protobuf_unittest.repeated_opt1", [1, 2] + set_option :".protobuf_unittest.repeated_opt2", [{ :qux => 3 }, { :qux => 4 }] + set_option :".protobuf_unittest.complex_opt2", { :bar => { :foo => 743, :".protobuf_unittest.corge" => { :qux => 2008 }, :".protobuf_unittest.quux" => 1999 }, :baz => 987, :fred => { :waldo => 321 }, :barney => [{ :waldo => 101 }, { :waldo => 212 }], :".protobuf_unittest.garply" => { :foo => 741, :".protobuf_unittest.corge" => { :qux => 2121 }, :".protobuf_unittest.quux" => 1998 }, :".protobuf_unittest.grault" => 654 } + set_option :".protobuf_unittest.complex_opt1", { :foo => 42, :foo4 => [99, 88], :".protobuf_unittest.corge" => { :qux => 876 }, :".protobuf_unittest.quux" => 324 } + + end + class AggregateMessageSet + # Message Options + set_option :message_set_wire_format, false + # Extension Fields extensions 4...536870912 optional ::Protobuf_unittest::AggregateMessageSetElement, :".protobuf_unittest.AggregateMessageSetElement.message_set_extension", 15447542, :extension => true @@ -168,11 +243,17 @@ class Aggregate end class AggregateMessage + # Message Options + set_option :".protobuf_unittest.msgopt", { :i => 101, :s => "MessageAnnotation" } + optional :int32, :fieldname, 1, :".protobuf_unittest.fieldopt" => { :s => "FieldAnnotation" } end class NestedOptionType class NestedMessage + # Message Options + set_option :".protobuf_unittest.message_opt1", 1001 + optional :int32, :nested_field, 1, :".protobuf_unittest.field_opt1" => 1002 end @@ -186,6 +267,12 @@ class NewOptionType required ::Protobuf_unittest::NewOptionType::TestEnum, :value, 1 end + class TestMessageWithRequiredEnumOption + # Message Options + set_option :".protobuf_unittest.required_enum_opt", { :value => ::Protobuf_unittest::OldOptionType::TestEnum::OLD_VALUE } + + end + ## # Extended Message Fields diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index 9e4ccb85..190aa3ba 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -79,6 +79,10 @@ class ResourceSleepRequest end class Resource + # Message Options + set_option :map_entry, false + set_option :".test.message_option", -56 + required :string, :name, 1, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD, :".test.field_option" => 8765432109 optional :int64, :date_created, 2 optional ::Test::StatusType, :status, 3 @@ -138,6 +142,10 @@ class ::Google::Protobuf::EnumOptions < ::Protobuf::Message optional :int64, :".test.enum_option", 590284, :extension => true end + class ::Google::Protobuf::MessageOptions < ::Protobuf::Message + optional :int64, :".test.message_option", 485969, :extension => true + end + ## # Service Classes diff --git a/spec/support/protos/resource.proto b/spec/support/protos/resource.proto index 7ab353a0..e30af694 100644 --- a/spec/support/protos/resource.proto +++ b/spec/support/protos/resource.proto @@ -19,6 +19,10 @@ extend google.protobuf.EnumOptions { optional int64 enum_option = 590284; } +extend google.protobuf.MessageOptions { + optional int64 message_option = 485969; +} + enum StatusType { option allow_alias = true; option (enum_option) = -789; @@ -42,6 +46,9 @@ message ResourceSleepRequest { } message Resource { + option map_entry = false; + option (message_option) = -56; + extensions 100 to max; required string name = 1 [(field_option) = 8765432109, ctype = CORD]; From 3ca275cebaa7e6cdee846006c5158d24b957b9d5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 4 Mar 2017 15:38:16 -0700 Subject: [PATCH 1040/1191] acceptable check is not needed most places as coerce runs the same logic and use fetch instead of checking for key --- lib/protobuf/field/bool_field.rb | 2 +- lib/protobuf/field/float_field.rb | 2 ++ lib/protobuf/field/varint_field.rb | 7 ++++++- lib/protobuf/message.rb | 18 ++++++------------ spec/lib/protobuf/field/float_field_spec.rb | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 6eb8e5a2..6a247381 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -30,7 +30,7 @@ def coerce!(val) return true if val == TRUE_STRING return false if val == FALSE_STRING - val + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end def decode(value) diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 3c6ac8a4..304593d6 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -22,6 +22,8 @@ def acceptable?(val) def coerce!(val) Float(val) + rescue + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end def decode(bytes) diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index f1d7ffbd..48aa7e29 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -54,8 +54,10 @@ def acceptable?(val) int_val = if val.is_a?(Integer) return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path val + elsif val.is_a?(Numeric) + val.to_i else - coerce!(val) + Integer(val, 10) end int_val >= self.class.min && int_val <= self.class.max @@ -64,8 +66,11 @@ def acceptable?(val) end def coerce!(val) + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) return val.to_i if val.is_a?(Numeric) Integer(val, 10) + rescue + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end def decode(value) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 5fc39f2c..b9a48eb0 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -151,16 +151,12 @@ def ==(other) def [](name) field = self.class.get_field(name, true) + return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) if field.repeated? - fail ArgumentError, "invalid field name=#{name.inspect}" unless field - - if field.repeated? - @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) - elsif @values.key?(field.fully_qualified_name) - @values[field.fully_qualified_name] - else - field.default_value - end + @values.fetch(field.fully_qualified_name, field.default_value) + rescue # not having a field should be the exceptional state + raise if field + fail ArgumentError, "invalid field name=#{name.inspect}" end def []=(name, value) @@ -213,10 +209,8 @@ def set_field(name, value, ignore_nil_for_repeated) else if value.nil? # rubocop:disable Style/IfInsideElse @values.delete(field.fully_qualified_name) - elsif field.acceptable?(value) - @values[field.fully_qualified_name] = field.coerce!(value) else - fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" + @values[field.fully_qualified_name] = field.coerce!(value) end end else diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb index 5fa76247..818f0954 100644 --- a/spec/lib/protobuf/field/float_field_spec.rb +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -43,7 +43,7 @@ class SomeFloatMessage < ::Protobuf::Message let(:value) { "aaaa" } it 'throws an error' do - expect { subject }.to raise_error(ArgumentError) + expect { subject }.to raise_error(TypeError) end end From d3336ce0f915ba608be985e02336e1ee52636ef7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 4 Mar 2017 16:12:47 -0700 Subject: [PATCH 1041/1191] encode straight to stream without intermediary copies --- lib/protobuf/encoder.rb | 4 ++-- lib/protobuf/field/base_field.rb | 4 ++++ lib/protobuf/field/bytes_field.rb | 7 +++++++ lib/protobuf/field/string_field.rb | 10 ++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 8038ae1f..5591ed4c 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -8,11 +8,11 @@ def self.encode(message, stream) stream << "#{field.tag_encoded}#{::Protobuf::Field::VarintField.encode(packed_value.size)}#{packed_value}" else value.each do |val| - stream << "#{field.tag_encoded}#{field.encode(val)}" + field.encode_to_stream(val, stream) end end else - stream << "#{field.tag_encoded}#{field.encode(value)}" + field.encode_to_stream(value, stream) end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index f58edca7..f34907aa 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -90,6 +90,10 @@ def encode(_value) fail NotImplementedError, "#{self.class.name}##{__method__}" end + def encode_to_stream(value, stream) + stream << tag_encoded << encode(value) + end + def extension? options.key?(:extension) end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index b5950ed6..1d519c02 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -46,6 +46,13 @@ def encode(value) "#{string_size}#{value_to_encode}" end + def encode_to_stream(value, stream) + value = value.encode if value.is_a?(::Protobuf::Message) + byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) + + stream << tag_encoded << byte_size << value + end + def wire_type ::Protobuf::WireType::LENGTH_DELIMITED end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index ac36ea70..f7d434fb 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -28,6 +28,16 @@ def encode(value) "#{::Protobuf::Field::VarintField.encode(value_to_encode.size)}#{value_to_encode}" end + def encode_to_stream(value, stream) + if value.encoding != ::Protobuf::Field::StringField::ENCODING + value = value.dup + value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + end + + byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) + stream << tag_encoded << byte_size << value + end + end end end From 65464b88135bd7e2e64ee21340cfda772790b029 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 4 Mar 2017 21:13:30 -0700 Subject: [PATCH 1042/1191] only catch ArgumentError in the coercion methods of float and integer --- lib/protobuf/field/float_field.rb | 2 +- lib/protobuf/field/varint_field.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 304593d6..e5bfcb70 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -22,7 +22,7 @@ def acceptable?(val) def coerce!(val) Float(val) - rescue + rescue ArgumentError fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 48aa7e29..02a8cddc 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -69,7 +69,7 @@ def coerce!(val) fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) return val.to_i if val.is_a?(Numeric) Integer(val, 10) - rescue + rescue ArgumentError fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end From 611a9ca7628f3c96640f60afbdcd246ac14f4acc Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 6 Mar 2017 14:35:47 -0700 Subject: [PATCH 1043/1191] move dynamic rule checks to the initialize method --- lib/protobuf/field/base_field.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index f34907aa..f734d9d4 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -47,6 +47,13 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl set_option(option_name, value) end + @extension = options.key?(:extension) + @deprecated = options.key?(:deprecated) + @required = rule == :required + @repeated = rule == :repeated + @optional = rule == :optional + @packed = @repeated && options.key?(:packed) + validate_packed_field if packed? define_accessor(simple_name, fully_qualified_name) if simple_name tag_encoded @@ -83,7 +90,7 @@ def default_value end def deprecated? - options.key?(:deprecated) + @deprecated end def encode(_value) @@ -95,7 +102,7 @@ def encode_to_stream(value, stream) end def extension? - options.key?(:extension) + @extension end def enum? @@ -107,15 +114,15 @@ def message? end def optional? - rule == :optional + @optional end def packed? - repeated? && options.key?(:packed) + @packed end def repeated? - rule == :repeated + @repeated end def repeated_message? @@ -123,7 +130,7 @@ def repeated_message? end def required? - rule == :required + @required end # FIXME: need to cleanup (rename) this warthog of a method. From 1c65061df86bfbebd9b8519c61c3817df8ede5f1 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 7 Mar 2017 17:13:54 -0700 Subject: [PATCH 1044/1191] fix multiple load issue --- lib/protobuf.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 5efb8780..29cc457c 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -94,14 +94,6 @@ def self.ignore_unknown_fields=(value) symbolized_connector_type = env_connector_type.to_s.downcase.strip.to_sym if [:zmq, :socket].include?(symbolized_connector_type) require "protobuf/#{symbolized_connector_type}" - - ::Protobuf.connector_type_class = - case symbolized_connector_type - when :zmq - ::Protobuf::Rpc::Connectors::Zmq - else - ::Protobuf::Rpc::Connectors::Socket - end else require "#{env_connector_type}" # rubocop:disable Style/UnneededInterpolation classified = env_connector_type.classify From d26725ea9487c4098bf3077f2580617ca5437aa8 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 8 Mar 2017 11:12:16 -0800 Subject: [PATCH 1045/1191] Add support for custom service options --- lib/protobuf/generators/service_generator.rb | 2 ++ spec/lib/protobuf/optionable_spec.rb | 13 +++++++++++++ .../protos/google_unittest_custom_options.pb.rb | 2 ++ spec/support/protos/resource.pb.rb | 5 +++++ spec/support/protos/resource.proto | 6 ++++++ 5 files changed, 28 insertions(+) diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb index 5e449768..27e0f923 100644 --- a/lib/protobuf/generators/service_generator.rb +++ b/lib/protobuf/generators/service_generator.rb @@ -1,4 +1,5 @@ require 'protobuf/generators/base' +require 'protobuf/generators/option_generator' module Protobuf module Generators @@ -7,6 +8,7 @@ class ServiceGenerator < Base def compile run_once(:compile) do print_class(descriptor.name, :service) do + print OptionGenerator.new(descriptor.options, current_indent).to_s if descriptor.options descriptor.method.each do |method_descriptor| puts build_method(method_descriptor) end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 4c134277..b898defa 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -235,5 +235,18 @@ def optionable_descriptor_class expect(subject.get_option!(:".test.message_option")).to eq(-56) end end + + context 'service options' do + subject { ::Test::ResourceService } + + it 'gets unset options' do + expect(subject.get_option!(:deprecated)).to eq(nil) + expect(subject.get_option(:deprecated)).to eq(false) + end + + it 'gets custom options' do + expect(subject.get_option!(:".test.service_option")).to eq(-9876543210) + end + end end end diff --git a/spec/support/protos/google_unittest_custom_options.pb.rb b/spec/support/protos/google_unittest_custom_options.pb.rb index 531c2ad8..c9a318d0 100644 --- a/spec/support/protos/google_unittest_custom_options.pb.rb +++ b/spec/support/protos/google_unittest_custom_options.pb.rb @@ -344,10 +344,12 @@ class ::Google::Protobuf::MethodOptions < ::Protobuf::Message # Service Classes # class TestServiceWithCustomOptions < ::Protobuf::Rpc::Service + set_option :".protobuf_unittest.service_opt1", -9876543210 rpc :foo, ::Protobuf_unittest::CustomOptionFooRequest, ::Protobuf_unittest::CustomOptionFooResponse end class AggregateService < ::Protobuf::Rpc::Service + set_option :".protobuf_unittest.serviceopt", { :s => "ServiceAnnotation" } rpc :method, ::Protobuf_unittest::AggregateMessage, ::Protobuf_unittest::AggregateMessage end diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index 190aa3ba..13b6e7b5 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -146,11 +146,16 @@ class ::Google::Protobuf::MessageOptions < ::Protobuf::Message optional :int64, :".test.message_option", 485969, :extension => true end + class ::Google::Protobuf::ServiceOptions < ::Protobuf::Message + optional :int64, :".test.service_option", 5869607, :extension => true + end + ## # Service Classes # class ResourceService < ::Protobuf::Rpc::Service + set_option :".test.service_option", -9876543210 rpc :find, ::Test::ResourceFindRequest, ::Test::Resource rpc :find_with_rpc_failed, ::Test::ResourceFindRequest, ::Test::Resource rpc :find_with_sleep, ::Test::ResourceSleepRequest, ::Test::Resource diff --git a/spec/support/protos/resource.proto b/spec/support/protos/resource.proto index e30af694..e6befb98 100644 --- a/spec/support/protos/resource.proto +++ b/spec/support/protos/resource.proto @@ -23,6 +23,10 @@ extend google.protobuf.MessageOptions { optional int64 message_option = 485969; } +extend google.protobuf.ServiceOptions { + optional int64 service_option = 5869607; +} + enum StatusType { option allow_alias = true; option (enum_option) = -789; @@ -117,6 +121,8 @@ extend Nested.NestedLevelOne { } service ResourceService { + option (service_option) = -9876543210; + rpc Find (ResourceFindRequest) returns (Resource); rpc FindWithRpcFailed (ResourceFindRequest) returns (Resource); rpc FindWithSleep (ResourceSleepRequest) returns (Resource); From 495e6b516ccb0b777279d80fcbd82e69a48fef81 Mon Sep 17 00:00:00 2001 From: Joshua Morris Date: Thu, 9 Jun 2016 00:48:31 -0700 Subject: [PATCH 1046/1191] upcase enums during default value generation --- lib/protobuf/generators/field_generator.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 11e2a448..134af402 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -115,7 +115,13 @@ def type_name private def enum_default_value - "#{type_name}::#{verbatim_default_value}" + optionally_upcased_default = + if ENV.key?('PB_UPCASE_ENUMS') + verbatim_default_value.upcase + else + verbatim_default_value + end + "#{type_name}::#{optionally_upcased_default}" end def float_double_default_value From a5f105b944fc9269e3ca8bdb716e68b8b74a71d7 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 8 Mar 2017 11:52:28 -0800 Subject: [PATCH 1047/1191] Add support for custom method options --- lib/protobuf/generators/service_generator.rb | 28 +++++++- lib/protobuf/rpc/rpc_method.rb | 16 +++++ lib/protobuf/rpc/service.rb | 7 +- .../generators/service_generator_spec.rb | 72 +++++++++++++++---- spec/lib/protobuf/optionable_spec.rb | 13 ++++ .../google_unittest_custom_options.pb.rb | 8 ++- spec/support/protos/resource.pb.rb | 8 ++- spec/support/protos/resource.proto | 8 ++- 8 files changed, 135 insertions(+), 25 deletions(-) create mode 100644 lib/protobuf/rpc/rpc_method.rb diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb index 27e0f923..f7e9febd 100644 --- a/lib/protobuf/generators/service_generator.rb +++ b/lib/protobuf/generators/service_generator.rb @@ -10,17 +10,39 @@ def compile print_class(descriptor.name, :service) do print OptionGenerator.new(descriptor.options, current_indent).to_s if descriptor.options descriptor.method.each do |method_descriptor| - puts build_method(method_descriptor) + print_method(method_descriptor) end end end end - def build_method(method_descriptor) + private + + def print_method(method_descriptor) request_klass = modulize(method_descriptor.input_type) response_klass = modulize(method_descriptor.output_type) name = ENV.key?('PB_USE_RAW_RPC_NAMES') ? method_descriptor.name : method_descriptor.name.underscore - "rpc :#{name}, #{request_klass}, #{response_klass}" + options = {} + if method_descriptor.options + method_descriptor.options.each_field do |field_option| + option_value = method_descriptor.options[field_option.name] + next unless method_descriptor.options.field?(field_option.name) + options[field_option.fully_qualified_name] = serialize_value(option_value) + end + end + + rpc = "rpc :#{name}, #{request_klass}, #{response_klass}" + + if options.empty? + puts rpc + return + end + + puts rpc + " do" + options.each do |option_name, value| + indent { puts "set_option #{option_name.inspect}, #{value}" } + end + puts "end" end end diff --git a/lib/protobuf/rpc/rpc_method.rb b/lib/protobuf/rpc/rpc_method.rb new file mode 100644 index 00000000..dfb4a196 --- /dev/null +++ b/lib/protobuf/rpc/rpc_method.rb @@ -0,0 +1,16 @@ +module Protobuf + module Rpc + class RpcMethod + ::Protobuf::Optionable.inject(self, false) { ::Google::Protobuf::MethodOptions } + + attr_reader :method, :request_type, :response_type + + def initialize(method, request_type, response_type, &options_block) + @method = method + @request_type = request_type + @response_type = response_type + instance_eval(&options_block) if options_block + end + end + end +end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 8a4ff3c8..cc1974ad 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -2,13 +2,12 @@ require 'protobuf/message' require 'protobuf/rpc/client' require 'protobuf/rpc/error' +require 'protobuf/rpc/rpc_method' require 'protobuf/rpc/service_filters' module Protobuf module Rpc # Object to encapsulate the request/response types for a given service method - # - RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) class Service include ::Protobuf::Logging @@ -103,8 +102,8 @@ class << self # This methods is only used by the generated service definitions # and not useful for user code. # - def self.rpc(method, request_type, response_type) - rpcs[method] = RpcMethod.new(method, request_type, response_type) + def self.rpc(method, request_type, response_type, &options_block) + rpcs[method] = RpcMethod.new(method, request_type, response_type, &options_block) end # Hash containing the set of methods defined via `rpc`. diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 141085c2..07d1c9af 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -4,10 +4,38 @@ RSpec.describe ::Protobuf::Generators::ServiceGenerator do + class ::CustomMethodEnum < ::Protobuf::Enum + define :BOOM, 1 + define :BAM, 2 + end + + class ::CustomMethodMessage < ::Protobuf::Message + optional :string, :foo, 1 + end + + class ::Google::Protobuf::MethodOptions < ::Protobuf::Message + optional :string, :custom_string_option, 22000, :extension => true + optional :bool, :custom_bool_option, 22001, :extension => true + optional :int32, :custom_int32_option, 22002, :extension => true + optional ::CustomMethodEnum, :custom_enum_option, 22003, :extension => true + optional ::CustomMethodMessage, :custom_message_option, 22004, :extension => true + end + let(:methods) do [ { :name => 'Search', :input_type => 'FooRequest', :output_type => 'FooResponse' }, - { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' }, + { + :name => 'FooBar', + :input_type => '.foo.Request', + :output_type => '.bar.Response', + :options => { + :custom_string_option => 'boom', + :custom_bool_option => true, + :custom_int32_option => 123, + :custom_message_option => CustomMethodMessage.new(:foo => 'bam'), + :custom_enum_option => CustomMethodEnum::BAM, + }, + }, ] end let(:service_fields) do @@ -19,37 +47,53 @@ let(:service) { ::Google::Protobuf::ServiceDescriptorProto.new(service_fields) } - subject { described_class.new(service) } + subject(:service_generator) { described_class.new(service) } describe '#compile' do let(:compiled) do - 'class TestService < ::Protobuf::Rpc::Service + < "bam" } + end end -' +EOF end - it 'compiles the service and it\'s rpc methods' do + it "compiles the service and it's rpc methods" do subject.compile expect(subject.to_s).to eq(compiled) end + + context 'with PB_USE_RAW_RPC_NAMES in the environemnt' do + let(:compiled) do + < "bam" } end +end - describe '#build_method' do - it 'returns a string identifying the given method descriptor' do - expect(subject.build_method(service.method.first)).to eq("rpc :search, FooRequest, FooResponse") - end +EOF + end - context 'with PB_USE_RAW_RPC_NAMES in the environemnt' do before { allow(ENV).to receive(:key?).with('PB_USE_RAW_RPC_NAMES').and_return(true) } it 'uses the raw RPC name and does not underscore it' do - expect(subject.build_method(service.method.first)).to eq("rpc :Search, FooRequest, FooResponse") - expect(subject.build_method(service.method.last)).to eq("rpc :FooBar, ::Foo::Request, ::Bar::Response") + subject.compile + expect(subject.to_s).to eq(compiled) end end end - end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index b898defa..c7480c03 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -248,5 +248,18 @@ def optionable_descriptor_class expect(subject.get_option!(:".test.service_option")).to eq(-9876543210) end end + + context 'method options' do + subject { ::Test::ResourceService.rpcs[:find] } + + it 'gets unset options' do + expect(subject.get_option!(:deprecated)).to eq(nil) + expect(subject.get_option(:deprecated)).to eq(false) + end + + it 'gets custom options' do + expect(subject.get_option!(:".test.method_option")).to eq(2) + end + end end end diff --git a/spec/support/protos/google_unittest_custom_options.pb.rb b/spec/support/protos/google_unittest_custom_options.pb.rb index c9a318d0..9ca77aee 100644 --- a/spec/support/protos/google_unittest_custom_options.pb.rb +++ b/spec/support/protos/google_unittest_custom_options.pb.rb @@ -345,12 +345,16 @@ class ::Google::Protobuf::MethodOptions < ::Protobuf::Message # class TestServiceWithCustomOptions < ::Protobuf::Rpc::Service set_option :".protobuf_unittest.service_opt1", -9876543210 - rpc :foo, ::Protobuf_unittest::CustomOptionFooRequest, ::Protobuf_unittest::CustomOptionFooResponse + rpc :foo, ::Protobuf_unittest::CustomOptionFooRequest, ::Protobuf_unittest::CustomOptionFooResponse do + set_option :".protobuf_unittest.method_opt1", ::Protobuf_unittest::MethodOpt1::METHODOPT1_VAL2 + end end class AggregateService < ::Protobuf::Rpc::Service set_option :".protobuf_unittest.serviceopt", { :s => "ServiceAnnotation" } - rpc :method, ::Protobuf_unittest::AggregateMessage, ::Protobuf_unittest::AggregateMessage + rpc :method, ::Protobuf_unittest::AggregateMessage, ::Protobuf_unittest::AggregateMessage do + set_option :".protobuf_unittest.methodopt", { :s => "MethodAnnotation" } + end end end diff --git a/spec/support/protos/resource.pb.rb b/spec/support/protos/resource.pb.rb index 13b6e7b5..f81ef52f 100644 --- a/spec/support/protos/resource.pb.rb +++ b/spec/support/protos/resource.pb.rb @@ -150,13 +150,19 @@ class ::Google::Protobuf::ServiceOptions < ::Protobuf::Message optional :int64, :".test.service_option", 5869607, :extension => true end + class ::Google::Protobuf::MethodOptions < ::Protobuf::Message + optional :int64, :".test.method_option", 7893233, :extension => true + end + ## # Service Classes # class ResourceService < ::Protobuf::Rpc::Service set_option :".test.service_option", -9876543210 - rpc :find, ::Test::ResourceFindRequest, ::Test::Resource + rpc :find, ::Test::ResourceFindRequest, ::Test::Resource do + set_option :".test.method_option", 2 + end rpc :find_with_rpc_failed, ::Test::ResourceFindRequest, ::Test::Resource rpc :find_with_sleep, ::Test::ResourceSleepRequest, ::Test::Resource rpc :find_not_implemented, ::Test::ResourceFindRequest, ::Test::Resource diff --git a/spec/support/protos/resource.proto b/spec/support/protos/resource.proto index e6befb98..70b338b3 100644 --- a/spec/support/protos/resource.proto +++ b/spec/support/protos/resource.proto @@ -27,6 +27,10 @@ extend google.protobuf.ServiceOptions { optional int64 service_option = 5869607; } +extend google.protobuf.MethodOptions { + optional int64 method_option = 7893233; +} + enum StatusType { option allow_alias = true; option (enum_option) = -789; @@ -123,7 +127,9 @@ extend Nested.NestedLevelOne { service ResourceService { option (service_option) = -9876543210; - rpc Find (ResourceFindRequest) returns (Resource); + rpc Find (ResourceFindRequest) returns (Resource) { + option (method_option) = 2; + } rpc FindWithRpcFailed (ResourceFindRequest) returns (Resource); rpc FindWithSleep (ResourceSleepRequest) returns (Resource); rpc FindNotImplemented (ResourceFindRequest) returns (Resource); From 5541dd4719d94a3ba67760f275cc49b5031f2ae1 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 8 Mar 2017 16:00:55 -0800 Subject: [PATCH 1048/1191] Add test for upcasing default enum values --- spec/lib/protobuf/generators/field_generator_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 9e5f5676..c3763eea 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -53,6 +53,15 @@ specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } end + context 'when type is an enum with lowercase default value with PB_UPCASE_ENUMS set' do + let(:type_enum) { :TYPE_ENUM } + let(:type_name) { '.foo.bar.Baz' } + let(:default_value) { 'quux' } + before { allow(ENV).to receive(:key?).with('PB_UPCASE_ENUMS').and_return(true) } + + specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } + end + context 'when the type is a string' do let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } From 41ea11c2a87e9e90a31249e773d45719af6f1dab Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 15 Mar 2017 10:12:54 -0400 Subject: [PATCH 1049/1191] update changelog --- CHANGES.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 44cfae2e..4953d1eb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,26 @@ -# Stable (3.x) +# Beta (3.7.x) + +3.7.0 (pre3) +----------- +- Evaluate extension fields in code generation (#329) +- Change the ping port to use ms timeout and make the default 200ms (#332) +- Fix build failures caused by Rails 5 requirement of Ruby 2.2.2 (#343) +- Add functional tests (#346) +- Extract client and server (#347) (#348) +- BUG: Fix decoding of packed fields (#349) +- Add support for custom file options (#350) +- BUG: enum_for_tags returns nil if tag nil (#352) +- Update rubocop and fix cops (#353) +- Optimization for varint (#356) +- Add support for custom field options (#357) +- Add support for custom enum options (#359) +- Add support for custom message options (#360) +- Acceptable check is not needed most places as coerce runs the same logic (#361) +- Encode straight to stream without intermediary copies (#362) +- Move dynamic rule checks to the initialize method (#363) +- Add support for custom service options (#364) +- Add support for custom method options (#365) +- Upcase enum default (#366) 3.7.0 (pre2) ----------- @@ -20,6 +42,8 @@ - Refresh google/protobuf/descriptor.{proto,pb.rb} - Properly encode and decode negative enum values. +# Stable (3.6.x) + 3.6.9 -------- - Make protobuf serivce directory pluggable. From 182b96989373713f53ee234b474b72e115d8e560 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 29 Mar 2017 14:54:26 -0400 Subject: [PATCH 1050/1191] Bump version to 3.7.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index a1fb101d..04b79a77 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.12' # rubocop:disable Style/MutableConstant + VERSION = '3.7.0' # rubocop:disable Style/MutableConstant end From 45aaa05c7790d1d4d0eac46f189aafb47b48f9cc Mon Sep 17 00:00:00 2001 From: Embark Date: Thu, 27 Apr 2017 16:37:24 -0700 Subject: [PATCH 1051/1191] Use regular alias_method in place of alias_method_chain Today activesupport 5.1.0 was released which no longer supports alias_method_chain. It was deprecated prior to this version. Can't use Module#prepend if we still want to support Ruby < 2.0.0 --- lib/protobuf/code_generator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 2963dc0c..73d7d271 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -86,7 +86,8 @@ def option_set(message_field, subfield, subvalue) end end - alias_method_chain :set, :options + alias_method :set_without_options, :set + alias_method :set, :set_with_options end end end From bba8847b065a20c405c4d73bc9a43f1f87394d70 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 28 Apr 2017 08:15:50 -0400 Subject: [PATCH 1052/1191] Travis caches an old zmq version. This uses the latest version from 4 stable. --- .travis.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34d330d9..87911ea1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,12 @@ before_install: - - sudo apt-get update -qq - - sudo apt-get install -y libzmq3-dev + - wget https://github.com/zeromq/libzmq/releases/download/v4.2.1/zeromq-4.2.1.tar.gz + - tar xvf zeromq-4.2.1.tar.gz + - cd zeromq-4.2.1 + - ./configure + - make -j4 + - sudo make install + # Retrun to project directory + - cd .. - sudo -E ./install-protobuf.sh - java -Xmx1g -version - javac -J-Xmx1g -version From 27bb8e29b4adf014b62cb7276abf41cf0ba9b3db Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 28 Apr 2017 10:31:16 -0400 Subject: [PATCH 1053/1191] Bump version to 3.7.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 04b79a77..6cb4471d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.0' # rubocop:disable Style/MutableConstant + VERSION = '3.7.1' # rubocop:disable Style/MutableConstant end From 46e46c0d9a7832cd8d63ad1a88d9ea0874cde90f Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Tue, 2 May 2017 17:42:57 -0600 Subject: [PATCH 1054/1191] Add server_host to the response object --- lib/protobuf.rb | 11 +++++++++++ lib/protobuf/rpc/error.rb | 2 +- lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++-- lib/protobuf/rpc/rpc.pb.rb | 1 + proto/rpc.proto | 1 + .../protobuf/rpc/middleware/response_encoder_spec.rb | 5 ++++- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 29cc457c..d9b43a28 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -37,6 +37,13 @@ class << self # # The name or address of the host to use during client RPC calls. attr_writer :client_host + + # Server Host + # + # Default: first ipv4 address of the system + # + # The name or address of the host to use during client RPC calls. + attr_writer :server_host end def self.client_host @@ -81,6 +88,10 @@ def self.ignore_unknown_fields? def self.ignore_unknown_fields=(value) @ignore_unknown_fields = !!value end + + def self.server_host + @server_host ||= Socket.gethostname + end end unless ENV.key?('PB_NO_NETWORKING') diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 343d1889..7ad7f9ea 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -18,7 +18,7 @@ def encode end def to_response - ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type) + ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type, :server => ::Protobuf.server_host) end end end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index e7a9f2c4..361db7d6 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -72,9 +72,9 @@ def validate!(candidate) # def wrapped_response if response.is_a?(::Protobuf::Rpc::PbError) - ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) + ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type, :server => ::Protobuf.server_host) else - ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode) + ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode, :server => ::Protobuf.server_host) end end end diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index 900f1324..eaea971f 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -48,6 +48,7 @@ class Response optional :string, :error, 2 optional :bool, :callback, 3, :default => false optional ::Protobuf::Socketrpc::ErrorReason, :error_reason, 4 + optional :string, :server, 5 end end diff --git a/proto/rpc.proto b/proto/rpc.proto index c786d24c..17a1e350 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -38,6 +38,7 @@ message Response optional string error = 2; // Error message, if any optional bool callback = 3 [default = false]; // Was callback invoked (not sure what this is for) optional ErrorReason error_reason = 4; // Error Reason + optional string server = 5; // Server hostname or address } // Possible error reasons diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 106de050..cf7427d3 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -10,10 +10,13 @@ end let(:encoded_response) { response_wrapper.encode } let(:response) { Test::Resource.new(:name => 'required') } - let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) } + let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response, :server => server_host) } + let(:server_host) { 'beepboopbop' } subject { described_class.new(app) } + before { ::Protobuf.server_host = server_host } + describe "#call" do it "encodes the response" do stack_env = subject.call(env) From 2fde442a7ac382d6150f423e9bdce3cf2d4381ff Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 3 May 2017 10:40:35 -0600 Subject: [PATCH 1055/1191] Log the server from the response wrapper --- lib/protobuf/rpc/connectors/base.rb | 1 + lib/protobuf/rpc/stat.rb | 14 ++++++++------ lib/protobuf/version.rb | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index e7e9195a..2e9c76ba 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -104,6 +104,7 @@ def parse_response # Parse out the raw response @stats.response_size = @response_data.size unless @response_data.nil? response_wrapper = ::Protobuf::Socketrpc::Response.decode(@response_data) + @stats.server = response_wrapper.server if response_wrapper.field?(:server) # Determine success or failure based on parsed data if response_wrapper.field?(:error_reason) diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index a4c7e8d1..18d0eff6 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -6,7 +6,8 @@ module Protobuf module Rpc class Stat attr_accessor :mode, :start_time, :end_time, :request_size, :dispatcher - attr_accessor :response_size, :client, :server, :service, :method_name + attr_accessor :response_size, :client, :service, :method_name + attr_reader :server MODES = [:SERVER, :CLIENT].freeze @@ -32,11 +33,12 @@ def method_name end def server=(peer) - @server = { :port => peer[0], :ip => peer[1] } - end - - def server - @server ? "#{@server[:ip]}:#{@server[:port]}" : nil + case peer + when Array + @server = "#{peer[1]}:#{peer[0]}" + when String + @server = peer + end end def service diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6cb4471d..26afc1db 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.1' # rubocop:disable Style/MutableConstant + VERSION = '3.7.2.pre1' # rubocop:disable Style/MutableConstant end From 2a403085ebda8011b007ba298dafba112d5f92bb Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 3 May 2017 11:12:39 -0600 Subject: [PATCH 1056/1191] Add specs around response.server handling --- spec/lib/protobuf/rpc/connectors/base_spec.rb | 18 ++++++++++++++++++ spec/lib/protobuf/rpc/stat_spec.rb | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 254b3fa8..02aadf9b 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -20,6 +20,24 @@ specify { expect(subject.respond_to?(:verify_callbacks)).to be true } end + describe "#parse_response" do + let(:options) { { :response_type => Test::Resource, :port => 55589, :host => '127.3.4.5' } } + it "updates stats#server from the response" do + allow(subject).to receive(:close_connection) + subject.instance_variable_set(:@response_data, ::Protobuf::Socketrpc::Response.new(:server => "serverless").encode) + subject.initialize_stats + subject.parse_response + expect(subject.stats.server).to eq("serverless") + end + it "does not override stats#server when response.server is missing" do + allow(subject).to receive(:close_connection) + subject.instance_variable_set(:@response_data, ::Protobuf::Socketrpc::Response.new.encode) + subject.initialize_stats + subject.parse_response + expect(subject.stats.server).to eq("127.3.4.5:55589") + end + end + describe "#any_callbacks?" do [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| it "returns true if #{cb} is provided" do diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index 14c4556d..2b6c6011 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -8,6 +8,20 @@ BarService = ::Struct.new(:method_name) unless defined?(BarService) end + describe '#server=' do + it 'understands Array' do + stat = ::Protobuf::Rpc::Stat.new + stat.server = [3333, "127.0.0.1"] + expect(stat.server).to eq("127.0.0.1:3333") + end + + it 'understands String' do + stat = ::Protobuf::Rpc::Stat.new + stat.server = "thatserverthough" + expect(stat.server).to eq("thatserverthough") + end + end + describe 'server mode' do it 'describes a server response to a client' do ::Timecop.freeze(10.minutes.ago) do From 4c7295e2073eaef08753453422b21ba6a3276d3c Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 3 May 2017 11:16:45 -0600 Subject: [PATCH 1057/1191] Revert version change --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 26afc1db..6253f943 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.2.pre1' # rubocop:disable Style/MutableConstant + VERSION = '3.7.2' # rubocop:disable Style/MutableConstant end From 3c08614d68022f010864fb20c7b6dcd30966a9fa Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 3 May 2017 11:17:46 -0600 Subject: [PATCH 1058/1191] Revert version change --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6253f943..6cb4471d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.2' # rubocop:disable Style/MutableConstant + VERSION = '3.7.1' # rubocop:disable Style/MutableConstant end From 08197b509fd3a01d12ad76a73247ccd6f13c4be2 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 3 May 2017 16:32:27 -0600 Subject: [PATCH 1059/1191] Don't override user settings of client/server_host --- lib/protobuf.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/base_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index d9b43a28..e2efab15 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -47,7 +47,7 @@ class << self end def self.client_host - @client_host ||= Socket.gethostname + defined?(@client_host) ? @client_host : @client_host = Socket.gethostname end def self.connector_type_class @@ -90,7 +90,7 @@ def self.ignore_unknown_fields=(value) end def self.server_host - @server_host ||= Socket.gethostname + defined?(@server_host) ? @server_host : @server_host = Socket.gethostname end end diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 02aadf9b..e5890307 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -36,6 +36,13 @@ subject.parse_response expect(subject.stats.server).to eq("127.3.4.5:55589") end + it "does not override stats#server when response.server is nil" do + allow(subject).to receive(:close_connection) + subject.instance_variable_set(:@response_data, ::Protobuf::Socketrpc::Response.new(:server => nil).encode) + subject.initialize_stats + subject.parse_response + expect(subject.stats.server).to eq("127.3.4.5:55589") + end end describe "#any_callbacks?" do From 078a31d9980c988d1e84ee41adc99848d0664845 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 8 May 2017 09:47:26 -0600 Subject: [PATCH 1060/1191] Do not change current behavior --- lib/protobuf.rb | 11 ----------- lib/protobuf/rpc/error.rb | 2 +- lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++-- .../protobuf/rpc/middleware/response_encoder_spec.rb | 5 +---- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index e2efab15..8aa8fef9 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -37,13 +37,6 @@ class << self # # The name or address of the host to use during client RPC calls. attr_writer :client_host - - # Server Host - # - # Default: first ipv4 address of the system - # - # The name or address of the host to use during client RPC calls. - attr_writer :server_host end def self.client_host @@ -88,10 +81,6 @@ def self.ignore_unknown_fields? def self.ignore_unknown_fields=(value) @ignore_unknown_fields = !!value end - - def self.server_host - defined?(@server_host) ? @server_host : @server_host = Socket.gethostname - end end unless ENV.key?('PB_NO_NETWORKING') diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 7ad7f9ea..343d1889 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -18,7 +18,7 @@ def encode end def to_response - ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type, :server => ::Protobuf.server_host) + ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type) end end end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 361db7d6..e7a9f2c4 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -72,9 +72,9 @@ def validate!(candidate) # def wrapped_response if response.is_a?(::Protobuf::Rpc::PbError) - ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type, :server => ::Protobuf.server_host) + ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) else - ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode, :server => ::Protobuf.server_host) + ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode) end end end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index cf7427d3..106de050 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -10,13 +10,10 @@ end let(:encoded_response) { response_wrapper.encode } let(:response) { Test::Resource.new(:name => 'required') } - let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response, :server => server_host) } - let(:server_host) { 'beepboopbop' } + let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) } subject { described_class.new(app) } - before { ::Protobuf.server_host = server_host } - describe "#call" do it "encodes the response" do stack_env = subject.call(env) From a20dd0b2e86e1aa78a8ac4d52ae1d9e7261ce123 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 8 May 2017 09:54:18 -0600 Subject: [PATCH 1061/1191] Revert irrelevant change --- lib/protobuf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 8aa8fef9..29cc457c 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -40,7 +40,7 @@ class << self end def self.client_host - defined?(@client_host) ? @client_host : @client_host = Socket.gethostname + @client_host ||= Socket.gethostname end def self.connector_type_class From 740f9480054fc8ec295a4e1afa3e3cb544ade025 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 8 May 2017 10:22:13 -0600 Subject: [PATCH 1062/1191] Don't give Protobuf.server_host a default --- lib/protobuf.rb | 7 +++++++ lib/protobuf/rpc/error.rb | 2 +- lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++-- spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb | 5 ++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 29cc457c..450c67b5 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -37,6 +37,13 @@ class << self # # The name or address of the host to use during client RPC calls. attr_writer :client_host + + # Server Host + # + # Default: first ipv4 address of the system + # + # The name or address of the host to use during client RPC calls. + attr_accessor :server_host end def self.client_host diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 343d1889..7ad7f9ea 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -18,7 +18,7 @@ def encode end def to_response - ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type) + ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type, :server => ::Protobuf.server_host) end end end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index e7a9f2c4..361db7d6 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -72,9 +72,9 @@ def validate!(candidate) # def wrapped_response if response.is_a?(::Protobuf::Rpc::PbError) - ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) + ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type, :server => ::Protobuf.server_host) else - ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode) + ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode, :server => ::Protobuf.server_host) end end end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 106de050..cf7427d3 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -10,10 +10,13 @@ end let(:encoded_response) { response_wrapper.encode } let(:response) { Test::Resource.new(:name => 'required') } - let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) } + let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response, :server => server_host) } + let(:server_host) { 'beepboopbop' } subject { described_class.new(app) } + before { ::Protobuf.server_host = server_host } + describe "#call" do it "encodes the response" do stack_env = subject.call(env) From 6b10a0c32bad65f5526c9e629aa4e26d006bcd72 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 8 May 2017 10:46:13 -0600 Subject: [PATCH 1063/1191] Revert server side changes --- lib/protobuf.rb | 7 ------- lib/protobuf/rpc/error.rb | 2 +- lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++-- spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb | 5 +---- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 450c67b5..29cc457c 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -37,13 +37,6 @@ class << self # # The name or address of the host to use during client RPC calls. attr_writer :client_host - - # Server Host - # - # Default: first ipv4 address of the system - # - # The name or address of the host to use during client RPC calls. - attr_accessor :server_host end def self.client_host diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 7ad7f9ea..343d1889 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -18,7 +18,7 @@ def encode end def to_response - ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type, :server => ::Protobuf.server_host) + ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type) end end end diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 361db7d6..e7a9f2c4 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -72,9 +72,9 @@ def validate!(candidate) # def wrapped_response if response.is_a?(::Protobuf::Rpc::PbError) - ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type, :server => ::Protobuf.server_host) + ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) else - ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode, :server => ::Protobuf.server_host) + ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode) end end end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index cf7427d3..106de050 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -10,13 +10,10 @@ end let(:encoded_response) { response_wrapper.encode } let(:response) { Test::Resource.new(:name => 'required') } - let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response, :server => server_host) } - let(:server_host) { 'beepboopbop' } + let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) } subject { described_class.new(app) } - before { ::Protobuf.server_host = server_host } - describe "#call" do it "encodes the response" do stack_env = subject.call(env) From ea095653e6e2562247f910715eb21a615d3e54a6 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 10 May 2017 15:24:50 -0600 Subject: [PATCH 1064/1191] Allow a server to be set in the response --- lib/protobuf/rpc/env.rb | 1 + lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++-- lib/protobuf/rpc/server.rb | 4 ++-- .../rpc/middleware/response_encoder_spec.rb | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index f89b2a1e..cf6aea60 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -45,6 +45,7 @@ def self.hash_accessor(*names) #:nodoc: :response_type, :rpc_method, :rpc_service, + :server, :service_name, :worker_id diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index e7a9f2c4..ae79daf4 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -72,9 +72,9 @@ def validate!(candidate) # def wrapped_response if response.is_a?(::Protobuf::Rpc::PbError) - ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type) + ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type, :server => env.server) else - ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode) + ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode, :server => env.server) end end end diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index 27dbaf8a..f988e341 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -20,10 +20,10 @@ def gc_pause # Invoke the service method dictated by the proto wrapper request object # - def handle_request(request_data) + def handle_request(request_data, env_data = {}) # Create an env object that holds different parts of the environment and # is available to all of the middlewares - env = Env.new('encoded_request' => request_data, 'log_signature' => log_signature) + env = Env.new(env_data.merge('encoded_request' => request_data, 'log_signature' => log_signature)) # Invoke the middleware stack, the last of which is the service dispatcher env = Rpc.middleware.call(env) diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 106de050..0ed47e60 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -71,5 +71,21 @@ expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError) end end + + context "when server exists in the env" do + let(:env) do + Protobuf::Rpc::Env.new( + 'response_type' => Test::Resource, + 'log_signature' => 'log_signature', + 'server' => 'itsaserver', + ) + end + + it "adds the servers to the response" do + expected_response = ::Protobuf::Socketrpc::Response.new(:response_proto => response, :server => 'itsaserver').encode + subject.call(env) + expect(env.encoded_response).to eq(expected_response) + end + end end end From a7e5515f9e2204c095ff120bb577b9b7625a0cfc Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 12 May 2017 10:28:31 -0600 Subject: [PATCH 1065/1191] prevent infinite loop on socket create when a problem --- lib/protobuf/rpc/connectors/zmq.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a81edb81..e06bc4b6 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -88,7 +88,10 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket + attempt_number = 0 + begin + attempt_number += 1 socket = zmq_context.socket(::ZMQ::REQ) if socket # Make sure the context builds the socket @@ -97,8 +100,9 @@ def create_socket zmq_error_check(socket.connect(server_uri), :socket_connect) socket = socket_to_available_server(socket) if first_alive_load_balance? end - end while socket.try(:socket).nil? + end while socket.nil? && attempt_number < socket_creation_attempts + raise RequestTimeout, "Cannot create new ZMQ client socket" if socket.nil? socket end @@ -241,6 +245,10 @@ def snd_timeout end end + def socket_creation_attempts + @socket_creation_attempts ||= (ENV["PB_ZMQ_CLIENT_SOCKET_CREATION_ATTEMPTS"] || 5).to_i + end + def socket_to_available_server(socket) check_available_response = "" socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) From aa2141ab65c7456b0868889a264884f8f93ffb21 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 12 May 2017 10:36:31 -0600 Subject: [PATCH 1066/1191] relaod the context when has run through configued number of new sockets --- lib/protobuf/rpc/connectors/zmq.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index e06bc4b6..835bac05 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -28,7 +28,8 @@ def self.ping_port_responses @ping_port_responses ||= ::ThreadSafe::Cache.new end - def self.zmq_context + def self.zmq_context(reload = false) + @zmq_contexts = nil if reload @zmq_contexts ||= Hash.new do |hash, key| hash[key] = ZMQ::Context.new end @@ -88,6 +89,7 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket + has_reloaded_context = false attempt_number = 0 begin @@ -100,6 +102,12 @@ def create_socket zmq_error_check(socket.connect(server_uri), :socket_connect) socket = socket_to_available_server(socket) if first_alive_load_balance? end + + if !has_reloaded_context && attempt_number == socket_creation_attempts + zmq_context(true) # reload the context + attempt_number = 0 + has_reloaded_context = true + end end while socket.nil? && attempt_number < socket_creation_attempts raise RequestTimeout, "Cannot create new ZMQ client socket" if socket.nil? @@ -271,8 +279,8 @@ def socket_to_available_server(socket) # If the context does not exist, create it, then register # an exit block to ensure the context is terminated correctly. # - def zmq_context - self.class.zmq_context + def zmq_context(reload = false) + self.class.zmq_context(reload) end def zmq_eagain_error_check(return_code, source) From 320319db2501b247eae61b0cb39f27402ef2e458 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 May 2017 08:04:17 -0600 Subject: [PATCH 1067/1191] log when cannot create context --- lib/protobuf/rpc/connectors/zmq.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 835bac05..145226e8 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -104,6 +104,7 @@ def create_socket end if !has_reloaded_context && attempt_number == socket_creation_attempts + logger.info { sign_message("Reset Context: could not create socket") } zmq_context(true) # reload the context attempt_number = 0 has_reloaded_context = true From d480e0240e2eed9d4b429e2893e30bc2174f3865 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 May 2017 09:37:12 -0600 Subject: [PATCH 1068/1191] Bump version from 3.7.1 to 3.7.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6cb4471d..6253f943 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.1' # rubocop:disable Style/MutableConstant + VERSION = '3.7.2' # rubocop:disable Style/MutableConstant end From 7e56c9ee077714710a80dcf53f9c34433787b95d Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Mon, 15 May 2017 10:06:52 -0600 Subject: [PATCH 1069/1191] Bump version from 3.7.2 to 3.7.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6253f943..7ab13465 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.2' # rubocop:disable Style/MutableConstant + VERSION = '3.7.3' # rubocop:disable Style/MutableConstant end From a37520d484b1181e92dfc5cb074aeca42c7dd462 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 16 May 2017 09:38:34 -0600 Subject: [PATCH 1070/1191] fix socket check in zmq connector to check the internal socket --- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 145226e8..a5ead281 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -109,9 +109,9 @@ def create_socket attempt_number = 0 has_reloaded_context = true end - end while socket.nil? && attempt_number < socket_creation_attempts + end while socket.try(:socket).nil? && attempt_number < socket_creation_attempts - raise RequestTimeout, "Cannot create new ZMQ client socket" if socket.nil? + raise RequestTimeout, "Cannot create new ZMQ client socket" if socket.try(:socket).nil? socket end From 79cc6ef03cac21fddb16c713b3eb25f6c0c673b7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 16 May 2017 11:02:28 -0600 Subject: [PATCH 1071/1191] bump to 3.7.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 7ab13465..1d772587 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.3' # rubocop:disable Style/MutableConstant + VERSION = '3.7.4' # rubocop:disable Style/MutableConstant end From bda56c4f4af085e28368ed12a5486939523609b6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 17 May 2017 14:53:57 -0600 Subject: [PATCH 1072/1191] reload context causes depletion of file descriptors --- lib/protobuf/rpc/connectors/zmq.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a5ead281..3d99fb96 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -89,7 +89,6 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - has_reloaded_context = false attempt_number = 0 begin @@ -102,13 +101,6 @@ def create_socket zmq_error_check(socket.connect(server_uri), :socket_connect) socket = socket_to_available_server(socket) if first_alive_load_balance? end - - if !has_reloaded_context && attempt_number == socket_creation_attempts - logger.info { sign_message("Reset Context: could not create socket") } - zmq_context(true) # reload the context - attempt_number = 0 - has_reloaded_context = true - end end while socket.try(:socket).nil? && attempt_number < socket_creation_attempts raise RequestTimeout, "Cannot create new ZMQ client socket" if socket.try(:socket).nil? From bbdeae031dccae8ad1f4c8c2ed39b7aad6b1f9aa Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 17 May 2017 14:56:40 -0600 Subject: [PATCH 1073/1191] bump to 3.7.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 1d772587..b8e0b822 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.4' # rubocop:disable Style/MutableConstant + VERSION = '3.7.5' # rubocop:disable Style/MutableConstant end From c0ac85cb48bf4b3f6f5a25e355fc3a14ca8c67dd Mon Sep 17 00:00:00 2001 From: Mikhail Petrov Date: Thu, 6 Jul 2017 12:55:11 +0300 Subject: [PATCH 1074/1191] Fixed rake task This fix allows to reuse `::Rake::Task['protobuf:compile'].invoke` in custom rake tasks. `system` call doesn't replace current process, but `exec` call does. --- lib/protobuf/tasks/compile.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index 65c09576..db9f01bb 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -22,7 +22,7 @@ namespace :protobuf do full_command = command.join(' ') puts full_command - exec(full_command) + system(full_command) end desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' From 0e6ca3c451531a86f7aeac8dfdd0da7832a4b3d9 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Tue, 10 May 2016 17:41:23 -0400 Subject: [PATCH 1075/1191] support map types --- lib/protobuf/field/base_field.rb | 18 ++ lib/protobuf/field/field_array.rb | 8 +- lib/protobuf/field/field_hash.rb | 100 +++++++++++ lib/protobuf/generators/field_generator.rb | 65 ++++++-- lib/protobuf/generators/group_generator.rb | 10 +- lib/protobuf/generators/message_generator.rb | 2 +- lib/protobuf/message.rb | 38 ++++- lib/protobuf/message/fields.rb | 13 ++ spec/functional/code_generator_spec.rb | 20 +++ spec/lib/protobuf/field/field_array_spec.rb | 60 +++++-- spec/lib/protobuf/field/field_hash_spec.rb | 121 ++++++++++++++ .../generators/extension_generator_spec.rb | 6 +- .../generators/field_generator_spec.rb | 67 ++++++-- spec/lib/protobuf/message_spec.rb | 37 +++++ spec/support/protos/map-test.bin | 157 ++++++++++++++++++ spec/support/protos/map-test.pb.rb | 85 ++++++++++ spec/support/protos/map-test.proto | 68 ++++++++ 17 files changed, 826 insertions(+), 49 deletions(-) create mode 100644 lib/protobuf/field/field_hash.rb create mode 100644 spec/lib/protobuf/field/field_hash_spec.rb create mode 100644 spec/support/protos/map-test.bin create mode 100644 spec/support/protos/map-test.pb.rb create mode 100644 spec/support/protos/map-test.proto diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index f734d9d4..d18827da 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,5 +1,7 @@ require 'active_support/core_ext/hash/slice' require 'protobuf/field/field_array' +require 'protobuf/field/field_hash' + module Protobuf module Field class BaseField @@ -82,6 +84,8 @@ def default def default_value @default_value ||= if optional? || required? typed_default_value + elsif map? + ::Protobuf::Field::FieldHash.new(self).freeze elsif repeated? ::Protobuf::Field::FieldArray.new(self).freeze else @@ -113,6 +117,10 @@ def message? false end + def map? + repeated_message? && type_class.get_option(:map_entry) + end + def optional? @optional end @@ -136,6 +144,16 @@ def required? # FIXME: need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) return message_instance[name] = decode(bytes) unless repeated? + + if map? + hash = message_instance[name] + entry = decode(bytes) + # decoded value could be nil for an + # enum value that is not recognized + hash[entry.key] = entry.value unless entry.value.nil? + return + end + return message_instance[name] << decode(bytes) unless packed? array = message_instance[name] diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 78bb79e0..0c0e1428 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -65,7 +65,7 @@ def normalize(value) fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) if field.is_a?(::Protobuf::Field::EnumField) - field.type_class.fetch(value) + fetch_enum(field.type_class, value) elsif field.is_a?(::Protobuf::Field::MessageField) && value.is_a?(field.type_class) value elsif field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) @@ -75,6 +75,12 @@ def normalize(value) end end + def fetch_enum(type, val) + en = type.fetch(val) + raise_type_error(val) if en.nil? + en + end + def raise_type_error(val) fail TypeError, <<-TYPE_ERROR Expected repeated value of type '#{field.type_class}' diff --git a/lib/protobuf/field/field_hash.rb b/lib/protobuf/field/field_hash.rb new file mode 100644 index 00000000..d35056f7 --- /dev/null +++ b/lib/protobuf/field/field_hash.rb @@ -0,0 +1,100 @@ +module Protobuf + module Field + class FieldHash < Hash + + ## + # Attributes + # + + attr_reader :field, :key_field, :value_field + + ## + # Constructor + # + + def initialize(field) + @field = field + @key_field = field.type_class.get_field(:key) + @value_field = field.type_class.get_field(:value) + end + + ## + # Public Instance Methods + # + + def []=(key, val) + super(normalize_key(key), normalize_val(val)) + end + + alias store []= + + def replace(val) + raise_type_error(val) unless val.is_a?(Hash) + clear + update(val) + end + + def merge!(other) + raise_type_error(other) unless other.is_a?(Hash) + # keys and values will be normalized by []= above + other.each { |k, v| self[k] = v } + end + + alias update merge! + + # Return a hash-representation of the given values for this field type. + # The value in this case would be the hash itself. + def to_hash_value + self + end + + def to_s + "{#{field.name}}" + end + + private + + ## + # Private Instance Methods + # + + def normalize_key(key) + normalize(:key, key, key_field) + end + + def normalize_val(value) + normalize(:value, value, value_field) + end + + def normalize(what, value, normalize_field) + raise_type_error(value) if value.nil? + value = value.to_proto if value.respond_to?(:to_proto) + fail TypeError, "Unacceptable #{what} #{value} for field #{field.name} of type #{normalize_field.type_class}" unless normalize_field.acceptable?(value) + + if normalize_field.is_a?(::Protobuf::Field::EnumField) + fetch_enum(normalize_field.type_class, value) + elsif normalize_field.is_a?(::Protobuf::Field::MessageField) && value.is_a?(normalize_field.type_class) + value + elsif normalize_field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) + normalize_field.type_class.new(value.to_hash) + else + value + end + end + + def fetch_enum(type, val) + en = type.fetch(val) + raise_type_error(val) if en.nil? + en + end + + def raise_type_error(val) + fail TypeError, <<-TYPE_ERROR + Expected map value of type '#{key_field.type_class} -> #{value_field.type_class}' + Got '#{val.class}' for map protobuf field #{field.name} + TYPE_ERROR + end + + end + end +end diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 134af402..256c5b30 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -19,6 +19,11 @@ class FieldGenerator < Base # attr_reader :field_options + def initialize(field_descriptor, enclosing_msg_descriptor, indent_level) + super(field_descriptor, indent_level) + @enclosing_msg_descriptor = enclosing_msg_descriptor + end + def applicable_options # Note on the strange use of `#inspect`: # :boom.inspect #=> ":boom" @@ -60,7 +65,11 @@ def extension? def compile run_once(:compile) do - field_definition = ["#{label} #{type_name}", name, number, applicable_options] + field_definition = if map? + ["map #{map_key_type_name}", map_value_type_name, name, number, applicable_options] + else + ["#{label} #{type_name}", name, number, applicable_options] + end puts field_definition.flatten.compact.join(', ') end end @@ -101,15 +110,30 @@ def packed? # Determine the field type def type_name - @type_name ||= begin - case descriptor.type.name - when :TYPE_MESSAGE, :TYPE_ENUM, :TYPE_GROUP then - modulize(descriptor.type_name) - else - type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '') - ":#{type_name}" - end - end + @type_name ||= determine_type_name(descriptor) + end + + # If this field is a map field, this returns a message descriptor that + # represents the entries in the map. Returns nil if this field is not + # a map field. + def map_entry + @map_entry ||= determine_map_entry + end + + def map? + !map_entry.nil? + end + + def map_key_type_name + e = map_entry + return nil if e.nil? + determine_type_name(e.field.find { |v| v.name == 'key' && v.number == 1 }) + end + + def map_value_type_name + e = map_entry + return nil if e.nil? + determine_type_name(e.field.find { |v| v.name == 'value' && v.number == 2 }) end private @@ -145,6 +169,27 @@ def verbatim_default_value descriptor.default_value end + def determine_type_name(descriptor) + case descriptor.type.name + when :TYPE_MESSAGE, :TYPE_ENUM, :TYPE_GROUP then + modulize(descriptor.type_name) + else + type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '') + ":#{type_name}" + end + end + + def determine_map_entry + return nil if @enclosing_msg_descriptor.nil? + return nil unless descriptor.label.name == :LABEL_REPEATED && descriptor.type.name == :TYPE_MESSAGE + # find nested message type + name_parts = descriptor.type_name.split(".") + return nil if name_parts.size < 2 || name_parts[-2] != @enclosing_msg_descriptor.name + nested = @enclosing_msg_descriptor.nested_type.find { |e| e.name == name_parts[-1] } + return nested if !nested.nil? && nested.options.try(:map_entry?) { false } + nil + end + end end end diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index 0bb0cd34..33e7b5be 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -46,7 +46,7 @@ def add_extended_messages(extended_messages, skip_empty_fields = true) def add_extension_fields(field_descriptors) field_descriptors.each do |field_descriptor| - @groups[:extension_field] << FieldGenerator.new(field_descriptor, indent_level) + @groups[:extension_field] << FieldGenerator.new(field_descriptor, nil, indent_level) end end @@ -61,18 +61,22 @@ def add_header(type, message) def add_message_declarations(descriptors) descriptors.each do |descriptor| + # elide synthetic map entry messages (we handle map fields differently) + next if descriptor.options.try(:map_entry?) { false } @groups[:message_declaration] << MessageGenerator.new(descriptor, indent_level, :declaration => true) end end - def add_message_fields(field_descriptors) + def add_message_fields(field_descriptors, msg_descriptor) field_descriptors.each do |field_descriptor| - @groups[:field] << FieldGenerator.new(field_descriptor, indent_level) + @groups[:field] << FieldGenerator.new(field_descriptor, msg_descriptor, indent_level) end end def add_messages(descriptors, options = {}) descriptors.each do |descriptor| + # elide synthetic map entry message (we handle map fields differently) + next if descriptor.options.try(:map_entry?) { false } @groups[:message] << MessageGenerator.new(descriptor, indent_level, options) end end diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index a58986c1..bbaf84d5 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -44,7 +44,7 @@ def compile_message group.add_messages(descriptor.nested_type, :extension_fields => @extension_fields, :namespace => type_namespace) group.add_comment(:options, 'Message Options') group.add_options(descriptor.options) if options? - group.add_message_fields(descriptor.field) + group.add_message_fields(descriptor.field, descriptor) self.class.validate_tags(fully_qualified_type_namespace, descriptor.field.map(&:number)) group.add_comment(:extension_range, 'Extension Fields') diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index b9a48eb0..1b71a831 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -50,7 +50,7 @@ def initialize(fields = {}) def clear! @values.delete_if do |_, value| - if value.is_a?(::Protobuf::Field::FieldArray) + if value.is_a?(::Protobuf::Field::FieldArray) || value.is_a?(::Protobuf::Field::FieldHash) value.clear false else @@ -86,6 +86,17 @@ def each_field_for_serialization fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if field.required? next end + if field.map? + # on-the-wire, maps are represented like an array of entries where + # each entry is a message of two fields, key and value. + array = Array.new(value.size) + i = 0 + value.each do |k, v| + array[i] = field.type_class.new(:key => k, :value => v) + i += 1 + end + value = array + end yield(field, value) end @@ -151,9 +162,14 @@ def ==(other) def [](name) field = self.class.get_field(name, true) - return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) if field.repeated? - @values.fetch(field.fully_qualified_name, field.default_value) + if field.map? + return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(field) + elsif field.repeated? + return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) + else + @values.fetch(field.fully_qualified_name, field.default_value) + end rescue # not having a field should be the exceptional state raise if field fail ArgumentError, "invalid field name=#{name.inspect}" @@ -186,7 +202,21 @@ def []=(name, value) def set_field(name, value, ignore_nil_for_repeated) if (field = self.class.get_field(name, true)) - if field.repeated? + if field.map? + unless value.is_a?(Hash) + fail TypeError, <<-TYPE_ERROR + Expected map value + Got '#{value.class}' for map protobuf field #{field.name} + TYPE_ERROR + end + + if value.empty? + @values.delete(field.fully_qualified_name) + else + @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(field) + @values[field.fully_qualified_name].replace(value) + end + elsif field.repeated? if value.nil? && ignore_nil_for_repeated ::Protobuf.deprecator.deprecation_warning("#{self.class}#[#{name}]=nil", "use an empty array instead of nil") return diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 296ba482..6f5617a3 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -44,6 +44,19 @@ def required(type_class, name, tag, options = {}) define_field(:required, type_class, name, tag, options) end + # Define a map field. + # + def map(key_type_class, value_type_class, name, tag, options = {}) + # manufacture a message that represents the map entry, used for + # serialization and deserialization + entry_type = Class.new(::Protobuf::Message) do + set_option :map_entry, true + optional key_type_class, :key, 1 + optional value_type_class, :value, 2 + end + define_field(:repeated, entry_type, name, tag, options) + end + # Define an extension range. # def extensions(range) diff --git a/spec/functional/code_generator_spec.rb b/spec/functional/code_generator_spec.rb index 0e23dc78..aac45319 100644 --- a/spec/functional/code_generator_spec.rb +++ b/spec/functional/code_generator_spec.rb @@ -24,6 +24,26 @@ expect(code_generator.response_bytes).to eq(expected_output) end + it "generates code for map types" do + input_descriptor = ::Google::Protobuf::FileDescriptorSet.decode( + IO.read(PROTOS_PATH.join('map-test.bin'), :mode => 'rb')) + request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:file_to_generate => ['map-test.proto'], + :proto_file => input_descriptor.file) + + file_name = "map-test.pb.rb" + file_content = File.open(PROTOS_PATH.join(file_name), "r:UTF-8", &:read) + expected_file_output = + ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new( + :name => file_name, :content => file_content) + + expected_response = + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => [expected_file_output]) + + code_generator = ::Protobuf::CodeGenerator.new(request.encode) + code_generator.eval_unknown_extensions! + expect(code_generator.response_bytes).to eq(expected_response) + end + it "generates code (including service stubs) with custom field and method options" do expected_unittest_custom_options = File.open(PROTOS_PATH.join('google_unittest_custom_options.pb.rb'), "r:UTF-8", &:read) diff --git a/spec/lib/protobuf/field/field_array_spec.rb b/spec/lib/protobuf/field/field_array_spec.rb index 48133381..0c93b65e 100644 --- a/spec/lib/protobuf/field/field_array_spec.rb +++ b/spec/lib/protobuf/field/field_array_spec.rb @@ -2,21 +2,39 @@ RSpec.describe Protobuf::Field::FieldArray do - class SomeBasicMessage < ::Protobuf::Message - optional :string, :field, 1 + let(:basic_message) do + Class.new(::Protobuf::Message) do + optional :string, :field, 1 + end end - class MoreComplexMessage < SomeBasicMessage + let(:more_complex_message) do + Class.new(BasicMessage) do + end end - class OtherBasicMessage < ::Protobuf::Message - optional :string, :other_field, 1 + let(:some_enum) do + Class.new(::Protobuf::Enum) do + define :FOO, 1 + define :BAR, 2 + define :BAZ, 3 + end end - class SomeRepeatMessage < ::Protobuf::Message - optional :string, :some_string, 1 - repeated :string, :multiple_strings, 2 - repeated SomeBasicMessage, :multiple_basic_msgs, 3 + let(:repeat_message) do + Class.new(::Protobuf::Message) do + optional :string, :some_string, 1 + repeated :string, :multiple_strings, 2 + repeated BasicMessage, :multiple_basic_msgs, 3 + repeated SomeEnum, :multiple_enums, 4 + end + end + + before do + stub_const('BasicMessage', basic_message) + stub_const('MoreComplexMessage', more_complex_message) + stub_const('SomeEnum', some_enum) + stub_const('SomeRepeatMessage', repeat_message) end let(:instance) { SomeRepeatMessage.new } @@ -40,17 +58,21 @@ class SomeRepeatMessage < ::Protobuf::Message context 'when applied to a MessageField field array' do it 'adds a MessageField object' do expect(instance.multiple_basic_msgs).to be_empty - basic_msg1 = SomeBasicMessage.new + basic_msg1 = BasicMessage.new instance.multiple_basic_msgs.send(method, basic_msg1) expect(instance.multiple_basic_msgs).to eq([basic_msg1]) - basic_msg2 = SomeBasicMessage.new + basic_msg2 = BasicMessage.new instance.multiple_basic_msgs.send(method, basic_msg2) expect(instance.multiple_basic_msgs).to eq([basic_msg1, basic_msg2]) end + it 'fails if not adding a MessageField' do + expect { instance.multiple_basic_msgs.send(method, 100.0) }.to raise_error(TypeError) + end + it 'adds a Hash from a MessageField object' do expect(instance.multiple_basic_msgs).to be_empty - basic_msg1 = SomeBasicMessage.new + basic_msg1 = BasicMessage.new basic_msg1.field = 'my value' instance.multiple_basic_msgs.send(method, basic_msg1.to_hash) expect(instance.multiple_basic_msgs).to eq([basic_msg1]) @@ -64,6 +86,20 @@ class SomeRepeatMessage < ::Protobuf::Message expect(instance.multiple_basic_msgs.first).to be_a(MoreComplexMessage) end end + + context 'when applied to an EnumField field array' do + it 'adds an EnumField object' do + expect(instance.multiple_enums).to be_empty + instance.multiple_enums.send(method, SomeEnum::FOO) + expect(instance.multiple_enums).to eq([SomeEnum::FOO]) + instance.multiple_enums.send(method, SomeEnum::BAR) + expect(instance.multiple_enums).to eq([SomeEnum::FOO, SomeEnum::BAR]) + end + + it 'fails if not adding an EnumField' do + expect { instance.multiple_basic_msgs.send(method, 100.0) }.to raise_error(TypeError) + end + end end end end diff --git a/spec/lib/protobuf/field/field_hash_spec.rb b/spec/lib/protobuf/field/field_hash_spec.rb new file mode 100644 index 00000000..631f537c --- /dev/null +++ b/spec/lib/protobuf/field/field_hash_spec.rb @@ -0,0 +1,121 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::FieldHash do + + let(:basic_message) do + Class.new(::Protobuf::Message) do + optional :string, :field, 1 + end + end + + let(:more_complex_message) do + Class.new(BasicMessage) do + end + end + + let(:some_enum) do + Class.new(::Protobuf::Enum) do + define :FOO, 1 + define :BAR, 2 + define :BAZ, 3 + end + end + + let(:map_message) do + Class.new(::Protobuf::Message) do + optional :string, :some_string, 1 + map :int32, :string, :map_int32_to_string, 2 + map :string, BasicMessage, :map_string_to_msg, 3 + map :string, SomeEnum, :map_string_to_enum, 4 + end + end + + before do + stub_const('BasicMessage', basic_message) + stub_const('MoreComplexMessage', more_complex_message) + stub_const('SomeEnum', some_enum) + stub_const('SomeMapMessage', map_message) + end + + let(:instance) { SomeMapMessage.new } + + %w([]= store).each do |method| + describe "\##{method}" do + context 'when applied to an int32->string field hash' do + it 'adds an int -> string entry' do + expect(instance.map_int32_to_string).to be_empty + instance.map_int32_to_string.send(method, 1, 'string 1') + expect(instance.map_int32_to_string).to eq(1 => 'string 1') + instance.map_int32_to_string.send(method, 2, 'string 2') + expect(instance.map_int32_to_string).to eq(1 => 'string 1', 2 => 'string 2') + end + + it 'fails if not adding an int -> string' do + expect { instance.map_int32_to_string.send(method, 1, 100.0) }.to raise_error(TypeError) + expect { instance.map_int32_to_string.send(method, 'foo', 100.0) }.to raise_error(TypeError) + expect { instance.map_int32_to_string.send(method, BasicMessage.new, 100.0) }.to raise_error(TypeError) + expect { instance.map_int32_to_string.send(method, 'foo', 'bar') }.to raise_error(TypeError) + expect { instance.map_int32_to_string.send(method, nil, 'foo') }.to raise_error(TypeError) + expect { instance.map_int32_to_string.send(method, 1, nil) }.to raise_error(TypeError) + end + end + + context 'when applied to a string->MessageField field hash' do + it 'adds a string -> MessageField entry' do + expect(instance.map_string_to_msg).to be_empty + basic_msg1 = BasicMessage.new + instance.map_string_to_msg.send(method, 'msg1', basic_msg1) + expect(instance.map_string_to_msg).to eq('msg1' => basic_msg1) + basic_msg2 = BasicMessage.new + instance.map_string_to_msg.send(method, 'msg2', basic_msg2) + expect(instance.map_string_to_msg).to eq('msg1' => basic_msg1, 'msg2' => basic_msg2) + end + + it 'fails if not adding a string -> MessageField entry' do + expect { instance.map_string_to_msg.send(method, 1, 100.0) }.to raise_error(TypeError) + expect { instance.map_string_to_msg.send(method, 'foo', SomeEnum::FOO) }.to raise_error(TypeError) + expect { instance.map_string_to_msg.send(method, SomeEnum::FOO, BasicMessage.new) }.to raise_error(TypeError) + expect { instance.map_string_to_msg.send(method, nil, BasicMessage.new) }.to raise_error(TypeError) + expect { instance.map_string_to_msg.send(method, 'foo', nil) }.to raise_error(TypeError) + end + + it 'adds a Hash from a MessageField object' do + expect(instance.map_string_to_msg).to be_empty + basic_msg1 = BasicMessage.new + basic_msg1.field = 'my value' + instance.map_string_to_msg.send(method, 'foo', basic_msg1.to_hash) + expect(instance.map_string_to_msg).to eq('foo' => basic_msg1) + end + + it 'does not downcast a MessageField' do + expect(instance.map_string_to_msg).to be_empty + basic_msg1 = MoreComplexMessage.new + instance.map_string_to_msg.send(method, 'foo', basic_msg1) + expect(instance.map_string_to_msg).to eq('foo' => basic_msg1) + expect(instance.map_string_to_msg['foo']).to be_a(MoreComplexMessage) + end + end + + context 'when applied to a string->EnumField field hash' do + it 'adds a string -> EnumField entry' do + expect(instance.map_string_to_enum).to be_empty + instance.map_string_to_enum.send(method, 'msg1', SomeEnum::FOO) + expect(instance.map_string_to_enum).to eq('msg1' => SomeEnum::FOO) + instance.map_string_to_enum.send(method, 'msg2', SomeEnum::BAR) + expect(instance.map_string_to_enum).to eq('msg1' => SomeEnum::FOO, 'msg2' => SomeEnum::BAR) + end + + it 'fails if not adding a string -> EnumField entry' do + expect { instance.map_string_to_enum.send(method, 1, 100.0) }.to raise_error(TypeError) + expect { instance.map_string_to_enum.send(method, nil, 100.0) }.to raise_error(TypeError) + expect { instance.map_string_to_enum.send(method, 1, nil) }.to raise_error(TypeError) + expect { instance.map_string_to_enum.send(method, 'foo', BasicMessage.new) }.to raise_error(TypeError) + expect { instance.map_string_to_enum.send(method, 1, SomeEnum::FOO) }.to raise_error(TypeError) + expect { instance.map_string_to_enum.send(method, nil, SomeEnum::FOO) }.to raise_error(TypeError) + expect { instance.map_string_to_enum.send(method, 'foo', nil) }.to raise_error(TypeError) + end + + end + end + end +end diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 55eb98ad..9f241921 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -15,9 +15,9 @@ let(:message_type) { 'FooBar' } before do - expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[0], 1).and_return(field_descriptors[0]) - expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[1], 1).and_return(field_descriptors[1]) - expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[2], 1).and_return(field_descriptors[2]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[0], nil, 1).and_return(field_descriptors[0]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[1], nil, 1).and_return(field_descriptors[1]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[2], nil, 1).and_return(field_descriptors[2]) end subject { described_class.new(message_type, field_descriptors, 0) } diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index c3763eea..71da1cf9 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -25,32 +25,41 @@ :options => field_options, } end - let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) } + let(:nested_types) { [] } + let(:owner_fields) do + { + :name => 'Baz', + :field => [field], + :nested_type => nested_types, + } + end + let(:owner_msg) { ::Google::Protobuf::DescriptorProto.new(owner_fields) } + describe '#compile' do - subject { described_class.new(field).to_s } + subject { described_class.new(field, owner_msg, 1).to_s } - specify { expect(subject).to eq "optional :string, :foo_bar, 3\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3\n" } context 'when the type is another message' do let(:type_enum) { :TYPE_MESSAGE } let(:type_name) { '.foo.bar.Baz' } - specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" } + specify { expect(subject).to eq " optional ::Foo::Bar::Baz, :foo_bar, 3\n" } end context 'when a default value is used' do let(:type_enum) { :TYPE_INT32 } let(:default_value) { '42' } - specify { expect(subject).to eq "optional :int32, :foo_bar, 3, :default => 42\n" } + specify { expect(subject).to eq " optional :int32, :foo_bar, 3, :default => 42\n" } context 'when type is an enum' do let(:type_enum) { :TYPE_ENUM } let(:type_name) { '.foo.bar.Baz' } let(:default_value) { 'QUUX' } - specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } + specify { expect(subject).to eq " optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } end context 'when type is an enum with lowercase default value with PB_UPCASE_ENUMS set' do @@ -66,7 +75,7 @@ let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :default => \"a default \"string\"\"\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :default => \"a default \"string\"\"\n" } end context 'when float or double field type' do @@ -92,19 +101,47 @@ context 'when the field is an extension' do let(:extendee) { 'foo.bar.Baz' } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :extension => true\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :extension => true\n" } end context 'when field is packed' do let(:field_options) { { :packed => true } } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :packed => true\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :packed => true\n" } + end + + context 'when field is a map' do + let(:type_enum) { :TYPE_MESSAGE } + let(:type_name) { '.foo.bar.Baz.FooBarEntry' } + let(:label_enum) { :LABEL_REPEATED } + let(:nested_types) do + [::Google::Protobuf::DescriptorProto.new( + :name => 'FooBarEntry', + :field => [ + ::Google::Protobuf::FieldDescriptorProto.new( + :label => :LABEL_OPTIONAL, + :name => 'key', + :number => 1, + :type => :TYPE_STRING, + :type_name => nil), + ::Google::Protobuf::FieldDescriptorProto.new( + :label => :LABEL_OPTIONAL, + :name => 'value', + :number => 2, + :type => :TYPE_ENUM, + :type_name => '.foo.bar.SnafuState'), + ], + :options => ::Google::Protobuf::MessageOptions.new(:map_entry => true)), + ] + end + + specify { expect(subject).to eq " map :string, ::Foo::Bar::SnafuState, :foo_bar, 3\n" } end context 'when field is deprecated' do let(:field_options) { { :deprecated => true } } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :deprecated => true\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :deprecated => true\n" } end context 'when field uses a custom option that is an extension' do @@ -128,31 +165,31 @@ class ::Google::Protobuf::FieldOptions < ::Protobuf::Message describe 'option has a string value' do let(:field_options) { { :custom_string_option => 'boom' } } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_string_option => \"boom\"\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :custom_string_option => \"boom\"\n" } end describe 'option has a bool value' do let(:field_options) { { :custom_bool_option => true } } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_bool_option => true\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :custom_bool_option => true\n" } end describe 'option has a int32 value' do let(:field_options) { { :custom_int32_option => 123 } } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_int32_option => 123\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :custom_int32_option => 123\n" } end describe 'option has a message value' do let(:field_options) { { :custom_message_option => CustomFieldMessage.new(:foo => 'boom') } } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_message_option => { :foo => \"boom\" }\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :custom_message_option => { :foo => \"boom\" }\n" } end describe 'option has a enum value' do let(:field_options) { { :custom_enum_option => CustomFieldEnum::BAM } } - specify { expect(subject).to eq "optional :string, :foo_bar, 3, :custom_enum_option => ::CustomFieldEnum::BAM\n" } + specify { expect(subject).to eq " optional :string, :foo_bar, 3, :custom_enum_option => ::CustomFieldEnum::BAM\n" } end end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 471727dc..04b17ff1 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -715,6 +715,43 @@ end end + describe 'map fields' do + it 'serializes the same as equivalent non-map-field' do + class MessageWithMapField < ::Protobuf::Message + map :int32, :string, :map, 1 + end + + class MessageWithoutMapField < ::Protobuf::Message + class MapEntry < ::Protobuf::Message + optional :int32, :key, 1 + optional :string, :value, 2 + end + repeated MapEntry, :map, 1 + end + + map_msg = MessageWithMapField.new(:map => + { + 1 => 'one', + 2 => 'two', + 3 => 'three', + 4 => 'four', + },,) + mapless_msg = MessageWithoutMapField.new(:map => + [{ :key => 1, :value => 'one' }, + { :key => 2, :value => 'two' }, + { :key => 3, :value => 'three' }, + { :key => 4, :value => 'four' }, + ],,) + + map_bytes = map_msg.encode + mapless_bytes = mapless_msg.encode + expect(map_bytes).to eq(mapless_bytes) + + expect(MessageWithMapField.decode(mapless_bytes)).to eq(map_msg) + expect(MessageWithoutMapField.decode(map_bytes)).to eq(mapless_msg) + end + end + describe '.[]=' do context 'clearing fields' do it 'clears repeated fields with an empty array' do diff --git a/spec/support/protos/map-test.bin b/spec/support/protos/map-test.bin new file mode 100644 index 00000000..5f6e02c3 --- /dev/null +++ b/spec/support/protos/map-test.bin @@ -0,0 +1,157 @@ + +�! +map-test.protofoo"� +Baz2 +looks_like_map ( 2.foo.Baz.LooksLikeMapEntry@ +does_not_look_like_map ( 2 .foo.Baz.DoesNotLookLikeMapEntry3 +LooksLikeMapEntry +key (  +value ( :85 +DoesNotLookLikeMapEntry +key (  +value ( "� +Bar0 + sint32_to_baz ( 2.foo.Bar.Sint32ToBazEntry0 + sint64_to_baz ( 2.foo.Bar.Sint64ToBazEntry. + int32_to_baz ( 2.foo.Bar.Int32ToBazEntry. + int64_to_baz ( 2.foo.Bar.Int64ToBazEntry0 + uint32_to_baz ( 2.foo.Bar.Uint32ToBazEntry0 + uint64_to_baz ( 2.foo.Bar.Uint64ToBazEntry0 + string_to_baz ( 2.foo.Bar.StringToBazEntry: +sint32_to_frobnitz ( 2.foo.Bar.Sint32ToFrobnitzEntry: +sint64_to_frobnitz ( 2.foo.Bar.Sint64ToFrobnitzEntry8 +int32_to_frobnitz + ( 2.foo.Bar.Int32ToFrobnitzEntry8 +int64_to_frobnitz ( 2.foo.Bar.Int64ToFrobnitzEntry: +uint32_to_frobnitz ( 2.foo.Bar.Uint32ToFrobnitzEntry: +uint64_to_frobnitz ( 2.foo.Bar.Uint64ToFrobnitzEntry: +string_to_frobnitz ( 2.foo.Bar.StringToFrobnitzEntry6 +sint32_to_string ( 2.foo.Bar.Sint32ToStringEntry6 +sint64_to_string ( 2.foo.Bar.Sint64ToStringEntry4 +int32_to_string ( 2.foo.Bar.Int32ToStringEntry4 +int64_to_string ( 2.foo.Bar.Int64ToStringEntry6 +uint32_to_string ( 2.foo.Bar.Uint32ToStringEntry6 +uint64_to_string ( 2.foo.Bar.Uint64ToStringEntry6 +string_to_string ( 2.foo.Bar.StringToStringEntry4 +sint32_to_float ( 2.foo.Bar.Sint32ToFloatEntry4 +sint64_to_float ( 2.foo.Bar.Sint64ToFloatEntry2 +int32_to_float ( 2.foo.Bar.Int32ToFloatEntry2 +int64_to_float ( 2.foo.Bar.Int64ToFloatEntry4 +uint32_to_float ( 2.foo.Bar.Uint32ToFloatEntry4 +uint64_to_float ( 2.foo.Bar.Uint64ToFloatEntry4 +string_to_float ( 2.foo.Bar.StringToFloatEntry6 +sint32_to_double ( 2.foo.Bar.Sint32ToDoubleEntry6 +sint64_to_double ( 2.foo.Bar.Sint64ToDoubleEntry4 +int32_to_double ( 2.foo.Bar.Int32ToDoubleEntry4 +int64_to_double ( 2.foo.Bar.Int64ToDoubleEntry6 +uint32_to_double! ( 2.foo.Bar.Uint32ToDoubleEntry6 +uint64_to_double" ( 2.foo.Bar.Uint64ToDoubleEntry6 +string_to_double# ( 2.foo.Bar.StringToDoubleEntry< +Sint32ToBazEntry +key ( +value ( 2.foo.Baz:8< +Sint64ToBazEntry +key ( +value ( 2.foo.Baz:8; +Int32ToBazEntry +key ( +value ( 2.foo.Baz:8; +Int64ToBazEntry +key ( +value ( 2.foo.Baz:8< +Uint32ToBazEntry +key (  +value ( 2.foo.Baz:8< +Uint64ToBazEntry +key ( +value ( 2.foo.Baz:8< +StringToBazEntry +key (  +value ( 2.foo.Baz:8F +Sint32ToFrobnitzEntry +key ( +value (2 .foo.Frobnitz:8F +Sint64ToFrobnitzEntry +key ( +value (2 .foo.Frobnitz:8E +Int32ToFrobnitzEntry +key ( +value (2 .foo.Frobnitz:8E +Int64ToFrobnitzEntry +key ( +value (2 .foo.Frobnitz:8F +Uint32ToFrobnitzEntry +key (  +value (2 .foo.Frobnitz:8F +Uint64ToFrobnitzEntry +key ( +value (2 .foo.Frobnitz:8F +StringToFrobnitzEntry +key (  +value (2 .foo.Frobnitz:85 +Sint32ToStringEntry +key ( +value ( :85 +Sint64ToStringEntry +key ( +value ( :84 +Int32ToStringEntry +key ( +value ( :84 +Int64ToStringEntry +key ( +value ( :85 +Uint32ToStringEntry +key (  +value ( :85 +Uint64ToStringEntry +key ( +value ( :85 +StringToStringEntry +key (  +value ( :84 +Sint32ToFloatEntry +key ( +value (:84 +Sint64ToFloatEntry +key ( +value (:83 +Int32ToFloatEntry +key ( +value (:83 +Int64ToFloatEntry +key ( +value (:84 +Uint32ToFloatEntry +key (  +value (:84 +Uint64ToFloatEntry +key ( +value (:84 +StringToFloatEntry +key (  +value (:85 +Sint32ToDoubleEntry +key ( +value (:85 +Sint64ToDoubleEntry +key ( +value (:84 +Int32ToDoubleEntry +key ( +value (:84 +Int64ToDoubleEntry +key ( +value (:85 +Uint32ToDoubleEntry +key (  +value (:85 +Uint64ToDoubleEntry +key ( +value (:85 +StringToDoubleEntry +key (  +value (:8* +Frobnitz +FROB +NITZ \ No newline at end of file diff --git a/spec/support/protos/map-test.pb.rb b/spec/support/protos/map-test.pb.rb new file mode 100644 index 00000000..bd856360 --- /dev/null +++ b/spec/support/protos/map-test.pb.rb @@ -0,0 +1,85 @@ +# encoding: utf-8 + +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf' + +module Foo + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } + + ## + # Enum Classes + # + class Frobnitz < ::Protobuf::Enum + define :FROB, 1 + define :NITZ, 2 + end + + + ## + # Message Classes + # + class Baz < ::Protobuf::Message + class DoesNotLookLikeMapEntry < ::Protobuf::Message; end + + end + + class Bar < ::Protobuf::Message + end + + + + ## + # Message Fields + # + class Baz + class DoesNotLookLikeMapEntry + optional :string, :key, 1 + optional :string, :value, 2 + end + + map :string, :string, :looks_like_map, 1 + repeated ::Foo::Baz::DoesNotLookLikeMapEntry, :does_not_look_like_map, 2 + end + + class Bar + map :sint32, ::Foo::Baz, :sint32_to_baz, 1 + map :sint64, ::Foo::Baz, :sint64_to_baz, 2 + map :int32, ::Foo::Baz, :int32_to_baz, 3 + map :int64, ::Foo::Baz, :int64_to_baz, 4 + map :uint32, ::Foo::Baz, :uint32_to_baz, 5 + map :uint64, ::Foo::Baz, :uint64_to_baz, 6 + map :string, ::Foo::Baz, :string_to_baz, 7 + map :sint32, ::Foo::Frobnitz, :sint32_to_frobnitz, 8 + map :sint64, ::Foo::Frobnitz, :sint64_to_frobnitz, 9 + map :int32, ::Foo::Frobnitz, :int32_to_frobnitz, 10 + map :int64, ::Foo::Frobnitz, :int64_to_frobnitz, 11 + map :uint32, ::Foo::Frobnitz, :uint32_to_frobnitz, 12 + map :uint64, ::Foo::Frobnitz, :uint64_to_frobnitz, 13 + map :string, ::Foo::Frobnitz, :string_to_frobnitz, 14 + map :sint32, :string, :sint32_to_string, 15 + map :sint64, :string, :sint64_to_string, 16 + map :int32, :string, :int32_to_string, 17 + map :int64, :string, :int64_to_string, 18 + map :uint32, :string, :uint32_to_string, 19 + map :uint64, :string, :uint64_to_string, 20 + map :string, :string, :string_to_string, 21 + map :sint32, :float, :sint32_to_float, 22 + map :sint64, :float, :sint64_to_float, 23 + map :int32, :float, :int32_to_float, 24 + map :int64, :float, :int64_to_float, 25 + map :uint32, :float, :uint32_to_float, 26 + map :uint64, :float, :uint64_to_float, 27 + map :string, :float, :string_to_float, 28 + map :sint32, :double, :sint32_to_double, 29 + map :sint64, :double, :sint64_to_double, 30 + map :int32, :double, :int32_to_double, 31 + map :int64, :double, :int64_to_double, 32 + map :uint32, :double, :uint32_to_double, 33 + map :uint64, :double, :uint64_to_double, 34 + map :string, :double, :string_to_double, 35 + end + +end + diff --git a/spec/support/protos/map-test.proto b/spec/support/protos/map-test.proto new file mode 100644 index 00000000..6f7f221d --- /dev/null +++ b/spec/support/protos/map-test.proto @@ -0,0 +1,68 @@ +// Use protoc v3.0.0 to compile this file into map-test.bin: +// protoc --descriptor_set_out=map-test.bin map-test.proto + +syntax = "proto2"; + +package foo; + +enum Frobnitz { + FROB = 1; + NITZ = 2; +} + +message Baz { + message LooksLikeMapEntry { + option map_entry = true; + optional string key = 1; + optional string value = 2; + } + repeated LooksLikeMapEntry looks_like_map = 1; + + message DoesNotLookLikeMapEntry { + optional string key = 1; + optional string value = 2; + } + repeated DoesNotLookLikeMapEntry does_not_look_like_map = 2; +} + +message Bar { + map sint32_to_baz = 1; + map sint64_to_baz = 2; + map int32_to_baz = 3; + map int64_to_baz = 4; + map uint32_to_baz = 5; + map uint64_to_baz = 6; + map string_to_baz = 7; + + map sint32_to_frobnitz = 8; + map sint64_to_frobnitz = 9; + map int32_to_frobnitz = 10; + map int64_to_frobnitz = 11; + map uint32_to_frobnitz = 12; + map uint64_to_frobnitz = 13; + map string_to_frobnitz = 14; + + map sint32_to_string = 15; + map sint64_to_string = 16; + map int32_to_string = 17; + map int64_to_string = 18; + map uint32_to_string = 19; + map uint64_to_string = 20; + map string_to_string = 21; + + map sint32_to_float = 22; + map sint64_to_float = 23; + map int32_to_float = 24; + map int64_to_float = 25; + map uint32_to_float = 26; + map uint64_to_float = 27; + map string_to_float = 28; + + map sint32_to_double = 29; + map sint64_to_double = 30; + map int32_to_double = 31; + map int64_to_double = 32; + map uint32_to_double = 33; + map uint64_to_double = 34; + map string_to_double = 35; +} From dcdd1c62957813080b3002b541ffd631d85f3f63 Mon Sep 17 00:00:00 2001 From: Embark Date: Tue, 28 Mar 2017 20:56:29 -0700 Subject: [PATCH 1076/1191] Rubocop adjustments --- lib/protobuf/message.rb | 11 +++---- spec/lib/protobuf/message_spec.rb | 54 +++++++++++++++---------------- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1b71a831..dee84d8b 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -163,13 +163,9 @@ def ==(other) def [](name) field = self.class.get_field(name, true) - if field.map? - return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(field) - elsif field.repeated? - return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) - else - @values.fetch(field.fully_qualified_name, field.default_value) - end + return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(field) if field.map? + return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) if field.repeated? + @values.fetch(field.fully_qualified_name, field.default_value) rescue # not having a field should be the exceptional state raise if field fail ArgumentError, "invalid field name=#{name.inspect}" @@ -200,6 +196,7 @@ def []=(name, value) private + # rubocop:disable Metrics/MethodLength def set_field(name, value, ignore_nil_for_repeated) if (field = self.class.get_field(name, true)) if field.map? diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 04b17ff1..da9a7c7e 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -721,34 +721,34 @@ class MessageWithMapField < ::Protobuf::Message map :int32, :string, :map, 1 end - class MessageWithoutMapField < ::Protobuf::Message - class MapEntry < ::Protobuf::Message - optional :int32, :key, 1 - optional :string, :value, 2 - end - repeated MapEntry, :map, 1 + class MessageWithoutMapField < ::Protobuf::Message + class MapEntry < ::Protobuf::Message + optional :int32, :key, 1 + optional :string, :value, 2 end - - map_msg = MessageWithMapField.new(:map => - { - 1 => 'one', - 2 => 'two', - 3 => 'three', - 4 => 'four', - },,) - mapless_msg = MessageWithoutMapField.new(:map => - [{ :key => 1, :value => 'one' }, - { :key => 2, :value => 'two' }, - { :key => 3, :value => 'three' }, - { :key => 4, :value => 'four' }, - ],,) - - map_bytes = map_msg.encode - mapless_bytes = mapless_msg.encode - expect(map_bytes).to eq(mapless_bytes) - - expect(MessageWithMapField.decode(mapless_bytes)).to eq(map_msg) - expect(MessageWithoutMapField.decode(map_bytes)).to eq(mapless_msg) + repeated MapEntry, :map, 1 + end + + map_msg = MessageWithMapField.new(:map => + { + 1 => 'one', + 2 => 'two', + 3 => 'three', + 4 => 'four', + }) + mapless_msg = MessageWithoutMapField.new(:map => + [{ :key => 1, :value => 'one' }, + { :key => 2, :value => 'two' }, + { :key => 3, :value => 'three' }, + { :key => 4, :value => 'four' }, + ]) + + map_bytes = map_msg.encode + mapless_bytes = mapless_msg.encode + expect(map_bytes).to eq(mapless_bytes) + + expect(MessageWithMapField.decode(mapless_bytes)).to eq(map_msg) + expect(MessageWithoutMapField.decode(map_bytes)).to eq(mapless_msg) end end From 58ced28559c9e18775442b3fd78676878b20bf26 Mon Sep 17 00:00:00 2001 From: Embark Date: Tue, 11 Jul 2017 21:11:30 -0700 Subject: [PATCH 1077/1191] Fix specs --- spec/lib/protobuf/generators/field_generator_spec.rb | 2 +- spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 71da1cf9..45225393 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -68,7 +68,7 @@ let(:default_value) { 'quux' } before { allow(ENV).to receive(:key?).with('PB_UPCASE_ENUMS').and_return(true) } - specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } + specify { expect(subject).to eq " optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } end context 'when the type is a string' do diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 7c291053..f58be4fc 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -86,7 +86,7 @@ let(:request_wrapper) do ::Protobuf::Socketrpc::Request.new( :caller => client_host, - :service_name => 'Foo', + :service_name => 'NonexistantService', :method_name => method_name.to_s, :request_proto => request, ) From f6d290c2ee6ced304bb65fd1a9766ca54fcefe70 Mon Sep 17 00:00:00 2001 From: Alex Coomans Date: Fri, 5 May 2017 13:55:56 -0700 Subject: [PATCH 1078/1191] Properly convert values in a map to a hash --- lib/protobuf/field/field_hash.rb | 8 +++- spec/lib/protobuf/field/field_hash_spec.rb | 47 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/field_hash.rb b/lib/protobuf/field/field_hash.rb index d35056f7..f54fc091 100644 --- a/lib/protobuf/field/field_hash.rb +++ b/lib/protobuf/field/field_hash.rb @@ -43,9 +43,13 @@ def merge!(other) alias update merge! # Return a hash-representation of the given values for this field type. - # The value in this case would be the hash itself. + # The value in this case would be the hash itself, right? Unfortunately + # not because the values of the map could be messages themselves that we + # need to transform. def to_hash_value - self + each_with_object({}) do |(key, value), hash| + hash[key] = value.respond_to?(:to_hash_value) ? value.to_hash_value : value + end end def to_s diff --git a/spec/lib/protobuf/field/field_hash_spec.rb b/spec/lib/protobuf/field/field_hash_spec.rb index 631f537c..42a46682 100644 --- a/spec/lib/protobuf/field/field_hash_spec.rb +++ b/spec/lib/protobuf/field/field_hash_spec.rb @@ -114,7 +114,54 @@ expect { instance.map_string_to_enum.send(method, nil, SomeEnum::FOO) }.to raise_error(TypeError) expect { instance.map_string_to_enum.send(method, 'foo', nil) }.to raise_error(TypeError) end + end + end + + describe '#to_hash_value' do + context 'when applied to an int32->string field hash' do + before do + instance.map_int32_to_string[1] = 'string 1' + instance.map_int32_to_string[2] = 'string 2' + end + + it 'converts properly' do + expect(instance.to_hash_value).to eq(:map_int32_to_string => { + 1 => 'string 1', + 2 => 'string 2', + }) + end + end + + context 'when applied to a string->MessageField field hash' do + before do + instance.map_string_to_msg['msg1'] = BasicMessage.new(:field => 'string 1') + instance.map_string_to_msg['msg2'] = BasicMessage.new(:field => 'string 2') + end + + it 'converts properly' do + expect(instance.to_hash_value).to eq(:map_string_to_msg => { + 'msg1' => { + :field => 'string 1', + }, + 'msg2' => { + :field => 'string 2', + }, + }) + end + end + context 'when applied to a string->EnumField field hash' do + before do + instance.map_string_to_enum['msg1'] = SomeEnum::FOO + instance.map_string_to_enum['msg2'] = SomeEnum::BAR + end + + it 'converts properly' do + expect(instance.to_hash_value).to eq(:map_string_to_enum => { + 'msg1' => 1, + 'msg2' => 2, + }) + end end end end From 5886ecc3c242b8517779ccf784c420ae06d8a0f3 Mon Sep 17 00:00:00 2001 From: Embark Date: Wed, 12 Jul 2017 18:20:49 -0700 Subject: [PATCH 1079/1191] minor feedback changes --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/generators/field_generator.rb | 14 ++++++-------- spec/lib/protobuf/field/field_hash_spec.rb | 2 +- .../protobuf/generators/field_generator_spec.rb | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d18827da..22914244 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -151,7 +151,7 @@ def set(message_instance, bytes) # decoded value could be nil for an # enum value that is not recognized hash[entry.key] = entry.value unless entry.value.nil? - return + return hash[entry.key] end return message_instance[name] << decode(bytes) unless packed? diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 256c5b30..68652fcc 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -125,15 +125,13 @@ def map? end def map_key_type_name - e = map_entry - return nil if e.nil? - determine_type_name(e.field.find { |v| v.name == 'key' && v.number == 1 }) + return nil if map_entry.nil? + determine_type_name(map_entry.field.find { |v| v.name == 'key' && v.number == 1 }) end def map_value_type_name - e = map_entry - return nil if e.nil? - determine_type_name(e.field.find { |v| v.name == 'value' && v.number == 2 }) + return nil if map_entry.nil? + determine_type_name(map_entry.field.find { |v| v.name == 'value' && v.number == 2 }) end private @@ -174,7 +172,7 @@ def determine_type_name(descriptor) when :TYPE_MESSAGE, :TYPE_ENUM, :TYPE_GROUP then modulize(descriptor.type_name) else - type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '') + type_name = descriptor.type.name.to_s.downcase.sub(/^type_/, '') ":#{type_name}" end end @@ -186,7 +184,7 @@ def determine_map_entry name_parts = descriptor.type_name.split(".") return nil if name_parts.size < 2 || name_parts[-2] != @enclosing_msg_descriptor.name nested = @enclosing_msg_descriptor.nested_type.find { |e| e.name == name_parts[-1] } - return nested if !nested.nil? && nested.options.try(:map_entry?) { false } + return nested if !nested.nil? && nested.options.try(:map_entry?) nil end diff --git a/spec/lib/protobuf/field/field_hash_spec.rb b/spec/lib/protobuf/field/field_hash_spec.rb index 42a46682..2b328755 100644 --- a/spec/lib/protobuf/field/field_hash_spec.rb +++ b/spec/lib/protobuf/field/field_hash_spec.rb @@ -40,7 +40,7 @@ let(:instance) { SomeMapMessage.new } %w([]= store).each do |method| - describe "\##{method}" do + describe "##{method}" do context 'when applied to an int32->string field hash' do it 'adds an int -> string entry' do expect(instance.map_int32_to_string).to be_empty diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 45225393..e4d78ea2 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -132,7 +132,7 @@ :type_name => '.foo.bar.SnafuState'), ], :options => ::Google::Protobuf::MessageOptions.new(:map_entry => true)), - ] + ] end specify { expect(subject).to eq " map :string, ::Foo::Bar::SnafuState, :foo_bar, 3\n" } From e93ae308c70d4e2ea3971d2aa358e14241df1677 Mon Sep 17 00:00:00 2001 From: Embark Date: Mon, 24 Jul 2017 12:53:10 -0700 Subject: [PATCH 1080/1191] memoize #map? --- lib/protobuf/field/base_field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 22914244..197ed9b4 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -118,7 +118,7 @@ def message? end def map? - repeated_message? && type_class.get_option(:map_entry) + @is_map ||= repeated_message? && type_class.get_option(:map_entry) end def optional? From 2ab80d9452c361376feb1b90374dfcb54eccb507 Mon Sep 17 00:00:00 2001 From: Thierry Deo Date: Sat, 22 Jul 2017 18:40:51 +0200 Subject: [PATCH 1081/1191] Add option to have require_relative statements --- lib/protobuf/generators/file_generator.rb | 2 +- lib/protobuf/generators/printable.rb | 4 ++-- spec/lib/protobuf/generators/file_generator_spec.rb | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 6382d708..f94d2264 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -125,7 +125,7 @@ def print_import_requires header "Imports" descriptor.dependency.each do |dependency| - print_require(convert_filename(dependency)) + print_require(convert_filename(dependency), ENV.key?('PB_REQUIRE_RELATIVE')) end puts diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 4a4f4dee..3d8fe770 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -127,8 +127,8 @@ def print_module(name, &block) # # print_require('foo/bar/baz') -> "require 'foo/bar/baz'" # - def print_require(file) - puts "require '#{file}'" + def print_require(file, relative = false) + puts "require#{'_relative' if relative} '#{file}'" end # Puts the given message prefixed by the indent level. diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index b1eb0d64..51a6156f 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -22,11 +22,18 @@ end it 'prints a ruby require for each dependency' do - expect(subject).to receive(:print_require).with('test/bar.pb') - expect(subject).to receive(:print_require).with('test/baz.pb') + expect(subject).to receive(:print_require).with('test/bar.pb', false) + expect(subject).to receive(:print_require).with('test/baz.pb', false) subject.print_import_requires end + it 'prints a ruby require_relative for each dependency if environment variable was set' do + expect(subject).to receive(:print_require).with('test/bar.pb', true) + expect(subject).to receive(:print_require).with('test/baz.pb', true) + ENV['PB_REQUIRE_RELATIVE'] = 'true' + subject.print_import_requires + ENV.delete('PB_REQUIRE_RELATIVE') + end end describe '#compile' do From b1a3746f3e06d4b57c86be0994024ff8ef83a4c4 Mon Sep 17 00:00:00 2001 From: Embark Date: Mon, 14 Aug 2017 10:45:47 -0700 Subject: [PATCH 1082/1191] Remove new repeated enum error behavior --- lib/protobuf/field/field_array.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 0c0e1428..78bb79e0 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -65,7 +65,7 @@ def normalize(value) fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) if field.is_a?(::Protobuf::Field::EnumField) - fetch_enum(field.type_class, value) + field.type_class.fetch(value) elsif field.is_a?(::Protobuf::Field::MessageField) && value.is_a?(field.type_class) value elsif field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) @@ -75,12 +75,6 @@ def normalize(value) end end - def fetch_enum(type, val) - en = type.fetch(val) - raise_type_error(val) if en.nil? - en - end - def raise_type_error(val) fail TypeError, <<-TYPE_ERROR Expected repeated value of type '#{field.type_class}' From 572c4be936bc46ef198a0f128c953c6e03d11f40 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 6 Sep 2017 15:59:01 -0400 Subject: [PATCH 1083/1191] Bump version to 3.8.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b8e0b822..0723a105 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.7.5' # rubocop:disable Style/MutableConstant + VERSION = '3.8.0' # rubocop:disable Style/MutableConstant end From 24b44e3f1cfbadeb7d05e351ad00da83dd5e5ed6 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 6 Sep 2017 16:00:43 -0400 Subject: [PATCH 1084/1191] Update changelog --- CHANGES.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4953d1eb..2677938a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,8 @@ -# Beta (3.7.x) +# Stable (3.8.x) + +3.8.0 +----- +- Map types now supported (#367) 3.7.0 (pre3) ----------- From a3cafa77fb8b26a4adf5913788bbdb0c6c1aeaaa Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Thu, 21 Sep 2017 21:25:25 -0400 Subject: [PATCH 1085/1191] Bump version to 3.8.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 0723a105..9a1e425b 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.8.0' # rubocop:disable Style/MutableConstant + VERSION = '3.8.1' # rubocop:disable Style/MutableConstant end From 2bc8653fc181d0b9dee3bdb69d4d5b3399e91b8d Mon Sep 17 00:00:00 2001 From: Rick Song Date: Thu, 5 Oct 2017 21:44:29 -0700 Subject: [PATCH 1086/1191] Fix compatibility issues for Ruby 2.4.0 This change uses 1.class instead of hard coding to Fixnum to prevent Ruby >= 2.4.0 from raising a deprecation warning. We use this implementation to also guarantee backward compatibility as well. --- .travis.yml | 1 + lib/protobuf/enum.rb | 10 ++++++++-- spec/lib/protobuf/enum_spec.rb | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 87911ea1..f0153d97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ rvm: - 2.2 - 2.2.2 - 2.3 + - 2.4 - jruby-9.1.7.0 - rbx-2 env: diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index c0e012c6..3ab67a0c 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -259,10 +259,16 @@ def initialize(parent_class, name, tag) super(tag) end - # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum + # Overriding the class so ActiveRecord/Arel visitor will visit the enum as an + # Integer. # def class - Fixnum + # This is done for backward compatibility for < 2.4.0. This ensures that + # if Ruby version >= 2.4.0, this will return Integer. If below, then will + # return Fixnum. + # + # This prevents the constant deprecation warnings on Fixnum. + tag.class end def inspect diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 3084647f..cdc39004 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -214,7 +214,7 @@ end subject { Test::EnumTestType::ONE } - specify { expect(subject.class).to eq(Fixnum) } + specify { expect(subject.class).to eq(1.class) } specify { expect(subject.parent_class).to eq(Test::EnumTestType) } specify { expect(subject.name).to eq(:ONE) } specify { expect(subject.tag).to eq(1) } From dba95292cb96303208290c834ddb01932d524a95 Mon Sep 17 00:00:00 2001 From: "adam.hutchison" Date: Thu, 22 Feb 2018 10:07:17 -0700 Subject: [PATCH 1087/1191] Update the compile task to work with protoc v3 The Protocol Buffers v3 compiler (protoc) now comes with a builtin Ruby plugin. This conflicts with our local custom Ruby plugin. In order to use it, the custom plugin must be passed to the compiler, and invoked via the custom output generator: protoc --plugin=protoc-gen-ruby-protobuf=/path/to/bin/protoc-gen-ruby --ruby-protobuf_out=lib Update the compile task to take this new pattern into account so that it works with both the v2 and v3 compilers. --- lib/protobuf/tasks/compile.rake | 52 +++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index db9f01bb..9e8c34cc 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -1,13 +1,32 @@ -require 'fileutils' +require "fileutils" namespace :protobuf do - desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' + desc "Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first." task :compile, [:package, :source, :destination, :plugin, :file_extension] do |_tasks, args| - args.with_defaults(:destination => 'lib') - args.with_defaults(:source => 'definitions') - args.with_defaults(:plugin => 'ruby') - args.with_defaults(:file_extension => '.pb.rb') + binpath = ::File.expand_path("../../../../bin", __FILE__) + + args.with_defaults(:destination => "lib") + args.with_defaults(:source => "definitions") + args.with_defaults(:plugin => "protoc-gen-ruby-protobuf=#{binpath}/protoc-gen-ruby") + args.with_defaults(:file_extension => ".pb.rb") + + # The local Ruby generator collides with the builtin Ruby generator + # + # From the protoc docs: + # + # --plugin=EXECUTABLE + # + # ...EXECUTABLE may be of the form NAME=PATH, in which case the given plugin name + # is mapped to the given executable even if the executable"s own name differs. + # + # Use the NAME=PATH form to specify an alternative plugin name that avoids the name collision + # + plugin_name, _plugin_path = args[:plugin].split("=") + + # The plugin name MUST have the protoc-gen- prefix in order to work, but that prefix is dropped + # when using the plugin to generate definitions + plugin_name.gsub!("protoc-gen-", "") unless do_not_clean? force_clean! @@ -16,22 +35,23 @@ namespace :protobuf do command = [] command << "protoc" - command << "--#{args[:plugin]}_out=#{args[:destination]}" + command << "--plugin=#{args[:plugin]}" + command << "--#{plugin_name}_out=#{args[:destination]}" command << "-I #{args[:source]}" command << Dir["#{args[:source]}/#{args[:package]}/**/*.proto"].join(" ") - full_command = command.join(' ') + full_command = command.join(" ") puts full_command system(full_command) end - desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' + desc "Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step." task :clean, [:package, :destination, :file_extension] do |_task, args| - args.with_defaults(:destination => 'lib') - args.with_defaults(:file_extension => '.pb.rb') + args.with_defaults(:destination => "lib") + args.with_defaults(:file_extension => ".pb.rb") - file_extension = args[:file_extension].sub(/\*?\.+/, '') - files_to_clean = ::File.join(args[:destination], args[:package], '**', "*.#{file_extension}") + file_extension = args[:file_extension].sub(/\*?\.+/, "") + files_to_clean = ::File.join(args[:destination], args[:package], "**", "*.#{file_extension}") if force_clean? || permission_to_clean?(files_to_clean) ::Dir.glob(files_to_clean).each do |file| @@ -41,15 +61,15 @@ namespace :protobuf do end def do_not_clean? - ! ::ENV.key?('PB_NO_CLEAN') + ! ::ENV.key?("PB_NO_CLEAN") end def force_clean? - ::ENV.key?('PB_FORCE_CLEAN') + ::ENV.key?("PB_FORCE_CLEAN") end def force_clean! - ::ENV['PB_FORCE_CLEAN'] = '1' + ::ENV["PB_FORCE_CLEAN"] = "1" end def permission_to_clean?(files_to_clean) From b16196ecc55add425129e79bab1083dbba1ae986 Mon Sep 17 00:00:00 2001 From: "adam.hutchison" Date: Thu, 22 Feb 2018 14:51:01 -0700 Subject: [PATCH 1088/1191] Bump version to 3.8.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9a1e425b..9b9ceddd 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.8.1' # rubocop:disable Style/MutableConstant + VERSION = '3.8.2' # rubocop:disable Style/MutableConstant end From 1338abeb387c7f5ec3a440c90876b753432158c0 Mon Sep 17 00:00:00 2001 From: Alex Coomans Date: Thu, 3 May 2018 11:04:03 -0500 Subject: [PATCH 1089/1191] Base64 encode byte fields when converting to JSON --- lib/protobuf.rb | 3 ++- lib/protobuf/enum.rb | 1 + lib/protobuf/field/bytes_field.rb | 4 ++++ lib/protobuf/field/field_array.rb | 15 +++++++++++++++ lib/protobuf/field/field_hash.rb | 18 ++++++++++++++++++ lib/protobuf/field/string_field.rb | 3 +++ lib/protobuf/message.rb | 28 +++++++++++++++++++++++++++- spec/lib/protobuf/message_spec.rb | 10 ++++++++++ 8 files changed, 80 insertions(+), 2 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 29cc457c..148b1170 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -1,6 +1,7 @@ +require 'base64' require 'logger' -require 'socket' require 'pp' +require 'socket' require 'stringio' require 'active_support/core_ext/object/blank' diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 3ab67a0c..537b031f 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -316,5 +316,6 @@ def try(*args, &block) # Instance Aliases # alias :to_hash_value to_i + alias :to_json_hash_value to_i end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 1d519c02..9546780e 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -69,6 +69,10 @@ def coerce!(value) fail TypeError, "Unacceptable value #{value} for field #{name} of type #{type_class}" end end + + def json_encode(value) + Base64.strict_encode64(value) + end end end end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 78bb79e0..e4f2eb1a 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -46,6 +46,21 @@ def to_hash_value end end + # Return a hash-representation of the given values for this field type + # that is safe to convert to JSON. + # The value in this case would be an array. + def to_json_hash_value + if field.respond_to?(:json_encode) + map do |value| + field.json_encode(value) + end + else + map do |value| + value.respond_to?(:to_json_hash_value) ? value.to_json_hash_value : value + end + end + end + def to_s "[#{field.name}]" end diff --git a/lib/protobuf/field/field_hash.rb b/lib/protobuf/field/field_hash.rb index f54fc091..36b26447 100644 --- a/lib/protobuf/field/field_hash.rb +++ b/lib/protobuf/field/field_hash.rb @@ -52,6 +52,24 @@ def to_hash_value end end + # Return a hash-representation of the given values for this field type + # that is safe to convert to JSON. + # + # The value in this case would be the hash itself, right? Unfortunately + # not because the values of the map could be messages themselves that we + # need to transform. + def to_json_hash_value + if field.respond_to?(:json_encode) + each_with_object({}) do |(key, value), hash| + hash[key] = field.json_encode(value) + end + else + each_with_object({}) do |(key, value), hash| + hash[key] = value.respond_to?(:to_json_hash_value) ? value.to_json_hash_value : value + end + end + end + def to_s "{#{field.name}}" end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index f7d434fb..43ac0b12 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -38,6 +38,9 @@ def encode_to_stream(value, stream) stream << tag_encoded << byte_size << value end + def json_encode(value) + value + end end end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index dee84d8b..859864fd 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -145,7 +145,32 @@ def to_hash end def to_json(options = {}) - to_hash.to_json(options) + to_json_hash.to_json(options) + end + + # Return a hash-representation of the given fields for this message type that + # is safe to convert to JSON. + def to_json_hash + result = {} + + @values.each_key do |field_name| + value = self[field_name] + field = self.class.get_field(field_name, true) + + # NB: to_json_hash_value should come before json_encode so as to handle + # repeated fields without extra logic. + hashed_value = if value.respond_to?(:to_json_hash_value) + value.to_json_hash_value + elsif field.respond_to?(:json_encode) + field.json_encode(value) + else + value + end + + result[field.name] = hashed_value + end + + result end def to_proto @@ -179,6 +204,7 @@ def []=(name, value) # Instance Aliases # alias :to_hash_value to_hash + alias :to_json_hash_value to_json_hash alias :to_proto_hash to_hash alias :responds_to_has? respond_to_has? alias :respond_to_and_has? respond_to_has? diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index da9a7c7e..96668b67 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -427,6 +427,16 @@ end specify { expect(subject.to_json).to eq '{"name":"Test Name","active":false}' } + + context 'for byte fields' do + let(:bytes) { "\x06\x8D1HP\x17:b" } + + subject do + ::Test::ResourceFindRequest.new(:widget_bytes => [bytes]) + end + + specify { expect(subject.to_json).to eq '{"widget_bytes":["Bo0xSFAXOmI="]}' } + end end describe '.to_json' do From 1553f775c467421c6049f29038aae422a31b3ee2 Mon Sep 17 00:00:00 2001 From: matthew-nichols Date: Thu, 7 Jun 2018 16:08:43 -0600 Subject: [PATCH 1090/1191] Implement Enum#to_json to There is an issue in JrJackson RubyAnySerializer that does not render Protobuf::Enum correctly because it does not implement to_json. This fixes that issue here until the serializer can be patched. --- lib/protobuf/enum.rb | 8 ++++++++ spec/lib/protobuf/enum_spec.rb | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 537b031f..e5e07280 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -283,6 +283,14 @@ def to_int tag.to_int end + ## + # This fixes a reflection bug in JrJackson RubyAnySerializer that does not + # render Protobuf enums correctly because to_json is not defined. + # + def to_json + to_s + end + def to_s(format = :tag) case format when :tag diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index cdc39004..5f9fbbd2 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -160,6 +160,13 @@ end end + describe '.to_json' do + it 'renders the enum value' do + expect(Test::EnumTestType::ONE.to_json).to eq("1") + expect({ :value => Test::EnumTestType::ONE }.to_json).to eq(%({"value":1})) + end + end + describe '.valid_tag?' do context 'when tag is defined' do specify { expect(Test::EnumTestType.valid_tag?(tag)).to be true } From 9a24cb2b74102eb0b259a682bdbd46e822da3ae7 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 8 Jun 2018 11:54:20 -0400 Subject: [PATCH 1091/1191] Expect Enum#to_json to return a number --- lib/protobuf/enum.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index e5e07280..b159acf5 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -288,7 +288,7 @@ def to_int # render Protobuf enums correctly because to_json is not defined. # def to_json - to_s + to_i end def to_s(format = :tag) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 5f9fbbd2..1378668d 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -162,7 +162,7 @@ describe '.to_json' do it 'renders the enum value' do - expect(Test::EnumTestType::ONE.to_json).to eq("1") + expect(Test::EnumTestType::ONE.to_json).to eq(1) expect({ :value => Test::EnumTestType::ONE }.to_json).to eq(%({"value":1})) end end From cebadfa41564138f651324dd213eee423d3673d5 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 8 Jun 2018 16:20:42 -0400 Subject: [PATCH 1092/1191] Bump version to 3.8.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9b9ceddd..eaa5bb9b 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.8.2' # rubocop:disable Style/MutableConstant + VERSION = '3.8.3' # rubocop:disable Style/MutableConstant end From ab0de8d17651bd5034c99502d98b6266adb61993 Mon Sep 17 00:00:00 2001 From: Alex Coomans Date: Mon, 11 Jun 2018 13:52:45 -0500 Subject: [PATCH 1093/1191] Fix enum's to_json --- lib/protobuf/enum.rb | 9 +++++---- spec/lib/protobuf/enum_spec.rb | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index b159acf5..a50ebc54 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -283,12 +283,13 @@ def to_int tag.to_int end - ## # This fixes a reflection bug in JrJackson RubyAnySerializer that does not - # render Protobuf enums correctly because to_json is not defined. + # render Protobuf enums correctly because to_json is not defined. It takes + # any number of arguments to support the JSON gem trying to pass an argument. + # NB: This method is required to return a string and not an integer. # - def to_json - to_i + def to_json(*) + to_s end def to_s(format = :tag) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 1378668d..a2bebb8d 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -162,8 +162,10 @@ describe '.to_json' do it 'renders the enum value' do - expect(Test::EnumTestType::ONE.to_json).to eq(1) + expect(Test::EnumTestType::ONE.to_json).to eq("1") expect({ :value => Test::EnumTestType::ONE }.to_json).to eq(%({"value":1})) + # JSON.dump passes arguments to the to_json method which broke in the 3.8.3 release. + expect(JSON.dump(:value => Test::EnumTestType::ONE)).to eq(%({"value":1})) end end From ac12151db8c6ef5a0931642558d195e5fac16b4d Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Tue, 12 Jun 2018 12:02:04 -0400 Subject: [PATCH 1094/1191] Bump version to 3.8.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index eaa5bb9b..f3007bb4 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.8.3' # rubocop:disable Style/MutableConstant + VERSION = '3.8.4' # rubocop:disable Style/MutableConstant end From 485d419c50e3886162c24f1c2fc45aeea8f9842a Mon Sep 17 00:00:00 2001 From: Alex Coomans Date: Wed, 13 Jun 2018 19:11:48 -0500 Subject: [PATCH 1095/1191] Fix enum equality --- lib/protobuf/enum.rb | 14 ++++++++++++++ spec/lib/protobuf/enum_spec.rb | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 3ab67a0c..096a5b78 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -259,6 +259,20 @@ def initialize(parent_class, name, tag) super(tag) end + # Custom equality method since otherwise identical values from different + # enums will be considered equal by Integer's equality method (or + # Fixnum's on Ruby < 2.4.0). + # + def ==(other) + if other.is_a?(Protobuf::Enum) + parent_class == other.parent_class && tag == other.tag + elsif tag.class == other.class + tag == other + else + false + end + end + # Overriding the class so ActiveRecord/Arel visitor will visit the enum as an # Integer. # diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index cdc39004..1b3b3c0d 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -21,6 +21,20 @@ end end + describe '.==' do + it 'is true for identical values' do + expect(Test::EnumTestType::THREE).to eq(Test::EnumTestType::THREE) + end + + it 'is false for different values in the same enum' do + expect(Test::EnumTestType::TWO).to_not eq(Test::EnumTestType::THREE) + end + + it 'is false for values from different enums' do + expect(Test::EnumTestType::THREE).to_not eq(Test::AliasedEnum::THREE) + end + end + describe '.aliases_allowed?' do it 'is false when the option is not set' do expect(Test::EnumTestType.aliases_allowed?).to be false From da5b844c63f6f4b29a9f6921fc3256c2674d677a Mon Sep 17 00:00:00 2001 From: "adam.hutchison" Date: Fri, 9 Nov 2018 12:52:02 -0700 Subject: [PATCH 1096/1191] Fix enum hash equality Protobuf::Enum delegates methods to Fixnum, which has a custom hash equality method (`eql?`). This causes enum values to be equivalent when using `==`, `===`, `equals?`, but not `eql?`**: 2.3.7 :002 > Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO) => false However, they are equilvalent to their tag value: 2.3.7 :002 > Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO.tag) => true Use the hash equality implementation from Object#eql?, which is equivalent to == instead. **The implementation changed in Ruby 2.5, so this only affects Ruby versions less than v2.5. --- lib/protobuf/enum.rb | 19 +++++++++++++++++++ spec/lib/protobuf/enum_spec.rb | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index a50ebc54..f9d5d4de 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -271,6 +271,25 @@ def class tag.class end + # Protobuf::Enum delegates methods to Fixnum, which has a custom hash equality method (`eql?`) + # This causes enum values to be equivalent when using `==`, `===`, `equals?`, but not `eql?`**: + # + # 2.3.7 :002 > ::Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO) + # => false + # + # However, they are equilvalent to their tag value: + # + # 2.3.7 :002 > ::Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO.tag) + # => true + # + # **The implementation changed in Ruby 2.5, so this only affects Ruby versions less than v2.4. + # + # Use the hash equality implementation from Object#eql?, which is equivalent to == instead. + # + def eql?(other) + self == other + end + def inspect "\#" end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index a2bebb8d..49b9602b 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -268,6 +268,20 @@ specify { subject.try { |yielded| expect(yielded).to eq(subject) } } end + describe '#eql?' do + it "is equal to itself" do + expect(::Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO)).to be(true) + end + + it "is equal to it's tag" do + expect(::Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO.tag)).to be(true) + end + + it "is not equal to it's name" do + expect(::Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO.name)).to be(false) + end + end + context 'when coercing from enum' do subject { Test::StatusType::PENDING } it { is_expected.to eq(0) } From 21a5dd9a586cf5712deb3790f15686e5faa503b8 Mon Sep 17 00:00:00 2001 From: "adam.hutchison" Date: Tue, 13 Nov 2018 10:21:38 -0700 Subject: [PATCH 1097/1191] Bump version to 3.8.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f3007bb4..9a70aa66 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.8.4' # rubocop:disable Style/MutableConstant + VERSION = '3.8.5' # rubocop:disable Style/MutableConstant end From c4c355c5fdd396048cd8eda2005c1ef05a625ef0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Dec 2018 12:24:05 -0700 Subject: [PATCH 1098/1191] adding new encoders with java protobuf helpers --- lib/protobuf.rb | 7 + lib/protobuf/enum.rb | 7 +- lib/protobuf/field/base_field.rb | 88 +- lib/protobuf/field/bool_field.rb | 14 +- lib/protobuf/field/integer_field.rb | 22 + lib/protobuf/field/string_field.rb | 4 + lib/protobuf/field/varint_field.rb | 55 +- .../field/varint_field_encoder_pure.rb | 48 + lib/protobuf/varint.rb | 6 + profile.html | 4497 +++++++++++++++++ protobuf.gemspec | 5 +- varint_prof.rb | 65 + 12 files changed, 4767 insertions(+), 51 deletions(-) create mode 100644 lib/protobuf/field/varint_field_encoder_pure.rb create mode 100644 profile.html create mode 100644 varint_prof.rb diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 148b1170..3f9b7e91 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -10,6 +10,13 @@ require 'active_support/json' require 'active_support/notifications' +# rubocop:disable Lint/HandleExceptions +begin + require 'protobuf_java_helpers' +rescue LoadError +end +# rubocop:enable Lint/HandleExceptions + # All top-level run time code requires, ordered by necessity require 'protobuf/wire_type' diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 6dee47b6..c38b216b 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -58,6 +58,7 @@ def self.define(name, tag) # to be incorrect; reset them @mapped_enums = @values = nil const_set(name, enum) + mapped_enums end # Internal: A mapping of enum number -> enums defined @@ -132,6 +133,10 @@ def self.enum_for_tag(tag) tag && (mapped_enums[tag.to_i] || []).first end + def self.enum_for_tag_integer(tag) + (@mapped_enums[tag] || []).first + end + # Public: Get an Enum by a variety of type-checking mechanisms. # # candidate - An Enum, Numeric, String, or Symbol object. @@ -153,7 +158,7 @@ def self.enum_for_tag(tag) # Returns an Enum object or nil. # def self.fetch(candidate) - return enum_for_tag(candidate) if candidate.is_a?(::Integer) + return enum_for_tag_integer(candidate) if candidate.is_a?(::Integer) case candidate when self diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 197ed9b4..93dbdbf6 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -58,6 +58,10 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl validate_packed_field if packed? define_accessor(simple_name, fully_qualified_name) if simple_name + set_repeated_message! + set_map! +# define_field_method! +# define_for_serialization! tag_encoded end @@ -113,12 +117,88 @@ def enum? false end +# def define_field_method! +# if repeated? +# def field?(values) +# values.key?(fully_qualified_name) && values[fully_qualified_name].present? +# end +# else +# def field?(values) +# values.key?(fully_qualified_name) +# end +# end +# end + +# def define_for_serialization! +# set_map! +# +# if map? +# if required? +# def for_serialization(values) +# value = values[fully_qualified_name] +# +# if value.nil? +# fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{name} does not have a value." +# else +# # on-the-wire, maps are represented like an array of entries where +# # each entry is a message of two fields, key and value. +# array = Array.new(value.size) +# i = 0 +# value.each do |k, v| +# array[i] = type_class.new(:key => k, :value => v) +# i += 1 +# end +# value = array +# end +# +# value +# end +# else +# def for_serialization(values) +# value = values[fully_qualified_name] +# +# unless value.nil? +# # on-the-wire, maps are represented like an array of entries where +# # each entry is a message of two fields, key and value. +# array = Array.new(value.size) +# i = 0 +# value.each do |k, v| +# array[i] = type_class.new(:key => k, :value => v) +# i += 1 +# end +# value = array +# end +# +# value +# end +# end +# else +# if required? +# def for_serialization(values) +# value = values[fully_qualified_name] +# fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{name} does not have a value." if value.nil? +# +# value +# end +# else +# def for_serialization(values) +# values[@fully_qualified_name] +# end +# end +# end +# end + def message? false end + def set_map! + set_repeated_message! + @is_map = repeated_message? && type_class.get_option!(:map_entry) + end + def map? - @is_map ||= repeated_message? && type_class.get_option(:map_entry) + @is_map end def optional? @@ -133,8 +213,12 @@ def repeated? @repeated end + def set_repeated_message! + @repeated_message = repeated? && message? + end + def repeated_message? - repeated? && message? + @repeated_message end def required? diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 6a247381..530cfed8 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -3,10 +3,14 @@ module Protobuf module Field class BoolField < VarintField + ONE = 1.freeze FALSE_ENCODE = [0].pack('C') FALSE_STRING = "false".freeze + FALSE_VALUES = [false, FALSE_STRING].freeze TRUE_ENCODE = [1].pack('C') TRUE_STRING = "true".freeze + TRUE_VALUES = [true, TRUE_STRING].freeze + ACCEPTABLES = [true, false, TRUE_STRING, FALSE_STRING].freeze ## # Class Methods @@ -21,20 +25,18 @@ def self.default # # def acceptable?(val) - val == true || val == false || val == TRUE_STRING || val == FALSE_STRING + ACCEPTABLES.include?(val) end def coerce!(val) - return true if val == true - return false if val == false - return true if val == TRUE_STRING - return false if val == FALSE_STRING + return true if TRUE_VALUES.include?(val) + return false if FALSE_VALUES.include?(val) fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end def decode(value) - value == 1 + value == ONE end def encode(value) diff --git a/lib/protobuf/field/integer_field.rb b/lib/protobuf/field/integer_field.rb index 5eb3b064..3b66ec2c 100644 --- a/lib/protobuf/field/integer_field.rb +++ b/lib/protobuf/field/integer_field.rb @@ -7,6 +7,28 @@ class IntegerField < VarintField ## # Public Instance Methods # + def acceptable?(val) + int_val = if val.is_a?(Integer) + return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path + val + elsif val.is_a?(Numeric) + val.to_i + else + Integer(val, 10) + end + + int_val >= self.class.min && int_val <= self.class.max + rescue + false + end + + def coerce!(val) + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) + return val.to_i if val.is_a?(Numeric) + Integer(val, 10) + rescue ArgumentError + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" + end def decode(value) value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 43ac0b12..354b6f1b 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -14,6 +14,10 @@ class StringField < BytesField # Public Instance Methods # + def acceptable?(val) + val.is_a?(String) || val.nil? || val.is_a?(Symbol) + end + def decode(bytes) bytes_to_decode = bytes.dup bytes_to_decode.force_encoding(::Protobuf::Field::StringField::ENCODING) diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 02a8cddc..70879c03 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -1,4 +1,5 @@ require 'protobuf/field/base_field' +require 'protobuf/field/varint_field_encoder_pure' module Protobuf module Field @@ -24,55 +25,27 @@ def self.default 0 end - # Because all tags and enums are calculated as VarInt it is "most common" to have - # values < CACHE_LIMIT (low numbers) which is defaulting to 1024 - def self.cached_varint(value) - @_varint_cache ||= {} - (@_varint_cache[value] ||= encode(value, false)).dup - end - - def self.encode(value, use_cache = true) - return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT + if defined?(::ProtobufJavaHelpers) + include ::ProtobufJavaHelpers::VarintProtobufField + extend ::ProtobufJavaHelpers::VarintProtobufField + extend ::ProtobufJavaHelpers::Varinter - bytes = [] - until value < 128 - bytes << (0x80 | (value & 0x7f)) - value >>= 7 + def self.encode(value) + to_varint(value) end - (bytes << value).pack('C*') - end + else + include ::Protobuf::Field::VarintFieldEncoderPure + extend ::Protobuf::Field::VarintFieldEncoderPure::ClassMethods - # Load the cache of VarInts on load of file - (0..CACHE_LIMIT).each do |cached_value| - cached_varint(cached_value) + # Load the cache of VarInts on load of file + (0..CACHE_LIMIT).each do |cached_value| + cached_varint(cached_value) + end end ## # Public Instance Methods # - def acceptable?(val) - int_val = if val.is_a?(Integer) - return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path - val - elsif val.is_a?(Numeric) - val.to_i - else - Integer(val, 10) - end - - int_val >= self.class.min && int_val <= self.class.max - rescue - false - end - - def coerce!(val) - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) - return val.to_i if val.is_a?(Numeric) - Integer(val, 10) - rescue ArgumentError - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" - end - def decode(value) value end diff --git a/lib/protobuf/field/varint_field_encoder_pure.rb b/lib/protobuf/field/varint_field_encoder_pure.rb new file mode 100644 index 00000000..2dba22c5 --- /dev/null +++ b/lib/protobuf/field/varint_field_encoder_pure.rb @@ -0,0 +1,48 @@ +module Protobuf + module Field + module VarintFieldEncoderPure + module ClassMethods + # Because all tags and enums are calculated as VarInt it is "most common" to have + # values < CACHE_LIMIT (low numbers) which is defaulting to 1024 + def cached_varint(value) + @_varint_cache ||= {} + (@_varint_cache[value] ||= encode(value, false)).dup + end + + def encode(value, use_cache = true) + return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT + + bytes = [] + until value < 128 + bytes << (0x80 | (value & 0x7f)) + value >>= 7 + end + (bytes << value).pack('C*') + end + end + + def acceptable?(val) + int_val = if val.is_a?(Integer) + return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path + val + elsif val.is_a?(Numeric) + val.to_i + else + Integer(val, 10) + end + + int_val >= self.class.min && int_val <= self.class.max + rescue + false + end + + def coerce!(val) + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) + return val.to_i if val.is_a?(Numeric) + Integer(val, 10) + rescue ArgumentError + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" + end + end + end +end diff --git a/lib/protobuf/varint.rb b/lib/protobuf/varint.rb index fef5e953..1012d658 100644 --- a/lib/protobuf/varint.rb +++ b/lib/protobuf/varint.rb @@ -2,6 +2,12 @@ module Protobuf class Varint if defined?(::Varint) extend ::Varint + elsif defined?(::ProtobufJavaHelpers) + extend ::ProtobufJavaHelpers::Varinter + + def self.decode(stream) + read_varint(stream) + end else extend VarintPure end diff --git a/profile.html b/profile.html new file mode 100644 index 00000000..76e05283 --- /dev/null +++ b/profile.html @@ -0,0 +1,4497 @@ + + + + + + + +

Profile Report: main

+

Total time: 23.21

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
%Total %Self Total Self Children CallsName
100%0%23.210.0023.210(top)
20.060.0020.061/1Benchmark::IPS.ips
0.940.000.942/112Kernel.require
0.920.040.881/5##times
0.810.000.816/1877Kernel.require
0.470.060.4117/19Kernel.load
0.110.000.111/468431Gem::Specification.each_gemspec
0.220.000.2219/468431Kernel.require
0.280.080.20466834/468431Protobuf::Message#each_field_for_serialization
10.000.199.811/468431Benchmark::IPS::Job#run_warmup
10.050.0010.051/468431Benchmark::IPS::Job#run_benchmark
90%1%21.030.3120.71468431##each
19.730.1619.57217694/217694Benchmark::IPS::Job::Entry#call_times
1.870.301.57933668/933668Protobuf::Field::BaseField#encode_to_stream
1.030.300.73466834/466834Protobuf::Field::StringField#encode_to_stream
0.540.430.104202197/9808248##[]
0.390.390.004201506/7002511Protobuf::Field::BaseField#fully_qualified_name
0.270.270.002801004/2801004Protobuf::Field::BaseField#required?
0.190.190.001400502/4201506Protobuf::Field::BaseField#map?
0.170.170.001400502/5602467Protobuf::Field::BaseField#repeated?
0.110.110.002801021/2801653##nil?
0.920.040.881/5(top)
20.050.0020.052/5Benchmark::IPS::Job#run
90%0%21.000.0620.945##times
10.050.0010.051/1Benchmark::IPS::Job#run_benchmark
10.000.0010.001/1Benchmark::IPS::Job#run_warmup
0.410.010.4110000/466834Protobuf::Message::Serialization::ClassMethods.decode_from
0.310.010.3010000/466834Protobuf::Encoder.encode
20.060.0020.061/1(top)
86%0%20.060.0020.061Benchmark::IPS.ips
20.050.0020.051/1Benchmark::IPS::Job#run
20.050.0020.051/1Benchmark::IPS.ips
86%0%20.050.0020.051Benchmark::IPS::Job#run
20.050.0020.052/5##times
19.730.1619.57217694/217694##each
85%0%19.730.1619.57217694Benchmark::IPS::Job::Entry#call_times
19.510.3919.12456834/457411Proc#call
19.510.3919.12456834/457411Benchmark::IPS::Job::Entry#call_times
84%1%19.540.4019.14457411Proc#call
8.540.148.41456834/466834Protobuf::Message::Serialization::ClassMethods.decode_from
6.830.146.69456834/466834Protobuf::Encoder.encode
2.400.072.33456834/935061Class#new
1.150.111.04456834/466834Test::Resource#status=
0.120.070.06456834/466834StringIO.new
10.050.0010.051/1##times
43%0%10.050.0010.051Benchmark::IPS::Job#run_benchmark
10.050.0010.051/468431##each
10.000.0010.001/1##times
43%0%10.000.0010.001Benchmark::IPS::Job#run_warmup
10.000.199.811/468431##each
0.410.010.4110000/466834##times
8.540.148.41456834/466834Proc#call
38%0%8.950.148.81466834Protobuf::Message::Serialization::ClassMethods.decode_from
8.480.138.36466834/466834Protobuf::Message::Serialization.decode_from
0.330.060.27466834/935061Class#new
8.480.138.36466834/466834Protobuf::Message::Serialization::ClassMethods.decode_from
36%0%8.480.138.36466834Protobuf::Message::Serialization.decode_from
8.360.887.47466834/466834Protobuf::Decoder.decode_each_field
8.360.887.47466834/466834Protobuf::Message::Serialization.decode_from
36%3%8.360.887.47466834Protobuf::Decoder.decode_each_field
6.570.456.131400502/1400502Protobuf::Message::Serialization.set_field_bytes
0.520.330.192801004/2801004Protobuf::Varint.decode
0.100.100.001867336/1867336StringIO#eof
0.310.010.3010000/466834##times
6.830.146.69456834/466834Proc#call
30%0%7.140.156.99466834Protobuf::Encoder.encode
6.990.186.81466834/466834Protobuf::Message#each_field_for_serialization
6.990.186.81466834/466834Protobuf::Encoder.encode
30%0%6.990.186.81466834Protobuf::Message#each_field_for_serialization
0.280.080.20466834/468431##each
6.570.456.131400502/1400502Protobuf::Decoder.decode_each_field
28%1%6.570.456.131400502Protobuf::Message::Serialization.set_field_bytes
5.540.535.011400502/1400502Protobuf::Field::BaseField#set
0.520.210.321400502/4201813Protobuf::Message::Fields::ClassMethods.get_field
1.070.270.80466834/2801004Test::Resource#status=
2.020.601.42933668/2801004##each
3.070.872.191400502/2801004Protobuf::Message#[]=
26%7%6.161.744.422801004Protobuf::Message#set_field
1.040.440.602801004/4201813Protobuf::Message::Fields::ClassMethods.get_field
0.810.290.52933668/933668Protobuf::Field::IntegerField#coerce!
0.750.190.56933668/933668Protobuf::Field::EnumField#coerce!
0.370.370.002801004/4201506Protobuf::Field::BaseField#map?
0.330.200.12933668/933668Protobuf::Field::BytesField#coerce!
0.310.310.002801004/7002511Protobuf::Field::BaseField#fully_qualified_name
0.300.300.002801004/5602467Protobuf::Field::BaseField#repeated?
0.280.280.002801004/2805760##[]=
0.120.120.002801004/4669248Kernel.class
0.110.110.002801004/4669192Kernel.nil?
5.540.535.011400502/1400502Protobuf::Message::Serialization.set_field_bytes
23%2%5.540.535.011400502Protobuf::Field::BaseField#set
3.250.193.071400502/1400502Protobuf::Message#[]=
0.920.120.80466834/466834Protobuf::Field::EnumField#decode
0.280.200.08466834/933668Protobuf::Field::IntegerField#decode
0.190.120.08466834/466834Protobuf::Field::StringField#decode
0.180.180.001400502/5602467Protobuf::Field::BaseField#repeated?
0.180.180.001400502/1400502Protobuf::Field::BaseField#name
0.230.010.231/935061Bundler::Dsl#to_definition
0.330.060.27466834/935061Protobuf::Message::Serialization::ClassMethods.decode_from
2.400.072.33456834/935061Proc#call
14%1%3.350.253.11935061Class#new
2.690.392.30933668/933668Protobuf::Message#initialize
0.230.000.221/1Bundler::Definition#initialize
3.250.193.071400502/1400502Protobuf::Field::BaseField#set
14%0%3.250.193.071400502Protobuf::Message#[]=
3.070.872.191400502/2801004Protobuf::Message#set_field
2.690.392.30933668/933668Class#new
11%1%2.690.392.30933668Protobuf::Message#initialize
2.210.192.02933668/933879##each
2.210.192.02933668/933879Protobuf::Message#initialize
9%0%2.230.202.03933879##each
2.020.601.42933668/2801004Protobuf::Message#set_field
0.370.030.352/1877Kernel.load
0.810.000.816/1877(top)
0.940.000.94112/1877Kernel.require
9%0%2.120.032.091877Kernel.require
0.790.000.791/1Bundler.setup
0.220.000.2219/468431##each
0.110.000.111/1Gem::Specification.load_defaults
1.870.301.57933668/933668##each
8%1%1.870.301.57933668Protobuf::Field::BaseField#encode_to_stream
0.610.110.49466834/466834Protobuf::Field::EnumField#encode
0.430.250.19466834/933668Protobuf::Field::IntegerField#encode
0.360.180.181867336/3267838IO::GenericWritable.<<
0.170.170.00933668/1400655Protobuf::Field::BaseField#tag_encoded
0.520.210.321400502/4201813Protobuf::Message::Serialization.set_field_bytes
1.040.440.602801004/4201813Protobuf::Message#set_field
6%2%1.570.650.924201813Protobuf::Message::Fields::ClassMethods.get_field
0.500.500.004201813/4202318Protobuf::Message::Fields::ClassMethods.field_store
0.410.410.004201813/9808248##[]
1.150.111.04456834/466834Proc#call
5%0%1.200.131.07466834Test::Resource#status=
1.070.270.80466834/2801004Protobuf::Message#set_field
0.410.410.004201813/9808248Protobuf::Message::Fields::ClassMethods.get_field
0.540.430.104202197/9808248##each
4%4%1.070.940.139808248##[]
0.110.100.012803132/2803342##default
1.030.300.73466834/466834##each
4%1%1.030.300.73466834Protobuf::Field::StringField#encode_to_stream
0.300.140.161400502/3267838IO::GenericWritable.<<
0.150.080.07466834/1400655Protobuf::Field::VarintField.encode
0.120.120.00466834/1400655Protobuf::Field::BaseField#tag_encoded
0.940.000.942/112(top)
4%0%0.940.000.94112Kernel.require
0.940.000.94112/1877Kernel.require
0.920.120.80466834/466834Protobuf::Field::BaseField#set
3%0%0.920.120.80466834Protobuf::Field::EnumField#decode
0.560.170.39466834/466834Protobuf::Field::EnumField#acceptable?
0.240.170.07466834/933668Protobuf::Field::IntegerField#decode
0.390.220.16466834/933668Protobuf::Field::EnumField#encode
0.430.250.19466834/933668Protobuf::Field::BaseField#encode_to_stream
3%2%0.820.470.35933668Protobuf::Field::IntegerField#encode
0.210.120.09933668/1400655Protobuf::Field::VarintField.encode
0.140.140.00933668/3267838##&
0.810.290.52933668/933668Protobuf::Message#set_field
3%1%0.810.290.52933668Protobuf::Field::IntegerField#coerce!
0.430.280.15933668/933668Protobuf::Field::IntegerField#acceptable?
0.790.000.791/1Kernel.require
3%0%0.790.000.791Bundler.setup
0.430.010.421/2Bundler.definition
0.360.000.361/1Bundler::Runtime#setup
0.290.110.18466834/1400502Protobuf::Field::EnumField#acceptable?
0.500.170.33933668/1400502Protobuf::Field::EnumField#coerce!
3%1%0.790.280.511400502Protobuf::Enum.fetch
0.440.280.161400502/1400502Protobuf::Enum.enum_for_tag_integer
0.750.190.56933668/933668Protobuf::Message#set_field
3%0%0.750.190.56933668Protobuf::Field::EnumField#coerce!
0.500.170.33933668/1400502Protobuf::Enum.fetch
0.310.310.002801004/7002511Protobuf::Message#set_field
0.390.390.004201506/7002511##each
3%3%0.700.700.007002511Protobuf::Field::BaseField#fully_qualified_name
0.300.140.161400502/3267838Protobuf::Field::StringField#encode_to_stream
0.360.180.181867336/3267838Protobuf::Field::BaseField#encode_to_stream
2%1%0.660.310.343267838IO::GenericWritable.<<
0.340.340.003267838/3267838StringIO#write
0.170.170.001400502/5602467##each
0.180.180.001400502/5602467Protobuf::Field::BaseField#set
0.300.300.002801004/5602467Protobuf::Message#set_field
2%2%0.650.650.005602467Protobuf::Field::BaseField#repeated?
0.610.110.49466834/466834Protobuf::Field::BaseField#encode_to_stream
2%0%0.610.110.49466834Protobuf::Field::EnumField#encode
0.390.220.16466834/933668Protobuf::Field::IntegerField#encode
0.110.070.04466834/467102Protobuf::Enum#to_i
0.190.190.001400502/4201506##each
0.370.370.002801004/4201506Protobuf::Message#set_field
2%2%0.560.560.004201506Protobuf::Field::BaseField#map?
0.560.170.39466834/466834Protobuf::Field::EnumField#decode
2%0%0.560.170.39466834Protobuf::Field::EnumField#acceptable?
0.290.110.18466834/1400502Protobuf::Enum.fetch
0.240.170.07466834/933668Protobuf::Field::EnumField#decode
0.280.200.08466834/933668Protobuf::Field::BaseField#set
2%1%0.530.380.15933668Protobuf::Field::IntegerField#decode
0.110.110.00933668/3267838##&
0.520.330.192801004/2801004Protobuf::Decoder.decode_each_field
2%1%0.520.330.192801004Protobuf::Varint.decode
0.190.190.002801004/2801004ProtobufJavaHelpers::Varinter.read_varint
0.500.500.004201813/4202318Protobuf::Message::Fields::ClassMethods.get_field
2%2%0.510.510.004202318Protobuf::Message::Fields::ClassMethods.field_store
0.470.060.4117/19(top)
2%0%0.470.060.4119Kernel.load
0.370.030.352/1877Kernel.require
0.440.280.161400502/1400502Protobuf::Enum.fetch
1%1%0.440.280.161400502Protobuf::Enum.enum_for_tag_integer
0.430.280.15933668/933668Protobuf::Field::IntegerField#coerce!
1%1%0.430.280.15933668Protobuf::Field::IntegerField#acceptable?
0.430.010.421/2Bundler.setup
1%0%0.430.010.422Bundler.definition
0.340.000.341/1Bundler::Definition.build
0.330.000.331/869Bundler::Runtime#requested_specs
1%0%0.410.000.41869Kernel.send
0.330.000.331/1Bundler::Definition#requested_specs
0.150.080.07466834/1400655Protobuf::Field::StringField#encode_to_stream
0.210.120.09933668/1400655Protobuf::Field::IntegerField#encode
1%0%0.360.200.161400655Protobuf::Field::VarintField.encode
0.160.160.001400655/1400655ProtobufJavaHelpers::Varinter.to_varint
0.360.000.361/1Bundler.setup
1%0%0.360.000.361Bundler::Runtime#setup
0.330.000.331/1Bundler::Runtime#requested_specs
0.340.340.003267838/3267838IO::GenericWritable.<<
1%1%0.340.340.003267838StringIO#write
0.340.000.341/1Bundler.definition
1%0%0.340.000.341Bundler::Definition.build
0.330.000.331/1Bundler::Dsl.evaluate
0.330.000.331/1Bundler::Runtime#setup
1%0%0.330.000.331Bundler::Runtime#requested_specs
0.330.000.331/869Kernel.send
0.330.000.331/1Kernel.send
1%0%0.330.000.331Bundler::Definition#requested_specs
0.330.000.331/1Bundler::Definition#specs_for
0.330.000.331/1Bundler::Definition#requested_specs
1%0%0.330.000.331Bundler::Definition#specs_for
0.320.000.321/1Bundler::Definition#specs
0.330.000.331/1Bundler::Definition.build
1%0%0.330.000.331Bundler::Dsl.evaluate
0.230.000.231/1Bundler::Dsl#to_definition
0.330.200.12933668/933668Protobuf::Message#set_field
1%0%0.330.200.12933668Protobuf::Field::BytesField#coerce!
0.320.000.321/1Bundler::Definition#specs_for
1%0%0.320.000.321Bundler::Definition#specs
0.220.000.221/1Bundler::SpecSet#materialize
0.110.110.00933668/3267838Protobuf::Field::IntegerField#decode
0.140.140.00933668/3267838Protobuf::Field::IntegerField#encode
1%1%0.310.310.003267838##&
0.120.120.00466834/1400655Protobuf::Field::StringField#encode_to_stream
0.170.170.00933668/1400655Protobuf::Field::BaseField#encode_to_stream
1%1%0.300.300.001400655Protobuf::Field::BaseField#tag_encoded
0.280.280.002801004/2805760Protobuf::Message#set_field
1%1%0.290.280.012805760##[]=
0.270.270.002801004/2801004##each
1%1%0.270.270.002801004Protobuf::Field::BaseField#required?
0.230.000.231/1Bundler::Dsl.evaluate
1%0%0.230.000.231Bundler::Dsl#to_definition
0.230.010.231/935061Class#new
0.230.000.221/1Class#new
0%0%0.230.000.221Bundler::Definition#initialize
0.180.000.181/389Bundler::SpecSet#materialize
0%0%0.220.020.20389##map!
0.180.000.1838/38Bundler::LazySpecification#__materialize__
0.220.000.221/1Bundler::Definition#specs
0%0%0.220.000.221Bundler::SpecSet#materialize
0.180.000.181/389##map!
0.120.120.002801004/4669248Protobuf::Message#set_field
0%0%0.200.200.004669248Kernel.class
0.190.120.08466834/466834Protobuf::Field::BaseField#set
0%0%0.190.120.08466834Protobuf::Field::StringField#decode
0.190.190.002801004/2801004Protobuf::Varint.decode
0%0%0.190.190.002801004ProtobufJavaHelpers::Varinter.read_varint
0.110.110.002801004/4669192Protobuf::Message#set_field
0%0%0.190.190.004669192Kernel.nil?
0.180.000.1838/38##map!
0%0%0.180.000.1838Bundler::LazySpecification#__materialize__
0.150.000.1537/37Bundler::Source::Rubygems#specs
0.180.180.001400502/1400502Protobuf::Field::BaseField#set
0%0%0.180.180.001400502Protobuf::Field::BaseField#name
0%0%0.180.180.003269205Kernel.kind_of?
0.160.160.001400655/1400655Protobuf::Field::VarintField.encode
0%0%0.160.160.001400655ProtobufJavaHelpers::Varinter.to_varint
0.120.000.123/285Gem::Specification.gemspec_stubs_in
0%0%0.160.020.14285##select
0.120.000.1267/67Gem::StubSpecification#valid?
0.150.000.151/2Bundler::Source::Rubygems#installed_specs
0%0%0.160.000.152Bundler::Index.build
0.140.000.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0.150.000.1537/37Bundler::LazySpecification#__materialize__
0%0%0.150.000.1537Bundler::Source::Rubygems#specs
0.150.000.151/1Bundler::Source::Rubygems#installed_specs
0.150.000.151/1Bundler::Source::Rubygems#specs
0%0%0.150.000.151Bundler::Source::Rubygems#installed_specs
0.150.000.151/2Bundler::Index.build
0.140.000.141/1Bundler::Index.build
0%0%0.140.000.141Bundler::RubygemsIntegration::MoreFuture#all_specs
0.140.000.141/1Gem::Specification.stubs
0.140.000.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0%0%0.140.000.141Gem::Specification.stubs
0.120.070.06456834/466834Proc#call
0%0%0.130.070.06466834StringIO.new
0%0%0.130.000.133Gem::Specification.gemspec_stubs_in
0.120.000.123/285##select
0%0%0.120.030.0960Kernel.eval
0.120.000.1167/1199Gem::StubSpecification#valid?
0%0%0.120.000.111199Gem::StubSpecification#data
0.110.010.1167/67Kernel.open
0%0%0.120.120.001400529Protobuf::Field::BaseField#type_class
0.120.000.1267/67##select
0%0%0.120.000.1267Gem::StubSpecification#valid?
0.120.000.1167/1199Gem::StubSpecification#data
0.110.010.1167/67Gem::StubSpecification#data
0%0%0.110.010.1167Kernel.open
0.110.100.012803132/2803342##[]
0%0%0.110.100.012803342##default
0.110.110.002801021/2801653##each
0%0%0.110.110.002801653##nil?
0.110.000.111/1Kernel.require
0%0%0.110.000.111Gem::Specification.load_defaults
0.110.000.111/1Gem::Specification.each_spec
0.110.070.04466834/467102Protobuf::Field::EnumField#encode
0%0%0.110.070.04467102Protobuf::Enum#to_i
0.110.000.111/1Gem::Specification.load_defaults
0%0%0.110.000.111Gem::Specification.each_spec
0.110.000.111/1Gem::Specification.each_gemspec
0.110.000.111/1Gem::Specification.each_spec
0%0%0.110.000.111Gem::Specification.each_gemspec
0.110.000.111/468431##each
0%0%0.100.070.04467605BasicObject#!=
0.100.100.001867336/1867336Protobuf::Decoder.decode_each_field
0%0%0.100.100.001867336StringIO#eof
+ + diff --git a/protobuf.gemspec b/protobuf.gemspec index 624a43eb..4e20358a 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -26,6 +26,7 @@ require "protobuf/version" s.add_dependency 'thor' s.add_dependency 'thread_safe' + s.add_development_dependency 'benchmark-ips' s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses s.add_development_dependency 'rspec', '>= 3.0' @@ -49,7 +50,9 @@ require "protobuf/version" s.add_development_dependency 'varint' s.add_development_dependency 'ruby-prof' - else + elsif RUBY_PLATFORM =~ /java/i + s.add_development_dependency 'protobuf_java_helpers' + s.add_development_dependency 'fast_blank_java' s.add_development_dependency 'pry' end end diff --git a/varint_prof.rb b/varint_prof.rb new file mode 100644 index 00000000..7c864dc4 --- /dev/null +++ b/varint_prof.rb @@ -0,0 +1,65 @@ +require 'base64' +require 'benchmark/ips' +require 'pry' +require "./spec/support/protos/resource.pb" +#require "jruby/profiler/flame_graph_profile_printer" + +VALUES = { + 0 => "AA==", + 5 => "BQ==", + 51 => "Mw==", + 9_192 => "6Ec=", + 80_389 => "hfQE", + 913_389 => "7d83", + 516_192_829_912_693 => "9eyMkpivdQ==", + 9_999_999_999_999_999_999 => "//+fz8jgyOOKAQ==", +}.freeze + +#DECODEME = ::Derp.encode_cache_hash(2576) +#DECODEME2 = ::Derp.encode_cache_hash(25763111) + +10_000.times do + t = ::Test::Resource.new(:name => "derp", :date_created => 123456789) + t.status = 3 + ss = StringIO.new + ::Protobuf::Encoder.encode(t.to_proto, ss) + ss.rewind + t2 = ::Test::Resource.decode_from(ss) +end + +if ENV["FLAME"] + result = JRuby::Profiler.profile do + 1_000_000.times do + t = ::Test::Resource.new(:name => "derp", :date_created => 123456789) + t.status = 3 + ss = StringIO.new + ::Protobuf::Encoder.encode(t.to_proto, ss) + ss.rewind + t2 = ::Test::Resource.decode_from(ss) + #fail "derp" unless t == t2 + + #t = ::Test::Resource.new(:name => "derp", :date_created => 123456789) + #t.field?(:name) + #t.field?(:date_created) + #t.field?(:derp_derp) + #t.respond_to_has_and_present?(:name) + #t.respond_to_has_and_present?(:date_created) + #t.respond_to_has_and_present?(:derp_derp) + end + end + + printer = JRuby::Profiler::FlameGraphProfilePrinter.new(result) + printer.printProfile(STDOUT) +else + Benchmark.ips do |x| + x.config(:time => 10, :warmup => 10) + x.report("to_proto => true java") do + t = ::Test::Resource.new(:name => "derp", :date_created => 123456789) + t.status = 3 + ss = StringIO.new + ::Protobuf::Encoder.encode(t.to_proto, ss) + ss.rewind + t2 = ::Test::Resource.decode_from(ss) + end + end +end From 98fd53750b129e5da86615e05745204b562c1976 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Dec 2018 12:25:26 -0700 Subject: [PATCH 1099/1191] remove repeated_map with meta --- lib/protobuf/field/base_field.rb | 109 ++++++++--- .../field/base_field_method_definitions.rb | 179 ++++++++++++++++++ lib/protobuf/field/string_field.rb | 6 +- lib/protobuf/message/serialization.rb | 3 +- 4 files changed, 268 insertions(+), 29 deletions(-) create mode 100644 lib/protobuf/field/base_field_method_definitions.rb diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 197ed9b4..9c29e301 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,6 +1,7 @@ require 'active_support/core_ext/hash/slice' require 'protobuf/field/field_array' require 'protobuf/field/field_hash' +require 'protobuf/field/base_field_method_definitions' module Protobuf module Field @@ -58,6 +59,12 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl validate_packed_field if packed? define_accessor(simple_name, fully_qualified_name) if simple_name + define_hash_accessor_for_message! + define_field_p! + define_field_and_present_p! + define_set_field! + define_set_method! + set_default_value! tag_encoded end @@ -81,7 +88,7 @@ def default options[:default] end - def default_value + def set_default_value! @default_value ||= if optional? || required? typed_default_value elsif map? @@ -93,6 +100,46 @@ def default_value end end + def default_value + @default_value + end + + def define_field_p! + if repeated? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_field_p!(self) + else + ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_field_p!(self) + end + end + + def define_field_and_present_p! + if type_class == ::Protobuf::Field::BoolField # boolean present check + ::Protobuf::Field::BaseFieldMethodDefinitions.define_bool_field_and_present_p!(self) + else + ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_field_and_present_p!(self) + end + end + + def define_hash_accessor_for_message! + if map? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_value_from_values!(self) + elsif repeated? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_value_from_values!(self) + else + ::Protobuf::Field::BaseFieldMethodDefinitions.define_field_value_from_values!(self) + end + end + + def define_set_field! + if map? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_set_field!(self) + elsif repeated? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_set_field!(self) + else + ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_set_field!(self) + end + end + def deprecated? @deprecated end @@ -118,7 +165,7 @@ def message? end def map? - @is_map ||= repeated_message? && type_class.get_option(:map_entry) + @is_map ||= repeated_message? && type_class.get_option!(:map_entry) end def optional? @@ -141,33 +188,45 @@ def required? @required end - # FIXME: need to cleanup (rename) this warthog of a method. - def set(message_instance, bytes) - return message_instance[name] = decode(bytes) unless repeated? - + def define_set_method! if map? - hash = message_instance[name] - entry = decode(bytes) - # decoded value could be nil for an - # enum value that is not recognized - hash[entry.key] = entry.value unless entry.value.nil? - return hash[entry.key] - end - - return message_instance[name] << decode(bytes) unless packed? - - array = message_instance[name] - stream = StringIO.new(bytes) - - if wire_type == ::Protobuf::WireType::VARINT - array << decode(Varint.decode(stream)) until stream.eof? - elsif wire_type == ::Protobuf::WireType::FIXED64 - array << decode(stream.read(8)) until stream.eof? - elsif wire_type == ::Protobuf::WireType::FIXED32 - array << decode(stream.read(4)) until stream.eof? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_set_method!(self) + elsif repeated? && packed? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_packed_set_method!(self) + elsif repeated? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_not_packed_set_method!(self) + else + ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_set_method!(self) end end +# # FIXME: need to cleanup (rename) this warthog of a method. +# def set(message_instance, bytes) +# return message_instance.set_field(name, decode(bytes), true, self) unless repeated? +# +# if map? +# hash = message_instance[name] +# entry = decode(bytes) +# # decoded value could be nil for an +# # enum value that is not recognized +# hash[entry.key] = entry.value unless entry.value.nil? +# return hash[entry.key] +# end +# +# return message_instance[name] << decode(bytes) unless packed? +# +# array = message_instance[name] +# stream = StringIO.new(bytes) +# +# if wire_type == ::Protobuf::WireType::VARINT +# array << decode(Varint.decode(stream)) until stream.eof? +# elsif wire_type == ::Protobuf::WireType::FIXED64 +# array << decode(stream.read(8)) until stream.eof? +# elsif wire_type == ::Protobuf::WireType::FIXED32 +# array << decode(stream.read(4)) until stream.eof? +# end +# end + def tag_encoded @tag_encoded ||= begin case diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb new file mode 100644 index 00000000..62a0963d --- /dev/null +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -0,0 +1,179 @@ +module Protobuf + module Field + class BaseFieldMethodDefinitions + + def self.fully_qualified_name_string(selph) + fully_qualified_name = "" + fully_qualified_name << ":" + fully_qualified_name << '"' if selph.fully_qualified_name.to_s.start_with?(".") + fully_qualified_name << selph.fully_qualified_name.to_s + fully_qualified_name << '"' if selph.fully_qualified_name.to_s.start_with?(".") + fully_qualified_name + end + + def self.define_base_set_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set(message_instance, bytes) + message_instance.set_field(name, decode(bytes), true, self) + end + RUBY + end + + def self.define_map_set_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set(message_instance, bytes) + hash = message_instance[name] + entry = decode(bytes) + # decoded value could be nil for an + # enum value that is not recognized + hash[entry.key] = entry.value unless entry.value.nil? + hash[entry.key] + end + RUBY + end + + def self.define_repeated_not_packed_set_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set(message_instance, bytes) + message_instance[name] << decode(bytes) + end + RUBY + end + + def self.define_repeated_packed_set_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set(message_instance, bytes) + array = message_instance[name] + stream = ::StringIO.new(bytes) + + if wire_type == ::Protobuf::WireType::VARINT + array << decode(Varint.decode(stream)) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED64 + array << decode(stream.read(8)) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED32 + array << decode(stream.read(4)) until stream.eof? + end + end + RUBY + end + + def self.define_map_set_field!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated) + unless value.is_a?(Hash) + fail TypeError, <<-TYPE_ERROR + Expected map value + Got '#{value.class}' for map protobuf field #{selph.name} + TYPE_ERROR + end + + if value.empty? + values.delete(#{fully_qualified_name_string(selph)}) + else + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) + values[#{fully_qualified_name_string(selph)}].replace(value) + end + end + RUBY + end + + def self.define_repeated_set_field!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated) + if value.nil? && ignore_nil_for_repeated + ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") + return + end + + unless value.is_a?(Array) + fail TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{selph.type_class}' + Got '\#{value.class}' for repeated protobuf field #{selph.name} + TYPE_ERROR + end + + value = value.compact + + if value.empty? + values.delete(#{fully_qualified_name_string(selph)}) + else + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) + values[#{fully_qualified_name_string(selph)}].replace(value) + end + end + RUBY + end + + def self.define_base_set_field!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated) + if value.nil? + values.delete(#{fully_qualified_name_string(selph)}) + else + values[#{fully_qualified_name_string(selph)}] = coerce!(value) + end + end + RUBY + end + + def self.define_base_field_and_present_p!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def field_and_present?(values) + values[#{fully_qualified_name_string(selph)}].present? + end + RUBY + end + + def self.define_bool_field_and_present_p!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + BOOL_VALUES = [true, false].freeze unless defined?(BOOL_VALUES) + + def field_and_present?(values) + BOOL_VALUES.include?(values[#{fully_qualified_name_string(selph)}]) + end + RUBY + end + + def self.define_base_field_p!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def field?(values) + values.key?(#{fully_qualified_name_string(selph)}) + end + RUBY + end + + def self.define_repeated_field_p!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def field?(values) + values.key?(#{fully_qualified_name_string(selph)}) && values[#{fully_qualified_name_string(selph)}].present? + end + RUBY + end + + def self.define_field_value_from_values!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def value_from_values(values) + values.fetch(#{fully_qualified_name_string(selph)}) { default_value } + end + RUBY + end + + def self.define_map_value_from_values!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def value_from_values(values) + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) + end + RUBY + end + + def self.define_repeated_value_from_values!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def value_from_values(values) + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) + end + RUBY + end + + end + end +end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 43ac0b12..ad0bc553 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -15,13 +15,13 @@ class StringField < BytesField # def decode(bytes) - bytes_to_decode = bytes.dup + bytes_to_decode = "" + bytes bytes_to_decode.force_encoding(::Protobuf::Field::StringField::ENCODING) bytes_to_decode end def encode(value) - value_to_encode = value.dup + value_to_encode = "" + value # dup is slower value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) @@ -30,7 +30,7 @@ def encode(value) def encode_to_stream(value, stream) if value.encoding != ::Protobuf::Field::StringField::ENCODING - value = value.dup + value = "" + value value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") end diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index de6aa40d..246168de 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -76,7 +76,8 @@ def encode_to(stream) private def set_field_bytes(tag, bytes) - field = self.class.get_field(tag, true) + #field = self.class.get_field(tag, true) + field = _protobuf_message_field[tag] field.set(self, bytes) if field end From 66df35b0773d725f3ea4f743861a108ab87998c7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Dec 2018 12:29:22 -0700 Subject: [PATCH 1100/1191] more message changes --- lib/protobuf/message.rb | 95 +++++++++++------------------------------ protobuf.gemspec | 1 + 2 files changed, 26 insertions(+), 70 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 859864fd..429b8574 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -23,6 +23,15 @@ class Message include ::Protobuf::Message::Serialization ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::MessageOptions } + def self.inherited(subclass) + subclass.const_set("PROTOBUF_MESSAGE_GET_FIELD", subclass.field_store) + subclass.class_eval <<~RUBY, __FILE__, __LINE__ + def _protobuf_message_field + PROTOBUF_MESSAGE_GET_FIELD + end + RUBY + end + ## # Class Methods # @@ -103,14 +112,10 @@ def each_field_for_serialization end def field?(name) - field = self.class.get_field(name, true) - return false if field.nil? - if field.repeated? - @values.key?(field.fully_qualified_name) && @values[field.fully_qualified_name].present? - else - @values.key?(field.fully_qualified_name) - end + field = _protobuf_message_field[name] + field && field.field?(@values) end + alias :respond_to_has? field? ::Protobuf.deprecator.define_deprecated_methods(self, :has_field? => :field?) def inspect @@ -121,13 +126,9 @@ def inspect "#<#{self.class} #{attrs}>" end - def respond_to_has?(key) - respond_to?(key) && field?(key) - end - def respond_to_has_and_present?(key) - respond_to_has?(key) && - (self[key].present? || [true, false].include?(self[key])) + field = _protobuf_message_field[key] + field && field.field_and_present?(@values) end # Return a hash-representation of the given fields for this message type. @@ -136,7 +137,7 @@ def to_hash @values.each_key do |field_name| value = self[field_name] - field = self.class.get_field(field_name, true) + field = _protobuf_message_field[field_name] hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value result[field.name] = hashed_value end @@ -186,11 +187,8 @@ def ==(other) end def [](name) - field = self.class.get_field(name, true) - - return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(field) if field.map? - return @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) if field.repeated? - @values.fetch(field.fully_qualified_name, field.default_value) + field = _protobuf_message_field[name] + field.value_from_values(@values) rescue # not having a field should be the exceptional state raise if field fail ArgumentError, "invalid field name=#{name.inspect}" @@ -200,6 +198,14 @@ def []=(name, value) set_field(name, value, true) end + def set_field(name, value, ignore_nil_for_repeated, field = nil) + if (field || field = _protobuf_message_field[name]) + field.set_field(@values, value, ignore_nil_for_repeated) + else + fail(::Protobuf::FieldNotDefinedError, name) unless ::Protobuf.ignore_unknown_fields? + end + end + ## # Instance Aliases # @@ -222,57 +228,6 @@ def []=(name, value) private - # rubocop:disable Metrics/MethodLength - def set_field(name, value, ignore_nil_for_repeated) - if (field = self.class.get_field(name, true)) - if field.map? - unless value.is_a?(Hash) - fail TypeError, <<-TYPE_ERROR - Expected map value - Got '#{value.class}' for map protobuf field #{field.name} - TYPE_ERROR - end - - if value.empty? - @values.delete(field.fully_qualified_name) - else - @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(field) - @values[field.fully_qualified_name].replace(value) - end - elsif field.repeated? - if value.nil? && ignore_nil_for_repeated - ::Protobuf.deprecator.deprecation_warning("#{self.class}#[#{name}]=nil", "use an empty array instead of nil") - return - end - unless value.is_a?(Array) - fail TypeError, <<-TYPE_ERROR - Expected repeated value of type '#{field.type_class}' - Got '#{value.class}' for repeated protobuf field #{field.name} - TYPE_ERROR - end - - value = value.compact - - if value.empty? - @values.delete(field.fully_qualified_name) - else - @values[field.fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(field) - @values[field.fully_qualified_name].replace(value) - end - else - if value.nil? # rubocop:disable Style/IfInsideElse - @values.delete(field.fully_qualified_name) - else - @values[field.fully_qualified_name] = field.coerce!(value) - end - end - else - unless ::Protobuf.ignore_unknown_fields? - fail ::Protobuf::FieldNotDefinedError, name - end - end - end - def copy_to(object, method) duplicate = proc do |obj| case obj diff --git a/protobuf.gemspec b/protobuf.gemspec index 624a43eb..48719ed4 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -26,6 +26,7 @@ require "protobuf/version" s.add_dependency 'thor' s.add_dependency 'thread_safe' + s.add_development_dependency 'benchmark-ips' s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses s.add_development_dependency 'rspec', '>= 3.0' From f3c5599e651a3dabad1c89bcc7de3bc097613d42 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Dec 2018 12:36:02 -0700 Subject: [PATCH 1101/1191] add to_hash benchmark --- varint_prof.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/varint_prof.rb b/varint_prof.rb index 7c864dc4..79a2177a 100644 --- a/varint_prof.rb +++ b/varint_prof.rb @@ -51,8 +51,13 @@ printer = JRuby::Profiler::FlameGraphProfilePrinter.new(result) printer.printProfile(STDOUT) else + TO_HASH = ::Test::Resource.new(:name => "derp", :date_created => 123456789) Benchmark.ips do |x| x.config(:time => 10, :warmup => 10) + x.report("to_hash => true java") do + TO_HASH.to_hash + end + x.report("to_proto => true java") do t = ::Test::Resource.new(:name => "derp", :date_created => 123456789) t.status = 3 From 0a07915560c9293bde5277e30dce2be99c4f50a4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Dec 2018 12:41:15 -0700 Subject: [PATCH 1102/1191] remove extra field access in hash methods --- lib/protobuf/message.rb | 2 +- varint_prof.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 429b8574..c06e36e6 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -136,8 +136,8 @@ def to_hash result = {} @values.each_key do |field_name| - value = self[field_name] field = _protobuf_message_field[field_name] + value = field.value_from_values(@values) hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value result[field.name] = hashed_value end diff --git a/varint_prof.rb b/varint_prof.rb index 79a2177a..056a1d96 100644 --- a/varint_prof.rb +++ b/varint_prof.rb @@ -53,7 +53,7 @@ else TO_HASH = ::Test::Resource.new(:name => "derp", :date_created => 123456789) Benchmark.ips do |x| - x.config(:time => 10, :warmup => 10) + x.config(:time => 20, :warmup => 10) x.report("to_hash => true java") do TO_HASH.to_hash end From 8ef1eecd2b087353a8681e93482c352577548b58 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 24 Dec 2018 19:55:48 -0700 Subject: [PATCH 1103/1191] add methods for required field tracking --- .../field/base_field_method_definitions.rb | 168 +++++++++++++----- lib/protobuf/message.rb | 32 ++-- lib/protobuf/message/fields.rb | 5 + 3 files changed, 141 insertions(+), 64 deletions(-) diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 62a0963d..011dfaec 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -14,7 +14,7 @@ def self.fully_qualified_name_string(selph) def self.define_base_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - message_instance.set_field(name, decode(bytes), true, self) + message_instance.set_field("#{selph.name}", decode(bytes), true, self) end RUBY end @@ -22,7 +22,7 @@ def set(message_instance, bytes) def self.define_map_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - hash = message_instance[name] + hash = message_instance["#{selph.name}"] entry = decode(bytes) # decoded value could be nil for an # enum value that is not recognized @@ -35,7 +35,7 @@ def set(message_instance, bytes) def self.define_repeated_not_packed_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - message_instance[name] << decode(bytes) + message_instance["#{selph.name}"] << decode(bytes) end RUBY end @@ -43,7 +43,7 @@ def set(message_instance, bytes) def self.define_repeated_packed_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - array = message_instance[name] + array = message_instance["#{selph.name}"] stream = ::StringIO.new(bytes) if wire_type == ::Protobuf::WireType::VARINT @@ -58,62 +58,127 @@ def set(message_instance, bytes) end def self.define_map_set_field!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated) - unless value.is_a?(Hash) - fail TypeError, <<-TYPE_ERROR - Expected map value - Got '#{value.class}' for map protobuf field #{selph.name} - TYPE_ERROR + if selph.required? + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + unless value.is_a?(Hash) + fail TypeError, <<-TYPE_ERROR + Expected map value + Got '#{value.class}' for map protobuf field #{selph.name} + TYPE_ERROR + end + + if value.empty? + values.delete(#{fully_qualified_name_string(selph)}) + message_instance._protobuf_message_required_field_tags << #{selph.tag} + else + message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) + values[#{fully_qualified_name_string(selph)}].replace(value) + end end + RUBY + else + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + unless value.is_a?(Hash) + fail TypeError, <<-TYPE_ERROR + Expected map value + Got '#{value.class}' for map protobuf field #{selph.name} + TYPE_ERROR + end - if value.empty? - values.delete(#{fully_qualified_name_string(selph)}) - else - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) - values[#{fully_qualified_name_string(selph)}].replace(value) + if value.empty? + values.delete(#{fully_qualified_name_string(selph)}) + else + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) + values[#{fully_qualified_name_string(selph)}].replace(value) + end end - end - RUBY + RUBY + end end def self.define_repeated_set_field!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated) - if value.nil? && ignore_nil_for_repeated - ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") - return - end + if selph.required? + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? && ignore_nil_for_repeated + ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") + return + end + + unless value.is_a?(Array) + fail TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{selph.type_class}' + Got '\#{value.class}' for repeated protobuf field #{selph.name} + TYPE_ERROR + end + + value = value.compact - unless value.is_a?(Array) - fail TypeError, <<-TYPE_ERROR - Expected repeated value of type '#{selph.type_class}' - Got '\#{value.class}' for repeated protobuf field #{selph.name} - TYPE_ERROR + if value.empty? + values.delete(#{fully_qualified_name_string(selph)}) + message_instance._protobuf_message_required_field_tags << #{selph.tag} + else + message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) + values[#{fully_qualified_name_string(selph)}].replace(value) + end end + RUBY + else + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? && ignore_nil_for_repeated + ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") + return + end - value = value.compact + unless value.is_a?(Array) + fail TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{selph.type_class}' + Got '\#{value.class}' for repeated protobuf field #{selph.name} + TYPE_ERROR + end - if value.empty? - values.delete(#{fully_qualified_name_string(selph)}) - else - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) - values[#{fully_qualified_name_string(selph)}].replace(value) + value = value.compact + + if value.empty? + values.delete(#{fully_qualified_name_string(selph)}) + else + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) + values[#{fully_qualified_name_string(selph)}].replace(value) + end end - end - RUBY + RUBY + end end def self.define_base_set_field!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated) - if value.nil? - values.delete(#{fully_qualified_name_string(selph)}) - else - values[#{fully_qualified_name_string(selph)}] = coerce!(value) + if selph.required? + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? + values.delete(#{fully_qualified_name_string(selph)}) + message_instance._protobuf_message_required_field_tags << #{selph.tag} + else + message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + values[#{fully_qualified_name_string(selph)}] = coerce!(value) + end end - end - RUBY + RUBY + else + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? + values.delete(#{fully_qualified_name_string(selph)}) + else + values[#{fully_qualified_name_string(selph)}] = coerce!(value) + end + end + RUBY + end end def self.define_base_field_and_present_p!(selph) @@ -155,6 +220,7 @@ def self.define_field_value_from_values!(selph) def value_from_values(values) values.fetch(#{fully_qualified_name_string(selph)}) { default_value } end + alias :value_from_values_for_serialization value_from_values RUBY end @@ -163,6 +229,17 @@ def self.define_map_value_from_values!(selph) def value_from_values(values) values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) end + + def value_from_values_for_serialization(values) + value = value_from_values(values) + + array = Array.new(value.size) + value.each do |k, v| + array << type_class.new(:key => k, :value => v) + end + + array + end RUBY end @@ -171,6 +248,7 @@ def self.define_repeated_value_from_values!(selph) def value_from_values(values) values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) end + alias :value_from_values_for_serialization value_from_values RUBY end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c06e36e6..e08706ca 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -24,11 +24,16 @@ class Message ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::MessageOptions } def self.inherited(subclass) + subclass.const_set("PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS", subclass.required_field_tags) subclass.const_set("PROTOBUF_MESSAGE_GET_FIELD", subclass.field_store) subclass.class_eval <<~RUBY, __FILE__, __LINE__ def _protobuf_message_field PROTOBUF_MESSAGE_GET_FIELD end + + def _protobuf_message_required_field_tags + @_protobuf_message_required_field_tags ||= PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS.dup + end RUBY end @@ -89,25 +94,14 @@ def each_field end def each_field_for_serialization - self.class.all_fields.each do |field| - value = @values[field.fully_qualified_name] - if value.nil? - fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if field.required? - next - end - if field.map? - # on-the-wire, maps are represented like an array of entries where - # each entry is a message of two fields, key and value. - array = Array.new(value.size) - i = 0 - value.each do |k, v| - array[i] = field.type_class.new(:key => k, :value => v) - i += 1 - end - value = array - end + _protobuf_message_required_field_tags.each do |tag| + field = _protobuf_message_field[tag] + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." + end - yield(field, value) + @values.each_key do |fully_qualified_name| + field = _protobuf_message_field[fully_qualified_name] + yield(field, field.value_from_values_for_serialization(@values)) end end @@ -200,7 +194,7 @@ def []=(name, value) def set_field(name, value, ignore_nil_for_repeated, field = nil) if (field || field = _protobuf_message_field[name]) - field.set_field(@values, value, ignore_nil_for_repeated) + field.set_field(@values, value, ignore_nil_for_repeated, self) else fail(::Protobuf::FieldNotDefinedError, name) unless ::Protobuf.ignore_unknown_fields? end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 6f5617a3..268851a8 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -41,6 +41,7 @@ def repeated(type_class, name, tag, options = {}) # Define a required field. # def required(type_class, name, tag, options = {}) + required_field_tags << tag define_field(:required, type_class, name, tag, options) end @@ -78,6 +79,10 @@ def extension_ranges @extension_ranges ||= [] end + def required_field_tags + @required_field_tags ||= [] + end + def extension_tag?(tag) tag.respond_to?(:to_i) && get_extension_field(tag).present? end From a71557a433e4a0b8b3b4bbb10dda59d43178d0a5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 25 Dec 2018 18:04:03 -0700 Subject: [PATCH 1104/1191] add encode to stream to to field --- lib/protobuf/encoder.rb | 13 +- lib/protobuf/field/base_field.rb | 15 +- .../field/base_field_method_definitions.rb | 27 + profile.html | 7947 +++++++++++------ 4 files changed, 5315 insertions(+), 2687 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 5591ed4c..33e2d8ad 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -2,18 +2,7 @@ module Protobuf class Encoder def self.encode(message, stream) message.each_field_for_serialization do |field, value| - if field.repeated? - if field.packed? - packed_value = value.map { |val| field.encode(val) }.join - stream << "#{field.tag_encoded}#{::Protobuf::Field::VarintField.encode(packed_value.size)}#{packed_value}" - else - value.each do |val| - field.encode_to_stream(val, stream) - end - end - else - field.encode_to_stream(value, stream) - end + field.encode_to_stream(value, stream) end stream diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d34eb612..74925ccb 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -66,6 +66,7 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl define_field_and_present_p! define_set_field! define_set_method! + define_encode_to_stream! set_default_value! tag_encoded end @@ -106,6 +107,16 @@ def default_value @default_value end + def define_encode_to_stream! + if repeated? && packed? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_packed_encode_to_stream_method!(self) + elsif repeated? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_not_packed_encode_to_stream_method!(self) + else + ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_encode_to_stream_method!(self) + end + end + def define_field_p! if repeated? ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_field_p!(self) @@ -150,10 +161,6 @@ def encode(_value) fail NotImplementedError, "#{self.class.name}##{__method__}" end - def encode_to_stream(value, stream) - stream << tag_encoded << encode(value) - end - def extension? @extension end diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 011dfaec..d674fdb5 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -11,6 +11,33 @@ def self.fully_qualified_name_string(selph) fully_qualified_name end + def self.define_base_encode_to_stream_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def encode_to_stream(value, stream) + stream << tag_encoded << encode(value) + end + RUBY + end + + def self.define_repeated_not_packed_encode_to_stream_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def encode_to_stream(value, stream) + value.each do |val| + stream << tag_encoded << encode(val) + end + end + RUBY + end + + def self.define_repeated_packed_encode_to_stream_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def encode_to_stream(value, stream) + packed_value = value.map { |val| encode(val) }.join + stream << "\#{tag_encoded}\#{::Protobuf::Field::VarintField.encode(packed_value.size)}\#{packed_value}" + end + RUBY + end + def self.define_base_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) diff --git a/profile.html b/profile.html index 76e05283..1d9dd45a 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 23.21

+

Total time: 70.11

@@ -67,1677 +67,2113 @@

Total time: 23.21

- + - + - + - + - + - + - - - - - + + + + + - + - - - - - + + + + + - + - + - - + + - + - - - - + + + + - - - - - - - - - - + - - - - + + + + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + - + - - + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - + - - + + + - + - - - - - + + + + + - + - - - + + + - + - - + - - + + + - + - - - - - + + + + + - - - - - - + + + + + - - - - - + + + + + - - - - - - - + + + + + + + + + + + + + + + + - + - + + + + + + + + + + - - - + + + - + - + - + - + - + - + - - - + + + - + - + + + + + + + + + + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - - + + + + + + - + - - - - + + + + - + + + + + + + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - + + + + + + + + + + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - - - - - + + + + + - + - - - - - + + + + + + + + + + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - + + - - + - - - - - + + + + + + - - - - + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + + + + + + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - + - - - + + + - + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - - - - - - + - - + + - + - - - - - + + + + + - + - - + + - - + + - + + - - - - - + + + + + - + + - - - - + + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - + + + + + + + + + + - - + + + + + + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + + + + + + + + + + - - + + - + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + + - - - + + - - + - - - - - - - - - - - - + + + - + + - - - - - + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - + + - + - - + + - - - - + + + + - + - + - + - + - + + + + + + + + + + - - - + + + - + - + - + - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - - + + + + + + + + + + - - - - - + + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - + - - + - - - - - - - - - - - - + + + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - + + - - + + - - + + - - - + + - - - - + + + + + - - - + + - + - + - - - + + + - - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - - + + + + + + + + + + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - + + + + + + + + + + + + + - + - - + + - - + + - + - - - - - + + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - - - - + + + + + - - - - - - + + + + + + - + - - + + + + + + + + + + - - + + + - + - + + - - - + + - - + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - - + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + + - - + - - + + + - - + + + + + + + + + + - - + - - + + + - + - - - - - + + + + + + - - - - + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1746,1135 +2182,3251 @@

Total time: 23.21

- - + + - - + + - - + + + + + + + + + + + - - + + - - + + - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + - - - - - + + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - + - - + + + - + - - - - + + + + - - - - - - - + + + + + + + - + - - - - + + + + - + - - + - - + + + - - - - + + + + + + + + + + + + - - + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - - - - + + + + - + - + - + - + - + - + - + - - - + + + - - + + - - - + + + - + - + - - - - - - - - - - - - - + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - + - + - + - - + + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - - - - - + + + + + - + - + + - - - + + - - + + + - - - + + - + + - - - - - + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + - - - + + - - + + + - - - + + - + + - - - - - + + + + + + + + + + + + + + - + - + - + - + - - + + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - - + + + + + + - + - + - + - + - - + + - + - + - + - + - - - + + + - + - - + - - + + + + + + + + + + + + + - - + + - - + + - - - - + + + + - - + + - - - - - - - - - - - + - - + + + - - - - + + + - - + + + - - + - - + - - - - - - - - - - - + + + - + - - + + - - + + - - - - + + + + - - + + + + + + + + + + + + - + - + - + - - + + - + - + - + - - - - - + + + + + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + - + - + - - - + + + - - - - - + + + + + - + - + - - - + + + - + - + - + - + - + - + - + - + - + - - - + + + - + - - + - - + + + - - + - - + + + - - + - - - - + + + + + + + + + + + + + + - - - - - + + + + + - + - - + - - + + + - - + - - + + + - + + + + + + + + + + - - + + - - + + - - + + - - + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - - - - - - - - - - - + - - + + + - - - - - - + + + + + - + - - + - - + + + - - + - - + + + - + + + + + + + + + + - + - - - + + + - - - - - + + + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + + + + + + + + + + - - - + + + - + - + - - - + + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + + - - - + + - + + - - - + + - + - - - - + + + + - - - - - + + + + + - + - + + + + + + + + + + - - - + + + - + + - - + + - - - - - + + + + + + + + + + + + + - + - - - + + + - - - + + + - + - - - - - - - - - - - - - + + + - + - - + + @@ -2882,65 +5434,94 @@

Total time: 23.21

- - + + + + + + + + + + + - + + + - - - + + + + + + + + + + + - - - + + + - - - + + + + + + + + + + + + + - + - - - + + + - - - - + + + + - + - - + + - - + + @@ -2948,8 +5529,8 @@

Total time: 23.21

- - + + @@ -2958,8 +5539,8 @@

Total time: 23.21

- - + + @@ -2967,46 +5548,46 @@

Total time: 23.21

- - + + - + - - - - - + + + + + - + - - - - + + + + - - - - + + + + - + - - - + + + @@ -3014,1239 +5595,1277 @@

Total time: 23.21

- - + + - + + + + + + + + + - - + + + + - - - - - + + + + + - - - - - + + + + + - + + - + - - - + + + - - - - - + + + + - - + + + + + + + + + + - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + + + + + + - - + + + + + + + + + + - - - - - + + - - - - - + + + + + + - - - - - - - - + + + + + + - + + + + + + + + + + - - + + + + - - - - + + - - - - - + - - + + - + + + + + + + + + + + + - + + + + - - - + - - - - - - - + + - + + + + + + + + + + + + + - - - + - - - - - + + - + - - - + - - - - + + + + + + + + + + + + + + - - - - - - - + + - - - + + + + + - - + + + + + + + + + + - + + - + + + + + + + + + + + + + + + + - + - + + + - - - + + + + + + + + + - - - + - + - - - - - - - - - - - + + + + + + - - - - - + - - - - - + + + + + + - + - - - - - + + + - - - - - - - - + + + + + - - + + + - - - - + + + + + + - + + - - - - + + + + - - - - - - - - - - - - - - - - + + + - - - - - - + + + - + - - + + + + + + + + - - - - - + + + + - - - - + - - - + + + - - + + + + + - - - - + + + - + + + + - - + + + - - - - - - - - - + - - - + + - + + + + - + + + - - - - - + + - - - + + + + + + + - - - - - + + + + + + + + + + + + + + + - - + + + + + + - - + - - - - - + + + + + + + + + - - - - + + - - - + + - - - + + + + - - - - + + + + + + - - - - + - - - - - - + - - - - - - - - - + + + - + + - + - - - - - - - + - - + - - - - - - + + + + + - - - - - - - + - - + + + - - - + + - - + + + - - - - - + + - + + + + + + - + + - - - + + - - - - - - - - - - - - - + + + + + + + + + + + + - + + + + - - + + - - - - - - + + + + + + + + + + + - + + + + - - - - - + - + + + + + - - + - - - - + - + - - + + - + + - - - - - + + + + + + + + + + + + + - - - - - - + - - - + + - + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + - + + + + + - + + - - + - + + - - - - - - - - + - - - + - + + - + - + + - - - + + + - - + - + + - - + + - - - + + - - + + - - - - - - - - + - - + - + + + @@ -4254,69 +6873,54 @@

Total time: 23.21

- - - + - - + + - + - + - - - - - - - + + - - - - - - - - @@ -4328,59 +6932,61 @@

Total time: 23.21

+ + + + + + - - - - + - + - - + + - - + + - @@ -4392,7 +6998,6 @@

Total time: 23.21

- @@ -4408,12 +7013,13 @@

Total time: 23.21

+ - + @@ -4425,7 +7031,6 @@

Total time: 23.21

- @@ -4434,6 +7039,7 @@

Total time: 23.21

+ @@ -4441,7 +7047,6 @@

Total time: 23.21

- From 6f4327b07e6f8ccbf828bf291e2e74058ff74451 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 25 Dec 2018 18:43:29 -0700 Subject: [PATCH 1105/1191] do not define the encode to stream is a field level value is already present --- .../field/base_field_method_definitions.rb | 6 + lib/protobuf/field/string_field.rb | 12 +- profile.html | 6932 ++++++++--------- 3 files changed, 3384 insertions(+), 3566 deletions(-) diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index d674fdb5..e39f61f0 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -12,6 +12,8 @@ def self.fully_qualified_name_string(selph) end def self.define_base_encode_to_stream_method!(selph) + return if selph.respond_to?(:encode_to_stream) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) stream << tag_encoded << encode(value) @@ -20,6 +22,8 @@ def encode_to_stream(value, stream) end def self.define_repeated_not_packed_encode_to_stream_method!(selph) + return if selph.respond_to?(:encode_to_stream) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) value.each do |val| @@ -30,6 +34,8 @@ def encode_to_stream(value, stream) end def self.define_repeated_packed_encode_to_stream_method!(selph) + return if selph.respond_to?(:encode_to_stream) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) packed_value = value.map { |val| encode(val) }.join diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 1248a3aa..fa6f33cf 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -18,6 +18,14 @@ def acceptable?(val) val.is_a?(String) || val.nil? || val.is_a?(Symbol) end + def coerce!(value) + if value.nil? + nil + else + value.to_s + end + end + def decode(bytes) bytes_to_decode = "" + bytes bytes_to_decode.force_encoding(::Protobuf::Field::StringField::ENCODING) @@ -26,7 +34,9 @@ def decode(bytes) def encode(value) value_to_encode = "" + value # dup is slower - value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + unless value_to_encode.encoding == ENCODING + value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + end value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) "#{::Protobuf::Field::VarintField.encode(value_to_encode.size)}#{value_to_encode}" diff --git a/profile.html b/profile.html index 1d9dd45a..0afe829f 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 70.11

+

Total time: 69.40

%Total
100% 0%23.2170.11 0.0023.2170.11 0 (top)
20.0660.20 0.0020.0660.20 1/1 Benchmark::IPS.ips
0.940.000.942/112Kernel.require2.840.112.731/5Fixnum#times
0.920.040.881/5##times2.630.012.622/115Kernel.require
0.812.57 0.000.816/18772.575/1904 Kernel.require
0.470.060.4117/191.840.191.6524/26 Kernel.load
0.110.000.111/468431Gem::Specification.each_gemspec
0.220.000.2219/4684310.120.060.062/5 Kernel.require
0.280.080.20466834/468431Protobuf::Message#each_field_for_serialization2.840.112.731/5(top)
10.000.199.811/468431Benchmark::IPS::Job#run_warmup60.190.0060.192/5Benchmark::IPS::Job#run
90%0%63.150.1762.985Fixnum#times
10.0540.15 0.0010.051/46843140.151/1 Benchmark::IPS::Job#run_benchmark
90%1%21.030.3120.71468431##each
20.040.0020.041/1Benchmark::IPS::Job#run_warmup
19.730.1619.57217694/217694Benchmark::IPS::Job::Entry#call_times1.130.021.1210000/393326Protobuf::Message::Serialization::ClassMethods.decode_from
1.870.301.57933668/933668Protobuf::Field::BaseField#encode_to_stream1.090.051.0410000/393326Protobuf::Encoder.encode
1.030.300.73466834/466834Protobuf::Field::StringField#encode_to_stream0.350.020.3320000/1182416Class#new
0.540.430.104202197/9808248##[]0.140.040.0910000/393326Test::Resource#status=
0.390.390.13 0.004201506/7002511Protobuf::Field::BaseField#fully_qualified_name0.134/395067Bundler::SpecSet#tsort_each_node
0.270.270.002801004/2801004Protobuf::Field::BaseField#required?0.170.010.161/395067Bundler::LockfileParser#initialize
0.190.19 0.001400502/4201506Protobuf::Field::BaseField#map?0.191/395067Bundler::Source::Path#load_spec_files
0.170.170.24 0.001400502/5602467Protobuf::Field::BaseField#repeated?0.241/395067Gem::Specification.each_gemspec
0.110.110.002801021/2801653##nil?0.700.010.6820/395067Kernel.require
0.920.040.881/5(top)20.041.6718.381/395067Benchmark::IPS::Job#run_warmup
20.050.0020.052/5Benchmark::IPS::Job#run40.150.0240.131/395067Benchmark::IPS::Job#run_benchmark
90%0%21.000.0620.945##times88%2%62.051.8160.24395067Array#each
57.551.9155.641400333/1400333Benchmark::IPS::Job::Entry#call_times
10.050.710.420.291400883/1400883Benchmark::Timing.now
0.19 0.0010.051/1Benchmark::IPS::Job#run_benchmark0.1912/13Gem::Specification.load
10.000.19 0.0010.000.19 1/1Benchmark::IPS::Job#run_warmupBundler::Source::Path#validate_spec
0.410.17 0.010.4110000/466834Protobuf::Message::Serialization::ClassMethods.decode_from0.16160/838Kernel.send
0.310.160.160.001400337/1400337Float#<
0.12 0.010.3010000/466834Protobuf::Encoder.encode0.12118/118TSort.each_strongly_connected_component_from
20.0660.20 0.0020.0660.20 1/1 (top)
86%85% 0%20.0660.20 0.0020.0660.20 1 Benchmark::IPS.ips
20.0560.19 0.0020.0560.19 1/1 Benchmark::IPS::Job#run
20.0560.19 0.0020.0560.19 1/1 Benchmark::IPS.ips
86%85% 0%20.0560.19 0.0020.0560.19 1 Benchmark::IPS::Job#run
20.0560.19 0.0020.0560.19 2/5##timesFixnum#times
19.730.1619.57217694/217694##each57.551.9155.641400333/1400333Array#each
85%0%19.730.1619.5721769482%2%57.551.9155.641400333 Benchmark::IPS::Job::Entry#call_times
19.510.3919.12456834/45741155.102.3252.785714009/5714540 Proc#call
0.540.540.007113788/7900374Fixnum#<
19.510.3919.12456834/45741155.102.3252.785714009/5714540 Benchmark::IPS::Job::Entry#call_times
84%1%19.540.4019.1445741178%3%55.162.3552.815714540 Proc#call
8.540.148.41456834/46683424.192.1822.015330683/5330683Protobuf::Message#to_hash
12.140.2311.91383326/393326 Protobuf::Message::Serialization::ClassMethods.decode_from
6.830.146.69456834/46683410.280.2810.00383326/393326 Protobuf::Encoder.encode
2.400.072.33456834/9350614.340.373.97766652/1182416 Class#new
1.150.111.04456834/4668341.680.381.30383326/393326 Test::Resource#status=
0.120.070.06456834/466834StringIO.new0.100.100.00383326/393326Protobuf::Message#to_proto
10.0540.15 0.0010.0540.15 1/1##timesFixnum#times
43%57% 0%10.0540.15 0.0010.0540.15 1 Benchmark::IPS::Job#run_benchmark
10.050.0010.051/468431##each40.150.0240.131/395067Array#each
10.000.0010.001/1##times10.421.718.70393326/5724010Protobuf::Message#each_field_for_serialization
22.019.3012.715330683/5724010Protobuf::Message#to_hash
43%0%10.000.0010.001Benchmark::IPS::Job#run_warmup46%15%32.4311.0121.415724010Hash#each_key
10.000.199.811/468431##each3.642.920.7110661366/10662885Kernel.respond_to?
0.410.010.4110000/466834##times3.590.343.25393326/393326Protobuf::Field::StringField(singleton)#encode_to_stream
8.540.148.41456834/466834Proc#call
38%0%8.950.148.81466834Protobuf::Message::Serialization::ClassMethods.decode_from2.491.810.685724009/6117335Protobuf::Field::Int64Field(singleton)#value_from_values
8.480.138.36466834/466834Protobuf::Message::Serialization.decode_from2.431.710.725724009/6117335Protobuf::Field::StringField(singleton)#value_from_values
0.330.060.27466834/935061Class#new1.880.301.58393326/393326Protobuf::Field::EnumField(singleton)#encode_to_stream
8.480.138.36466834/466834Protobuf::Message::Serialization::ClassMethods.decode_from1.710.301.40393326/393326Protobuf::Field::Int64Field(singleton)#encode_to_stream
36%0%8.480.138.36466834Protobuf::Message::Serialization.decode_from
1.681.680.0011841344/15386948Hash#[]
8.360.887.47466834/466834Protobuf::Decoder.decode_each_field1.281.280.0010661366/13026447Hash#[]=
8.360.887.47466834/466834Protobuf::Message::Serialization.decode_from1.241.240.0011841344/14201302Test::Resource#_protobuf_message_field
36%3%8.360.887.47466834Protobuf::Decoder.decode_each_field
6.570.456.131400502/1400502Protobuf::Message::Serialization.set_field_bytes
0.520.330.192801004/2801004Protobuf::Varint.decode
0.100.101.131.13 0.001867336/1867336StringIO#eof10661366/10661556Protobuf::Field::BaseField#name
0.310.010.3010000/466834##times0.350.070.28393326/786652Protobuf::Field::EnumField(singleton)#value_from_values
6.830.146.69456834/46683424.192.1822.015330683/5330683 Proc#call
30%0%7.140.156.99466834Protobuf::Encoder.encode34%3%24.192.1822.015330683Protobuf::Message#to_hash
6.990.186.81466834/466834Protobuf::Message#each_field_for_serialization22.019.3012.715330683/5724010Hash#each_key
6.990.186.81466834/466834Protobuf::Encoder.encode20.040.0020.041/1Fixnum#times
30%28% 0%6.990.186.81466834Protobuf::Message#each_field_for_serialization20.040.0020.041Benchmark::IPS::Job#run_warmup
0.280.080.20466834/468431##each20.041.6718.381/395067Array#each
6.570.456.131400502/1400502Protobuf::Decoder.decode_each_field1.130.021.1210000/393326Fixnum#times
12.140.2311.91383326/393326Proc#call
28%1%6.570.456.131400502Protobuf::Message::Serialization.set_field_bytes18%0%13.270.2513.03393326Protobuf::Message::Serialization::ClassMethods.decode_from
5.540.535.011400502/1400502Protobuf::Field::BaseField#set12.260.2811.97393326/393326Protobuf::Message::Serialization.decode_from
0.520.77 0.210.321400502/4201813Protobuf::Message::Fields::ClassMethods.get_field0.56393326/1182416Class#new
1.070.270.80466834/2801004Test::Resource#status=12.260.2811.97393326/393326Protobuf::Message::Serialization::ClassMethods.decode_from
17%0%12.260.2811.97393326Protobuf::Message::Serialization.decode_from
2.020.601.42933668/2801004##each11.971.5210.46393326/393326Protobuf::Decoder.decode_each_field
3.070.872.191400502/2801004Protobuf::Message#[]=11.971.5210.46393326/393326Protobuf::Message::Serialization.decode_from
26%7%6.161.744.422801004Protobuf::Message#set_field17%2%11.971.5210.46393326Protobuf::Decoder.decode_each_field
1.040.440.602801004/4201813Protobuf::Message::Fields::ClassMethods.get_field9.040.808.241179978/1179978Protobuf::Message::Serialization.set_field_bytes
0.810.290.52933668/933668Protobuf::Field::IntegerField#coerce!0.930.570.362359956/2359956Protobuf::Varint.decode
0.75 0.190.56933668/933668Protobuf::Field::EnumField#coerce!
0.370.370.19 0.002801004/4201506Protobuf::Field::BaseField#map?393326/393326StringIO#read
0.330.200.12933668/933668Protobuf::Field::BytesField#coerce!0.160.160.001573304/1573304StringIO#eof
0.310.310.130.13 0.002801004/7002511Protobuf::Field::BaseField#fully_qualified_name1572988/1575615Fixnum#==
0.300.300.002801004/5602467Protobuf::Field::BaseField#repeated?1.090.051.0410000/393326Fixnum#times
10.28 0.280.280.002801004/2805760##[]=10.00383326/393326Proc#call
0.120.120.002801004/4669248Kernel.class
16%0%11.370.3311.04393326Protobuf::Encoder.encode
0.110.110.002801004/4669192Kernel.nil?11.040.4510.59393326/393326Protobuf::Message#each_field_for_serialization
5.540.535.011400502/1400502Protobuf::Message::Serialization.set_field_bytes11.040.4510.59393326/393326Protobuf::Encoder.encode
23%2%5.540.535.011400502Protobuf::Field::BaseField#set15%0%11.040.4510.59393326Protobuf::Message#each_field_for_serialization
3.250.193.071400502/1400502Protobuf::Message#[]=10.421.718.70393326/5724010Hash#each_key
0.92 0.120.120.00393326/1179979Test::Resource#_protobuf_message_required_field_tags
9.04 0.80466834/466834Protobuf::Field::EnumField#decode8.241179978/1179978Protobuf::Decoder.decode_each_field
12%1%9.040.808.241179978Protobuf::Message::Serialization.set_field_bytes
0.280.200.08466834/933668Protobuf::Field::IntegerField#decode3.230.262.97393326/393326Protobuf::Field::EnumField(singleton)#set
0.190.120.08466834/466834Protobuf::Field::StringField#decode2.310.242.07393326/393326Protobuf::Field::Int64Field(singleton)#set
0.180.182.240.271.98393326/393326Protobuf::Field::StringField(singleton)#set
0.260.26 0.001400502/5602467Protobuf::Field::BaseField#repeated?1179978/15386948Hash#[]
0.180.180.200.20 0.001400502/1400502Protobuf::Field::BaseField#name1179978/14201302Test::Resource#_protobuf_message_field
0.230.010.231/935061Bundler::Dsl#to_definition1.140.170.97393326/2359958Protobuf::Field::EnumField(singleton)#set
0.330.060.27466834/935061Protobuf::Message::Serialization::ClassMethods.decode_from1.340.161.18393326/2359958Protobuf::Field::Int64Field(singleton)#set
2.400.072.33456834/935061Proc#call1.390.261.13393326/2359958Test::Resource#status=
1.530.241.29393326/2359958Protobuf::Field::StringField(singleton)#set
2.970.562.41786654/2359958Hash#each
14%11% 1%3.350.253.11935061Class#new8.371.406.972359958Protobuf::Message#set_field
2.690.392.30933668/933668Protobuf::Message#initialize2.430.751.69786653/786653Protobuf::Field::StringField(singleton)#set_field
2.150.511.64786653/786653Protobuf::Field::Int64Field(singleton)#set_field
1.970.521.45786652/786652Protobuf::Field::EnumField(singleton)#set_field
0.230.23 0.000.221/1Bundler::Definition#initialize1179980/15386948Hash#[]
3.25 0.193.071400502/1400502Protobuf::Field::BaseField#set
14%0%3.25 0.193.071400502Protobuf::Message#[]=0.001179980/14201302Test::Resource#_protobuf_message_field
3.070.872.191400502/2801004Protobuf::Message#set_field0.130.060.0735/1182416Kernel.require
2.690.392.30933668/933668Class#new0.230.050.1814/1182416Kernel.eval
0.350.020.3320000/1182416Fixnum#times
0.440.010.43153/1182416Protobuf::Field.build
0.590.010.581/1182416Bundler::Dsl#to_definition
0.770.210.56393326/1182416Protobuf::Message::Serialization::ClassMethods.decode_from
4.340.373.97766652/1182416Proc#call
11%10% 1%2.690.392.30933668Protobuf::Message#initialize7.140.846.301182416Class#new
2.210.192.02933668/933879##each4.730.903.83786653/786653Protobuf::Message#initialize
0.580.010.571/1Bundler::Definition#initialize
0.430.020.42153/153Protobuf::Field::BaseField#initialize
2.21 0.192.02933668/933879Protobuf::Message#initialize0.000.191/1Bundler::LockfileParser#initialize
9%0%2.230.202.03933879##each
0.190.010.1817/17Gem::Specification#initialize
2.020.601.42933668/2801004Protobuf::Message#set_field0.120.120.00393326/393326StringIO#initialize
0.370.030.352/18771.490.071.422/1904 Kernel.load
0.812.57 0.000.816/18772.575/1904 (top)
0.942.62 0.000.94112/18772.62115/1904 Kernel.require
9% 0%2.120.032.0918776.670.076.601904 Kernel.require
0.792.22 0.000.792.22 1/1 Bundler.setup
0.220.700.010.6820/395067Array#each
0.33 0.000.2219/468431##each0.33109/109Protobuf::Message::Fields::ClassMethods.optional
0.110.24 0.000.110.24 1/1 Gem::Specification.load_defaults
1.870.301.57933668/933668##each
8%1%1.870.301.57933668Protobuf::Field::BaseField#encode_to_stream0.190.000.192/7IO.open
0.610.110.49466834/466834Protobuf::Field::EnumField#encode0.140.000.1437/37Protobuf::Message::Fields::ClassMethods.repeated
0.430.250.19466834/933668Protobuf::Field::IntegerField#encode0.130.060.0735/1182416Class#new
0.360.180.181867336/3267838IO::GenericWritable.<<0.120.060.062/5Fixnum#times
0.170.170.00933668/1400655Protobuf::Field::BaseField#tag_encoded4.730.903.83786653/786653Class#new
6%1%4.730.903.83786653Protobuf::Message#initialize
0.520.210.321400502/4201813Protobuf::Message::Serialization.set_field_bytes3.660.702.97786653/786864Hash#each
1.040.440.602801004/4201813Protobuf::Message#set_field3.660.702.97786653/786864Protobuf::Message#initialize
6%2%1.570.650.924201813Protobuf::Message::Fields::ClassMethods.get_field5%1%3.750.753.00786864Hash#each
0.500.500.004201813/4202318Protobuf::Message::Fields::ClassMethods.field_store2.970.562.41786654/2359958Protobuf::Message#set_field
3.642.920.7110661366/10662885Hash#each_key
5%4%3.642.930.7210662885Kernel.respond_to?
0.410.410.720.72 0.004201813/9808248##[]10662776/10662778Kernel.respond_to_missing?
1.150.111.04456834/466834Proc#call3.590.343.25393326/393326Hash#each_key
5% 0%1.200.131.07466834Test::Resource#status=3.590.343.25393326Protobuf::Field::StringField(singleton)#encode_to_stream
1.070.272.54 0.80466834/2801004Protobuf::Message#set_field
0.410.410.004201813/9808248Protobuf::Message::Fields::ClassMethods.get_field1.74393326/393326Protobuf::Field::StringField#encode
0.540.430.104202197/9808248##each
4%4%1.070.940.139808248##[]0.490.200.29786652/2359956IO::GenericWritable.<<
0.110.100.012803132/2803342##default0.230.230.00393326/1180131Protobuf::Field::BaseField#tag_encoded
1.030.300.73466834/466834##each3.230.262.97393326/393326Protobuf::Message::Serialization.set_field_bytes
4%1%1.030.300.73466834Protobuf::Field::StringField#encode_to_stream0%3.230.262.97393326Protobuf::Field::EnumField(singleton)#set
0.300.140.161400502/3267838IO::GenericWritable.<<1.830.251.58393326/393326Protobuf::Field::EnumField#decode
0.150.080.07466834/1400655Protobuf::Field::VarintField.encode1.140.170.97393326/2359958Protobuf::Message#set_field
0.120.120.140.14 0.00466834/1400655Protobuf::Field::BaseField#tag_encoded1179978/15386948Protobuf::Enum.enum_for_tag_integer
0.940.230.23 0.000.942/112(top)1179980/15386948Protobuf::Message#set_field
4%0%0.94
0.260.26 0.000.94112Kernel.require1179978/15386948Protobuf::Message::Serialization.set_field_bytes
0.940.34 0.000.94112/1877Kernel.require0.34261/15386948Set#include?
0.920.120.80466834/466834Protobuf::Field::BaseField#set1.681.680.0011841344/15386948Hash#each_key
3%0%0.920.120.80466834Protobuf::Field::EnumField#decode3%2.722.320.4015386948Hash#[]
0.560.170.39466834/466834Protobuf::Field::EnumField#acceptable?0.330.000.33153/295Bundler::DepProxy#hash
0.240.170.07466834/933668Protobuf::Field::IntegerField#decode2.630.012.622/115(top)
3%0%2.630.012.62115Kernel.require
0.390.220.16466834/933668Protobuf::Field::EnumField#encode2.620.002.62115/1904Kernel.require
0.430.250.19466834/933668Protobuf::Field::BaseField#encode_to_stream2.540.801.74393326/393326Protobuf::Field::StringField(singleton)#encode_to_stream
3%2%0.820.470.35933668Protobuf::Field::IntegerField#encode1%2.540.801.74393326Protobuf::Field::StringField#encode
0.210.120.09933668/14006551.221.060.16393326/393326String#encode!
0.280.160.13393326/1180131 Protobuf::Field::VarintField.encode
0.140.140.100.10 0.00933668/3267838##&393326/786790String#+
0.810.290.52933668/933668Protobuf::Message#set_field2.491.810.685724009/6117335Hash#each_key
3%1%0.810.290.52933668Protobuf::Field::IntegerField#coerce!2%2.491.810.686117335Protobuf::Field::Int64Field(singleton)#value_from_values
0.430.280.15933668/933668Protobuf::Field::IntegerField#acceptable?0.430.005724009/11842646Hash#fetch
0.790.000.791/1Kernel.require2.430.751.69786653/786653Protobuf::Message#set_field
3%0%0.790.000.791Bundler.setup1%2.430.751.69786653Protobuf::Field::StringField(singleton)#set_field
0.430.010.590.380.20786653/786653Protobuf::Field::BytesField#coerce!
0.53 0.421/2Bundler.definition0.11786653/1179979Test::Resource#_protobuf_message_required_field_tags
0.360.270.27 0.000.361/1Bundler::Runtime#setup786653/786836Array#delete
0.290.110.18466834/1400502Protobuf::Field::EnumField#acceptable?0.210.210.00786653/13026447Hash#[]=
0.500.170.33933668/1400502Protobuf::Field::EnumField#coerce!2.431.710.725724009/6117335Hash#each_key
3%1%0.790.280.511400502Protobuf::Enum.fetch2%2.431.710.726117335Protobuf::Field::StringField(singleton)#value_from_values
0.440.280.161400502/1400502Protobuf::Enum.enum_for_tag_integer0.430.430.005724009/11842646Hash#fetch
0.750.190.56933668/933668Protobuf::Message#set_field2.310.242.07393326/393326Protobuf::Message::Serialization.set_field_bytes
3% 0%0.750.190.56933668Protobuf::Field::EnumField#coerce!2.310.242.07393326Protobuf::Field::Int64Field(singleton)#set
0.500.170.33933668/1400502Protobuf::Enum.fetch1.340.161.18393326/2359958Protobuf::Message#set_field
0.310.310.002801004/7002511Protobuf::Message#set_field0.730.430.30393326/786652Protobuf::Field::IntegerField#decode
0.390.390.004201506/7002511##each2.240.271.98393326/393326Protobuf::Message::Serialization.set_field_bytes
3%3%0.700.700.007002511Protobuf::Field::BaseField#fully_qualified_name0%2.240.271.98393326Protobuf::Field::StringField(singleton)#set
0.300.140.161400502/3267838Protobuf::Field::StringField#encode_to_stream1.530.241.29393326/2359958Protobuf::Message#set_field
0.360.180.181867336/3267838Protobuf::Field::BaseField#encode_to_stream
2%1%0.660.310.343267838IO::GenericWritable.<<0.450.280.17393326/393326Protobuf::Field::StringField#decode
0.340.342.22 0.003267838/3267838StringIO#write2.221/1Kernel.require
3%0%2.220.002.221Bundler.setup
0.170.171.18 0.001400502/5602467##each1.181/1Bundler::Runtime#setup
0.180.180.001400502/5602467Protobuf::Field::BaseField#set1.020.011.001/2Bundler.definition
0.300.300.002801004/56024672.150.511.64786653/786653 Protobuf::Message#set_field
2%2%0.650.653%0%2.150.511.64786653Protobuf::Field::Int64Field(singleton)#set_field
1.460.570.88786653/786653Protobuf::Field::IntegerField#coerce!
0.120.12 0.005602467Protobuf::Field::BaseField#repeated?786653/13026447Hash#[]=
0.610.110.49466834/466834Protobuf::Field::BaseField#encode_to_stream1.970.521.45786652/786652Protobuf::Message#set_field
2% 0%0.610.110.49466834Protobuf::Field::EnumField#encode1.970.521.45786652Protobuf::Field::EnumField(singleton)#set_field
0.390.220.16466834/933668Protobuf::Field::IntegerField#encode1.270.330.93786652/786652Protobuf::Field::EnumField#coerce!
0.110.130.130.00786652/13026447Hash#[]=
1.880.301.58393326/393326Hash#each_key
2%0%1.880.301.58393326Protobuf::Field::EnumField(singleton)#encode_to_stream
1.150.240.91393326/393326Protobuf::Field::EnumField#encode
0.290.150.14786652/2359956IO::GenericWritable.<<
0.140.140.00393326/1180131Protobuf::Field::BaseField#tag_encoded
1.840.191.6524/26(top)
2%0%1.840.191.6526Kernel.load
1.49 0.071.422/1904Kernel.require
1.830.251.58393326/393326Protobuf::Field::EnumField(singleton)#set
2%0%1.830.251.58393326Protobuf::Field::EnumField#decode
1.040.310.73393326/393326Protobuf::Field::EnumField#acceptable?
0.540.330.21393326/786652Protobuf::Field::IntegerField#decode
0.14 0.04466834/467102Protobuf::Enum#to_i0.0910000/393326Fixnum#times
1.680.381.30383326/393326Proc#call
2%0%1.810.421.39393326Test::Resource#status=
1.390.261.13393326/2359958Protobuf::Message#set_field
0.120.120.00786653/13026447Protobuf::Field::Int64Field(singleton)#set_field
0.130.130.00786652/13026447Protobuf::Field::EnumField(singleton)#set_field
0.210.210.00786653/13026447Protobuf::Field::StringField(singleton)#set_field
1.281.280.0010661366/13026447Hash#each_key
2%2%1.791.770.0213026447Hash#[]=
1.710.301.40393326/393326Hash#each_key
2%0%1.710.301.40393326Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.860.480.38393326/786652Protobuf::Field::IntegerField#encode
0.380.150.22786652/2359956IO::GenericWritable.<<
0.160.160.00393326/1180131Protobuf::Field::BaseField#tag_encoded
0.19 0.19 0.001400502/4201506##each1179980/14201302Protobuf::Message#set_field
0.370.370.200.20 0.002801004/4201506Protobuf::Message#set_field1179978/14201302Protobuf::Message::Serialization.set_field_bytes
1.241.240.0011841344/14201302Hash#each_key
2% 2%0.560.561.621.62 0.004201506Protobuf::Field::BaseField#map?14201302Test::Resource#_protobuf_message_field
0.560.170.68 0.39466834/466834Protobuf::Field::EnumField#decode0.29393326/786652Protobuf::Field::EnumField#encode
0.860.480.38393326/786652Protobuf::Field::Int64Field(singleton)#encode_to_stream
2%1%1.540.870.67786652Protobuf::Field::IntegerField#encode
0.370.210.16786652/1180131Protobuf::Field::VarintField.encode
0.310.310.00786559/1573117Fixnum#&
1.460.570.88786653/786653Protobuf::Field::Int64Field(singleton)#set_field
2% 0%1.460.570.88786653Protobuf::Field::IntegerField#coerce!
0.710.520.18786653/786653Protobuf::Field::IntegerField#acceptable?
0.560.170.39466834Protobuf::Field::EnumField#acceptable?0.200.37393326/1179987Protobuf::Field::EnumField#acceptable?
0.830.300.53786652/1179987Protobuf::Field::EnumField#coerce!
1%0%1.390.490.901179987Protobuf::Enum.fetch
0.790.530.271179978/1179978Protobuf::Enum.enum_for_tag_integer
0.29 0.110.18466834/1400502Protobuf::Enum.fetch0.110.001179987/2754972Kernel.kind_of?
0.170.010.16160/838Array#each
1.100.001.101/838Bundler::Runtime#requested_specs
1%0%1.280.011.26838Kernel.send
1.100.001.101/1Bundler::Definition#requested_specs
0.110.000.1177/79Bundler::LockfileParser#parse_source
0.540.330.21393326/786652Protobuf::Field::EnumField#decode
0.730.430.30393326/786652Protobuf::Field::Int64Field(singleton)#set
1%1%1.270.760.51786652Protobuf::Field::IntegerField#decode
0.270.190.08786652/786915Numeric#nonzero?
0.250.250.00786558/1573117Fixnum#&
1.270.330.93786652/786652Protobuf::Field::EnumField(singleton)#set_field
1%0%1.270.330.93786652Protobuf::Field::EnumField#coerce!
0.830.300.53786652/1179987Protobuf::Enum.fetch
0.110.110.00786652/1180209Protobuf::Field::BaseField#type_class
1.221.060.16393326/393326Protobuf::Field::StringField#encode
1%1%1.221.060.16393326String#encode!
0.160.160.002359956/2362883Hash#default
1.180.001.181/1Bundler.setup
1%0%1.180.001.181Bundler::Runtime#setup
1.100.001.101/1Bundler::Runtime#requested_specs
0.290.150.14786652/2359956Protobuf::Field::EnumField(singleton)#encode_to_stream
0.380.150.22786652/2359956Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.490.200.29786652/2359956Protobuf::Field::StringField(singleton)#encode_to_stream
1%0%1.160.510.652359956IO::GenericWritable.<<
0.650.650.002359956/2359956StringIO#write
1.150.240.91393326/393326Protobuf::Field::EnumField(singleton)#encode_to_stream
1%0%1.150.240.91393326Protobuf::Field::EnumField#encode
0.680.390.29393326/786652Protobuf::Field::IntegerField#encode
0.230.150.08393326/393594Protobuf::Enum#to_i
1.131.130.0010661366/10661556Hash#each_key
1%1%1.131.130.0010661556Protobuf::Field::BaseField#name
1.100.001.101/1Bundler::Runtime#setup
1%0%1.100.001.101Bundler::Runtime#requested_specs
1.100.001.101/838Kernel.send
1.100.001.101/1Kernel.send
1%0%1.100.001.101Bundler::Definition#requested_specs
1.100.001.101/1Bundler::Definition#specs_for
1.100.001.101/1Bundler::Definition#requested_specs
1%0%1.100.001.101Bundler::Definition#specs_for
1.080.001.081/1Bundler::Definition#specs
1.080.001.081/1Bundler::Definition#specs_for
1%0%1.080.001.081Bundler::Definition#specs
0.570.000.571/1Bundler::Definition#resolve
0.470.000.471/1Bundler::SpecSet#materialize
1.040.310.73393326/393326Protobuf::Field::EnumField#decode
1%0%1.040.310.73393326Protobuf::Field::EnumField#acceptable?
0.560.200.37393326/1179987Protobuf::Enum.fetch
1.020.011.001/2Bundler.setup
1%0%1.020.011.002Bundler.definition
0.820.010.811/1Bundler::Definition.build
0.130.000.131/1Bundler.configure
0.930.570.362359956/2359956Protobuf::Decoder.decode_each_field
1%0%0.930.570.362359956Protobuf::Varint.decode
0.360.360.002359956/2359956ProtobufJavaHelpers::Varinter.read_varint
0.430.430.005724009/11842646Protobuf::Field::StringField(singleton)#value_from_values
0.430.430.005724009/11842646Protobuf::Field::Int64Field(singleton)#value_from_values
1%1%0.920.910.0111842646Hash#fetch
0.820.010.811/1Bundler.definition
1%0%0.820.010.811Bundler::Definition.build
0.790.000.791/1Bundler::Dsl.evaluate
0.790.530.271179978/1179978Protobuf::Enum.fetch
1%0%0.790.530.271179978Protobuf::Enum.enum_for_tag_integer
0.140.140.001179978/15386948Hash#[]
0.130.130.001179978/1180431Array#first
0.790.000.791/1Bundler::Definition.build
1%0%0.790.000.791Bundler::Dsl.evaluate
0.590.000.591/1Bundler::Dsl#to_definition
0.170.000.171/1Bundler::Dsl#eval_gemfile
0.720.720.0010662776/10662778Kernel.respond_to?
1%1%0.720.720.0010662778Kernel.respond_to_missing?
0.710.520.18786653/786653Protobuf::Field::IntegerField#coerce!
1%0%0.710.520.18786653Protobuf::Field::IntegerField#acceptable?
0.100.100.00786653/2754972Kernel.kind_of?
0.710.420.291400883/1400883Array#each
1%0%0.710.420.291400883Benchmark::Timing.now
0.290.290.001400883/1400884Process.clock_gettime
0.280.160.13393326/1180131Protobuf::Field::StringField#encode
0.370.210.16786652/1180131Protobuf::Field::IntegerField#encode
0%0%0.660.370.291180131Protobuf::Field::VarintField.encode
0.290.290.001180131/1180131ProtobufJavaHelpers::Varinter.to_varint
0.650.650.002359956/2359956IO::GenericWritable.<<
0%0%0.650.650.002359956StringIO#write
0.120.120.00393326/1179979Protobuf::Message#each_field_for_serialization
0.530.420.11786653/1179979Protobuf::Field::StringField(singleton)#set_field
0%0%0.640.540.111179979Test::Resource#_protobuf_message_required_field_tags
0.110.110.00786653/787731Kernel.dup
0.540.540.007113788/7900374Benchmark::IPS::Job::Entry#call_times
0%0%0.630.630.007900374Fixnum#<
0.590.000.591/1Bundler::Dsl.evaluate
0%0%0.590.000.591Bundler::Dsl#to_definition
0.590.010.581/1182416Class#new
0.590.380.20786653/786653Protobuf::Field::StringField(singleton)#set_field
0%0%0.590.380.20786653Protobuf::Field::BytesField#coerce!
0.130.130.00786653/796051Module#===
0.580.010.571/1Class#new
0%0%0.580.010.571Bundler::Definition#initialize
0.220.000.221/1Bundler::Definition#converge_paths
0.400.000.401/6Bundler::Definition#resolve
0%0%0.570.000.576Bundler::SpecSet#for
0.570.010.566/6Kernel.loop
0.570.000.571/1Bundler::Definition#specs
0%0%0.570.000.571Bundler::Definition#resolve
0.400.000.401/6Bundler::SpecSet#for
0.160.000.161/1Bundler::Definition#converge_locked_specs
0.570.010.566/6Bundler::SpecSet#for
0%0%0.570.010.566Kernel.loop
0.360.000.35240/240Set#add?
0.190.010.18215/215Bundler::SpecSet#spec_for_dependency
0.250.250.00786558/1573117Protobuf::Field::IntegerField#decode
0.310.310.00786559/1573117Protobuf::Field::IntegerField#encode
0%0%0.550.550.001573117Fixnum#&
0.140.140.00393326/1180131Protobuf::Field::EnumField(singleton)#encode_to_stream
0.160.160.00393326/1180131Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.230.230.00393326/1180131Protobuf::Field::StringField(singleton)#encode_to_stream
0%0%0.550.540.011180131Protobuf::Field::BaseField#tag_encoded
0.140.000.1337/153Protobuf::Message::Fields::ClassMethods.repeated
0.330.010.32109/153Protobuf::Message::Fields::ClassMethods.optional
0%0%0.480.010.47153Protobuf::Message::Fields::ClassMethods.define_field
0.460.000.45153/153Protobuf::Field.build
0.470.000.471/1Bundler::Definition#specs
0%0%0.470.000.471Bundler::SpecSet#materialize
0.340.000.341/223Array#map!
0.460.000.45153/153Protobuf::Message::Fields::ClassMethods.define_field
0%0%0.460.000.45153Protobuf::Field.build
0.440.010.43153/1182416Class#new
0.450.280.17393326/393326Protobuf::Field::StringField(singleton)#set
0%0%0.450.280.17393326Protobuf::Field::StringField#decode
0.130.130.00393326/786790String#+
0.430.020.42153/153Class#new
0%0%0.430.020.42153Protobuf::Field::BaseField#initialize
0.340.000.341/223Bundler::SpecSet#materialize
0%0%0.390.010.39223Array#map!
0.340.000.3439/39Bundler::LazySpecification#__materialize__
0.160.000.161/984Bundler::Dsl#eval_gemfile
0%0%0.390.190.20984BasicObject#instance_eval
0.150.000.151/1Bundler::Dsl#gemspec
0.360.360.002359956/2359956Protobuf::Varint.decode
0%0%0.360.360.002359956ProtobufJavaHelpers::Varinter.read_varint
0.360.000.35240/240Kernel.loop
0%0%0.360.000.35240Set#add?
0.340.000.34240/261Set#include?
0.330.000.33144/1249Bundler::DepProxy#hash
0%0%0.350.000.351249Array#hash
0.320.000.32144/390Gem::Dependency#hash
0.350.070.28393326/786652Hash#each_key
0%0%0.350.070.28786652Protobuf::Field::EnumField(singleton)#value_from_values
0.340.000.34240/261Set#add?
0%0%0.340.000.34261Set#include?
0.340.000.34261/15386948Hash#[]
0.340.000.3439/39Array#map!
0%0%0.340.000.3439Bundler::LazySpecification#__materialize__
0.230.000.2338/38Bundler::Source::Rubygems#specs
0.320.000.32144/390Array#hash
0%0%0.340.010.33390Gem::Dependency#hash
0.320.310.01390/390Gem::Requirement#hash
0.330.000.33153/295Hash#[]
0%0%0.330.000.33295Bundler::DepProxy#hash
0.330.000.33144/1249Array#hash
0.330.000.33109/109Kernel.require
0%0%0.330.000.33109Protobuf::Message::Fields::ClassMethods.optional
0.330.010.32109/153Protobuf::Message::Fields::ClassMethods.define_field
0.320.310.01390/390Gem::Dependency#hash
0%0%0.320.310.01390Gem::Requirement#hash
0.100.100.00786653/2754972Protobuf::Field::IntegerField#acceptable?
0.110.110.001179987/2754972Protobuf::Enum.fetch
0%0%0.310.310.002754972Kernel.kind_of?
0.290.290.001400883/1400884Benchmark::Timing.now
0%0%0.290.290.001400884Process.clock_gettime
0.290.290.001180131/1180131Protobuf::Field::VarintField.encode
0%0%0.290.290.001180131ProtobufJavaHelpers::Varinter.to_varint
0.190.050.1413/14Gem::Specification.load
0%0%0.290.050.2314Kernel.eval
0.230.050.1814/1182416Class#new
0.270.270.00786653/786836Protobuf::Field::StringField(singleton)#set_field
0%0%0.280.280.00786836Array#delete
0.270.190.08786652/786915Protobuf::Field::IntegerField#decode
0%0%0.270.190.08786915Numeric#nonzero?
0.240.000.241/1Kernel.require
0%0%0.240.000.241Gem::Specification.load_defaults
0.240.000.241/1Gem::Specification.each_spec
0.240.000.241/1Gem::Specification.load_defaults
0%0%0.240.000.241Gem::Specification.each_spec
0.240.000.241/1Gem::Specification.each_gemspec
0.240.000.241/1Gem::Specification.each_spec
0%0%0.240.000.241Gem::Specification.each_gemspec
0.240.000.241/395067Array#each
0.210.000.211/2Bundler::Source::Rubygems#installed_specs
0%0%0.240.000.232Bundler::Index.build
0.160.000.161/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0.230.150.08393326/393594Protobuf::Field::EnumField#encode
0%0%0.230.150.08393594Protobuf::Enum#to_i
0.100.100.00393326/786790Protobuf::Field::StringField#encode
0.130.130.00393326/786790Protobuf::Field::StringField#decode
0%0%0.230.230.00786790String#+
0%0%0.230.230.002754943Kernel.nil?
0.220.000.221/142Bundler::Definition#converge_paths
0%0%0.230.000.23142Array#any?
0.220.000.221/1Bundler::Definition#specs_changed?
0.230.000.2338/38Bundler::LazySpecification#__materialize__
0%0%0.230.000.2338Bundler::Source::Rubygems#specs
0.210.000.211/1Bundler::Source::Rubygems#installed_specs
0.100.000.101/630Bundler::Dsl#gemspec
0%0%0.220.040.18630Array#map
0.100.000.101/2Bundler.load_gemspec
0%0%0.220.040.18287Array#select
0.220.000.221/1Bundler::Definition#initialize
0%0%0.220.000.221Bundler::Definition#converge_paths
0.220.000.221/142Array#any?
0.220.000.221/1Array#any?
0%0%0.220.000.221Bundler::Definition#specs_changed?
0.240.170.07466834/933668Protobuf::Field::EnumField#decode0.210.000.211/1Bundler::Definition#specs_for_source_changed?
0.280.200.08466834/933668Protobuf::Field::BaseField#set0.210.000.211/1Bundler::Definition#specs_changed?
2%1%0.530.380.15933668Protobuf::Field::IntegerField#decode0%0%0.210.000.211Bundler::Definition#specs_for_source_changed?
0.110.110.20 0.00933668/3267838##&0.201/2Bundler::Source::Path#specs
0.520.33 0.192801004/2801004Protobuf::Decoder.decode_each_field0.000.1912/13Array#each
2%1%0.520.330.192801004Protobuf::Varint.decode0%0%0.210.010.2013Gem::Specification.load
0.190.190.002801004/2801004ProtobufJavaHelpers::Varinter.read_varint0.050.1413/14Kernel.eval
0.500.500.21 0.004201813/4202318Protobuf::Message::Fields::ClassMethods.get_field0.211/1Bundler::Source::Rubygems#specs
2%2%0.510.510%0%0.210.000.211Bundler::Source::Rubygems#installed_specs
0.21 0.004202318Protobuf::Message::Fields::ClassMethods.field_store0.211/2Bundler::Index.build
0.470.060.4117/19(top)0.200.000.201/2Bundler::Definition#specs_for_source_changed?
2% 0%0.470.060.4119Kernel.load0%0.200.000.202Bundler::Source::Path#specs
0.370.030.352/1877Kernel.require0.200.000.202/2Bundler::Source::Path#local_specs
0.440.28 0.161400502/1400502Protobuf::Enum.fetch
1%1%0.440.28 0.161400502Protobuf::Enum.enum_for_tag_integer
0.430.280.15933668/933668Protobuf::Field::IntegerField#coerce!0.002359956/2362883String#encode!
1%1%0.430.280.15933668Protobuf::Field::IntegerField#acceptable?0%0%0.200.160.042362883Hash#default
0.430.010.421/2Bundler.setup0.200.000.202/2Bundler::Source::Path#specs
1% 0%0.430.010.420%0.200.000.20 2Bundler.definitionBundler::Source::Path#local_specs
0.340.20 0.000.340.20 1/1Bundler::Definition.buildBundler::Source::Path#load_spec_files
0.330.20 0.000.331/869Bundler::Runtime#requested_specs0.201/1Bundler::Source::Path#local_specs
1% 0%0.410%0.20 0.000.41869Kernel.send0.201Bundler::Source::Path#load_spec_files
0.330.19 0.000.331/1Bundler::Definition#requested_specs
0.150.080.07466834/1400655Protobuf::Field::StringField#encode_to_stream0.191/395067Array#each
0.210.120.09933668/1400655Protobuf::Field::IntegerField#encode0.190.000.192/7Kernel.require
1% 0%0.360.200.161400655Protobuf::Field::VarintField.encode0%0.190.000.197IO.open
0.160.160.001400655/1400655ProtobufJavaHelpers::Varinter.to_varint0.180.080.112/2IO#each_line
0.360.19 0.000.360.19 1/1Bundler.setupArray#each
1% 0%0.360%0.19 0.000.360.19 1Bundler::Runtime#setupBundler::Source::Path#validate_spec
0.330.19 0.000.330.19 1/1Bundler::Runtime#requested_specs
0.340.340.003267838/3267838IO::GenericWritable.<<
1%1%0.340.340.003267838StringIO#writeBundler::RubygemsIntegration#validate
0.340.19 0.000.340.19 1/1Bundler.definitionBundler::Source::Path#validate_spec
1% 0%0.340%0.19 0.000.340.19 1Bundler::Definition.buildBundler::RubygemsIntegration#validate
0.330.18 0.000.330.18 1/1Bundler::Dsl.evaluateBundler::UI::Silent#silence
0.330.19 0.000.330.19 1/1Bundler::Runtime#setupClass#new
1% 0%0.330%0.19 0.000.330.19 1Bundler::Runtime#requested_specsBundler::LockfileParser#initialize
0.330.000.331/869Kernel.send0.170.010.161/395067Array#each
0.330.190.19 0.000.331/1Kernel.send393326/393326Protobuf::Decoder.decode_each_field
1% 0%0.330%0.190.19 0.000.331Bundler::Definition#requested_specs393326StringIO#read
0.330.000.331/1Bundler::Definition#specs_for0.190.010.18215/215Kernel.loop
0%0%0.190.010.18215Bundler::SpecSet#spec_for_dependency
0.330.190.010.1817/17Class#new
0%0%0.190.010.1817Gem::Specification#initialize
0.110.11 0.000.331/1Bundler::Definition#requested_specs786652/1180209Protobuf::Field::EnumField#coerce!
1% 0%0.330%0.190.19 0.000.331Bundler::Definition#specs_for1180209Protobuf::Field::BaseField#type_class
0.320.000.321/1Bundler::Definition#specs0.180.080.112/2IO.open
0%0%0.180.080.112IO#each_line
0.330.18 0.000.330.18 1/1Bundler::Definition.buildBundler::RubygemsIntegration#validate
1% 0%0.330%0.18 0.000.330.18 1Bundler::Dsl.evaluateBundler::UI::Silent#silence
0.230.18 0.000.230.18 1/1Bundler::Dsl#to_definitionGem::Specification#validate
0.330.200.12933668/933668Protobuf::Message#set_field0.180.000.181/1Bundler::UI::Silent#silence
1% 0%0.330.200.12933668Protobuf::Field::BytesField#coerce!0%0.180.000.181Gem::Specification#validate
0.320.17 0.000.320.17 1/1Bundler::Definition#specs_forBundler::Dsl.evaluate
1% 0%0.320%0.17 0.000.320.17 1Bundler::Definition#specsBundler::Dsl#eval_gemfile
0.220.16 0.000.221/1Bundler::SpecSet#materialize0.161/984BasicObject#instance_eval
0.110.110.16 0.00933668/3267838Protobuf::Field::IntegerField#decode0.161/1Bundler::Definition#resolve
0%0%0.160.000.161Bundler::Definition#converge_locked_specs
0.140.140.160.16 0.00933668/3267838Protobuf::Field::IntegerField#encode1573304/1573304Protobuf::Decoder.decode_each_field
1%1%0.310.310%0%0.160.16 0.003267838##&1573304StringIO#eof
0.120.120.00466834/1400655Protobuf::Field::StringField#encode_to_stream
0.170.170.16 0.00933668/1400655Protobuf::Field::BaseField#encode_to_stream0.161/1Bundler::Index.build
1%1%0.300.300%0%0.16 0.001400655Protobuf::Field::BaseField#tag_encoded0.161Bundler::RubygemsIntegration::MoreFuture#all_specs
0.280.280.15 0.002801004/2805760Protobuf::Message#set_field
1%1%0.290.280.012805760##[]=0.151/1Gem::Specification.stubs
0.270.270.160.16 0.002801004/2801004##each1400337/1400337Array#each
1%1%0.270.270%0%0.160.16 0.002801004Protobuf::Field::BaseField#required?1400337Float#<
0%0%0.160.000.159Bundler::SpecSet#each
0.230.15 0.000.230.15 1/1Bundler::Dsl.evaluateBasicObject#instance_eval
1% 0%0.230%0.15 0.000.230.15 1Bundler::Dsl#to_definitionBundler::Dsl#gemspec
0.230.010.231/935061Class#new0.100.000.101/630Array#map
0.230.15 0.000.220.15 1/1Class#newBundler::RubygemsIntegration::MoreFuture#all_specs
0% 0%0.230.15 0.000.220.15 1Bundler::Definition#initializeGem::Specification.stubs
0%0%0.140.000.1410Bundler::SpecSet#sorted
0.130.000.134/4TSort.tsort
0.180.14 0.000.181/389Bundler::SpecSet#materialize0.1437/37Kernel.require
0% 0%0.220.020.20389##map!0.140.000.1437Protobuf::Message::Fields::ClassMethods.repeated
0.180.14 0.000.1838/38Bundler::LazySpecification#__materialize__0.1337/153Protobuf::Message::Fields::ClassMethods.define_field
0.220.13 0.000.220.13 1/1Bundler::Definition#specsBundler.definition
0% 0%0.220.13 0.000.220.13 1Bundler::SpecSet#materializeBundler.configure
0.180.13 0.000.181/389##map!0.131/1Bundler.configure_gem_home_and_path
0.120.120.13 0.002801004/4669248Protobuf::Message#set_field0.131/1Bundler.configure
0% 0%0.200.200.13 0.004669248Kernel.class0.131Bundler.configure_gem_home_and_path
0.19 0.120.08466834/466834Protobuf::Field::BaseField#set0.000.121/1Bundler.configure_gem_path
0.130.130.001572988/1575615Protobuf::Decoder.decode_each_field
0% 0%0.190.120.08466834Protobuf::Field::StringField#decode0.130.130.001575615Fixnum#==
0.190.190.13 0.002801004/2801004Protobuf::Varint.decode0.134/4Bundler::SpecSet#sorted
0% 0%0.190.190.13 0.002801004ProtobufJavaHelpers::Varinter.read_varint0.134TSort.tsort
0.130.000.134/4TSort.tsort
0.110.110.130.13 0.002801004/4669192Protobuf::Message#set_field786653/796051Protobuf::Field::BytesField#coerce!
0% 0%0.190.190.130.13 0.004669192Kernel.nil?796051Module#===
0.180.13 0.000.1838/38##map!0.134/4TSort.tsort
0% 0%0.180.13 0.000.1838Bundler::LazySpecification#__materialize__0.134TSort.tsort
0.150.13 0.000.1537/37Bundler::Source::Rubygems#specs0.134/4Enumerable#to_a
0.180.180.001400502/1400502Protobuf::Field::BaseField#set
0%0%0.180.180.11 0.001400502Protobuf::Field::BaseField#name0.1050/193Bundler::Index.sort_specs
0% 0%0.180.180.003269205Kernel.kind_of?0.130.010.12193Enumerable#sort_by
0.160.160.13 0.001400655/1400655Protobuf::Field::VarintField.encode0.134/8Enumerator#each
0% 0%0.160.160.13 0.001400655ProtobufJavaHelpers::Varinter.to_varint0.138TSort.tsort_each
0.130.000.134/4TSort.each_strongly_connected_component
0.120.13 0.000.123/285Gem::Specification.gemspec_stubs_in0.134/8Enumerable#to_a
0% 0%0.160.020.14285##select0.130.000.138Enumerator#each
0.120.13 0.000.1267/67Gem::StubSpecification#valid?0.134/8TSort.tsort_each
0.150.13 0.000.151/2Bundler::Source::Rubygems#installed_specs0.134/4TSort.tsort
0% 0%0.160.13 0.000.152Bundler::Index.build0.134Enumerable#to_a
0.140.13 0.000.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs0.134/8Enumerator#each
0.150.13 0.000.1537/37Bundler::LazySpecification#__materialize__0.134/4TSort.tsort_each
0% 0%0.150.13 0.000.1537Bundler::Source::Rubygems#specs0.134TSort.each_strongly_connected_component
0.150.13 0.000.151/1Bundler::Source::Rubygems#installed_specs0.134/122Method#call
0.150.13 0.000.151/1Bundler::Source::Rubygems#specs0.134/122TSort.each_strongly_connected_component
0% 0%0.150.130.000.13122Method#call
0.13 0.000.151Bundler::Source::Rubygems#installed_specs0.134/4Bundler::SpecSet#tsort_each_node
0.150.11 0.000.151/2Bundler::Index.build0.11118/118Bundler::SpecSet#tsort_each_child
0.140.13 0.000.141/1Bundler::Index.build0.134/4Method#call
0% 0%0.140.13 0.000.141Bundler::RubygemsIntegration::MoreFuture#all_specs0.134Bundler::SpecSet#tsort_each_node
0.140.13 0.000.141/1Gem::Specification.stubs0.134/395067Array#each
0.140.130.13 0.000.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs1179978/1180431Protobuf::Enum.enum_for_tag_integer
0% 0%0.140.130.13 0.000.141Gem::Specification.stubs1180431Array#first
0.120.070.06456834/466834Proc#call0.010.12118/118Array#each
0% 0%0.130.070.06466834StringIO.new0.120.010.12118TSort.each_strongly_connected_component_from
0% 0%0.130.120.010.12336Bundler::SpecSet#lookup
0.11 0.000.133Gem::Specification.gemspec_stubs_in0.108/50Bundler::Index.sort_specs
0.12 0.00 0.123/285##select1/1Bundler.configure_gem_home_and_path
0% 0% 0.120.030.0960Kernel.eval0.000.121Bundler.configure_gem_path
0.120.000.121/1Bundler.use_system_gems?
0.12 0.000.1167/1199Gem::StubSpecification#valid?0.121/1Bundler.configure_gem_path
0% 0% 0.12 0.000.111199Gem::StubSpecification#data0.121Bundler.use_system_gems?
0.110.010.1167/67Kernel.open
0%0%0.12 0.12 0.001400529Protobuf::Field::BaseField#type_class0.121/2Bundler.configured_bundle_path
0.12 0.00 0.1267/67##select1/2Bundler.use_system_gems?
0% 0.12 0.00 0.1267Gem::StubSpecification#valid?2Bundler.configured_bundle_path
0.100.010.091/218Bundler.settings
0.120.12 0.000.1167/1199Gem::StubSpecification#data393326/393326Class#new
0%0%0.120.120.00393326StringIO#initialize
0.110.01 0.1167/67Gem::StubSpecification#data0.00786653/787731Test::Resource#_protobuf_message_required_field_tags
0% 0% 0.110.01 0.1167Kernel.open0.00787731Kernel.dup
0%0%0.110.080.03583Module#module_eval
0.11 0.10 0.012803132/2803342##[]0.091/218Bundler.configured_bundle_path
0% 0% 0.110.100.012803342##default0.020.09218Bundler.settings
0.110.110.100.10 0.002801021/2801653##each383326/393326Proc#call
0% 0.11 0.11 0.002801653##nil?393326Protobuf::Message#to_proto
0.11 0.00 0.111/1Kernel.require77/79Kernel.send
0% 0.11 0.00 0.111Gem::Specification.load_defaults79Bundler::LockfileParser#parse_source
0.110.000.111/1Gem::Specification.each_spec0.100.020.0873/73Bundler::LockfileParser#parse_spec
0.110.070.04466834/467102Protobuf::Field::EnumField#encode0.000.11118/118Method#call
0% 0% 0.110.070.04467102Protobuf::Enum#to_i0.000.11118Bundler::SpecSet#tsort_each_child
0.11 0.000.111/1Gem::Specification.load_defaults0.108/50Bundler::SpecSet#lookup
0% 0.11 0.00 0.111Gem::Specification.each_spec50Bundler::Index.sort_specs
0.11 0.000.1050/193Enumerable#sort_by
0%0% 0.111/1Gem::Specification.each_gemspec0.110.00786652String#force_encoding
0.110.000.111/1Gem::Specification.each_spec0.100.020.0873/73Bundler::LockfileParser#parse_source
0% 0%0.110.000.111Gem::Specification.each_gemspec0.100.020.0873Bundler::LockfileParser#parse_spec
0.110.10 0.000.111/468431##each0.101/2Array#map
0% 0% 0.100.070.04467605BasicObject#!=0.000.102Bundler.load_gemspec
0.100.000.101/1Bundler.load_gemspec_uncached
0.10 0.001867336/1867336Protobuf::Decoder.decode_each_field0.101/1Bundler.load_gemspec
0% 0% 0.100.10 0.001867336StringIO#eof
0.101Bundler.load_gemspec_uncached
@@ -67,165 +67,156 @@

Total time: 70.11

- + - + - + - + - + - + - - - - - - - - - - - - + + + - + - + - + - + - + + + + + + + + + + - + - + + - - - - - - - - - - - + - + - + - - - + + + - + - + - + - + - + - + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + @@ -234,82 +225,82 @@

Total time: 70.11

- + - + - - + + - - - - + + + + - - - - + + + + - + - - + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - + - + @@ -318,821 +309,821 @@

Total time: 70.11

- + - - - - + + + + - + - - + - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - - + + - + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - + + - - + + - + - - + + - + - + - - + + - - + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - + - + - + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - + + - + - + - + - + - - + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - + - - - - + + + + - + - + - - + + - + - - + + - + - + - - + + - + - + - - + + - - - - - + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - + - + - - + + - + - - + + - + - - + + - + - - + + @@ -1140,165 +1131,165 @@

Total time: 70.11

- - + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - + - + - + - + - - - - - - - - - - + - - + + - + - - + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - + - + - + - + - + - + - + @@ -1307,1319 +1298,1236 @@

Total time: 70.11

- - - - - - - - - - + - + - - + + - + - - - - + + + + + + + + + + + + + - + - - - - + + + + - - - - + + + + - + - + - - + + - + + + + + + + + + + - + - - + + - + - - + + - + - - - - + + + + - + - - - - + + + + - - - - - + + + + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + - + - - - - + + + + - + - + - - + + - - - - - - - - - - - - - - + + + + + - - - - - - - - + + + + + + + + - + - + + - - - + + + - - - - + + + + - - - - - - + + + + + + - + - + + - - - + + - + - - - + + + - - - + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - + - - + + - - + + - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + - + - - - - + + + + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + - + - + - - + + - + - + - - - - + + + + - - - - - - + + + + + + - + - - - - - + + + + + - - + - - - - - - - - - - + - - - + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - + - - + + - + - - + + - + - - - - + + + + - + - - - - + + + + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - + + + + - + - - - + + + - + - - - - + + + + - - - - - - - - - - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - + + - - + + - - - - - - - - - - - + + - - + + - - + + - + - - - - - + + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - - + + - - - - - + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + - + - - - - - + + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - - - - - + + + + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + + + + + + + + + + - + + - - + + - - + + + + + + + + + + + - + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - + + + - + - - - - + + + + - + - - + + - - - - + + + + - + - - + + - + - + - - + + - + - - - - + + + + - - - - + + + + - + - + - - + + - + - - + + - + - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - - + + - + - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - + - - + + + - - - + + - - + + + - + + + + + + + + + + @@ -2638,7 +2546,7 @@

Total time: 70.11

- + @@ -2666,114 +2574,151 @@

Total time: 70.11

- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - - - + + + - + - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -2782,170 +2727,179 @@

Total time: 70.11

- + - + - - + + - + - + - + - + - - + + - + - - + + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - + - + - + - + - - - - - + + + + + + + + + + + + + + - - - - + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + + - + - + - + - + - + - + @@ -2954,201 +2908,192 @@

Total time: 70.11

- + - + - + - + - - - - + + + + - - + + + + + + + + + + + - - + + - + - - - - - + + + + + - - - - - - - - - - - - + + + - - + + - + - - - - + + + + - - - - - + + + + + - + - - + + - + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - + + - - - - - + + + + + - + + - - + + - - + + - - - + + - - + + - - + + - - + + @@ -3169,48 +3114,20 @@

Total time: 70.11

- + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -3219,693 +3136,751 @@

Total time: 70.11

- + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - + + + - - - - - - - - - - + - - + - - - - - - - - - - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - - - - + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - + - + - + - + - + - + - + - + - + - - - - + + + + + + + + + + + + + - - - + + + - + + - - - - - + + + + + - - - - - - + + + + + - - - - - + + + + + - + - - + - - + + + - + - - - - - + + + + + - - - - + + + + - + + + + + + + + + + - + - + - + - + - + - + - + - + - + - - - + + + - - - - - + + + + + - + - - - - - + + + + + - + - - + - - + + + - - - - - + + + + + - + + + + + + + + + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + - - - - + + - - - - - + + + + + - + - + + - - - + + - + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - + + - - - + + - + + - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + + - - - + + - - - - - - - - - - - - - - + + + + + - + - + - - - + + + + + + + + + + + + - - - + + + - + + - + + - - - + + - - + + - - - + + - - - - - - - - - - - - - + + + + + - - - + + + - - - + + - - + - - + + + + + + + + + + + + - - + + + - - + + - - + + - - + + - - + + - - - - + + + + - - - - - + + + + + - + - - + + @@ -3913,128 +3888,118 @@

Total time: 70.11

- - + + - - + + - + - + - + - + - - + + - + - - + - - + + + - - + - - + + + - - + - - - - - - - - - - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -4042,152 +4007,171 @@

Total time: 70.11

- + - + - + - + - + - + - - + + - + - - - + + + - - - - - + + + + + - + - + - - - - - - - - - - - - - + + + + - - - - - + + + + + - + + + + + + + + + + + - - - + + + - - + - - + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + - - + + - + - + - + - + - + - + - + - + - - + + @@ -4195,113 +4179,122 @@

Total time: 70.11

- - + + - + - + - - - + + + - + - + - - - + + + - - - - - + + + + + - + + + + + + + + + + + + - - - + + + + + + + + + + + - - - - - - + + + + + - + - + - + - + - + - + - + - + - + - - - + + + - + - + + - - - + + - - - - - - - - - - - - + + + - + @@ -4320,7 +4313,7 @@

Total time: 70.11

- + @@ -4329,13 +4322,13 @@

Total time: 70.11

- + - + - + @@ -4343,49 +4336,49 @@

Total time: 70.11

- - + + - + - - + + - + - + - + - + - + - + - + - + - + - - - + + + - + @@ -4404,7 +4397,7 @@

Total time: 70.11

- + @@ -4413,26 +4406,26 @@

Total time: 70.11

- + - - - - - + + + + + - - - - + + + + - + @@ -4451,7 +4444,7 @@

Total time: 70.11

- + @@ -4479,16 +4472,16 @@

Total time: 70.11

- + - + - + @@ -4507,16 +4500,16 @@

Total time: 70.11

- + - + - + @@ -4535,7 +4528,7 @@

Total time: 70.11

- + @@ -4544,7 +4537,7 @@

Total time: 70.11

- + @@ -4563,7 +4556,7 @@

Total time: 70.11

- + @@ -4572,7 +4565,7 @@

Total time: 70.11

- + @@ -4580,7 +4573,7 @@

Total time: 70.11

- + @@ -4589,113 +4582,47 @@

Total time: 70.11

- - - - - - - - - - + - + - - - + + + - - - - - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - + + + - + @@ -4714,7 +4641,7 @@

Total time: 70.11

- + @@ -4742,62 +4669,44 @@

Total time: 70.11

- + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - + - - - + + + - + - - + + @@ -4805,8 +4714,8 @@

Total time: 70.11

- - + + @@ -4816,7 +4725,7 @@

Total time: 70.11

- + @@ -4825,26 +4734,26 @@

Total time: 70.11

- + - + - + - - - + + + - + - - + + @@ -4852,20 +4761,10 @@

Total time: 70.11

- - + + - - - - - - - - - - @@ -4873,7 +4772,7 @@

Total time: 70.11

- + @@ -4882,108 +4781,80 @@

Total time: 70.11

- + - + - - - - - + + + + + - + - + - + - - - - - - - - - - - - - - - - - - - - - + + - + - - - + + + - - - - - - - - - - - + + - + - + - + - + - + - + - + @@ -4991,86 +4862,58 @@

Total time: 70.11

- + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - + + - + - - + + @@ -5078,8 +4921,8 @@

Total time: 70.11

- - + + @@ -5088,8 +4931,8 @@

Total time: 70.11

- - + + @@ -5097,46 +4940,27 @@

Total time: 70.11

- - + + - + - - - - - - - - - - - - - - - - - - - - - + + - + - - + + @@ -5144,27 +4968,27 @@

Total time: 70.11

- - + + - + - - + + - + - - + + @@ -5172,205 +4996,224 @@

Total time: 70.11

- - + + - + + + + + + + + + + + - - - - + + + + - - + - + - - - + + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - - - - - + + + + + - - - - - + + + + + - + + - + - + - + + + + + + + + + + - + - + - - - + + + - + - + - + - + - + - + - + - + - + - - - + + + - + - - + - - + + + - - + - - + + + - - + - + - - + + - - - + + + + - + - - + + - - + - - + + - + - + - - - + + + - + - - + + @@ -5378,27 +5221,27 @@

Total time: 70.11

- - + + - + - - + + - + - - + + @@ -5406,27 +5249,27 @@

Total time: 70.11

- - + + - + - - + + - + - - + + @@ -5434,94 +5277,93 @@

Total time: 70.11

- - + + - + - - - - - + + + + + - + - - - + + + - - - + + + - - + + - - - + + - - - + + + + - - + + - - - - - + + + + - + - - - + + + - - - + + + - + - - + + - - + + @@ -5529,46 +5371,28 @@

Total time: 70.11

- - + + - - - - - - - - - - - - - - - - - - - - - + + + - + - - + + @@ -5576,75 +5400,56 @@

Total time: 70.11

- - + + - + - + - - + + - - - - - - - - - - + - - - - - - - - - - - - + + - + - - - - + + + + - - - - + + + + - + - - + + @@ -5652,1270 +5457,1272 @@

Total time: 70.11

- - - - - - - - - - - + + - - + - + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + - - - + + + + - - - - - - - - - - + + - - - - - - - - + + + + + + + + - - + + + - - - - + + + + + - - + + + + + + + + + - - - - - - - + + + + + + - - - - + + + + + + + + + - + + - + - + + + - - + + + + - - - - - + - - - - - - - + - - - - + + + - + - - + + + + + - - - - - - - - + + - - - - - + + + + + + + + - + - - + - + + - - - - - - - - - - + + + + + + + - - - - - + + + + + + + - + + + - + + + + + - - - - + - + + + + + - - + + + + + + - - - - - - - - - + - + + + - - - - - - - - - - - - - - - - + + - + + + + - - - + + + + + + + + + + + - - - + + - - - - - - + + - + + + + + + + - + + - - - - - - + - + + + + + + + + + + + - - - - - - + + + + + + - + + + + + - - - + + + - - - - - - - - - - - - - - + + + - - + + + - - - - + + + + + - - - + + + + + + - - - + - + + - - - - - - - - + + + + + + + + + - - - - + + + + + - + - - - + + - - - - - + + - - - - - + - - + - - - + + + - + + + + + + - - + + - - - - + + - - - + + + + - - + + - - - - - - - + + + + + + + + - - - - - + - - - - - - - - - - + - - - - - - + + + + + + + - + - - - - - - - + + - + + + + + - - + + + - - + + + + + - - - - + + + - - - - - + + + - - - + + + + + + - + + + + + + + + + + - - + - + - - + + - - + + + + - + + + + - + - - - - - + + - - + + - + - - + + + + + + - - - + + + + - - + + + + + + + + - - - - - - + - - - + + - + + + + - - - - - + - - - - - - - - - - - - - + + + + + + - - - - - - - - - + + + - - + + + + - - - - + + - + + + + - - - + - - + - + + + - + - - - + - - + + + - - - - - + + - - - + + + + + - + - - - - + + + - + + + - - + + + + + - - - - - - + + - - + + + + + + - - - + - + - - - - + + - + + + - - + + + + + - - + + - + + - + + + - + + + + - - + + + + + - - - - - - + - - + + + + - - - + + - + + - - - - - + - + + + + - - + - - + + + + + + - + - + @@ -6924,6 +6731,7 @@

Total time: 70.11

+ @@ -6932,18 +6740,13 @@

Total time: 70.11

- - - - - - + @@ -6953,41 +6756,41 @@

Total time: 70.11

- + + - + - - + - - + + @@ -7003,6 +6806,7 @@

Total time: 70.11

+ @@ -7013,13 +6817,11 @@

Total time: 70.11

- - @@ -7030,6 +6832,7 @@

Total time: 70.11

+ @@ -7039,7 +6842,6 @@

Total time: 70.11

- From 98d5c1435108154bb0fabaeedb55d6488aadc1b7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 26 Dec 2018 09:03:35 -0700 Subject: [PATCH 1106/1191] remove respond_to in to_hash --- lib/protobuf/field/base_field.rb | 107 ++---------------- .../field/base_field_method_definitions.rb | 24 +++- lib/protobuf/message.rb | 4 +- 3 files changed, 30 insertions(+), 105 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d34eb612..6550b498 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -66,6 +66,7 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl define_field_and_present_p! define_set_field! define_set_method! + define_to_message_hash! set_default_value! tag_encoded end @@ -142,6 +143,14 @@ def define_set_field! end end + def define_to_message_hash! + if message? || enum? || repeated? || map? + ::Protobuf::Field::BaseFieldMethodDefinitions.define_to_hash_value_to_message_hash!(self) + else + ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_to_message_hash!(self) + end + end + def deprecated? @deprecated end @@ -162,77 +171,6 @@ def enum? false end -# def define_field_method! -# if repeated? -# def field?(values) -# values.key?(fully_qualified_name) && values[fully_qualified_name].present? -# end -# else -# def field?(values) -# values.key?(fully_qualified_name) -# end -# end -# end - -# def define_for_serialization! -# set_map! -# -# if map? -# if required? -# def for_serialization(values) -# value = values[fully_qualified_name] -# -# if value.nil? -# fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{name} does not have a value." -# else -# # on-the-wire, maps are represented like an array of entries where -# # each entry is a message of two fields, key and value. -# array = Array.new(value.size) -# i = 0 -# value.each do |k, v| -# array[i] = type_class.new(:key => k, :value => v) -# i += 1 -# end -# value = array -# end -# -# value -# end -# else -# def for_serialization(values) -# value = values[fully_qualified_name] -# -# unless value.nil? -# # on-the-wire, maps are represented like an array of entries where -# # each entry is a message of two fields, key and value. -# array = Array.new(value.size) -# i = 0 -# value.each do |k, v| -# array[i] = type_class.new(:key => k, :value => v) -# i += 1 -# end -# value = array -# end -# -# value -# end -# end -# else -# if required? -# def for_serialization(values) -# value = values[fully_qualified_name] -# fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{name} does not have a value." if value.nil? -# -# value -# end -# else -# def for_serialization(values) -# values[@fully_qualified_name] -# end -# end -# end -# end - def message? false end @@ -282,33 +220,6 @@ def define_set_method! end end -# # FIXME: need to cleanup (rename) this warthog of a method. -# def set(message_instance, bytes) -# return message_instance.set_field(name, decode(bytes), true, self) unless repeated? -# -# if map? -# hash = message_instance[name] -# entry = decode(bytes) -# # decoded value could be nil for an -# # enum value that is not recognized -# hash[entry.key] = entry.value unless entry.value.nil? -# return hash[entry.key] -# end -# -# return message_instance[name] << decode(bytes) unless packed? -# -# array = message_instance[name] -# stream = StringIO.new(bytes) -# -# if wire_type == ::Protobuf::WireType::VARINT -# array << decode(Varint.decode(stream)) until stream.eof? -# elsif wire_type == ::Protobuf::WireType::FIXED64 -# array << decode(stream.read(8)) until stream.eof? -# elsif wire_type == ::Protobuf::WireType::FIXED32 -# array << decode(stream.read(4)) until stream.eof? -# end -# end - def tag_encoded @tag_encoded ||= begin case diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 62a0963d..ba64fce9 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -11,10 +11,26 @@ def self.fully_qualified_name_string(selph) fully_qualified_name end + def self.define_to_hash_value_to_message_hash!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def to_message_hash(values, result) + result["#{selph.name}"] = value_from_values(values).to_hash_value + end + RUBY + end + + def self.define_base_to_message_hash!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def to_message_hash(values, result) + result["#{selph.name}"] = value_from_values(values) + end + RUBY + end + def self.define_base_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - message_instance.set_field(name, decode(bytes), true, self) + message_instance.set_field("#{selph.name}", decode(bytes), true, self) end RUBY end @@ -22,7 +38,7 @@ def set(message_instance, bytes) def self.define_map_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - hash = message_instance[name] + hash = message_instance["#{selph.name}"] entry = decode(bytes) # decoded value could be nil for an # enum value that is not recognized @@ -35,7 +51,7 @@ def set(message_instance, bytes) def self.define_repeated_not_packed_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - message_instance[name] << decode(bytes) + message_instance["#{selph.name}"] << decode(bytes) end RUBY end @@ -43,7 +59,7 @@ def set(message_instance, bytes) def self.define_repeated_packed_set_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) - array = message_instance[name] + array = message_instance["#{selph.name}"] stream = ::StringIO.new(bytes) if wire_type == ::Protobuf::WireType::VARINT diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c06e36e6..98297d5c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -137,9 +137,7 @@ def to_hash @values.each_key do |field_name| field = _protobuf_message_field[field_name] - value = field.value_from_values(@values) - hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value - result[field.name] = hashed_value + field.to_message_hash(@values, result) end result From 10c7ee53d614d32aa7c70c210ba63869874e469f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 26 Dec 2018 10:27:24 -0700 Subject: [PATCH 1107/1191] start by copying string and dump the tag_encoded when we write the encode_to_stream methods --- lib/protobuf/field/base_field_method_definitions.rb | 6 +++--- lib/protobuf/field/string_field.rb | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index b83c5b5f..ce6a3bf5 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -33,7 +33,7 @@ def self.define_repeated_packed_encode_to_stream_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) packed_value = value.map { |val| encode(val) }.join - stream << "\#{tag_encoded}\#{::Protobuf::Field::VarintField.encode(packed_value.size)}\#{packed_value}" + stream << #{selph.tag_encoded.dump} << "\#{::Protobuf::Field::VarintField.encode(packed_value.size)}\#{packed_value}" end RUBY end @@ -43,7 +43,7 @@ def self.define_base_encode_to_stream_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) - stream << tag_encoded << encode(value) + stream << #{selph.tag_encoded.dump} << encode(value) end RUBY end @@ -54,7 +54,7 @@ def self.define_repeated_not_packed_encode_to_stream_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) value.each do |val| - stream << tag_encoded << encode(val) + stream << #{selph.tag_encoded.dump} << encode(val) end end RUBY diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index fa6f33cf..8889816a 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -43,13 +43,12 @@ def encode(value) end def encode_to_stream(value, stream) - if value.encoding != ::Protobuf::Field::StringField::ENCODING - value = "" + value - value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + new_value = "" + value + if new_value.encoding != ::Protobuf::Field::StringField::ENCODING + new_value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") end - byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) - stream << tag_encoded << byte_size << value + stream << tag_encoded << ::Protobuf::Field::VarintField.encode(new_value.bytesize) << new_value end def json_encode(value) From fe1b5050fb5ca416c026dc69af812f7f25718904 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 26 Dec 2018 11:36:36 -0700 Subject: [PATCH 1108/1191] move all encode_to_stream methods to definitions --- lib/protobuf/field/base_field.rb | 4 + .../field/base_field_method_definitions.rb | 30 +- lib/protobuf/field/bytes_field.rb | 7 - lib/protobuf/field/string_field.rb | 9 - profile.html | 7778 +++++++---------- 5 files changed, 3046 insertions(+), 4782 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 9f185582..7cb668b7 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -113,6 +113,10 @@ def define_encode_to_stream! ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_packed_encode_to_stream_method!(self) elsif repeated? ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_not_packed_encode_to_stream_method!(self) + elsif message? || type_class == ::Protobuf::Field::BytesField + ::Protobuf::Field::BaseFieldMethodDefinitions.define_bytes_encode_to_stream_method!(self) + elsif type_class == ::Protobuf::Field::StringField + ::Protobuf::Field::BaseFieldMethodDefinitions.define_string_encode_to_stream_method!(self) else ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_encode_to_stream_method!(self) end diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index ce6a3bf5..f4207b57 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -28,8 +28,6 @@ def to_message_hash(values, result) end def self.define_repeated_packed_encode_to_stream_method!(selph) - return if selph.respond_to?(:encode_to_stream) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) packed_value = value.map { |val| encode(val) }.join @@ -38,9 +36,31 @@ def encode_to_stream(value, stream) RUBY end - def self.define_base_encode_to_stream_method!(selph) - return if selph.respond_to?(:encode_to_stream) + def self.define_bytes_encode_to_stream_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def encode_to_stream(value, stream) + value = value.encode if value.is_a?(::Protobuf::Message) + byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) + + stream << #{selph.tag_encoded.dump} << byte_size << value + end + RUBY + end + + def self.define_string_encode_to_stream_method!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def encode_to_stream(value, stream) + new_value = "" + value + if new_value.encoding != ::Protobuf::Field::StringField::ENCODING + new_value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + end + stream << #{selph.tag_encoded.dump} << ::Protobuf::Field::VarintField.encode(new_value.bytesize) << new_value + end + RUBY + end + + def self.define_base_encode_to_stream_method!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) stream << #{selph.tag_encoded.dump} << encode(value) @@ -49,8 +69,6 @@ def encode_to_stream(value, stream) end def self.define_repeated_not_packed_encode_to_stream_method!(selph) - return if selph.respond_to?(:encode_to_stream) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) value.each do |val| diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 9546780e..40aa3fbe 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -46,13 +46,6 @@ def encode(value) "#{string_size}#{value_to_encode}" end - def encode_to_stream(value, stream) - value = value.encode if value.is_a?(::Protobuf::Message) - byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) - - stream << tag_encoded << byte_size << value - end - def wire_type ::Protobuf::WireType::LENGTH_DELIMITED end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 8889816a..a59fd652 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -42,15 +42,6 @@ def encode(value) "#{::Protobuf::Field::VarintField.encode(value_to_encode.size)}#{value_to_encode}" end - def encode_to_stream(value, stream) - new_value = "" + value - if new_value.encoding != ::Protobuf::Field::StringField::ENCODING - new_value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") - end - - stream << tag_encoded << ::Protobuf::Field::VarintField.encode(new_value.bytesize) << new_value - end - def json_encode(value) value end diff --git a/profile.html b/profile.html index 0afe829f..2e13a6ae 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 69.40

+

Total time: 63.12

%Total
100% 0%70.1169.40 0.0070.1169.40 0 (top)
60.2060.09 0.0060.2060.09 1/1 Benchmark::IPS.ips
2.840.112.731/5Fixnum#times
2.630.012.622.650.002.65 2/115 Kernel.require
2.572.43 0.002.572.42 5/1904 Kernel.require
1.842.400.122.281/5Fixnum#times
1.80 0.191.651.61 24/26 Kernel.load
2.40 0.120.060.062/5Kernel.require
2.840.112.732.28 1/5 (top)
60.1960.08 0.0060.1960.08 2/5 Benchmark::IPS::Job#run
90% 0%63.150.1762.9862.570.1662.40 5 Fixnum#times
40.1540.08 0.0040.1540.08 1/1 Benchmark::IPS::Job#run_benchmark
20.0420.00 0.0020.0420.00 1/1 Benchmark::IPS::Job#run_warmup
1.130.021.1210000/3933261.080.011.0610000/415768 Protobuf::Message::Serialization::ClassMethods.decode_from
1.090.051.0410000/3933260.760.030.7310000/415768 Protobuf::Encoder.encode
0.350.31 0.020.3320000/11824160.2920000/1249742 Class#new
0.140.040.0910000/3933260.110.030.0810000/415768 Test::Resource#status=
0.130.000.134/3950670.110.010.114/417509 Bundler::SpecSet#tsort_each_node
0.170.010.161/3950670.140.020.121/417509 Bundler::LockfileParser#initialize
0.19 0.00 0.191/3950671/417509 Bundler::Source::Path#load_spec_files
0.240.25 0.000.241/3950670.251/417509 Gem::Specification.each_gemspec
0.700.010.6820/3950670.660.020.6420/417509 Kernel.require
20.041.6718.381/39506720.001.6818.321/417509 Benchmark::IPS::Job#run_warmup
40.1540.08 0.0240.131/39506740.061/417509 Benchmark::IPS::Job#run_benchmark
88%89% 2%62.051.8160.2439506761.891.8460.05417509 Array#each
57.551.9155.641400333/140033357.531.9455.591412256/1412256 Benchmark::IPS::Job::Entry#call_times
0.710.420.291400883/14008830.640.400.241412810/1412810 Benchmark::Timing.now
0.190.20 0.000.190.20 12/13 Gem::Specification.load
0.19 1/1 Bundler::Source::Path#validate_spec
0.170.01 0.16160/838Kernel.send0.160.001412260/1412260Float#<
0.160.160.13 0.001400337/1400337Float#<0.13160/838Kernel.send
0.120.11 0.010.120.10 118/118 TSort.each_strongly_connected_component_from
60.2060.09 0.0060.2060.09 1/1 (top)
85%86% 0%60.2060.09 0.0060.2060.09 1 Benchmark::IPS.ips
60.1960.08 0.0060.1960.08 1/1 Benchmark::IPS::Job#run
60.1960.08 0.0060.1960.08 1/1 Benchmark::IPS.ips
85%86% 0%60.1960.08 0.0060.1960.08 1 Benchmark::IPS::Job#run
60.1960.08 0.0060.1960.08 2/5 Fixnum#times
57.551.9155.641400333/140033357.531.9455.591412256/1412256 Array#each
82% 2%57.551.9155.64140033357.531.9455.591412256 Benchmark::IPS::Job::Entry#call_times
55.102.3252.785714009/571454055.042.2752.775853424/5853955 Proc#call
0.540.540.550.55 0.007113788/79003747265478/8096960 Fixnum#<
55.102.3252.785714009/571454055.042.2752.775853424/5853955 Benchmark::IPS::Job::Entry#call_times
78%79% 3%55.162.3552.81571454055.092.2952.805853955 Proc#call
24.192.1822.015330683/533068324.252.1522.105447656/5447656 Protobuf::Message#to_hash
12.140.2311.91383326/39332612.790.3012.49405768/415768 Protobuf::Message::Serialization::ClassMethods.decode_from
10.280.2810.00383326/3933269.780.329.45405768/415768 Protobuf::Encoder.encode
4.340.373.97766652/11824164.230.303.92811536/1249742 Class#new
1.680.381.550.25 1.30383326/393326405768/415768 Test::Resource#status=
0.100.100.110.11 0.00383326/393326405768/415768 Protobuf::Message#to_proto
40.1540.08 0.0040.1540.08 1/1 Fixnum#times
57% 0%40.1540.08 0.0040.1540.08 1 Benchmark::IPS::Job#run_benchmark
40.1540.08 0.0240.131/39506740.061/417509 Array#each
10.421.718.70393326/57240109.551.867.69415768/5863425 Protobuf::Message#each_field_for_serialization
22.019.3012.715330683/572401022.109.2512.855447656/5863425 Protobuf::Message#to_hash
46%15%32.4311.0121.41572401045%16%31.6511.1120.545863425 Hash#each_key
3.642.920.7110661366/106628853.382.760.6210895312/10896957 Kernel.respond_to?
3.590.343.25393326/393326Protobuf::Field::StringField(singleton)#encode_to_stream2.691.920.775863424/6279192Protobuf::Field::StringField(singleton)#value_from_values
2.491.810.685724009/61173352.661.890.775863424/6279192 Protobuf::Field::Int64Field(singleton)#value_from_values
2.431.710.725724009/6117335Protobuf::Field::StringField(singleton)#value_from_values2.340.691.66415768/415768Protobuf::Field::StringField#encode_to_stream
1.880.301.58393326/3933261.980.311.68415768/415768 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.710.301.40393326/3933261.720.291.42415768/415768 Protobuf::Field::Int64Field(singleton)#encode_to_stream
1.681.681.671.67 0.0011841344/1538694812142616/15890196 Hash#[]
1.281.281.411.41 0.0010661366/13026447Hash#[]=10895312/10895502Protobuf::Field::BaseField#name
1.241.241.311.31 0.0011841344/1420130212142616/14637226 Test::Resource#_protobuf_message_field
1.131.130.990.99 0.0010661366/10661556Protobuf::Field::BaseField#name10895312/13395045Hash#[]=
0.350.070.28393326/7866520.380.080.29415768/831536 Protobuf::Field::EnumField(singleton)#value_from_values
24.192.1822.015330683/533068324.252.1522.105447656/5447656 Proc#call
34% 3%24.192.1822.01533068324.252.1522.105447656 Protobuf::Message#to_hash
22.019.3012.715330683/572401022.109.2512.855447656/5863425 Hash#each_key
20.0420.00 0.0020.0420.00 1/1 Fixnum#times
28% 0%20.0420.00 0.0020.0420.00 1 Benchmark::IPS::Job#run_warmup
20.041.6718.381/39506720.001.6818.321/417509 Array#each
1.130.021.1210000/3933261.080.011.0610000/415768 Fixnum#times
12.140.2311.91383326/39332612.790.3012.49405768/415768 Proc#call
18%19% 0%13.270.2513.0339332613.870.3213.56415768 Protobuf::Message::Serialization::ClassMethods.decode_from
12.260.2811.97393326/39332612.810.3112.50415768/415768 Protobuf::Message::Serialization.decode_from
0.770.210.56393326/11824160.750.180.57415768/1249742 Class#new
12.260.2811.97393326/39332612.810.3112.50415768/415768 Protobuf::Message::Serialization::ClassMethods.decode_from
17%18% 0%12.260.2811.9739332612.810.3112.50415768 Protobuf::Message::Serialization.decode_from
11.971.5210.46393326/39332612.501.4711.04415768/415768 Protobuf::Decoder.decode_each_field
11.971.5210.46393326/39332612.501.4711.04415768/415768 Protobuf::Message::Serialization.decode_from
17%18% 2%11.971.5210.4639332612.501.4711.04415768 Protobuf::Decoder.decode_each_field
9.040.808.241179978/11799789.561.058.511247304/1247304 Protobuf::Message::Serialization.set_field_bytes
0.930.570.970.61 0.362359956/23599562494608/2494608 Protobuf::Varint.decode
0.190.190.210.21 0.00393326/393326415768/415768 StringIO#read
0.16 0.16 0.001573304/15733041663072/1663072 StringIO#eof
0.130.130.140.14 0.001572988/15756151662784/1665061 Fixnum#==
1.090.051.0410000/3933260.760.030.7310000/415768 Fixnum#times
10.280.2810.00383326/3933269.780.329.45405768/415768 Proc#call
16%15% 0%11.370.3311.0439332610.540.3510.18415768 Protobuf::Encoder.encode
11.040.4510.59393326/39332610.180.479.72415768/415768 Protobuf::Message#each_field_for_serialization
11.040.4510.59393326/39332610.180.479.72415768/415768 Protobuf::Encoder.encode
15%14% 0%11.040.4510.5939332610.180.479.72415768 Protobuf::Message#each_field_for_serialization
10.421.718.70393326/57240109.551.867.69415768/5863425 Hash#each_key
0.120.120.110.11 0.00393326/1179979415768/1247305 Test::Resource#_protobuf_message_required_field_tags
9.040.808.241179978/11799789.561.058.511247304/1247304 Protobuf::Decoder.decode_each_field
12%13% 1%9.040.808.2411799789.561.058.511247304 Protobuf::Message::Serialization.set_field_bytes
3.233.29 0.262.97393326/3933263.03415768/415768 Protobuf::Field::EnumField(singleton)#set
2.310.242.07393326/3933262.390.252.14415768/415768 Protobuf::Field::Int64Field(singleton)#set
2.242.27 0.271.98393326/3933262.00415768/415768 Protobuf::Field::StringField(singleton)#set
0.260.260.320.32 0.001179978/153869481247304/15890196 Hash#[]
0.200.200.240.24 0.001179978/142013021247304/14637226 Test::Resource#_protobuf_message_field
1.141.15 0.170.97393326/23599580.98415768/2494610 Protobuf::Field::EnumField(singleton)#set
1.340.161.18393326/2359958Protobuf::Field::Int64Field(singleton)#set1.380.241.14415768/2494610Test::Resource#status=
1.390.261.13393326/2359958Test::Resource#status=0.151.24415768/2494610Protobuf::Field::Int64Field(singleton)#set
1.530.241.29393326/23599581.490.211.28415768/2494610 Protobuf::Field::StringField(singleton)#set
2.970.562.41786654/23599582.900.552.35831538/2494610 Hash#each
11% 1%8.371.406.9723599588.311.326.992494610 Protobuf::Message#set_field
2.430.751.69786653/7866532.370.761.61831537/831537 Protobuf::Field::StringField(singleton)#set_field
2.150.511.64786653/7866532.190.501.69831537/831537 Protobuf::Field::Int64Field(singleton)#set_field
1.970.521.45786652/7866522.000.491.51831536/831536 Protobuf::Field::EnumField(singleton)#set_field
0.230.230.240.24 0.001179980/153869481247306/15890196 Hash#[]
0.19 0.19 0.001179980/142013021247306/14637226 Test::Resource#_protobuf_message_field
0.130.12 0.060.0735/11824160.0635/1249742 Kernel.require
0.230.24 0.050.1814/11824160.1914/1249742 Kernel.eval
0.350.31 0.020.3320000/11824160.2920000/1249742 Fixnum#times
0.440.40 0.010.43153/11824160.39153/1249742 Protobuf::Field.build
0.59 0.010.581/11824160.571/1249742 Bundler::Dsl#to_definition
0.770.210.56393326/11824160.750.180.57415768/1249742 Protobuf::Message::Serialization::ClassMethods.decode_from
4.340.373.97766652/11824164.230.303.92811536/1249742 Proc#call
10% 1%7.140.846.3011824166.950.736.221249742 Class#new
4.730.903.83786653/7866534.660.873.78831537/831537 Protobuf::Message#initialize
0.580.57 0.01 0.57 1/1 Bundler::Definition#initialize
0.430.39 0.020.420.37 153/153 Protobuf::Field::BaseField#initialize
0.190.000.191/1Bundler::LockfileParser#initialize
0.190.010.200.02 0.18 17/17 Gem::Specification#initialize
0.120.120.150.000.151/1Bundler::LockfileParser#initialize
0.130.13 0.00393326/393326415768/415768 StringIO#initialize
1.491.44 0.071.421.37 2/1904 Kernel.load
2.572.43 0.002.572.42 5/1904 (top)
2.622.64 0.002.622.64 115/1904 Kernel.require
9% 0%6.676.51 0.076.606.44 1904 Kernel.require
2.222.21 0.002.222.21 1/1 Bundler.setup
0.700.010.6820/3950670.660.020.6420/417509 Array#each
0.330.32 0.000.330.31 109/109 Protobuf::Message::Fields::ClassMethods.optional
0.240.26 0.000.240.26 1/1 Gem::Specification.load_defaults
0.19 2/7 IO.open
0.140.000.1437/37Protobuf::Message::Fields::ClassMethods.repeated
0.130.12 0.060.0735/11824160.0635/1249742 Class#new
0.120.060.062/5Fixnum#times0.000.1237/37Protobuf::Message::Fields::ClassMethods.repeated
0.110.000.111/1Concurrent::Utility::NativeExtensionLoader.load_native_extensions
4.730.903.83786653/7866534.660.873.78831537/831537 Class#new
6% 1%4.730.903.837866534.660.873.78831537 Protobuf::Message#initialize
3.663.60 0.702.97786653/7868642.90831537/831748 Hash#each
0.100.100.00831537/831706Kernel.block_given?
3.663.60 0.702.97786653/7868642.90831537/831748 Protobuf::Message#initialize
5% 1%3.753.68 0.753.007868642.93831748 Hash#each
2.970.562.41786654/23599582.900.552.35831538/2494610 Protobuf::Message#set_field
3.642.920.7110661366/106628853.382.760.6210895312/10896957 Hash#each_key
5% 4%3.642.930.72106628853%3.392.770.6310896957 Kernel.respond_to?
0.720.720.630.63 0.0010662776/1066277810896824/10896826 Kernel.respond_to_missing?
3.590.343.25393326/393326Hash#each_key
5%0%3.590.343.25393326Protobuf::Field::StringField(singleton)#encode_to_stream
2.540.801.74393326/393326Protobuf::Field::StringField#encode
0.490.200.29786652/2359956IO::GenericWritable.<<
0.230.230.00393326/1180131Protobuf::Field::BaseField#tag_encoded
3.233.29 0.262.97393326/3933263.03415768/415768 Protobuf::Message::Serialization.set_field_bytes
4% 0%3.233.29 0.262.973933263.03415768 Protobuf::Field::EnumField(singleton)#set
1.830.251.58393326/3933261.880.241.64415768/415768 Protobuf::Field::EnumField#decode
1.141.15 0.170.97393326/23599580.98415768/2494610 Protobuf::Message#set_field
0.140.140.001179978/15386948Protobuf::Enum.enum_for_tag_integer
0.230.230.001179980/15386948Protobuf::Message#set_field2.691.920.775863424/6279192Hash#each_key
0.260.260.001179978/15386948Protobuf::Message::Serialization.set_field_bytes
3%2%2.691.920.776279192Protobuf::Field::StringField(singleton)#value_from_values
0.340.490.49 0.000.34261/15386948Set#include?5863424/12143918Hash#fetch
1.681.680.0011841344/153869482.661.890.775863424/6279192 Hash#each_key
3%3%2.722.320.4015386948Hash#[]2%2.661.890.776279192Protobuf::Field::Int64Field(singleton)#value_from_values
0.330.460.46 0.000.33153/295Bundler::DepProxy#hash5863424/12143918Hash#fetch
2.630.012.622.650.002.65 2/115 (top)
3% 0%2.630.012.622.650.002.65 115 Kernel.require
2.622.64 0.002.622.64 115/1904 Kernel.require
2.540.801.74393326/393326Protobuf::Field::StringField(singleton)#encode_to_stream
3%1%2.540.801.74393326Protobuf::Field::StringField#encode
1.221.06 0.16393326/393326String#encode!
0.28 0.160.13393326/1180131Protobuf::Field::VarintField.encode0.001247304/15890196Protobuf::Enum.enum_for_tag_integer
0.100.100.240.24 0.00393326/786790String#+1247306/15890196Protobuf::Message#set_field
2.491.810.685724009/61173350.320.320.001247304/15890196Protobuf::Message::Serialization.set_field_bytes
1.671.670.0012142616/15890196 Hash#each_key
3%2%2.491.810.686117335Protobuf::Field::Int64Field(singleton)#value_from_values3%2.472.400.0715890196Hash#[]
2.390.252.14415768/415768Protobuf::Message::Serialization.set_field_bytes
3%0%2.390.252.14415768Protobuf::Field::Int64Field(singleton)#set
1.390.151.24415768/2494610Protobuf::Message#set_field
0.75 0.430.430.005724009/11842646Hash#fetch0.32415768/831536Protobuf::Field::IntegerField#decode
2.430.751.69786653/7866532.370.761.61831537/831537 Protobuf::Message#set_field
3% 1%2.430.751.697866532.370.761.61831537 Protobuf::Field::StringField(singleton)#set_field
0.590.380.20786653/786653Protobuf::Field::BytesField#coerce!0.530.410.13831537/1247305Test::Resource#_protobuf_message_required_field_tags
0.530.420.11786653/1179979Test::Resource#_protobuf_message_required_field_tags0.520.370.15831537/831537Protobuf::Field::StringField#coerce!
0.270.270.290.29 0.00786653/786836831537/831720 Array#delete
0.210.210.180.18 0.00786653/13026447831537/13395045 Hash#[]=
2.431.710.725724009/61173352.340.691.66415768/415768 Hash#each_key
3%2%2.431.710.726117335Protobuf::Field::StringField(singleton)#value_from_values0%2.340.691.66415768Protobuf::Field::StringField#encode_to_stream
0.430.430.005724009/11842646Hash#fetch0.590.240.351247304/2910376IO::GenericWritable.<<
2.310.242.07393326/393326Protobuf::Message::Serialization.set_field_bytes
3%0%2.310.36 0.242.07393326Protobuf::Field::Int64Field(singleton)#set0.11415768/416553BasicObject#!=
1.340.161.18393326/2359958Protobuf::Message#set_field0.320.170.15415768/1247457Protobuf::Field::VarintField.encode
0.730.430.30393326/786652Protobuf::Field::IntegerField#decode0.250.250.00415768/1247457Protobuf::Field::BaseField#tag_encoded
2.242.27 0.271.98393326/3933262.00415768/415768 Protobuf::Message::Serialization.set_field_bytes
3% 0%2.242.27 0.271.983933262.00415768 Protobuf::Field::StringField(singleton)#set
1.530.241.29393326/23599581.490.211.28415768/2494610 Protobuf::Message#set_field
0.450.280.17393326/3933260.510.260.25415768/415768 Protobuf::Field::StringField#decode
2.222.21 0.002.222.21 1/1 Kernel.require
3% 0%2.222.21 0.002.222.21 1 Bundler.setup
1.181.17 0.001.181.17 1/1 Bundler::Runtime#setup
1.020.010.02 1.00 1/2 Bundler.definition
2.150.511.64786653/7866532.190.501.69831537/831537 Protobuf::Message#set_field
3% 0%2.150.511.647866532.190.501.69831537 Protobuf::Field::Int64Field(singleton)#set_field
1.460.570.88786653/7866531.490.600.89831537/831537 Protobuf::Field::IntegerField#coerce!
0.120.120.140.14 0.00786653/13026447831537/13395045 Hash#[]=
1.970.521.45786652/7866522.000.491.51831536/831536 Protobuf::Message#set_field
2% 0%1.970.521.457866522.000.491.51831536 Protobuf::Field::EnumField(singleton)#set_field
1.270.330.93786652/7866521.340.360.98831536/831536 Protobuf::Field::EnumField#coerce!
0.130.130.110.11 0.00786652/13026447831536/13395045 Hash#[]=
1.880.301.58393326/3933261.980.311.68415768/415768 Hash#each_key
2% 0%1.880.301.583933261.980.311.68415768 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.150.240.91393326/3933261.250.260.99415768/415768 Protobuf::Field::EnumField#encode
0.290.150.14786652/23599560.300.160.13831536/2910376 IO::GenericWritable.<<
0.140.140.130.13 0.00393326/1180131415768/1247457 Protobuf::Field::BaseField#tag_encoded
1.840.191.6524/26(top)
2%0%1.840.191.6526Kernel.load
1.490.071.422/1904Kernel.require
1.830.251.58393326/3933261.880.241.64415768/415768 Protobuf::Field::EnumField(singleton)#set
2% 0%1.830.251.583933261.880.241.64415768 Protobuf::Field::EnumField#decode
1.040.310.73393326/3933260.320.72415768/415768 Protobuf::Field::EnumField#acceptable?
0.540.330.21393326/7866520.600.360.24415768/831536 Protobuf::Field::IntegerField#decode
0.140.040.0910000/393326Fixnum#times
1.680.381.30383326/393326Proc#call1.800.191.6124/26(top)
2% 0%1.810.421.39393326Test::Resource#status=1.800.191.6126Kernel.load
1.390.261.13393326/2359958Protobuf::Message#set_field1.440.071.372/1904Kernel.require
0.120.120.190.19 0.00786653/13026447Protobuf::Field::Int64Field(singleton)#set_field1247306/14637226Protobuf::Message#set_field
0.130.130.00786652/13026447Protobuf::Field::EnumField(singleton)#set_field
0.210.210.240.24 0.00786653/13026447Protobuf::Field::StringField(singleton)#set_field1247304/14637226Protobuf::Message::Serialization.set_field_bytes
1.281.281.311.31 0.0010661366/1302644712142616/14637226 Hash#each_key
2% 2%1.791.770.0213026447Hash#[]=1.741.740.0014637226Test::Resource#_protobuf_message_field
1.710.301.40393326/3933261.720.291.42415768/415768 Hash#each_key
2% 0%1.710.301.403933261.720.291.42415768 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.860.480.38393326/7866520.960.490.47415768/831536 Protobuf::Field::IntegerField#encode
0.380.150.22786652/23599560.350.160.19831536/2910376 IO::GenericWritable.<<
0.160.160.110.11 0.00393326/1180131415768/1247457 Protobuf::Field::BaseField#tag_encoded
0.190.190.001179980/14201302Protobuf::Message#set_field0.750.400.34415768/831536Protobuf::Field::EnumField#encode
0.200.200.001179978/14201302Protobuf::Message::Serialization.set_field_bytes0.960.490.47415768/831536Protobuf::Field::Int64Field(singleton)#encode_to_stream
2%1%1.710.900.81831536Protobuf::Field::IntegerField#encode
1.241.240.0011841344/14201302Hash#each_key0.470.240.23831536/1247457Protobuf::Field::VarintField.encode
2%2%1.621.62
0.340.34 0.0014201302Test::Resource#_protobuf_message_field831464/1662929Fixnum#&
0.680.390.29393326/786652Protobuf::Field::EnumField#encode0.110.030.0810000/415768Fixnum#times
0.860.480.38393326/786652Protobuf::Field::Int64Field(singleton)#encode_to_stream1.550.251.30405768/415768Proc#call
2%1%1.540.870.67786652Protobuf::Field::IntegerField#encode
0.370.210.16786652/1180131Protobuf::Field::VarintField.encode0%1.660.281.38415768Test::Resource#status=
0.310.310.00786559/1573117Fixnum#&1.380.241.14415768/2494610Protobuf::Message#set_field
1.460.570.88786653/7866531.490.600.89831537/831537 Protobuf::Field::Int64Field(singleton)#set_field
2% 0%1.460.570.887866531.490.600.89831537 Protobuf::Field::IntegerField#coerce!
0.710.520.18786653/7866530.720.510.21831537/831537 Protobuf::Field::IntegerField#acceptable?
0.560.200.37393326/1179987Protobuf::Field::EnumField#acceptable?0.110.110.00831536/13395045Protobuf::Field::EnumField(singleton)#set_field
0.830.300.53786652/1179987Protobuf::Field::EnumField#coerce!0.140.140.00831537/13395045Protobuf::Field::Int64Field(singleton)#set_field
1%0%1.390.490.901179987Protobuf::Enum.fetch
0.180.180.00831537/13395045Protobuf::Field::StringField(singleton)#set_field
0.790.530.271179978/1179978Protobuf::Enum.enum_for_tag_integer0.990.990.0010895312/13395045Hash#each_key
2%2%1.461.440.0213395045Hash#[]=
0.110.111.411.41 0.001179987/2754972Kernel.kind_of?10895312/10895502Hash#each_key
2%2%1.411.410.0010895502Protobuf::Field::BaseField#name
0.170.010.16160/838Array#each0.530.190.34415768/1247313Protobuf::Field::EnumField#acceptable?
1.100.001.101/838Bundler::Runtime#requested_specs0.850.300.55831536/1247313Protobuf::Field::EnumField#coerce!
1% 0%1.280.011.26838Kernel.send1.380.490.901247313Protobuf::Enum.fetch
1.100.001.101/1Bundler::Definition#requested_specs0.780.520.271247304/1247304Protobuf::Enum.enum_for_tag_integer
0.110.00 0.1177/79Bundler::LockfileParser#parse_source0.001247313/2912066Kernel.kind_of?
0.540.330.21393326/7866520.600.360.24415768/831536 Protobuf::Field::EnumField#decode
0.730.75 0.430.30393326/7866520.32415768/831536 Protobuf::Field::Int64Field(singleton)#set
1% 1%1.270.760.517866521.340.780.56831536 Protobuf::Field::IntegerField#decode
0.270.190.290.21 0.08786652/786915831536/831799 Numeric#nonzero?
0.250.250.260.26 0.00786558/1573117831465/1662929 Fixnum#&
1.270.330.93786652/7866521.340.360.98831536/831536 Protobuf::Field::EnumField(singleton)#set_field
1% 0%1.270.330.937866521.340.360.98831536 Protobuf::Field::EnumField#coerce!
0.830.85 0.300.53786652/11799870.55831536/1247313 Protobuf::Enum.fetch
0.110.110.120.12 0.00786652/1180209831536/1247535 Protobuf::Field::BaseField#type_class
1.221.060.16393326/393326Protobuf::Field::StringField#encode1.250.260.99415768/415768Protobuf::Field::EnumField(singleton)#encode_to_stream
1%1%1.221.060.16393326String#encode!
0.160.160.002359956/2362883Hash#default0%1.250.260.99415768Protobuf::Field::EnumField#encode
1.180.001.181/1Bundler.setup
1%0%1.180.001.181Bundler::Runtime#setup0.750.400.34415768/831536Protobuf::Field::IntegerField#encode
1.100.001.101/1Bundler::Runtime#requested_specs0.240.140.10415768/416036Protobuf::Enum#to_i
0.290.150.14786652/23599560.300.160.13831536/2910376 Protobuf::Field::EnumField(singleton)#encode_to_stream
0.380.150.22786652/23599560.350.160.19831536/2910376 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.490.200.29786652/2359956Protobuf::Field::StringField(singleton)#encode_to_stream0.590.240.351247304/2910376Protobuf::Field::StringField#encode_to_stream
1% 0%1.160.510.6523599561.240.560.682910376 IO::GenericWritable.<<
0.650.650.680.68 0.002359956/23599562910376/2910376 StringIO#write
1.150.240.91393326/393326Protobuf::Field::EnumField(singleton)#encode_to_stream0.130.000.13160/838Array#each
1.100.001.101/838Bundler::Runtime#requested_specs
1% 0%1.150.240.91393326Protobuf::Field::EnumField#encode
0.680.390.29393326/786652Protobuf::Field::IntegerField#encode1.240.001.23838Kernel.send
0.230.150.08393326/393594Protobuf::Enum#to_i1.100.001.101/1Bundler::Definition#requested_specs
1.131.131.17 0.0010661366/10661556Hash#each_key1.171/1Bundler.setup
1%1%1.131.130%1.17 0.0010661556Protobuf::Field::BaseField#name1.171Bundler::Runtime#setup
1.100.001.101/1Bundler::Runtime#requested_specs
1 Bundler::Runtime#requested_specs
1.10 1 Bundler::Definition#requested_specs
1.101.09 0.001.101.09 1/1 Bundler::Definition#specs_for
1.101.09 0.001.101.09 1/1 Bundler::Definition#requested_specs
1% 0%1.101.09 0.001.101.09 1 Bundler::Definition#specs_for
1.081.07 0.001.081.07 1/1 Bundler::Definition#specs
1.081.07 0.001.081.07 1/1 Bundler::Definition#specs_for
1% 0%1.081.07 0.001.081.07 1 Bundler::Definition#specs
0.570.54 0.000.570.54 1/1 Bundler::Definition#resolve
0.470.49 0.000.470.49 1/1 Bundler::SpecSet#materialize
1.040.310.73393326/3933260.320.72415768/415768 Protobuf::Field::EnumField#decode
1% 0% 1.040.310.733933260.320.72415768 Protobuf::Field::EnumField#acceptable?
0.560.200.37393326/11799870.530.190.34415768/1247313 Protobuf::Enum.fetch
0.100.100.00415768/1247535Protobuf::Field::BaseField#type_class
0.460.460.005863424/12143918Protobuf::Field::Int64Field(singleton)#value_from_values
0.490.490.005863424/12143918Protobuf::Field::StringField(singleton)#value_from_values
1%1%1.021.000.0212143918Hash#fetch
1.020.010.02 1.00 1/2 Bundler.setup 1% 0% 1.020.010.02 1.00 2 Bundler.definition
0.820.01 0.810.020.80 1/1 Bundler::Definition.build
0.130.14 0.000.130.14 1/1 Bundler.configure
0.930.570.970.61 0.362359956/23599562494608/2494608 Protobuf::Decoder.decode_each_field
1% 0%0.930.570.970.61 0.3623599562494608 Protobuf::Varint.decode
0.36 0.36 0.002359956/23599562494608/2494608 ProtobufJavaHelpers::Varinter.read_varint
0.430.430.005724009/11842646Protobuf::Field::StringField(singleton)#value_from_values
0.430.430.005724009/11842646Protobuf::Field::Int64Field(singleton)#value_from_values
1%1%0.920.910.0111842646Hash#fetch
0.820.01 0.810.020.80 1/1 Bundler.definition
1% 0%0.820.01 0.810.020.80 1 Bundler::Definition.build
0.790.78 0.000.790.78 1/1 Bundler::Dsl.evaluate
0.790.530.271179978/1179978Protobuf::Enum.fetch0.320.170.15415768/1247457Protobuf::Field::StringField#encode_to_stream
0.470.240.23831536/1247457Protobuf::Field::IntegerField#encode
1% 0% 0.790.530.271179978Protobuf::Enum.enum_for_tag_integer0.410.381247457Protobuf::Field::VarintField.encode
0.140.140.380.380.001247457/1247457ProtobufJavaHelpers::Varinter.to_varint
0.780.520.271247304/1247304Protobuf::Enum.fetch
1%0%0.780.520.271247304Protobuf::Enum.enum_for_tag_integer
0.160.16 0.001179978/153869481247304/15890196 Hash#[]
0.130.130.110.11 0.001179978/11804311247304/1247757 Array#first
0.790.78 0.000.790.78 1/1 Bundler::Definition.build
1% 0%0.790.78 0.000.790.78 1 Bundler::Dsl.evaluate
0.59 1/1 Bundler::Dsl#to_definition
0.170.16 0.000.170.16 1/1 Bundler::Dsl#eval_gemfile
0.720.720.0010662776/10662778Kernel.respond_to?0.510.21831537/831537Protobuf::Field::IntegerField#coerce!
1%1%0.720% 0.720.510.21831537Protobuf::Field::IntegerField#acceptable?
0.120.12 0.0010662778Kernel.respond_to_missing?831537/2912066Kernel.kind_of?
0.710.520.18786653/786653Protobuf::Field::IntegerField#coerce!0.680.680.002910376/2910376IO::GenericWritable.<<
1% 0%0.710.520.18786653Protobuf::Field::IntegerField#acceptable?
0.100.100%0.680.68 0.00786653/2754972Kernel.kind_of?2910376StringIO#write
0.710.420.291400883/14008830.640.400.241412810/1412810 Array#each
1% 0%0.710.420.2914008830%0.640.400.241412810 Benchmark::Timing.now
0.290.290.240.24 0.001400883/14008841412810/1412811 Process.clock_gettime
0.280.160.13393326/1180131Protobuf::Field::StringField#encode0.110.110.00415768/1247305Protobuf::Message#each_field_for_serialization
0.370.210.16786652/1180131Protobuf::Field::IntegerField#encode0.530.410.13831537/1247305Protobuf::Field::StringField(singleton)#set_field
0% 0%0.660.370.291180131Protobuf::Field::VarintField.encode0.640.520.131247305Test::Resource#_protobuf_message_required_field_tags
0.290.290.130.13 0.001180131/1180131ProtobufJavaHelpers::Varinter.to_varint831537/832615Kernel.dup
0.650.650.550.55 0.002359956/2359956IO::GenericWritable.<<7265478/8096960Benchmark::IPS::Job::Entry#call_times
0% 0%0.650.650.640.64 0.002359956StringIO#write8096960Fixnum#<
0.120.120.630.63 0.00393326/1179979Protobuf::Message#each_field_for_serialization
0.530.420.11786653/1179979Protobuf::Field::StringField(singleton)#set_field10896824/10896826Kernel.respond_to?
0% 0%0.640.540.111179979Test::Resource#_protobuf_message_required_field_tags0.630.630.0010896826Kernel.respond_to_missing?
0.110.110.260.26 0.00786653/787731Kernel.dup831465/1662929Protobuf::Field::IntegerField#decode
0.540.540.340.34 0.007113788/7900374Benchmark::IPS::Job::Entry#call_times831464/1662929Protobuf::Field::IntegerField#encode
0% 0%0.630.630.610.61 0.007900374Fixnum#<1662929Fixnum#&
1 Bundler::Dsl#to_definition
0.59 0.010.581/11824160.571/1249742 Class#new
0.590.380.20786653/786653Protobuf::Field::StringField(singleton)#set_field
0%0%0.590.380.20786653Protobuf::Field::BytesField#coerce!
0.130.130.00786653/796051Module#===
0.580.57 0.01 0.57 1/1
0% 0%0.580.57 0.01 0.57 1 Bundler::Definition#initialize
0.220.23 0.000.220.23 1/1 Bundler::Definition#converge_paths
0.400.000.401/6Bundler::Definition#resolve
0%0%0.570.000.576Bundler::SpecSet#for
0.570.010.566/6Kernel.loop
0.570.54 0.000.570.54 1/1 Bundler::Definition#specs
0% 0%0.570.54 0.000.570.54 1 Bundler::Definition#resolve
0.400.34 0.000.400.34 1/6 Bundler::SpecSet#for
0.160.19 0.000.160.19 1/1 Bundler::Definition#converge_locked_specs
0.570.010.566/6Bundler::SpecSet#for0.340.000.341/6Bundler::Definition#resolve
0% 0%0.570.010.560.530.000.53 6Kernel.loop
0.360.000.35240/240Set#add?Bundler::SpecSet#for
0.190.010.18215/215Bundler::SpecSet#spec_for_dependency
0.250.250.00786558/1573117Protobuf::Field::IntegerField#decode0.530.020.516/6Kernel.loop
0.310.310.00786559/1573117Protobuf::Field::IntegerField#encode0.530.020.516/6Bundler::SpecSet#for
0% 0%0.550.550.001573117Fixnum#&0.530.020.516Kernel.loop
0.460.010.46215/215Bundler::SpecSet#spec_for_dependency
0.140.140.110.11 0.00393326/1180131Protobuf::Field::EnumField(singleton)#encode_to_stream415768/1247457Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.160.160.130.13 0.00393326/1180131Protobuf::Field::Int64Field(singleton)#encode_to_stream415768/1247457Protobuf::Field::EnumField(singleton)#encode_to_stream
0.230.230.250.25 0.00393326/1180131Protobuf::Field::StringField(singleton)#encode_to_stream415768/1247457Protobuf::Field::StringField#encode_to_stream
0% 0%0.550.540.520.51 0.0111801311247457 Protobuf::Field::BaseField#tag_encoded
0.140.000.1337/153Protobuf::Message::Fields::ClassMethods.repeated0.520.370.15831537/831537Protobuf::Field::StringField(singleton)#set_field
0%0%0.520.370.15831537Protobuf::Field::StringField#coerce!
0.330.010.32109/153Protobuf::Message::Fields::ClassMethods.optional0.510.260.25415768/415768Protobuf::Field::StringField(singleton)#set
0% 0%0.480.010.47153Protobuf::Message::Fields::ClassMethods.define_field0.510.260.25415768Protobuf::Field::StringField#decode
0.460.180.18 0.000.45153/153Protobuf::Field.build415768/415906String#+
0.470.49 0.000.470.49 1/1 Bundler::Definition#specs
0% 0%0.470.49 0.000.470.49 1 Bundler::SpecSet#materialize
0.340.37 0.000.340.37 1/223 Array#map!
0.460.000.45153/153Protobuf::Message::Fields::ClassMethods.define_field0.010.46215/215Kernel.loop
0% 0% 0.460.010.46215Bundler::SpecSet#spec_for_dependency
0.35 0.000.45153Protobuf::Field.build0.34215/336Bundler::SpecSet#lookup
0.440.010.43153/1182416Class#new0.120.000.1237/153Protobuf::Message::Fields::ClassMethods.repeated
0.450.280.17393326/393326Protobuf::Field::StringField(singleton)#set0.310.010.30109/153Protobuf::Message::Fields::ClassMethods.optional
0% 0%0.450.280.17393326Protobuf::Field::StringField#decode0.440.010.43153Protobuf::Message::Fields::ClassMethods.define_field
0.130.130.41 0.00393326/786790String#+0.41153/153Protobuf::Field.build
0.430.020.42153/153Class#new0.350.000.34215/336Bundler::SpecSet#spec_for_dependency
0% 0%0.430.02 0.42153Protobuf::Field::BaseField#initialize0.010.41336Bundler::SpecSet#lookup
0.390.000.398/50Bundler::Index.sort_specs
0.340.37 0.000.340.37 1/223 Bundler::SpecSet#materialize
0% 0%0.390.42 0.010.390.41 223 Array#map!
0.340.37 0.000.340.37 39/39 Bundler::LazySpecification#__materialize__
0.160.41 0.000.161/984Bundler::Dsl#eval_gemfile0.41153/153Protobuf::Message::Fields::ClassMethods.define_field
0% 0%0.390.190.20984BasicObject#instance_eval0.410.000.41153Protobuf::Field.build
0.150.000.151/1Bundler::Dsl#gemspec0.400.010.39153/1249742Class#new
0.360.360.39 0.002359956/2359956Protobuf::Varint.decode0.3950/193Bundler::Index.sort_specs
0% 0%0.360.360.002359956ProtobufJavaHelpers::Varinter.read_varint0.410.010.40193Enumerable#sort_by
0.380.010.371378/1520Array#<=>
0.360.39 0.000.35240/240Kernel.loop0.398/50Bundler::SpecSet#lookup
0% 0%0.360.39 0.000.35240Set#add?0.3950Bundler::Index.sort_specs
0.340.39 0.000.34240/261Set#include?0.3950/193Enumerable#sort_by
0.390.020.37153/153Class#new
0%0%0.390.020.37153Protobuf::Field::BaseField#initialize
0.370.04 0.330.000.33144/1249Bundler::DepProxy#hash1378/1439Array#<=>
0% 0%0.350.000.351249Array#hash0.390.050.341439Gem::Version#<=>
0.320.300.30 0.000.32144/390Gem::Dependency#hash1224/1224Fixnum#>
0.350.070.28393326/786652Hash#each_key0.360.240.11415768/416553Protobuf::Field::StringField#encode_to_stream
0% 0%0.350.070.28786652Protobuf::Field::EnumField(singleton)#value_from_values0.380.250.13416553BasicObject#!=
0.340.380.38 0.000.34240/261Set#add?1247457/1247457Protobuf::Field::VarintField.encode
0% 0%0.340.380.38 0.000.34261Set#include?1247457ProtobufJavaHelpers::Varinter.to_varint
0.340.000.34261/15386948Hash#[]0.380.010.371378/1520Enumerable#sort_by
0%0%0.380.010.371520Array#<=>
0.370.040.331378/1439Gem::Version#<=>
0.340.380.080.29415768/831536Hash#each_key
0%0%0.380.080.29831536Protobuf::Field::EnumField(singleton)#value_from_values
0.37 0.000.340.37 39/39 Array#map!
0% 0%0.340.37 0.000.340.37 39 Bundler::LazySpecification#__materialize__
0.230.24 0.000.230.24 38/38 Bundler::Source::Rubygems#specs
0.320.360.36 0.000.32144/390Array#hash2494608/2494608Protobuf::Varint.decode
0% 0%0.340.010.33390Gem::Dependency#hash
0.320.310.01390/390Gem::Requirement#hash0.360.360.002494608ProtobufJavaHelpers::Varinter.read_varint
0.330.16 0.000.33153/295Hash#[]0.161/933Bundler::Dsl#eval_gemfile
0% 0% 0.330.140.19933BasicObject#instance_eval
0.15 0.000.33295Bundler::DepProxy#hash0.141/1Bundler::Dsl#gemspec
0.330.110.11 0.000.33144/1249Array#hash1247313/2912066Protobuf::Enum.fetch
0.330.120.12 0.000.33109/109Kernel.require831537/2912066Protobuf::Field::IntegerField#acceptable?
0% 0%0.330.000.33109Protobuf::Message::Fields::ClassMethods.optional
0.330.01 0.32109/153Protobuf::Message::Fields::ClassMethods.define_field0.320.002912066Kernel.kind_of?
0.320.00 0.310.01390/390Gem::Dependency#hash109/109Kernel.require
0% 0% 0.320.00 0.310.01390Gem::Requirement#hash109Protobuf::Message::Fields::ClassMethods.optional
0.100.100.310.010.30109/153Protobuf::Message::Fields::ClassMethods.define_field
0%0%0.300.30 0.00786653/2754972Protobuf::Field::IntegerField#acceptable?3743574Kernel.nil?
0.110.110.300.30 0.001179987/2754972Protobuf::Enum.fetch1224/1224Gem::Version#<=>
0% 0%0.310.310.300.30 0.002754972Kernel.kind_of?1224Fixnum#>
0.290.290.001400883/1400884Benchmark::Timing.now0.210.08831536/831799Protobuf::Field::IntegerField#decode
0% 0%0.290.290.001400884Process.clock_gettime0.300.210.08831799Numeric#nonzero?
0.29 0.29 0.001180131/1180131Protobuf::Field::VarintField.encode831537/831720Protobuf::Field::StringField(singleton)#set_field
0% 0.29 0.29 0.001180131ProtobufJavaHelpers::Varinter.to_varint831720Array#delete
0.190.050.140.040.15 13/14 Gem::Specification.load
0% 0%0.290.28 0.050.230.24 14 Kernel.eval
0.230.24 0.050.1814/11824160.1914/1249742 Class#new
0.270.270.23 0.00786653/786836Protobuf::Field::StringField(singleton)#set_field0.231/2Bundler::Source::Rubygems#installed_specs
0% 0%0.280.280.26 0.00786836Array#delete0.262Bundler::Index.build
0.270.190.08786652/786915Protobuf::Field::IntegerField#decode
0%0%0.270.190.08786915Numeric#nonzero?0.200.000.201/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0.240.26 0.000.240.26 1/1 Kernel.require
0% 0%0.240.26 0.000.240.26 1 Gem::Specification.load_defaults
0.240.26 0.000.240.25 1/1 Gem::Specification.each_spec
0.240.26 0.000.240.25 1/1 Gem::Specification.load_defaults
0% 0%0.240.26 0.000.240.25 1 Gem::Specification.each_spec
0.240.25 0.000.240.25 1/1 Gem::Specification.each_gemspec
0.240.25 0.000.240.25 1/1 Gem::Specification.each_spec
0% 0%0.240.25 0.000.240.25 1 Gem::Specification.each_gemspec
0.240.25 0.000.241/3950670.251/417509 Array#each
0.210.10 0.000.211/2Bundler::Source::Rubygems#installed_specs0.103/287Gem::Specification.gemspec_stubs_in
0% 0%0.240.000.232Bundler::Index.build0.250.050.20287Array#select
0.160.10 0.000.161/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0.230.150.08393326/393594Protobuf::Field::EnumField#encode0.1062/62Gem::StubSpecification#valid?
0% 0%0.230.150.08393594Protobuf::Enum#to_i0.240.050.20630Array#map
0.240.14 0.10415768/416036Protobuf::Field::EnumField#encode
0%0%0.240.14 0.100.00393326/786790Protobuf::Field::StringField#encode416036Protobuf::Enum#to_i
0.130.130.24 0.00393326/786790Protobuf::Field::StringField#decode0.2438/38Bundler::LazySpecification#__materialize__
0% 0%0.240.000.2438Bundler::Source::Rubygems#specs
0.230.00 0.231/1Bundler::Source::Rubygems#installed_specs
0.240.24 0.00786790String#+1412810/1412811Benchmark::Timing.now
0% 0%0.230.230.240.24 0.002754943Kernel.nil?1412811Process.clock_gettime
0.220.23 0.000.220.23 1/142 Bundler::Definition#converge_paths
0% 0%0.230.24 0.000.230.24 142 Array#any?
0.220.23 0.000.220.23 1/1 Bundler::Definition#specs_changed?
0.23 0.00 0.2338/38Bundler::LazySpecification#__materialize__1/1Bundler::Definition#initialize
0% 0.23 0.00 0.2338Bundler::Source::Rubygems#specs1Bundler::Definition#converge_paths
0.210.23 0.000.211/1Bundler::Source::Rubygems#installed_specs0.231/142Array#any?
0.100.23 0.000.101/630Bundler::Dsl#gemspec0.231/1Array#any?
0% 0%0.220.040.18630Array#map0.230.000.231Bundler::Definition#specs_changed?
0.210.000.211/1Bundler::Definition#specs_for_source_changed?
0.10 0.10 0.000.101/2Bundler.load_gemspec415768/1247535Protobuf::Field::EnumField#acceptable?
0.120.120.00831536/1247535Protobuf::Field::EnumField#coerce!
0% 0%0.220.040.18287Array#select0.230.230.001247535Protobuf::Field::BaseField#type_class
0.220.23 0.000.220.23 1/1Bundler::Definition#initializeBundler::Source::Rubygems#specs
0% 0%0.220.23 0.000.220.23 1Bundler::Definition#converge_pathsBundler::Source::Rubygems#installed_specs
0.220.23 0.000.221/142Array#any?0.231/2Bundler::Index.build
0.220.210.21 0.000.221/1Array#any?415768/415768Protobuf::Decoder.decode_each_field
0% 0%0.220.000.221Bundler::Definition#specs_changed?
0.210.00 0.211/1Bundler::Definition#specs_for_source_changed?0.00415768StringIO#read
1 Bundler::Definition#specs_for_source_changed?
0.20 1/2 Bundler::Source::Path#specs
0.190.20 0.000.190.20 12/13 Array#each
0% 0% 0.210.010.200.000.21 13 Gem::Specification.load
0.190.050.140.040.15 13/14 Kernel.eval
0.210.20 0.000.210.20 1/1Bundler::Source::Rubygems#specsBundler::Index.build
0% 0%0.210.20 0.000.210.20 1Bundler::Source::Rubygems#installed_specsBundler::RubygemsIntegration::MoreFuture#all_specs
0.210.19 0.000.211/2Bundler::Index.build0.191/1Gem::Specification.stubs
2 Bundler::Source::Path#specs
0.20 2/2 Bundler::Source::Path#local_specs
0.160.160.002359956/2362883String#encode!0.200.020.1817/17Class#new
0% 0% 0.200.160.042362883Hash#default0.020.1817Gem::Specification#initialize
2 Bundler::Source::Path#local_specs
0.20 1 Bundler::Source::Path#load_spec_files
0.19 0.00 0.191/3950671/417509 Array#each
7 IO.open
0.18 0.080.110.10 2/2 IO#each_line
1 Bundler::Source::Path#validate_spec
0.19 1/1 Bundler::RubygemsIntegration#validate
1 Bundler::RubygemsIntegration#validate
0.18 1/1 Bundler::UI::Silent#silence
0.00 0.19 1/1Class#newBundler::Definition#resolve
0% 0.00 0.19 1Bundler::LockfileParser#initialize
0.170.010.161/395067Array#eachBundler::Definition#converge_locked_specs
0.190.19 0.00393326/393326Protobuf::Decoder.decode_each_field0.191/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0% 0% 0.190.19 0.00393326StringIO#read
0.190.010.18215/215Kernel.loop
0%0% 0.190.010.18215Bundler::SpecSet#spec_for_dependency1Gem::Specification.stubs
0.190.01 0.1817/17Class#new
0%0%0.190.01 0.1817Gem::Specification#initialize
0.110.11 0.00786652/1180209Protobuf::Field::EnumField#coerce!415768/415906Protobuf::Field::StringField#decode
0% 0%0.190.190.001180209Protobuf::Field::BaseField#type_class
0.180.080.112/2IO.open
0%0% 0.180.080.112IO#each_line0.00415906String#+
1 Bundler::UI::Silent#silence
0.18 1 Gem::Specification#validate
0.170.000.171/1Bundler::Dsl.evaluate0.180.080.102/2IO.open
0% 0%0.170.000.171Bundler::Dsl#eval_gemfile
0.160.000.161/984BasicObject#instance_eval
0.160.000.161/1Bundler::Definition#resolve0.180.080.102IO#each_line
0% 0%0.160.17 0.000.161Bundler::Definition#converge_locked_specs0.179Bundler::SpecSet#each
0.16 0.16 0.001573304/1573304Protobuf::Decoder.decode_each_field1412260/1412260Array#each
0% 0.16 0.16 0.001573304StringIO#eof1412260Float#<
0.00 0.16 1/1Bundler::Index.buildBundler::Dsl.evaluate
0% 0.00 0.16 1Bundler::RubygemsIntegration::MoreFuture#all_specsBundler::Dsl#eval_gemfile
0.150.16 0.000.151/1Gem::Specification.stubs0.161/933BasicObject#instance_eval
0.16 0.16 0.001400337/1400337Array#each1663072/1663072Protobuf::Decoder.decode_each_field
0% 0.16 0.16 0.001400337Float#<1663072StringIO#eof
0%0%0.160.000.159Bundler::SpecSet#each
0.00 0.15 1/1BasicObject#instance_evalClass#new
0% 0.00 0.15 1Bundler::Dsl#gemspecBundler::LockfileParser#initialize
0.100.000.101/630Array#map0.140.020.121/417509Array#each
0.15 0.000.150.14 1/1Bundler::RubygemsIntegration::MoreFuture#all_specsBasicObject#instance_eval
0% 0% 0.15 0.000.151Gem::Specification.stubs
0%0%0.140.00 0.1410Bundler::SpecSet#sorted
0.130.000.134/4TSort.tsort1Bundler::Dsl#gemspec
0.140.00 0.1437/37Kernel.require0.001662784/1665061Protobuf::Decoder.decode_each_field
0% 0% 0.140.000.1437Protobuf::Message::Fields::ClassMethods.repeated
0.14 0.000.1337/153Protobuf::Message::Fields::ClassMethods.define_field1665061Fixnum#==
0.130.14 0.000.130.14 1/1 Bundler.definition
0% 0%0.130.14 0.000.130.14 1 Bundler.configure
0.130.14 0.000.130.14 1/1 Bundler.configure_gem_home_and_path
0.130.14 0.000.130.14 1/1 Bundler.configure
0% 0%0.130.14 0.000.130.14 1 Bundler.configure_gem_home_and_path
0.120.13 0.000.120.13 1/1 Bundler.configure_gem_path
0.13 0.13 0.001572988/1575615Protobuf::Decoder.decode_each_field
0%0%0.130.130.001575615Fixnum#==
0.130.000.134/4Bundler::SpecSet#sorted831537/832615Test::Resource#_protobuf_message_required_field_tags
0% 0% 0.130.000.134TSort.tsort
0.13 0.000.134/4TSort.tsort832615Kernel.dup
0.13 0.13 0.00786653/796051Protobuf::Field::BytesField#coerce!415768/415768Class#new
0% 0.13 0.13 0.00796051Module#===415768StringIO#initialize
0.13 0.00 0.134/4TSort.tsort1/1Bundler.configure_gem_home_and_path
0% 0.13 0.00 0.134TSort.tsort1Bundler.configure_gem_path
0.13 0.00 0.134/4Enumerable#to_a
0.110.000.1050/193Bundler::Index.sort_specs
0%0%0.130.010.12193Enumerable#sort_by1/1Bundler.use_system_gems?
0.13 0.00 0.134/8Enumerator#each1/1Bundler.configure_gem_path
0% 0.13 0.00 0.138TSort.tsort_each1Bundler.use_system_gems?
0.13 0.00 0.134/4TSort.each_strongly_connected_component1/2Bundler.configured_bundle_path
0.13 0.00 0.134/8Enumerable#to_a1/2Bundler.use_system_gems?
0% 0.13 0.00 0.138Enumerator#each2Bundler.configured_bundle_path
0.110.020.101/218Bundler.settings
0%0% 0.130.000.134/8TSort.tsort_each0.010.123Gem::Specification.gemspec_stubs_in
0.130.10 0.000.134/4TSort.tsort0.103/287Array#select
0% 0%0.130.12 0.000.134Enumerable#to_a0.1210Bundler::SpecSet#sorted
0.130.12 0.000.134/8Enumerator#each0.124/4TSort.tsort
0.130.12 0.000.134/4TSort.tsort_each0.1237/37Kernel.require
0% 0%0.130.12 0.000.134TSort.each_strongly_connected_component0.1237Protobuf::Message::Fields::ClassMethods.repeated
0.130.12 0.000.134/122Method#call0.1237/153Protobuf::Message::Fields::ClassMethods.define_field
0.130.000.134/122TSort.each_strongly_connected_component0.110.020.101/218Bundler.configured_bundle_path
0% 0%0.130.000.13122Method#call0.120.020.10218Bundler.settings
0.130.12 0.000.130.12 4/4Bundler::SpecSet#tsort_each_nodeBundler::SpecSet#sorted
0%0%0.120.000.124TSort.tsort
0.110.12 0.000.11118/118Bundler::SpecSet#tsort_each_child0.124/4TSort.tsort
0.130.12 0.000.130.12 4/4Method#callTSort.tsort
0% 0%0.130.12 0.000.130.12 4Bundler::SpecSet#tsort_each_nodeTSort.tsort
0.130.12 0.000.134/395067Array#each0.124/4Enumerable#to_a
0.130.130.12 0.001179978/1180431Protobuf::Enum.enum_for_tag_integer0.124/8Enumerator#each
0% 0%0.130.130.12 0.001180431Array#first0.128TSort.tsort_each
0.120.010.00 0.12118/118Array#each4/4TSort.each_strongly_connected_component
0%0%
0.120.010.00 0.12118TSort.each_strongly_connected_component_from4/4TSort.tsort
0% 0% 0.120.010.00 0.12336Bundler::SpecSet#lookup4Enumerable#to_a
0.110.12 0.000.108/50Bundler::Index.sort_specs0.124/8Enumerator#each
0.12 0.00 0.121/1Bundler.configure_gem_home_and_path4/8Enumerable#to_a
0% 0.12 0.00 0.121Bundler.configure_gem_path8Enumerator#each
0.12 0.00 0.121/1Bundler.use_system_gems?4/8TSort.tsort_each
0.12 0.00 0.121/1Bundler.configure_gem_path4/4TSort.tsort_each
0% 0.12 0.00 0.121Bundler.use_system_gems?4TSort.each_strongly_connected_component
0.12 0.00 0.121/2Bundler.configured_bundle_path4/122Method#call
0.12 0.00 0.121/2Bundler.use_system_gems?4/122TSort.each_strongly_connected_component
0% 0.12 0.00 0.122Bundler.configured_bundle_path122Method#call
0.100.010.091/218Bundler.settings0.120.000.124/4Bundler::SpecSet#tsort_each_node
0.120.12 0.00393326/393326Class#new0.124/4Method#call
0% 0% 0.120.12 0.00393326StringIO#initialize0.124Bundler::SpecSet#tsort_each_node
0.110.01 0.110.00786653/787731Test::Resource#_protobuf_message_required_field_tags4/417509Array#each
0%0%
0.11 0.11 0.00787731Kernel.dup405768/415768Proc#call
0% 0% 0.110.080.03583Module#module_eval0.110.00415768Protobuf::Message#to_proto
0.10 0.010.091/218Bundler.configured_bundle_path0.1062/1079Gem::StubSpecification#valid?
0% 0% 0.11 0.020.09218Bundler.settings0.101079Gem::StubSpecification#data
0.100.100.110.11 0.00383326/393326Proc#call1247304/1247757Protobuf::Enum.enum_for_tag_integer
0% 0.11 0.11 0.00393326Protobuf::Message#to_proto1247757Array#first
0.110.000.1177/79Kernel.send
0% 0% 0.110.000.1179Bundler::LockfileParser#parse_source
0.100.02 0.0873/73Bundler::LockfileParser#parse_spec0.03583Module#module_eval
0.11 0.00 0.11118/118Method#call1/1Kernel.require
0% 0.11 0.00 0.11118Bundler::SpecSet#tsort_each_child1Concurrent::Utility::NativeExtensionLoader.load_native_extensions
0.110.000.01 0.108/50Bundler::SpecSet#lookup118/118Array#each
0% 0% 0.110.000.1150Bundler::Index.sort_specs
0.110.000.01 0.1050/193Enumerable#sort_by
0%0%0.110.110.00786652String#force_encoding118TSort.each_strongly_connected_component_from
0.100.020.0873/73Bundler::LockfileParser#parse_source0.100.00831537/831706Protobuf::Message#initialize
0% 0% 0.100.020.0873Bundler::LockfileParser#parse_spec0.100.00831706Kernel.block_given?
0.10 0.00 0.101/2Array#map62/62Array#select
0% 0.10 0.00 0.102Bundler.load_gemspec
0.100.000.101/1Bundler.load_gemspec_uncached62Gem::StubSpecification#valid?
0.100.000.01 0.101/1Bundler.load_gemspec62/1079Gem::StubSpecification#data
0% 0% 0.100.00 0.101Bundler.load_gemspec_uncached
0.0026Java::JavaPackage#method_missing
@@ -67,95 +67,95 @@

Total time: 69.40

- + - + - + - + - + - + - + - - + + - + - + - - + + - + - - - + + + - + - + - - - - + + + + - + - - - + + + - + - + - + - - - + + + - + - + - + - + - + @@ -164,526 +164,454 @@

Total time: 69.40

- + - - - - + + + + - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + + + + - + - - + + - - - - + + + + - - - + + + - - - - + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - + - - + + - - + + - + - - - - - - - - - - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - + + + + + + + + + + + - - + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + + + - - - - + + - + - + - + - + - + - + - + - + - - - - - + + + + + - + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - - - - - - - - - - + - - + + - - + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + @@ -693,10 +621,10 @@

Total time: 69.40

- + - + @@ -704,1301 +632,1219 @@

Total time: 69.40

- + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - - - - - - - + - - + + - + - + - - + + - - + + - - + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + - - - - + + + + - + - - - + + + - + - + - - + + - + - - - - + + + + - + - - + + - - + + - + - + - - - - - + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + - + - - - - + + + + - - - - - + + + + + + + + + + + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - - + + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - - + + + - + - - - + + + - + + - - - - - + + + + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - + + - - - + + - + - + + - - - + + - + - + + - - - + + - + - - - - - + + + + + - + - + + - - - + + + + + + + + + + + - + + - - - - - + + + + + - - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + + - - + + - - + + - - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - - - - - - + + + + + - - - - - - + + + + + + - + + - - - - - + + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + - - - - - - - - + + + + + + + + - + - - + + - - + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - - + - - + + - - + + + - - - - + + + + - + + + + + + + + + + - - - - - + + + + + - + - - + + - - - - - - - - - - - + + - + - + - - + + - + - - + + - + - - + + - + - + - - - - + + + + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + - - + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + - - - - - - - - - - + - - - - - - - - - - - - + + + - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + @@ -2007,3325 +1853,1719 @@

Total time: 69.40

- + - - + + - - + + - - + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + + - - - + + - + + - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - - + - - + + - - + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + - - - - - - - - - - - - - - + + + + + - - - - - - + + + + + - - - + + + + + + + + + + + + - - + + - - - - - + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + - + + + - - - - + + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - - + + + + + - + + - - + + + + + + + + + + + + + + + + + + + + - - + + - - - - - + + + + + - - - - - + + + + + - + - - - - + + + + - + - - + + - + - + - - - - - - - + + + + + + + - - - - - + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - - + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - + - - + + - - + + - - - - - - - - - - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - + - + + - - - + + + + + + + + + + + - - - - - - + + + + + + - + - + + - - - + + - + - + + - - - + + - - - - - - - - - - - + + + - - - + + - + - + - + - + - + - + + + + + + + + + + - + - + - + - + - + - + + - - - + + - - + + + - - - + + - + + - + + - - - + + - - + + - - - + + - - - - - - - - - - - + + + - - - + + - + + - - - - - + + + + + - - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - + + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - + + - - - + + - + + - - - + + - + + - - - - - + + + + + + + + + + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - + + - - - + + - - - - - - - - - - + + - - - + + - + - + - - - + + + - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - - + - + - + - + + - + + - - - + + - + - - + + - - + + + + + + + + + + + - - + + - - + + - + - + - + - + - + - + - + - + - - - + + + - + - + - + - + - + - + - - + - - - - - - - - - - - - - - - - - - - - + - - - + + + - + - - + - - + + + - - + - - + + + - - + - + - + - + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + - + - - + - - + + + - - + - - + + + - + + + + + + + + + + - + - + - + - + - + - + - + - - - - - + + + + + - + - + - + - + - + - + - + + + + + + + + + + - + - - + + - - + + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - - - - - + + + + + + + + + + + + + + + - - - + + - + + - + + - - - + + - - - + + - - + + - - + + - - + + - + - - + - - + + + - - + + + + + + + + + + - - + + + - + - + - + - + - + - + - + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - - - + + + - + - + + - - - + + - + + - - - + + - + + - - - - - + + + + + - - - - - - + + + + + - + + - - - - - + + + + + - + - - - - + + + - + + - + + - - - + + - - - - - + + + + + - - - + + + - + + - - - + + - + + - + + + + + + + + + + + - - - + + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - - - - - - - - - - + + - - - + + - + - + + - - - + + - - - - - - - - - - + + - - - + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - - - - - + + + + + - + - + + - - - + + - - - - - - - - - - + + - - - + + - + - - - - - + + + + + - - - - - + + + + + - - - - - - - - + + + + + + + + + - + - - - + + + - - - - - - - - - - - + + - + - - - + + + - - - - - - - - - - - - + + + - + - - + + @@ -5333,37 +3573,46 @@

Total time: 69.40

- - + + - - - - - + + + + + - - - - + + + + + + + + + + + + + - + - - + + @@ -5371,75 +3620,74 @@

Total time: 69.40

- - + + + - - - + + - + - + - + - + - + - + - - + - - - - - - - - - - + - - + + - + - - - + + + + + + + + + + + - - + + + @@ -5448,8 +3696,8 @@

Total time: 69.40

- - + + @@ -5457,17 +3705,17 @@

Total time: 69.40

- - + + - + - + - - + + @@ -5476,1190 +3724,1184 @@

Total time: 69.40

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + - - + - - + + + + + - + + + + + + + + - + + + + + - - - - - - + + - - + + + + + + + + + - - - + - - - - - + + + + + - - - - - - - - - + + + + + + + - + + + - - - - - - - - - - - - - - - - + + + + + + + - + + + + + + + + + + + - - - - - - - - - - - - + - - - + - + + - - - - - - - + + + + - - - - - - - - + - + - - - + + - - - - - - - + + - - - - - + + + + - - - - - - - - - - - + + + - - - - - - - - - - - - + + - + - - - + + + - - + + + - + + - - - + + + + - - - - - - - - - - - + - - + + + - - + + + + - - - - - - - - - - + + + + + - - - - - - - - - - - + - - + + + + + - - - - + + + - - - - - + + + + - - - + + + + + + + + + + - - - - - - + + + - - + + + + + + + + + + - - - + + + + + - - - - - - + + + + + + + + - + + + + + + + - - + + - - - - - - - + + - + + + - + - - - - + + + + + + - + + + - + + - - - - - + + + + + - - - - - - - - - - - - + + - - + + + + + - - - - + + + + + + - - + + + - - - - - - - - + - + + + + - - - - - - - - - - - - - + - - + + - - - + + + + + + + + + + - - - + - - - - - - - - + - - + + - - - - - - - + + + + + + + + + + - + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - + + + - - - + + + + + - - - - - - + + - - - - + + - - - - - - - - + + + + - + + + + + + + + - - - - - + + + + + - + + - + - - + + + - - - + + + + + + + + + + + - - - - + + + + - - - - + + + - - + - - - - - - + + - - - - + + + - + + + + + + + + - + + - - + + + + + + + - - + + + + + - + + + + + + + + + - + + + + + - + + + - - + + - - - - - + - - + + + + + + + - - - - - + + + + + + + + + + + + - + + + + + + + + + + + - - - - + - - + - - - + - + - + - - - - - - - - + + + - + + + + + + - - - - - - - + + - - - - + - - - + + - + - - + + + + + + + + - - + + - + + - - - + - + + + @@ -6669,71 +4911,82 @@

Total time: 69.40

- + + + - + + + + - - - - + + + + + + - - + + + + - - + + - + + - + - - + + + - + @@ -6746,27 +4999,28 @@

Total time: 69.40

- + + - + + + - - @@ -6775,7 +5029,6 @@

Total time: 69.40

- @@ -6784,13 +5037,12 @@

Total time: 69.40

- + - @@ -6799,6 +5051,7 @@

Total time: 69.40

+ @@ -6806,13 +5059,15 @@

Total time: 69.40

- + + + @@ -6829,20 +5084,22 @@

Total time: 69.40

+ - + + @@ -6857,6 +5114,7 @@

Total time: 69.40

+ From 83f8d21a23581b9737ae475475f9400d96f4face Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 26 Dec 2018 12:52:06 -0700 Subject: [PATCH 1109/1191] fix interpolation issues in method definitions and code generator relying on old code and false/true probs --- lib/protobuf/code_generator.rb | 29 +- .../field/base_field_method_definitions.rb | 8 +- lib/protobuf/message.rb | 14 +- profile.html | 5916 +++++++++-------- 4 files changed, 3171 insertions(+), 2796 deletions(-) diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 73d7d271..230a7501 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -50,6 +50,32 @@ def response_bytes end Protobuf::Field::BaseField.module_eval do + def set_without_options(message_instance, bytes) + return message_instance[name] = decode(bytes) unless repeated? + + if map? + hash = message_instance[name] + entry = decode(bytes) + # decoded value could be nil for an + # enum value that is not recognized + hash[entry.key] = entry.value unless entry.value.nil? + return hash[entry.key] + end + + return message_instance[name] << decode(bytes) unless packed? + + array = message_instance[name] + stream = StringIO.new(bytes) + + if wire_type == ::Protobuf::WireType::VARINT + array << decode(Varint.decode(stream)) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED64 + array << decode(stream.read(8)) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED32 + array << decode(stream.read(4)) until stream.eof? + end + end + # Sets a MessageField that is known to be an option. # We must allow fields to be set one at a time, as option syntax allows us to # set each field within the option using a separate "option" line. @@ -85,9 +111,6 @@ def option_set(message_field, subfield, subvalue) message_field[subfield.tag] = subvalue end end - - alias_method :set_without_options, :set - alias_method :set, :set_with_options end end end diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index f4207b57..5b1864a1 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -14,7 +14,7 @@ def self.fully_qualified_name_string(selph) def self.define_to_hash_value_to_message_hash!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def to_message_hash(values, result) - result["#{selph.name}"] = value_from_values(values).to_hash_value + result[#{selph.name.inspect}] = value_from_values(values).to_hash_value end RUBY end @@ -22,7 +22,7 @@ def to_message_hash(values, result) def self.define_base_to_message_hash!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def to_message_hash(values, result) - result["#{selph.name}"] = value_from_values(values) + result[#{selph.name.inspect}] = value_from_values(values) end RUBY end @@ -131,7 +131,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) unless value.is_a?(Hash) fail TypeError, <<-TYPE_ERROR Expected map value - Got '#{value.class}' for map protobuf field #{selph.name} + Got '\#{value.class}' for map protobuf field #{selph.name} TYPE_ERROR end @@ -151,7 +151,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) unless value.is_a?(Hash) fail TypeError, <<-TYPE_ERROR Expected map value - Got '#{value.class}' for map protobuf field #{selph.name} + Got '\#{value.class}' for map protobuf field #{selph.name} TYPE_ERROR end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 89695507..54e8621d 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -107,7 +107,12 @@ def each_field_for_serialization def field?(name) field = _protobuf_message_field[name] - field && field.field?(@values) + + if field + field.field?(@values) + else + false + end end alias :respond_to_has? field? ::Protobuf.deprecator.define_deprecated_methods(self, :has_field? => :field?) @@ -122,7 +127,12 @@ def inspect def respond_to_has_and_present?(key) field = _protobuf_message_field[key] - field && field.field_and_present?(@values) + + if field + field.field_and_present?(@values) + else + false + end end # Return a hash-representation of the given fields for this message type. diff --git a/profile.html b/profile.html index 2e13a6ae..fd9f6fb2 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 63.12

+

Total time: 63.30

%Total
100% 0%69.4063.12 0.0069.4063.12 0 (top)
60.0960.13 0.0060.0960.13 1/1 Benchmark::IPS.ips
2.650.90 0.002.652/1150.902/112 Kernel.require
2.430.89 0.002.425/19040.896/1880 Kernel.require
2.400.122.280.740.040.70 1/5Fixnum#times##times
1.800.191.6124/260.460.060.4017/19 Kernel.load
2.400.122.280.740.040.70 1/5 (top)
60.0860.12 0.0060.0860.12 2/5 Benchmark::IPS::Job#run
90%96% 0%62.570.1662.4060.880.0560.83 5Fixnum#times##times
40.0840.12 0.0040.0840.12 1/1 Benchmark::IPS::Job#run_benchmark
20.00 1/1 Benchmark::IPS::Job#run_warmup
1.080.011.0610000/4157680.340.000.3310000/1018106 Protobuf::Message::Serialization::ClassMethods.decode_from
0.760.030.7310000/415768Protobuf::Encoder.encode
0.310.020.2920000/1249742Class#new
0.110.030.0810000/415768Test::Resource#status=
0.110.22 0.010.114/417509Bundler::SpecSet#tsort_each_node
0.140.020.121/417509Bundler::LockfileParser#initialize
0.190.000.191/417509Bundler::Source::Path#load_spec_files0.2110000/1018106Protobuf::Encoder.encode
0.250.10 0.000.251/4175090.101/1019611 Gem::Specification.each_gemspec
0.660.020.6420/4175090.230.000.2319/1019611 Kernel.require
20.001.6818.321/4175091.6718.331/1019611 Benchmark::IPS::Job#run_warmup
40.080.0240.061/41750940.120.0140.121/1019611 Benchmark::IPS::Job#run_benchmark
89%96% 2%61.891.8460.05417509Array#each60.791.7159.091019611##each
57.531.9455.591412256/141225657.282.7154.563377944/3377944 Benchmark::IPS::Job::Entry#call_times
0.640.400.241412810/14128100.860.430.433378485/3378485 Benchmark::Timing.now
0.200.000.2012/13Gem::Specification.load
0.190.000.191/1Bundler::Source::Path#validate_spec
0.160.160.170.17 0.001412260/1412260Float#<3377948/3377948##<
0.130.00 0.13160/838Kernel.send
0.110.010.10118/118TSort.each_strongly_connected_component_from0.003377958/17079139##+
60.0960.13 0.0060.0960.13 1/1 (top)
86%95% 0%60.0960.13 0.0060.0960.13 1 Benchmark::IPS.ips
60.0860.13 0.0060.0860.13 1/1 Benchmark::IPS::Job#run
60.0860.13 0.0060.0860.13 1/1 Benchmark::IPS.ips
86%95% 0%60.0860.13 0.0060.0860.13 1 Benchmark::IPS::Job#run
60.0860.12 0.0060.0860.12 2/5Fixnum#times##times
57.531.9455.591412256/1412256Array#each57.282.7154.563377944/3377944##each
82%2%57.531.9455.59141225690%4%57.282.7154.563377944 Benchmark::IPS::Job::Entry#call_times
55.042.2752.775853424/585395553.312.0951.2213700098/13700643 Proc#call
0.550.550.680.680.0017078042/19114271##<
0.570.57 0.007265478/8096960Fixnum#<13700098/17079139##+
55.042.2752.775853424/585395553.312.0951.2213700098/13700643 Benchmark::IPS::Job::Entry#call_times
79%84% 3%55.092.2952.80585395553.342.1051.2513700643 Proc#call
24.252.1522.105447656/544765622.712.2220.4912691992/12691992 Protobuf::Message#to_hash
12.790.3012.49405768/41576813.530.2813.241008106/1018106 Protobuf::Message::Serialization::ClassMethods.decode_from
9.780.329.45405768/4157688.820.318.511008106/1018106 Protobuf::Encoder.encode
4.230.303.92811536/12497423.980.153.831008106/2037678 Class#new
1.550.251.30405768/4157681.780.261.521008106/1018106 Test::Resource#status=
0.240.13 0.110.110.00405768/415768Protobuf::Message#to_proto1008106/1018106StringIO.new
40.0840.12 0.0040.0840.12 1/1Fixnum#times##times
57%63% 0%40.0840.12 0.0040.0840.12 1 Benchmark::IPS::Job#run_benchmark
40.080.0240.061/417509Array#each40.120.0140.121/1019611##each
9.551.867.69415768/58634258.081.326.761018106/13710099 Protobuf::Message#each_field_for_serialization
22.109.2512.855447656/586342520.495.4315.0712691992/13710099 Protobuf::Message#to_hash
45%16%31.6511.1120.545863425Hash#each_key10%28.586.7521.8313710099##each_key
3.382.760.6210895312/10896957Kernel.respond_to?6.052.163.8912691992/12691992Protobuf::Field::Int64Field(singleton)#to_message_hash
2.691.920.775863424/6279192Protobuf::Field::StringField(singleton)#value_from_values5.942.233.7012691992/12691992Protobuf::Field::StringField(singleton)#to_message_hash
2.661.890.775863424/6279192Protobuf::Field::Int64Field(singleton)#value_from_values2.122.120.0028438302/37606151##[]
2.340.691.66415768/415768Protobuf::Field::StringField#encode_to_stream1.870.601.271018106/1018106Protobuf::Field::StringField(singleton)#encode_to_stream
1.980.311.68415768/4157681.850.251.601018106/1018106 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.720.291.42415768/4157681.510.281.231018106/1018106 Protobuf::Field::Int64Field(singleton)#encode_to_stream
1.671.670.0012142616/15890196Hash#[]
1.411.411.381.38 0.0010895312/10895502Protobuf::Field::BaseField#name28438302/34546940Test::Resource#_protobuf_message_field
1.311.310.0012142616/14637226Test::Resource#_protobuf_message_field0.420.090.331018106/14728204Protobuf::Field::StringField(singleton)#value_from_values
0.990.990.0010895312/13395045Hash#[]=0.370.090.281018106/14728204Protobuf::Field::Int64Field(singleton)#value_from_values
0.380.080.29415768/8315360.320.090.241018106/2036212 Protobuf::Field::EnumField(singleton)#value_from_values
24.252.1522.105447656/544765622.712.2220.4912691992/12691992 Proc#call
34%35% 3%24.252.1522.10544765622.712.2220.4912691992 Protobuf::Message#to_hash
22.109.2512.855447656/5863425Hash#each_key20.495.4315.0712691992/13710099##each_key
0.00 20.00 1/1Fixnum#times##times
28%31% 0% 20.00 0.00 1 Benchmark::IPS::Job#run_warmup
20.001.6818.321/417509Array#each1.6718.331/1019611##each
1.080.011.0610000/415768Fixnum#times0.340.000.3310000/1018106##times
12.790.3012.49405768/41576813.530.2813.241008106/1018106 Proc#call
19%21% 0%13.870.3213.5641576813.860.2913.581018106 Protobuf::Message::Serialization::ClassMethods.decode_from
12.810.3112.50415768/41576812.890.2512.641018106/1018106 Protobuf::Message::Serialization.decode_from
0.750.180.57415768/12497420.680.170.521018106/2037678 Class#new
12.810.3112.50415768/41576812.890.2512.641018106/1018106 Protobuf::Message::Serialization::ClassMethods.decode_from
18%20% 0%12.810.3112.5041576812.890.2512.641018106 Protobuf::Message::Serialization.decode_from
12.501.4711.04415768/41576812.641.6810.961018106/1018106 Protobuf::Decoder.decode_each_field
12.501.4711.04415768/41576812.641.6810.961018106/1018106 Protobuf::Message::Serialization.decode_from
18%20% 2%12.501.4711.0441576812.641.6810.961018106 Protobuf::Decoder.decode_each_field
9.561.058.511247304/12473049.120.968.153054318/3054318 Protobuf::Message::Serialization.set_field_bytes
0.970.610.362494608/24946081.060.680.396108636/6108636 Protobuf::Varint.decode
0.210.210.00415768/415768StringIO#read
0.160.160.200.20 0.001663072/16630724072424/4072424 StringIO#eof
0.140.140.180.18 0.001662784/1665061Fixnum#==4072424/4075603##==
0.760.030.7310000/415768Fixnum#times0.150.150.003054318/3054318##>>
9.780.329.45405768/415768Proc#call
15%0%10.540.3510.18415768Protobuf::Encoder.encode0.120.120.001018106/1018106StringIO#read
10.180.479.72415768/415768Protobuf::Message#each_field_for_serialization0.120.120.003054318/7126742##&
10.180.479.72415768/415768Protobuf::Encoder.encode
14%0%10.180.479.72415768Protobuf::Message#each_field_for_serialization
9.551.867.69415768/5863425Hash#each_key
0.110.110.00415768/1247305Test::Resource#_protobuf_message_required_field_tags
9.561.058.511247304/12473049.120.968.153054318/3054318 Protobuf::Decoder.decode_each_field
13%14% 1%9.561.058.5112473049.120.968.153054318 Protobuf::Message::Serialization.set_field_bytes
3.290.263.03415768/4157680.233.061018106/1018106 Protobuf::Field::EnumField(singleton)#set
2.392.21 0.252.14415768/4157681.961018106/1018106 Protobuf::Field::Int64Field(singleton)#set
2.270.272.00415768/4157682.080.241.841018106/1018106 Protobuf::Field::StringField(singleton)#set
0.320.320.330.33 0.001247304/15890196Hash#[]3054318/37606151##[]
0.24 0.24 0.001247304/146372263054318/34546940 Test::Resource#_protobuf_message_field
1.150.170.98415768/2494610Protobuf::Field::EnumField(singleton)#set0.220.010.2110000/1018106##times
1.380.241.14415768/2494610Test::Resource#status=8.820.318.511008106/1018106Proc#call
14%0%9.040.328.721018106Protobuf::Encoder.encode
8.720.448.291018106/1018106Protobuf::Message#each_field_for_serialization
1.390.151.260.161.101018106/6108638Protobuf::Field::EnumField(singleton)#set
1.400.16 1.24415768/24946101018106/6108638 Protobuf::Field::Int64Field(singleton)#set
1.490.211.28415768/24946101.440.191.251018106/6108638 Protobuf::Field::StringField(singleton)#set
2.900.552.35831538/2494610Hash#each1.550.251.301018106/6108638Test::Resource#status=
3.100.502.602036214/6108638##each
11%1%8.311.326.99249461013%2%8.751.277.486108638 Protobuf::Message#set_field
2.370.761.61831537/8315372.400.751.652036213/2036213 Protobuf::Field::StringField(singleton)#set_field
2.190.501.69831537/8315372.370.511.872036213/2036213 Protobuf::Field::Int64Field(singleton)#set_field
2.000.491.51831536/8315362.250.471.792036212/2036212 Protobuf::Field::EnumField(singleton)#set_field
0.240.240.260.26 0.001247306/15890196Hash#[]3054320/37606151##[]
0.190.190.200.20 0.001247306/146372263054320/34546940 Test::Resource#_protobuf_message_field
0.120.060.0635/1249742Kernel.require8.720.448.291018106/1018106Protobuf::Encoder.encode
13%0%8.720.448.291018106Protobuf::Message#each_field_for_serialization
8.081.326.761018106/13710099##each_key
0.150.150.001018106/3054319Test::Resource#_protobuf_message_required_field_tags
0.240.050.1914/1249742Kernel.eval6.052.163.8912691992/12691992##each_key
9%3%6.052.163.8912691992Protobuf::Field::Int64Field(singleton)#to_message_hash
2.411.910.5012691992/14728204Protobuf::Field::Int64Field(singleton)#value_from_values
1.481.480.0012691992/31497159##[]=
0.310.020.2920000/1249742Fixnum#times5.942.233.7012691992/12691992##each_key
9%3%5.942.233.7012691992Protobuf::Field::StringField(singleton)#to_message_hash
2.551.960.5912691992/14728204Protobuf::Field::StringField(singleton)#value_from_values
1.151.150.0012691992/31497159##[]=
0.400.15 0.010.39153/12497420.14153/2037678 Protobuf::Field.build
0.590.21 0.010.571/12497420.201/2037678 Bundler::Dsl#to_definition
0.750.180.57415768/12497420.680.170.521018106/2037678 Protobuf::Message::Serialization::ClassMethods.decode_from
4.230.303.92811536/12497423.980.153.831008106/2037678 Proc#call
10%1%6.950.736.2212497428%0%5.440.425.022037678 Class#new
4.660.873.78831537/8315374.430.753.682036213/2036213 Protobuf::Message#initialize
0.570.010.570.200.000.20 1/1 Bundler::Definition#initialize
0.390.020.370.140.010.13 153/153 Protobuf::Field::BaseField#initialize
0.200.020.1817/17Gem::Specification#initialize4.430.753.682036213/2036213Class#new
0.150.000.151/1Bundler::LockfileParser#initialize
7%1%4.430.753.682036213Protobuf::Message#initialize
0.130.130.00415768/415768StringIO#initialize3.520.423.102036213/2036424##each
1.440.071.372/1904Kernel.load3.520.423.102036213/2036424Protobuf::Message#initialize
5%0%3.540.433.112036424##each
2.430.002.425/1904(top)3.100.502.602036214/6108638Protobuf::Message#set_field
2.640.002.64115/1904Kernel.require3.290.233.061018106/1018106Protobuf::Message::Serialization.set_field_bytes
9%5% 0%6.510.076.441904Kernel.require3.290.233.061018106Protobuf::Field::EnumField(singleton)#set
2.210.002.211/1Bundler.setup1.800.221.581018106/1018106Protobuf::Field::EnumField#decode
0.660.020.6420/417509Array#each1.260.161.101018106/6108638Protobuf::Message#set_field
0.320.170.17 0.000.31109/109Protobuf::Message::Fields::ClassMethods.optional2036213/31497159Protobuf::Field::Int64Field(singleton)#set_field
0.260.180.18 0.000.261/1Gem::Specification.load_defaults2036212/31497159Protobuf::Field::EnumField(singleton)#set_field
0.190.200.20 0.000.192/7IO.open2036213/31497159Protobuf::Field::StringField(singleton)#set_field
0.120.060.0635/1249742Class#new1.151.150.0012691992/31497159Protobuf::Field::StringField(singleton)#to_message_hash
0.121.481.48 0.000.1237/37Protobuf::Message::Fields::ClassMethods.repeated12691992/31497159Protobuf::Field::Int64Field(singleton)#to_message_hash
5%5%3.193.190.0131497159##[]=
0.110.000.111/1Concurrent::Utility::NativeExtensionLoader.load_native_extensions0.420.090.331018106/14728204##each_key
4.660.873.78831537/831537Class#new2.551.960.5912691992/14728204Protobuf::Field::StringField(singleton)#to_message_hash
6%1%4.660.873.78831537Protobuf::Message#initialize4%3%2.972.050.9214728204Protobuf::Field::StringField(singleton)#value_from_values
3.600.702.90831537/831748Hash#each0.690.690.0013710098/28439604##fetch
0.100.100.170.17 0.00831537/831706Kernel.block_given?3054318/37606151Protobuf::Enum.enum_for_tag_integer
3.600.702.90831537/831748Protobuf::Message#initialize
5%1%3.680.752.93831748Hash#each0.260.260.003054320/37606151Protobuf::Message#set_field
2.900.552.35831538/2494610Protobuf::Message#set_field0.330.330.003054318/37606151Protobuf::Message::Serialization.set_field_bytes
3.382.760.6210895312/10896957Hash#each_key2.122.120.0028438302/37606151##each_key
4%3%3.392.770.6310896957Kernel.respond_to?4%2.902.880.0337606151##[]
0.630.630.0010896824/10896826Kernel.respond_to_missing?0.370.090.281018106/14728204##each_key
3.290.263.03415768/415768Protobuf::Message::Serialization.set_field_bytes2.411.910.5012691992/14728204Protobuf::Field::Int64Field(singleton)#to_message_hash
4%0%3.290.263.03415768Protobuf::Field::EnumField(singleton)#set
1.880.241.64415768/415768Protobuf::Field::EnumField#decode3%2.781.990.7914728204Protobuf::Field::Int64Field(singleton)#value_from_values
1.150.170.98415768/2494610Protobuf::Message#set_field0.560.560.0013710098/28439604##fetch
2.691.920.775863424/6279192Hash#each_key2.400.751.652036213/2036213Protobuf::Message#set_field
3%2%2.691.920.776279192Protobuf::Field::StringField(singleton)#value_from_values1%2.400.751.652036213Protobuf::Field::StringField(singleton)#set_field
0.490.490.005863424/12143918Hash#fetch0.620.500.122036213/3054319Test::Resource#_protobuf_message_required_field_tags
2.661.890.775863424/6279192Hash#each_key0.570.400.172036213/2036213Protobuf::Field::StringField#coerce!
3%2%2.661.890.776279192Protobuf::Field::Int64Field(singleton)#value_from_values
0.200.200.002036213/31497159##[]=
0.460.460.180.18 0.005863424/12143918Hash#fetch2036213/2036396##delete
2.650.002.652/115(top)2.370.511.872036213/2036213Protobuf::Message#set_field
3% 0%2.650.002.65115Kernel.require2.370.511.872036213Protobuf::Field::Int64Field(singleton)#set_field
2.640.002.64115/1904Kernel.require1.620.591.032036213/2036213Protobuf::Field::IntegerField#coerce!
0.160.160.170.17 0.001247304/15890196Protobuf::Enum.enum_for_tag_integer2036213/31497159##[]=
0.240.240.001247306/158901962.250.471.792036212/2036212 Protobuf::Message#set_field
3%0%2.250.471.792036212Protobuf::Field::EnumField(singleton)#set_field
0.320.320.001247304/15890196Protobuf::Message::Serialization.set_field_bytes1.530.411.122036212/2036212Protobuf::Field::EnumField#coerce!
1.671.670.180.18 0.0012142616/15890196Hash#each_key
3%3%2.472.400.0715890196Hash#[]2036212/31497159##[]=
2.392.21 0.252.14415768/4157681.961018106/1018106 Protobuf::Message::Serialization.set_field_bytes
3% 0%2.392.21 0.252.144157681.961018106 Protobuf::Field::Int64Field(singleton)#set
1.390.151.400.16 1.24415768/24946101018106/6108638 Protobuf::Message#set_field
0.750.430.32415768/8315360.560.400.161018106/2036212 Protobuf::Field::IntegerField#decode
2.370.761.61831537/831537Protobuf::Message#set_field
3%1%2.370.761.61831537Protobuf::Field::StringField(singleton)#set_field0.360.030.342/1880Kernel.load
0.530.410.13831537/1247305Test::Resource#_protobuf_message_required_field_tags0.890.000.896/1880(top)
0.520.370.15831537/831537Protobuf::Field::StringField#coerce!
0.290.290.00831537/831720Array#delete
0.180.180.90 0.00831537/13395045Hash#[]=
2.340.691.66415768/415768Hash#each_key0.90112/1880Kernel.require
3% 0%2.340.691.66415768Protobuf::Field::StringField#encode_to_stream2.150.032.121880Kernel.require
0.590.240.351247304/2910376IO::GenericWritable.<<0.750.000.751/1Bundler.setup
0.360.240.11415768/416553BasicObject#!=0.230.000.2319/1019611##each
0.320.170.15415768/1247457Protobuf::Field::VarintField.encode0.110.000.11109/109Protobuf::Message::Fields::ClassMethods.optional
0.250.250.10 0.00415768/1247457Protobuf::Field::BaseField#tag_encoded0.101/1Gem::Specification.load_defaults
2.270.272.00415768/4157682.080.241.841018106/1018106 Protobuf::Message::Serialization.set_field_bytes
3% 0%2.270.272.004157682.080.241.841018106 Protobuf::Field::StringField(singleton)#set
1.490.211.28415768/24946101.440.191.251018106/6108638 Protobuf::Message#set_field
0.510.260.40 0.25415768/4157680.161018106/1018106 Protobuf::Field::StringField#decode
2.210.002.211/1Kernel.require
3%0%2.210.002.211Bundler.setup
1.170.001.171/1Bundler::Runtime#setup
1.020.021.001/2Bundler.definition
2.190.501.69831537/831537Protobuf::Message#set_field1.870.601.271018106/1018106##each_key
3%2% 0%2.190.501.69831537Protobuf::Field::Int64Field(singleton)#set_field
1.491.87 0.600.89831537/831537Protobuf::Field::IntegerField#coerce!
0.140.140.00831537/13395045Hash#[]=1.271018106Protobuf::Field::StringField(singleton)#encode_to_stream
2.000.491.51831536/831536Protobuf::Message#set_field
2%0%2.000.491.51831536Protobuf::Field::EnumField(singleton)#set_field0.610.300.323054318/7126742IO::GenericWritable.<<
1.340.360.98831536/831536Protobuf::Field::EnumField#coerce!0.260.160.101018106/3054471Protobuf::Field::VarintField.encode
0.110.110.00831536/13395045Hash#[]=0.180.120.061018106/1018887BasicObject#!=
1.980.311.68415768/415768Hash#each_key1.850.251.601018106/1018106##each_key
2% 0%1.980.311.684157681.850.251.601018106 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.250.260.99415768/4157681.230.231.011018106/1018106 Protobuf::Field::EnumField#encode
0.300.160.13831536/29103760.370.190.182036212/7126742 IO::GenericWritable.<<
0.130.130.00415768/1247457Protobuf::Field::BaseField#tag_encoded
1.880.241.64415768/415768Protobuf::Field::EnumField(singleton)#set1.780.261.521008106/1018106Proc#call
2% 0%1.880.241.64415768Protobuf::Field::EnumField#decode
1.040.320.72415768/415768Protobuf::Field::EnumField#acceptable?1.820.281.551018106Test::Resource#status=
0.600.360.24415768/831536Protobuf::Field::IntegerField#decode1.550.251.301018106/6108638Protobuf::Message#set_field
1.800.191.6124/26(top)
2%0%1.800.191.6126Kernel.load
1.440.071.372/1904Kernel.require
0.190.190.200.20 0.001247306/146372263054320/34546940 Protobuf::Message#set_field
0.24 0.24 0.001247304/146372263054318/34546940 Protobuf::Message::Serialization.set_field_bytes
1.311.311.381.38 0.0012142616/14637226Hash#each_key28438302/34546940##each_key
2% 2%1.741.741.821.82 0.001463722634546940 Test::Resource#_protobuf_message_field
1.720.291.42415768/415768Hash#each_key1.800.221.581018106/1018106Protobuf::Field::EnumField(singleton)#set
2% 0%1.720.291.42415768Protobuf::Field::Int64Field(singleton)#encode_to_stream1.800.221.581018106Protobuf::Field::EnumField#decode
0.960.490.47415768/831536Protobuf::Field::IntegerField#encode1.060.310.751018106/1018106Protobuf::Field::EnumField#acceptable?
0.52 0.35 0.160.19831536/2910376IO::GenericWritable.<<1018106/2036212Protobuf::Field::IntegerField#decode
0.110.110.00415768/1247457Protobuf::Field::BaseField#tag_encoded1.620.591.032036213/2036213Protobuf::Field::Int64Field(singleton)#set_field
2%0%1.620.591.032036213Protobuf::Field::IntegerField#coerce!
0.850.550.292036213/2036213Protobuf::Field::IntegerField#acceptable?
0.750.400.41 0.34415768/8315361018106/2036212 Protobuf::Field::EnumField#encode
0.960.490.47415768/8315360.820.430.391018106/2036212 Protobuf::Field::Int64Field(singleton)#encode_to_stream
2% 1%1.710.900.818315361.570.850.732036212 Protobuf::Field::IntegerField#encode
0.470.240.23831536/12474570.430.250.182036212/3054471 Protobuf::Field::VarintField.encode
0.340.340.290.29 0.00831464/1662929Fixnum#&2036212/7126742##&
0.110.030.0810000/415768Fixnum#times0.560.190.371018106/3054327Protobuf::Field::EnumField#acceptable?
1.550.251.30405768/415768Proc#call0.980.330.652036212/3054327Protobuf::Field::EnumField#coerce!
2% 0%1.660.281.38415768Test::Resource#status=1.540.521.023054327Protobuf::Enum.fetch
1.380.241.14415768/2494610Protobuf::Message#set_field0.870.530.343054318/3054318Protobuf::Enum.enum_for_tag_integer
0.140.140.003054327/7128126Kernel.kind_of?
1.490.600.89831537/831537Protobuf::Field::Int64Field(singleton)#set_field1.530.411.122036212/2036212Protobuf::Field::EnumField(singleton)#set_field
2% 0%1.490.600.89831537Protobuf::Field::IntegerField#coerce!1.530.411.122036212Protobuf::Field::EnumField#coerce!
0.720.510.21831537/831537Protobuf::Field::IntegerField#acceptable?0.980.330.652036212/3054327Protobuf::Enum.fetch
0.110.110.140.14 0.00831536/13395045Protobuf::Field::EnumField(singleton)#set_field2036212/3054760Protobuf::Field::BaseField#type_class
0.140.140.00831537/13395045Protobuf::Field::Int64Field(singleton)#set_field1.510.281.231018106/1018106##each_key
2%0%1.510.281.231018106Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.820.430.391018106/2036212Protobuf::Field::IntegerField#encode
0.410.190.222036212/7126742IO::GenericWritable.<<
0.370.19 0.180.180.00831537/13395045Protobuf::Field::StringField(singleton)#set_field2036212/7126742Protobuf::Field::EnumField(singleton)#encode_to_stream
0.990.990.0010895312/13395045Hash#each_key
2%2%1.461.440.0213395045Hash#[]=0.410.190.222036212/7126742Protobuf::Field::Int64Field(singleton)#encode_to_stream
1.411.410.0010895312/10895502Hash#each_key0.610.300.323054318/7126742Protobuf::Field::StringField(singleton)#encode_to_stream
2%2%1.411.411%1.390.670.727126742IO::GenericWritable.<<
0.720.72 0.0010895502Protobuf::Field::BaseField#name7126742/7126742StringIO#write
0.530.190.34415768/1247313Protobuf::Field::EnumField#acceptable?0.560.560.0013710098/28439604Protobuf::Field::Int64Field(singleton)#value_from_values
0.850.300.55831536/1247313Protobuf::Field::EnumField#coerce!0.690.690.0013710098/28439604Protobuf::Field::StringField(singleton)#value_from_values
2%2%1.301.300.0028439604##fetch
1.230.231.011018106/1018106Protobuf::Field::EnumField(singleton)#encode_to_stream
1% 0%1.380.490.901247313Protobuf::Enum.fetch1.230.231.011018106Protobuf::Field::EnumField#encode
0.780.520.271247304/1247304Protobuf::Enum.enum_for_tag_integer0.750.410.341018106/2036212Protobuf::Field::IntegerField#encode
0.260.15 0.110.110.001247313/2912066Kernel.kind_of?1018106/1018374Protobuf::Enum#to_i
0.600.360.24415768/8315360.520.350.161018106/2036212 Protobuf::Field::EnumField#decode
0.750.430.32415768/8315360.560.400.161018106/2036212 Protobuf::Field::Int64Field(singleton)#set
1% 1%1.340.780.568315361.080.750.332036212 Protobuf::Field::IntegerField#decode
0.290.210.08831536/831799Numeric#nonzero?0.230.230.002036212/7126742##&
0.260.261.060.680.396108636/6108636Protobuf::Decoder.decode_each_field
1%1%1.060.680.396108636Protobuf::Varint.decode
0.390.39 0.00831465/1662929Fixnum#&6108636/6108636ProtobufJavaHelpers::Varinter.read_varint
1.340.360.98831536/831536Protobuf::Field::EnumField(singleton)#set_field1.060.310.751018106/1018106Protobuf::Field::EnumField#decode
1% 0%1.340.360.98831536Protobuf::Field::EnumField#coerce!1.060.310.751018106Protobuf::Field::EnumField#acceptable?
0.850.300.55831536/12473130.560.190.371018106/3054327 Protobuf::Enum.fetch
0.120.120.100.10 0.00831536/12475351018106/3054760 Protobuf::Field::BaseField#type_class
1.250.260.99415768/415768Protobuf::Field::EnumField(singleton)#encode_to_stream
0.900.000.902/112(top)
1% 0%1.250.260.99415768Protobuf::Field::EnumField#encode0.900.000.90112Kernel.require
0.750.400.34415768/831536Protobuf::Field::IntegerField#encode0.900.000.90112/1880Kernel.require
0.240.140.10415768/416036Protobuf::Enum#to_i0.870.530.343054318/3054318Protobuf::Enum.fetch
1%0%0.870.530.343054318Protobuf::Enum.enum_for_tag_integer
0.300.160.13831536/2910376Protobuf::Field::EnumField(singleton)#encode_to_stream0.170.170.003054318/37606151##[]
0.350.160.19831536/2910376Protobuf::Field::Int64Field(singleton)#encode_to_stream0.170.170.003054318/3054780##first
0.590.240.351247304/2910376Protobuf::Field::StringField#encode_to_stream0.860.430.433378485/3378485##each
1% 0%1.240.560.682910376IO::GenericWritable.<<0.860.430.433378485Benchmark::Timing.now
0.680.680.430.43 0.002910376/2910376StringIO#write3378485/3378486Process.clock_gettime
0.130.000.13160/838Array#each
1.100.001.101/838Bundler::Runtime#requested_specs0.850.550.292036213/2036213Protobuf::Field::IntegerField#coerce!
1% 0%1.240.001.23838Kernel.send0.850.550.292036213Protobuf::Field::IntegerField#acceptable?
1.100.100.10 0.001.101/1Bundler::Definition#requested_specs2036213/7128126Kernel.kind_of?
1.170.150.15 0.001.171/1Bundler.setup1018106/3054319Protobuf::Message#each_field_for_serialization
0.620.500.122036213/3054319Protobuf::Field::StringField(singleton)#set_field
1%0%1.170.001.171Bundler::Runtime#setup1%0.770.660.123054319Test::Resource#_protobuf_message_required_field_tags
1.100.120.12 0.001.101/1Bundler::Runtime#requested_specs2036213/2037179Kernel.dup
1.100.680.68 0.001.101/1Bundler::Runtime#setup17078042/19114271Benchmark::IPS::Job::Entry#call_times
1%0%1.100.001.101Bundler::Runtime#requested_specs
1.101%0.770.77 0.001.101/838Kernel.send19114271##<
1.100.75 0.001.100.75 1/1Kernel.sendKernel.require
1% 0%1.100.75 0.001.100.75 1Bundler::Definition#requested_specsBundler.setup
0.390.010.391/2Bundler.definition
1.090.35 0.001.090.35 1/1Bundler::Definition#specs_forBundler::Runtime#setup
1.090.720.72 0.001.091/1Bundler::Definition#requested_specs7126742/7126742IO::GenericWritable.<<
1%0%1.091%0.720.72 0.001.091Bundler::Definition#specs_for7126742StringIO#write
1.070.130.13 0.001.071/1Bundler::Definition#specs3377958/17079139##each
1.070.570.57 0.001.071/1Bundler::Definition#specs_for13700098/17079139Benchmark::IPS::Job::Entry#call_times
1%0%1.070.001.071Bundler::Definition#specs
0.541%0.710.71 0.000.541/1Bundler::Definition#resolve17079139##+
0.490.000.491/1Bundler::SpecSet#materialize0.260.160.101018106/3054471Protobuf::Field::StringField(singleton)#encode_to_stream
1.040.320.72415768/415768Protobuf::Field::EnumField#decode0.430.250.182036212/3054471Protobuf::Field::IntegerField#encode
1% 0%1.040.320.72415768Protobuf::Field::EnumField#acceptable?0.690.410.283054471Protobuf::Field::VarintField.encode
0.530.190.34415768/1247313Protobuf::Enum.fetch0.280.280.003054471/3054471ProtobufJavaHelpers::Varinter.to_varint
0.100.100.120.12 0.00415768/1247535Protobuf::Field::BaseField#type_class3054318/7126742Protobuf::Decoder.decode_each_field
0.460.460.005863424/12143918Protobuf::Field::Int64Field(singleton)#value_from_values
0.490.490.005863424/12143918Protobuf::Field::StringField(singleton)#value_from_values
1%1%1.021.000.0212143918Hash#fetch
1.020.021.001/2Bundler.setup
1%0%1.020.021.002Bundler.definition
0.810.020.801/1Bundler::Definition.build
0.140.000.141/1Bundler.configure
0.970.610.362494608/2494608Protobuf::Decoder.decode_each_field
1%0%0.970.610.362494608Protobuf::Varint.decode
0.360.360.002494608/2494608ProtobufJavaHelpers::Varinter.read_varint
0.810.020.801/1Bundler.definition
1%0%0.810.020.801Bundler::Definition.build
0.780.000.781/1Bundler::Dsl.evaluate
0.320.170.15415768/1247457Protobuf::Field::StringField#encode_to_stream
0.470.24 0.23831536/1247457Protobuf::Field::IntegerField#encode
1%0%0.790.410.381247457Protobuf::Field::VarintField.encode
0.380.380.001247457/1247457ProtobufJavaHelpers::Varinter.to_varint
0.780.520.271247304/1247304Protobuf::Enum.fetch
1%0%0.780.520.271247304Protobuf::Enum.enum_for_tag_integer
0.160.160.001247304/15890196Hash#[]
0.110.110.23 0.001247304/1247757Array#first2036212/7126742Protobuf::Field::IntegerField#decode
0.780.290.29 0.000.781/1Bundler::Definition.build2036212/7126742Protobuf::Field::IntegerField#encode
1%0%0.780.000.781Bundler::Dsl.evaluate
0.590.000.591/1Bundler::Dsl#to_definition
0.160.000.161/1Bundler::Dsl#eval_gemfile
0.720.510.21831537/831537Protobuf::Field::IntegerField#coerce!
1%0%0.720.510.21831537Protobuf::Field::IntegerField#acceptable?
0.120.120.00831537/2912066Kernel.kind_of?
0.680.680.002910376/2910376IO::GenericWritable.<<
0%0%0.680.680.650.65 0.002910376StringIO#write7126742##&
0.640.400.241412810/1412810Array#each
0%0%0.640.57 0.400.241412810Benchmark::Timing.now
0.240.240.001412810/1412811Process.clock_gettime
0.110.110.00415768/1247305Protobuf::Message#each_field_for_serialization
0.530.410.13831537/1247305Protobuf::Field::StringField(singleton)#set_field
0%0%0.640.520.131247305Test::Resource#_protobuf_message_required_field_tags
0.130.130.00831537/832615Kernel.dup
0.550.550.007265478/8096960Benchmark::IPS::Job::Entry#call_times
0%0%0.640.640.008096960Fixnum#<
0.630.630.0010896824/10896826Kernel.respond_to?
0%0%0.630.630.0010896826Kernel.respond_to_missing?
0.260.260.00831465/1662929Protobuf::Field::IntegerField#decode
0.340.340.00831464/1662929Protobuf::Field::IntegerField#encode
0%0%0.610.610.001662929Fixnum#&
0.590.000.591/1Bundler::Dsl.evaluate
0%0%0.590.000.591Bundler::Dsl#to_definition
0.590.010.571/1249742Class#new
0.570.010.571/1Class#new
0%0%0.570.010.571Bundler::Definition#initialize
0.230.000.231/1Bundler::Definition#converge_paths
0.540.000.541/1Bundler::Definition#specs
0%0%0.540.000.541Bundler::Definition#resolve
0.340.000.341/6Bundler::SpecSet#for
0.190.000.191/1Bundler::Definition#converge_locked_specs
0.340.000.341/6Bundler::Definition#resolve
0%0%0.530.000.536Bundler::SpecSet#for
0.530.020.516/6Kernel.loop
0.530.020.516/6Bundler::SpecSet#for
0%0%0.530.020.516Kernel.loop
0.460.010.46215/215Bundler::SpecSet#spec_for_dependency
0.110.110.00415768/1247457Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.130.130.00415768/1247457Protobuf::Field::EnumField(singleton)#encode_to_stream
0.250.250.00415768/1247457Protobuf::Field::StringField#encode_to_stream
0%0%0.520.510.011247457Protobuf::Field::BaseField#tag_encoded
0.520.370.15831537/831537Protobuf::Field::StringField(singleton)#set_field
0%0%0.520.370.15831537Protobuf::Field::StringField#coerce!
0.510.260.25415768/415768Protobuf::Field::StringField(singleton)#set
0%0%0.510.260.25415768Protobuf::Field::StringField#decode
0.180.180.00415768/415906String#+
0.490.000.491/1Bundler::Definition#specs
0%0%0.490.000.491Bundler::SpecSet#materialize
0.370.000.371/223Array#map!
0.460.010.46215/215Kernel.loop
0%0%0.460.010.46215Bundler::SpecSet#spec_for_dependency
0.350.000.34215/336Bundler::SpecSet#lookup
0.120.000.1237/153Protobuf::Message::Fields::ClassMethods.repeated
0.310.010.30109/153Protobuf::Message::Fields::ClassMethods.optional
0%0%0.440.010.43153Protobuf::Message::Fields::ClassMethods.define_field
0.410.000.41153/153Protobuf::Field.build
0.350.000.34215/336Bundler::SpecSet#spec_for_dependency
0%0%0.420.010.41336Bundler::SpecSet#lookup
0.390.000.398/50Bundler::Index.sort_specs
0.370.000.371/223Bundler::SpecSet#materialize
0%0%0.420.010.41223Array#map!
0.370.000.3739/39Bundler::LazySpecification#__materialize__
0.410.000.41153/153Protobuf::Message::Fields::ClassMethods.define_field
0%0%0.410.000.41153Protobuf::Field.build
0.400.010.39153/1249742Class#new
0.390.000.3950/193Bundler::Index.sort_specs
0%0%0.410.010.40193Enumerable#sort_by
0.380.010.371378/1520Array#<=>
0.390.000.398/50Bundler::SpecSet#lookup
0%0%0.390.000.3950Bundler::Index.sort_specs
0.390.000.3950/193Enumerable#sort_by
0.390.020.37153/153Class#new
0%0%0.390.020.37153Protobuf::Field::BaseField#initialize
0.370.040.331378/1439Array#<=>
0%0%0.390.050.341439Gem::Version#<=>
0.300.300.001224/1224Fixnum#>
0.360.240.11415768/416553Protobuf::Field::StringField#encode_to_stream
0%0%0.380.250.13416553BasicObject#!=
0.380.380.001247457/1247457Protobuf::Field::VarintField.encode
0%0%0.380.380.001247457ProtobufJavaHelpers::Varinter.to_varint
0.380.010.371378/1520Enumerable#sort_by
0%0%0.380.010.371520Array#<=>
0.370.040.331378/1439Gem::Version#<=>
0.380.080.29415768/831536Hash#each_key
0%0%0.380.080.29831536Protobuf::Field::EnumField(singleton)#value_from_values
0.370.000.3739/39Array#map!
0%0%0.370.000.3739Bundler::LazySpecification#__materialize__
0.240.000.2438/38Bundler::Source::Rubygems#specs
0.360.360.002494608/2494608Protobuf::Varint.decode
0%0%0.360.360.002494608ProtobufJavaHelpers::Varinter.read_varint
0.160.000.161/933Bundler::Dsl#eval_gemfile
0%0%0.330.140.19933BasicObject#instance_eval
0.150.000.141/1Bundler::Dsl#gemspec
0.110.110.001247313/2912066Protobuf::Enum.fetch
0.120.120.00831537/2912066Protobuf::Field::IntegerField#acceptable?
0%0%0.320.320.002912066Kernel.kind_of?
0.320.000.31109/109Kernel.require
0%0%0.320.000.31109Protobuf::Message::Fields::ClassMethods.optional
0.310.010.30109/153Protobuf::Message::Fields::ClassMethods.define_field
0%0%0.300.300.003743574Kernel.nil?
0.300.300.001224/1224Gem::Version#<=>
0%0%0.300.300.001224Fixnum#>
0.290.210.08831536/831799Protobuf::Field::IntegerField#decode
0%0%0.300.210.08831799Numeric#nonzero?
0.290.290.00831537/831720Protobuf::Field::StringField(singleton)#set_field
0%0%0.290.290.00831720Array#delete
0.190.040.1513/14Gem::Specification.load
0%0%0.280.050.2414Kernel.eval
0.240.050.1914/1249742Class#new
0.230.000.231/2Bundler::Source::Rubygems#installed_specs
0%0%0.260.000.262Bundler::Index.build
0.200.000.201/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0.260.000.261/1Kernel.require
0%0%0.260.000.261Gem::Specification.load_defaults
0.260.000.251/1Gem::Specification.each_spec
0.260.000.251/1Gem::Specification.load_defaults
0%0%0.260.000.251Gem::Specification.each_spec
0.250.000.251/1Gem::Specification.each_gemspec
0.250.000.251/1Gem::Specification.each_spec
0%0%0.250.000.251Gem::Specification.each_gemspec
0.250.000.251/417509Array#each
0.100.000.103/287Gem::Specification.gemspec_stubs_in
0%0%0.250.050.20287Array#select
0.100.000.1062/62Gem::StubSpecification#valid?
0%0%0.240.050.20630Array#map
0.240.140.10415768/416036Protobuf::Field::EnumField#encode
0%0%0.240.140.10416036Protobuf::Enum#to_i
0.240.000.2438/38Bundler::LazySpecification#__materialize__
0%0%0.240.000.2438Bundler::Source::Rubygems#specs
0.230.000.231/1Bundler::Source::Rubygems#installed_specs
0.240.240.001412810/1412811Benchmark::Timing.now
0%0%0.240.240.001412811Process.clock_gettime
0.230.000.231/142Bundler::Definition#converge_paths
0%0%0.240.000.24142Array#any?
0.230.000.231/1Bundler::Definition#specs_changed?
0.230.000.231/1Bundler::Definition#initialize
0%0%0.230.000.231Bundler::Definition#converge_paths
0.230.000.231/142Array#any?
0.230.000.231/1Array#any?
0%0%0.230.000.231Bundler::Definition#specs_changed?
0.210.000.211/1Bundler::Definition#specs_for_source_changed?
0.100.100.00415768/1247535Protobuf::Field::EnumField#acceptable?
0.120.120.00831536/1247535Protobuf::Field::EnumField#coerce!
0%0%0.230.230.001247535Protobuf::Field::BaseField#type_class
0.230.000.231/1Bundler::Source::Rubygems#specs
0%0%0.230.000.231Bundler::Source::Rubygems#installed_specs
0.230.000.231/2Bundler::Index.build
0.210.210.00415768/415768Protobuf::Decoder.decode_each_field
0%0%0.210.210.00415768StringIO#read
0.210.000.211/1Bundler::Definition#specs_changed?
0%0%0.210.000.211Bundler::Definition#specs_for_source_changed?
0.200.000.201/2Bundler::Source::Path#specs
0.200.000.2012/13Array#each
0%0%0.210.000.2113Gem::Specification.load
0.190.040.1513/14Kernel.eval
0.200.000.201/1Bundler::Index.build
0%0%0.200.000.201Bundler::RubygemsIntegration::MoreFuture#all_specs
0.190.000.191/1Gem::Specification.stubs
0.200.000.201/2Bundler::Definition#specs_for_source_changed?
0%0%0.200.000.202Bundler::Source::Path#specs
0.200.000.202/2Bundler::Source::Path#local_specs
0.200.020.1817/17Class#new0.172036213/2036213Protobuf::Field::StringField(singleton)#set_field
0% 0%0.200.020.1817Gem::Specification#initialize0.570.400.172036213Protobuf::Field::StringField#coerce!
0.200.000.202/2Bundler::Source::Path#specs0.460.060.4017/19(top)
0% 0%0.200.000.202Bundler::Source::Path#local_specs0.460.060.4019Kernel.load
0.200.000.201/1Bundler::Source::Path#load_spec_files0.360.030.342/1880Kernel.require
0.200.430.43 0.000.201/1Bundler::Source::Path#local_specs3378485/3378486Benchmark::Timing.now
0% 0%0.200.430.43 0.000.201Bundler::Source::Path#load_spec_files3378486Process.clock_gettime
0.190.000.191/417509Array#each0.400.250.161018106/1018106Protobuf::Field::StringField(singleton)#set
0%0%0.400.250.161018106Protobuf::Field::StringField#decode
0.190.000.192/7Kernel.require0.390.010.391/2Bundler.setup
0% 0%0.190.000.197IO.open0.390.010.392Bundler.definition
0.180.080.102/2IO#each_line0.300.000.301/1Bundler::Definition.build
0.190.390.39 0.000.191/1Array#each6108636/6108636Protobuf::Varint.decode
0% 0%0.190.000.191Bundler::Source::Path#validate_spec
0.190.390.39 0.000.191/1Bundler::RubygemsIntegration#validate6108636ProtobufJavaHelpers::Varinter.read_varint
0.190.32 0.000.191/1Bundler::Source::Path#validate_spec0.321/838Bundler::Runtime#requested_specs
0% 0%0.190.39 0.000.191Bundler::RubygemsIntegration#validate0.38838Kernel.send
0.180.32 0.000.180.32 1/1Bundler::UI::Silent#silenceBundler::Definition#requested_specs
0.190.35 0.000.190.35 1/1Bundler::Definition#resolveBundler.setup
0% 0%0.190.35 0.000.190.35 1Bundler::Definition#converge_locked_specsBundler::Runtime#setup
0.190.32 0.000.190.32 1/1Bundler::RubygemsIntegration::MoreFuture#all_specsBundler::Runtime#requested_specs
0% 0%0.190.340.34 0.000.191Gem::Specification.stubs9163848Kernel.nil?
0.180.180.100.10 0.00415768/415906Protobuf::Field::StringField#decode2036213/7128126Protobuf::Field::IntegerField#acceptable?
0.140.140.003054327/7128126Protobuf::Enum.fetch
0% 0%0.180.180.340.34 0.00415906String#+7128126Kernel.kind_of?
0.180.32 0.000.180.32 1/1Bundler::RubygemsIntegration#validateBundler::Runtime#setup
0% 0%0.180.32 0.000.180.32 1Bundler::UI::Silent#silenceBundler::Runtime#requested_specs
0.180.32 0.000.181/1Gem::Specification#validate0.321/838Kernel.send
0.180.32 0.000.180.32 1/1Bundler::UI::Silent#silenceKernel.send
0% 0%0.180.32 0.000.180.32 1Gem::Specification#validateBundler::Definition#requested_specs
0.180.080.102/2IO.open
0%0%0.180.080.102IO#each_line
0%0%0.170.32 0.000.179Bundler::SpecSet#each0.321/1Bundler::Definition#specs_for
0.160.160.32 0.001412260/1412260Array#each0.321/1Bundler::Definition#requested_specs
0% 0%0.160.160.32 0.001412260Float#<0.321Bundler::Definition#specs_for
0.160.31 0.000.160.31 1/1Bundler::Dsl.evaluateBundler::Definition#specs
0.320.090.241018106/2036212##each_key
0% 0%0.160.000.161Bundler::Dsl#eval_gemfile
0.160.000.161/933BasicObject#instance_eval0.320.090.242036212Protobuf::Field::EnumField(singleton)#value_from_values
0.160.160.31 0.001663072/1663072Protobuf::Decoder.decode_each_field0.311/1Bundler::Definition#specs_for
0% 0%0.160.160.31 0.001663072StringIO#eof0.311Bundler::Definition#specs
0.210.000.211/1Bundler::SpecSet#materialize
0.150.30 0.000.150.30 1/1Class#newBundler.definition
0% 0%0.150.30 0.000.150.30 1Bundler::LockfileParser#initializeBundler::Definition.build
0.140.020.121/417509Array#each0.290.000.291/1Bundler::Dsl.evaluate
0.150.29 0.000.140.29 1/1BasicObject#instance_evalBundler::Definition.build
0% 0%0.150.29 0.000.140.29 1Bundler::Dsl#gemspecBundler::Dsl.evaluate
0.210.000.211/1Bundler::Dsl#to_definition
0.140.140.280.28 0.001662784/1665061Protobuf::Decoder.decode_each_field3054471/3054471Protobuf::Field::VarintField.encode
0% 0%0.140.140.280.28 0.001665061Fixnum#==3054471ProtobufJavaHelpers::Varinter.to_varint
0.140.000.141/1Bundler.definition0.260.150.111018106/1018374Protobuf::Field::EnumField#encode
0% 0%0.140.000.141Bundler.configure0.260.150.111018374Protobuf::Enum#to_i
0.140.110.11 0.000.141/1Bundler.configure_gem_home_and_path1018374/1018374Protobuf::Enum#tag
0.140.000.141/1Bundler.configure0.240.130.111008106/1018106Proc#call
0% 0%0.25 0.140.111018106StringIO.new
0.110.11 0.000.141Bundler.configure_gem_home_and_path1018106/1018106StringIO#initialize
0.130.100.10 0.000.131/1Bundler.configure_gem_path1018106/3054760Protobuf::Field::EnumField#acceptable?
0.130.130.140.14 0.00831537/832615Test::Resource#_protobuf_message_required_field_tags2036212/3054760Protobuf::Field::EnumField#coerce!
0% 0%0.130.130.240.24 0.00832615Kernel.dup3054760Protobuf::Field::BaseField#type_class
0.130.130.18 0.00415768/415768Class#new0.181/400Bundler::SpecSet#materialize
0% 0%0.130.130.220.020.20400##map!
0.18 0.00415768StringIO#initialize0.1839/39Bundler::LazySpecification#__materialize__
0.130.21 0.000.130.21 1/1Bundler.configure_gem_home_and_pathBundler::Dsl.evaluate
0% 0%0.130.21 0.000.130.21 1Bundler.configure_gem_pathBundler::Dsl#to_definition
0.130.000.131/1Bundler.use_system_gems?0.210.010.201/2037678Class#new
0.130.21 0.000.130.21 1/1Bundler.configure_gem_pathBundler::Definition#specs
0% 0%0.130.21 0.000.130.21 1Bundler.use_system_gems?Bundler::SpecSet#materialize
0.130.18 0.000.131/2Bundler.configured_bundle_path0.181/400##map!
0.130.200.20 0.000.131/2Bundler.use_system_gems?4072424/4072424Protobuf::Decoder.decode_each_field
0% 0%0.130.200.20 0.000.132Bundler.configured_bundle_path4072424StringIO#eof
0.110.020.101/218Bundler.settings0.200.000.201/1Class#new
0% 0%0.130.010.123Gem::Specification.gemspec_stubs_in0.200.000.201Bundler::Definition#initialize
0.100.000.103/287Array#select0.180.120.061018106/1018887Protobuf::Field::StringField(singleton)#encode_to_stream
0% 0%0.19 0.120.000.1210Bundler::SpecSet#sorted0.061018887BasicObject#!=
0.120.180.18 0.000.124/4TSort.tsort4072424/4075603Protobuf::Decoder.decode_each_field
0.12
0%0%0.180.18 0.000.1237/37Kernel.require4075603##==
0% 0%0.120.180.18 0.000.1237Protobuf::Message::Fields::ClassMethods.repeated2036350##+
0.120.180.180.002036213/2036396Protobuf::Field::StringField(singleton)#set_field
0%0%0.180.18 0.000.1237/153Protobuf::Message::Fields::ClassMethods.define_field2036396##delete
0.110.020.101/218Bundler.configured_bundle_path0.180.000.1839/39##map!
0% 0%0.120.020.10218Bundler.settings0.180.000.1839Bundler::LazySpecification#__materialize__
0.120.170.17 0.000.124/4Bundler::SpecSet#sorted3054318/3054780Protobuf::Enum.enum_for_tag_integer
0% 0%0.120.000.124TSort.tsort
0.120.170.17 0.000.124/4TSort.tsort3054780##first
0.120.170.17 0.000.124/4TSort.tsort3377948/3377948##each
0% 0%0.120.000.124TSort.tsort
0.120.170.17 0.000.124/4Enumerable#to_a3377948##<
0.120.11 0.000.124/8Enumerator#each0.11109/153Protobuf::Message::Fields::ClassMethods.optional
0% 0%0.120.16 0.000.128TSort.tsort_each0.16153Protobuf::Message::Fields::ClassMethods.define_field
0.120.15 0.000.124/4TSort.each_strongly_connected_component0.15153/153Protobuf::Field.build
0.120.15 0.000.124/4TSort.tsort0.15153/153Protobuf::Message::Fields::ClassMethods.define_field
0% 0%0.120.15 0.000.124Enumerable#to_a0.15153Protobuf::Field.build
0.120.000.124/8Enumerator#each0.150.010.14153/2037678Class#new
0.120.150.15 0.000.124/8Enumerable#to_a3054318/3054318Protobuf::Decoder.decode_each_field
0% 0%0.120.000.128Enumerator#each
0.120.150.15 0.000.124/8TSort.tsort_each3054318##>>
0.120.000.124/4TSort.tsort_each0.140.010.13153/153Class#new
0% 0%0.120.000.124TSort.each_strongly_connected_component0.140.010.13153Protobuf::Field::BaseField#initialize
0.120.000.124/122Method#call
0%0%0.130.060.071137BasicObject#instance_eval
0.120.00 0.124/122TSort.each_strongly_connected_component0.001018106/1018106Protobuf::Decoder.decode_each_field
0% 0% 0.120.000.12122Method#call
0.12 0.000.124/4Bundler::SpecSet#tsort_each_node1018106StringIO#read
0.120.00 0.124/4Method#call0.002036213/2037179Test::Resource#_protobuf_message_required_field_tags
0% 0% 0.120.00 0.124Bundler::SpecSet#tsort_each_node
0.110.010.114/417509Array#each0.002037179Kernel.dup
0.11 0.11 0.00405768/415768Proc#call1018106/1018106StringIO.new
0% 0.11 0.11 0.00415768Protobuf::Message#to_proto1018106StringIO#initialize
0.100.010.1062/1079Gem::StubSpecification#valid?0.110.000.11109/109Kernel.require
0% 0% 0.110.020.101079Gem::StubSpecification#data0.000.11109Protobuf::Message::Fields::ClassMethods.optional
0.110.000.11109/153Protobuf::Message::Fields::ClassMethods.define_field
0.11 0.11 0.001247304/1247757Protobuf::Enum.enum_for_tag_integer1018374/1018374Protobuf::Enum#to_i
0% 0.11 0.11 0.001247757Array#first1018374Protobuf::Enum#tag
0% 0% 0.110.02 0.080.03583Module#module_eval60Kernel.eval
0.110.10 0.000.110.10 1/1 Kernel.require
0% 0%0.110.10 0.000.110.10 1Concurrent::Utility::NativeExtensionLoader.load_native_extensionsGem::Specification.load_defaults
0.110.01 0.10118/118Array#each
0%0%0.110.010.00 0.10118TSort.each_strongly_connected_component_from1/1Gem::Specification.each_spec
0.100.10 0.00831537/831706Protobuf::Message#initialize0.101/1Gem::Specification.load_defaults
0% 0% 0.100.000.101Gem::Specification.each_spec
0.10 0.00831706Kernel.block_given?0.101/1Gem::Specification.each_gemspec
0.10 0.00 0.1062/62Array#select1/1Gem::Specification.each_spec
0% 0.10 0.00 0.1062Gem::StubSpecification#valid?1Gem::Specification.each_gemspec
0.100.010.00 0.1062/1079Gem::StubSpecification#data1/1019611##each
0.10 0.10 0.0026Java::JavaPackage#method_missing
2037360##to_s
@@ -67,551 +67,569 @@

Total time: 63.12

- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - + - - - - - - - - - - - - + + + - + - + - - - + + + - + - - - + + + - + - - - - - + + + + + + + + + + + + + + - + - - - - - + + + + + - - + - + + + + + + + + + + + - - - + + - + - + + - - - + + + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + - - + + + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - + - - + + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - - - + + + - + - - - + + + - - - - + + + + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - + - - + + - + - + - - + + - + - + - - + + - + - - - - + + + + - - - - + + + + - + - - - - - + + + + + @@ -621,7 +639,7 @@

Total time: 63.12

- + @@ -632,270 +650,270 @@

Total time: 63.12

- + - - - - + + + + - + - - - + + + - + - - + + - + - - + + - + - - - - + + + + - + - - + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - + + - - + + - + - - + + - - + + - + - - + + - + - - + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - + - + - - - + + + - - - - + + + + - - - - + + + + - + - - - - + + + + @@ -905,1642 +923,1642 @@

Total time: 63.12

- + - - - - - + + + + + - - - - - + + + + + - - + + - + - - - - - + + + + + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - + + + - + - - + + - - + + - + - - + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - - - - + + + + - + - - + + - + - + - - + + - - + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - + - - + + - - + + - + - - - - + + + + - - - - + + + + - + - - - + + + - + - + - + - + - + - + - + - - - + + + - + - - - + + + - + - - - - - + + + + + - + - - - - + + + + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - + - - - - - - - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - + + - - + + - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - + + + + + - + - + - - - + + + - - - - - + + + + + - - - - - + + + + + - + - - + + - - + + - - - - - - - - - - - - - - + + + + + - + - + + - - - - - - - - - - - - + + - - - - - - - - + + + + + + + + - + - - + + - - + + - + - - - - + + + + - - - - + + + + - + - + - - + + - + - - + + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - + - + - + + + + + + + + + + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + - + - - - - + + + + - - - - - + + + + + - + - - - - + + + + - + - - + + - - + + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - - - + + + + + + + + + + + + - - - + + + - + - - - - - + + + + + - + + + + + + + + + + - - + + - + - - + + - + - - + + - - + + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - - + + + + + - - - - - - - - - - - - - - + + + + + - - + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - - - - - - - - - - + + + + + - - - - - + + + + + - + - - + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + - + - + - + - - - - + + + + - - - - + + + + - + - - + + - + - + - - + + - + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - + - + + - - - - + + + + - - - - + + + + - - + + - + - + - + - - + + - + - - + + - + - - + + - - + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - - - + + + + - + - - + + - - + + - + - - - - + + + + - - - - + + + + - + - - + + - + - - - - - + + + + + - - - - - - - - - - - - - - + + + + + - + - - + - - + + + - + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - + - - - + + + - - - + + + - + - - + + - - + + - + - - + + - - + + - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + + + - - - - - + + + + + - + - - - - - + + + + + - - + - - + - - + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - + + - - + + - - + + - - + + - - + + - - + + - + + - - - + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + - + - + + - - - + + - + - - + + - - + + @@ -2548,8 +2566,8 @@

Total time: 63.12

- - + + @@ -2558,8 +2576,8 @@

Total time: 63.12

- - + + @@ -2567,53 +2585,53 @@

Total time: 63.12

- + - - + + - - + + - - - - + + + + - + - - + + - - - + + + - + - - + + - + @@ -2623,242 +2641,242 @@

Total time: 63.12

- + - - + + - + - - + + - + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + + + + + + + + + + - - + + - + + + + + + + + + + + - - + + - + @@ -2867,43 +2885,43 @@

Total time: 63.12

- + - - + + - + - + - + - + - + - + - + - + @@ -2911,694 +2929,1039 @@

Total time: 63.12

- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + - + - + - + - + - + - + - + - + + + + + + + + + + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + - - + - - + + + - - + - - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + - - + + - - - - - + + + + + - - - - - - - - - - - + - - + + + - - + - - - - - + + + + + + - - + + - - + + - - + + - - + + - + - + - - - + + + - - - - - + + + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - - - + + + - + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - + + - - - + + - + - - - - - + + + + + - - - - - + + + + + - - + - - + - - + + + - - - - - + + + + + + - - + + - - - + + - - + + - - + - - + + + - - + - - + + + - - + - + - - - + + + + - - - - - + + + + + - + - - + - - + + + - - + - - + + + - + + + + + + + + + + - - + + - - + + - - + + - - + + + + + + + + + + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - - - - - + + + + + - + - - + - - + + + - - + - - + + + - - + - - - - - - - - - - + - - + + + + + + + + + + + + - - - - - - + + + + + - + - - - + + + + + + + + + + + - - + + + - + - - - + + + + + + + + + + + - - + + + - + - - + - - + + + - - + - - + + + + + + + + + + + + - + - + - + - + - + - + @@ -3608,1301 +3971,1280 @@

Total time: 63.12

- - + + - - + + - - + + - - + + - - - - - - - - - - - + + - - - + + - + + - - - + + - + + - + - + - + - - - - - + + + + - - - + + + + - - + + - + - - - - + + + + - + - - - + + + - - - + + + - + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + - - - - - - + + - - - - - - - - + + + + - - - - + + - + + - - + - - - - - - - - - + + + - + + + - - - - - + + + + + - - - - - - - + + + - - - + + + + + + + + + + + + - - - - - - - + + + + - - + - - - - - - - - - - + + + + - + - - + + + + + + + + + - - - - - + + + + - + + + + + + + + + - - + + + + + + + - - + - - - - + + + + + - - - + + + + + + + + + + - - + - + - - - + - - - - - - - - - + + + + + - - - - - - - - + + - - - - - + + + - + + - - - - - - - - - - - - + + - - - - - - + + + + + + + + + - - - - + + + + + + + + + - - - + - - - - - - - - - - + + + + + - - + + + + + + + - - - + + + + + + + - - - - - - - + + + - + - - - - - - - + + - - + + + - - - - - - + - - - - - - + + + - - - + + - - + + + + + + + + + + - - - - + + + + + + + - + + + + + + + + + + + + + + + - - + + + - - - - - + + + + - - - - - - - + - - + - + + - - - - + + + + + + + + + + + + - - - + + + + + - - - - - - - - - - + + + - + + + - + - - + - - - - - - + + + + + + - - - - + - - - - + + + + + + + - - - - - - + + + + - - - + - - - - - - - + + + + - - + + - - - - + - - - - - + + + + - - - + + + - - - + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + - - - + - - - - - - - - - - - + + + + + + + - - - - + + + + + - - - + + + + - + + + + - - + + + + + - - + + - - + - + - - - - - - + - - - - - - - - + + - - + + + + + + + - + + + + - - - - - - - - - - - - + - - - - - + + - + + + - - - - + + + + + + + + + + + + + + + - + + - - - - + + - - - - - + + + + + - - - - - - - - - + + + - + + - - - - - - - - - - - + + + + + + + - - + + + + + + + + + + + + + - + + - - + + + + + + + + + - - - - - - - - - + + + + + + + + + + - - + + - - - + - - + + - - - - - - - + + + - - - - + - + + + - + - - + @@ -4912,84 +5254,81 @@

Total time: 63.12

+ + + - - - - + + - - - + - - - - - + + - + - - + - - + + - - + - - - + + + + + + + - - - + - + + @@ -4999,21 +5338,24 @@

Total time: 63.12

+ + + - - + + + + + - - - @@ -5037,11 +5379,12 @@

Total time: 63.12

+ + - @@ -5051,8 +5394,8 @@

Total time: 63.12

- + @@ -5063,14 +5406,13 @@

Total time: 63.12

- + - - + @@ -5084,26 +5426,26 @@

Total time: 63.12

- + - + - + @@ -5114,7 +5456,6 @@

Total time: 63.12

- @@ -5123,6 +5464,7 @@

Total time: 63.12

+ From 07e5c92074d485ab197896e0fd8354b957f03999 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 26 Dec 2018 16:30:37 -0700 Subject: [PATCH 1110/1191] fix issue with hash generation --- lib/protobuf/field/base_field.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 7cb668b7..1fdc56a9 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -255,6 +255,17 @@ def wire_type def fully_qualified_name_only! @name = @fully_qualified_name + + ## + # Recreate all of the meta methods as they may have used the original `name` value + # + define_hash_accessor_for_message! + define_field_p! + define_field_and_present_p! + define_set_field! + define_set_method! + define_to_message_hash! + define_encode_to_stream! end private From 8a6a87d668224adfdb5514e71ebdd93cd34e61e6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 26 Dec 2018 17:19:15 -0700 Subject: [PATCH 1111/1191] use local helpers to troubleshoot encoding differences --- Gemfile | 2 ++ lib/protobuf/field/bool_field.rb | 11 +++++++---- protobuf.gemspec | 2 +- spec/encoding/extreme_values_spec.rb | Bin 1358 -> 1381 bytes 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index fa75df15..d5b5bd21 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source 'https://rubygems.org/' +gem 'protobuf_java_helpers', :path => "~/code/protobuf_java_helpers" + gemspec diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 530cfed8..b325acfd 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -29,10 +29,13 @@ def acceptable?(val) end def coerce!(val) - return true if TRUE_VALUES.include?(val) - return false if FALSE_VALUES.include?(val) - - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" + if TRUE_VALUES.include?(val) + true + elsif FALSE_VALUES.include?(val) + false + else + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" + end end def decode(value) diff --git a/protobuf.gemspec b/protobuf.gemspec index 4e20358a..2d9330ef 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -51,7 +51,7 @@ require "protobuf/version" s.add_development_dependency 'varint' s.add_development_dependency 'ruby-prof' elsif RUBY_PLATFORM =~ /java/i - s.add_development_dependency 'protobuf_java_helpers' + #s.add_development_dependency 'protobuf_java_helpers' s.add_development_dependency 'fast_blank_java' s.add_development_dependency 'pry' end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 477e695aa37676462eb7cbcd5cc355e2f7fc387d..6678f991028fce2a8ad5b948a1dfd6ee62a458c3 100644 GIT binary patch delta 188 zcmX@d^^|MESw`iFXJZ+aCu=d*0Lf*H3R21nU|?01T9hB3mXn`YqF`&MV4%aLJoz4@ zxGYS%I5#mT2O)2$X9`jwz@!K?#*j%KNCq&;0?Aw^bs#x~NexKuV$ueZPr+)~m{oyn uZDuVX8Op2xBukkMfaG~*@yUCbg~2RiAj!l6Qm4+M0wldzG=XFZ%Pjz6yDt6! delta 167 zcmaFLb&hMo*@@?3C+jfQOkT;TpsxT1R#mA*`SEEv`H3Y8wsr~zI$Tik{Jd0zu%Qmu z$Q+KNy;d5L-PDfy*IIjJDC+(3p}S@}8o u0d Date: Thu, 27 Dec 2018 11:49:21 -0700 Subject: [PATCH 1112/1191] create exception for boolean fetch/hash access but use the faster --- lib/protobuf/field/base_field.rb | 2 + .../field/base_field_method_definitions.rb | 11 +- profile.html | 5963 +++++++++-------- 3 files changed, 3058 insertions(+), 2918 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 1fdc56a9..7a63ece1 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -143,6 +143,8 @@ def define_hash_accessor_for_message! ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_value_from_values!(self) elsif repeated? ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_value_from_values!(self) + elsif type_class == ::Protobuf::Field::BoolField # boolean present check + ::Protobuf::Field::BaseFieldMethodDefinitions.define_bool_field_value_from_values!(self) else ::Protobuf::Field::BaseFieldMethodDefinitions.define_field_value_from_values!(self) end diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 5b1864a1..7076f5cd 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -282,10 +282,19 @@ def field?(values) RUBY end + def self.define_bool_field_value_from_values!(selph) + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def value_from_values(values) + values.fetch(#{fully_qualified_name_string(selph)}) { default_value } + end + alias :value_from_values_for_serialization value_from_values + RUBY + end + def self.define_field_value_from_values!(selph) selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 def value_from_values(values) - values.fetch(#{fully_qualified_name_string(selph)}) { default_value } + values[#{fully_qualified_name_string(selph)}] || default_value end alias :value_from_values_for_serialization value_from_values RUBY diff --git a/profile.html b/profile.html index fd9f6fb2..1d3eed61 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 63.30

+

Total time: 63.27

%Total
100% 0%63.1263.30 0.0063.1263.30 0 (top)
60.1360.08 0.0060.1360.08 1/1 Benchmark::IPS.ips
0.900.99 0.000.900.99 2/112 Kernel.require
0.890.94 0.000.890.94 6/1880 Kernel.require
0.740.77 0.040.700.72 1/5##times##times
0.460.52 0.060.400.45 17/19 Kernel.load
0.740.040.701/5(top)0.120.000.121/992490Gem::Specification.each_gemspec
60.120.13 0.0060.122/5Benchmark::IPS::Job#run
96%0%60.880.0560.835##times0.131/992490##flat_map
40.120.25 0.0040.121/1Benchmark::IPS::Job#run_benchmark0.2519/992490Kernel.require
20.000.0020.001/11.7618.251/992490 Benchmark::IPS::Job#run_warmup
0.340.000.3310000/1018106Protobuf::Message::Serialization::ClassMethods.decode_from40.080.0140.071/992490Benchmark::IPS::Job#run_benchmark
96%2%60.921.8059.12992490##each
0.220.010.2110000/1018106Protobuf::Encoder.encode57.172.6954.483301171/3301171Benchmark::IPS::Job::Entry#call_times
0.100.840.420.423301704/3301704Benchmark::Timing.now
0.150.15 0.000.101/1019611Gem::Specification.each_gemspec3301175/3301175##<
0.230.130.13 0.000.2319/1019611Kernel.require3301185/16556215##+
0.130.000.132/3Gem::Specification.gemspec_stubs_in
20.001.6718.331/1019611Benchmark::IPS::Job#run_warmup0.770.040.721/5(top)
40.120.0140.121/1019611Benchmark::IPS::Job#run_benchmark60.080.0060.082/5Benchmark::IPS::Job#run
96%2%60.791.7159.091019611##each0%60.870.0660.815##times
57.282.7154.563377944/3377944Benchmark::IPS::Job::Entry#call_times40.080.0040.081/1Benchmark::IPS::Job#run_benchmark
0.860.430.433378485/3378485Benchmark::Timing.now20.000.0020.001/1Benchmark::IPS::Job#run_warmup
0.170.170.35 0.003377948/3377948##<0.3510000/990985Protobuf::Message::Serialization::ClassMethods.decode_from
0.130.130.003377958/17079139##+0.230.010.2210000/990985Protobuf::Encoder.encode
60.1360.08 0.0060.1360.08 1/1 (top)
95%94% 0%60.1360.08 0.0060.1360.08 1 Benchmark::IPS.ips
60.1360.08 0.0060.1360.08 1/1 Benchmark::IPS::Job#run
60.1360.08 0.0060.1360.08 1/1 Benchmark::IPS.ips
95%94% 0%60.1360.08 0.0060.1360.08 1 Benchmark::IPS::Job#run
60.1260.08 0.0060.1260.08 2/5##times##times
57.282.7154.563377944/3377944##each57.172.6954.483301171/3301171##each
90% 4%57.282.7154.56337794457.172.6954.483301171 Benchmark::IPS::Job::Entry#call_times
53.312.0951.2213700098/1370064353.282.2051.0813253947/13254492 Proc#call
0.680.680.630.63 0.0017078042/19114271##<16555118/18537105##<
0.57 0.57 0.0013700098/17079139##+13253947/16556215##+
53.312.0951.2213700098/1370064353.282.2051.0813253947/13254492 Benchmark::IPS::Job::Entry#call_times
84% 3%53.342.1051.251370064353.312.2151.1013254492 Proc#call
22.712.2220.4912691992/1269199222.652.1720.4812272962/12272962 Protobuf::Message#to_hash
13.5313.54 0.2813.241008106/101810613.26980985/990985 Protobuf::Message::Serialization::ClassMethods.decode_from
8.820.318.511008106/10181068.740.308.44980985/990985 Protobuf::Encoder.encode
3.980.153.831008106/20376783.960.143.82980985/1983436 Class#new
1.781.79 0.261.521008106/10181061.53980985/990985 Test::Resource#status=
0.240.130.260.15 0.111008106/1018106980985/990985 StringIO.new
40.1240.08 0.0040.1240.08 1/1##times##times
63% 0%40.1240.08 0.0040.1240.08 1 Benchmark::IPS::Job#run_benchmark
40.1240.08 0.0140.121/1019611##each40.071/992490##each
8.081.326.761018106/137100991.336.75990985/13263948 Protobuf::Message#each_field_for_serialization
20.495.4315.0712691992/1371009920.485.3315.1412272962/13263948 Protobuf::Message#to_hash
45% 10%28.586.7521.8313710099##each_key28.566.6621.8913263948##each_key
6.052.163.8912691992/126919925.982.173.8012272962/12272962 Protobuf::Field::Int64Field(singleton)#to_message_hash
5.942.233.7012691992/126919925.722.183.5412272962/12272962 Protobuf::Field::StringField(singleton)#to_message_hash
2.122.122.452.45 0.0028438302/37606151##[]27518879/36442639##[]
1.870.601.271018106/10181061.920.631.29990985/990985 Protobuf::Field::StringField(singleton)#encode_to_stream
1.850.251.601018106/10181061.760.271.49990985/990985 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.510.281.231018106/10181061.470.261.22990985/990985 Protobuf::Field::Int64Field(singleton)#encode_to_stream
1.381.381.451.45 0.0028438302/3454694027518879/33464791 Test::Resource#_protobuf_message_field
0.420.41 0.090.331018106/147282040.32990985/14254932 Protobuf::Field::StringField(singleton)#value_from_values
0.370.39 0.090.281018106/147282040.30990985/14254932 Protobuf::Field::Int64Field(singleton)#value_from_values
0.320.34 0.090.241018106/20362120.25990985/1981970 Protobuf::Field::EnumField(singleton)#value_from_values
22.712.2220.4912691992/1269199222.652.1720.4812272962/12272962 Proc#call
35% 3%22.712.2220.491269199222.652.1720.4812272962 Protobuf::Message#to_hash
20.495.4315.0712691992/13710099##each_key20.485.3315.1412272962/13263948##each_key
0.00 20.00 1/1##times##times
31% 1 Benchmark::IPS::Job#run_warmup
20.001.6718.331/1019611##each1.7618.251/992490##each
0.340.35 0.000.3310000/1018106##times0.3510000/990985##times
13.5313.54 0.2813.241008106/101810613.26980985/990985 Proc#call
21% 0%13.8613.89 0.2913.58101810613.61990985 Protobuf::Message::Serialization::ClassMethods.decode_from
12.890.2512.641018106/101810612.960.2312.73990985/990985 Protobuf::Message::Serialization.decode_from
0.680.170.650.13 0.521018106/2037678990985/1983436 Class#new
12.890.2512.641018106/101810612.960.2312.73990985/990985 Protobuf::Message::Serialization::ClassMethods.decode_from
20% 0%12.890.2512.64101810612.960.2312.73990985 Protobuf::Message::Serialization.decode_from
12.641.6810.961018106/101810612.731.7510.98990985/990985 Protobuf::Decoder.decode_each_field
12.641.6810.961018106/101810612.731.7510.98990985/990985 Protobuf::Message::Serialization.decode_from
20% 2%12.641.6810.96101810612.731.7510.98990985 Protobuf::Decoder.decode_each_field
9.120.968.153054318/30543189.211.058.172972955/2972955 Protobuf::Message::Serialization.set_field_bytes
1.060.680.396108636/61086361.040.670.375945910/5945910 Protobuf::Varint.decode
0.200.200.190.19 0.004072424/40724243963940/3963940 StringIO#eof
0.180.180.170.17 0.004072424/4075603##==3963940/3966993##==
0.150.150.140.14 0.003054318/3054318##>>2972955/2972955##>>
0.12 0.12 0.001018106/1018106StringIO#read2972955/6936895##&
0.12 0.12 0.003054318/7126742##&990985/990985StringIO#read
9.120.968.153054318/30543189.211.058.172972955/2972955 Protobuf::Decoder.decode_each_field
14% 1%9.120.968.1530543189.211.058.172972955 Protobuf::Message::Serialization.set_field_bytes
3.290.233.061018106/10181063.380.253.13990985/990985 Protobuf::Field::EnumField(singleton)#set
2.210.251.961018106/10181062.260.271.99990985/990985 Protobuf::Field::Int64Field(singleton)#set
2.080.241.841018106/10181062.020.221.80990985/990985 Protobuf::Field::StringField(singleton)#set
0.330.330.260.26 0.003054318/37606151##[]2972955/36442639##[]
0.240.240.250.25 0.003054318/345469402972955/33464791 Test::Resource#_protobuf_message_field
0.220.23 0.010.2110000/1018106##times0.2210000/990985##times
8.820.318.511008106/10181068.740.308.44980985/990985 Proc#call
14% 0%9.040.328.7210181068.970.318.66990985 Protobuf::Encoder.encode
8.720.448.291018106/10181068.660.408.26990985/990985 Protobuf::Message#each_field_for_serialization
1.26 0.16 1.101018106/6108638990985/5945912 Protobuf::Field::EnumField(singleton)#set
1.400.161.241018106/6108638Protobuf::Field::Int64Field(singleton)#set1.380.201.18990985/5945912Protobuf::Field::StringField(singleton)#set
1.440.191.251018106/6108638Protobuf::Field::StringField(singleton)#set1.410.151.26990985/5945912Protobuf::Field::Int64Field(singleton)#set
1.550.251.560.26 1.301018106/6108638990985/5945912 Test::Resource#status=
3.100.502.602036214/6108638##each3.090.542.551981972/5945912##each
13% 2%8.751.277.4861086388.701.317.395945912 Protobuf::Message#set_field
2.400.751.652036213/2036213Protobuf::Field::StringField(singleton)#set_field2.380.491.891981971/1981971Protobuf::Field::Int64Field(singleton)#set_field
2.370.511.872036213/2036213Protobuf::Field::Int64Field(singleton)#set_field2.260.731.521981971/1981971Protobuf::Field::StringField(singleton)#set_field
2.250.471.792036212/20362120.481.771981970/1981970 Protobuf::Field::EnumField(singleton)#set_field
0.260.260.290.29 0.003054320/37606151##[]2972957/36442639##[]
0.200.200.210.21 0.003054320/345469402972957/33464791 Test::Resource#_protobuf_message_field
8.720.448.291018106/10181068.660.408.26990985/990985 Protobuf::Encoder.encode
13% 0%8.720.448.2910181068.660.408.26990985 Protobuf::Message#each_field_for_serialization
8.081.326.761018106/13710099##each_key1.336.75990985/13263948##each_key
0.150.150.001018106/30543190.140.140.00990985/2972956 Test::Resource#_protobuf_message_required_field_tags
6.052.163.8912691992/12691992##each_key5.982.173.8012272962/12272962##each_key
9% 3%6.052.163.89126919925.982.173.8012272962 Protobuf::Field::Int64Field(singleton)#to_message_hash
2.411.912.341.84 0.5012691992/1472820412272962/14254932 Protobuf::Field::Int64Field(singleton)#value_from_values
1.481.481.471.47 0.0012691992/31497159##[]=12272962/30496373##[]=
5.942.233.7012691992/12691992##each_key5.722.183.5412272962/12272962##each_key
9% 3%5.942.233.70126919925.722.183.5412272962 Protobuf::Field::StringField(singleton)#to_message_hash
2.551.960.5912691992/147282042.511.930.5812272962/14254932 Protobuf::Field::StringField(singleton)#value_from_values
1.151.151.031.03 0.0012691992/31497159##[]=12272962/30496373##[]=
0.150.16 0.010.14153/20376780.15153/1983436 Protobuf::Field.build
0.210.24 0.010.201/20376780.241/1983436 Bundler::Dsl#to_definition
0.680.170.650.13 0.521018106/2037678990985/1983436 Protobuf::Message::Serialization::ClassMethods.decode_from
3.980.153.831008106/20376783.960.143.82980985/1983436 Proc#call
8% 0%5.440.425.0220376785.380.375.001983436 Class#new
4.430.753.682036213/20362130.823.611981971/1981971 Protobuf::Message#initialize
0.200.24 0.000.200.23 1/1 Bundler::Definition#initialize
0.140.15 0.010.130.15 153/153 Protobuf::Field::BaseField#initialize
4.430.753.682036213/20362130.823.611981971/1981971 Class#new
7%6% 1% 4.430.753.6820362130.823.611981971 Protobuf::Message#initialize
3.520.423.102036213/2036424##each3.440.353.091981971/1982182##each
3.520.423.102036213/20364243.440.353.091981971/1982182 Protobuf::Message#initialize
5% 0%3.540.433.112036424##each3.470.373.101982182##each
3.100.502.602036214/61086383.090.542.551981972/5945912 Protobuf::Message#set_field
3.290.233.061018106/10181063.380.253.13990985/990985 Protobuf::Message::Serialization.set_field_bytes
5% 0%3.290.233.0610181063.380.253.13990985 Protobuf::Field::EnumField(singleton)#set
1.800.221.581018106/10181061.870.251.63990985/990985 Protobuf::Field::EnumField#decode
1.26 0.16 1.101018106/6108638990985/5945912 Protobuf::Message#set_field
0.170.170.002036213/31497159Protobuf::Field::Int64Field(singleton)#set_field
0.18 0.18 0.002036212/31497159Protobuf::Field::EnumField(singleton)#set_field2972955/36442639Protobuf::Enum.enum_for_tag_integer
0.200.200.260.26 0.002036213/31497159Protobuf::Field::StringField(singleton)#set_field2972955/36442639Protobuf::Message::Serialization.set_field_bytes
1.151.150.290.29 0.0012691992/31497159Protobuf::Field::StringField(singleton)#to_message_hash2972957/36442639Protobuf::Message#set_field
1.481.482.452.45 0.0012691992/31497159Protobuf::Field::Int64Field(singleton)#to_message_hash27518879/36442639##each_key
5% 5%3.193.190.0131497159##[]=
0.420.090.331018106/14728204##each_key3.213.180.0336442639##[]
2.551.960.5912691992/14728204Protobuf::Field::StringField(singleton)#to_message_hash
4%3%2.972.050.9214728204Protobuf::Field::StringField(singleton)#value_from_values
0.690.690.150.15 0.0013710098/28439604##fetch1981971/30496373Protobuf::Field::StringField(singleton)#set_field
0.170.170.150.15 0.003054318/37606151Protobuf::Enum.enum_for_tag_integer1981971/30496373Protobuf::Field::Int64Field(singleton)#set_field
0.260.260.180.18 0.003054320/37606151Protobuf::Message#set_field1981970/30496373Protobuf::Field::EnumField(singleton)#set_field
0.330.331.031.03 0.003054318/37606151Protobuf::Message::Serialization.set_field_bytes12272962/30496373Protobuf::Field::StringField(singleton)#to_message_hash
2.122.121.471.47 0.0028438302/37606151##each_key12272962/30496373Protobuf::Field::Int64Field(singleton)#to_message_hash
4% 4%2.902.880.0337606151##[]2.992.980.0130496373##[]=
0.370.41 0.090.281018106/14728204##each_key0.32990985/14254932##each_key
2.411.910.5012691992/14728204Protobuf::Field::Int64Field(singleton)#to_message_hash2.511.930.5812272962/14254932Protobuf::Field::StringField(singleton)#to_message_hash
4% 3%2.781.990.7914728204Protobuf::Field::Int64Field(singleton)#value_from_values2.932.020.9014254932Protobuf::Field::StringField(singleton)#value_from_values
0.560.560.670.67 0.0013710098/28439604##fetch13263947/27520181##fetch
2.400.751.652036213/2036213Protobuf::Message#set_field
3%1%2.400.751.652036213Protobuf::Field::StringField(singleton)#set_field0.390.090.30990985/14254932##each_key
0.622.341.84 0.500.122036213/3054319Test::Resource#_protobuf_message_required_field_tags
0.570.400.172036213/2036213Protobuf::Field::StringField#coerce!12272962/14254932Protobuf::Field::Int64Field(singleton)#to_message_hash
0.200.200.002036213/31497159##[]=
4%3%2.721.930.8014254932Protobuf::Field::Int64Field(singleton)#value_from_values
0.180.180.550.55 0.002036213/2036396##delete13263947/27520181##fetch
2.370.511.872036213/20362132.380.491.891981971/1981971 Protobuf::Message#set_field
3% 0%2.370.511.8720362132.380.491.891981971 Protobuf::Field::Int64Field(singleton)#set_field
1.621.65 0.591.032036213/20362131.061981971/1981971 Protobuf::Field::IntegerField#coerce!
0.170.170.150.15 0.002036213/31497159##[]=1981971/30496373##[]=
2.250.471.792036212/2036212Protobuf::Message#set_field
3%0%2.250.471.792036212Protobuf::Field::EnumField(singleton)#set_field
1.53 0.411.122036212/2036212Protobuf::Field::EnumField#coerce!
0.180.180.002036212/31497159##[]=
2.210.251.961018106/1018106Protobuf::Message::Serialization.set_field_bytes
3%0%2.210.251.961018106Protobuf::Field::Int64Field(singleton)#set
1.400.161.241018106/6108638Protobuf::Message#set_field
0.560.400.161018106/2036212Protobuf::Field::IntegerField#decode
0.36 0.030.340.39 2/1880 Kernel.load
0.890.94 0.000.890.94 6/1880 (top)
0.900.99 0.000.900.99 112/1880 Kernel.require
3% 0%2.152.34 0.032.122.31 1880 Kernel.require
0.750.84 0.000.750.84 1/1 Bundler.setup
0.230.25 0.000.2319/1019611##each0.2519/992490##each
0.110.12 0.000.110.121/1Gem::Specification.load_defaults
0.120.000.12 109/109 Protobuf::Message::Fields::ClassMethods.optional
0.102.260.731.521981971/1981971Protobuf::Message#set_field
3%1%2.260.731.521981971Protobuf::Field::StringField(singleton)#set_field
0.580.460.121981971/2972956Test::Resource#_protobuf_message_required_field_tags
0.530.360.161981971/1981971Protobuf::Field::StringField#coerce!
0.170.17 0.000.101/1Gem::Specification.load_defaults1981971/1982154##delete
0.150.150.001981971/30496373##[]=
2.080.241.841018106/10181062.260.271.99990985/990985 Protobuf::Message::Serialization.set_field_bytes
3% 0%2.080.241.841018106Protobuf::Field::StringField(singleton)#set2.260.271.99990985Protobuf::Field::Int64Field(singleton)#set
1.440.191.251018106/61086381.410.151.26990985/5945912 Protobuf::Message#set_field
0.400.250.580.43 0.161018106/1018106Protobuf::Field::StringField#decode990985/1981970Protobuf::Field::IntegerField#decode
1.870.601.271018106/1018106##each_key2.250.481.771981970/1981970Protobuf::Message#set_field
2%3% 0%1.870.601.271018106Protobuf::Field::StringField(singleton)#encode_to_stream
0.610.300.323054318/7126742IO::GenericWritable.<<2.250.481.771981970Protobuf::Field::EnumField(singleton)#set_field
0.260.160.101018106/3054471Protobuf::Field::VarintField.encode1.520.371.151981970/1981970Protobuf::Field::EnumField#coerce!
0.180.120.061018106/1018887BasicObject#!=0.180.001981970/30496373##[]=
1.850.251.601018106/1018106##each_key2.020.221.80990985/990985Protobuf::Message::Serialization.set_field_bytes
2%3% 0%1.850.251.601018106Protobuf::Field::EnumField(singleton)#encode_to_stream2.020.221.80990985Protobuf::Field::StringField(singleton)#set
1.230.231.011018106/1018106Protobuf::Field::EnumField#encode1.380.201.18990985/5945912Protobuf::Message#set_field
0.370.190.182036212/7126742IO::GenericWritable.<<0.420.260.15990985/990985Protobuf::Field::StringField#decode
1.780.261.521008106/1018106Proc#call1.920.631.29990985/990985##each_key
2%0%1.823%1%1.920.631.29990985Protobuf::Field::StringField(singleton)#encode_to_stream
0.62 0.281.551018106Test::Resource#status=0.342972955/6936895IO::GenericWritable.<<
1.550.251.301018106/6108638Protobuf::Message#set_field0.270.180.09990985/2973108Protobuf::Field::VarintField.encode
0.180.120.06990985/991766BasicObject#!=
0.200.200.210.21 0.003054320/345469402972957/33464791 Protobuf::Message#set_field
0.240.240.250.25 0.003054318/345469402972955/33464791 Protobuf::Message::Serialization.set_field_bytes
1.381.381.451.45 0.0028438302/34546940##each_key27518879/33464791##each_key
2%2%1.821.823%3%1.911.91 0.003454694033464791 Test::Resource#_protobuf_message_field
1.800.221.581018106/10181061.870.251.63990985/990985 Protobuf::Field::EnumField(singleton)#set
2% 0%1.800.221.5810181061.870.251.63990985 Protobuf::Field::EnumField#decode
1.060.310.751018106/10181061.120.350.78990985/990985 Protobuf::Field::EnumField#acceptable?
0.520.350.161018106/20362120.500.360.14990985/1981970 Protobuf::Field::IntegerField#decode
1.620.591.032036213/2036213Protobuf::Field::Int64Field(singleton)#set_field1.790.261.53980985/990985Proc#call
2% 0%1.620.591.032036213Protobuf::Field::IntegerField#coerce!
0.850.550.292036213/2036213Protobuf::Field::IntegerField#acceptable?1.830.271.56990985Test::Resource#status=
0.750.410.341018106/2036212Protobuf::Field::EnumField#encode1.560.261.30990985/5945912Protobuf::Message#set_field
0.820.430.391018106/2036212Protobuf::Field::Int64Field(singleton)#encode_to_stream1.760.271.49990985/990985##each_key
2%1%1.570.850.732036212Protobuf::Field::IntegerField#encode0%1.760.271.49990985Protobuf::Field::EnumField(singleton)#encode_to_stream
0.430.250.182036212/3054471Protobuf::Field::VarintField.encode1.140.210.93990985/990985Protobuf::Field::EnumField#encode
0.290.290.002036212/7126742##&0.350.180.171981970/6936895IO::GenericWritable.<<
0.560.190.371018106/3054327Protobuf::Field::EnumField#acceptable?
0.980.330.652036212/3054327Protobuf::Field::EnumField#coerce!1.650.591.061981971/1981971Protobuf::Field::Int64Field(singleton)#set_field
2% 0%1.540.521.023054327Protobuf::Enum.fetch1.650.591.061981971Protobuf::Field::IntegerField#coerce!
0.870.530.890.600.291981971/1981971Protobuf::Field::IntegerField#acceptable?
0.570.210.37990985/2972964Protobuf::Field::EnumField#acceptable?
0.99 0.343054318/30543180.651981970/2972964Protobuf::Field::EnumField#coerce!
2%0%1.570.551.022972964Protobuf::Enum.fetch
0.870.550.322972955/2972955 Protobuf::Enum.enum_for_tag_integer
0.14 0.14 0.003054327/71281262972964/6938279 Kernel.kind_of?
1.530.411.122036212/20362121.520.371.151981970/1981970 Protobuf::Field::EnumField(singleton)#set_field
2% 0%1.530.411.1220362121.520.371.151981970 Protobuf::Field::EnumField#coerce!
0.980.330.990.34 0.652036212/30543271981970/2972964 Protobuf::Enum.fetch
0.140.140.150.15 0.002036212/30547601981970/2973397 Protobuf::Field::BaseField#type_class
0.690.380.31990985/1981970Protobuf::Field::EnumField#encode
0.830.480.35990985/1981970Protobuf::Field::Int64Field(singleton)#encode_to_stream
2%1% 1.510.281.231018106/1018106##each_key0.850.661981970Protobuf::Field::IntegerField#encode
0.410.250.161981970/2973108Protobuf::Field::VarintField.encode
0.250.250.001981970/6936895##&
1.470.261.22990985/990985##each_key
2% 0%1.510.281.2310181061.470.261.22990985 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.820.430.391018106/20362120.830.480.35990985/1981970 Protobuf::Field::IntegerField#encode
0.410.190.222036212/71267420.390.180.211981970/6936895 IO::GenericWritable.<<
0.370.190.35 0.182036212/71267420.171981970/6936895 Protobuf::Field::EnumField(singleton)#encode_to_stream
0.410.190.222036212/71267420.390.180.211981970/6936895 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.610.300.323054318/71267420.620.280.342972955/6936895 Protobuf::Field::StringField(singleton)#encode_to_stream
2% 1%1.390.671.370.64 0.7271267426936895 IO::GenericWritable.<<
0.72 0.72 0.007126742/71267426936895/6936895 StringIO#write
0.560.560.550.55 0.0013710098/2843960413263947/27520181 Protobuf::Field::Int64Field(singleton)#value_from_values
0.690.690.670.67 0.0013710098/2843960413263947/27520181 Protobuf::Field::StringField(singleton)#value_from_values
2% 2%1.301.301.281.27 0.0028439604##fetch27520181##fetch
1.230.231.011018106/10181061.140.210.93990985/990985 Protobuf::Field::EnumField(singleton)#encode_to_stream
1% 0%1.230.231.0110181061.140.210.93990985 Protobuf::Field::EnumField#encode
0.750.410.341018106/20362120.690.380.31990985/1981970 Protobuf::Field::IntegerField#encode
0.260.150.111018106/10183740.250.140.10990985/991253 Protobuf::Enum#to_i
0.521.12 0.350.161018106/20362120.78990985/990985Protobuf::Field::EnumField#decode
1%0%1.120.350.78990985Protobuf::Field::EnumField#acceptable?
0.570.210.37990985/2972964Protobuf::Enum.fetch
0.110.110.00990985/2973397Protobuf::Field::BaseField#type_class
0.500.360.14990985/1981970 Protobuf::Field::EnumField#decode
0.560.400.580.43 0.161018106/2036212990985/1981970 Protobuf::Field::Int64Field(singleton)#set
1% 1%1.080.750.3320362121.090.790.301981970 Protobuf::Field::IntegerField#decode
0.230.230.200.20 0.002036212/7126742##&1981970/6936895##&
1.060.680.396108636/61086361.040.670.375945910/5945910 Protobuf::Decoder.decode_each_field
1% 1%1.060.680.3961086361.040.670.375945910 Protobuf::Varint.decode
0.390.390.370.37 0.006108636/61086365945910/5945910 ProtobufJavaHelpers::Varinter.read_varint
1.060.310.751018106/1018106Protobuf::Field::EnumField#decode0.990.000.992/112(top)
1% 0%1.060.310.751018106Protobuf::Field::EnumField#acceptable?
0.560.190.371018106/3054327Protobuf::Enum.fetch0.990.000.99112Kernel.require
0.100.100.99 0.001018106/3054760Protobuf::Field::BaseField#type_class0.99112/1880Kernel.require
0.900.000.902/112(top)0.890.600.291981971/1981971Protobuf::Field::IntegerField#coerce!
1% 0%0.900.000.90112Kernel.require0.890.600.291981971Protobuf::Field::IntegerField#acceptable?
0.900.120.12 0.000.90112/1880Kernel.require1981971/6938279Kernel.kind_of?
0.870.530.343054318/30543180.550.322972955/2972955 Protobuf::Enum.fetch
1% 0% 0.870.530.3430543180.550.322972955 Protobuf::Enum.enum_for_tag_integer
0.170.170.180.18 0.003054318/37606151##[]2972955/36442639##[]
0.170.170.150.15 0.003054318/3054780##first2972955/2973417##first
0.860.430.433378485/3378485##each
1%0%0.860.430.433378485Benchmark::Timing.now
0.430.430.84 0.003378485/3378486Process.clock_gettime
0.850.550.292036213/2036213Protobuf::Field::IntegerField#coerce!0.841/1Kernel.require
1% 0%0.850.550.292036213Protobuf::Field::IntegerField#acceptable?0.840.000.841Bundler.setup
0.100.100.002036213/7128126Kernel.kind_of?0.440.010.441/2Bundler.definition
0.150.150.38 0.001018106/3054319Protobuf::Message#each_field_for_serialization0.381/1Bundler::Runtime#setup
0.620.500.122036213/3054319Protobuf::Field::StringField(singleton)#set_field0.840.420.423301704/3301704##each
1%1%0.770.660.123054319Test::Resource#_protobuf_message_required_field_tags0%0.840.420.423301704Benchmark::Timing.now
0.120.120.420.42 0.002036213/2037179Kernel.dup3301704/3301705Process.clock_gettime
0.680.680.720.72 0.0017078042/19114271Benchmark::IPS::Job::Entry#call_times6936895/6936895IO::GenericWritable.<<
1% 1%0.770.770.720.72 0.0019114271##<6936895StringIO#write
0.750.140.14 0.000.751/1Kernel.require990985/2972956Protobuf::Message#each_field_for_serialization
0.580.460.121981971/2972956Protobuf::Field::StringField(singleton)#set_field
1% 0%0.750.000.751Bundler.setup
0.390.010.391/2Bundler.definition0.720.600.122972956Test::Resource#_protobuf_message_required_field_tags
0.350.120.12 0.000.351/1Bundler::Runtime#setup1981971/1982937Kernel.dup
0.720.720.630.63 0.007126742/7126742IO::GenericWritable.<<16555118/18537105Benchmark::IPS::Job::Entry#call_times
1% 0.72 0.72 0.007126742StringIO#write18537105##<
0.13 0.13 0.003377958/17079139##each3301185/16556215##each
0.57 0.57 0.0013700098/1707913913253947/16556215 Benchmark::IPS::Job::Entry#call_times
1% 1%0.710.710.700.70 0.0017079139##+16556215##+
0.260.160.101018106/30544710.270.180.09990985/2973108 Protobuf::Field::StringField(singleton)#encode_to_stream
0.430.41 0.250.182036212/30544710.161981970/2973108 Protobuf::Field::IntegerField#encode
1% 0% 0.690.410.2830544710.430.262973108 Protobuf::Field::VarintField.encode
0.280.280.260.26 0.003054471/30544712973108/2973108 ProtobufJavaHelpers::Varinter.to_varint
0.12 0.12 0.003054318/71267422972955/6936895 Protobuf::Decoder.decode_each_field
0.230.230.200.20 0.002036212/71267421981970/6936895 Protobuf::Field::IntegerField#decode
0.290.290.250.25 0.002036212/71267421981970/6936895 Protobuf::Field::IntegerField#encode
1%1%0.650.650%0%0.570.57 0.007126742##&6936895##&
0.570.400.172036213/20362130.530.360.161981971/1981971 Protobuf::Field::StringField(singleton)#set_field
0% 0%0.570.400.1720362130.530.360.161981971 Protobuf::Field::StringField#coerce!
0.460.52 0.060.400.45 17/19 (top)
0% 0%0.460.52 0.060.400.45 19 Kernel.load
0.360.41 0.030.340.39 2/1880 Kernel.require
0.430.430.003378485/3378486Benchmark::Timing.now
0%0%0.430.430.003378486Process.clock_gettime
0.400.250.161018106/1018106Protobuf::Field::StringField(singleton)#set
0%0%0.400.250.161018106Protobuf::Field::StringField#decode
0.390.44 0.010.390.44 1/2 Bundler.setup
0% 0%0.390.44 0.010.390.44 2 Bundler.definition
0.300.35 0.000.300.35 1/1 Bundler::Definition.build
0.390.390.006108636/6108636Protobuf::Varint.decode
0%0%0.390.390.006108636ProtobufJavaHelpers::Varinter.read_varint
0.320.36 0.000.320.36 1/838 Bundler::Runtime#requested_specs
0% 0%0.390.42 0.000.380.42 838 Kernel.send
0.320.36 0.000.320.36 1/1 Bundler::Definition#requested_specs
0.350.420.42 0.000.353301704/3301705Benchmark::Timing.now
0%0%0.420.420.003301705Process.clock_gettime
0.420.260.15990985/990985Protobuf::Field::StringField(singleton)#set
0%0%0.420.260.15990985Protobuf::Field::StringField#decode
0.380.000.38 1/1 Bundler.setup
0% 0%0.350.38 0.000.350.38 1 Bundler::Runtime#setup
0.320.36 0.000.320.36 1/1 Bundler::Runtime#requested_specs
0.370.370.005945910/5945910Protobuf::Varint.decode
0% 0%0.340.340.370.37 0.0091638485945910ProtobufJavaHelpers::Varinter.read_varint
0%0%0.360.360.008919759 Kernel.nil?
0.100.100.120.12 0.002036213/71281261981971/6938279 Protobuf::Field::IntegerField#acceptable?
0.14 0.14 0.003054327/71281262972964/6938279 Protobuf::Enum.fetch
0% 0%0.340.340.360.36 0.0071281266938279 Kernel.kind_of?
0.320.36 0.000.320.36 1/1 Bundler::Runtime#setup
0% 0%0.320.36 0.000.320.36 1 Bundler::Runtime#requested_specs
0.320.36 0.000.320.36 1/838 Kernel.send
0.320.36 0.000.320.36 1/1 Kernel.send
0% 0%0.320.36 0.000.320.36 1 Bundler::Definition#requested_specs
0.320.36 0.000.320.36 1/1 Bundler::Definition#specs_for
0.320.36 0.000.320.36 1/1 Bundler::Definition#requested_specs
0% 0%0.320.36 0.000.320.36 1 Bundler::Definition#specs_for
0.310.35 0.000.310.35 1/1 Bundler::Definition#specs
0.320.090.241018106/2036212##each_key0.350.000.351/1Bundler.definition
0% 0%0.320.090.242036212Protobuf::Field::EnumField(singleton)#value_from_values0.350.000.351Bundler::Definition.build
0.340.000.341/1Bundler::Dsl.evaluate
0.310.35 0.000.310.35 1/1 Bundler::Definition#specs_for
0% 0%0.310.35 0.000.310.35 1 Bundler::Definition#specs
0.210.22 0.000.210.22 1/1 Bundler::SpecSet#materialize
0.110.000.111/1Bundler::Definition#resolve
0.300.34 0.000.300.34 1/1Bundler.definitionBundler::Definition.build
0% 0%0.300.34 0.000.300.34 1Bundler::Definition.buildBundler::Dsl.evaluate
0.290.24 0.000.290.241/1Bundler::Dsl#to_definition
0.340.090.25990985/1981970##each_key
0%0%0.340.090.251981970Protobuf::Field::EnumField(singleton)#value_from_values
0.260.150.11980985/990985Proc#call
0%0%0.270.150.12990985StringIO.new
0.120.120.00990985/990985StringIO#initialize
0.110.110.00990985/2973397Protobuf::Field::EnumField#acceptable?
0.150.150.001981970/2973397Protobuf::Field::EnumField#coerce!
0%0%0.270.270.002973397Protobuf::Field::BaseField#type_class
0.260.260.002973108/2973108Protobuf::Field::VarintField.encode
0%0%0.260.260.002973108ProtobufJavaHelpers::Varinter.to_varint
0.250.140.10990985/991253Protobuf::Field::EnumField#encode
0%0%0.250.140.10991253Protobuf::Enum#to_i
0.100.100.00991253/991253Protobuf::Enum#tag
0.240.000.24 1/1 Bundler::Dsl.evaluate
0%0%0.240.000.241Bundler::Dsl#to_definition
0.240.010.241/1983436Class#new
0.290.24 0.000.290.23 1/1Bundler::Definition.buildClass#new
0% 0%0.290.24 0.000.290.23 1Bundler::Dsl.evaluateBundler::Definition#initialize
0.210.19 0.000.210.191/400Bundler::SpecSet#materialize
0%0%0.230.020.22400##map!
0.190.000.1939/39Bundler::LazySpecification#__materialize__
0.220.000.22 1/1Bundler::Dsl#to_definitionBundler::Definition#specs
0%0%0.220.000.221Bundler::SpecSet#materialize
0.190.000.191/400##map!
0.280.280.19 0.003054471/3054471Protobuf::Field::VarintField.encode0.1939/39##map!
0% 0%0.280.280.19 0.003054471ProtobufJavaHelpers::Varinter.to_varint0.1939Bundler::LazySpecification#__materialize__
0.160.000.1638/38Bundler::Source::Rubygems#specs
0%0%0.190.190.001982108##+
0.260.150.190.190.003963940/3963940Protobuf::Decoder.decode_each_field
0%0%0.190.190.003963940StringIO#eof
0.100.100.003/642Gem::Specification.gemspec_stubs_in
0%0%0.19 0.111018106/1018374Protobuf::Field::EnumField#encode0.07642##map
0.180.120.06990985/991766Protobuf::Field::StringField(singleton)#encode_to_stream
0%0%0.180.120.06991766BasicObject#!=
0.120.000.11109/153Protobuf::Message::Fields::ClassMethods.optional
0%0%0.180.000.17153Protobuf::Message::Fields::ClassMethods.define_field
0.170.000.17153/153Protobuf::Field.build
0.170.170.001981971/1982154Protobuf::Field::StringField(singleton)#set_field
0% 0%0.260.150.111018374Protobuf::Enum#to_i
0.110.110.170.17 0.001018374/1018374Protobuf::Enum#tag1982154##delete
0.240.130.111008106/1018106Proc#call0.170.000.17153/153Protobuf::Message::Fields::ClassMethods.define_field
0% 0%0.250.140.111018106StringIO.new
0.110.110.17 0.001018106/1018106StringIO#initialize0.17153Protobuf::Field.build
0.100.100.001018106/3054760Protobuf::Field::EnumField#acceptable?0.160.010.15153/1983436Class#new
0.140.140.170.17 0.002036212/3054760Protobuf::Field::EnumField#coerce!3963940/3966993Protobuf::Decoder.decode_each_field
0% 0%0.240.240.170.17 0.003054760Protobuf::Field::BaseField#type_class3966993##==
0.180.16 0.000.181/400Bundler::SpecSet#materialize0.161/2Bundler::Source::Rubygems#installed_specs
0% 0%0.220.020.20400##map!0.170.000.162Bundler::Index.build
0.180.15 0.000.1839/39Bundler::LazySpecification#__materialize__0.151/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0.210.16 0.000.211/1Bundler::Dsl.evaluate0.1638/38Bundler::LazySpecification#__materialize__
0% 0%0.210.16 0.000.211Bundler::Dsl#to_definition0.1638Bundler::Source::Rubygems#specs
0.210.010.201/2037678Class#new0.160.000.161/1Bundler::Source::Rubygems#installed_specs
0.210.16 0.000.210.16 1/1Bundler::Definition#specsBundler::Source::Rubygems#specs
0% 0%0.210.16 0.000.210.16 1Bundler::SpecSet#materializeBundler::Source::Rubygems#installed_specs
0.180.16 0.000.181/400##map!0.161/2Bundler::Index.build
0.200.200.004072424/4072424Protobuf::Decoder.decode_each_field0.150.010.15153/153Class#new
0% 0%0.200.200.004072424StringIO#eof0.150.010.15153Protobuf::Field::BaseField#initialize
0.200.150.15 0.000.201/1Class#new3301175/3301175##each
0% 0%0.200.150.15 0.000.201Bundler::Definition#initialize3301175##<
0.180.120.061018106/1018887Protobuf::Field::StringField(singleton)#encode_to_stream0.150.000.151/1Bundler::Index.build
0% 0%0.190.120.061018887BasicObject#!=0.150.000.151Bundler::RubygemsIntegration::MoreFuture#all_specs
0.180.180.15 0.004072424/4075603Protobuf::Decoder.decode_each_field0.151/1Gem::Specification.stubs
0%0%0.180.18
0.150.15 0.004075603##==2972955/2973417Protobuf::Enum.enum_for_tag_integer
0% 0%0.180.180.150.15 0.002036350##+2973417##first
0.180.180.15 0.002036213/2036396Protobuf::Field::StringField(singleton)#set_field0.151/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0% 0%0.180.180.15 0.002036396##delete0.151Gem::Specification.stubs
0.180.13 0.000.1839/39##map!0.131/1Gem::Specification.installed_stubs
0% 0%0.180.000.1839Bundler::LazySpecification#__materialize__0.140.060.081137BasicObject#instance_eval
0.170.170.13 0.003054318/3054780Protobuf::Enum.enum_for_tag_integer0.132/3##each
0% 0%0.170.170.14 0.003054780##first0.143Gem::Specification.gemspec_stubs_in
0.100.100.003/642##map
0.170.170.140.14 0.003377948/3377948##each2972955/2972955Protobuf::Decoder.decode_each_field
0% 0%0.170.170.140.14 0.003377948##<2972955##>>
0%0%0.130.030.1060Kernel.eval
0.110.13 0.000.11109/153Protobuf::Message::Fields::ClassMethods.optional0.131/1Gem::Specification.stubs
0% 0%0.160.13 0.000.16153Protobuf::Message::Fields::ClassMethods.define_field0.131Gem::Specification.installed_stubs
0.150.13 0.000.15153/153Protobuf::Field.build0.131/1Gem::Specification.map_stubs
0.150.13 0.000.15153/153Protobuf::Message::Fields::ClassMethods.define_field0.131/1Gem::Specification.installed_stubs
0% 0%0.150.13 0.000.15153Protobuf::Field.build0.131Gem::Specification.map_stubs
0.150.010.14153/2037678Class#new0.130.000.131/1##flat_map
0.150.150.13 0.003054318/3054318Protobuf::Decoder.decode_each_field0.131/1Gem::Specification.map_stubs
0% 0%0.150.150.13 0.003054318##>>0.131##flat_map
0.140.01 0.13153/153Class#new
0%0%0.140.010.00 0.13153Protobuf::Field::BaseField#initialize1/992490##each
0.120.120.001981971/1982937Test::Resource#_protobuf_message_required_field_tags
0% 0%0.130.060.071137BasicObject#instance_eval0.120.120.001982937Kernel.dup
0.120.12 0.001018106/1018106Protobuf::Decoder.decode_each_field0.121/1Kernel.require
0% 0% 0.120.000.121Gem::Specification.load_defaults
0.12 0.001018106StringIO#read0.121/1Gem::Specification.each_spec
0.120.12 0.002036213/2037179Test::Resource#_protobuf_message_required_field_tags0.121/1Gem::Specification.load_defaults
0% 0% 0.120.000.121Gem::Specification.each_spec
0.12 0.002037179Kernel.dup0.121/1Gem::Specification.each_gemspec
0.110.110.12 0.001018106/1018106StringIO.new0.121/1Gem::Specification.each_spec
0% 0%0.110.110.12 0.001018106StringIO#initialize0.121Gem::Specification.each_gemspec
0.120.000.121/992490##each
0.110.12 0.000.110.12 109/109 Kernel.require
0% 0%0.110.12 0.000.110.12 109 Protobuf::Message::Fields::ClassMethods.optional
0.110.12 0.00 0.11 109/153
0.110.110.120.12 0.001018374/1018374Protobuf::Enum#to_i990985/990985Protobuf::Decoder.decode_each_field
0% 0%0.110.110.120.12 0.001018374Protobuf::Enum#tag990985StringIO#read
0%0%0.110.020.0860Kernel.eval
0.100.120.12 0.000.101/1Kernel.require990985/990985StringIO.new
0% 0%0.100.120.12 0.000.101Gem::Specification.load_defaults990985StringIO#initialize
0.100.11 0.000.100.11 1/1Gem::Specification.each_specBundler::Definition#specs
0.10
0%0%0.11 0.000.101/1Gem::Specification.load_defaults0.111Bundler::Definition#resolve
0% 0% 0.10 0.00 0.101Gem::Specification.each_spec6Bundler::SpecSet#for
0.100.000.101/1Gem::Specification.each_gemspec0.010.096/6Kernel.loop
0.100.00 0.101/1Gem::Specification.each_spec0.00991253/991253Protobuf::Enum#to_i
0% 0% 0.100.00 0.101Gem::Specification.each_gemspec0.00991253Protobuf::Enum#tag
0.100.000.101/1019611##each0.010.096/6Bundler::SpecSet#for
0% 0% 0.100.100.002037360##to_s
0.010.096Kernel.loop
@@ -67,195 +67,195 @@

Total time: 63.30

- + - + - + - + - + - + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - + - - - + + + - + - - - + + + - + - - + + - - - + + + - + - - + + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - - + + - + - + - - - + + + - + - + - + - + - + - - - + + + - + - + - + - + - + @@ -264,372 +264,381 @@

Total time: 63.30

- + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - + + + + - + - + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - + - - + + - + - + - - + + - + - + + + + + + + + + + - + - + - + - + - + - + - + - - - + + + - + - - - - + + + + - - - - + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + - - + + - + - - + + - + - + - + - - + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - + + + - + - + - - + + - + - - - - + + + + - - - - + + + + - + - - - - - + + + + + @@ -639,7 +648,7 @@

Total time: 63.30

- + @@ -650,482 +659,445 @@

Total time: 63.30

- + - - - - + + + + - + - - - + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - - - - + + + + - - - - + + + + - + - + - - + + - + - - + + - + - - + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - + + - + - - + + - - + + - + - - + + - - + + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - + + + - + - + - + - - + + - - + + - + - - + + - + - + - - - + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - + + - - - + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - + - - + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - + - - - - + + + + - - - - + + + + - + - - - - - + + + + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + @@ -1134,403 +1106,458 @@

Total time: 63.30

- + - + - - + + - + - - + + - + - - + + - - - - + + + + - + - - - - + + + + - + - + - + - + - + - + - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + - + - - - - - + + + + + - + - + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - + + - - - + + - - + + - - + + - - + + + + + + + + + + + + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + + - - - - - + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - + + + + + - - - - + + + + - - - - - + + + + + - + - - + + - - + + - - - - + + + + - - - - + + + + - - - - - + + + + + - + - - + + - - + + - + - - + + - + - - + + - + - - + + - + - + - - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + - - + + @@ -1539,182 +1566,182 @@

Total time: 63.30

- + - + - + - + - + - + - - - + + + - + - - + + - + - + - - - + + + - + - - - - + + + + - - - - - - - - - - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - - - - - - - + + - + - - - + + + - - - + + + - + - - - + + + - + - - - - - - + + + + + + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -1723,795 +1750,785 @@

Total time: 63.30

- + - + - + - - + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + - - + + - - + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - + + + + + + + + + + - - + + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + + + + + + + + + + - + - - - + + + - + - - + + - + - - - - + + + + - + - + + - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - + - - - - + + + + - + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + + - - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + - + - - + + - - + + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - + + - - - - - - - - - - - - - - - - - - - - - + + - + - - + + - - + + - - - - - + + + + + - - - - - + + + + + + + + + + + + + + - + - + + - - - + + - + - - - - - + + + + + - - - - - + + + + + - + - - + - - + + + - + - - - - + + + + - - - - + + + + - + - - + + - + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - + + + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + - - + + - - + + @@ -2520,137 +2537,137 @@

Total time: 63.30

- - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - - + + - - + + - - + + - - + + - - + + - + - - - - + + + + - - - - + + + + - + - - + + - + - - + + - + - - + + - + @@ -2659,101 +2676,139 @@

Total time: 63.30

- + - - + + - - + + - - + + - + - - + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - - + + - + - - - - - + + + + + - - - - - + + + + + - + + - + + - - - + + + + + + + + + + + - + - + - - + + @@ -2762,130 +2817,147 @@

Total time: 63.30

- + - + - + - + - + - - + - - + + + - - + - - + + + - - + - - - - - - - - - - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - + + + + + + + + + + - - + + + - - - + - - + + + - + + + + + + + + + + - - + + - + + + + + + + + + + - + - + @@ -2894,241 +2966,261 @@

Total time: 63.30

- + + + + + + + + + + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - + + + + + - + - - + + - - + + - - - - - + + + + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + - + @@ -3137,2198 +3229,2237 @@

Total time: 63.30

- + - - + + - + - - - - - + + + + + - + + + + + + + + + + - - + + - - - - - + + + + + - - - - - - - - - - - + + - - + + - + - + - + - + - + - + - + - - - - - + + + + + - + - - - - - + + + + + - + + + + + + + + + + + + - - - + + - + - + + - - - + + - - - - - + + + + + - + + - + - - - - - - - - - - - - - + + + - + - - - + + + - + - + - - - + + + - + - + + - - - + + - + + - - - + + - + + - + + - - - + + - - - + + - - + + - - + - - + + + - - + - - + + + - + + + + + + + + + + - - + + - - + + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - + - - + + - - - - - + + + + + - + - + - - - + + + - + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + - - + + - - + + - - + + - - + + - + + + + + + + + + + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + + - - - + + - + + - - - + + - + + - + + - - - + + - + + + + + + + + + + - + - + - + - + - + - + - + - + - - - + + + - + - - - - - + + + + + - - - - - + + + + + - - + - - - - - - - - - - - + - - + + + - + - + - + - + - + - + - + - + - - - + + + - + - - + + - - + + - - + + - - + + - - - - - - - - - - + - - - + + + - + - + - - - - - - - - - - - - - + + + - + - + - - - + + + - + - - - + + + - + - - - + + + - + - - + - - + + + - - + + + + + + + + + + - - - - - - - - - - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - - + - - + + + - - + - - + + + + + + + + + + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + + + + + + + + + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + + - - - + + - + + - - - + + - + + - + + + + + + + + - - + + + + - + - - + - - + + + - - + - - + + + - + - - + + - - + + - - + + - - + + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + - - - + + - + - - - - + + + + - + - - - + + + + + + + + + + + + - - + + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + - - - + + + + + + + + + - - - + + + + + - - - - - + - - - - - - - - - - + - - - - - + + - - - - + + + - + - - - - + + - + + + + + + + - - - + + - - - - - - + + - - - - + + - - - - + + + + + + + + + + + + - - - - - + - - - - - + - - - - - - - + - - - - - - - - + + + - + - + + - + + + - + + + + - + + - + + + + + + + + + + + + + + - - - + + + - - + + + + + - - + + - - - - - + + + + + + + + + + + + + + + - - + + + + + + - - - - - - - - - + - - - - - - - - - - + + + + - + + + - - - - - - - - - - - + - - - - - - - - - - + + - + + + + - - + + - - + + + - + + + + + - + - - - + + + + + - - - - - - - - - - + + - + + + + + + + + + + - + + + + - - - - - - - - - + + - - - - - - + + - - - - - - + - + + - - - + + + + + + + - - - + + + - - + + + - - + + - - - + + + - - + + + - - - - - + + + - - + + - - - - - + + + - - - + + - - - + + + + + - + + + - + + + + - - - - - - - + - - - - - - - + + + + - - - + + + + - + - + + + + + + + + + + + - - + + + + - - + - - + + + + + - - - - - + + - - - + + - - - - - - - + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - + + + - - + + + + + - - - - - - - - + + - - - - - - - + - + + + + + + - - - - + + - - - - - + + + + + + - - + + + + - + + + + + + + + + + + + - + + - + - - + + + - - - - - - - + + + - - - - + + - + + + + + - - + - - - + + + + + + - - + - - - - + - - + - - + - - - - - + + + - - - - + + + + + - - - - - + + + - - - - - + + + + + + - - - - - - + + - + + + + + + + + - - - - + - - + - - - - + - - - + - - + + + - + - - - - - - + + - + - - - - - + - - - - - + + - + + - - + + - + + + + + + + - - - - - + + + + - + + - + - + - + - + + + + + - + + + + + + + + + - - - + - - - - - - + - + - + + - - + + - + + - + + - + + + - - - - + - + + - - @@ -5338,32 +5469,30 @@

Total time: 63.30

- - - - - - + + + + @@ -5375,14 +5504,14 @@

Total time: 63.30

+ - - + @@ -5395,24 +5524,24 @@

Total time: 63.30

- + + - + - @@ -5425,16 +5554,15 @@

Total time: 63.30

+ - - @@ -5445,9 +5573,9 @@

Total time: 63.30

- + @@ -5458,13 +5586,13 @@

Total time: 63.30

+ - @@ -5473,6 +5601,7 @@

Total time: 63.30

+ From 5147ab270ca4e51c1c392312b7cbe668217534cf Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 27 Dec 2018 17:31:52 -0700 Subject: [PATCH 1113/1191] add some of the java methods to integers and create a custom set_field for string values --- lib/protobuf/field/base_field.rb | 2 + .../field/base_field_method_definitions.rb | 26 + lib/protobuf/field/enum_field.rb | 32 +- lib/protobuf/field/int64_field.rb | 23 +- profile.html | 6180 ++++++++--------- 5 files changed, 3135 insertions(+), 3128 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 7a63ece1..689b23ca 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -155,6 +155,8 @@ def define_set_field! ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_set_field!(self) elsif repeated? ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_set_field!(self) + elsif type_class == ::Protobuf::Field::StringField + ::Protobuf::Field::BaseFieldMethodDefinitions.define_string_set_field!(self) else ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_set_field!(self) end diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 7076f5cd..2ff4786c 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -222,6 +222,32 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) end end + def self.define_string_set_field!(selph) + if selph.required? + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? + values.delete(#{fully_qualified_name_string(selph)}) + message_instance._protobuf_message_required_field_tags << #{selph.tag} + else + message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + values[#{fully_qualified_name_string(selph)}] = value.to_s + end + end + RUBY + else + selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? + values.delete(#{fully_qualified_name_string(selph)}) + else + values[#{fully_qualified_name_string(selph)}] = value.to_s + end + end + RUBY + end + end + def self.define_base_set_field!(selph) if selph.required? selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index e2c8c311..4c7f6653 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -15,18 +15,31 @@ def self.default ## # Public Instance Methods # + if defined?(::ProtobufJavaHelpers) + include ::ProtobufJavaHelpers::Varinter + include ::ProtobufJavaHelpers::IntegerProtobufField - def acceptable?(val) - !type_class.fetch(val).nil? - end + def encode(value) + to_varint_64(value.to_i) # Calling `to_i` because it is a delegator and the java side doesn't follow + end + + def decode(value) + decode_varint_64(value) + end + else + def encode(value) + # original Google's library uses 64bits integer for negative value + ::Protobuf::Field::VarintField.encode(value & 0xffff_ffff_ffff_ffff) + end - def encode(value) - super(value.to_i) + def decode(value) + value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? + value if acceptable?(value) + end end - def decode(value) - decoded = super(value) - decoded if acceptable?(decoded) + def acceptable?(val) + !type_class.fetch(val).nil? end def enum? @@ -35,8 +48,7 @@ def enum? def coerce!(value) enum_value = type_class.fetch(value) - fail TypeError, "Invalid Enum value: #{value.inspect} for #{name}" unless enum_value - enum_value + enum_value || fail(TypeError, "Invalid Enum value: #{value.inspect} for #{name}") end private diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb index 18538f4b..493f6ab2 100644 --- a/lib/protobuf/field/int64_field.rb +++ b/lib/protobuf/field/int64_field.rb @@ -7,13 +7,26 @@ class Int64Field < IntegerField ## # Class Methods # + if defined?(::ProtobufJavaHelpers) + include ::ProtobufJavaHelpers::Varinter + include ::ProtobufJavaHelpers::IntegerProtobufField + include ::ProtobufJavaHelpers::Int64ProtobufField - def self.max - INT64_MAX - end + def encode(value) + to_varint_64(value) + end + + def decode(value) + decode_varint_64(value) + end + else + def self.max + INT64_MAX + end - def self.min - INT64_MIN + def self.min + INT64_MIN + end end end diff --git a/profile.html b/profile.html index 1d3eed61..b4e04e95 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 63.27

+

Total time: 63.20

%Total
100% 0%63.3063.27 0.0063.3063.27 0 (top)
60.0860.10 0.0060.0860.10 1/1 Benchmark::IPS.ips
0.991.04 0.000.992/1121.032/115 Kernel.require
0.940.92 0.000.946/18800.926/1886 Kernel.require
0.770.73 0.040.720.69 1/5##times##times
0.520.48 0.060.450.42 17/19 Kernel.load
0.120.11 0.000.121/992490Gem::Specification.each_gemspec0.114/1037819Bundler::SpecSet#tsort_each_node
0.130.11 0.000.131/992490##flat_map0.111/1037819Gem::Specification.each_gemspec
0.250.23 0.000.2519/9924900.2319/1037819 Kernel.require
20.001.7618.251/9924901.8318.171/1037819 Benchmark::IPS::Job#run_warmup
40.0840.09 0.0140.071/99249040.091/1037819 Benchmark::IPS::Job#run_benchmark
96% 2%60.921.8059.12992490##each60.951.8759.081037819##each
57.172.6954.483301171/330117157.052.7754.283593390/3593390 Benchmark::IPS::Job::Entry#call_times
0.840.420.423301704/33017040.870.440.433593944/3593944 Benchmark::Timing.now
0.150.150.180.18 0.003301175/3301175##<3593394/3593394##<
0.130.130.140.14 0.003301185/16556215##+3593404/18522606##+
0.130.11 0.000.132/3Gem::Specification.gemspec_stubs_in0.10118/118TSort.each_strongly_connected_component_from
0.770.73 0.040.720.69 1/5 (top)
60.0860.10 0.0060.0860.10 2/5 Benchmark::IPS::Job#run
96% 0%60.870.0660.8160.850.0560.80 5##times##times
40.0840.09 0.0040.0840.09 1/1 Benchmark::IPS::Job#run_benchmark
20.00 1/1 Benchmark::IPS::Job#run_warmup
0.350.34 0.000.3510000/9909850.3310000/1036260 Protobuf::Message::Serialization::ClassMethods.decode_from
0.230.21 0.010.2210000/9909850.2110000/1036260 Protobuf::Encoder.encode
60.0860.10 0.0060.0860.10 1/1 (top)
94% 0%60.0860.10 0.0060.0860.10 1 Benchmark::IPS.ips
60.0860.10 0.0060.0860.10 1/1 Benchmark::IPS::Job#run
60.0860.10 0.0060.0860.10 1/1 Benchmark::IPS.ips
94% 0%60.0860.10 0.0060.0860.10 1 Benchmark::IPS::Job#run
60.0860.10 0.0060.0860.10 2/5##times##times
57.172.6954.483301171/3301171##each57.052.7754.283593390/3593390##each
90% 4%57.172.6954.48330117157.052.7754.283593390 Benchmark::IPS::Job::Entry#call_times
53.2852.94 2.2051.0813253947/1325449250.7414928119/14928667 Proc#call
0.630.630.710.71 0.0016555118/18537105##<18521509/20594046##<
0.570.570.630.63 0.0013253947/16556215##+14928119/18522606##+
53.2852.94 2.2051.0813253947/1325449250.7414928119/14928667 Benchmark::IPS::Job::Entry#call_times
84%83% 3%53.312.2151.101325449252.972.2050.7714928667 Proc#call
22.652.1720.4812272962/1227296222.242.5019.7413901859/13901859 Protobuf::Message#to_hash
13.540.2813.26980985/99098513.710.2513.461026260/1036260 Protobuf::Message::Serialization::ClassMethods.decode_from
8.740.308.44980985/9909858.670.278.401026260/1036260 Protobuf::Encoder.encode
3.963.94 0.143.82980985/19834363.801026260/2074044 Class#new
1.790.261.770.25 1.53980985/9909851026260/1036260 Test::Resource#status=
0.260.150.250.14 0.11980985/9909851026260/1036260 StringIO.new
0.100.100.001026260/1036260Protobuf::Message#to_proto
40.0840.09 0.0040.0840.09 1/1##times##times
63% 0%40.0840.09 0.0040.0840.09 1 Benchmark::IPS::Job#run_benchmark
40.0840.09 0.0140.071/992490##each40.091/1037819##each
8.081.336.75990985/132639488.011.406.611036260/14938120 Protobuf::Message#each_field_for_serialization
20.485.3315.1412272962/1326394819.745.9413.8013901859/14938120 Protobuf::Message#to_hash
45%10%28.566.6621.8913263948##each_key43%11%27.757.3420.4114938120##each_key
5.982.173.8012272962/12272962Protobuf::Field::Int64Field(singleton)#to_message_hash5.452.363.0913901859/13901859Protobuf::Field::StringField(singleton)#to_message_hash
5.722.183.5412272962/12272962Protobuf::Field::StringField(singleton)#to_message_hash5.262.263.0013901859/13901859Protobuf::Field::Int64Field(singleton)#to_message_hash
2.452.451.941.94 0.0027518879/36442639##[]30912498/71156329##[]
1.920.631.900.61 1.29990985/9909851036260/1036260 Protobuf::Field::StringField(singleton)#encode_to_stream
1.761.89 0.271.49990985/9909851.621036260/1036260 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.470.261.22990985/990985Protobuf::Field::Int64Field(singleton)#encode_to_stream1.551.550.0030912498/37130060Test::Resource#_protobuf_message_field
1.451.450.0027518879/33464791Test::Resource#_protobuf_message_field1.500.271.231036260/1036260Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.410.090.32990985/142549320.340.100.251036260/15974379 Protobuf::Field::StringField(singleton)#value_from_values
0.390.09 0.30990985/142549320.080.221036260/15974379 Protobuf::Field::Int64Field(singleton)#value_from_values
0.340.28 0.090.25990985/19819700.191036260/2072520 Protobuf::Field::EnumField(singleton)#value_from_values
22.652.1720.4812272962/1227296222.242.5019.7413901859/13901859 Proc#call
35% 3%22.652.1720.481227296222.242.5019.7413901859 Protobuf::Message#to_hash
20.485.3315.1412272962/13263948##each_key19.745.9413.8013901859/14938120##each_key
0.00 20.00 1/1##times##times
31% 1 Benchmark::IPS::Job#run_warmup
20.001.7618.251/992490##each1.8318.171/1037819##each
0.350.34 0.000.3510000/990985##times0.3310000/1036260##times
13.540.2813.26980985/99098513.710.2513.461026260/1036260 Proc#call
21%22% 0%13.890.2913.6199098514.050.2613.791036260 Protobuf::Message::Serialization::ClassMethods.decode_from
12.960.2312.73990985/99098513.160.2412.921036260/1036260 Protobuf::Message::Serialization.decode_from
0.650.63 0.130.52990985/19834360.501036260/2074044 Class#new
12.960.2312.73990985/99098513.160.2412.921036260/1036260 Protobuf::Message::Serialization::ClassMethods.decode_from
20% 0%12.960.2312.7399098513.160.2412.921036260 Protobuf::Message::Serialization.decode_from
12.7312.92 1.7510.98990985/99098511.171036260/1036260 Protobuf::Decoder.decode_each_field
12.7312.92 1.7510.98990985/99098511.171036260/1036260 Protobuf::Message::Serialization.decode_from
20% 2%12.7312.92 1.7510.9899098511.171036260 Protobuf::Decoder.decode_each_field
9.211.058.172972955/29729559.221.008.223108780/3108780 Protobuf::Message::Serialization.set_field_bytes
1.040.670.375945910/59459101.170.710.466217560/6217560 Protobuf::Varint.decode
0.190.190.210.21 0.003963940/39639404145040/4145040 StringIO#eof
0.17 0.17 0.003963940/3966993##==4145040/4148208##==
0.140.140.150.15 0.002972955/2972955##>>3108780/3108780##>>
0.120.120.130.13 0.002972955/6936895##&3108780/7253820##&
0.12 0.12 0.00990985/9909851036260/1036260 StringIO#read
9.211.058.172972955/29729559.221.008.223108780/3108780 Protobuf::Decoder.decode_each_field
14% 1%9.211.058.1729729559.221.008.223108780 Protobuf::Message::Serialization.set_field_bytes
3.380.253.13990985/9909853.430.263.181036260/1036260 Protobuf::Field::EnumField(singleton)#set
2.260.271.99990985/9909850.252.011036260/1036260 Protobuf::Field::Int64Field(singleton)#set
2.02 0.22 1.80990985/9909851036260/1036260 Protobuf::Field::StringField(singleton)#set
0.260.260.270.27 0.002972955/36442639##[]3108780/71156329##[]
0.250.250.240.24 0.002972955/334647913108780/37130060 Test::Resource#_protobuf_message_field
0.230.21 0.010.2210000/990985##times0.2110000/1036260##times
8.740.308.44980985/9909858.670.278.401026260/1036260 Proc#call
14% 0%8.970.318.669909858.890.288.601036260 Protobuf::Encoder.encode
8.660.408.26990985/9909858.600.398.211036260/1036260 Protobuf::Message#each_field_for_serialization
1.260.161.10990985/59459121.280.171.121036260/6217562 Protobuf::Field::EnumField(singleton)#set
1.381.41 0.201.18990985/59459121.211036260/6217562 Protobuf::Field::StringField(singleton)#set
1.410.151.26990985/59459120.171.241036260/6217562 Protobuf::Field::Int64Field(singleton)#set
1.560.261.30990985/59459121.550.281.281036260/6217562 Test::Resource#status=
3.090.542.551981972/5945912##each3.110.522.582072522/6217562##each
13% 2%8.701.317.3959459128.751.337.426217562 Protobuf::Message#set_field
2.382.37 0.491.891981971/19819711.882072521/2072521 Protobuf::Field::Int64Field(singleton)#set_field
2.260.731.521981971/19819712.350.761.592072521/2072521 Protobuf::Field::StringField(singleton)#set_field
2.250.481.771981970/19819702.270.471.802072520/2072520 Protobuf::Field::EnumField(singleton)#set_field
0.290.290.230.23 0.002972957/36442639##[]3108782/71156329##[]
0.21 0.21 0.002972957/334647913108782/37130060 Test::Resource#_protobuf_message_field
8.660.408.26990985/9909858.600.398.211036260/1036260 Protobuf::Encoder.encode
13% 0%8.660.408.269909858.600.398.211036260 Protobuf::Message#each_field_for_serialization
8.081.336.75990985/13263948##each_key8.011.406.611036260/14938120##each_key
0.140.140.150.15 0.00990985/29729561036260/3108781 Test::Resource#_protobuf_message_required_field_tags
5.982.173.8012272962/12272962##each_key
9%3%5.982.173.8012272962Protobuf::Field::Int64Field(singleton)#to_message_hash
2.341.840.5012272962/14254932Protobuf::Field::Int64Field(singleton)#value_from_values
1.471.470.0012272962/30496373##[]=
5.722.183.5412272962/12272962##each_key5.452.363.0913901859/13901859##each_key
9%8% 3%5.722.183.54122729625.452.363.0913901859 Protobuf::Field::StringField(singleton)#to_message_hash
2.511.930.5812272962/142549322.261.590.6813901859/15974379 Protobuf::Field::StringField(singleton)#value_from_values
1.031.030.830.83 0.0012272962/30496373##[]=13901859/34025837##[]=
0.16 0.01 0.15153/1983436153/2074044 Protobuf::Field.build
0.240.30 0.010.241/19834360.301/2074044 Bundler::Dsl#to_definition
0.650.63 0.130.52990985/19834360.501036260/2074044 Protobuf::Message::Serialization::ClassMethods.decode_from
3.963.94 0.143.82980985/19834363.801026260/2074044 Proc#call
8% 0%5.380.375.0019834365.390.385.012074044 Class#new
4.430.823.611981971/19819714.390.713.672072521/2072521 Protobuf::Message#initialize
0.240.30 0.000.230.29 1/1 Bundler::Definition#initialize
0.15 0.010.150.14 153/153 Protobuf::Field::BaseField#initialize
4.430.823.611981971/1981971Class#new5.262.263.0013901859/13901859##each_key
6%1%4.430.823.611981971Protobuf::Message#initialize
3.440.353.091981971/1982182##each8%3%5.262.263.0013901859Protobuf::Field::Int64Field(singleton)#to_message_hash
3.440.353.091981971/1982182Protobuf::Message#initialize
5%0%3.470.373.101982182##each2.201.550.6413901859/15974379Protobuf::Field::Int64Field(singleton)#value_from_values
3.090.542.551981972/5945912Protobuf::Message#set_field0.800.800.0013901859/34025837##[]=
3.380.253.13990985/990985Protobuf::Message::Serialization.set_field_bytes4.390.713.672072521/2072521Class#new
5%0%3.380.253.13990985Protobuf::Field::EnumField(singleton)#set
1.870.251.63990985/990985Protobuf::Field::EnumField#decode6%1%4.390.713.672072521Protobuf::Message#initialize
1.260.161.10990985/5945912Protobuf::Message#set_field3.490.383.112072521/2072735##each
0.18 0.18 0.002972955/364426393108780/71156329 Protobuf::Enum.enum_for_tag_integer
0.260.260.230.23 0.002972955/36442639Protobuf::Message::Serialization.set_field_bytes3108782/71156329Protobuf::Message#set_field
0.290.290.270.27 0.002972957/36442639Protobuf::Message#set_field3108780/71156329Protobuf::Message::Serialization.set_field_bytes
2.452.450.710.71 0.0027518879/36442639##each_key
5%5%3.213.180.0336442639##[]14938119/71156329Protobuf::Field::Int64Field(singleton)#value_from_values
0.150.150.750.75 0.001981971/30496373Protobuf::Field::StringField(singleton)#set_field14938119/71156329Protobuf::Field::StringField(singleton)#value_from_values
0.150.151.941.94 0.001981971/30496373Protobuf::Field::Int64Field(singleton)#set_field30912498/71156329##each_key
6%6%4.164.130.0371156329##[]
0.180.180.001981970/30496373Protobuf::Field::EnumField(singleton)#set_field3.490.383.112072521/2072735Protobuf::Message#initialize
5%0%3.510.403.112072735##each
1.031.030.0012272962/30496373Protobuf::Field::StringField(singleton)#to_message_hash3.110.522.582072522/6217562Protobuf::Message#set_field
1.471.470.0012272962/30496373Protobuf::Field::Int64Field(singleton)#to_message_hash3.430.263.181036260/1036260Protobuf::Message::Serialization.set_field_bytes
4%4%2.992.980.0130496373##[]=5%0%3.430.263.181036260Protobuf::Field::EnumField(singleton)#set
1.890.251.651036260/1036260Protobuf::Field::EnumField#decode
1.280.171.121036260/6217562Protobuf::Message#set_field
0.410.090.32990985/14254932##each_key0.340.100.251036260/15974379##each_key
2.511.930.5812272962/142549322.261.590.6813901859/15974379 Protobuf::Field::StringField(singleton)#to_message_hash
4%3%2.932.020.90142549322%2.601.680.9215974379 Protobuf::Field::StringField(singleton)#value_from_values
0.670.670.750.75 0.0013263947/27520181##fetch14938119/71156329##[]
0.390.09 0.30990985/14254932##each_key0.080.221036260/15974379##each_key
2.341.840.5012272962/142549322.201.550.6413901859/15974379 Protobuf::Field::Int64Field(singleton)#to_message_hash
4% 3%2.721.930.80142549322%2.501.640.8615974379 Protobuf::Field::Int64Field(singleton)#value_from_values
0.550.550.710.71 0.0013263947/27520181##fetch14938119/71156329##[]
2.382.37 0.491.891981971/19819711.882072521/2072521 Protobuf::Message#set_field
3% 0%2.382.37 0.491.8919819711.882072521 Protobuf::Field::Int64Field(singleton)#set_field
1.650.591.660.60 1.061981971/19819712072521/2072521 Protobuf::Field::IntegerField#coerce!
0.150.150.140.14 0.001981971/30496373##[]=2072521/34025837##[]=
2.350.761.592072521/2072521Protobuf::Message#set_field
3%1%2.350.761.592072521Protobuf::Field::StringField(singleton)#set_field
0.600.470.132072521/3108781Test::Resource#_protobuf_message_required_field_tags
0.57 0.410.162072521/2072521Protobuf::Field::StringField#coerce!
0.180.180.002072521/34025837##[]=
0.160.160.002072521/2072705##delete
0.38 0.030.392/18800.362/1886 Kernel.load
0.940.92 0.000.946/18800.926/1886 (top)
0.991.03 0.000.99112/18801.03115/1886 Kernel.require
2.34 0.03 2.3118801886 Kernel.require
0.840.89 0.000.840.89 1/1 Bundler.setup
0.250.23 0.000.2519/992490##each0.2319/1037819##each
0.12 0.00 0.121/1Gem::Specification.load_defaults109/109Protobuf::Message::Fields::ClassMethods.optional
0.120.11 0.000.12109/109Protobuf::Message::Fields::ClassMethods.optional0.111/1Gem::Specification.load_defaults
2.260.731.521981971/19819712.270.471.802072520/2072520 Protobuf::Message#set_field
3%1%2.260.731.521981971Protobuf::Field::StringField(singleton)#set_field
0.580.460.121981971/2972956Test::Resource#_protobuf_message_required_field_tags0%2.270.471.802072520Protobuf::Field::EnumField(singleton)#set_field
0.530.360.161981971/1981971Protobuf::Field::StringField#coerce!1.560.391.172072520/2072520Protobuf::Field::EnumField#coerce!
0.17 0.17 0.001981971/1982154##delete
0.150.150.001981971/30496373##[]=2072520/34025837##[]=
2.260.271.99990985/9909850.252.011036260/1036260 Protobuf::Message::Serialization.set_field_bytes
3% 0% 2.260.271.999909850.252.011036260 Protobuf::Field::Int64Field(singleton)#set
1.410.151.26990985/59459120.171.241036260/6217562 Protobuf::Message#set_field
0.580.430.16990985/1981970Protobuf::Field::IntegerField#decode
0.600.420.181036260/2072520Protobuf::Field::IntegerField#decode
2.250.481.771981970/1981970Protobuf::Message#set_field
3%0%2.250.481.771981970Protobuf::Field::EnumField(singleton)#set_field0.140.140.002072521/34025837Protobuf::Field::Int64Field(singleton)#set_field
1.520.371.151981970/1981970Protobuf::Field::EnumField#coerce!0.170.170.002072520/34025837Protobuf::Field::EnumField(singleton)#set_field
0.18 0.18 0.001981970/30496373##[]=2072521/34025837Protobuf::Field::StringField(singleton)#set_field
0.800.800.0013901859/34025837Protobuf::Field::Int64Field(singleton)#to_message_hash
0.830.830.0013901859/34025837Protobuf::Field::StringField(singleton)#to_message_hash
3%3%2.122.110.0134025837##[]=
2.02 0.22 1.80990985/9909851036260/1036260 Protobuf::Message::Serialization.set_field_bytes
2.02 0.22 1.809909851036260 Protobuf::Field::StringField(singleton)#set
1.381.41 0.201.18990985/59459121.211036260/6217562 Protobuf::Message#set_field
0.420.260.15990985/9909850.400.240.161036260/1036260 Protobuf::Field::StringField#decode
1.920.631.29990985/990985##each_key
3%1%1.920.631.29990985Protobuf::Field::StringField(singleton)#encode_to_stream
0.620.280.342972955/6936895IO::GenericWritable.<<
0.270.180.09990985/2973108Protobuf::Field::VarintField.encode
0.180.120.06990985/991766BasicObject#!=
0.21 0.21 0.002972957/334647913108782/37130060 Protobuf::Message#set_field
0.250.250.240.24 0.002972955/334647913108780/37130060 Protobuf::Message::Serialization.set_field_bytes
1.451.451.551.55 0.0027518879/33464791##each_key30912498/37130060##each_key
3% 3%1.911.912.002.00 0.003346479137130060 Test::Resource#_protobuf_message_field
1.870.251.63990985/990985Protobuf::Field::EnumField(singleton)#set1.900.611.291036260/1036260##each_key
2% 0%1.870.251.63990985Protobuf::Field::EnumField#decode1.900.611.291036260Protobuf::Field::StringField(singleton)#encode_to_stream
1.120.350.78990985/990985Protobuf::Field::EnumField#acceptable?0.630.310.323108780/7253820IO::GenericWritable.<<
0.500.360.250.160.091036260/3108933Protobuf::Field::VarintField.encode
0.19 0.14990985/1981970Protobuf::Field::IntegerField#decode0.061036260/1037071BasicObject#!=
1.790.261.53980985/990985Proc#call1.890.251.651036260/1036260Protobuf::Field::EnumField(singleton)#set
2% 0%1.830.271.56990985Test::Resource#status=1.890.251.651036260Protobuf::Field::EnumField#decode
1.560.261.30990985/5945912Protobuf::Message#set_field1.120.330.791036260/1036260Protobuf::Field::EnumField#acceptable?
0.530.380.151036260/2072520Protobuf::Field::IntegerField#decode
1.761.89 0.271.49990985/990985##each_key1.621036260/1036260##each_key
2% 0%1.761.89 0.271.499909851.621036260 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.140.210.93990985/9909851.250.241.001036260/1036260 Protobuf::Field::EnumField#encode
0.350.380.19 0.180.171981970/69368952072520/7253820 IO::GenericWritable.<<
1.650.591.770.251.531026260/1036260Proc#call
2%0%1.810.261.551036260Test::Resource#status=
1.550.281.281036260/6217562Protobuf::Message#set_field
1.660.60 1.061981971/19819712072521/2072521 Protobuf::Field::Int64Field(singleton)#set_field
2% 0%1.650.591.660.60 1.0619819712072521 Protobuf::Field::IntegerField#coerce!
0.890.600.291981971/19819710.870.580.282072521/2072521 Protobuf::Field::IntegerField#acceptable?
0.110.110.002072521/7255321Kernel.kind_of?
0.570.210.37990985/29729640.590.200.381036260/3108789 Protobuf::Field::EnumField#acceptable?
0.990.340.651981970/29729641.020.350.672072520/3108789 Protobuf::Field::EnumField#coerce!
2% 0%1.570.551.0229729641.610.561.053108789 Protobuf::Enum.fetch
0.870.550.322972955/29729550.910.570.343108780/3108780 Protobuf::Enum.enum_for_tag_integer
0.14 0.14 0.002972964/69382793108789/7255321 Kernel.kind_of?
1.520.371.151981970/19819701.560.391.172072520/2072520 Protobuf::Field::EnumField(singleton)#set_field
2% 0%1.520.371.1519819701.560.391.172072520 Protobuf::Field::EnumField#coerce!
0.990.340.651981970/29729641.020.350.672072520/3108789 Protobuf::Enum.fetch
0.15 0.15 0.001981970/29733972072520/3109338 Protobuf::Field::BaseField#type_class
0.690.380.31990985/19819700.720.400.321036260/2072520 Protobuf::Field::EnumField#encode
0.830.480.35990985/19819700.820.430.391036260/2072520 Protobuf::Field::Int64Field(singleton)#encode_to_stream
2% 1%1.510.850.6619819701.540.830.712072520 Protobuf::Field::IntegerField#encode
0.410.250.161981970/29731080.460.260.202072520/3108933 Protobuf::Field::VarintField.encode
0.25 0.25 0.001981970/6936895##&2072520/7253820##&
1.470.261.22990985/990985##each_key1.500.271.231036260/1036260##each_key
2% 0%1.470.261.229909851.500.271.231036260 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.830.480.35990985/19819700.820.430.391036260/2072520 Protobuf::Field::IntegerField#encode
0.390.180.211981970/69368950.410.190.222072520/7253820 IO::GenericWritable.<<
0.350.380.19 0.180.171981970/69368952072520/7253820 Protobuf::Field::EnumField(singleton)#encode_to_stream
0.390.180.211981970/69368950.410.190.222072520/7253820 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.620.280.342972955/69368950.630.310.323108780/7253820 Protobuf::Field::StringField(singleton)#encode_to_stream
2% 1%1.370.640.7269368951.410.690.737253820 IO::GenericWritable.<<
0.720.720.730.73 0.006936895/69368957253820/7253820 StringIO#write
0.550.550.0013263947/27520181Protobuf::Field::Int64Field(singleton)#value_from_values
0.670.670.0013263947/27520181Protobuf::Field::StringField(singleton)#value_from_values
2%2%1.281.270.0027520181##fetch
1.140.210.93990985/9909851.250.241.001036260/1036260 Protobuf::Field::EnumField(singleton)#encode_to_stream
1% 0%1.140.210.939909851.250.241.001036260 Protobuf::Field::EnumField#encode
0.690.380.31990985/19819700.720.400.321036260/2072520 Protobuf::Field::IntegerField#encode
0.250.140.10990985/9912530.280.170.111036260/1036528 Protobuf::Enum#to_i
1.120.350.78990985/990985Protobuf::Field::EnumField#decode1.170.710.466217560/6217560Protobuf::Decoder.decode_each_field
1%0%1.120.350.78990985Protobuf::Field::EnumField#acceptable?
0.570.210.37990985/2972964Protobuf::Enum.fetch1%1.170.710.466217560Protobuf::Varint.decode
0.110.110.460.46 0.00990985/2973397Protobuf::Field::BaseField#type_class6217560/6217560ProtobufJavaHelpers::Varinter.read_varint
0.500.360.14990985/19819700.530.380.151036260/2072520 Protobuf::Field::EnumField#decode
0.580.430.16990985/19819700.600.420.181036260/2072520 Protobuf::Field::Int64Field(singleton)#set
1% 1%1.090.790.3019819701.130.800.332072520 Protobuf::Field::IntegerField#decode
0.200.200.220.22 0.001981970/6936895##&
1.040.670.375945910/5945910Protobuf::Decoder.decode_each_field
1%1%1.040.670.375945910Protobuf::Varint.decode2072520/7253820##&
0.370.370.110.11 0.005945910/5945910ProtobufJavaHelpers::Varinter.read_varint2072520/2072845Numeric#nonzero?
0.990.000.992/112(top)1.120.330.791036260/1036260Protobuf::Field::EnumField#decode
1% 0%0.990.000.99112Kernel.require1.120.330.791036260Protobuf::Field::EnumField#acceptable?
0.590.200.381036260/3108789Protobuf::Enum.fetch
0.990.110.11 0.000.99112/1880Kernel.require1036260/3109338Protobuf::Field::BaseField#type_class
0.890.600.291981971/1981971Protobuf::Field::IntegerField#coerce!1.040.001.032/115(top)
1% 0%0.890.600.291981971Protobuf::Field::IntegerField#acceptable?1.040.001.03115Kernel.require
0.120.121.03 0.001981971/6938279Kernel.kind_of?1.03115/1886Kernel.require
0.870.550.322972955/29729550.910.570.343108780/3108780 Protobuf::Enum.fetch
1% 0%0.870.550.3229729550.910.570.343108780 Protobuf::Enum.enum_for_tag_integer
0.18 0.18 0.002972955/36442639##[]3108780/71156329##[]
0.150.150.170.17 0.002972955/2973417##first3108780/3109269##first
0.840.89 0.000.840.89 1/1 Kernel.require
1% 0%0.840.89 0.000.840.89 1 Bundler.setup
0.440.51 0.010.440.50 1/2 Bundler.definition
0.380.37 0.000.380.37 1/1 Bundler::Runtime#setup
0.840.420.423301704/3301704##each0.870.440.433593944/3593944##each
1% 0%0.840.420.4233017040.870.440.433593944 Benchmark::Timing.now
0.420.420.430.43 0.003301704/33017053593944/3593945 Process.clock_gettime
0.720.720.870.580.282072521/2072521Protobuf::Field::IntegerField#coerce!
1%0%0.870.580.282072521Protobuf::Field::IntegerField#acceptable?
0.110.11 0.006936895/6936895IO::GenericWritable.<<2072521/7255321Kernel.kind_of?
0.710.710.0018521509/20594046Benchmark::IPS::Job::Entry#call_times
1% 1%0.720.720.790.79 0.006936895StringIO#write20594046##<
0.14 0.14 0.00990985/2972956Protobuf::Message#each_field_for_serialization3593404/18522606##each
0.580.460.121981971/2972956Protobuf::Field::StringField(singleton)#set_field
1%0%0.720.600.122972956Test::Resource#_protobuf_message_required_field_tags
0.120.120.001981971/1982937Kernel.dup
0.63 0.63 0.0016555118/1853710514928119/18522606 Benchmark::IPS::Job::Entry#call_times
1% 1%0.720.720.780.78 0.0018537105##<18522606##+
0.150.150.001036260/3108781Protobuf::Message#each_field_for_serialization
0.600.470.132072521/3108781Protobuf::Field::StringField(singleton)#set_field
1%0%0.750.620.133108781Test::Resource#_protobuf_message_required_field_tags
0.13 0.13 0.003301185/16556215##each2072521/2073553Kernel.dup
0.570.570.730.73 0.0013253947/16556215Benchmark::IPS::Job::Entry#call_times7253820/7253820IO::GenericWritable.<<
1% 1%0.700.700.730.73 0.0016556215##+7253820StringIO#write
0.270.180.250.16 0.09990985/29731081036260/3108933 Protobuf::Field::StringField(singleton)#encode_to_stream
0.410.250.161981970/29731080.460.260.202072520/3108933 Protobuf::Field::IntegerField#encode
1% 0%0.690.430.2629731080.710.420.293108933 Protobuf::Field::VarintField.encode
0.260.260.290.29 0.002973108/29731083108933/3108933 ProtobufJavaHelpers::Varinter.to_varint
0.120.120.130.13 0.002972955/69368953108780/7253820 Protobuf::Decoder.decode_each_field
0.200.200.220.22 0.001981970/69368952072520/7253820 Protobuf::Field::IntegerField#decode
0.25 0.25 0.001981970/69368952072520/7253820 Protobuf::Field::IntegerField#encode
0% 0%0.570.570.610.61 0.006936895##&7253820##&
0.530.360.570.41 0.161981971/19819712072521/2072521 Protobuf::Field::StringField(singleton)#set_field
0% 0%0.530.360.570.41 0.1619819712072521 Protobuf::Field::StringField#coerce!
0.520.510.010.501/2Bundler.setup
0%0%0.510.010.502Bundler.definition
0.410.000.411/1Bundler::Definition.build
0.48 0.060.450.42 17/19 (top)
0% 0%0.520.48 0.060.450.42 19 Kernel.load
0.410.38 0.030.392/18800.362/1886 Kernel.require
0.440.010.441/2Bundler.setup0.460.460.006217560/6217560Protobuf::Varint.decode
0% 0%0.440.010.442Bundler.definition0.460.460.006217560ProtobufJavaHelpers::Varinter.read_varint
0.350.430.43 0.000.351/1Bundler::Definition.build3593944/3593945Benchmark::Timing.now
0%0%0.430.430.003593945Process.clock_gettime
0.360.33 0.000.361/8380.331/873 Bundler::Runtime#requested_specs
0.42 0.00 0.42838873 Kernel.send
0.360.33 0.000.360.33 1/1 Bundler::Definition#requested_specs
0.420.420.41 0.003301704/3301705Benchmark::Timing.now0.411/1Bundler.definition
0% 0%0.420.420.41 0.003301705Process.clock_gettime0.411Bundler::Definition.build
0.420.260.15990985/990985Protobuf::Field::StringField(singleton)#set
0%0%0.420.260.15990985Protobuf::Field::StringField#decode0.400.000.401/1Bundler::Dsl.evaluate
0.380.40 0.000.380.40 1/1Bundler.setupBundler::Definition.build
0% 0%0.380.40 0.000.380.40 1Bundler::Runtime#setupBundler::Dsl.evaluate
0.360.30 0.000.360.30 1/1Bundler::Runtime#requested_specsBundler::Dsl#to_definition
0.370.370.005945910/5945910Protobuf::Varint.decode0.400.240.161036260/1036260Protobuf::Field::StringField(singleton)#set
0% 0%0.370.400.240.161036260Protobuf::Field::StringField#decode
0.37 0.005945910ProtobufJavaHelpers::Varinter.read_varint0.371/1Bundler.setup
0% 0%0.360.360.37 0.008919759Kernel.nil?0.371Bundler::Runtime#setup
0.330.000.331/1Bundler::Runtime#requested_specs
0.120.120.110.11 0.001981971/69382792072521/7255321 Protobuf::Field::IntegerField#acceptable?
0.110.110.002072521/7255321Protobuf::Field::IntegerField#coerce!
0.140.140.14 0.002972964/69382793108789/7255321 Protobuf::Enum.fetch
0.36 0.36 0.0069382797255321 Kernel.kind_of?
0%0%0.350.350.009327308Kernel.nil?
0.360.33 0.000.360.33 1/1 Bundler::Runtime#setup
0% 0%0.360.33 0.000.360.33 1 Bundler::Runtime#requested_specs
0.360.33 0.000.361/8380.331/873 Kernel.send
0.360.33 0.000.360.33 1/1 Kernel.send
0% 0%0.360.33 0.000.360.33 1 Bundler::Definition#requested_specs
0.360.33 0.000.360.33 1/1 Bundler::Definition#specs_for
0.360.33 0.000.360.33 1/1 Bundler::Definition#requested_specs
0% 0%0.360.33 0.000.360.33 1 Bundler::Definition#specs_for
0.350.32 0.000.350.32 1/1 Bundler::Definition#specs
0.350.32 0.000.350.32 1/1Bundler.definitionBundler::Definition#specs_for
0% 0%0.350.32 0.000.350.32 1Bundler::Definition.buildBundler::Definition#specs
0.340.21 0.000.340.21 1/1Bundler::Dsl.evaluateBundler::SpecSet#materialize
0.350.30 0.000.350.30 1/1Bundler::Definition#specs_forBundler::Dsl.evaluate
0% 0%0.350.30 0.000.350.30 1Bundler::Definition#specs
0.220.000.221/1Bundler::SpecSet#materializeBundler::Dsl#to_definition
0.110.000.111/1Bundler::Definition#resolve0.300.010.301/2074044Class#new
0.340.30 0.000.340.29 1/1Bundler::Definition.buildClass#new
0% 0%0.340.30 0.000.340.29 1Bundler::Dsl.evaluateBundler::Definition#initialize
0.240.10 0.000.240.10 1/1Bundler::Dsl#to_definitionBundler::Definition#converge_paths
0.340.090.25990985/1981970##each_key0.290.290.003108933/3108933Protobuf::Field::VarintField.encode
0% 0%0.340.090.251981970Protobuf::Field::EnumField(singleton)#value_from_values0.290.290.003108933ProtobufJavaHelpers::Varinter.to_varint
0.260.150.280.17 0.11980985/990985Proc#call1036260/1036528Protobuf::Field::EnumField#encode
0% 0%0.270.150.12990985StringIO.new0.280.170.111036528Protobuf::Enum#to_i
0.120.120.110.11 0.00990985/990985StringIO#initialize1036528/1036528Protobuf::Enum#tag
0.280.090.191036260/2072520##each_key
0%0%0.280.090.192072520Protobuf::Field::EnumField(singleton)#value_from_values
0.11 0.11 0.00990985/29733971036260/3109338 Protobuf::Field::EnumField#acceptable?
0.15 0.15 0.001981970/29733972072520/3109338 Protobuf::Field::EnumField#coerce!
0% 0%0.270.270.260.26 0.0029733973109338 Protobuf::Field::BaseField#type_class
0.260.260.002973108/2973108Protobuf::Field::VarintField.encode0.250.140.111026260/1036260Proc#call
0% 0% 0.260.260.140.121036260StringIO.new
0.120.12 0.002973108ProtobufJavaHelpers::Varinter.to_varint1036260/1036260StringIO#initialize
0.250.140.10990985/991253Protobuf::Field::EnumField#encode0.210.210.004145040/4145040Protobuf::Decoder.decode_each_field
0% 0%0.250.140.10991253Protobuf::Enum#to_i
0.100.100.210.21 0.00991253/991253Protobuf::Enum#tag4145040StringIO#eof
0.240.21 0.000.240.21 1/1Bundler::Dsl.evaluateBundler::Definition#specs
0% 0%0.240.21 0.000.240.21 1Bundler::Dsl#to_definitionBundler::SpecSet#materialize
0.240.010.241/1983436Class#new0.110.000.111/412##map!
0.240.000.231/1Class#new0.190.140.061036260/1037071Protobuf::Field::StringField(singleton)#encode_to_stream
0% 0%0.240.200.140.061037071BasicObject#!=
0%0%0.200.20 0.000.231Bundler::Definition#initialize2072662##+
0.190.180.18 0.000.191/400Bundler::SpecSet#materialize3593394/3593394##each
0% 0%0.230.020.22400##map!0.180.180.003593394##<
0.190.12 0.000.1939/39Bundler::LazySpecification#__materialize__
0.220.000.221/1Bundler::Definition#specs0.12109/153Protobuf::Message::Fields::ClassMethods.optional
0% 0%0.220.17 0.000.221Bundler::SpecSet#materialize0.17153Protobuf::Message::Fields::ClassMethods.define_field
0.190.16 0.000.191/400##map!0.16153/153Protobuf::Field.build
0.190.170.17 0.000.1939/39##map!4145040/4148208Protobuf::Decoder.decode_each_field
0% 0%0.190.170.17 0.000.1939Bundler::LazySpecification#__materialize__4148208##==
0.160.170.17 0.000.1638/38Bundler::Source::Rubygems#specs3108780/3109269Protobuf::Enum.enum_for_tag_integer
0% 0%0.190.190.170.17 0.001982108##+3109269##first
0.190.190.16 0.003963940/3963940Protobuf::Decoder.decode_each_field0.16153/153Protobuf::Message::Fields::ClassMethods.define_field
0% 0%0.190.190.16 0.003963940StringIO#eof0.16153Protobuf::Field.build
0.160.010.15153/2074044Class#new
0.100.100.160.16 0.003/642Gem::Specification.gemspec_stubs_in2072521/2072705Protobuf::Field::StringField(singleton)#set_field
0% 0%0.190.110.07642##map0.160.160.002072705##delete
0.180.120.06990985/991766Protobuf::Field::StringField(singleton)#encode_to_stream0.150.010.14153/153Class#new
0% 0%0.180.120.06991766BasicObject#!=0.150.010.14153Protobuf::Field::BaseField#initialize
0.120.11 0.00 0.11109/153Protobuf::Message::Fields::ClassMethods.optional1/412Bundler::SpecSet#materialize
0% 0%0.180.000.17153Protobuf::Message::Fields::ClassMethods.define_field0.150.020.13412##map!
0.170.11 0.000.17153/153Protobuf::Field.build0.1139/39Bundler::LazySpecification#__materialize__
0.170.170.150.15 0.001981971/1982154Protobuf::Field::StringField(singleton)#set_field3108780/3108780Protobuf::Decoder.decode_each_field
0% 0%0.170.170.150.15 0.001982154##delete3108780##>>
0.170.000.17153/153Protobuf::Message::Fields::ClassMethods.define_field
0% 0%0.170.000.17153Protobuf::Field.build
0.160.010.15153/1983436Class#new0.140.060.081137BasicObject#instance_eval
0.170.170.130.13 0.003963940/3966993Protobuf::Decoder.decode_each_field2072521/2073553Test::Resource#_protobuf_message_required_field_tags
0% 0%0.170.170.130.13 0.003966993##==2073553Kernel.dup
0%0%0.130.030.1061Kernel.eval
0.160.12 0.000.161/2Bundler::Source::Rubygems#installed_specs0.12109/109Kernel.require
0% 0%0.170.12 0.000.162Bundler::Index.build0.12109Protobuf::Message::Fields::ClassMethods.optional
0.150.12 0.000.151/1Bundler::RubygemsIntegration::MoreFuture#all_specs0.12109/153Protobuf::Message::Fields::ClassMethods.define_field
0.160.120.12 0.000.1638/38Bundler::LazySpecification#__materialize__1036260/1036260Protobuf::Decoder.decode_each_field
0% 0%0.160.120.12 0.000.1638Bundler::Source::Rubygems#specs1036260StringIO#read
0.160.120.12 0.000.161/1Bundler::Source::Rubygems#installed_specs1036260/1036260StringIO.new
0%0%0.120.120.001036260StringIO#initialize
0.160.11 0.000.160.11 1/1Bundler::Source::Rubygems#specsKernel.require
0% 0%0.160.11 0.000.160.11 1Bundler::Source::Rubygems#installed_specsGem::Specification.load_defaults
0.160.11 0.000.161/2Bundler::Index.build0.111/1Gem::Specification.each_spec
0.150.010.15153/153Class#new0.110.000.111/1Gem::Specification.load_defaults
0% 0%0.150.010.15153Protobuf::Field::BaseField#initialize0.110.000.111Gem::Specification.each_spec
0.150.150.003301175/3301175##each
0%0%0.150.150.11 0.003301175##<0.111/1Gem::Specification.each_gemspec
0.150.11 0.000.150.11 1/1Bundler::Index.buildGem::Specification.each_spec
0% 0%0.150.11 0.000.150.11 1Bundler::RubygemsIntegration::MoreFuture#all_specsGem::Specification.each_gemspec
0.150.11 0.000.151/1Gem::Specification.stubs0.111/1037819##each
0.150.150.110.11 0.002972955/2973417Protobuf::Enum.enum_for_tag_integer2072520/2072845Protobuf::Field::IntegerField#decode
0% 0%0.150.150.110.11 0.002973417##first2072845Numeric#nonzero?
0.150.000.151/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0% 0%0.150.11 0.000.151Gem::Specification.stubs0.1113Bundler::SpecSet#sorted
0.130.11 0.000.131/1Gem::Specification.installed_stubs
0%0%0.140.060.081137BasicObject#instance_eval0.114/4TSort.tsort
0.130.10 0.000.132/3##each0.101/172Bundler::Definition#converge_paths
0% 0%0.140.11 0.000.143Gem::Specification.gemspec_stubs_in0.11172##any?
0.100.10 0.003/642##map0.102/2Bundler::Definition#specs_changed?
0.140.140.11 0.002972955/2972955Protobuf::Decoder.decode_each_field0.114/176##to_a
0% 0%0.140.140.110.000.11176Enumerator#each
0.11 0.002972955##>>
0%0%0.130.030.1060Kernel.eval0.114/8TSort.tsort_each
0.130.11 0.000.131/1Gem::Specification.stubs0.114/4Bundler::SpecSet#sorted
0% 0%0.130.11 0.000.131Gem::Specification.installed_stubs0.114TSort.tsort
0.130.11 0.000.131/1Gem::Specification.map_stubs0.114/4TSort.tsort
0.130.11 0.000.131/1Gem::Specification.installed_stubs0.114/4TSort.tsort
0% 0%0.130.11 0.000.131Gem::Specification.map_stubs0.114TSort.tsort
0.130.11 0.000.131/1##flat_map0.114/4##to_a
0.130.11 0.000.131/1Gem::Specification.map_stubs0.114/8Enumerator#each
0% 0%0.130.11 0.000.131##flat_map0.118TSort.tsort_each
0.130.11 0.000.131/992490##each0.114/4TSort.each_strongly_connected_component
0.120.120.11 0.001981971/1982937Test::Resource#_protobuf_message_required_field_tags0.114/4TSort.tsort
0% 0%0.120.120.11 0.001982937Kernel.dup0.114##to_a
0.110.000.114/176Enumerator#each
0.120.11 0.000.121/1Kernel.require0.114/4TSort.tsort_each
0% 0%0.120.11 0.000.121Gem::Specification.load_defaults0.114TSort.each_strongly_connected_component
0.120.11 0.000.121/1Gem::Specification.each_spec0.114/122Method#call
0.120.11 0.000.121/1Gem::Specification.load_defaults0.114/122TSort.each_strongly_connected_component
0% 0%0.120.11 0.000.121Gem::Specification.each_spec0.11122Method#call
0.120.11 0.000.121/1Gem::Specification.each_gemspec0.114/4Bundler::SpecSet#tsort_each_node
0.100.000.10118/118Bundler::SpecSet#tsort_each_child
0.120.11 0.000.121/1Gem::Specification.each_spec0.114/4Method#call
0% 0%0.120.11 0.000.121Gem::Specification.each_gemspec0.114Bundler::SpecSet#tsort_each_node
0.120.11 0.000.121/992490##each0.114/1037819##each
0.120.110.11 0.000.12109/109Kernel.require1036528/1036528Protobuf::Enum#to_i
0% 0%0.120.110.11 0.000.12109Protobuf::Message::Fields::ClassMethods.optional1036528Protobuf::Enum#tag
0.120.11 0.000.10118/118##each
0%0% 0.11109/153Protobuf::Message::Fields::ClassMethods.define_field0.000.10118TSort.each_strongly_connected_component_from
0.120.120.11 0.00990985/990985Protobuf::Decoder.decode_each_field0.1139/39##map!
0% 0%0.120.120.11 0.00990985StringIO#read0.1139Bundler::LazySpecification#__materialize__
0.120.120.100.10 0.00990985/990985StringIO.new1026260/1036260Proc#call
0% 0%0.120.120.110.11 0.00990985StringIO#initialize1036260Protobuf::Message#to_proto
0.110.10 0.000.110.10 1/1Bundler::Definition#specsBundler::Definition#initialize
0% 0%0.110.10 0.000.110.10 1Bundler::Definition#resolveBundler::Definition#converge_paths
0.100.000.101/172##any?
0.100.000.102/2##any?
0% 0% 0.10 0.00 0.106Bundler::SpecSet#for2Bundler::Definition#specs_changed?
0.100.010.096/6Kernel.loop0.000.102/2Bundler::Definition#specs_for_source_changed?
0.100.10 0.00991253/991253Protobuf::Enum#to_i0.102/2Bundler::Definition#specs_changed?
0% 0% 0.100.000.102Bundler::Definition#specs_for_source_changed?
0%0% 0.10 0.00991253Protobuf::Enum#tag0.105Bundler::Source::Path#specs
0.100.010.096/6Bundler::SpecSet#for0.000.10118/118Method#call
0% 0% 0.100.010.096Kernel.loop
0.000.10118Bundler::SpecSet#tsort_each_child
@@ -67,195 +67,204 @@

Total time: 63.27

- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - - + + - + - + - - - + + + - + - - + + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - - + + - - + + - + + + - - - + + + + + + + + + + - + - + - + - + - - - + + + - + - + - + - + - + @@ -264,381 +273,381 @@

Total time: 63.27

- + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - - + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - + - + - + - + - + - + - + - - - + + + - + - - - - + + + + - - - - + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - - - - - - - - - - + - - - - + + + + - + - - - - - + + + + + - + - - + + - + - + - - - - + + + + + + + + + + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - - - - + + + + - + - - - - - + + + + + @@ -648,7 +657,7 @@

Total time: 63.27

- + @@ -659,1904 +668,1681 @@

Total time: 63.27

- + - - - - + + + + - + - - - + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - + + - - + + - + - - + + - + - - - - + + + + - - - - + + + + - + - - - - - + + + + + - + - - + + - + - + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - + + - - - - - - - - - - - - + + - + - - - - - + + + + + - - - - + + + + - + - + - - + + - + - - + + - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - - + + - - - - + + + + - - + + - + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - - + + + + + + + + + + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + - - + + - + - - + + - - + + - - + - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - - - - - - - - - - - - - - - - + + - + + - - - - - + + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + - + - - + + - - + + - + - + - - + + - + - - - + + + - + - - - - + + + + - + - - - - - + + + + + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - + + - - - + - - - - - - - - - - - + + + - - + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - + + - - + + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - + + - - + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - + + + + + - - + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - - - - + + + + - - + - + + - - - - + + + + - - - - + + + + - + - - + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - + + - - + + - - + + - - + + - + - - - - - + + + + + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - + + + + + - + - - + + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - + + + + + - - - - - - + + + + + + - + - - + + - - + + - + - - + + - - + + - - + + - - + + - - - - - + + + + + - + + + + + + + + + + - - + + - - + + - - - - - + + + + + - - + + @@ -2565,240 +2351,222 @@

Total time: 63.27

- - + + - - - - - + + + + + - - - - - - - - - - - - + + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - + + + + + - - - - - + + + + + - + - - + + - - + + - + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + + - - + + - - + + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - - - - - - - + - - - + + + - + @@ -2814,13 +2582,13 @@

Total time: 63.27

- + - + - + @@ -2829,101 +2597,120 @@

Total time: 63.27

- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + @@ -2932,54 +2719,7 @@

Total time: 63.27

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -2998,7 +2738,7 @@

Total time: 63.27

- + @@ -3026,7 +2766,7 @@

Total time: 63.27

- + @@ -3035,7 +2775,7 @@

Total time: 63.27

- + @@ -3054,7 +2794,7 @@

Total time: 63.27

- + @@ -3063,7 +2803,63 @@

Total time: 63.27

- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3082,7 +2878,7 @@

Total time: 63.27

- + @@ -3091,80 +2887,126 @@

Total time: 63.27

- + + + + + + + + + + - + - + - + - + - + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - - - - - + + + + + - - + + + + + + + + + + + - - + + @@ -3173,7 +3015,7 @@

Total time: 63.27

- + @@ -3182,16 +3024,16 @@

Total time: 63.27

- + - + - + @@ -3199,75 +3041,133 @@

Total time: 63.27

- - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + + + + + + + + + + + - - + + - + - - + + - + - - - - - + + + + + - - - - - + + + + + - + + - - + + - - + + + + + + + + + + + @@ -3276,7 +3176,7 @@

Total time: 63.27

- + @@ -3285,10 +3185,10 @@

Total time: 63.27

- - + + - + @@ -3307,99 +3207,89 @@

Total time: 63.27

- - - - - - - - - - + - - - - - + + + + + - - - - - + + + + + - - - - - - + + + + - - + + + - + - - - + + + - - - + + + - + + + + + + + + + + - + + - - - + + - - - - - - - - - - + + - - - + + - + - + @@ -3408,18 +3298,18 @@

Total time: 63.27

- - + + - + - - + + @@ -3427,186 +3317,204 @@

Total time: 63.27

- - + + - - + + - + - - + + - - - - - - - - - - + - + - - + + - - + + - - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + + + + + + + + + + - + - + - - - + + + - - - - - + + + + + - + - + - - - + + + - + - - + - - + + + - - + - - + + + - - - - + + + - - - - + + + + - + - - + + - - + + - - + + - - - - - - - - - - - - + + - + - + - + - + - + - + - + - + @@ -3614,329 +3522,359 @@

Total time: 63.27

- - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - + - - - + + + - + - + + + + + + + + + + + - - + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - - + - - + + + - - + + + + + + + + + + - - + + + + + + + + + + + + + - - + - - - + + + - + - + - + - + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - + + + - - - - + + + + - - - - + + - + + - + + - - - + + + + + + + + + + + - + - + + - - - + + - + + - - - + + - - - - + + + + + + - - - + + @@ -3945,63 +3883,45 @@

Total time: 63.27

- - + + - + - - - + + + - + - - + + - + - - - + + + - - - - - - - - - - - - - - - - - - - - + + @@ -4010,8 +3930,8 @@

Total time: 63.27

- - + + @@ -4019,27 +3939,37 @@

Total time: 63.27

- - + + - + + + + + + + + + - - + + + + - + - - + + @@ -4047,37 +3977,37 @@

Total time: 63.27

- - + + + - - - + + + - - - + + - + - - + + @@ -4085,122 +4015,150 @@

Total time: 63.27

- - + + + + + + + + + + + - + - - + - - + + + + + + + + + + + - - + + + - + - + - - - + + + + + + + + + + + + + - - + + - + - - + + - + - - - + + + - - - - - - - - - - - + + - + - - - + + + + + + + + + + + - - + + + + - - - + + - + - - + + @@ -4208,1253 +4166,1248 @@

Total time: 63.27

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + - - - - - - + + - - - - - - - - - + + + + - - - - - + - + + + + + + + + + - + - - + + + + + + - - - - + + + - + + + + + + + + + + + + + + + - + + + - - - - + + - - - + - - + + + + + + - + - + + + - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + - + + - - - - + + - - + + + - - + - + + + + - - - - - - - - - - - - - - + + - - - - - - + - - - + - - - - - + + + - - + + + + - + - + - + - - - + + + + - - - - - - + + + + + - - - - + - - - + - - - + + + + + + + + + + + - - - - - - - + + + + + - + + + + - - - - - - + + + - - - - - - - + + + + + + - - - + + + - + + + - - - - - + + + - - - - - + + - - - - - - - - - - - + + + + + - - + + + + + + - - - + + + + + + + + + + + + + - - + - - + + + - - - - - - + + + + + + - - - + + + - - - - - + + + + + + + + - - + + - + + + + + - - - - - - + + - - + + - - - - - + + - + + + - - - - + + + + + + + + - - - - - - - + + + + + + + - + - - - - + + - - - - - + + + + + + - + + + + + - - - - - - - - + + + - - + - - - - + - + + + - - - - - + - - - - + - - - - - - - - - - - - - - + - - - + + - - + + + - + + + + - - + + + + + + + + + + - - + + + + + + + + + + + + + - + + - - - - - - - - + - + + + + + + + + - - - - - + + + - - - - - - - - - - - - - - - - + - - + + + + + + - - + + + + + + - - + + - - - + - - - - - - - - + + - - + + - - - - - - + + + + - - + - - - + + + + + + + + + - + + + + + + - - + - - + + - + + + + + + + + + + + + + + + + + - - - - - - - - + + + - - + + + + + + - - - - - - - + - + + + + - + - - - + + + - + - + + + + - + + - + + + - - + + - - - - - - + + - + + + - - - - + + - - - + - + + + - - - + + + - - - + + - - - + - + - - - - + + + - - - - - - + - + + + - + - + + + + + + + + + + + + + + - - + + - - + + + - - - - + - - - - - + + + - + - - + + @@ -5464,8 +5417,11 @@

Total time: 63.27

+ + + @@ -5473,26 +5429,25 @@

Total time: 63.27

+ - + + - - - @@ -5504,19 +5459,18 @@

Total time: 63.27

- - + @@ -5527,34 +5481,35 @@

Total time: 63.27

+ - - - + + + + - @@ -5562,6 +5517,7 @@

Total time: 63.27

+ @@ -5573,9 +5529,9 @@

Total time: 63.27

+ - @@ -5586,7 +5542,6 @@

Total time: 63.27

- @@ -5601,7 +5556,6 @@

Total time: 63.27

- From 9468229ce4d1e1d118b0c12e18c24f1890e5edd2 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 27 Dec 2018 17:47:24 -0700 Subject: [PATCH 1114/1191] remove unneeded comment --- lib/protobuf/message/serialization.rb | 1 - profile.html | 5610 ++++++++++++------------- 2 files changed, 2724 insertions(+), 2887 deletions(-) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 246168de..9da948ca 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -76,7 +76,6 @@ def encode_to(stream) private def set_field_bytes(tag, bytes) - #field = self.class.get_field(tag, true) field = _protobuf_message_field[tag] field.set(self, bytes) if field end diff --git a/profile.html b/profile.html index b4e04e95..301a2adf 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 63.20

+

Total time: 63.22

%Total
100% 0%63.2763.20 0.0063.2763.20 0 (top)
60.1060.08 0.0060.1060.08 1/1 Benchmark::IPS.ips
1.041.01 0.001.031.00 2/115 Kernel.require
0.920.93 0.000.920.93 6/1886 Kernel.require
0.730.65 0.040.690.61 1/5##times##times
0.480.53 0.060.420.47 17/19 Kernel.load
0.110.13 0.000.114/10378190.124/1265137 Bundler::SpecSet#tsort_each_node
0.110.14 0.000.111/10378190.141/1265137 Gem::Specification.each_gemspec
0.230.24 0.00 0.2319/103781919/1265137 Kernel.require
20.001.8318.171/10378191.8018.201/1265137 Benchmark::IPS::Job#run_warmup
40.0940.07 0.0140.091/103781940.071/1265137 Benchmark::IPS::Job#run_benchmark
96% 2%60.951.8759.081037819##each60.941.8459.091265137##each
57.052.7754.283593390/359339057.022.9254.103554696/3554696 Benchmark::IPS::Job::Entry#call_times
0.870.440.433593944/35939440.910.450.463555260/3555260 Benchmark::Timing.now
0.18 0.18 0.003593394/3593394##<3554700/3554700##<
0.140.140.150.15 0.003593404/18522606##+3554710/18454858##+
0.120.01 0.110.000.10 118/118 TSort.each_strongly_connected_component_from
0.110.000.1113/14Gem::Specification.load
0.730.65 0.040.690.61 1/5 (top)
60.1060.07 0.0060.1060.07 2/5 Benchmark::IPS::Job#run
96% 0%60.850.0560.8060.750.0660.69 5##times##times
40.0940.07 0.0040.0940.07 1/1 Benchmark::IPS::Job#run_benchmark
20.00 1/1 Benchmark::IPS::Job#run_warmup
0.340.29 0.000.3310000/10362600.2910000/1263578 Protobuf::Message::Serialization::ClassMethods.decode_from
0.210.19 0.010.2110000/10362600.1810000/1263578 Protobuf::Encoder.encode
60.1060.08 0.0060.1060.08 1/1 (top)
94%95% 0%60.1060.08 0.0060.1060.08 1 Benchmark::IPS.ips
60.1060.08 0.0060.1060.08 1/1 Benchmark::IPS::Job#run
60.1060.08 0.0060.1060.08 1/1 Benchmark::IPS.ips
94%95% 0%60.1060.08 0.0060.1060.08 1 Benchmark::IPS::Job#run
60.1060.07 0.0060.1060.07 2/5##times##times
57.052.7754.283593390/3593390##each57.022.9254.103554696/3554696##each
90% 4%57.052.7754.28359339057.022.9254.103554696 Benchmark::IPS::Job::Entry#call_times
52.942.2050.7414928119/1492866752.792.3150.4914899065/14899613 Proc#call
0.710.710.700.70 0.0018521509/20594046##<18453761/18453786##<
0.630.630.610.61 0.0014928119/18522606##+14899065/18454858##+
52.942.2050.7414928119/1492866752.792.3150.4914899065/14899613 Benchmark::IPS::Job::Entry#call_times
83% 3%52.972.2050.771492866752.822.3150.5114899613 Proc#call
22.242.5019.7413901859/1390185922.292.3619.9313645487/13645487 Protobuf::Message#to_hash
13.710.2513.461026260/103626013.180.3012.871253578/1263578 Protobuf::Message::Serialization::ClassMethods.decode_from
8.670.278.401026260/10362608.720.308.421253578/1263578 Protobuf::Encoder.encode
3.940.143.801026260/20740443.740.173.571253578/2528680 Class#new
1.770.251.531026260/10362602.110.291.821253578/1263578 Test::Resource#status=
0.250.140.111026260/10362600.270.170.101253578/1263578 StringIO.new
0.100.100.110.11 0.001026260/10362601253578/1263578 Protobuf::Message#to_proto
40.0940.07 0.0040.0940.07 1/1##times##times
63% 0%40.0940.07 0.0040.0940.07 1 Benchmark::IPS::Job#run_benchmark
40.0940.07 0.0140.091/1037819##each40.071/1265137##each
8.011.406.611036260/149381207.921.576.361263578/14909066 Protobuf::Message#each_field_for_serialization
19.745.9413.8013901859/1493812019.935.8514.0913645487/14909066 Protobuf::Message#to_hash
43%44% 11%27.757.3420.4114938120##each_key27.867.4120.4514909066##each_key
5.452.363.0913901859/139018595.602.353.2513645487/13645487 Protobuf::Field::StringField(singleton)#to_message_hash
5.262.263.0013901859/139018595.412.243.1713645487/13645487 Protobuf::Field::Int64Field(singleton)#to_message_hash
1.941.940.0030912498/71156329##[]
1.900.611.291036260/10362602.300.731.571263578/1263578 Protobuf::Field::StringField(singleton)#encode_to_stream
1.890.271.621036260/1036260Protobuf::Field::EnumField(singleton)#encode_to_stream2.022.020.0031081708/72277033##[]
1.551.551.541.54 0.0030912498/3713006031081708/38663178 Test::Resource#_protobuf_message_field
1.500.271.231036260/10362601.370.291.081263578/1263578Protobuf::Field::EnumField(singleton)#encode_to_stream
1.090.300.791263578/1263578 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.340.100.251036260/159743790.400.120.281263578/16172643 Protobuf::Field::StringField(singleton)#value_from_values
0.300.080.221036260/15974379Protobuf::Field::Int64Field(singleton)#value_from_values0.360.100.261263578/2527156Protobuf::Field::EnumField(singleton)#value_from_values
0.280.090.191036260/2072520Protobuf::Field::EnumField(singleton)#value_from_values0.360.100.251263578/16172643Protobuf::Field::Int64Field(singleton)#value_from_values
22.242.5019.7413901859/1390185922.292.3619.9313645487/13645487 Proc#call
35% 3%22.242.5019.741390185922.292.3619.9313645487 Protobuf::Message#to_hash
19.745.9413.8013901859/14938120##each_key19.935.8514.0913645487/14909066##each_key
0.00 20.00 1/1##times##times
31% 1 Benchmark::IPS::Job#run_warmup
20.001.8318.171/1037819##each1.8018.201/1265137##each
0.340.29 0.000.3310000/1036260##times0.2910000/1263578##times
13.710.2513.461026260/103626013.180.3012.871253578/1263578 Proc#call
22%21% 0%14.050.2613.79103626013.470.3113.161263578 Protobuf::Message::Serialization::ClassMethods.decode_from
13.160.2412.921036260/103626012.380.2912.091263578/1263578 Protobuf::Message::Serialization.decode_from
0.630.130.501036260/20740440.780.170.611263578/2528680 Class#new
13.160.2412.921036260/103626012.380.2912.091263578/1263578 Protobuf::Message::Serialization::ClassMethods.decode_from
20%19% 0%13.160.2412.92103626012.380.2912.091263578 Protobuf::Message::Serialization.decode_from
12.921.7511.171036260/103626012.092.129.981263578/1263578 Protobuf::Decoder.decode_each_field
12.921.7511.171036260/103626012.092.129.981263578/1263578 Protobuf::Message::Serialization.decode_from
20%2%12.921.7511.17103626019%3%12.092.129.981263578 Protobuf::Decoder.decode_each_field
9.221.008.223108780/31087807.631.226.413790734/3790734 Protobuf::Message::Serialization.set_field_bytes
1.170.710.466217560/62175601.390.840.547581468/7581468 Protobuf::Varint.decode
0.210.210.280.28 0.004145040/41450405054312/5054312 StringIO#eof
0.170.170.210.21 0.004145040/4148208##==5054312/5057540##==
0.150.150.170.17 0.003108780/3108780##>>3790734/3790734##>>
0.130.130.170.17 0.003108780/7253820##&3790734/3790734##&
0.120.120.140.14 0.001036260/10362601263578/1263578 StringIO#read
9.221.008.223108780/3108780Protobuf::Decoder.decode_each_field
14%1%9.221.008.223108780Protobuf::Message::Serialization.set_field_bytes
3.430.263.181036260/1036260Protobuf::Field::EnumField(singleton)#set
2.260.252.011036260/1036260Protobuf::Field::Int64Field(singleton)#set
2.020.221.801036260/1036260Protobuf::Field::StringField(singleton)#set
0.270.270.003108780/71156329##[]
0.240.240.003108780/37130060Test::Resource#_protobuf_message_field
0.210.19 0.010.2110000/1036260##times0.1810000/1263578##times
8.670.278.401026260/10362608.720.308.421253578/1263578 Proc#call
14% 0%8.890.288.6010362608.910.318.591263578 Protobuf::Encoder.encode
8.600.398.211036260/10362608.590.448.161263578/1263578 Protobuf::Message#each_field_for_serialization
1.280.68 0.171.121036260/6217562Protobuf::Field::EnumField(singleton)#set0.511263578/7581470Protobuf::Field::Int64Field(singleton)#set
1.410.201.211036260/62175621.640.191.461263578/7581470 Protobuf::Field::StringField(singleton)#set
1.410.171.241036260/6217562Protobuf::Field::Int64Field(singleton)#set1.670.161.511263578/7581470Protobuf::Field::EnumField(singleton)#set
1.550.281.281036260/62175621.850.321.531263578/7581470 Test::Resource#status=
3.110.522.582072522/6217562##each2.800.632.182527158/7581470##each
13% 2%8.751.337.4262175628.651.467.197581470 Protobuf::Message#set_field
2.370.491.882072521/2072521Protobuf::Field::Int64Field(singleton)#set_field2.890.582.312527156/2527156Protobuf::Field::EnumField(singleton)#set_field
2.350.761.592072521/20725212.800.891.912527157/2527157 Protobuf::Field::StringField(singleton)#set_field
2.270.471.802072520/2072520Protobuf::Field::EnumField(singleton)#set_field0.960.580.382527157/2527157Protobuf::Field::Int64Field(singleton)#set_field
0.230.230.290.29 0.003108782/71156329##[]3790736/72277033##[]
0.210.210.250.25 0.003108782/371300603790736/38663178 Test::Resource#_protobuf_message_field
8.600.398.211036260/10362608.590.448.161263578/1263578 Protobuf::Encoder.encode
13% 0%8.600.398.2110362608.590.448.161263578 Protobuf::Message#each_field_for_serialization
8.011.406.611036260/14938120##each_key7.921.576.361263578/14909066##each_key
0.150.150.170.17 0.001036260/31087811263578/3790735 Test::Resource#_protobuf_message_required_field_tags
5.452.363.0913901859/13901859##each_key7.631.226.413790734/3790734Protobuf::Decoder.decode_each_field
8%3%5.452.363.0913901859Protobuf::Field::StringField(singleton)#to_message_hash12%1%7.631.226.413790734Protobuf::Message::Serialization.set_field_bytes
2.261.590.6813901859/15974379Protobuf::Field::StringField(singleton)#value_from_values2.390.252.131263578/1263578Protobuf::Field::StringField(singleton)#set
0.830.830.0013901859/34025837##[]=2.180.261.921263578/1263578Protobuf::Field::EnumField(singleton)#set
0.160.010.15153/2074044Protobuf::Field.build1.200.250.951263578/1263578Protobuf::Field::Int64Field(singleton)#set
0.300.010.301/2074044Bundler::Dsl#to_definition0.350.350.003790734/72277033##[]
0.630.130.501036260/2074044Protobuf::Message::Serialization::ClassMethods.decode_from0.290.290.003790734/38663178Test::Resource#_protobuf_message_field
3.940.143.801026260/2074044Proc#call5.602.353.2513645487/13645487##each_key
8%0%5.390.385.012074044Class#new3%5.602.353.2513645487Protobuf::Field::StringField(singleton)#to_message_hash
4.390.713.672072521/2072521Protobuf::Message#initialize2.381.590.7913645487/16172643Protobuf::Field::StringField(singleton)#value_from_values
0.300.870.87 0.000.291/1Bundler::Definition#initialize
0.150.010.14153/153Protobuf::Field::BaseField#initialize13645487/34877001##[]=
5.262.263.0013901859/13901859##each_key5.412.243.1713645487/13645487##each_key
8% 3%5.262.263.00139018595.412.243.1713645487 Protobuf::Field::Int64Field(singleton)#to_message_hash
2.202.33 1.550.6413901859/159743790.7813645487/16172643 Protobuf::Field::Int64Field(singleton)#value_from_values
0.800.800.840.84 0.0013901859/34025837##[]=13645487/34877001##[]=
4.390.713.672072521/2072521Class#new0.110.030.0816/2528680Kernel.eval
0.170.010.17153/2528680Protobuf::Field.build
0.290.010.281/2528680Bundler::Dsl#to_definition
0.780.170.611263578/2528680Protobuf::Message::Serialization::ClassMethods.decode_from
3.740.173.571253578/2528680Proc#call
6%1%4.390.713.672072521Protobuf::Message#initialize8%0%5.330.464.872528680Class#new
3.490.383.112072521/2072735##each4.250.813.432527157/2527157Protobuf::Message#initialize
0.280.000.281/1Bundler::Definition#initialize
0.170.010.16153/153Protobuf::Field::BaseField#initialize
0.180.180.150.15 0.003108780/711563292527156/72277033 Protobuf::Enum.enum_for_tag_integer
0.230.230.290.29 0.003108782/711563293790736/72277033 Protobuf::Message#set_field
0.270.270.350.35 0.003108780/711563293790734/72277033 Protobuf::Message::Serialization.set_field_bytes
0.710.710.850.85 0.0014938119/7115632914909065/72277033 Protobuf::Field::Int64Field(singleton)#value_from_values
0.750.750.890.89 0.0014938119/7115632914909065/72277033 Protobuf::Field::StringField(singleton)#value_from_values
1.941.942.022.02 0.0030912498/71156329##each_key31081708/72277033##each_key
6%6%4.164.137%7%4.664.63 0.0371156329##[]72277033##[]
3.490.383.112072521/2072735Protobuf::Message#initialize4.250.813.432527157/2527157Class#new
5%0%3.510.403.112072735##each6%1%4.250.813.432527157Protobuf::Message#initialize
3.110.522.582072522/6217562Protobuf::Message#set_field3.220.422.802527157/2527371##each
3.430.263.181036260/1036260Protobuf::Message::Serialization.set_field_bytes
5%0%3.430.263.181036260Protobuf::Field::EnumField(singleton)#set0.110.110.002527157/2527158##to_hash
1.890.251.651036260/1036260Protobuf::Field::EnumField#decode0.100.100.002527157/2527330Kernel.block_given?
1.280.171.121036260/6217562Protobuf::Message#set_field3.220.422.802527157/2527371Protobuf::Message#initialize
5%0%3.240.432.812527371##each
0.340.100.251036260/15974379##each_key2.800.632.182527158/7581470Protobuf::Message#set_field
2.261.590.6813901859/15974379Protobuf::Field::StringField(singleton)#to_message_hash2.890.582.312527156/2527156Protobuf::Message#set_field
4%2%2.601.680.9215974379Protobuf::Field::StringField(singleton)#value_from_values0%2.890.582.312527156Protobuf::Field::EnumField(singleton)#set_field
0.750.750.0014938119/71156329##[]2.040.471.572527156/2527156Protobuf::Field::EnumField#coerce!
0.300.080.221036260/15974379##each_key0.180.180.002527156/34877001##[]=
2.201.550.6413901859/15974379Protobuf::Field::Int64Field(singleton)#to_message_hash
3%2%2.501.640.8615974379Protobuf::Field::Int64Field(singleton)#value_from_values
0.710.710.0014938119/71156329##[]
2.370.491.882072521/2072521Protobuf::Message#set_field
3%0%2.370.491.882072521Protobuf::Field::Int64Field(singleton)#set_field
1.660.601.062072521/2072521Protobuf::Field::IntegerField#coerce!
0.140.140.002072521/34025837##[]=
2.350.761.592072521/20725212.800.891.912527157/2527157 Protobuf::Message#set_field
3%4% 1%2.350.761.5920725212.800.891.912527157 Protobuf::Field::StringField(singleton)#set_field
0.600.470.132072521/3108781Test::Resource#_protobuf_message_required_field_tags0.690.480.212527157/2527157Protobuf::Field::StringField#coerce!
0.570.410.162072521/2072521Protobuf::Field::StringField#coerce!0.680.530.152527157/3790735Test::Resource#_protobuf_message_required_field_tags
0.180.180.230.23 0.002072521/34025837##[]=2527157/34877001##[]=
0.160.160.210.21 0.002072521/2072705##delete2527157/2527341##delete
0.380.030.362/1886Kernel.load0.100.100.002527157/10109592Kernel.nil?
0.920.000.926/1886(top)0.400.120.281263578/16172643##each_key
1.030.001.03115/1886Kernel.require2.381.590.7913645487/16172643Protobuf::Field::StringField(singleton)#to_message_hash
3%0%2.340.032.311886Kernel.require4%2%2.781.711.0716172643Protobuf::Field::StringField(singleton)#value_from_values
0.890.00 0.891/1Bundler.setup
0.23 0.000.2319/1037819##each
0.120.000.12109/109Protobuf::Message::Fields::ClassMethods.optional14909065/72277033##[]
0.110.000.111/1Gem::Specification.load_defaults0.360.100.251263578/16172643##each_key
2.270.471.802072520/2072520Protobuf::Message#set_field2.331.550.7813645487/16172643Protobuf::Field::Int64Field(singleton)#to_message_hash
3%0%2.270.471.802072520Protobuf::Field::EnumField(singleton)#set_field
1.560.391.172072520/2072520Protobuf::Field::EnumField#coerce!4%2%2.691.651.0316172643Protobuf::Field::Int64Field(singleton)#value_from_values
0.170.170.850.85 0.002072520/34025837##[]=14909065/72277033##[]
2.262.39 0.252.011036260/10362602.131263578/1263578 Protobuf::Message::Serialization.set_field_bytes
3% 0%2.262.39 0.252.011036260Protobuf::Field::Int64Field(singleton)#set2.131263578Protobuf::Field::StringField(singleton)#set
1.410.171.241036260/62175621.640.191.461263578/7581470 Protobuf::Message#set_field
0.600.420.181036260/2072520Protobuf::Field::IntegerField#decode0.490.280.221263578/1263578Protobuf::Field::StringField#decode
0.140.140.160.16 0.002072521/340258372527157/34877001 Protobuf::Field::Int64Field(singleton)#set_field
0.170.170.180.18 0.002072520/340258372527156/34877001 Protobuf::Field::EnumField(singleton)#set_field
0.180.180.230.23 0.002072521/340258372527157/34877001 Protobuf::Field::StringField(singleton)#set_field
0.800.800.840.84 0.0013901859/3402583713645487/34877001 Protobuf::Field::Int64Field(singleton)#to_message_hash
0.830.830.870.87 0.0013901859/3402583713645487/34877001 Protobuf::Field::StringField(singleton)#to_message_hash
3% 3%2.122.110.0134025837##[]=2.382.290.0834877001##[]=
2.020.221.801036260/1036260Protobuf::Message::Serialization.set_field_bytes
3%0%2.020.221.801036260Protobuf::Field::StringField(singleton)#set
1.410.201.211036260/6217562Protobuf::Message#set_field
0.430.03 0.400.240.161036260/1036260Protobuf::Field::StringField#decode2/1886Kernel.load
0.210.210.93 0.003108782/37130060Protobuf::Message#set_field
0.240.240.003108780/37130060Protobuf::Message::Serialization.set_field_bytes0.936/1886(top)
1.551.551.00 0.0030912498/37130060##each_key1.00115/1886Kernel.require
3%3%2.002.000.0037130060Test::Resource#_protobuf_message_field
1.900.611.291036260/1036260##each_key
2% 0%1.900.611.291036260Protobuf::Field::StringField(singleton)#encode_to_stream2.360.032.331886Kernel.require
0.630.310.323108780/7253820IO::GenericWritable.<<0.860.000.861/1Bundler.setup
0.250.160.091036260/3108933Protobuf::Field::VarintField.encode0.240.000.2319/1265137##each
0.19 0.140.061036260/1037071BasicObject#!=
1.890.251.651036260/1036260Protobuf::Field::EnumField(singleton)#set
2%0%1.890.251.651036260Protobuf::Field::EnumField#decode
1.120.330.791036260/1036260Protobuf::Field::EnumField#acceptable?0.000.141/1Gem::Specification.load_defaults
0.530.380.151036260/2072520Protobuf::Field::IntegerField#decode0.140.000.13109/109Protobuf::Message::Fields::ClassMethods.optional
1.890.271.621036260/1036260##each_key2.300.731.571263578/1263578##each_key
2%0%1.890.271.621036260Protobuf::Field::EnumField(singleton)#encode_to_stream
1.250.241.001036260/1036260Protobuf::Field::EnumField#encode3%1%2.300.731.571263578Protobuf::Field::StringField(singleton)#encode_to_stream
0.380.190.182072520/72538200.750.360.403790734/8845046 IO::GenericWritable.<<
1.770.251.531026260/1036260Proc#call
2%0%1.810.261.551036260Test::Resource#status=
1.550.281.281036260/6217562Protobuf::Message#set_field
1.660.601.062072521/2072521Protobuf::Field::Int64Field(singleton)#set_field
2%0%1.660.601.062072521Protobuf::Field::IntegerField#coerce!0.320.220.111263578/1263731Protobuf::Field::VarintField.encode
0.870.580.282072521/2072521Protobuf::Field::IntegerField#acceptable?0.220.160.061263578/1264389BasicObject#!=
0.110.110.140.14 0.002072521/7255321Kernel.kind_of?1263578/2527298##+
0.590.200.381036260/3108789Protobuf::Field::EnumField#acceptable?
1.020.350.672072520/3108789Protobuf::Field::EnumField#coerce!2.180.261.921263578/1263578Protobuf::Message::Serialization.set_field_bytes
2%3% 0%1.610.561.053108789Protobuf::Enum.fetch2.180.261.921263578Protobuf::Field::EnumField(singleton)#set
0.910.570.343108780/3108780Protobuf::Enum.enum_for_tag_integer1.670.161.511263578/7581470Protobuf::Message#set_field
0.140.140.003108789/7255321Kernel.kind_of?0.250.200.051263578/1263578Protobuf::Field::EnumField#decode
1.560.391.172072520/2072520Protobuf::Field::EnumField(singleton)#set_field2.110.291.821253578/1263578Proc#call
2%3% 0%1.560.391.172072520Protobuf::Field::EnumField#coerce!2.150.301.851263578Test::Resource#status=
1.020.350.672072520/3108789Protobuf::Enum.fetch1.850.321.531263578/7581470Protobuf::Message#set_field
0.150.150.250.25 0.002072520/3109338Protobuf::Field::BaseField#type_class3790736/38663178Protobuf::Message#set_field
0.720.400.321036260/2072520Protobuf::Field::EnumField#encode0.290.290.003790734/38663178Protobuf::Message::Serialization.set_field_bytes
0.820.430.391036260/2072520Protobuf::Field::Int64Field(singleton)#encode_to_stream
2%1% 1.540.830.712072520Protobuf::Field::IntegerField#encode
0.460.260.202072520/3108933Protobuf::Field::VarintField.encode1.540.0031081708/38663178##each_key
0.250.25
3%3%2.072.07 0.002072520/7253820##&38663178Test::Resource#_protobuf_message_field
1.500.271.231036260/1036260##each_key2.040.471.572527156/2527156Protobuf::Field::EnumField(singleton)#set_field
2%3% 0%1.500.271.231036260Protobuf::Field::Int64Field(singleton)#encode_to_stream2.040.471.572527156Protobuf::Field::EnumField#coerce!
0.820.430.391036260/2072520Protobuf::Field::IntegerField#encode1.350.450.902527156/2527165Protobuf::Enum.fetch
0.410.19 0.222072520/7253820IO::GenericWritable.<<0.220.002527156/2527714Protobuf::Field::BaseField#type_class
0.380.190.182072520/72538200.430.230.202527156/8845046 Protobuf::Field::EnumField(singleton)#encode_to_stream
0.410.190.46 0.222072520/72538200.242527156/8845046 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.630.310.323108780/72538200.750.360.403790734/8845046 Protobuf::Field::StringField(singleton)#encode_to_stream
2% 1%1.410.690.7372538201.650.810.838845046 IO::GenericWritable.<<
0.730.730.830.83 0.007253820/72538208845046/8845046 StringIO#write
1.250.241.001036260/1036260Protobuf::Field::EnumField(singleton)#encode_to_stream1.390.840.547581468/7581468Protobuf::Decoder.decode_each_field
2% 1%1.390.840.547581468Protobuf::Varint.decode
0.540.540.007581468/7581468ProtobufJavaHelpers::Varinter.read_varint
1.370.291.081263578/1263578##each_key
2% 0%1.250.241.001036260Protobuf::Field::EnumField#encode1.370.291.081263578Protobuf::Field::EnumField(singleton)#encode_to_stream
0.720.400.321036260/2072520Protobuf::Field::IntegerField#encode0.650.270.381263578/1263578Protobuf::Field::EnumField#encode
0.280.170.111036260/1036528Protobuf::Enum#to_i0.430.230.202527156/8845046IO::GenericWritable.<<
1.170.710.466217560/6217560Protobuf::Decoder.decode_each_field1.350.450.902527156/2527165Protobuf::Field::EnumField#coerce!
1%1%1.170.710.466217560Protobuf::Varint.decode2%0%1.350.450.902527165Protobuf::Enum.fetch
0.460.460.006217560/6217560ProtobufJavaHelpers::Varinter.read_varint0.770.490.282527156/2527156Protobuf::Enum.enum_for_tag_integer
0.530.380.151036260/2072520Protobuf::Field::EnumField#decode0.130.130.002527165/2528655Kernel.kind_of?
0.600.420.181036260/2072520Protobuf::Field::Int64Field(singleton)#set1.200.250.951263578/1263578Protobuf::Message::Serialization.set_field_bytes
1%1%1.130.800.332072520Protobuf::Field::IntegerField#decode0%1.200.250.951263578Protobuf::Field::Int64Field(singleton)#set
0.220.220.002072520/7253820##&0.680.170.511263578/7581470Protobuf::Message#set_field
0.110.110.002072520/2072845Numeric#nonzero?0.270.200.071263578/1263578Protobuf::Field::Int64Field#decode
1.120.331.090.30 0.791036260/1036260Protobuf::Field::EnumField#decode1263578/1263578##each_key
1% 0%1.120.331.090.30 0.791036260Protobuf::Field::EnumField#acceptable?1263578Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.590.200.381036260/3108789Protobuf::Enum.fetch0.460.220.242527156/8845046IO::GenericWritable.<<
0.110.110.001036260/3109338Protobuf::Field::BaseField#type_class0.330.210.121263578/1263578Protobuf::Field::Int64Field#encode
1.041.01 0.001.031.00 2/115 (top)
1% 0%1.041.01 0.001.031.00 115 Kernel.require
1.031.00 0.001.031.00 115/1886 Kernel.require
0.910.570.343108780/3108780Protobuf::Enum.fetch0.960.580.382527157/2527157Protobuf::Message#set_field
1% 0%0.910.570.343108780Protobuf::Enum.enum_for_tag_integer0.960.580.382527157Protobuf::Field::Int64Field(singleton)#set_field
0.180.180.160.16 0.003108780/71156329##[]2527157/34877001##[]=
0.170.170.120.120.002527157/2527157ProtobufJavaHelpers::Int64ProtobufField.coerce!
0.910.450.463555260/3555260##each
1%0%0.910.450.463555260Benchmark::Timing.now
0.460.46 0.003108780/3109269##first3555260/3555261Process.clock_gettime
0.890.86 0.000.890.86 1/1 Kernel.require
1% 0%0.890.86 0.000.890.86 1 Bundler.setup
0.510.49 0.010.500.48 1/2 Bundler.definition
0.370.36 0.000.370.36 1/1 Bundler::Runtime#setup
0.870.440.433593944/3593944##each
1%0%0.870.440.433593944Benchmark::Timing.now
0.430.430.170.17 0.003593944/3593945Process.clock_gettime1263578/3790735Protobuf::Message#each_field_for_serialization
0.870.580.282072521/2072521Protobuf::Field::IntegerField#coerce!0.680.530.152527157/3790735Protobuf::Field::StringField(singleton)#set_field
1%0%0.870.580.282072521Protobuf::Field::IntegerField#acceptable?1%0.850.700.153790735Test::Resource#_protobuf_message_required_field_tags
0.110.110.150.15 0.002072521/7255321Kernel.kind_of?2527157/2528189Kernel.dup
0.710.710.830.83 0.0018521509/20594046Benchmark::IPS::Job::Entry#call_times8845046/8845046IO::GenericWritable.<<
1% 1%0.790.790.830.83 0.0020594046##<8845046StringIO#write
0.140.140.003593404/18522606##each0.770.490.282527156/2527156Protobuf::Enum.fetch
1%0%0.770.490.282527156Protobuf::Enum.enum_for_tag_integer
0.630.630.150.15 0.0014928119/18522606Benchmark::IPS::Job::Entry#call_times2527156/72277033##[]
1%1%0.780.78
0.130.13 0.0018522606##+2527156/2527645##first
0.15 0.15 0.001036260/3108781Protobuf::Message#each_field_for_serialization3554710/18454858##each
0.600.470.132072521/3108781Protobuf::Field::StringField(singleton)#set_field0.610.610.0014899065/18454858Benchmark::IPS::Job::Entry#call_times
1%0%0.750.620.133108781Test::Resource#_protobuf_message_required_field_tags
0.130.131%0.760.76 0.002072521/2073553Kernel.dup18454858##+
0.730.730.700.70 0.007253820/7253820IO::GenericWritable.<<18453761/18453786Benchmark::IPS::Job::Entry#call_times
1% 1%0.730.730.700.70 0.007253820StringIO#write18453786##<
0.250.160.091036260/3108933Protobuf::Field::StringField(singleton)#encode_to_stream
0.460.260.202072520/3108933Protobuf::Field::IntegerField#encode0.690.480.212527157/2527157Protobuf::Field::StringField(singleton)#set_field
1% 0%0.710.420.293108933Protobuf::Field::VarintField.encode0.690.480.212527157Protobuf::Field::StringField#coerce!
0.290.290.120.12 0.003108933/3108933ProtobufJavaHelpers::Varinter.to_varint2527157/2528322##to_s
0.130.130.003108780/7253820Protobuf::Decoder.decode_each_field0.650.270.381263578/1263578Protobuf::Field::EnumField(singleton)#encode_to_stream
1%0%0.650.270.381263578Protobuf::Field::EnumField#encode
0.220.220.002072520/7253820Protobuf::Field::IntegerField#decode0.280.170.111263578/1263846Protobuf::Enum#to_i
0.250.250.540.54 0.002072520/7253820Protobuf::Field::IntegerField#encode7581468/7581468Protobuf::Varint.decode
0% 0%0.610.610.540.54 0.007253820##&7581468ProtobufJavaHelpers::Varinter.read_varint
0.570.410.162072521/2072521Protobuf::Field::StringField(singleton)#set_field0.530.060.4717/19(top)
0% 0%0.570.410.162072521Protobuf::Field::StringField#coerce!0.530.060.4719Kernel.load
0.430.030.402/1886Kernel.require
0.510.49 0.010.500.48 1/2 Bundler.setup
0% 0%0.510.49 0.010.500.48 2 Bundler.definition
0.410.40 0.000.410.39 1/1 Bundler::Definition.build
0.480.060.4217/19(top)0.490.280.221263578/1263578Protobuf::Field::StringField(singleton)#set
0% 0%0.480.060.4219Kernel.load0.490.280.221263578Protobuf::Field::StringField#decode
0.380.030.362/1886Kernel.require0.140.140.001263578/2527298##+
0.46 0.46 0.006217560/6217560Protobuf::Varint.decode
0%0%0.460.460.006217560ProtobufJavaHelpers::Varinter.read_varint
0.430.430.003593944/35939453555260/3555261 Benchmark::Timing.now
0%0%0.430.430%0.460.46 0.0035939453555261 Process.clock_gettime
0% 0%0.420.41 0.000.420.41 873 Kernel.send
0.33 1/1 Bundler::Definition#requested_specs
0.410.40 0.000.410.39 1/1 Bundler.definition
0% 0%0.410.40 0.000.410.39 1 Bundler::Definition.build
0.400.38 0.000.400.38 1/1 Bundler::Dsl.evaluate
0.400.38 0.000.400.38 1/1 Bundler::Definition.build
0% 0%0.400.38 0.000.400.38 1 Bundler::Dsl.evaluate
0.300.29 0.000.300.29 1/1 Bundler::Dsl#to_definition
0.400.240.161036260/1036260Protobuf::Field::StringField(singleton)#set0.100.100.002527157/10109592Protobuf::Field::StringField(singleton)#set_field
0% 0%0.400.240.161036260Protobuf::Field::StringField#decode0.380.380.0010109592Kernel.nil?
0.360.100.261263578/2527156##each_key
0%0%0.360.100.262527156Protobuf::Field::EnumField(singleton)#value_from_values
0.370.36 0.000.370.36 1/1 Bundler.setup
0% 0%0.370.36 0.000.370.36 1 Bundler::Runtime#setup
0.33 1/1 Bundler::Runtime#requested_specs
0.110.110.002072521/7255321Protobuf::Field::IntegerField#acceptable?
0.110.110.002072521/7255321Protobuf::Field::IntegerField#coerce!
0.140.140.003108789/7255321Protobuf::Enum.fetch
0%0%0.360.360.007255321Kernel.kind_of?
0%0%0.350.350.009327308Kernel.nil?
1 Bundler::Runtime#requested_specs
0.33 1 Bundler::Definition#requested_specs
0.33 1/1 Bundler::Definition#specs_for
1 Bundler::Definition#specs_for
0.32 1/1 Bundler::Definition#specs
0.330.210.121263578/1263578Protobuf::Field::Int64Field(singleton)#encode_to_stream
0%0%0.330.210.121263578Protobuf::Field::Int64Field#encode
0.120.120.001263578/2527156ProtobufJavaHelpers::Varinter.to_varint_64
0.320.220.111263578/1263731Protobuf::Field::StringField(singleton)#encode_to_stream
0%0%0.330.220.111263731Protobuf::Field::VarintField.encode
0.110.110.001263731/1263731ProtobufJavaHelpers::Varinter.to_varint
1 Bundler::Definition#specs
0.21 1/1 Bundler::SpecSet#materialize
0.100.000.101/1Bundler::Definition#resolve
0.300.29 0.000.300.29 1/1 Bundler::Dsl.evaluate
0% 0%0.300.29 0.000.300.29 1 Bundler::Dsl#to_definition
0.300.29 0.010.301/20740440.281/2528680 Class#new
0.300.140.140.001263578/2527298Protobuf::Field::StringField#decode
0.140.14 0.001263578/2527298Protobuf::Field::StringField(singleton)#encode_to_stream
0%0% 0.290.290.002527298##+
0.280.000.28 1/1 Class#new
0% 0%0.300.28 0.000.290.28 1 Bundler::Definition#initialize
0.100.11 0.000.100.11 1/1 Bundler::Definition#converge_paths
0.290.290.003108933/3108933Protobuf::Field::VarintField.encode0.270.170.101253578/1263578Proc#call
0% 0%0.290.290.280.180.101263578StringIO.new
0.100.10 0.003108933ProtobufJavaHelpers::Varinter.to_varint1263578/1263578StringIO#initialize
0.28 0.17 0.111036260/10365281263578/1263846 Protobuf::Field::EnumField#encode
0.28 0.17 0.1110365281263846 Protobuf::Enum#to_i
0.11 0.11 0.001036528/10365281263846/1263846 Protobuf::Enum#tag
0.280.090.191036260/2072520##each_key0.280.005054312/5054312Protobuf::Decoder.decode_each_field
0%0%0.280.280.005054312StringIO#eof
0.270.200.071263578/1263578Protobuf::Field::Int64Field(singleton)#set
0%0%0.270.200.071263578Protobuf::Field::Int64Field#decode
0.250.200.051263578/1263578Protobuf::Field::EnumField(singleton)#set
0% 0%0.280.090.192072520Protobuf::Field::EnumField(singleton)#value_from_values0.250.200.051263578Protobuf::Field::EnumField#decode
0.110.110.001036260/3109338Protobuf::Field::EnumField#acceptable?0.220.160.061263578/1264389Protobuf::Field::StringField(singleton)#encode_to_stream
0%0%0.230.160.071264389BasicObject#!=
0.150.150.220.22 0.002072520/31093382527156/2527714 Protobuf::Field::EnumField#coerce!
0% 0%0.260.260.220.22 0.0031093382527714 Protobuf::Field::BaseField#type_class
0.250.140.111026260/1036260Proc#call0.120.120.001263578/2527156Protobuf::Field::Int64Field#encode
0% 0%0.260.140.121036260StringIO.new0.220.220.002527156ProtobufJavaHelpers::Varinter.to_varint_64
0.120.120.210.21 0.001036260/1036260StringIO#initialize2527157/2527341Protobuf::Field::StringField(singleton)#set_field
0%0%0.210.210.002527341##delete
0.21 0.21 0.004145040/41450405054312/5057540 Protobuf::Decoder.decode_each_field
0.21 0.21 0.004145040StringIO#eof5057540##==
1 Bundler::SpecSet#materialize
0.110.000.111/412##map!
0.190.140.061036260/1037071Protobuf::Field::StringField(singleton)#encode_to_stream0.130.000.13109/153Protobuf::Message::Fields::ClassMethods.optional
0% 0%0.200.140.061037071BasicObject#!=0.190.000.18153Protobuf::Message::Fields::ClassMethods.define_field
0%0%0.200.20
0.18 0.002072662##+0.18153/153Protobuf::Field.build
0.180.18 0.003593394/3593394##each0.18153/153Protobuf::Message::Fields::ClassMethods.define_field
0% 0% 0.180.18 0.003593394##<0.18153Protobuf::Field.build
0.170.010.17153/2528680Class#new
0.120.180.18 0.000.12109/153Protobuf::Message::Fields::ClassMethods.optional3554700/3554700##each
0% 0%0.170.000.17153Protobuf::Message::Fields::ClassMethods.define_field
0.160.180.18 0.000.16153/153Protobuf::Field.build3554700##<
0.17 0.17 0.004145040/41482083790734/3790734 Protobuf::Decoder.decode_each_field
0.17 0.17 0.004148208##==3790734##>>
0.17 0.17 0.003108780/3109269Protobuf::Enum.enum_for_tag_integer3790734/3790734Protobuf::Decoder.decode_each_field
0% 0.17 0.17 0.003109269##first3790734##&
0.160.000.170.01 0.16 153/153Protobuf::Message::Fields::ClassMethods.define_fieldClass#new
0% 0%0.160.000.170.01 0.16 153Protobuf::Field.build
0.160.010.15153/2074044Class#newProtobuf::Field::BaseField#initialize
0.160.160.150.15 0.002072521/2072705Protobuf::Field::StringField(singleton)#set_field2527157/2528189Test::Resource#_protobuf_message_required_field_tags
0% 0%0.160.160.150.15 0.002072705##delete2528189Kernel.dup
0%0%0.150.070.081137BasicObject#instance_eval
0%0%0.140.030.1261Kernel.eval
0.110.030.0816/2528680Class#new
0.150.01 0.14153/153Class#new0.000.141/1Kernel.require
0% 0%0.150.01 0.14153Protobuf::Field::BaseField#initialize0.000.141Gem::Specification.load_defaults
0.140.000.141/1Gem::Specification.each_spec
0.110.14 0.000.111/412Bundler::SpecSet#materialize0.141/1Gem::Specification.load_defaults
0% 0%0.150.020.13412##map!0.140.000.141Gem::Specification.each_spec
0.110.14 0.000.1139/39Bundler::LazySpecification#__materialize__0.141/1Gem::Specification.each_gemspec
0.150.150.14 0.003108780/3108780Protobuf::Decoder.decode_each_field0.141/1Gem::Specification.each_spec
0% 0%0.150.150.14 0.003108780##>>0.141Gem::Specification.each_gemspec
0%0%
0.140.060.081137BasicObject#instance_eval0.000.141/1265137##each
0.130.130.140.14 0.002072521/2073553Test::Resource#_protobuf_message_required_field_tags1263578/1263578Protobuf::Decoder.decode_each_field
0% 0%0.130.130.140.14 0.002073553Kernel.dup
0%0%0.130.030.1061Kernel.eval1263578StringIO#read
0.120.14 0.000.120.13 109/109 Kernel.require
0% 0%0.120.14 0.000.120.13 109 Protobuf::Message::Fields::ClassMethods.optional
0.120.13 0.000.120.13 109/153 Protobuf::Message::Fields::ClassMethods.define_field
0.120.120.130.13 0.001036260/1036260Protobuf::Decoder.decode_each_field2527165/2528655Protobuf::Enum.fetch
0% 0%0.120.120.130.13 0.001036260StringIO#read2528655Kernel.kind_of?
0.120.120.130.13 0.001036260/1036260StringIO.new2527156/2527645Protobuf::Enum.enum_for_tag_integer
0% 0%0.120.120.130.13 0.001036260StringIO#initialize2527645##first
0.110.000.111/1Kernel.require
0% 0%0.110.13 0.000.111Gem::Specification.load_defaults0.1313Bundler::SpecSet#sorted
0.110.13 0.000.134/4TSort.tsort
0%0%0.130.02 0.111/1Gem::Specification.each_spec412##map!
0.110.13 0.000.111/1Gem::Specification.load_defaults0.134/176##to_a
0% 0%0.110.13 0.000.111Gem::Specification.each_spec0.13176Enumerator#each
0.110.13 0.000.111/1Gem::Specification.each_gemspec0.134/8TSort.tsort_each
0.110.13 0.000.111/1Gem::Specification.each_spec0.134/4Bundler::SpecSet#sorted
0% 0%0.110.13 0.000.111Gem::Specification.each_gemspec0.134TSort.tsort
0.110.13 0.000.111/1037819##each0.134/4TSort.tsort
0.110.110.13 0.002072520/2072845Protobuf::Field::IntegerField#decode0.134/4TSort.tsort
0% 0%0.110.110.130.000.134TSort.tsort
0.13 0.002072845Numeric#nonzero?0.134/4##to_a
0.130.000.134/8Enumerator#each
0% 0%0.110.13 0.000.1113Bundler::SpecSet#sorted0.138TSort.tsort_each
0.110.13 0.000.110.13 4/4TSort.tsortTSort.each_strongly_connected_component
0.100.13 0.000.101/172Bundler::Definition#converge_paths0.134/4TSort.tsort
0% 0%0.110.13 0.000.11172##any?0.134##to_a
0.100.13 0.000.102/2Bundler::Definition#specs_changed?0.134/176Enumerator#each
0.110.13 0.000.114/176##to_a0.134/4TSort.tsort_each
0% 0%0.110.13 0.000.11176Enumerator#each0.134TSort.each_strongly_connected_component
0.110.13 0.000.114/8TSort.tsort_each0.134/122Method#call
0.110.13 0.000.114/4Bundler::SpecSet#sorted0.134/122TSort.each_strongly_connected_component
0% 0%0.110.13 0.000.114TSort.tsort0.13122Method#call
0.110.13 0.000.110.13 4/4TSort.tsortBundler::SpecSet#tsort_each_node
0.110.13 0.000.110.13 4/4TSort.tsortMethod#call
0% 0%0.110.13 0.000.110.13 4TSort.tsortBundler::SpecSet#tsort_each_node
0.110.13 0.000.114/4##to_a0.124/1265137##each
0.120.01 0.110.000.114/8Enumerator#each118/118##each
0% 0%0.120.01 0.110.000.118TSort.tsort_each118TSort.each_strongly_connected_component_from
0.110.120.12 0.000.114/4TSort.each_strongly_connected_component2527157/2527157Protobuf::Field::Int64Field(singleton)#set_field
0%0%0.120.120.002527157ProtobufJavaHelpers::Int64ProtobufField.coerce!
0.110.120.12 0.000.114/4TSort.tsort2527157/2528322Protobuf::Field::StringField#coerce!
0% 0%0.110.120.12 0.000.114##to_a2528322##to_s
0.11
0%0%0.120.12 0.000.114/176Enumerator#each2527156ProtobufJavaHelpers::IntegerProtobufField.decode_varint_64
0.11 0.00 0.114/4TSort.tsort_each1/172Bundler::Definition#converge_paths
0% 0%0.110.12 0.000.114TSort.each_strongly_connected_component0.12172##any?
0.11 0.00 0.114/122Method#call2/2Bundler::Definition#specs_changed?
0.110.00 0.114/122TSort.each_strongly_connected_component0.001263846/1263846Protobuf::Enum#to_i
0% 0% 0.110.000.11122Method#call
0.110.00 0.114/4Bundler::SpecSet#tsort_each_node
0.10 0.000.10118/118Bundler::SpecSet#tsort_each_child1263846Protobuf::Enum#tag
0.11 0.00 0.114/4Method#call13/14##each
0% 0.11 0.00 0.114Bundler::SpecSet#tsort_each_node14Gem::Specification.load
0.110.11 0.002527157/2527158Protobuf::Message#initialize
0%0% 0.114/1037819##each0.110.002527158##to_hash
0.11 0.11 0.001036528/1036528Protobuf::Enum#to_i1253578/1263578Proc#call
0% 0.11 0.11 0.001036528Protobuf::Enum#tag1263578Protobuf::Message#to_proto
0.110.11 0.000.10118/118##each1263731/1263731Protobuf::Field::VarintField.encode
0% 0% 0.110.11 0.000.10118TSort.each_strongly_connected_component_from1263731ProtobufJavaHelpers::Varinter.to_varint
0.11 0.00 0.1139/39##map!1/1Bundler::Definition#initialize
0% 0.11 0.00 0.1139Bundler::LazySpecification#__materialize__1Bundler::Definition#converge_paths
0.110.000.111/172##any?
0.100.100.11 0.001026260/1036260Proc#call0.112/2##any?
0% 0% 0.110.000.112Bundler::Definition#specs_changed?
0.11 0.001036260Protobuf::Message#to_proto0.112/2Bundler::Definition#specs_for_source_changed?
0.100.11 0.000.101/1Bundler::Definition#initialize0.112/2Bundler::Definition#specs_changed?
0%0%0.110.000.112Bundler::Definition#specs_for_source_changed?
0% 0% 0.10 0.00 0.101Bundler::Definition#converge_paths5Bundler::Source::Path#specs
0.10 0.00 0.101/172##any?5/5Bundler::Source::Path#local_specs
0.100.00 0.102/2##any?0.002527157/2527330Protobuf::Message#initialize
0% 0% 0.100.000.102Bundler::Definition#specs_changed?
0.10 0.000.102/2Bundler::Definition#specs_for_source_changed?2527330Kernel.block_given?
0.100.00 0.102/2Bundler::Definition#specs_changed?0.001263578/1263578StringIO.new
0% 0% 0.100.10 0.001263578StringIO#initialize
0.102Bundler::Definition#specs_for_source_changed?0.000.101/1Bundler::Definition#specs
0% 0% 0.10 0.00 0.105Bundler::Source::Path#specs1Bundler::Definition#resolve
0.10 0.00 0.10118/118Method#call5/5Bundler::Source::Path#specs
0% 0.10 0.00 0.10118Bundler::SpecSet#tsort_each_child
5Bundler::Source::Path#local_specs
@@ -67,13 +67,13 @@

Total time: 63.20

- + - + - + @@ -82,152 +82,125 @@

Total time: 63.20

- + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - + + - - - + + + - - - + + + - + - + - - - - - + + + + + - + - - - + + + - + - - - - + + + + - - - - - - - - - - + - - + + - - - - - - - - - - - + + - + - + + - - - + + - + @@ -240,31 +213,31 @@

Total time: 63.20

- + - + - + - + - + - + - + - + - + @@ -273,25 +246,25 @@

Total time: 63.20

- + - - + + - + - + - + @@ -310,7 +283,7 @@

Total time: 63.20

- + @@ -319,7 +292,7 @@

Total time: 63.20

- + @@ -338,316 +311,316 @@

Total time: 63.20

- + - + - + - + - + - - - - + + + + - - - + + + - + - + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - + - - - - + + + + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - - + + - + - - - - + + + + - - - - + + + + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - + - + - + - - + + - - + + - + - - + + - + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - + + + - + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + @@ -657,7 +630,7 @@

Total time: 63.20

- + @@ -668,14 +641,14 @@

Total time: 63.20

- + - - - - + + + + @@ -683,154 +656,154 @@

Total time: 63.20

- - - + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - + - + - - + + - - + + - + - - + + - + - - + + - + - - + + - + @@ -840,319 +813,319 @@

Total time: 63.20

- - + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + - - + + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - + + - - + + - + - + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - - + + - + @@ -1160,1105 +1133,1114 @@

Total time: 63.20

- - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - + - - + + - + - + - + - + - - + + - + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - - + + - - - - + + + + - - + + - + - + - - + + - + - - + + - + - - - - - + + + + + - + - - + + - + - - + + - - + + - - - - + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - + + - + - - - - - + + + + + - - - - + + + + - - - - + + + + - + - - + + - - + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - + - + - + - + - + - + - + - + - - + + - + - + - + - - - - + + + + - + - + - - + + - + - - - - + + + + - + - - + + - - + + - + - - - - + + + + - - - - + + + + - + - + - - + + - + - - + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - + + + + + + + + + + - - - - - + + + + + - + - - + + - - + + - - - - - + + + + + - - + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + + + - + - - + + - + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + + - - - - - + + + + + - - - - - - + + + + + + + + + + + + + + - - - - - + + + + + - + - - + + - - + + - - - - - + + + + + - - - - + + + + - + - + - - + + - + - + - - + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - + - - + + - + - + - - + + - + - + - - - - + + + + - - - - + + + + - + - + - - + + - + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - + - + - + - + - + - + - - - - + + + + - - - - + + + + - + - - + + - + - - + + - + - + + + + + + + + + + - - - - - + + + + + - - - - + + + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + @@ -2267,450 +2249,440 @@

Total time: 63.20

- + - - + + - + - + - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + - + - - - - + + + + - + + + + + + + + + + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - - - - + + + + - + - - + + - - + + - + - - + + - + - - + + - + - + - - - + + + - + - - - + + + - + - + - + - + - + - + - - - + + + - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - + + + + + + + + + + - - + + - - - - - + + + + + - - - - + + + + - + - + - + - + - + - + @@ -2719,7 +2691,35 @@

Total time: 63.20

- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2738,7 +2738,7 @@

Total time: 63.20

- + @@ -2766,7 +2766,7 @@

Total time: 63.20

- + @@ -2775,7 +2775,7 @@

Total time: 63.20

- + @@ -2794,7 +2794,7 @@

Total time: 63.20

- + @@ -2803,63 +2803,7 @@

Total time: 63.20

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -2878,16 +2822,16 @@

Total time: 63.20

- + - + - + - + @@ -2896,82 +2840,110 @@

Total time: 63.20

- + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + @@ -2980,32 +2952,32 @@

Total time: 63.20

- + - + - - + + - - - - + + + + - + - - + + - + @@ -3013,274 +2985,302 @@

Total time: 63.20

- - - - + + + + - - - - + + + + - + + - - + + - - + + - - - + + - - + + - - + + - - + + - - + + - - + + - - - - - + + + + + - + - - + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + - + - - + + + + + + + + + + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - + - + + - + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + + - + + + + + + + + + + + + + + + + + + + - + - + - + - - + + - + - - + + - - + + - - + + - - + + @@ -3289,7 +3289,7 @@

Total time: 63.20

- + @@ -3298,55 +3298,93 @@

Total time: 63.20

- - + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - + + + + + + + + + + - - + + + - + - - + + - - + + - + + + + + + + + + + + - + @@ -3355,93 +3393,46 @@

Total time: 63.20

- + - - - - - - - - - - - + - + - + - - + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - + + @@ -3450,8 +3441,8 @@

Total time: 63.20

- - + + @@ -3459,27 +3450,18 @@

Total time: 63.20

- - - - - - - - - - - + + - + - - + + @@ -3487,36 +3469,8 @@

Total time: 63.20

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -3525,8 +3479,8 @@

Total time: 63.20

- - + + @@ -3534,8 +3488,8 @@

Total time: 63.20

- - + + @@ -3544,8 +3498,8 @@

Total time: 63.20

- - + + @@ -3553,29 +3507,10 @@

Total time: 63.20

- - + + - - - - - - - - - - - - - - - - - - - @@ -3583,185 +3518,17 @@

Total time: 63.20

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - + + @@ -3769,112 +3536,101 @@

Total time: 63.20

- - + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - + + - + - - - - + + + + - - - - + + + + - - + - - - - - - - - - - - + + - - - + + + - - - - - - - - + + + + + + - - + + + @@ -3893,9 +3649,9 @@

Total time: 63.20

- + - + @@ -3904,53 +3660,53 @@

Total time: 63.20

- + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - + - - + + @@ -3958,56 +3714,84 @@

Total time: 63.20

- - + + - - - + + + + + + + + + + + - - + + + - + + + + + + + + + + + + + + + + + + - - + + + + - - + + - + - - - + + + @@ -4015,19 +3799,19 @@

Total time: 63.20

- - + + - + - - + + - + @@ -4035,7 +3819,7 @@

Total time: 63.20

- + @@ -4044,92 +3828,130 @@

Total time: 63.20

- + - + - + - - - + + + - + - - - + + + + + + + + + + + - - + + + + - - + - + - + - + - + - - + + + + + + + + + + + + - + + + + + + + + + + - - + + - - + + - - + + - - + + + + + + + + + + + + - - + + - - + + - - + + - - + + @@ -4150,1233 +3972,1247 @@

Total time: 63.20

- + + + + + + + + - - + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - + + + + + + + + + + - - - - + + - + + + + - - - - - - - - - + + + + - + + + + + - - - - - - + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - + + + + + - - + + - + + - - - - - - - - - - + + - - - - - + + + + + + + + - - - - - - - - - - + - + + + + + - + + + - - + + + - - - + + + - - - - - + + + - - + + + - + + + - + + + + + + + + + + + + + + + - - - - - - - - + + - + - + + + + + + - - - - + + - - - - - + + + - + + + - + - - - - - - - - + + + + + - - - + + + + + + + - - - - - + + + - - + + + - - + + + + + + + - - - + + - + + - - - - - + + + + + + - - - + - + - - - - + + + + + - - - + + + + + + + + - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + - + + - - - - - - + - - + + + + + + + - + - - + - + + + - - - - - - + + - - + - - - - - - - + - - + + + - - + + + + + + + + + - - + - - - + - - + + + + + - - - - - - + + + + + - - - - - - - + + + - + + + + - - + + + + + + + + - - - - - - + - - - - - - - - + + - + - + + + + + - - - + + + + + + - + + + + + + + - + + + - + - - - - - + + + + - - - - + + + + - - - - - - - - - - + - - - + + + - + - - - - - - - - - - - + + + + + + + + + - + + + + + - - - - - - - - - - + - + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + - - + + - + + + + + + + - - + - - + + + - - - - + + + + + + + + - + - + - - - + - - - - - + + - - - - - - + + - + + - - + + - + - - - + + + + + - - - - + + + - - - - - + + - - - + + + + - - - - - - + + - + + - + - - - + - + + + + + + + - - - - + - + + - - + - - - - + + - - - + + + + + + + + + + + + + + + + - + + + + + - - + + + - - - + + + - - + + - + + - - + + - + + - - - + + - - + + + - - + + + + - - - - - - - + + + + + - + + + + + + + + - - + - - - - - - - - - - - + - - - - + - @@ -5384,44 +5220,45 @@

Total time: 63.20

- + + + + + - - - + - + + - - + + + - - - @@ -5429,23 +5266,23 @@

Total time: 63.20

- + - - + + @@ -5470,7 +5307,7 @@

Total time: 63.20

- + @@ -5478,10 +5315,12 @@

Total time: 63.20

+ + + - @@ -5492,21 +5331,19 @@

Total time: 63.20

- - - + - + @@ -5517,21 +5354,22 @@

Total time: 63.20

- + + - + From e03383604da55ec2bc293ac56d2bd39e0eb84db9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Dec 2018 10:57:08 -0700 Subject: [PATCH 1115/1191] do not need an intermediate stored value --- lib/protobuf/field/enum_field.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 4c7f6653..9a29b42a 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -47,8 +47,7 @@ def enum? end def coerce!(value) - enum_value = type_class.fetch(value) - enum_value || fail(TypeError, "Invalid Enum value: #{value.inspect} for #{name}") + type_class.fetch(value) || fail(TypeError, "Invalid Enum value: #{value.inspect} for #{name}") end private From e0acb26f6f34f40911b318bb2843560dff40bc60 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Dec 2018 11:21:09 -0700 Subject: [PATCH 1116/1191] no need for intermediary --- lib/protobuf/message.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 54e8621d..c61087db 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -95,8 +95,7 @@ def each_field def each_field_for_serialization _protobuf_message_required_field_tags.each do |tag| - field = _protobuf_message_field[tag] - fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{_protobuf_message_field[tag].name} does not have a value." end @values.each_key do |fully_qualified_name| From cf430a380edd3ab2051ed4a8b25b920595d40b88 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Dec 2018 12:01:03 -0700 Subject: [PATCH 1117/1191] more java helpers and we should not need to copy decoded string fields --- lib/protobuf/field/string_field.rb | 5 ++--- lib/protobuf/field/uint32_field.rb | 17 ++++++++++------- lib/protobuf/field/uint64_field.rb | 17 ++++++++++------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index a59fd652..49b6d2b8 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -27,9 +27,8 @@ def coerce!(value) end def decode(bytes) - bytes_to_decode = "" + bytes - bytes_to_decode.force_encoding(::Protobuf::Field::StringField::ENCODING) - bytes_to_decode + bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) + bytes end def encode(value) diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb index 50fa8fef..6d512c8e 100644 --- a/lib/protobuf/field/uint32_field.rb +++ b/lib/protobuf/field/uint32_field.rb @@ -7,15 +7,18 @@ class Uint32Field < VarintField ## # Class Methods # + if defined?(::ProtobufJavaHelpers) + include ::ProtobufJavaHelpers::Uint32ProtobufField + extend ::ProtobufJavaHelpers::Uint32ProtobufField + else + def self.max + UINT32_MAX + end - def self.max - UINT32_MAX + def self.min + 0 + end end - - def self.min - 0 - end - end end end diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb index 8a060f14..0ef93bdf 100644 --- a/lib/protobuf/field/uint64_field.rb +++ b/lib/protobuf/field/uint64_field.rb @@ -7,15 +7,18 @@ class Uint64Field < VarintField ## # Class Methods # + if defined?(::ProtobufJavaHelpers) + include ::ProtobufJavaHelpers::Uint64ProtobufField + extend ::ProtobufJavaHelpers::Uint64ProtobufField + else + def self.max + UINT64_MAX + end - def self.max - UINT64_MAX + def self.min + 0 + end end - - def self.min - 0 - end - end end end From 5b8013f0f39ca902d686d733767ef898a4b73540 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Dec 2018 12:05:47 -0700 Subject: [PATCH 1118/1191] should be using bytesize for string and bytes fields --- lib/protobuf/field/bytes_field.rb | 20 ++++++++------------ lib/protobuf/field/string_field.rb | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 40aa3fbe..81a3634d 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -27,23 +27,19 @@ def acceptable?(val) end def decode(bytes) - bytes_to_decode = bytes.dup - bytes_to_decode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - bytes_to_decode + bytes.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + bytes end def encode(value) - value_to_encode = - if value.is_a?(::Protobuf::Message) - value.encode - else - value.dup - end + value_to_encode = if value.is_a?(::Protobuf::Message) + value.encode + else + "" + value + end value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) - - "#{string_size}#{value_to_encode}" + "#{::Protobuf::Field::VarintField.encode(value_to_encode.bytesize)}#{value_to_encode}" end def wire_type diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 49b6d2b8..055ace43 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -38,7 +38,7 @@ def encode(value) end value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - "#{::Protobuf::Field::VarintField.encode(value_to_encode.size)}#{value_to_encode}" + "#{::Protobuf::Field::VarintField.encode(value_to_encode.bytesize)}#{value_to_encode}" end def json_encode(value) From 69d948be6ef01d492b143e90136d6386f2e2951c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Dec 2018 17:14:51 -0700 Subject: [PATCH 1119/1191] account for int32 values --- lib/protobuf/field/int32_field.rb | 25 +++++++++++++++++++------ spec/encoding/extreme_values_spec.rb | Bin 1381 -> 1378 bytes 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb index 4a7865f9..b8f3ab88 100644 --- a/lib/protobuf/field/int32_field.rb +++ b/lib/protobuf/field/int32_field.rb @@ -7,15 +7,28 @@ class Int32Field < IntegerField ## # Class Methods # + if defined?(::ProtobufJavaHelpers) + include ::ProtobufJavaHelpers::Varinter + include ::ProtobufJavaHelpers::IntegerProtobufField + include ::ProtobufJavaHelpers::Int32ProtobufField + extend ::ProtobufJavaHelpers::Int32ProtobufField - def self.max - INT32_MAX - end + def encode(value) + to_varint_64(value) + end - def self.min - INT32_MIN - end + def decode(value) + decode_varint_64(value) + end + else + def self.max + INT32_MAX + end + def self.min + INT32_MIN + end + end end end end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 6678f991028fce2a8ad5b948a1dfd6ee62a458c3..097e8ede11f9edc24c5fca6bfc690451247df920 100644 GIT binary patch delta 21 dcmaFL^@wYOHsfX;#xADG+nKdCKVoiX1OQpC2e$wK delta 31 mcmaFF^^|LaHY20*W^KkUCPwAS_nE~fpJ5gT3fyOIW&{AAfC;Gp From 13eb3d34a96ce353f5d0aa8a761710de3a3e0403 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 29 Dec 2018 20:12:11 -0700 Subject: [PATCH 1120/1191] should wait for helpers --- Gemfile | 2 - lib/protobuf/field/enum_field.rb | 27 +++------ lib/protobuf/field/int32_field.rb | 25 ++------ lib/protobuf/field/int64_field.rb | 32 +++++----- lib/protobuf/field/integer_field.rb | 22 ------- lib/protobuf/field/message_field.rb | 2 +- lib/protobuf/field/uint32_field.rb | 17 +++--- lib/protobuf/field/uint64_field.rb | 17 +++--- lib/protobuf/field/varint_field.rb | 55 +++++++++++++----- .../field/varint_field_encoder_pure.rb | 48 --------------- lib/protobuf/message.rb | 22 +++---- protobuf.gemspec | 1 - spec/encoding/extreme_values_spec.rb | Bin 1378 -> 1358 bytes 13 files changed, 93 insertions(+), 177 deletions(-) delete mode 100644 lib/protobuf/field/varint_field_encoder_pure.rb diff --git a/Gemfile b/Gemfile index d5b5bd21..fa75df15 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ source 'https://rubygems.org/' -gem 'protobuf_java_helpers', :path => "~/code/protobuf_java_helpers" - gemspec diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 9a29b42a..63f4d49b 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -15,27 +15,14 @@ def self.default ## # Public Instance Methods # - if defined?(::ProtobufJavaHelpers) - include ::ProtobufJavaHelpers::Varinter - include ::ProtobufJavaHelpers::IntegerProtobufField - - def encode(value) - to_varint_64(value.to_i) # Calling `to_i` because it is a delegator and the java side doesn't follow - end - - def decode(value) - decode_varint_64(value) - end - else - def encode(value) - # original Google's library uses 64bits integer for negative value - ::Protobuf::Field::VarintField.encode(value & 0xffff_ffff_ffff_ffff) - end + def encode(value) + # original Google's library uses 64bits integer for negative value + ::Protobuf::Field::VarintField.encode(value & 0xffff_ffff_ffff_ffff) + end - def decode(value) - value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? - value if acceptable?(value) - end + def decode(value) + value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? + value if acceptable?(value) end def acceptable?(val) diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb index b8f3ab88..4a7865f9 100644 --- a/lib/protobuf/field/int32_field.rb +++ b/lib/protobuf/field/int32_field.rb @@ -7,28 +7,15 @@ class Int32Field < IntegerField ## # Class Methods # - if defined?(::ProtobufJavaHelpers) - include ::ProtobufJavaHelpers::Varinter - include ::ProtobufJavaHelpers::IntegerProtobufField - include ::ProtobufJavaHelpers::Int32ProtobufField - extend ::ProtobufJavaHelpers::Int32ProtobufField - def encode(value) - to_varint_64(value) - end - - def decode(value) - decode_varint_64(value) - end - else - def self.max - INT32_MAX - end + def self.max + INT32_MAX + end - def self.min - INT32_MIN - end + def self.min + INT32_MIN end + end end end diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb index 493f6ab2..3b338894 100644 --- a/lib/protobuf/field/int64_field.rb +++ b/lib/protobuf/field/int64_field.rb @@ -7,26 +7,26 @@ class Int64Field < IntegerField ## # Class Methods # - if defined?(::ProtobufJavaHelpers) - include ::ProtobufJavaHelpers::Varinter - include ::ProtobufJavaHelpers::IntegerProtobufField - include ::ProtobufJavaHelpers::Int64ProtobufField - def encode(value) - to_varint_64(value) - end + def self.max + INT64_MAX + end - def decode(value) - decode_varint_64(value) - end - else - def self.max - INT64_MAX - end + def self.min + INT64_MIN + end - def self.min - INT64_MIN + ## + # Instance Methods + # + def acceptable?(val) + if val.is_a?(Integer) || val.is_a?(Numeric) + val >= INT64_MIN && val <= INT64_MAX + else + Integer(val, 10) >= INT64_MIN && Integer(val, 10) <= INT64_MAX end + rescue + return false end end diff --git a/lib/protobuf/field/integer_field.rb b/lib/protobuf/field/integer_field.rb index 3b66ec2c..5eb3b064 100644 --- a/lib/protobuf/field/integer_field.rb +++ b/lib/protobuf/field/integer_field.rb @@ -7,28 +7,6 @@ class IntegerField < VarintField ## # Public Instance Methods # - def acceptable?(val) - int_val = if val.is_a?(Integer) - return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path - val - elsif val.is_a?(Numeric) - val.to_i - else - Integer(val, 10) - end - - int_val >= self.class.min && int_val <= self.class.max - rescue - false - end - - def coerce!(val) - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) - return val.to_i if val.is_a?(Numeric) - Integer(val, 10) - rescue ArgumentError - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" - end def decode(value) value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero? diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 304a201f..34f45fd2 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -18,7 +18,7 @@ def decode(bytes) def encode(value) bytes = value.encode - result = ::Protobuf::Field::VarintField.encode(bytes.size) + result = ::Protobuf::Field::VarintField.encode(bytes.bytesize) result << bytes end diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb index 6d512c8e..50fa8fef 100644 --- a/lib/protobuf/field/uint32_field.rb +++ b/lib/protobuf/field/uint32_field.rb @@ -7,18 +7,15 @@ class Uint32Field < VarintField ## # Class Methods # - if defined?(::ProtobufJavaHelpers) - include ::ProtobufJavaHelpers::Uint32ProtobufField - extend ::ProtobufJavaHelpers::Uint32ProtobufField - else - def self.max - UINT32_MAX - end - def self.min - 0 - end + def self.max + UINT32_MAX end + + def self.min + 0 + end + end end end diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb index 0ef93bdf..8a060f14 100644 --- a/lib/protobuf/field/uint64_field.rb +++ b/lib/protobuf/field/uint64_field.rb @@ -7,18 +7,15 @@ class Uint64Field < VarintField ## # Class Methods # - if defined?(::ProtobufJavaHelpers) - include ::ProtobufJavaHelpers::Uint64ProtobufField - extend ::ProtobufJavaHelpers::Uint64ProtobufField - else - def self.max - UINT64_MAX - end - def self.min - 0 - end + def self.max + UINT64_MAX end + + def self.min + 0 + end + end end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 70879c03..02a8cddc 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -1,5 +1,4 @@ require 'protobuf/field/base_field' -require 'protobuf/field/varint_field_encoder_pure' module Protobuf module Field @@ -25,27 +24,55 @@ def self.default 0 end - if defined?(::ProtobufJavaHelpers) - include ::ProtobufJavaHelpers::VarintProtobufField - extend ::ProtobufJavaHelpers::VarintProtobufField - extend ::ProtobufJavaHelpers::Varinter + # Because all tags and enums are calculated as VarInt it is "most common" to have + # values < CACHE_LIMIT (low numbers) which is defaulting to 1024 + def self.cached_varint(value) + @_varint_cache ||= {} + (@_varint_cache[value] ||= encode(value, false)).dup + end - def self.encode(value) - to_varint(value) - end - else - include ::Protobuf::Field::VarintFieldEncoderPure - extend ::Protobuf::Field::VarintFieldEncoderPure::ClassMethods + def self.encode(value, use_cache = true) + return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT - # Load the cache of VarInts on load of file - (0..CACHE_LIMIT).each do |cached_value| - cached_varint(cached_value) + bytes = [] + until value < 128 + bytes << (0x80 | (value & 0x7f)) + value >>= 7 end + (bytes << value).pack('C*') + end + + # Load the cache of VarInts on load of file + (0..CACHE_LIMIT).each do |cached_value| + cached_varint(cached_value) end ## # Public Instance Methods # + def acceptable?(val) + int_val = if val.is_a?(Integer) + return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path + val + elsif val.is_a?(Numeric) + val.to_i + else + Integer(val, 10) + end + + int_val >= self.class.min && int_val <= self.class.max + rescue + false + end + + def coerce!(val) + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) + return val.to_i if val.is_a?(Numeric) + Integer(val, 10) + rescue ArgumentError + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" + end + def decode(value) value end diff --git a/lib/protobuf/field/varint_field_encoder_pure.rb b/lib/protobuf/field/varint_field_encoder_pure.rb deleted file mode 100644 index 2dba22c5..00000000 --- a/lib/protobuf/field/varint_field_encoder_pure.rb +++ /dev/null @@ -1,48 +0,0 @@ -module Protobuf - module Field - module VarintFieldEncoderPure - module ClassMethods - # Because all tags and enums are calculated as VarInt it is "most common" to have - # values < CACHE_LIMIT (low numbers) which is defaulting to 1024 - def cached_varint(value) - @_varint_cache ||= {} - (@_varint_cache[value] ||= encode(value, false)).dup - end - - def encode(value, use_cache = true) - return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT - - bytes = [] - until value < 128 - bytes << (0x80 | (value & 0x7f)) - value >>= 7 - end - (bytes << value).pack('C*') - end - end - - def acceptable?(val) - int_val = if val.is_a?(Integer) - return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path - val - elsif val.is_a?(Numeric) - val.to_i - else - Integer(val, 10) - end - - int_val >= self.class.min && int_val <= self.class.max - rescue - false - end - - def coerce!(val) - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) - return val.to_i if val.is_a?(Numeric) - Integer(val, 10) - rescue ArgumentError - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" - end - end - end -end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c61087db..412732f1 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -23,20 +23,6 @@ class Message include ::Protobuf::Message::Serialization ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::MessageOptions } - def self.inherited(subclass) - subclass.const_set("PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS", subclass.required_field_tags) - subclass.const_set("PROTOBUF_MESSAGE_GET_FIELD", subclass.field_store) - subclass.class_eval <<~RUBY, __FILE__, __LINE__ - def _protobuf_message_field - PROTOBUF_MESSAGE_GET_FIELD - end - - def _protobuf_message_required_field_tags - @_protobuf_message_required_field_tags ||= PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS.dup - end - RUBY - end - ## # Class Methods # @@ -207,6 +193,14 @@ def set_field(name, value, ignore_nil_for_repeated, field = nil) end end + def _protobuf_message_field + @_protobuf_message_field ||= self.class.field_store + end + + def _protobuf_message_required_field_tags + @_protobuf_message_required_field_tags ||= self.class.required_field_tags + end + ## # Instance Aliases # diff --git a/protobuf.gemspec b/protobuf.gemspec index 2d9330ef..4f182c4e 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -51,7 +51,6 @@ require "protobuf/version" s.add_development_dependency 'varint' s.add_development_dependency 'ruby-prof' elsif RUBY_PLATFORM =~ /java/i - #s.add_development_dependency 'protobuf_java_helpers' s.add_development_dependency 'fast_blank_java' s.add_development_dependency 'pry' end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 097e8ede11f9edc24c5fca6bfc690451247df920..477e695aa37676462eb7cbcd5cc355e2f7fc387d 100644 GIT binary patch delta 125 zcmaFFb&hMo*@@?FPF}&NpsxT1R#mA*`SEEv`H3Y8wsr~zI$Tik{Jd0zu%QmuDT23A$6Mfve*Ir)ht3bu9%20C2IlkYK#%fh6K za}#rN5b}n4rXUppOo~8b44LGCWB`*akj!OL2a;2m)PUqJCT$@36s(4gSry3EX4V3d eq09 Date: Sun, 30 Dec 2018 12:48:05 -0700 Subject: [PATCH 1121/1191] delegator fix for encode in enum_field --- lib/protobuf/field/enum_field.rb | 2 +- profile.html | 6236 ++++++++++++++++-------------- 2 files changed, 3265 insertions(+), 2973 deletions(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 63f4d49b..6993faff 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -17,7 +17,7 @@ def self.default # def encode(value) # original Google's library uses 64bits integer for negative value - ::Protobuf::Field::VarintField.encode(value & 0xffff_ffff_ffff_ffff) + ::Protobuf::Field::VarintField.encode(value.to_i & 0xffff_ffff_ffff_ffff) end def decode(value) diff --git a/profile.html b/profile.html index 301a2adf..cdc0569d 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 63.22

+

Total time: 63.34

%Total
100% 0%63.2063.22 0.0063.2063.22 0 (top)
60.08 1/1 Benchmark::IPS.ips
1.011.05 0.001.001.05 2/115 Kernel.require
0.930.91 0.000.930.91 6/1886 Kernel.require
0.65 0.04 0.61 1/5##times##times
0.530.52 0.060.470.46 17/19 Kernel.load
0.130.00 0.124/1265137Bundler::SpecSet#tsort_each_node
0.14 0.000.141/12651370.121/1292879 Gem::Specification.each_gemspec
0.240.00 0.2319/12651370.000.2219/1292879 Kernel.require
20.001.8018.201/12651371.7718.241/1292879 Benchmark::IPS::Job#run_warmup
40.0740.08 0.01 40.071/12651371/1292879 Benchmark::IPS::Job#run_benchmark
96% 2%60.941.8459.091265137##each60.851.8159.041292879##each
57.022.9254.103554696/35546963.0653.963681351/3681351 Benchmark::IPS::Job::Entry#call_times
0.910.450.463555260/35552600.950.470.493681900/3681900 Benchmark::Timing.now
0.180.180.003554700/3554700##<
0.150.150.170.17 0.003554710/18454858##+
0.120.010.11118/118TSort.each_strongly_connected_component_from3681355/3681355##<
0.110.140.14 0.000.1113/14Gem::Specification.load3681365/18790704##+
60.0760.08 0.0060.0760.08 2/5 Benchmark::IPS::Job#run
96% 0%60.7560.76 0.0660.6960.70 5##times##times
40.0740.08 0.0040.0740.08 1/1 Benchmark::IPS::Job#run_benchmark
20.00 1/1 Benchmark::IPS::Job#run_warmup
0.29 0.000.2910000/12635780.2810000/1291320 Protobuf::Message::Serialization::ClassMethods.decode_from
0.19 0.01 0.1810000/126357810000/1291320 Protobuf::Encoder.encode
1 Benchmark::IPS.ips
60.08 1/1 Benchmark::IPS::Job#run
1 Benchmark::IPS::Job#run
60.0760.08 0.0060.0760.08 2/5##times##times
57.022.9254.103554696/3554696##each3.0653.963681351/3681351##each
90% 4% 57.022.9254.1035546963.0653.963681351 Benchmark::IPS::Job::Entry#call_times
52.7952.58 2.3150.4914899065/1489961350.2615108256/15108804 Proc#call
0.700.700.710.71 0.0018453761/18453786##<18789607/18789624##<
0.610.610.670.67 0.0014899065/18454858##+15108256/18790704##+
52.7952.58 2.3150.4914899065/1489961350.2615108256/15108804 Benchmark::IPS::Job::Entry#call_times
83% 3%52.822.3150.511489961352.612.3250.2915108804 Proc#call
22.292.3619.9313645487/1364548722.112.3719.7413826936/13826936 Protobuf::Message#to_hash
13.180.3012.871253578/126357812.920.3312.591281320/1291320 Protobuf::Message::Serialization::ClassMethods.decode_from
8.720.308.421253578/12635789.100.358.751281320/1291320 Protobuf::Encoder.encode
3.743.53 0.173.571253578/25286803.361281320/2584164 Class#new
2.110.291.821253578/12635782.170.311.871281320/1291320 Test::Resource#status=
0.270.28 0.170.101253578/12635780.111281320/1291320 StringIO.new
0.11 0.11 0.001253578/12635781281320/1291320 Protobuf::Message#to_proto
40.0740.08 0.0040.0740.08 1/1##times##times
63% 0%40.0740.08 0.0040.0740.08 1 Benchmark::IPS::Job#run_benchmark
40.0740.08 0.01 40.071/1265137##each1/1292879##each
7.921.576.361263578/149090668.231.646.601291320/15118257 Protobuf::Message#each_field_for_serialization
19.935.8514.0913645487/1490906619.745.9313.8113826936/15118257 Protobuf::Message#to_hash
44% 11%27.867.4120.4514909066##each_key27.987.5720.4115118257##each_key
5.602.353.2513645487/136454875.462.323.1513826936/13826936 Protobuf::Field::StringField(singleton)#to_message_hash
5.412.243.1713645487/136454875.342.273.0613826936/13826936 Protobuf::Field::Int64Field(singleton)#to_message_hash
2.300.730.74 1.571263578/12635781291320/1291320 Protobuf::Field::StringField(singleton)#encode_to_stream
2.022.021.991.99 0.0031081708/72277033##[]31527832/73391217##[]
1.541.541.551.55 0.0031081708/3866317831527832/39275754 Test::Resource#_protobuf_message_field
1.370.291.081263578/12635781.440.321.121291320/1291320 Protobuf::Field::EnumField(singleton)#encode_to_stream
1.090.300.791263578/12635781.180.320.861291320/1291320 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.400.120.281263578/161726430.410.110.301291320/16409576 Protobuf::Field::StringField(singleton)#value_from_values
0.360.100.261263578/25271560.370.110.271291320/2582640 Protobuf::Field::EnumField(singleton)#value_from_values
0.360.100.251263578/161726430.110.261291320/16409576 Protobuf::Field::Int64Field(singleton)#value_from_values
22.292.3619.9313645487/1364548722.112.3719.7413826936/13826936 Proc#call
35%34% 3%22.292.3619.931364548722.112.3719.7413826936 Protobuf::Message#to_hash
19.935.8514.0913645487/14909066##each_key19.745.9313.8113826936/15118257##each_key
0.00 20.00 1/1##times##times
31% 1 Benchmark::IPS::Job#run_warmup
20.001.8018.201/1265137##each1.7718.241/1292879##each
0.29 0.000.2910000/1263578##times0.2810000/1291320##times
13.180.3012.871253578/126357812.920.3312.591281320/1291320 Proc#call
21%20% 0%13.470.3113.16126357813.200.3312.871291320 Protobuf::Message::Serialization::ClassMethods.decode_from
12.380.2912.091263578/126357812.110.3211.781291320/1291320 Protobuf::Message::Serialization.decode_from
0.780.76 0.170.611263578/25286800.591291320/2584164 Class#new
12.380.2912.091263578/126357812.110.3211.781291320/1291320 Protobuf::Message::Serialization::ClassMethods.decode_from
19% 0%12.380.2912.09126357812.110.3211.781291320 Protobuf::Message::Serialization.decode_from
12.092.129.981263578/126357811.782.059.741291320/1291320 Protobuf::Decoder.decode_each_field
12.092.129.981263578/126357811.782.059.741291320/1291320 Protobuf::Message::Serialization.decode_from
19%18% 3%12.092.129.98126357811.782.059.741291320 Protobuf::Decoder.decode_each_field
7.631.226.413790734/37907347.401.166.243873960/3873960 Protobuf::Message::Serialization.set_field_bytes
1.390.840.547581468/75814681.420.850.577747920/7747920 Protobuf::Varint.decode
0.280.280.240.24 0.005054312/50543125165280/5165280 StringIO#eof
0.210.210.200.20 0.005054312/5057540##==5165280/5168510##==
0.17 0.17 0.003790734/3790734##>>3873960/3873960##>>
0.17 0.17 0.003790734/3790734##&3873960/3873960##&
0.140.140.130.13 0.001263578/12635781291320/1291320 StringIO#read
0.19 0.01 0.1810000/1263578##times10000/1291320##times
8.720.308.421253578/12635789.100.358.751281320/1291320 Proc#call
14% 0%8.910.318.5912635789.280.368.931291320 Protobuf::Encoder.encode
8.590.448.161263578/12635788.930.458.481291320/1291320 Protobuf::Message#each_field_for_serialization
0.688.930.458.481291320/1291320Protobuf::Encoder.encode
14%0%8.930.458.481291320Protobuf::Message#each_field_for_serialization
8.231.646.601291320/15118257##each_key
0.180.180.001291320/3873961Test::Resource#_protobuf_message_required_field_tags
0.69 0.170.511263578/75814700.521291320/7747922 Protobuf::Field::Int64Field(singleton)#set
1.641.34 0.191.461263578/75814701.151291320/7747922 Protobuf::Field::StringField(singleton)#set
1.671.73 0.161.511263578/75814701.571291320/7747922 Protobuf::Field::EnumField(singleton)#set
1.850.321.531263578/75814701.890.311.591291320/7747922 Test::Resource#status=
2.800.632.182527158/7581470##each2.570.641.932582642/7747922##each
13% 2%8.651.467.1975814708.221.476.757747922 Protobuf::Message#set_field
2.890.582.312527156/25271562.980.602.392582640/2582640 Protobuf::Field::EnumField(singleton)#set_field
2.800.891.912527157/25271572.210.941.272582641/2582641 Protobuf::Field::StringField(singleton)#set_field
0.960.580.382527157/25271570.970.600.372582641/2582641 Protobuf::Field::Int64Field(singleton)#set_field
0.290.290.320.32 0.003790736/72277033##[]3873962/73391217##[]
0.250.250.260.26 0.003790736/386631783873962/39275754 Test::Resource#_protobuf_message_field
8.590.448.161263578/1263578Protobuf::Encoder.encode
13%0%8.590.448.161263578Protobuf::Message#each_field_for_serialization
7.921.576.361263578/14909066##each_key
0.170.170.001263578/3790735Test::Resource#_protobuf_message_required_field_tags
7.631.226.413790734/37907347.401.166.243873960/3873960 Protobuf::Decoder.decode_each_field
12%11% 1%7.631.226.4137907347.401.166.243873960 Protobuf::Message::Serialization.set_field_bytes
2.390.252.131263578/1263578Protobuf::Field::StringField(singleton)#set2.250.271.971291320/1291320Protobuf::Field::EnumField(singleton)#set
2.180.261.921263578/1263578Protobuf::Field::EnumField(singleton)#set2.120.281.851291320/1291320Protobuf::Field::StringField(singleton)#set
1.200.250.951263578/12635781.240.270.971291320/1291320 Protobuf::Field::Int64Field(singleton)#set
0.350.350.340.34 0.003790734/72277033##[]3873960/73391217##[]
0.29 0.29 0.003790734/386631783873960/39275754 Test::Resource#_protobuf_message_field
5.602.353.2513645487/13645487##each_key5.462.323.1513826936/13826936##each_key
8% 3%5.602.353.25136454875.462.323.1513826936 Protobuf::Field::StringField(singleton)#to_message_hash
2.381.590.7913645487/161726432.341.660.6813826936/16409576 Protobuf::Field::StringField(singleton)#value_from_values
0.870.870.810.81 0.0013645487/34877001##[]=13826936/35406351##[]=
5.412.243.1713645487/13645487##each_key5.342.273.0613826936/13826936##each_key
8% 3%5.412.243.17136454875.342.273.0613826936 Protobuf::Field::Int64Field(singleton)#to_message_hash
2.331.550.7813645487/161726432.241.590.6513826936/16409576 Protobuf::Field::Int64Field(singleton)#value_from_values
0.840.840.820.82 0.0013645487/34877001##[]=13826936/35406351##[]=
0.110.030.100.02 0.0816/252868016/2584164 Kernel.eval
0.17 0.010.17153/25286800.16153/2584164 Protobuf::Field.build
0.290.30 0.010.281/25286800.291/2584164 Bundler::Dsl#to_definition
0.780.76 0.170.611263578/25286800.591291320/2584164 Protobuf::Message::Serialization::ClassMethods.decode_from
3.743.53 0.173.571253578/25286803.361281320/2584164 Proc#call
8% 0%5.335.12 0.464.8725286804.662584164 Class#new
4.254.02 0.813.432527157/25271573.212582641/2582641 Protobuf::Message#initialize
0.280.29 0.000.280.29 1/1 Bundler::Definition#initialize
0.170.01 0.160.010.15 153/153 Protobuf::Field::BaseField#initialize
0.15 0.15 0.002527156/722770332582640/73391217 Protobuf::Enum.enum_for_tag_integer
0.290.290.320.32 0.003790736/722770333873962/73391217 Protobuf::Message#set_field
0.350.350.340.34 0.003790734/722770333873960/73391217 Protobuf::Message::Serialization.set_field_bytes
0.850.850.720.72 0.0014909065/7227703315118256/73391217 Protobuf::Field::Int64Field(singleton)#value_from_values
0.890.890.760.76 0.0014909065/7227703315118256/73391217 Protobuf::Field::StringField(singleton)#value_from_values
2.022.021.991.99 0.0031081708/72277033##each_key31527832/73391217##each_key
7%7%4.664.636%6%4.404.37 0.0372277033##[]73391217##[]
4.254.02 0.813.432527157/25271573.212582641/2582641 Class#new
6% 1%4.254.02 0.813.4325271573.212582641 Protobuf::Message#initialize
3.220.422.802527157/2527371##each3.000.432.572582641/2582855##each
0.11 0.11 0.002527157/2527158##to_hash2582641/2582814Kernel.block_given?
0.100.100.110.11 0.002527157/2527330Kernel.block_given?2582641/2582642##to_hash
3.220.422.802527157/25273713.000.432.572582641/2582855 Protobuf::Message#initialize
5%4% 0%3.240.432.812527371##each3.020.442.582582855##each
2.800.632.182527158/75814702.570.641.932582642/7747922 Protobuf::Message#set_field
2.890.582.312527156/25271562.980.602.392582640/2582640 Protobuf::Message#set_field
4% 0%2.890.582.3125271562.980.602.392582640 Protobuf::Field::EnumField(singleton)#set_field
2.040.471.572527156/25271562.110.491.622582640/2582640 Protobuf::Field::EnumField#coerce!
0.180.180.002527156/34877001##[]=
2.800.891.912527157/2527157Protobuf::Message#set_field
4%1%2.800.891.912527157Protobuf::Field::StringField(singleton)#set_field
0.690.480.212527157/2527157Protobuf::Field::StringField#coerce!
0.680.530.152527157/3790735Test::Resource#_protobuf_message_required_field_tags
0.230.230.002527157/34877001##[]=
0.210.210.002527157/2527341##delete
0.100.100.170.17 0.002527157/10109592Kernel.nil?2582640/35406351##[]=
0.400.120.281263578/16172643##each_key0.410.110.301291320/16409576##each_key
2.381.590.7913645487/161726432.341.660.6813826936/16409576 Protobuf::Field::StringField(singleton)#to_message_hash
4% 2%2.781.711.07161726432.751.770.9816409576 Protobuf::Field::StringField(singleton)#value_from_values
0.890.890.760.76 0.0014909065/72277033##[]15118256/73391217##[]
0.360.100.251263578/16172643##each_key0.110.261291320/16409576##each_key
2.331.550.7813645487/161726432.241.590.6513826936/16409576 Protobuf::Field::Int64Field(singleton)#to_message_hash
4% 2%2.691.651.03161726432.611.700.9116409576 Protobuf::Field::Int64Field(singleton)#value_from_values
0.850.850.720.72 0.0014909065/72277033##[]15118256/73391217##[]
2.390.252.131263578/1263578Protobuf::Message::Serialization.set_field_bytes
3%0%2.390.252.131263578Protobuf::Field::StringField(singleton)#set
1.640.191.461263578/7581470Protobuf::Message#set_field
0.490.280.221263578/1263578Protobuf::Field::StringField#decode
0.160.160.002527157/34877001Protobuf::Field::Int64Field(singleton)#set_field
0.180.180.002527156/34877001Protobuf::Field::EnumField(singleton)#set_field
0.230.230.002527157/34877001Protobuf::Field::StringField(singleton)#set_field
0.840.840.0013645487/34877001Protobuf::Field::Int64Field(singleton)#to_message_hash
0.870.870.0013645487/34877001Protobuf::Field::StringField(singleton)#to_message_hash
3%3%2.382.290.0834877001##[]=
0.430.42 0.030.400.39 2/1886 Kernel.load
0.930.91 0.000.930.91 6/1886 (top)
1.001.05 0.001.001.05 115/1886 Kernel.require
3% 0%2.362.37 0.032.332.34 1886 Kernel.require
0.860.88 0.000.860.88 1/1 Bundler.setup
0.240.00 0.2319/1265137##each0.000.2219/1292879##each
0.140.13 0.000.140.13 1/1 Gem::Specification.load_defaults
0.140.12 0.000.130.12 109/109 Protobuf::Message::Fields::ClassMethods.optional
2.300.730.74 1.571263578/1263578##each_key1291320/1291320##each_key
3% 1% 2.300.730.74 1.5712635781291320 Protobuf::Field::StringField(singleton)#encode_to_stream
0.750.360.403790734/88450460.740.350.393873960/9039240 IO::GenericWritable.<<
0.320.34 0.220.111263578/12637310.121291320/1291473 Protobuf::Field::VarintField.encode
0.220.160.061263578/12643890.240.170.071291320/1292131 BasicObject#!=
0.140.140.120.12 0.001263578/2527298##+1291320/2582782##+
2.180.261.921263578/12635782.250.271.971291320/1291320 Protobuf::Message::Serialization.set_field_bytes
3% 0%2.180.261.9212635782.250.271.971291320 Protobuf::Field::EnumField(singleton)#set
1.671.73 0.161.511263578/75814701.571291320/7747922 Protobuf::Message#set_field
0.250.200.240.19 0.051263578/12635781291320/1291320 Protobuf::Field::EnumField#decode
2.110.291.821253578/12635782.170.311.871281320/1291320 Proc#call
3% 0%2.150.301.8512635782.210.321.891291320 Test::Resource#status=
1.850.321.531263578/75814701.890.311.591291320/7747922 Protobuf::Message#set_field
0.250.250.003790736/386631782.210.941.272582641/2582641 Protobuf::Message#set_field
3%1%2.210.941.272582641Protobuf::Field::StringField(singleton)#set_field
0.290.290.003790734/38663178Protobuf::Message::Serialization.set_field_bytes0.680.530.152582641/3873961Test::Resource#_protobuf_message_required_field_tags
1.541.540.200.20 0.0031081708/38663178##each_key2582641/2582825##delete
3%3%2.072.07
0.180.18 0.0038663178Test::Resource#_protobuf_message_field2582641/35406351##[]=
0.100.100.002582641/7748887Kernel.nil?
0.100.100.002582641/2583806##to_s
2.040.471.572527156/25271560.160.160.002582641/35406351Protobuf::Field::Int64Field(singleton)#set_field
0.170.170.002582640/35406351 Protobuf::Field::EnumField(singleton)#set_field
0.180.180.002582641/35406351Protobuf::Field::StringField(singleton)#set_field
0.810.810.0013826936/35406351Protobuf::Field::StringField(singleton)#to_message_hash
0.820.820.0013826936/35406351Protobuf::Field::Int64Field(singleton)#to_message_hash
3%3%2.152.140.0135406351##[]=
2.120.281.851291320/1291320Protobuf::Message::Serialization.set_field_bytes
3% 0%2.040.471.5725271562.120.281.851291320Protobuf::Field::StringField(singleton)#set
1.340.191.151291320/7747922Protobuf::Message#set_field
0.500.300.201291320/1291320Protobuf::Field::StringField#decode
2.110.491.622582640/2582640Protobuf::Field::EnumField(singleton)#set_field
3%0%2.110.491.622582640 Protobuf::Field::EnumField#coerce!
1.350.450.902527156/25271651.380.460.922582640/2582649 Protobuf::Enum.fetch
0.220.220.240.24 0.002527156/25277142582640/2583314 Protobuf::Field::BaseField#type_class
0.430.230.202527156/8845046Protobuf::Field::EnumField(singleton)#encode_to_stream0.260.260.003873962/39275754Protobuf::Message#set_field
0.460.220.242527156/8845046Protobuf::Field::Int64Field(singleton)#encode_to_stream0.290.290.003873960/39275754Protobuf::Message::Serialization.set_field_bytes
0.750.360.403790734/8845046Protobuf::Field::StringField(singleton)#encode_to_stream1.551.550.0031527832/39275754##each_key
2%1%1.650.810.838845046IO::GenericWritable.<<3%3%2.092.090.0039275754Test::Resource#_protobuf_message_field
0.830.830.008845046/8845046StringIO#write0.440.230.212582640/9039240Protobuf::Field::EnumField(singleton)#encode_to_stream
1.390.840.547581468/7581468Protobuf::Decoder.decode_each_field0.480.230.252582640/9039240Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.740.350.393873960/9039240Protobuf::Field::StringField(singleton)#encode_to_stream
2% 1%1.390.840.547581468Protobuf::Varint.decode1.670.820.859039240IO::GenericWritable.<<
0.540.540.850.85 0.007581468/7581468ProtobufJavaHelpers::Varinter.read_varint9039240/9039240StringIO#write
1.370.291.081263578/1263578##each_key1.440.321.121291320/1291320##each_key
2% 0%1.370.291.0812635781.440.321.121291320 Protobuf::Field::EnumField(singleton)#encode_to_stream
0.650.68 0.270.381263578/12635780.421291320/1291320 Protobuf::Field::EnumField#encode
0.430.44 0.230.202527156/88450460.212582640/9039240 IO::GenericWritable.<<
1.350.450.902527156/25271651.420.850.577747920/7747920Protobuf::Decoder.decode_each_field
2%1%1.420.850.577747920Protobuf::Varint.decode
0.570.570.007747920/7747920ProtobufJavaHelpers::Varinter.read_varint
1.380.460.922582640/2582649 Protobuf::Field::EnumField#coerce!
2% 0%1.350.450.9025271651.380.460.922582649 Protobuf::Enum.fetch
0.770.490.780.51 0.282527156/25271562582640/2582640 Protobuf::Enum.enum_for_tag_integer
0.130.130.140.14 0.002527165/25286552582649/2584139 Kernel.kind_of?
1.200.250.951263578/12635781.240.270.971291320/1291320 Protobuf::Message::Serialization.set_field_bytes
1% 0%1.200.250.9512635781.240.270.971291320 Protobuf::Field::Int64Field(singleton)#set
0.680.69 0.170.511263578/75814700.521291320/7747922 Protobuf::Message#set_field
0.270.200.071263578/12635780.280.220.061291320/1291320 Protobuf::Field::Int64Field#decode
1.090.300.791263578/1263578##each_key1.180.320.861291320/1291320##each_key
1% 0%1.090.300.7912635781.180.320.861291320 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.460.220.242527156/88450460.480.230.252582640/9039240 IO::GenericWritable.<<
0.330.210.121263578/12635780.380.240.141291320/1291320 Protobuf::Field::Int64Field#encode
1.011.05 0.001.001.05 2/115 (top)
1% 0%1.011.05 0.001.001.05 115 Kernel.require
1.001.05 0.001.001.05 115/1886 Kernel.require
0.960.580.382527157/25271570.970.600.372582641/2582641 Protobuf::Message#set_field
1% 0%0.960.580.3825271570.970.600.372582641 Protobuf::Field::Int64Field(singleton)#set_field
0.16 0.16 0.002527157/34877001##[]=2582641/35406351##[]=
0.120.120.110.11 0.002527157/25271572582641/2582641 ProtobufJavaHelpers::Int64ProtobufField.coerce!
0.100.100.002582641/7748887Kernel.nil?
0.910.450.463555260/3555260##each0.950.470.493681900/3681900##each
1% 0%0.910.450.4635552600.950.470.493681900 Benchmark::Timing.now
0.460.460.490.49 0.003555260/35552613681900/3681901 Process.clock_gettime
0.860.88 0.000.860.88 1/1 Kernel.require
1% 0%0.860.88 0.000.860.88 1 Bundler.setup
0.490.52 0.010.480.51 1/2 Bundler.definition
0.360.35 0.000.360.35 1/1 Bundler::Runtime#setup
0.170.170.180.18 0.001263578/37907351291320/3873961 Protobuf::Message#each_field_for_serialization
0.68 0.53 0.152527157/37907352582641/3873961 Protobuf::Field::StringField(singleton)#set_field
1% 1%0.850.700.860.71 0.1537907353873961 Test::Resource#_protobuf_message_required_field_tags
0.15 0.15 0.002527157/25281892582641/2583673 Kernel.dup
0.830.830.850.85 0.008845046/88450469039240/9039240 IO::GenericWritable.<<
1% 1%0.830.830.850.85 0.0088450469039240 StringIO#write
0.770.490.140.140.003681365/18790704##each
0.670.670.0015108256/18790704Benchmark::IPS::Job::Entry#call_times
1%1%0.810.810.0018790704##+
0.780.51 0.282527156/25271562582640/2582640 Protobuf::Enum.fetch
1% 0%0.770.490.780.51 0.2825271562582640 Protobuf::Enum.enum_for_tag_integer
0.15 0.15 0.002527156/72277033##[]2582640/73391217##[]
0.13 0.13 0.002527156/2527645##first
0.150.150.003554710/18454858##each
0.610.610.0014899065/18454858Benchmark::IPS::Job::Entry#call_times
1%1%0.760.760.0018454858##+2582640/2583129##first
0.700.700.710.71 0.0018453761/1845378618789607/18789624 Benchmark::IPS::Job::Entry#call_times
1% 1%0.700.700.710.71 0.0018453786##<18789624##<
0.690.480.212527157/2527157Protobuf::Field::StringField(singleton)#set_field
1%0%0.690.480.212527157Protobuf::Field::StringField#coerce!
0.120.120.002527157/2528322##to_s
0.650.68 0.270.381263578/12635780.421291320/1291320 Protobuf::Field::EnumField(singleton)#encode_to_stream
1% 0%0.650.68 0.270.3812635780.421291320 Protobuf::Field::EnumField#encode
0.280.170.111263578/12638460.310.180.141291320/1291588 Protobuf::Enum#to_i
0.100.100.001291320/2582640ProtobufJavaHelpers::Varinter.to_varint_64
0.540.540.570.57 0.007581468/75814687747920/7747920 Protobuf::Varint.decode
0% 0%0.540.540.570.57 0.0075814687747920 ProtobufJavaHelpers::Varinter.read_varint
0.530.52 0.060.470.46 17/19 (top)
0% 0%0.530.52 0.060.470.46 19 Kernel.load
0.430.42 0.030.400.39 2/1886 Kernel.require
0.490.52 0.010.480.51 1/2 Bundler.setup
0% 0%0.490.52 0.010.480.51 2 Bundler.definition
0.400.42 0.000.390.42 1/1 Bundler::Definition.build
0.490.280.221263578/12635780.500.300.201291320/1291320 Protobuf::Field::StringField(singleton)#set
0% 0%0.490.280.2212635780.500.300.201291320 Protobuf::Field::StringField#decode
0.140.140.130.13 0.001263578/2527298##+1291320/2582782##+
0.460.460.490.49 0.003555260/35552613681900/3681901 Benchmark::Timing.now
0% 0%0.460.460.490.49 0.0035552613681901 Process.clock_gettime
0.330.42 0.000.331/873Bundler::Runtime#requested_specs0.421/1Bundler.definition
0% 0%0.410.42 0.000.41873Kernel.send0.421Bundler::Definition.build
0.330.40 0.000.330.40 1/1Bundler::Definition#requested_specsBundler::Dsl.evaluate
0.400.33 0.000.391/1Bundler.definition0.331/873Bundler::Runtime#requested_specs
0% 0%0.400.41 0.000.391Bundler::Definition.build0.41873Kernel.send
0.380.33 0.000.380.33 1/1Bundler::Dsl.evaluateBundler::Definition#requested_specs
0.380.40 0.000.380.40 1/1 Bundler::Definition.build
0% 0%0.380.40 0.000.380.40 1 Bundler::Dsl.evaluate
0.290.30 0.000.290.30 1/1 Bundler::Dsl#to_definition
0.100.100.002527157/10109592Protobuf::Field::StringField(singleton)#set_field0.380.240.141291320/1291320Protobuf::Field::Int64Field(singleton)#encode_to_stream
0% 0% 0.380.380.240.141291320Protobuf::Field::Int64Field#encode
0.140.14 0.0010109592Kernel.nil?1291320/2582640ProtobufJavaHelpers::Varinter.to_varint_64
0.360.100.261263578/2527156##each_key0.370.110.271291320/2582640##each_key
0% 0%0.360.100.2625271560.370.110.272582640 Protobuf::Field::EnumField(singleton)#value_from_values
0.360.35 0.000.360.35 1/1 Bundler.setup
0% 0%0.360.35 0.000.360.35 1 Bundler::Runtime#setup
0.33 1/1 Bundler::Runtime#requested_specs
0.340.220.121291320/1291473Protobuf::Field::StringField(singleton)#encode_to_stream
0%0%0.340.220.121291473Protobuf::Field::VarintField.encode
0.120.120.001291473/1291473ProtobufJavaHelpers::Varinter.to_varint
1 Bundler::Runtime#requested_specs
0.33 1 Bundler::Definition#requested_specs
0.33 1/1 Bundler::Definition#specs_for
1 Bundler::Definition#specs_for
0.32 1/1 Bundler::Definition#specs
0.330.210.121263578/1263578Protobuf::Field::Int64Field(singleton)#encode_to_stream
0%0%0.330.210.121263578Protobuf::Field::Int64Field#encode
0.120.120.001263578/2527156ProtobufJavaHelpers::Varinter.to_varint_64
0.320.220.111263578/1263731Protobuf::Field::StringField(singleton)#encode_to_stream
0%0%0.330.220.111263731Protobuf::Field::VarintField.encode
0.110.110.001263731/1263731ProtobufJavaHelpers::Varinter.to_varint
1 Bundler::Definition#specs
0.210.20 0.000.210.20 1/1 Bundler::SpecSet#materialize
0.10 1/1 Bundler::Definition#resolve
0.290.000.291/1Bundler::Dsl.evaluate0.310.180.141291320/1291588Protobuf::Field::EnumField#encode
0% 0%0.290.000.291Bundler::Dsl#to_definition0.310.180.141291588Protobuf::Enum#to_i
0.290.010.281/2528680Class#new0.140.140.001291588/1291588Protobuf::Enum#tag
0.140.140.100.10 0.001263578/2527298Protobuf::Field::StringField#decode2582641/7748887Protobuf::Field::Int64Field(singleton)#set_field
0.140.140.100.10 0.001263578/2527298Protobuf::Field::StringField(singleton)#encode_to_stream2582641/7748887Protobuf::Field::StringField(singleton)#set_field
0% 0%0.290.290.300.30 0.002527298##+7748887Kernel.nil?
0.280.30 0.000.280.301/1Bundler::Dsl.evaluate
0%0%0.300.000.301Bundler::Dsl#to_definition
0.300.010.291/2584164Class#new
0.290.000.29 1/1 Class#new
0% 0%0.280.29 0.000.280.29 1 Bundler::Definition#initialize
0.11 1/1 Bundler::Definition#converge_paths
0.270.28 0.170.101253578/12635780.111281320/1291320 Proc#call
0% 0%0.280.180.1012635780.290.170.111291320 StringIO.new
0.100.100.110.11 0.001263578/12635781291320/1291320 StringIO#initialize
0.280.170.111263578/1263846Protobuf::Field::EnumField#encode0.220.061291320/1291320Protobuf::Field::Int64Field(singleton)#set
0% 0% 0.280.170.111263846Protobuf::Enum#to_i0.220.061291320Protobuf::Field::Int64Field#decode
0.110.110.120.12 0.001263846/1263846Protobuf::Enum#tag1291320/2582782Protobuf::Field::StringField(singleton)#encode_to_stream
0.280.280.130.13 0.005054312/5054312Protobuf::Decoder.decode_each_field1291320/2582782Protobuf::Field::StringField#decode
0% 0%0.280.280.250.25 0.005054312StringIO#eof2582782##+
0.270.200.240.17 0.071263578/1263578Protobuf::Field::Int64Field(singleton)#set1291320/1292131Protobuf::Field::StringField(singleton)#encode_to_stream
0% 0%0.270.200.071263578Protobuf::Field::Int64Field#decode0.240.170.081292131BasicObject#!=
0.250.200.240.19 0.051263578/12635781291320/1291320 Protobuf::Field::EnumField(singleton)#set
0% 0%0.250.200.240.19 0.0512635781291320 Protobuf::Field::EnumField#decode
0.220.160.061263578/1264389Protobuf::Field::StringField(singleton)#encode_to_stream
0%0%0.230.160.071264389BasicObject#!=
0.220.220.240.24 0.002527156/25277142582640/2583314 Protobuf::Field::EnumField#coerce!
0% 0%0.220.220.240.24 0.0025277142583314 Protobuf::Field::BaseField#type_class
0.120.120.100.100.001291320/2582640Protobuf::Field::EnumField#encode
0.140.14 0.001263578/25271561291320/2582640 Protobuf::Field::Int64Field#encode
0% 0%0.220.220.240.24 0.0025271562582640 ProtobufJavaHelpers::Varinter.to_varint_64
0.210.210.240.24 0.002527157/2527341Protobuf::Field::StringField(singleton)#set_field5165280/5165280Protobuf::Decoder.decode_each_field
0% 0%0.210.210.240.24 0.002527341##delete5165280StringIO#eof
0.210.210.200.20 0.005054312/50575405165280/5168510 Protobuf::Decoder.decode_each_field
0% 0%0.210.210.200.20 0.005057540##==5168510##==
0.210.200.20 0.000.212582641/2582825Protobuf::Field::StringField(singleton)#set_field
0%0%0.200.200.002582825##delete
0.200.000.20 1/1 Bundler::Definition#specs
0% 0%0.210.20 0.000.210.20 1 Bundler::SpecSet#materialize
0.130.12 0.000.130.12 109/153 Protobuf::Message::Fields::ClassMethods.optional
0% 0%0.190.18 0.00 0.18 153 Protobuf::Message::Fields::ClassMethods.define_field
0.180.17 0.000.180.17 153/153 Protobuf::Field.build
0.180.170.17 0.000.183873960/3873960Protobuf::Decoder.decode_each_field
0%0%0.170.170.003873960##>>
0.170.000.17 153/153 Protobuf::Message::Fields::ClassMethods.define_field
0% 0%0.180.17 0.000.180.17 153 Protobuf::Field.build
0.17 0.010.17153/25286800.16153/2584164 Class#new
0.180.180.170.17 0.003554700/3554700##each3681355/3681355##each
0% 0%0.180.180.170.17 0.003554700##<3681355##<
0.17 0.17 0.003790734/37907343873960/3873960 Protobuf::Decoder.decode_each_field
0.17 0.17 0.003790734##>>3873960##&
0%0%0.160.000.166Bundler::SpecSet#for
0.160.010.166/6Kernel.loop
0.170.170.003790734/3790734Protobuf::Decoder.decode_each_field0.160.010.166/6Bundler::SpecSet#for
0% 0%0.170.170.160.010.166Kernel.loop
0.14 0.003790734##&0.14215/215Bundler::SpecSet#spec_for_dependency
0.170.01 0.160.010.15 153/153 Class#new
0% 0%0.170.01 0.160.010.15 153 Protobuf::Field::BaseField#initialize
0%0%0.150.060.091137BasicObject#instance_eval
0.15 0.15 0.002527157/25281892582641/2583673 Test::Resource#_protobuf_message_required_field_tags
0.15 0.15 0.0025281892583673 Kernel.dup
0%0%0.150.070.081137BasicObject#instance_eval
0% 0% 0.14 0.030.120.11 61 Kernel.eval
0.110.030.100.02 0.0816/252868016/2584164 Class#new
0.140.000.141/1Kernel.require
0%0%0.140.000.141Gem::Specification.load_defaults
0.140.000.141/1Gem::Specification.each_spec
0.14 0.000.141/1Gem::Specification.load_defaults2582649/2584139Protobuf::Enum.fetch
0% 0% 0.140.000.141Gem::Specification.each_spec
0.14 0.000.141/1Gem::Specification.each_gemspec2584139Kernel.kind_of?
0.14 0.00 0.141/1Gem::Specification.each_spec215/215Kernel.loop
0% 0.14 0.00 0.141Gem::Specification.each_gemspec
0.140.000.141/1265137##each215Bundler::SpecSet#spec_for_dependency
0.14 0.14 0.001263578/1263578Protobuf::Decoder.decode_each_field1291588/1291588Protobuf::Enum#to_i
0% 0.14 0.14 0.001263578StringIO#read
0.140.000.13109/109Kernel.require
0%0%0.140.000.13109Protobuf::Message::Fields::ClassMethods.optional
0.130.000.13109/153Protobuf::Message::Fields::ClassMethods.define_field1291588Protobuf::Enum#tag
0.13 0.13 0.002527165/2528655Protobuf::Enum.fetch2582640/2583129Protobuf::Enum.enum_for_tag_integer
0% 0.13 0.13 0.002528655Kernel.kind_of?2583129##first
0.13 0.13 0.002527156/2527645Protobuf::Enum.enum_for_tag_integer1291320/1291320Protobuf::Decoder.decode_each_field
0% 0.13 0.13 0.002527645##first1291320StringIO#read
0%0%0.130.000.1313Bundler::SpecSet#sorted
0.130.000.134/4TSort.tsort
0% 0% 0.02 0.11 412##map!
0.130.000.134/176##to_a
0%0%0.130.000.13176Enumerator#each
0.130.000.134/8TSort.tsort_each
0.130.000.134/4Bundler::SpecSet#sorted
0%0%0.130.000.134TSort.tsort
0.130.000.134/4TSort.tsort
0.130.000.134/4TSort.tsort
0%0%0.130.000.134TSort.tsort
0.130.000.134/4##to_a
0.130.000.134/8Enumerator#each
0%0%0.130.000.138TSort.tsort_each
0.130.000.134/4TSort.each_strongly_connected_component
0.130.000.134/4TSort.tsort
0%0%0.130.000.134##to_a
0.130.000.134/176Enumerator#each
0.130.000.134/4TSort.tsort_each
0%0%0.130.000.134TSort.each_strongly_connected_component
0.130.000.134/122Method#call##map!
0.13 0.00 0.134/122TSort.each_strongly_connected_component1/1Kernel.require
0% 0.13 0.00 0.13122Method#call1Gem::Specification.load_defaults
0.130.12 0.000.134/4Bundler::SpecSet#tsort_each_node0.121/1Gem::Specification.each_spec
0.130.12 0.000.134/4Method#call0.121/1Gem::Specification.load_defaults
0% 0%0.130.12 0.000.134Bundler::SpecSet#tsort_each_node0.121Gem::Specification.each_spec
0.130.12 0.00 0.124/1265137##each1/1Gem::Specification.each_gemspec
0.120.010.11118/118##each0.000.12109/109Kernel.require
0% 0% 0.120.010.11118TSort.each_strongly_connected_component_from0.000.12109Protobuf::Message::Fields::ClassMethods.optional
0.120.12 0.002527157/2527157Protobuf::Field::Int64Field(singleton)#set_field
0%0% 0.120.120.002527157ProtobufJavaHelpers::Int64ProtobufField.coerce!109/153Protobuf::Message::Fields::ClassMethods.define_field
0.120.12 0.002527157/2528322Protobuf::Field::StringField#coerce!0.121/1Gem::Specification.each_spec
0% 0% 0.120.12 0.002528322##to_s
0%0% 0.121Gem::Specification.each_gemspec
0.12 0.002527156ProtobufJavaHelpers::IntegerProtobufField.decode_varint_640.121/1292879##each
0.00 0.12 172##any?##any?
0.11 2/2 Bundler::Definition#specs_changed?
0.110.110.120.12 0.001263846/1263846Protobuf::Enum#to_i1291473/1291473Protobuf::Field::VarintField.encode
0% 0%0.110.110.120.12 0.001263846Protobuf::Enum#tag1291473ProtobufJavaHelpers::Varinter.to_varint
0.110.00 0.1113/14##each0.001291320/1291320StringIO.new
0% 0% 0.110.00 0.1114Gem::Specification.load0.001291320StringIO#initialize
0.11 0.11 0.002527157/2527158Protobuf::Message#initialize2582641/2582641Protobuf::Field::Int64Field(singleton)#set_field
0% 0.11 0.11 0.002527158##to_hash2582641ProtobufJavaHelpers::Int64ProtobufField.coerce!
0.110.11 0.001253578/1263578Proc#call0.111/1Bundler::Definition#initialize
0% 0% 0.110.000.111Bundler::Definition#converge_paths
0.11 0.001263578Protobuf::Message#to_proto0.111/172##any?
0.110.000.112/2##any?
0%0%0.110.000.112Bundler::Definition#specs_changed?
0.11 0.001263731/1263731Protobuf::Field::VarintField.encode0.112/2Bundler::Definition#specs_for_source_changed?
0% 0% 0.11 0.11 0.001263731ProtobufJavaHelpers::Varinter.to_varint2582640ProtobufJavaHelpers::IntegerProtobufField.decode_varint_64
0.110.10 0.000.111/1Bundler::Definition#initialize0.102/5Bundler::Definition#specs_for_source_changed?
0% 0.11 0.00 0.111Bundler::Definition#converge_paths5Bundler::Source::Path#specs
0.11 0.00 0.111/172##any?5/5Bundler::Source::Path#local_specs
0.00 0.11 2/2##any?Bundler::Definition#specs_changed?
0% 0.00 0.11 2Bundler::Definition#specs_changed?Bundler::Definition#specs_for_source_changed?
0.110.10 0.000.112/2Bundler::Definition#specs_for_source_changed?0.102/5Bundler::Source::Path#specs
0.110.00 0.112/2Bundler::Definition#specs_changed?0.002582641/2582814Protobuf::Message#initialize
0% 0% 0.110.11 0.002582814Kernel.block_given?
0.112Bundler::Definition#specs_for_source_changed?0.000.115/5Bundler::Source::Path#specs
0% 0%0.100.11 0.000.100.11 5Bundler::Source::Path#specsBundler::Source::Path#local_specs
0.100.11 0.000.105/50.113/3Bundler::Source::Path#load_spec_files
0.110.000.113/3 Bundler::Source::Path#local_specs
0%0%0.110.000.113Bundler::Source::Path#load_spec_files
0.100.100.110.11 0.002527157/2527330Protobuf::Message#initialize1281320/1291320Proc#call
0% 0%0.100.100.110.11 0.002527330Kernel.block_given?1291320Protobuf::Message#to_proto
0%0%0.110.090.02449##reverse_each
0.100.100.110.11 0.001263578/1263578StringIO.new2582641/2582642Protobuf::Message#initialize
0% 0%0.100.100.110.11 0.001263578StringIO#initialize2582642##to_hash
1 Bundler::Definition#resolve
0.100.10 0.002582641/2583806Protobuf::Field::StringField(singleton)#set_field
0%0% 0.105/5Bundler::Source::Path#specs0.100.002583806##to_s
0% 0% 0.10 0.00 0.105Bundler::Source::Path#local_specs14Gem::Specification.load
@@ -67,13 +67,13 @@

Total time: 63.22

- + - + - + @@ -82,34 +82,34 @@

Total time: 63.22

- + - + - - + + - + - - - - - + + + + + - + - - - - - + + + + + - + @@ -118,153 +118,189 @@

Total time: 63.22

- + - - - - - + + + + + - + - - - + + + - + + + + + + + + + + + + + + + + + + + - - - + + + - + - + - - - - - - - - - - - - + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - + - - + + + - + + + + + + + + + - - + + + - - - - - - + + + + + - + - - - + + + - - - - - - + + + + + + - + - + + + + + + + + + + + + + + + + + + + + - - - + + - + - + + - - - + + - + - + - - - + + + - + - - - - - + + + + + - + @@ -275,7 +311,7 @@

Total time: 63.22

- + @@ -283,7 +319,7 @@

Total time: 63.22

- + @@ -292,7 +328,7 @@

Total time: 63.22

- + @@ -303,7 +339,7 @@

Total time: 63.22

- + @@ -311,144 +347,135 @@

Total time: 63.22

- + - + - + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - - + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + - + + - - - - - - - - - - + @@ -456,7 +483,7 @@

Total time: 63.22

- + @@ -467,160 +494,160 @@

Total time: 63.22

- + - + - - + + - + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - + + - - + + - + - - + + - - + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + @@ -630,7 +657,7 @@

Total time: 63.22

- + @@ -641,813 +668,1051 @@

Total time: 63.22

- + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - + + - + - + - - + + - - + + - + - - + + - - + + - + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - + + - - + + - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - + - - - + + + - + - - - - - + + + + + - + - - + + - - + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + + + + + + + + + + - + - - + + + + + + + + + + + - - + + - + - - + + - - + + - - + - - - - - + + + + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + - + - - + + - - + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - + + - - + + + + + + + + + + + - - + + - + - - + + - + - - + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - + - + - + - + - + - - + + - + - - + + + + + + + + + + + - + - - + + - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - + - - - - + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + + - - + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + - + - - + + - - + + - + - - - - + + + + - - - - - + + + + + - + - - - - + + + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - + + - - + + - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - - + + + + + + + + + + + + + - - - - + + + + - + - - + + - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + + + - + - - + + - - + + @@ -1456,978 +1721,1081 @@

Total time: 63.22

- + - + - - + + - + - - + + - + - - + + - + - + - + - + - - - + + + - + - + - + - + - + - + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + - - + + + + + + + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - + + + + - + - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - - + + - - + + - + + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - - - - - + + + + + - - - - - - - + + + + + + + + + + + + + + + + - + + + + + + + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - - - - - + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - - + + + + + - + - - + + - + - - - - - - - - - - - - - - + + + + + - + - - - - + + + + - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - + - - + + - + - - + + - + - + - - + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - - - - + + + + - - - - - - - - - - - - - - - + + + + + + - - + - - - - - - - - - - - + + - - + + - + - - + + - - + + - - + + - + - - + + - - + + - - - - - + + + + + - - - - - - - - - - - - - - + + + + + - + - - + + - - + + - - - - - + + + + + - - - + + + + + + + + + + + + - - + + - + - - - - - + + + + + - - - - - + + + + + - + - - - - + + + + - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + @@ -2448,126 +2816,89 @@

Total time: 63.22

- + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + - + - - - - - + + + + + - - - - - - - - - - - - - - + + + + + - + - + @@ -2576,10 +2907,10 @@

Total time: 63.22

- + - + @@ -2588,138 +2919,110 @@

Total time: 63.22

- + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - - - - - - - - - - - + + - - + + - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - - - - - + + + + + - - - - - + + + + + - + - - + - - + + + - + @@ -2738,13 +3041,13 @@

Total time: 63.22

- + - + @@ -2766,7 +3069,7 @@

Total time: 63.22

- + @@ -2775,7 +3078,7 @@

Total time: 63.22

- + @@ -2794,7 +3097,7 @@

Total time: 63.22

- + @@ -2803,7 +3106,26 @@

Total time: 63.22

- + + + + + + + + + + + + + + + + + + + + @@ -2822,314 +3144,317 @@

Total time: 63.22

- + - + - + - - - - - - - - - - + - - - - - + + + + + - - - - - - - - - - - - - + + + + - - + + - - + + - - + + + + + + + + + + + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + + - - - - - + + + + + + + + + + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - - + - - + + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - + - - + + + - - + + - - + + - - + + - - + + - - - - - + + + + + - + - - - - - + + + + + - + + + + + + + + + - - - + + + + - + - - + + - - + + - - + + - - + + - - - - - + + + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -3138,8 +3463,8 @@

Total time: 63.22

- - + + @@ -3147,840 +3472,827 @@

Total time: 63.22

- - + + - + - - + - - + + + - - + - - + + + - - + - + - - - + + + + + + + + + + + + + - - - - - + + + + + - + - + + - - - + + - - - + + + - + + - + + - - - + + + + + + + + + + + - + - - + + - - + + - - - + + + - - + + - + - - - + + + - + - + - + - + - - - - + + + + - + - - + - - + + + - - - - - + + + + + - - + - - - - - - - - - - - + - - + + + - + - - - - - - - - - - - - + + + - + - - - - - + + + + + - + - - + + - + - - + + - + - + - + - + - + - - - - + + + - - - - + + + + - + - - - + + + + + + + + + + + + + + + + + + + + + - - + + + - - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - - - - - + + + + + - + - + + - - - + + - + + - - - + + - + + - - - + + + - - - + + - + - - + - - + + + - - + - - + + + - - + - - - - - - - - - - - + - - + + + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - - - - - - - - - - + - - - - - + + + + + - + - - - - - + + + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - + - + - + - + - - - + + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - - + + - - + + - - + + - - + + - + - - + - - + + + - - + + + + + + + + + + - - + + + - + - - + + - - + + - - + + - - + + - + + - - - + + - - - - - - - - - - + + - - - + + - + - + - - - + + + - + - - - + + + - + + + - - - - + + - + - - + + - - + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - - + - - + + + - - + - - + + + + + + + + + + + + - + - - - + + + - + - - - + + + - + - + - - - + + + + + - - - - + + + + - - - - + + - + - - - + + + - - - - - - - - - - - - + + - - + - - - - - - - - - - - + + - + - - + + - + - - - + + + - + - - + + @@ -3988,1228 +4300,1207 @@

Total time: 63.22

- - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + - - - - + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - - - - - + + + + + + + + + + - - - + + + + + + + + + + + - - - - - + - - - - + + + + - - - + + + + + - + - - - - + + + + + + - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + - - + + + + - + + + - - + + - - + + - - - - - - - - - - - - - - + + - - + + + - - + - + + + + + - - - - - - + + + - - + + + + + + + + - - - + + + + + - - - + - - - - - - + - - - - - - - + + - - - + + + - - - + + + + + + - - + + + - - - - - + + + + + + - - + - - + + + + + + + + + + + + + + - - - - - - - + + - + + + + + + + + + + + + + + + - - - - + + - + + + + - - - - - + - + + + - - - - - - - - - + + + + - - + - - + + + + - + + - - - - - - - - + - + + + + - - + + - - - - - - - + + - - - - - - - + + + + - - + + - - - - - + + + - + + + - + + - - - - - - + + + + - - - - + - + + + + - - + + - - - - - - - - + + + + + + + + + - - - - - + + + - + + + + + + + + + + + + + + + - - + + + - - - - - - + + - - - - - - + + + - + + - + + + - - - - - + + + + - + + + + - - + - + + + + + + - - - + + + + - + + - - - - + + + + + + + - - - - + + + + - + - - - + + - + + + + - - - - - + + - - - - - + + + + + + - - - - + + + + - - - - - - - - - - + - - - - - - - - - - + - - - - + + + + + - - + - - - - - - + + - + + + + + - + + + + - - - + + - - + + + + + + - - - - - - + - + + + - + - + - - - - + + - + - - - + + + - + - - - - - + - - - + - + + + + + - - - - - + + + + + + + + + + - - + + - - - - - - + - - - - - + + + + - - - + - + + + + - - - - - + - - - - - - - - - - + + + + + + + + + - - + + - + + - - - - - - - + + - + + - - + - - - - - + + - - - + - + - + + - + + + + + - - + + - + + + - - - - + - - - - + + + + + - - - - + + - - - + - - - + + + - + + + + + - @@ -5218,18 +5509,17 @@

Total time: 63.22

+ + - - - + - - + @@ -5237,23 +5527,23 @@

Total time: 63.22

+ + + + - + + - - - - - @@ -5261,17 +5551,19 @@

Total time: 63.22

+ + + - @@ -5282,7 +5574,6 @@

Total time: 63.22

- @@ -5295,6 +5586,8 @@

Total time: 63.22

+ + @@ -5307,18 +5600,17 @@

Total time: 63.22

- + + + - - - @@ -5328,6 +5620,7 @@

Total time: 63.22

+ @@ -5339,11 +5632,9 @@

Total time: 63.22

- - @@ -5353,14 +5644,15 @@

Total time: 63.22

+ + - - + @@ -5369,12 +5661,12 @@

Total time: 63.22

- + From 71b2fc09951d042d8d24470de9e3353b94144f22 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Dec 2018 13:11:13 -0700 Subject: [PATCH 1122/1191] move the const setting to the module fields --- lib/protobuf/message.rb | 8 -------- lib/protobuf/message/fields.rb | 11 +++++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 412732f1..3ff3115e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -193,14 +193,6 @@ def set_field(name, value, ignore_nil_for_repeated, field = nil) end end - def _protobuf_message_field - @_protobuf_message_field ||= self.class.field_store - end - - def _protobuf_message_required_field_tags - @_protobuf_message_required_field_tags ||= self.class.required_field_tags - end - ## # Instance Aliases # diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 268851a8..87793c5c 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -20,6 +20,17 @@ def self.extended(other) module ClassMethods def inherited(subclass) inherit_fields!(subclass) + subclass.const_set("PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS", subclass.required_field_tags) + subclass.const_set("PROTOBUF_MESSAGE_GET_FIELD", subclass.field_store) + subclass.class_eval <<~RUBY, __FILE__, __LINE__ + def _protobuf_message_field + PROTOBUF_MESSAGE_GET_FIELD + end + + def _protobuf_message_required_field_tags + @_protobuf_message_required_field_tags ||= PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS.dup + end + RUBY end ## From c54ae743e3873481211bced3bfdad526286e261a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 31 Dec 2018 11:03:52 -0700 Subject: [PATCH 1123/1191] fixing specs for refactor --- lib/protobuf.rb | 7 ------- .../field/base_field_method_definitions.rb | 14 +++++++++++--- lib/protobuf/field/string_field.rb | 4 +++- lib/protobuf/varint.rb | 6 ------ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 3f9b7e91..148b1170 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -10,13 +10,6 @@ require 'active_support/json' require 'active_support/notifications' -# rubocop:disable Lint/HandleExceptions -begin - require 'protobuf_java_helpers' -rescue LoadError -end -# rubocop:enable Lint/HandleExceptions - # All top-level run time code requires, ordered by necessity require 'protobuf/wire_type' diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 2ff4786c..a19b1a96 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -231,7 +231,11 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) message_instance._protobuf_message_required_field_tags << #{selph.tag} else message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) - values[#{fully_qualified_name_string(selph)}] = value.to_s + values[#{fully_qualified_name_string(selph)}] = if value.is_a?(String) + value + else + coerce!(value) + end end end RUBY @@ -241,7 +245,11 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? values.delete(#{fully_qualified_name_string(selph)}) else - values[#{fully_qualified_name_string(selph)}] = value.to_s + values[#{fully_qualified_name_string(selph)}] = if value.is_a?(String) + value + else + coerce!(value) + end end end RUBY @@ -335,7 +343,7 @@ def value_from_values(values) def value_from_values_for_serialization(values) value = value_from_values(values) - array = Array.new(value.size) + array = [] value.each do |k, v| array << type_class.new(:key => k, :value => v) end diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 055ace43..6c9c278f 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -21,8 +21,10 @@ def acceptable?(val) def coerce!(value) if value.nil? nil - else + elsif acceptable?(value) value.to_s + else + fail TypeError, "Unacceptable value #{value} for field #{name} of type #{type_class}" end end diff --git a/lib/protobuf/varint.rb b/lib/protobuf/varint.rb index 1012d658..fef5e953 100644 --- a/lib/protobuf/varint.rb +++ b/lib/protobuf/varint.rb @@ -2,12 +2,6 @@ module Protobuf class Varint if defined?(::Varint) extend ::Varint - elsif defined?(::ProtobufJavaHelpers) - extend ::ProtobufJavaHelpers::Varinter - - def self.decode(stream) - read_varint(stream) - end else extend VarintPure end From 451384755d6e0bb4ccc190d742c959c6aa763263 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 31 Dec 2018 13:34:53 -0700 Subject: [PATCH 1124/1191] fix specs and keep the cops happy --- .rubocop.yml | 2 ++ lib/protobuf/code_generator.rb | 4 ++++ lib/protobuf/field/base_field.rb | 6 +----- lib/protobuf/field/bool_field.rb | 2 +- lib/protobuf/message.rb | 4 +++- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9972b631..e0cad4be 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,8 @@ AllCops: DisplayCopNames: true Exclude: - 'spec/support/protos/*.pb.rb' + - 'lib/protobuf/field/base_field_method_definitions.rb' + - 'varint_prof.rb' Lint/EndAlignment: AlignWith: keyword diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 230a7501..7b04a32c 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -50,6 +50,9 @@ def response_bytes end Protobuf::Field::BaseField.module_eval do + def define_set_method! + end + def set_without_options(message_instance, bytes) return message_instance[name] = decode(bytes) unless repeated? @@ -98,6 +101,7 @@ def set_with_options(message_instance, bytes) set_without_options(message_instance, bytes) end + alias_method :set, :set_with_options def option_set(message_field, subfield, subvalue) return unless yield diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 689b23ca..a219a462 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -22,7 +22,7 @@ class BaseField ## # Attributes # - attr_reader :message_class, :name, :fully_qualified_name, :options, :rule, :tag, :type_class + attr_reader :default_value, :message_class, :name, :fully_qualified_name, :options, :rule, :tag, :type_class ## # Class Methods @@ -104,10 +104,6 @@ def set_default_value! end end - def default_value - @default_value - end - def define_encode_to_stream! if repeated? && packed? ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_packed_encode_to_stream_method!(self) diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index b325acfd..bba089f4 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -3,7 +3,7 @@ module Protobuf module Field class BoolField < VarintField - ONE = 1.freeze + ONE = 1 FALSE_ENCODE = [0].pack('C') FALSE_STRING = "false".freeze FALSE_VALUES = [false, FALSE_STRING].freeze diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 3ff3115e..d1db6551 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -186,7 +186,9 @@ def []=(name, value) end def set_field(name, value, ignore_nil_for_repeated, field = nil) - if (field || field = _protobuf_message_field[name]) + field ||= _protobuf_message_field[name] + + if field field.set_field(@values, value, ignore_nil_for_repeated, self) else fail(::Protobuf::FieldNotDefinedError, name) unless ::Protobuf.ignore_unknown_fields? From 400b1d3ca23ebbf36ca255ad172a449661838b16 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 31 Dec 2018 13:46:05 -0700 Subject: [PATCH 1125/1191] specs and cops passing --- .rubocop.yml | 1 - .../field/base_field_method_definitions.rb | 104 +++++++++--------- lib/protobuf/message/fields.rb | 2 +- 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e0cad4be..310aa0c8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,6 @@ AllCops: DisplayCopNames: true Exclude: - 'spec/support/protos/*.pb.rb' - - 'lib/protobuf/field/base_field_method_definitions.rb' - 'varint_prof.rb' Lint/EndAlignment: diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index a19b1a96..069ee40e 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -12,7 +12,7 @@ def self.fully_qualified_name_string(selph) end def self.define_to_hash_value_to_message_hash!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def to_message_hash(values, result) result[#{selph.name.inspect}] = value_from_values(values).to_hash_value end @@ -20,7 +20,7 @@ def to_message_hash(values, result) end def self.define_base_to_message_hash!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def to_message_hash(values, result) result[#{selph.name.inspect}] = value_from_values(values) end @@ -28,7 +28,7 @@ def to_message_hash(values, result) end def self.define_repeated_packed_encode_to_stream_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) packed_value = value.map { |val| encode(val) }.join stream << #{selph.tag_encoded.dump} << "\#{::Protobuf::Field::VarintField.encode(packed_value.size)}\#{packed_value}" @@ -37,7 +37,7 @@ def encode_to_stream(value, stream) end def self.define_bytes_encode_to_stream_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) value = value.encode if value.is_a?(::Protobuf::Message) byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) @@ -48,7 +48,7 @@ def encode_to_stream(value, stream) end def self.define_string_encode_to_stream_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) new_value = "" + value if new_value.encoding != ::Protobuf::Field::StringField::ENCODING @@ -61,7 +61,7 @@ def encode_to_stream(value, stream) end def self.define_base_encode_to_stream_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) stream << #{selph.tag_encoded.dump} << encode(value) end @@ -69,7 +69,7 @@ def encode_to_stream(value, stream) end def self.define_repeated_not_packed_encode_to_stream_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def encode_to_stream(value, stream) value.each do |val| stream << #{selph.tag_encoded.dump} << encode(val) @@ -79,7 +79,7 @@ def encode_to_stream(value, stream) end def self.define_base_set_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) message_instance.set_field("#{selph.name}", decode(bytes), true, self) end @@ -87,7 +87,7 @@ def set(message_instance, bytes) end def self.define_map_set_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) hash = message_instance["#{selph.name}"] entry = decode(bytes) @@ -100,7 +100,7 @@ def set(message_instance, bytes) end def self.define_repeated_not_packed_set_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) message_instance["#{selph.name}"] << decode(bytes) end @@ -108,7 +108,7 @@ def set(message_instance, bytes) end def self.define_repeated_packed_set_method!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set(message_instance, bytes) array = message_instance["#{selph.name}"] stream = ::StringIO.new(bytes) @@ -126,7 +126,7 @@ def set(message_instance, bytes) def self.define_map_set_field!(selph) if selph.required? - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set_field(values, value, ignore_nil_for_repeated, message_instance) unless value.is_a?(Hash) fail TypeError, <<-TYPE_ERROR @@ -146,7 +146,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) end RUBY else - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set_field(values, value, ignore_nil_for_repeated, message_instance) unless value.is_a?(Hash) fail TypeError, <<-TYPE_ERROR @@ -166,36 +166,40 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) end end - def self.define_repeated_set_field!(selph) - if selph.required? - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - if value.nil? && ignore_nil_for_repeated - ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") - return - end + def self.define_required_repeated_set_field!(selph) + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 + def set_field(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? && ignore_nil_for_repeated + ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") + return + end - unless value.is_a?(Array) - fail TypeError, <<-TYPE_ERROR - Expected repeated value of type '#{selph.type_class}' - Got '\#{value.class}' for repeated protobuf field #{selph.name} - TYPE_ERROR - end + unless value.is_a?(Array) + fail TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{selph.type_class}' + Got '\#{value.class}' for repeated protobuf field #{selph.name} + TYPE_ERROR + end - value = value.compact + value = value.compact - if value.empty? - values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_required_field_tags << #{selph.tag} - else - message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) - values[#{fully_qualified_name_string(selph)}].replace(value) - end + if value.empty? + values.delete(#{fully_qualified_name_string(selph)}) + message_instance._protobuf_message_required_field_tags << #{selph.tag} + else + message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) + values[#{fully_qualified_name_string(selph)}].replace(value) end - RUBY + end + RUBY + end + + def self.define_repeated_set_field!(selph) + if selph.required? + define_required_repeated_set_field!(selph) else - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? && ignore_nil_for_repeated ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") @@ -224,7 +228,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) def self.define_string_set_field!(selph) if selph.required? - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? values.delete(#{fully_qualified_name_string(selph)}) @@ -240,7 +244,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) end RUBY else - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? values.delete(#{fully_qualified_name_string(selph)}) @@ -258,7 +262,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) def self.define_base_set_field!(selph) if selph.required? - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? values.delete(#{fully_qualified_name_string(selph)}) @@ -270,7 +274,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) end RUBY else - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? values.delete(#{fully_qualified_name_string(selph)}) @@ -283,7 +287,7 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) end def self.define_base_field_and_present_p!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def field_and_present?(values) values[#{fully_qualified_name_string(selph)}].present? end @@ -291,7 +295,7 @@ def field_and_present?(values) end def self.define_bool_field_and_present_p!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 BOOL_VALUES = [true, false].freeze unless defined?(BOOL_VALUES) def field_and_present?(values) @@ -301,7 +305,7 @@ def field_and_present?(values) end def self.define_base_field_p!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def field?(values) values.key?(#{fully_qualified_name_string(selph)}) end @@ -309,7 +313,7 @@ def field?(values) end def self.define_repeated_field_p!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def field?(values) values.key?(#{fully_qualified_name_string(selph)}) && values[#{fully_qualified_name_string(selph)}].present? end @@ -317,7 +321,7 @@ def field?(values) end def self.define_bool_field_value_from_values!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def value_from_values(values) values.fetch(#{fully_qualified_name_string(selph)}) { default_value } end @@ -326,7 +330,7 @@ def value_from_values(values) end def self.define_field_value_from_values!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def value_from_values(values) values[#{fully_qualified_name_string(selph)}] || default_value end @@ -335,7 +339,7 @@ def value_from_values(values) end def self.define_map_value_from_values!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def value_from_values(values) values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) end @@ -354,7 +358,7 @@ def value_from_values_for_serialization(values) end def self.define_repeated_value_from_values!(selph) - selph.instance_eval <<~RUBY, __FILE__, __LINE__ + 1 + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def value_from_values(values) values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 87793c5c..f3c51012 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -22,7 +22,7 @@ def inherited(subclass) inherit_fields!(subclass) subclass.const_set("PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS", subclass.required_field_tags) subclass.const_set("PROTOBUF_MESSAGE_GET_FIELD", subclass.field_store) - subclass.class_eval <<~RUBY, __FILE__, __LINE__ + subclass.class_eval <<-RUBY, __FILE__, __LINE__ def _protobuf_message_field PROTOBUF_MESSAGE_GET_FIELD end From e41fe3c0dce42f1c9528bf9c2a1bb723f0af6b9d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 2 Jan 2019 13:30:12 -0700 Subject: [PATCH 1126/1191] remove empty string --- .../field/base_field_method_definitions.rb | 1 - varint_prof.rb | 22 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 069ee40e..0b2484dc 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -3,7 +3,6 @@ module Field class BaseFieldMethodDefinitions def self.fully_qualified_name_string(selph) - fully_qualified_name = "" fully_qualified_name << ":" fully_qualified_name << '"' if selph.fully_qualified_name.to_s.start_with?(".") fully_qualified_name << selph.fully_qualified_name.to_s diff --git a/varint_prof.rb b/varint_prof.rb index 056a1d96..dedf95a8 100644 --- a/varint_prof.rb +++ b/varint_prof.rb @@ -52,19 +52,27 @@ printer.printProfile(STDOUT) else TO_HASH = ::Test::Resource.new(:name => "derp", :date_created => 123456789) + ENCODE = ::Test::Resource.new(:name => "derp", :date_created => 123456789) + DECODE = begin + ss = StringIO.new + ::Protobuf::Encoder.encode(ENCODE.to_proto, ss) + ss.rewind + ss.string + end + Benchmark.ips do |x| x.config(:time => 20, :warmup => 10) - x.report("to_hash => true java") do + x.report("to_hash") do TO_HASH.to_hash end - x.report("to_proto => true java") do - t = ::Test::Resource.new(:name => "derp", :date_created => 123456789) - t.status = 3 + x.report("encode") do ss = StringIO.new - ::Protobuf::Encoder.encode(t.to_proto, ss) - ss.rewind - t2 = ::Test::Resource.decode_from(ss) + ::Protobuf::Encoder.encode(ENCODE.to_proto, ss) + end + + x.report("decode") do + ::Test::Resource.decode_from(::StringIO.new(DECODE.dup)) end end end From 964ab0ad9c995a2f33da85ed87cc5641aef57a47 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 4 Jan 2019 11:41:02 -0700 Subject: [PATCH 1127/1191] load protobuf helpers if present and use the java encode/decode and fix minor issues with perf in to_i enum and fix a typo --- lib/protobuf.rb | 14 +++++++++++ lib/protobuf/enum.rb | 13 ++++------ .../field/base_field_method_definitions.rb | 2 +- lib/protobuf/field/varint_field.rb | 25 ++----------------- lib/protobuf/message.rb | 10 -------- lib/protobuf/varint.rb | 11 ++++++++ lib/protobuf/varint_pure.rb | 18 +++++++++++++ 7 files changed, 51 insertions(+), 42 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 148b1170..a1300025 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -9,6 +9,20 @@ require 'active_support/inflector' require 'active_support/json' require 'active_support/notifications' +# Under MRI, this optimizes proto decoding by around 15% in tests. +# When unavailable, we fall to pure Ruby. +# rubocop:disable Lint/HandleExceptions +begin + require 'varint/varint' +rescue LoadError +end +# rubocop:enable Lint/HandleExceptions +# rubocop:disable Lint/HandleExceptions +begin + require 'protobuf_java_helpers' +rescue LoadError +end +# rubocop:enable Lint/HandleExceptions # All top-level run time code requires, ordered by necessity require 'protobuf/wire_type' diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index c38b216b..c0a2a809 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -313,10 +313,6 @@ def inspect "\#" end - def to_i - tag - end - def to_int tag.to_int end @@ -357,12 +353,13 @@ def try(*args, &block) end end - ::Protobuf.deprecator.define_deprecated_methods(self, :value => :to_i) - ## # Instance Aliases # - alias :to_hash_value to_i - alias :to_json_hash_value to_i + alias :to_i tag + alias :to_hash_value tag + alias :to_json_hash_value tag + + ::Protobuf.deprecator.define_deprecated_methods(self, :value => :to_i) end end diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index 0b2484dc..e9053919 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -3,7 +3,7 @@ module Field class BaseFieldMethodDefinitions def self.fully_qualified_name_string(selph) - fully_qualified_name << ":" + fully_qualified_name = ":" fully_qualified_name << '"' if selph.fully_qualified_name.to_s.start_with?(".") fully_qualified_name << selph.fully_qualified_name.to_s fully_qualified_name << '"' if selph.fully_qualified_name.to_s.start_with?(".") diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 02a8cddc..3372094e 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -7,8 +7,6 @@ class VarintField < BaseField ## # Constants # - - CACHE_LIMIT = 2048 INT32_MAX = 2**31 - 1 INT32_MIN = -2**31 INT64_MAX = 2**63 - 1 @@ -24,27 +22,8 @@ def self.default 0 end - # Because all tags and enums are calculated as VarInt it is "most common" to have - # values < CACHE_LIMIT (low numbers) which is defaulting to 1024 - def self.cached_varint(value) - @_varint_cache ||= {} - (@_varint_cache[value] ||= encode(value, false)).dup - end - - def self.encode(value, use_cache = true) - return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT - - bytes = [] - until value < 128 - bytes << (0x80 | (value & 0x7f)) - value >>= 7 - end - (bytes << value).pack('C*') - end - - # Load the cache of VarInts on load of file - (0..CACHE_LIMIT).each do |cached_value| - cached_varint(cached_value) + def self.encode(value) + ::Protobuf::Varint.encode(value) end ## diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index d1db6551..cc73ff6d 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,15 +1,5 @@ require 'protobuf/message/fields' require 'protobuf/message/serialization' - -# Under MRI, this optimizes proto decoding by around 15% in tests. -# When unavailable, we fall to pure Ruby. -# rubocop:disable Lint/HandleExceptions -begin - require 'varint/varint' -rescue LoadError -end -# rubocop:enable Lint/HandleExceptions - require 'protobuf/varint' module Protobuf diff --git a/lib/protobuf/varint.rb b/lib/protobuf/varint.rb index fef5e953..be70cca3 100644 --- a/lib/protobuf/varint.rb +++ b/lib/protobuf/varint.rb @@ -2,6 +2,17 @@ module Protobuf class Varint if defined?(::Varint) extend ::Varint + + def self.encode(value) + bytes = [] + until value < 128 + bytes << (0x80 | (value & 0x7f)) + value >>= 7 + end + (bytes << value).pack('C*') + end + elsif defined?(::ProtobufJavaHelpers) + extend ::ProtobufJavaHelpers::EncodeDecode else extend VarintPure end diff --git a/lib/protobuf/varint_pure.rb b/lib/protobuf/varint_pure.rb index eeffbecc..6013241c 100644 --- a/lib/protobuf/varint_pure.rb +++ b/lib/protobuf/varint_pure.rb @@ -1,5 +1,12 @@ module Protobuf module VarintPure + CACHE_LIMIT = 2048 + + def cached_varint(value) + @_varint_cache ||= {} + (@_varint_cache[value] ||= encode(value, false)).dup + end + def decode(stream) value = index = 0 begin @@ -9,5 +16,16 @@ def decode(stream) end while (byte & 0x80).nonzero? value end + + def encode(value, use_cache = true) + return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT + + bytes = [] + until value < 128 + bytes << (0x80 | (value & 0x7f)) + value >>= 7 + end + (bytes << value).pack('C*') + end end end From 801553b026ce37134ee78b0afe930d20d240adfc Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 4 Jan 2019 12:03:29 -0700 Subject: [PATCH 1128/1191] fix some of our install and travis issues --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f0153d97..f89eb2e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ before_install: - java -Xmx1g -version - javac -J-Xmx1g -version - export JRUBY_OPTS=-J-Xmx1g - # Required for rainbow installation issue, https://github.com/sickill/rainbow/issues/44 - - gem update --system - gem update bundler language: ruby rvm: @@ -20,10 +18,11 @@ rvm: - 2.0.0 - 2.1 - 2.2 - - 2.2.2 - 2.3 - 2.4 - - jruby-9.1.7.0 + - 2.5 + - jruby-9.1.17.0 + - jruby-9.2.5.0 - rbx-2 env: - PROTOBUF_VERSION=2.6.1 From a993f92125642126096a610e310cc032981b1c79 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jan 2019 13:36:56 -0700 Subject: [PATCH 1129/1191] change tags names to reflect only unset field tags --- lib/protobuf/field/base_field.rb | 1 - .../field/base_field_method_definitions.rb | 16 ++++++++-------- lib/protobuf/message.rb | 2 +- lib/protobuf/message/fields.rb | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index a219a462..f8dba7a3 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -69,7 +69,6 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl define_to_message_hash! define_encode_to_stream! set_default_value! - tag_encoded end ## diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index e9053919..afbae3cf 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -136,9 +136,9 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.empty? values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_required_field_tags << #{selph.tag} + message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} else - message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) values[#{fully_qualified_name_string(selph)}].replace(value) end @@ -184,9 +184,9 @@ def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.empty? values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_required_field_tags << #{selph.tag} + message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} else - message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) values[#{fully_qualified_name_string(selph)}].replace(value) end @@ -231,9 +231,9 @@ def self.define_string_set_field!(selph) def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_required_field_tags << #{selph.tag} + message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} else - message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) values[#{fully_qualified_name_string(selph)}] = if value.is_a?(String) value else @@ -265,9 +265,9 @@ def self.define_base_set_field!(selph) def set_field(values, value, ignore_nil_for_repeated, message_instance) if value.nil? values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_required_field_tags << #{selph.tag} + message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} else - message_instance._protobuf_message_required_field_tags.delete(#{selph.tag}) + message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) values[#{fully_qualified_name_string(selph)}] = coerce!(value) end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index cc73ff6d..a57329dc 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -70,7 +70,7 @@ def each_field end def each_field_for_serialization - _protobuf_message_required_field_tags.each do |tag| + _protobuf_message_unset_required_field_tags.each do |tag| fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{_protobuf_message_field[tag].name} does not have a value." end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index f3c51012..d07e1eff 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -27,8 +27,8 @@ def _protobuf_message_field PROTOBUF_MESSAGE_GET_FIELD end - def _protobuf_message_required_field_tags - @_protobuf_message_required_field_tags ||= PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS.dup + def _protobuf_message_unset_required_field_tags + @_protobuf_message_unset_required_field_tags ||= PROTOBUF_MESSAGE_REQUIRED_FIELD_TAGS.dup end RUBY end From b05b1922439ec6010b9ec7699f8e25f7cf855c4d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 14 Jan 2019 19:34:24 -0700 Subject: [PATCH 1130/1191] build a string keys version of to_hash for protobuf object --- lib/protobuf/field/base_field.rb | 2 ++ .../field/base_field_method_definitions.rb | 16 ++++++++++++++++ lib/protobuf/message.rb | 11 +++++++++++ varint_prof.rb | 4 ++++ 4 files changed, 33 insertions(+) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index a219a462..ae076435 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -161,8 +161,10 @@ def define_set_field! def define_to_message_hash! if message? || enum? || repeated? || map? ::Protobuf::Field::BaseFieldMethodDefinitions.define_to_hash_value_to_message_hash!(self) + ::Protobuf::Field::BaseFieldMethodDefinitions.define_to_hash_value_to_message_hash_with_string_key!(self) else ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_to_message_hash!(self) + ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_to_message_hash_with_string_key!(self) end end diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb index e9053919..6a79db7f 100644 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ b/lib/protobuf/field/base_field_method_definitions.rb @@ -10,6 +10,22 @@ def self.fully_qualified_name_string(selph) fully_qualified_name end + def self.define_to_hash_value_to_message_hash_with_string_key!(selph) + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 + def to_message_hash_with_string_key(values, result) + result["#{selph.name}"] = value_from_values(values).to_hash_value + end + RUBY + end + + def self.define_base_to_message_hash_with_string_key!(selph) + selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 + def to_message_hash_with_string_key(values, result) + result["#{selph.name}"] = value_from_values(values) + end + RUBY + end + def self.define_to_hash_value_to_message_hash!(selph) selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def to_message_hash(values, result) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index cc73ff6d..b49214f0 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -122,6 +122,17 @@ def to_hash result end + def to_hash_with_string_keys + result = {} + + @values.each_key do |field_name| + field = _protobuf_message_field[field_name] + field.to_message_hash_with_string_key(@values, result) + end + + result + end + def to_json(options = {}) to_json_hash.to_json(options) end diff --git a/varint_prof.rb b/varint_prof.rb index dedf95a8..ddd9abbb 100644 --- a/varint_prof.rb +++ b/varint_prof.rb @@ -66,6 +66,10 @@ TO_HASH.to_hash end + x.report("to_hash_with_string_keys") do + TO_HASH.to_hash_with_string_keys + end + x.report("encode") do ss = StringIO.new ::Protobuf::Encoder.encode(ENCODE.to_proto, ss) From faaaca217d00b73e3c5ca68372aad5052f359d34 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 15 Jan 2019 13:33:14 -0700 Subject: [PATCH 1131/1191] remove all meta programming --- lib/protobuf/field/base_field.rb | 194 +- .../field/base_field_method_definitions.rb | 386 - .../field/base_field_object_definitions.rb | 504 ++ lib/protobuf/field/varint_field.rb | 14 +- profile.html | 6686 ++++++++--------- 5 files changed, 3682 insertions(+), 4102 deletions(-) delete mode 100644 lib/protobuf/field/base_field_method_definitions.rb create mode 100644 lib/protobuf/field/base_field_object_definitions.rb diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 7054b2e4..66b5076b 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,7 +1,7 @@ require 'active_support/core_ext/hash/slice' require 'protobuf/field/field_array' require 'protobuf/field/field_hash' -require 'protobuf/field/base_field_method_definitions' +require 'protobuf/field/base_field_object_definitions' module Protobuf module Field @@ -12,7 +12,7 @@ class BaseField ## # Constants # - + OBJECT_MODULE = ::Protobuf::Field::BaseFieldObjectDefinitions PACKED_TYPES = [ ::Protobuf::WireType::VARINT, ::Protobuf::WireType::FIXED32, @@ -61,9 +61,20 @@ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simpl define_accessor(simple_name, fully_qualified_name) if simple_name set_repeated_message! set_map! - define_hash_accessor_for_message! - define_field_p! - define_field_and_present_p! + @value_from_values = nil + @value_from_values_for_serialization = nil + @field_predicate = nil + @field_and_present_predicate = nil + @set_field = nil + @set_method = nil + @to_message_hash = nil + @to_message_hash_string_keys = nil + @encode_to_stream = nil + + define_value_from_values! + define_value_from_values_for_serialization! + define_field_predicate! + define_field_and_present_predicate! define_set_field! define_set_method! define_to_message_hash! @@ -104,69 +115,121 @@ def set_default_value! end def define_encode_to_stream! - if repeated? && packed? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_packed_encode_to_stream_method!(self) - elsif repeated? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_not_packed_encode_to_stream_method!(self) - elsif message? || type_class == ::Protobuf::Field::BytesField - ::Protobuf::Field::BaseFieldMethodDefinitions.define_bytes_encode_to_stream_method!(self) - elsif type_class == ::Protobuf::Field::StringField - ::Protobuf::Field::BaseFieldMethodDefinitions.define_string_encode_to_stream_method!(self) - else - ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_encode_to_stream_method!(self) - end + @encode_to_stream = if repeated? && packed? + OBJECT_MODULE::RepeatedPackedEncodeToStream.new(self) + elsif repeated? + OBJECT_MODULE::RepeatedNotPackedEncodeToStream.new(self) + elsif message? || type_class == ::Protobuf::Field::BytesField + OBJECT_MODULE::BytesEncodeToStream.new(self) + elsif type_class == ::Protobuf::Field::StringField + OBJECT_MODULE::StringEncodeToStream.new(self) + else + OBJECT_MODULE::BaseEncodeToStream.new(self) + end + end + + def encode_to_stream(value, stream) + @encode_to_stream.call(value, stream) + end + + def define_field_predicate! + @field_predicate = if repeated? + OBJECT_MODULE::RepeatedFieldPredicate.new(self) + else + OBJECT_MODULE::BaseFieldPredicate.new(self) + end end - def define_field_p! - if repeated? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_field_p!(self) - else - ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_field_p!(self) - end + def field?(values) + @field_predicate.call(values) end - def define_field_and_present_p! - if type_class == ::Protobuf::Field::BoolField # boolean present check - ::Protobuf::Field::BaseFieldMethodDefinitions.define_bool_field_and_present_p!(self) - else - ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_field_and_present_p!(self) - end + def define_field_and_present_predicate! + @field_and_present_predicate = if type_class == ::Protobuf::Field::BoolField # boolean present check + OBJECT_MODULE::BoolFieldAndPresentPredicate.new(self) + else + OBJECT_MODULE::BaseFieldAndPresentPredicate.new(self) + end end - def define_hash_accessor_for_message! - if map? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_value_from_values!(self) - elsif repeated? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_value_from_values!(self) - elsif type_class == ::Protobuf::Field::BoolField # boolean present check - ::Protobuf::Field::BaseFieldMethodDefinitions.define_bool_field_value_from_values!(self) - else - ::Protobuf::Field::BaseFieldMethodDefinitions.define_field_value_from_values!(self) - end + def field_and_present?(values) + @field_and_present_predicate.call(values) + end + + def define_value_from_values! + @value_from_values = if map? + OBJECT_MODULE::MapValueFromValues.new(self) + elsif repeated? + OBJECT_MODULE::RepeatedFieldValueFromValues.new(self) + elsif type_class == ::Protobuf::Field::BoolField # boolean present check + OBJECT_MODULE::BoolFieldValueFromValues.new(self) + else + OBJECT_MODULE::BaseFieldValueFromValues.new(self) + end + end + + def value_from_values(values) + @value_from_values.call(values) + end + + def define_value_from_values_for_serialization! + @value_from_values_for_serialization = if map? + OBJECT_MODULE::MapValueFromValuesForSerialization.new(self) + elsif repeated? + OBJECT_MODULE::RepeatedFieldValueFromValuesForSerialization.new(self) + elsif type_class == ::Protobuf::Field::BoolField # boolean present check + OBJECT_MODULE::BoolFieldValueFromValuesForSerialization.new(self) + else + OBJECT_MODULE::BaseFieldValueFromValuesForSerialization.new(self) + end + end + + def value_from_values_for_serialization(values) + @value_from_values_for_serialization.call(values) end def define_set_field! - if map? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_set_field!(self) - elsif repeated? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_set_field!(self) - elsif type_class == ::Protobuf::Field::StringField - ::Protobuf::Field::BaseFieldMethodDefinitions.define_string_set_field!(self) - else - ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_set_field!(self) - end + @set_field = if map? && required? + OBJECT_MODULE::RequiredMapSetField.new(self) + elsif repeated? && required? + OBJECT_MODULE::RequiredRepeatedSetField.new(self) + elsif type_class == ::Protobuf::Field::StringField && required? + OBJECT_MODULE::RequiredStringSetField.new(self) + elsif required? + OBJECT_MODULE::RequiredBaseSetField.new(self) + elsif map? + OBJECT_MODULE::MapSetField.new(self) + elsif repeated? + OBJECT_MODULE::RepeatedSetField.new(self) + elsif type_class == ::Protobuf::Field::StringField + OBJECT_MODULE::StringSetField.new(self) + else + OBJECT_MODULE::BaseSetField.new(self) + end + end + + def set_field(values, value, ignore_nil_for_repeated, message_instance) + @set_field.call(values, value, ignore_nil_for_repeated, message_instance) end def define_to_message_hash! if message? || enum? || repeated? || map? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_to_hash_value_to_message_hash!(self) - ::Protobuf::Field::BaseFieldMethodDefinitions.define_to_hash_value_to_message_hash_with_string_key!(self) + @to_message_hash = OBJECT_MODULE::ToHashValueToMessageHash.new(self) + @to_message_hash_string_keys = OBJECT_MODULE::ToHashValueToMessageHashWithStringKey.new(self) else - ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_to_message_hash!(self) - ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_to_message_hash_with_string_key!(self) + @to_message_hash = OBJECT_MODULE::BaseToMessageHash.new(self) + @to_message_hash_string_keys = OBJECT_MODULE::BaseToMessageHashWithStringKey.new(self) end end + def to_message_hash(values, result) + @to_message_hash.call(values, result) + end + + def to_message_hash_with_string_key(values, result) + @to_message_hash_string_keys.call(values, result) + end + def deprecated? @deprecated end @@ -221,15 +284,19 @@ def required? end def define_set_method! - if map? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_map_set_method!(self) - elsif repeated? && packed? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_packed_set_method!(self) - elsif repeated? - ::Protobuf::Field::BaseFieldMethodDefinitions.define_repeated_not_packed_set_method!(self) - else - ::Protobuf::Field::BaseFieldMethodDefinitions.define_base_set_method!(self) - end + @set_method = if map? + OBJECT_MODULE::MapSetMethod.new(self) + elsif repeated? && packed? + OBJECT_MODULE::RepeatedPackedSetMethod.new(self) + elsif repeated? + OBJECT_MODULE::RepeatedNotPackedSetMethod.new(self) + else + OBJECT_MODULE::BaseSetMethod.new(self) + end + end + + def set(message_instance, bytes) + @set_method.call(message_instance, bytes) end def tag_encoded @@ -260,9 +327,10 @@ def fully_qualified_name_only! ## # Recreate all of the meta methods as they may have used the original `name` value # - define_hash_accessor_for_message! - define_field_p! - define_field_and_present_p! + define_value_from_values! + define_value_from_values_for_serialization! + define_field_predicate! + define_field_and_present_predicate! define_set_field! define_set_method! define_to_message_hash! diff --git a/lib/protobuf/field/base_field_method_definitions.rb b/lib/protobuf/field/base_field_method_definitions.rb deleted file mode 100644 index 5c4c9f9a..00000000 --- a/lib/protobuf/field/base_field_method_definitions.rb +++ /dev/null @@ -1,386 +0,0 @@ -module Protobuf - module Field - class BaseFieldMethodDefinitions - - def self.fully_qualified_name_string(selph) - fully_qualified_name = ":" - fully_qualified_name << '"' if selph.fully_qualified_name.to_s.start_with?(".") - fully_qualified_name << selph.fully_qualified_name.to_s - fully_qualified_name << '"' if selph.fully_qualified_name.to_s.start_with?(".") - fully_qualified_name - end - - def self.define_to_hash_value_to_message_hash_with_string_key!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def to_message_hash_with_string_key(values, result) - result["#{selph.name}"] = value_from_values(values).to_hash_value - end - RUBY - end - - def self.define_base_to_message_hash_with_string_key!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def to_message_hash_with_string_key(values, result) - result["#{selph.name}"] = value_from_values(values) - end - RUBY - end - - def self.define_to_hash_value_to_message_hash!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def to_message_hash(values, result) - result[#{selph.name.inspect}] = value_from_values(values).to_hash_value - end - RUBY - end - - def self.define_base_to_message_hash!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def to_message_hash(values, result) - result[#{selph.name.inspect}] = value_from_values(values) - end - RUBY - end - - def self.define_repeated_packed_encode_to_stream_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def encode_to_stream(value, stream) - packed_value = value.map { |val| encode(val) }.join - stream << #{selph.tag_encoded.dump} << "\#{::Protobuf::Field::VarintField.encode(packed_value.size)}\#{packed_value}" - end - RUBY - end - - def self.define_bytes_encode_to_stream_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def encode_to_stream(value, stream) - value = value.encode if value.is_a?(::Protobuf::Message) - byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) - - stream << #{selph.tag_encoded.dump} << byte_size << value - end - RUBY - end - - def self.define_string_encode_to_stream_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def encode_to_stream(value, stream) - new_value = "" + value - if new_value.encoding != ::Protobuf::Field::StringField::ENCODING - new_value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") - end - - stream << #{selph.tag_encoded.dump} << ::Protobuf::Field::VarintField.encode(new_value.bytesize) << new_value - end - RUBY - end - - def self.define_base_encode_to_stream_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def encode_to_stream(value, stream) - stream << #{selph.tag_encoded.dump} << encode(value) - end - RUBY - end - - def self.define_repeated_not_packed_encode_to_stream_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def encode_to_stream(value, stream) - value.each do |val| - stream << #{selph.tag_encoded.dump} << encode(val) - end - end - RUBY - end - - def self.define_base_set_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set(message_instance, bytes) - message_instance.set_field("#{selph.name}", decode(bytes), true, self) - end - RUBY - end - - def self.define_map_set_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set(message_instance, bytes) - hash = message_instance["#{selph.name}"] - entry = decode(bytes) - # decoded value could be nil for an - # enum value that is not recognized - hash[entry.key] = entry.value unless entry.value.nil? - hash[entry.key] - end - RUBY - end - - def self.define_repeated_not_packed_set_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set(message_instance, bytes) - message_instance["#{selph.name}"] << decode(bytes) - end - RUBY - end - - def self.define_repeated_packed_set_method!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set(message_instance, bytes) - array = message_instance["#{selph.name}"] - stream = ::StringIO.new(bytes) - - if wire_type == ::Protobuf::WireType::VARINT - array << decode(Varint.decode(stream)) until stream.eof? - elsif wire_type == ::Protobuf::WireType::FIXED64 - array << decode(stream.read(8)) until stream.eof? - elsif wire_type == ::Protobuf::WireType::FIXED32 - array << decode(stream.read(4)) until stream.eof? - end - end - RUBY - end - - def self.define_map_set_field!(selph) - if selph.required? - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - unless value.is_a?(Hash) - fail TypeError, <<-TYPE_ERROR - Expected map value - Got '\#{value.class}' for map protobuf field #{selph.name} - TYPE_ERROR - end - - if value.empty? - values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} - else - message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) - values[#{fully_qualified_name_string(selph)}].replace(value) - end - end - RUBY - else - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - unless value.is_a?(Hash) - fail TypeError, <<-TYPE_ERROR - Expected map value - Got '\#{value.class}' for map protobuf field #{selph.name} - TYPE_ERROR - end - - if value.empty? - values.delete(#{fully_qualified_name_string(selph)}) - else - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) - values[#{fully_qualified_name_string(selph)}].replace(value) - end - end - RUBY - end - end - - def self.define_required_repeated_set_field!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - if value.nil? && ignore_nil_for_repeated - ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") - return - end - - unless value.is_a?(Array) - fail TypeError, <<-TYPE_ERROR - Expected repeated value of type '#{selph.type_class}' - Got '\#{value.class}' for repeated protobuf field #{selph.name} - TYPE_ERROR - end - - value = value.compact - - if value.empty? - values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} - else - message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) - values[#{fully_qualified_name_string(selph)}].replace(value) - end - end - RUBY - end - - def self.define_repeated_set_field!(selph) - if selph.required? - define_required_repeated_set_field!(selph) - else - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - if value.nil? && ignore_nil_for_repeated - ::Protobuf.deprecator.deprecation_warning("['#{fully_qualified_name_string(selph)}']=nil", "use an empty array instead of nil") - return - end - - unless value.is_a?(Array) - fail TypeError, <<-TYPE_ERROR - Expected repeated value of type '#{selph.type_class}' - Got '\#{value.class}' for repeated protobuf field #{selph.name} - TYPE_ERROR - end - - value = value.compact - - if value.empty? - values.delete(#{fully_qualified_name_string(selph)}) - else - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) - values[#{fully_qualified_name_string(selph)}].replace(value) - end - end - RUBY - end - end - - def self.define_string_set_field!(selph) - if selph.required? - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - if value.nil? - values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} - else - message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) - values[#{fully_qualified_name_string(selph)}] = if value.is_a?(String) - value - else - coerce!(value) - end - end - end - RUBY - else - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - if value.nil? - values.delete(#{fully_qualified_name_string(selph)}) - else - values[#{fully_qualified_name_string(selph)}] = if value.is_a?(String) - value - else - coerce!(value) - end - end - end - RUBY - end - end - - def self.define_base_set_field!(selph) - if selph.required? - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - if value.nil? - values.delete(#{fully_qualified_name_string(selph)}) - message_instance._protobuf_message_unset_required_field_tags << #{selph.tag} - else - message_instance._protobuf_message_unset_required_field_tags.delete(#{selph.tag}) - values[#{fully_qualified_name_string(selph)}] = coerce!(value) - end - end - RUBY - else - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def set_field(values, value, ignore_nil_for_repeated, message_instance) - if value.nil? - values.delete(#{fully_qualified_name_string(selph)}) - else - values[#{fully_qualified_name_string(selph)}] = coerce!(value) - end - end - RUBY - end - end - - def self.define_base_field_and_present_p!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def field_and_present?(values) - values[#{fully_qualified_name_string(selph)}].present? - end - RUBY - end - - def self.define_bool_field_and_present_p!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - BOOL_VALUES = [true, false].freeze unless defined?(BOOL_VALUES) - - def field_and_present?(values) - BOOL_VALUES.include?(values[#{fully_qualified_name_string(selph)}]) - end - RUBY - end - - def self.define_base_field_p!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def field?(values) - values.key?(#{fully_qualified_name_string(selph)}) - end - RUBY - end - - def self.define_repeated_field_p!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def field?(values) - values.key?(#{fully_qualified_name_string(selph)}) && values[#{fully_qualified_name_string(selph)}].present? - end - RUBY - end - - def self.define_bool_field_value_from_values!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def value_from_values(values) - values.fetch(#{fully_qualified_name_string(selph)}) { default_value } - end - alias :value_from_values_for_serialization value_from_values - RUBY - end - - def self.define_field_value_from_values!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def value_from_values(values) - values[#{fully_qualified_name_string(selph)}] || default_value - end - alias :value_from_values_for_serialization value_from_values - RUBY - end - - def self.define_map_value_from_values!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def value_from_values(values) - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldHash.new(self) - end - - def value_from_values_for_serialization(values) - value = value_from_values(values) - - array = [] - value.each do |k, v| - array << type_class.new(:key => k, :value => v) - end - - array - end - RUBY - end - - def self.define_repeated_value_from_values!(selph) - selph.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 - def value_from_values(values) - values[#{fully_qualified_name_string(selph)}] ||= ::Protobuf::Field::FieldArray.new(self) - end - alias :value_from_values_for_serialization value_from_values - RUBY - end - - end - end -end diff --git a/lib/protobuf/field/base_field_object_definitions.rb b/lib/protobuf/field/base_field_object_definitions.rb new file mode 100644 index 00000000..93a93226 --- /dev/null +++ b/lib/protobuf/field/base_field_object_definitions.rb @@ -0,0 +1,504 @@ +module Protobuf + module Field + module BaseFieldObjectDefinitions + + class ToHashValueToMessageHashWithStringKey + def initialize(selph) + @selph = selph + @name = selph.name.to_s + end + + def call(values, result) + result[@name] = @selph.value_from_values(values).to_hash_value + end + end + + class BaseToMessageHashWithStringKey + def initialize(selph) + @selph = selph + @name = selph.name.to_s + end + + def call(values, result) + result[@name] = @selph.value_from_values(values) + end + end + + class ToHashValueToMessageHash + def initialize(selph) + @selph = selph + @name = selph.name.to_sym + end + + def call(values, result) + result[@name] = @selph.value_from_values(values).to_hash_value + end + end + + class BaseToMessageHash + def initialize(selph) + @selph = selph + @name = selph.name.to_sym + end + + def call(values, result) + result[@name] = @selph.value_from_values(values) + end + end + + class RepeatedPackedEncodeToStream + def initialize(selph) + @selph = selph + @tag_encoded = selph.tag_encoded + end + + def call(value, stream) + packed_value = value.map { |val| @selph.encode(val) }.join + stream << @tag_encoded << "#{::Protobuf::Field::VarintField.encode(packed_value.size)}#{packed_value}" + end + end + + class BytesEncodeToStream + def initialize(selph) + @selph = selph + @tag_encoded = selph.tag_encoded + end + + def call(value, stream) + value = value.encode if value.is_a?(::Protobuf::Message) + byte_size = ::Protobuf::Field::VarintField.encode(value.bytesize) + + stream << @tag_encoded << byte_size << value + end + end + + class StringEncodeToStream + def initialize(selph) + @selph = selph + @tag_encoded = selph.tag_encoded + end + + def call(value, stream) + new_value = "" + value + if new_value.encoding != ::Protobuf::Field::StringField::ENCODING + new_value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") + end + + stream << @tag_encoded << ::Protobuf::Field::VarintField.encode(new_value.bytesize) << new_value + end + end + + class BaseEncodeToStream + def initialize(selph) + @selph = selph + @tag_encoded = selph.tag_encoded + end + + def call(value, stream) + stream << @tag_encoded << @selph.encode(value) + end + end + + class RepeatedNotPackedEncodeToStream + def initialize(selph) + @selph = selph + @tag_encoded = selph.tag_encoded + end + + def call(value, stream) + value.each do |val| + stream << @tag_encoded << @selph.encode(val) + end + end + end + + class BaseSetMethod + def initialize(selph) + @selph = selph + @name = selph.name + end + + def call(message_instance, bytes) + message_instance.set_field(@name, @selph.decode(bytes), true, @selph) + end + end + + class MapSetMethod + def initialize(selph) + @selph = selph + @name = selph.name + end + + def call(message_instance, bytes) + hash = message_instance[@name] + entry = @selph.decode(bytes) + # decoded value could be nil for an + # enum value that is not recognized + hash[entry.key] = entry.value unless entry.value.nil? + hash[entry.key] + end + end + + class RepeatedNotPackedSetMethod + def initialize(selph) + @selph = selph + @name = selph.name + end + + def call(message_instance, bytes) + message_instance[@name] << @selph.decode(bytes) + end + end + + class RepeatedPackedSetMethod + def initialize(selph) + @selph = selph + @name = selph.name + @wire_type = selph.wire_type + end + + def call(message_instance, bytes) + array = message_instance[@name] + stream = ::StringIO.new(bytes) + + if @wire_type == ::Protobuf::WireType::VARINT + array << @selph.decode(Varint.decode(stream)) until stream.eof? + elsif @wire_type == ::Protobuf::WireType::FIXED64 + array << @selph.decode(stream.read(8)) until stream.eof? + elsif @wire_type == ::Protobuf::WireType::FIXED32 + array << @selph.decode(stream.read(4)) until stream.eof? + end + end + end + + class RequiredMapSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, _ignore_nil_for_repeated, message_instance) + unless value.is_a?(Hash) + fail TypeError, <<-TYPE_ERROR + Expected map value + Got '#{value.class}' for map protobuf field #{@selph.name} + TYPE_ERROR + end + + if value.empty? + values.delete(@fully_qualified_name) + message_instance._protobuf_message_unset_required_field_tags << @tag + else + message_instance._protobuf_message_unset_required_field_tags.delete(@tag) + values[@fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(@selph) + values[@fully_qualified_name].replace(value) + end + end + end + + class MapSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, _ignore_nil_for_repeated, _message_instance) + unless value.is_a?(Hash) + fail TypeError, <<-TYPE_ERROR + Expected map value + Got '#{value.class}' for map protobuf field #{@selph.name} + TYPE_ERROR + end + + if value.empty? + values.delete(@fully_qualified_name) + else + values[@fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(@selph) + values[@fully_qualified_name].replace(value) + end + end + end + + class RequiredRepeatedSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, ignore_nil_for_repeated, message_instance) + if value.nil? && ignore_nil_for_repeated + ::Protobuf.deprecator.deprecation_warning("['#{@fully_qualified_name}']=nil", "use an empty array instead of nil") + return + end + + unless value.is_a?(Array) + fail TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{@selph.type_class}' + Got '#{value.class}' for repeated protobuf field #{@selph.name} + TYPE_ERROR + end + + value = value.compact + + if value.empty? + values.delete(@fully_qualified_name) + message_instance._protobuf_message_unset_required_field_tags << @tag + else + message_instance._protobuf_message_unset_required_field_tags.delete(@tag) + values[@fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(@selph) + values[@fully_qualified_name].replace(value) + end + end + end + + class RepeatedSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, ignore_nil_for_repeated, _message_instance) + if value.nil? && ignore_nil_for_repeated + ::Protobuf.deprecator.deprecation_warning("['#{@fully_qualified_name}']=nil", "use an empty array instead of nil") + return + end + + unless value.is_a?(Array) + fail TypeError, <<-TYPE_ERROR + Expected repeated value of type '#{@selph.type_class}' + Got '#{value.class}' for repeated protobuf field #{@selph.name} + TYPE_ERROR + end + + value = value.compact + + if value.empty? + values.delete(@fully_qualified_name) + else + values[@fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(@selph) + values[@fully_qualified_name].replace(value) + end + end + end + + class RequiredStringSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, _ignore_nil_for_repeated, message_instance) + if value + message_instance._protobuf_message_unset_required_field_tags.delete(@tag) + values[@fully_qualified_name] = if value.is_a?(String) + value + else + @selph.coerce!(value) + end + else + values.delete(@fully_qualified_name) + message_instance._protobuf_message_unset_required_field_tags << @tag + end + end + end + + class StringSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, _ignore_nil_for_repeated, _message_instance) + if value + values[@fully_qualified_name] = if value.is_a?(String) + value + else + @selph.coerce!(value) + end + else + values.delete(@fully_qualified_name) + end + end + end + + class RequiredBaseSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, _ignore_nil_for_repeated, message_instance) + if value.nil? + values.delete(@fully_qualified_name) + message_instance._protobuf_message_unset_required_field_tags << @tag + else + message_instance._protobuf_message_unset_required_field_tags.delete(@tag) + values[@fully_qualified_name] = @selph.coerce!(value) + end + end + end + + class BaseSetField + def initialize(selph) + @selph = selph + @tag = selph.tag + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values, value, _ignore_nil_for_repeated, _message_instance) + if value.nil? + values.delete(@fully_qualified_name) + else + values[@fully_qualified_name] = @selph.coerce!(value) + end + end + end + + class BaseFieldAndPresentPredicate + def initialize(selph) + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values[@fully_qualified_name].present? + end + end + + class BoolFieldAndPresentPredicate + BOOL_VALUES = [true, false].freeze + + def initialize(selph) + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + BOOL_VALUES.include?(values[@fully_qualified_name]) + end + end + + class BaseFieldPredicate + def initialize(selph) + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values.key?(@fully_qualified_name) + end + end + + class RepeatedFieldPredicate + def initialize(selph) + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values.key?(@fully_qualified_name) && + values[@fully_qualified_name].present? + end + end + + class BoolFieldValueFromValues + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values.fetch(@fully_qualified_name) { @selph.default_value } + end + end + + class BoolFieldValueFromValuesForSerialization + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values.fetch(@fully_qualified_name) { @selph.default_value } + end + end + + class BaseFieldValueFromValues + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values[@fully_qualified_name] || @selph.default_value + end + end + + class BaseFieldValueFromValuesForSerialization + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values[@fully_qualified_name] || @selph.default_value + end + end + + class MapValueFromValues + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values[@fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(@selph) + end + end + + class MapValueFromValuesForSerialization + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + @type_class = selph.type_class + end + + def call(values) + value = values[@fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(@selph) + + array = [] + value.each do |k, v| + array << @type_class.new(:key => k, :value => v) + end + + array + end + end + + class RepeatedFieldValueFromValues + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values[@fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(@selph) + end + end + + class RepeatedFieldValueFromValuesForSerialization + def initialize(selph) + @selph = selph + @fully_qualified_name = selph.fully_qualified_name + end + + def call(values) + values[@fully_qualified_name] ||= ::Protobuf::Field::FieldArray.new(@selph) + end + end + end + end +end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 3372094e..0a183f0f 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -45,9 +45,17 @@ def acceptable?(val) end def coerce!(val) - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) - return val.to_i if val.is_a?(Numeric) - Integer(val, 10) + if val.is_a?(Integer) && val >= 0 && val <= INT32_MAX + val + else + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" unless acceptable?(val) + + if val.is_a?(Integer) || val.is_a?(Numeric) + val.to_i + else + Integer(val, 10) + end + end rescue ArgumentError fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end diff --git a/profile.html b/profile.html index cdc0569d..6ac4b900 100644 --- a/profile.html +++ b/profile.html @@ -52,7 +52,7 @@

Profile Report: main

-

Total time: 63.34

+

Total time: 123.51

%Total
100% 0%63.2263.34 0.0063.2263.34 0 (top)
60.08 1/1 Benchmark::IPS.ips
1.050.95 0.001.052/1150.952/112 Kernel.require
0.910.000.916/1886Kernel.require0.900.040.861/5##times
0.650.040.611/5##times0.890.000.896/1865Kernel.require
0.52 17/19 Kernel.load
0.120.000.121/1292879Gem::Specification.each_gemspec0.900.040.861/5(top)
0.2360.08 0.000.2219/1292879Kernel.require60.082/5Benchmark::IPS::Job#run
96%0%61.000.0560.955##times
40.080.0040.081/1Benchmark::IPS::Job#run_benchmark
20.001.7718.241/12928790.0020.001/1 Benchmark::IPS::Job#run_warmup
40.080.42 0.0140.071/1292879Benchmark::IPS::Job#run_benchmark
96%2%60.851.8159.041292879##each0.4210000/761459Protobuf::Message::Serialization::ClassMethods.decode_from
57.023.0653.963681351/3681351Benchmark::IPS::Job::Entry#call_times0.270.010.2610000/761459Protobuf::Encoder.encode
0.950.470.493681900/3681900Benchmark::Timing.now0.110.000.1010000/1524359Class#new
0.170.170.12 0.003681355/3681355##<0.121/762970##flat_map
0.140.00 0.141/762970Gem::Specification.each_gemspec
0.23 0.003681365/18790704##+0.2319/762970Kernel.require
0.650.040.611/5(top)20.001.6918.321/762970Benchmark::IPS::Job#run_warmup
60.0840.08 0.0060.082/5Benchmark::IPS::Job#run40.071/762970Benchmark::IPS::Job#run_benchmark
96%0%60.760.0660.705##times2%60.891.7259.17762970##each
40.0857.312.6854.623368410/3368410Benchmark::IPS::Job::Entry#call_times
0.740.310.443368939/3368939Benchmark::Timing.now
0.180.18 0.0040.081/1Benchmark::IPS::Job#run_benchmark3368414/3368414##<
20.000.140.14 0.0020.001/1Benchmark::IPS::Job#run_warmup3368424/23728693##+
0.290.12 0.000.2810000/1291320Protobuf::Message::Serialization::ClassMethods.decode_from0.122/3Gem::Specification.gemspec_stubs_in
0.190.010.1810000/1291320Protobuf::Encoder.encode0.110.000.1013/14Gem::Specification.load
(top)
95%94% 0% 60.08 0.00 1 Benchmark::IPS.ips
60.08 1/1 Benchmark::IPS::Job#run
Benchmark::IPS.ips
95%94% 0% 60.08 0.00 1 Benchmark::IPS::Job#run
60.08 0.00 60.08 2/5##times##times
57.023.0653.963681351/3681351##each57.312.6854.623368410/3368410##each
90% 4%57.023.0653.96368135157.312.6854.623368410 Benchmark::IPS::Job::Entry#call_times
52.582.3150.2615108256/1510880453.422.1651.2613506055/13506589 Proc#call
0.710.710.650.65 0.0018789607/18789624##<16874465/19924325##<
0.670.670.560.56 0.0015108256/18790704##+13506055/23728693##+
52.582.3150.2615108256/1510880453.422.1651.2613506055/13506589 Benchmark::IPS::Job::Entry#call_times
83%84% 3%52.612.3250.291510880453.452.1751.2813506589 Proc#call
22.112.3719.7413826936/1382693622.462.3520.1112754596/12754596 Protobuf::Message#to_hash
12.920.3312.591281320/129132015.050.2014.85751459/761459 Protobuf::Message::Serialization::ClassMethods.decode_from
9.100.358.751281320/12913208.850.278.58751459/761459 Protobuf::Encoder.encode
3.530.173.361281320/25841643.220.123.09751459/1524359 Class#new
2.170.311.871281320/12913201.360.211.15751459/761459 Test::Resource#status=
0.280.170.20 0.111281320/12913200.09751459/761459 StringIO.new
0.110.110.001281320/1291320Protobuf::Message#to_proto
0.00 40.08 1/1##times##times
63% 1 Benchmark::IPS::Job#run_benchmark
40.080.010.00 40.071/1292879##each1/762970##each
8.231.646.601291320/151182578.371.057.32761459/13516056 Protobuf::Message#each_field_for_serialization
19.745.9313.8113826936/1511825720.115.3814.7312754596/13516056 Protobuf::Message#to_hash
44%11%27.987.5720.4115118257##each_key10%28.486.4322.0413516056##each_key
5.462.323.1513826936/138269365.572.243.3312754596/12754596 Protobuf::Field::StringField(singleton)#to_message_hash
5.342.273.0613826936/138269365.182.133.0412754596/12754596 Protobuf::Field::Int64Field(singleton)#to_message_hash
2.300.741.571291320/1291320Protobuf::Field::StringField(singleton)#encode_to_stream2.590.212.38761459/761459Protobuf::Field::Int64Field(singleton)#encode_to_stream
1.991.992.422.42 0.0031527832/73391217##[]27793569/32362325Protobuf::Message#_protobuf_message_field
1.551.552.012.01 0.0031527832/39275754Test::Resource#_protobuf_message_field27793569/63970204##[]
1.440.321.121291320/1291320Protobuf::Field::EnumField(singleton)#encode_to_stream1.890.511.38761459/761459Protobuf::Field::StringField(singleton)#encode_to_stream
1.180.320.861291320/1291320Protobuf::Field::Int64Field(singleton)#encode_to_stream1.660.211.46761459/761459Protobuf::Field::EnumField(singleton)#encode_to_stream
0.410.110.301291320/164095760.260.070.19761459/14277514 Protobuf::Field::StringField(singleton)#value_from_values
0.370.110.271291320/2582640Protobuf::Field::EnumField(singleton)#value_from_values0.250.070.18761459/14277514Protobuf::Field::Int64Field(singleton)#value_from_values
0.360.110.261291320/16409576Protobuf::Field::Int64Field(singleton)#value_from_values0.230.070.16761459/1522918Protobuf::Field::EnumField(singleton)#value_from_values
22.112.3719.7413826936/1382693622.462.3520.1112754596/12754596 Proc#call
34%35% 3%22.112.3719.741382693622.462.3520.1112754596 Protobuf::Message#to_hash
19.745.9313.8113826936/15118257##each_key20.115.3814.7312754596/13516056##each_key
0.00 20.00 1/1##times##times
31% 1 Benchmark::IPS::Job#run_warmup
20.001.7718.241/1292879##each1.6918.321/762970##each
0.290.000.2810000/1291320##times0.420.010.4210000/761459##times
12.920.3312.591281320/129132015.050.2014.85751459/761459 Proc#call
20%24% 0%13.200.3312.87129132015.470.2115.27761459 Protobuf::Message::Serialization::ClassMethods.decode_from
12.110.3211.781291320/129132014.760.2214.54761459/761459 Protobuf::Message::Serialization.decode_from
0.760.170.591291320/25841640.510.110.40761459/1524359 Class#new
12.110.3211.781291320/129132014.760.2214.54761459/761459 Protobuf::Message::Serialization::ClassMethods.decode_from
19%23% 0%12.110.3211.78129132014.760.2214.54761459 Protobuf::Message::Serialization.decode_from
11.782.059.741291320/129132014.541.3113.23761459/761459 Protobuf::Decoder.decode_each_field
11.782.059.741291320/129132014.541.3113.23761459/761459 Protobuf::Message::Serialization.decode_from
18%3%11.782.059.74129132022%2%14.541.3113.23761459 Protobuf::Decoder.decode_each_field
7.401.166.243873960/38739607.130.816.312284377/2284377 Protobuf::Message::Serialization.set_field_bytes
1.420.850.577747920/7747920Protobuf::Varint.decode5.562.882.694568754/4568754Protobuf::VarintPure.decode
0.240.240.150.15 0.005165280/51652803045836/3045836 StringIO#eof
0.200.200.130.13 0.005165280/5168510##==3045836/3048922##==
0.170.170.100.10 0.003873960/3873960##>>761459/761459StringIO#read
0.170.170.003873960/3873960##&0.270.010.2610000/761459##times
0.130.130.001291320/1291320StringIO#read
0.190.010.1810000/1291320##times
9.100.358.751281320/12913208.850.278.58751459/761459 Proc#call
14% 0%9.280.368.9312913209.120.288.84761459 Protobuf::Encoder.encode
8.930.458.481291320/12913208.840.328.52761459/761459 Protobuf::Message#each_field_for_serialization
8.930.458.481291320/12913208.840.328.52761459/761459 Protobuf::Encoder.encode
14%13% 0%8.930.458.4812913208.840.328.52761459 Protobuf::Message#each_field_for_serialization
8.231.646.601291320/15118257##each_key8.371.057.32761459/13516056##each_key
0.180.180.110.11 0.001291320/3873961Test::Resource#_protobuf_message_required_field_tags761459/2284378Protobuf::Message#_protobuf_message_required_field_tags
0.690.170.521291320/77479227.130.816.312284377/2284377Protobuf::Decoder.decode_each_field
11%1%7.130.816.312284377Protobuf::Message::Serialization.set_field_bytes
2.460.192.27761459/761459Protobuf::Field::EnumField(singleton)#set
1.710.211.49761459/761459 Protobuf::Field::Int64Field(singleton)#set
1.341.40 0.191.151291320/77479221.21761459/761459 Protobuf::Field::StringField(singleton)#set
0.530.400.132284377/32362325Protobuf::Message#_protobuf_message_field
0.210.210.002284377/63970204##[]
1.730.161.571291320/77479220.940.120.82761459/4568756 Protobuf::Field::EnumField(singleton)#set
1.890.311.591291320/77479221.000.160.84761459/4568756Protobuf::Field::StringField(singleton)#set
1.070.120.95761459/4568756Protobuf::Field::Int64Field(singleton)#set
1.180.190.98761459/4568756 Test::Resource#status=
2.570.641.932582642/7747922##each2.550.412.151522920/4568756##each
13%2%8.221.476.75774792210%1%6.741.005.744568756 Protobuf::Message#set_field
2.980.602.392582640/2582640Protobuf::Field::EnumField(singleton)#set_field1.800.391.421522919/1522919Protobuf::Field::Int64Field(singleton)#set_field
2.210.941.272582641/2582641Protobuf::Field::StringField(singleton)#set_field1.660.351.311522918/1522918Protobuf::Field::EnumField(singleton)#set_field
0.971.60 0.600.372582641/2582641Protobuf::Field::Int64Field(singleton)#set_field1.001522919/1522919Protobuf::Field::StringField(singleton)#set_field
0.320.320.003873962/73391217##[]0.470.340.132284379/32362325Protobuf::Message#_protobuf_message_field
0.260.260.200.20 0.003873962/39275754Test::Resource#_protobuf_message_field2284379/63970204##[]
7.401.166.243873960/3873960Protobuf::Decoder.decode_each_field5.572.243.3312754596/12754596##each_key
11%1%7.401.166.243873960Protobuf::Message::Serialization.set_field_bytes8%3%5.572.243.3312754596Protobuf::Field::StringField(singleton)#to_message_hash
2.250.271.971291320/1291320Protobuf::Field::EnumField(singleton)#set2.371.530.8412754596/14277514Protobuf::Field::StringField(singleton)#value_from_values
2.120.281.851291320/1291320Protobuf::Field::StringField(singleton)#set0.960.960.0012754596/30084503##[]=
1.240.270.971291320/1291320Protobuf::Field::Int64Field(singleton)#set5.562.882.694568754/4568754Protobuf::Decoder.decode_each_field
8%4%5.562.882.694568754Protobuf::VarintPure.decode
0.340.340.890.660.226853131/6853131IO::GenericReadable.readbyte
0.470.47 0.003873960/73391217##[]13706262/21322798##&
0.290.290.280.28 0.003873960/39275754Test::Resource#_protobuf_message_field6853131/6853284##<<
5.462.323.1513826936/13826936##each_key0.270.270.006853131/8376374Numeric#nonzero?
8%3%5.462.323.1513826936Protobuf::Field::StringField(singleton)#to_message_hash
0.270.270.006853131/23728693##+
2.341.660.6813826936/16409576Protobuf::Field::StringField(singleton)#value_from_values0.260.260.006853131/9139607##|
0.810.810.260.26 0.0013826936/35406351##[]=6853131/6853756##*
5.342.273.0613826936/13826936##each_key5.182.133.0412754596/12754596##each_key
8% 3%5.342.273.06138269365.182.133.0412754596 Protobuf::Field::Int64Field(singleton)#to_message_hash
2.241.590.6513826936/164095762.141.480.6612754596/14277514 Protobuf::Field::Int64Field(singleton)#value_from_values
0.820.820.900.90 0.0013826936/35406351##[]=12754596/30084503##[]=
0.110.00 0.1010000/1524359##times
0.11 0.020.0816/25841640.0915/1524359 Kernel.eval
0.170.15 0.010.16153/25841640.14153/1524359 Protobuf::Field.build
0.300.24 0.010.291/25841640.231/1524359 Bundler::Dsl#to_definition
0.760.170.591291320/25841640.510.110.40761459/1524359 Protobuf::Message::Serialization::ClassMethods.decode_from
3.530.173.361281320/25841643.220.123.09751459/1524359 Proc#call
8%7% 0%5.120.464.6625841644.590.354.251524359 Class#new
4.020.813.212582641/25826413.600.593.001522919/1522919 Protobuf::Message#initialize
0.290.23 0.000.290.23 1/1 Bundler::Definition#initialize
0.160.14 0.010.150.14 153/153 Protobuf::Field::BaseField#initialize
0.150.150.140.14 0.002582640/733912172284377/63970204 Protobuf::Enum.enum_for_tag_integer
0.320.320.170.170.001525107/63970204Protobuf::Field::VarintField.cached_varint
0.200.20 0.003873962/733912172284379/63970204 Protobuf::Message#set_field
0.340.340.210.21 0.003873960/733912172284377/63970204 Protobuf::Message::Serialization.set_field_bytes
0.720.720.710.71 0.0015118256/7339121713516055/63970204 Protobuf::Field::Int64Field(singleton)#value_from_values
0.760.760.900.90 0.0015118256/7339121713516055/63970204 Protobuf::Field::StringField(singleton)#value_from_values
1.991.992.012.01 0.0031527832/73391217##each_key27793569/63970204##each_key
6% 6%4.404.374.424.39 0.0373391217##[]63970204##[]
4.020.813.212582641/25826413.600.593.001522919/1522919 Class#new
6%1%4.020.813.2125826415%0%3.600.593.001522919 Protobuf::Message#initialize
3.000.432.572582641/2582855##each2.870.322.551522919/1523130##each
0.110.110.470.340.132284379/32362325Protobuf::Message#set_field
0.530.400.132284377/32362325Protobuf::Message::Serialization.set_field_bytes
2.422.42 0.002582641/2582814Kernel.block_given?27793569/32362325##each_key
5%4%3.433.160.2632362325Protobuf::Message#_protobuf_message_field
0.110.110.200.20 0.002582641/2582642##to_hash1522919/1523730Protobuf::Message::Fields::ClassMethods.field_store
3.000.432.572582641/25828552.870.322.551522919/1523130 Protobuf::Message#initialize
4% 0%3.020.442.582582855##each2.890.332.561523130##each
2.570.641.932582642/77479222.550.412.151522920/4568756 Protobuf::Message#set_field
2.980.602.392582640/2582640Protobuf::Message#set_field0.540.160.38761459/2286579Protobuf::Field::EnumField#encode
0.580.170.41761459/2286579Protobuf::Field::StringField(singleton)#encode_to_stream
1.630.840.79761459/2286579Protobuf::Field::IntegerField#encode
4%0%2.980.602.392582640Protobuf::Field::EnumField(singleton)#set_field1%2.771.181.592286579Protobuf::Field::VarintField.encode
2.110.491.622582640/2582640Protobuf::Field::EnumField#coerce!0.660.390.271523058/1525107Protobuf::Field::VarintField.cached_varint
0.170.170.210.21 0.002582640/35406351##[]=3049844/3051803##<<
0.410.120.120.00763521/763523##pack
0.120.120.003049844/19924325##<
0.110.110.002284530/3809398##<=
0.11 0.110.301291320/16409576##each_key0.002286323/4570700##>>
2.341.660.6813826936/164095760.260.070.19761459/14277514##each_key
2.371.530.8412754596/14277514 Protobuf::Field::StringField(singleton)#to_message_hash
4% 2%2.751.770.98164095762.621.591.0314277514 Protobuf::Field::StringField(singleton)#value_from_values
0.760.760.900.90 0.0015118256/73391217##[]13516055/63970204##[]
0.360.110.261291320/16409576##each_key2.590.212.38761459/761459##each_key
4%0%2.590.212.38761459Protobuf::Field::Int64Field(singleton)#encode_to_stream
2.060.341.73761459/761459Protobuf::Field::IntegerField#encode
0.320.150.171522918/5330213IO::GenericWritable.<<
2.241.590.6513826936/164095762.460.192.27761459/761459Protobuf::Message::Serialization.set_field_bytes
3%0%2.460.192.27761459Protobuf::Field::EnumField(singleton)#set
1.330.331.00761459/761459Protobuf::Field::EnumField#decode
0.940.120.82761459/4568756Protobuf::Message#set_field
0.250.070.18761459/14277514##each_key
2.141.480.6612754596/14277514 Protobuf::Field::Int64Field(singleton)#to_message_hash
4%3% 2%2.611.700.91164095762.381.550.8414277514 Protobuf::Field::Int64Field(singleton)#value_from_values
0.720.720.710.71 0.0015118256/73391217##[]13516055/63970204##[]
0.42 0.03 0.392/18862/1865 Kernel.load
0.910.89 0.000.916/18860.896/1865 (top)
1.050.95 0.001.05115/18860.95112/1865 Kernel.require
3% 0%2.372.26 0.032.3418862.231865 Kernel.require
0.880.81 0.000.880.81 1/1 Bundler.setup
0.23 0.000.2219/1292879##each0.2319/762970##each
0.130.14 0.000.130.14 1/1 Gem::Specification.load_defaults
0.120.11 0.000.120.11 109/109 Protobuf::Message::Fields::ClassMethods.optional
2.300.741.571291320/1291320##each_key
3%1%2.300.741.571291320Protobuf::Field::StringField(singleton)#encode_to_stream0.120.120.001522919/30084503Protobuf::Field::Int64Field(singleton)#set_field
0.740.350.393873960/9039240IO::GenericWritable.<<0.120.120.001522918/30084503Protobuf::Field::EnumField(singleton)#set_field
0.340.220.121291320/1291473Protobuf::Field::VarintField.encode0.130.130.001522919/30084503Protobuf::Field::StringField(singleton)#set_field
0.240.170.071291320/1292131BasicObject#!=0.900.900.0012754596/30084503Protobuf::Field::Int64Field(singleton)#to_message_hash
0.120.120.960.96 0.001291320/2582782##+12754596/30084503Protobuf::Field::StringField(singleton)#to_message_hash
3%3%2.242.240.0130084503##[]=
2.250.271.971291320/1291320Protobuf::Message::Serialization.set_field_bytes2.060.341.73761459/761459Protobuf::Field::Int64Field(singleton)#encode_to_stream
3% 0%2.250.271.971291320Protobuf::Field::EnumField(singleton)#set2.060.341.73761459Protobuf::Field::IntegerField#encode
1.730.161.571291320/7747922Protobuf::Message#set_field1.630.840.79761459/2286579Protobuf::Field::VarintField.encode
0.240.190.051291320/1291320Protobuf::Field::EnumField#decode0.100.100.00761459/21322798##&
2.170.311.871281320/1291320Proc#call1.890.511.38761459/761459##each_key
3%2% 0%2.210.32 1.891291320Test::Resource#status=0.511.38761459Protobuf::Field::StringField(singleton)#encode_to_stream
1.890.311.591291320/7747922Protobuf::Message#set_field0.580.170.41761459/2286579Protobuf::Field::VarintField.encode
0.470.230.242284377/5330213IO::GenericWritable.<<
0.140.100.04761459/762229BasicObject#!=
2.210.941.272582641/25826411.800.391.421522919/1522919 Protobuf::Message#set_field
3%1%2.210.941.272582641Protobuf::Field::StringField(singleton)#set_field2%0%1.800.391.421522919Protobuf::Field::Int64Field(singleton)#set_field
0.680.530.152582641/3873961Test::Resource#_protobuf_message_required_field_tags1.240.440.801522919/1522919Protobuf::Field::VarintField#coerce!
0.200.200.120.12 0.002582641/2582825##delete1522919/30084503##[]=
0.180.180.002582641/35406351##[]=1.710.211.49761459/761459Protobuf::Message::Serialization.set_field_bytes
2%0%1.710.211.49761459Protobuf::Field::Int64Field(singleton)#set
0.100.100.002582641/7748887Kernel.nil?1.070.120.95761459/4568756Protobuf::Message#set_field
0.100.100.002582641/2583806##to_s0.430.320.11761459/761459Protobuf::Field::IntegerField#decode
0.160.160.002582641/35406351Protobuf::Field::Int64Field(singleton)#set_field1.660.211.46761459/761459##each_key
2%0%1.660.211.46761459Protobuf::Field::EnumField(singleton)#encode_to_stream
0.170.170.002582640/35406351Protobuf::Field::EnumField(singleton)#set_field1.180.340.84761459/761459Protobuf::Field::EnumField#encode
0.180.180.002582641/35406351Protobuf::Field::StringField(singleton)#set_field0.280.150.131522918/5330213IO::GenericWritable.<<
0.810.811.660.351.311522918/1522918Protobuf::Message#set_field
2%0%1.660.351.311522918Protobuf::Field::EnumField(singleton)#set_field
1.130.270.861522918/1522918Protobuf::Field::EnumField#coerce!
0.120.12 0.0013826936/35406351Protobuf::Field::StringField(singleton)#to_message_hash1522918/30084503##[]=
0.820.820.0013826936/35406351Protobuf::Field::Int64Field(singleton)#to_message_hash1.600.601.001522919/1522919Protobuf::Message#set_field
3%3%2.152.140.0135406351##[]=2%0%1.600.601.001522919Protobuf::Field::StringField(singleton)#set_field
0.660.410.251522919/2284378Protobuf::Message#_protobuf_message_required_field_tags
0.130.130.001522919/30084503##[]=
2.120.281.851291320/12913201.400.191.21761459/761459 Protobuf::Message::Serialization.set_field_bytes
3%2% 0%2.120.281.8512913201.400.191.21761459 Protobuf::Field::StringField(singleton)#set
1.340.191.151291320/77479221.000.160.84761459/4568756 Protobuf::Message#set_field
0.500.300.201291320/12913200.210.140.07761459/761459 Protobuf::Field::StringField#decode
2.110.491.622582640/2582640Protobuf::Field::EnumField(singleton)#set_field1.360.211.15751459/761459Proc#call
3%2% 0%2.110.491.622582640Protobuf::Field::EnumField#coerce!1.400.221.18761459Test::Resource#status=
1.380.460.922582640/2582649Protobuf::Enum.fetch1.180.190.98761459/4568756Protobuf::Message#set_field
0.240.240.002582640/2583314Protobuf::Field::BaseField#type_class1.330.331.00761459/761459Protobuf::Field::EnumField(singleton)#set
2%0%1.330.331.00761459Protobuf::Field::EnumField#decode
0.880.280.60761459/761459Protobuf::Field::EnumField#acceptable?
1.240.440.801522919/1522919Protobuf::Field::Int64Field(singleton)#set_field
1%0%1.240.440.801522919Protobuf::Field::VarintField#coerce!
0.650.420.221522919/1522919Protobuf::Field::Int64Field#acceptable?
0.450.160.28761459/2284386Protobuf::Field::EnumField#acceptable?
0.760.270.501522918/2284386Protobuf::Field::EnumField#coerce!
1%0%1.210.430.782284386Protobuf::Enum.fetch
0.670.41 0.260.262284377/2284377Protobuf::Enum.enum_for_tag_integer
0.110.11 0.003873962/39275754Protobuf::Message#set_field2284386/5331568Kernel.kind_of?
0.290.291.180.340.84761459/761459Protobuf::Field::EnumField(singleton)#encode_to_stream
1%0%1.180.340.84761459Protobuf::Field::EnumField#encode
0.540.160.38761459/2286579Protobuf::Field::VarintField.encode
0.180.110.07761459/761727Protobuf::Enum#to_i
0.110.11 0.003873960/39275754Protobuf::Message::Serialization.set_field_bytes761459/21322798##&
1.551.550.0031527832/39275754##each_key1.130.270.861522918/1522918Protobuf::Field::EnumField(singleton)#set_field
3%3%2.092.091%0%1.130.270.861522918Protobuf::Field::EnumField#coerce!
0.760.270.501522918/2284386Protobuf::Enum.fetch
0.100.10 0.0039275754Test::Resource#_protobuf_message_field1522918/2285051Protobuf::Field::BaseField#type_class
0.440.230.212582640/90392400.280.150.131522918/5330213 Protobuf::Field::EnumField(singleton)#encode_to_stream
0.480.230.252582640/90392400.320.150.171522918/5330213 Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.740.350.393873960/90392400.470.230.242284377/5330213 Protobuf::Field::StringField(singleton)#encode_to_stream
2% 1%1.670.820.8590392400%1.060.520.545330213 IO::GenericWritable.<<
0.850.850.540.54 0.009039240/90392405330213/5330213 StringIO#write
1.440.321.121291320/1291320##each_key
2%0%1.440.321.121291320Protobuf::Field::EnumField(singleton)#encode_to_stream0.100.100.00761459/21322798Protobuf::Field::IntegerField#encode
0.680.270.421291320/12913200.110.110.00761459/21322798 Protobuf::Field::EnumField#encode
0.440.230.212582640/9039240IO::GenericWritable.<<
1.420.850.577747920/7747920Protobuf::Decoder.decode_each_field0.470.470.0013706262/21322798Protobuf::VarintPure.decode
2% 1%1.420.850.577747920Protobuf::Varint.decode
0.570.571%1.001.00 0.007747920/7747920ProtobufJavaHelpers::Varinter.read_varint21322798##&
1.380.460.922582640/2582649Protobuf::Field::EnumField#coerce!
2%0%1.380.460.922582649Protobuf::Enum.fetch
0.780.510.282582640/2582640Protobuf::Enum.enum_for_tag_integer
0.14 0.14 0.002582649/2584139Kernel.kind_of?3368424/23728693##each
1.24 0.270.971291320/1291320Protobuf::Message::Serialization.set_field_bytes
1%0%1.24 0.270.971291320Protobuf::Field::Int64Field(singleton)#set
0.690.170.521291320/7747922Protobuf::Message#set_field
0.280.220.061291320/1291320Protobuf::Field::Int64Field#decode0.006853131/23728693Protobuf::VarintPure.decode
1.180.320.861291320/1291320##each_key0.560.560.0013506055/23728693Benchmark::IPS::Job::Entry#call_times
1%0%1.180.320.861291320Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.480.230.252582640/9039240IO::GenericWritable.<<
0.380.240.141291320/1291320Protobuf::Field::Int64Field#encode1%0.970.970.0023728693##+
1.050.95 0.001.052/1150.952/112 (top)
1% 0%1.050.95 0.001.051150.95112 Kernel.require
1.050.95 0.001.05115/18860.95112/1865 Kernel.require
0.970.600.372582641/2582641Protobuf::Message#set_field0.890.660.226853131/6853131Protobuf::VarintPure.decode
1%0%0.970.600.372582641Protobuf::Field::Int64Field(singleton)#set_field
0.160.160.002582641/35406351##[]=
0.110.110.002582641/2582641ProtobufJavaHelpers::Int64ProtobufField.coerce!1%0.890.660.226853131IO::GenericReadable.readbyte
0.100.100.220.22 0.002582641/7748887Kernel.nil?6853131/6853131StringIO#getbyte
0.950.470.493681900/3681900##each0.880.280.60761459/761459Protobuf::Field::EnumField#decode
1% 0%0.950.470.493681900Benchmark::Timing.now0.880.280.60761459Protobuf::Field::EnumField#acceptable?
0.490.490.003681900/3681901Process.clock_gettime0.450.160.28761459/2284386Protobuf::Enum.fetch
0.880.81 0.000.880.81 1/1 Kernel.require
1% 0%0.880.81 0.000.880.81 1 Bundler.setup
0.520.44 0.010.510.43 1/2 Bundler.definition
0.350.36 0.000.350.36 1/1 Bundler::Runtime#setup
0.180.180.110.11 0.001291320/3873961761459/2284378 Protobuf::Message#each_field_for_serialization
0.680.530.152582641/38739610.660.410.251522919/2284378 Protobuf::Field::StringField(singleton)#set_field
1%1%0.860.710.153873961Test::Resource#_protobuf_message_required_field_tags
0.150.150.002582641/2583673Kernel.dup0%0.770.520.252284378Protobuf::Message#_protobuf_message_required_field_tags
0.850.850.009039240/9039240IO::GenericWritable.<<
1%1%0.850.850.200.20 0.009039240StringIO#write1522919/1522926Protobuf::Message::Fields::ClassMethods.required_field_tags
0.140.140.120.12 0.003681365/18790704##each3049844/19924325Protobuf::Field::VarintField.encode
0.670.670.650.65 0.0015108256/1879070416874465/19924325 Benchmark::IPS::Job::Entry#call_times
1% 1%0.810.810.760.76 0.0018790704##+19924325##<
0.780.510.282582640/2582640Protobuf::Enum.fetch0.740.310.443368939/3368939##each
1% 0%0.780.510.282582640Protobuf::Enum.enum_for_tag_integer
0.150.150.002582640/73391217##[]0.740.310.443368939Benchmark::Timing.now
0.130.130.440.44 0.002582640/2583129##first3368939/3368940Process.clock_gettime
0.710.710.0018789607/18789624Benchmark::IPS::Job::Entry#call_times0.660.390.271523058/1525107Protobuf::Field::VarintField.encode
1%1%0.710.710%0.680.390.281525107Protobuf::Field::VarintField.cached_varint
0.170.17 0.0018789624##<1525107/63970204##[]
0.680.270.421291320/1291320Protobuf::Field::EnumField(singleton)#encode_to_stream0.670.410.262284377/2284377Protobuf::Enum.fetch
1% 0%0.680.270.421291320Protobuf::Field::EnumField#encode0.670.410.262284377Protobuf::Enum.enum_for_tag_integer
0.310.18 0.141291320/1291588Protobuf::Enum#to_i0.140.002284377/63970204##[]
0.100.100.120.12 0.001291320/2582640ProtobufJavaHelpers::Varinter.to_varint_642284377/2284829##first
0.570.570.650.420.221522919/1522919Protobuf::Field::VarintField#coerce!
1%0%0.650.420.221522919Protobuf::Field::Int64Field#acceptable?
0.540.54 0.007747920/7747920Protobuf::Varint.decode5330213/5330213IO::GenericWritable.<<
0% 0%0.570.570.540.54 0.007747920ProtobufJavaHelpers::Varinter.read_varint5330213StringIO#write
19 Kernel.load
0.42 0.03 0.392/18862/1865 Kernel.require
0.520.44 0.010.510.43 1/2 Bundler.setup
0% 0%0.520.44 0.010.510.43 2 Bundler.definition
0.420.35 0.000.420.34 1/1 Bundler::Definition.build
0.500.300.201291320/1291320Protobuf::Field::StringField(singleton)#set
0%0%0.500.300.201291320Protobuf::Field::StringField#decode
0.130.130.001291320/2582782##+
0.490.490.440.44 0.003681900/36819013368939/3368940 Benchmark::Timing.now
0% 0%0.490.490.440.44 0.0036819013368940 Process.clock_gettime
0.420.000.421/1Bundler.definition0.430.320.11761459/761459Protobuf::Field::Int64Field(singleton)#set
0% 0%0.420.000.421Bundler::Definition.build
0.400.000.401/1Bundler::Dsl.evaluate0.430.320.11761459Protobuf::Field::IntegerField#decode
0.33 0.00 0.331/8731/822 Bundler::Runtime#requested_specs
0.41 0.00 0.41873822 Kernel.send
0.33 1/1 Bundler::Definition#requested_specs
0.400.36 0.000.400.36 1/1Bundler::Definition.buildBundler.setup
0% 0%0.400.36 0.000.400.36 1Bundler::Dsl.evaluateBundler::Runtime#setup
0.300.33 0.000.300.33 1/1Bundler::Dsl#to_definitionBundler::Runtime#requested_specs
0.380.240.141291320/1291320Protobuf::Field::Int64Field(singleton)#encode_to_stream0.260.260.006853131/9139607Protobuf::VarintPure.decode
0% 0%0.380.240.141291320Protobuf::Field::Int64Field#encode
0.140.140.350.35 0.001291320/2582640ProtobufJavaHelpers::Varinter.to_varint_649139607##|
0.370.110.271291320/2582640##each_key
0%0%0.370.110.272582640Protobuf::Field::EnumField(singleton)#value_from_values
0.35 0.000.350.34 1/1Bundler.setupBundler.definition
0% 0% 0.35 0.000.350.34 1Bundler::Runtime#setupBundler::Definition.build
0.33 0.00 0.33 1/1Bundler::Runtime#requested_specsBundler::Dsl.evaluate
0.340.220.121291320/1291473Protobuf::Field::StringField(singleton)#encode_to_stream0.330.000.331/1Bundler::Definition.build
0% 0%0.340.220.121291473Protobuf::Field::VarintField.encode0.330.000.331Bundler::Dsl.evaluate
0.120.120.24 0.001291473/1291473ProtobufJavaHelpers::Varinter.to_varint0.241/1Bundler::Dsl#to_definition
1 Bundler::Runtime#requested_specs
0.33 0.00 0.331/8731/822 Kernel.send
1 Bundler::Definition#requested_specs
0.33 1/1 Bundler::Definition#specs_for
1 Bundler::Definition#specs_for
0.32 1/1 Bundler::Definition#specs
0.270.270.006853131/8376374Protobuf::VarintPure.decode
0%0%0.330.330.008376374Numeric#nonzero?
1 Bundler::Definition#specs
0.200.21 0.000.200.21 1/1 Bundler::SpecSet#materialize
0.100.000.101/1Bundler::Definition#resolve
0.310.180.141291320/1291588Protobuf::Field::EnumField#encode0.280.280.006853131/6853284Protobuf::VarintPure.decode
0%0%0.310.180.141291588Protobuf::Enum#to_i
0.140.140%0%0.280.28 0.001291588/1291588Protobuf::Enum#tag6853284##<<
0.100.100.110.11 0.002582641/7748887Protobuf::Field::Int64Field(singleton)#set_field2284386/5331568Protobuf::Enum.fetch
0%0%0.270.270.005331568Kernel.kind_of?
0.100.100.260.26 0.002582641/7748887Protobuf::Field::StringField(singleton)#set_field6853131/6853756Protobuf::VarintPure.decode
0% 0%0.300.300.260.26 0.007748887Kernel.nil?6853756##*
0.300.24 0.000.300.24 1/1 Bundler::Dsl.evaluate
0% 0%0.300.24 0.000.300.24 1 Bundler::Dsl#to_definition
0.300.24 0.010.291/25841640.231/1524359 Class#new
0.290.23 0.000.290.23 1/1 Class#new
0% 0%0.290.23 0.000.290.23 1 Bundler::Definition#initialize
0.110.000.111/1Bundler::Definition#converge_paths0.230.070.16761459/1522918##each_key
0%0%0.230.070.161522918Protobuf::Field::EnumField(singleton)#value_from_values
0.280.170.111281320/1291320Proc#call0.190.000.191/392Bundler::SpecSet#materialize
0% 0%0.290.170.111291320StringIO.new0.230.020.21392##map!
0.110.110.19 0.001291320/1291320StringIO#initialize0.1938/38Bundler::LazySpecification#__materialize__
0.28 0.220.061291320/1291320Protobuf::Field::Int64Field(singleton)#set0.220.006853131/6853131IO::GenericReadable.readbyte
0% 0%0.28 0.220.061291320Protobuf::Field::Int64Field#decode
0.120.120.001291320/2582782Protobuf::Field::StringField(singleton)#encode_to_stream
0.130.130.22 0.001291320/2582782Protobuf::Field::StringField#decode6853131StringIO#getbyte
0% 0%0.250.250.220.22 0.002582782##+5331092Kernel.nil?
0.240.170.210.14 0.071291320/1292131Protobuf::Field::StringField(singleton)#encode_to_stream761459/761459Protobuf::Field::StringField(singleton)#set
0% 0%0.240.170.081292131BasicObject#!=0.210.140.07761459Protobuf::Field::StringField#decode
0.240.190.051291320/1291320Protobuf::Field::EnumField(singleton)#set0.210.000.211/1Bundler::Definition#specs
0% 0%0.240.210.000.211Bundler::SpecSet#materialize
0.190.051291320Protobuf::Field::EnumField#decode0.000.191/392##map!
0.240.240.210.21 0.002582640/2583314Protobuf::Field::EnumField#coerce!3049844/3051803Protobuf::Field::VarintField.encode
0% 0%0.240.240.210.21 0.002583314Protobuf::Field::BaseField#type_class3051803##<<
0.100.100.001291320/2582640Protobuf::Field::EnumField#encode0.200.110.09751459/761459Proc#call
0%0%0.210.110.09761459StringIO.new
0.140.140.200.20 0.001291320/2582640Protobuf::Field::Int64Field#encode1522919/1523730Protobuf::Message#_protobuf_message_field
0% 0%0.240.240.200.20 0.002582640ProtobufJavaHelpers::Varinter.to_varint_641523730Protobuf::Message::Fields::ClassMethods.field_store
0.240.240.110.11 0.005165280/5165280Protobuf::Decoder.decode_each_field2286323/4570700Protobuf::Field::VarintField.encode
0% 0%0.240.240.200.20 0.005165280StringIO#eof4570700##>>
0.20 0.20 0.005165280/5168510Protobuf::Decoder.decode_each_field1522919/1522926Protobuf::Message#_protobuf_message_required_field_tags
0% 0.20 0.20 0.005168510##==1522926Protobuf::Message::Fields::ClassMethods.required_field_tags
0.200.200.19 0.002582641/2582825Protobuf::Field::StringField(singleton)#set_field0.1938/38##map!
0% 0%0.200.200.19 0.002582825##delete0.1938Bundler::LazySpecification#__materialize__
0.200.15 0.000.201/1Bundler::Definition#specs0.1537/37Bundler::Source::Rubygems#specs
0.180.110.07761459/761727Protobuf::Field::EnumField#encode
0% 0%0.200.000.201Bundler::SpecSet#materialize0.180.110.07761727Protobuf::Enum#to_i
0.120.100.10 0.000.12109/153Protobuf::Message::Fields::ClassMethods.optional1522918/2285051Protobuf::Field::EnumField#coerce!
0% 0% 0.180.00 0.18153Protobuf::Message::Fields::ClassMethods.define_field0.002285051Protobuf::Field::BaseField#type_class
0.170.180.18 0.000.17153/153Protobuf::Field.build3368414/3368414##each
0%0%0.180.180.003368414##<
0.170.170.110.11 0.003873960/3873960Protobuf::Decoder.decode_each_field2284530/3809398Protobuf::Field::VarintField.encode
0%0%0.170.170%0.180.18 0.003873960##>>3809398##<=
0.170.11 0.000.17153/153Protobuf::Message::Fields::ClassMethods.define_field0.11109/153Protobuf::Message::Fields::ClassMethods.optional
0% 0%0.170.16 0.000.170.16 153Protobuf::Field.buildProtobuf::Message::Fields::ClassMethods.define_field
0.170.01 0.16153/2584164Class#new0.000.15153/153Protobuf::Field.build
0.170.170.12 0.003681355/3681355##each0.123/285Gem::Specification.gemspec_stubs_in
0% 0%0.170.170.003681355##<0.160.020.15285##select
0.170.170.003873960/3873960Protobuf::Decoder.decode_each_field
0%0%0.170.170.12 0.003873960##&0.1268/68Gem::StubSpecification#valid?
0% 0% 0.160.000.166Bundler::SpecSet#for
0.160.01 0.166/6Kernel.loop0.003807453##>=
0.160.010.166/6Bundler::SpecSet#for0.150.000.151/2Bundler::Source::Rubygems#installed_specs
0% 0% 0.160.010.00 0.166Kernel.loop2Bundler::Index.build
0.14 0.00 0.14215/215Bundler::SpecSet#spec_for_dependency1/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0.160.010.00 0.15 153/153Class#newProtobuf::Message::Fields::ClassMethods.define_field
0% 0% 0.160.010.00 0.15 153Protobuf::Field::BaseField#initializeProtobuf::Field.build
0%0%
0.150.060.091137BasicObject#instance_eval0.010.14153/1524359Class#new
0.150.15 0.002582641/2583673Test::Resource#_protobuf_message_required_field_tags0.1537/37Bundler::LazySpecification#__materialize__
0% 0% 0.150.000.1537Bundler::Source::Rubygems#specs
0.150.000.151/1Bundler::Source::Rubygems#installed_specs
0.15 0.002583673Kernel.dup0.151/1Bundler::Source::Rubygems#specs
0% 0%0.140.030.1161Kernel.eval0.150.000.151Bundler::Source::Rubygems#installed_specs
0.100.020.0816/2584164Class#new0.150.000.151/2Bundler::Index.build
0.140.140.002582649/2584139Protobuf::Enum.fetch0.100.04761459/762229Protobuf::Field::StringField(singleton)#encode_to_stream
0% 0%0.140.140.002584139Kernel.kind_of?0.150.100.05762229BasicObject#!=
0.140.150.15 0.000.14215/215Kernel.loop3045836/3045836Protobuf::Decoder.decode_each_field
0% 0%0.140.150.15 0.000.14215Bundler::SpecSet#spec_for_dependency3045836StringIO#eof
0.140.01 0.140.001291588/1291588Protobuf::Enum#to_i153/153Class#new
0% 0% 0.140.01 0.140.001291588Protobuf::Enum#tag153Protobuf::Field::BaseField#initialize
0.130.130.14 0.002582640/2583129Protobuf::Enum.enum_for_tag_integer0.141/1Bundler::Index.build
0% 0%0.130.130.14 0.002583129##first0.141Bundler::RubygemsIntegration::MoreFuture#all_specs
0.130.130.001291320/1291320Protobuf::Decoder.decode_each_field
0%0%0.130.130.14 0.001291320StringIO#read0.141/1Gem::Specification.stubs
0% 0%0.130.020.11412##map!0.140.060.081136BasicObject#instance_eval
0.130.14 0.000.130.14 1/1 Kernel.require
0% 0%0.130.14 0.000.130.14 1 Gem::Specification.load_defaults
0.120.14 0.000.120.14 1/1 Gem::Specification.each_spec
0.120.000.121/1Gem::Specification.load_defaults
0% 0%0.120.000.121Gem::Specification.each_spec0.140.030.1160Kernel.eval
0.120.000.121/1Gem::Specification.each_gemspec0.110.020.0915/1524359Class#new
0.120.14 0.000.12109/109Kernel.require0.141/1Gem::Specification.load_defaults
0% 0%0.120.14 0.000.12109Protobuf::Message::Fields::ClassMethods.optional0.141Gem::Specification.each_spec
0.120.14 0.000.12109/153Protobuf::Message::Fields::ClassMethods.define_field0.141/1Gem::Specification.each_gemspec
0.120.14 0.000.120.14 1/1 Gem::Specification.each_spec
0% 0%0.120.14 0.000.120.14 1 Gem::Specification.each_gemspec
0.120.14 0.000.121/1292879##each0.141/762970##each
0.110.14 0.000.111/172Bundler::Definition#converge_paths0.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0% 0%0.120.14 0.000.12172##any?0.141Gem::Specification.stubs
0.110.12 0.000.112/2Bundler::Definition#specs_changed?0.121/1Gem::Specification.installed_stubs
0.120.120.130.13 0.001291473/1291473Protobuf::Field::VarintField.encode3045836/3048922Protobuf::Decoder.decode_each_field
0% 0%0.120.120.130.13 0.001291473ProtobufJavaHelpers::Varinter.to_varint3048922##==
0.110.110.12 0.001291320/1291320StringIO.new0.122/3##each
0% 0%0.110.110.130.000.133Gem::Specification.gemspec_stubs_in
0.12 0.001291320StringIO#initialize0.123/285##select
0.110.110.120.12 0.002582641/2582641Protobuf::Field::Int64Field(singleton)#set_field763521/763523Protobuf::Field::VarintField.encode
0% 0%0.110.110.120.12 0.002582641ProtobufJavaHelpers::Int64ProtobufField.coerce!763523##pack
0.110.120.12 0.000.111/1Bundler::Definition#initialize2284377/2284829Protobuf::Enum.enum_for_tag_integer
0% 0%0.110.000.111Bundler::Definition#converge_paths
0.110.120.12 0.000.111/172##any?2284829##first
0.110.12 0.000.112/2##any?0.1268/1220Gem::StubSpecification#valid?
0% 0%0.110.12 0.000.112Bundler::Definition#specs_changed?0.121220Gem::StubSpecification#data
0.120.01 0.110.000.112/2Bundler::Definition#specs_for_source_changed?68/68Kernel.open
0% 0%0.110.110.120.12 0.002582640ProtobufJavaHelpers::IntegerProtobufField.decode_varint_643046840Kernel.class
0.100.12 0.000.102/5Bundler::Definition#specs_for_source_changed?0.1268/68##select
0% 0%0.110.12 0.000.115Bundler::Source::Path#specs0.1268Gem::StubSpecification#valid?
0.110.12 0.000.115/5Bundler::Source::Path#local_specs0.1268/1220Gem::StubSpecification#data
0.110.12 0.000.112/2Bundler::Definition#specs_changed?0.121/1Gem::Specification.stubs
0% 0%0.110.12 0.000.112Bundler::Definition#specs_for_source_changed?0.121Gem::Specification.installed_stubs
0.100.12 0.000.102/5Bundler::Source::Path#specs0.121/1Gem::Specification.map_stubs
0.110.110.12 0.002582641/2582814Protobuf::Message#initialize0.121/1Gem::Specification.installed_stubs
0% 0%0.110.110.12 0.002582814Kernel.block_given?0.121Gem::Specification.map_stubs
0.120.000.121/1##flat_map
0.110.12 0.000.115/5Bundler::Source::Path#specs0.121/1Gem::Specification.map_stubs
0% 0%0.110.12 0.000.115Bundler::Source::Path#local_specs0.121##flat_map
0.110.12 0.000.113/3Bundler::Source::Path#load_spec_files0.121/762970##each
0.120.01 0.110.000.113/3Bundler::Source::Path#local_specs68/68Gem::StubSpecification#data
0% 0%0.120.01 0.110.000.113Bundler::Source::Path#load_spec_files68Kernel.open
0.110.11 0.001281320/1291320Proc#call0.11109/109Kernel.require
0% 0% 0.110.11 0.001291320Protobuf::Message#to_proto
0%0% 0.110.090.02449##reverse_each109Protobuf::Message::Fields::ClassMethods.optional
0.110.11 0.002582641/2582642Protobuf::Message#initialize
0%0%0.11 0.110.002582642##to_hash109/153Protobuf::Message::Fields::ClassMethods.define_field
0.100.11 0.00 0.101/1Bundler::Definition#specs13/14##each
0% 0%0.100.11 0.000.101Bundler::Definition#resolve0.1114Gem::Specification.load
0.10 0.10 0.002582641/2583806Protobuf::Field::StringField(singleton)#set_field761459/761459Protobuf::Decoder.decode_each_field
0% 0.10 0.10 0.002583806##to_s761459StringIO#read
0%0%0.100.000.1014Gem::Specification.load
@@ -67,4074 +67,3430 @@

Total time: 63.34

- + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - - + + - - - - - - - - - - + - - - - - - - - - - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - + - + + - - - + + - + - + + - - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - + - - + + - - + + - - - - + + + + - - - - - - + + + + + + - - - - - - - - - - + - - - - + + + + - + - - - - + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - + + + + - + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - - - - - - - - - - - + - - - - - + + + + + + - - - - + + + + - - - - - - - - - - + - - - - - + + + + + - + - - - - - + + + + + - - - - - - - - + + + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - - - - - + + + + + - + - - - + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + - + - + - - + + - - + + - + - - + + - + - + + + + + + + + + + + + + + + + + + + - + - - - + + + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - + + - - + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + + + + + + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - - + + - - + + - - - - + + + + - + - - - - - + + + + + - + - + + - - + - + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + - - + + - - + + - - - - - + + + + + - + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + + + - - + + + - - + + + + + + + + + + + + + + + + + + + + - - + + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - - - + + + + - - + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - - + - - - - - + + + + + - + - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - + - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + - - + + - - + + - + + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - - - - - - - - - + + + + + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - + + + + + + + + + + + - - + + - + - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - + + - - - - - + + + + + - - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - - - - - - + + + - - + + - + - + - - + + - + - - + + - + - - + + - + - + - - + + - + - + - + - + - - - - - + + + + + - + - + - + - + + - - - - - + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + - - + + + + + + + + + + + + + + + + + + + + - - + + + - - + + + + + + + + + + + - - + + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - + + + + + - - - - - - - + + + + + + + - + + - - - - + + + + - + + + + + + + + + + - - + + - - + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - + + - - + + - - + - - - - - - - - - - - - - - + + + + + - + - - - - + + + + - + + - - - - - + + + + + - - - - - - - - - - - - - + + + - + - - - - - + + + + + - + - - - - - + + + + + + + + + + + + + + - - - - - + + + + + - + - - - - - - - - - - - + + - - + + - + - - + + - - + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + - + - - + + - - + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + - + + - - - - - + + + + + - - - - - - + + + + + - - - + - - + + + + - + - - - - - + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + - - + - - - - - + + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + - + - - + - - + + + - + - + + - - - + + - - + + + - - - + + - + - - - - + + + + - + + - - - - - + + + + + + + + + + + + + + - + - - + + - + - - - - - + + + + + - - - - - - + + + + + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - - - - - + + + + + - - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + - - - + + - - - - - - - - - - + + - - - + + - + - - + + - - + + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - - + - - - - - - - - - - - - - - + + + + + - + - - - - - + + + + + - - - - - + + + + + - + - + + - - - + + - + - - + - - + + + - - + - - + + + - - - - - - + + + + - - + + + - + - - - - - + + + + + - - - - - + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - - - + + + - + - - + + - - + + - - + + - - + + - - - - - + + + + + - - - - - + + + + + - - + - - + - - + + + - - - - - + + + + + + - - + + - - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - - - - - + + + + + - - - - - + + + + + - - + - - - - - - - - - - - + - - + + + - + - - + - - + + + - - + - - + + + - - + - - - - - - - - - - - + - - + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + + - - - + + - - - - - + + + + + - + + - + + - - - + + - - - + + - - + + - + + - - - + + - - - - - - - - - - + + - - - + + - + - + - - - + + + - + - - - + + + - + - + - - + + - + - + - - - + + + - + - - - + + + - + - + - + - + - + - + + - - - + + - + + - - - + + - + + - + + - - - + + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - - + - - + - - + + + - - - - - + + + + + + - - + + - - - - - - + + + + + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - - - + + + + + + + + + + + + + - - - - - - + + + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + - + - + + - - - + + - + + - - - + + + + + + + + + + + + - + + - + + - - - + + + + + + + + + + + - + + - - - + + - - - - - - - - - - + + - - - + + - + - - - + + + - + - - - + + + - + - + - + - + - + - - + + - - + + - - + + - - + + - + - + + - - - + + - - - - - - - - - - + + - - - + + - + - - + - - + + + - - + + + + + + + + + + - - + + + - + - - + - - + + + - - + + + + + + + + + + - - + + + - + - - - + + + - + - - - + + + - + - - - - - - - - - - - - + - - + + + - + - + - - - + + + - + - - - + + + - - - - + + + + + + + + + + + + + + + - - - + + + - + @@ -4142,7 +3498,7 @@

Total time: 63.34

- + @@ -4151,18 +3507,18 @@

Total time: 63.34

- + - + - + - + @@ -4170,7 +3526,7 @@

Total time: 63.34

- + @@ -4179,16 +3535,16 @@

Total time: 63.34

- + - + - + @@ -4198,7 +3554,7 @@

Total time: 63.34

- + @@ -4207,1334 +3563,1362 @@

Total time: 63.34

- + - + - - + + - - - - - + + + + + - - - - + + + + + + + + + + + + + - + - + - - - + + + - + - - - + + + - + - + - - - + + + - + - + - - + + - - - - - - - - - - - - - + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + - - - + + + + - - + + + + - - - - - - - - - - + + + + + + + - - - + + - - - - - - + + + + + + + + - - + + + - + + + + + + - - - - + + + + + + - - - - - - + + - - - - - - + - + + - - - - - + + + + + + + + + + + - - - - - - - + + + + + - - + + + + + + + + + + + + - - - - - - + + + + + - - + + + - - + + + + + + + - - - + + - - + + - - + + + + + + - - + + - + - - + + - - - - - - - - - + - - - - - - - - + - - - - - + + - + + + - + + + + + + + + + + - - - - - + + + + + + - - - - - - + + + + + + + + + + + + - - - + - - - + + + + + + - - - + + + + + + - + - - - - - - - - - - - - - - + + - - + + - - + + + + + + + + + + - - - - - - + + + + - - - - - - - + + + - - + - - - - - - - - + + + - + + + + + + + - - - + + + + + + + + + + + + + - - - - - + + - - + - + - - - - + + - - + + + + + + - - + + + + - - - - + - - - - - + + - - - + + + - - + + + + + + + + + + + - - - - + + + + + + - + + + - - - - - - + + + + - - - - - - - - - + + + - - - - - - + - - - - - + - - - - - - - + - - - + - - + + + + + + + + - + + + + - - + + + + - - - - - + + - - - - + + + + + + + - - - + - + + - - - - - - + + + + - - - - + + + + - - - - - - - - - + + + - - - - + + + + + + + + + + - + + - - + + - - - - + - + + + - + + - - - + - - - + + + + + + + + + + + + + - - - - + + + + + + + + - + - - + - - - - + + - - + + + - + + - - - - - + + + - + + + - - - - - + + + + + + - - - + + + - - - + + - + - - - - + - - - + + + + + + + + - + + + + - - - - + + + - + - + + + + + + - + - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - + + - - - - + + + + + + - + - - - - + + + + - + + + - + - + - - + + + - - - - - - - - + - - + + + + + + + + + + + - - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + - - + + + - - - + + + - + - - - - - - - - + + + + + - + - - - - - - - + + + + - + + - + - - + + - - - + - - + + + + + - - - + + + + - + + - - - - + + - - @@ -5546,36 +4930,39 @@

Total time: 63.34

+ - + - - + + + + - + @@ -5586,11 +4973,11 @@

Total time: 63.34

- + @@ -5604,11 +4991,8 @@

Total time: 63.34

- - - @@ -5619,8 +5003,8 @@

Total time: 63.34

+ - @@ -5629,6 +5013,7 @@

Total time: 63.34

+ @@ -5636,25 +5021,25 @@

Total time: 63.34

+ + - - - + @@ -5666,9 +5051,9 @@

Total time: 63.34

- + @@ -5677,6 +5062,7 @@

Total time: 63.34

+ From ded40a7bbe798456493e104eb958be1425de01d7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 15 Jan 2019 13:39:08 -0700 Subject: [PATCH 1132/1191] bump to 3.9.0.pre --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9a70aa66..34d7e5fc 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.8.5' # rubocop:disable Style/MutableConstant + VERSION = '3.9.0.pre' # rubocop:disable Style/MutableConstant end From b0c3c3ebd36f02589f5a57e38f0f327f7c5e29eb Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 16 Jan 2019 09:04:31 -0700 Subject: [PATCH 1133/1191] only use boolean check when not repeated --- lib/protobuf/field/base_field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 66b5076b..6f2f4f7f 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -145,7 +145,7 @@ def field?(values) end def define_field_and_present_predicate! - @field_and_present_predicate = if type_class == ::Protobuf::Field::BoolField # boolean present check + @field_and_present_predicate = if !repeated? && type_class == ::Protobuf::Field::BoolField # boolean present check OBJECT_MODULE::BoolFieldAndPresentPredicate.new(self) else OBJECT_MODULE::BaseFieldAndPresentPredicate.new(self) From a01a4d1f4c291682ab6d398be736ebd75c1769c6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 16 Jan 2019 09:04:57 -0700 Subject: [PATCH 1134/1191] bump to pre2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 34d7e5fc..635d6204 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.9.0.pre' # rubocop:disable Style/MutableConstant + VERSION = '3.9.0.pre2' # rubocop:disable Style/MutableConstant end From 6d82a30e718e0a8a7ff36e624569d7f79d3e773b Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Thu, 31 Jan 2019 16:53:11 -0700 Subject: [PATCH 1135/1191] adding tracing --- lib/protobuf/rpc/client.rb | 7 +++++-- lib/protobuf/rpc/connectors/base.rb | 10 +++++++++- lib/protobuf/rpc/middleware/request_decoder.rb | 16 +++++++++++++++- lib/protobuf/rpc/rpc.pb.rb | 9 +++++++++ proto/rpc.proto | 11 +++++++++++ protobuf.gemspec | 1 + 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 74791d23..4baa8504 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -105,7 +105,8 @@ def on_success=(callable) def method_missing(method_name, *params) service = options[:service] if service.rpc_method?(method_name) - logger.debug { sign_message("#{service.name}##{method_name}") } + operation = "#{service.name}##{method_name}" + logger.debug { sign_message(operation) } rpc = service.rpcs[method_name.to_sym] options[:request_type] = rpc.request_type @@ -126,7 +127,9 @@ def method_missing(method_name, *params) logger.debug { sign_message("no block given for callbacks") } end - send_request + ::OpenTracing.start_active_span(operation) do |scope| + send_request + end else logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } super(method_name, *params) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 2e9c76ba..39127b1a 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -4,6 +4,7 @@ require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' require 'protobuf/rpc/stat' +require 'json' module Protobuf module Rpc @@ -138,11 +139,18 @@ def ping_port_enabled? end def request_bytes + trace_carrier = {} + ::OpenTracing.inject(::OpenTracing.active_span.context, + ::OpenTracing::FORMAT_TEXT_MAP, + trace_carrier) + trace = ::Protobuf::Socketrpc::Trace.new(:raw => JSON.generate(trace_carrier)) + validate_request_type! fields = { :service_name => @options[:service].name, :method_name => @options[:method].to_s, :request_proto => @options[:request], - :caller => request_caller } + :caller => request_caller, + :trace => trace } return ::Protobuf::Socketrpc::Request.encode(fields) rescue => e diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 45469883..99c108df 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -28,7 +28,16 @@ def _call(env) env.request_type = rpc_method.request_type env.response_type = rpc_method.response_type - app.call(env) + operation = "#{service_name}##{method_name}" + trace = ::OpenTracing.extract(::OpenTracing::FORMAT_TEXT_MAP, trace_context) + + # return app.call(env) if trace.nil? + + result = nil + ::OpenTracing.start_active_span(operation, :child_of => trace) do |scope| + result = app.call(env) + end + result end def log_signature @@ -51,6 +60,11 @@ def request raise BadRequestData, "Unable to decode request: #{exception.message}" end + def trace_context + return nil if request_wrapper.trace.nil? # XXX test + @trace_context ||= JSON.parse(request_wrapper.trace.raw) + end + # Decode the incoming request object into our expected request object # def request_wrapper diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index eaea971f..c88a3c28 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -31,6 +31,7 @@ class ErrorReason < ::Protobuf::Enum # class Request < ::Protobuf::Message; end class Response < ::Protobuf::Message; end + class Trace < ::Protobuf::Message; end ## @@ -41,6 +42,9 @@ class Request required :string, :method_name, 2 optional :bytes, :request_proto, 3 optional :string, :caller, 4 + # Extension Fields + extensions 200...536870912 + optional ::Protobuf::Socketrpc::Trace, :".protobuf.socketrpc.Request.trace", 200, :extension => true end class Response @@ -51,6 +55,11 @@ class Response optional :string, :server, 5 end + class Trace + optional :string, :type, 1 + optional :bytes, :raw, 2 + end + end end diff --git a/proto/rpc.proto b/proto/rpc.proto index 17a1e350..52061aba 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -26,10 +26,16 @@ package protobuf.socketrpc; message Request { + extensions 200 to max; + required string service_name = 1; // Fully- qualified Service class name required string method_name = 2; // Service method to invoke optional bytes request_proto = 3; // Serialized request bytes optional string caller = 4; // Calling hostname or address + + extend Request { + optional Trace trace = 200; + } } message Response @@ -41,6 +47,11 @@ message Response optional string server = 5; // Server hostname or address } +message Trace { + optional string type = 1; + optional bytes raw = 2; +} + // Possible error reasons // The server-side errors are returned in the response from the server. // The client-side errors are returned by the client-side code when it doesn't diff --git a/protobuf.gemspec b/protobuf.gemspec index 624a43eb..598c28c5 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -23,6 +23,7 @@ require "protobuf/version" active_support_max_version = "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2") s.add_dependency "activesupport", '>= 3.2', active_support_max_version s.add_dependency 'middleware' + s.add_dependency 'opentracing' s.add_dependency 'thor' s.add_dependency 'thread_safe' From 220da508b9f6309ecfe50f5bde1a91b2fe643f00 Mon Sep 17 00:00:00 2001 From: Nephi Allred Date: Mon, 4 Feb 2019 11:48:36 -0700 Subject: [PATCH 1136/1191] Changed trace injection/extraction format to binary --- lib/protobuf/rpc/connectors/base.rb | 7 +++---- lib/protobuf/rpc/middleware/request_decoder.rb | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 39127b1a..e424ca69 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -4,7 +4,6 @@ require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' require 'protobuf/rpc/stat' -require 'json' module Protobuf module Rpc @@ -139,11 +138,11 @@ def ping_port_enabled? end def request_bytes - trace_carrier = {} + trace_carrier = "" ::OpenTracing.inject(::OpenTracing.active_span.context, - ::OpenTracing::FORMAT_TEXT_MAP, + ::OpenTracing::FORMAT_BINARY, trace_carrier) - trace = ::Protobuf::Socketrpc::Trace.new(:raw => JSON.generate(trace_carrier)) + trace = ::Protobuf::Socketrpc::Trace.new(:raw => trace_carrier) validate_request_type! fields = { :service_name => @options[:service].name, diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 99c108df..6bcd6461 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -29,7 +29,7 @@ def _call(env) env.response_type = rpc_method.response_type operation = "#{service_name}##{method_name}" - trace = ::OpenTracing.extract(::OpenTracing::FORMAT_TEXT_MAP, trace_context) + trace = ::OpenTracing.extract(::OpenTracing::FORMAT_BINARY, trace_context) # return app.call(env) if trace.nil? @@ -62,7 +62,7 @@ def request def trace_context return nil if request_wrapper.trace.nil? # XXX test - @trace_context ||= JSON.parse(request_wrapper.trace.raw) + @trace_context ||= request_wrapper.trace.raw.to_s end # Decode the incoming request object into our expected request object From 7653155dec0d71837807e8939d917d442eacec83 Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Tue, 5 Feb 2019 16:37:08 -0700 Subject: [PATCH 1137/1191] moving request decoder logic out of this gem and into another middleware gem --- lib/protobuf/rpc/env.rb | 1 + lib/protobuf/rpc/middleware/request_decoder.rb | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index cf6aea60..3d7c166e 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -41,6 +41,7 @@ def self.hash_accessor(*names) #:nodoc: :method_name, :request, :request_type, + :request_wrapper, :response, :response_type, :rpc_method, diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 6bcd6461..396b41ac 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -21,6 +21,7 @@ def _call(env) env.service_name = service_name env.method_name = method_name env.request = request + env.request_wrapper = request_wrapper env.client_host = request_wrapper.caller env.rpc_service = service @@ -28,16 +29,7 @@ def _call(env) env.request_type = rpc_method.request_type env.response_type = rpc_method.response_type - operation = "#{service_name}##{method_name}" - trace = ::OpenTracing.extract(::OpenTracing::FORMAT_BINARY, trace_context) - - # return app.call(env) if trace.nil? - - result = nil - ::OpenTracing.start_active_span(operation, :child_of => trace) do |scope| - result = app.call(env) - end - result + app.call(env) end def log_signature From e8a2bf6011d037456706780686ed57865cbe3b69 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 5 Feb 2019 18:47:39 -0700 Subject: [PATCH 1138/1191] bump to 3.9.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 635d6204..8d43f2bf 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.9.0.pre2' # rubocop:disable Style/MutableConstant + VERSION = '3.9.0' # rubocop:disable Style/MutableConstant end From 119414766edcd4a444da8cf6e00726348e0ea604 Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Wed, 6 Feb 2019 12:13:31 -0700 Subject: [PATCH 1139/1191] removing tracing from client --- lib/protobuf/rpc/connectors/base.rb | 9 +-------- protobuf.gemspec | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index e424ca69..2e9c76ba 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -138,18 +138,11 @@ def ping_port_enabled? end def request_bytes - trace_carrier = "" - ::OpenTracing.inject(::OpenTracing.active_span.context, - ::OpenTracing::FORMAT_BINARY, - trace_carrier) - trace = ::Protobuf::Socketrpc::Trace.new(:raw => trace_carrier) - validate_request_type! fields = { :service_name => @options[:service].name, :method_name => @options[:method].to_s, :request_proto => @options[:request], - :caller => request_caller, - :trace => trace } + :caller => request_caller } return ::Protobuf::Socketrpc::Request.encode(fields) rescue => e diff --git a/protobuf.gemspec b/protobuf.gemspec index 598c28c5..624a43eb 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -23,7 +23,6 @@ require "protobuf/version" active_support_max_version = "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2") s.add_dependency "activesupport", '>= 3.2', active_support_max_version s.add_dependency 'middleware' - s.add_dependency 'opentracing' s.add_dependency 'thor' s.add_dependency 'thread_safe' From dfad4eed44f7e96b333f020516812b2960129bb2 Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Wed, 6 Feb 2019 12:36:46 -0700 Subject: [PATCH 1140/1191] removing tracing from client and decoder --- lib/protobuf/rpc/client.rb | 7 ++----- lib/protobuf/rpc/middleware/request_decoder.rb | 5 ----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 4baa8504..74791d23 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -105,8 +105,7 @@ def on_success=(callable) def method_missing(method_name, *params) service = options[:service] if service.rpc_method?(method_name) - operation = "#{service.name}##{method_name}" - logger.debug { sign_message(operation) } + logger.debug { sign_message("#{service.name}##{method_name}") } rpc = service.rpcs[method_name.to_sym] options[:request_type] = rpc.request_type @@ -127,9 +126,7 @@ def method_missing(method_name, *params) logger.debug { sign_message("no block given for callbacks") } end - ::OpenTracing.start_active_span(operation) do |scope| - send_request - end + send_request else logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } super(method_name, *params) diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 396b41ac..c4efe823 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -52,11 +52,6 @@ def request raise BadRequestData, "Unable to decode request: #{exception.message}" end - def trace_context - return nil if request_wrapper.trace.nil? # XXX test - @trace_context ||= request_wrapper.trace.raw.to_s - end - # Decode the incoming request object into our expected request object # def request_wrapper From b1563a37cd636fbd9516a139cbeb279fe1ea65d9 Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Thu, 7 Feb 2019 14:03:01 -0700 Subject: [PATCH 1141/1191] moving to map of headers --- lib/protobuf/rpc/rpc.pb.rb | 9 +++++++-- proto/rpc.proto | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index c88a3c28..d1b2b441 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -32,6 +32,7 @@ class ErrorReason < ::Protobuf::Enum class Request < ::Protobuf::Message; end class Response < ::Protobuf::Message; end class Trace < ::Protobuf::Message; end + class MapEntry < ::Protobuf::Message; end ## @@ -56,8 +57,12 @@ class Response end class Trace - optional :string, :type, 1 - optional :bytes, :raw, 2 + repeated ::Protobuf::Socketrpc::MapEntry, :headers, 1 + end + + class MapEntry + optional :string, :key, 1 + optional :string, :value, 2 end end diff --git a/proto/rpc.proto b/proto/rpc.proto index 52061aba..22671154 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -48,8 +48,12 @@ message Response } message Trace { - optional string type = 1; - optional bytes raw = 2; + repeated MapEntry headers = 1; +} + +message MapEntry { + optional string key = 1; + optional string value = 2; } // Possible error reasons From beb9d4e5c290fe4abab4cd2eb585d93e46d89e1f Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Fri, 8 Feb 2019 14:11:41 -0700 Subject: [PATCH 1142/1191] moving to request headers --- lib/protobuf/rpc/rpc.pb.rb | 13 ++++--------- proto/rpc.proto | 13 +++---------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index d1b2b441..741d6999 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -31,8 +31,7 @@ class ErrorReason < ::Protobuf::Enum # class Request < ::Protobuf::Message; end class Response < ::Protobuf::Message; end - class Trace < ::Protobuf::Message; end - class MapEntry < ::Protobuf::Message; end + class Header < ::Protobuf::Message; end ## @@ -43,9 +42,9 @@ class Request required :string, :method_name, 2 optional :bytes, :request_proto, 3 optional :string, :caller, 4 + repeated ::Protobuf::Socketrpc::Header, :headers, 5 # Extension Fields extensions 200...536870912 - optional ::Protobuf::Socketrpc::Trace, :".protobuf.socketrpc.Request.trace", 200, :extension => true end class Response @@ -56,12 +55,8 @@ class Response optional :string, :server, 5 end - class Trace - repeated ::Protobuf::Socketrpc::MapEntry, :headers, 1 - end - - class MapEntry - optional :string, :key, 1 + class Header + required :string, :key, 1 optional :string, :value, 2 end diff --git a/proto/rpc.proto b/proto/rpc.proto index 22671154..dce4586c 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -32,10 +32,7 @@ message Request required string method_name = 2; // Service method to invoke optional bytes request_proto = 3; // Serialized request bytes optional string caller = 4; // Calling hostname or address - - extend Request { - optional Trace trace = 200; - } + repeated Header headers = 5; // General purpose request headers } message Response @@ -47,12 +44,8 @@ message Response optional string server = 5; // Server hostname or address } -message Trace { - repeated MapEntry headers = 1; -} - -message MapEntry { - optional string key = 1; +message Header { + required string key = 1; optional string value = 2; } From 0796277076017953c36d439881ed0d144cab4b0c Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Fri, 8 Feb 2019 14:13:12 -0700 Subject: [PATCH 1143/1191] removing extension bounds --- lib/protobuf/rpc/rpc.pb.rb | 2 -- proto/rpc.proto | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index 741d6999..0d2937a7 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -43,8 +43,6 @@ class Request optional :bytes, :request_proto, 3 optional :string, :caller, 4 repeated ::Protobuf::Socketrpc::Header, :headers, 5 - # Extension Fields - extensions 200...536870912 end class Response diff --git a/proto/rpc.proto b/proto/rpc.proto index dce4586c..f496139e 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -26,8 +26,6 @@ package protobuf.socketrpc; message Request { - extensions 200 to max; - required string service_name = 1; // Fully- qualified Service class name required string method_name = 2; // Service method to invoke optional bytes request_proto = 3; // Serialized request bytes From 996f4f40f0ee0ca15269257483c1c6eea9fc72de Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Mon, 18 Mar 2019 13:49:26 -0600 Subject: [PATCH 1144/1191] Creating request fields in new Base#request_fields method. --- lib/protobuf/rpc/connectors/base.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 2e9c76ba..f248f253 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -137,14 +137,16 @@ def ping_port_enabled? ENV.key?("PB_RPC_PING_PORT") end + def request_fields + { :service_name => @options[:service].name, + :method_name => @options[:method].to_s, + :request_proto => @options[:request], + :caller => request_caller } + end + def request_bytes validate_request_type! - fields = { :service_name => @options[:service].name, - :method_name => @options[:method].to_s, - :request_proto => @options[:request], - :caller => request_caller } - - return ::Protobuf::Socketrpc::Request.encode(fields) + return ::Protobuf::Socketrpc::Request.encode(request_fields) rescue => e failure(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") end From 8d6c7ce4dc9c48a64ac284ff2d6bec06b1a8bbcf Mon Sep 17 00:00:00 2001 From: Marcos Minond Date: Mon, 18 Mar 2019 14:26:43 -0600 Subject: [PATCH 1145/1191] Alphabetically sorting class methods --- lib/protobuf/rpc/connectors/base.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index f248f253..bb1c084e 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -137,13 +137,6 @@ def ping_port_enabled? ENV.key?("PB_RPC_PING_PORT") end - def request_fields - { :service_name => @options[:service].name, - :method_name => @options[:method].to_s, - :request_proto => @options[:request], - :caller => request_caller } - end - def request_bytes validate_request_type! return ::Protobuf::Socketrpc::Request.encode(request_fields) @@ -155,6 +148,13 @@ def request_caller @options[:client_host] || ::Protobuf.client_host end + def request_fields + { :service_name => @options[:service].name, + :method_name => @options[:method].to_s, + :request_proto => @options[:request], + :caller => request_caller } + end + def send_request fail 'If you inherit a Connector from Base you must implement send_request' end From a2448e4df3fad0650c49655517d4fe141129e1dd Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 18 Mar 2019 17:32:10 -0400 Subject: [PATCH 1146/1191] Bump version to 3.10.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 8d43f2bf..9a551198 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.9.0' # rubocop:disable Style/MutableConstant + VERSION = '3.10.0' # rubocop:disable Style/MutableConstant end From a2e0cbb783d49d37648c07d795dc4f7eb8d14eb1 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 18 Mar 2019 17:33:46 -0400 Subject: [PATCH 1147/1191] Update changelog --- CHANGES.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2677938a..1577e709 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,14 @@ # Stable (3.8.x) + +3.10.0 +------ +- Add headers to request proto + +3.9.0 +----- +- Performance improvements + 3.8.0 ----- - Map types now supported (#367) From 0f03ed27fd28372675c7c3ed26188acbb1bbe8e5 Mon Sep 17 00:00:00 2001 From: Steve Newell Date: Mon, 26 Aug 2019 10:33:01 -0600 Subject: [PATCH 1148/1191] Add error reason to logs The error status will only be set in ::Protobuf::Rpc::Connectors::Base#failure method. Otherwise it will default to NONE. --- lib/protobuf/rpc/connectors/base.rb | 3 ++- lib/protobuf/rpc/stat.rb | 24 ++++++++++++++++++++++-- proto/rpc.proto | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index bb1c084e..969d777c 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -63,8 +63,9 @@ def data_callback(data) # @param [String] message The error message def failure(code, message) @error = ClientError.new - @error.code = ::Protobuf::Socketrpc::ErrorReason.fetch(code) + @stats.status = @error.code = ::Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message + logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } @failure_cb.call(@error) unless @failure_cb.nil? diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 18d0eff6..3eaf9499 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -1,20 +1,36 @@ require 'date' require 'time' require 'protobuf/logging' +require 'protobuf/rpc/rpc.pb' module Protobuf module Rpc class Stat attr_accessor :mode, :start_time, :end_time, :request_size, :dispatcher - attr_accessor :response_size, :client, :service, :method_name + attr_accessor :response_size, :client, :service, :method_name, :status attr_reader :server MODES = [:SERVER, :CLIENT].freeze + ERROR_TRANSLATIONS = { + ::Protobuf::Socketrpc::ErrorReason::NONE => "OK", + ::Protobuf::Socketrpc::ErrorReason::BAD_REQUEST_DATA => "BAD_REQUEST_DATA", + ::Protobuf::Socketrpc::ErrorReason::BAD_REQUEST_PROTO => "BAD_REQUEST_PROTO", + ::Protobuf::Socketrpc::ErrorReason::SERVICE_NOT_FOUND => "SERVICE_NOT_FOUND", + ::Protobuf::Socketrpc::ErrorReason::METHOD_NOT_FOUND => "METHOD_NOT_FOUND", + ::Protobuf::Socketrpc::ErrorReason::RPC_ERROR => "RPC_ERROR", + ::Protobuf::Socketrpc::ErrorReason::RPC_FAILED => "RPC_FAILED", + ::Protobuf::Socketrpc::ErrorReason::INVALID_REQUEST_PROTO => "INVALID_REQUEST_PROTO", + ::Protobuf::Socketrpc::ErrorReason::BAD_RESPONSE_PROTO => "BAD_RESPONSE_PROTO", + ::Protobuf::Socketrpc::ErrorReason::UNKNOWN_HOST => "UNKNOWN_HOST", + ::Protobuf::Socketrpc::ErrorReason::IO_ERROR => "IO_ERROR", + } + def initialize(mode = :SERVER) @mode = mode @request_size = 0 @response_size = 0 + @status = ::Protobuf::Socketrpc::ErrorReason::NONE # default to NONE and only set if error occurs start end @@ -78,6 +94,10 @@ def client? @mode == :CLIENT end + def status_string + ERROR_TRANSLATIONS.fetch(status, "UNKNOWN_ERROR") + end + def to_s [ server? ? "[SRV]" : "[CLT]", @@ -86,6 +106,7 @@ def to_s rpc, sizes, elapsed_time, + status_string, @end_time.try(:iso8601), ].compact.join(' - ') end @@ -93,7 +114,6 @@ def to_s def trace_id ::Thread.current.object_id.to_s(16) end - end end end diff --git a/proto/rpc.proto b/proto/rpc.proto index f496139e..353a1e1d 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -66,4 +66,5 @@ enum ErrorReason BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto UNKNOWN_HOST = 8; // Could not find supplied host IO_ERROR = 9; // I/O error while communicating with server + NONE = 10000; // No error. Typically not used. This is a placeholder to remind us not to use this value. } From 3557e4b98cf8196582c6fb96b48426fcec37d162 Mon Sep 17 00:00:00 2001 From: Steve Newell Date: Tue, 27 Aug 2019 10:40:46 -0600 Subject: [PATCH 1149/1191] remove enum NONE --- lib/protobuf/rpc/stat.rb | 4 ++-- proto/rpc.proto | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 3eaf9499..20a5ca8a 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -13,7 +13,6 @@ class Stat MODES = [:SERVER, :CLIENT].freeze ERROR_TRANSLATIONS = { - ::Protobuf::Socketrpc::ErrorReason::NONE => "OK", ::Protobuf::Socketrpc::ErrorReason::BAD_REQUEST_DATA => "BAD_REQUEST_DATA", ::Protobuf::Socketrpc::ErrorReason::BAD_REQUEST_PROTO => "BAD_REQUEST_PROTO", ::Protobuf::Socketrpc::ErrorReason::SERVICE_NOT_FOUND => "SERVICE_NOT_FOUND", @@ -30,7 +29,6 @@ def initialize(mode = :SERVER) @mode = mode @request_size = 0 @response_size = 0 - @status = ::Protobuf::Socketrpc::ErrorReason::NONE # default to NONE and only set if error occurs start end @@ -95,6 +93,8 @@ def client? end def status_string + return "OK" if status.nil? + ERROR_TRANSLATIONS.fetch(status, "UNKNOWN_ERROR") end diff --git a/proto/rpc.proto b/proto/rpc.proto index 353a1e1d..f496139e 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -66,5 +66,4 @@ enum ErrorReason BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto UNKNOWN_HOST = 8; // Could not find supplied host IO_ERROR = 9; // I/O error while communicating with server - NONE = 10000; // No error. Typically not used. This is a placeholder to remind us not to use this value. } From ceba333492a60165dd68a0b92817453831e9421a Mon Sep 17 00:00:00 2001 From: Steve Newell Date: Tue, 27 Aug 2019 13:55:18 -0600 Subject: [PATCH 1150/1191] update/fix specs --- spec/lib/protobuf/rpc/connectors/base_spec.rb | 10 +++---- spec/lib/protobuf/rpc/stat_spec.rb | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index e5890307..32b8cd8b 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -187,14 +187,14 @@ shared_examples "a ConnectorDisposition" do |meth, cb, *args| it "calls #complete before exit" do - subject.stats = double("Object", :stop => true) + subject.stats = ::Protobuf::Rpc::Stat.new(:stop => true) expect(subject).to receive(:complete) subject.method(meth).call(*args) end it "calls the #{cb} callback when provided" do - stats = double("Object") + stats = ::Protobuf::Rpc::Stat.new allow(stats).to receive(:stop).and_return(true) subject.stats = stats some_cb = double("Object") @@ -205,7 +205,7 @@ end it "calls the complete callback when provided" do - stats = double("Object") + stats = ::Protobuf::Rpc::Stat.new allow(stats).to receive(:stop).and_return(true) subject.stats = stats comp_cb = double("Object") @@ -217,8 +217,8 @@ end - it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message") - it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message") + it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", :RPC_ERROR, "message") + it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", :RPC_ERROR, "message") it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response") it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response") it_behaves_like("a ConnectorDisposition", :complete, "complete_cb") diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index 2b6c6011..9abd627f 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -33,7 +33,7 @@ ::Timecop.freeze(1.62.seconds.from_now) do stats.stop - expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}" + expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - OK - #{::Time.now.iso8601}" end end end @@ -44,7 +44,7 @@ stats.client = 'myserver1' stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars)) stats.request_size = 43 - expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-" + expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/- - OK" end end end @@ -61,12 +61,31 @@ ::Timecop.freeze(0.832.seconds.from_now) do stats.stop - expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}" + expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - OK - #{::Time.now.iso8601}" end end end + describe 'error log' do + it 'resolves error to a string' do + ::Timecop.freeze(10.minutes.ago) do + stats = ::Protobuf::Rpc::Stat.new(:CLIENT) + stats.server = ['30000', 'myserver1.myhost.com'] + stats.service = 'Foo::BarService' + stats.status = ::Protobuf::Socketrpc::ErrorReason::RPC_ERROR + stats.method_name = 'find_bars' + stats.request_size = 37 + stats.response_size = 12345 + + ::Timecop.freeze(0.832.seconds.from_now) do + stats.stop + expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - RPC_ERROR - #{::Time.now.iso8601}" + end + end + end + end + context 'when request is still running' do it 'omits response size, duration, and timestamp' do stats = ::Protobuf::Rpc::Stat.new(:CLIENT) @@ -74,7 +93,7 @@ stats.service = 'Foo::BarService' stats.method_name = 'find_bars' stats.request_size = 37 - expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-" + expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/- - OK" end end end From 0abd9bed19bfad3d9b4872b3d003d686219374c9 Mon Sep 17 00:00:00 2001 From: Steve Newell Date: Tue, 27 Aug 2019 14:27:49 -0600 Subject: [PATCH 1151/1191] rubocop --- lib/protobuf/rpc/stat.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 20a5ca8a..841181a3 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -23,7 +23,7 @@ class Stat ::Protobuf::Socketrpc::ErrorReason::BAD_RESPONSE_PROTO => "BAD_RESPONSE_PROTO", ::Protobuf::Socketrpc::ErrorReason::UNKNOWN_HOST => "UNKNOWN_HOST", ::Protobuf::Socketrpc::ErrorReason::IO_ERROR => "IO_ERROR", - } + }.freeze def initialize(mode = :SERVER) @mode = mode From 313756208739c2f47f23cbcecfb9100ad2cc9216 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 28 Aug 2019 10:41:41 -0400 Subject: [PATCH 1152/1191] Bump version to 3.10.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9a551198..6f29ce5f 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.0' # rubocop:disable Style/MutableConstant + VERSION = '3.10.1' # rubocop:disable Style/MutableConstant end From 7b77060f2bf3f16e5229966336c818db6c22a9c3 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 9 Oct 2019 20:40:26 -0400 Subject: [PATCH 1153/1191] Add a "before_server_bind" event for server to do work before starting --- lib/protobuf/cli.rb | 2 ++ spec/lib/protobuf/cli_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3432a0dd..35c6d936 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -240,6 +240,8 @@ def shutdown_server def start_server debug_say('Running server') + ::ActiveSupport::Notifications.instrument("before_server_bind") + runner.run do logger.info do "pid #{::Process.pid} -- #{mode} RPC Server listening at #{options.host}:#{options.port}" diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 99fdb960..26b974bc 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -275,6 +275,17 @@ end end + context 'before server bind' do + it 'publishes a message before the runner runs' do + server_published_message_before_bind = false + ::ActiveSupport::Notifications.subscribe('before_server_bind') do + server_published_message_before_bind = true + end + described_class.start(args) + expect(server_published_message_before_bind).to eq(true) + end + end + end end From 91e59ebfd332553b24f2cf5eff012670591608c6 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 9 Oct 2019 20:50:21 -0400 Subject: [PATCH 1154/1191] Add {before,after}_server_bind callbacks to Protobuf --- lib/protobuf.rb | 12 ++++++++++++ spec/lib/protobuf/cli_spec.rb | 30 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index a1300025..69139e2c 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -54,6 +54,18 @@ class << self attr_writer :client_host end + def self.after_server_bind(&block) + ::ActiveSupport::Notifications.subscribe('after_server_bind') do |*args| + block.call(*args) + end + end + + def self.before_server_bind(&block) + ::ActiveSupport::Notifications.subscribe('before_server_bind') do |*args| + block.call(*args) + end + end + def self.client_host @client_host ||= Socket.gethostname end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 26b974bc..ea78ed0d 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -275,14 +275,38 @@ end end + context 'after server bind' do + let(:sock_runner) { double("FakeRunner", :run => nil) } + + before { allow(sock_runner).to receive(:run).and_yield } + + it 'publishes when using the lib/protobuf callback' do + message_after_bind = false + ::Protobuf.after_server_bind do + message_after_bind = true + end + described_class.start(args) + expect(message_after_bind).to eq(true) + end + end + context 'before server bind' do it 'publishes a message before the runner runs' do - server_published_message_before_bind = false + message_before_bind = false ::ActiveSupport::Notifications.subscribe('before_server_bind') do - server_published_message_before_bind = true + message_before_bind = true + end + described_class.start(args) + expect(message_before_bind).to eq(true) + end + + it 'publishes when using the lib/protobuf callback' do + message_before_bind = false + ::Protobuf.before_server_bind do + message_before_bind = true end described_class.start(args) - expect(server_published_message_before_bind).to eq(true) + expect(message_before_bind).to eq(true) end end From dd245b6ffce47aacb2ce29fee25f51e0edebf3f4 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 14 Oct 2019 20:12:49 -0600 Subject: [PATCH 1155/1191] Bump version to 3.10.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6f29ce5f..5bd60165 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.1' # rubocop:disable Style/MutableConstant + VERSION = '3.10.2' # rubocop:disable Style/MutableConstant end From 4f45a8a44cb864a561fc7988994c4886bf22453b Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Tue, 7 Jan 2020 10:04:01 -0500 Subject: [PATCH 1156/1191] Bump version to 3.10.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5bd60165..d96e0847 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.2' # rubocop:disable Style/MutableConstant + VERSION = '3.10.3' # rubocop:disable Style/MutableConstant end From ff9133f5367365e3f2b6fb742283d505e8b6bbcd Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 17:37:11 -0600 Subject: [PATCH 1157/1191] Add a CI config for circle-ci --- .circleci/config.yml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..9d4e511a --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,43 @@ +version: 2.1 + +orbs: + # orbs are basically bundles of pre-written build scripts that work for common cases + # https://github.com/CircleCI-Public/ruby-orb + ruby: circleci/ruby@1.1 + +jobs: + # skipping build step because Gemfile.lock is not included in the source + # this makes the bundler caching step a noop + test: + parameters: + ruby-image: + type: string + docker: + - image: << parameters.ruby-image >> + steps: + - run: + command: sudo apt-get update + - run: + message: Install ZeroMQ and Protobuf Compiler + command: sudo apt-get -y install libzmq3-dev protobuf-compiler + - checkout + - run: + command: gem install bundler + - run: + command: bundle install + - run: + command: bundle exec rake + +workflows: + build_and_test: + jobs: + - test: + matrix: + parameters: + ruby-image: + # - circleci/jruby:9.2.6.0-jdk + # - circleci/jruby:9.1.17.0-jdk + # - circleci/jruby:9.2-jdk8 + # - circleci/ruby:2.4 + # - circleci/ruby:2.5 + - circleci/ruby:2.7 From 0375f93f7c20901eb5c0fdb536714c9550442f34 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 17:57:32 -0600 Subject: [PATCH 1158/1191] Specify the proto syntax version --- proto/dynamic_discovery.proto | 2 ++ proto/google/protobuf/compiler/plugin.proto | 2 ++ proto/rpc.proto | 2 ++ 3 files changed, 6 insertions(+) diff --git a/proto/dynamic_discovery.proto b/proto/dynamic_discovery.proto index dcecca5f..a2301b5a 100644 --- a/proto/dynamic_discovery.proto +++ b/proto/dynamic_discovery.proto @@ -22,6 +22,8 @@ // // Protobufs needed for dynamic discovery zmq server and client. +syntax = "proto2"; + package protobuf.rpc.dynamicDiscovery; enum BeaconType { diff --git a/proto/google/protobuf/compiler/plugin.proto b/proto/google/protobuf/compiler/plugin.proto index 77b888f3..d001fa16 100644 --- a/proto/google/protobuf/compiler/plugin.proto +++ b/proto/google/protobuf/compiler/plugin.proto @@ -44,6 +44,8 @@ // plugin should be named "protoc-gen-$NAME", and will then be used when the // flag "--${NAME}_out" is passed to protoc. +syntax = "proto2"; + package google.protobuf.compiler; option java_package = "com.google.protobuf.compiler"; option java_outer_classname = "PluginProtos"; diff --git a/proto/rpc.proto b/proto/rpc.proto index f496139e..87fef057 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -22,6 +22,8 @@ // // Protobufs needed for socket rpcs. +syntax = "proto2"; + package protobuf.socketrpc; message Request From 555dcc628a25328b16a8c7e4599c782a0753f547 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:00:27 -0600 Subject: [PATCH 1159/1191] Use protoc-gen-ruby-protobuf for compiling protos --- Rakefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 8df9895f..cecc48a4 100644 --- a/Rakefile +++ b/Rakefile @@ -22,10 +22,12 @@ namespace :compile do task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) proto_files = Dir[File.join(proto_path, '**', '*.proto')] - cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}) - puts cmd - system(cmd) + proto_files.each do |proto_file| + cmd = %(protoc --plugin=protoc-gen-ruby-protobuf=./bin/protoc-gen-ruby --ruby-protobuf_out=#{proto_path} -I #{proto_path} #{proto_file}) + puts cmd + system(cmd) || fail("Failed to compile spec proto: #{proto_file}") + end end desc 'Compile rpc protos in protos/ directory' @@ -35,10 +37,10 @@ namespace :compile do output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) - cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}) + cmd = %(protoc --plugin=protoc-gen-ruby-protobuf=./bin/protoc-gen-ruby --ruby-protobuf_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}) puts cmd - system(cmd) + system(cmd) || fail("Failed to compile rpc protos!") files = { 'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc', From db5e65fe2eada3d86b8452f14f534c9aec5f77f6 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:04:15 -0600 Subject: [PATCH 1160/1191] Fix the broken map-test.proto test --- spec/support/protos/map-test.bin | Bin 4286 -> 4286 bytes spec/support/protos/map-test.proto | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/support/protos/map-test.bin b/spec/support/protos/map-test.bin index 5f6e02c39696ca01440c748db94d24b7ef6baf83..97ad6500d22947de1139add13242bbeeafa21914 100644 GIT binary patch delta 19 acmdm|xKDAzW&v&nAr3AUKhKaT0Y(5j!vwnk delta 19 acmdm|xKDAzW&v(SAr3AUKhKaT0VV)D&jh^y diff --git a/spec/support/protos/map-test.proto b/spec/support/protos/map-test.proto index 6f7f221d..447c651d 100644 --- a/spec/support/protos/map-test.proto +++ b/spec/support/protos/map-test.proto @@ -1,13 +1,13 @@ // Use protoc v3.0.0 to compile this file into map-test.bin: -// protoc --descriptor_set_out=map-test.bin map-test.proto +// protoc --descriptor_set_out=map-test.bin map-test.proto syntax = "proto2"; package foo; enum Frobnitz { - FROB = 1; - NITZ = 2; + FROB = 0; + NITZ = 1; } message Baz { From 91e505faae331b5b09ed6dc5c9ba211f6e1a3f7a Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:04:38 -0600 Subject: [PATCH 1161/1191] Add missing code from bx rake compile:spec --- spec/support/google/protobuf/descriptor.pb.rb | 360 ++++++++++++++++++ spec/support/protos/map-test.pb.rb | 4 +- 2 files changed, 362 insertions(+), 2 deletions(-) create mode 100644 spec/support/google/protobuf/descriptor.pb.rb diff --git a/spec/support/google/protobuf/descriptor.pb.rb b/spec/support/google/protobuf/descriptor.pb.rb new file mode 100644 index 00000000..acff3ebd --- /dev/null +++ b/spec/support/google/protobuf/descriptor.pb.rb @@ -0,0 +1,360 @@ +# encoding: utf-8 + +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf' + +module Google + module Protobuf + ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions } + + ## + # Message Classes + # + class FileDescriptorSet < ::Protobuf::Message; end + class FileDescriptorProto < ::Protobuf::Message; end + class DescriptorProto < ::Protobuf::Message + class ExtensionRange < ::Protobuf::Message; end + class ReservedRange < ::Protobuf::Message; end + + end + + class ExtensionRangeOptions < ::Protobuf::Message; end + class FieldDescriptorProto < ::Protobuf::Message + class Type < ::Protobuf::Enum + define :TYPE_DOUBLE, 1 + define :TYPE_FLOAT, 2 + define :TYPE_INT64, 3 + define :TYPE_UINT64, 4 + define :TYPE_INT32, 5 + define :TYPE_FIXED64, 6 + define :TYPE_FIXED32, 7 + define :TYPE_BOOL, 8 + define :TYPE_STRING, 9 + define :TYPE_GROUP, 10 + define :TYPE_MESSAGE, 11 + define :TYPE_BYTES, 12 + define :TYPE_UINT32, 13 + define :TYPE_ENUM, 14 + define :TYPE_SFIXED32, 15 + define :TYPE_SFIXED64, 16 + define :TYPE_SINT32, 17 + define :TYPE_SINT64, 18 + end + + class Label < ::Protobuf::Enum + define :LABEL_OPTIONAL, 1 + define :LABEL_REQUIRED, 2 + define :LABEL_REPEATED, 3 + end + + end + + class OneofDescriptorProto < ::Protobuf::Message; end + class EnumDescriptorProto < ::Protobuf::Message + class EnumReservedRange < ::Protobuf::Message; end + + end + + class EnumValueDescriptorProto < ::Protobuf::Message; end + class ServiceDescriptorProto < ::Protobuf::Message; end + class MethodDescriptorProto < ::Protobuf::Message; end + class FileOptions < ::Protobuf::Message + class OptimizeMode < ::Protobuf::Enum + define :SPEED, 1 + define :CODE_SIZE, 2 + define :LITE_RUNTIME, 3 + end + + end + + class MessageOptions < ::Protobuf::Message; end + class FieldOptions < ::Protobuf::Message + class CType < ::Protobuf::Enum + define :STRING, 0 + define :CORD, 1 + define :STRING_PIECE, 2 + end + + class JSType < ::Protobuf::Enum + define :JS_NORMAL, 0 + define :JS_STRING, 1 + define :JS_NUMBER, 2 + end + + end + + class OneofOptions < ::Protobuf::Message; end + class EnumOptions < ::Protobuf::Message; end + class EnumValueOptions < ::Protobuf::Message; end + class ServiceOptions < ::Protobuf::Message; end + class MethodOptions < ::Protobuf::Message + class IdempotencyLevel < ::Protobuf::Enum + define :IDEMPOTENCY_UNKNOWN, 0 + define :NO_SIDE_EFFECTS, 1 + define :IDEMPOTENT, 2 + end + + end + + class UninterpretedOption < ::Protobuf::Message + class NamePart < ::Protobuf::Message; end + + end + + class SourceCodeInfo < ::Protobuf::Message + class Location < ::Protobuf::Message; end + + end + + class GeneratedCodeInfo < ::Protobuf::Message + class Annotation < ::Protobuf::Message; end + + end + + + + ## + # File Options + # + set_option :java_package, "com.google.protobuf" + set_option :java_outer_classname, "DescriptorProtos" + set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED + set_option :go_package, "google.golang.org/protobuf/types/descriptorpb" + set_option :cc_enable_arenas, true + set_option :objc_class_prefix, "GPB" + set_option :csharp_namespace, "Google.Protobuf.Reflection" + + + ## + # Message Fields + # + class FileDescriptorSet + repeated ::Google::Protobuf::FileDescriptorProto, :file, 1 + end + + class FileDescriptorProto + optional :string, :name, 1 + optional :string, :package, 2 + repeated :string, :dependency, 3 + repeated :int32, :public_dependency, 10 + repeated :int32, :weak_dependency, 11 + repeated ::Google::Protobuf::DescriptorProto, :message_type, 4 + repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 5 + repeated ::Google::Protobuf::ServiceDescriptorProto, :service, 6 + repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 7 + optional ::Google::Protobuf::FileOptions, :options, 8 + optional ::Google::Protobuf::SourceCodeInfo, :source_code_info, 9 + optional :string, :syntax, 12 + end + + class DescriptorProto + class ExtensionRange + optional :int32, :start, 1 + optional :int32, :end, 2 + optional ::Google::Protobuf::ExtensionRangeOptions, :options, 3 + end + + class ReservedRange + optional :int32, :start, 1 + optional :int32, :end, 2 + end + + optional :string, :name, 1 + repeated ::Google::Protobuf::FieldDescriptorProto, :field, 2 + repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 6 + repeated ::Google::Protobuf::DescriptorProto, :nested_type, 3 + repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 4 + repeated ::Google::Protobuf::DescriptorProto::ExtensionRange, :extension_range, 5 + repeated ::Google::Protobuf::OneofDescriptorProto, :oneof_decl, 8 + optional ::Google::Protobuf::MessageOptions, :options, 7 + repeated ::Google::Protobuf::DescriptorProto::ReservedRange, :reserved_range, 9 + repeated :string, :reserved_name, 10 + end + + class ExtensionRangeOptions + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class FieldDescriptorProto + optional :string, :name, 1 + optional :int32, :number, 3 + optional ::Google::Protobuf::FieldDescriptorProto::Label, :label, 4 + optional ::Google::Protobuf::FieldDescriptorProto::Type, :type, 5 + optional :string, :type_name, 6 + optional :string, :extendee, 2 + optional :string, :default_value, 7 + optional :int32, :oneof_index, 9 + optional :string, :json_name, 10 + optional ::Google::Protobuf::FieldOptions, :options, 8 + optional :bool, :proto3_optional, 17 + end + + class OneofDescriptorProto + optional :string, :name, 1 + optional ::Google::Protobuf::OneofOptions, :options, 2 + end + + class EnumDescriptorProto + class EnumReservedRange + optional :int32, :start, 1 + optional :int32, :end, 2 + end + + optional :string, :name, 1 + repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2 + optional ::Google::Protobuf::EnumOptions, :options, 3 + repeated ::Google::Protobuf::EnumDescriptorProto::EnumReservedRange, :reserved_range, 4 + repeated :string, :reserved_name, 5 + end + + class EnumValueDescriptorProto + optional :string, :name, 1 + optional :int32, :number, 2 + optional ::Google::Protobuf::EnumValueOptions, :options, 3 + end + + class ServiceDescriptorProto + optional :string, :name, 1 + repeated ::Google::Protobuf::MethodDescriptorProto, :method, 2 + optional ::Google::Protobuf::ServiceOptions, :options, 3 + end + + class MethodDescriptorProto + optional :string, :name, 1 + optional :string, :input_type, 2 + optional :string, :output_type, 3 + optional ::Google::Protobuf::MethodOptions, :options, 4 + optional :bool, :client_streaming, 5, :default => false + optional :bool, :server_streaming, 6, :default => false + end + + class FileOptions + optional :string, :java_package, 1 + optional :string, :java_outer_classname, 8 + optional :bool, :java_multiple_files, 10, :default => false + optional :bool, :java_generate_equals_and_hash, 20, :deprecated => true + optional :bool, :java_string_check_utf8, 27, :default => false + optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED + optional :string, :go_package, 11 + optional :bool, :cc_generic_services, 16, :default => false + optional :bool, :java_generic_services, 17, :default => false + optional :bool, :py_generic_services, 18, :default => false + optional :bool, :php_generic_services, 42, :default => false + optional :bool, :deprecated, 23, :default => false + optional :bool, :cc_enable_arenas, 31, :default => true + optional :string, :objc_class_prefix, 36 + optional :string, :csharp_namespace, 37 + optional :string, :swift_prefix, 39 + optional :string, :php_class_prefix, 40 + optional :string, :php_namespace, 41 + optional :string, :php_metadata_namespace, 44 + optional :string, :ruby_package, 45 + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class MessageOptions + optional :bool, :message_set_wire_format, 1, :default => false + optional :bool, :no_standard_descriptor_accessor, 2, :default => false + optional :bool, :deprecated, 3, :default => false + optional :bool, :map_entry, 7 + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class FieldOptions + optional ::Google::Protobuf::FieldOptions::CType, :ctype, 1, :default => ::Google::Protobuf::FieldOptions::CType::STRING + optional :bool, :packed, 2 + optional ::Google::Protobuf::FieldOptions::JSType, :jstype, 6, :default => ::Google::Protobuf::FieldOptions::JSType::JS_NORMAL + optional :bool, :lazy, 5, :default => false + optional :bool, :deprecated, 3, :default => false + optional :bool, :weak, 10, :default => false + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class OneofOptions + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class EnumOptions + optional :bool, :allow_alias, 2 + optional :bool, :deprecated, 3, :default => false + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class EnumValueOptions + optional :bool, :deprecated, 1, :default => false + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class ServiceOptions + optional :bool, :deprecated, 33, :default => false + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class MethodOptions + optional :bool, :deprecated, 33, :default => false + optional ::Google::Protobuf::MethodOptions::IdempotencyLevel, :idempotency_level, 34, :default => ::Google::Protobuf::MethodOptions::IdempotencyLevel::IDEMPOTENCY_UNKNOWN + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + + class UninterpretedOption + class NamePart + required :string, :name_part, 1 + required :bool, :is_extension, 2 + end + + repeated ::Google::Protobuf::UninterpretedOption::NamePart, :name, 2 + optional :string, :identifier_value, 3 + optional :uint64, :positive_int_value, 4 + optional :int64, :negative_int_value, 5 + optional :double, :double_value, 6 + optional :bytes, :string_value, 7 + optional :string, :aggregate_value, 8 + end + + class SourceCodeInfo + class Location + repeated :int32, :path, 1, :packed => true + repeated :int32, :span, 2, :packed => true + optional :string, :leading_comments, 3 + optional :string, :trailing_comments, 4 + repeated :string, :leading_detached_comments, 6 + end + + repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1 + end + + class GeneratedCodeInfo + class Annotation + repeated :int32, :path, 1, :packed => true + optional :string, :source_file, 2 + optional :int32, :begin, 3 + optional :int32, :end, 4 + end + + repeated ::Google::Protobuf::GeneratedCodeInfo::Annotation, :annotation, 1 + end + + end + +end + diff --git a/spec/support/protos/map-test.pb.rb b/spec/support/protos/map-test.pb.rb index bd856360..849bad87 100644 --- a/spec/support/protos/map-test.pb.rb +++ b/spec/support/protos/map-test.pb.rb @@ -12,8 +12,8 @@ module Foo # Enum Classes # class Frobnitz < ::Protobuf::Enum - define :FROB, 1 - define :NITZ, 2 + define :FROB, 0 + define :NITZ, 1 end From 7993689a62aba537405ed08011e9b5ef0061b260 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:06:15 -0600 Subject: [PATCH 1162/1191] Drop the circle ruby orb --- .circleci/config.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d4e511a..3eb220c1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,10 +1,5 @@ version: 2.1 -orbs: - # orbs are basically bundles of pre-written build scripts that work for common cases - # https://github.com/CircleCI-Public/ruby-orb - ruby: circleci/ruby@1.1 - jobs: # skipping build step because Gemfile.lock is not included in the source # this makes the bundler caching step a noop From 636481bad211e4dc48e74cd230a7000b681ffc2c Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:08:33 -0600 Subject: [PATCH 1163/1191] Add full ruby version matrix --- .circleci/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3eb220c1..b346a46a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,9 +30,9 @@ workflows: matrix: parameters: ruby-image: - # - circleci/jruby:9.2.6.0-jdk - # - circleci/jruby:9.1.17.0-jdk - # - circleci/jruby:9.2-jdk8 - # - circleci/ruby:2.4 - # - circleci/ruby:2.5 + - circleci/jruby:9.2.6.0-jdk + - circleci/jruby:9.1.17.0-jdk + - circleci/jruby:9.2-jdk8 + - circleci/ruby:2.4 + - circleci/ruby:2.5 - circleci/ruby:2.7 From 1ce2617a0a87c1411f31797ac780c5bb88b4aec2 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:14:18 -0600 Subject: [PATCH 1164/1191] Print the protoc version --- .circleci/config.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b346a46a..fe0d5655 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,6 +15,8 @@ jobs: - run: message: Install ZeroMQ and Protobuf Compiler command: sudo apt-get -y install libzmq3-dev protobuf-compiler + - run: + command: protoc --version - checkout - run: command: gem install bundler @@ -31,8 +33,8 @@ workflows: parameters: ruby-image: - circleci/jruby:9.2.6.0-jdk - - circleci/jruby:9.1.17.0-jdk - - circleci/jruby:9.2-jdk8 - - circleci/ruby:2.4 - - circleci/ruby:2.5 - - circleci/ruby:2.7 + # - circleci/jruby:9.1.17.0-jdk + # - circleci/jruby:9.2-jdk8 + # - circleci/ruby:2.4 + # - circleci/ruby:2.5 + # - circleci/ruby:2.7 From aac6b0263c395210f8267e2cacc87a86abbbc3ab Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:18:45 -0600 Subject: [PATCH 1165/1191] Use protoc version 3.16.0 --- .circleci/config.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fe0d5655..7991ae40 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,12 +11,20 @@ jobs: - image: << parameters.ruby-image >> steps: - run: - command: sudo apt-get update - - run: - message: Install ZeroMQ and Protobuf Compiler - command: sudo apt-get -y install libzmq3-dev protobuf-compiler + name: Install protobuf compiler + command: | + archive=protoc-3.16.0-linux-x86_64 + curl -O -L https://github.com/protocolbuffers/protobuf/releases/download/v3.16.0/$archive.zip + sudo unzip -d '/usr/local' $archive.zip 'bin/*' 'include/*' + sudo chown -R $(whoami) /usr/local/bin/protoc /usr/local/include/google + rm -rf $archive.zip - run: command: protoc --version + - run: + command: sudo apt-get update + - run: + message: Install ZeroMQ + command: sudo apt-get -y install libzmq3-dev - checkout - run: command: gem install bundler From 15135c9dfbe5fe0dc67611e1d670d12fab368e86 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:39:30 -0600 Subject: [PATCH 1166/1191] Enable all ruby versions once again --- .circleci/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7991ae40..e1c40701 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,8 +41,8 @@ workflows: parameters: ruby-image: - circleci/jruby:9.2.6.0-jdk - # - circleci/jruby:9.1.17.0-jdk - # - circleci/jruby:9.2-jdk8 - # - circleci/ruby:2.4 - # - circleci/ruby:2.5 - # - circleci/ruby:2.7 + - circleci/jruby:9.1.17.0-jdk + - circleci/jruby:9.2-jdk8 + - circleci/ruby:2.4 + - circleci/ruby:2.5 + - circleci/ruby:2.7 From d3d759229cc496687803f8212cc68cb6e1e6479f Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:45:01 -0600 Subject: [PATCH 1167/1191] So long, travis! --- .travis.yml | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f89eb2e6..00000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -before_install: - - wget https://github.com/zeromq/libzmq/releases/download/v4.2.1/zeromq-4.2.1.tar.gz - - tar xvf zeromq-4.2.1.tar.gz - - cd zeromq-4.2.1 - - ./configure - - make -j4 - - sudo make install - # Retrun to project directory - - cd .. - - sudo -E ./install-protobuf.sh - - java -Xmx1g -version - - javac -J-Xmx1g -version - - export JRUBY_OPTS=-J-Xmx1g - - gem update bundler -language: ruby -rvm: - - 1.9.3 - - 2.0.0 - - 2.1 - - 2.2 - - 2.3 - - 2.4 - - 2.5 - - jruby-9.1.17.0 - - jruby-9.2.5.0 - - rbx-2 -env: - - PROTOBUF_VERSION=2.6.1 - - PROTOBUF_VERSION=3.0.0-alpha-2 -matrix: - allow_failures: - - rvm: rbx-2 - - env: PROTOBUF_VERSION=3.0.0-alpha-2 -notifications: - webhooks: - urls: - - https://webhooks.gitter.im/e/51a956bcd2b1854d6756 - on_success: change # options: [always|never|change] default: always - on_failure: always # options: [always|never|change] default: always - on_start: false # default: false From 4e236ebb083db2ce1a1e9dd0d23bbee3fc3d841c Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 26 Jun 2021 18:47:51 -0600 Subject: [PATCH 1168/1191] Remove the instal-protobuf script --- install-protobuf.sh | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100755 install-protobuf.sh diff --git a/install-protobuf.sh b/install-protobuf.sh deleted file mode 100755 index b3872fd0..00000000 --- a/install-protobuf.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env sh - -set -ex - -gdie() { - echo "$@" >&2 - exit 1 -} - -test -n "$PROTOBUF_VERSION" || die "PROTOBUF_VERSION env var is undefined" - -case "$PROTOBUF_VERSION" in -2*) - basename=protobuf-$PROTOBUF_VERSION - ;; -3*) - basename=protobuf-cpp-$PROTOBUF_VERSION - ;; -*) - die "unknown protobuf version: $PROTOBUF_VERSION" - ;; -esac - -curl -sL https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename.tar.gz | tar zx - -cd protobuf-$PROTOBUF_VERSION - -./configure --prefix=/usr && make -j2 && make install From b385f4a95988b8db1414fe3f1fbbc0c317a9e207 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 21 Jun 2021 15:14:27 -0600 Subject: [PATCH 1169/1191] Add proto v3 features to the plugin.proto --- .../descriptors/google/protobuf/compiler/plugin.pb.rb | 6 ++++++ proto/google/protobuf/compiler/plugin.proto | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb index 354aa845..e4c402da 100644 --- a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -21,6 +21,11 @@ module Compiler # class CodeGeneratorRequest < ::Protobuf::Message; end class CodeGeneratorResponse < ::Protobuf::Message + class Feature < ::Protobuf::Enum + define :FEATURE_NONE, 0 + define :FEATURE_PROTO3_OPTIONAL, 1 + end + class File < ::Protobuf::Message; end end @@ -51,6 +56,7 @@ class File end optional :string, :error, 1 + optional :uint64, :supported_features, 2 repeated ::Google::Protobuf::Compiler::CodeGeneratorResponse::File, :file, 15 end diff --git a/proto/google/protobuf/compiler/plugin.proto b/proto/google/protobuf/compiler/plugin.proto index d001fa16..a1718e77 100644 --- a/proto/google/protobuf/compiler/plugin.proto +++ b/proto/google/protobuf/compiler/plugin.proto @@ -88,6 +88,16 @@ message CodeGeneratorResponse { // exiting with a non-zero status code. optional string error = 1; + // A bitmask of supported features that the code generator supports. + // This is a bitwise "or" of values from the Feature enum. + optional uint64 supported_features = 2; + + // Sync with code_generator.h. + enum Feature { + FEATURE_NONE = 0; + FEATURE_PROTO3_OPTIONAL = 1; + } + // Represents a single generated file. message File { // The file name, relative to the output directory. The name must not From 33af6ada73e242ca75a682c9f8dd73c21cf2b694 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 21 Jun 2021 15:14:53 -0600 Subject: [PATCH 1170/1191] Wire the compiler to support proto v3 with optional fields --- lib/protobuf/code_generator.rb | 11 ++++++++++- spec/functional/code_generator_spec.rb | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 7b04a32c..7068800b 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -46,7 +46,16 @@ def response_bytes generate_file(file_descriptor) end - ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files) + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode( + :file => generated_files, + :supported_features => supported_features, + ) + end + + def supported_features + # The only available feature is proto3 with optional fields. + # This is backwards compatible with proto2 optional fields. + ::Google::Protobuf::Compiler::CodeGeneratorResponse::Feature::FEATURE_PROTO3_OPTIONAL.to_i end Protobuf::Field::BaseField.module_eval do diff --git a/spec/functional/code_generator_spec.rb b/spec/functional/code_generator_spec.rb index aac45319..3f767b23 100644 --- a/spec/functional/code_generator_spec.rb +++ b/spec/functional/code_generator_spec.rb @@ -17,7 +17,7 @@ end expected_output = - ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => expected_file_descriptors) + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => expected_file_descriptors, :supported_features => 1) code_generator = ::Protobuf::CodeGenerator.new(bytes) code_generator.eval_unknown_extensions! @@ -37,7 +37,7 @@ :name => file_name, :content => file_content) expected_response = - ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => [expected_file_output]) + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => [expected_file_output], :supported_features => 1) code_generator = ::Protobuf::CodeGenerator.new(request.encode) code_generator.eval_unknown_extensions! From 59eb89671e319b3d5b878b302c02feec02276edb Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 21 Jun 2021 15:19:21 -0600 Subject: [PATCH 1171/1191] Add functional v3 proto with optional fields compiler test --- spec/lib/protobuf/code_generator_spec.rb | 2 +- spec/support/protos/optional_v3_fields.pb.rb | 22 ++++++++++++++++++++ spec/support/protos/optional_v3_fields.proto | 6 ++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/support/protos/optional_v3_fields.pb.rb create mode 100644 spec/support/protos/optional_v3_fields.proto diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 230029c0..44b8dd16 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -23,7 +23,7 @@ end let(:expected_response_bytes) do - COMPILER::CodeGeneratorResponse.encode(:file => [output_file1, output_file2]) + COMPILER::CodeGeneratorResponse.encode(:file => [output_file1, output_file2], :supported_features => 1) end before do diff --git a/spec/support/protos/optional_v3_fields.pb.rb b/spec/support/protos/optional_v3_fields.pb.rb new file mode 100644 index 00000000..058f37ff --- /dev/null +++ b/spec/support/protos/optional_v3_fields.pb.rb @@ -0,0 +1,22 @@ +# encoding: utf-8 + +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf' + + +## +# Message Classes +# +class SomethingWithOptionalFields < ::Protobuf::Message; end + + +## +# Message Fields +# +class SomethingWithOptionalFields + optional :string, :i_am_optional, 1 + optional :string, :i_am_not_optional, 2 +end + diff --git a/spec/support/protos/optional_v3_fields.proto b/spec/support/protos/optional_v3_fields.proto new file mode 100644 index 00000000..b145fba2 --- /dev/null +++ b/spec/support/protos/optional_v3_fields.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +message SomethingWithOptionalFields { + optional string i_am_optional = 1; + string i_am_not_optional = 2; +} From f1606fa51a5aa7b3c29716254669c2c028269676 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 21 Jun 2021 22:03:25 -0600 Subject: [PATCH 1172/1191] Update map-test.proto to use 0 value enum I manually corrected the enum values via pry debugger and wrote the new request bytes to disk, hence the map-test.bin change. This was causing the rake compile:spec task to fail. From 03c841be846edd925ca6ac6747eca7ca358bb3c7 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 30 Jun 2021 14:10:33 -0600 Subject: [PATCH 1173/1191] Bump version to 3.10.4 and add notes to CHANGES --- CHANGES.md | 1 + lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 1577e709..032d0ce5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ 3.10.0 ------ - Add headers to request proto +- Add support for compiling v3 protos with optional fields as v2 optional fields 3.9.0 ----- diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index d96e0847..77a79c63 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.3' # rubocop:disable Style/MutableConstant + VERSION = '3.10.4' # rubocop:disable Style/MutableConstant end From 993ecba46cc20f4727704a967de0b167fd60f448 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Tue, 13 Jul 2021 11:31:05 -0700 Subject: [PATCH 1174/1191] refresh well known protos: descriptor.proto, plugin.proto from: https://raw.githubusercontent.com/google/protobuf/master/src/google/protobuf/descriptor.proto https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf/compiler/plugin.proto --- .../google/protobuf/compiler/plugin.pb.rb | 17 + .../google/protobuf/descriptor.pb.rb | 71 +++- proto/google/protobuf/compiler/plugin.proto | 36 +- proto/google/protobuf/descriptor.proto | 324 ++++++++++++------ 4 files changed, 345 insertions(+), 103 deletions(-) diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb index 354aa845..62e17f56 100644 --- a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -19,8 +19,14 @@ module Compiler ## # Message Classes # + class Version < ::Protobuf::Message; end class CodeGeneratorRequest < ::Protobuf::Message; end class CodeGeneratorResponse < ::Protobuf::Message + class Feature < ::Protobuf::Enum + define :FEATURE_NONE, 0 + define :FEATURE_PROTO3_OPTIONAL, 1 + end + class File < ::Protobuf::Message; end end @@ -32,15 +38,24 @@ class File < ::Protobuf::Message; end # set_option :java_package, "com.google.protobuf.compiler" set_option :java_outer_classname, "PluginProtos" + set_option :go_package, "google.golang.org/protobuf/types/pluginpb" ## # Message Fields # + class Version + optional :int32, :major, 1 + optional :int32, :minor, 2 + optional :int32, :patch, 3 + optional :string, :suffix, 4 + end + class CodeGeneratorRequest repeated :string, :file_to_generate, 1 optional :string, :parameter, 2 repeated ::Google::Protobuf::FileDescriptorProto, :proto_file, 15 + optional ::Google::Protobuf::Compiler::Version, :compiler_version, 3 end class CodeGeneratorResponse @@ -48,9 +63,11 @@ class File optional :string, :name, 1 optional :string, :insertion_point, 2 optional :string, :content, 15 + optional ::Google::Protobuf::GeneratedCodeInfo, :generated_code_info, 16 end optional :string, :error, 1 + optional :uint64, :supported_features, 2 repeated ::Google::Protobuf::Compiler::CodeGeneratorResponse::File, :file, 15 end diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index 534d83a5..acff3ebd 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -20,6 +20,7 @@ class ReservedRange < ::Protobuf::Message; end end + class ExtensionRangeOptions < ::Protobuf::Message; end class FieldDescriptorProto < ::Protobuf::Message class Type < ::Protobuf::Enum define :TYPE_DOUBLE, 1 @@ -51,7 +52,11 @@ class Label < ::Protobuf::Enum end class OneofDescriptorProto < ::Protobuf::Message; end - class EnumDescriptorProto < ::Protobuf::Message; end + class EnumDescriptorProto < ::Protobuf::Message + class EnumReservedRange < ::Protobuf::Message; end + + end + class EnumValueDescriptorProto < ::Protobuf::Message; end class ServiceDescriptorProto < ::Protobuf::Message; end class MethodDescriptorProto < ::Protobuf::Message; end @@ -80,10 +85,19 @@ class JSType < ::Protobuf::Enum end + class OneofOptions < ::Protobuf::Message; end class EnumOptions < ::Protobuf::Message; end class EnumValueOptions < ::Protobuf::Message; end class ServiceOptions < ::Protobuf::Message; end - class MethodOptions < ::Protobuf::Message; end + class MethodOptions < ::Protobuf::Message + class IdempotencyLevel < ::Protobuf::Enum + define :IDEMPOTENCY_UNKNOWN, 0 + define :NO_SIDE_EFFECTS, 1 + define :IDEMPOTENT, 2 + end + + end + class UninterpretedOption < ::Protobuf::Message class NamePart < ::Protobuf::Message; end @@ -94,6 +108,11 @@ class Location < ::Protobuf::Message; end end + class GeneratedCodeInfo < ::Protobuf::Message + class Annotation < ::Protobuf::Message; end + + end + ## @@ -102,7 +121,8 @@ class Location < ::Protobuf::Message; end set_option :java_package, "com.google.protobuf" set_option :java_outer_classname, "DescriptorProtos" set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED - set_option :go_package, "descriptor" + set_option :go_package, "google.golang.org/protobuf/types/descriptorpb" + set_option :cc_enable_arenas, true set_option :objc_class_prefix, "GPB" set_option :csharp_namespace, "Google.Protobuf.Reflection" @@ -133,6 +153,7 @@ class DescriptorProto class ExtensionRange optional :int32, :start, 1 optional :int32, :end, 2 + optional ::Google::Protobuf::ExtensionRangeOptions, :options, 3 end class ReservedRange @@ -152,6 +173,12 @@ class ReservedRange repeated :string, :reserved_name, 10 end + class ExtensionRangeOptions + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + class FieldDescriptorProto optional :string, :name, 1 optional :int32, :number, 3 @@ -163,16 +190,25 @@ class FieldDescriptorProto optional :int32, :oneof_index, 9 optional :string, :json_name, 10 optional ::Google::Protobuf::FieldOptions, :options, 8 + optional :bool, :proto3_optional, 17 end class OneofDescriptorProto optional :string, :name, 1 + optional ::Google::Protobuf::OneofOptions, :options, 2 end class EnumDescriptorProto + class EnumReservedRange + optional :int32, :start, 1 + optional :int32, :end, 2 + end + optional :string, :name, 1 repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2 optional ::Google::Protobuf::EnumOptions, :options, 3 + repeated ::Google::Protobuf::EnumDescriptorProto::EnumReservedRange, :reserved_range, 4 + repeated :string, :reserved_name, 5 end class EnumValueDescriptorProto @@ -200,18 +236,23 @@ class FileOptions optional :string, :java_package, 1 optional :string, :java_outer_classname, 8 optional :bool, :java_multiple_files, 10, :default => false - optional :bool, :java_generate_equals_and_hash, 20, :default => false + optional :bool, :java_generate_equals_and_hash, 20, :deprecated => true optional :bool, :java_string_check_utf8, 27, :default => false optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED optional :string, :go_package, 11 optional :bool, :cc_generic_services, 16, :default => false optional :bool, :java_generic_services, 17, :default => false optional :bool, :py_generic_services, 18, :default => false + optional :bool, :php_generic_services, 42, :default => false optional :bool, :deprecated, 23, :default => false - optional :bool, :cc_enable_arenas, 31, :default => false + optional :bool, :cc_enable_arenas, 31, :default => true optional :string, :objc_class_prefix, 36 optional :string, :csharp_namespace, 37 - optional :bool, :javanano_use_deprecated_package, 38 + optional :string, :swift_prefix, 39 + optional :string, :php_class_prefix, 40 + optional :string, :php_namespace, 41 + optional :string, :php_metadata_namespace, 44 + optional :string, :ruby_package, 45 repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 @@ -239,6 +280,12 @@ class FieldOptions extensions 1000...536870912 end + class OneofOptions + repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 + # Extension Fields + extensions 1000...536870912 + end + class EnumOptions optional :bool, :allow_alias, 2 optional :bool, :deprecated, 3, :default => false @@ -263,6 +310,7 @@ class ServiceOptions class MethodOptions optional :bool, :deprecated, 33, :default => false + optional ::Google::Protobuf::MethodOptions::IdempotencyLevel, :idempotency_level, 34, :default => ::Google::Protobuf::MethodOptions::IdempotencyLevel::IDEMPOTENCY_UNKNOWN repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999 # Extension Fields extensions 1000...536870912 @@ -295,6 +343,17 @@ class Location repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1 end + class GeneratedCodeInfo + class Annotation + repeated :int32, :path, 1, :packed => true + optional :string, :source_file, 2 + optional :int32, :begin, 3 + optional :int32, :end, 4 + end + + repeated ::Google::Protobuf::GeneratedCodeInfo::Annotation, :annotation, 1 + end + end end diff --git a/proto/google/protobuf/compiler/plugin.proto b/proto/google/protobuf/compiler/plugin.proto index d001fa16..9242aacc 100644 --- a/proto/google/protobuf/compiler/plugin.proto +++ b/proto/google/protobuf/compiler/plugin.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -50,8 +50,20 @@ package google.protobuf.compiler; option java_package = "com.google.protobuf.compiler"; option java_outer_classname = "PluginProtos"; +option go_package = "google.golang.org/protobuf/types/pluginpb"; + import "google/protobuf/descriptor.proto"; +// The version number of protocol compiler. +message Version { + optional int32 major = 1; + optional int32 minor = 2; + optional int32 patch = 3; + // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should + // be empty for mainline stable releases. + optional string suffix = 4; +} + // An encoded CodeGeneratorRequest is written to the plugin's stdin. message CodeGeneratorRequest { // The .proto files that were explicitly listed on the command-line. The @@ -73,7 +85,14 @@ message CodeGeneratorRequest { // the entire set into memory at once. However, as of this writing, this // is not similarly optimized on protoc's end -- it will store all fields in // memory at once before sending them to the plugin. + // + // Type names of fields and extensions in the FileDescriptorProto are always + // fully qualified. repeated FileDescriptorProto proto_file = 15; + + // The version number of protocol compiler. + optional Version compiler_version = 3; + } // The plugin writes an encoded CodeGeneratorResponse to stdout. @@ -88,6 +107,16 @@ message CodeGeneratorResponse { // exiting with a non-zero status code. optional string error = 1; + // A bitmask of supported features that the code generator supports. + // This is a bitwise "or" of values from the Feature enum. + optional uint64 supported_features = 2; + + // Sync with code_generator.h. + enum Feature { + FEATURE_NONE = 0; + FEATURE_PROTO3_OPTIONAL = 1; + } + // Represents a single generated file. message File { // The file name, relative to the output directory. The name must not @@ -144,6 +173,11 @@ message CodeGeneratorResponse { // The file contents. optional string content = 15; + + // Information describing the file content being inserted. If an insertion + // point is used, this information will be appropriately offset and inserted + // into the code generation metadata for the generated files. + optional GeneratedCodeInfo generated_code_info = 16; } repeated File file = 15; } diff --git a/proto/google/protobuf/descriptor.proto b/proto/google/protobuf/descriptor.proto index c59a6022..156e410a 100644 --- a/proto/google/protobuf/descriptor.proto +++ b/proto/google/protobuf/descriptor.proto @@ -40,11 +40,13 @@ syntax = "proto2"; package google.protobuf; -option go_package = "descriptor"; + +option go_package = "google.golang.org/protobuf/types/descriptorpb"; option java_package = "com.google.protobuf"; option java_outer_classname = "DescriptorProtos"; option csharp_namespace = "Google.Protobuf.Reflection"; option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; // descriptor.proto must be optimized for speed because reflection-based // algorithms don't work during bootstrapping. @@ -58,8 +60,8 @@ message FileDescriptorSet { // Describes a complete .proto file. message FileDescriptorProto { - optional string name = 1; // file name, relative to root of source tree - optional string package = 2; // e.g. "foo", "foo.bar", etc. + optional string name = 1; // file name, relative to root of source tree + optional string package = 2; // e.g. "foo", "foo.bar", etc. // Names of files imported by this file. repeated string dependency = 3; @@ -99,8 +101,10 @@ message DescriptorProto { repeated EnumDescriptorProto enum_type = 4; message ExtensionRange { - optional int32 start = 1; - optional int32 end = 2; + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. + + optional ExtensionRangeOptions options = 3; } repeated ExtensionRange extension_range = 5; @@ -112,8 +116,8 @@ message DescriptorProto { // fields or extension ranges in the same message. Reserved ranges may // not overlap. message ReservedRange { - optional int32 start = 1; // Inclusive. - optional int32 end = 2; // Exclusive. + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. } repeated ReservedRange reserved_range = 9; // Reserved field names, which may not be used by fields in the same message. @@ -121,44 +125,56 @@ message DescriptorProto { repeated string reserved_name = 10; } +message ExtensionRangeOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + // Describes a field within a message. message FieldDescriptorProto { enum Type { // 0 is reserved for errors. // Order is weird for historical reasons. - TYPE_DOUBLE = 1; - TYPE_FLOAT = 2; + TYPE_DOUBLE = 1; + TYPE_FLOAT = 2; // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if // negative values are likely. - TYPE_INT64 = 3; - TYPE_UINT64 = 4; + TYPE_INT64 = 3; + TYPE_UINT64 = 4; // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if // negative values are likely. - TYPE_INT32 = 5; - TYPE_FIXED64 = 6; - TYPE_FIXED32 = 7; - TYPE_BOOL = 8; - TYPE_STRING = 9; - TYPE_GROUP = 10; // Tag-delimited aggregate. - TYPE_MESSAGE = 11; // Length-delimited aggregate. + TYPE_INT32 = 5; + TYPE_FIXED64 = 6; + TYPE_FIXED32 = 7; + TYPE_BOOL = 8; + TYPE_STRING = 9; + // Tag-delimited aggregate. + // Group type is deprecated and not supported in proto3. However, Proto3 + // implementations should still be able to parse the group wire format and + // treat group fields as unknown fields. + TYPE_GROUP = 10; + TYPE_MESSAGE = 11; // Length-delimited aggregate. // New in version 2. - TYPE_BYTES = 12; - TYPE_UINT32 = 13; - TYPE_ENUM = 14; - TYPE_SFIXED32 = 15; - TYPE_SFIXED64 = 16; - TYPE_SINT32 = 17; // Uses ZigZag encoding. - TYPE_SINT64 = 18; // Uses ZigZag encoding. - }; + TYPE_BYTES = 12; + TYPE_UINT32 = 13; + TYPE_ENUM = 14; + TYPE_SFIXED32 = 15; + TYPE_SFIXED64 = 16; + TYPE_SINT32 = 17; // Uses ZigZag encoding. + TYPE_SINT64 = 18; // Uses ZigZag encoding. + } enum Label { // 0 is reserved for errors - LABEL_OPTIONAL = 1; - LABEL_REQUIRED = 2; - LABEL_REPEATED = 3; - // TODO(sanjay): Should we add LABEL_MAP? - }; + LABEL_OPTIONAL = 1; + LABEL_REQUIRED = 2; + LABEL_REPEATED = 3; + } optional string name = 1; optional int32 number = 3; @@ -197,11 +213,35 @@ message FieldDescriptorProto { optional string json_name = 10; optional FieldOptions options = 8; + + // If true, this is a proto3 "optional". When a proto3 field is optional, it + // tracks presence regardless of field type. + // + // When proto3_optional is true, this field must be belong to a oneof to + // signal to old proto3 clients that presence is tracked for this field. This + // oneof is known as a "synthetic" oneof, and this field must be its sole + // member (each proto3 optional field gets its own synthetic oneof). Synthetic + // oneofs exist in the descriptor only, and do not generate any API. Synthetic + // oneofs must be ordered after all "real" oneofs. + // + // For message fields, proto3_optional doesn't create any semantic change, + // since non-repeated message fields always track presence. However it still + // indicates the semantic detail of whether the user wrote "optional" or not. + // This can be useful for round-tripping the .proto file. For consistency we + // give message fields a synthetic oneof also, even though it is not required + // to track presence. This is especially important because the parser can't + // tell if a field is a message or an enum, so it must always create a + // synthetic oneof. + // + // Proto2 optional fields do not set this flag, because they already indicate + // optional with `LABEL_OPTIONAL`. + optional bool proto3_optional = 17; } // Describes a oneof. message OneofDescriptorProto { optional string name = 1; + optional OneofOptions options = 2; } // Describes an enum type. @@ -211,6 +251,26 @@ message EnumDescriptorProto { repeated EnumValueDescriptorProto value = 2; optional EnumOptions options = 3; + + // Range of reserved numeric values. Reserved values may not be used by + // entries in the same enum. Reserved ranges may not overlap. + // + // Note that this is distinct from DescriptorProto.ReservedRange in that it + // is inclusive such that it can appropriately represent the entire int32 + // domain. + message EnumReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Inclusive. + } + + // Range of reserved numeric values. Reserved numeric values may not be used + // by enum values in the same enum declaration. Reserved ranges may not + // overlap. + repeated EnumReservedRange reserved_range = 4; + + // Reserved enum value names, which may not be reused. A given name may only + // be reserved once. + repeated string reserved_name = 5; } // Describes a value within an enum. @@ -241,9 +301,9 @@ message MethodDescriptorProto { optional MethodOptions options = 4; // Identifies if client streams multiple client messages - optional bool client_streaming = 5 [default=false]; + optional bool client_streaming = 5 [default = false]; // Identifies if server streams multiple server messages - optional bool server_streaming = 6 [default=false]; + optional bool server_streaming = 6 [default = false]; } @@ -279,7 +339,6 @@ message MethodDescriptorProto { // If this turns out to be popular, a web service will be set up // to automatically assign option numbers. - message FileOptions { // Sets the Java package where classes generated from this .proto will be @@ -289,34 +348,23 @@ message FileOptions { optional string java_package = 1; - // If set, all the classes from the .proto file are wrapped in a single - // outer class with the given name. This applies to both Proto1 - // (equivalent to the old "--one_java_file" option) and Proto2 (where - // a .proto always translates to a single class, but you may want to - // explicitly choose the class name). + // Controls the name of the wrapper Java class generated for the .proto file. + // That class will always contain the .proto file's getDescriptor() method as + // well as any top-level extensions defined in the .proto file. + // If java_multiple_files is disabled, then all the other classes from the + // .proto file will be nested inside the single wrapper outer class. optional string java_outer_classname = 8; - // If set true, then the Java code generator will generate a separate .java + // If enabled, then the Java code generator will generate a separate .java // file for each top-level message, enum, and service defined in the .proto - // file. Thus, these types will *not* be nested inside the outer class - // named by java_outer_classname. However, the outer class will still be + // file. Thus, these types will *not* be nested inside the wrapper class + // named by java_outer_classname. However, the wrapper class will still be // generated to contain the file's getDescriptor() method as well as any // top-level extensions defined in the file. - optional bool java_multiple_files = 10 [default=false]; - - // If set true, then the Java code generator will generate equals() and - // hashCode() methods for all messages defined in the .proto file. - // This increases generated code size, potentially substantially for large - // protos, which may harm a memory-constrained application. - // - In the full runtime this is a speed optimization, as the - // AbstractMessage base class includes reflection-based implementations of - // these methods. - // - In the lite runtime, setting this option changes the semantics of - // equals() and hashCode() to more closely match those of the full runtime; - // the generated methods compute their results based on field values rather - // than object identity. (Implementations should not assume that hashcodes - // will be consistent across runtimes or versions of the protocol compiler.) - optional bool java_generate_equals_and_hash = 20 [default=false]; + optional bool java_multiple_files = 10 [default = false]; + + // This option does nothing. + optional bool java_generate_equals_and_hash = 20 [deprecated=true]; // If set true, then the Java2 code generator will generate code that // throws an exception whenever an attempt is made to assign a non-UTF-8 @@ -324,17 +372,17 @@ message FileOptions { // Message reflection will do the same. // However, an extension field still accepts non-UTF-8 byte sequences. // This option has no effect on when used with the lite runtime. - optional bool java_string_check_utf8 = 27 [default=false]; + optional bool java_string_check_utf8 = 27 [default = false]; // Generated classes can be optimized for speed or code size. enum OptimizeMode { - SPEED = 1; // Generate complete code for parsing, serialization, - // etc. - CODE_SIZE = 2; // Use ReflectionOps to implement these methods. - LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. + SPEED = 1; // Generate complete code for parsing, serialization, + // etc. + CODE_SIZE = 2; // Use ReflectionOps to implement these methods. + LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. } - optional OptimizeMode optimize_for = 9 [default=SPEED]; + optional OptimizeMode optimize_for = 9 [default = SPEED]; // Sets the Go package where structs generated from this .proto will be // placed. If omitted, the Go package will be derived from the following: @@ -345,6 +393,7 @@ message FileOptions { + // Should generic services be generated in each language? "Generic" services // are not specific to any particular RPC system. They are generated by the // main code generators in each language (without additional plugins). @@ -355,19 +404,20 @@ message FileOptions { // that generate code specific to your particular RPC system. Therefore, // these default to false. Old code which depends on generic services should // explicitly set them to true. - optional bool cc_generic_services = 16 [default=false]; - optional bool java_generic_services = 17 [default=false]; - optional bool py_generic_services = 18 [default=false]; + optional bool cc_generic_services = 16 [default = false]; + optional bool java_generic_services = 17 [default = false]; + optional bool py_generic_services = 18 [default = false]; + optional bool php_generic_services = 42 [default = false]; // Is this file deprecated? // Depending on the target platform, this can emit Deprecated annotations // for everything in the file, or it will be completely ignored; in the very // least, this is a formalization for deprecating files. - optional bool deprecated = 23 [default=false]; + optional bool deprecated = 23 [default = false]; // Enables the use of arenas for the proto messages in this file. This applies // only to generated classes for C++. - optional bool cc_enable_arenas = 31 [default=false]; + optional bool cc_enable_arenas = 31 [default = true]; // Sets the objective c class prefix which is prepended to all objective c @@ -377,15 +427,41 @@ message FileOptions { // Namespace for generated classes; defaults to the package. optional string csharp_namespace = 37; - // Whether the nano proto compiler should generate in the deprecated non-nano - // suffixed package. - optional bool javanano_use_deprecated_package = 38; + // By default Swift generators will take the proto package and CamelCase it + // replacing '.' with underscore and use that to prefix the types/symbols + // defined. When this options is provided, they will use this value instead + // to prefix the types/symbols defined. + optional string swift_prefix = 39; - // The parser stores options it doesn't recognize here. See above. + // Sets the php class prefix which is prepended to all php generated classes + // from this .proto. Default is empty. + optional string php_class_prefix = 40; + + // Use this option to change the namespace of php generated classes. Default + // is empty. When this option is empty, the package name will be used for + // determining the namespace. + optional string php_namespace = 41; + + // Use this option to change the namespace of php generated metadata classes. + // Default is empty. When this option is empty, the proto file name will be + // used for determining the namespace. + optional string php_metadata_namespace = 44; + + // Use this option to change the package of ruby generated classes. Default + // is empty. When this option is not set, the package name will be used for + // determining the ruby package. + optional string ruby_package = 45; + + + // The parser stores options it doesn't recognize here. + // See the documentation for the "Options" section above. repeated UninterpretedOption uninterpreted_option = 999; - // Clients can define custom options in extensions of this message. See above. + // Clients can define custom options in extensions of this message. + // See the documentation for the "Options" section above. extensions 1000 to max; + + reserved 38; } message MessageOptions { @@ -407,18 +483,20 @@ message MessageOptions { // // Because this is an option, the above two restrictions are not enforced by // the protocol compiler. - optional bool message_set_wire_format = 1 [default=false]; + optional bool message_set_wire_format = 1 [default = false]; // Disables the generation of the standard "descriptor()" accessor, which can // conflict with a field of the same name. This is meant to make migration // from proto1 easier; new code should avoid fields named "descriptor". - optional bool no_standard_descriptor_accessor = 2 [default=false]; + optional bool no_standard_descriptor_accessor = 2 [default = false]; // Is this message deprecated? // Depending on the target platform, this can emit Deprecated annotations // for the message, or it will be completely ignored; in the very least, // this is a formalization for deprecating messages. - optional bool deprecated = 3 [default=false]; + optional bool deprecated = 3 [default = false]; + + reserved 4, 5, 6; // Whether the message is an automatically generated map entry type for the // maps field. @@ -435,7 +513,7 @@ message MessageOptions { // // Implementations may choose not to generate the map_entry=true message, but // use a native map in the target language to hold the keys and values. - // The reflection APIs in such implementions still need to work as + // The reflection APIs in such implementations still need to work as // if the field is a repeated message field. // // NOTE: Do not set the option in .proto files. Always use the maps syntax @@ -443,6 +521,10 @@ message MessageOptions { // parser. optional bool map_entry = 7; + reserved 8; // javalite_serializable + reserved 9; // javanano_as_lite + + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -471,16 +553,17 @@ message FieldOptions { // false will avoid using packed encoding. optional bool packed = 2; - // The jstype option determines the JavaScript type used for values of the // field. The option is permitted only for 64 bit integral and fixed types - // (int64, uint64, sint64, fixed64, sfixed64). By default these types are - // represented as JavaScript strings. This avoids loss of precision that can - // happen when a large value is converted to a floating point JavaScript - // numbers. Specifying JS_NUMBER for the jstype causes the generated - // JavaScript code to use the JavaScript "number" type instead of strings. - // This option is an enum to permit additional types to be added, - // e.g. goog.math.Integer. + // (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + // is represented as JavaScript string, which avoids loss of precision that + // can happen when a large value is converted to a floating point JavaScript. + // Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + // use the JavaScript "number" type. The behavior of the default option + // JS_NORMAL is implementation dependent. + // + // This option is an enum to permit additional types to be added, e.g. + // goog.math.Integer. optional JSType jstype = 6 [default = JS_NORMAL]; enum JSType { // Use the default type. @@ -512,7 +595,7 @@ message FieldOptions { // // // Note that implementations may choose not to check required fields within - // a lazy sub-message. That is, calling IsInitialized() on the outher message + // a lazy sub-message. That is, calling IsInitialized() on the outer message // may return true even if the inner message has missing required fields. // This is necessary because otherwise the inner message would have to be // parsed in order to perform the check, defeating the purpose of lazy @@ -521,18 +604,28 @@ message FieldOptions { // implementation must either *always* check its required fields, or *never* // check its required fields, regardless of whether or not the message has // been parsed. - optional bool lazy = 5 [default=false]; + optional bool lazy = 5 [default = false]; // Is this field deprecated? // Depending on the target platform, this can emit Deprecated annotations // for accessors, or it will be completely ignored; in the very least, this // is a formalization for deprecating fields. - optional bool deprecated = 3 [default=false]; + optional bool deprecated = 3 [default = false]; // For Google-internal migration only. Do not use. - optional bool weak = 10 [default=false]; + optional bool weak = 10 [default = false]; + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; + + reserved 4; // removed jtype +} + +message OneofOptions { // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -550,7 +643,9 @@ message EnumOptions { // Depending on the target platform, this can emit Deprecated annotations // for the enum, or it will be completely ignored; in the very least, this // is a formalization for deprecating enums. - optional bool deprecated = 3 [default=false]; + optional bool deprecated = 3 [default = false]; + + reserved 5; // javanano_as_lite // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -564,7 +659,7 @@ message EnumValueOptions { // Depending on the target platform, this can emit Deprecated annotations // for the enum value, or it will be completely ignored; in the very least, // this is a formalization for deprecating enum values. - optional bool deprecated = 1 [default=false]; + optional bool deprecated = 1 [default = false]; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -584,7 +679,7 @@ message ServiceOptions { // Depending on the target platform, this can emit Deprecated annotations // for the service, or it will be completely ignored; in the very least, // this is a formalization for deprecating services. - optional bool deprecated = 33 [default=false]; + optional bool deprecated = 33 [default = false]; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -604,7 +699,18 @@ message MethodOptions { // Depending on the target platform, this can emit Deprecated annotations // for the method, or it will be completely ignored; in the very least, // this is a formalization for deprecating methods. - optional bool deprecated = 33 [default=false]; + optional bool deprecated = 33 [default = false]; + + // Is this method side-effect-free (or safe in HTTP parlance), or idempotent, + // or neither? HTTP based RPC implementation may choose GET verb for safe + // methods, and PUT verb for idempotent methods instead of the default POST. + enum IdempotencyLevel { + IDEMPOTENCY_UNKNOWN = 0; + NO_SIDE_EFFECTS = 1; // implies idempotent + IDEMPOTENT = 2; // idempotent, but may have side effects + } + optional IdempotencyLevel idempotency_level = 34 + [default = IDEMPOTENCY_UNKNOWN]; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -685,7 +791,7 @@ message SourceCodeInfo { // beginning of the "extend" block and is shared by all extensions within // the block. // - Just because a location's span is a subset of some other location's span - // does not mean that it is a descendent. For example, a "group" defines + // does not mean that it is a descendant. For example, a "group" defines // both a type and a field in a single declaration. Thus, the locations // corresponding to the type and field and their components will overlap. // - Code which tries to interpret locations should probably be designed to @@ -716,14 +822,14 @@ message SourceCodeInfo { // [ 4, 3, 2, 7 ] // this path refers to the whole field declaration (from the beginning // of the label to the terminating semicolon). - repeated int32 path = 1 [packed=true]; + repeated int32 path = 1 [packed = true]; // Always has exactly three or four elements: start line, start column, // end line (optional, otherwise assumed same as start line), end column. // These are packed into a single field for efficiency. Note that line // and column numbers are zero-based -- typically you will want to add // 1 to each before displaying to a user. - repeated int32 span = 2 [packed=true]; + repeated int32 span = 2 [packed = true]; // If this SourceCodeInfo represents a complete declaration, these are any // comments appearing before and after the declaration which appear to be @@ -777,3 +883,29 @@ message SourceCodeInfo { repeated string leading_detached_comments = 6; } } + +// Describes the relationship between generated code and its original source +// file. A GeneratedCodeInfo message is associated with only one generated +// source file, but may contain references to different source .proto files. +message GeneratedCodeInfo { + // An Annotation connects some span of text in generated code to an element + // of its generating .proto file. + repeated Annotation annotation = 1; + message Annotation { + // Identifies the element in the original source .proto file. This field + // is formatted the same as SourceCodeInfo.Location.path. + repeated int32 path = 1 [packed = true]; + + // Identifies the filesystem path to the original source .proto. + optional string source_file = 2; + + // Identifies the starting offset in bytes in the generated code + // that relates to the identified object. + optional int32 begin = 3; + + // Identifies the ending offset in bytes in the generated code that + // relates to the identified offset. The end offset should be one past + // the last relevant byte (so the length of the text = end - begin). + optional int32 end = 4; + } +} From db85425bc8a8d2a60d8e4ab46360e6bcd9074e28 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 13 Sep 2021 09:31:58 -0600 Subject: [PATCH 1175/1191] Bump version to v3.10.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 77a79c63..8ed405a7 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.4' # rubocop:disable Style/MutableConstant + VERSION = '3.10.5' # rubocop:disable Style/MutableConstant end From 4d2278e2fb5c365f2cf61ac56204f6e2fcbef09e Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 27 Apr 2022 10:26:21 -0600 Subject: [PATCH 1176/1191] Use activesupport/all in tests (>= 6 causes load errors) --- spec/lib/protobuf/rpc/stat_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index 9abd627f..10015491 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' require 'timecop' -require 'active_support/core_ext/numeric/time' +require 'active_support/all' RSpec.describe ::Protobuf::Rpc::Stat do From 7f0a2b89afd417fa67561ee81380f546f46f64fe Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 27 Apr 2022 10:42:02 -0600 Subject: [PATCH 1177/1191] Ensure server is always set for PbError messages in exception handler --- lib/protobuf/rpc/error.rb | 8 ++++---- lib/protobuf/rpc/middleware/exception_handler.rb | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 343d1889..038eeca9 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -13,12 +13,12 @@ def initialize(message = 'An unknown RpcError occurred', error_type = 'RPC_ERROR super message end - def encode - to_response.encode + def encode(args = {}) + to_response(args).encode end - def to_response - ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type) + def to_response(args = {}) + ::Protobuf::Socketrpc::Response.new({:error => message, :error_reason => error_type}.merge(args)) end end end diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index 9592c049..376e0375 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -22,7 +22,7 @@ def _call(env) # Rescue exceptions, re-wrap them as generic Protobuf errors, # and encode them env.response = wrap_exception(exception) - env.encoded_response = env.response.encode + env.encoded_response = wrap_and_encode_with_server(env.response, env) env end @@ -34,6 +34,17 @@ def wrap_exception(exception) exception = RpcFailed.new(exception.message) unless exception.is_a?(PbError) exception end + + # If the response is a PbError, it won't have the server merged into the response proto. + # We should add it here since exception handler is always at the bottom of the middleware + # stack. Without this, the server hostname in the client rpc log will not be set. + def wrap_and_encode_with_server(response, env) + if response.is_a?(PbError) + response.encode(:server => env.server) + else + response.encode + end + end end end end From ddb619082d34bb29a74246959454cf6f755c467c Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 27 Apr 2022 10:48:11 -0600 Subject: [PATCH 1178/1191] Add supporting tests showing server is added to the encoded error --- spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index 0a71e43d..01248f40 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Protobuf::Rpc::Middleware::ExceptionHandler do let(:app) { proc { |env| env } } - let(:env) { Protobuf::Rpc::Env.new } + let(:env) { Protobuf::Rpc::Env.new("server" => "cooldude") } subject { described_class.new(app) } @@ -17,7 +17,7 @@ end context "when exceptions occur" do - let(:encoded_error) { error.encode } + let(:encoded_error) { error.encode(:server => "cooldude") } let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } before { allow(app).to receive(:call).and_raise(error, 'Boom!') } @@ -42,7 +42,7 @@ end context "when exception is not a Protobuf error" do - let(:encoded_error) { error.encode } + let(:encoded_error) { error.encode(:server => "cooldude") } let(:error) { Protobuf::Rpc::RpcFailed.new('Boom!') } before { allow(app).to receive(:call).and_raise(RuntimeError, 'Boom!') } From 89827d67ed5ab6e69b7062e612c8b5d35b87f3d4 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 27 Apr 2022 10:49:53 -0600 Subject: [PATCH 1179/1191] Rubocop --- lib/protobuf/rpc/error.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index 038eeca9..584a0425 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -18,7 +18,7 @@ def encode(args = {}) end def to_response(args = {}) - ::Protobuf::Socketrpc::Response.new({:error => message, :error_reason => error_type}.merge(args)) + ::Protobuf::Socketrpc::Response.new({ :error => message, :error_reason => error_type }.merge(args)) end end end From bcd668f32a482c5d5b5a678253bee7943994c97d Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 27 Apr 2022 11:28:22 -0600 Subject: [PATCH 1180/1191] simplify ci / drop 2.4 ruby --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e1c40701..c90128e3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,7 +42,5 @@ workflows: ruby-image: - circleci/jruby:9.2.6.0-jdk - circleci/jruby:9.1.17.0-jdk - - circleci/jruby:9.2-jdk8 - - circleci/ruby:2.4 - circleci/ruby:2.5 - circleci/ruby:2.7 From ea0c98efc316288e2f7e080cf7aa186cc220adf7 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 27 Apr 2022 11:36:03 -0600 Subject: [PATCH 1181/1191] Bump version to 3.10.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 8ed405a7..28251aa8 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.5' # rubocop:disable Style/MutableConstant + VERSION = '3.10.6' # rubocop:disable Style/MutableConstant end From 3305a9d9b43730572b5ea0f17c54c8bffc2c3ddc Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 24 Aug 2022 13:30:54 +0800 Subject: [PATCH 1182/1191] Allow captialize enums name Signed-off-by: tison --- lib/protobuf/generators/enum_generator.rb | 1 + lib/protobuf/generators/field_generator.rb | 2 ++ spec/lib/protobuf/generators/enum_generator_spec.rb | 9 +++++++++ spec/lib/protobuf/generators/field_generator_spec.rb | 9 +++++++++ 4 files changed, 21 insertions(+) diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 1088e3ed..b8522171 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -29,6 +29,7 @@ def compile def build_value(enum_value_descriptor) name = enum_value_descriptor.name + name.capitalize! if ENV.key?('PB_CAPITALIZE_ENUMS') name.upcase! if ENV.key?('PB_UPCASE_ENUMS') number = enum_value_descriptor.number "define :#{name}, #{number}" diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 68652fcc..1642308f 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -140,6 +140,8 @@ def enum_default_value optionally_upcased_default = if ENV.key?('PB_UPCASE_ENUMS') verbatim_default_value.upcase + elsif ENV.key?('PB_CAPITALIZE_ENUMS') + verbatim_default_value.capitalize else verbatim_default_value end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 1c263188..95637aac 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -77,6 +77,15 @@ class TestEnum < ::Protobuf::Enum expect(subject.build_value(enum.value.first)).to eq("define :BOOM, 1") end end + + context 'with PB_CAPITALIZE_ENUMS set' do + before { allow(ENV).to receive(:key?).with('PB_CAPITALIZE_ENUMS').and_return(true) } + let(:values) { [{ :name => 'boom', :number => 1 }] } + + it 'returns a string with the given enum name in ALL CAPS' do + expect(subject.build_value(enum.value.first)).to eq("define :Boom, 1") + end + end end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index e4d78ea2..d1ec7635 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -71,6 +71,15 @@ specify { expect(subject).to eq " optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } end + context 'when type is an enum with lowercase default value with PB_CAPITALIZE_ENUMS set' do + let(:type_enum) { :TYPE_ENUM } + let(:type_name) { '.foo.bar.Baz' } + let(:default_value) { 'quux' } + before { allow(ENV).to receive(:key?).with('PB_CAPITALIZE_ENUMS').and_return(true) } + + specify { expect(subject).to eq " optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::Quux\n" } + end + context 'when the type is a string' do let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } From e59fdf4fe3dd428b48bb0c641790d55691cbcd43 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 24 Aug 2022 10:17:38 -0600 Subject: [PATCH 1183/1191] Fix rspec to work with different receiver args --- spec/lib/protobuf/generators/enum_generator_spec.rb | 2 ++ spec/lib/protobuf/generators/field_generator_spec.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 95637aac..767a5d9d 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -71,6 +71,7 @@ class TestEnum < ::Protobuf::Enum context 'with PB_UPCASE_ENUMS set' do before { allow(ENV).to receive(:key?).with('PB_UPCASE_ENUMS').and_return(true) } + before { allow(ENV).to receive(:key?).with('PB_CAPITALIZE_ENUMS').and_return(false) } let(:values) { [{ :name => 'boom', :number => 1 }] } it 'returns a string with the given enum name in ALL CAPS' do @@ -79,6 +80,7 @@ class TestEnum < ::Protobuf::Enum end context 'with PB_CAPITALIZE_ENUMS set' do + before { allow(ENV).to receive(:key?).with('PB_UPCASE_ENUMS').and_return(false) } before { allow(ENV).to receive(:key?).with('PB_CAPITALIZE_ENUMS').and_return(true) } let(:values) { [{ :name => 'boom', :number => 1 }] } diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index d1ec7635..fc7c3def 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -67,6 +67,7 @@ let(:type_name) { '.foo.bar.Baz' } let(:default_value) { 'quux' } before { allow(ENV).to receive(:key?).with('PB_UPCASE_ENUMS').and_return(true) } + before { allow(ENV).to receive(:key?).with('PB_CAPITALIZE_ENUMS').and_return(false) } specify { expect(subject).to eq " optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } end @@ -75,6 +76,7 @@ let(:type_enum) { :TYPE_ENUM } let(:type_name) { '.foo.bar.Baz' } let(:default_value) { 'quux' } + before { allow(ENV).to receive(:key?).with('PB_UPCASE_ENUMS').and_return(false) } before { allow(ENV).to receive(:key?).with('PB_CAPITALIZE_ENUMS').and_return(true) } specify { expect(subject).to eq " optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::Quux\n" } From b866fc5667226d0582f328ab24c648e578c5a380 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 24 Aug 2022 10:18:08 -0600 Subject: [PATCH 1184/1191] Bump version to 3.10.7 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 28251aa8..f29d2675 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.6' # rubocop:disable Style/MutableConstant + VERSION = '3.10.7' # rubocop:disable Style/MutableConstant end From 869dcfd3613c3f4f7078fa83cd7abc776c3a25c0 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 8 Nov 2023 20:01:25 +0100 Subject: [PATCH 1185/1191] Require `active_support` before cherry-picking features It's part of the Active Support contract, the entry point must be loaded, otherwise requiring individual components may fail. Fixes: ``` active_support/core_ext/time/conversions.rb:62:in `': undefined method `deprecator' for ActiveSupport:Module (NoMethodError) from gems/activesupport-7.1.1/lib/active_support/core_ext/time/conversions.rb:7:in `' from gems/activesupport-7.1.1/lib/active_support/core_ext/object/json.rb:14:in `require' from gems/activesupport-7.1.1/lib/active_support/core_ext/object/json.rb:14:in `' from gems/activesupport-7.1.1/lib/active_support/json/encoding.rb:3:in `require' from gems/activesupport-7.1.1/lib/active_support/json/encoding.rb:3:in `' from gems/activesupport-7.1.1/lib/active_support/json.rb:4:in `require' from gems/activesupport-7.1.1/lib/active_support/json.rb:4:in `' from gems/protobuf-cucumber-3.10.8/lib/protobuf.rb:10:in `require' ``` --- lib/protobuf.rb | 1 + lib/protobuf/cli.rb | 1 + lib/protobuf/code_generator.rb | 1 + lib/protobuf/deprecation.rb | 1 + lib/protobuf/field/base_field.rb | 1 + spec/support/server.rb | 1 + 6 files changed, 6 insertions(+) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 69139e2c..c6040fd4 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -4,6 +4,7 @@ require 'socket' require 'stringio' +require 'active_support' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/try' require 'active_support/inflector' diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 35c6d936..0a84443b 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,3 +1,4 @@ +require 'active_support' require 'active_support/core_ext/hash/keys' require 'active_support/inflector' diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 7068800b..0a006f56 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -1,3 +1,4 @@ +require 'active_support' require 'active_support/core_ext/module/aliasing' require 'protobuf/generators/file_generator' diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index 8c0d415e..97b56698 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -1,3 +1,4 @@ +require 'active_support' require 'active_support/deprecation' module Protobuf diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 6f2f4f7f..86472738 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,3 +1,4 @@ +require 'active_support' require 'active_support/core_ext/hash/slice' require 'protobuf/field/field_array' require 'protobuf/field/field_hash' diff --git a/spec/support/server.rb b/spec/support/server.rb index 8a0203b6..16fc5678 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,5 +1,6 @@ require 'ostruct' +require 'active_support' require 'active_support/core_ext/hash/reverse_merge' require 'spec_helper' From ee5f73bb270b1a7b7ab44c95c8099a7790fc4882 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 27 Nov 2023 09:30:22 -0700 Subject: [PATCH 1186/1191] Bump version to 3.10.8 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f29d2675..f570feaa 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.7' # rubocop:disable Style/MutableConstant + VERSION = '3.10.8' # rubocop:disable Style/MutableConstant end From cfde698227e8b2fe0076625b7c653f10501bb7d6 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Mon, 13 Apr 2020 12:11:15 +0200 Subject: [PATCH 1187/1191] Load correct versions of pry and pry-byebug on older Rubies This does two things: - Move complex dependency logic out of the gemspec. The gemspec logic is only evaluated at build time, so keeping Ruby version dependendent logic in there causes different gems to be published depending on the source machine. - Load slightly older pry versions on Ruby 2.3 and lower, so they work with the pry-byebug version that supports those older Ruby versions. --- Gemfile | 23 +++++++++++++++++++++++ protobuf.gemspec | 19 ------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index fa75df15..a19bf744 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,26 @@ source 'https://rubygems.org/' gemspec + +group :development do + # debuggers only work in MRI + if RUBY_ENGINE.to_sym == :ruby + if RUBY_VERSION < '2.0.0' + gem 'pry-debugger' + elsif RUBY_VERSION < '2.4.0' + gem 'pry-byebug' + gem 'pry', '~> 0.12.0' + else + gem 'pry-byebug', '~> 3.9.0' + gem 'pry', '~> 0.13.0' + end + + gem 'pry-stack_explorer' + + gem 'varint' + gem 'ruby-prof' + elsif RUBY_PLATFORM =~ /java/i + gem 'fast_blank_java' + gem 'pry' + end +end diff --git a/protobuf.gemspec b/protobuf.gemspec index 4f182c4e..9cad244b 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -35,23 +35,4 @@ require "protobuf/version" s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' s.add_development_dependency 'yard' - - # debuggers only work in MRI - if RUBY_ENGINE.to_sym == :ruby - # we don't support MRI < 1.9.3 - pry_debugger = if RUBY_VERSION < '2.0.0' - 'pry-debugger' - else - 'pry-byebug' - end - - s.add_development_dependency pry_debugger - s.add_development_dependency 'pry-stack_explorer' - - s.add_development_dependency 'varint' - s.add_development_dependency 'ruby-prof' - elsif RUBY_PLATFORM =~ /java/i - s.add_development_dependency 'fast_blank_java' - s.add_development_dependency 'pry' - end end From b00d91e7df255536428843723e0b18cb768d6751 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Mon, 13 Apr 2020 08:50:16 +0200 Subject: [PATCH 1188/1191] Update development dependencies --- protobuf.gemspec | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index 9cad244b..055be259 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -28,10 +28,9 @@ require "protobuf/version" s.add_development_dependency 'benchmark-ips' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses - s.add_development_dependency 'rspec', '>= 3.0' - s.add_development_dependency "rubocop", "~> 0.38.0" - s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984 + s.add_development_dependency 'rake', '~> 13.0' + s.add_development_dependency 'rspec', '~> 3.5' + s.add_development_dependency "rubocop", "~> 0.81.0" s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' s.add_development_dependency 'yard' From 4faecead1fb12419295db78bc24b8e795f0d3304 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Mon, 13 Apr 2020 08:58:31 +0200 Subject: [PATCH 1189/1191] Update RuboCop configuration for RuboCop 0.81.0 --- .rubocop.yml | 29 ++- .rubocop_todo.yml | 516 ++++++++++++++++++++++++++++++++----- lib/protobuf/rpc/buffer.rb | 4 +- 3 files changed, 476 insertions(+), 73 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 310aa0c8..c4fa04ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,8 +6,8 @@ AllCops: - 'spec/support/protos/*.pb.rb' - 'varint_prof.rb' -Lint/EndAlignment: - AlignWith: keyword +Layout/EndAlignment: + EnforcedStyleAlignWith: keyword Lint/Loop: Enabled: false @@ -18,25 +18,25 @@ Metrics/ClassLength: Metrics/ModuleLength: Enabled: false -Style/CaseIndentation: - IndentWhenRelativeTo: end +Layout/CaseIndentation: + EnforcedStyle: end Style/ClassAndModuleChildren: Exclude: - '**/*.pb.rb' -Style/ClassAndModuleCamelCase: +Naming/ClassAndModuleCamelCase: Exclude: - '**/*.pb.rb' -Style/EmptyLineBetweenDefs: +Layout/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true -Style/EmptyLines: +Layout/EmptyLines: Exclude: - '**/*.pb.rb' -Style/FileName: +Naming/FileName: Exclude: - '**/protoc-gen-ruby*' @@ -46,7 +46,7 @@ Style/GuardClause: Style/HashSyntax: EnforcedStyle: hash_rockets -Style/IndentHash: +Layout/FirstHashElementIndentation: EnforcedStyle: consistent Style/Semicolon: @@ -55,16 +55,23 @@ Style/Semicolon: Style/SingleLineBlockParams: Enabled: false -Style/TrailingBlankLines: +Layout/TrailingEmptyLines: Exclude: - '**/*.pb.rb' Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: comma Style/TrivialAccessors: AllowDSLWriters: true AllowPredicates: true + +Style/Encoding: + Exclude: + - '**/*.pb.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 611730ad..bd670fea 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,30 +1,208 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-09-25 12:31:31 -0700 using RuboCop version 0.34.2. +# on 2020-04-13 09:00:39 +0200 using RuboCop version 0.81.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 31 +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'protobuf.gemspec' + +# Offense count: 2 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RubyVersionGlobalsUsage: + Exclude: + - 'protobuf.gemspec' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/ClosingParenthesisIndentation: + Exclude: + - 'spec/lib/protobuf/generators/base_spec.rb' + - 'spec/lib/protobuf/rpc/service_spec.rb' + +# Offense count: 42 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'protobuf.gemspec' + +# Offense count: 83 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Enabled: false + +# Offense count: 75 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Enabled: false + +# Offense count: 39 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Enabled: false + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'Rakefile' + - 'lib/protobuf/field.rb' + - 'lib/protobuf/rpc/connectors/base.rb' + - 'spec/lib/protobuf/enum_spec.rb' + - 'spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: squiggly, active_support, powerpack, unindent +Layout/HeredocIndentation: + Exclude: + - 'spec/lib/protobuf/generators/enum_generator_spec.rb' + - 'spec/lib/protobuf/generators/file_generator_spec.rb' + - 'spec/lib/protobuf/generators/service_generator_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineArrayBraceLayout: + Exclude: + - 'spec/lib/protobuf/generators/field_generator_spec.rb' + - 'spec/lib/protobuf/message_spec.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'spec/functional/code_generator_spec.rb' + - 'spec/lib/protobuf/generators/field_generator_spec.rb' + - 'spec/lib/protobuf/optionable_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Layout/MultilineMethodCallIndentation: + Exclude: + - 'spec/lib/protobuf/generators/file_generator_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/RescueEnsureAlignment: + Exclude: + - 'lib/protobuf/rpc/servers/socket/server.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/SpaceAfterNot: + Exclude: + - 'lib/protobuf/field/base_field.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + - 'lib/protobuf/rpc/servers/socket/worker.rb' + - 'lib/protobuf/tasks/compile.rake' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'lib/protobuf/field/base_field.rb' + +# Offense count: 6 +Lint/DuplicateMethods: + Exclude: + - 'lib/protobuf/generators/field_generator.rb' + - 'lib/protobuf/rpc/buffer.rb' + - 'lib/protobuf/rpc/stat.rb' + +# Offense count: 1 +Lint/EmptyWhen: + Exclude: + - 'lib/protobuf/rpc/servers/socket/server.rb' + +# Offense count: 1 +Lint/InterpolationCheck: + Exclude: + - 'spec/lib/protobuf/message_spec.rb' + +# Offense count: 1 +# Configuration parameters: MaximumRangeSize. +Lint/MissingCopEnableDirective: + Exclude: + - 'lib/protobuf/message/fields.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Lint/RedundantCopDisableDirective: + Exclude: + - 'lib/protobuf.rb' + - 'lib/protobuf/message/fields.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Lint/RedundantRequireStatement: + Exclude: + - 'lib/protobuf/rpc/servers/zmq/broker.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + - 'lib/protobuf/rpc/servers/zmq/worker.rb' + - 'lib/protobuf/rpc/servers/zmq_runner.rb' + - 'lib/protobuf/rpc/service_directory.rb' + +# Offense count: 2 +# Configuration parameters: AllowComments. +Lint/SuppressedException: + Exclude: + - 'lib/protobuf.rb' + +# Offense count: 44 +# Configuration parameters: IgnoredMethods. Metrics/AbcSize: - Max: 59 + Max: 55 + +# Offense count: 116 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 742 # Offense count: 1 +# Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 5 -# Offense count: 6 +# Offense count: 19 +# Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 12 -# Offense count: 493 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 199 - -# Offense count: 44 -# Configuration parameters: CountComments. +# Offense count: 65 +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 38 @@ -33,21 +211,73 @@ Metrics/MethodLength: Metrics/ParameterLists: Max: 7 -# Offense count: 6 +# Offense count: 18 +# Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: - Max: 17 + Max: 13 -# Offense count: 1 +# Offense count: 5 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'spec/lib/protobuf/generators/file_generator_spec.rb' + - 'spec/lib/protobuf/generators/service_generator_spec.rb' + +# Offense count: 13 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'lib/protobuf/field/base_field.rb' + - 'lib/protobuf/logging.rb' + - 'lib/protobuf/rpc/client.rb' + - 'lib/protobuf/rpc/connectors/base.rb' + - 'lib/protobuf/rpc/connectors/socket.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + - 'lib/protobuf/rpc/server.rb' + - 'lib/protobuf/rpc/servers/socket/server.rb' + - 'lib/protobuf/rpc/servers/socket/worker.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + - 'lib/protobuf/rpc/stat.rb' + - 'spec/support/server.rb' + +# Offense count: 2 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp +Naming/MethodParameterName: + Exclude: + - 'lib/protobuf/logging.rb' + - 'spec/lib/protobuf/rpc/service_filters_spec.rb' + +# Offense count: 6 # Cop supports --auto-correct. -Performance/StringReplacement: +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: Exclude: - - 'lib/protobuf/rpc/buffer.rb' + - 'lib/protobuf/rpc/connectors/base.rb' + - 'lib/protobuf/rpc/middleware/exception_handler.rb' + - 'lib/protobuf/rpc/middleware/request_decoder.rb' + - 'lib/protobuf/rpc/middleware/response_encoder.rb' + - 'lib/protobuf/rpc/service_filters.rb' -Performance/TimesMap: - Enabled: false +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - '**/*.pb.rb' + - 'spec/lib/protobuf/generators/field_generator_spec.rb' + - 'spec/lib/protobuf/generators/service_generator_spec.rb' + +# Offense count: 2 +Style/CommentedKeyword: + Exclude: + - 'lib/protobuf/rpc/servers/socket_runner.rb' + - 'lib/protobuf/rpc/servers/zmq_runner.rb' -# Offense count: 127 -# Configuration parameters: Exclude. +# Offense count: 203 Style/Documentation: Enabled: false @@ -62,84 +292,250 @@ Style/DoubleNegation: - 'lib/protobuf/rpc/servers/zmq/worker.rb' - 'lib/protobuf/rpc/service_directory.rb' +# Offense count: 9 +# Cop supports --auto-correct. +Style/EmptyCaseCondition: + Exclude: + - 'lib/protobuf/enum.rb' + - 'lib/protobuf/field/base_field.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + - 'lib/protobuf/rpc/servers/socket/server.rb' + - 'lib/protobuf/rpc/servers/socket_runner.rb' + - 'lib/protobuf/rpc/servers/zmq_runner.rb' + # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty, nil, both Style/EmptyElse: Exclude: - 'lib/protobuf/enum.rb' - 'lib/protobuf/message/fields.rb' -# Offense count: 77 +# Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/EmptyLinesAroundBlockBody: - Enabled: false +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'lib/protobuf/code_generator.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - '**/*.pb.rb' + - 'protobuf.gemspec' + - 'spec/lib/protobuf/field/string_field_spec.rb' + - 'spec/lib/protobuf/message_spec.rb' -# Offense count: 90 +# Offense count: 1 +Style/EvalWithLocation: + Exclude: + - 'lib/protobuf/message/fields.rb' + +# Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/EmptyLinesAroundClassBody: +Style/ExpandPathArguments: + Exclude: + - 'spec/benchmark/tasks.rb' + - 'spec/lib/protobuf/cli_spec.rb' + +# Offense count: 167 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 50 +# Offense count: 1 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'lib/protobuf/generators/base.rb' + +# Offense count: 22 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/EmptyLinesAroundModuleBody: +Style/IfUnlessModifier: Enabled: false -# Offense count: 2 -Style/IndentationWidth: +# Offense count: 1 +Style/MethodMissingSuper: Exclude: - - 'protobuf.gemspec' - - 'lib/protobuf/cli.rb' + - 'lib/protobuf/rpc/client.rb' -# Offense count: 3 -Style/ElseAlignment: +# Offense count: 1 +Style/MissingRespondToMissing: Exclude: - - 'protobuf.gemspec' - - 'lib/protobuf/cli.rb' + - 'lib/protobuf/rpc/client.rb' -# Offense count: 8 +# Offense count: 17 # Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Style/ExtraSpacing: +Style/MultilineWhenThen: Exclude: - - 'lib/protobuf/rpc/connectors/common.rb' - - 'lib/protobuf/rpc/connectors/socket.rb' + - 'lib/protobuf/generators/field_generator.rb' + - 'lib/protobuf/generators/printable.rb' - 'lib/protobuf/rpc/connectors/zmq.rb' - - 'lib/protobuf/rpc/servers/socket/server.rb' - - 'spec/lib/protobuf/rpc/service_directory_spec.rb' + - 'lib/protobuf/rpc/servers/socket_runner.rb' + - 'lib/protobuf/rpc/servers/zmq_runner.rb' + +# Offense count: 1 +Style/MultipleComparison: + Exclude: + - 'lib/protobuf/generators/group_generator.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/protobuf/generators/field_generator.rb' + - 'lib/protobuf/rpc/buffer.rb' + - 'lib/protobuf/rpc/servers/zmq/util.rb' -# Offense count: 46 +# Offense count: 51 # Cop supports --auto-correct. +# Configuration parameters: Strict. Style/NumericLiterals: MinDigits: 21 +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/protobuf/generators/file_generator.rb' + - 'lib/protobuf/generators/message_generator.rb' + - 'lib/protobuf/rpc/buffer.rb' + - 'lib/protobuf/rpc/servers/socket/server.rb' + - 'lib/protobuf/rpc/servers/zmq/broker.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + - 'lib/protobuf/rpc/servers/zmq/worker.rb' + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'lib/protobuf/cli.rb' + - 'spec/lib/protobuf/field/field_array_spec.rb' + - 'spec/lib/protobuf/rpc/service_directory_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'lib/protobuf/message/fields.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantCondition: + Exclude: + - 'lib/protobuf/rpc/connectors/base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantInterpolation: + Exclude: + - 'lib/protobuf.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/protobuf/field/int64_field.rb' + - 'lib/protobuf/rpc/connectors/base.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + +# Offense count: 23 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'lib/protobuf/cli.rb' + - 'lib/protobuf/field/int64_field.rb' + - 'lib/protobuf/field/varint_field.rb' + - 'lib/protobuf/generators/file_generator.rb' + - 'lib/protobuf/message.rb' + - 'lib/protobuf/rpc/connectors/base.rb' + - 'lib/protobuf/rpc/connectors/ping.rb' + - 'lib/protobuf/rpc/connectors/socket.rb' + - 'lib/protobuf/rpc/middleware/exception_handler.rb' + - 'lib/protobuf/rpc/middleware/request_decoder.rb' + - 'lib/protobuf/rpc/middleware/response_encoder.rb' + - 'lib/protobuf/rpc/servers/zmq/broker.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + - 'lib/protobuf/rpc/servers/zmq/worker.rb' + - 'lib/protobuf/rpc/service_directory.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/protobuf/generators/field_generator.rb' + - 'lib/protobuf/generators/service_generator.rb' + - 'lib/protobuf/message/serialization.rb' + - 'lib/protobuf/rpc/connectors/base.rb' + - 'lib/protobuf/rpc/connectors/ping.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + +# Offense count: 71 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: only_raise, only_fail, semantic Style/SignalException: Enabled: false -# Offense count: 473 +# Offense count: 6 +# Cop supports --auto-correct. +Style/StderrPuts: + Exclude: + - 'lib/protobuf/cli.rb' + - 'lib/protobuf/code_generator.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + +# Offense count: 627 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes Style/StringLiterals: Enabled: false -# Offense count: 7 +# Offense count: 26 # Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -Style/SymbolProc: +# Configuration parameters: MinSize. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets + +# Offense count: 4 +# Cop supports --auto-correct. +Style/UnpackFirst: Exclude: - - 'lib/protobuf/generators/printable.rb' - - 'lib/protobuf/rpc/servers/socket/server.rb' - - 'spec/encoding/all_types_spec.rb' - - 'spec/encoding/extreme_values_spec.rb' - - 'spec/functional/socket_server_spec.rb' - - 'spec/functional/zmq_server_spec.rb' - - 'spec/lib/protobuf/rpc/servers/socket_server_spec.rb' + - 'lib/protobuf/field/double_field.rb' + - 'lib/protobuf/field/fixed32_field.rb' + - 'lib/protobuf/field/float_field.rb' + - 'lib/protobuf/field/sfixed32_field.rb' # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: WordRegex. +# SupportedStyles: percent, brackets Style/WordArray: - MinSize: 4 + EnforcedStyle: percent + MinSize: 3 + +# Offense count: 728 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 196 diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 53f163f2..afadec42 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -44,7 +44,7 @@ def <<(data) end end - def set_data(data) # rubocop:disable Style/AccessorMethodName + def set_data(data) # rubocop:disable Naming/AccessorMethodName @data = data.to_s @size = @data.size end @@ -61,7 +61,7 @@ def flushed? @flush end - def get_data_size # rubocop:disable Style/AccessorMethodName + def get_data_size # rubocop:disable Naming/AccessorMethodName if @size == 0 || @data.match(SIZE_REGEX) sliced_size = @data.slice!(SIZE_REGEX) @size = sliced_size.delete('-').to_i unless sliced_size.nil? From 32f60567fefe1209e234cd29392eb0a769f98943 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 12 Jan 2024 12:24:14 -0700 Subject: [PATCH 1190/1191] Clean up a few remaining rules for specs and rubocop to pass --- .rubocop.yml | 4 ++++ Gemfile | 6 +++--- protobuf.gemspec | 1 - spec/lib/protobuf/field/string_field_spec.rb | 2 -- spec/lib/protobuf/message_spec.rb | 2 -- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c4fa04ce..ea05f74d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,9 @@ AllCops: - 'spec/support/protos/*.pb.rb' - 'varint_prof.rb' +Bundler/DuplicatedGem: + Enabled: false + Layout/EndAlignment: EnforcedStyleAlignWith: keyword @@ -24,6 +27,7 @@ Layout/CaseIndentation: Style/ClassAndModuleChildren: Exclude: - '**/*.pb.rb' + - 'spec/**/*.rb' Naming/ClassAndModuleCamelCase: Exclude: diff --git a/Gemfile b/Gemfile index a19bf744..ea1fdd91 100644 --- a/Gemfile +++ b/Gemfile @@ -8,17 +8,17 @@ group :development do if RUBY_VERSION < '2.0.0' gem 'pry-debugger' elsif RUBY_VERSION < '2.4.0' - gem 'pry-byebug' gem 'pry', '~> 0.12.0' + gem 'pry-byebug' else - gem 'pry-byebug', '~> 3.9.0' gem 'pry', '~> 0.13.0' + gem 'pry-byebug', '~> 3.9.0' end gem 'pry-stack_explorer' - gem 'varint' gem 'ruby-prof' + gem 'varint' elsif RUBY_PLATFORM =~ /java/i gem 'fast_blank_java' gem 'pry' diff --git a/protobuf.gemspec b/protobuf.gemspec index 055be259..698c434b 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -1,4 +1,3 @@ -# encoding: UTF-8 $LOAD_PATH.push ::File.expand_path("../lib", __FILE__) require "protobuf/version" diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index f666907a..4fe358a3 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' RSpec.describe ::Protobuf::Field::StringField do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 96668b67..50513f14 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'stringio' require 'spec_helper' require PROTOS_PATH.join('resource.pb') From b700faf13ff113abecea2fbc39f0dc7805fb4cd1 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 12 Jan 2024 12:40:35 -0700 Subject: [PATCH 1191/1191] Bump version to 3.10.9 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f570feaa..0d7d5f38 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.10.8' # rubocop:disable Style/MutableConstant + VERSION = '3.10.9' # rubocop:disable Style/MutableConstant end
%Total
100% 0%63.34123.51 0.0063.34123.51 0 (top)
60.08120.19 0.0060.08120.19 1/1 Benchmark::IPS.ips
0.951.03 0.000.952/1121.022/115 Kernel.require
0.900.91 0.040.860.87 1/5##times##times
0.890.87 0.000.896/18650.876/1883 Kernel.require
0.520.50 0.060.460.44 17/19 Kernel.load
0.900.91 0.040.860.87 1/5 (top)
60.08120.19 0.0060.08120.19 2/5 Benchmark::IPS::Job#run
96%98% 0%61.00121.12 0.0560.95121.07 5##times##times
40.0880.18 0.0040.0880.18 1/1 Benchmark::IPS::Job#run_benchmark
20.0040.00 0.0020.0040.00 1/1 Benchmark::IPS::Job#run_warmup
0.420.45 0.010.4210000/7614590.4410000/2123384 Protobuf::Message::Serialization::ClassMethods.decode_from
0.270.28 0.010.2610000/7614590.2710000/4103921 Protobuf::Encoder.encode
0.110.000.1010000/1524359Class#new
0.12 0.00 0.121/762970##flat_map
0.140.000.141/7629701/4105546 Gem::Specification.each_gemspec
0.230.000.2319/7629700.250.010.2419/4105546 Kernel.require
20.001.6918.321/76297040.003.5136.491/4105546 Benchmark::IPS::Job#run_warmup
40.080.0040.071/76297080.180.0280.171/4105546 Benchmark::IPS::Job#run_benchmark
96%97% 2%60.891.7259.17762970##each120.963.56117.404105546##each
57.312.6854.623368410/3368410114.335.40108.926794724/6794724 Benchmark::IPS::Job::Entry#call_times
0.740.310.443368939/33689391.670.810.866795778/6795778 Benchmark::Timing.now
0.180.180.003368414/3368414##<
0.140.140.003368424/23728693##+
0.120.340.34 0.000.122/3Gem::Specification.gemspec_stubs_in6794732/6794732##<
0.110.300.30 0.000.1013/14Gem::Specification.load6794740/46949692##+
60.08120.19 0.0060.08120.19 1/1 (top)
94%97% 0%60.08120.19 0.0060.08120.19 1 Benchmark::IPS.ips
60.08120.19 0.0060.08120.19 1/1 Benchmark::IPS::Job#run
60.08120.19 0.0060.08120.19 1/1 Benchmark::IPS.ips
94%97% 0%60.08120.19 0.0060.08120.19 1 Benchmark::IPS::Job#run
60.08120.19 0.0060.08120.19 2/5##times##times
57.312.6854.623368410/3368410##each114.335.40108.926794724/6794724##each
90%92% 4%57.312.6854.623368410114.335.40108.926794724 Benchmark::IPS::Job::Entry#call_times
53.422.1651.2613506055/13506589106.564.94101.6225271252/25271834 Proc#call
0.650.651.281.28 0.0016874465/19924325##<32065976/32065992##<
0.560.561.081.08 0.0013506055/23728693##+25271252/46949692##+
53.422.1651.2613506055/13506589106.564.94101.6225271252/25271834 Benchmark::IPS::Job::Entry#call_times
84%3%53.452.1751.281350658986%4%106.604.95101.6425271834 Proc#call
22.462.3520.1112754596/12754596Protobuf::Message#to_hash
15.050.2014.85751459/76145927.520.4627.062113384/2123384 Protobuf::Message::Serialization::ClassMethods.decode_from
8.850.278.58751459/76145925.390.8124.584093920/4103921 Protobuf::Encoder.encode
3.220.123.09751459/1524359Class#new23.631.9021.739393746/9393746Protobuf::Message#to_hash_with_string_keys
1.360.211.15751459/761459Test::Resource#status=23.521.9321.609670202/9670202Protobuf::Message#to_hash
0.200.110.09751459/7614591.060.700.376207304/6217305 StringIO.new
0.320.320.004093920/4103921Protobuf::Message#to_proto
0.180.180.002113384/4247921Kernel.dup
40.0880.18 0.0040.0880.18 1/1##times##times
63%64% 0%40.0880.18 0.0040.0880.18 1 Benchmark::IPS::Job#run_benchmark
40.080.0040.071/762970##each
8.371.057.32761459/13516056Protobuf::Message#each_field_for_serialization80.180.0280.171/4105546##each
20.115.3814.7312754596/1351605621.604.5317.069670202/23167870 Protobuf::Message#to_hash
44%10%28.486.4322.0413516056##each_key
5.572.243.3312754596/12754596Protobuf::Field::StringField(singleton)#to_message_hash21.734.3317.399393746/23167870Protobuf::Message#to_hash_with_string_keys
5.182.133.0412754596/12754596Protobuf::Field::Int64Field(singleton)#to_message_hash22.783.5319.244103921/23167870Protobuf::Message#each_field_for_serialization
2.590.212.38761459/761459Protobuf::Field::Int64Field(singleton)#encode_to_stream
53%10%66.1012.4053.7023167870##each_key
2.422.420.0027793569/32362325Protobuf::Message#_protobuf_message_field15.223.2511.9618787492/18787492Protobuf::Field::BaseField#to_message_hash_with_string_key
2.012.010.0027793569/63970204##[]14.753.3011.4519340404/19340404Protobuf::Field::BaseField#to_message_hash
1.890.511.38761459/761459Protobuf::Field::StringField(singleton)#encode_to_stream14.731.6313.118217842/8217842Protobuf::Field::BaseField#encode_to_stream
3.341.69 1.660.211.46761459/761459Protobuf::Field::EnumField(singleton)#encode_to_stream
0.260.070.19761459/14277514Protobuf::Field::StringField(singleton)#value_from_values
0.250.070.18761459/14277514Protobuf::Field::Int64Field(singleton)#value_from_values
0.230.070.16761459/1522918Protobuf::Field::EnumField(singleton)#value_from_values8217842/8217842Protobuf::Field::BaseField#value_from_values_for_serialization
22.462.3520.1112754596/12754596Proc#call
35%3%22.462.3520.1112754596Protobuf::Message#to_hash3.203.200.0046345738/97013401##[]
20.115.3814.7312754596/13516056##each_key2.462.460.0046345738/50632510Test::Resource#_protobuf_message_field
20.0040.00 0.0020.0040.00 1/1##times##times
31%32% 0%20.0040.00 0.0020.0040.00 1 Benchmark::IPS::Job#run_warmup
20.001.6918.321/762970##each40.003.5136.491/4105546##each
0.420.45 0.010.4210000/761459##times0.4410000/2123384##times
15.050.2014.85751459/76145927.520.4627.062113384/2123384 Proc#call
24%22% 0%15.470.2115.2776145927.960.4627.502123384 Protobuf::Message::Serialization::ClassMethods.decode_from
14.760.2214.54761459/76145926.260.4325.832123384/2123384 Protobuf::Message::Serialization.decode_from
0.510.110.40761459/15243591.240.310.942123384/2136384 Class#new
14.760.2214.54761459/76145926.260.4325.832123384/2123384 Protobuf::Message::Serialization::ClassMethods.decode_from
23%21% 0%14.760.2214.5476145926.260.4325.832123384 Protobuf::Message::Serialization.decode_from
14.541.3113.23761459/76145925.832.3923.442123384/2123384 Protobuf::Decoder.decode_each_field
14.541.3113.23761459/76145925.832.3923.442123384/2123384 Protobuf::Message::Serialization.decode_from
22%2%14.541.3113.2376145920%1%25.832.3923.442123384 Protobuf::Decoder.decode_each_field
7.130.816.312284377/2284377Protobuf::Message::Serialization.set_field_bytes11.705.835.888513536/8513536ProtobufJavaHelpers::EncodeDecode.decode
5.562.882.694568754/4568754Protobuf::VarintPure.decode10.641.419.234256768/4256768Protobuf::Message::Serialization.set_field_bytes
0.150.150.310.31 0.003045836/30458366380152/6380152 StringIO#eof
0.130.130.250.25 0.003045836/3048922##==6380152/6383519##==
0.100.100.230.23 0.00761459/7614592123384/2123384 StringIO#read
0.180.180.004256768/4256768##>>
0.120.120.004256768/40271449##&
0.270.28 0.010.2610000/761459##times0.2710000/4103921##times
8.850.278.58751459/76145925.390.8124.584093920/4103921 Proc#call
14%20% 0%9.120.288.8476145925.670.8224.854103921 Protobuf::Encoder.encode
8.840.328.52761459/76145924.851.3223.524103921/4103921 Protobuf::Message#each_field_for_serialization
8.840.328.52761459/76145924.851.3223.524103921/4103921 Protobuf::Encoder.encode
13%0%8.840.328.5276145920%1%24.851.3223.524103921 Protobuf::Message#each_field_for_serialization
8.371.057.32761459/13516056##each_key22.783.5319.244103921/23167870##each_key
0.110.110.560.56 0.00761459/2284378Protobuf::Message#_protobuf_message_required_field_tags4103921/6237307Test::Resource#_protobuf_message_unset_required_field_tags
7.130.816.312284377/2284377Protobuf::Decoder.decode_each_field23.631.9021.739393746/9393746Proc#call
11%19% 1%7.130.816.312284377Protobuf::Message::Serialization.set_field_bytes23.631.9021.739393746Protobuf::Message#to_hash_with_string_keys
2.460.192.27761459/761459Protobuf::Field::EnumField(singleton)#set21.734.3317.399393746/23167870##each_key
1.710.211.49761459/761459Protobuf::Field::Int64Field(singleton)#set23.521.9321.609670202/9670202Proc#call
19%1%23.521.9321.609670202Protobuf::Message#to_hash
1.400.191.21761459/761459Protobuf::Field::StringField(singleton)#set21.604.5317.069670202/23167870##each_key
0.530.400.132284377/32362325Protobuf::Message#_protobuf_message_field15.223.2511.9618787492/18787492##each_key
12%2%15.223.2511.9618787492Protobuf::Field::BaseField#to_message_hash_with_string_key
0.210.210.002284377/63970204##[]11.963.658.3118787492/18787492Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHashWithStringKey#call
0.940.120.82761459/4568756Protobuf::Field::EnumField(singleton)#set14.753.3011.4519340404/19340404##each_key
11%2%14.753.3011.4519340404Protobuf::Field::BaseField#to_message_hash
1.000.160.84761459/4568756Protobuf::Field::StringField(singleton)#set
1.070.120.95761459/4568756Protobuf::Field::Int64Field(singleton)#set
1.180.190.98761459/4568756Test::Resource#status=11.453.647.8219340404/19340404Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHash#call
2.550.412.151522920/4568756##each14.731.6313.118217842/8217842##each_key
10%11% 1%6.741.005.744568756Protobuf::Message#set_field14.731.6313.118217842Protobuf::Field::BaseField#encode_to_stream
1.800.391.421522919/1522919Protobuf::Field::Int64Field(singleton)#set_field7.092.095.004103921/4103921Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
1.660.351.311522918/1522918Protobuf::Field::EnumField(singleton)#set_field6.021.034.994113921/4113921Protobuf::Field::BaseFieldObjectDefinitions::BaseEncodeToStream#call
1.600.601.001522919/1522919Protobuf::Field::StringField(singleton)#set_field6.273.133.1418787492/38127896Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHashWithStringKey#call
0.470.340.132284379/32362325Protobuf::Message#_protobuf_message_field6.453.193.2619340404/38127896Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHash#call
10%5%12.726.326.4038127896Protobuf::Field::BaseField#value_from_values
0.200.200.002284379/63970204##[]6.404.142.2638127896/38127896Protobuf::Field::BaseFieldObjectDefinitions::BaseFieldValueFromValues#call
5.572.243.3312754596/12754596##each_key11.963.658.3118787492/18787492Protobuf::Field::BaseField#to_message_hash_with_string_key
8%3%5.572.243.3312754596Protobuf::Field::StringField(singleton)#to_message_hash9%2%11.963.658.3118787492Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHashWithStringKey#call
2.371.530.8412754596/14277514Protobuf::Field::StringField(singleton)#value_from_values6.273.133.1418787492/38127896Protobuf::Field::BaseField#value_from_values
0.960.962.042.04 0.0012754596/30084503##[]=18787492/42419312##[]=
5.562.882.694568754/456875411.705.835.888513536/8513536 Protobuf::Decoder.decode_each_field
8%9% 4%5.562.882.694568754Protobuf::VarintPure.decode11.705.835.888513536ProtobufJavaHelpers::EncodeDecode.decode
0.892.041.38 0.660.226853131/685313114883688/14883688 IO::GenericReadable.readbyte
0.470.471.001.00 0.0013706262/21322798##&29767376/40271449##&
0.280.280.590.59 0.006853131/6853284##<<14883688/17017539Numeric#nonzero?
0.270.270.580.58 0.006853131/8376374Numeric#nonzero?14883688/14883841##<<
0.270.270.560.56 0.006853131/23728693##+14883688/46949692##+
0.260.260.560.56 0.006853131/9139607##|14883688/14883841##|
0.260.260.540.54 0.006853131/6853756##*14883688/14884832##*
5.182.133.0412754596/12754596##each_key11.453.647.8219340404/19340404Protobuf::Field::BaseField#to_message_hash
8%3%5.182.133.0412754596Protobuf::Field::Int64Field(singleton)#to_message_hash9%2%11.453.647.8219340404Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHash#call
2.141.480.6612754596/14277514Protobuf::Field::Int64Field(singleton)#value_from_values6.453.193.2619340404/38127896Protobuf::Field::BaseField#value_from_values
0.900.901.371.37 0.0012754596/30084503##[]=19340404/42419312##[]=
0.110.000.1010000/1524359##times10.641.419.234256768/4256768Protobuf::Decoder.decode_each_field
8%1%10.641.419.234256768Protobuf::Message::Serialization.set_field_bytes
0.110.020.0915/1524359Kernel.eval8.480.877.604256768/4256768Protobuf::Field::BaseField#set
0.150.010.14153/1524359Protobuf::Field.build0.420.420.004256768/97013401##[]
0.240.010.231/1524359Bundler::Dsl#to_definition0.330.330.004256768/50632510Test::Resource#_protobuf_message_field
0.510.110.40761459/1524359Protobuf::Message::Serialization::ClassMethods.decode_from8.480.877.604256768/4256768Protobuf::Message::Serialization.set_field_bytes
6%0%8.480.877.604256768Protobuf::Field::BaseField#set
7.601.026.584256768/4256768Protobuf::Field::BaseFieldObjectDefinitions::BaseSetMethod#call
3.220.123.09751459/1524359Proc#call7.601.026.584256768/4256768Protobuf::Field::BaseField#set
7%6% 0%4.590.354.251524359Class#new7.601.026.584256768Protobuf::Field::BaseFieldObjectDefinitions::BaseSetMethod#call
3.600.593.001522919/1522919Protobuf::Message#initialize5.010.624.394256768/4286772Protobuf::Message#set_field
0.230.000.231/1Bundler::Definition#initialize1.080.780.302123384/2123384Protobuf::Field::IntegerField#decode
0.140.010.14153/153Protobuf::Field::BaseField#initialize0.460.300.162123384/2123384Protobuf::Field::StringField#decode
0.140.147.092.095.004103921/4103921Protobuf::Field::BaseField#encode_to_stream
5%1%7.092.095.004103921Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
2.361.201.1612311763/20539605IO::GenericWritable.<<
1.410.530.884103921/8217995Protobuf::Field::VarintField.encode
0.580.400.184103921/4104743BasicObject#!=
0.280.28 0.002284377/63970204Protobuf::Enum.enum_for_tag_integer4103921/4104065##+
0.210.210.004103921/4103921##encoding
0.17 0.17 0.001525107/63970204Protobuf::Field::VarintField.cached_varint4103921/4103921##bytesize
0.200.206.404.142.2638127896/38127896Protobuf::Field::BaseField#value_from_values
5%3%6.404.142.2638127896Protobuf::Field::BaseFieldObjectDefinitions::BaseFieldValueFromValues#call
2.262.26 0.002284379/63970204Protobuf::Message#set_field38127896/97013401##[]
0.210.210.420.42 0.002284377/639702044256768/97013401 Protobuf::Message::Serialization.set_field_bytes
0.710.710.480.48 0.0013516055/63970204Protobuf::Field::Int64Field(singleton)#value_from_values8217842/97013401Protobuf::Field::BaseFieldObjectDefinitions::BaseFieldValueFromValuesForSerialization#call
0.900.902.262.26 0.0013516055/63970204Protobuf::Field::StringField(singleton)#value_from_values38127896/97013401Protobuf::Field::BaseFieldObjectDefinitions::BaseFieldValueFromValues#call
2.012.013.203.20 0.0027793569/63970204##each_key46345738/97013401##each_key
6%6%4.424.395%5%6.396.36 0.0363970204##[]97013401##[]
3.600.593.001522919/1522919Class#new6.021.034.994113921/4113921Protobuf::Field::BaseField#encode_to_stream
5%4% 0%3.600.593.001522919Protobuf::Message#initialize
2.870.322.551522919/1523130##each6.021.034.994113921Protobuf::Field::BaseFieldObjectDefinitions::BaseEncodeToStream#call
0.470.340.132284379/32362325Protobuf::Message#set_field3.351.481.864103921/4103921Protobuf::Field::IntegerField#encode
0.530.400.132284377/32362325Protobuf::Message::Serialization.set_field_bytes1.610.800.818227842/20539605IO::GenericWritable.<<
2.422.420.0027793569/32362325##each_key5.010.624.394256768/4286772Protobuf::Field::BaseFieldObjectDefinitions::BaseSetMethod#call
5% 4%3.433.160.2632362325Protobuf::Message#_protobuf_message_field0%5.100.634.474286772Protobuf::Message#set_field
0.200.200.001522919/1523730Protobuf::Message::Fields::ClassMethods.field_store4.460.903.564286772/4286772Protobuf::Field::BaseField#set_field
2.870.322.551522919/1523130Protobuf::Message#initialize4.460.903.564286772/4286772Protobuf::Message#set_field
4%3% 0%2.890.332.561523130##each4.460.903.564286772Protobuf::Field::BaseField#set_field
2.550.412.151522920/4568756Protobuf::Message#set_field1.780.571.212153386/2153386Protobuf::Field::BaseFieldObjectDefinitions::BaseSetField#call
0.540.160.38761459/2286579Protobuf::Field::EnumField#encode1.780.691.092133386/2133386Protobuf::Field::BaseFieldObjectDefinitions::RequiredStringSetField#call
0.580.170.41761459/2286579Protobuf::Field::StringField(singleton)#encode_to_stream1.610.800.818227842/20539605Protobuf::Field::BaseFieldObjectDefinitions::BaseEncodeToStream#call
1.630.840.79761459/2286579Protobuf::Field::IntegerField#encode2.361.201.1612311763/20539605Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
4%3% 1%2.771.181.592286579Protobuf::Field::VarintField.encode
0.660.390.271523058/1525107Protobuf::Field::VarintField.cached_varint3.972.001.9720539605IO::GenericWritable.<<
0.210.211.971.97 0.003049844/3051803##<<20539605/20539605StringIO#write
0.120.120.180.18 0.00763521/763523##pack2153386/42419312Protobuf::Field::BaseFieldObjectDefinitions::BaseSetField#call
0.120.120.200.20 0.003049844/19924325##<2133386/42419312Protobuf::Field::BaseFieldObjectDefinitions::RequiredStringSetField#call
0.110.111.371.37 0.002284530/3809398##<=19340404/42419312Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHash#call
0.110.112.042.04 0.002286323/4570700##>>18787492/42419312Protobuf::Field::BaseFieldObjectDefinitions::BaseToMessageHashWithStringKey#call
0.260.070.19761459/14277514##each_key
3%3%3.803.790.0142419312##[]=
2.371.530.8412754596/14277514Protobuf::Field::StringField(singleton)#to_message_hash3.351.481.864103921/4103921Protobuf::Field::BaseFieldObjectDefinitions::BaseEncodeToStream#call
4% 2%2.621.591.0314277514Protobuf::Field::StringField(singleton)#value_from_values1%3.351.481.864103921Protobuf::Field::IntegerField#encode
0.900.901.450.500.954103921/8217995Protobuf::Field::VarintField.encode
0.410.41 0.0013516055/63970204##[]4103921/40271449##&
2.590.212.38761459/761459##each_key3.341.691.668217842/8217842##each_key
4%0%2.590.212.38761459Protobuf::Field::Int64Field(singleton)#encode_to_stream2%1%3.341.691.668217842Protobuf::Field::BaseField#value_from_values_for_serialization
2.060.341.73761459/761459Protobuf::Field::IntegerField#encode1.661.180.488217842/8217842Protobuf::Field::BaseFieldObjectDefinitions::BaseFieldValueFromValuesForSerialization#call
0.320.150.171522918/5330213IO::GenericWritable.<<1.410.530.884103921/8217995Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
2.460.192.27761459/761459Protobuf::Message::Serialization.set_field_bytes1.450.500.954103921/8217995Protobuf::Field::IntegerField#encode
3%2% 0%2.460.192.27761459Protobuf::Field::EnumField(singleton)#set
1.330.331.00761459/761459Protobuf::Field::EnumField#decode2.871.031.848217995Protobuf::Field::VarintField.encode
0.940.120.82761459/4568756Protobuf::Message#set_field1.840.930.918217995/8217995ProtobufJavaHelpers::EncodeDecode.encode
0.250.070.18761459/14277514##each_key0.330.330.004256768/50632510Protobuf::Message::Serialization.set_field_bytes
2.141.480.6612754596/14277514Protobuf::Field::Int64Field(singleton)#to_message_hash2.462.460.0046345738/50632510##each_key
3% 2%2.381.550.8414277514Protobuf::Field::Int64Field(singleton)#value_from_values
0.710.712%2.792.79 0.0013516055/63970204##[]50632510Test::Resource#_protobuf_message_field
0.420.41 0.030.392/18650.382/1883 Kernel.load
0.890.87 0.000.896/18650.876/1883 (top)
0.951.02 0.000.95112/18651.02115/1883 Kernel.require
3%1% 0%2.262.30 0.032.2318652.271883 Kernel.require
0.810.86 0.000.810.86 1/1 Bundler.setup
0.230.000.2319/762970##each0.250.010.2419/4105546##each
0.140.12 0.000.140.12 1/1 Gem::Specification.load_defaults
0.110.000.11109/109Protobuf::Message::Fields::ClassMethods.optional0.280.010.271/2136384Bundler::Dsl#to_definition
0.120.121.240.310.942123384/2136384Protobuf::Message::Serialization::ClassMethods.decode_from
1%0%2.060.501.562136384Class#new
1.020.690.342133386/2133386Protobuf::Message#initialize
0.27 0.001522919/30084503Protobuf::Field::Int64Field(singleton)#set_field0.271/1Bundler::Definition#initialize
0.120.122.041.380.6614883688/14883688ProtobufJavaHelpers::EncodeDecode.decode
1%1%2.041.380.6614883688IO::GenericReadable.readbyte
0.660.66 0.001522918/30084503Protobuf::Field::EnumField(singleton)#set_field14883688/14883688StringIO#getbyte
0.130.131.971.970.0020539605/20539605IO::GenericWritable.<<
1%1%1.971.97 0.001522919/30084503Protobuf::Field::StringField(singleton)#set_field20539605StringIO#write
0.900.900.300.30 0.0012754596/30084503Protobuf::Field::Int64Field(singleton)#to_message_hash6794740/46949692##each
0.960.960.560.56 0.0012754596/30084503Protobuf::Field::StringField(singleton)#to_message_hash14883688/46949692ProtobufJavaHelpers::EncodeDecode.decode
3%3%2.242.240.0130084503##[]=
2.060.341.73761459/761459Protobuf::Field::Int64Field(singleton)#encode_to_stream1.081.080.0025271252/46949692Benchmark::IPS::Job::Entry#call_times
3%0%2.060.341.73761459Protobuf::Field::IntegerField#encode1%1%1.941.940.0046949692##+
1.630.840.79761459/22865791.840.930.918217995/8217995 Protobuf::Field::VarintField.encode
1%0%1.840.930.918217995ProtobufJavaHelpers::EncodeDecode.encode
0.100.100.910.91 0.00761459/21322798##&8217995/8217995ProtobufJavaHelpers::Varinter.to_varint
1.890.511.38761459/761459##each_key1.780.571.212153386/2153386Protobuf::Field::BaseField#set_field
2%1% 0%1.890.511.38761459Protobuf::Field::StringField(singleton)#encode_to_stream1.780.571.212153386Protobuf::Field::BaseFieldObjectDefinitions::BaseSetField#call
0.580.170.41761459/2286579Protobuf::Field::VarintField.encode0.920.630.292133386/2133386Protobuf::Field::VarintField#coerce!
0.470.230.242284377/5330213IO::GenericWritable.<<
0.140.100.04761459/762229BasicObject#!=0.180.180.002153386/42419312##[]=
1.800.391.421522919/1522919Protobuf::Message#set_field1.780.691.092133386/2133386Protobuf::Field::BaseField#set_field
2%1% 0%1.800.391.421522919Protobuf::Field::Int64Field(singleton)#set_field1.780.691.092133386Protobuf::Field::BaseFieldObjectDefinitions::RequiredStringSetField#call
1.240.440.801522919/1522919Protobuf::Field::VarintField#coerce!0.610.430.182133386/6237307Test::Resource#_protobuf_message_unset_required_field_tags
0.120.120.200.20 0.001522919/30084503##[]=2133386/42419312##[]=
1.710.211.49761459/761459Protobuf::Message::Serialization.set_field_bytes
2%0%1.710.211.49761459Protobuf::Field::Int64Field(singleton)#set0.160.160.002133386/2133570##delete
1.07 0.120.95761459/4568756Protobuf::Message#set_field0.120.002133386/4298337Kernel.kind_of?
0.430.320.11761459/761459Protobuf::Field::IntegerField#decode0.120.120.004256768/40271449Protobuf::Decoder.decode_each_field
1.66 0.211.46761459/761459##each_key
2%0%1.66 0.211.46761459Protobuf::Field::EnumField(singleton)#encode_to_stream0.002123384/40271449Protobuf::Field::IntegerField#decode
1.180.340.84761459/761459Protobuf::Field::EnumField#encode0.410.410.004103921/40271449Protobuf::Field::IntegerField#encode
0.280.150.131522918/5330213IO::GenericWritable.<<1.001.000.0029767376/40271449ProtobufJavaHelpers::EncodeDecode.decode
1%1%1.761.760.0040271449##&
1.660.351.311522918/1522918Protobuf::Message#set_field1.670.810.866795778/6795778##each
2%1% 0%1.660.351.311522918Protobuf::Field::EnumField(singleton)#set_field
1.130.271.670.81 0.861522918/1522918Protobuf::Field::EnumField#coerce!6795778Benchmark::Timing.now
0.120.120.860.86 0.001522918/30084503##[]=6795778/6795779Process.clock_gettime
1.600.601.001522919/1522919Protobuf::Message#set_field1.661.180.488217842/8217842Protobuf::Field::BaseField#value_from_values_for_serialization
2%1% 0%1.600.601.001522919Protobuf::Field::StringField(singleton)#set_field
0.660.410.251522919/2284378Protobuf::Message#_protobuf_message_required_field_tags1.661.180.488217842Protobuf::Field::BaseFieldObjectDefinitions::BaseFieldValueFromValuesForSerialization#call
0.130.130.480.48 0.001522919/30084503##[]=8217842/97013401##[]
1.400.191.21761459/761459Protobuf::Message::Serialization.set_field_bytes1.281.280.0032065976/32065992Benchmark::IPS::Job::Entry#call_times
2%0%1.400.191.21761459Protobuf::Field::StringField(singleton)#set
1.000.160.84761459/4568756Protobuf::Message#set_field1%1%1.281.280.0032065992##<
0.210.140.07761459/761459Protobuf::Field::StringField#decode0.560.560.004103921/6237307Protobuf::Message#each_field_for_serialization
1.360.211.15751459/761459Proc#call0.610.430.182133386/6237307Protobuf::Field::BaseFieldObjectDefinitions::RequiredStringSetField#call
2% 0%1.400.220% 1.18761459Test::Resource#status=1.000.186237307Test::Resource#_protobuf_message_unset_required_field_tags
1.180.190.98761459/4568756Protobuf::Message#set_field0.180.180.002133386/4247921Kernel.dup
1.330.331.00761459/761459Protobuf::Field::EnumField(singleton)#set1.080.780.302123384/2123384Protobuf::Field::BaseFieldObjectDefinitions::BaseSetMethod#call
2% 0%1.330.331.00761459Protobuf::Field::EnumField#decode0%1.080.780.302123384Protobuf::Field::IntegerField#decode
0.880.280.60761459/761459Protobuf::Field::EnumField#acceptable?0.210.210.002123384/40271449##&
1.240.440.801522919/1522919Protobuf::Field::Int64Field(singleton)#set_field1.060.700.376207304/6217305Proc#call
1% 0%1.240.440.801522919Protobuf::Field::VarintField#coerce!
0.650.420.221522919/1522919Protobuf::Field::Int64Field#acceptable?0%1.070.700.376217305StringIO.new
0.450.160.28761459/2284386Protobuf::Field::EnumField#acceptable?0.370.370.006217305/6217305StringIO#initialize
0.760.270.501522918/2284386Protobuf::Field::EnumField#coerce!1.030.001.022/115(top)
1% 0%1.210.430.782284386Protobuf::Enum.fetch
0.670.410.262284377/2284377Protobuf::Enum.enum_for_tag_integer0%1.030.001.02115Kernel.require
0.110.111.02 0.002284386/5331568Kernel.kind_of?1.02115/1883Kernel.require
1.181.020.69 0.340.84761459/761459Protobuf::Field::EnumField(singleton)#encode_to_stream2133386/2133386Class#new
1% 0%1.180%1.020.69 0.340.84761459Protobuf::Field::EnumField#encode2133386Protobuf::Message#initialize
0.54 0.160.38761459/2286579Protobuf::Field::VarintField.encode0.100.062133386/2133600##each
0.180.110.07761459/761727Protobuf::Enum#to_i0.920.630.292133386/2133386Protobuf::Field::BaseFieldObjectDefinitions::BaseSetField#call
0%0%0.920.630.292133386Protobuf::Field::VarintField#coerce!
0.11 0.11 0.00761459/21322798##&2133386/4298337Kernel.kind_of?
1.130.270.861522918/1522918Protobuf::Field::EnumField(singleton)#set_field0.910.910.008217995/8217995ProtobufJavaHelpers::EncodeDecode.encode
1% 0%1.130.270.861522918Protobuf::Field::EnumField#coerce!0%0.910.910.008217995ProtobufJavaHelpers::Varinter.to_varint
0.760.270.501522918/2284386Protobuf::Enum.fetch
0.100.100.001522918/2285051Protobuf::Field::BaseField#type_class
0.280.150.131522918/5330213Protobuf::Field::EnumField(singleton)#encode_to_stream
0.320.150.171522918/5330213Protobuf::Field::Int64Field(singleton)#encode_to_stream
0.470.230.242284377/5330213Protobuf::Field::StringField(singleton)#encode_to_stream
1%0%1.060.520.545330213IO::GenericWritable.<<
0.540.540.005330213/5330213StringIO#write
0.100.100.00761459/21322798Protobuf::Field::IntegerField#encode
0.110.110.00761459/21322798Protobuf::Field::EnumField#encode
0.470.470.0013706262/21322798Protobuf::VarintPure.decode
1%1%1.001.000.0021322798##&
0.140.140.003368424/23728693##each
0.270.270.006853131/23728693Protobuf::VarintPure.decode
0.560.560.0013506055/23728693Benchmark::IPS::Job::Entry#call_times
1%1%0.970.970.0023728693##+
0.950.000.952/112(top)
1%0%0.950.000.95112Kernel.require
0.950.000.95112/1865Kernel.require
0.890.660.226853131/6853131Protobuf::VarintPure.decode
1%1%0.890.660.226853131IO::GenericReadable.readbyte
0.220.220.006853131/6853131StringIO#getbyte
0.880.280.60761459/761459Protobuf::Field::EnumField#decode
1%0%0.880.280.60761459Protobuf::Field::EnumField#acceptable?
0.450.160.28761459/2284386Protobuf::Enum.fetch
0.810.000.811/1Kernel.require
1%0%0.810.000.811Bundler.setup
0.440.010.431/2Bundler.definition
0.360.000.361/1Bundler::Runtime#setup
0.110.110.00761459/2284378Protobuf::Message#each_field_for_serialization
0.660.410.251522919/2284378Protobuf::Field::StringField(singleton)#set_field
1%0%0.770.520.252284378Protobuf::Message#_protobuf_message_required_field_tags
0.200.200.001522919/1522926Protobuf::Message::Fields::ClassMethods.required_field_tags
0.120.120.003049844/19924325Protobuf::Field::VarintField.encode
0.650.650.0016874465/19924325Benchmark::IPS::Job::Entry#call_times
1%1%0.760.760.0019924325##<
0.740.310.443368939/3368939##each
1%0%0.740.310.443368939Benchmark::Timing.now
0.440.440.003368939/3368940Process.clock_gettime
0.660.390.271523058/1525107Protobuf::Field::VarintField.encode
1%0%0.680.390.281525107Protobuf::Field::VarintField.cached_varint
0.170.170.001525107/63970204##[]
0.670.410.262284377/2284377Protobuf::Enum.fetch
1%0%0.670.410.262284377Protobuf::Enum.enum_for_tag_integer
0.140.140.002284377/63970204##[]
0.120.120.002284377/2284829##first
0.650.420.221522919/1522919Protobuf::Field::VarintField#coerce!
1%0%0.650.420.221522919Protobuf::Field::Int64Field#acceptable?
0.540.540.005330213/5330213IO::GenericWritable.<<
0%0%0.540.540.005330213StringIO#write
0.520.060.4617/19(top)
0%0%0.520.060.4619Kernel.load
0.420.030.392/1865Kernel.require
0.440.010.431/2Bundler.setup
0%0%0.440.010.432Bundler.definition
0.350.000.341/1Bundler::Definition.build
0.440.440.003368939/3368940Benchmark::Timing.now
0%0%0.440.440.003368940Process.clock_gettime
0.430.320.11761459/761459Protobuf::Field::Int64Field(singleton)#set
0%0%0.430.320.11761459Protobuf::Field::IntegerField#decode
0.330.000.331/822Bundler::Runtime#requested_specs
0%0%0.410.000.41822Kernel.send
0.330.000.331/1Bundler::Definition#requested_specs
0.360.000.361/1Bundler.setup
0%0%0.360.000.361Bundler::Runtime#setup
0.330.000.331/1Bundler::Runtime#requested_specs
0.260.260.860.86 0.006853131/9139607Protobuf::VarintPure.decode6795778/6795779Benchmark::Timing.now
0% 0%0.350.350.860.86 0.009139607##|6795779Process.clock_gettime
0.350.000.341/1Bundler.definition
0%0%0.350.000.341Bundler::Definition.build
0.330.000.331/1Bundler::Dsl.evaluate
0.330.86 0.000.330.86 1/1Bundler::Definition.buildKernel.require
0% 0%0.330.86 0.000.330.86 1Bundler::Dsl.evaluateBundler.setup
0.240.000.241/1Bundler::Dsl#to_definition0.480.010.481/2Bundler.definition
0.330.37 0.000.330.37 1/1 Bundler::Runtime#setup
0%0%0.330.000.331Bundler::Runtime#requested_specs
0.330.000.331/822Kernel.send
0.330.000.331/1Kernel.send
0%0%0.330.000.331Bundler::Definition#requested_specs
0.330.000.331/1Bundler::Definition#specs_for
0.330.590.59 0.000.331/1Bundler::Definition#requested_specs14883688/17017539ProtobufJavaHelpers::EncodeDecode.decode
0% 0%0.330.000.331Bundler::Definition#specs_for
0.320.680.68 0.000.321/1Bundler::Definition#specs17017539Numeric#nonzero?
0.270.270.660.66 0.006853131/8376374Protobuf::VarintPure.decode14883688/14883688IO::GenericReadable.readbyte
0% 0%0.330.330.660.66 0.008376374Numeric#nonzero?14883688StringIO#getbyte
0.320.000.321/1Bundler::Definition#specs_for0.580.400.184103921/4104743Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
0% 0%0.320.000.321Bundler::Definition#specs0.590.400.184104743BasicObject#!=
0.210.180.18 0.000.211/1Bundler::SpecSet#materialize4104167/4104503BasicObject#==
0.280.280.580.58 0.006853131/6853284Protobuf::VarintPure.decode14883688/14883841ProtobufJavaHelpers::EncodeDecode.decode
0% 0%0.280.280.580.58 0.006853284##<<14883841##<<
0.110.110.560.56 0.002284386/5331568Protobuf::Enum.fetch14883688/14883841ProtobufJavaHelpers::EncodeDecode.decode
0% 0%0.270.270.560.56 0.005331568Kernel.kind_of?14883841##|
0.260.260.540.54 0.006853131/6853756Protobuf::VarintPure.decode14883688/14884832ProtobufJavaHelpers::EncodeDecode.decode
0% 0%0.260.260.540.54 0.006853756##*14884832##*
0.240.000.241/1Bundler::Dsl.evaluate0.500.060.4417/19(top)
0% 0%0.240.000.241Bundler::Dsl#to_definition0.500.060.4419Kernel.load
0.240.010.231/1524359Class#new0.410.030.382/1883Kernel.require
0.230.000.231/1Class#new0.480.010.481/2Bundler.setup
0% 0%0.230.000.231Bundler::Definition#initialize0.480.010.482Bundler.definition
0.230.070.16761459/1522918##each_key
0%0%0.230.070.161522918Protobuf::Field::EnumField(singleton)#value_from_values0.390.000.381/1Bundler::Definition.build
0.190.000.191/392Bundler::SpecSet#materialize0.460.300.162123384/2123384Protobuf::Field::BaseFieldObjectDefinitions::BaseSetMethod#call
0% 0%0.230.020.21392##map!0.460.300.162123384Protobuf::Field::StringField#decode
0.190.160.16 0.000.1938/38Bundler::LazySpecification#__materialize__2123384/2123384##force_encoding
0.220.220.34 0.006853131/6853131IO::GenericReadable.readbyte0.341/874Bundler::Runtime#requested_specs
0% 0%0.220.220.42 0.006853131StringIO#getbyte0.42874Kernel.send
0%0%0.220.22
0.34 0.005331092Kernel.nil?0.341/1Bundler::Definition#requested_specs
0.210.140.07761459/761459Protobuf::Field::StringField(singleton)#set0.390.000.381/1Bundler.definition
0% 0%0.210.140.07761459Protobuf::Field::StringField#decode0.390.000.381Bundler::Definition.build
0.370.000.371/1Bundler::Dsl.evaluate
0.210.37 0.000.210.37 1/1Bundler::Definition#specsBundler::Definition.build
0% 0%0.210.37 0.000.210.37 1Bundler::SpecSet#materializeBundler::Dsl.evaluate
0.190.28 0.000.191/392##map!0.281/1Bundler::Dsl#to_definition
0.210.210.370.37 0.003049844/3051803Protobuf::Field::VarintField.encode6217305/6217305StringIO.new
0% 0%0.210.210.370.37 0.003051803##<<6217305StringIO#initialize
0.200.110.09751459/761459Proc#call0.370.000.371/1Bundler.setup
0% 0%0.210.110.09761459StringIO.new0.370.000.371Bundler::Runtime#setup
0.200.200.34 0.001522919/1523730Protobuf::Message#_protobuf_message_field0.341/1Bundler::Runtime#requested_specs
0%0%0.200.20
0.180.18 0.001523730Protobuf::Message::Fields::ClassMethods.field_store2113384/4247921Proc#call
0.110.110.180.18 0.002286323/4570700Protobuf::Field::VarintField.encode2133386/4247921Test::Resource#_protobuf_message_unset_required_field_tags
0% 0%0.200.200.360.36 0.004570700##>>4247921Kernel.dup
0.200.200.340.34 0.001522919/1522926Protobuf::Message#_protobuf_message_required_field_tags6794732/6794732##each
0% 0%0.200.200.340.34 0.001522926Protobuf::Message::Fields::ClassMethods.required_field_tags6794732##<
0.190.34 0.000.1938/38##map!0.341/1Bundler::Runtime#setup
0% 0%0.190.34 0.000.1938Bundler::LazySpecification#__materialize__0.341Bundler::Runtime#requested_specs
0.150.34 0.000.1537/37Bundler::Source::Rubygems#specs0.341/874Kernel.send
0.180.110.07761459/761727Protobuf::Field::EnumField#encode0.340.000.341/1Kernel.send
0% 0%0.180.110.07761727Protobuf::Enum#to_i0.340.000.341Bundler::Definition#requested_specs
0.100.100.001522918/2285051Protobuf::Field::EnumField#coerce!
0%0%0.180.180.34 0.002285051Protobuf::Field::BaseField#type_class0.341/1Bundler::Definition#specs_for
0.180.180.34 0.003368414/3368414##each0.341/1Bundler::Definition#requested_specs
0% 0%0.180.180.34 0.003368414##<0.341Bundler::Definition#specs_for
0.110.110.002284530/3809398Protobuf::Field::VarintField.encode
0%0%0.180.180.33 0.003809398##<=0.331/1Bundler::Definition#specs
0.110.33 0.000.11109/153Protobuf::Message::Fields::ClassMethods.optional0.331/1Bundler::Definition#specs_for
0% 0%0.160.33 0.000.16153Protobuf::Message::Fields::ClassMethods.define_field0.331Bundler::Definition#specs
0.160.22 0.000.15153/153Protobuf::Field.build0.221/1Bundler::SpecSet#materialize
0.120.320.32 0.000.123/285Gem::Specification.gemspec_stubs_in4093920/4103921Proc#call
0% 0%0.160.020.15285##select0.320.320.004103921Protobuf::Message#to_proto
0.120.310.31 0.000.1268/68Gem::StubSpecification#valid?6380152/6380152Protobuf::Decoder.decode_each_field
0% 0%0.160.160.310.31 0.003807453##>=6380152StringIO#eof
0.150.280.28 0.000.151/2Bundler::Source::Rubygems#installed_specs4103921/4104065Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
0% 0%0.160.000.162Bundler::Index.build
0.140.280.28 0.000.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs4104065##+
0.160.28 0.000.15153/153Protobuf::Message::Fields::ClassMethods.define_field0.281/1Bundler::Dsl.evaluate
0% 0%0.160.28 0.000.15153Protobuf::Field.build0.281Bundler::Dsl#to_definition
0.150.28 0.010.14153/15243590.271/2136384 Class#new
0.150.27 0.000.1537/37Bundler::LazySpecification#__materialize__0.271/1Class#new
0% 0%0.150.27 0.000.1537Bundler::Source::Rubygems#specs0.271Bundler::Definition#initialize
0.150.10 0.000.150.10 1/1Bundler::Source::Rubygems#installed_specsBundler::Definition#converge_paths
0.150.250.25 0.000.151/1Bundler::Source::Rubygems#specs6380152/6383519Protobuf::Decoder.decode_each_field
0% 0%0.150.250.25 0.000.151Bundler::Source::Rubygems#installed_specs6383519##==
0.150.230.23 0.000.151/2Bundler::Index.build2123384/2123384Protobuf::Decoder.decode_each_field
0%0%0.230.230.002123384StringIO#read
0.140.100.04761459/762229Protobuf::Field::StringField(singleton)#encode_to_stream0.190.000.191/425Bundler::SpecSet#materialize
0% 0%0.150.100.05762229BasicObject#!=0.230.020.21425##map!
0.150.150.19 0.003045836/3045836Protobuf::Decoder.decode_each_field0.1939/39Bundler::LazySpecification#__materialize__
0%0%0.150.15
0.110.11 0.003045836StringIO#eof2133386/4298337Protobuf::Field::VarintField#coerce!
0.140.010.14153/153Class#new0.120.120.002133386/4298337Protobuf::Field::BaseFieldObjectDefinitions::RequiredStringSetField#call
0% 0%0.140.010.14153Protobuf::Field::BaseField#initialize0.230.230.004298337Kernel.kind_of?
0.140.22 0.000.140.22 1/1Bundler::Index.buildBundler::Definition#specs
0% 0%0.140.22 0.000.140.22 1Bundler::RubygemsIntegration::MoreFuture#all_specsBundler::SpecSet#materialize
0.140.19 0.000.141/1Gem::Specification.stubs0.191/425##map!
0.210.210.004103921/4103921Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
0% 0%0.140.060.081136BasicObject#instance_eval0.210.210.004103921##encoding
0.140.19 0.000.141/1Kernel.require0.1939/39##map!
0% 0%0.140.19 0.000.141Gem::Specification.load_defaults0.1939Bundler::LazySpecification#__materialize__
0.140.16 0.000.141/1Gem::Specification.each_spec0.1637/37Bundler::Source::Rubygems#specs
0.160.100.062133386/2133600Protobuf::Message#initialize
0% 0%0.140.030.1160Kernel.eval
0.110.020.0915/1524359Class#new0.190.120.072133600##each
0.140.180.18 0.000.141/1Gem::Specification.load_defaults4256768/4256768Protobuf::Decoder.decode_each_field
0% 0%0.140.180.18 0.000.141Gem::Specification.each_spec4256768##>>
0%0%0.180.020.16697##map
0.140.180.18 0.000.141/1Gem::Specification.each_gemspec4104167/4104503BasicObject#!=
0%0%0.180.180.004104503BasicObject#==
0.140.170.17 0.000.141/1Gem::Specification.each_spec4103921/4103921Protobuf::Field::BaseFieldObjectDefinitions::StringEncodeToStream#call
0% 0%0.140.000.141Gem::Specification.each_gemspec
0.140.170.17 0.000.141/762970##each4103921##bytesize
0.140.15 0.000.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs0.151/2Bundler::Source::Rubygems#installed_specs
0% 0%0.140.16 0.000.141Gem::Specification.stubs0.162Bundler::Index.build
0.120.15 0.000.120.15 1/1Gem::Specification.installed_stubsBundler::RubygemsIntegration::MoreFuture#all_specs
0.130.130.160.16 0.003045836/3048922Protobuf::Decoder.decode_each_field2133386/2133570Protobuf::Field::BaseFieldObjectDefinitions::RequiredStringSetField#call
0% 0%0.130.130.160.16 0.003048922##==2133570##delete
0.120.160.16 0.000.122/3##each2123384/2123384Protobuf::Field::StringField#decode
0% 0%0.130.000.133Gem::Specification.gemspec_stubs_in
0.120.160.16 0.000.123/285##select2123384##force_encoding
0.120.120.16 0.00763521/763523Protobuf::Field::VarintField.encode0.1637/37Bundler::LazySpecification#__materialize__
0% 0%0.120.120.160.000.1637Bundler::Source::Rubygems#specs
0.15 0.00763523##pack0.151/1Bundler::Source::Rubygems#installed_specs
0.120.120.15 0.002284377/2284829Protobuf::Enum.enum_for_tag_integer0.151/1Bundler::Source::Rubygems#specs
0% 0%0.120.120.150.000.151Bundler::Source::Rubygems#installed_specs
0.15 0.002284829##first0.151/2Bundler::Index.build
0.120.15 0.000.1268/1220Gem::StubSpecification#valid?0.151/1Bundler::Index.build
0% 0%0.120.15 0.000.121220Gem::StubSpecification#data0.151Bundler::RubygemsIntegration::MoreFuture#all_specs
0.120.010.1168/68Kernel.open
0%0%0.120.120.14 0.003046840Kernel.class0.141/1Gem::Specification.stubs
0.120.14 0.000.1268/68##select0.141/1Bundler::RubygemsIntegration::MoreFuture#all_specs
0% 0%0.120.14 0.000.1268Gem::StubSpecification#valid?0.141Gem::Specification.stubs
0.12
0%0%0.140.030.1161Kernel.eval
0%0%0.13 0.000.1268/1220Gem::StubSpecification#data0.133Gem::Specification.gemspec_stubs_in
0.00 0.12 1/1Gem::Specification.stubsKernel.require
0% 0.00 0.12 1Gem::Specification.installed_stubsGem::Specification.load_defaults
0.12 0.00 0.12 1/1Gem::Specification.map_stubsGem::Specification.each_spec
0.00 0.12 1/1Gem::Specification.installed_stubsGem::Specification.load_defaults
0% 0.00 0.12 1Gem::Specification.map_stubsGem::Specification.each_spec
0.12 0.00 0.12 1/1##flat_mapGem::Specification.each_gemspec
0.00 0.12 1/1Gem::Specification.map_stubsGem::Specification.each_spec
0% 0.00 0.12 1##flat_mapGem::Specification.each_gemspec
0.12 0.00 0.121/762970##each1/4105546##each
0.120.010.1168/68Gem::StubSpecification#data0.100.000.101/178Bundler::Definition#converge_paths
0% 0%0.120.01 0.1168Kernel.open0.000.11178##any?
0.100.000.102/2Bundler::Definition#specs_changed?
0.110.10 0.000.11109/109Kernel.require0.101/1Bundler::Definition#initialize
0% 0%0.110.10 0.000.11109Protobuf::Message::Fields::ClassMethods.optional0.101Bundler::Definition#converge_paths
0.110.10 0.000.11109/153Protobuf::Message::Fields::ClassMethods.define_field0.101/178##any?
0.110.10 0.00 0.1013/14##each2/2##any?
0% 0%0.110.000.1114Gem::Specification.load
0.10 0.10 0.00761459/761459Protobuf::Decoder.decode_each_field0.102Bundler::Definition#specs_changed?
0% 0% 0.100.10 0.00761459StringIO#read0.10153Protobuf::Message::Fields::ClassMethods.define_field